402
int allow_unrelated_histories;
403
int show_messages;
404
int name_only;
405
+ int use_stdin;
406
};
407
408
static int real_merge(struct merge_tree_options *o,
413
struct commit_list *merge_bases = NULL;
414
struct merge_options opt;
415
struct merge_result result = { 0 };
416
+ int show_messages = o->show_messages;
417
418
parent1 = get_merge_parent(branch1);
419
if (!parent1)
445
if (result.clean < 0)
446
die(_("failure to merge"));
447
446
- if (o->show_messages == -1)
447
- o->show_messages = !result.clean;
448
+ if (show_messages == -1)
449
+ show_messages = !result.clean;
450
451
+ if (o->use_stdin)
452
+ printf("%d%c", result.clean, line_termination);
453
printf("%s%c", oid_to_hex(&result.tree->object.oid), line_termination);
454
if (!result.clean) {
455
struct string_list conflicted_files = STRING_LIST_INIT_NODUP;
471
}
472
string_list_clear(&conflicted_files, 1);
473
}
470
- if (o->show_messages) {
474
+ if (show_messages) {
475
putchar(line_termination);
476
merge_display_update_messages(&opt, line_termination == '\0',
477
&result);
478
}
479
+ if (o->use_stdin)
480
+ putchar(line_termination);
481
merge_finalize(&opt, &result);
482
return !result.clean; /* result.clean < 0 handled above */
483
}
511
&o.allow_unrelated_histories,
512
N_("allow merging unrelated histories"),
513
PARSE_OPT_NONEG),
514
+ OPT_BOOL_F(0, "stdin",
515
+ &o.use_stdin,
516
+ N_("perform multiple merges, one per line of input"),
517
+ PARSE_OPT_NONEG),
518
OPT_END()
519
};
520
522
original_argc = argc - 1; /* ignoring argv[0] */
523
argc = parse_options(argc, argv, prefix, mt_options,
524
merge_tree_usage, PARSE_OPT_STOP_AT_NON_OPTION);
525
+
526
+ /* Handle --stdin */
527
+ if (o.use_stdin) {
528
+ struct strbuf buf = STRBUF_INIT;
529
+
530
+ if (o.mode == MODE_TRIVIAL)
531
+ die(_("--trivial-merge is incompatible with all other options"));
532
+ line_termination = '\0';
533
+ while (strbuf_getline_lf(&buf, stdin) != EOF) {
534
+ struct strbuf **split;
535
+ int result;
536
+
537
+ split = strbuf_split(&buf, ' ');
538
+ if (!split[0] || !split[1] || split[2])
539
+ die(_("malformed input line: '%s'."), buf.buf);
540
+ strbuf_rtrim(split[0]);
541
+ result = real_merge(&o, split[0]->buf, split[1]->buf, prefix);
542
+ if (result < 0)
543
+ die(_("merging cannot continue; got unclean result of %d"), result);
544
+ strbuf_list_free(split);
545
+ }
546
+ strbuf_release(&buf);
547
+ return 0;
548
+ }
549
+
550
+ /* Figure out which mode to use */
551
switch (o.mode) {
552
default:
553
BUG("unexpected command mode %d", o.mode);