Merge branch 'jk/snprintf-cleanups'

Code clean-up.

* jk/snprintf-cleanups:
  daemon: use an argv_array to exec children
  gc: replace local buffer with git_path
  transport-helper: replace checked snprintf with xsnprintf
  convert unchecked snprintf into xsnprintf
  combine-diff: replace malloc/snprintf with xstrfmt
  replace unchecked snprintf calls with heap buffers
  receive-pack: print --pack-header directly into argv array
  name-rev: replace static buffer with strbuf
  create_branch: use xstrfmt for reflog message
  create_branch: move msg setup closer to point of use
  avoid using mksnpath for refs
  avoid using fixed PATH_MAX buffers for refs
  fetch: use heap buffer to format reflog
  tag: use strbuf to format tag header
  diff: avoid fixed-size buffer for patch-ids
  odb_mkstemp: use git_path_buf
  odb_mkstemp: write filename into strbuf
  do not check odb_mkstemp return value for errors
maint
Junio C Hamano 2017-04-16 23:29:26 -07:00
commit cb054eb264
28 changed files with 238 additions and 223 deletions

View File

@ -200,6 +200,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
{ {
struct commit_list *p; struct commit_list *p;
struct commit_dist *array = xcalloc(nr, sizeof(*array)); struct commit_dist *array = xcalloc(nr, sizeof(*array));
struct strbuf buf = STRBUF_INIT;
int cnt, i; int cnt, i;


for (p = list, cnt = 0; p; p = p->next) { for (p = list, cnt = 0; p; p = p->next) {
@ -217,17 +218,18 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
} }
QSORT(array, cnt, compare_commit_dist); QSORT(array, cnt, compare_commit_dist);
for (p = list, i = 0; i < cnt; i++) { for (p = list, i = 0; i < cnt; i++) {
char buf[100]; /* enough for dist=%d */
struct object *obj = &(array[i].commit->object); struct object *obj = &(array[i].commit->object);


snprintf(buf, sizeof(buf), "dist=%d", array[i].distance); strbuf_reset(&buf);
add_name_decoration(DECORATION_NONE, buf, obj); strbuf_addf(&buf, "dist=%d", array[i].distance);
add_name_decoration(DECORATION_NONE, buf.buf, obj);


p->item = array[i].commit; p->item = array[i].commit;
p = p->next; p = p->next;
} }
if (p) if (p)
p->next = NULL; p->next = NULL;
strbuf_release(&buf);
free(array); free(array);
return list; return list;
} }

View File

