archive: convert to use parse_pathspec
[gitweb.git] / pathspec.c
index 1c07c23fe0e4bb7b9847fca47624b3097a175adf..ba6408a74cff0e0fe0028e98e508bd8db4e2dc33 100644 (file)
@@ -203,7 +203,17 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
        else
                match = prefix_path(prefix, prefixlen, copyfrom);
        *raw = item->match = match;
-       item->original = elt;
+       /*
+        * Prefix the pathspec (keep all magic) and assign to
+        * original. Useful for passing to another command.
+        */
+       if (flags & PATHSPEC_PREFIX_ORIGIN) {
+               struct strbuf sb = STRBUF_INIT;
+               strbuf_add(&sb, elt, copyfrom - elt);
+               strbuf_addstr(&sb, match);
+               item->original = strbuf_detach(&sb, NULL);
+       } else
+               item->original = elt;
        item->len = strlen(item->match);
 
        if ((flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) &&
@@ -214,6 +224,26 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
                match[item->len] = '\0';
        }
 
+       if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
+               for (i = 0; i < active_nr; i++) {
+                       struct cache_entry *ce = active_cache[i];
+                       int ce_len = ce_namelen(ce);
+
+                       if (!S_ISGITLINK(ce->ce_mode))
+                               continue;
+
+                       if (item->len <= ce_len || match[ce_len] != '/' ||
+                           memcmp(ce->name, match, ce_len))
+                               continue;
+                       if (item->len == ce_len + 1) {
+                               /* strip trailing slash */
+                               item->len--;
+                               match[item->len] = '\0';
+                       } else
+                               die (_("Pathspec '%s' is in submodule '%.*s'"),
+                                    elt, ce_len, ce->name);
+               }
+
        if (limit_pathspec_to_literal())
                item->nowildcard_len = item->len;
        else
@@ -329,6 +359,12 @@ void parse_pathspec(struct pathspec *pathspec,
                        unsupported_magic(entry,
                                          item[i].magic & magic_mask,
                                          short_magic);
+
+               if ((flags & PATHSPEC_SYMLINK_LEADING_PATH) &&
+                   has_symlink_leading_path(item[i].match, item[i].len)) {
+                       die(_("pathspec '%s' is beyond a symbolic link"), entry);
+               }
+
                if (item[i].nowildcard_len < item[i].len)
                        pathspec->has_wildcard = 1;
                pathspec->magic |= item[i].magic;