parse_pathspec: support stripping/checking submodule paths
PATHSPEC_SYMLINK_LEADING_PATH and _STRIP_SUBMODULE_SLASH_EXPENSIVE are respectively the alternate implementation of pathspec.c:die_if_path_beyond_symlink() and pathspec.c:check_path_for_gitlink(). They are intended to replace those functions when builtin/add.c and builtin/check-ignore.c are converted to use parse_pathspec. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
8745024422d4b38d8bf93d342b7b173f57cbceaa
2 files changed
+36
pathspec.c
+26
@@ -214,6 +214,26 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
214
match[item->len] = '\0';
215
}
216
217
+ if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
218
+ for (i = 0; i < active_nr; i++) {
219
+ struct cache_entry *ce = active_cache[i];
220
+ int ce_len = ce_namelen(ce);
221
+
222
+ if (!S_ISGITLINK(ce->ce_mode))
223
+ continue;
224
+
225
+ if (item->len <= ce_len || match[ce_len] != '/' ||
226
+ memcmp(ce->name, match, ce_len))
227
+ continue;
228
+ if (item->len == ce_len + 1) {
229
+ /* strip trailing slash */
230
+ item->len--;
231
+ match[item->len] = '\0';
232
+ } else
233
+ die (_("Pathspec '%s' is in submodule '%.*s'"),
234
+ elt, ce_len, ce->name);
235
+ }
236
+
237
if (limit_pathspec_to_literal())
238
item->nowildcard_len = item->len;
239
else
@@ -329,6 +349,12 @@ void parse_pathspec(struct pathspec *pathspec,
349
unsupported_magic(entry,
350
item[i].magic & magic_mask,
351
short_magic);
352
+
353
+ if ((flags & PATHSPEC_SYMLINK_LEADING_PATH) &&
354
+ has_symlink_leading_path(item[i].match, item[i].len)) {
355
+ die(_("pathspec '%s' is beyond a symbolic link"), entry);
356
+ }
357
+
358
if (item[i].nowildcard_len < item[i].len)
359
pathspec->has_wildcard = 1;
360
pathspec->magic |= item[i].magic;
pathspec.h
+10
@@ -33,6 +33,16 @@ struct pathspec {
33
#define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
34
/* strip the trailing slash if the given path is a gitlink */
35
#define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<3)
36
+/* die if a symlink is part of the given path's directory */
37
+#define PATHSPEC_SYMLINK_LEADING_PATH (1<<4)
38
+/*
39
+ * This is like a combination of ..LEADING_PATH and .._SLASH_CHEAP
40
+ * (but not the same): it strips the trailing slash if the given path
41
+ * is a gitlink but also checks and dies if gitlink is part of the
42
+ * leading path (i.e. the given path goes beyond a submodule). It's
43
+ * safer than _SLASH_CHEAP and also more expensive.
44
+ */
45
+#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5)
46
47
extern int init_pathspec(struct pathspec *, const char **);
48
extern void parse_pathspec(struct pathspec *pathspec,