Rev 2365: Create a helper tree which has a semi-interesting history. in http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/log_ancestry

John Arbash Meinel john at arbash-meinel.com
Wed Apr 18 23:15:10 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/log_ancestry

------------------------------------------------------------
revno: 2365
revision-id: john at arbash-meinel.com-20070418221454-zkozu1yyny4zx3rv
parent: john at arbash-meinel.com-20070418215032-38i9ynsx6fkqaiyf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: log_ancestry
timestamp: Wed 2007-04-18 17:14:54 -0500
message:
  Create a helper tree which has a semi-interesting history.
  This allows us to test which files are actually modified.
modified:
  bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
-------------- next part --------------
=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2006-11-03 18:35:29 +0000
+++ b/bzrlib/tests/test_log.py	2007-04-18 22:14:54 +0000
@@ -1,6 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
-# -*- coding: utf-8 -*-
-# vim: encoding=utf-8
+# Copyright (C) 2005, 2006, 2007 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
@@ -400,3 +398,102 @@
         self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
             ('4b', '4', 0)],
             revisions)
+
+
+class TestGetRevisionsTouchingFileID(TestCaseWithTransport):
+
+    def create_tree_with_single_merge(self):
+        """Create a branch with a moderate layout.
+
+        The revision graph looks like:
+
+           A
+           |\
+           B C
+           |/
+           D
+
+        In this graph, A introduced files f1 and f2 and f3.
+        B modifies f1 and f3, and C modifies f2 and f3.
+        D merges the changes from B and C and resolves the conflict for f3.
+        """
+        # TODO: jam 20070218 This seems like it could really be done
+        #       with make_branch_and_memory_tree() if we could just
+        #       create the content of those files.
+        # TODO: jam 20070218 Another alternative is that we would really
+        #       like to only create this tree 1 time for all tests that
+        #       use it. Since 'log' only uses the tree in a readonly
+        #       fashion, it seems a shame to regenerate an identical
+        #       tree for each test.
+        tree = self.make_branch_and_tree('tree')
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+
+        self.build_tree_contents([('tree/f1', 'A\n'),
+                                  ('tree/f2', 'A\n'),
+                                  ('tree/f3', 'A\n'),
+                                 ])
+        tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
+        tree.commit('A', rev_id='A')
+
+        self.build_tree_contents([('tree/f2', 'A\nC\n'),
+                                  ('tree/f3', 'A\nC\n'),
+                                 ])
+        tree.commit('C', rev_id='C')
+        # Revert back to A to build the other history.
+        tree.set_last_revision('A')
+        tree.branch.set_last_revision_info(1, 'A')
+        self.build_tree_contents([('tree/f1', 'A\nB\n'),
+                                  ('tree/f2', 'A\n'),
+                                  ('tree/f3', 'A\nB\n'),
+                                 ])
+        tree.commit('B', rev_id='B')
+        tree.set_parent_ids(['B', 'C'])
+        self.build_tree_contents([('tree/f1', 'A\nB\n'),
+                                  ('tree/f2', 'A\nC\n'),
+                                  ('tree/f3', 'A\nB\nC\n'),
+                                 ])
+        tree.commit('D', rev_id='D')
+
+        # Switch to a read lock for this tree.
+        # We still have addCleanup(unlock)
+        tree.unlock()
+        tree.lock_read()
+        return tree
+
+    def test_tree_with_single_merge(self):
+        """Make sure the tree layout is correct."""
+        tree = self.create_tree_with_single_merge()
+        rev_A_tree = tree.branch.repository.revision_tree('A')
+        rev_B_tree = tree.branch.repository.revision_tree('B')
+
+        f1_changed = (u'f1', 'f1-id', 'file', True, False)
+        f2_changed = (u'f2', 'f2-id', 'file', True, False)
+        f3_changed = (u'f3', 'f3-id', 'file', True, False)
+
+        delta = rev_B_tree.changes_from(rev_A_tree)
+        self.assertEqual([f1_changed, f3_changed], delta.modified)
+        self.assertEqual([], delta.renamed)
+        self.assertEqual([], delta.added)
+        self.assertEqual([], delta.removed)
+
+        rev_C_tree = tree.branch.repository.revision_tree('C')
+        delta = rev_C_tree.changes_from(rev_A_tree)
+        self.assertEqual([f2_changed, f3_changed], delta.modified)
+        self.assertEqual([], delta.renamed)
+        self.assertEqual([], delta.added)
+        self.assertEqual([], delta.removed)
+
+        rev_D_tree = tree.branch.repository.revision_tree('D')
+        delta = rev_D_tree.changes_from(rev_B_tree)
+        self.assertEqual([f2_changed, f3_changed], delta.modified)
+        self.assertEqual([], delta.renamed)
+        self.assertEqual([], delta.added)
+        self.assertEqual([], delta.removed)
+
+        delta = rev_D_tree.changes_from(rev_C_tree)
+        self.assertEqual([f1_changed, f3_changed], delta.modified)
+        self.assertEqual([], delta.renamed)
+        self.assertEqual([], delta.added)
+        self.assertEqual([], delta.removed)
+



More information about the bazaar-commits mailing list