[PATCH] Improved per-user .hgignore patch -- documentation updates and minor implementation difference

Colin McMillen mcmillen at cs.cmu.edu
Fri Mar 24 20:50:58 UTC 2006


> > +                # FIXME: if there are errors in patterns, matcher will
> > +                # print out an error containing src ('.hgignore');
> > +                # really, we want the original source file to be
> > +                # printed instead.
> 
> Maybe the hgignore files can be parsed again (with recording
> sources) when an error is detected, so the extra overhead is only
> done in case of errors.

Here is an attempt to implement this suggestion.

- Colin

# HG changeset patch
# User mcmillen at cs.cmu.edu
# Node ID 60d042d52a0a729bd09fe1c539bea15ba7f54f02
# Parent  dd73f18b538c942eae30f37a5d86904ed7dffc6e
On error parsing hgignore file, print the correct filename.

diff -r dd73f18b538c942eae30f37a5d86904ed7dffc6e -r 60d042d52a0a729bd09fe1c539bea15ba7f54f02 mercurial/dirstate.py
--- a/mercurial/dirstate.py     Fri Mar 24 15:14:12 2006 -0500
+++ b/mercurial/dirstate.py     Fri Mar 24 15:49:27 2006 -0500
@@ -65,9 +65,10 @@ class dirstate(object):
         repoignore = self.wjoin('.hgignore')
         files = [repoignore]
         files.extend(self.ui.hgignorefiles())
-        pats = []
+        pats = {}
         for f in files:
             try:
+                pats[f] = []
                 fp = open(f)
                 syntax = 'relre:'
                 for line in parselines(fp):
@@ -84,7 +85,7 @@ class dirstate(object):
                         if line.startswith(s):
                             pat = line
                             break
-                    pats.append(pat)
+                    pats[f].append(pat)
             except IOError:
                 if f != repoignore:
                     self.ui.warn(_("ignore file %s not found\n") % f)
@@ -99,13 +100,16 @@ class dirstate(object):
         if not self.ignorefunc:
             ignore = self.hgignore()
             if ignore:
-                # FIXME: if there are errors in patterns, matcher will
-                # print out an error containing src ('.hgignore');
-                # really, we want the original source file to be
-                # printed instead.
-                files, self.ignorefunc, anypats = util.matcher(self.root,
-                                                               inc=ignore,
-                                                               src='.hgignore')
+                try:
+                    allpats = []
+                    [allpats.extend(patlist) for patlist in ignore.values()]
+                    files, self.ignorefunc, anypats = (
+                        util.matcher(self.root, inc=allpats, src='.hgignore'))
+                except util.Abort:
+                    # Re-raise an exception where the src is the right file
+                    for f, patlist in ignore.items():
+                        files, self.ignorefunc, anypats = (
+                            util.matcher(self.root, inc=patlist, src=f))
             else:
                 self.ignorefunc = util.never
         return self.ignorefunc(fn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20060324/788a951c/attachment-0001.asc>


More information about the Mercurial mailing list