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 <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Julian Phillips committed
Jun 26, 2010 at 00:41 UTC
1d2f80fa79cdc6f7f4fa1cefb47d7d19be3bc5ee
16 files changed
+64
-64
Documentation/technical/api-string-list.txt
+2
-2
@@ -38,8 +38,8 @@ struct string_list list;
38
int i;
39
40
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");
43
for (i = 0; i < list.nr; i++)
44
printf("%s\n", list.items[i].string)
45
----
builtin/apply.c
+1
-1
@@ -3394,7 +3394,7 @@ static void add_name_limit(const char *name, int exclude)
3394
{
3395
struct string_list_item *it;
3396
3397
- it = string_list_append(name, &limit_by_name);
3397
+ it = string_list_append(&limit_by_name, name);
3398
it->util = exclude ? NULL : (void *) 1;
3399
}
3400
builtin/fast-export.c
+2
-2
@@ -438,7 +438,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
438
/* handle nested tags */
439
while (tag && tag->object.type == OBJ_TAG) {
440
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;
442
tag = (struct tag *)tag->tagged;
443
}
444
if (!tag)
@@ -464,7 +464,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
464
}
465
if (commit->util)
466
/* 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;
468
else
469
commit->util = full_name;
470
}
builtin/fetch.c
+4
-4
@@ -745,7 +745,7 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv)
745
{
746
struct string_list *list = priv;
747
if (!remote->skip_default_update)
748
- string_list_append(remote->name, list);
748
+ string_list_append(list, remote->name);
749
return 0;
750
}
751
@@ -764,8 +764,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
764
int space = strcspn(value, " \t\n");
765
while (*value) {
766
if (space > 1) {
767
- string_list_append(xstrndup(value, space),
768
- g->list);
767
+ string_list_append(g->list,
768
+ xstrndup(value, space));
769
}
770
value += space + (value[space] != '\0');
771
space = strcspn(value, " \t\n");
@@ -786,7 +786,7 @@ static int add_remote_or_group(const char *name, struct string_list *list)
786
if (!remote_is_configured(name))
787
return 0;
788
remote = remote_get(name);
789
- string_list_append(remote->name, list);
789
+ string_list_append(list, remote->name);
790
}
791
return 1;
792
}
builtin/fmt-merge-msg.c
+9
-9
@@ -82,7 +82,7 @@ static int handle_line(char *line)
82
83
item = unsorted_string_list_lookup(&srcs, src);
84
if (!item) {
85
- item = string_list_append(src, &srcs);
85
+ item = string_list_append(&srcs, src);
86
item->util = xcalloc(1, sizeof(struct src_data));
87
init_src_data(item->util);
88
}
@@ -93,19 +93,19 @@ static int handle_line(char *line)
93
src_data->head_status |= 1;
94
} else if (!prefixcmp(line, "branch ")) {
95
origin = line + 7;
96
- string_list_append(origin, &src_data->branch);
96
+ string_list_append(&src_data->branch, origin);
97
src_data->head_status |= 2;
98
} else if (!prefixcmp(line, "tag ")) {
99
origin = line;
100
- string_list_append(origin + 4, &src_data->tag);
100
+ string_list_append(&src_data->tag, origin + 4);
101
src_data->head_status |= 2;
102
} else if (!prefixcmp(line, "remote branch ")) {
103
origin = line + 14;
104
- string_list_append(origin, &src_data->r_branch);
104
+ string_list_append(&src_data->r_branch, origin);
105
src_data->head_status |= 2;
106
} else {
107
origin = src;
108
- string_list_append(line, &src_data->generic);
108
+ string_list_append(&src_data->generic, line);
109
src_data->head_status |= 2;
110
}
111
@@ -118,7 +118,7 @@ static int handle_line(char *line)
118
sprintf(new_origin, "%s of %s", origin, src);
119
origin = new_origin;
120
}
121
- string_list_append(origin, &origins)->util = sha1;
121
+ string_list_append(&origins, origin)->util = sha1;
122
return 0;
123
}
124
@@ -176,10 +176,10 @@ static void shortlog(const char *name, unsigned char *sha1,
176
strbuf_ltrim(&sb);
177
178
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));
181
else
182
- string_list_append(strbuf_detach(&sb, NULL), &subjects);
182
+ string_list_append(&subjects, strbuf_detach(&sb, NULL));
183
}
184
185
if (count > limit)
builtin/log.c
+10
-10
@@ -535,13 +535,13 @@ static void add_header(const char *value)
535
len--;
536
537
if (!strncasecmp(value, "to: ", 4)) {
538
- item = string_list_append(value + 4, &extra_to);
538
+ item = string_list_append(&extra_to, value + 4);
539
len -= 4;
540
} else if (!strncasecmp(value, "cc: ", 4)) {
541
- item = string_list_append(value + 4, &extra_cc);
541
+ item = string_list_append(&extra_cc, value + 4);
542
len -= 4;
543
} else {
544
- item = string_list_append(value, &extra_hdr);
544
+ item = string_list_append(&extra_hdr, value);
545
}
546
547
item->string[len] = '\0';
@@ -565,13 +565,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
565
if (!strcmp(var, "format.to")) {
566
if (!value)
567
return config_error_nonbool(var);
568
- string_list_append(value, &extra_to);
568
+ string_list_append(&extra_to, value);
569
return 0;
570
}
571
if (!strcmp(var, "format.cc")) {
572
if (!value)
573
return config_error_nonbool(var);
574
- string_list_append(value, &extra_cc);
574
+ string_list_append(&extra_cc, value);
575
return 0;
576
}
577
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)
949
if (unset)
950
string_list_clear(&extra_to, 0);
951
else
952
- string_list_append(arg, &extra_to);
952
+ string_list_append(&extra_to, arg);
953
return 0;
954
}
955
@@ -958,7 +958,7 @@ static int cc_callback(const struct option *opt, const char *arg, int unset)
958
if (unset)
959
string_list_clear(&extra_cc, 0);
960
else
961
- string_list_append(arg, &extra_cc);
961
+ string_list_append(&extra_cc, arg);
962
return 0;
963
}
964
@@ -1239,7 +1239,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1239
rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
1240
if (in_reply_to) {
1241
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);
1243
}
1244
rev.numbered_files = numbered_files;
1245
rev.patch_suffix = fmt_patch_suffix;
@@ -1286,8 +1286,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1286
&& (!cover_letter || rev.nr > 1))
1287
free(rev.message_id);
1288
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);
1291
}
1292
gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
1293
}
builtin/receive-pack.c
+1
-1
@@ -534,7 +534,7 @@ static void check_aliased_updates(struct command *commands)
534
535
for (cmd = commands; cmd; cmd = cmd->next) {
536
struct string_list_item *item =
537
- string_list_append(cmd->ref_name, &ref_list);
537
+ string_list_append(&ref_list, cmd->ref_name);
538
item->util = (void *)cmd;
539
}
540
sort_string_list(&ref_list);
builtin/remote.c
+23
-23
@@ -87,7 +87,7 @@ static int opt_parse_track(const struct option *opt, const char *arg, int not)
87
if (not)
88
string_list_clear(list, 0);
89
else
90
- string_list_append(arg, list);
90
+ string_list_append(list, arg);
91
return 0;
92
}
93
@@ -160,7 +160,7 @@ static int add(int argc, const char **argv)
160
strbuf_addf(&buf, "remote.%s.fetch", name);
161
162
if (track.nr == 0)
163
- string_list_append("*", &track);
163
+ string_list_append(&track, "*");
164
for (i = 0; i < track.nr; i++) {
165
struct string_list_item *item = track.items + i;
166
@@ -266,11 +266,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
266
while (space) {
267
char *merge;
268
merge = xstrndup(value, space - value);
269
- string_list_append(merge, &info->merge);
269
+ string_list_append(&info->merge, merge);
270
value = abbrev_branch(space + 1);
271
space = strchr(value, ' ');
272
}
273
- string_list_append(xstrdup(value), &info->merge);
273
+ string_list_append(&info->merge, xstrdup(value));
274
} else
275
info->rebase = git_config_bool(orig_key, value);
276
}
@@ -307,14 +307,14 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
307
for (ref = fetch_map; ref; ref = ref->next) {
308
unsigned char sha1[20];
309
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));
311
else
312
- string_list_append(abbrev_branch(ref->name), &states->tracked);
312
+ string_list_append(&states->tracked, abbrev_branch(ref->name));
313
}
314
stale_refs = get_stale_heads(states->remote, fetch_map);
315
for (ref = stale_refs; ref; ref = ref->next) {
316
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));
318
item->util = xstrdup(ref->name);
319
}
320
free_refs(stale_refs);
@@ -363,8 +363,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
363
continue;
364
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
365
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));
368
item->util = xcalloc(sizeof(struct push_info), 1);
369
info = item->util;
370
info->forced = ref->force;
@@ -399,7 +399,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
399
400
states->push.strdup_strings = 1;
401
if (!remote->push_refspec_nr) {
402
- item = string_list_append("(matching)", &states->push);
402
+ item = string_list_append(&states->push, "(matching)");
403
info = item->util = xcalloc(sizeof(struct push_info), 1);
404
info->status = PUSH_STATUS_NOTQUERIED;
405
info->dest = xstrdup(item->string);
@@ -407,11 +407,11 @@ static int get_push_ref_states_noquery(struct ref_states *states)
407
for (i = 0; i < remote->push_refspec_nr; i++) {
408
struct refspec *spec = remote->push + i;
409
if (spec->matching)
410
- item = string_list_append("(matching)", &states->push);
410
+ item = string_list_append(&states->push, "(matching)");
411
else if (strlen(spec->src))
412
- item = string_list_append(spec->src, &states->push);
412
+ item = string_list_append(&states->push, spec->src);
413
else
414
- item = string_list_append("(delete)", &states->push);
414
+ item = string_list_append(&states->push, "(delete)");
415
416
info = item->util = xcalloc(sizeof(struct push_info), 1);
417
info->forced = spec->force;
@@ -435,7 +435,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
435
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
436
fetch_map, 1);
437
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));
439
440
free_refs(fetch_map);
441
free_refs(matches);
@@ -499,8 +499,8 @@ static int add_branch_for_removal(const char *refname,
499
if (prefixcmp(refname, "refs/remotes")) {
500
/* advise user how to delete local branches */
501
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));
504
/* silently skip over other non-remote refs */
505
return 0;
506
}
@@ -509,7 +509,7 @@ static int add_branch_for_removal(const char *refname,
509
if (flags & REF_ISSYMREF)
510
return unlink(git_path("%s", refname));
511
512
- item = string_list_append(refname, branches->branches);
512
+ item = string_list_append(branches->branches, refname);
513
item->util = xmalloc(20);
514
hashcpy(item->util, sha1);
515
@@ -534,7 +534,7 @@ static int read_remote_branches(const char *refname,
534
535
strbuf_addf(&buf, "refs/remotes/%s", rename->old);
536
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));
538
symref = resolve_ref(refname, orig_sha1, 1, &flag);
539
if (flag & REF_ISSYMREF)
540
item->util = xstrdup(symref);
@@ -817,7 +817,7 @@ static int append_ref_to_tracked_list(const char *refname,
817
memset(&refspec, 0, sizeof(refspec));
818
refspec.dst = (char *)refname;
819
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));
821
822
return 0;
823
}
@@ -965,7 +965,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
965
show_info->width = n;
966
if ((n = strlen(push_info->dest)) > show_info->width2)
967
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);
969
item->util = push_item->util;
970
return 0;
971
}
@@ -1379,10 +1379,10 @@ static int get_one_entry(struct remote *remote, void *priv)
1379
1380
if (remote->url_nr > 0) {
1381
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 =
1383
strbuf_detach(&url_buf, NULL);
1384
} else
1385
- string_list_append(remote->name, list)->util = NULL;
1385
+ string_list_append(list, remote->name)->util = NULL;
1386
if (remote->pushurl_nr) {
1387
url = remote->pushurl;
1388
url_nr = remote->pushurl_nr;
@@ -1393,7 +1393,7 @@ static int get_one_entry(struct remote *remote, void *priv)
1393
for (i = 0; i < url_nr; i++)
1394
{
1395
strbuf_addf(&url_buf, "%s (push)", url[i]);
1396
- string_list_append(remote->name, list)->util =
1396
+ string_list_append(list, remote->name)->util =
1397
strbuf_detach(&url_buf, NULL);
1398
}
1399
builtin/rerere.c
+1
-1
@@ -59,7 +59,7 @@ static void garbage_collect(struct string_list *rr)
59
cutoff = (has_rerere_resolution(e->d_name)
60
? cutoff_resolve : cutoff_noresolve);
61
if (then < now - cutoff * 86400)
62
- string_list_append(e->d_name, &to_remove);
62
+ string_list_append(&to_remove, e->d_name);
63
}
64
for (i = 0; i < to_remove.nr; i++)
65
unlink_rr_item(to_remove.items[i].string);
builtin/shortlog.c
+1
-1
@@ -115,7 +115,7 @@ static void insert_one_record(struct shortlog *log,
115
}
116
}
117
118
- string_list_append(buffer, item->util);
118
+ string_list_append(item->util, buffer);
119
}
120
121
static void read_from_stdin(struct shortlog *log)
notes.c
+3
-3
@@ -838,7 +838,7 @@ static int string_list_add_one_ref(const char *path, const unsigned char *sha1,
838
{
839
struct string_list *refs = cb;
840
if (!unsorted_string_list_has_string(refs, path))
841
- string_list_append(path, refs);
841
+ string_list_append(refs, path);
842
return 0;
843
}
844
@@ -851,7 +851,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
851
if (get_sha1(glob, sha1))
852
warning("notes ref %s is invalid", glob);
853
if (!unsorted_string_list_has_string(list, glob))
854
- string_list_append(glob, list);
854
+ string_list_append(list, glob);
855
}
856
}
857
@@ -983,7 +983,7 @@ void init_display_notes(struct display_notes_opt *opt)
983
assert(!display_notes_trees);
984
985
if (!opt || !opt->suppress_default_notes) {
986
- string_list_append(default_notes_ref(), &display_notes_refs);
986
+ string_list_append(&display_notes_refs, default_notes_ref());
987
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
988
if (display_ref_env) {
989
string_list_add_refs_from_colon_sep(&display_notes_refs,
remote.c
+1
-1
@@ -1711,7 +1711,7 @@ struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
1711
info.ref_names = &ref_names;
1712
info.stale_refs_tail = &stale_refs;
1713
for (ref = fetch_map; ref; ref = ref->next)
1714
- string_list_append(ref->name, &ref_names);
1714
+ string_list_append(&ref_names, ref->name);
1715
sort_string_list(&ref_names);
1716
for_each_ref(get_stale_heads_cb, &info);
1717
string_list_clear(&ref_names, 0);
revision.c
+2
-2
@@ -1205,8 +1205,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1205
else
1206
strbuf_addstr(&buf, "refs/notes/");
1207
strbuf_addstr(&buf, arg+13);
1208
- string_list_append(strbuf_detach(&buf, NULL),
1209
- revs->notes_opt.extra_notes_refs);
1208
+ string_list_append(revs->notes_opt.extra_notes_refs,
1209
+ strbuf_detach(&buf, NULL));
1210
} else if (!strcmp(arg, "--no-notes")) {
1211
revs->show_notes = 0;
1212
revs->show_notes_given = 1;
string-list.c
+1
-1
@@ -148,7 +148,7 @@ void print_string_list(const struct string_list *p, const char *text)
148
printf("%s:%p\n", p->items[i].string, p->items[i].util);
149
}
150
151
-struct string_list_item *string_list_append(const char *string, struct string_list *list)
151
+struct string_list_item *string_list_append(struct string_list *list, const char *string)
152
{
153
ALLOC_GROW(list->items, list->nr + 1, list->alloc);
154
list->items[list->nr].string =
string-list.h
+1
-1
@@ -35,7 +35,7 @@ struct string_list_item *string_list_insert_at_index(struct string_list *list,
35
struct string_list_item *string_list_lookup(struct string_list *list, const char *string);
36
37
/* Use these functions only on unsorted lists: */
38
-struct string_list_item *string_list_append(const char *string, struct string_list *list);
38
+struct string_list_item *string_list_append(struct string_list *list, const char *string);
39
void sort_string_list(struct string_list *list);
40
int unsorted_string_list_has_string(struct string_list *list, const char *string);
41
struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
transport-helper.c
+2
-2
@@ -727,10 +727,10 @@ static int push_refs_with_export(struct transport *transport,
727
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
728
if (private && !get_sha1(private, sha1)) {
729
strbuf_addf(&buf, "^%s", private);
730
- string_list_append(strbuf_detach(&buf, NULL), &revlist_args);
730
+ string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
731
}
732
733
- string_list_append(ref->name, &revlist_args);
733
+ string_list_append(&revlist_args, ref->name);
734
735
}
736