@ -234,7 +234,7 @@ void create_branch(const char *name, const char *start_name,
{ {
struct commit *commit; struct commit *commit;
unsigned char sha1[20]; unsigned char sha1[20];
char *real_ref, msg[PATH_MAX + 20]; char *real_ref;
struct strbuf ref = STRBUF_INIT; struct strbuf ref = STRBUF_INIT;
int forcing = 0; int forcing = 0;
int dont_change_ref = 0; int dont_change_ref = 0;
@ -290,19 +290,18 @@ void create_branch(const char *name, const char *start_name,
die(_("Not a valid branch point: '%s'."), start_name); die(_("Not a valid branch point: '%s'."), start_name);
hashcpy(sha1, commit->object.oid.hash); hashcpy(sha1, commit->object.oid.hash);


if (forcing)
snprintf(msg, sizeof msg, "branch: Reset to %s",
start_name);
else if (!dont_change_ref)
snprintf(msg, sizeof msg, "branch: Created from %s",
start_name);

if (reflog) if (reflog)
log_all_ref_updates = LOG_REFS_NORMAL; log_all_ref_updates = LOG_REFS_NORMAL;


if (!dont_change_ref) { if (!dont_change_ref) {
struct ref_transaction *transaction; struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
char *msg;

if (forcing)
msg = xstrfmt("branch: Reset to %s", start_name);
else
msg = xstrfmt("branch: Created from %s", start_name);


transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
@ -313,6 +312,7 @@ void create_branch(const char *name, const char *start_name,
die("%s", err.buf); die("%s", err.buf);
ref_transaction_free(transaction); ref_transaction_free(transaction);
strbuf_release(&err); strbuf_release(&err);
free(msg);
} }


if (real_ref && track) if (real_ref && track)

View File

@ -908,11 +908,10 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
static const char *unique_tracking_name(const char *name, struct object_id *oid) static const char *unique_tracking_name(const char *name, struct object_id *oid)
{ {
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 }; struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
char src_ref[PATH_MAX]; cb_data.src_ref = xstrfmt("refs/heads/%s", name);
snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
cb_data.src_ref = src_ref;
cb_data.dst_oid = oid; cb_data.dst_oid = oid;
for_each_remote(check_tracking_name, &cb_data); for_each_remote(check_tracking_name, &cb_data);
free(cb_data.src_ref);
if (cb_data.unique) if (cb_data.unique)
return cb_data.dst_ref; return cb_data.dst_ref;
free(cb_data.dst_ref); free(cb_data.dst_ref);

View File

@ -421,7 +421,7 @@ static int s_update_ref(const char *action,
struct ref *ref, struct ref *ref,
int check_old) int check_old)
{ {
char msg[1024]; char *msg;
char *rla = getenv("GIT_REFLOG_ACTION"); char *rla = getenv("GIT_REFLOG_ACTION");
struct ref_transaction *transaction; struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
@ -431,7 +431,7 @@ static int s_update_ref(const char *action,
return 0; return 0;
if (!rla) if (!rla)
rla = default_rla.buf; rla = default_rla.buf;
snprintf(msg, sizeof(msg), "%s: %s", rla, action); msg = xstrfmt("%s: %s", rla, action);


transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
@ -449,11 +449,13 @@ static int s_update_ref(const char *action,


ref_transaction_free(transaction); ref_transaction_free(transaction);
strbuf_release(&err); strbuf_release(&err);
free(msg);
return 0; return 0;
fail: fail:
ref_transaction_free(transaction); ref_transaction_free(transaction);
error("%s", err.buf); error("%s", err.buf);
strbuf_release(&err); strbuf_release(&err);
free(msg);
return df_conflict ? STORE_REF_ERROR_DF_CONFLICT return df_conflict ? STORE_REF_ERROR_DF_CONFLICT
: STORE_REF_ERROR_OTHER; : STORE_REF_ERROR_OTHER;
} }

View File

@ -135,8 +135,6 @@ static int too_many_loose_objects(void)
* distributed, we can check only one and get a reasonable * distributed, we can check only one and get a reasonable
* estimate. * estimate.
*/ */
char path[PATH_MAX];
const char *objdir = get_object_directory();
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
int auto_threshold; int auto_threshold;
@ -146,11 +144,7 @@ static int too_many_loose_objects(void)
if (gc_auto_threshold <= 0) if (gc_auto_threshold <= 0)
return 0; return 0;


if (sizeof(path) <= snprintf(path, sizeof(path), "%s/17", objdir)) { dir = opendir(git_path("objects/17"));
warning(_("insanely long object directory %.*s"), 50, objdir);
return 0;
}
dir = opendir(path);
if (!dir) if (!dir)
return 0; return 0;



View File

@ -307,14 +307,15 @@ static const char *open_pack_file(const char *pack_name)
if (from_stdin) { if (from_stdin) {
input_fd = 0; input_fd = 0;
if (!pack_name) { if (!pack_name) {
static char tmp_file[PATH_MAX]; struct strbuf tmp_file = STRBUF_INIT;
output_fd = odb_mkstemp(tmp_file, sizeof(tmp_file), output_fd = odb_mkstemp(&tmp_file,
"pack/tmp_pack_XXXXXX"); "pack/tmp_pack_XXXXXX");
pack_name = xstrdup(tmp_file); pack_name = strbuf_detach(&tmp_file, NULL);
} else } else {
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600); output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd < 0) if (output_fd < 0)
die_errno(_("unable to create '%s'"), pack_name); die_errno(_("unable to create '%s'"), pack_name);
}
nothread_data.pack_fd = output_fd; nothread_data.pack_fd = output_fd;
} else { } else {
input_fd = open(pack_name, O_RDONLY); input_fd = open(pack_name, O_RDONLY);
@ -1442,10 +1443,11 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
if (!from_stdin) { if (!from_stdin) {
printf("%s\n", sha1_to_hex(sha1)); printf("%s\n", sha1_to_hex(sha1));
} else { } else {
char buf[48]; struct strbuf buf = STRBUF_INIT;
int len = snprintf(buf, sizeof(buf), "%s\t%s\n",
report, sha1_to_hex(sha1)); strbuf_addf(&buf, "%s\t%s\n", report, sha1_to_hex(sha1));
write_or_die(1, buf, len); write_or_die(1, buf.buf, buf.len);
strbuf_release(&buf);


/* /*
* Let's just mimic git-unpack-objects here and write * Let's just mimic git-unpack-objects here and write

View File

@ -17,17 +17,19 @@ static const char * const ls_remote_usage[] = {
static int tail_match(const char **pattern, const char *path) static int tail_match(const char **pattern, const char *path)
{ {
const char *p; const char *p;
char pathbuf[PATH_MAX]; char *pathbuf;


if (!pattern) if (!pattern)
return 1; /* no restriction */ return 1; /* no restriction */


if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf)) pathbuf = xstrfmt("/%s", path);
return error("insanely long ref %.*s...", 20, path);
while ((p = *(pattern++)) != NULL) { while ((p = *(pattern++)) != NULL) {
if (!wildmatch(p, pathbuf, 0, NULL)) if (!wildmatch(p, pathbuf, 0, NULL)) {
free(pathbuf);
return 1; return 1;
}
} }
free(pathbuf);
return 0; return 0;
} }



View File

@ -238,10 +238,9 @@ static const char *get_exact_ref_match(const struct object *o)
return NULL; return NULL;
} }


/* returns a static buffer */ /* may return a constant string or use "buf" as scratch space */
static const char *get_rev_name(const struct object *o) static const char *get_rev_name(const struct object *o, struct strbuf *buf)
{ {
static char buffer[1024];
struct rev_name *n; struct rev_name *n;
struct commit *c; struct commit *c;


@ -258,10 +257,9 @@ static const char *get_rev_name(const struct object *o)
int len = strlen(n->tip_name); int len = strlen(n->tip_name);
if (len > 2 && !strcmp(n->tip_name + len - 2, "^0")) if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
len -= 2; len -= 2;
snprintf(buffer, sizeof(buffer), "%.*s~%d", len, n->tip_name, strbuf_reset(buf);
n->generation); strbuf_addf(buf, "%.*s~%d", len, n->tip_name, n->generation);

return buf->buf;
return buffer;
} }
} }


@ -271,10 +269,11 @@ static void show_name(const struct object *obj,
{ {
const char *name; const char *name;
const struct object_id *oid = &obj->oid; const struct object_id *oid = &obj->oid;
struct strbuf buf = STRBUF_INIT;


if (!name_only) if (!name_only)
printf("%s ", caller_name ? caller_name : oid_to_hex(oid)); printf("%s ", caller_name ? caller_name : oid_to_hex(oid));
name = get_rev_name(obj); name = get_rev_name(obj, &buf);
if (name) if (name)
printf("%s\n", name); printf("%s\n", name);
else if (allow_undefined) else if (allow_undefined)
@ -283,6 +282,7 @@ static void show_name(const struct object *obj,
printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
else else
die("cannot describe '%s'", oid_to_hex(oid)); die("cannot describe '%s'", oid_to_hex(oid));
strbuf_release(&buf);
} }


static char const * const name_rev_usage[] = { static char const * const name_rev_usage[] = {
@ -294,6 +294,7 @@ static char const * const name_rev_usage[] = {


static void name_rev_line(char *p, struct name_ref_data *data) static void name_rev_line(char *p, struct name_ref_data *data)
{ {
struct strbuf buf = STRBUF_INIT;
int forty = 0; int forty = 0;
char *p_start; char *p_start;
for (p_start = p; *p; p++) { for (p_start = p; *p; p++) {
@ -314,7 +315,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
struct object *o = struct object *o =
lookup_object(sha1); lookup_object(sha1);
if (o) if (o)
name = get_rev_name(o); name = get_rev_name(o, &buf);
} }
*(p+1) = c; *(p+1) = c;


@ -332,6 +333,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
/* flush */ /* flush */
if (p_start != p) if (p_start != p)
fwrite(p_start, p - p_start, 1, stdout); fwrite(p_start, p - p_start, 1, stdout);

strbuf_release(&buf);
} }


int cmd_name_rev(int argc, const char **argv, const char *prefix) int cmd_name_rev(int argc, const char **argv, const char *prefix)

View File

@ -554,7 +554,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
struct notes_tree *t; struct notes_tree *t;
unsigned char object[20], new_note[20]; unsigned char object[20], new_note[20];
const unsigned char *note; const unsigned char *note;
char logmsg[100]; char *logmsg;
const char * const *usage; const char * const *usage;
struct note_data d = { 0, 0, NULL, STRBUF_INIT }; struct note_data d = { 0, 0, NULL, STRBUF_INIT };
struct option options[] = { struct option options[] = {
@ -618,17 +618,16 @@ static int append_edit(int argc, const char **argv, const char *prefix)
write_note_data(&d, new_note); write_note_data(&d, new_note);
if (add_note(t, object, new_note, combine_notes_overwrite)) if (add_note(t, object, new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed"); die("BUG: combine_notes_overwrite failed");
snprintf(logmsg, sizeof(logmsg), "Notes added by 'git notes %s'", logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
argv[0]);
} else { } else {
fprintf(stderr, _("Removing note for object %s\n"), fprintf(stderr, _("Removing note for object %s\n"),
sha1_to_hex(object)); sha1_to_hex(object));
remove_note(t, object); remove_note(t, object);
snprintf(logmsg, sizeof(logmsg), "Notes removed by 'git notes %s'", logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
argv[0]);
} }
commit_notes(t, logmsg); commit_notes(t, logmsg);


free(logmsg);
free_note_data(&d); free_note_data(&d);
free_notes(t); free_notes(t);
return 0; return 0;

View File

@ -1634,12 +1634,17 @@ static const char *parse_pack_header(struct pack_header *hdr)


static const char *pack_lockfile; static const char *pack_lockfile;


static void push_header_arg(struct argv_array *args, struct pack_header *hdr)
{
argv_array_pushf(args, "--pack_header=%"PRIu32",%"PRIu32,
ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries));
}

static const char *unpack(int err_fd, struct shallow_info *si) static const char *unpack(int err_fd, struct shallow_info *si)
{ {
struct pack_header hdr; struct pack_header hdr;
const char *hdr_err; const char *hdr_err;
int status; int status;
char hdr_arg[38];
struct child_process child = CHILD_PROCESS_INIT; struct child_process child = CHILD_PROCESS_INIT;
int fsck_objects = (receive_fsck_objects >= 0 int fsck_objects = (receive_fsck_objects >= 0
? receive_fsck_objects ? receive_fsck_objects
@ -1653,9 +1658,6 @@ static const char *unpack(int err_fd, struct shallow_info *si)
close(err_fd); close(err_fd);
return hdr_err; return hdr_err;
} }
snprintf(hdr_arg, sizeof(hdr_arg),
"--pack_header=%"PRIu32",%"PRIu32,
ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));


if (si->nr_ours || si->nr_theirs) { if (si->nr_ours || si->nr_theirs) {
alt_shallow_file = setup_temporary_shallow(si->shallow); alt_shallow_file = setup_temporary_shallow(si->shallow);
@ -1679,7 +1681,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
tmp_objdir_add_as_alternate(tmp_objdir); tmp_objdir_add_as_alternate(tmp_objdir);


if (ntohl(hdr.hdr_entries) < unpack_limit) { if (ntohl(hdr.hdr_entries) < unpack_limit) {
argv_array_pushl(&child.args, "unpack-objects", hdr_arg, NULL); argv_array_push(&child.args, "unpack-objects");
push_header_arg(&child.args, &hdr);
if (quiet) if (quiet)
argv_array_push(&child.args, "-q"); argv_array_push(&child.args, "-q");
if (fsck_objects) if (fsck_objects)
@ -1697,8 +1700,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
} else { } else {
char hostname[256]; char hostname[256];


argv_array_pushl(&child.args, "index-pack", argv_array_pushl(&child.args, "index-pack", "--stdin", NULL);
"--stdin", hdr_arg, NULL); push_header_arg(&child.args, &hdr);


if (gethostname(hostname, sizeof(hostname))) if (gethostname(hostname, sizeof(hostname)))
xsnprintf(hostname, sizeof(hostname), "localhost"); xsnprintf(hostname, sizeof(hostname), "localhost");

View File

@ -93,26 +93,31 @@ typedef int (*each_replace_name_fn)(const char *name, const char *ref,
static int for_each_replace_name(const char **argv, each_replace_name_fn fn) static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
{ {
const char **p, *full_hex; const char **p, *full_hex;
char ref[PATH_MAX]; struct strbuf ref = STRBUF_INIT;
size_t base_len;
int had_error = 0; int had_error = 0;
struct object_id oid; struct object_id oid;


strbuf_addstr(&ref, git_replace_ref_base);
base_len = ref.len;

for (p = argv; *p; p++) { for (p = argv; *p; p++) {
if (get_oid(*p, &oid)) { if (get_oid(*p, &oid)) {
error("Failed to resolve '%s' as a valid ref.", *p); error("Failed to resolve '%s' as a valid ref.", *p);
had_error = 1; had_error = 1;
continue; continue;
} }
full_hex = oid_to_hex(&oid);
snprintf(ref, sizeof(ref), "%s%s", git_replace_ref_base, full_hex); strbuf_setlen(&ref, base_len);
/* read_ref() may reuse the buffer */ strbuf_addstr(&ref, oid_to_hex(&oid));
full_hex = ref + strlen(git_replace_ref_base); full_hex = ref.buf + base_len;
if (read_ref(ref, oid.hash)) {
if (read_ref(ref.buf, oid.hash)) {
error("replace ref '%s' not found.", full_hex); error("replace ref '%s' not found.", full_hex);
had_error = 1; had_error = 1;
continue; continue;
} }
if (fn(full_hex, ref, &oid)) if (fn(full_hex, ref.buf, &oid))
had_error = 1; had_error = 1;
} }
return had_error; return had_error;
@ -129,21 +134,18 @@ static int delete_replace_ref(const char *name, const char *ref,


static void check_ref_valid(struct object_id *object, static void check_ref_valid(struct object_id *object,
struct object_id *prev, struct object_id *prev,
char *ref, struct strbuf *ref,
int ref_size,
int force) int force)
{ {
if (snprintf(ref, ref_size, strbuf_reset(ref);
"%s%s", git_replace_ref_base, strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
oid_to_hex(object)) > ref_size - 1) if (check_refname_format(ref->buf, 0))
die("replace ref name too long: %.*s...", 50, ref); die("'%s' is not a valid ref name.", ref->buf);
if (check_refname_format(ref, 0))
die("'%s' is not a valid ref name.", ref);


if (read_ref(ref, prev->hash)) if (read_ref(ref->buf, prev->hash))
oidclr(prev); oidclr(prev);
else if (!force) else if (!force)
die("replace ref '%s' already exists", ref); die("replace ref '%s' already exists", ref->buf);
} }


static int replace_object_oid(const char *object_ref, static int replace_object_oid(const char *object_ref,
@ -154,7 +156,7 @@ static int replace_object_oid(const char *object_ref,
{ {
struct object_id prev; struct object_id prev;
enum object_type obj_type, repl_type; enum object_type obj_type, repl_type;
char ref[PATH_MAX]; struct strbuf ref = STRBUF_INIT;
struct ref_transaction *transaction; struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;


@ -167,16 +169,17 @@ static int replace_object_oid(const char *object_ref,
object_ref, typename(obj_type), object_ref, typename(obj_type),
replace_ref, typename(repl_type)); replace_ref, typename(repl_type));


check_ref_valid(object, &prev, ref, sizeof(ref), force); check_ref_valid(object, &prev, &ref, force);


transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, ref, repl->hash, prev.hash, ref_transaction_update(transaction, ref.buf, repl->hash, prev.hash,
0, NULL, &err) || 0, NULL, &err) ||
ref_transaction_commit(transaction, &err)) ref_transaction_commit(transaction, &err))
die("%s", err.buf); die("%s", err.buf);


ref_transaction_free(transaction); ref_transaction_free(transaction);
strbuf_release(&ref);
return 0; return 0;
} }


@ -280,7 +283,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
enum object_type type; enum object_type type;
struct object_id old, new, prev; struct object_id old, new, prev;
char ref[PATH_MAX]; struct strbuf ref = STRBUF_INIT;


if (get_oid(object_ref, &old) < 0) if (get_oid(object_ref, &old) < 0)
die("Not a valid object name: '%s'", object_ref); die("Not a valid object name: '%s'", object_ref);
@ -289,7 +292,8 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (type < 0) if (type < 0)
die("unable to get object type for %s", oid_to_hex(&old)); die("unable to get object type for %s", oid_to_hex(&old));


check_ref_valid(&old, &prev, ref, sizeof(ref), force); check_ref_valid(&old, &prev, &ref, force);
strbuf_release(&ref);


export_object(&old, type, raw, tmpfile); export_object(&old, type, raw, tmpfile);
if (launch_editor(tmpfile, NULL, NULL) < 0) if (launch_editor(tmpfile, NULL, NULL) < 0)

View File

@ -213,13 +213,14 @@ static int show_abbrev(const unsigned char *sha1, void *cb_data)


static void show_datestring(const char *flag, const char *datestr) static void show_datestring(const char *flag, const char *datestr)
{ {
static char buffer[100]; char *buffer;


/* date handling requires both flags and revs */ /* date handling requires both flags and revs */
if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS)) if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
return; return;
snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr)); buffer = xstrfmt("%s%lu", flag, approxidate(datestr));
show(buffer); show(buffer);
free(buffer);
} }


static int show_file(const char *arg, int output_prefix) static int show_file(const char *arg, int output_prefix)

View File

@ -72,25 +72,22 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
const void *cb_data) const void *cb_data)
{ {
const char **p; const char **p;
char ref[PATH_MAX]; struct strbuf ref = STRBUF_INIT;
int had_error = 0; int had_error = 0;
unsigned char sha1[20]; unsigned char sha1[20];


for (p = argv; *p; p++) { for (p = argv; *p; p++) {
if (snprintf(ref, sizeof(ref), "refs/tags/%s", *p) strbuf_reset(&ref);
>= sizeof(ref)) { strbuf_addf(&ref, "refs/tags/%s", *p);
error(_("tag name too long: %.*s..."), 50, *p); if (read_ref(ref.buf, sha1)) {
had_error = 1;
continue;
}
if (read_ref(ref, sha1)) {
error(_("tag '%s' not found."), *p); error(_("tag '%s' not found."), *p);
had_error = 1; had_error = 1;
continue; continue;
} }
if (fn(*p, ref, sha1, cb_data)) if (fn(*p, ref.buf, sha1, cb_data))
had_error = 1; had_error = 1;
} }
strbuf_release(&ref);
return had_error; return had_error;
} }


@ -231,26 +228,22 @@ static void create_tag(const unsigned char *object, const char *tag,
unsigned char *prev, unsigned char *result) unsigned char *prev, unsigned char *result)
{ {
enum object_type type; enum object_type type;
char header_buf[1024]; struct strbuf header = STRBUF_INIT;
int header_len;
char *path = NULL; char *path = NULL;


type = sha1_object_info(object, NULL); type = sha1_object_info(object, NULL);
if (type <= OBJ_NONE) if (type <= OBJ_NONE)
die(_("bad object type.")); die(_("bad object type."));


header_len = snprintf(header_buf, sizeof(header_buf), strbuf_addf(&header,
"object %s\n" "object %s\n"
"type %s\n" "type %s\n"
"tag %s\n" "tag %s\n"
"tagger %s\n\n", "tagger %s\n\n",
sha1_to_hex(object), sha1_to_hex(object),
typename(type), typename(type),
tag, tag,
git_committer_info(IDENT_STRICT)); git_committer_info(IDENT_STRICT));

if (header_len > sizeof(header_buf) - 1)
die(_("tag header too big."));


if (!opt->message_given) { if (!opt->message_given) {
int fd; int fd;
@ -288,7 +281,8 @@ static void create_tag(const unsigned char *object, const char *tag,
if (!opt->message_given && !buf->len) if (!opt->message_given && !buf->len)
die(_("no tag message?")); die(_("no tag message?"));


strbuf_insert(buf, 0, header_buf, header_len); strbuf_insert(buf, 0, header.buf, header.len);
strbuf_release(&header);


if (build_tag_object(buf, opt->sign, result) < 0) { if (build_tag_object(buf, opt->sign, result) < 0) {
if (path) if (path)

View File

@ -1675,9 +1675,12 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
extern void pack_report(void); extern void pack_report(void);


/* /*
* Create a temporary file rooted in the object database directory. * Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/ */
extern int odb_mkstemp(char *template, size_t limit, const char *pattern); extern int odb_mkstemp(struct strbuf *template, const char *pattern);


/* /*
* Generate the filename to be used for a pack file with checksum "sha1" and * Generate the filename to be used for a pack file with checksum "sha1" and

View File

@ -292,9 +292,10 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
enum object_type type; enum object_type type;


if (S_ISGITLINK(mode)) { if (S_ISGITLINK(mode)) {
blob = xmalloc(100); struct strbuf buf = STRBUF_INIT;
*size = snprintf(blob, 100, strbuf_addf(&buf, "Subproject commit %s\n", oid_to_hex(oid));
"Subproject commit %s\n", oid_to_hex(oid)); *size = buf.len;
blob = strbuf_detach(&buf, NULL);
} else if (is_null_oid(oid)) { } else if (is_null_oid(oid)) {
/* deleted blob */ /* deleted blob */
*size = 0; *size = 0;

View File

@ -449,46 +449,42 @@ static void copy_to_log(int fd)
fclose(fp); fclose(fp);
} }


static int run_service_command(const char **argv) static int run_service_command(struct child_process *cld)
{ {
struct child_process cld = CHILD_PROCESS_INIT; argv_array_push(&cld->args, ".");

cld->git_cmd = 1;
cld.argv = argv; cld->err = -1;
cld.git_cmd = 1; if (start_command(cld))
cld.err = -1;
if (start_command(&cld))
return -1; return -1;


close(0); close(0);
close(1); close(1);


copy_to_log(cld.err); copy_to_log(cld->err);


return finish_command(&cld); return finish_command(cld);
} }


static int upload_pack(void) static int upload_pack(void)
{ {
/* Timeout as string */ struct child_process cld = CHILD_PROCESS_INIT;
char timeout_buf[64]; argv_array_pushl(&cld.args, "upload-pack", "--strict", NULL);
const char *argv[] = { "upload-pack", "--strict", NULL, ".", NULL }; argv_array_pushf(&cld.args, "--timeout=%u", timeout);

return run_service_command(&cld);
argv[2] = timeout_buf;

snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
return run_service_command(argv);
} }


static int upload_archive(void) static int upload_archive(void)
{ {
static const char *argv[] = { "upload-archive", ".", NULL }; struct child_process cld = CHILD_PROCESS_INIT;
return run_service_command(argv); argv_array_push(&cld.args, "upload-archive");
return run_service_command(&cld);
} }


static int receive_pack(void) static int receive_pack(void)
{ {
static const char *argv[] = { "receive-pack", ".", NULL }; struct child_process cld = CHILD_PROCESS_INIT;
return run_service_command(argv); argv_array_push(&cld.args, "receive-pack");
return run_service_command(&cld);
} }


static struct daemon_service daemon_service[] = { static struct daemon_service daemon_service[] = {

68
diff.c
View File

@ -4570,6 +4570,19 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
data->patchlen += new_len; data->patchlen += new_len;
} }


static void patch_id_add_string(git_SHA_CTX *ctx, const char *str)
{
git_SHA1_Update(ctx, str, strlen(str));
}

static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)
{
/* large enough for 2^32 in octal */
char buf[12];
int len = xsnprintf(buf, sizeof(buf), "%06o", mode);
git_SHA1_Update(ctx, buf, len);
}

/* returns 0 upon success, and writes result into sha1 */ /* returns 0 upon success, and writes result into sha1 */
static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only) static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
{ {
@ -4577,7 +4590,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1,
int i; int i;
git_SHA_CTX ctx; git_SHA_CTX ctx;
struct patch_id_t data; struct patch_id_t data;
char buffer[PATH_MAX * 4 + 20];


git_SHA1_Init(&ctx); git_SHA1_Init(&ctx);
memset(&data, 0, sizeof(struct patch_id_t)); memset(&data, 0, sizeof(struct patch_id_t));
@ -4609,36 +4621,30 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1,


len1 = remove_space(p->one->path, strlen(p->one->path)); len1 = remove_space(p->one->path, strlen(p->one->path));
len2 = remove_space(p->two->path, strlen(p->two->path)); len2 = remove_space(p->two->path, strlen(p->two->path));
if (p->one->mode == 0) patch_id_add_string(&ctx, "diff--git");
len1 = snprintf(buffer, sizeof(buffer), patch_id_add_string(&ctx, "a/");
"diff--gita/%.*sb/%.*s" git_SHA1_Update(&ctx, p->one->path, len1);
"newfilemode%06o" patch_id_add_string(&ctx, "b/");
"---/dev/null" git_SHA1_Update(&ctx, p->two->path, len2);
"+++b/%.*s",
len1, p->one->path, if (p->one->mode == 0) {
len2, p->two->path, patch_id_add_string(&ctx, "newfilemode");
p->two->mode, patch_id_add_mode(&ctx, p->two->mode);
len2, p->two->path); patch_id_add_string(&ctx, "---/dev/null");
else if (p->two->mode == 0) patch_id_add_string(&ctx, "+++b/");
len1 = snprintf(buffer, sizeof(buffer), git_SHA1_Update(&ctx, p->two->path, len2);
"diff--gita/%.*sb/%.*s" } else if (p->two->mode == 0) {
"deletedfilemode%06o" patch_id_add_string(&ctx, "deletedfilemode");
"---a/%.*s" patch_id_add_mode(&ctx, p->one->mode);
"+++/dev/null", patch_id_add_string(&ctx, "---a/");
len1, p->one->path, git_SHA1_Update(&ctx, p->one->path, len1);
len2, p->two->path, patch_id_add_string(&ctx, "+++/dev/null");
p->one->mode, } else {
len1, p->one->path); patch_id_add_string(&ctx, "---a/");
else git_SHA1_Update(&ctx, p->one->path, len1);
len1 = snprintf(buffer, sizeof(buffer), patch_id_add_string(&ctx, "+++b/");
"diff--gita/%.*sb/%.*s" git_SHA1_Update(&ctx, p->two->path, len2);
"---a/%.*s" }
"+++b/%.*s",
len1, p->one->path,
len2, p->two->path,
len1, p->one->path,
len2, p->two->path);
git_SHA1_Update(&ctx, buffer, len1);


if (diff_header_only) if (diff_header_only)
continue; continue;

View File

@ -277,7 +277,7 @@ char *get_object_directory(void)
return git_object_dir; return git_object_dir;
} }


int odb_mkstemp(char *template, size_t limit, const char *pattern) int odb_mkstemp(struct strbuf *template, const char *pattern)
{ {
int fd; int fd;
/* /*
@ -285,18 +285,16 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
* restrictive except to remove write permission. * restrictive except to remove write permission.
*/ */
int mode = 0444; int mode = 0444;
snprintf(template, limit, "%s/%s", git_path_buf(template, "objects/%s", pattern);
get_object_directory(), pattern); fd = git_mkstemp_mode(template->buf, mode);
fd = git_mkstemp_mode(template, mode);
if (0 <= fd) if (0 <= fd)
return fd; return fd;


/* slow path */ /* slow path */
/* some mkstemp implementations erase template on failure */ /* some mkstemp implementations erase template on failure */
snprintf(template, limit, "%s/%s", git_path_buf(template, "objects/%s", pattern);
get_object_directory(), pattern); safe_create_leading_directories(template->buf);
safe_create_leading_directories(template); return xmkstemp_mode(template->buf, mode);
return xmkstemp_mode(template, mode);
} }


int odb_pack_keep(const char *name) int odb_pack_keep(const char *name)

View File

@ -890,14 +890,15 @@ static struct tree_content *dup_tree_content(struct tree_content *s)


static void start_packfile(void) static void start_packfile(void)
{ {
static char tmp_file[PATH_MAX]; struct strbuf tmp_file = STRBUF_INIT;
struct packed_git *p; struct packed_git *p;
struct pack_header hdr; struct pack_header hdr;
int pack_fd; int pack_fd;


pack_fd = odb_mkstemp(tmp_file, sizeof(tmp_file), pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
"pack/tmp_pack_XXXXXX"); FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
FLEX_ALLOC_STR(p, pack_name, tmp_file); strbuf_release(&tmp_file);

p->pack_fd = pack_fd; p->pack_fd = pack_fd;
p->do_not_close = 1; p->do_not_close = 1;
pack_file = sha1fd(pack_fd, p->pack_name); pack_file = sha1fd(pack_fd, p->pack_name);

4
grep.c
View File

@ -1171,7 +1171,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
} }
if (opt->linenum) { if (opt->linenum) {
char buf[32]; char buf[32];
snprintf(buf, sizeof(buf), "%d", lno); xsnprintf(buf, sizeof(buf), "%d", lno);
output_color(opt, buf, strlen(buf), opt->color_lineno); output_color(opt, buf, strlen(buf), opt->color_lineno);
output_sep(opt, sign); output_sep(opt, sign);
} }
@ -1653,7 +1653,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
opt->color_filename); opt->color_filename);
output_sep(opt, ':'); output_sep(opt, ':');
} }
snprintf(buf, sizeof(buf), "%u\n", count); xsnprintf(buf, sizeof(buf), "%u\n", count);
opt->output(opt, buf, strlen(buf)); opt->output(opt, buf, strlen(buf));
return 1; return 1;
} }

10
http.c
View File

@ -1366,9 +1366,9 @@ static int handle_curl_result(struct slot_results *results)
* FAILONERROR it is lost, so we can give only the numeric * FAILONERROR it is lost, so we can give only the numeric
* status code. * status code.
*/ */
snprintf(curl_errorstr, sizeof(curl_errorstr), xsnprintf(curl_errorstr, sizeof(curl_errorstr),
"The requested URL returned error: %ld", "The requested URL returned error: %ld",
results->http_code); results->http_code);
} }


if (results->curl_result == CURLE_OK) { if (results->curl_result == CURLE_OK) {
@ -1410,8 +1410,8 @@ int run_one_slot(struct active_request_slot *slot,
{ {
slot->results = results; slot->results = results;
if (!start_active_slot(slot)) { if (!start_active_slot(slot)) {
snprintf(curl_errorstr, sizeof(curl_errorstr), xsnprintf(curl_errorstr, sizeof(curl_errorstr),
"failed to start HTTP request"); "failed to start HTTP request");
return HTTP_START_FAILED; return HTTP_START_FAILED;
} }



View File

@ -964,7 +964,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f
int gai; int gai;
char portstr[6]; char portstr[6];


snprintf(portstr, sizeof(portstr), "%d", srvc->port); xsnprintf(portstr, sizeof(portstr), "%d", srvc->port);


memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;

View File

@ -508,18 +508,16 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
const char *filename, const char *filename,
uint16_t options) uint16_t options)
{ {
static char tmp_file[PATH_MAX];
static uint16_t default_version = 1; static uint16_t default_version = 1;
static uint16_t flags = BITMAP_OPT_FULL_DAG; static uint16_t flags = BITMAP_OPT_FULL_DAG;
struct strbuf tmp_file = STRBUF_INIT;
struct sha1file *f; struct sha1file *f;


struct bitmap_disk_header header; struct bitmap_disk_header header;


int fd = odb_mkstemp(tmp_file, sizeof(tmp_file), "pack/tmp_bitmap_XXXXXX"); int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");


if (fd < 0) f = sha1fd(fd, tmp_file.buf);
die_errno("unable to create '%s'", tmp_file);
f = sha1fd(fd, tmp_file);


memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)); memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
header.version = htons(default_version); header.version = htons(default_version);
@ -539,9 +537,11 @@ void bitmap_writer_finish(struct pack_idx_entry **index,


sha1close(f, NULL, CSUM_FSYNC); sha1close(f, NULL, CSUM_FSYNC);


if (adjust_shared_perm(tmp_file)) if (adjust_shared_perm(tmp_file.buf))
die_errno("unable to make temporary bitmap file readable"); die_errno("unable to make temporary bitmap file readable");


if (rename(tmp_file, filename)) if (rename(tmp_file.buf, filename))
die_errno("unable to rename temporary bitmap file to '%s'", filename); die_errno("unable to rename temporary bitmap file to '%s'", filename);

strbuf_release(&tmp_file);
} }

View File

@ -71,15 +71,15 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
f = sha1fd_check(index_name); f = sha1fd_check(index_name);
} else { } else {
if (!index_name) { if (!index_name) {
static char tmp_file[PATH_MAX]; struct strbuf tmp_file = STRBUF_INIT;
fd = odb_mkstemp(tmp_file, sizeof(tmp_file), "pack/tmp_idx_XXXXXX"); fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
index_name = xstrdup(tmp_file); index_name = strbuf_detach(&tmp_file, NULL);
} else { } else {
unlink(index_name); unlink(index_name);
fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
if (fd < 0)
die_errno("unable to create '%s'", index_name);
} }
if (fd < 0)
die_errno("unable to create '%s'", index_name);
f = sha1fd(fd, index_name); f = sha1fd(fd, index_name);
} }


@ -329,11 +329,11 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,


struct sha1file *create_tmp_packfile(char **pack_tmp_name) struct sha1file *create_tmp_packfile(char **pack_tmp_name)
{ {
char tmpname[PATH_MAX]; struct strbuf tmpname = STRBUF_INIT;
int fd; int fd;


fd = odb_mkstemp(tmpname, sizeof(tmpname), "pack/tmp_pack_XXXXXX"); fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = xstrdup(tmpname); *pack_tmp_name = strbuf_detach(&tmpname, NULL);
return sha1fd(fd, *pack_tmp_name); return sha1fd(fd, *pack_tmp_name);
} }



44
refs.c
View File

@ -429,29 +429,31 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
{ {
const char **p, *r; const char **p, *r;
int refs_found = 0; int refs_found = 0;
struct strbuf fullref = STRBUF_INIT;


*ref = NULL; *ref = NULL;
for (p = ref_rev_parse_rules; *p; p++) { for (p = ref_rev_parse_rules; *p; p++) {
char fullref[PATH_MAX];
unsigned char sha1_from_ref[20]; unsigned char sha1_from_ref[20];
unsigned char *this_result; unsigned char *this_result;
int flag; int flag;


this_result = refs_found ? sha1_from_ref : sha1; this_result = refs_found ? sha1_from_ref : sha1;
mksnpath(fullref, sizeof(fullref), *p, len, str); strbuf_reset(&fullref);
r = resolve_ref_unsafe(fullref, RESOLVE_REF_READING, strbuf_addf(&fullref, *p, len, str);
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
this_result, &flag); this_result, &flag);
if (r) { if (r) {
if (!refs_found++) if (!refs_found++)
*ref = xstrdup(r); *ref = xstrdup(r);
if (!warn_ambiguous_refs) if (!warn_ambiguous_refs)
break; break;
} else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD")) { } else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) {
warning("ignoring dangling symref %s.", fullref); warning("ignoring dangling symref %s.", fullref.buf);
} else if ((flag & REF_ISBROKEN) && strchr(fullref, '/')) { } else if ((flag & REF_ISBROKEN) && strchr(fullref.buf, '/')) {
warning("ignoring broken ref %s.", fullref); warning("ignoring broken ref %s.", fullref.buf);
} }
} }
strbuf_release(&fullref);
return refs_found; return refs_found;
} }


@ -460,21 +462,22 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
char *last_branch = substitute_branch_name(&str, &len); char *last_branch = substitute_branch_name(&str, &len);
const char **p; const char **p;
int logs_found = 0; int logs_found = 0;
struct strbuf path = STRBUF_INIT;


*log = NULL; *log = NULL;
for (p = ref_rev_parse_rules; *p; p++) { for (p = ref_rev_parse_rules; *p; p++) {
unsigned char hash[20]; unsigned char hash[20];
char path[PATH_MAX];
const char *ref, *it; const char *ref, *it;


mksnpath(path, sizeof(path), *p, len, str); strbuf_reset(&path);
ref = resolve_ref_unsafe(path, RESOLVE_REF_READING, strbuf_addf(&path, *p, len, str);
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
hash, NULL); hash, NULL);
if (!ref) if (!ref)
continue; continue;
if (reflog_exists(path)) if (reflog_exists(path.buf))
it = path; it = path.buf;
else if (strcmp(ref, path) && reflog_exists(ref)) else if (strcmp(ref, path.buf) && reflog_exists(ref))
it = ref; it = ref;
else else
continue; continue;
@ -485,6 +488,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
if (!warn_ambiguous_refs) if (!warn_ambiguous_refs)
break; break;
} }
strbuf_release(&path);
free(last_branch); free(last_branch);
return logs_found; return logs_found;
} }
@ -944,6 +948,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
static char **scanf_fmts; static char **scanf_fmts;
static int nr_rules; static int nr_rules;
char *short_name; char *short_name;
struct strbuf resolved_buf = STRBUF_INIT;


