add.c: extract new die_if_path_beyond_symlink() for reuse
authorAdam Spiers <git@adamspiers.org>
Sun, 6 Jan 2013 16:58:11 +0000 (16:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 6 Jan 2013 22:26:37 +0000 (14:26 -0800)
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>
builtin/add.c
pathspec.c
pathspec.h
index f95ded2567035a41f365df9cb765bfe6820ced96..3716617e221932d00c34e5b0eed80beb18791785 100644 (file)
@@ -153,6 +153,11 @@ static void refresh(int verbose, const char **pathspec)
         free(seen);
 }
 
+/*
+ * Normalizes argv relative to prefix, via get_pathspec(), and then
+ * runs die_if_path_beyond_symlink() on each path in the normalized
+ * list.
+ */
 static const char **validate_pathspec(const char **argv, const char *prefix)
 {
        const char **pathspec = get_pathspec(prefix, argv);
@@ -160,10 +165,7 @@ static 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);
-                       }
+                       die_if_path_beyond_symlink(*p, prefix);
                }
        }
 
index 02d33444608ec65d02f45623e1ddf694f61747bd..284f3970a31eb86a121712267e36ff162452590d 100644 (file)
@@ -87,3 +87,15 @@ const char *check_path_for_gitlink(const char *path)
        }
        return path;
 }
+
+/*
+ * Dies if the given path refers to a file inside a symlinked
+ * directory in the index.
+ */
+void die_if_path_beyond_symlink(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);
+       }
+}
index bf8eb9629add8798c6d9c1a8dbc5215a5ba8a4e6..db0184a1acda155fa2b6d6fa07b6a87dc0683e57 100644 (file)
@@ -4,5 +4,6 @@
 extern char *find_pathspecs_matching_against_index(const char **pathspec);
 extern void add_pathspec_matches_against_index(const char **pathspec, char *seen, int specs);
 extern const char *check_path_for_gitlink(const char *path);
+extern void die_if_path_beyond_symlink(const char *path, const char *prefix);
 
 #endif /* PATHSPEC_H */