Skip to content

Commit f950eb9

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

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
257257
m = xcalloc(1, i);
258258

259259
if (with_tree) {
260-
char *max_prefix = pathspec_prefix(pattern);
260+
char *max_prefix = common_prefix(pattern);
261261
overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
262262
free(max_prefix);
263263
}

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(pathspec);
544+
max_prefix = common_prefix(pathspec);
545545
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
546546

547547
/* Treat unmatching pathspec elements as errors */

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ 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 char *pathspec_prefix(const char **pathspec);
430429
extern void setup_work_tree(void);
431430
extern const char *setup_git_directory_gently(int *);
432431
extern const char *setup_git_directory(void);

dir.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int fnmatch_icase(const char *pattern, const char *string, int flags)
3434
return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
3535
}
3636

37-
size_t common_prefix_len(const char **pathspec)
37+
static size_t common_prefix_len(const char **pathspec)
3838
{
3939
const char *n, *first;
4040
size_t max = 0;
@@ -61,6 +61,17 @@ size_t common_prefix_len(const char **pathspec)
6161
return max;
6262
}
6363

64+
/*
65+
* Returns a copy of the longest leading path common among all
66+
* pathspecs.
67+
*/
68+
char *common_prefix(const char **pathspec)
69+
{
70+
unsigned long len = common_prefix_len(pathspec);
71+
72+
return len ? xmemdupz(*pathspec, len) : NULL;
73+
}
74+
6475
int fill_directory(struct dir_struct *dir, const char **pathspec)
6576
{
6677
const char *path;

dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct dir_struct {
6464
#define MATCHED_RECURSIVELY 1
6565
#define MATCHED_FNMATCH 2
6666
#define MATCHED_EXACTLY 3
67-
extern size_t common_prefix_len(const char **pathspec);
67+
extern char *common_prefix(const char **pathspec);
6868
extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
6969
extern int match_pathspec_depth(const struct pathspec *pathspec,
7070
const char *name, int namelen,

setup.c

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

267-
char *pathspec_prefix(const char **pathspec)
268-
{
269-
size_t len = common_prefix_len(pathspec);
270-
271-
return len ? xmemdupz(*pathspec, len) : NULL;
272-
}
273-
274267
/*
275268
* Test if it looks like we're at a git directory.
276269
* We want to see:

0 commit comments

Comments
 (0)