Mercurial > public > mercurial-scm > hg
diff mercurial/context.py @ 41755:a4358f7345b4
context: introduce p[12]copies() methods and debugp[12]copies commands
As mentioned earlier, I'm working on support for storing copy metadata
in the changeset instead of in the filelog.
In order to transition a repo from storing metadata in filelogs to
storing it in the changeset, I'm going to provide a config option for
reading the metadata from the changeset, but falling back to getting
it from the filelog if it's not in the changeset. In this compatiblity
mode, the changeset-optmized algorithms will be used. We will then
need to convert the filelog copy metadata to look like that provided
by changeset copy metadata. This patch introduces methods that do just
that.
By having these methods here, we can start writing changeset-optimized
algorithms that should work already before we add any support for
storing the metadata in the changesets.
This commit also includes new debugp[12]copies commands and exercises
them in test-copies.t.
Differential Revision: https://phab.mercurial-scm.org/D5990
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 18 Jan 2019 13:13:30 -0800 |
parents | d4c9eebdd72d |
children | aaad36b88298 |
line wrap: on
line diff
--- a/mercurial/context.py Thu Feb 14 22:46:18 2019 -0800 +++ b/mercurial/context.py Fri Jan 18 13:13:30 2019 -0800 @@ -439,6 +439,29 @@ return self._changeset.date def files(self): return self._changeset.files + @propertycache + def _copies(self): + p1copies = {} + p2copies = {} + p1 = self.p1() + p2 = self.p2() + narrowmatch = self._repo.narrowmatch() + for dst in self.files(): + if not narrowmatch(dst) or dst not in self: + continue + copied = self[dst].renamed() + if not copied: + continue + src, srcnode = copied + if src in p1 and p1[src].filenode() == srcnode: + p1copies[dst] = src + elif src in p2 and p2[src].filenode() == srcnode: + p2copies[dst] = src + return p1copies, p2copies + def p1copies(self): + return self._copies[0] + def p2copies(self): + return self._copies[1] def description(self): return self._changeset.description def branch(self): @@ -1158,7 +1181,26 @@ def files(self): return sorted(self._status.modified + self._status.added + self._status.removed) - + @propertycache + def _copies(self): + p1copies = {} + p2copies = {} + parents = self._repo.dirstate.parents() + p1manifest = self._repo[parents[0]].manifest() + p2manifest = self._repo[parents[1]].manifest() + narrowmatch = self._repo.narrowmatch() + for dst, src in self._repo.dirstate.copies().items(): + if not narrowmatch(dst): + continue + if src in p1manifest: + p1copies[dst] = src + elif src in p2manifest: + p2copies[dst] = src + return p1copies, p2copies + def p1copies(self): + return self._copies[0] + def p2copies(self): + return self._copies[1] def modified(self): return self._status.modified def added(self): @@ -1810,6 +1852,30 @@ return [f for f in self._cache.keys() if not self._cache[f]['exists'] and self._existsinparent(f)] + def p1copies(self): + copies = self._repo._wrappedctx.p1copies().copy() + narrowmatch = self._repo.narrowmatch() + for f in self._cache.keys(): + if not narrowmatch(f): + continue + copies.pop(f, None) # delete if it exists + source = self._cache[f]['copied'] + if source: + copies[f] = source + return copies + + def p2copies(self): + copies = self._repo._wrappedctx.p2copies().copy() + narrowmatch = self._repo.narrowmatch() + for f in self._cache.keys(): + if not narrowmatch(f): + continue + copies.pop(f, None) # delete if it exists + source = self._cache[f]['copied'] + if source: + copies[f] = source + return copies + def isinmemory(self): return True