Skip to content

Commit

Permalink
prompt: clean up strbuf usage
Browse files Browse the repository at this point in the history
The do_askpass function inherited a few bad habits from the
original git_getpass. One, there's no need to strbuf_reset a
buffer which was just initialized. And two, it's a good
habit to use strbuf_detach to claim ownership of a buffer's
string (even though in this case the owning buffer goes out
of scope, so it's effectively the same thing).

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 Feb 3, 2012
1 parent 828ea97 commit 31b49d9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static char *do_askpass(const char *cmd, const char *prompt)
if (start_command(&pass))
exit(1);

strbuf_reset(&buffer);
if (strbuf_read(&buffer, pass.out, 20) < 0)
die("failed to get '%s' from %s\n", prompt, cmd);

Expand All @@ -32,7 +31,7 @@ static char *do_askpass(const char *cmd, const char *prompt)

strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));

return buffer.buf;
return strbuf_detach(&buffer, NULL);
}

char *git_prompt(const char *prompt, int flags)
Expand Down

0 comments on commit 31b49d9

Please sign in to comment.