Rev 1: Change the autopack code to first prompt to see if the user in http://bzr.arbash-meinel.com/plugins/prompt_repack
John Arbash Meinel
john at arbash-meinel.com
Wed Mar 16 12:15:10 UTC 2011
At http://bzr.arbash-meinel.com/plugins/prompt_repack
------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20110316121502-f98lvx6skfaj1fgh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: prompt_repack
timestamp: Wed 2011-03-16 13:15:02 +0100
message:
Change the autopack code to first prompt to see if the user
really wants to repack now.
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2011-03-16 12:15:02 +0000
@@ -0,0 +1,71 @@
+# Copyright (C) 2011 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Make autopacking optional based on a prompt."""
+
+import sys
+import os
+
+from bzrlib import (
+ osutils,
+ urlutils,
+ trace,
+ )
+from bzrlib.repofmt import groupcompress_repo
+
+
+orig_do_autopack = groupcompress_repo.GCRepositoryPackCollection._do_autopack
+
+def _trapped_autopack(self):
+ # The next call to _execute_pack_operations is going to be because of this
+ # autopack, so trap it.
+ execute = self._execute_pack_operations
+ def _ask_execute_pack_operations(pack_operations, *args, **kwargs):
+ num_revs_affected = sum([po[0] for po in pack_operations])
+ location = urlutils.unescape_for_display(
+ self.repo.bzrdir.user_url, sys.stderr.encoding or 'ascii')
+ sys.stderr.write('Repository %s wants to repack %d revisions.\n'
+ % (location, num_revs_affected))
+ can_background = (getattr(os, 'fork', None) is not None)
+ if can_background:
+ sys.stderr.write('Do it [N]ow, [p]ostpone,'
+ ' or [b]ackground it? [Npb]:')
+ else:
+ sys.stderr.write('Do it [N]ow or [p]ostpone? [Np]:')
+ char = osutils.getchar()
+ if char in '\r\nnN':
+ return execute(pack_operations, *args, **kwargs)
+ elif char in 'pP':
+ return False
+ elif char in 'bB' and can_background:
+ if os.fork() == 0:
+ # We aren't holding the repository names lock at this point, so
+ # it is safe to fork. But we are holding stuff like the branch
+ # locks that we don't want to release from the child.
+ execute(pack_operations, *args, **kwargs)
+ os._exit(0)
+ else:
+ return False
+ else:
+ trace.note('Unknown responsed: %r, repacking\n' % (char,))
+ return execute(pack_operations, *args, **kwargs)
+ self._execute_pack_operations = _ask_execute_pack_operations
+ try:
+ return orig_do_autopack(self)
+ finally:
+ self._execute_pack_operations = execute
+
+groupcompress_repo.GCRepositoryPackCollection._do_autopack = _trapped_autopack
More information about the bazaar-commits
mailing list