[PATCH 2 of 5] manifest: extract method for creating manifest text

Martin von Zweigbergk martinvonz at google.com
Mon Mar 30 19:19:39 CDT 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1427495866 25200
#      Fri Mar 27 15:37:46 2015 -0700
# Node ID c61e8d4b91da9094bede396e32caf982ec78fc39
# Parent  90ddd267bb1d2988195ba8240d8c7c9cf7bbf3fd
manifest: extract method for creating manifest text

Similar to the previous change, this one extracts a method for
producing a manifest text from an iterator over (path, node, flags)
tuples.

diff -r 90ddd267bb1d -r c61e8d4b91da mercurial/manifest.py
--- a/mercurial/manifest.py	Fri Mar 27 15:02:43 2015 -0700
+++ b/mercurial/manifest.py	Fri Mar 27 15:37:46 2015 -0700
@@ -31,6 +31,21 @@
         else:
             yield f, revlog.bin(n), ''
 
+def _text(it):
+    """Given an iterator over (path, node, flags) tuples, returns a manifest
+    text"""
+    files = []
+    lines = []
+    _hex = revlog.hex
+    for f, n, fl in it:
+        files.append(f)
+        # if this is changed to support newlines in filenames,
+        # be sure to check the templates/ dir again (especially *-raw.tmpl)
+        lines.append("%s\0%s%s\n" % (f, _hex(n), fl))
+
+    _checkforbidden(files)
+    return ''.join(lines)
+
 class _lazymanifest(dict):
     """This is the pure implementation of lazymanifest.
 
@@ -92,13 +107,7 @@
 
     def text(self):
         """Get the full data of this manifest as a bytestring."""
-        fl = self.iterentries()
-
-        _hex = revlog.hex
-        # if this is changed to support newlines in filenames,
-        # be sure to check the templates/ dir again (especially *-raw.tmpl)
-        return ''.join("%s\0%s%s\n" % (
-            f, _hex(n[:20]), flag) for f, n, flag in fl)
+        return _text(self.iterentries())
 
 try:
     _lazymanifest = parsers.lazymanifest
@@ -578,13 +587,8 @@
 
     def text(self):
         """Get the full data of this manifest as a bytestring."""
-        fl = self.keys()
-        _checkforbidden(fl)
-
-        hex, flags = revlog.hex, self.flags
-        # if this is changed to support newlines in filenames,
-        # be sure to check the templates/ dir again (especially *-raw.tmpl)
-        return ''.join("%s\0%s%s\n" % (f, hex(self[f]), flags(f)) for f in fl)
+        flags = self.flags
+        return _text((f, self[f], flags(f)) for f in self.keys())
 
 class manifest(revlog.revlog):
     def __init__(self, opener):


More information about the Mercurial-devel mailing list