rev-parse: use skip_prefix when parsing options
Using skip_prefix lets us avoid manually-counted offsets into the argument string. This patch converts the simple and obvious cases. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									e7e07d5a4f
								
							
						
					
					
						commit
						ef87cc79df
					
				|  | @ -719,8 +719,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				for_each_ref(show_reference, NULL); | 				for_each_ref(show_reference, NULL); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--disambiguate=")) { | 			if (skip_prefix(arg, "--disambiguate=", &arg)) { | ||||||
| 				for_each_abbrev(arg + 15, show_abbrev, NULL); | 				for_each_abbrev(arg, show_abbrev, NULL); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--bisect")) { | 			if (!strcmp(arg, "--bisect")) { | ||||||
|  | @ -728,8 +728,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				for_each_ref_in("refs/bisect/good", anti_reference, NULL); | 				for_each_ref_in("refs/bisect/good", anti_reference, NULL); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--branches=")) { | 			if (skip_prefix(arg, "--branches=", &arg)) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 11, | 				for_each_glob_ref_in(show_reference, arg, | ||||||
| 					"refs/heads/", NULL); | 					"refs/heads/", NULL); | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
|  | @ -739,8 +739,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--tags=")) { | 			if (skip_prefix(arg, "--tags=", &arg)) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 7, | 				for_each_glob_ref_in(show_reference, arg, | ||||||
| 					"refs/tags/", NULL); | 					"refs/tags/", NULL); | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
|  | @ -750,13 +750,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--glob=")) { | 			if (skip_prefix(arg, "--glob=", &arg)) { | ||||||
| 				for_each_glob_ref(show_reference, arg + 7, NULL); | 				for_each_glob_ref(show_reference, arg, NULL); | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--remotes=")) { | 			if (skip_prefix(arg, "--remotes=", &arg)) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 10, | 				for_each_glob_ref_in(show_reference, arg, | ||||||
| 					"refs/remotes/", NULL); | 					"refs/remotes/", NULL); | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
|  | @ -766,8 +766,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				clear_ref_exclusion(&ref_excludes); | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--exclude=")) { | 			if (skip_prefix(arg, "--exclude=", &arg)) { | ||||||
| 				add_ref_exclusion(&ref_excludes, arg + 10); | 				add_ref_exclusion(&ref_excludes, arg); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--show-toplevel")) { | 			if (!strcmp(arg, "--show-toplevel")) { | ||||||
|  | @ -849,20 +849,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 				} | 				} | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--since=")) { | 			if (skip_prefix(arg, "--since=", &arg)) { | ||||||
| 				show_datestring("--max-age=", arg+8); | 				show_datestring("--max-age=", arg); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--after=")) { | 			if (skip_prefix(arg, "--after=", &arg)) { | ||||||
| 				show_datestring("--max-age=", arg+8); | 				show_datestring("--max-age=", arg); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--before=")) { | 			if (skip_prefix(arg, "--before=", &arg)) { | ||||||
| 				show_datestring("--min-age=", arg+9); | 				show_datestring("--min-age=", arg); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (starts_with(arg, "--until=")) { | 			if (skip_prefix(arg, "--until=", &arg)) { | ||||||
| 				show_datestring("--min-age=", arg+8); | 				show_datestring("--min-age=", arg); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (show_flag(arg) && verify) | 			if (show_flag(arg) && verify) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Jeff King
						Jeff King