Rev 2949: Prefer tree.get_root_id() as more explicit than tree.path2id('') in http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/tree_root_id

John Arbash Meinel john at arbash-meinel.com
Fri Oct 26 20:19:29 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/tree_root_id

------------------------------------------------------------
revno: 2949
revision-id:john at arbash-meinel.com-20071026191848-kn2zemp87fo5cavb
parent: john at arbash-meinel.com-20071026191529-st3fn58l61g24017
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: tree_root_id
timestamp: Fri 2007-10-26 14:18:48 -0500
message:
  Prefer tree.get_root_id() as more explicit than tree.path2id('')
  Besides, it turns out that all trees had that implemented anyway.
  And WT4 already had an implementation that did not require loading the full inventory.
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/tests/repository_implementations/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
  bzrlib/tests/repository_implementations/test_fetch.py test_fetch.py-20070814052151-5cxha9slx4c93uog-1
  bzrlib/tests/repository_implementations/test_fileid_involved.py test_file_involved.py-20051215205901-728a172d1014daaa
  bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
  bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
  bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
  bzrlib/tests/workingtree_implementations/test_unversion.py test_unversion.py-20060907074408-bygh2y28jz8u0cg7-1
  bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
  bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/branch.py	2007-10-26 19:18:48 +0000
@@ -1308,7 +1308,7 @@
     def get_root_id(self):
         """See Branch.get_root_id."""
         tree = self.repository.revision_tree(self.last_revision())
-        return tree.path2id('')
+        return tree.get_root_id()
 
     def is_locked(self):
         return self.control_files.is_locked()

=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/fetch.py	2007-10-26 19:18:48 +0000
@@ -347,7 +347,7 @@
         to_store = self.target.weave_store
         for tree in self.iter_rev_trees(revs):
             revision_id = tree.inventory.root.revision
-            root_id = tree.path2id('')
+            root_id = tree.get_root_id()
             parents = inventory_weave.get_parents(revision_id)
             if root_id not in versionedfile:
                 versionedfile[root_id] = to_store.get_weave_or_empty(root_id, 

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/merge.py	2007-10-26 19:18:48 +0000
@@ -550,7 +550,7 @@
                                  self.tt.root)
         if self.other_tree.inventory.root is None:
             return
-        other_root_file_id = self.other_tree.path2id('')
+        other_root_file_id = self.other_tree.get_root_id()
         other_root = self.tt.trans_id_file_id(other_root_file_id)
         if other_root == self.tt.root:
             return

=== modified file 'bzrlib/tests/repository_implementations/test_commit_builder.py'
--- a/bzrlib/tests/repository_implementations/test_commit_builder.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/repository_implementations/test_commit_builder.py	2007-10-26 19:18:48 +0000
@@ -147,7 +147,7 @@
         builder = tree.branch.get_commit_builder([parent_tree.inventory])
         try:
             ie = inventory.make_entry('directory', '', None,
-                    tree.path2id(''))
+                    tree.get_root_id())
             delta, version_recorded = builder.record_entry_contents(
                 ie, [parent_tree.inventory], '', tree,
                 tree.path_content_summary(''))
@@ -367,7 +367,7 @@
             # root
             builder.record_entry_contents(
                 inventory.make_entry('directory', '', None,
-                    tree.path2id('')), parent_invs, '', tree,
+                    tree.get_root_id()), parent_invs, '', tree,
                     tree.path_content_summary(''))
             def commit_id(file_id):
                 old_ie = tree.inventory[file_id]
@@ -379,7 +379,7 @@
 
             file_id = tree.path2id(new_name)
             parent_id = tree.inventory[file_id].parent_id
-            if parent_id != tree.path2id(''):
+            if parent_id != tree.get_root_id():
                 commit_id(parent_id)
             # because a change of some sort is meant to have occurred,
             # recording the entry must return True.

=== modified file 'bzrlib/tests/repository_implementations/test_fetch.py'
--- a/bzrlib/tests/repository_implementations/test_fetch.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/repository_implementations/test_fetch.py	2007-10-26 19:18:48 +0000
@@ -68,7 +68,7 @@
         # disk.
         knit3_repo = b_bzrdir.open_repository()
         rev1_tree = knit3_repo.revision_tree('rev1')
-        lines = rev1_tree.get_file_lines(rev1_tree.path2id(''))
+        lines = rev1_tree.get_file_lines(rev1_tree.get_root_id())
         self.assertEqual([], lines)
         b_branch = b_bzrdir.create_branch()
         b_branch.pull(tree_a.branch)

=== modified file 'bzrlib/tests/repository_implementations/test_fileid_involved.py'
--- a/bzrlib/tests/repository_implementations/test_fileid_involved.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/repository_implementations/test_fileid_involved.py	2007-10-26 19:18:48 +0000
@@ -174,7 +174,7 @@
     def fileids_altered_by_revision_ids(self, revision_ids):
         """This is a wrapper to strip TREE_ROOT if it occurs"""
         repo = self.branch.repository
