git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kristian Høgsberg" <krh@redhat.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, "Kristian Høgsberg" <krh@redhat.com>
Subject: [PATCH] Use a strbuf for copying the command line for the reflog.
Date: Tue,  4 Dec 2007 02:25:46 -0500	[thread overview]
Message-ID: <1196753147-20073-1-git-send-email-krh@redhat.com> (raw)

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
 builtin-fetch.c |   24 ++++++++----------------
 1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/builtin-fetch.c b/builtin-fetch.c
index de9947e..f6d16fe 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -14,7 +14,7 @@ static const char fetch_usage[] = "git-fetch [-a | --append] [--upload-pack <upl
 
 static int append, force, tags, no_tags, update_head_ok, verbose, quiet;
 static const char *depth;
-static char *default_rla = NULL;
+static struct strbuf default_rla = STRBUF_INIT;
 static struct transport *transport;
 
 static void unlock_pack(void)
@@ -142,7 +142,7 @@ static int s_update_ref(const char *action,
 	static struct ref_lock *lock;
 
 	if (!rla)
-		rla = default_rla;
+		rla = default_rla.buf;
 	snprintf(msg, sizeof(msg), "%s: %s", rla, action);
 	lock = lock_any_ref_for_update(ref->name,
 				       check_old ? ref->old_sha1 : NULL, 0);
@@ -543,16 +543,19 @@ static void set_option(const char *name, const char *value)
 int cmd_fetch(int argc, const char **argv, const char *prefix)
 {
 	struct remote *remote;
-	int i, j, rla_offset;
+	int i;
 	static const char **refs = NULL;
 	int ref_nr = 0;
-	int cmd_len = 0;
 	const char *upload_pack = NULL;
 	int keep = 0;
 
+	/* Record the command line for the reflog */
+	strbuf_addstr(&default_rla, "fetch");
+	for (i = 1; i < argc; i++)
+		strbuf_addf(&default_rla, " %s", argv[i]);
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
-		cmd_len += strlen(arg);
 
 		if (arg[0] != '-')
 			break;
@@ -613,17 +616,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 		usage(fetch_usage);
 	}
 
-	for (j = i; j < argc; j++)
-		cmd_len += strlen(argv[j]);
-
-	default_rla = xmalloc(cmd_len + 5 + argc + 1);
-	sprintf(default_rla, "fetch");
-	rla_offset = strlen(default_rla);
-	for (j = 1; j < argc; j++) {
-		sprintf(default_rla + rla_offset, " %s", argv[j]);
-		rla_offset += strlen(argv[j]) + 1;
-	}
-
 	if (i == argc)
 		remote = remote_get(NULL);
 	else
-- 
1.5.3.4

             reply	other threads:[~2007-12-04  6:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-04  7:25 Kristian Høgsberg [this message]
2007-12-04  7:25 ` [PATCH] Rewrite builtin-fetch option parsing to use parse_options() Kristian Høgsberg
2007-12-04 15:46 ` [PATCH] Use a strbuf for copying the command line for the reflog Kristian Høgsberg

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=1196753147-20073-1-git-send-email-krh@redhat.com \
    --to=krh@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).