Rev 6495: (jelmer) Reintroduce support for passing lists to Tree.path2id(). (Jelmer in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Mar 12 13:38:10 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6495 [merge]
revision-id: pqm at pqm.ubuntu.com-20120312133809-q6xr6ujz40gpucun
parent: pqm at pqm.ubuntu.com-20120312123559-g4tqzz3790kszu03
parent: jelmer at samba.org-20120305172908-diwejxq31xmy3sbl
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2012-03-12 13:38:09 +0000
message:
  (jelmer) Reintroduce support for passing lists to Tree.path2id(). (Jelmer
   Vernooij)
added:
  bzrlib/tests/per_tree/test_ids.py test_ids.py-20120305171825-5psigdaz3yad4893-1
modified:
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
  bzrlib/tests/per_tree/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
  bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
  doc/en/release-notes/bzr-2.6.txt bzr2.6.txt-20120116134316-8w1xxom1c7vcu1t5-1
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2012-02-17 16:37:15 +0000
+++ b/bzrlib/inventory.py	2012-03-05 17:29:08 +0000
@@ -2111,13 +2111,16 @@
     def path2id(self, relpath):
         """See CommonInventory.path2id()."""
         # TODO: perhaps support negative hits?
+        if isinstance(relpath, basestring):
+            names = osutils.splitpath(relpath)
+        else:
+            names = relpath
+            if relpath == []:
+                relpath = [""]
+            relpath = osutils.pathjoin(*relpath)
         result = self._path_to_fileid_cache.get(relpath, None)
         if result is not None:
             return result
-        if isinstance(relpath, basestring):
-            names = osutils.splitpath(relpath)
-        else:
-            names = relpath
         current_id = self.root_id
         if current_id is None:
             return None

=== modified file 'bzrlib/tests/per_tree/__init__.py'
--- a/bzrlib/tests/per_tree/__init__.py	2011-06-14 01:26:41 +0000
+++ b/bzrlib/tests/per_tree/__init__.py	2012-03-05 17:29:08 +0000
@@ -382,6 +382,7 @@
         'get_file_with_stat',
         'get_root_id',
         'get_symlink_target',
+        'ids',
         'inv',
         'iter_search_rules',
         'is_executable',

=== added file 'bzrlib/tests/per_tree/test_ids.py'
--- a/bzrlib/tests/per_tree/test_ids.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_tree/test_ids.py	2012-03-05 17:29:08 +0000
@@ -0,0 +1,51 @@
+# Copyright (C) 2012 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+from bzrlib import (
+    errors,
+    )
+from bzrlib.tests.per_tree import TestCaseWithTree
+
+class IdTests(TestCaseWithTree):
+
+    def setUp(self):
+        super(IdTests, self).setUp()
+        work_a = self.make_branch_and_tree('wta')
+        self.build_tree(['wta/bla', 'wta/dir/', 'wta/dir/file'])
+        work_a.add(['bla', 'dir', 'dir/file'], ['bla-id', 'dir-id', 'file-id'])
+        work_a.commit('add files')
+        self.tree_a = self.workingtree_to_test_tree(work_a)
+
+    def test_path2id(self):
+        self.assertEquals('bla-id', self.tree_a.path2id('bla'))
+        self.assertEquals('dir-id', self.tree_a.path2id('dir'))
+        self.assertIs(None, self.tree_a.path2id('idontexist'))
+
+    def test_path2id_list(self):
+        self.assertEquals('bla-id', self.tree_a.path2id(['bla']))
+        self.assertEquals('dir-id', self.tree_a.path2id(['dir']))
+        self.assertEquals('file-id', self.tree_a.path2id(['dir', 'file']))
+        self.assertEquals(self.tree_a.get_root_id(),
+            self.tree_a.path2id([]))
+        self.assertIs(None, self.tree_a.path2id(['idontexist']))
+        self.assertIs(None, self.tree_a.path2id(['dir', 'idontexist']))
+
+    def test_id2path(self):
+        self.addCleanup(self.tree_a.lock_read().unlock)
+        self.assertEquals('bla', self.tree_a.id2path('bla-id'))
+        self.assertEquals('dir', self.tree_a.id2path('dir-id'))
+        self.assertEquals('dir/file', self.tree_a.id2path('file-id'))
+        self.assertRaises(errors.NoSuchId, self.tree_a.id2path, 'nonexistant')

=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py	2012-02-06 23:38:33 +0000
+++ b/bzrlib/transform.py	2012-03-05 17:29:08 +0000
@@ -2117,6 +2117,10 @@
         return cur_parent
 
     def path2id(self, path):
+        if isinstance(path, list):
+            if path == []:
+                path = [""]
+            path = osutils.pathjoin(*path)
         return self._transform.final_file_id(self._path2trans_id(path))
 
     def id2path(self, file_id):

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2012-02-23 19:45:15 +0000
+++ b/bzrlib/workingtree_4.py	2012-03-12 13:38:09 +0000
@@ -894,6 +894,10 @@
     @needs_read_lock
     def path2id(self, path):
         """Return the id for path in this tree."""
+        if isinstance(path, list):
+            if path == []:
+                path = [""]
+            path = osutils.pathjoin(*path)
         path = path.strip('/')
         entry = self._get_entry(path=path)
         if entry == (None, None):
@@ -1777,7 +1781,8 @@
         if path is not None:
             path = path.encode('utf8')
         parent_index = self._get_parent_index()
-        return self._dirstate._get_entry(parent_index, fileid_utf8=file_id, path_utf8=path)
+        return self._dirstate._get_entry(parent_index, fileid_utf8=file_id,
+            path_utf8=path)
 
     def _generate_inventory(self):
         """Create and set self.inventory from the dirstate object.
@@ -2029,6 +2034,10 @@
     def path2id(self, path):
         """Return the id for path in this tree."""
         # lookup by path: faster than splitting and walking the ivnentory.
+        if isinstance(path, list):
+            if path == []:
+                path = [""]
+            path = osutils.pathjoin(*path)
         entry = self._get_entry(path=path)
         if entry == (None, None):
             return None

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-03-11 17:03:05 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-03-12 13:38:09 +0000
@@ -95,6 +95,9 @@
 .. Major internal changes, unlikely to be visible to users or plugin 
    developers, but interesting for bzr developers.
 
+* ``Tree.path2id`` now once again accepts a list of path elements
+  in addition to a path. (Jelmer Vernooij)
+
 * Turn config option expansion on by default. The only options for which
   this should be disabled are templates which should already have used
   conf.get(option, expand=False) or conf.get_user_option(option,
@@ -107,6 +110,5 @@
    suite.  This can include new facilities for writing tests, fixes to 
    spurious test failures and changes to the way things should be tested.
 
-
 ..
    vim: tw=74 ft=rst ff=unix




More information about the bazaar-commits mailing list