Skip to content

Commit d5d284d

Browse files
jltoblergitster
authored andcommitted
remote: allow guess_remote_head() to suppress advice
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 <[email protected]> Acked-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683c54c commit d5d284d

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
16381638

16391639
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
16401640
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
1641-
fetch_map, 1);
1641+
fetch_map, REMOTE_GUESS_HEAD_ALL);
16421642
for (ref = matches; ref; ref = ref->next) {
16431643
string_list_append(&heads, strip_refshead(ref->name));
16441644
}

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
511511

512512
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
513513
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
514-
fetch_map, 1);
514+
fetch_map, REMOTE_GUESS_HEAD_ALL);
515515
for (ref = matches; ref; ref = ref->next)
516516
string_list_append(&states->heads, abbrev_branch(ref->name));
517517

remote.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ struct ref *get_local_heads(void)
22972297

22982298
struct ref *guess_remote_head(const struct ref *head,
22992299
const struct ref *refs,
2300-
int all)
2300+
unsigned flags)
23012301
{
23022302
const struct ref *r;
23032303
struct ref *list = NULL;
@@ -2315,8 +2315,10 @@ struct ref *guess_remote_head(const struct ref *head,
23152315
return copy_ref(find_ref_by_name(refs, head->symref));
23162316

23172317
/* If a remote branch exists with the default branch name, let's use it. */
2318-
if (!all) {
2319-
char *default_branch = repo_default_branch_name(the_repository, 0);
2318+
if (!(flags & REMOTE_GUESS_HEAD_ALL)) {
2319+
char *default_branch =
2320+
repo_default_branch_name(the_repository,
2321+
flags & REMOTE_GUESS_HEAD_QUIET);
23202322
char *ref = xstrfmt("refs/heads/%s", default_branch);
23212323

23222324
r = find_ref_by_name(refs, ref);
@@ -2339,7 +2341,7 @@ struct ref *guess_remote_head(const struct ref *head,
23392341
oideq(&r->old_oid, &head->old_oid)) {
23402342
*tail = copy_ref(r);
23412343
tail = &((*tail)->next);
2342-
if (!all)
2344+
if (!(flags & REMOTE_GUESS_HEAD_ALL))
23432345
break;
23442346
}
23452347
}

remote.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
387387
int show_divergence_advice);
388388

389389
struct ref *get_local_heads(void);
390+
390391
/*
391392
* Find refs from a list which are likely to be pointed to by the given HEAD
392-
* ref. If 'all' is false, returns the most likely ref; otherwise, returns a
393-
* list of all candidate refs. If no match is found (or 'head' is NULL),
394-
* returns NULL. All returns are newly allocated and should be freed.
393+
* ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
394+
* otherwise, return the most likely ref. If no match is found (or 'head' is
395+
* NULL), returns NULL. All returns are newly allocated and should be freed.
395396
*/
397+
#define REMOTE_GUESS_HEAD_ALL (1 << 0)
398+
#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
396399
struct ref *guess_remote_head(const struct ref *head,
397400
const struct ref *refs,
398-
int all);
401+
unsigned flags);
399402

400403
/* Return refs which no longer exist on remote */
401404
struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);

0 commit comments

Comments
 (0)