1180
const char *name_for_errormsg;
1181
};
1182
1183
+static int ref_excluded(struct rev_info *revs, const char *path)
1184
+{
1185
+ struct string_list_item *item;
1186
+
1187
+ if (!revs->ref_excludes)
1188
+ return 0;
1189
+ for_each_string_list_item(item, revs->ref_excludes) {
1190
+ if (!fnmatch(item->string, path, 0))
1191
+ return 1;
1192
+ }
1193
+ return 0;
1194
+}
1195
+
1196
static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
1197
{
1198
struct all_refs_cb *cb = cb_data;
1186
- struct object *object = get_reference(cb->all_revs, path, sha1,
1187
- cb->all_flags);
1199
+ struct object *object;
1200
+
1201
+ if (ref_excluded(cb->all_revs, path))
1202
+ return 0;
1203
+
1204
+ object = get_reference(cb->all_revs, path, sha1, cb->all_flags);
1205
add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
1206
add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags);
1207
return 0;
1214
cb->all_flags = flags;
1215
}
1216
1217
+static void clear_ref_exclusion(struct rev_info *revs)
1218
+{
1219
+ if (revs->ref_excludes) {
1220
+ string_list_clear(revs->ref_excludes, 0);
1221
+ free(revs->ref_excludes);
1222
+ }
1223
+ revs->ref_excludes = NULL;
1224
+}
1225
+
1226
+static void add_ref_exclusion(struct rev_info *revs, const char *exclude)
1227
+{
1228
+ if (!revs->ref_excludes) {
1229
+ revs->ref_excludes = xcalloc(1, sizeof(*revs->ref_excludes));
1230
+ revs->ref_excludes->strdup_strings = 1;
1231
+ }
1232
+ string_list_append(revs->ref_excludes, exclude);
1233
+}
1234
+
1235
static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
1236
int (*for_each)(const char *, each_ref_fn, void *))
1237
{
1988
if (!strcmp(arg, "--all")) {
1989
handle_refs(submodule, revs, *flags, for_each_ref_submodule);
1990
handle_refs(submodule, revs, *flags, head_ref_submodule);
1991
+ clear_ref_exclusion(revs);
1992
} else if (!strcmp(arg, "--branches")) {
1993
handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
1994
+ clear_ref_exclusion(revs);
1995
} else if (!strcmp(arg, "--bisect")) {
1996
handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
1997
handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);
1998
revs->bisect = 1;
1999
} else if (!strcmp(arg, "--tags")) {
2000
handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);
2001
+ clear_ref_exclusion(revs);
2002
} else if (!strcmp(arg, "--remotes")) {
2003
handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);
2004
+ clear_ref_exclusion(revs);
2005
} else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
2006
struct all_refs_cb cb;
2007
init_all_refs_cb(&cb, revs, *flags);
2008
for_each_glob_ref(handle_one_ref, optarg, &cb);
2009
+ clear_ref_exclusion(revs);
2010
+ return argcount;
2011
+ } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
2012
+ add_ref_exclusion(revs, optarg);
2013
return argcount;
2014
} else if (!prefixcmp(arg, "--branches=")) {
2015
struct all_refs_cb cb;
2016
init_all_refs_cb(&cb, revs, *flags);
2017
for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
2018
+ clear_ref_exclusion(revs);
2019
} else if (!prefixcmp(arg, "--tags=")) {
2020
struct all_refs_cb cb;
2021
init_all_refs_cb(&cb, revs, *flags);
2022
for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
2023
+ clear_ref_exclusion(revs);
2024
} else if (!prefixcmp(arg, "--remotes=")) {
2025
struct all_refs_cb cb;
2026
init_all_refs_cb(&cb, revs, *flags);
2027
for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
2028
+ clear_ref_exclusion(revs);
2029
} else if (!strcmp(arg, "--reflog")) {
2030
handle_reflog(revs, *flags);
2031
} else if (!strcmp(arg, "--not")) {