@matheusbsbs / matheus-bagliano / commits / 2d324efad6
Fork 0

Use a strbuf for copying the command line for the reflog.

Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kristian Høgsberg committed Dec 4, 2007 at 02:25 UTC 2d324efad6a8f4808c5eec8fd299b79ab80a7ba3
1 file changed +8 -16
builtin-fetch.c
+8 -16
@@ -14,7 +14,7 @@ static const char fetch_usage[] = "git-fetch [-a | --append] [--upload-pack <upl
14
15 static int append, force, tags, no_tags, update_head_ok, verbose, quiet;
16 static const char *depth;
17 -static char *default_rla = NULL;
17 +static struct strbuf default_rla = STRBUF_INIT;
18 static struct transport *transport;
19
20 static void unlock_pack(void)
@@ -142,7 +142,7 @@ static int s_update_ref(const char *action,
142 static struct ref_lock *lock;
143
144 if (!rla)
145 - rla = default_rla;
145 + rla = default_rla.buf;
146 snprintf(msg, sizeof(msg), "%s: %s", rla, action);
147 lock = lock_any_ref_for_update(ref->name,
148 check_old ? ref->old_sha1 : NULL, 0);
@@ -543,16 +543,19 @@ static void set_option(const char *name, const char *value)
543 int cmd_fetch(int argc, const char **argv, const char *prefix)
544 {
545 struct remote *remote;
546 - int i, j, rla_offset;
546 + int i;
547 static const char **refs = NULL;
548 int ref_nr = 0;
549 - int cmd_len = 0;
549 const char *upload_pack = NULL;
550 int keep = 0;
551
552 + /* Record the command line for the reflog */
553 + strbuf_addstr(&default_rla, "fetch");
554 + for (i = 1; i < argc; i++)
555 + strbuf_addf(&default_rla, " %s", argv[i]);
556 +
557 for (i = 1; i < argc; i++) {
558 const char *arg = argv[i];
555 - cmd_len += strlen(arg);
559
560 if (arg[0] != '-')
561 break;
@@ -613,17 +616,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
616 usage(fetch_usage);
617 }
618
616 - for (j = i; j < argc; j++)
617 - cmd_len += strlen(argv[j]);
618 -
619 - default_rla = xmalloc(cmd_len + 5 + argc + 1);
620 - sprintf(default_rla, "fetch");
621 - rla_offset = strlen(default_rla);
622 - for (j = 1; j < argc; j++) {
623 - sprintf(default_rla + rla_offset, " %s", argv[j]);
624 - rla_offset += strlen(argv[j]) + 1;
625 - }
626 -
619 if (i == argc)
620 remote = remote_get(NULL);
621 else