Skip to content

Commit 1d2f80f

Browse files
qurgitster
authored andcommitted
string_list: Fix argument order for string_list_append
Update the definition and callers of string_list_append to use the string_list as the first argument. This helps make the string_list API easier to use by being more consistent. Signed-off-by: Julian Phillips <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8c8b71 commit 1d2f80f

File tree

16 files changed

+64
-64
lines changed

16 files changed

+64
-64
lines changed

Documentation/technical/api-string-list.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct string_list list;
3838
int i;
3939

4040
memset(&list, 0, sizeof(struct string_list));
41-
string_list_append("foo", &list);
42-
string_list_append("bar", &list);
41+
string_list_append(&list, "foo");
42+
string_list_append(&list, "bar");
4343
for (i = 0; i < list.nr; i++)
4444
printf("%s\n", list.items[i].string)
4545
----

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,7 @@ static void add_name_limit(const char *name, int exclude)
33943394
{
33953395
struct string_list_item *it;
33963396

3397-
it = string_list_append(name, &limit_by_name);
3397+
it = string_list_append(&limit_by_name, name);
33983398
it->util = exclude ? NULL : (void *) 1;
33993399
}
34003400

builtin/fast-export.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
438438
/* handle nested tags */
439439
while (tag && tag->object.type == OBJ_TAG) {
440440
parse_object(tag->object.sha1);
441-
string_list_append(full_name, extra_refs)->util = tag;
441+
string_list_append(extra_refs, full_name)->util = tag;
442442
tag = (struct tag *)tag->tagged;
443443
}
444444
if (!tag)
@@ -464,7 +464,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
464464
}
465465
if (commit->util)
466466
/* more than one name for the same object */
467-
string_list_append(full_name, extra_refs)->util = commit;
467+
string_list_append(extra_refs, full_name)->util = commit;
468468
else
469469
commit->util = full_name;
470470
}

builtin/fetch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv)
745745
{
746746
struct string_list *list = priv;
747747
if (!remote->skip_default_update)
748-
string_list_append(remote->name, list);
748+
string_list_append(list, remote->name);
749749
return 0;
750750
}
751751

@@ -764,8 +764,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
764764
int space = strcspn(value, " \t\n");
765765
while (*value) {
766766
if (space > 1) {
767-
string_list_append(xstrndup(value, space),
768-
g->list);
767+
string_list_append(g->list,
768+
xstrndup(value, space));
769769
}
770770
value += space + (value[space] != '\0');
771771
space = strcspn(value, " \t\n");
@@ -786,7 +786,7 @@ static int add_remote_or_group(const char *name, struct string_list *list)
786786
if (!remote_is_configured(name))
787787
return 0;
788788
remote = remote_get(name);
789-
string_list_append(remote->name, list);
789+
string_list_append(list, remote->name);
790790
}
791791
return 1;
792792
}

builtin/fmt-merge-msg.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int handle_line(char *line)
8282

8383
item = unsorted_string_list_lookup(&srcs, src);
8484
if (!item) {
85-
item = string_list_append(src, &srcs);
85+
item = string_list_append(&srcs, src);
8686
item->util = xcalloc(1, sizeof(struct src_data));
8787
init_src_data(item->util);
8888
}
@@ -93,19 +93,19 @@ static int handle_line(char *line)
9393
src_data->head_status |= 1;
9494
} else if (!prefixcmp(line, "branch ")) {
9595
origin = line + 7;
96-
string_list_append(origin, &src_data->branch);
96+
string_list_append(&src_data->branch, origin);
9797
src_data->head_status |= 2;
9898
} else if (!prefixcmp(line, "tag ")) {
9999
origin = line;
100-
string_list_append(origin + 4, &src_data->tag);
100+
string_list_append(&src_data->tag, origin + 4);
101101
src_data->head_status |= 2;
102102
} else if (!prefixcmp(line, "remote branch ")) {
103103
origin = line + 14;
104-
string_list_append(origin, &src_data->r_branch);
104+
string_list_append(&src_data->r_branch, origin);
105105
src_data->head_status |= 2;
106106
} else {
107107
origin = src;
108-
string_list_append(line, &src_data->generic);
108+
string_list_append(&src_data->generic, line);
109109
src_data->head_status |= 2;
110110
}
111111

