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>
This commit is contained in:
parent
b73a439759
commit
27350891de
@ -20,6 +20,7 @@ SYNOPSIS
|
|||||||
[ \--not ]
|
[ \--not ]
|
||||||
[ \--all ]
|
[ \--all ]
|
||||||
[ \--stdin ]
|
[ \--stdin ]
|
||||||
|
[ \--quiet ]
|
||||||
[ \--topo-order ]
|
[ \--topo-order ]
|
||||||
[ \--parents ]
|
[ \--parents ]
|
||||||
[ \--timestamp ]
|
[ \--timestamp ]
|
||||||
@ -270,6 +271,14 @@ limiting may be applied.
|
|||||||
In addition to the '<commit>' listed on the command
|
In addition to the '<commit>' listed on the command
|
||||||
line, read them from the standard input.
|
line, read them from the standard input.
|
||||||
|
|
||||||
|
--quiet::
|
||||||
|
|
||||||
|
Don't print anything to standard output. This form of
|
||||||
|
git-rev-list is primarly meant to allow the caller to
|
||||||
|
test the exit status to see if a range of objects is fully
|
||||||
|
connected (or not). It is faster than redirecting stdout
|
||||||
|
to /dev/null as the output does not have to be formatted.
|
||||||
|
|
||||||
--cherry-pick::
|
--cherry-pick::
|
||||||
|
|
||||||
Omit any commit that introduces the same change as
|
Omit any commit that introduces the same change as
|
||||||
|
@ -26,6 +26,7 @@ static const char rev_list_usage[] =
|
|||||||
" --remove-empty\n"
|
" --remove-empty\n"
|
||||||
" --all\n"
|
" --all\n"
|
||||||
" --stdin\n"
|
" --stdin\n"
|
||||||
|
" --quiet\n"
|
||||||
" ordering output:\n"
|
" ordering output:\n"
|
||||||
" --topo-order\n"
|
" --topo-order\n"
|
||||||
" --date-order\n"
|
" --date-order\n"
|
||||||
@ -50,6 +51,7 @@ static int show_timestamp;
|
|||||||
static int hdr_termination;
|
static int hdr_termination;
|
||||||
static const char *header_prefix;
|
static const char *header_prefix;
|
||||||
|
|
||||||
|
static void finish_commit(struct commit *commit);
|
||||||
static void show_commit(struct commit *commit)
|
static void show_commit(struct commit *commit)
|
||||||
{
|
{
|
||||||
if (show_timestamp)
|
if (show_timestamp)
|
||||||
@ -93,6 +95,11 @@ static void show_commit(struct commit *commit)
|
|||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
maybe_flush_or_die(stdout, "stdout");
|
maybe_flush_or_die(stdout, "stdout");
|
||||||
|
finish_commit(commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void finish_commit(struct commit *commit)
|
||||||
|
{
|
||||||
if (commit->parents) {
|
if (commit->parents) {
|
||||||
free_commit_list(commit->parents);
|
free_commit_list(commit->parents);
|
||||||
commit->parents = NULL;
|
commit->parents = NULL;
|
||||||
@ -101,6 +108,12 @@ static void show_commit(struct commit *commit)
|
|||||||
commit->buffer = NULL;
|
commit->buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
static void show_object(struct object_array_entry *p)
|
static void show_object(struct object_array_entry *p)
|
||||||
{
|
{
|
||||||
/* An object with name "foo\n0000000..." can be used to
|
/* An object with name "foo\n0000000..." can be used to
|
||||||
@ -108,9 +121,7 @@ static void show_object(struct object_array_entry *p)
|
|||||||
*/
|
*/
|
||||||
const char *ep = strchr(p->name, '\n');
|
const char *ep = strchr(p->name, '\n');
|
||||||
|
|
||||||
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
|
finish_object(p);
|
||||||
die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
|
|
||||||
|
|
||||||
if (ep) {
|
if (ep) {
|
||||||
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
|
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
|
||||||
(int) (ep - p->name),
|
(int) (ep - p->name),
|
||||||
@ -527,6 +538,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
|
|||||||
int read_from_stdin = 0;
|
int read_from_stdin = 0;
|
||||||
int bisect_show_vars = 0;
|
int bisect_show_vars = 0;
|
||||||
int bisect_find_all = 0;
|
int bisect_find_all = 0;
|
||||||
|
int quiet = 0;
|
||||||
|
|
||||||
git_config(git_default_config);
|
git_config(git_default_config);
|
||||||
init_revisions(&revs, prefix);
|
init_revisions(&revs, prefix);
|
||||||
@ -565,6 +577,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
|
|||||||
read_revisions_from_stdin(&revs);
|
read_revisions_from_stdin(&revs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(arg, "--quiet")) {
|
||||||
|
quiet = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
usage(rev_list_usage);
|
usage(rev_list_usage);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -640,7 +656,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
traverse_commit_list(&revs, show_commit, show_object);
|
traverse_commit_list(&revs,
|
||||||
|
quiet ? finish_commit : show_commit,
|
||||||
|
quiet ? finish_object : show_object);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user