@matheusbsbs / matheus-bagliano / commits / af8ccd8ade
Fork 0

remote: drop "explicit" parameter from remote_ref_for_branch()

Commit 9700fae5ee (for-each-ref: let upstream/push report the remote ref name, 2017-11-07) added a remote_ref_for_branch() helper, which is modeled after remote_for_branch(). This includes providing an "explicit" out-parameter that tells the caller whether the remote was configured by the user, or whether we picked a default name like "origin". But unlike remote names, there is no default name when the user didn't configure one. The only way the "explicit" parameter is used by the caller is to use the value returned from the helper when it is set, and use an empty string otherwise, ignoring the returned value from the helper. Let's drop the "explicit" out-parameter, and return NULL when the returned value from the helper should be ignored, to simplify the function interface. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Damien Robert <damien.olivier.robert+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 3, 2020 at 17:12 UTC af8ccd8ade1e2dd1bf332067b98dd4459e29c1d3
3 files changed +5 -15
ref-filter.c
+2 -4
@@ -1459,12 +1459,10 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
1459 remote_for_branch(branch, &explicit);
1460 *s = xstrdup(explicit ? remote : "");
1461 } else if (atom->u.remote_ref.option == RR_REMOTE_REF) {
1462 - int explicit;
1462 const char *merge;
1463
1465 - merge = remote_ref_for_branch(branch, atom->u.remote_ref.push,
1466 - &explicit);
1467 - *s = xstrdup(explicit ? merge : "");
1464 + merge = remote_ref_for_branch(branch, atom->u.remote_ref.push);
1465 + *s = xstrdup(merge ? merge : "");
1466 } else
1467 BUG("unhandled RR_* enum");
1468 }
remote.c
+2 -9
@@ -516,14 +516,11 @@ const char *pushremote_for_branch(struct branch *branch, int *explicit)
516 return remote_for_branch(branch, explicit);
517 }
518
519 -const char *remote_ref_for_branch(struct branch *branch, int for_push,
520 - int *explicit)
519 +const char *remote_ref_for_branch(struct branch *branch, int for_push)
520 {
521 if (branch) {
522 if (!for_push) {
523 if (branch->merge_nr) {
525 - if (explicit)
526 - *explicit = 1;
524 return branch->merge_name[0];
525 }
526 } else {
@@ -534,15 +531,11 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push,
531 if (remote && remote->push.nr &&
532 (dst = apply_refspecs(&remote->push,
533 branch->refname))) {
537 - if (explicit)
538 - *explicit = 1;
534 return dst;
535 }
536 }
537 }
543 - if (explicit)
544 - *explicit = 0;
545 - return "";
538 + return NULL;
539 }
540
541 static struct remote *remote_get_1(const char *name,
remote.h
+1 -2
@@ -261,8 +261,7 @@ struct branch {
261 struct branch *branch_get(const char *name);
262 const char *remote_for_branch(struct branch *branch, int *explicit);
263 const char *pushremote_for_branch(struct branch *branch, int *explicit);
264 -const char *remote_ref_for_branch(struct branch *branch, int for_push,
265 - int *explicit);
264 +const char *remote_ref_for_branch(struct branch *branch, int for_push);
265
266 /* returns true if the given branch has merge configuration given. */
267 int branch_has_merge_config(struct branch *branch);