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 <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Spiers committed
Jan 6, 2013 at 16:58 UTC
512aaf9453cecfa57dddc61aec2132b936b2ff70
3 files changed
+19
-4
builtin/add.c
+6
-4
@@ -153,6 +153,11 @@ static void refresh(int verbose, const char **pathspec)
153
free(seen);
154
}
155
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
+ */
161
static const char **validate_pathspec(const char **argv, const char *prefix)
162
{
163
const char **pathspec = get_pathspec(prefix, argv);
@@ -160,10 +165,7 @@ static const char **validate_pathspec(const char **argv, const char *prefix)
165
if (pathspec) {
166
const char **p;
167
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);
169
}
170
}
171
pathspec.c
+12
@@ -87,3 +87,15 @@ const char *check_path_for_gitlink(const char *path)
87
}
88
return path;
89
}
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
+1
@@ -4,5 +4,6 @@
4
extern char *find_pathspecs_matching_against_index(const char **pathspec);
5
extern void add_pathspec_matches_against_index(const char **pathspec, char *seen, int specs);
6
extern const char *check_path_for_gitlink(const char *path);
7
+extern void die_if_path_beyond_symlink(const char *path, const char *prefix);
8
9
#endif /* PATHSPEC_H */