Rev 5031: (vila) Don't add conflict related files unless explicitly required in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Feb 11 11:48:59 GMT 2010


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

------------------------------------------------------------
revno: 5031 [merge]
revision-id: pqm at pqm.ubuntu.com-20100211114855-owq7q18cogsdbbpc
parent: pqm at pqm.ubuntu.com-20100211100121-dqc7ja698m73k3tu
parent: v.ladeuil+lp at free.fr-20100211105311-pzvxx1w00bsaldmg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-02-11 11:48:55 +0000
message:
  (vila) Don't add conflict related files unless explicitly required
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/conflicts.py            conflicts.py-20051001061850-78ef952ba63d2b42
  bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
  bzrlib/tests/per_workingtree/test_smart_add.py test_smart_add.py-20070215175752-9s5mxoz8aqpd80fm-1
=== modified file 'NEWS'
--- a/NEWS	2010-02-11 09:27:55 +0000
+++ b/NEWS	2010-02-11 11:48:55 +0000
@@ -56,6 +56,9 @@
 * Avoid ``malloc(0)`` in ``patiencediff``, which is non-portable.
   (Martin Pool, #331095)
 
+* ``bzr add`` will not add conflict related files unless explicitly required.
+  (Vincent Ladeuil, #322767, #414589)
+
 * Network transfer amounts and rates are now displayed in SI units according
   to the Ubuntu Units Policy <https://wiki.ubuntu.com/UnitsPolicy>.
   (Gordon Tyler, #514399)

=== modified file 'bzrlib/conflicts.py'
--- a/bzrlib/conflicts.py	2010-02-10 17:52:08 +0000
+++ b/bzrlib/conflicts.py	2010-02-11 09:51:03 +0000
@@ -412,8 +412,17 @@
             raise NotImplementedError(self.__class__.__name__ + '.' + action)
         meth(tree)
 
+    def associated_filenames(self):
+        """The names of the files generated to help resolve the conflict."""
+        raise NotImplementedError(self.associated_filenames)
+
     def cleanup(self, tree):
-        raise NotImplementedError(self.cleanup)
+        for fname in self.associated_filenames():
+            try:
+                osutils.delete_any(tree.abspath(fname))
+            except OSError, e:
+                if e.errno != errno.ENOENT:
+                    raise
 
     def action_done(self, tree):
         """Mark the conflict as solved once it has been handled."""
@@ -446,9 +455,9 @@
             s.add('conflict_path', self.conflict_path)
         return s
 
-    def cleanup(self, tree):
+    def associated_filenames(self):
         # No additional files have been generated here
-        pass
+        return []
 
     def action_take_this(self, tree):
         tree.rename_one(self.conflict_path, self.path)
@@ -467,13 +476,8 @@
 
     format = 'Contents conflict in %(path)s'
 
-    def cleanup(self, tree):
-        for suffix in ('.BASE', '.OTHER'):
-            try:
-                osutils.delete_any(tree.abspath(self.path + suffix))
-            except OSError, e:
-                if e.errno != errno.ENOENT:
-                    raise
+    def associated_filenames(self):
+        return [self.path + suffix for suffix in ('.BASE', '.OTHER')]
 
     # FIXME: I smell something weird here and it seems we should be able to be
     # more coherent with some other conflict ? bzr *did* a choice there but
@@ -501,13 +505,8 @@
 
     format = 'Text conflict in %(path)s'
 
-    def cleanup(self, tree):
-        for suffix in CONFLICT_SUFFIXES:
-            try:
-                osutils.delete_any(tree.abspath(self.path+suffix))
-            except OSError, e:
-                if e.errno != errno.ENOENT:
-                    raise
+    def associated_filenames(self):
+        return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
 
 
 class HandledConflict(Conflict):
@@ -529,9 +528,9 @@
         s.add('action', self.action)
         return s
 
-    def cleanup(self, tree):
-        """Nothing to cleanup."""
-        pass
+    def associated_filenames(self):
+        # Nothing has been generated here
+        return []
 
 
 class HandledPathConflict(HandledConflict):

=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py	2009-10-06 14:40:37 +0000
+++ b/bzrlib/mutabletree.py	2010-02-10 16:41:09 +0000
@@ -380,6 +380,8 @@
 
         if not file_list:
             # no paths supplied: add the entire tree.
+            # FIXME: this assumes we are running in a working tree subdir :-/
+            # -- vila 20100208
             file_list = [u'.']
         # mutter("smart add of %r")
         inv = self.inventory
@@ -387,6 +389,14 @@
         ignored = {}
         dirs_to_add = []
         user_dirs = set()
+        conflicts_related = set()
+        # Not all mutable trees can have conflicts
+        if getattr(self, 'conflicts', None) is not None:
+            # Collect all related files without checking whether they exist or
+            # are versioned. It's cheaper to do that once for all conflicts
+            # than trying to find the relevant conflict for each added file.
+            for c in self.conflicts():
+                conflicts_related.update(c.associated_filenames())
 
         # validate user file paths and convert all paths to tree
         # relative : it's cheaper to make a tree relative path an abspath
@@ -453,6 +463,13 @@
             if illegalpath_re.search(directory.raw_path):
                 trace.warning("skipping %r (contains \\n or \\r)" % abspath)
                 continue
+            if directory.raw_path in conflicts_related:
+                # If the file looks like one generated for a conflict, don't
+                # add it.
+                trace.warning(
+                    'skipping %s (generated to help resolve conflicts)',
+                    abspath)
+                continue
 
             if parent_ie is not None:
                 versioned = directory.base_path in parent_ie.children

=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
--- a/bzrlib/tests/per_workingtree/test_smart_add.py	2010-02-10 17:52:08 +0000
+++ b/bzrlib/tests/per_workingtree/test_smart_add.py	2010-02-11 10:53:11 +0000
@@ -227,6 +227,36 @@
                                 in wt.inventory.iter_entries()])
 
 
+class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
+
+    def make_tree_with_text_conflict(self):
+        tb = self.make_branch_and_tree('base')
+        self.build_tree_contents([('base/file', 'content in base')])
+        tb.add('file')
+        tb.commit('Adding file')
+
+        t1 = tb.bzrdir.sprout('t1').open_workingtree()
+
+        self.build_tree_contents([('base/file', 'content changed in base')])
+        tb.commit('Changing file in base')
+
+        self.build_tree_contents([('t1/file', 'content in t1')])
+        t1.commit('Changing file in t1')
+        t1.merge_from_branch(tb.branch)
+        return t1
+
+    def test_cant_add_generated_files_implicitly(self):
+        t = self.make_tree_with_text_conflict()
+        added, ignored = t.smart_add([t.basedir])
+        self.assertEqual(([], {}), (added, ignored))
+
+    def test_can_add_generated_files_explicitly(self):
+        fnames = ['file.%s' % s  for s in ('BASE', 'THIS', 'OTHER')]
+        t = self.make_tree_with_text_conflict()
+        added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
+        self.assertEqual((fnames, {}), (added, ignored))
+
+
 class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
 
     _test_needs_features = [tests.UnicodeFilenameFeature]
@@ -239,7 +269,14 @@
 
     def test_accessible_explicit(self):
         osutils.normalized_filename = osutils._accessible_normalized_filename
-        self.wt.smart_add([u'a\u030a'])
+        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
+            self.expectFailure(
+                'With WorkingTreeFormat2, smart_add requires'
+                ' normalized unicode filenames',
+                self.assertRaises, errors.NoSuchFile,
+                self.wt.smart_add, [u'a\u030a'])
+        else:
+            self.wt.smart_add([u'a\u030a'])
         self.wt.lock_read()
         self.addCleanup(self.wt.unlock)
         self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
@@ -248,12 +285,19 @@
 
     def test_accessible_implicit(self):
         osutils.normalized_filename = osutils._accessible_normalized_filename
-        self.wt.smart_add([])
+        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
+            self.expectFailure(
+                'With WorkingTreeFormat2, smart_add requires'
+                ' normalized unicode filenames',
+                self.assertRaises, errors.NoSuchFile,
+                self.wt.smart_add, [])
+        else:
+            self.wt.smart_add([])
         self.wt.lock_read()
         self.addCleanup(self.wt.unlock)
         self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
-                         [(path, ie.kind) for path,ie in
-                          self.wt.inventory.iter_entries()])
+                         [(path, ie.kind) for path,ie
+                          in self.wt.inventory.iter_entries()])
 
     def test_inaccessible_explicit(self):
         osutils.normalized_filename = osutils._inaccessible_normalized_filename




More information about the bazaar-commits mailing list