changeset 24525:e118f74d246f

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.
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 27 Mar 2015 15:37:46 -0700
parents 63b6031384fc
children cd50f3717639
files mercurial/manifest.py
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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):