Skip to content

Commit 5879f56

Browse files
Clemens Buchachergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8894d53 commit 5879f56

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

builtin/commit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
257257
m = xcalloc(1, i);
258258

259259
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);
262263
}
263264

264265
for (i = 0; i < active_nr; i++) {

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
541541
strip_trailing_slash_from_submodules();
542542

543543
/* Find common prefix for all pathspec's */
544-
max_prefix = pathspec_prefix(prefix, pathspec);
544+
max_prefix = pathspec_prefix(pathspec);
545545
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
546546

547547
/* Treat unmatching pathspec elements as errors */

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ extern void set_git_work_tree(const char *tree);
426426
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
427427

428428
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);
430430
extern void setup_work_tree(void);
431431
extern const char *setup_git_directory_gently(int *);
432432
extern const char *setup_git_directory(void);

setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
264264
return pathspec;
265265
}
266266

267-
const char *pathspec_prefix(const char *prefix, const char **pathspec)
267+
char *pathspec_prefix(const char **pathspec)
268268
{
269269
const char **p, *n, *prev;
270270
unsigned long max;
271271

272272
if (!pathspec)
273-
return prefix ? xmemdupz(prefix, strlen(prefix)) : NULL;
273+
return NULL;
274274

275275
prev = NULL;
276276
max = PATH_MAX;

0 commit comments

Comments
 (0)