@@ -118,7 +118,7 @@ static int handle_line(char *line)
118118
sprintf(new_origin, "%s of %s", origin, src);
119119
origin = new_origin;
120120
}
121-
string_list_append(origin, &origins)->util = sha1;
121+
string_list_append(&origins, origin)->util = sha1;
122122
return 0;
123123
}
124124

@@ -176,10 +176,10 @@ static void shortlog(const char *name, unsigned char *sha1,
176176
strbuf_ltrim(&sb);
177177

178178
if (!sb.len)
179-
string_list_append(sha1_to_hex(commit->object.sha1),
180-
&subjects);
179+
string_list_append(&subjects,
180+
sha1_to_hex(commit->object.sha1));
181181
else
182-
string_list_append(strbuf_detach(&sb, NULL), &subjects);
182+
string_list_append(&subjects, strbuf_detach(&sb, NULL));
183183
}
184184

185185
if (count > limit)

builtin/log.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,13 @@ static void add_header(const char *value)
535535
len--;
536536

537537
if (!strncasecmp(value, "to: ", 4)) {
538-
item = string_list_append(value + 4, &extra_to);
538+
item = string_list_append(&extra_to, value + 4);
539539
len -= 4;
540540
} else if (!strncasecmp(value, "cc: ", 4)) {
541-
item = string_list_append(value + 4, &extra_cc);
541+
item = string_list_append(&extra_cc, value + 4);
542542
len -= 4;
543543
} else {
544-
item = string_list_append(value, &extra_hdr);
544+
item = string_list_append(&extra_hdr, value);
545545
}
546546

547547
item->string[len] = '\0';
@@ -565,13 +565,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
565565
if (!strcmp(var, "format.to")) {
566566
if (!value)
567567
return config_error_nonbool(var);
568-
string_list_append(value, &extra_to);
568+
string_list_append(&extra_to, value);
569569
return 0;
570570
}
571571
if (!strcmp(var, "format.cc")) {
572572
if (!value)
573573
return config_error_nonbool(var);
574-
string_list_append(value, &extra_cc);
574+
string_list_append(&extra_cc, value);
575575
return 0;
576576
}
577577
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
@@ -949,7 +949,7 @@ static int to_callback(const struct option *opt, const char *arg, int unset)
949949
if (unset)
950950
string_list_clear(&extra_to, 0);
951951
else
952-
string_list_append(arg, &extra_to);
952+
string_list_append(&extra_to, arg);
953953
return 0;
954954
}
955955

@@ -958,7 +958,7 @@ static int cc_callback(const struct option *opt, const char *arg, int unset)
958958
if (unset)
959959
string_list_clear(&extra_cc, 0);
960960
else
961-
string_list_append(arg, &extra_cc);
961+
string_list_append(&extra_cc, arg);
962962
return 0;
963963
}
964964

@@ -1239,7 +1239,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
12391239
rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
12401240
if (in_reply_to) {
12411241
const char *msgid = clean_message_id(in_reply_to);
1242-
string_list_append(msgid, rev.ref_message_ids);
1242+
string_list_append(rev.ref_message_ids, msgid);
12431243
}
12441244
rev.numbered_files = numbered_files;
12451245
rev.patch_suffix = fmt_patch_suffix;
@@ -1286,8 +1286,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
12861286
&& (!cover_letter || rev.nr > 1))
12871287
free(rev.message_id);
12881288
else
1289-
string_list_append(rev.message_id,
1290-
rev.ref_message_ids);
1289+
string_list_append(rev.ref_message_ids,
1290+
rev.message_id);
12911291
}
12921292
gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
12931293
}

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static void check_aliased_updates(struct command *commands)
534534

535535
for (cmd = commands; cmd; cmd = cmd->next) {
536536
struct string_list_item *item =
537-
string_list_append(cmd->ref_name, &ref_list);
537+
string_list_append(&ref_list, cmd->ref_name);
538538
item->util = (void *)cmd;
539539
}
540540
sort_string_list(&ref_list);

