@matheusbsbs / matheus-bagliano / commits / 27350891de
Fork 0

rev-list: Introduce --quiet to avoid /dev/null redirects

Some uses of git-rev-list are to run it with --objects to see if a range of objects between two or more commits is fully connected or not. In such a case the caller doesn't care about the actual object names or hash hints so formatting this data only for it to be dumped to /dev/null by a redirect is a waste of CPU time. If all the caller needs is the exit status then --quiet can be used to bypass the commit and object formatting. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 11, 2007 at 02:29 UTC 27350891de59608d4db689cf0851f7e49158a6e3
2 files changed +31 -4
Documentation/git-rev-list.txt
+9
@@ -20,6 +20,7 @@ SYNOPSIS
20 [ \--not ]
21 [ \--all ]
22 [ \--stdin ]
23 + [ \--quiet ]
24 [ \--topo-order ]
25 [ \--parents ]
26 [ \--timestamp ]
@@ -270,6 +271,14 @@ limiting may be applied.
271 In addition to the '<commit>' listed on the command
272 line, read them from the standard input.
273
274 +--quiet::
275 +
276 + Don't print anything to standard output. This form of
277 + git-rev-list is primarly meant to allow the caller to
278 + test the exit status to see if a range of objects is fully
279 + connected (or not). It is faster than redirecting stdout
280 + to /dev/null as the output does not have to be formatted.
281 +
282 --cherry-pick::
283
284 Omit any commit that introduces the same change as
builtin-rev-list.c
+22 -4
@@ -26,6 +26,7 @@ static const char rev_list_usage[] =
26 " --remove-empty\n"
27 " --all\n"
28 " --stdin\n"
29 +" --quiet\n"
30 " ordering output:\n"
31 " --topo-order\n"
32 " --date-order\n"
@@ -50,6 +51,7 @@ static int show_timestamp;
51 static int hdr_termination;
52 static const char *header_prefix;
53
54 +static void finish_commit(struct commit *commit);
55 static void show_commit(struct commit *commit)
56 {
57 if (show_timestamp)
@@ -93,6 +95,11 @@ static void show_commit(struct commit *commit)
95 strbuf_release(&buf);
96 }
97 maybe_flush_or_die(stdout, "stdout");
98 + finish_commit(commit);
99 +}
100 +
101 +static void finish_commit(struct commit *commit)
102 +{
103 if (commit->parents) {
104 free_commit_list(commit->parents);
105 commit->parents = NULL;
@@ -101,6 +108,12 @@ static void show_commit(struct commit *commit)
108 commit->buffer = NULL;
109 }
110
111 +static void finish_object(struct object_array_entry *p)
112 +{
113 + if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
114 + die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
115 +}
116 +
117 static void show_object(struct object_array_entry *p)
118 {
119 /* An object with name "foo\n0000000..." can be used to
@@ -108,9 +121,7 @@ static void show_object(struct object_array_entry *p)
121 */
122 const char *ep = strchr(p->name, '\n');
123
111 - if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
112 - die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
113 -
124 + finish_object(p);
125 if (ep) {
126 printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
127 (int) (ep - p->name),
@@ -527,6 +538,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
538 int read_from_stdin = 0;
539 int bisect_show_vars = 0;
540 int bisect_find_all = 0;
541 + int quiet = 0;
542
543 git_config(git_default_config);
544 init_revisions(&revs, prefix);
@@ -565,6 +577,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
577 read_revisions_from_stdin(&revs);
578 continue;
579 }
580 + if (!strcmp(arg, "--quiet")) {
581 + quiet = 1;
582 + continue;
583 + }
584 usage(rev_list_usage);
585
586 }
@@ -640,7 +656,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
656 }
657 }
658
643 - traverse_commit_list(&revs, show_commit, show_object);
659 + traverse_commit_list(&revs,
660 + quiet ? finish_commit : show_commit,
661 + quiet ? finish_object : show_object);
662
663 return 0;
664 }