Thread (9 messages) flat view 9 messages, 3 authors, 2016-06-15
DORMANTno replies

[PATCH 1/2] prompt: clean up strbuf usage

From: Jeff King <hidden>
Date: 2016-06-15 22:52:56
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
Neither is a big deal, but just some style cleanups while I was in the
area.

 prompt.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/prompt.c b/prompt.c
index 72ab9de..64f817b 100644
--- a/prompt.c
+++ b/prompt.c
@@ -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);
 
@@ -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)
-- 
1.7.9.rc1.28.gf4be5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help