From 5879f5684cfe8a38326b4ffd078f96e35c68e640 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Sun, 4 Sep 2011 12:41:59 +0200 Subject: remove prefix argument from pathspec_prefix Passing a prefix to a function that is supposed to find the prefix is strange. And it's really only used if the pathspec is NULL. Make the callers handle this case instead. As we are always returning a fresh copy of a string (or NULL), change the type of the returned value to non-const "char *". Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setup.c') diff --git a/setup.c b/setup.c index 699fcf096..f767d8adb 100644 --- a/setup.c +++ b/setup.c @@ -264,13 +264,13 @@ const char **get_pathspec(const char *prefix, const char **pathspec) return pathspec; } -const char *pathspec_prefix(const char *prefix, const char **pathspec) +char *pathspec_prefix(const char **pathspec) { const char **p, *n, *prev; unsigned long max; if (!pathspec) - return prefix ? xmemdupz(prefix, strlen(prefix)) : NULL; + return NULL; prev = NULL; max = PATH_MAX; -- cgit v1.2.1 From 4a085b16f430bcfe1b6e2e84e7a569f4e191e906 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 6 Sep 2011 12:32:30 -0700 Subject: consolidate pathspec_prefix and common_prefix The implementation from pathspec_prefix (slightly modified) replaces the current common_prefix, because it also respects glob characters. Based on a patch by Clemens Buchacher. Signed-off-by: Junio C Hamano --- setup.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'setup.c') diff --git a/setup.c b/setup.c index f767d8adb..70b887fe6 100644 --- a/setup.c +++ b/setup.c @@ -266,34 +266,9 @@ const char **get_pathspec(const char *prefix, const char **pathspec) char *pathspec_prefix(const char **pathspec) { - const char **p, *n, *prev; - unsigned long max; + size_t len = common_prefix_len(pathspec); - if (!pathspec) - return NULL; - - prev = NULL; - max = PATH_MAX; - for (p = pathspec; (n = *p) != NULL; p++) { - int i, len = 0; - for (i = 0; i < max; i++) { - char c = n[i]; - if (prev && prev[i] != c) - break; - if (!c || c == '*' || c == '?') - break; - if (c == '/') - len = i+1; - } - prev = n; - if (len < max) { - max = len; - if (!max) - break; - } - } - - return max ? xmemdupz(prev, max) : NULL; + return len ? xmemdupz(*pathspec, len) : NULL; } /* -- cgit v1.2.1 From f950eb956092831730182daa7160eaa352277fa9 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Sun, 4 Sep 2011 12:42:01 +0200 Subject: rename pathspec_prefix() to common_prefix() and move to dir.[ch] Also make common_prefix_len() static as this refactoring makes dir.c itself the only caller of this helper function. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- setup.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'setup.c') diff --git a/setup.c b/setup.c index 70b887fe6..ce87900ce 100644 --- a/setup.c +++ b/setup.c @@ -264,13 +264,6 @@ const char **get_pathspec(const char *prefix, const char **pathspec) return pathspec; } -char *pathspec_prefix(const char **pathspec) -{ - size_t len = common_prefix_len(pathspec); - - return len ? xmemdupz(*pathspec, len) : NULL; -} - /* * Test if it looks like we're at a git directory. * We want to see: -- cgit v1.2.1