[PATCH 5 of 7] filelog: add support for packing and repacking lwcopy entries

Sune Foldager cryo at cyanite.org
Tue Sep 14 04:56:34 CDT 2010


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1284454341 -7200
# Node ID c9ecf6d42dbaf1624833591c1c580ba93b0afa04
# Parent  a216867d6bb6f768ebeca2140d36c207e08264d1
filelog: add support for packing and repacking lwcopy entries

diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -8,6 +8,8 @@
 import revlog, mdiff
 import re
 
+from error import LookupError
+
 class filelog(revlog.revlog):
     def __init__(self, opener, path):
         revlog.revlog.__init__(self, opener,
@@ -24,9 +26,17 @@
         return _parsemeta(self.revision(node))[0]
 
     def add(self, text, meta, transaction, link, p1=None, p2=None):
+        hashtext = None
         if meta or text.startswith('\1\n'):
+            if "copylw" in meta:
+                hashmeta = dict(meta)
+                del hashmeta["copylw"]
+                hashtext = "\1\n%s\1\n%s" % (_packmeta(hashmeta), text)
+                ptext = self._ptext(meta)
+                text = mdiff.textdiff(ptext, text)
             text = "\1\n%s\1\n%s" % (_packmeta(meta), text)
-        return self.addrevision(text, transaction, link, p1, p2)
+        return self.addrevision(text, transaction, link, p1, p2,
+                                hashtext=hashtext)
 
     def renamed(self, node):
         if self.parents(node)[0] != revlog.nullid:
@@ -86,6 +96,31 @@
         text = revlog.revlog._chunkbase(self, rev)
         return self._unpack_text(text)
 
+    def _hash(self, text, hashtext, p1, p2):
+        if hashtext is None:
+            hashtext = self._unpack_text(text)
+        return revlog.revlog._hash(self, text, hashtext, p1, p2)
+
+    def _textfromdelta(self, text, delta):
+        repack = len(text) == 0 and "lwcopy" in self.opener.options
+        text, hashtext = revlog.revlog._textfromdelta(self, text, delta)
+        if repack:
+            hashtext = text
+            meta, keys, mdlen = _parsemeta(text)
+            if not meta or "copy" not in meta:
+                return text, None
+            try:
+                ptext = self._ptext(meta)
+            except LookupError:
+                # we miss the data from changegroup, it will appear later
+                # fallback to standard behaviour
+                return text, None
+            meta["copylw"] = ''
+            keys.append("copylw")
+            text = mdiff.textdiff(ptext, buffer(text, mdlen))
+            text = "\1\n%s\1\n%s" % (_packmeta(meta, keys), text)
+        return text, hashtext
+
 _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