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 <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Clemens Buchacher committed
Sep 4, 2011 at 12:41 UTC
5879f5684cfe8a38326b4ffd078f96e35c68e640
4 files changed
+7
-6
builtin/commit.c
+3
-2
@@ -257,8 +257,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
257
m = xcalloc(1, i);
258
259
if (with_tree) {
260
- const char *max_prefix = pathspec_prefix(prefix, pattern);
261
- overlay_tree_on_cache(with_tree, max_prefix);
260
+ char *max_prefix = pathspec_prefix(pattern);
261
+ overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
262
+ free(max_prefix);
263
}
264
265
for (i = 0; i < active_nr; i++) {
builtin/ls-files.c
+1
-1
@@ -541,7 +541,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
541
strip_trailing_slash_from_submodules();
542
543
/* Find common prefix for all pathspec's */
544
- max_prefix = pathspec_prefix(prefix, pathspec);
544
+ max_prefix = pathspec_prefix(pathspec);
545
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
546
547
/* Treat unmatching pathspec elements as errors */
cache.h
+1
-1
@@ -426,7 +426,7 @@ extern void set_git_work_tree(const char *tree);
426
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
427
428
extern const char **get_pathspec(const char *prefix, const char **pathspec);
429
-extern const char *pathspec_prefix(const char *prefix, const char **pathspec);
429
+extern char *pathspec_prefix(const char **pathspec);
430
extern void setup_work_tree(void);
431
extern const char *setup_git_directory_gently(int *);
432
extern const char *setup_git_directory(void);
setup.c
+2
-2
@@ -264,13 +264,13 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
264
return pathspec;
265
}
266
267
-const char *pathspec_prefix(const char *prefix, const char **pathspec)
267
+char *pathspec_prefix(const char **pathspec)
268
{
269
const char **p, *n, *prev;
270
unsigned long max;
271
272
if (!pathspec)
273
- return prefix ? xmemdupz(prefix, strlen(prefix)) : NULL;
273
+ return NULL;
274
275
prev = NULL;
276
max = PATH_MAX;