Skip to content

Commit 08e6a7a

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 376d7f1 commit 08e6a7a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

builtin/remote.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static int mv(int argc, const char **argv, const char *prefix,
741741
old_remote_context = STRBUF_INIT;
742742
struct string_list remote_branches = STRING_LIST_INIT_DUP;
743743
struct rename_info rename;
744-
int refs_renamed_nr = 0, refspec_updated = 0;
744+
int refs_renamed_nr = 0, refspecs_need_update = 0;
745745
struct progress *progress = NULL;
746746
int result = 0;
747747

@@ -782,19 +782,23 @@ static int mv(int argc, const char **argv, const char *prefix,
782782
goto out;
783783
}
784784

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+
785791
if (oldremote->fetch.nr) {
786792
strbuf_reset(&buf);
787793
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
788794
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
789-
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
790795
for (int i = 0; i < oldremote->fetch.nr; i++) {
791796
char *ptr;
792797

793798
strbuf_reset(&buf2);
794799
strbuf_addstr(&buf2, oldremote->fetch.items[i].raw);
795800
ptr = strstr(buf2.buf, old_remote_context.buf);
796801
if (ptr) {
797-
refspec_updated = 1;
798802
strbuf_splice(&buf2,
799803
ptr-buf2.buf + strlen(":refs/remotes/"),
800804
strlen(rename.old_name), rename.new_name,
@@ -825,7 +829,7 @@ static int mv(int argc, const char **argv, const char *prefix,
825829
}
826830
}
827831

828-
if (!refspec_updated)
832+
if (!refspecs_need_update)
829833
goto out;
830834

831835
/*

0 commit comments

Comments
 (0)