Patchwork [4,of,6] ignore: combine readignorefile and _ignorefile

login
register
mail settings
Submitter Durham Goode
Date May 18, 2015, 6:29 p.m.
Message ID <8f3107192afae4980357.1431973740@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9144/
State Accepted
Headers show

Comments

Durham Goode - May 18, 2015, 6:29 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1431816306 25200
#      Sat May 16 15:45:06 2015 -0700
# Node ID 8f3107192afae4980357ab70d69a060f57e9ac9f
# Parent  d74b5e7ce361d09fc240c68e3c5eaec89ae2c92f
ignore: combine readignorefile and _ignorefile

_ignorefile did nothing except open the file. Let's combine it with
readignorefile for simplicity. This will make it easier to rename and move to
match.py in upcoming patches.

Patch

diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -11,15 +11,16 @@  import re
 
 _commentre = None
 
-def ignorepats(lines):
-    '''parse lines (iterable) of .hgignore text, returning a tuple of
-    (patterns, parse errors). These patterns should be given to compile()
+def readignorefile(filepath):
+    '''parse a pattern file, returning a list of
+    patterns. These patterns should be given to compile()
     to be validated and converted into a match function.'''
     syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:'}
     syntax = 'relre:'
     patterns = []
 
-    for line in lines:
+    fp = open(filepath)
+    for line in fp:
         if "#" in line:
             global _commentre
             if not _commentre:
@@ -51,15 +52,9 @@  def ignorepats(lines):
                 line = line[len(s) + 1:]
                 break
         patterns.append(linesyntax + line)
-
+    fp.close()
     return patterns
 
-def readignorefile(filepath):
-    fp = open(filepath)
-    pats = ignorepats(fp)
-    fp.close()
-    return pats
-
 def readpats(root, files, warn):
     '''return a dict mapping ignore-file-name to list-of-patterns'''