Rev 5002: Some cleanup. in file:///home/vila/src/bzr/reviews/update/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Feb 10 09:20:57 GMT 2010


At file:///home/vila/src/bzr/reviews/update/

------------------------------------------------------------
revno: 5002
revision-id: v.ladeuil+lp at free.fr-20100210092056-z7j27rei1si1v9l7
parent: gerard_ at gna.org-20100206222548-10cj2d0isjqf37lh
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: update
timestamp: Wed 2010-02-10 10:20:56 +0100
message:
  Some cleanup.
  
  * bzrlib/tests/blackbox/test_update.py:
  (TestUpdate.test_update_checkout_prevent_double_merge): Use full
  lines for changes to get a cleanly formatted conflicted file
  content.
  (TestUpdate.test_update_remove_commit): Add graph variable
  definitions from review.
  
  * bzrlib/tests/blackbox/test_commit.py:
  (TestCommit.test_commit_a_text_merge_in_a_checkout): Use full
  lines for changes to get a cleanly formatted conflicted file
  content.
  
  * bzrlib/workingtree.py:
  (WorkingTree._update_tree): Use 'nb_conflicts' instead of 'result'
  to clarify.
-------------- next part --------------
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2010-02-06 15:59:20 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2010-02-10 09:20:56 +0000
@@ -343,27 +343,29 @@
         trunk = self.make_branch_and_tree('trunk')
 
         u1 = trunk.branch.create_checkout('u1')
-        self.build_tree_contents([('u1/hosts', 'initial contents')])
+        self.build_tree_contents([('u1/hosts', 'initial contents\n')])
         u1.add('hosts')
         self.run_bzr('commit -m add-hosts u1')
 
         u2 = trunk.branch.create_checkout('u2')
-        self.build_tree_contents([('u2/hosts', 'altered in u2')])
+        self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
         self.run_bzr('commit -m checkin-from-u2 u2')
 
         # make an offline commits
-        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
+        self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
         self.run_bzr('commit -m checkin-offline --local u1')
 
         # now try to pull in online work from u2, and then commit our offline
         # work as a merge
         # retcode 1 as we expect a text conflict
         self.run_bzr('update u1', retcode=1)
-        self.assertFileEqual('<<<<<<< TREE\n'
-                             'first offline change in u1'
-                             '=======\n'
-                             'altered in u2'
-                             '>>>>>>> MERGE-SOURCE\n',
+        self.assertFileEqual('''\
+<<<<<<< TREE
+first offline change in u1
+=======
+altered in u2
+>>>>>>> MERGE-SOURCE
+''',
                              'u1/hosts')
 
         self.run_bzr('resolved u1/hosts')

=== modified file 'bzrlib/tests/blackbox/test_update.py'
--- a/bzrlib/tests/blackbox/test_update.py	2010-02-06 17:17:01 +0000
+++ b/bzrlib/tests/blackbox/test_update.py	2010-02-10 09:20:56 +0000
@@ -314,56 +314,68 @@
         """"Launchpad bug 113809 in bzr "update performs two merges"
         https://launchpad.net/bugs/113809"""
         master = self.make_branch_and_tree('master')
-        self.build_tree_contents([('master/file', 'initial contents')])
+        self.build_tree_contents([('master/file', 'initial contents\n')])
         master.add(['file'])
         master.commit('one', rev_id='m1')
 
         checkout = master.branch.create_checkout('checkout')
         lightweight = checkout.branch.create_checkout('lightweight',
                                                       lightweight=True)
-        
+
         # time to create a mess
         # add a commit to the master
-        self.build_tree_contents([('master/file', 'master')])
+        self.build_tree_contents([('master/file', 'master\n')])
         master.commit('two', rev_id='m2')
-        self.build_tree_contents([('master/file', 'master local changes')])
+        self.build_tree_contents([('master/file', 'master local changes\n')])
 
         # local commit on the checkout
-        self.build_tree_contents([('checkout/file', 'checkout')])
+        self.build_tree_contents([('checkout/file', 'checkout\n')])
         checkout.commit('tree', rev_id='c2', local=True)
-        self.build_tree_contents([('checkout/file', 'checkout local changes')])
+        self.build_tree_contents([('checkout/file',
+                                   'checkout local changes\n')])
 
         # lightweight 
         self.build_tree_contents([('lightweight/file',
-                                   'lightweight local changes')])
+                                   'lightweight local changes\n')])
 
         # now update (and get conflicts)
         out, err = self.run_bzr('update lightweight', retcode=1)
         self.assertEqual('', out)
