Skip to content

Commit 42cabc3

Browse files
author
Junio C Hamano
committed
Teach rev-list an option to read revs from the standard input.
When --stdin option is given, in addition to the <rev>s listed on the command line, the command can read one rev parameter per line from the standard input. The list of revs ends at the first empty line or EOF. Note that you still have to give all the flags from the command line; only rev arguments (including A..B, A...B, and A^@ notations) can be give from the standard input. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 5d6f093 commit 42cabc3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Documentation/git-rev-list.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SYNOPSIS
1717
[ \--remove-empty ]
1818
[ \--not ]
1919
[ \--all ]
20+
[ \--stdin ]
2021
[ \--topo-order ]
2122
[ \--parents ]
2223
[ [\--objects | \--objects-edge] [ \--unpacked ] ]
@@ -171,6 +172,11 @@ limiting may be applied.
171172
Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the
172173
command line as '<commit>'.
173174

175+
--stdin::
176+
177+
In addition to the '<commit>' listed on the command
178+
line, read them from the standard input.
179+
174180
--merge::
175181

176182
After a failed merge, show refs that touch files having a

builtin-rev-list.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const char rev_list_usage[] =
2323
" --no-merges\n"
2424
" --remove-empty\n"
2525
" --all\n"
26+
" --stdin\n"
2627
" ordering output:\n"
2728
" --topo-order\n"
2829
" --date-order\n"
@@ -304,10 +305,28 @@ static void mark_edges_uninteresting(struct commit_list *list)
304305
}
305306
}
306307

308+
static void read_revisions_from_stdin(struct rev_info *revs)
309+
{
310+
char line[1000];
311+
312+
while (fgets(line, sizeof(line), stdin) != NULL) {
313+
int len = strlen(line);
314+
if (line[len - 1] == '\n')
315+
line[--len] = 0;
316+
if (!len)
317+
break;
318+
if (line[0] == '-')
319+
die("options not supported in --stdin mode");
320+
if (handle_revision_arg(line, revs, 0, 1))
321+
die("bad revision '%s'", line);
322+
}
323+
}
324+
307325
int cmd_rev_list(int argc, const char **argv, const char *prefix)
308326
{
309327
struct commit_list *list;
310328
int i;
329+
int read_from_stdin = 0;
311330

312331
init_revisions(&revs, prefix);
313332
revs.abbrev = 0;
@@ -329,6 +348,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
329348
bisect_list = 1;
330349
continue;
331350
}
351+
if (!strcmp(arg, "--stdin")) {
352+
if (read_from_stdin++)
353+
die("--stdin given twice?");
354+
read_revisions_from_stdin(&revs);
355+
continue;
356+
}
332357
usage(rev_list_usage);
333358

334359
}

0 commit comments

Comments
 (0)