[PATCH 4 of 6] filelog: add support for unpacking lwcopy entries

Sune Foldager cryo at cyanite.org
Mon Jan 31 04:21:42 CST 2011


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1296295857 -3600
# Node ID b973580739760fc25f971b947864a890abf5eb2c
# Parent  c53628efd882402813e98fc86bde1bf825ad1c79
filelog: add support for unpacking lwcopy entries

diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import revlog
+import revlog, mdiff
 import re
 
 class filelog(revlog.revlog):
@@ -67,6 +67,23 @@
 
         return True
 
+    def _ptext(self, meta):
+        return filelog(self.opener, meta["copy"]).read(revlog.bin(meta["copyrev"]))
+
+    def _unpack_text(self, text):
+        meta, keys, mdlen = _parsemeta(text)
+        if meta and "copylw" in meta:
+            ptext = self._ptext(meta)
+            text = mdiff.patches(ptext, [buffer(text, mdlen)])
+            # delete copylw entry to get just what we should get without lwcopy
+            keys.remove("copylw")
+            text = "\1\n%s\1\n%s" % (_packmeta(meta, keys), text)
+        return text
+
+    def _chunkbase(self, rev):
+        text = revlog.revlog._chunkbase(self, rev)
+        return self._unpack_text(text)
+
 _mdre = re.compile('\1\n')
 def _parsemeta(text):
     # text can be buffer, so we can't use .startswith or .index


More information about the Mercurial-devel mailing list