Patchwork [1,of,3] ignore: refactor ignore into two functions

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 18, 2012, 12:30 a.m.
Message ID <c0143219521a427970cc.1355790601@fedora>
Download mbox | patch
Permalink /patch/177/
State Accepted
Commit 5712e3b1227446a47ae94489abb6a459457a3c57
Headers show

Comments

Bryan O'Sullivan - Dec. 18, 2012, 12:30 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1355790217 28800
# Node ID c0143219521a427970cc224f0c4ea3ac7428236f
# Parent  3d1dc7aeca39446b6b2f7966e4890283f6560d63
ignore: refactor ignore into two functions

This prepares us for eventually being able to hash the list of patterns
in use.

Patch

diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -52,6 +52,24 @@ 
 
     return patterns, warnings
 
+def readpats(root, files, warn):
+    '''return a dict mapping ignore-file-name to list-of-patterns'''
+
+    pats = {}
+    for f in files:
+        try:
+            pats[f] = []
+            fp = open(f)
+            pats[f], warnings = ignorepats(fp)
+            fp.close()
+            for warning in warnings:
+                warn("%s: %s\n" % (f, warning))
+        except IOError, inst:
+            if f != files[0]:
+                warn(_("skipping unreadable ignore file '%s': %s\n") %
+                     (f, inst.strerror))
+    return pats
+
 def ignore(root, files, warn):
     '''return matcher covering patterns in 'files'.
 
@@ -72,19 +90,7 @@ 
     glob:pattern   # non-rooted glob
     pattern        # pattern of the current default type'''
 
-    pats = {}
-    for f in files:
-        try:
-            pats[f] = []
-            fp = open(f)
-            pats[f], warnings = ignorepats(fp)
-            fp.close()
-            for warning in warnings:
-                warn("%s: %s\n" % (f, warning))
-        except IOError, inst:
-            if f != files[0]:
-                warn(_("skipping unreadable ignore file '%s': %s\n") %
-                     (f, inst.strerror))
+    pats = readpats(root, files, warn)
 
     allpats = []
     for patlist in pats.values():