Skip to content

Commit

Permalink
Use a strbuf for copying the command line for the reflog.
Browse files Browse the repository at this point in the history
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Kristian Høgsberg authored and Junio C Hamano committed Dec 4, 2007
1 parent 0240e21 commit 2d324ef
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d324ef

Please sign in to comment.