Skip to content

Commit 31b49d9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 828ea97 commit 31b49d9

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

prompt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static char *do_askpass(const char *cmd, const char *prompt)
2121
if (start_command(&pass))
2222
exit(1);
2323

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

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

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

35-
return buffer.buf;
34+
return strbuf_detach(&buffer, NULL);
3635
}
3736

3837
char *git_prompt(const char *prompt, int flags)

0 commit comments

Comments
 (0)