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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Jun 5, 2018 at 14:40 UTC
3c87aa946a9ffc31cf1355b11e63df7c3315a2f9
4 files changed
+15
-7
builtin/checkout.c
+7
-3
@@ -878,7 +878,8 @@ static int parse_branchname_arg(int argc, const char **argv,
878
int dwim_new_local_branch_ok,
879
struct branch_info *new_branch_info,
880
struct checkout_opts *opts,
881
- struct object_id *rev)
881
+ struct object_id *rev,
882
+ int *dwim_remotes_matched)
883
{
884
struct tree **source_tree = &opts->source_tree;
885
const char **new_branch = &opts->new_branch;
@@ -972,7 +973,8 @@ static int parse_branchname_arg(int argc, const char **argv,
973
recover_with_dwim = 0;
974
975
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);
978
if (remote) {
979
*new_branch = arg;
980
arg = remote;
@@ -1109,6 +1111,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1111
struct branch_info new_branch_info;
1112
char *conflict_style = NULL;
1113
int dwim_new_local_branch = 1;
1114
+ int dwim_remotes_matched = 0;
1115
struct option options[] = {
1116
OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
1117
OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
@@ -1219,7 +1222,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1222
opts.track == BRANCH_TRACK_UNSPECIFIED &&
1223
!opts.new_branch;
1224
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);
1227
argv += n;
1228
argc -= n;
1229
}
builtin/worktree.c
+2
-2
@@ -412,7 +412,7 @@ static const char *dwim_branch(const char *path, const char **new_branch)
412
if (guess_remote) {
413
struct object_id oid;
414
const char *remote =
415
- unique_tracking_name(*new_branch, &oid);
415
+ unique_tracking_name(*new_branch, &oid, NULL);
416
return remote;
417
}
418
return NULL;
@@ -484,7 +484,7 @@ static int add(int ac, const char **av, const char *prefix)
484
485
commit = lookup_commit_reference_by_name(branch);
486
if (!commit) {
487
- remote = unique_tracking_name(branch, &oid);
487
+ remote = unique_tracking_name(branch, &oid, NULL);
488
if (remote) {
489
new_branch = branch;
490
branch = remote;
checkout.c
+4
-1
@@ -32,12 +32,15 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
32
return 0;
33
}
34
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)
37
{
38
struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
39
cb_data.src_ref = xstrfmt("refs/heads/%s", name);
40
cb_data.dst_oid = oid;
41
for_each_remote(check_tracking_name, &cb_data);
42
+ if (dwim_remotes_matched)
43
+ *dwim_remotes_matched = cb_data.num_matches;
44
free(cb_data.src_ref);
45
if (cb_data.num_matches == 1)
46
return cb_data.dst_ref;
checkout.h
+2
-1
@@ -9,6 +9,7 @@
9
* exists, NULL otherwise.
10
*/
11
extern const char *unique_tracking_name(const char *name,
12
- struct object_id *oid);
12
+ struct object_id *oid,
13
+ int *dwim_remotes_matched);
14
15
#endif /* CHECKOUT_H */