108
struct name_ref_data {
109
int tags_only;
110
int name_only;
111
- const char *ref_filter;
111
+ struct string_list ref_filters;
112
};
113
114
static struct tip_table {
150
if (data->tags_only && !starts_with(path, "refs/tags/"))
151
return 0;
152
153
- if (data->ref_filter) {
154
- switch (subpath_matches(path, data->ref_filter)) {
155
- case -1: /* did not match */
156
- return 0;
157
- case 0: /* matched fully */
158
- break;
159
- default: /* matched subpath */
160
- can_abbreviate_output = 1;
161
- break;
153
+ if (data->ref_filters.nr) {
154
+ struct string_list_item *item;
155
+ int matched = 0;
156
+
157
+ /* See if any of the patterns match. */
158
+ for_each_string_list_item(item, &data->ref_filters) {
159
+ /*
160
+ * Check all patterns even after finding a match, so
161
+ * that we can see if a match with a subpath exists.
162
+ * When a user asked for 'refs/tags/v*' and 'v1.*',
163
+ * both of which match, the user is showing her
164
+ * willingness to accept a shortened output by having
165
+ * the 'v1.*' in the acceptable refnames, so we
166
+ * shouldn't stop when seeing 'refs/tags/v1.4' matches
167
+ * 'refs/tags/v*'. We should show it as 'v1.4'.
168
+ */
169
+ switch (subpath_matches(path, item->string)) {
170
+ case -1: /* did not match */
171
+ break;
172
+ case 0: /* matched fully */
173
+ matched = 1;
174
+ break;
175
+ default: /* matched subpath */
176
+ matched = 1;
177
+ can_abbreviate_output = 1;
178
+ break;
179
+ }
180
}
181
+
182
+ /* If none of the patterns matched, stop now */
183
+ if (!matched)
184
+ return 0;
185
}
186
187
add_to_tip_table(oid->hash, path, can_abbreviate_output);
328
{
329
struct object_array revs = OBJECT_ARRAY_INIT;
330
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
309
- struct name_ref_data data = { 0, 0, NULL };
331
+ struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP };
332
struct option opts[] = {
333
OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
334
OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
313
- OPT_STRING(0, "refs", &data.ref_filter, N_("pattern"),
335
+ OPT_STRING_LIST(0, "refs", &data.ref_filters, N_("pattern"),
336
N_("only use refs matching <pattern>")),
337
OPT_GROUP(""),
338
OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),