From a6080a0a44d5ead84db3dabbbc80e82df838533d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 7 Jun 2007 00:04:01 -0700 Subject: War on whitespace This uses "git-apply --whitespace=strip" to fix whitespace errors that have crept in to our source files over time. There are a few files that need to have trailing whitespaces (most notably, test vectors). The results still passes the test, and build result in Documentation/ area is unchanged. Signed-off-by: Junio C Hamano --- path-list.c | 1 - 1 file changed, 1 deletion(-) (limited to 'path-list.c') diff --git a/path-list.c b/path-list.c index caaa5cc57..dcb4b3ac1 100644 --- a/path-list.c +++ b/path-list.c @@ -100,4 +100,3 @@ void print_path_list(const char *text, const struct path_list *p) for (i = 0; i < p->nr; i++) printf("%s:%p\n", p->items[i].path, p->items[i].util); } - -- cgit v1.2.1 From 79d722224dbad49a50072f92f823d8b12c2e5707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 15 Aug 2007 17:59:24 +0200 Subject: path-list.c: always free strdup'ed paths Always free .paths if .strdup_paths is set, no matter if the parameter free_items is set or not, plugging a minor memory leak. And to clarify the meaning of the flag, rename it to free_util, since it now only affects the freeing of the .util field. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- path-list.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'path-list.c') diff --git a/path-list.c b/path-list.c index dcb4b3ac1..3d83b7ba9 100644 --- a/path-list.c +++ b/path-list.c @@ -76,16 +76,18 @@ struct path_list_item *path_list_lookup(const char *path, struct path_list *list return list->items + i; } -void path_list_clear(struct path_list *list, int free_items) +void path_list_clear(struct path_list *list, int free_util) { if (list->items) { int i; - if (free_items) - for (i = 0; i < list->nr; i++) { - if (list->strdup_paths) - free(list->items[i].path); + if (list->strdup_paths) { + for (i = 0; i < list->nr; i++) + free(list->items[i].path); + } + if (free_util) { + for (i = 0; i < list->nr; i++) free(list->items[i].util); - } + } free(list->items); } list->items = NULL; -- cgit v1.2.1 From 363d59df1a773039d0c69ad8c3109a56bb1b491d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 29 Feb 2008 01:44:56 +0000 Subject: path-list: add functions to work with unsorted lists Up to now, path-lists were sorted at all times. But sometimes it is much more convenient to build the list and sort it at the end, or sort it not at all. Add path_list_append() and sort_path_list() to allow that. Also, add the unsorted_path_list_has_path() function, to do a linear search. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- path-list.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'path-list.c') diff --git a/path-list.c b/path-list.c index 3d83b7ba9..92e5cf20f 100644 --- a/path-list.c +++ b/path-list.c @@ -102,3 +102,33 @@ void print_path_list(const char *text, const struct path_list *p) for (i = 0; i < p->nr; i++) printf("%s:%p\n", p->items[i].path, p->items[i].util); } + +struct path_list_item *path_list_append(const char *path, struct path_list *list) +{ + ALLOC_GROW(list->items, list->nr + 1, list->alloc); + list->items[list->nr].path = + list->strdup_paths ? xstrdup(path) : (char *)path; + return list->items + list->nr++; +} + +static int cmp_items(const void *a, const void *b) +{ + const struct path_list_item *one = a; + const struct path_list_item *two = b; + return strcmp(one->path, two->path); +} + +void sort_path_list(struct path_list *list) +{ + qsort(list->items, list->nr, sizeof(*list->items), cmp_items); +} + +int unsorted_path_list_has_path(struct path_list *list, const char *path) +{ + int i; + for (i = 0; i < list->nr; i++) + if (!strcmp(path, list->items[i].path)) + return 1; + return 0; +} + -- cgit v1.2.1 From c455c87c5cd42bbbe586b31cea1143132f3a39e4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 21 Jul 2008 19:03:49 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- path-list.c | 134 ------------------------------------------------------------ 1 file changed, 134 deletions(-) delete mode 100644 path-list.c (limited to 'path-list.c') diff --git a/path-list.c b/path-list.c deleted file mode 100644 index 92e5cf20f..000000000 --- a/path-list.c +++ /dev/null @@ -1,134 +0,0 @@ -#include "cache.h" -#include "path-list.h" - -/* if there is no exact match, point to the index where the entry could be - * inserted */ -static int get_entry_index(const struct path_list *list, const char *path, - int *exact_match) -{ - int left = -1, right = list->nr; - - while (left + 1 < right) { - int middle = (left + right) / 2; - int compare = strcmp(path, list->items[middle].path); - if (compare < 0) - right = middle; - else if (compare > 0) - left = middle; - else { - *exact_match = 1; - return middle; - } - } - - *exact_match = 0; - return right; -} - -/* returns -1-index if already exists */ -static int add_entry(struct path_list *list, const char *path) -{ - int exact_match; - int index = get_entry_index(list, path, &exact_match); - - if (exact_match) - return -1 - index; - - if (list->nr + 1 >= list->alloc) { - list->alloc += 32; - list->items = xrealloc(list->items, list->alloc - * sizeof(struct path_list_item)); - } - if (index < list->nr) - memmove(list->items + index + 1, list->items + index, - (list->nr - index) - * sizeof(struct path_list_item)); - list->items[index].path = list->strdup_paths ? - xstrdup(path) : (char *)path; - list->items[index].util = NULL; - list->nr++; - - return index; -} - -struct path_list_item *path_list_insert(const char *path, struct path_list *list) -{ - int index = add_entry(list, path); - - if (index < 0) - index = -1 - index; - - return list->items + index; -} - -int path_list_has_path(const struct path_list *list, const char *path) -{ - int exact_match; - get_entry_index(list, path, &exact_match); - return exact_match; -} - -struct path_list_item *path_list_lookup(const char *path, struct path_list *list) -{ - int exact_match, i = get_entry_index(list, path, &exact_match); - if (!exact_match) - return NULL; - return list->items + i; -} - -void path_list_clear(struct path_list *list, int free_util) -{ - if (list->items) { - int i; - if (list->strdup_paths) { - for (i = 0; i < list->nr; i++) - free(list->items[i].path); - } - if (free_util) { - for (i = 0; i < list->nr; i++) - free(list->items[i].util); - } - free(list->items); - } - list->items = NULL; - list->nr = list->alloc = 0; -} - -void print_path_list(const char *text, const struct path_list *p) -{ - int i; - if ( text ) - printf("%s\n", text); - for (i = 0; i < p->nr; i++) - printf("%s:%p\n", p->items[i].path, p->items[i].util); -} - -struct path_list_item *path_list_append(const char *path, struct path_list *list) -{ - ALLOC_GROW(list->items, list->nr + 1, list->alloc); - list->items[list->nr].path = - list->strdup_paths ? xstrdup(path) : (char *)path; - return list->items + list->nr++; -} - -static int cmp_items(const void *a, const void *b) -{ - const struct path_list_item *one = a; - const struct path_list_item *two = b; - return strcmp(one->path, two->path); -} - -void sort_path_list(struct path_list *list) -{ - qsort(list->items, list->nr, sizeof(*list->items), cmp_items); -} - -int unsorted_path_list_has_path(struct path_list *list, const char *path) -{ - int i; - for (i = 0; i < list->nr; i++) - if (!strcmp(path, list->items[i].path)) - return 1; - return 0; -} - -- cgit v1.2.1