Thread (253 messages) 253 messages, 6 authors, 14h ago

Re: [PATCH v22 1/7] branch: add --forked filter for --list mode

From: Junio C Hamano <hidden>
Date: 2026-07-25 04:16:53

"Harald Nordgren via GitGitGadget" [off-list ref] writes:
quoted hunk ↗ jump to hunk
diff --git a/ref-filter.c b/ref-filter.c
index 284796c49b..cbdac1a19a 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2744,6 +2744,72 @@ static int filter_exclude_match(struct ref_filter *filter, const char *refname)
 	return match_pattern(filter->exclude.v, refname, filter->ignore_case);
 }
 
+static const char *short_upstream_name(const char *full_ref)
+{
+	const char *short_name = full_ref;
+	(void)(skip_prefix(short_name, "refs/heads/", &short_name) ||
+	       skip_prefix(short_name, "refs/remotes/", &short_name));
+	return short_name;
+}
It is a bit tricky to read the above, which is equivalent to this

	if (!skip_prefix(short_name, "refs/heads/", &short_name))
		skip_prefix(short_name, "refs/remotes/", &short_name);
	return short_name;

which is written in a more dumb way.

Unless we are going to add more "if the string does not begin with
this prefix, try this other one" to the cascade, the dumb "try
stripping local branch prefix, if not, try the remote-tracking
branch prefix" way might be easier to understand.
+/*
+ * Match the configured upstream of a branch against the registered
+ * --forked patterns. Exact patterns are compared against the full
+ * upstream refname so they are unambiguous; glob patterns are matched
+ * against the abbreviated upstream so that a glob such as origin/...
+ * works as typed.
+ */
+static int filter_forked_match(struct ref_filter *filter, const char *refname)
+{
+	const char *short_name;
+	struct branch *branch;
+	const char *upstream;
+	int i;
+
+	if (!skip_prefix(refname, "refs/heads/", &short_name))
+		return 0;
+	branch = branch_get(short_name);
+	if (!branch)
+		return 0;
+	upstream = branch_get_upstream(branch, NULL);
+	if (!upstream)
+		return 0;
+
+	for (i = 0; i < filter->forked.nr; i++) {
The 'filter->forked' member is added by this patch and of type
'struct strvec', filter->forked.nr is of type 'size_t'.  And 'i',
which is of type 'int', is compared with it.
quoted hunk ↗ jump to hunk
diff --git a/ref-filter.h b/ref-filter.h
index 120221b47f..9361296e2a 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -67,6 +67,7 @@ struct ref_filter {
 	const char **name_patterns;
 	const char *start_after;
 	struct strvec exclude;
+	struct strvec forked;
 	struct oid_array points_at;
 	struct commit_list *with_commit;
 	struct commit_list *no_commit;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help