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>
			
			
				maint
			
			
		
							parent
							
								
									902f235378
								
							
						
					
					
						commit
						d5f53d6d6f
					
				
							
								
								
									
										25
									
								
								archive.c
								
								
								
								
							
							
						
						
									
										25
									
								
								archive.c
								
								
								
								
							|  | @ -211,10 +211,33 @@ static const struct archiver *lookup_archiver(const char *name) | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static int reject_entry(const unsigned char *sha1, const char *base, | ||||||
|  | 			int baselen, const char *filename, unsigned mode, | ||||||
|  | 			int stage, void *context) | ||||||
|  | { | ||||||
|  | 	return -1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int path_exists(struct tree *tree, const char *path) | ||||||
|  | { | ||||||
|  | 	const char *pathspec[] = { path, NULL }; | ||||||
|  |  | ||||||
|  | 	if (read_tree_recursive(tree, "", 0, 0, pathspec, reject_entry, NULL)) | ||||||
|  | 		return 1; | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| static void parse_pathspec_arg(const char **pathspec, | static void parse_pathspec_arg(const char **pathspec, | ||||||
| 		struct archiver_args *ar_args) | 		struct archiver_args *ar_args) | ||||||
| { | { | ||||||
| 	ar_args->pathspec = get_pathspec("", pathspec); | 	ar_args->pathspec = pathspec = get_pathspec("", pathspec); | ||||||
|  | 	if (pathspec) { | ||||||
|  | 		while (*pathspec) { | ||||||
|  | 			if (!path_exists(ar_args->tree, *pathspec)) | ||||||
|  | 				die("path not found: %s", *pathspec); | ||||||
|  | 			pathspec++; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| static void parse_treeish_arg(const char **argv, | static void parse_treeish_arg(const char **argv, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 René Scharfe
						René Scharfe