-        root_id = self.branch.basis_tree().path2id('')
+        root_id = self.branch.basis_tree().get_root_id()
         result = repo.fileids_altered_by_revision_ids(revision_ids)
         if root_id in result:
             del result[root_id]
@@ -245,7 +245,7 @@
         repo.lock_read()
         self.addCleanup(repo.unlock)
         file_ids = repo.fileids_altered_by_revision_ids([revision_id])
-        root_id = main_wt.basis_tree().path2id('')
+        root_id = main_wt.basis_tree().get_root_id()
         if root_id in file_ids:
             self.assertEqual({file_id:set([revision_id]),
                               root_id:set([revision_id])

=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/test_dirstate.py	2007-10-26 19:18:48 +0000
@@ -360,7 +360,7 @@
         # There are no files on disk and no parents
         tree = self.make_branch_and_tree('tree')
         expected_result = ([], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
              ])])
         state = dirstate.DirState.from_tree(tree, 'dirstate')
@@ -373,7 +373,7 @@
         rev_id = tree.commit('first post').encode('utf8')
         root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir))
         expected_result = ([rev_id], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
               ('d', '', 0, False, rev_id), # first parent details
              ])])
@@ -393,7 +393,7 @@
         rev_id2 = tree2.commit('second post', allow_pointless=True)
         tree.merge_from_branch(tree2.branch)
         expected_result = ([rev_id, rev_id2], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
               ('d', '', 0, False, rev_id), # first parent details
               ('d', '', 0, False, rev_id2), # second parent details
@@ -412,7 +412,7 @@
         tree = self.make_branch_and_tree('tree')
         self.build_tree(['tree/unknown'])
         expected_result = ([], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
              ])])
         state = dirstate.DirState.from_tree(tree, 'dirstate')
@@ -429,7 +429,7 @@
         # There are files on disk and no parents
         tree = self.get_tree_with_a_file()
         expected_result = ([], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
              ]),
             (('', 'a file', 'a file id'), # common
@@ -447,7 +447,7 @@
         # and length:
         self.build_tree_contents([('tree/a file', 'new content\n')])
         expected_result = ([rev_id], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
               ('d', '', 0, False, rev_id), # first parent details
              ]),
