[MERGE] Add optional location to ancestry and fix behaviour for checkouts.

Michael Ellerman michael at ellerman.id.au
Wed May 31 09:50:05 BST 2006


Hi ya'll,

I've added support for location to ancestry, and also changed the
behaviour as per the FIXME that was there.

Add optional location to ancestry and fix behaviour for checkouts.

This adds an optional location parameter to the ancestry command. It
also changes the behaviour of ancestry on checkouts such that if they
have been created with a subset of the branch history, only the subset
is shown by 'bzr ancestry'. Tests for all of that as well.

At: http://michael.ellerman.id.au/bzr/branches/mpe/

cheers

=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py	
+++ bzrlib/builtins.py	
@@ -880,13 +880,21 @@
 
 class cmd_ancestry(Command):
     """List all revisions merged into this branch."""
+    takes_args = ['location?']
+
     hidden = True
     @display_command
-    def run(self):
-        tree = WorkingTree.open_containing(u'.')[0]
-        b = tree.branch
-        # FIXME. should be tree.last_revision
-        revision_ids = b.repository.get_ancestry(b.last_revision())
+    def run(self, location="."):
+        try:
+            wt = WorkingTree.open_containing(location)[0]
+        except errors.NoWorkingTree:
+            b = Branch.open(location)
+            last_revision = b.last_revision()
+        else:
+            b = wt.branch
+            last_revision = wt.last_revision()
+
+        revision_ids = b.repository.get_ancestry(last_revision)
         assert revision_ids[0] == None
         revision_ids.pop(0)
         for revision_id in revision_ids:

=== modified file 'bzrlib/tests/blackbox/test_ancestry.py'
--- bzrlib/tests/blackbox/test_ancestry.py	
+++ bzrlib/tests/blackbox/test_ancestry.py	
@@ -19,12 +19,12 @@
 from bzrlib.builtins import merge
 from bzrlib.tests import TestCaseWithTransport
 from bzrlib.workingtree import WorkingTree
+from bzrlib.branch import Branch
 
 
 class TestAncestry(TestCaseWithTransport):
 
-    def test_ancestry(self):
-        """Tests 'ancestry' command"""
+    def _build_branches(self):
         a_wt = self.make_branch_and_tree('A')
         open('A/foo', 'wb').write('1111\n')
         a_wt.add('foo')
@@ -37,13 +37,65 @@
         a_wt.commit('modified A/foo',rev_id='A2')
         merge(['B',-1],['B',1],this_dir='A')
         a_wt.commit('merged B into A',rev_id='A3')
+
+    def _check_ancestry(self, location='', result=None):
+        out = self.capture('ancestry ' + location)
+        if result is None:
+            result = "A1\nB1\nA2\nA3\n"
+        self.assertEqualDiff(out, result)
+
+    def test_ancestry(self):
+        """Tests 'ancestry' command"""
+        self._build_branches()
         os.chdir('A')
-        out, err = self.run_bzr('ancestry')
-        self.assertEquals(err, '')
-        self.assertEqualDiff(out,
-"""A1
-B1
-A2
-A3
-""")
-
+        self._check_ancestry()
+
+    def test_ancestry_with_location(self):
+        """Tests 'ancestry' command with a specified location."""
+        self._build_branches()
+        self._check_ancestry('A')
+
+    def test_ancestry_with_repo_branch(self):
+        """Tests 'ancestry' command with a location that is a
+        repository branch."""
+        self._build_branches()
+        self.run_bzr('init-repo', 'repo')
+        self.run_bzr('branch', 'A', 'repo/A')
+        self._check_ancestry('repo/A')
+
+    def test_ancestry_with_checkout(self):
+        """Tests 'ancestry' command with a location that is a
+        checkout of a repository branch."""
+        self._build_branches()
+        self.run_bzr('init-repo', 'repo')
+        self.run_bzr('branch', 'A', 'repo/A')
+        self.run_bzr('checkout', 'repo/A', 'A-checkout')
+        self._check_ancestry('A-checkout')
+
+    def test_ancestry_with_lightweight_checkout(self):
+        """Tests 'ancestry' command with a location that is a
+        lightweight checkout of a repository branch."""
+        self._build_branches()
+        self.run_bzr('init-repo', 'repo')
+        self.run_bzr('branch', 'A', 'repo/A')
+        self.run_bzr('checkout', '--lightweight', 'repo/A', 'A-checkout')
+        self._check_ancestry('A-checkout')
+
+    def test_ancestry_with_truncated_checkout(self):
+        """Tests 'ancestry' command with a location that is a
+        checkout of a repository branch with a shortened revision history."""
+        self._build_branches()
+        self.run_bzr('init-repo', 'repo')
+        self.run_bzr('branch', 'A', 'repo/A')
+        self.run_bzr('checkout', '-r', '2', 'repo/A', 'A-checkout')
+        self._check_ancestry('A-checkout', "A1\nA2\n")
+
+    def test_ancestry_with_truncated_lightweight_checkout(self):
+        """Tests 'ancestry' command with a location that is a lightweight
+        checkout of a repository branch with a shortened revision history."""
+        self._build_branches()
+        self.run_bzr('init-repo', 'repo')
+        self.run_bzr('branch', 'A', 'repo/A')
+        self.run_bzr('checkout', '-r', '2', '--lightweight',
+                'repo/A', 'A-checkout')
+        self._check_ancestry('A-checkout', "A1\nA2\n")



-- 
Michael Ellerman
IBM OzLabs

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060531/f9edca38/attachment.pgp 


More information about the bazaar mailing list