git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] revision: add --except option

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Aug 30, 2013, 05:00 UTC
Message-ID
<1377838805-7693-1-git-send-email-felipe.contreras@gmail.com>

So that it's possible to remove certain refs from the list without removing the objects that are referenced by other refs.

For example this repository:
  * 374e8dd (crap) crap
  * 4cbbf7b (test) two
  * d025ae0 (HEAD, master) one
When using '--branches --except crap':
  * 4cbbf7b (test) two
  * d025ae0 (HEAD, master) one
But when using '--branches --not crap' nothing will come out.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/git-rev-parse.txt        |  6 ++++++
 contrib/completion/git-completion.bash |  2 +-
 revision.c                             | 10 ++++++++++
 revision.h                             |  3 ++-
 t/t6112-rev-list-except.sh             | 35 ++++++++++++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100755 t/t6112-rev-list-except.sh
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 2b126c0..fe5cc6b 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -110,6 +110,12 @@ can be used.
 	strip '{caret}' prefix from the object names that already have
 	one.
 
+--except::
+	Skip the following object names. For example:
+	'--branches --except master' will show all the branches, except master.
+	This differs from --not in that --except will still show the object, if
+	they are referenced by another object name.
+
 --symbolic::
 	Usually the object names are output in SHA-1 form (with
 	possible '{caret}' prefix); this option makes them output in a
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5da920e..aed8c12 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1386,7 +1386,7 @@ _git_ls_tree ()
 
 # Options that go well for log, shortlog and gitk
 __git_log_common_options="
-	--not --all
+	--not --except --all
 	--branches --tags --remotes
 	--first-parent --merges --no-merges
 	--max-count=
diff --git a/revision.c b/revision.c
index 84ccc05..375adab 100644
--- a/revision.c
+++ b/revision.c
@@ -1984,6 +1984,8 @@ static int handle_revision_pseudo_opt(const char *submodule,
 		handle_reflog(revs, *flags);
 	} else if (!strcmp(arg, "--not")) {
 		*flags ^= UNINTERESTING | BOTTOM;
+	} else if (!strcmp(arg, "--except")) {
+		*flags ^= SKIP;
 	} else if (!strcmp(arg, "--no-walk")) {
 		revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
 	} else if (!prefixcmp(arg, "--no-walk=")) {
@@ -2578,6 +2580,7 @@ int prepare_revision_walk(struct rev_info *revs)
 	int nr = revs->pending.nr;
 	struct object_array_entry *e, *list;
 	struct commit_list **next = &revs->commits;
+	int i;
 
 	e = list = revs->pending.objects;
 	revs->pending.nr = 0;
@@ -2585,12 +2588,19 @@ int prepare_revision_walk(struct rev_info *revs)
 	revs->pending.objects = NULL;
 	while (--nr >= 0) {
 		struct commit *commit = handle_commit(revs, e->item, e->name);
+		for (i = 0; i < revs->cmdline.nr; i++) {
+			struct rev_cmdline_entry *ce;
+			ce = &revs->cmdline.rev[i];
+			if ((ce->flags & SKIP) && !strcmp(ce->name, e->name))
+				goto next;
+		}
 		if (commit) {
 			if (!(commit->object.flags & SEEN)) {
 				commit->object.flags |= SEEN;
 				next = commit_list_append(commit, next);
 			}
 		}
+next:
 		e++;
 	}
 	if (!revs->leak_pending)
diff --git a/revision.h b/revision.h
index 95859ba..89f5037 100644
--- a/revision.h
+++ b/revision.h
@@ -17,7 +17,8 @@
 #define SYMMETRIC_LEFT	(1u<<8)
 #define PATCHSAME	(1u<<9)
 #define BOTTOM		(1u<<10)
-#define ALL_REV_FLAGS	((1u<<11)-1)
+#define SKIP		(1u<<11)
+#define ALL_REV_FLAGS	((1u<<12)-1)
 
 #define DECORATE_SHORT_REFS	1
 #define DECORATE_FULL_REFS	2
diff --git a/t/t6112-rev-list-except.sh b/t/t6112-rev-list-except.sh
new file mode 100755
index 0000000..b8f9a61
--- /dev/null
+++ b/t/t6112-rev-list-except.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='test for rev-list --except'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+
+	echo one > content &&
+	git add content &&
+	git commit -m one &&
+	git checkout -b test master &&
+	echo two > content &&
+	git commit -a -m two &&
+	git checkout -b merge master &&
+	git merge test
+'
+
+test_expect_success 'rev-list --except' '
+
+	git rev-list --topo-order --branches --except merge > actual &&
+	git rev-list --topo-order test > expect &&
+	test_cmp expect actual
+'
+
+test_expect_success 'rev-list --except with extra' '
+
+	echo three > content &&
+	git commit -a -m three &&
+	git rev-list --topo-order --branches --except merge > actual &&
+	git rev-list --topo-order test > expect &&
+	test_cmp expect actual
+'
+
+test_done
-- 
1.8.4-fc
Next: Felipe Contreras
Message 1 of 32 in “revision: add --except option”
  1. revision: add --except optionFelipe Contreras, Aug 30, 2013
  2. Felipe ContrerasAug 30, 2013
  3. Junio C HamanoAug 30, 2013
  4. Felipe ContrerasAug 30, 2013
  5. Johannes SixtAug 30, 2013
  6. Felipe ContrerasAug 31, 2013
  7. Johannes SixtSep 2, 2013
  8. Felipe ContrerasSep 2, 2013
  9. Johannes SixtAug 30, 2013
  10. Felipe ContrerasAug 30, 2013
  11. Felipe ContrerasAug 30, 2013
  12. Johannes SixtAug 30, 2013
  13. Junio C HamanoAug 30, 2013
  14. Felipe ContrerasAug 30, 2013
  15. revision: introduce --exclude=<glob> to tame wildcardsJunio C Hamano, Aug 30, 2013
  16. Duy NguyenAug 31, 2013
  17. Junio C HamanoAug 31, 2013
  18. Felipe ContrerasAug 31, 2013
  19. Junio C HamanoSep 3, 2013
  20. Felipe ContrerasSep 3, 2013
  21. Johannes SixtSep 2, 2013
  22. Felipe ContrerasSep 2, 2013
  23. Michael HaggertySep 3, 2013
  24. Junio C HamanoSep 3, 2013
  25. Johannes SixtSep 3, 2013
  26. 0/5 ref glob exclusion follow-upJunio C Hamano, Nov 1, 2013
  27. 3/5 rev-list --exclude: testsJunio C Hamano, Nov 1, 2013
  28. 4/5 rev-list --exclude: export add/clear-ref-exclusion and ref-excluded APIJunio C Hamano, Nov 1, 2013
  29. 5/5 rev-parse: introduce --exclude=<glob> to tame wildcardsJunio C Hamano, Nov 1, 2013
  30. Eric SunshineNov 1, 2013
  31. Junio C HamanoNov 1, 2013
  32. Johannes SixtNov 1, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.