Patchwork [1,of,2] manifest: move checkforbidden to module-level

login
register
mail settings
Submitter Augie Fackler
Date Sept. 10, 2014, 6:45 p.m.
Message ID <9c62e343f996d00e9061.1410374750@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/5771/
State Accepted
Headers show

Comments

Augie Fackler - Sept. 10, 2014, 6:45 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1407419165 14400
#      Thu Aug 07 09:46:05 2014 -0400
# Node ID 9c62e343f996d00e90614f42b7148760974201f2
# Parent  293930a1fa0a52d9bef832e72ef4c505b74e0c64
manifest: move checkforbidden to module-level

There's no need for this function to be nested, so let's just define
it once instead of every time manifest.add() gets called.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -40,6 +40,15 @@ 
     def flagsdiff(self, d2):
         return dicthelpers.diff(self._flags, d2._flags, "")
 
+
+def checkforbidden(l):
+    """Check filenames for illegal characters."""
+    for f in l:
+        if '\n' in f or '\r' in f:
+            raise error.RevlogError(
+                _("'\\n' and '\\r' disallowed in filenames: %r") % f)
+
+
 class manifest(revlog.revlog):
     def __init__(self, opener):
         # we expect to deal with not more than four revs at a time,
@@ -152,12 +161,6 @@ 
                            + content for start, end, content in x)
             return deltatext, newaddlist
 
-        def checkforbidden(l):
-            for f in l:
-                if '\n' in f or '\r' in f:
-                    raise error.RevlogError(
-                        _("'\\n' and '\\r' disallowed in filenames: %r") % f)
-
         # if we're using the cache, make sure it is valid and
         # parented by the same node we're diffing against
         if not (changed and p1 and (p1 in self._mancache)):