Rev 4807: (vila) Fix typo and tests for per-file merge hook in file:///home/pqm/archives/thelove/bzr/2.1/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Feb 2 12:01:17 GMT 2010


At file:///home/pqm/archives/thelove/bzr/2.1/

------------------------------------------------------------
revno: 4807 [merge]
revision-id: pqm at pqm.ubuntu.com-20100202120116-9f3yguzuwqgc35gd
parent: pqm at pqm.ubuntu.com-20100130093410-xyutv8mobva3juuo
parent: v.ladeuil+lp at free.fr-20100202084806-knoe10w8pwsx5l46
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.1
timestamp: Tue 2010-02-02 12:01:16 +0000
message:
  (vila) Fix typo and tests for per-file merge hook
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
  bzrlib/tests/test_merge_core.py test_merge_core.py-20050824132511-eb99b23a0eec641b
=== modified file 'NEWS'
--- a/NEWS	2010-01-30 09:01:03 +0000
+++ b/NEWS	2010-02-02 08:36:12 +0000
@@ -26,6 +26,9 @@
   increase memory pressure on processes using threads.
   (Robert Collins, John Arbash Meinel, #514090)
 
+* The new ``merge_file_content`` should now be ok with tests to avoid
+  regressions.
+  (Vincent Ladeuil, #515597)
 
 bzr 2.1.0rc2
 ############

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2010-01-28 18:05:44 +0000
+++ b/bzrlib/merge.py	2010-02-01 17:29:44 +0000
@@ -99,9 +99,14 @@
     This is a base class for concrete custom file merging logic. Concrete
     classes should implement ``merge_text``.
 
+    See ``bzrlib.plugins.news_merge.news_merge`` for an example concrete class.
+    
     :ivar affected_files: The configured file paths to merge.
+
     :cvar name_prefix: The prefix to use when looking up configuration
-        details.
+        details. <name_prefix>_merge_files describes the files targeted by the
+        hook for example.
+        
     :cvar default_files: The default file paths to merge when no configuration
         is present.
     """
@@ -118,6 +123,11 @@
             raise ValueError("name_prefix must be set.")
 
     def filename_matches_config(self, params):
+        """Check whether the file should call the merge hook.
+
+        <name_prefix>_merge_files configuration variable is a list of files
+        that should use the hook.
+        """
         affected_files = self.affected_files
         if affected_files is None:
             config = self.merger.this_tree.branch.get_config()
@@ -150,7 +160,7 @@
             # option.
             not self.filename_matches_config(params)):
             return 'not_applicable', None
-        return self.merge_text(self, params)
+        return self.merge_text(params)
 
     def merge_text(self, params):
         """Merge the byte contents of a single file.

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-01-20 16:31:24 +0000
+++ b/bzrlib/tests/__init__.py	2010-02-02 08:36:12 +0000
@@ -921,7 +921,7 @@
             self._lock_check_thorough = False
         else:
             self._lock_check_thorough = True
-            
+
         self.addCleanup(self._check_locks)
         _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
                                                 self._lock_acquired, None)

=== modified file 'bzrlib/tests/test_merge.py'
--- a/bzrlib/tests/test_merge.py	2010-01-28 18:05:44 +0000
+++ b/bzrlib/tests/test_merge.py	2010-02-02 08:36:12 +0000
@@ -2841,24 +2841,81 @@
 
 class TestConfigurableFileMerger(tests.TestCaseWithTransport):
 
-    def test_affected_files_cached(self):
-        """Ensures that the config variable is cached"""
-        class SimplePlan(_mod_merge.ConfigurableFileMerger):
+    def setUp(self):
+        super(TestConfigurableFileMerger, self).setUp()
+        self.calls = []
+
+    def get_merger_factory(self):
+        # Allows  the inner methods to access the test attributes
+        test = self
+
+        class FooMerger(_mod_merge.ConfigurableFileMerger):
             name_prefix = "foo"
-            default_files = ["my default"]
+            default_files = ['bar']
+
             def merge_text(self, params):
-                return ('not applicable', None)
+                test.calls.append('merge_text')
+                return ('not_applicable', None)
+
         def factory(merger):
-            result = SimplePlan(merger)
+            result = FooMerger(merger)
+            # Make sure we start with a clean slate
             self.assertEqual(None, result.affected_files)
+            # Track the original merger
             self.merger = result
             return result
+
+        return factory
+
+    def _install_hook(self, factory):
         _mod_merge.Merger.hooks.install_named_hook('merge_file_content',
-            factory, 'test factory')
+                                                   factory, 'test factory')
+
+    def make_builder(self):
         builder = test_merge_core.MergeBuilder(self.test_base_dir)
         self.addCleanup(builder.cleanup)
-        builder.add_file('NEWS', builder.tree_root, 'name1', 'text1', True)
-        builder.change_contents('NEWS', other='text4', this='text3')
+        return builder
+
+    def make_text_conflict(self, file_name='bar'):
+        factory = self.get_merger_factory()
+        self._install_hook(factory)
+        builder = self.make_builder()
+        builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
+        builder.change_contents('bar-id', other='text4', this='text3')
+        return builder
+
+    def make_kind_change(self):
+        factory = self.get_merger_factory()
+        self._install_hook(factory)
+        builder = self.make_builder()
+        builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
+                         this=False)
+        builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
+                        base=False, other=False)
+        return builder
+
+    def test_affected_files_cached(self):
+        """Ensures that the config variable is cached"""
+        builder = self.make_text_conflict()
         conflicts = builder.merge()
         # The hook should set the variable
-        self.assertEqual(["my default"], self.merger.affected_files)
+        self.assertEqual(['bar'], self.merger.affected_files)
+        self.assertEqual(1, len(conflicts))
+
+    def test_hook_called_for_text_conflicts(self):
+        builder = self.make_text_conflict()
+        conflicts = builder.merge()
+        # The hook should call the merge_text() method
+        self.assertEqual(['merge_text'], self.calls)
+
+    def test_hook_not_called_for_kind_change(self):
+        builder = self.make_kind_change()
+        conflicts = builder.merge()
+        # The hook should not call the merge_text() method
+        self.assertEqual([], self.calls)
+
+    def test_hook_not_called_for_other_files(self):
+        builder = self.make_text_conflict('foobar')
+        conflicts = builder.merge()
+        # The hook should not call the merge_text() method
+        self.assertEqual([], self.calls)

=== modified file 'bzrlib/tests/test_merge_core.py'
--- a/bzrlib/tests/test_merge_core.py	2010-01-15 03:58:20 +0000
+++ b/bzrlib/tests/test_merge_core.py	2010-02-02 08:36:12 +0000
@@ -114,10 +114,11 @@
                 tt.cancel_versioning(trans_id)
                 tt.set_executability(None, trans_id)
 
-    def add_dir(self, file_id, parent, name):
-        for tt in self.list_transforms():
-            parent_id = tt.trans_id_file_id(parent)
-            tt.new_directory(name, parent_id, file_id)
+    def add_dir(self, file_id, parent, name, this=True, base=True, other=True):
+        for option, tt in self.selected_transforms(this, base, other):
+            if option is True:
+                parent_id = tt.trans_id_file_id(parent)
+                tt.new_directory(name, parent_id, file_id)
 
     def change_name(self, id, base=None, this=None, other=None):
         for val, tt in ((base, self.base_tt), (this, self.this_tt),




More information about the bazaar-commits mailing list