Skip to content

Commit

Permalink
remote.c: drop extraneous local variable from migrate_file
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Aug 10, 2015
1 parent e3cf230 commit b21a5d6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions builtin/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ static int migrate_file(struct remote *remote)
{
struct strbuf buf = STRBUF_INIT;
int i;
const char *path = NULL;

strbuf_addf(&buf, "remote.%s.url", remote->name);
for (i = 0; i < remote->url_nr; i++)
Expand All @@ -601,11 +600,9 @@ static int migrate_file(struct remote *remote)
return error(_("Could not append '%s' to '%s'"),
remote->fetch_refspec[i], buf.buf);
if (remote->origin == REMOTE_REMOTES)
path = git_path("remotes/%s", remote->name);
unlink_or_warn(git_path("remotes/%s", remote->name));
else if (remote->origin == REMOTE_BRANCHES)
path = git_path("branches/%s", remote->name);
if (path)
unlink_or_warn(path);
unlink_or_warn(git_path("branches/%s", remote->name));
return 0;
}

Expand Down

0 comments on commit b21a5d6

Please sign in to comment.