-        self.assertFileEqual('<<<<<<< TREE\n'
-                             'lightweight local changes'
-                             '=======\n'
-                             'checkout'
-                             '>>>>>>> MERGE-SOURCE\n',
+        self.assertFileEqual('''\
+<<<<<<< TREE
+lightweight local changes
+=======
+checkout
+>>>>>>> MERGE-SOURCE
+''',
                              'lightweight/file')
-        
+
         # resolve it
         self.build_tree_contents([('lightweight/file',
-                                   'lightweight+checkout')])
-        self.run_bzr('resolved lightweight/file')
+                                   'lightweight+checkout\n')])
+        self.run_bzr('resolve lightweight/file')
 
         # check we get the second conflict
         out, err = self.run_bzr('update lightweight', retcode=1)
         self.assertEqual('', out)
-        self.assertFileEqual('<<<<<<< TREE\n'
-                             'lightweight+checkout'
-                             '=======\n'
-                             'master'
-                             '>>>>>>> MERGE-SOURCE\n',
+        self.assertFileEqual('''\
+<<<<<<< TREE
+lightweight+checkout
+=======
+master
+>>>>>>> MERGE-SOURCE
+''',
                              'lightweight/file')
 
     def test_update_remove_commit(self):
-        """Update should remove revisions when the branch has removed some commits
+        """Update should remove revisions when the branch has removed
+        some commits.
+
+        B: wt.branch.last_revision()
+        M: wt.branch.get_master_branch().last_revision()
+        W: wt.last_revision()
+
+
             1
             |\
           B-2 3
@@ -385,7 +397,7 @@
 
         And the changes in 4 have been removed from the WT.
         """
-        
+
         # building the picture
         M = self.make_branch_and_tree('M')
         self.build_tree_contents([('M/file1', '1')])
@@ -399,7 +411,7 @@
         self.build_tree_contents([('B/file4', '4')])
         B.add(['file4'])
         B.commit('four', rev_id='c4', local=True)
-        
+
         W = B.branch.create_checkout('W', lightweight=True)
         # move B back to 2
         B.pull(B.branch, local=True, stop_revision='c2', overwrite=True)
@@ -410,7 +422,7 @@
         self.build_tree_contents([('M/file5', '5')])
         M.add(['file5'])
         M.commit('five', rev_id='c5')
-        
+
         # now check if everything is as we expect it to be (test the test)
         # M has 1,3,5
         self.failUnlessExists('M/file1')

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2010-02-06 21:26:00 +0000
+++ b/bzrlib/workingtree.py	2010-02-10 09:20:56 +0000
@@ -2261,7 +2261,7 @@
         # We MUST save it even if an error occurs, because otherwise the users
         # local work is unreferenced and will appear to have been lost.
         #
-        result = 0
+        nb_conflicts = 0
         try:
             last_rev = self.get_parent_ids()[0]
         except IndexError:
@@ -2271,24 +2271,21 @@
         else:
             if revision not in self.branch.revision_history():
                 raise errors.NoSuchRevision(self.branch, revision)
-                
+
         old_tip = old_tip or _mod_revision.NULL_REVISION
-        
+
         if not _mod_revision.is_null(old_tip) and old_tip != last_rev:
             # the branch we are bound to was updated
             # merge those changes in first
             base_tree  = self.basis_tree()
             other_tree = self.branch.repository.revision_tree(old_tip)
-            result = merge.merge_inner(
-                                  self.branch,
-                                  other_tree,
-                                  base_tree,
-                                  this_tree=self,
-                                  change_reporter=change_reporter)
-            if result > 0:
+            nb_conflicts = merge.merge_inner(self.branch, other_tree,
+                                             base_tree, this_tree=self,
+                                             change_reporter=change_reporter)
+            if nb_conflicts:
                 self.add_parent_tree((old_tip, other_tree))
                 trace.note('Rerun update after fixing the conflicts.')
-                return result
+                return nb_conflicts
 
         if last_rev != _mod_revision.ensure_null(revision):
             # the working tree is up to date with the branch
@@ -2308,15 +2305,13 @@
 
             # determine the branch point
             graph = self.branch.repository.get_graph()
-            base_rev_id = graph.find_unique_lca(self.branch.last_revision(), last_rev)
+            base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
+                                                last_rev)
             base_tree = self.branch.repository.revision_tree(base_rev_id)
 
-            result = merge.merge_inner(
-                                  self.branch,
-                                  to_tree,
-                                  base_tree,
-                                  this_tree=self,
-                                  change_reporter=change_reporter)
+            nb_conflicts = merge.merge_inner(self.branch, to_tree, base_tree,
+                                             this_tree=self,
+                                             change_reporter=change_reporter)
             self.set_last_revision(revision)
             # TODO - dedup parents list with things merged by pull ?
             # reuse the tree we've updated to to set the basis:
@@ -2335,7 +2330,7 @@
                     (old_tip, self.branch.repository.revision_tree(old_tip)))
             self.set_parent_trees(parent_trees)
             last_rev = parent_trees[0][0]
-        return result
+        return nb_conflicts
 
     def _write_hashcache_if_dirty(self):
         """Write out the hashcache if it is dirty."""



More information about the bazaar-commits mailing list