dirstate: optimize copied for treestate

Summary:
For treestate, `copies` is more expensive as it's not a cache but calculates
from the source of truth. So avoid using `copies` but read the copy
information directly from the tree.

Reviewed By: DurhamG

Differential Revision: D8595357

fbshipit-source-id: bcea254358d66c9fa9f933d73221bbeb0bd8d5b2
This commit is contained in:
Jun Wu 2018-06-25 13:55:57 -07:00 committed by Facebook Github Bot
parent 0630c7d183
commit 0191b7396f
2 changed files with 15 additions and 1 deletions

View File

@ -422,7 +422,10 @@ class dirstate(object):
self._updatedfiles.add(dest)
def copied(self, file):
return self._map.copymap.get(file, None)
if self._istreestate:
return self._map.copysource(file)
else:
return self._map.copymap.get(file, None)
def copies(self):
return self._map.copymap

View File

@ -460,3 +460,14 @@ class treestatemap(object):
state |= treestate.NEED_CHECK
self._tree.insert(path, state, mode, size, mtime, copied)
return True
def copysource(self, path):
"""Return the copysource for path. Return None if it's not copied, or
path does not exist.
"""
existing = self._tree.get(path, None)
if existing:
_state, _mode, _size, _mtime, copied = existing
return copied
else:
return None