From: Junio C Hamano Date: Mon, 28 Jan 2013 19:07:18 +0000 (-0800) Subject: Merge branch 'mh/ceiling' into maint X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ce956fc48eb6f4a8eb90fd22a7d730e8d012f91f;p=git.git Merge branch 'mh/ceiling' into maint An element on GIT_CEILING_DIRECTORIES list that does not name the real path to a directory (i.e. a symbolic link) could have caused the GIT_DIR discovery logic to escape the ceiling. * mh/ceiling: string_list_longest_prefix(): remove function setup_git_directory_gently_1(): resolve symlinks in ceiling paths longest_ancestor_length(): require prefix list entries to be normalized longest_ancestor_length(): take a string_list argument for prefixes longest_ancestor_length(): use string_list_split() Introduce new function real_path_if_valid() real_path_internal(): add comment explaining use of cwd Introduce new static function real_path_internal() --- ce956fc48eb6f4a8eb90fd22a7d730e8d012f91f diff --cc Documentation/technical/api-string-list.txt index 7386bcab3,618400d80..20be34883 --- a/Documentation/technical/api-string-list.txt +++ b/Documentation/technical/api-string-list.txt @@@ -76,20 -75,6 +76,12 @@@ Function to be deleted. Preserve the order of the items that are retained. +`string_list_remove_empty_items`:: + + Remove any empty strings from the list. If free_util is true, + call free() on the util members of any items that have to be + deleted. Preserve the order of the items that are retained. + - `string_list_longest_prefix`:: - - Return the longest string within a string_list that is a - prefix (in the sense of prefixcmp()) of the specified string, - or NULL if no such prefix exists. This function does not - require the string_list to be sorted (it does a linear - search). - `print_string_list`:: Dump a string_list to stdout, useful mainly for debugging purposes. It diff --cc string-list.c index 397e6cfa7,decfa747f..480173fe6 --- a/string-list.c +++ b/string-list.c @@@ -136,35 -136,6 +136,15 @@@ void filter_string_list(struct string_l list->nr = dst; } +static int item_is_not_empty(struct string_list_item *item, void *unused) +{ + return *item->string != '\0'; +} + +void string_list_remove_empty_items(struct string_list *list, int free_util) { + filter_string_list(list, free_util, item_is_not_empty, NULL); +} + - char *string_list_longest_prefix(const struct string_list *prefixes, - const char *string) - { - int i, max_len = -1; - char *retval = NULL; - - for (i = 0; i < prefixes->nr; i++) { - char *prefix = prefixes->items[i].string; - if (!prefixcmp(string, prefix)) { - int len = strlen(prefix); - if (len > max_len) { - retval = prefix; - max_len = len; - } - } - } - - return retval; - } - void string_list_clear(struct string_list *list, int free_util) { if (list->items) { diff --cc string-list.h index c50b0d0de,3a6a6dc39..db1284861 --- a/string-list.h +++ b/string-list.h @@@ -38,22 -38,7 +38,13 @@@ int for_each_string_list(struct string_ void filter_string_list(struct string_list *list, int free_util, string_list_each_func_t want, void *cb_data); +/* + * Remove any empty strings from the list. If free_util is true, call + * free() on the util members of any items that have to be deleted. + * Preserve the order of the items that are retained. + */ +void string_list_remove_empty_items(struct string_list *list, int free_util); - /* - * Return the longest string in prefixes that is a prefix (in the - * sense of prefixcmp()) of string, or NULL if no such prefix exists. - * This function does not require the string_list to be sorted (it - * does a linear search). - */ - char *string_list_longest_prefix(const struct string_list *prefixes, const char *string); - - /* Use these functions only on sorted lists: */ int string_list_has_string(const struct string_list *list, const char *string); int string_list_find_insert_index(const struct string_list *list, const char *string,