@matheusbsbs / matheus-bagliano / commits / 8b3dce5650
Fork 0

Teach --stdin option to "log" family

Move the logic to read revs from standard input that rev-list knows about from it to revision machinery, so that all the users of setup_revisions() can feed the list of revs from the standard input when "--stdin" is used on the command line. Allow some users of the revision machinery that want different semantics from the "--stdin" option to disable it by setting an option in the rev_info structure. This also cleans up the kludge made to bundle.c via cut and paste. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 3, 2009 at 06:59 UTC 8b3dce565084c89ceb19f7ccf0fe22ffd365f7fd
7 files changed +20 -22
Documentation/rev-list-options.txt
+1 -1
@@ -243,12 +243,12 @@ endif::git-rev-list[]
243 Pretend as if all the refs in `$GIT_DIR/refs/remotes` are listed
244 on the command line as '<commit>'.
245
246 -ifdef::git-rev-list[]
246 --stdin::
247
248 In addition to the '<commit>' listed on the command
249 line, read them from the standard input.
250
251 +ifdef::git-rev-list[]
252 --quiet::
253
254 Don't print anything to standard output. This form
builtin-blame.c
+1
@@ -2352,6 +2352,7 @@ parse_done:
2352 die_errno("cannot stat path '%s'", path);
2353 }
2354
2355 + revs.disable_stdin = 1;
2356 setup_revisions(argc, argv, &revs, NULL);
2357 memset(&sb, 0, sizeof(sb));
2358
builtin-diff-tree.c
+1
@@ -104,6 +104,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
104 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
105 opt->abbrev = 0;
106 opt->diff = 1;
107 + opt->disable_stdin = 1;
108 argc = setup_revisions(argc, argv, opt, NULL);
109
110 while (--argc > 0) {
builtin-rev-list.c
-7
@@ -306,7 +306,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
306 struct rev_info revs;
307 struct rev_list_info info;
308 int i;
309 - int read_from_stdin = 0;
309 int bisect_list = 0;
310 int bisect_show_vars = 0;
311 int bisect_find_all = 0;
@@ -349,12 +348,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
348 bisect_show_vars = 1;
349 continue;
350 }
352 - if (!strcmp(arg, "--stdin")) {
353 - if (read_from_stdin++)
354 - die("--stdin given twice?");
355 - read_revisions_from_stdin(&revs);
356 - continue;
357 - }
351 usage(rev_list_usage);
352
353 }
bundle.c
+2 -10
@@ -204,7 +204,6 @@ int create_bundle(struct bundle_header *header, const char *path,
204 int i, ref_count = 0;
205 char buffer[1024];
206 struct rev_info revs;
207 - int read_from_stdin = 0;
207 struct child_process rls;
208 FILE *rls_fout;
209
@@ -256,15 +255,8 @@ int create_bundle(struct bundle_header *header, const char *path,
255 /* write references */
256 argc = setup_revisions(argc, argv, &revs, NULL);
257
259 - for (i = 1; i < argc; i++) {
260 - if (!strcmp(argv[i], "--stdin")) {
261 - if (read_from_stdin++)
262 - die("--stdin given twice?");
263 - read_revisions_from_stdin(&revs);
264 - continue;
265 - }
266 - return error("unrecognized argument: %s'", argv[i]);
267 - }
258 + if (argc > 1)
259 + return error("unrecognized argument: %s'", argv[1]);
260
261 object_array_remove_duplicates(&revs.pending);
262
revision.c
+13 -2
@@ -953,7 +953,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
953 return 0;
954 }
955
956 -void read_revisions_from_stdin(struct rev_info *revs)
956 +static void read_revisions_from_stdin(struct rev_info *revs)
957 {
958 struct strbuf sb;
959
@@ -1229,7 +1229,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
1229 */
1230 int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
1231 {
1232 - int i, flags, left, seen_dashdash;
1232 + int i, flags, left, seen_dashdash, read_from_stdin;
1233
1234 /* First, search for "--" */
1235 seen_dashdash = 0;
@@ -1247,6 +1247,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1247
1248 /* Second, deal with arguments and options */
1249 flags = 0;
1250 + read_from_stdin = 0;
1251 for (left = i = 1; i < argc; i++) {
1252 const char *arg = argv[i];
1253 if (*arg == '-') {
@@ -1285,6 +1286,16 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1286 revs->no_walk = 0;
1287 continue;
1288 }
1289 + if (!strcmp(arg, "--stdin")) {
1290 + if (revs->disable_stdin) {
1291 + argv[left++] = arg;
1292 + continue;
1293 + }
1294 + if (read_from_stdin++)
1295 + die("--stdin given twice?");
1296 + read_revisions_from_stdin(revs);
1297 + continue;
1298 + }
1299
1300 opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv);
1301 if (opts > 0) {
revision.h
+2 -2
@@ -83,6 +83,8 @@ struct rev_info {
83 use_terminator:1,
84 missing_newline:1,
85 date_mode_explicit:1;
86 + unsigned int disable_stdin:1;
87 +
88 enum date_mode date_mode;
89
90 unsigned int abbrev;
@@ -128,8 +130,6 @@ struct rev_info {
130 #define REV_TREE_DIFFERENT 3 /* Mixed changes */
131
132 /* revision.c */
131 -void read_revisions_from_stdin(struct rev_info *revs);
132 -
133 typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
134 extern volatile show_early_output_fn_t show_early_output;
135