builtin/remote.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int opt_parse_track(const struct option *opt, const char *arg, int not)
8787
if (not)
8888
string_list_clear(list, 0);
8989
else
90-
string_list_append(arg, list);
90+
string_list_append(list, arg);
9191
return 0;
9292
}
9393

@@ -160,7 +160,7 @@ static int add(int argc, const char **argv)
160160
strbuf_addf(&buf, "remote.%s.fetch", name);
161161

162162
if (track.nr == 0)
163-
string_list_append("*", &track);
163+
string_list_append(&track, "*");
164164
for (i = 0; i < track.nr; i++) {
165165
struct string_list_item *item = track.items + i;
166166

@@ -266,11 +266,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
266266
while (space) {
267267
char *merge;
268268
merge = xstrndup(value, space - value);
269-
string_list_append(merge, &info->merge);
269+
string_list_append(&info->merge, merge);
270270
value = abbrev_branch(space + 1);
271271
space = strchr(value, ' ');
272272
}
273-
string_list_append(xstrdup(value), &info->merge);
273+
string_list_append(&info->merge, xstrdup(value));
274274
} else
275275
info->rebase = git_config_bool(orig_key, value);
276276
}
@@ -307,14 +307,14 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
307307
for (ref = fetch_map; ref; ref = ref->next) {
308308
unsigned char sha1[20];
309309
if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
310-
string_list_append(abbrev_branch(ref->name), &states->new);
310+
string_list_append(&states->new, abbrev_branch(ref->name));
311311
else
312-
string_list_append(abbrev_branch(ref->name), &states->tracked);
312+
string_list_append(&states->tracked, abbrev_branch(ref->name));
313313
}
314314
stale_refs = get_stale_heads(states->remote, fetch_map);
315315
for (ref = stale_refs; ref; ref = ref->next) {
316316
struct string_list_item *item =
317-
string_list_append(abbrev_branch(ref->name), &states->stale);
317+
string_list_append(&states->stale, abbrev_branch(ref->name));
318318
item->util = xstrdup(ref->name);
319319
}
320320
free_refs(stale_refs);
@@ -363,8 +363,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
363363
continue;
364364
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
365365

366-
item = string_list_append(abbrev_branch(ref->peer_ref->name),
367-
&states->push);
366+
item = string_list_append(&states->push,
367+
abbrev_branch(ref->peer_ref->name));
368368
item->util = xcalloc(sizeof(struct push_info), 1);
369369
info = item->util;
370370
info->forced = ref->force;
@@ -399,19 +399,19 @@ static int get_push_ref_states_noquery(struct ref_states *states)
399399

400400
states->push.strdup_strings = 1;
401401
if (!remote->push_refspec_nr) {
402-
item = string_list_append("(matching)", &states->push);
402+
item = string_list_append(&states->push, "(matching)");
403403
info = item->util = xcalloc(sizeof(struct push_info), 1);
404404
info->status = PUSH_STATUS_NOTQUERIED;
405405
info->dest = xstrdup(item->string);
406406
}
407407
for (i = 0; i < remote->push_refspec_nr; i++) {
408408
struct refspec *spec = remote->push + i;
409409
if (spec->matching)
410-
item = string_list_append("(matching)", &states->push);
410+
item = string_list_append(&states->push, "(matching)");
411411
else if (strlen(spec->src))
412-
item = string_list_append(spec->src, &states->push);
412+
item = string_list_append(&states->push, spec->src);
413413
else
414-
item = string_list_append("(delete)", &states->push);
414+
item = string_list_append(&states->push, "(delete)");
415415

416416
info = item->util = xcalloc(sizeof(struct push_info), 1);
417417
info->forced = spec->force;
@@ -435,7 +435,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
435435
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
436436
fetch_map, 1);
437437
for (ref = matches; ref; ref = ref->next)
438-
string_list_append(abbrev_branch(ref->name), &states->heads);
438+
string_list_append(&states->heads, abbrev_branch(ref->name));
439439