if (!nr_rules) { if (!nr_rules) {
/* /*
@ -1002,7 +1007,6 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
*/ */
for (j = 0; j < rules_to_fail; j++) { for (j = 0; j < rules_to_fail; j++) {
const char *rule = ref_rev_parse_rules[j]; const char *rule = ref_rev_parse_rules[j];
char refname[PATH_MAX];


/* skip matched rule */ /* skip matched rule */
if (i == j) if (i == j)
@ -1013,9 +1017,10 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
* (with this previous rule) to a valid ref * (with this previous rule) to a valid ref
* read_ref() returns 0 on success * read_ref() returns 0 on success
*/ */
mksnpath(refname, sizeof(refname), strbuf_reset(&resolved_buf);
rule, short_name_len, short_name); strbuf_addf(&resolved_buf, rule,
if (ref_exists(refname)) short_name_len, short_name);
if (ref_exists(resolved_buf.buf))
break; break;
} }


@ -1023,10 +1028,13 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
* short name is non-ambiguous if all previous rules * short name is non-ambiguous if all previous rules
* haven't resolved to a valid ref * haven't resolved to a valid ref
*/ */
if (j == rules_to_fail) if (j == rules_to_fail) {
strbuf_release(&resolved_buf);
return short_name; return short_name;
}
} }


