Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/dirstate.py @ 2003:62647394e368
Implementation of per-user .hgignore.
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.
author | mcmillen@cs.cmu.edu |
---|---|
date | Fri, 24 Mar 2006 20:18:02 +0100 |
parents | 98b6c1cad58b |
children | 7dd6317ab4fd |
comparison
equal
deleted
inserted
replaced
2002:4aab906517c6 | 2003:62647394e368 |
---|---|
32 cwd = os.getcwd() | 32 cwd = os.getcwd() |
33 if cwd == self.root: return '' | 33 if cwd == self.root: return '' |
34 return cwd[len(self.root) + 1:] | 34 return cwd[len(self.root) + 1:] |
35 | 35 |
36 def hgignore(self): | 36 def hgignore(self): |
37 '''return the contents of .hgignore as a list of patterns. | 37 '''return the contents of .hgignore files as a list of patterns. |
38 | |
39 the files parsed for patterns include: | |
40 .hgignore in the repository root | |
41 any additional files specified in the [ui] section of ~/.hgrc | |
38 | 42 |
39 trailing white space is dropped. | 43 trailing white space is dropped. |
40 the escape character is backslash. | 44 the escape character is backslash. |
41 comments start with #. | 45 comments start with #. |
42 empty lines are skipped. | 46 empty lines are skipped. |
56 if escape: escape = False | 60 if escape: escape = False |
57 elif line[i] == '\\': escape = True | 61 elif line[i] == '\\': escape = True |
58 elif line[i] == '#': break | 62 elif line[i] == '#': break |
59 line = line[:i].rstrip() | 63 line = line[:i].rstrip() |
60 if line: yield line | 64 if line: yield line |
65 files = [self.wjoin('.hgignore')] | |
66 files.extend(self.ui.hgignorefiles()) | |
61 pats = [] | 67 pats = [] |
62 try: | 68 for f in files: |
63 fp = open(self.wjoin('.hgignore')) | 69 try: |
64 syntax = 'relre:' | 70 fp = open(f) |
65 for line in parselines(fp): | 71 syntax = 'relre:' |
66 if line.startswith('syntax:'): | 72 for line in parselines(fp): |
67 s = line[7:].strip() | 73 if line.startswith('syntax:'): |
68 try: | 74 s = line[7:].strip() |
69 syntax = syntaxes[s] | 75 try: |
70 except KeyError: | 76 syntax = syntaxes[s] |
71 self.ui.warn(_(".hgignore: ignoring invalid " | 77 except KeyError: |
72 "syntax '%s'\n") % s) | 78 self.ui.warn(_("%s: ignoring invalid " |
73 continue | 79 "syntax '%s'\n") % (f, s)) |
74 pat = syntax + line | 80 continue |
75 for s in syntaxes.values(): | 81 pat = syntax + line |
76 if line.startswith(s): | 82 for s in syntaxes.values(): |
77 pat = line | 83 if line.startswith(s): |
78 break | 84 pat = line |
79 pats.append(pat) | 85 break |
80 except IOError: pass | 86 pats.append(pat) |
87 except IOError: pass | |
81 return pats | 88 return pats |
82 | 89 |
83 def ignore(self, fn): | 90 def ignore(self, fn): |
84 '''default match function used by dirstate and localrepository. | 91 '''default match function used by dirstate and |
85 this honours the .hgignore file, and nothing more.''' | 92 localrepository. this honours the repository .hgignore file |
93 and any other files specified in the [ui] section of .hgrc.''' | |
86 if self.blockignore: | 94 if self.blockignore: |
87 return False | 95 return False |
88 if not self.ignorefunc: | 96 if not self.ignorefunc: |
89 ignore = self.hgignore() | 97 ignore = self.hgignore() |
90 if ignore: | 98 if ignore: |
99 # FIXME: if there are errors in patterns, matcher will | |
100 # print out an error containing src ('.hgignore'); | |
101 # really, we want the original source file to be | |
102 # printed instead. | |
91 files, self.ignorefunc, anypats = util.matcher(self.root, | 103 files, self.ignorefunc, anypats = util.matcher(self.root, |
92 inc=ignore, | 104 inc=ignore, |
93 src='.hgignore') | 105 src='.hgignore') |
94 else: | 106 else: |
95 self.ignorefunc = util.never | 107 self.ignorefunc = util.never |