Skip to content

Commit 12621cb

Browse files
committed
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
2 parents 4328190 + 1cefa14 commit 12621cb

File tree

13 files changed

+41
-103
lines changed

13 files changed

+41
-103
lines changed

builtin/blame.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
13711371

13721372
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
13731373
{
1374-
int cnt;
13751374
struct commit_list *l = first_scapegoat(revs, commit);
1376-
for (cnt = 0; l; l = l->next)
1377-
cnt++;
1378-
return cnt;
1375+
return commit_list_count(l);
13791376
}
13801377

13811378
/* Distribute collected unsorted blames to the respected sorted lists

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
702702
char *buffer;
703703
buffer = strstr(use_message_buffer, "\n\n");
704704
if (buffer)
705-
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
705+
strbuf_addstr(&sb, buffer + 2);
706706
hook_arg1 = "commit";
707707
hook_arg2 = use_message;
708708
} else if (fixup_message) {

builtin/for-each-ref.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
283283
}
284284
}
285285

286-
static int num_parents(struct commit *commit)
287-
{
288-
struct commit_list *parents;
289-
int i;
290-
291-
for (i = 0, parents = commit->parents;
292-
parents;
293-
parents = parents->next)
294-
i++;
295-
return i;
296-
}
297-
298286
/* See grab_values */
299287
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
300288
{
@@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
315303
}
316304
if (!strcmp(name, "numparent")) {
317305
char *s = xmalloc(40);
318-
v->ul = num_parents(commit);
306+
v->ul = commit_list_count(commit->parents);
319307
sprintf(s, "%lu", v->ul);
320308
v->s = s;
321309
}
322310
else if (!strcmp(name, "parent")) {
323-
int num = num_parents(commit);
311+
int num = commit_list_count(commit->parents);
324312
int i;
325313
struct commit_list *parents;
326314
char *s = xmalloc(41 * num + 1);

bundle.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ int create_bundle(struct bundle_header *header, const char *path,
237237
static struct lock_file lock;
238238
int bundle_fd = -1;
239239
int bundle_to_stdout;
240-
struct argv_array argv_boundary = ARGV_ARRAY_INIT;
241-
struct argv_array argv_pack = ARGV_ARRAY_INIT;
242240
int i, ref_count = 0;
243241
struct strbuf buf = STRBUF_INIT;
244242
struct rev_info revs;
@@ -260,14 +258,12 @@ int create_bundle(struct bundle_header *header, const char *path,
260258
init_revisions(&revs, NULL);
261259

262260
/* write prerequisites */
263-
argv_array_pushl(&argv_boundary,
261+
memset(&rls, 0, sizeof(rls));
262+
argv_array_pushl(&rls.args,
264263
"rev-list", "--boundary", "--pretty=oneline",
265264
NULL);
266265
for (i = 1; i < argc; i++)
267-
argv_array_push(&argv_boundary, argv[i]);
268-
269-
memset(&rls, 0, sizeof(rls));
270-
rls.argv = argv_boundary.argv;
266+
argv_array_push(&rls.args, argv[i]);
271267
rls.out = -1;
272268
rls.git_cmd = 1;
273269
if (start_command(&rls))
@@ -382,12 +378,11 @@ int create_bundle(struct bundle_header *header, const char *path,
382378
write_or_die(bundle_fd, "\n", 1);
383379

384380
/* write pack */
385-
argv_array_pushl(&argv_pack,
381+
memset(&rls, 0, sizeof(rls));
382+
argv_array_pushl(&rls.args,
386383
"pack-objects", "--all-progress-implied",
387384
"--stdout", "--thin", "--delta-base-offset",
388385
NULL);
389-
memset(&rls, 0, sizeof(rls));
390-
rls.argv = argv_pack.argv;
391386
rls.in = -1;
392387
rls.out = bundle_fd;
393388
rls.git_cmd = 1;

commit.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
970970
}
971971

972972
/* There are more than one */
973-
cnt = 0;
974-
list = result;
975-
while (list) {
976-
list = list->next;
977-
cnt++;
978-
}
973+
cnt = commit_list_count(result);
979974
rslt = xcalloc(cnt, sizeof(*rslt));
980975
for (list = result, i = 0; list; list = list->next)
981976
rslt[i++] = list->item;

diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
525525
ep += 2; /* skip over @@ */
526526

527527
/* The hunk header in fraginfo color */
528-
strbuf_add(&msgbuf, frag, strlen(frag));
528+
strbuf_addstr(&msgbuf, frag);
529529
strbuf_add(&msgbuf, line, ep - line);
530-
strbuf_add(&msgbuf, reset, strlen(reset));
530+
strbuf_addstr(&msgbuf, reset);
531531

532532
/*
533533
* trailing "\r\n"
@@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
541541
if (*ep != ' ' && *ep != '\t')
542542
break;
543543
if (ep != cp) {
544-
strbuf_add(&msgbuf, plain, strlen(plain));
544+
strbuf_addstr(&msgbuf, plain);
545545
strbuf_add(&msgbuf, cp, ep - cp);
546-
strbuf_add(&msgbuf, reset, strlen(reset));
546+
strbuf_addstr(&msgbuf, reset);
547547
}
548548

549549
if (ep < line + len) {
550-
strbuf_add(&msgbuf, func, strlen(func));
550+
strbuf_addstr(&msgbuf, func);
551551
strbuf_add(&msgbuf, ep, line + len - ep);
552-
strbuf_add(&msgbuf, reset, strlen(reset));
552+
strbuf_addstr(&msgbuf, reset);
553553
}
554554

555555
strbuf_add(&msgbuf, line + len, org_len - len);

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2324,7 +2324,7 @@ static void file_change_m(const char *p, struct branch *b)
23242324
}
23252325

23262326
/* Git does not track empty, non-toplevel directories. */
2327-
if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) {
2327+
if (S_ISDIR(mode) && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN) && *p) {
23282328
tree_content_remove(&b->branch_tree, p, NULL, 0);
23292329
return;
23302330
}

line-log.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
766766
}
767767
}
768768

769-
static int count_parents(struct commit *commit)
770-
{
771-
struct commit_list *parents = commit->parents;
772-
int count = 0;
773-
while (parents) {
774-
count++;
775-
parents = parents->next;
776-
}
777-
return count;
778-
}
779-
780769
static void move_diff_queue(struct diff_queue_struct *dst,
781770
struct diff_queue_struct *src)
782771
{
@@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
11501139
struct commit **parents;
11511140
struct commit_list *p;
11521141
int i;
1153-
int nparents = count_parents(commit);
1142+
int nparents = commit_list_count(commit->parents);
11541143

11551144
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
11561145
cand = xmalloc(nparents * sizeof(*cand));

path.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,16 @@ char *expand_user_path(const char *path)
275275
const char *home = getenv("HOME");
276276
if (!home)
277277
goto return_null;
278-
strbuf_add(&user_path, home, strlen(home));
278+
strbuf_addstr(&user_path, home);
279279
} else {
280280
struct passwd *pw = getpw_str(username, username_len);
281281
if (!pw)
282282
goto return_null;
283-
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
283+
strbuf_addstr(&user_path, pw->pw_dir);
284284
}
285285
to_copy = first_slash;
286286
}
287-
strbuf_add(&user_path, to_copy, strlen(to_copy));
287+
strbuf_addstr(&user_path, to_copy);
288288
return strbuf_detach(&user_path, NULL);
289289
return_null:
290290
strbuf_release(&user_path);

pretty.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,12 +1554,7 @@ static void pp_header(struct pretty_print_context *pp,
15541554
}
15551555

15561556
if (!parents_shown) {
1557-
struct commit_list *parent;
1558-
int num;
1559-
for (parent = commit->parents, num = 0;
1560-
parent;
1561-
parent = parent->next, num++)
1562-
;
1557+
unsigned num = commit_list_count(commit->parents);
15631558
/* with enough slop */
15641559
strbuf_grow(sb, num * 50 + 20);
15651560
add_merge_info(pp, sb, commit);

0 commit comments

Comments
 (0)