Merge branch 'fix'
* fix: commit-tree.c: check_valid() microoptimization. Fix filename verification when in a subdirectory rebase: typofix. socksetup: don't return on set_reuse_addr() error
This commit is contained in:
		
							
								
								
									
										1
									
								
								cache.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								cache.h
									
									
									
									
									
								
							| @ -134,6 +134,7 @@ extern const char *setup_git_directory_gently(int *); | |||||||
| extern const char *setup_git_directory(void); | extern const char *setup_git_directory(void); | ||||||
| extern const char *prefix_path(const char *prefix, int len, const char *path); | extern const char *prefix_path(const char *prefix, int len, const char *path); | ||||||
| extern const char *prefix_filename(const char *prefix, int len, const char *path); | extern const char *prefix_filename(const char *prefix, int len, const char *path); | ||||||
|  | extern void verify_filename(const char *prefix, const char *name); | ||||||
|  |  | ||||||
| #define alloc_nr(x) (((x)+16)*3/2) | #define alloc_nr(x) (((x)+16)*3/2) | ||||||
|  |  | ||||||
|  | |||||||
| @ -45,14 +45,13 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...) | |||||||
|  |  | ||||||
| static void check_valid(unsigned char *sha1, const char *expect) | static void check_valid(unsigned char *sha1, const char *expect) | ||||||
| { | { | ||||||
| 	void *buf; |  | ||||||
| 	char type[20]; | 	char type[20]; | ||||||
| 	unsigned long size; |  | ||||||
|  |  | ||||||
| 	buf = read_sha1_file(sha1, type, &size); | 	if (sha1_object_info(sha1, type, NULL)) | ||||||
| 	if (!buf || strcmp(type, expect)) | 		die("%s is not a valid object", sha1_to_hex(sha1)); | ||||||
| 		die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect); | 	if (expect && strcmp(type, expect)) | ||||||
| 	free(buf); | 		die("%s is not a valid '%s' object", sha1_to_hex(sha1), | ||||||
|  | 		    expect); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  | |||||||
| @ -107,7 +107,7 @@ onto=$(git-rev-parse --verify "${onto_name}^0") || exit | |||||||
|  |  | ||||||
| # Check if we are already based on $onto, but this should be | # Check if we are already based on $onto, but this should be | ||||||
| # done only when upstream and onto are the same. | # done only when upstream and onto are the same. | ||||||
| if test "$upstream" = "onto" | if test "$upstream" = "$onto" | ||||||
| then | then | ||||||
| 	mb=$(git-merge-base "$onto" "$branch") | 	mb=$(git-merge-base "$onto" "$branch") | ||||||
| 	if test "$mb" = "$onto" | 	if test "$mb" = "$onto" | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								rev-parse.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								rev-parse.c
									
									
									
									
									
								
							| @ -160,14 +160,6 @@ static int show_file(const char *arg) | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void die_badfile(const char *arg) |  | ||||||
| { |  | ||||||
| 	if (errno != ENOENT) |  | ||||||
| 		die("'%s': %s", arg, strerror(errno)); |  | ||||||
| 	die("'%s' is ambiguous - revision name or file/directory name?\n" |  | ||||||
| 	    "Please put '--' before the list of filenames.", arg); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||||
| { | { | ||||||
| 	int i, as_is = 0, verify = 0; | 	int i, as_is = 0, verify = 0; | ||||||
| @ -177,14 +169,12 @@ int main(int argc, char **argv) | |||||||
| 	git_config(git_default_config); | 	git_config(git_default_config); | ||||||
|  |  | ||||||
| 	for (i = 1; i < argc; i++) { | 	for (i = 1; i < argc; i++) { | ||||||
| 		struct stat st; |  | ||||||
| 		char *arg = argv[i]; | 		char *arg = argv[i]; | ||||||
| 		char *dotdot; | 		char *dotdot; | ||||||
|  |  | ||||||
| 		if (as_is) { | 		if (as_is) { | ||||||
| 			if (show_file(arg) && as_is < 2) | 			if (show_file(arg) && as_is < 2) | ||||||
| 				if (lstat(arg, &st) < 0) | 				verify_filename(prefix, arg); | ||||||
| 					die_badfile(arg); |  | ||||||
| 			continue; | 			continue; | ||||||
| 		} | 		} | ||||||
| 		if (!strcmp(arg,"-n")) { | 		if (!strcmp(arg,"-n")) { | ||||||
| @ -350,8 +340,7 @@ int main(int argc, char **argv) | |||||||
| 			continue; | 			continue; | ||||||
| 		if (verify) | 		if (verify) | ||||||
| 			die("Needed a single revision"); | 			die("Needed a single revision"); | ||||||
| 		if (lstat(arg, &st) < 0) | 		verify_filename(prefix, arg); | ||||||
| 			die_badfile(arg); |  | ||||||
| 	} | 	} | ||||||
| 	show_default(); | 	show_default(); | ||||||
| 	if (verify && revs_count != 1) | 	if (verify && revs_count != 1) | ||||||
|  | |||||||
| @ -752,17 +752,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch | |||||||
| 			arg++; | 			arg++; | ||||||
| 		} | 		} | ||||||
| 		if (get_sha1(arg, sha1) < 0) { | 		if (get_sha1(arg, sha1) < 0) { | ||||||
| 			struct stat st; |  | ||||||
| 			int j; | 			int j; | ||||||
|  |  | ||||||
| 			if (seen_dashdash || local_flags) | 			if (seen_dashdash || local_flags) | ||||||
| 				die("bad revision '%s'", arg); | 				die("bad revision '%s'", arg); | ||||||
|  |  | ||||||
| 			/* If we didn't have a "--", all filenames must exist */ | 			/* If we didn't have a "--", all filenames must exist */ | ||||||
| 			for (j = i; j < argc; j++) { | 			for (j = i; j < argc; j++) | ||||||
| 				if (lstat(argv[j], &st) < 0) | 				verify_filename(revs->prefix, argv[j]); | ||||||
| 					die("'%s': %s", argv[j], strerror(errno)); |  | ||||||
| 			} |  | ||||||
| 			revs->prune_data = get_pathspec(revs->prefix, argv + i); | 			revs->prune_data = get_pathspec(revs->prefix, argv + i); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								setup.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								setup.c
									
									
									
									
									
								
							| @ -62,6 +62,29 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) | |||||||
| 	return path; | 	return path; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Verify a filename that we got as an argument for a pathspec | ||||||
|  |  * entry. Note that a filename that begins with "-" never verifies | ||||||
|  |  * as true, because even if such a filename were to exist, we want | ||||||
|  |  * it to be preceded by the "--" marker (or we want the user to | ||||||
|  |  * use a format like "./-filename") | ||||||
|  |  */ | ||||||
|  | void verify_filename(const char *prefix, const char *arg) | ||||||
|  | { | ||||||
|  | 	const char *name; | ||||||
|  | 	struct stat st; | ||||||
|  |  | ||||||
|  | 	if (*arg == '-') | ||||||
|  | 		die("bad flag '%s' used after filename", arg); | ||||||
|  | 	name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg; | ||||||
|  | 	if (!lstat(name, &st)) | ||||||
|  | 		return; | ||||||
|  | 	if (errno == ENOENT) | ||||||
|  | 		die("ambiguous argument '%s': unknown revision or filename\n" | ||||||
|  | 		    "Use '--' to separate filenames from revisions", arg); | ||||||
|  | 	die("'%s': %s", arg, strerror(errno)); | ||||||
|  | } | ||||||
|  |  | ||||||
| const char **get_pathspec(const char *prefix, const char **pathspec) | const char **get_pathspec(const char *prefix, const char **pathspec) | ||||||
| { | { | ||||||
| 	const char *entry = *pathspec; | 	const char *entry = *pathspec; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Junio C Hamano
					Junio C Hamano