D4800: storageutil: extract copy metadata retrieval out of filelog

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Oct 3 15:05:30 UTC 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1d97a332c6d9: storageutil: extract copy metadata retrieval out of filelog (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4800?vs=11483&id=11614

REVISION DETAIL
  https://phab.mercurial-scm.org/D4800

AFFECTED FILES
  mercurial/filelog.py
  mercurial/utils/storageutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/storageutil.py b/mercurial/utils/storageutil.py
--- a/mercurial/utils/storageutil.py
+++ b/mercurial/utils/storageutil.py
@@ -89,6 +89,25 @@
     offset = text.index(b'\x01\n', 2)
     return text[offset + 2:]
 
+def filerevisioncopied(store, node):
+    """Resolve file revision copy metadata.
+
+    Returns ``False`` if the file has no copy metadata. Otherwise a
+    2-tuple of the source filename and node.
+    """
+    if store.parents(node)[0] != nullid:
+        return False
+
+    meta = parsemeta(store.revision(node))[0]
+
+    # copy and copyrev occur in pairs. In rare cases due to old bugs,
+    # one can occur without the other. So ensure both are present to flag
+    # as a copy.
+    if meta and b'copy' in meta and b'copyrev' in meta:
+        return meta[b'copy'], bin(meta[b'copyrev'])
+
+    return False
+
 def iterrevs(storelen, start=0, stop=None):
     """Iterate over revision numbers in a store."""
     step = 1
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -115,15 +115,7 @@
         return self.addrevision(text, transaction, link, p1, p2)
 
     def renamed(self, node):
-        if self.parents(node)[0] != revlog.nullid:
-            return False
-        t = self.revision(node)
-        m = storageutil.parsemeta(t)[0]
-        # copy and copyrev occur in pairs. In rare cases due to bugs,
-        # one can occur without the other.
-        if m and "copy" in m and "copyrev" in m:
-            return (m["copy"], revlog.bin(m["copyrev"]))
-        return False
+        return storageutil.filerevisioncopied(self, node)
 
     def size(self, rev):
         """return the size of a given revision"""



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list