440440
free_refs(fetch_map);
441441
free_refs(matches);
@@ -499,8 +499,8 @@ static int add_branch_for_removal(const char *refname,
499499
if (prefixcmp(refname, "refs/remotes")) {
500500
/* advise user how to delete local branches */
501501
if (!prefixcmp(refname, "refs/heads/"))
502-
string_list_append(abbrev_branch(refname),
503-
branches->skipped);
502+
string_list_append(branches->skipped,
503+
abbrev_branch(refname));
504504
/* silently skip over other non-remote refs */
505505
return 0;
506506
}
@@ -509,7 +509,7 @@ static int add_branch_for_removal(const char *refname,
509509
if (flags & REF_ISSYMREF)
510510
return unlink(git_path("%s", refname));
511511

512-
item = string_list_append(refname, branches->branches);
512+
item = string_list_append(branches->branches, refname);
513513
item->util = xmalloc(20);
514514
hashcpy(item->util, sha1);
515515

@@ -534,7 +534,7 @@ static int read_remote_branches(const char *refname,
534534

535535
strbuf_addf(&buf, "refs/remotes/%s", rename->old);
536536
if (!prefixcmp(refname, buf.buf)) {
537-
item = string_list_append(xstrdup(refname), rename->remote_branches);
537+
item = string_list_append(rename->remote_branches, xstrdup(refname));
538538
symref = resolve_ref(refname, orig_sha1, 1, &flag);
539539
if (flag & REF_ISSYMREF)
540540
item->util = xstrdup(symref);
@@ -817,7 +817,7 @@ static int append_ref_to_tracked_list(const char *refname,
817817
memset(&refspec, 0, sizeof(refspec));
818818
refspec.dst = (char *)refname;
819819
if (!remote_find_tracking(states->remote, &refspec))
820-
string_list_append(abbrev_branch(refspec.src), &states->tracked);
820+
string_list_append(&states->tracked, abbrev_branch(refspec.src));
821821

822822
return 0;
823823
}
@@ -965,7 +965,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
965965
show_info->width = n;
966966
if ((n = strlen(push_info->dest)) > show_info->width2)
967967
show_info->width2 = n;
968-
item = string_list_append(push_item->string, show_info->list);
968+
item = string_list_append(show_info->list, push_item->string);
969969
item->util = push_item->util;
970970
return 0;
971971
}
@@ -1379,10 +1379,10 @@ static int get_one_entry(struct remote *remote, void *priv)
13791379

13801380
if (remote->url_nr > 0) {
13811381
strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
1382-
string_list_append(remote->name, list)->util =
1382+
string_list_append(list, remote->name)->util =
13831383
strbuf_detach(&url_buf, NULL);
13841384
} else
1385-
string_list_append(remote->name, list)->util = NULL;
1385+
string_list_append(list, remote->name)->util = NULL;
13861386
if (remote->pushurl_nr) {
13871387
url = remote->pushurl;
13881388
url_nr = remote->pushurl_nr;
@@ -1393,7 +1393,7 @@ static int get_one_entry(struct remote *remote, void *priv)
13931393
for (i = 0; i < url_nr; i++)
13941394
{
13951395
strbuf_addf(&url_buf, "%s (push)", url[i]);
1396-
string_list_append(remote->name, list)->util =
1396+
string_list_append(list, remote->name)->util =
13971397
strbuf_detach(&url_buf, NULL);
13981398
}
13991399

builtin/rerere.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void garbage_collect(struct string_list *rr)
5959
cutoff = (has_rerere_resolution(e->d_name)
6060
? cutoff_resolve : cutoff_noresolve);
6161
if (then < now - cutoff * 86400)
62-
string_list_append(e->d_name, &to_remove);
62+
string_list_append(&to_remove, e->d_name);
6363
}
6464
for (i = 0; i < to_remove.nr; i++)
6565
unlink_rr_item(to_remove.items[i].string);

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void insert_one_record(struct shortlog *log,
115115
}
116116
}
117117

118-
string_list_append(buffer, item->util);
118+
string_list_append(item->util, buffer);
119119
}
120120

121121
static void read_from_stdin(struct shortlog *log)

0 commit comments

Comments
 (0)