@matheusbsbs / matheus-bagliano / commits / c455c87c5c
Fork 0

Rename path_list to string_list

The name path_list was correct for the first usage of that data structure, but it really is a general-purpose string list. $ perl -i -pe 's/path-list/string-list/g' $(git grep -l path-list) $ perl -i -pe 's/path_list/string_list/g' $(git grep -l path_list) $ git mv path-list.h string-list.h $ git mv path-list.c string-list.c $ perl -i -pe 's/has_path/has_string/g' $(git grep -l has_path) $ perl -i -pe 's/path/string/g' string-list.[ch] $ git mv Documentation/technical/api-path-list.txt \ Documentation/technical/api-string-list.txt $ perl -i -pe 's/strdup_paths/strdup_strings/g' $(git grep -l strdup_paths) ... and then fix all users of string-list to access the member "string" instead of "path". Documentation/technical/api-string-list.txt needed some rewrapping, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 21, 2008 at 19:03 UTC c455c87c5cd42bbbe586b31cea1143132f3a39e4
28 files changed +556 -553
Documentation/CodingGuidelines
+1 -1
@@ -105,7 +105,7 @@ For C programs:
105
106 - Use the API. No, really. We have a strbuf (variable length
107 string), several arrays with the ALLOC_GROW() macro, a
108 - path_list for sorted string lists, a hash map (mapping struct
108 + string_list for sorted string lists, a hash map (mapping struct
109 objects) named "struct decorate", amongst other things.
110
111 - When you come up with an API, document it.
Documentation/technical/api-path-list.txt deleted
-126
@@ -1,126 +0,0 @@
1 -path-list API
2 -=============
3 -
4 -The path_list API offers a data structure and functions to handle sorted
5 -and unsorted string lists.
6 -
7 -The name is a bit misleading, a path_list may store not only paths but
8 -strings in general.
9 -
10 -The caller:
11 -
12 -. Allocates and clears a `struct path_list` variable.
13 -
14 -. Initializes the members. You might want to set the flag `strdup_paths`
15 - if the strings should be strdup()ed. For example, this is necessary
16 - when you add something like git_path("..."), since that function returns
17 - a static buffer that will change with the next call to git_path().
18 -+
19 -If you need something advanced, you can manually malloc() the `items`
20 -member (you need this if you add things later) and you should set the
21 -`nr` and `alloc` members in that case, too.
22 -
23 -. Adds new items to the list, using `path_list_append` or `path_list_insert`.
24 -
25 -. Can check if a string is in the list using `path_list_has_path` or
26 - `unsorted_path_list_has_path` and get it from the list using
27 - `path_list_lookup` for sorted lists.
28 -
29 -. Can sort an unsorted list using `sort_path_list`.
30 -
31 -. Finally it should free the list using `path_list_clear`.
32 -
33 -Example:
34 -
35 -----
36 -struct path_list list;
37 -int i;
38 -
39 -memset(&list, 0, sizeof(struct path_list));
40 -path_list_append("foo", &list);
41 -path_list_append("bar", &list);
42 -for (i = 0; i < list.nr; i++)
43 - printf("%s\n", list.items[i].path)
44 -----
45 -
46 -NOTE: It is more efficient to build an unsorted list and sort it
47 -afterwards, instead of building a sorted list (`O(n log n)` instead of
48 -`O(n^2)`).
49 -+
50 -However, if you use the list to check if a certain string was added
51 -already, you should not do that (using unsorted_path_list_has_path()),
52 -because the complexity would be quadratic again (but with a worse factor).
53 -
54 -Functions
55 ----------
56 -
57 -* General ones (works with sorted and unsorted lists as well)
58 -
59 -`print_path_list`::
60 -
61 - Dump a path_list to stdout, useful mainly for debugging purposes. It
62 - can take an optional header argument and it writes out the
63 - string-pointer pairs of the path_list, each one in its own line.
64 -
65 -`path_list_clear`::
66 -
67 - Free a path_list. The `path` pointer of the items will be freed in case
68 - the `strdup_paths` member of the path_list is set. The second parameter
69 - controls if the `util` pointer of the items should be freed or not.
70 -
71 -* Functions for sorted lists only
72 -
73 -`path_list_has_path`::
74 -
75 - Determine if the path_list has a given string or not.
76 -
77 -`path_list_insert`::
78 -
79 - Insert a new element to the path_list. The returned pointer can be handy
80 - if you want to write something to the `util` pointer of the
81 - path_list_item containing the just added string.
82 -+
83 -Since this function uses xrealloc() (which die()s if it fails) if the
84 -list needs to grow, it is safe not to check the pointer. I.e. you may
85 -write `path_list_insert(...)->util = ...;`.
86 -
87 -`path_list_lookup`::
88 -
89 - Look up a given string in the path_list, returning the containing
90 - path_list_item. If the string is not found, NULL is returned.
91 -
92 -* Functions for unsorted lists only
93 -
94 -`path_list_append`::
95 -
96 - Append a new string to the end of the path_list.
97 -
98 -`sort_path_list`::
99 -
100 - Make an unsorted list sorted.
101 -
102 -`unsorted_path_list_has_path`::
103 -
104 - It's like `path_list_has_path()` but for unsorted lists.
105 -+
106 -This function needs to look through all items, as opposed to its
107 -counterpart for sorted lists, which performs a binary search.
108 -
109 -Data structures
110 ----------------
111 -
112 -* `struct path_list_item`
113 -
114 -Represents an item of the list. The `path` member is a pointer to the
115 -string, and you may use the `util` member for any purpose, if you want.
116 -
117 -* `struct path_list`
118 -
119 -Represents the list itself.
120 -
121 -. The array of items are available via the `items` member.
122 -. The `nr` member contains the number of items stored in the list.
123 -. The `alloc` member is used to avoid reallocating at every insertion.
124 - You should not tamper with it.
125 -. Setting the `strdup_paths` member to 1 will strdup() the strings
126 - before adding them, see above.
Documentation/technical/api-string-list.txt new
+128
@@ -0,0 +1,128 @@
1 +string-list API
2 +===============
3 +
4 +The string_list API offers a data structure and functions to handle sorted
5 +and unsorted string lists.
6 +
7 +The 'string_list' struct used to be called 'path_list', but was renamed
8 +because it is not specific to paths.
9 +
10 +The caller:
11 +
12 +. Allocates and clears a `struct string_list` variable.
13 +
14 +. Initializes the members. You might want to set the flag `strdup_strings`
15 + if the strings should be strdup()ed. For example, this is necessary
16 + when you add something like git_path("..."), since that function returns
17 + a static buffer that will change with the next call to git_path().
18 ++
19 +If you need something advanced, you can manually malloc() the `items`
20 +member (you need this if you add things later) and you should set the
21 +`nr` and `alloc` members in that case, too.
22 +
23 +. Adds new items to the list, using `string_list_append` or
24 + `string_list_insert`.
25 +
26 +. Can check if a string is in the list using `string_list_has_string` or
27 + `unsorted_string_list_has_string` and get it from the list using
28 + `string_list_lookup` for sorted lists.
29 +
30 +. Can sort an unsorted list using `sort_string_list`.
31 +
32 +. Finally it should free the list using `string_list_clear`.
33 +
34 +Example:
35 +
36 +----
37 +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);
43 +for (i = 0; i < list.nr; i++)
44 + printf("%s\n", list.items[i].path)
45 +----
46 +
47 +NOTE: It is more efficient to build an unsorted list and sort it
48 +afterwards, instead of building a sorted list (`O(n log n)` instead of
49 +`O(n^2)`).
50 ++
51 +However, if you use the list to check if a certain string was added
52 +already, you should not do that (using unsorted_string_list_has_string()),
53 +because the complexity would be quadratic again (but with a worse factor).
54 +
55 +Functions
56 +---------
57 +
58 +* General ones (works with sorted and unsorted lists as well)
59 +
60 +`print_string_list`::
61 +
62 + Dump a string_list to stdout, useful mainly for debugging purposes. It
63 + can take an optional header argument and it writes out the
64 + string-pointer pairs of the string_list, each one in its own line.
65 +
66 +`string_list_clear`::
67 +
68 + Free a string_list. The `string` pointer of the items will be freed in
69 + case the `strdup_strings` member of the string_list is set. The second
70 + parameter controls if the `util` pointer of the items should be freed
71 + or not.
72 +
73 +* Functions for sorted lists only
74 +
75 +`string_list_has_string`::
76 +
77 + Determine if the string_list has a given string or not.
78 +
79 +`string_list_insert`::
80 +
81 + Insert a new element to the string_list. The returned pointer can be
82 + handy if you want to write something to the `util` pointer of the
83 + string_list_item containing the just added string.
84 ++
85 +Since this function uses xrealloc() (which die()s if it fails) if the
86 +list needs to grow, it is safe not to check the pointer. I.e. you may
87 +write `string_list_insert(...)->util = ...;`.
88 +
89 +`string_list_lookup`::
90 +
91 + Look up a given string in the string_list, returning the containing
92 + string_list_item. If the string is not found, NULL is returned.
93 +
94 +* Functions for unsorted lists only
95 +
96 +`string_list_append`::
97 +
98 + Append a new string to the end of the string_list.
99 +
100 +`sort_string_list`::
101 +
102 + Make an unsorted list sorted.
103 +
104 +`unsorted_string_list_has_string`::
105 +
106 + It's like `string_list_has_string()` but for unsorted lists.
107 ++
108 +This function needs to look through all items, as opposed to its
109 +counterpart for sorted lists, which performs a binary search.
110 +
111 +Data structures
112 +---------------
113 +
114 +* `struct string_list_item`
115 +
116 +Represents an item of the list. The `path` member is a pointer to the
117 +string, and you may use the `util` member for any purpose, if you want.
118 +
119 +* `struct string_list`
120 +
121 +Represents the list itself.
122 +
123 +. The array of items are available via the `items` member.
124 +. The `nr` member contains the number of items stored in the list.
125 +. The `alloc` member is used to avoid reallocating at every insertion.
126 + You should not tamper with it.
127 +. Setting the `strdup_strings` member to 1 will strdup() the strings
128 + before adding them, see above.
Makefile
+2 -2
@@ -356,7 +356,7 @@ LIB_H += pack-refs.h
356 LIB_H += pack-revindex.h
357 LIB_H += parse-options.h
358 LIB_H += patch-ids.h
359 -LIB_H += path-list.h
359 +LIB_H += string-list.h
360 LIB_H += pkt-line.h
361 LIB_H += progress.h
362 LIB_H += quote.h
@@ -437,7 +437,7 @@ LIB_OBJS += pager.o
437 LIB_OBJS += parse-options.o
438 LIB_OBJS += patch-delta.o
439 LIB_OBJS += patch-ids.o
440 -LIB_OBJS += path-list.o
440 +LIB_OBJS += string-list.o
441 LIB_OBJS += path.o
442 LIB_OBJS += pkt-line.o
443 LIB_OBJS += pretty.o
builtin-apply.c
+8 -8
@@ -12,7 +12,7 @@
12 #include "blob.h"
13 #include "delta.h"
14 #include "builtin.h"
15 -#include "path-list.h"
15 +#include "string-list.h"
16
17 /*
18 * --check turns on checking that the working tree matches the
@@ -194,7 +194,7 @@ struct image {
194 * the case where more than one patches touch the same file.
195 */
196
197 -static struct path_list fn_table;
197 +static struct string_list fn_table;
198
199 static uint32_t hash_line(const char *cp, size_t len)
200 {
@@ -2250,12 +2250,12 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
2250
2251 static struct patch *in_fn_table(const char *name)
2252 {
2253 - struct path_list_item *item;
2253 + struct string_list_item *item;
2254
2255 if (name == NULL)
2256 return NULL;
2257
2258 - item = path_list_lookup(name, &fn_table);
2258 + item = string_list_lookup(name, &fn_table);
2259 if (item != NULL)
2260 return (struct patch *)item->util;
2261
@@ -2264,7 +2264,7 @@ static struct patch *in_fn_table(const char *name)
2264
2265 static void add_to_fn_table(struct patch *patch)
2266 {
2267 - struct path_list_item *item;
2267 + struct string_list_item *item;
2268
2269 /*
2270 * Always add new_name unless patch is a deletion
@@ -2272,7 +2272,7 @@ static void add_to_fn_table(struct patch *patch)
2272 * file creations and copies
2273 */
2274 if (patch->new_name != NULL) {
2275 - item = path_list_insert(patch->new_name, &fn_table);
2275 + item = string_list_insert(patch->new_name, &fn_table);
2276 item->util = patch;
2277 }
2278
@@ -2281,7 +2281,7 @@ static void add_to_fn_table(struct patch *patch)
2281 * later chunks shouldn't patch old names
2282 */
2283 if ((patch->new_name == NULL) || (patch->is_rename)) {
2284 - item = path_list_insert(patch->old_name, &fn_table);
2284 + item = string_list_insert(patch->old_name, &fn_table);
2285 item->util = (struct patch *) -1;
2286 }
2287 }
@@ -3051,7 +3051,7 @@ static int apply_patch(int fd, const char *filename, int options)
3051 int skipped_patch = 0;
3052
3053 /* FIXME - memory leak when using multiple patch files as inputs */
3054 - memset(&fn_table, 0, sizeof(struct path_list));
3054 + memset(&fn_table, 0, sizeof(struct string_list));
3055 strbuf_init(&buf, 0);
3056 patch_input_file = filename;
3057 read_patch_file(&buf, fd);
builtin-blame.c
+5 -5
@@ -16,7 +16,7 @@
16 #include "quote.h"
17 #include "xdiff-interface.h"
18 #include "cache-tree.h"
19 -#include "path-list.h"
19 +#include "string-list.h"
20 #include "mailmap.h"
21 #include "parse-options.h"
22
@@ -40,7 +40,7 @@ static int blank_boundary;
40 static int incremental;
41 static int cmd_is_annotate;
42 static int xdl_opts = XDF_NEED_MINIMAL;
43 -static struct path_list mailmap;
43 +static struct string_list mailmap;
44
45 #ifndef DEBUG
46 #define DEBUG 0
@@ -1926,7 +1926,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
1926 * Used for the command line parsing; check if the path exists
1927 * in the working tree.
1928 */
1929 -static int has_path_in_work_tree(const char *path)
1929 +static int has_string_in_work_tree(const char *path)
1930 {
1931 struct stat st;
1932 return !lstat(path, &st);
@@ -2390,14 +2390,14 @@ parse_done:
2390 if (argc < 2)
2391 usage_with_options(blame_opt_usage, options);
2392 path = add_prefix(prefix, argv[argc - 1]);
2393 - if (argc == 3 && !has_path_in_work_tree(path)) { /* (2b) */
2393 + if (argc == 3 && !has_string_in_work_tree(path)) { /* (2b) */
2394 path = add_prefix(prefix, argv[1]);
2395 argv[1] = argv[2];
2396 }
2397 argv[argc - 1] = "--";
2398
2399 setup_work_tree();
2400 - if (!has_path_in_work_tree(path))
2400 + if (!has_string_in_work_tree(path))
2401 die("cannot stat path %s: %s", path, strerror(errno));
2402 }
2403
builtin-commit.c
+10 -10
@@ -21,7 +21,7 @@
21 #include "strbuf.h"
22 #include "utf8.h"
23 #include "parse-options.h"
24 -#include "path-list.h"
24 +#include "string-list.h"
25 #include "rerere.h"
26 #include "unpack-trees.h"
27
@@ -150,7 +150,7 @@ static int commit_index_files(void)
150 * Take a union of paths in the index and the named tree (typically, "HEAD"),
151 * and return the paths that match the given pattern in list.
152 */
153 -static int list_paths(struct path_list *list, const char *with_tree,
153 +static int list_paths(struct string_list *list, const char *with_tree,
154 const char *prefix, const char **pattern)
155 {
156 int i;
@@ -169,24 +169,24 @@ static int list_paths(struct path_list *list, const char *with_tree,
169 continue;
170 if (!pathspec_match(pattern, m, ce->name, 0))
171 continue;
172 - path_list_insert(ce->name, list);
172 + string_list_insert(ce->name, list);
173 }
174
175 return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
176 }
177
178 -static void add_remove_files(struct path_list *list)
178 +static void add_remove_files(struct string_list *list)
179 {
180 int i;
181 for (i = 0; i < list->nr; i++) {
182 struct stat st;
183 - struct path_list_item *p = &(list->items[i]);
183 + struct string_list_item *p = &(list->items[i]);
184
185 - if (!lstat(p->path, &st)) {
186 - if (add_to_cache(p->path, &st, 0))
185 + if (!lstat(p->string, &st)) {
186 + if (add_to_cache(p->string, &st, 0))
187 die("updating files failed");
188 } else
189 - remove_file_from_cache(p->path);
189 + remove_file_from_cache(p->string);
190 }
191 }
192
@@ -221,7 +221,7 @@ static void create_base_index(void)
221 static char *prepare_index(int argc, const char **argv, const char *prefix)
222 {
223 int fd;
224 - struct path_list partial;
224 + struct string_list partial;
225 const char **pathspec = NULL;
226
227 if (interactive) {
@@ -305,7 +305,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
305 die("cannot do a partial commit during a merge.");
306
307 memset(&partial, 0, sizeof(partial));
308 - partial.strdup_paths = 1;
308 + partial.strdup_strings = 1;
309 if (list_paths(&partial, initial_commit ? NULL : "HEAD", prefix, pathspec))
310 exit(1);
311
builtin-fast-export.c
+7 -7
@@ -13,7 +13,7 @@
13 #include "log-tree.h"
14 #include "revision.h"
15 #include "decorate.h"
16 -#include "path-list.h"
16 +#include "string-list.h"
17 #include "utf8.h"
18 #include "parse-options.h"
19
@@ -309,7 +309,7 @@ static void handle_tag(const char *name, struct tag *tag)
309 }
310
311 static void get_tags_and_duplicates(struct object_array *pending,
312 - struct path_list *extra_refs)
312 + struct string_list *extra_refs)
313 {
314 struct tag *tag;
315 int i;
@@ -330,7 +330,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
330 case OBJ_TAG:
331 tag = (struct tag *)e->item;
332 while (tag && tag->object.type == OBJ_TAG) {
333 - path_list_insert(full_name, extra_refs)->util = tag;
333 + string_list_insert(full_name, extra_refs)->util = tag;
334 tag = (struct tag *)tag->tagged;
335 }
336 if (!tag)
@@ -350,19 +350,19 @@ static void get_tags_and_duplicates(struct object_array *pending,
350 }
351 if (commit->util)
352 /* more than one name for the same object */
353 - path_list_insert(full_name, extra_refs)->util = commit;
353 + string_list_insert(full_name, extra_refs)->util = commit;
354 else
355 commit->util = full_name;
356 }
357 }
358
359 -static void handle_tags_and_duplicates(struct path_list *extra_refs)
359 +static void handle_tags_and_duplicates(struct string_list *extra_refs)
360 {
361 struct commit *commit;
362 int i;
363
364 for (i = extra_refs->nr - 1; i >= 0; i--) {
365 - const char *name = extra_refs->items[i].path;
365 + const char *name = extra_refs->items[i].string;
366 struct object *object = extra_refs->items[i].util;
367 switch (object->type) {
368 case OBJ_TAG:
@@ -445,7 +445,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
445 {
446 struct rev_info revs;
447 struct object_array commits = { 0, 0, NULL };
448 - struct path_list extra_refs = { NULL, 0, 0, 0 };
448 + struct string_list extra_refs = { NULL, 0, 0, 0 };
449 struct commit *commit;
450 char *export_filename = NULL, *import_filename = NULL;
451 struct option options[] = {
builtin-fetch.c
+10 -10
@@ -5,7 +5,7 @@
5 #include "refs.h"
6 #include "commit.h"
7 #include "builtin.h"
8 -#include "path-list.h"
8 +#include "string-list.h"
9 #include "remote.h"
10 #include "transport.h"
11 #include "run-command.h"
@@ -465,8 +465,8 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
465 static int add_existing(const char *refname, const unsigned char *sha1,
466 int flag, void *cbdata)
467 {
468 - struct path_list *list = (struct path_list *)cbdata;
469 - path_list_insert(refname, list);
468 + struct string_list *list = (struct string_list *)cbdata;
469 + string_list_insert(refname, list);
470 return 0;
471 }
472
@@ -485,8 +485,8 @@ static void find_non_local_tags(struct transport *transport,
485 struct ref **head,
486 struct ref ***tail)
487 {
488 - struct path_list existing_refs = { NULL, 0, 0, 0 };
489 - struct path_list new_refs = { NULL, 0, 0, 1 };
488 + struct string_list existing_refs = { NULL, 0, 0, 0 };
489 + struct string_list new_refs = { NULL, 0, 0, 1 };
490 char *ref_name;
491 int ref_name_len;
492 const unsigned char *ref_sha1;
@@ -515,11 +515,11 @@ static void find_non_local_tags(struct transport *transport,
515 }
516 }
517
518 - if (!path_list_has_path(&existing_refs, ref_name) &&
519 - !path_list_has_path(&new_refs, ref_name) &&
518 + if (!string_list_has_string(&existing_refs, ref_name) &&
519 + !string_list_has_string(&new_refs, ref_name) &&
520 (has_sha1_file(ref->old_sha1) ||
521 will_fetch(head, ref->old_sha1))) {
522 - path_list_insert(ref_name, &new_refs);
522 + string_list_insert(ref_name, &new_refs);
523
524 rm = alloc_ref_from_str(ref_name);
525 rm->peer_ref = alloc_ref_from_str(ref_name);
@@ -530,8 +530,8 @@ static void find_non_local_tags(struct transport *transport,
530 }
531 free(ref_name);
532 }
533 - path_list_clear(&existing_refs, 0);
534 - path_list_clear(&new_refs, 0);
533 + string_list_clear(&existing_refs, 0);
534 + string_list_clear(&new_refs, 0);
535 }
536
537 static int do_fetch(struct transport *transport,
builtin-mailsplit.c
+6 -6
@@ -6,7 +6,7 @@
6 */
7 #include "cache.h"
8 #include "builtin.h"
9 -#include "path-list.h"
9 +#include "string-list.h"
10
11 static const char git_mailsplit_usage[] =
12 "git mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> [<mbox>|<Maildir>...]";
@@ -115,7 +115,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
115 exit(1);
116 }
117
118 -static int populate_maildir_list(struct path_list *list, const char *path)
118 +static int populate_maildir_list(struct string_list *list, const char *path)
119 {
120 DIR *dir;
121 struct dirent *dent;
@@ -136,7 +136,7 @@ static int populate_maildir_list(struct path_list *list, const char *path)
136 if (dent->d_name[0] == '.')
137 continue;
138 snprintf(name, sizeof(name), "%s/%s", *sub, dent->d_name);
139 - path_list_insert(name, list);
139 + string_list_insert(name, list);
140 }
141
142 closedir(dir);
@@ -152,14 +152,14 @@ static int split_maildir(const char *maildir, const char *dir,
152 char name[PATH_MAX];
153 int ret = -1;
154 int i;
155 - struct path_list list = {NULL, 0, 0, 1};
155 + struct string_list list = {NULL, 0, 0, 1};
156
157 if (populate_maildir_list(&list, maildir) < 0)
158 goto out;
159
160 for (i = 0; i < list.nr; i++) {
161 FILE *f;
162 - snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].path);
162 + snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].string);
163 f = fopen(file, "r");
164 if (!f) {
165 error("cannot open mail %s (%s)", file, strerror(errno));
@@ -179,7 +179,7 @@ static int split_maildir(const char *maildir, const char *dir,
179
180 ret = skip;
181 out:
182 - path_list_clear(&list, 1);
182 + string_list_clear(&list, 1);
183 return ret;
184 }
185
builtin-merge-recursive.c
+48 -48
@@ -13,7 +13,7 @@
13 #include "diffcore.h"
14 #include "tag.h"
15 #include "unpack-trees.h"
16 -#include "path-list.h"
16 +#include "string-list.h"
17 #include "xdiff-interface.h"
18 #include "ll-merge.h"
19 #include "interpolate.h"
@@ -79,8 +79,8 @@ struct stage_data
79 unsigned processed:1;
80 };
81
82 -static struct path_list current_file_set = {NULL, 0, 0, 1};
83 -static struct path_list current_directory_set = {NULL, 0, 0, 1};
82 +static struct string_list current_file_set = {NULL, 0, 0, 1};
83 +static struct string_list current_directory_set = {NULL, 0, 0, 1};
84
85 static int call_depth = 0;
86 static int verbosity = 2;
@@ -257,9 +257,9 @@ static int save_files_dirs(const unsigned char *sha1,
257 newpath[baselen + len] = '\0';
258
259 if (S_ISDIR(mode))
260 - path_list_insert(newpath, &current_directory_set);
260 + string_list_insert(newpath, &current_directory_set);
261 else
262 - path_list_insert(newpath, &current_file_set);
262 + string_list_insert(newpath, &current_file_set);
263 free(newpath);
264
265 return READ_TREE_RECURSIVE;
@@ -280,9 +280,9 @@ static int get_files_dirs(struct tree *tree)
280 */
281 static struct stage_data *insert_stage_data(const char *path,
282 struct tree *o, struct tree *a, struct tree *b,
283 - struct path_list *entries)
283 + struct string_list *entries)
284 {
285 - struct path_list_item *item;
285 + struct string_list_item *item;
286 struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
287 get_tree_entry(o->object.sha1, path,
288 e->stages[1].sha, &e->stages[1].mode);
@@ -290,7 +290,7 @@ static struct stage_data *insert_stage_data(const char *path,
290 e->stages[2].sha, &e->stages[2].mode);
291 get_tree_entry(b->object.sha1, path,
292 e->stages[3].sha, &e->stages[3].mode);
293 - item = path_list_insert(path, entries);
293 + item = string_list_insert(path, entries);
294 item->util = e;
295 return e;
296 }
@@ -299,23 +299,23 @@ static struct stage_data *insert_stage_data(const char *path,
299 * Create a dictionary mapping file names to stage_data objects. The
300 * dictionary contains one entry for every path with a non-zero stage entry.
301 */
302 -static struct path_list *get_unmerged(void)
302 +static struct string_list *get_unmerged(void)
303 {
304 - struct path_list *unmerged = xcalloc(1, sizeof(struct path_list));
304 + struct string_list *unmerged = xcalloc(1, sizeof(struct string_list));
305 int i;
306
307 - unmerged->strdup_paths = 1;
307 + unmerged->strdup_strings = 1;
308
309 for (i = 0; i < active_nr; i++) {
310 - struct path_list_item *item;
310 + struct string_list_item *item;
311 struct stage_data *e;
312 struct cache_entry *ce = active_cache[i];
313 if (!ce_stage(ce))
314 continue;
315
316 - item = path_list_lookup(ce->name, unmerged);
316 + item = string_list_lookup(ce->name, unmerged);
317 if (!item) {
318 - item = path_list_insert(ce->name, unmerged);
318 + item = string_list_insert(ce->name, unmerged);
319 item->util = xcalloc(1, sizeof(struct stage_data));
320 }
321 e = item->util;
@@ -340,17 +340,17 @@ struct rename
340 * 'b_tree') to be able to associate the correct cache entries with
341 * the rename information. 'tree' is always equal to either a_tree or b_tree.
342 */
343 -static struct path_list *get_renames(struct tree *tree,
343 +static struct string_list *get_renames(struct tree *tree,
344 struct tree *o_tree,
345 struct tree *a_tree,
346 struct tree *b_tree,
347 - struct path_list *entries)
347 + struct string_list *entries)
348 {
349 int i;
350 - struct path_list *renames;
350 + struct string_list *renames;
351 struct diff_options opts;
352
353 - renames = xcalloc(1, sizeof(struct path_list));
353 + renames = xcalloc(1, sizeof(struct string_list));
354 diff_setup(&opts);
355 DIFF_OPT_SET(&opts, RECURSIVE);
356 opts.detect_rename = DIFF_DETECT_RENAME;
@@ -364,7 +364,7 @@ static struct path_list *get_renames(struct tree *tree,
364 diff_tree_sha1(o_tree->object.sha1, tree->object.sha1, "", &opts);
365 diffcore_std(&opts);
366 for (i = 0; i < diff_queued_diff.nr; ++i) {
367 - struct path_list_item *item;
367 + struct string_list_item *item;
368 struct rename *re;
369 struct diff_filepair *pair = diff_queued_diff.queue[i];
370 if (pair->status != 'R') {
@@ -374,20 +374,20 @@ static struct path_list *get_renames(struct tree *tree,
374 re = xmalloc(sizeof(*re));
375 re->processed = 0;
376 re->pair = pair;
377 - item = path_list_lookup(re->pair->one->path, entries);
377 + item = string_list_lookup(re->pair->one->path, entries);
378 if (!item)
379 re->src_entry = insert_stage_data(re->pair->one->path,
380 o_tree, a_tree, b_tree, entries);
381 else
382 re->src_entry = item->util;
383
384 - item = path_list_lookup(re->pair->two->path, entries);
384 + item = string_list_lookup(re->pair->two->path, entries);
385 if (!item)
386 re->dst_entry = insert_stage_data(re->pair->two->path,
387 o_tree, a_tree, b_tree, entries);
388 else
389 re->dst_entry = item->util;
390 - item = path_list_insert(pair->one->path, renames);
390 + item = string_list_insert(pair->one->path, renames);
391 item->util = re;
392 }
393 opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -464,12 +464,12 @@ static char *unique_path(const char *path, const char *branch)
464 for (; *p; ++p)
465 if ('/' == *p)
466 *p = '_';
467 - while (path_list_has_path(&current_file_set, newpath) ||
468 - path_list_has_path(&current_directory_set, newpath) ||
467 + while (string_list_has_string(&current_file_set, newpath) ||
468 + string_list_has_string(&current_directory_set, newpath) ||
469 lstat(newpath, &st) == 0)
470 sprintf(p, "_%d", suffix++);
471
472 - path_list_insert(newpath, &current_file_set);
472 + string_list_insert(newpath, &current_file_set);
473 return newpath;
474 }
475
@@ -727,13 +727,13 @@ static void conflict_rename_rename(struct rename *ren1,
727 const char *ren2_dst = ren2->pair->two->path;
728 const char *dst_name1 = ren1_dst;
729 const char *dst_name2 = ren2_dst;
730 - if (path_list_has_path(&current_directory_set, ren1_dst)) {
730 + if (string_list_has_string(&current_directory_set, ren1_dst)) {
731 dst_name1 = del[delp++] = unique_path(ren1_dst, branch1);
732 output(1, "%s is a directory in %s added as %s instead",
733 ren1_dst, branch2, dst_name1);
734 remove_file(0, ren1_dst, 0);
735 }
736 - if (path_list_has_path(&current_directory_set, ren2_dst)) {
736 + if (string_list_has_string(&current_directory_set, ren2_dst)) {
737 dst_name2 = del[delp++] = unique_path(ren2_dst, branch2);
738 output(1, "%s is a directory in %s added as %s instead",
739 ren2_dst, branch1, dst_name2);
@@ -783,30 +783,30 @@ static void conflict_rename_rename_2(struct rename *ren1,
783 free(new_path1);
784 }
785
786 -static int process_renames(struct path_list *a_renames,
787 - struct path_list *b_renames,
786 +static int process_renames(struct string_list *a_renames,
787 + struct string_list *b_renames,
788 const char *a_branch,
789 const char *b_branch)
790 {
791 int clean_merge = 1, i, j;
792 - struct path_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
792 + struct string_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
793 const struct rename *sre;
794
795 for (i = 0; i < a_renames->nr; i++) {
796 sre = a_renames->items[i].util;
797 - path_list_insert(sre->pair->two->path, &a_by_dst)->util
797 + string_list_insert(sre->pair->two->path, &a_by_dst)->util
798 = sre->dst_entry;
799 }
800 for (i = 0; i < b_renames->nr; i++) {
801 sre = b_renames->items[i].util;
802 - path_list_insert(sre->pair->two->path, &b_by_dst)->util
802 + string_list_insert(sre->pair->two->path, &b_by_dst)->util
803 = sre->dst_entry;
804 }
805
806 for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
807 int compare;
808 char *src;
809 - struct path_list *renames1, *renames2, *renames2Dst;
809 + struct string_list *renames1, *renames2, *renames2Dst;
810 struct rename *ren1 = NULL, *ren2 = NULL;
811 const char *branch1, *branch2;
812 const char *ren1_src, *ren1_dst;
@@ -818,8 +818,8 @@ static int process_renames(struct path_list *a_renames,
818 compare = -1;
819 ren1 = a_renames->items[i++].util;
820 } else {
821 - compare = strcmp(a_renames->items[i].path,
822 - b_renames->items[j].path);
821 + compare = strcmp(a_renames->items[i].string,
822 + b_renames->items[j].string);
823 if (compare <= 0)
824 ren1 = a_renames->items[i++].util;
825 if (compare >= 0)
@@ -908,7 +908,7 @@ static int process_renames(struct path_list *a_renames,
908 }
909 } else {
910 /* Renamed in 1, maybe changed in 2 */
911 - struct path_list_item *item;
911 + struct string_list_item *item;
912 /* we only use sha1 and mode of these */
913 struct diff_filespec src_other, dst_other;
914 int try_merge, stage = a_renames == renames1 ? 3: 2;
@@ -922,7 +922,7 @@ static int process_renames(struct path_list *a_renames,
922
923 try_merge = 0;
924
925 - if (path_list_has_path(&current_directory_set, ren1_dst)) {
925 + if (string_list_has_string(&current_directory_set, ren1_dst)) {
926 clean_merge = 0;
927 output(1, "CONFLICT (rename/directory): Renamed %s->%s in %s "
928 " directory %s added in %s",
@@ -947,7 +947,7 @@ static int process_renames(struct path_list *a_renames,
947 new_path = unique_path(ren1_dst, branch2);
948 output(1, "Added as %s instead", new_path);
949 update_file(0, dst_other.sha1, dst_other.mode, new_path);
950 - } else if ((item = path_list_lookup(ren1_dst, renames2Dst))) {
950 + } else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {
951 ren2 = item->util;
952 clean_merge = 0;
953 ren2->processed = 1;
@@ -1003,8 +1003,8 @@ static int process_renames(struct path_list *a_renames,
1003 }
1004 }
1005 }
1006 - path_list_clear(&a_by_dst, 0);
1007 - path_list_clear(&b_by_dst, 0);
1006 + string_list_clear(&a_by_dst, 0);
1007 + string_list_clear(&b_by_dst, 0);
1008
1009 return clean_merge;
1010 }
@@ -1082,7 +1082,7 @@ static int process_entry(const char *path, struct stage_data *entry,
1082 sha = b_sha;
1083 conf = "directory/file";
1084 }
1085 - if (path_list_has_path(&current_directory_set, path)) {
1085 + if (string_list_has_string(&current_directory_set, path)) {
1086 const char *new_path = unique_path(path, add_branch);
1087 clean_merge = 0;
1088 output(1, "CONFLICT (%s): There is a directory with name %s in %s. "
@@ -1173,10 +1173,10 @@ int merge_trees(struct tree *head,
1173 sha1_to_hex(merge->object.sha1));
1174
1175 if (unmerged_cache()) {
1176 - struct path_list *entries, *re_head, *re_merge;
1176 + struct string_list *entries, *re_head, *re_merge;
1177 int i;
1178 - path_list_clear(&current_file_set, 1);
1179 - path_list_clear(&current_directory_set, 1);
1178 + string_list_clear(&current_file_set, 1);
1179 + string_list_clear(&current_directory_set, 1);
1180 get_files_dirs(head);
1181 get_files_dirs(merge);
1182
@@ -1186,16 +1186,16 @@ int merge_trees(struct tree *head,
1186 clean = process_renames(re_head, re_merge,
1187 branch1, branch2);
1188 for (i = 0; i < entries->nr; i++) {
1189 - const char *path = entries->items[i].path;
1189 + const char *path = entries->items[i].string;
1190 struct stage_data *e = entries->items[i].util;
1191 if (!e->processed
1192 && !process_entry(path, e, branch1, branch2))
1193 clean = 0;
1194 }
1195
1196 - path_list_clear(re_merge, 0);
1197 - path_list_clear(re_head, 0);
1198 - path_list_clear(entries, 1);
1196 + string_list_clear(re_merge, 0);
1197 + string_list_clear(re_head, 0);
1198 + string_list_clear(entries, 1);
1199
1200 }
1201 else
builtin-mv.c
+20 -19
@@ -7,7 +7,7 @@
7 #include "builtin.h"
8 #include "dir.h"
9 #include "cache-tree.h"
10 -#include "path-list.h"
10 +#include "string-list.h"
11 #include "parse-options.h"
12
13 static const char * const builtin_mv_usage[] = {
@@ -36,13 +36,14 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
36 return get_pathspec(prefix, result);
37 }
38
39 -static void show_list(const char *label, struct path_list *list)
39 +static void show_list(const char *label, struct string_list *list)
40 {
41 if (list->nr > 0) {
42 int i;
43 printf("%s", label);
44 for (i = 0; i < list->nr; i++)
45 - printf("%s%s", i > 0 ? ", " : "", list->items[i].path);
45 + printf("%s%s", i > 0 ? ", " : "",
46 + list->items[i].string);
47 putchar('\n');
48 }
49 }
@@ -75,11 +76,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
76 const char **source, **destination, **dest_path;
77 enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
78 struct stat st;
78 - struct path_list overwritten = {NULL, 0, 0, 0};
79 - struct path_list src_for_dst = {NULL, 0, 0, 0};
80 - struct path_list added = {NULL, 0, 0, 0};
81 - struct path_list deleted = {NULL, 0, 0, 0};
82 - struct path_list changed = {NULL, 0, 0, 0};
79 + struct string_list overwritten = {NULL, 0, 0, 0};
80 + struct string_list src_for_dst = {NULL, 0, 0, 0};
81 + struct string_list added = {NULL, 0, 0, 0};
82 + struct string_list deleted = {NULL, 0, 0, 0};
83 + struct string_list changed = {NULL, 0, 0, 0};
84
85 git_config(git_default_config, NULL);
86
@@ -189,16 +190,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
190 " will overwrite!\n",
191 bad);
192 bad = NULL;
192 - path_list_insert(dst, &overwritten);
193 + string_list_insert(dst, &overwritten);
194 } else
195 bad = "Cannot overwrite";
196 }
197 } else if (cache_name_pos(src, length) < 0)
198 bad = "not under version control";
198 - else if (path_list_has_path(&src_for_dst, dst))
199 + else if (string_list_has_string(&src_for_dst, dst))
200 bad = "multiple sources for the same target";
201 else
201 - path_list_insert(dst, &src_for_dst);
202 + string_list_insert(dst, &src_for_dst);
203
204 if (bad) {
205 if (ignore_errors) {
@@ -228,15 +229,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
229 continue;
230
231 if (cache_name_pos(src, strlen(src)) >= 0) {
231 - path_list_insert(src, &deleted);
232 + string_list_insert(src, &deleted);
233
234 /* destination can be a directory with 1 file inside */
234 - if (path_list_has_path(&overwritten, dst))
235 - path_list_insert(dst, &changed);
235 + if (string_list_has_string(&overwritten, dst))
236 + string_list_insert(dst, &changed);
237 else
237 - path_list_insert(dst, &added);
238 + string_list_insert(dst, &added);
239 } else
239 - path_list_insert(dst, &added);
240 + string_list_insert(dst, &added);
241 }
242
243 if (show_only) {
@@ -245,7 +246,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
246 show_list("Deleting : ", &deleted);
247 } else {
248 for (i = 0; i < changed.nr; i++) {
248 - const char *path = changed.items[i].path;
249 + const char *path = changed.items[i].string;
250 int j = cache_name_pos(path, strlen(path));
251 struct cache_entry *ce = active_cache[j];
252
@@ -255,13 +256,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
256 }
257
258 for (i = 0; i < added.nr; i++) {
258 - const char *path = added.items[i].path;
259 + const char *path = added.items[i].string;
260 if (add_file_to_cache(path, verbose ? ADD_CACHE_VERBOSE : 0))
261 die("updating index entries failed");
262 }
263
264 for (i = 0; i < deleted.nr; i++)
264 - remove_file_from_cache(deleted.items[i].path);
265 + remove_file_from_cache(deleted.items[i].string);
266
267 if (active_cache_changed) {
268 if (write_cache(newfd, active_cache, active_nr) ||
builtin-remote.c
+62 -62
@@ -2,7 +2,7 @@
2 #include "parse-options.h"
3 #include "transport.h"
4 #include "remote.h"
5 -#include "path-list.h"
5 +#include "string-list.h"
6 #include "strbuf.h"
7 #include "run-command.h"
8 #include "refs.h"
@@ -31,11 +31,11 @@ static inline int postfixcmp(const char *string, const char *postfix)
31
32 static int opt_parse_track(const struct option *opt, const char *arg, int not)
33 {
34 - struct path_list *list = opt->value;
34 + struct string_list *list = opt->value;
35 if (not)
36 - path_list_clear(list, 0);
36 + string_list_clear(list, 0);
37 else
38 - path_list_append(arg, list);
38 + string_list_append(arg, list);
39 return 0;
40 }
41
@@ -51,7 +51,7 @@ static int fetch_remote(const char *name)
51 static int add(int argc, const char **argv)
52 {
53 int fetch = 0, mirror = 0;
54 - struct path_list track = { NULL, 0, 0 };
54 + struct string_list track = { NULL, 0, 0 };
55 const char *master = NULL;
56 struct remote *remote;
57 struct strbuf buf, buf2;
@@ -96,18 +96,18 @@ static int add(int argc, const char **argv)
96 strbuf_addf(&buf, "remote.%s.fetch", name);
97
98 if (track.nr == 0)
99 - path_list_append("*", &track);
99 + string_list_append("*", &track);
100 for (i = 0; i < track.nr; i++) {
101 - struct path_list_item *item = track.items + i;
101 + struct string_list_item *item = track.items + i;
102
103 strbuf_reset(&buf2);
104 strbuf_addch(&buf2, '+');
105 if (mirror)
106 strbuf_addf(&buf2, "refs/%s:refs/%s",
107 - item->path, item->path);
107 + item->string, item->string);
108 else
109 strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s",
110 - item->path, name, item->path);
110 + item->string, name, item->string);
111 if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
112 return 1;
113 }
@@ -135,17 +135,17 @@ static int add(int argc, const char **argv)
135
136 strbuf_release(&buf);
137 strbuf_release(&buf2);
138 - path_list_clear(&track, 0);
138 + string_list_clear(&track, 0);
139
140 return 0;
141 }
142
143 struct branch_info {
144 char *remote;
145 - struct path_list merge;
145 + struct string_list merge;
146 };
147
148 -static struct path_list branch_list;
148 +static struct string_list branch_list;
149
150 static const char *abbrev_ref(const char *name, const char *prefix)
151 {
@@ -160,7 +160,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
160 {
161 if (!prefixcmp(key, "branch.")) {
162 char *name;
163 - struct path_list_item *item;
163 + struct string_list_item *item;
164 struct branch_info *info;
165 enum { REMOTE, MERGE } type;
166
@@ -174,7 +174,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
174 } else
175 return 0;
176
177 - item = path_list_insert(name, &branch_list);
177 + item = string_list_insert(name, &branch_list);
178
179 if (!item->util)
180 item->util = xcalloc(sizeof(struct branch_info), 1);
@@ -189,11 +189,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
189 while (space) {
190 char *merge;
191 merge = xstrndup(value, space - value);
192 - path_list_append(merge, &info->merge);
192 + string_list_append(merge, &info->merge);
193 value = abbrev_branch(space + 1);
194 space = strchr(value, ' ');
195 }
196 - path_list_append(xstrdup(value), &info->merge);
196 + string_list_append(xstrdup(value), &info->merge);
197 }
198 }
199 return 0;
@@ -204,12 +204,12 @@ static void read_branches(void)
204 if (branch_list.nr)
205 return;
206 git_config(config_read_branches, NULL);
207 - sort_path_list(&branch_list);
207 + sort_string_list(&branch_list);
208 }
209
210 struct ref_states {
211 struct remote *remote;
212 - struct path_list new, stale, tracked;
212 + struct string_list new, stale, tracked;
213 };
214
215 static int handle_one_branch(const char *refname,
@@ -221,16 +221,16 @@ static int handle_one_branch(const char *refname,
221 memset(&refspec, 0, sizeof(refspec));
222 refspec.dst = (char *)refname;
223 if (!remote_find_tracking(states->remote, &refspec)) {
224 - struct path_list_item *item;
224 + struct string_list_item *item;
225 const char *name = abbrev_branch(refspec.src);
226 /* symbolic refs pointing nowhere were handled already */
227 if ((flags & REF_ISSYMREF) ||
228 - unsorted_path_list_has_path(&states->tracked,
228 + unsorted_string_list_has_string(&states->tracked,
229 name) ||
230 - unsorted_path_list_has_path(&states->new,
230 + unsorted_string_list_has_string(&states->new,
231 name))
232 return 0;
233 - item = path_list_append(name, &states->stale);
233 + item = string_list_append(name, &states->stale);
234 item->util = xstrdup(refname);
235 }
236 return 0;
@@ -246,9 +246,9 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
246 die("Could not get fetch map for refspec %s",
247 states->remote->fetch_refspec[i]);
248
249 - states->new.strdup_paths = states->tracked.strdup_paths = 1;
249 + states->new.strdup_strings = states->tracked.strdup_strings = 1;
250 for (ref = fetch_map; ref; ref = ref->next) {
251 - struct path_list *target = &states->tracked;
251 + struct string_list *target = &states->tracked;
252 unsigned char sha1[20];
253 void *util = NULL;
254
@@ -259,12 +259,12 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
259 if (hashcmp(sha1, ref->new_sha1))
260 util = &states;
261 }
262 - path_list_append(abbrev_branch(ref->name), target)->util = util;
262 + string_list_append(abbrev_branch(ref->name), target)->util = util;
263 }
264 free_refs(fetch_map);
265
266 for_each_ref(handle_one_branch, states);
267 - sort_path_list(&states->stale);
267 + sort_string_list(&states->stale);
268
269 return 0;
270 }
@@ -296,7 +296,7 @@ static int add_known_remote(struct remote *remote, void *cb_data)
296
297 struct branches_for_remote {
298 struct remote *remote;
299 - struct path_list *branches;
299 + struct string_list *branches;
300 struct known_remotes *keep;
301 };
302
@@ -305,7 +305,7 @@ static int add_branch_for_removal(const char *refname,
305 {
306 struct branches_for_remote *branches = cb_data;
307 struct refspec refspec;
308 - struct path_list_item *item;
308 + struct string_list_item *item;
309 struct known_remote *kr;
310
311 memset(&refspec, 0, sizeof(refspec));
@@ -325,19 +325,19 @@ static int add_branch_for_removal(const char *refname,
325 if (flags & REF_ISSYMREF)
326 return unlink(git_path(refname));
327
328 - item = path_list_append(refname, branches->branches);
328 + item = string_list_append(refname, branches->branches);
329 item->util = xmalloc(20);
330 hashcpy(item->util, sha1);
331
332 return 0;
333 }
334
335 -static int remove_branches(struct path_list *branches)
335 +static int remove_branches(struct string_list *branches)
336 {
337 int i, result = 0;
338 for (i = 0; i < branches->nr; i++) {
339 - struct path_list_item *item = branches->items + i;
340 - const char *refname = item->path;
339 + struct string_list_item *item = branches->items + i;
340 + const char *refname = item->string;
341 unsigned char *sha1 = item->util;
342
343 if (delete_ref(refname, sha1))
@@ -354,7 +354,7 @@ static int rm(int argc, const char **argv)
354 struct remote *remote;
355 struct strbuf buf;
356 struct known_remotes known_remotes = { NULL, NULL };
357 - struct path_list branches = { NULL, 0, 0, 1 };
357 + struct string_list branches = { NULL, 0, 0, 1 };
358 struct branches_for_remote cb_data = { NULL, &branches, &known_remotes };
359 int i;
360
@@ -375,14 +375,14 @@ static int rm(int argc, const char **argv)
375
376 read_branches();
377 for (i = 0; i < branch_list.nr; i++) {
378 - struct path_list_item *item = branch_list.items + i;
378 + struct string_list_item *item = branch_list.items + i;
379 struct branch_info *info = item->util;
380 if (info->remote && !strcmp(info->remote, remote->name)) {
381 const char *keys[] = { "remote", "merge", NULL }, **k;
382 for (k = keys; *k; k++) {
383 strbuf_reset(&buf);
384 strbuf_addf(&buf, "branch.%s.%s",
385 - item->path, *k);
385 + item->string, *k);
386 if (git_config_set(buf.buf, NULL)) {
387 strbuf_release(&buf);
388 return -1;
@@ -402,12 +402,12 @@ static int rm(int argc, const char **argv)
402
403 if (!i)
404 i = remove_branches(&branches);
405 - path_list_clear(&branches, 1);
405 + string_list_clear(&branches, 1);
406
407 return i;
408 }
409
410 -static void show_list(const char *title, struct path_list *list)
410 +static void show_list(const char *title, struct string_list *list)
411 {
412 int i;
413
@@ -417,7 +417,7 @@ static void show_list(const char *title, struct path_list *list)
417 printf(title, list->nr > 1 ? "es" : "");
418 printf("\n ");
419 for (i = 0; i < list->nr; i++)
420 - printf("%s%s", i ? " " : "", list->items[i].path);
420 + printf("%s%s", i ? " " : "", list->items[i].string);
421 printf("\n");
422 }
423
@@ -455,7 +455,7 @@ static int append_ref_to_tracked_list(const char *refname,
455 memset(&refspec, 0, sizeof(refspec));
456 refspec.dst = (char *)refname;
457 if (!remote_find_tracking(states->remote, &refspec))
458 - path_list_append(abbrev_branch(refspec.src), &states->tracked);
458 + string_list_append(abbrev_branch(refspec.src), &states->tracked);
459
460 return 0;
461 }
@@ -487,7 +487,7 @@ static int show(int argc, const char **argv)
487 states.remote->url[0] : "(no URL)");
488
489 for (i = 0; i < branch_list.nr; i++) {
490 - struct path_list_item *branch = branch_list.items + i;
490 + struct string_list_item *branch = branch_list.items + i;
491 struct branch_info *info = branch->util;
492 int j;
493
@@ -496,9 +496,9 @@ static int show(int argc, const char **argv)
496 printf(" Remote branch%s merged with 'git pull' "
497 "while on branch %s\n ",
498 info->merge.nr > 1 ? "es" : "",
499 - branch->path);
499 + branch->string);
500 for (j = 0; j < info->merge.nr; j++)
501 - printf(" %s", info->merge.items[j].path);
501 + printf(" %s", info->merge.items[j].string);
502 printf("\n");
503 }
504
@@ -531,9 +531,9 @@ static int show(int argc, const char **argv)
531 }
532
533 /* NEEDSWORK: free remote */
534 - path_list_clear(&states.new, 0);
535 - path_list_clear(&states.stale, 0);
536 - path_list_clear(&states.tracked, 0);
534 + string_list_clear(&states.new, 0);
535 + string_list_clear(&states.stale, 0);
536 + string_list_clear(&states.tracked, 0);
537 }
538
539 return result;
@@ -579,9 +579,9 @@ static int prune(int argc, const char **argv)
579 }
580
581 /* NEEDSWORK: free remote */
582 - path_list_clear(&states.new, 0);
583 - path_list_clear(&states.stale, 0);
584 - path_list_clear(&states.tracked, 0);
582 + string_list_clear(&states.new, 0);
583 + string_list_clear(&states.stale, 0);
584 + string_list_clear(&states.tracked, 0);
585 }
586
587 return result;
@@ -589,15 +589,15 @@ static int prune(int argc, const char **argv)
589
590 static int get_one_remote_for_update(struct remote *remote, void *priv)
591 {
592 - struct path_list *list = priv;
592 + struct string_list *list = priv;
593 if (!remote->skip_default_update)
594 - path_list_append(xstrdup(remote->name), list);
594 + string_list_append(xstrdup(remote->name), list);
595 return 0;
596 }
597
598 struct remote_group {
599 const char *name;
600 - struct path_list *list;
600 + struct string_list *list;
601 } remote_group;
602
603 static int get_remote_group(const char *key, const char *value, void *cb)
@@ -608,7 +608,7 @@ static int get_remote_group(const char *key, const char *value, void *cb)
608 int space = strcspn(value, " \t\n");
609 while (*value) {
610 if (space > 1)
611 - path_list_append(xstrndup(value, space),
611 + string_list_append(xstrndup(value, space),
612 remote_group.list);
613 value += space + (value[space] != '\0');
614 space = strcspn(value, " \t\n");
@@ -621,7 +621,7 @@ static int get_remote_group(const char *key, const char *value, void *cb)
621 static int update(int argc, const char **argv)
622 {
623 int i, result = 0;
624 - struct path_list list = { NULL, 0, 0, 0 };
624 + struct string_list list = { NULL, 0, 0, 0 };
625 static const char *default_argv[] = { NULL, "default", NULL };
626
627 if (argc < 2) {
@@ -639,20 +639,20 @@ static int update(int argc, const char **argv)
639 result = for_each_remote(get_one_remote_for_update, &list);
640
641 for (i = 0; i < list.nr; i++)
642 - result |= fetch_remote(list.items[i].path);
642 + result |= fetch_remote(list.items[i].string);
643
644 /* all names were strdup()ed or strndup()ed */
645 - list.strdup_paths = 1;
646 - path_list_clear(&list, 0);
645 + list.strdup_strings = 1;
646 + string_list_clear(&list, 0);
647
648 return result;
649 }
650
651 static int get_one_entry(struct remote *remote, void *priv)
652 {
653 - struct path_list *list = priv;
653 + struct string_list *list = priv;
654
655 - path_list_append(remote->name, list)->util = remote->url_nr ?
655 + string_list_append(remote->name, list)->util = remote->url_nr ?
656 (void *)remote->url[0] : NULL;
657 if (remote->url_nr > 1)
658 warning("Remote %s has more than one URL", remote->name);
@@ -662,16 +662,16 @@ static int get_one_entry(struct remote *remote, void *priv)
662
663 static int show_all(void)
664 {
665 - struct path_list list = { NULL, 0, 0 };
665 + struct string_list list = { NULL, 0, 0 };
666 int result = for_each_remote(get_one_entry, &list);
667
668 if (!result) {
669 int i;
670
671 - sort_path_list(&list);
671 + sort_string_list(&list);
672 for (i = 0; i < list.nr; i++) {
673 - struct path_list_item *item = list.items + i;
674 - printf("%s%s%s\n", item->path,
673 + struct string_list_item *item = list.items + i;
674 + printf("%s%s%s\n", item->string,
675 verbose ? "\t" : "",
676 verbose && item->util ?
677 (const char *)item->util : "");
builtin-rerere.c
+10 -10
@@ -1,6 +1,6 @@
1 #include "builtin.h"
2 #include "cache.h"
3 -#include "path-list.h"
3 +#include "string-list.h"
4 #include "rerere.h"
5 #include "xdiff/xdiff.h"
6 #include "xdiff-interface.h"
@@ -48,9 +48,9 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb)
48 return 0;
49 }
50
51 -static void garbage_collect(struct path_list *rr)
51 +static void garbage_collect(struct string_list *rr)
52 {
53 - struct path_list to_remove = { NULL, 0, 0, 1 };
53 + struct string_list to_remove = { NULL, 0, 0, 1 };
54 DIR *dir;
55 struct dirent *e;
56 int i, cutoff;
@@ -69,11 +69,11 @@ static void garbage_collect(struct path_list *rr)
69 cutoff = (has_resolution(name)
70 ? cutoff_resolve : cutoff_noresolve);
71 if (then < now - cutoff * 86400)
72 - path_list_append(name, &to_remove);
72 + string_list_append(name, &to_remove);
73 }
74 for (i = 0; i < to_remove.nr; i++)
75 - unlink_rr_item(to_remove.items[i].path);
76 - path_list_clear(&to_remove, 0);
75 + unlink_rr_item(to_remove.items[i].string);
76 + string_list_clear(&to_remove, 0);
77 }
78
79 static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
@@ -111,7 +111,7 @@ static int diff_two(const char *file1, const char *label1,
111
112 int cmd_rerere(int argc, const char **argv, const char *prefix)
113 {
114 - struct path_list merge_rr = { NULL, 0, 0, 1 };
114 + struct string_list merge_rr = { NULL, 0, 0, 1 };
115 int i, fd;
116
117 if (argc < 2)
@@ -132,16 +132,16 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
132 garbage_collect(&merge_rr);
133 else if (!strcmp(argv[1], "status"))
134 for (i = 0; i < merge_rr.nr; i++)
135 - printf("%s\n", merge_rr.items[i].path);
135 + printf("%s\n", merge_rr.items[i].string);
136 else if (!strcmp(argv[1], "diff"))
137 for (i = 0; i < merge_rr.nr; i++) {
138 - const char *path = merge_rr.items[i].path;
138 + const char *path = merge_rr.items[i].string;
139 const char *name = (const char *)merge_rr.items[i].util;
140 diff_two(rr_path(name, "preimage"), path, path, path);
141 }
142 else
143 usage(git_rerere_usage);
144
145 - path_list_clear(&merge_rr, 1);
145 + string_list_clear(&merge_rr, 1);
146 return 0;
147 }
builtin-shortlog.c
+21 -21
@@ -2,7 +2,7 @@
2 #include "cache.h"
3 #include "commit.h"
4 #include "diff.h"
5 -#include "path-list.h"
5 +#include "string-list.h"
6 #include "revision.h"
7 #include "utf8.h"
8 #include "mailmap.h"
@@ -18,8 +18,8 @@ static char const * const shortlog_usage[] = {
18
19 static int compare_by_number(const void *a1, const void *a2)
20 {
21 - const struct path_list_item *i1 = a1, *i2 = a2;
22 - const struct path_list *l1 = i1->util, *l2 = i2->util;
21 + const struct string_list_item *i1 = a1, *i2 = a2;
22 + const struct string_list *l1 = i1->util, *l2 = i2->util;
23
24 if (l1->nr < l2->nr)
25 return 1;
@@ -35,8 +35,8 @@ static void insert_one_record(struct shortlog *log,
35 {
36 const char *dot3 = log->common_repo_prefix;
37 char *buffer, *p;
38 - struct path_list_item *item;
39 - struct path_list *onelines;
38 + struct string_list_item *item;
39 + struct string_list *onelines;
40 char namebuf[1024];
41 size_t len;
42 const char *eol;
@@ -69,9 +69,9 @@ static void insert_one_record(struct shortlog *log,
69 }
70
71 buffer = xstrdup(namebuf);
72 - item = path_list_insert(buffer, &log->list);
72 + item = string_list_insert(buffer, &log->list);
73 if (item->util == NULL)
74 - item->util = xcalloc(1, sizeof(struct path_list));
74 + item->util = xcalloc(1, sizeof(struct string_list));
75 else
76 free(buffer);
77
@@ -109,11 +109,11 @@ static void insert_one_record(struct shortlog *log,
109 onelines->alloc = alloc_nr(onelines->nr);
110 onelines->items = xrealloc(onelines->items,
111 onelines->alloc
112 - * sizeof(struct path_list_item));
112 + * sizeof(struct string_list_item));
113 }
114
115 onelines->items[onelines->nr].util = NULL;
116 - onelines->items[onelines->nr++].path = buffer;
116 + onelines->items[onelines->nr++].string = buffer;
117 }
118
119 static void read_from_stdin(struct shortlog *log)
@@ -231,7 +231,7 @@ void shortlog_init(struct shortlog *log)
231
232 read_mailmap(&log->mailmap, ".mailmap", &log->common_repo_prefix);
233
234 - log->list.strdup_paths = 1;
234 + log->list.strdup_strings = 1;
235 log->wrap = DEFAULT_WRAPLEN;
236 log->in1 = DEFAULT_INDENT1;
237 log->in2 = DEFAULT_INDENT2;
@@ -299,17 +299,17 @@ void shortlog_output(struct shortlog *log)
299 {
300 int i, j;
301 if (log->sort_by_number)
302 - qsort(log->list.items, log->list.nr, sizeof(struct path_list_item),
302 + qsort(log->list.items, log->list.nr, sizeof(struct string_list_item),
303 compare_by_number);
304 for (i = 0; i < log->list.nr; i++) {
305 - struct path_list *onelines = log->list.items[i].util;
305 + struct string_list *onelines = log->list.items[i].util;
306
307 if (log->summary) {
308 - printf("%6d\t%s\n", onelines->nr, log->list.items[i].path);
308 + printf("%6d\t%s\n", onelines->nr, log->list.items[i].string);
309 } else {
310 - printf("%s (%d):\n", log->list.items[i].path, onelines->nr);
310 + printf("%s (%d):\n", log->list.items[i].string, onelines->nr);
311 for (j = onelines->nr - 1; j >= 0; j--) {
312 - const char *msg = onelines->items[j].path;
312 + const char *msg = onelines->items[j].string;
313
314 if (log->wrap_lines) {
315 int col = print_wrapped_text(msg, log->in1, log->in2, log->wrap);
@@ -322,14 +322,14 @@ void shortlog_output(struct shortlog *log)
322 putchar('\n');
323 }
324
325 - onelines->strdup_paths = 1;
326 - path_list_clear(onelines, 1);
325 + onelines->strdup_strings = 1;
326 + string_list_clear(onelines, 1);
327 free(onelines);
328 log->list.items[i].util = NULL;
329 }
330
331 - log->list.strdup_paths = 1;
332 - path_list_clear(&log->list, 1);
333 - log->mailmap.strdup_paths = 1;
334 - path_list_clear(&log->mailmap, 1);
331 + log->list.strdup_strings = 1;
332 + string_list_clear(&log->list, 1);
333 + log->mailmap.strdup_strings = 1;
334 + string_list_clear(&log->mailmap, 1);
335 }
builtin-show-ref.c
+5 -5
@@ -3,7 +3,7 @@
3 #include "refs.h"
4 #include "object.h"
5 #include "tag.h"
6 -#include "path-list.h"
6 +#include "string-list.h"
7
8 static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<length>]] [--abbrev[=<length>]] [--tags] [--heads] [--] [pattern*] < ref-list";
9
@@ -98,8 +98,8 @@ match:
98
99 static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
100 {
101 - struct path_list *list = (struct path_list *)cbdata;
102 - path_list_insert(refname, list);
101 + struct string_list *list = (struct string_list *)cbdata;
102 + string_list_insert(refname, list);
103 return 0;
104 }
105
@@ -114,7 +114,7 @@ static int add_existing(const char *refname, const unsigned char *sha1, int flag
114 */
115 static int exclude_existing(const char *match)
116 {
117 - static struct path_list existing_refs = { NULL, 0, 0, 0 };
117 + static struct string_list existing_refs = { NULL, 0, 0, 0 };
118 char buf[1024];
119 int matchlen = match ? strlen(match) : 0;
120
@@ -143,7 +143,7 @@ static int exclude_existing(const char *match)
143 fprintf(stderr, "warning: ref '%s' ignored\n", ref);
144 continue;
145 }
146 - if (!path_list_has_path(&existing_refs, ref)) {
146 + if (!string_list_has_string(&existing_refs, ref)) {
147 printf("%s\n", buf);
148 }
149 }
diff-no-index.c
+11 -11
@@ -14,9 +14,9 @@
14 #include "revision.h"
15 #include "log-tree.h"
16 #include "builtin.h"
17 -#include "path-list.h"
17 +#include "string-list.h"
18
19 -static int read_directory(const char *path, struct path_list *list)
19 +static int read_directory(const char *path, struct string_list *list)
20 {
21 DIR *dir;
22 struct dirent *e;
@@ -26,7 +26,7 @@ static int read_directory(const char *path, struct path_list *list)
26
27 while ((e = readdir(dir)))
28 if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
29 - path_list_insert(e->d_name, list);
29 + string_list_insert(e->d_name, list);
30
31 closedir(dir);
32 return 0;
@@ -60,13 +60,13 @@ static int queue_diff(struct diff_options *o,
60
61 if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
62 char buffer1[PATH_MAX], buffer2[PATH_MAX];
63 - struct path_list p1 = {NULL, 0, 0, 1}, p2 = {NULL, 0, 0, 1};
63 + struct string_list p1 = {NULL, 0, 0, 1}, p2 = {NULL, 0, 0, 1};
64 int len1 = 0, len2 = 0, i1, i2, ret = 0;
65
66 if (name1 && read_directory(name1, &p1))
67 return -1;
68 if (name2 && read_directory(name2, &p2)) {
69 - path_list_clear(&p1, 0);
69 + string_list_clear(&p1, 0);
70 return -1;
71 }
72
@@ -95,14 +95,14 @@ static int queue_diff(struct diff_options *o,
95 else if (i2 == p2.nr)
96 comp = -1;
97 else
98 - comp = strcmp(p1.items[i1].path,
99 - p2.items[i2].path);
98 + comp = strcmp(p1.items[i1].string,
99 + p2.items[i2].string);
100
101 if (comp > 0)
102 n1 = NULL;
103 else {
104 n1 = buffer1;
105 - strncpy(buffer1 + len1, p1.items[i1++].path,
105 + strncpy(buffer1 + len1, p1.items[i1++].string,
106 PATH_MAX - len1);
107 }
108
@@ -110,14 +110,14 @@ static int queue_diff(struct diff_options *o,
110 n2 = NULL;
111 else {
112 n2 = buffer2;
113 - strncpy(buffer2 + len2, p2.items[i2++].path,
113 + strncpy(buffer2 + len2, p2.items[i2++].string,
114 PATH_MAX - len2);
115 }
116
117 ret = queue_diff(o, n1, n2);
118 }
119 - path_list_clear(&p1, 0);
120 - path_list_clear(&p2, 0);
119 + string_list_clear(&p1, 0);
120 + string_list_clear(&p2, 0);
121
122 return ret;
123 } else {
mailmap.c
+6 -6
@@ -1,8 +1,8 @@
1 #include "cache.h"
2 -#include "path-list.h"
2 +#include "string-list.h"
3 #include "mailmap.h"
4
5 -int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev)
5 +int read_mailmap(struct string_list *map, const char *filename, char **repo_abbrev)
6 {
7 char buffer[1024];
8 FILE *f = fopen(filename, "r");
@@ -54,16 +54,16 @@ int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev
54 for (i = 0; i < right_bracket - left_bracket - 1; i++)
55 email[i] = tolower(left_bracket[i + 1]);
56 email[right_bracket - left_bracket - 1] = '\0';
57 - path_list_insert(email, map)->util = name;
57 + string_list_insert(email, map)->util = name;
58 }
59 fclose(f);
60 return 0;
61 }
62
63 -int map_email(struct path_list *map, const char *email, char *name, int maxlen)
63 +int map_email(struct string_list *map, const char *email, char *name, int maxlen)
64 {
65 char *p;
66 - struct path_list_item *item;
66 + struct string_list_item *item;
67 char buf[1024], *mailbuf;
68 int i;
69
@@ -80,7 +80,7 @@ int map_email(struct path_list *map, const char *email, char *name, int maxlen)
80 for (i = 0; i < p - email; i++)
81 mailbuf[i] = tolower(email[i]);
82 mailbuf[i] = 0;
83 - item = path_list_lookup(mailbuf, map);
83 + item = string_list_lookup(mailbuf, map);
84 if (mailbuf != buf)
85 free(mailbuf);
86 if (item != NULL) {
mailmap.h
+2 -2
@@ -1,7 +1,7 @@
1 #ifndef MAILMAP_H
2 #define MAILMAP_H
3
4 -int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev);
5 -int map_email(struct path_list *mailmap, const char *email, char *name, int maxlen);
4 +int read_mailmap(struct string_list *map, const char *filename, char **repo_abbrev);
5 +int map_email(struct string_list *mailmap, const char *email, char *name, int maxlen);
6
7 #endif
path-list.c deleted
-134
@@ -1,134 +0,0 @@
1 -#include "cache.h"
2 -#include "path-list.h"
3 -
4 -/* if there is no exact match, point to the index where the entry could be
5 - * inserted */
6 -static int get_entry_index(const struct path_list *list, const char *path,
7 - int *exact_match)
8 -{
9 - int left = -1, right = list->nr;
10 -
11 - while (left + 1 < right) {
12 - int middle = (left + right) / 2;
13 - int compare = strcmp(path, list->items[middle].path);
14 - if (compare < 0)
15 - right = middle;
16 - else if (compare > 0)
17 - left = middle;
18 - else {
19 - *exact_match = 1;
20 - return middle;
21 - }
22 - }
23 -
24 - *exact_match = 0;
25 - return right;
26 -}
27 -
28 -/* returns -1-index if already exists */
29 -static int add_entry(struct path_list *list, const char *path)
30 -{
31 - int exact_match;
32 - int index = get_entry_index(list, path, &exact_match);
33 -
34 - if (exact_match)
35 - return -1 - index;
36 -
37 - if (list->nr + 1 >= list->alloc) {
38 - list->alloc += 32;
39 - list->items = xrealloc(list->items, list->alloc
40 - * sizeof(struct path_list_item));
41 - }
42 - if (index < list->nr)
43 - memmove(list->items + index + 1, list->items + index,
44 - (list->nr - index)
45 - * sizeof(struct path_list_item));
46 - list->items[index].path = list->strdup_paths ?
47 - xstrdup(path) : (char *)path;
48 - list->items[index].util = NULL;
49 - list->nr++;
50 -
51 - return index;
52 -}
53 -
54 -struct path_list_item *path_list_insert(const char *path, struct path_list *list)
55 -{
56 - int index = add_entry(list, path);
57 -
58 - if (index < 0)
59 - index = -1 - index;
60 -
61 - return list->items + index;
62 -}
63 -
64 -int path_list_has_path(const struct path_list *list, const char *path)
65 -{
66 - int exact_match;
67 - get_entry_index(list, path, &exact_match);
68 - return exact_match;
69 -}
70 -
71 -struct path_list_item *path_list_lookup(const char *path, struct path_list *list)
72 -{
73 - int exact_match, i = get_entry_index(list, path, &exact_match);
74 - if (!exact_match)
75 - return NULL;
76 - return list->items + i;
77 -}
78 -
79 -void path_list_clear(struct path_list *list, int free_util)
80 -{
81 - if (list->items) {
82 - int i;
83 - if (list->strdup_paths) {
84 - for (i = 0; i < list->nr; i++)
85 - free(list->items[i].path);
86 - }
87 - if (free_util) {
88 - for (i = 0; i < list->nr; i++)
89 - free(list->items[i].util);
90 - }
91 - free(list->items);
92 - }
93 - list->items = NULL;
94 - list->nr = list->alloc = 0;
95 -}
96 -
97 -void print_path_list(const char *text, const struct path_list *p)
98 -{
99 - int i;
100 - if ( text )
101 - printf("%s\n", text);
102 - for (i = 0; i < p->nr; i++)
103 - printf("%s:%p\n", p->items[i].path, p->items[i].util);
104 -}
105 -
106 -struct path_list_item *path_list_append(const char *path, struct path_list *list)
107 -{
108 - ALLOC_GROW(list->items, list->nr + 1, list->alloc);
109 - list->items[list->nr].path =
110 - list->strdup_paths ? xstrdup(path) : (char *)path;
111 - return list->items + list->nr++;
112 -}
113 -
114 -static int cmp_items(const void *a, const void *b)
115 -{
116 - const struct path_list_item *one = a;
117 - const struct path_list_item *two = b;
118 - return strcmp(one->path, two->path);
119 -}
120 -
121 -void sort_path_list(struct path_list *list)
122 -{
123 - qsort(list->items, list->nr, sizeof(*list->items), cmp_items);
124 -}
125 -
126 -int unsorted_path_list_has_path(struct path_list *list, const char *path)
127 -{
128 - int i;
129 - for (i = 0; i < list->nr; i++)
130 - if (!strcmp(path, list->items[i].path))
131 - return 1;
132 - return 0;
133 -}
134 -
path-list.h deleted
-28
@@ -1,28 +0,0 @@
1 -#ifndef PATH_LIST_H
2 -#define PATH_LIST_H
3 -
4 -struct path_list_item {
5 - char *path;
6 - void *util;
7 -};
8 -struct path_list
9 -{
10 - struct path_list_item *items;
11 - unsigned int nr, alloc;
12 - unsigned int strdup_paths:1;
13 -};
14 -
15 -void print_path_list(const char *text, const struct path_list *p);
16 -void path_list_clear(struct path_list *list, int free_util);
17 -
18 -/* Use these functions only on sorted lists: */
19 -int path_list_has_path(const struct path_list *list, const char *path);
20 -struct path_list_item *path_list_insert(const char *path, struct path_list *list);
21 -struct path_list_item *path_list_lookup(const char *path, struct path_list *list);
22 -
23 -/* Use these functions only on unsorted lists: */
24 -struct path_list_item *path_list_append(const char *path, struct path_list *list);
25 -void sort_path_list(struct path_list *list);
26 -int unsorted_path_list_has_path(struct path_list *list, const char *path);
27 -
28 -#endif /* PATH_LIST_H */
pretty.c
+2 -2
@@ -3,7 +3,7 @@
3 #include "utf8.h"
4 #include "diff.h"
5 #include "revision.h"
6 -#include "path-list.h"
6 +#include "string-list.h"
7 #include "mailmap.h"
8
9 static char *user_format;
@@ -292,7 +292,7 @@ static char *logmsg_reencode(const struct commit *commit,
292
293 static int mailmap_name(struct strbuf *sb, const char *email)
294 {
295 - static struct path_list *mail_map;
295 + static struct string_list *mail_map;
296 char buffer[1024];
297
298 if (!mail_map) {
reflog-walk.c
+5 -5
@@ -3,7 +3,7 @@
3 #include "refs.h"
4 #include "diff.h"
5 #include "revision.h"
6 -#include "path-list.h"
6 +#include "string-list.h"
7 #include "reflog-walk.h"
8
9 struct complete_reflogs {
@@ -127,7 +127,7 @@ struct commit_reflog {
127
128 struct reflog_walk_info {
129 struct commit_info_lifo reflogs;
130 - struct path_list complete_reflogs;
130 + struct string_list complete_reflogs;
131 struct commit_reflog *last_commit_reflog;
132 };
133
@@ -141,7 +141,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
141 {
142 unsigned long timestamp = 0;
143 int recno = -1;
144 - struct path_list_item *item;
144 + struct string_list_item *item;
145 struct complete_reflogs *reflogs;
146 char *branch, *at = strchr(name, '@');
147 struct commit_reflog *commit_reflog;
@@ -161,7 +161,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
161 } else
162 recno = 0;
163
164 - item = path_list_lookup(branch, &info->complete_reflogs);
164 + item = string_list_lookup(branch, &info->complete_reflogs);
165 if (item)
166 reflogs = item->util;
167 else {
@@ -189,7 +189,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
189 }
190 if (!reflogs || reflogs->nr == 0)
191 return -1;
192 - path_list_insert(branch, &info->complete_reflogs)->util
192 + string_list_insert(branch, &info->complete_reflogs)->util
193 = reflogs;
194 }
195
rerere.c
+20 -20
@@ -1,5 +1,5 @@
1 #include "cache.h"
2 -#include "path-list.h"
2 +#include "string-list.h"
3 #include "rerere.h"
4 #include "xdiff/xdiff.h"
5 #include "xdiff-interface.h"
@@ -23,7 +23,7 @@ static int has_resolution(const char *name)
23 return !stat(rr_path(name, "postimage"), &st);
24 }
25
26 -static void read_rr(struct path_list *rr)
26 +static void read_rr(struct string_list *rr)
27 {
28 unsigned char sha1[20];
29 char buf[PATH_MAX];
@@ -43,14 +43,14 @@ static void read_rr(struct path_list *rr)
43 ; /* do nothing */
44 if (i == sizeof(buf))
45 die("filename too long");
46 - path_list_insert(buf, rr)->util = name;
46 + string_list_insert(buf, rr)->util = name;
47 }
48 fclose(in);
49 }
50
51 static struct lock_file write_lock;
52
53 -static int write_rr(struct path_list *rr, int out_fd)
53 +static int write_rr(struct string_list *rr, int out_fd)
54 {
55 int i;
56 for (i = 0; i < rr->nr; i++) {
@@ -58,7 +58,7 @@ static int write_rr(struct path_list *rr, int out_fd)
58 int length;
59 if (!rr->items[i].util)
60 continue;
61 - path = rr->items[i].path;
61 + path = rr->items[i].string;
62 length = strlen(path) + 1;
63 if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
64 write_in_full(out_fd, "\t", 1) != 1 ||
@@ -154,7 +154,7 @@ static int handle_file(const char *path,
154 return hunk_no;
155 }
156
157 -static int find_conflict(struct path_list *conflict)
157 +static int find_conflict(struct string_list *conflict)
158 {
159 int i;
160 if (read_cache() < 0)
@@ -167,7 +167,7 @@ static int find_conflict(struct path_list *conflict)
167 ce_same_name(e2, e3) &&
168 S_ISREG(e2->ce_mode) &&
169 S_ISREG(e3->ce_mode)) {
170 - path_list_insert((const char *)e2->name, conflict);
170 + string_list_insert((const char *)e2->name, conflict);
171 i++; /* skip over both #2 and #3 */
172 }
173 }
@@ -208,7 +208,7 @@ static int merge(const char *name, const char *path)
208
209 static struct lock_file index_lock;
210
211 -static int update_paths(struct path_list *update)
211 +static int update_paths(struct string_list *update)
212 {
213 int i;
214 int fd = hold_locked_index(&index_lock, 0);
@@ -218,8 +218,8 @@ static int update_paths(struct path_list *update)
218 return -1;
219
220 for (i = 0; i < update->nr; i++) {
221 - struct path_list_item *item = &update->items[i];
222 - if (add_file_to_cache(item->path, ADD_CACHE_IGNORE_ERRORS))
221 + struct string_list_item *item = &update->items[i];
222 + if (add_file_to_cache(item->string, ADD_CACHE_IGNORE_ERRORS))
223 status = -1;
224 }
225
@@ -232,10 +232,10 @@ static int update_paths(struct path_list *update)
232 return status;
233 }
234
235 -static int do_plain_rerere(struct path_list *rr, int fd)
235 +static int do_plain_rerere(struct string_list *rr, int fd)
236 {
237 - struct path_list conflict = { NULL, 0, 0, 1 };
238 - struct path_list update = { NULL, 0, 0, 1 };
237 + struct string_list conflict = { NULL, 0, 0, 1 };
238 + struct string_list update = { NULL, 0, 0, 1 };
239 int i;
240
241 find_conflict(&conflict);
@@ -248,8 +248,8 @@ static int do_plain_rerere(struct path_list *rr, int fd)
248 */
249
250 for (i = 0; i < conflict.nr; i++) {
251 - const char *path = conflict.items[i].path;
252 - if (!path_list_has_path(rr, path)) {
251 + const char *path = conflict.items[i].string;
252 + if (!string_list_has_string(rr, path)) {
253 unsigned char sha1[20];
254 char *hex;
255 int ret;
@@ -257,7 +257,7 @@ static int do_plain_rerere(struct path_list *rr, int fd)
257 if (ret < 1)
258 continue;
259 hex = xstrdup(sha1_to_hex(sha1));
260 - path_list_insert(path, rr)->util = hex;
260 + string_list_insert(path, rr)->util = hex;
261 if (mkdir(git_path("rr-cache/%s", hex), 0755))
262 continue;;
263 handle_file(path, NULL, rr_path(hex, "preimage"));
@@ -273,13 +273,13 @@ static int do_plain_rerere(struct path_list *rr, int fd)
273
274 for (i = 0; i < rr->nr; i++) {
275 int ret;
276 - const char *path = rr->items[i].path;
276 + const char *path = rr->items[i].string;
277 const char *name = (const char *)rr->items[i].util;
278
279 if (has_resolution(name)) {
280 if (!merge(name, path)) {
281 if (rerere_autoupdate)
282 - path_list_insert(path, &update);
282 + string_list_insert(path, &update);
283 fprintf(stderr,
284 "%s '%s' using previous resolution.\n",
285 rerere_autoupdate
@@ -337,7 +337,7 @@ static int is_rerere_enabled(void)
337 return 1;
338 }
339
340 -int setup_rerere(struct path_list *merge_rr)
340 +int setup_rerere(struct string_list *merge_rr)
341 {
342 int fd;
343
@@ -353,7 +353,7 @@ int setup_rerere(struct path_list *merge_rr)
353
354 int rerere(void)
355 {
356 - struct path_list merge_rr = { NULL, 0, 0, 1 };
356 + struct string_list merge_rr = { NULL, 0, 0, 1 };
357 int fd;
358
359 fd = setup_rerere(&merge_rr);
rerere.h
+2 -2
@@ -1,9 +1,9 @@
1 #ifndef RERERE_H
2 #define RERERE_H
3
4 -#include "path-list.h"
4 +#include "string-list.h"
5
6 -extern int setup_rerere(struct path_list *);
6 +extern int setup_rerere(struct string_list *);
7 extern int rerere(void);
8
9 #endif
shortlog.h
+3 -3
@@ -1,10 +1,10 @@
1 #ifndef SHORTLOG_H
2 #define SHORTLOG_H
3
4 -#include "path-list.h"
4 +#include "string-list.h"
5
6 struct shortlog {
7 - struct path_list list;
7 + struct string_list list;
8 int summary;
9 int wrap_lines;
10 int sort_by_number;
@@ -15,7 +15,7 @@ struct shortlog {
15
16 char *common_repo_prefix;
17 int email;
18 - struct path_list mailmap;
18 + struct string_list mailmap;
19 };
20
21 void shortlog_init(struct shortlog *log);
string-list.c new
+134
@@ -0,0 +1,134 @@
1 +#include "cache.h"
2 +#include "string-list.h"
3 +
4 +/* if there is no exact match, point to the index where the entry could be
5 + * inserted */
6 +static int get_entry_index(const struct string_list *list, const char *string,
7 + int *exact_match)
8 +{
9 + int left = -1, right = list->nr;
10 +
11 + while (left + 1 < right) {
12 + int middle = (left + right) / 2;
13 + int compare = strcmp(string, list->items[middle].string);
14 + if (compare < 0)
15 + right = middle;
16 + else if (compare > 0)
17 + left = middle;
18 + else {
19 + *exact_match = 1;
20 + return middle;
21 + }
22 + }
23 +
24 + *exact_match = 0;
25 + return right;
26 +}
27 +
28 +/* returns -1-index if already exists */
29 +static int add_entry(struct string_list *list, const char *string)
30 +{
31 + int exact_match;
32 + int index = get_entry_index(list, string, &exact_match);
33 +
34 + if (exact_match)
35 + return -1 - index;
36 +
37 + if (list->nr + 1 >= list->alloc) {
38 + list->alloc += 32;
39 + list->items = xrealloc(list->items, list->alloc
40 + * sizeof(struct string_list_item));
41 + }
42 + if (index < list->nr)
43 + memmove(list->items + index + 1, list->items + index,
44 + (list->nr - index)
45 + * sizeof(struct string_list_item));
46 + list->items[index].string = list->strdup_strings ?
47 + xstrdup(string) : (char *)string;
48 + list->items[index].util = NULL;
49 + list->nr++;
50 +
51 + return index;
52 +}
53 +
54 +struct string_list_item *string_list_insert(const char *string, struct string_list *list)
55 +{
56 + int index = add_entry(list, string);
57 +
58 + if (index < 0)
59 + index = -1 - index;
60 +
61 + return list->items + index;
62 +}
63 +
64 +int string_list_has_string(const struct string_list *list, const char *string)
65 +{
66 + int exact_match;
67 + get_entry_index(list, string, &exact_match);
68 + return exact_match;
69 +}
70 +
71 +struct string_list_item *string_list_lookup(const char *string, struct string_list *list)
72 +{
73 + int exact_match, i = get_entry_index(list, string, &exact_match);
74 + if (!exact_match)
75 + return NULL;
76 + return list->items + i;
77 +}
78 +
79 +void string_list_clear(struct string_list *list, int free_util)
80 +{
81 + if (list->items) {
82 + int i;
83 + if (list->strdup_strings) {
84 + for (i = 0; i < list->nr; i++)
85 + free(list->items[i].string);
86 + }
87 + if (free_util) {
88 + for (i = 0; i < list->nr; i++)
89 + free(list->items[i].util);
90 + }
91 + free(list->items);
92 + }
93 + list->items = NULL;
94 + list->nr = list->alloc = 0;
95 +}
96 +
97 +void print_string_list(const char *text, const struct string_list *p)
98 +{
99 + int i;
100 + if ( text )
101 + printf("%s\n", text);
102 + for (i = 0; i < p->nr; i++)
103 + printf("%s:%p\n", p->items[i].string, p->items[i].util);
104 +}
105 +
106 +struct string_list_item *string_list_append(const char *string, struct string_list *list)
107 +{
108 + ALLOC_GROW(list->items, list->nr + 1, list->alloc);
109 + list->items[list->nr].string =
110 + list->strdup_strings ? xstrdup(string) : (char *)string;
111 + return list->items + list->nr++;
112 +}
113 +
114 +static int cmp_items(const void *a, const void *b)
115 +{
116 + const struct string_list_item *one = a;
117 + const struct string_list_item *two = b;
118 + return strcmp(one->string, two->string);
119 +}
120 +
121 +void sort_string_list(struct string_list *list)
122 +{
123 + qsort(list->items, list->nr, sizeof(*list->items), cmp_items);
124 +}
125 +
126 +int unsorted_string_list_has_string(struct string_list *list, const char *string)
127 +{
128 + int i;
129 + for (i = 0; i < list->nr; i++)
130 + if (!strcmp(string, list->items[i].string))
131 + return 1;
132 + return 0;
133 +}
134 +
string-list.h new
+28
@@ -0,0 +1,28 @@
1 +#ifndef PATH_LIST_H
2 +#define PATH_LIST_H
3 +
4 +struct string_list_item {
5 + char *string;
6 + void *util;
7 +};
8 +struct string_list
9 +{
10 + struct string_list_item *items;
11 + unsigned int nr, alloc;
12 + unsigned int strdup_strings:1;
13 +};
14 +
15 +void print_string_list(const char *text, const struct string_list *p);
16 +void string_list_clear(struct string_list *list, int free_util);
17 +
18 +/* Use these functions only on sorted lists: */
19 +int string_list_has_string(const struct string_list *list, const char *string);
20 +struct string_list_item *string_list_insert(const char *string, struct string_list *list);
21 +struct string_list_item *string_list_lookup(const char *string, struct string_list *list);
22 +
23 +/* Use these functions only on unsorted lists: */
24 +struct string_list_item *string_list_append(const char *string, struct string_list *list);
25 +void sort_string_list(struct string_list *list);
26 +int unsorted_string_list_has_string(struct string_list *list, const char *string);
27 +
28 +#endif /* PATH_LIST_H */