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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jul 31, 2025 at 16:56 UTC
08e6a7add4678662d929718e8aa80d2505352cfd
1 file changed
+8
-4
builtin/remote.c
+8
-4
@@ -741,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix,
741
old_remote_context = STRBUF_INIT;
742
struct string_list remote_branches = STRING_LIST_INIT_DUP;
743
struct rename_info rename;
744
- int refs_renamed_nr = 0, refspec_updated = 0;
744
+ int refs_renamed_nr = 0, refspecs_need_update = 0;
745
struct progress *progress = NULL;
746
int result = 0;
747
@@ -782,11 +782,16 @@ static int mv(int argc, const char **argv, const char *prefix,
782
goto out;
783
}
784
785
+ strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
786
+
787
+ for (int i = 0; i < oldremote->fetch.nr && !refspecs_need_update; i++)
788
+ refspecs_need_update = !!strstr(oldremote->fetch.items[i].raw,
789
+ old_remote_context.buf);
790
+
791
if (oldremote->fetch.nr) {
792
strbuf_reset(&buf);
793
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
794
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
789
- strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
795
for (int i = 0; i < oldremote->fetch.nr; i++) {
796
char *ptr;
797
@@ -794,7 +799,6 @@ static int mv(int argc, const char **argv, const char *prefix,
799
strbuf_addstr(&buf2, oldremote->fetch.items[i].raw);
800
ptr = strstr(buf2.buf, old_remote_context.buf);
801
if (ptr) {
797
- refspec_updated = 1;
802
strbuf_splice(&buf2,
803
ptr-buf2.buf + strlen(":refs/remotes/"),
804
strlen(rename.old_name), rename.new_name,
@@ -825,7 +829,7 @@ static int mv(int argc, const char **argv, const char *prefix,
829
}
830
}
831
828
- if (!refspec_updated)
832
+ if (!refspecs_need_update)
833
goto out;
834
835
/*