Rev 2353: Perform path2id lookups in dirstate revision trees from the dirstate index without requiring an inventory. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/
Robert Collins
robertc at robertcollins.net
Thu Feb 22 01:11:27 GMT 2007
At sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/
------------------------------------------------------------
revno: 2353
revision-id: robertc at robertcollins.net-20070222011012-edaxufwi05dcn4az
parent: john at arbash-meinel.com-20070221224546-3frplqdi81632elw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Thu 2007-02-22 12:10:12 +1100
message:
Perform path2id lookups in dirstate revision trees from the dirstate index without requiring an inventory.
modified:
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-21 11:10:37 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-22 01:10:12 +0000
@@ -862,6 +862,26 @@
pred = self.has_filename
return set((p for p in paths if not pred(p)))
+ def _get_entry(self, file_id=None, path=None):
+ """Get the dirstate row for file_id or path.
+
+ If either file_id or path is supplied, it is used as the key to lookup.
+ If both are supplied, the fastest lookup is used, and an error is
+ raised if they do not both point at the same row.
+
+ :param file_id: An optional unicode file_id to be looked up.
+ :param path: An optional unicode path to be looked up.
+ :return: The dirstate row tuple for path/file_id, or (None, None)
+ """
+ if file_id is None and path is None:
+ raise errors.BzrError('must supply file_id or path')
+ if file_id is not None:
+ file_id = file_id.encode('utf8')
+ if path is not None:
+ path = path.encode('utf8')
+ parent_index = self._dirstate.get_parent_ids().index(self._revision_id) + 1
+ 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.
@@ -983,11 +1003,14 @@
self._repository.lock_read()
self._locked += 1
+ @needs_read_lock
def path2id(self, path):
"""Return the id for path in this tree."""
- # TODO: if there is no inventory, do an optimistic lookup in the
- # dirstate by the path; commonly this will work.
- return self.inventory.path2id(path)
+ # lookup by path: faster than splitting and walking the ivnentory.
+ entry = self._get_entry(path=path)
+ if entry == (None, None):
+ return None
+ return entry[0][2].decode('utf8')
def unlock(self):
"""Unlock, freeing any cache memory used during the lock."""
More information about the bazaar-commits
mailing list