@@ -1533,20 +1533,34 @@ static void add_rev_cmdline_list(struct rev_info *revs,
}
}
-int ref_excluded(const struct ref_visibility *visibility, const char *path)
+static int ref_matched(struct string_list refs, const char *path)
{
- const char *stripped_path = strip_namespace(path);
struct string_list_item *item;
- for_each_string_list_item(item, &visibility->excluded_refs) {
+ for_each_string_list_item(item, &refs)
if (!wildmatch(item->string, path, 0))
return 1;
- }
- if (ref_is_hidden(stripped_path, path, &visibility->hidden_refs))
+ return 0;
+}
+
+int ref_excluded(const struct ref_visibility *visibility, const char *path)
+{
+ if (ref_is_hidden(strip_namespace(path), path, &visibility->hidden_refs))
return 1;
- return 0;
+ return ref_matched(visibility->excluded_refs, path);
+}
+
+int ref_visible(const struct ref_visibility *visibility, const char *path)
+{
+ if (ref_is_hidden(strip_namespace(path), path, &visibility->hidden_refs))
+ return 0;
+
+ if (ref_matched(visibility->excluded_refs, path))
+ return 0;
+
+ return ref_matched(visibility->included_refs, path);
}
void init_ref_visibility(struct ref_visibility *visibility)
@@ -1558,6 +1572,7 @@ void init_ref_visibility(struct ref_visibility *visibility)
void clear_ref_visibility(struct ref_visibility *visibility)
{
string_list_clear(&visibility->excluded_refs, 0);
+ string_list_clear(&visibility->included_refs, 0);
string_list_clear(&visibility->hidden_refs, 0);
visibility->hidden_refs_configured = 0;
}
@@ -1567,6 +1582,11 @@ void add_ref_exclusion(struct ref_visibility *visibility, const char *exclude)
string_list_append(&visibility->excluded_refs, exclude);
}
+void add_ref_inclusion(struct ref_visibility *visibility, const char *include)
+{
+ string_list_append(&visibility->included_refs, include);
+}
+
struct exclude_hidden_refs_cb {
struct ref_visibility *visibility;
const char *section;
@@ -91,6 +91,12 @@ struct ref_visibility {
*/
struct string_list excluded_refs;
+ /*
+ * Included refs is a list of wildmatch patterns. If any of the
+ * patterns match, the reference will be included.
+ */
+ struct string_list included_refs;
+
/*
* Hidden refs is a list of patterns that is to be hidden via
* `ref_is_hidden()`.
@@ -110,6 +116,7 @@ struct ref_visibility {
*/
#define REF_VISIBILITY_INIT { \
.excluded_refs = STRING_LIST_INIT_DUP, \
+ .included_refs = STRING_LIST_INIT_DUP, \
.hidden_refs = STRING_LIST_INIT_DUP, \
}
@@ -485,12 +492,22 @@ void show_object_with_name(FILE *, struct object *, const char *);
/**
* Helpers to check if a reference should be excluded.
+ *
+ * ref_excluded() checks if a ref has been explicitly excluded either
+ * because it is hidden, or it was added via an add_ref_exclusion() call.
+ *
+ * ref_visible() checks if a ref is visible by taking into account whether a ref
+ * has been included via an add_ref_inclusion() call, but also whether it has
+ * been excluded via add_ref_exclusion(). Exclusions take precedence. If a ref
+ * is hidden, it will also be treated as not visible.
+ *
*/
-
-int ref_excluded(const struct ref_visibility *exclusions, const char *path);
+int ref_excluded(const struct ref_visibility *visibility, const char *path);
+int ref_visible(const struct ref_visibility *visibility, const char *path);
void init_ref_visibility(struct ref_visibility *);
void clear_ref_visibility(struct ref_visibility *);
void add_ref_exclusion(struct ref_visibility *, const char *exclude);
+void add_ref_inclusion(struct ref_visibility *, const char *include);
void exclude_hidden_refs(struct ref_visibility *, const char *section);
/**