@@ -474,7 +474,7 @@
         # and length again, giving us three distinct values:
         self.build_tree_contents([('tree/a file', 'new content\n')])
         expected_result = ([rev_id, rev_id2], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
               ('d', '', 0, False, rev_id), # first parent details
               ('d', '', 0, False, rev_id2), # second parent details
@@ -526,7 +526,7 @@
         # get a state object
         # no parents, default tree content
         expected_result = ([], [
-            (('', '', tree.path2id('')), # common details
+            (('', '', tree.get_root_id()), # common details
              # current tree details, but new from_tree skips statting, it
              # uses set_state_from_inventory, and thus depends on the
              # inventory state.
@@ -679,7 +679,7 @@
         try:
             tree1.add('')
             revid1 = tree1.commit('foo').encode('utf8')
-            root_id = tree1.path2id('')
+            root_id = tree1.get_root_id()
             inv = tree1.inventory
         finally:
             tree1.unlock()
@@ -893,7 +893,7 @@
         tree2.lock_write()
         try:
             revid2 = tree2.commit('foo')
-            root_id = tree2.path2id('')
+            root_id = tree2.get_root_id()
         finally:
             tree2.unlock()
         state = dirstate.DirState.initialize('dirstate')
@@ -963,7 +963,7 @@
         try:
             tree2.put_file_bytes_non_atomic('file-id', 'new file-content')
             revid2 = tree2.commit('foo')
-            root_id = tree2.path2id('')
+            root_id = tree2.get_root_id()
         finally:
             tree2.unlock()
         # check the layout in memory

=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py	2007-10-26 19:15:29 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py	2007-10-26 19:18:48 +0000
@@ -262,7 +262,7 @@
             self.build_tree(paths[1:])
         except UnicodeError:
             raise tests.TestSkipped('filesystem does not support unicode.')
-        if tree.path2id('') is None:
+        if tree.get_root_id() is None:
             # Some trees do not have a root yet.
             tree.add(paths, file_ids)
         else:

=== modified file 'bzrlib/tests/workingtree_implementations/test_commit.py'
--- a/bzrlib/tests/workingtree_implementations/test_commit.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_commit.py	2007-10-26 19:18:48 +0000
@@ -105,7 +105,7 @@
 
         tree_a.lock_read()
         try:
-            root_id = tree_a.path2id('')
+            root_id = tree_a.get_root_id()
             paths = [(path, ie.file_id)
                      for path, ie in tree_a.iter_entries_by_dir()]
         finally:
@@ -126,7 +126,7 @@
 
         tree_a.lock_read()
         try:
-            root_id = tree_a.path2id('')
+            root_id = tree_a.get_root_id()
             paths = [(path, ie.file_id)
                      for path, ie in tree_a.iter_entries_by_dir()]
         finally:
@@ -145,7 +145,7 @@
 
         tree_a.lock_read()
         try:
-            root_id = tree_a.path2id('')
+            root_id = tree_a.get_root_id()
         finally:
             tree_a.unlock()
 

=== modified file 'bzrlib/tests/workingtree_implementations/test_unversion.py'
--- a/bzrlib/tests/workingtree_implementations/test_unversion.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_unversion.py	2007-10-26 19:18:48 +0000
@@ -118,7 +118,7 @@
 
         tree.lock_read()
         try:
-            root_id = tree.path2id('')
+            root_id = tree.get_root_id()
             paths = [(path, ie.file_id)
                      for path, ie in tree.iter_entries_by_dir()]
         finally:
@@ -149,7 +149,7 @@
 
         tree_a.lock_read()
         try:
-            root_id = tree_a.path2id('')
+            root_id = tree_a.get_root_id()
         finally:
             tree_a.unlock()
 

=== modified file 'bzrlib/tests/workingtree_implementations/test_workingtree.py'
--- a/bzrlib/tests/workingtree_implementations/test_workingtree.py	2007-08-29 16:09:51 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_workingtree.py	2007-10-26 19:18:48 +0000
@@ -745,7 +745,7 @@
         # if we write write an inventory then do a walkdirs we should get back
         # missing entries, and actual, and unknowns as appropriate.
         self.build_tree(['present', 'unknown'])
-        inventory = Inventory(tree.path2id(''))
+        inventory = Inventory(tree.get_root_id())
         inventory.add_path('missing', 'file', 'missing-id')
         inventory.add_path('present', 'file', 'present-id')
         # there is no point in being able to write an inventory to an unlocked
@@ -758,7 +758,7 @@
             present_stat = os.lstat('present')
             unknown_stat = os.lstat('unknown')
             expected_results = [
-                (('', tree.inventory.root.file_id),
+                (('', tree.get_root_id()),
                  [('missing', 'missing', 'unknown', None, 'missing-id', 'file'),
                   ('present', 'present', 'file', present_stat, 'present-id', 'file'),
                   ('unknown', 'unknown', 'file', unknown_stat, None, None),

=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/transform.py	2007-10-26 19:18:48 +0000
@@ -495,7 +495,7 @@
             return None
         # the file is old; the old id is still valid
         if self._new_root == trans_id:
-            return self._tree.path2id('')
+            return self._tree.get_root_id()
         return self._tree.inventory.path2id(path)
 
     def final_file_id(self, trans_id):
@@ -905,7 +905,7 @@
                         self.rename_count += 1
                 if trans_id in self._removed_id:
                     if trans_id == self._new_root:
-                        file_id = self._tree.path2id('')
+                        file_id = self._tree.get_root_id()
                     else:
                         file_id = self.tree_file_id(trans_id)
                     assert file_id is not None
@@ -1283,8 +1283,8 @@
         # is set within the tree, nor setting the root and thus
         # marking the tree as dirty, because we use two different
         # idioms here: tree interfaces and inventory interfaces.
-        if wt.path2id('') != tree.path2id(''):
-            wt.set_root_id(tree.path2id(''))
+        if wt.get_root_id() != tree.get_root_id():
+            wt.set_root_id(tree.get_root_id())
             wt.flush()
     tt = TreeTransform(wt)
     divert = set()

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-10-26 19:08:21 +0000
+++ b/bzrlib/workingtree.py	2007-10-26 19:18:48 +0000
@@ -1541,7 +1541,7 @@
                                 change_reporter=change_reporter)
                     if (basis_tree.inventory.root is None and
                         new_basis_tree.inventory.root is not None):
-                        self.set_root_id(new_basis_tree.path2id(''))
+                        self.set_root_id(new_basis_tree.get_root_id())
                 finally:
                     pb.finished()
                     basis_tree.unlock()
@@ -2139,7 +2139,7 @@
             try:
                 to_tree = self.branch.basis_tree()
                 if basis.inventory.root is None:
-                    self.set_root_id(to_tree.path2id(''))
+                    self.set_root_id(to_tree.get_root_id())
                     self.flush()
                 result += merge.merge_inner(
                                       self.branch,
@@ -2715,7 +2715,7 @@
                          _bzrdir=a_bzrdir)
         basis_tree = branch.repository.revision_tree(revision_id)
         if basis_tree.inventory.root is not None:
-            wt.set_root_id(basis_tree.path2id(''))
+            wt.set_root_id(basis_tree.get_root_id())
         # set the parent list and cache the basis tree.
         if _mod_revision.is_null(revision_id):
             parent_trees = []
@@ -2817,7 +2817,7 @@
             basis_tree = branch.repository.revision_tree(revision_id)
             # only set an explicit root id if there is one to set.
             if basis_tree.inventory.root is not None:
-                wt.set_root_id(basis_tree.path2id(''))
+                wt.set_root_id(basis_tree.get_root_id())
             if revision_id == NULL_REVISION:
                 wt.set_parent_trees([])
             else:



More information about the bazaar-commits mailing list