threads / discuss / 4187

Make git-rev-list understand --tags/--branches/--remotes

Subject: Make git-rev-list understand --tags/--branches/--remotes

## tl;dr

One message between May 17, 2006 and May 17, 2006.

replies: 0people: 1as markdown or json

Linus Torvalds· May 17, 2006, 21:44 UTC · lore

We shouldn't add stuff to git-rev-parse without teaching git-rev-list and all the other tools to do the same.

In fact, these days there is much less reason for git-rev-parse in the first place: it's usually used to verify a particular reference, or to just split the different argument types up from each other. Most tools don't need or use it any more (eg "gitk" will just pass its arguments directly to git-rev-list).

With this, you can now do (for example)
	gitk HEAD --not --tags

to see all the work on all the main branch that hasn't been included in a tagged version (replace HEAD with "--branches" to show all branches, of course).

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/revision.c b/revision.c
index 2294b16..1fc6725 100644
--- a/revision.c
+++ b/revision.c
@@ -470,11 +470,13 @@ static int handle_one_ref(const char *pa
 	return 0;
 }
 
-static void handle_all(struct rev_info *revs, unsigned flags)
+typedef int (*ref_fn_t)(int (*)(const char *, const unsigned char *));
+
+static void handle_ref(ref_fn_t fn, struct rev_info *revs, unsigned flags)
 {
 	all_revs = revs;
 	all_flags = flags;
-	for_each_ref(handle_one_ref);
+	fn(handle_one_ref);
 }
 
 static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
@@ -614,7 +616,19 @@ int setup_revisions(int argc, const char
 				continue;
 			}
 			if (!strcmp(arg, "--all")) {
-				handle_all(revs, flags);
+				handle_ref(for_each_ref, revs, flags);
+				continue;
+			}
+			if (!strcmp(arg, "--branches")) {
+				handle_ref(for_each_branch_ref, revs, flags);
+				continue;
+			}
+			if (!strcmp(arg, "--tags")) {
+				handle_ref(for_each_tag_ref, revs, flags);
+				continue;
+			}
+			if (!strcmp(arg, "--remotes")) {
+				handle_ref(for_each_remote_ref, revs, flags);
 				continue;
 			}
 			if (!strcmp(arg, "--not")) {

← back to recent threads