strbuf_release(&resolved_buf);
free(short_name); free(short_name);
return xstrdup(refname); return xstrdup(refname);
} }

View File

@ -3762,8 +3762,8 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
char hex[GIT_SHA1_HEXSZ+1]; char hex[GIT_SHA1_HEXSZ+1];
struct object_id oid; struct object_id oid;


snprintf(hex, sizeof(hex), "%02x%s", xsnprintf(hex, sizeof(hex), "%02x%s",
subdir_nr, de->d_name); subdir_nr, de->d_name);
if (!get_oid_hex(hex, &oid)) { if (!get_oid_hex(hex, &oid)) {
if (obj_cb) { if (obj_cb) {
r = obj_cb(&oid, path->buf, data); r = obj_cb(&oid, path->buf, data);

View File

@ -1436,7 +1436,7 @@ static int find_first_merges(struct object_array *result, const char *path,
memset(&rev_opts, 0, sizeof(rev_opts)); memset(&rev_opts, 0, sizeof(rev_opts));


/* get all revisions that merge commit a */ /* get all revisions that merge commit a */
snprintf(merged_revision, sizeof(merged_revision), "^%s", xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
oid_to_hex(&a->object.oid)); oid_to_hex(&a->object.oid));
init_revisions(&revs, NULL); init_revisions(&revs, NULL);
rev_opts.submodule = path; rev_opts.submodule = path;

View File

@ -347,14 +347,11 @@ static int set_helper_option(struct transport *transport,
static void standard_options(struct transport *t) static void standard_options(struct transport *t)
{ {
char buf[16]; char buf[16];
int n;
int v = t->verbose; int v = t->verbose;


set_helper_option(t, "progress", t->progress ? "true" : "false"); set_helper_option(t, "progress", t->progress ? "true" : "false");


n = snprintf(buf, sizeof(buf), "%d", v + 1); xsnprintf(buf, sizeof(buf), "%d", v + 1);
if (n >= sizeof(buf))
die("impossibly large verbosity value");
set_helper_option(t, "verbosity", buf); set_helper_option(t, "verbosity", buf);


switch (t->family) { switch (t->family) {