Mercurial > hg-git
comparison hggit/gitdirstate.py @ 1046:cf982a23e15c
gitdirstate: show pattern error in hgignore file as expected
Before this revision, invalid pattern in hgignore file causes
unintentional failure for UnboundLocalError of ignorefunc, if hggit is
used with Mercurial 3.5 or later.
In such case:
- checking source of invalid pattern at failure uses "pats" list for
hgignore files, but
- "pats" list is empty, if ignoremod is None (= Mercurial 3.5 or later)
- therefore, checking with matchmod.match() overlooks invalid pattern
Then, "return ignorefunc" is executed without assignment to
ignorefunc, and causes UnboundLocalError.
To show pattern error in hgignore file as expected even with Mercurial
3.5 or later, this revision puts '(FILE, ["include: FILE"])' tuples
into "pats" (to avoid code duplication, putting into allpats is
shared, too).
This makes checking source of invalid pattern at failure work as
expected for hgignore files.
Fixes #197
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 05 Aug 2017 02:13:11 +0900 |
parents | e3dab807e38c |
children | 94aaea5c65f7 |
comparison
equal
deleted
inserted
replaced
1045:c560ed4d5a55 | 1046:cf982a23e15c |
---|---|
73 def gignore(root, files, warn, extrapatterns=None): | 73 def gignore(root, files, warn, extrapatterns=None): |
74 allpats = [] | 74 allpats = [] |
75 pats = [] | 75 pats = [] |
76 if ignoremod: | 76 if ignoremod: |
77 pats = ignore.readpats(root, files, warn) | 77 pats = ignore.readpats(root, files, warn) |
78 for f, patlist in pats: | |
79 allpats.extend(patlist) | |
80 else: | 78 else: |
81 allpats.extend(['include:%s' % f for f in files]) | 79 pats = [(f, ['include:%s' % f]) for f in files] |
80 for f, patlist in pats: | |
81 allpats.extend(patlist) | |
82 | 82 |
83 if extrapatterns: | 83 if extrapatterns: |
84 allpats.extend(extrapatterns) | 84 allpats.extend(extrapatterns) |
85 if not allpats: | 85 if not allpats: |
86 return util.never | 86 return util.never |
89 except util.Abort: | 89 except util.Abort: |
90 for f, patlist in pats: | 90 for f, patlist in pats: |
91 try: | 91 try: |
92 matchmod.match(root, '', [], patlist) | 92 matchmod.match(root, '', [], patlist) |
93 except util.Abort, inst: | 93 except util.Abort, inst: |
94 if not ignoremod: | |
95 # in this case, patlist is ['include: FILE'], and | |
96 # inst[0] should already include FILE | |
97 raise | |
94 raise util.Abort('%s: %s' % (f, inst[0])) | 98 raise util.Abort('%s: %s' % (f, inst[0])) |
95 if extrapatterns: | 99 if extrapatterns: |
96 try: | 100 try: |
97 matchmod.match(root, '', [], extrapatterns) | 101 matchmod.match(root, '', [], extrapatterns) |
98 except util.Abort, inst: | 102 except util.Abort, inst: |