prompt: clean up strbuf usage
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>
Jeff King committed
Feb 3, 2012 at 17:14 UTC
31b49d9b653803e7c7fd18b21c8bdd86e3421668
1 file changed
+1
-2
prompt.c
+1
-2
@@ -21,7 +21,6 @@ static char *do_askpass(const char *cmd, const char *prompt)
21
if (start_command(&pass))
22
exit(1);
23
24
- strbuf_reset(&buffer);
24
if (strbuf_read(&buffer, pass.out, 20) < 0)
25
die("failed to get '%s' from %s\n", prompt, cmd);
26
@@ -32,7 +31,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
31
32
strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
33
35
- return buffer.buf;
34
+ return strbuf_detach(&buffer, NULL);
35
}
36
37
char *git_prompt(const char *prompt, int flags)