Rev 3269: (Daniel Watkins) Add a --revision option to 'bzr push' in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Mar 12 23:08:44 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3269
revision-id:pqm at pqm.ubuntu.com-20080312230834-g76zjwkvyaxxjju9
parent: pqm at pqm.ubuntu.com-20080312213603-mtgxmfy3td5n04yh
parent: d.m.watkins at warwick.ac.uk-20080309184131-o0nvgaub7p85w4n0
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-03-12 23:08:34 +0000
message:
  (Daniel Watkins) Add a --revision option to 'bzr push'
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
    ------------------------------------------------------------
    revno: 3256.1.5
    revision-id:d.m.watkins at warwick.ac.uk-20080309184131-o0nvgaub7p85w4n0
    parent: d.m.watkins at warwick.ac.uk-20080309180836-y7wwg4o22e2tegjf
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: push-r
    timestamp: Sun 2008-03-09 18:41:31 +0000
    message:
      Added NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3256.1.4
    revision-id:d.m.watkins at warwick.ac.uk-20080309180836-y7wwg4o22e2tegjf
    parent: d.m.watkins at warwick.ac.uk-20080309180626-7573qp300ehbr8f9
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: push-r
    timestamp: Sun 2008-03-09 18:08:36 +0000
    message:
      Added test to ensure that passing a range of revisions errors.
    modified:
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
    ------------------------------------------------------------
    revno: 3256.1.3
    revision-id:d.m.watkins at warwick.ac.uk-20080309180626-7573qp300ehbr8f9
    parent: d.m.watkins at warwick.ac.uk-20080309175847-sse7dt9uzeomzxu3
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: push-r
    timestamp: Sun 2008-03-09 18:06:26 +0000
    message:
      Clarified test intent.
    modified:
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
    ------------------------------------------------------------
    revno: 3256.1.2
    revision-id:d.m.watkins at warwick.ac.uk-20080309175847-sse7dt9uzeomzxu3
    parent: d.m.watkins at warwick.ac.uk-20080309164111-9g0mg1wz0fjxdk08
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: push-r
    timestamp: Sun 2008-03-09 17:58:47 +0000
    message:
      Added revision argument to push.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 3256.1.1
    revision-id:d.m.watkins at warwick.ac.uk-20080309164111-9g0mg1wz0fjxdk08
    parent: pqm at pqm.ubuntu.com-20080307231150-h9ct4c51ekdiexbs
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: push-r
    timestamp: Sun 2008-03-09 16:41:11 +0000
    message:
      Added test for push with a revspec.
    modified:
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
=== modified file 'NEWS'
--- a/NEWS	2008-03-12 19:55:37 +0000
+++ b/NEWS	2008-03-12 23:08:34 +0000
@@ -49,6 +49,9 @@
    * Merge directives that are automatically attached to emails have nicer
      filenames, based on branch-nick + revno. (Aaron Bentley)
 
+   * ``push`` has a ``--revision`` option, to specify what revision to push up
+     to.  (Daniel Watkins)
+
   BUGFIXES:
 
     * Disable plink's interactive prompt for password.

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-03-10 23:39:45 +0000
+++ b/bzrlib/builtins.py	2008-03-12 23:08:34 +0000
@@ -687,7 +687,7 @@
     """
 
     _see_also = ['pull', 'update', 'working-trees']
-    takes_options = ['remember', 'overwrite', 'verbose',
+    takes_options = ['remember', 'overwrite', 'verbose', 'revision',
         Option('create-prefix',
                help='Create the path leading up to the branch '
                     'if it does not already exist.'),
@@ -707,7 +707,7 @@
     encoding_type = 'replace'
 
     def run(self, location=None, remember=False, overwrite=False,
-            create_prefix=False, verbose=False,
+            create_prefix=False, verbose=False, revision=None,
             use_existing_dir=False,
             directory=None):
         # FIXME: Way too big!  Put this into a function called from the
@@ -746,6 +746,16 @@
             else:
                 # Found a branch, so we must have found a repository
                 repository_to = br_to.repository
+
+        if revision is not None:
+            if len(revision) == 1:
+                revision_id = revision[0].in_history(br_from).rev_id
+            else:
+                raise errors.BzrCommandError(
+                    'bzr push --revision takes one value.')
+        else:
+            revision_id = br_from.last_revision()
+
         push_result = None
         if verbose:
             old_rh = []
@@ -786,7 +796,7 @@
             # directory. So we need to create it, along with any work to create
             # all of the dependent branches, etc.
             dir_to = br_from.bzrdir.clone_on_transport(to_transport,
-                revision_id=br_from.last_revision())
+                                                       revision_id=revision_id)
             br_to = dir_to.open_branch()
             # TODO: Some more useful message about what was copied
             note('Created new branch.')
@@ -804,10 +814,8 @@
         elif br_to is None:
             # We have a repository but no branch, copy the revisions, and then
             # create a branch.
-            last_revision_id = br_from.last_revision()
-            repository_to.fetch(br_from.repository,
-                                revision_id=last_revision_id)
-            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
+            repository_to.fetch(br_from.repository, revision_id=revision_id)
+            br_to = br_from.clone(dir_to, revision_id=revision_id)
             note('Created new branch.')
             if br_from.get_push_location() is None or remember:
                 br_from.set_push_location(br_to.base)
@@ -825,13 +833,16 @@
                     warning("This transport does not update the working " 
                             "tree of: %s. See 'bzr help working-trees' for "
                             "more information." % br_to.base)
-                    push_result = br_from.push(br_to, overwrite)
+                    push_result = br_from.push(br_to, overwrite,
+                                               stop_revision=revision_id)
                 except errors.NoWorkingTree:
-                    push_result = br_from.push(br_to, overwrite)
+                    push_result = br_from.push(br_to, overwrite,
+                                               stop_revision=revision_id)
                 else:
                     tree_to.lock_write()
                     try:
-                        push_result = br_from.push(tree_to.branch, overwrite)
+                        push_result = br_from.push(tree_to.branch, overwrite,
+                                                   stop_revision=revision_id)
                         tree_to.update()
                     finally:
                         tree_to.unlock()

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2007-12-05 02:18:52 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2008-03-09 18:08:36 +0000
@@ -248,6 +248,24 @@
                 'push ../dir',
                 working_dir='tree')
 
+    def test_push_with_revisionspec(self):
+        """We should be able to push a revision older than the tip."""
+        tree_from = self.make_branch_and_tree('from')
+        tree_from.commit("One.", rev_id="from-1")
+        tree_from.commit("Two.", rev_id="from-2")
+
+        self.run_bzr('push -r1 ../to', working_dir='from')
+
+        tree_to = WorkingTree.open('to')
+        repo_to = tree_to.branch.repository
+        self.assertTrue(repo_to.has_revision('from-1'))
+        self.assertFalse(repo_to.has_revision('from-2'))
+        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
+
+        self.run_bzr_error(
+            "bzr: ERROR: bzr push --revision takes one value.\n",
+            'push -r0..2 ../to', working_dir='from')
+
 
 class RedirectingMemoryTransport(MemoryTransport):
 




More information about the bazaar-commits mailing list