Skip to content

Commit 9ab9b5d

Browse files
rafascgitster
authored andcommitted
refs: fix some exclude patterns being ignored
`--exclude` from rev-list and rev-parse fails to exclude references if the next `--branches`, `--tags` or `--remotes` use the optional inclusive glob because those options are implemented as particular cases of `--glob=`, which itself requires that exclude patterns begin with 'refs/'. But it makes sense for `--branches=glob` and friends to be aware that exclusions patterns for them shouldn't be 'refs/<type>/' prefixed, the same way exclude patterns for `--branches` and friends (without the optional glob) already are. Let's record in 'refs.c:struct ref_filter' which context the exclude pattern is tied to, so refs.c:filter_refs() can decide if it should ignore the prefix when trying to match. Signed-off-by: Rafael Ascensão <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d55dca commit 9ab9b5d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

refs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ char *resolve_refdup(const char *refname, int resolve_flags,
217217
/* The argument to filter_refs */
218218
struct ref_filter {
219219
const char *pattern;
220+
const char *prefix;
220221
each_ref_fn *fn;
221222
void *cb_data;
222223
};
@@ -296,6 +297,8 @@ static int filter_refs(const char *refname, const struct object_id *oid,
296297

297298
if (wildmatch(filter->pattern, refname, 0))
298299
return 0;
300+
if (filter->prefix)
301+
skip_prefix(refname, filter->prefix, &refname);
299302
return filter->fn(refname, oid, flags, filter->cb_data);
300303
}
301304

@@ -458,6 +461,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
458461
}
459462

460463
filter.pattern = real_pattern.buf;
464+
filter.prefix = prefix;
461465
filter.fn = fn;
462466
filter.cb_data = cb_data;
463467
ret = for_each_ref(filter_refs, &filter);

t/t6018-rev-list-glob.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,51 +147,51 @@ test_expect_success 'rev-parse accumulates multiple --exclude' '
147147
compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
148148
'
149149

150-
test_expect_failure 'rev-parse --exclude=glob with --branches=glob' '
150+
test_expect_success 'rev-parse --exclude=glob with --branches=glob' '
151151
compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
152152
'
153153

154-
test_expect_failure 'rev-parse --exclude=glob with --tags=glob' '
154+
test_expect_success 'rev-parse --exclude=glob with --tags=glob' '
155155
compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
156156
'
157157

158-
test_expect_failure 'rev-parse --exclude=glob with --remotes=glob' '
158+
test_expect_success 'rev-parse --exclude=glob with --remotes=glob' '
159159
compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
160160
'
161161

162-
test_expect_failure 'rev-parse --exclude=ref with --branches=glob' '
162+
test_expect_success 'rev-parse --exclude=ref with --branches=glob' '
163163
compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
164164
'
165165

166-
test_expect_failure 'rev-parse --exclude=ref with --tags=glob' '
166+
test_expect_success 'rev-parse --exclude=ref with --tags=glob' '
167167
compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
168168
'
169169

170-
test_expect_failure 'rev-parse --exclude=ref with --remotes=glob' '
170+
test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
171171
compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
172172
'
173173

174-
test_expect_failure 'rev-list --exclude=glob with --branches=glob' '
174+
test_expect_success 'rev-list --exclude=glob with --branches=glob' '
175175
compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
176176
'
177177

178-
test_expect_failure 'rev-list --exclude=glob with --tags=glob' '
178+
test_expect_success 'rev-list --exclude=glob with --tags=glob' '
179179
compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
180180
'
181181

182-
test_expect_failure 'rev-list --exclude=glob with --remotes=glob' '
182+
test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
183183
compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
184184
'
185185

186-
test_expect_failure 'rev-list --exclude=ref with --branches=glob' '
186+
test_expect_success 'rev-list --exclude=ref with --branches=glob' '
187187
compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
188188
'
189189

190-
test_expect_failure 'rev-list --exclude=ref with --tags=glob' '
190+
test_expect_success 'rev-list --exclude=ref with --tags=glob' '
191191
compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
192192
'
193193

194-
test_expect_failure 'rev-list --exclude=ref with --remotes=glob' '
194+
test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
195195
compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
196196
'
197197

0 commit comments

Comments
 (0)