diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-07-22 10:59:36 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-07-22 10:59:37 -0700 |
commit | 12621cb22224d1c2f507a643a578e386ee891c5c (patch) | |
tree | d0ab888b37baa09db9c7ef74840b739ff3cafb09 | |
parent | Merge branch 'nd/path-max-must-go' (diff) | |
parent | remote-testsvn: use internal argv_array of struct child_process in cmd_import() (diff) | |
download | tgif-12621cb22224d1c2f507a643a578e386ee891c5c.tar.xz |
Merge branch 'rs/code-cleaning'
* rs/code-cleaning:
remote-testsvn: use internal argv_array of struct child_process in cmd_import()
bundle: use internal argv_array of struct child_process in create_bundle()
fast-import: use hashcmp() for SHA1 hash comparison
transport: simplify fetch_objs_via_rsync() using argv_array
run-command: use internal argv_array of struct child_process in run_hook_ve()
use commit_list_count() to count the members of commit_lists
strbuf: use strbuf_addstr() for adding C strings
-rw-r--r-- | builtin/blame.c | 5 | ||||
-rw-r--r-- | builtin/commit.c | 2 | ||||
-rw-r--r-- | builtin/for-each-ref.c | 16 | ||||
-rw-r--r-- | bundle.c | 15 | ||||
-rw-r--r-- | commit.c | 7 | ||||
-rw-r--r-- | diff.c | 12 | ||||
-rw-r--r-- | fast-import.c | 2 | ||||
-rw-r--r-- | line-log.c | 13 | ||||
-rw-r--r-- | path.c | 6 | ||||
-rw-r--r-- | pretty.c | 7 | ||||
-rw-r--r-- | remote-testsvn.c | 16 | ||||
-rw-r--r-- | run-command.c | 15 | ||||
-rw-r--r-- | transport.c | 28 |
13 files changed, 41 insertions, 103 deletions
diff --git a/builtin/blame.c b/builtin/blame.c index 23212cbe87..17d30d00aa 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit static int num_scapegoats(struct rev_info *revs, struct commit *commit) { - int cnt; struct commit_list *l = first_scapegoat(revs, commit); - for (cnt = 0; l; l = l->next) - cnt++; - return cnt; + return commit_list_count(l); } /* Distribute collected unsorted blames to the respected sorted lists diff --git a/builtin/commit.c b/builtin/commit.c index 72eb3beb36..f2d7979deb 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, char *buffer; buffer = strstr(use_message_buffer, "\n\n"); if (buffer) - strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); + strbuf_addstr(&sb, buffer + 2); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 4135980f20..47bd624696 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob } } -static int num_parents(struct commit *commit) -{ - struct commit_list *parents; - int i; - - for (i = 0, parents = commit->parents; - parents; - parents = parents->next) - i++; - return i; -} - /* See grab_values */ static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz) { @@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object } if (!strcmp(name, "numparent")) { char *s = xmalloc(40); - v->ul = num_parents(commit); + v->ul = commit_list_count(commit->parents); sprintf(s, "%lu", v->ul); v->s = s; } else if (!strcmp(name, "parent")) { - int num = num_parents(commit); + int num = commit_list_count(commit->parents); int i; struct commit_list *parents; char *s = xmalloc(41 * num + 1); @@ -237,8 +237,6 @@ int create_bundle(struct bundle_header *header, const char *path, static struct lock_file lock; int bundle_fd = -1; int bundle_to_stdout; - struct argv_array argv_boundary = ARGV_ARRAY_INIT; - struct argv_array argv_pack = ARGV_ARRAY_INIT; int i, ref_count = 0; struct strbuf buf = STRBUF_INIT; struct rev_info revs; @@ -260,14 +258,12 @@ int create_bundle(struct bundle_header *header, const char *path, init_revisions(&revs, NULL); /* write prerequisites */ - argv_array_pushl(&argv_boundary, + memset(&rls, 0, sizeof(rls)); + argv_array_pushl(&rls.args, "rev-list", "--boundary", "--pretty=oneline", NULL); for (i = 1; i < argc; i++) - argv_array_push(&argv_boundary, argv[i]); - - memset(&rls, 0, sizeof(rls)); - rls.argv = argv_boundary.argv; + argv_array_push(&rls.args, argv[i]); rls.out = -1; rls.git_cmd = 1; if (start_command(&rls)) @@ -382,12 +378,11 @@ int create_bundle(struct bundle_header *header, const char *path, write_or_die(bundle_fd, "\n", 1); /* write pack */ - argv_array_pushl(&argv_pack, + memset(&rls, 0, sizeof(rls)); + argv_array_pushl(&rls.args, "pack-objects", "--all-progress-implied", "--stdout", "--thin", "--delta-base-offset", NULL); - memset(&rls, 0, sizeof(rls)); - rls.argv = argv_pack.argv; rls.in = -1; rls.out = bundle_fd; rls.git_cmd = 1; @@ -970,12 +970,7 @@ struct commit_list *get_merge_bases_many(struct commit *one, } /* There are more than one */ - cnt = 0; - list = result; - while (list) { - list = list->next; - cnt++; - } + cnt = commit_list_count(result); rslt = xcalloc(cnt, sizeof(*rslt)); for (list = result, i = 0; list; list = list->next) rslt[i++] = list->item; @@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata, ep += 2; /* skip over @@ */ /* The hunk header in fraginfo color */ - strbuf_add(&msgbuf, frag, strlen(frag)); + strbuf_addstr(&msgbuf, frag); strbuf_add(&msgbuf, line, ep - line); - strbuf_add(&msgbuf, reset, strlen(reset)); + strbuf_addstr(&msgbuf, reset); /* * trailing "\r\n" @@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata, if (*ep != ' ' && *ep != '\t') break; if (ep != cp) { - strbuf_add(&msgbuf, plain, strlen(plain)); + strbuf_addstr(&msgbuf, plain); strbuf_add(&msgbuf, cp, ep - cp); - strbuf_add(&msgbuf, reset, strlen(reset)); + strbuf_addstr(&msgbuf, reset); } if (ep < line + len) { - strbuf_add(&msgbuf, func, strlen(func)); + strbuf_addstr(&msgbuf, func); strbuf_add(&msgbuf, ep, line + len - ep); - strbuf_add(&msgbuf, reset, strlen(reset)); + strbuf_addstr(&msgbuf, reset); } strbuf_add(&msgbuf, line + len, org_len - len); diff --git a/fast-import.c b/fast-import.c index fa635f75c3..d73f58cbe3 100644 --- a/fast-import.c +++ b/fast-import.c @@ -2324,7 +2324,7 @@ static void file_change_m(const char *p, struct branch *b) } /* Git does not track empty, non-toplevel directories. */ - if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) { + if (S_ISDIR(mode) && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN) && *p) { tree_content_remove(&b->branch_tree, p, NULL, 0); return; } diff --git a/line-log.c b/line-log.c index afcc98db93..1008e72258 100644 --- a/line-log.c +++ b/line-log.c @@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list } } -static int count_parents(struct commit *commit) -{ - struct commit_list *parents = commit->parents; - int count = 0; - while (parents) { - count++; - parents = parents->next; - } - return count; -} - static void move_diff_queue(struct diff_queue_struct *dst, struct diff_queue_struct *src) { @@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm struct commit **parents; struct commit_list *p; int i; - int nparents = count_parents(commit); + int nparents = commit_list_count(commit->parents); diffqueues = xmalloc(nparents * sizeof(*diffqueues)); cand = xmalloc(nparents * sizeof(*cand)); @@ -275,16 +275,16 @@ char *expand_user_path(const char *path) const char *home = getenv("HOME"); if (!home) goto return_null; - strbuf_add(&user_path, home, strlen(home)); + strbuf_addstr(&user_path, home); } else { struct passwd *pw = getpw_str(username, username_len); if (!pw) goto return_null; - strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir)); + strbuf_addstr(&user_path, pw->pw_dir); } to_copy = first_slash; } - strbuf_add(&user_path, to_copy, strlen(to_copy)); + strbuf_addstr(&user_path, to_copy); return strbuf_detach(&user_path, NULL); return_null: strbuf_release(&user_path); @@ -1554,12 +1554,7 @@ static void pp_header(struct pretty_print_context *pp, } if (!parents_shown) { - struct commit_list *parent; - int num; - for (parent = commit->parents, num = 0; - parent; - parent = parent->next, num++) - ; + unsigned num = commit_list_count(commit->parents); /* with enough slop */ strbuf_grow(sb, num * 50 + 20); add_merge_info(pp, sb, commit); diff --git a/remote-testsvn.c b/remote-testsvn.c index 6be55cbe9e..686e07d317 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -175,8 +175,8 @@ static int cmd_import(const char *line) char *note_msg; unsigned char head_sha1[20]; unsigned int startrev; - struct argv_array svndump_argv = ARGV_ARRAY_INIT; struct child_process svndump_proc; + const char *command = "svnrdump"; if (read_ref(private_ref, head_sha1)) startrev = 0; @@ -202,15 +202,14 @@ static int cmd_import(const char *line) } else { memset(&svndump_proc, 0, sizeof(struct child_process)); svndump_proc.out = -1; - argv_array_push(&svndump_argv, "svnrdump"); - argv_array_push(&svndump_argv, "dump"); - argv_array_push(&svndump_argv, url); - argv_array_pushf(&svndump_argv, "-r%u:HEAD", startrev); - svndump_proc.argv = svndump_argv.argv; + argv_array_push(&svndump_proc.args, command); + argv_array_push(&svndump_proc.args, "dump"); + argv_array_push(&svndump_proc.args, url); + argv_array_pushf(&svndump_proc.args, "-r%u:HEAD", startrev); code = start_command(&svndump_proc); if (code) - die("Unable to start %s, code %d", svndump_proc.argv[0], code); + die("Unable to start %s, code %d", command, code); dumpin_fd = svndump_proc.out; } /* setup marks file import/export */ @@ -226,8 +225,7 @@ static int cmd_import(const char *line) if (!dump_from_file) { code = finish_command(&svndump_proc); if (code) - warning("%s, returned %d", svndump_proc.argv[0], code); - argv_array_clear(&svndump_argv); + warning("%s, returned %d", command, code); } return 0; diff --git a/run-command.c b/run-command.c index be07d4ad33..576dfeaa3f 100644 --- a/run-command.c +++ b/run-command.c @@ -770,28 +770,21 @@ char *find_hook(const char *name) int run_hook_ve(const char *const *env, const char *name, va_list args) { struct child_process hook; - struct argv_array argv = ARGV_ARRAY_INIT; const char *p; - int ret; p = find_hook(name); if (!p) return 0; - argv_array_push(&argv, p); - - while ((p = va_arg(args, const char *))) - argv_array_push(&argv, p); - memset(&hook, 0, sizeof(hook)); - hook.argv = argv.argv; + argv_array_push(&hook.args, p); + while ((p = va_arg(args, const char *))) + argv_array_push(&hook.args, p); hook.env = env; hook.no_stdin = 1; hook.stdout_to_stderr = 1; - ret = run_command(&hook); - argv_array_clear(&argv); - return ret; + return run_command(&hook); } int run_hook_le(const char *const *env, const char *name, ...) diff --git a/transport.c b/transport.c index 59c9727d8d..3e425709fd 100644 --- a/transport.c +++ b/transport.c @@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) static int fetch_objs_via_rsync(struct transport *transport, int nr_objs, struct ref **to_fetch) { - struct strbuf buf = STRBUF_INIT; struct child_process rsync; - const char *args[8]; - int result; - - strbuf_addstr(&buf, rsync_url(transport->url)); - strbuf_addstr(&buf, "/objects/"); memset(&rsync, 0, sizeof(rsync)); - rsync.argv = args; rsync.stdout_to_stderr = 1; - args[0] = "rsync"; - args[1] = (transport->verbose > 1) ? "-rv" : "-r"; - args[2] = "--ignore-existing"; - args[3] = "--exclude"; - args[4] = "info"; - args[5] = buf.buf; - args[6] = get_object_directory(); - args[7] = NULL; + argv_array_push(&rsync.args, "rsync"); + argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r"); + argv_array_push(&rsync.args, "--ignore-existing"); + argv_array_push(&rsync.args, "--exclude"); + argv_array_push(&rsync.args, "info"); + argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url)); + argv_array_push(&rsync.args, get_object_directory()); /* NEEDSWORK: handle one level of alternates */ - result = run_command(&rsync); - - strbuf_release(&buf); - - return result; + return run_command(&rsync); } static int write_one_ref(const char *name, const unsigned char *sha1, |