Skip to content

Commit d5f53d6

Browse files
René Scharfegitster
authored andcommitted
archive: complain about path specs that don't match anything
Verify that all path specs match at least one path in the specified tree and reject those that don't. This would have made the bug fixed by 782a000 easier to find. This implementation is simple to the point of being stupid. It walks the full tree for each path spec until it matches something. It's short and seems to be fast enough, though. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 902f235 commit d5f53d6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

archive.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,33 @@ static const struct archiver *lookup_archiver(const char *name)
211211
return NULL;
212212
}
213213

214+
static int reject_entry(const unsigned char *sha1, const char *base,
215+
int baselen, const char *filename, unsigned mode,
216+
int stage, void *context)
217+
{
218+
return -1;
219+
}
220+
221+
static int path_exists(struct tree *tree, const char *path)
222+
{
223+
const char *pathspec[] = { path, NULL };
224+
225+
if (read_tree_recursive(tree, "", 0, 0, pathspec, reject_entry, NULL))
226+
return 1;
227+
return 0;
228+
}
229+
214230
static void parse_pathspec_arg(const char **pathspec,
215231
struct archiver_args *ar_args)
216232
{
217-
ar_args->pathspec = get_pathspec("", pathspec);
233+
ar_args->pathspec = pathspec = get_pathspec("", pathspec);
234+
if (pathspec) {
235+
while (*pathspec) {
236+
if (!path_exists(ar_args->tree, *pathspec))
237+
die("path not found: %s", *pathspec);
238+
pathspec++;
239+
}
240+
}
218241
}
219242

220243
static void parse_treeish_arg(const char **argv,

0 commit comments

Comments
 (0)