Skip to content

Commit b21a5d6

Browse files
peffgitster
authored andcommitted
remote.c: drop extraneous local variable from migrate_file
It's an anti-pattern to assign the result of git_path to a variable, since other calls may reuse our buffer. In this case, we feed the result to unlink_or_warn immediately afterwards, so it's OK. However, it's nice to avoid assignment entirely, which makes it more obvious that there's no bug. We can just pass the result directly to unlink_or_warn, which is a known-simple function. As a bonus, the code flow is a little more obvious, as we eliminate an extra conditional (a reader does not have to wonder any more "under which circumstances is 'path' set?"). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3cf230 commit b21a5d6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

builtin/remote.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ static int migrate_file(struct remote *remote)
581581
{
582582
struct strbuf buf = STRBUF_INIT;
583583
int i;
584-
const char *path = NULL;
585584

586585
strbuf_addf(&buf, "remote.%s.url", remote->name);
587586
for (i = 0; i < remote->url_nr; i++)
@@ -601,11 +600,9 @@ static int migrate_file(struct remote *remote)
601600
return error(_("Could not append '%s' to '%s'"),
602601
remote->fetch_refspec[i], buf.buf);
603602
if (remote->origin == REMOTE_REMOTES)
604-
path = git_path("remotes/%s", remote->name);
603+
unlink_or_warn(git_path("remotes/%s", remote->name));
605604
else if (remote->origin == REMOTE_BRANCHES)
606-
path = git_path("branches/%s", remote->name);
607-
if (path)
608-
unlink_or_warn(path);
605+
unlink_or_warn(git_path("branches/%s", remote->name));
609606
return 0;
610607
}
611608

0 commit comments

Comments
 (0)