Rev 4497: Use tree.has_changes() where appropriate. in file:///home/vila/src/bzr/experimental/cleanup-strict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Jun 29 19:02:10 BST 2009


At file:///home/vila/src/bzr/experimental/cleanup-strict/

------------------------------------------------------------
revno: 4497
revision-id: v.ladeuil+lp at free.fr-20090629180209-a3xjmjo21qf6uw3r
parent: v.ladeuil+lp at free.fr-20090629162513-57jd3ni3ekqgd8ep
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: cleanup-strict
timestamp: Mon 2009-06-29 20:02:09 +0200
message:
  Use tree.has_changes() where appropriate.
  
  The test suite caught the has_changes() bug in an impressive number of tests.
  
  * bzrlib/tree.py:
  (Tree.has_changes): Exclude tree root.
  
  * bzrlib/send.py:
  (send): Use tree.has_changes() instead of tree.changes_from().
  
  * bzrlib/reconfigure.py:
  (Reconfigure._check): Use tree.has_changes() instead of
  tree.changes_from().
  
  * bzrlib/merge.py:
  (Merger.ensure_revision_trees, Merger.compare_basis): Use
  tree.has_changes() instead of tree.changes_from().
  
  * bzrlib/builtins.py:
  (cmd_remove_tree.run, cmd_push.run, cmd_merge.run): Use
  tree.has_changes() instead of tree.changes_from().
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-06-29 14:32:00 +0000
+++ b/bzrlib/builtins.py	2009-06-29 18:02:09 +0000
@@ -450,18 +450,18 @@
         except errors.NoWorkingTree:
             raise errors.BzrCommandError("No working tree to remove")
         except errors.NotLocalUrl:
-            raise errors.BzrCommandError("You cannot remove the working tree of a "
-                                         "remote path")
+            raise errors.BzrCommandError("You cannot remove the working tree"
+                                         " of a remote path")
         if not force:
-            changes = working.changes_from(working.basis_tree())
-            if changes.has_changed():
+            # XXX: What about pending merges ? -- vila 20090629
+            if working.has_changes(working.basis_tree()):
                 raise errors.UncommittedChanges(working)
 
         working_path = working.bzrdir.root_transport.base
         branch_path = working.branch.bzrdir.root_transport.base
         if working_path != branch_path:
-            raise errors.BzrCommandError("You cannot remove the working tree from "
-                                         "a lightweight checkout")
+            raise errors.BzrCommandError("You cannot remove the working tree"
+                                         " from a lightweight checkout")
 
         d.destroy_workingtree()
 
@@ -1054,11 +1054,11 @@
             revision_id = revision.in_history(br_from).rev_id
         else:
             revision_id = None
-        if (tree is not None and revision_id is None
-            and (strict is None or strict)): # Default to True:
-            changes = tree.changes_from(tree.basis_tree())
-            if changes.has_changed() or len(tree.get_parent_ids()) > 1:
-                raise errors.UncommittedChanges(tree)
+        if strict is None: strict = True # default value
+        if (strict and revision_id is None and tree is not None
+            and (tree.has_changes(tree.basis_tree())
+                 or len(tree.get_parent_ids()) > 1)):
+            raise errors.UncommittedChanges(tree)
 
         # Get the stacked_on branch, if any
         if stacked_on is not None:
@@ -3562,8 +3562,7 @@
         except errors.NoSuchRevision:
             basis_tree = tree.basis_tree()
         if not force:
-            changes = tree.changes_from(basis_tree)
-            if changes.has_changed():
+            if tree.has_changes(basis_tree):
                 raise errors.UncommittedChanges(tree)
 
         view_info = _get_view_info_for_change_reporter(tree)

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2009-04-14 15:02:46 +0000
+++ b/bzrlib/merge.py	2009-06-29 18:02:09 +0000
@@ -243,8 +243,7 @@
 
         if self.other_rev_id is None:
             other_basis_tree = self.revision_tree(self.other_basis)
-            changes = other_basis_tree.changes_from(self.other_tree)
-            if changes.has_changed():
+            if other_basis_tree.has_changes(self.other_tree):
                 raise WorkingTreeNotRevision(self.this_tree)
             other_rev_id = self.other_basis
             self.other_tree = other_basis_tree
@@ -276,8 +275,7 @@
             basis_tree = self.revision_tree(self.this_tree.last_revision())
         except errors.NoSuchRevision:
             basis_tree = self.this_tree.basis_tree()
-        changes = self.this_tree.changes_from(basis_tree)
-        if not changes.has_changed():
+        if not self.this_tree.has_changes(basis_tree):
             self.this_rev_id = self.this_basis
 
     def set_interesting_files(self, file_list):

=== modified file 'bzrlib/reconfigure.py'
--- a/bzrlib/reconfigure.py	2009-05-07 05:08:46 +0000
+++ b/bzrlib/reconfigure.py	2009-06-29 18:02:09 +0000
@@ -217,8 +217,8 @@
     def _check(self):
         """Raise if reconfiguration would destroy local changes"""
         if self._destroy_tree:
-            changes = self.tree.changes_from(self.tree.basis_tree())
-            if changes.has_changed():
+            # XXX: What about pending merges ? -- vila 20090629
+            if self.tree.has_changes(self.tree.basis_tree()):
                 raise errors.UncommittedChanges(self.tree)
         if self._create_reference and self.local_branch is not None:
             reference_branch = branch.Branch.open(self._select_bind_location())

=== modified file 'bzrlib/send.py'
--- a/bzrlib/send.py	2009-06-29 14:32:00 +0000
+++ b/bzrlib/send.py	2009-06-29 18:02:09 +0000
@@ -110,17 +110,18 @@
             if strict is None:
                 strict = branch.get_config(
                     ).get_user_option_as_bool('send_strict')
-            if strict is None or strict: # Default to True
-                changes = tree.changes_from(tree.basis_tree())
-                if changes.has_changed() or len(tree.get_parent_ids()) > 1:
-                    raise errors.UncommittedChanges(tree)
+            if strict is None: strict = True # default value
+            if (strict and tree is not None
+                and (tree.has_changes(tree.basis_tree())
+                     or len(tree.get_parent_ids()) > 1)):
+                raise errors.UncommittedChanges(tree)
             revision_id = branch.last_revision()
         if revision_id == NULL_REVISION:
             raise errors.BzrCommandError('No revisions to submit.')
         if format is None:
             # TODO: Query submit branch for its preferred format
             format = format_registry.get()
-        directive = format(branch, revision_id, submit_branch, 
+        directive = format(branch, revision_id, submit_branch,
             public_branch, no_patch, no_bundle, message, base_revision_id)
         if output is None:
             directive.compose_merge_request(mail_client, mail_to, body,

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2009-06-29 16:25:13 +0000
+++ b/bzrlib/tree.py	2009-06-29 18:02:09 +0000
@@ -105,13 +105,18 @@
             extra_trees, require_versioned, want_unversioned=want_unversioned)
 
 
+    @needs_read_lock
     def has_changes(self, from_tree):
         """Quickly check that the tree contains at least one change.
 
         :return: True if a change is found. False otherwise
         """
+        changes = self.iter_changes(from_tree)
         try:
-            self.iter_changes(from_tree).next()
+            change = changes.next()
+            # Exclude root (talk about black magic... --vila 20090629)
+            if change[4] == (None, None):
+                change = changes.next()
             return True
         except StopIteration:
             # No changes



More information about the bazaar-commits mailing list