Patchwork [5,of,8] ignore: pass root+ignorefilepath throughout ignore logic

login
register
mail settings
Submitter Durham Goode
Date May 13, 2015, 3:13 p.m.
Message ID <71a709c7d25b9e918538.1431529999@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9039/
State Changes Requested
Headers show

Comments

Durham Goode - May 13, 2015, 3:13 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1431485038 25200
#      Tue May 12 19:43:58 2015 -0700
# Node ID 71a709c7d25b9e918538ddbdc36d3c5734b83e23
# Parent  8bd4aa1146eca2364986ef2a17fbf88ed7cfcdb6
ignore: pass root+ignorefilepath throughout ignore logic

Previously we passed the root to some functions, the file path to some, and a
file object to other functions. Let's unify all of this so they all accept root
+ filepath. This will make it easier to make the ignore logic recursive in an
upcoming patch and will allow us to detect when an ignore file is in a
subdirectory of the repo.

Patch

diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -7,11 +7,11 @@ 
 
 from i18n import _
 import util, match
-import re
+import os, re
 
 _commentre = None
 
-def ignorepats(lines):
+def ignorepats(ui, root, filepath):
     '''parse lines (iterable) of .hgignore text, returning a tuple of
     (patterns, parse errors). These patterns should be given to compile()
     to be validated and converted into a match function.'''
@@ -20,7 +20,9 @@  def ignorepats(lines):
     patterns = []
     warnings = []
 
-    for line in lines:
+    fp = open(filepath)
+
+    for line in fp:
         if "#" in line:
             global _commentre
             if not _commentre:
@@ -53,14 +55,13 @@  def ignorepats(lines):
                 break
         patterns.append(linesyntax + line)
 
+    fp.close()
     return patterns, warnings
 
-def readignorefile(ui, filepath, skipwarning=False):
+def readignorefile(ui, root, filepath, skipwarning=False):
     try:
         pats = []
-        fp = open(filepath)
-        pats, warnings = ignorepats(fp)
-        fp.close()
+        pats, warnings = ignorepats(ui, root, filepath)
         for warning in warnings:
             ui.warn("%s: %s\n" % (filepath, warning))
     except IOError, inst:
@@ -77,7 +78,8 @@  def readpats(ui, root, files):
         if f in pats:
             continue
         skipwarning = f == files[0]
-        pats[f] = readignorefile(ui, f, skipwarning=skipwarning)
+        fullpath = os.path.normpath(os.path.join(root, f))
+        pats[f] = readignorefile(ui, root, fullpath, skipwarning=skipwarning)
 
     return [(f, pats[f]) for f in files if f in pats]