rev-parse: introduce --exclude=<glob> to tame wildcards
Teach "rev-parse" the same "I'm going to glob, but omit the ones that match these patterns" feature as "rev-list". Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									ff32d3420a
								
							
						
					
					
						commit
						9dc01bf063
					
				|  | @ -155,6 +155,20 @@ shown.  If the pattern does not contain a globbing character (`?`, | ||||||
| 	character (`?`, `*`, or `[`), it is turned into a prefix | 	character (`?`, `*`, or `[`), it is turned into a prefix | ||||||
| 	match by appending `/*`. | 	match by appending `/*`. | ||||||
|  |  | ||||||
|  | --exclude=<glob-pattern>:: | ||||||
|  | 	Do not include refs matching '<glob-pattern>' that the next `--all`, | ||||||
|  | 	`--branches`, `--tags`, `--remotes`, or `--glob` would otherwise | ||||||
|  | 	consider. Repetitions of this option accumulate exclusion patterns | ||||||
|  | 	up to the next `--all`, `--branches`, `--tags`, `--remotes`, or | ||||||
|  | 	`--glob` option (other options or arguments do not clear | ||||||
|  | 	accumlated patterns). | ||||||
|  | + | ||||||
|  | The patterns given should not begin with `refs/heads`, `refs/tags`, or | ||||||
|  | `refs/remotes` when applied to `--branches`, `--tags`, or `--remotes`, | ||||||
|  | respectively, and they must begin with `refs/` when applied to `--glob` | ||||||
|  | or `--all`. If a trailing '/{asterisk}' is intended, it must be given | ||||||
|  | explicitly. | ||||||
|  |  | ||||||
| --show-toplevel:: | --show-toplevel:: | ||||||
| 	Show the absolute path of the top-level directory. | 	Show the absolute path of the top-level directory. | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -9,6 +9,8 @@ | ||||||
| #include "quote.h" | #include "quote.h" | ||||||
| #include "builtin.h" | #include "builtin.h" | ||||||
| #include "parse-options.h" | #include "parse-options.h" | ||||||
|  | #include "diff.h" | ||||||
|  | #include "revision.h" | ||||||
|  |  | ||||||
| #define DO_REVS		1 | #define DO_REVS		1 | ||||||
| #define DO_NOREV	2 | #define DO_NOREV	2 | ||||||
|  | @ -30,6 +32,8 @@ static int abbrev_ref; | ||||||
| static int abbrev_ref_strict; | static int abbrev_ref_strict; | ||||||
| static int output_sq; | static int output_sq; | ||||||
|  |  | ||||||
|  | static struct string_list *ref_excludes; | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Some arguments are relevant "revision" arguments, |  * Some arguments are relevant "revision" arguments, | ||||||
|  * others are about output format or other details. |  * others are about output format or other details. | ||||||
|  | @ -185,6 +189,8 @@ static int show_default(void) | ||||||
|  |  | ||||||
| static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) | static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) | ||||||
| { | { | ||||||
|  | 	if (ref_excluded(ref_excludes, refname)) | ||||||
|  | 		return 0; | ||||||
| 	show_rev(NORMAL, sha1, refname); | 	show_rev(NORMAL, sha1, refname); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | @ -633,32 +639,43 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) | ||||||
| 			if (!prefixcmp(arg, "--branches=")) { | 			if (!prefixcmp(arg, "--branches=")) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 11, | 				for_each_glob_ref_in(show_reference, arg + 11, | ||||||
| 					"refs/heads/", NULL); | 					"refs/heads/", NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--branches")) { | 			if (!strcmp(arg, "--branches")) { | ||||||
| 				for_each_branch_ref(show_reference, NULL); | 				for_each_branch_ref(show_reference, NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!prefixcmp(arg, "--tags=")) { | 			if (!prefixcmp(arg, "--tags=")) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 7, | 				for_each_glob_ref_in(show_reference, arg + 7, | ||||||
| 					"refs/tags/", NULL); | 					"refs/tags/", NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--tags")) { | 			if (!strcmp(arg, "--tags")) { | ||||||
| 				for_each_tag_ref(show_reference, NULL); | 				for_each_tag_ref(show_reference, NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!prefixcmp(arg, "--glob=")) { | 			if (!prefixcmp(arg, "--glob=")) { | ||||||
| 				for_each_glob_ref(show_reference, arg + 7, NULL); | 				for_each_glob_ref(show_reference, arg + 7, NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!prefixcmp(arg, "--remotes=")) { | 			if (!prefixcmp(arg, "--remotes=")) { | ||||||
| 				for_each_glob_ref_in(show_reference, arg + 10, | 				for_each_glob_ref_in(show_reference, arg + 10, | ||||||
| 					"refs/remotes/", NULL); | 					"refs/remotes/", NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--remotes")) { | 			if (!strcmp(arg, "--remotes")) { | ||||||
| 				for_each_remote_ref(show_reference, NULL); | 				for_each_remote_ref(show_reference, NULL); | ||||||
|  | 				clear_ref_exclusion(&ref_excludes); | ||||||
|  | 				continue; | ||||||
|  | 			} | ||||||
|  | 			if (!prefixcmp(arg, "--exclude=")) { | ||||||
|  | 				add_ref_exclusion(&ref_excludes, arg + 10); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			if (!strcmp(arg, "--show-toplevel")) { | 			if (!strcmp(arg, "--show-toplevel")) { | ||||||
|  |  | ||||||
|  | @ -129,6 +129,18 @@ test_expect_success 'rev-parse --remotes=foo' ' | ||||||
|  |  | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'rev-parse --exclude with --branches' ' | ||||||
|  | 	compare rev-parse "--exclude=*/* --branches" "master someref subspace-x" | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'rev-parse --exclude with --all' ' | ||||||
|  | 	compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags" | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'rev-parse accumulates multiple --exclude' ' | ||||||
|  | 	compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' | test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' | ||||||
|  |  | ||||||
| 	compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" | 	compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano