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 782a0005 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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 12, 2009 at 16:00 UTC
d5f53d6d6f20bbd1ec5507824eb213463554b36a
1 file changed
+24
-1
archive.c
+24
-1
@@ -211,10 +211,33 @@ static const struct archiver *lookup_archiver(const char *name)
211
return NULL;
212
}
213
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
+
230
static void parse_pathspec_arg(const char **pathspec,
231
struct archiver_args *ar_args)
232
{
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
+ }
241
}
242
243
static void parse_treeish_arg(const char **argv,