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>
Junio C Hamano committed
Sep 5, 2006 at 21:39 UTC
42cabc341c4e6da3c9873db7af1003bd1a72a8fd
2 files changed
+31
Documentation/git-rev-list.txt
+6
@@ -17,6 +17,7 @@ SYNOPSIS
17
[ \--remove-empty ]
18
[ \--not ]
19
[ \--all ]
20
+ [ \--stdin ]
21
[ \--topo-order ]
22
[ \--parents ]
23
[ [\--objects | \--objects-edge] [ \--unpacked ] ]
@@ -171,6 +172,11 @@ limiting may be applied.
172
Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the
173
command line as '<commit>'.
174
175
+--stdin::
176
+
177
+ In addition to the '<commit>' listed on the command
178
+ line, read them from the standard input.
179
+
180
--merge::
181
182
After a failed merge, show refs that touch files having a
builtin-rev-list.c
+25
@@ -23,6 +23,7 @@ static const char rev_list_usage[] =
23
" --no-merges\n"
24
" --remove-empty\n"
25
" --all\n"
26
+" --stdin\n"
27
" ordering output:\n"
28
" --topo-order\n"
29
" --date-order\n"
@@ -304,10 +305,28 @@ static void mark_edges_uninteresting(struct commit_list *list)
305
}
306
}
307
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
+
325
int cmd_rev_list(int argc, const char **argv, const char *prefix)
326
{
327
struct commit_list *list;
328
int i;
329
+ int read_from_stdin = 0;
330
331
init_revisions(&revs, prefix);
332
revs.abbrev = 0;
@@ -329,6 +348,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
348
bisect_list = 1;
349
continue;
350
}
351
+ if (!strcmp(arg, "--stdin")) {
352
+ if (read_from_stdin++)
353
+ die("--stdin given twice?");
354
+ read_revisions_from_stdin(&revs);
355
+ continue;
356
+ }
357
usage(rev_list_usage);
358
359
}