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

[PATCH] Enable git rev-list to parse --quiet

From
Nick Andrew <nick@nick-andrew.net>
Date
Jul 18, 2008, 04:05 UTC
Message-ID
<20080718040459.13073.76896.stgit@marcab.local.tull.net>
Enable git rev-list to parse --quiet

git rev-list never sees the --quiet option because --quiet is also an option for diff-files.

Example:

$ ./git rev-list --quiet ^HEAD~2 HEAD 1e102bf7c83281944ffd9202a7d35c514e4a5644 3bf0dd1f4e75ee1591169b687ce04dff00ae2e3e $ echo $? 0

The fix scans the argument list to detect --quiet before passing it to setup_revisions(). It also arranges to count the number of commits or objects (whether sent to STDOUT or not) so --quiet can return an appropriate exit code (1 if there were commits/objects, 0 otherwise).

After fix:

$ ./git rev-list --quiet ^HEAD~2 HEAD $ echo $? 1 ---

 builtin-rev-list.c |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 8e1720c..e2e5e13 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -52,6 +52,11 @@ static const char rev_list_usage[] =
 
 static struct rev_info revs;
 
+/* Count of number of commits or objects noticed (even if not output).
+ * Used by --quiet option to set an appropriate exit status.
+ */
+static int seen_count;
+
 static int bisect_list;
 static int show_timestamp;
 static int hdr_termination;
@@ -167,12 +172,14 @@ static void finish_commit(struct commit *commit)
 	}
 	free(commit->buffer);
 	commit->buffer = NULL;
+	seen_count++;
 }
 
 static void finish_object(struct object_array_entry *p)
 {
 	if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
 		die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
+	seen_count++;
 }
 
 static void show_object(struct object_array_entry *p)
@@ -588,6 +595,17 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 	init_revisions(&revs, prefix);
 	revs.abbrev = 0;
 	revs.commit_format = CMIT_FMT_UNSPECIFIED;
+
+	/* Parse options which are also recognised by git-diff-files */
+	for (i = 1 ; i < argc; i++) {
+		const char *arg = argv[i];
+
+		if (!strcmp(arg, "--quiet")) {
+			quiet = 1;
+			continue;
+		}
+	}
+
 	argc = setup_revisions(argc, argv, &revs, NULL);
 
 	for (i = 1 ; i < argc; i++) {
@@ -621,10 +639,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 			read_revisions_from_stdin(&revs);
 			continue;
 		}
-		if (!strcmp(arg, "--quiet")) {
-			quiet = 1;
-			continue;
-		}
 		usage(rev_list_usage);
 
 	}
@@ -700,9 +714,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		}
 	}
 
+	seen_count = 0;
+
 	traverse_commit_list(&revs,
 		quiet ? finish_commit : show_commit,
 		quiet ? finish_object : show_object);
 
+	if (quiet) {
+		return seen_count ? 1 : 0;
+	}
+
 	return 0;
 }
Next: Junio C Hamano
Message 1 of 8 in “Enable git rev-list to parse --quiet”
  1. Enable git rev-list to parse --quietNick Andrew, Jul 18, 2008
  2. Junio C HamanoJul 18, 2008
  3. Junio C HamanoJul 18, 2008
  4. Nick AndrewJul 18, 2008
  5. Johannes SchindelinJul 18, 2008
  6. Junio C HamanoJul 20, 2008
  7. Nick AndrewJul 20, 2008
  8. Junio C HamanoJul 20, 2008

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.