Skip to content

Commit 512aaf9

Browse files
aspiersgitster
authored andcommitted
add.c: extract new die_if_path_beyond_symlink() for reuse
This will be reused by a new git check-ignore command. Also document validate_pathspec(). Signed-off-by: Adam Spiers <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d67b61 commit 512aaf9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

builtin/add.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,19 @@ static void refresh(int verbose, const char **pathspec)
153153
free(seen);
154154
}
155155

156+
/*
157+
* Normalizes argv relative to prefix, via get_pathspec(), and then
158+
* runs die_if_path_beyond_symlink() on each path in the normalized
159+
* list.
160+
*/
156161
static const char **validate_pathspec(const char **argv, const char *prefix)
157162
{
158163
const char **pathspec = get_pathspec(prefix, argv);
159164

160165
if (pathspec) {
161166
const char **p;
162167
for (p = pathspec; *p; p++) {
163-
if (has_symlink_leading_path(*p, strlen(*p))) {
164-
int len = prefix ? strlen(prefix) : 0;
165-
die(_("'%s' is beyond a symbolic link"), *p + len);
166-
}
168+
die_if_path_beyond_symlink(*p, prefix);
167169
}
168170
}
169171

pathspec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,15 @@ const char *check_path_for_gitlink(const char *path)
8787
}
8888
return path;
8989
}
90+
91+
/*
92+
* Dies if the given path refers to a file inside a symlinked
93+
* directory in the index.
94+
*/
95+
void die_if_path_beyond_symlink(const char *path, const char *prefix)
96+
{
97+
if (has_symlink_leading_path(path, strlen(path))) {
98+
int len = prefix ? strlen(prefix) : 0;
99+
die(_("'%s' is beyond a symbolic link"), path + len);
100+
}
101+
}

pathspec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
extern char *find_pathspecs_matching_against_index(const char **pathspec);
55
extern void add_pathspec_matches_against_index(const char **pathspec, char *seen, int specs);
66
extern const char *check_path_for_gitlink(const char *path);
7+
extern void die_if_path_beyond_symlink(const char *path, const char *prefix);
78

89
#endif /* PATHSPEC_H */

0 commit comments

Comments
 (0)