]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: allow `guess_remote_head()` to suppress advice
authorJustin Tobler <jltobler@gmail.com>
Tue, 25 Mar 2025 00:51:46 +0000 (19:51 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Mar 2025 23:09:27 +0000 (16:09 -0700)
The `repo_default_branch_name()` invoked through `guess_remote_head()`
is configured to always display the default branch advice message.

Adapt `guess_remote_head()` to accept flags and convert the `all`
parameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable
suppression of advice messages. Call sites are updated accordingly.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
builtin/remote.c
remote.c
remote.h

index 95fd0018b981fb83ebb8a15de9bff03c2d25a97c..763314bfcbe7ce572d12262ac4f3c0511571e808 100644 (file)
@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
 
        get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
        matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
-                                   fetch_map, 1);
+                                   fetch_map, REMOTE_GUESS_HEAD_ALL);
        for (ref = matches; ref; ref = ref->next) {
                string_list_append(&heads, strip_refshead(ref->name));
        }
index 1b7aad883807355e328e7f1ea34ecf5368b8db74..d2aeb5ba1fcd1e1a6b3a38c8ba7a0e6de443d2bf 100644 (file)
@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
 
        get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
        matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
-                                   fetch_map, 1);
+                                   fetch_map, REMOTE_GUESS_HEAD_ALL);
        for (ref = matches; ref; ref = ref->next)
                string_list_append(&states->heads, abbrev_branch(ref->name));
 
index e609cf5c56a77217d6316884440d6eaef5851bff..1db88beaf3dfab7447a29fcac3c763823728a812 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)
 
 struct ref *guess_remote_head(const struct ref *head,
                              const struct ref *refs,
-                             int all)
+                             unsigned flags)
 {
        const struct ref *r;
        struct ref *list = NULL;
@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,
                return copy_ref(find_ref_by_name(refs, head->symref));
 
        /* If a remote branch exists with the default branch name, let's use it. */
-       if (!all) {
-               char *default_branch = repo_default_branch_name(the_repository, 0);
+       if (!(flags & REMOTE_GUESS_HEAD_ALL)) {
+               char *default_branch =
+                       repo_default_branch_name(the_repository,
+                                                flags & REMOTE_GUESS_HEAD_QUIET);
                char *ref = xstrfmt("refs/heads/%s", default_branch);
 
                r = find_ref_by_name(refs, ref);
@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,
                    oideq(&r->old_oid, &head->old_oid)) {
                        *tail = copy_ref(r);
                        tail = &((*tail)->next);
-                       if (!all)
+                       if (!(flags & REMOTE_GUESS_HEAD_ALL))
                                break;
                }
        }
index 6be5031f64bec750ede6deaf6e6cd26eba04f37e..7e4943ae3a70ecefa3332d211084762ca30b59b6 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
                         int show_divergence_advice);
 
 struct ref *get_local_heads(void);
+
 /*
  * Find refs from a list which are likely to be pointed to by the given HEAD
- * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
- * list of all candidate refs. If no match is found (or 'head' is NULL),
- * returns NULL. All returns are newly allocated and should be freed.
+ * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
+ * otherwise, return the most likely ref. If no match is found (or 'head' is
+ * NULL), returns NULL. All returns are newly allocated and should be freed.
  */
+#define REMOTE_GUESS_HEAD_ALL  (1 << 0)
+#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
 struct ref *guess_remote_head(const struct ref *head,
                              const struct ref *refs,
-                             int all);
+                             unsigned flags);
 
 /* Return refs which no longer exist on remote */
 struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);