comparison 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
comparison
equal deleted inserted replaced
41754:d5edb5d3a337 41755:a4358f7345b4
437 return self._changeset.user 437 return self._changeset.user
438 def date(self): 438 def date(self):
439 return self._changeset.date 439 return self._changeset.date
440 def files(self): 440 def files(self):
441 return self._changeset.files 441 return self._changeset.files
442 @propertycache
443 def _copies(self):
444 p1copies = {}
445 p2copies = {}
446 p1 = self.p1()
447 p2 = self.p2()
448 narrowmatch = self._repo.narrowmatch()
449 for dst in self.files():
450 if not narrowmatch(dst) or dst not in self:
451 continue
452 copied = self[dst].renamed()
453 if not copied:
454 continue
455 src, srcnode = copied
456 if src in p1 and p1[src].filenode() == srcnode:
457 p1copies[dst] = src
458 elif src in p2 and p2[src].filenode() == srcnode:
459 p2copies[dst] = src
460 return p1copies, p2copies
461 def p1copies(self):
462 return self._copies[0]
463 def p2copies(self):
464 return self._copies[1]
442 def description(self): 465 def description(self):
443 return self._changeset.description 466 return self._changeset.description
444 def branch(self): 467 def branch(self):
445 return encoding.tolocal(self._changeset.extra.get("branch")) 468 return encoding.tolocal(self._changeset.extra.get("branch"))
446 def closesbranch(self): 469 def closesbranch(self):
1156 def description(self): 1179 def description(self):
1157 return self._text 1180 return self._text
1158 def files(self): 1181 def files(self):
1159 return sorted(self._status.modified + self._status.added + 1182 return sorted(self._status.modified + self._status.added +
1160 self._status.removed) 1183 self._status.removed)
1161 1184 @propertycache
1185 def _copies(self):
1186 p1copies = {}
1187 p2copies = {}
1188 parents = self._repo.dirstate.parents()
1189 p1manifest = self._repo[parents[0]].manifest()
1190 p2manifest = self._repo[parents[1]].manifest()
1191 narrowmatch = self._repo.narrowmatch()
1192 for dst, src in self._repo.dirstate.copies().items():
1193 if not narrowmatch(dst):
1194 continue
1195 if src in p1manifest:
1196 p1copies[dst] = src
1197 elif src in p2manifest:
1198 p2copies[dst] = src
1199 return p1copies, p2copies
1200 def p1copies(self):
1201 return self._copies[0]
1202 def p2copies(self):
1203 return self._copies[1]
1162 def modified(self): 1204 def modified(self):
1163 return self._status.modified 1205 return self._status.modified
1164 def added(self): 1206 def added(self):
1165 return self._status.added 1207 return self._status.added
1166 def removed(self): 1208 def removed(self):
1808 1850
1809 def removed(self): 1851 def removed(self):
1810 return [f for f in self._cache.keys() if 1852 return [f for f in self._cache.keys() if
1811 not self._cache[f]['exists'] and self._existsinparent(f)] 1853 not self._cache[f]['exists'] and self._existsinparent(f)]
1812 1854
1855 def p1copies(self):
1856 copies = self._repo._wrappedctx.p1copies().copy()
1857 narrowmatch = self._repo.narrowmatch()
1858 for f in self._cache.keys():
1859 if not narrowmatch(f):
1860 continue
1861 copies.pop(f, None) # delete if it exists
1862 source = self._cache[f]['copied']
1863 if source:
1864 copies[f] = source
1865 return copies
1866
1867 def p2copies(self):
1868 copies = self._repo._wrappedctx.p2copies().copy()
1869 narrowmatch = self._repo.narrowmatch()
1870 for f in self._cache.keys():
1871 if not narrowmatch(f):
1872 continue
1873 copies.pop(f, None) # delete if it exists
1874 source = self._cache[f]['copied']
1875 if source:
1876 copies[f] = source
1877 return copies
1878
1813 def isinmemory(self): 1879 def isinmemory(self):
1814 return True 1880 return True
1815 1881
1816 def filedate(self, path): 1882 def filedate(self, path):
1817 if self.isdirty(path): 1883 if self.isdirty(path):