[Pkg-bazaar-commits] ./bzr/unstable r685: - add -r option to the branch command

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:20:42 UTC 2009


------------------------------------------------------------
revno: 685
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-06-15 13:43:04 +1000
message:
  - add -r option to the branch command
    patch from aaron
modified:
  bzrlib/branch.py
  bzrlib/commands.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-06-14 08:16:19 +0000
+++ b/bzrlib/branch.py	2005-06-15 03:43:04 +0000
@@ -110,6 +110,15 @@
         self.branch2 = branch2
         Exception.__init__(self, "These branches have diverged.")
 
+
+class NoSuchRevision(BzrError):
+    def __init__(self, branch, revision):
+        self.branch = branch
+        self.revision = revision
+        msg = "Branch %s has no revision %d" % (branch, revision)
+        BzrError.__init__(self, msg)
+
+
 ######################################################################
 # branch objects
 
@@ -671,7 +680,7 @@
             return None
 
 
-    def missing_revisions(self, other):
+    def missing_revisions(self, other, stop_revision=None):
         """
         If self and other have not diverged, return a list of the revisions
         present in other, but missing from self.
@@ -706,12 +715,16 @@
         if common_index >= 0 and \
             self_history[common_index] != other_history[common_index]:
             raise DivergedBranches(self, other)
-        if self_len < other_len:
-            return other_history[self_len:]
-        return []
-
-
-    def update_revisions(self, other):
+
+        if stop_revision is None:
+            stop_revision = other_len
+        elif stop_revision > other_len:
+            raise NoSuchRevision(self, stop_revision)
+        
+        return other_history[self_len:stop_revision]
+
+
+    def update_revisions(self, other, stop_revision=None):
         """Pull in all new revisions from other branch.
         
         >>> from bzrlib.commit import commit
@@ -739,7 +752,7 @@
         pb = ProgressBar()
 
         pb.update('comparing histories')
-        revision_ids = self.missing_revisions(other)
+        revision_ids = self.missing_revisions(other, stop_revision)
         revisions = []
         needed_texts = sets.Set()
         i = 0

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-06-15 03:37:27 +0000
+++ b/bzrlib/commands.py	2005-06-15 03:43:04 +0000
@@ -517,16 +517,20 @@
 class cmd_branch(Command):
     """Create a new copy of a branch.
 
-    If the TO_LOCATION is omitted, the last component of the
-    FROM_LOCATION will be used.  In other words,
-    "branch ../foo/bar" will attempt to create ./bar.
+    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
+    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
+
+    To retrieve the branch as of a particular revision, supply the --revision
+    parameter, as in "branch foo/bar -r 5".
     """
     takes_args = ['from_location', 'to_location?']
+    takes_options = ['revision']
 
-    def run(self, from_location, to_location=None):
+    def run(self, from_location, to_location=None, revision=None):
         import errno
         from bzrlib.merge import merge
-        from branch import find_branch, DivergedBranches
+        from branch import find_branch, DivergedBranches, NoSuchRevision
+        from shutil import rmtree
         try:
             br_from = find_branch(from_location)
         except OSError, e:
@@ -552,10 +556,16 @@
                 raise
         br_to = Branch(to_location, init=True)
 
-        from_location = pull_loc(br_from)
-        br_to.update_revisions(br_from)
+        try:
+            br_to.update_revisions(br_from, stop_revision=revision)
+        except NoSuchRevision:
+            rmtree(to_location)
+            msg = "The branch %s has no revision %d." % (from_location,
+                                                         revision)
+            raise BzrCommandError(msg)
         merge((to_location, -1), (to_location, 0), this_dir=to_location,
               check_clean=False)
+        from_location = pull_loc(br_from)
         br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
 



More information about the Pkg-bazaar-commits mailing list