git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Neal Groothuis <ngroot@lo-cal.org>
Cc: Feanil Patel <feanil@gmail.com>, git@vger.kernel.org
Subject: [PATCH 1/2] prompt: clean up strbuf usage
Date: Fri, 3 Feb 2012 17:14:11 -0500	[thread overview]
Message-ID: <20120203221411.GA8065@sigill.intra.peff.net> (raw)
In-Reply-To: <20120203213654.GD1890@sigill.intra.peff.net>

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>
---
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

  parent reply	other threads:[~2012-02-03 22:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-03 15:50 Push from an SSH Terminal Feanil Patel
2012-02-03 16:21 ` Neal Groothuis
2012-02-03 16:40   ` Feanil Patel
2012-02-03 17:10     ` Neal Groothuis
2012-02-03 21:36       ` Jeff King
2012-02-03 22:13         ` Jeff King
2012-02-03 22:14         ` Jeff King [this message]
2012-02-03 22:16         ` [PATCH 2/2] prompt: fall back to terminal if askpass fails Jeff King
2012-02-04  7:47         ` Push from an SSH Terminal Junio C Hamano
2012-02-04  8:09           ` Jeff King
2012-02-04  8:16             ` Junio C Hamano
2012-02-03 21:35 ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120203221411.GA8065@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=feanil@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ngroot@lo-cal.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).