This will be reused by a new git check-ignore command. Signed-off-by: Adam Spiers <git@xxxxxxxxxxxxxx> --- pathspec.c | 20 ++++++++++++++------ pathspec.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pathspec.c b/pathspec.c index 8aea0d2..6724121 100644 --- a/pathspec.c +++ b/pathspec.c @@ -77,9 +77,20 @@ void treat_gitlinks(const char **pathspec) } /* + * Dies if the given path refers to a file inside a symlinked + * directory. + */ +void validate_path(const char *path, const char *prefix) +{ + if (has_symlink_leading_path(path, strlen(path))) { + int len = prefix ? strlen(prefix) : 0; + die(_("'%s' is beyond a symbolic link"), path + len); + } +} + +/* * Normalizes argv relative to prefix, via get_pathspec(), and then - * dies if any path in the normalized list refers to a file inside a - * symlinked directory. + * runs validate_path() on each path in the normalized list. */ const char **validate_pathspec(const char **argv, const char *prefix) { @@ -88,10 +99,7 @@ const char **validate_pathspec(const char **argv, const char *prefix) if (pathspec) { const char **p; for (p = pathspec; *p; p++) { - if (has_symlink_leading_path(*p, strlen(*p))) { - int len = prefix ? strlen(prefix) : 0; - die(_("'%s' is beyond a symbolic link"), *p + len); - } + validate_path(*p, prefix); } } diff --git a/pathspec.h b/pathspec.h index 8bb670b..c251441 100644 --- a/pathspec.h +++ b/pathspec.h @@ -2,4 +2,5 @@ extern char *find_used_pathspec(const char **pathspec); extern void fill_pathspec_matches(const char **pathspec, char *seen, int specs); extern const char *treat_gitlink(const char *path); extern void treat_gitlinks(const char **pathspec); +extern void validate_path(const char *path, const char *prefix); extern const char **validate_pathspec(const char **argv, const char *prefix); -- 1.7.11.2.249.g31c7954 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html