From: Patrick Steinhardt Date: Thu, 31 Jul 2025 14:56:52 +0000 (+0200) Subject: builtin/remote: determine whether refs need renaming early on X-Git-Tag: v2.52.0-rc0~190^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08e6a7add4678662d929718e8aa80d2505352cfd;p=thirdparty%2Fgit.git builtin/remote: determine whether refs need renaming early on When renaming a remote we may have to also rename remote refs in case the refspec changes. Pull out this computation into a separate loop. While that seems nonsensical right now, it'll help us in a subsequent commit where we will prepare the reference transaction before we rewrite the configuration. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/builtin/remote.c b/builtin/remote.c index f63c5eb888..34ddcaf5f6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -741,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix, old_remote_context = STRBUF_INIT; struct string_list remote_branches = STRING_LIST_INIT_DUP; struct rename_info rename; - int refs_renamed_nr = 0, refspec_updated = 0; + int refs_renamed_nr = 0, refspecs_need_update = 0; struct progress *progress = NULL; int result = 0; @@ -782,11 +782,16 @@ static int mv(int argc, const char **argv, const char *prefix, goto out; } + strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); + + for (int i = 0; i < oldremote->fetch.nr && !refspecs_need_update; i++) + refspecs_need_update = !!strstr(oldremote->fetch.items[i].raw, + old_remote_context.buf); + if (oldremote->fetch.nr) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); - strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); for (int i = 0; i < oldremote->fetch.nr; i++) { char *ptr; @@ -794,7 +799,6 @@ static int mv(int argc, const char **argv, const char *prefix, strbuf_addstr(&buf2, oldremote->fetch.items[i].raw); ptr = strstr(buf2.buf, old_remote_context.buf); if (ptr) { - refspec_updated = 1; strbuf_splice(&buf2, ptr-buf2.buf + strlen(":refs/remotes/"), strlen(rename.old_name), rename.new_name, @@ -825,7 +829,7 @@ static int mv(int argc, const char **argv, const char *prefix, } } - if (!refspec_updated) + if (!refspecs_need_update) goto out; /*