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

Colin McMillen mcmillen at cs.cmu.edu
Fri Mar 24 16:56:10 UTC 2006


# HG changeset patch
# User mcmillen at cs.cmu.edu
# Node ID 74f5942965aa5ce337b454400b480d5fe2073eb0
# Parent  18a3e63696004ac7ba8f916349d11986a893a5f5
Implementation of per-user .hgignore as suggested by Bryan O'Sullivan.

Reference: http://www.selenic.com/mercurial/bts/issue166

If the [ui] section of .hgrc contains keys like "ignore" or
"ignore.something", the values corresponding to these keys are
treated as per-user hgignore files. These hgignore files apply to all
repositories used by that user.

~/.hgignore is always read if it exists, even if not specified in
.hgrc; this provides a simple method of user-wide ignore for the common
case where a user just wants a single ignore file.

This patch contains documentation updates for the new functionality.

Sample .hgrc:

[ui]
ignore = ~/.hgignore-1
ignore.other = ~/.hgignore-2

Sample .hgignore-foo:

syntax: glob
FOO
bar*
syntax: re
baz$

diff -r 18a3e63696004ac7ba8f916349d11986a893a5f5 -r 74f5942965aa5ce337b454400b480d5fe2073eb0 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt    Tue Mar 21 23:31:04 2006 -0800
+++ b/doc/hgrc.5.txt    Fri Mar 24 11:52:43 2006 -0500
@@ -236,6 +236,13 @@ ui::
     Print debugging information.  True or False.  Default is False.
   editor;;
     The editor to use during a commit.  Default is $EDITOR or "vi".
+  ignore;;
+    A file to read per-user ignore patterns from. This file should be in 
+    the same format as a repository-wide .hgignore file. ~/.hgignore is 
+    always looked at for ignore patterns. If you want additional ignore 
+    files, add them here. This option supports hook syntax, so if you want 
+    to specify multiple ignore files, you can do so by setting something
+    like "ignore.other = ~/.hgignore2".
   interactive;;
     Allow to prompt the user.  True or False.  Default is True.
   logtemplate;;
diff -r 18a3e63696004ac7ba8f916349d11986a893a5f5 -r 74f5942965aa5ce337b454400b480d5fe2073eb0 mercurial/dirstate.py
--- a/mercurial/dirstate.py     Tue Mar 21 23:31:04 2006 -0800
+++ b/mercurial/dirstate.py     Fri Mar 24 11:52:43 2006 -0500
@@ -34,7 +34,12 @@ class dirstate(object):
         return cwd[len(self.root) + 1:]
 
     def hgignore(self):
-        '''return the contents of .hgignore as a list of patterns.
+        '''return the contents of .hgignore files as a list of patterns.
+
+        the files parsed for patterns include:
+        .hgignore in the repository root
+        ~/.hgignore
+        any additional files specified in the [ui] section of ~/.hgrc
 
         trailing white space is dropped.
         the escape character is backslash.
@@ -58,31 +63,37 @@ class dirstate(object):
                     elif line[i] == '#': break
                 line = line[:i].rstrip()
                 if line: yield line
+        files = [self.wjoin('.hgignore'),
+                 os.path.expanduser('~/.hgignore')]
+        files.extend(self.ui.hgignorefiles())
         pats = []
-        try:
-            fp = open(self.wjoin('.hgignore'))
-            syntax = 'relre:'
-            for line in parselines(fp):
-                if line.startswith('syntax:'):
-                    s = line[7:].strip()
-                    try:
-                        syntax = syntaxes[s]
-                    except KeyError:
-                        self.ui.warn(_(".hgignore: ignoring invalid "
-                                       "syntax '%s'\n") % s)
-                    continue
-                pat = syntax + line
-                for s in syntaxes.values():
-                    if line.startswith(s):
-                        pat = line
-                        break
-                pats.append(pat)
-        except IOError: pass
+        for f in files:
+            try:
+                fp = open(f)
+                syntax = 'relre:'
+                for line in parselines(fp):
+                    if line.startswith('syntax:'):
+                        s = line[7:].strip()
+                        try:
+                            syntax = syntaxes[s]
+                        except KeyError:
+                            self.ui.warn(_(".hgignore: ignoring invalid "
+                                           "syntax '%s'\n") % s)
+                        continue
+                    pat = syntax + line
+                    for s in syntaxes.values():
+                        if line.startswith(s):
+                            pat = line
+                            break
+                    pats.append(pat)
+            except IOError: pass
         return pats
 
     def ignore(self, fn):
         '''default match function used by dirstate and localrepository.
-        this honours the .hgignore file, and nothing more.'''
+        this honours the repository .hgignore file, the user ~/.hgignore
+        file, and any other files specified in the [ui] section of
+        .hgrc.'''
         if self.blockignore:
             return False
         if not self.ignorefunc:
diff -r 18a3e63696004ac7ba8f916349d11986a893a5f5 -r 74f5942965aa5ce337b454400b480d5fe2073eb0 mercurial/ui.py
--- a/mercurial/ui.py   Tue Mar 21 23:31:04 2006 -0800
+++ b/mercurial/ui.py   Fri Mar 24 11:52:43 2006 -0500
@@ -122,6 +122,15 @@ class ui(object):
 
     def extensions(self):
         return self.configitems("extensions")
+
+    def hgignorefiles(self):
+        result = []
+        cfgitems = self.configitems("ui")
+        for key, value in cfgitems:
+            if key == 'ignore' or key.startswith('ignore.'):
+                path = os.path.expanduser(value)
+                result.append(path)
+        return result


-------------- 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/23a65a8f/attachment-0001.asc>


More information about the Mercurial mailing list