git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 4/8] longest_ancestor_length(): use string_list_split()

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Oct 28, 2012, 16:16 UTC
Message-ID
<1351440987-26636-5-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1351440987-26636-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 path.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/path.c b/path.c
index cbbdf7d..f455e8e 100644
--- a/path.c
+++ b/path.c
@@ -12,6 +12,7 @@
  */
 #include "cache.h"
 #include "strbuf.h"
+#include "string-list.h"
 
 static char bad_path[] = "/bad-path/";
 
@@ -582,20 +583,22 @@ int normalize_path_copy(char *dst, const char *src)
  */
 int longest_ancestor_length(const char *path, const char *prefix_list)
 {
+	struct string_list prefixes = STRING_LIST_INIT_DUP;
 	char buf[PATH_MAX+1];
-	const char *ceil, *colon;
-	int len, max_len = -1;
+	int i, max_len = -1;
 
 	if (prefix_list == NULL || !strcmp(path, "/"))
 		return -1;
 
-	for (colon = ceil = prefix_list; *colon; ceil = colon+1) {
-		for (colon = ceil; *colon && *colon != PATH_SEP; colon++);
-		len = colon - ceil;
+	string_list_split(&prefixes, prefix_list, PATH_SEP, -1);
+
+	for (i = 0; i < prefixes.nr; i++) {
+		const char *ceil = prefixes.items[i].string;
+		int len = strlen(ceil);
+
 		if (len == 0 || len > PATH_MAX || !is_absolute_path(ceil))
 			continue;
-		strlcpy(buf, ceil, len+1);
-		if (normalize_path_copy(buf, buf) < 0)
+		if (normalize_path_copy(buf, ceil) < 0)
 			continue;
 		len = strlen(buf);
 		if (len > 0 && buf[len-1] == '/')
@@ -608,6 +611,7 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
 		}
 	}
 
+	string_list_clear(&prefixes, 0);
 	return max_len;
 }
 
-- 
1.8.0
Previous: Michael HaggertyNext: Michael Haggerty
Message 5 of 11 in “Fix GIT_CEILING_DIRECTORIES that contain symlinks”
  1. 0/8 Fix GIT_CEILING_DIRECTORIES that contain symlinksMichael Haggerty, Oct 28, 2012
  2. 1/8 Introduce new static function real_path_internal()Michael Haggerty, Oct 28, 2012
  3. 2/8 real_path_internal(): add comment explaining use of cwdMichael Haggerty, Oct 28, 2012
  4. 3/8 Introduce new function real_path_if_valid()Michael Haggerty, Oct 28, 2012
  5. 4/8 longest_ancestor_length(): use string_list_split()Michael Haggerty, Oct 28, 2012
  6. 5/8 longest_ancestor_length(): take a string_list argument for prefixesMichael Haggerty, Oct 28, 2012
  7. 6/8 longest_ancestor_length(): require prefix list entries to be normalizedMichael Haggerty, Oct 28, 2012
  8. Ramsay JonesOct 30, 2012
  9. Michael HaggertyNov 6, 2012
  10. 7/8 setup_git_directory_gently_1(): resolve symlinks in ceiling pathsMichael Haggerty, Oct 28, 2012
  11. 8/8 string_list_longest_prefix(): remove functionMichael Haggerty, Oct 28, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.