Skip to content

Commit 3c87aa9

Browse files
avargitster
authored andcommitted
checkout: pass the "num_matches" up to callers
Pass the previously added "num_matches" struct value up to the callers of unique_tracking_name(). This will allow callers to optionally print better error messages in a later change. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4d2d55 commit 3c87aa9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

builtin/checkout.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ static int parse_branchname_arg(int argc, const char **argv,
878878
int dwim_new_local_branch_ok,
879879
struct branch_info *new_branch_info,
880880
struct checkout_opts *opts,
881-
struct object_id *rev)
881+
struct object_id *rev,
882+
int *dwim_remotes_matched)
882883
{
883884
struct tree **source_tree = &opts->source_tree;
884885
const char **new_branch = &opts->new_branch;
@@ -972,7 +973,8 @@ static int parse_branchname_arg(int argc, const char **argv,
972973
recover_with_dwim = 0;
973974

974975
if (recover_with_dwim) {
975-
const char *remote = unique_tracking_name(arg, rev);
976+
const char *remote = unique_tracking_name(arg, rev,
977+
dwim_remotes_matched);
976978
if (remote) {
977979
*new_branch = arg;
978980
arg = remote;
@@ -1109,6 +1111,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11091111
struct branch_info new_branch_info;
11101112
char *conflict_style = NULL;
11111113
int dwim_new_local_branch = 1;
1114+
int dwim_remotes_matched = 0;
11121115
struct option options[] = {
11131116
OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
11141117
OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
@@ -1219,7 +1222,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
12191222
opts.track == BRANCH_TRACK_UNSPECIFIED &&
12201223
!opts.new_branch;
12211224
int n = parse_branchname_arg(argc, argv, dwim_ok,
1222-
&new_branch_info, &opts, &rev);
1225+
&new_branch_info, &opts, &rev,
1226+
&dwim_remotes_matched);
12231227
argv += n;
12241228
argc -= n;
12251229
}

builtin/worktree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static const char *dwim_branch(const char *path, const char **new_branch)
412412
if (guess_remote) {
413413
struct object_id oid;
414414
const char *remote =
415-
unique_tracking_name(*new_branch, &oid);
415+
unique_tracking_name(*new_branch, &oid, NULL);
416416
return remote;
417417
}
418418
return NULL;
@@ -484,7 +484,7 @@ static int add(int ac, const char **av, const char *prefix)
484484

485485
commit = lookup_commit_reference_by_name(branch);
486486
if (!commit) {
487-
remote = unique_tracking_name(branch, &oid);
487+
remote = unique_tracking_name(branch, &oid, NULL);
488488
if (remote) {
489489
new_branch = branch;
490490
branch = remote;

checkout.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
3232
return 0;
3333
}
3434

35-
const char *unique_tracking_name(const char *name, struct object_id *oid)
35+
const char *unique_tracking_name(const char *name, struct object_id *oid,
36+
int *dwim_remotes_matched)
3637
{
3738
struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
3839
cb_data.src_ref = xstrfmt("refs/heads/%s", name);
3940
cb_data.dst_oid = oid;
4041
for_each_remote(check_tracking_name, &cb_data);
42+
if (dwim_remotes_matched)
43+
*dwim_remotes_matched = cb_data.num_matches;
4144
free(cb_data.src_ref);
4245
if (cb_data.num_matches == 1)
4346
return cb_data.dst_ref;

checkout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* exists, NULL otherwise.
1010
*/
1111
extern const char *unique_tracking_name(const char *name,
12-
struct object_id *oid);
12+
struct object_id *oid,
13+
int *dwim_remotes_matched);
1314

1415
#endif /* CHECKOUT_H */

0 commit comments

Comments
 (0)