479
return prepare_revision_walk(rev);
480
}
481
482
-static void print_submodule_summary(struct rev_info *rev, FILE *f,
483
- const char *line_prefix,
484
- const char *del, const char *add, const char *reset)
482
+static void print_submodule_summary(struct rev_info *rev, struct diff_options *o)
483
{
484
static const char format[] = " %m %s";
485
struct strbuf sb = STRBUF_INIT;
490
ctx.date_mode = rev->date_mode;
491
ctx.output_encoding = get_log_output_encoding();
492
strbuf_setlen(&sb, 0);
495
- strbuf_addstr(&sb, line_prefix);
496
- if (commit->object.flags & SYMMETRIC_LEFT) {
497
- if (del)
498
- strbuf_addstr(&sb, del);
499
- }
500
- else if (add)
501
- strbuf_addstr(&sb, add);
493
format_commit_message(commit, format, &sb, &ctx);
503
- if (reset)
504
- strbuf_addstr(&sb, reset);
494
strbuf_addch(&sb, '\n');
506
- fprintf(f, "%s", sb.buf);
495
+ if (commit->object.flags & SYMMETRIC_LEFT)
496
+ diff_emit_submodule_del(o, sb.buf);
497
+ else
498
+ diff_emit_submodule_add(o, sb.buf);
499
}
500
strbuf_release(&sb);
501
}
522
* attempt to lookup both the left and right commits and put them into the
523
* left and right pointers.
524
*/
533
-static void show_submodule_header(FILE *f, const char *path,
534
- const char *line_prefix,
525
+static void show_submodule_header(struct diff_options *o, const char *path,
526
struct object_id *one, struct object_id *two,
536
- unsigned dirty_submodule, const char *meta,
537
- const char *reset,
527
+ unsigned dirty_submodule,
528
struct commit **left, struct commit **right,
529
struct commit_list **merge_bases)
530
{
533
int fast_forward = 0, fast_backward = 0;
534
535
if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
546
- fprintf(f, "%sSubmodule %s contains untracked content\n",
547
- line_prefix, path);
536
+ diff_emit_submodule_untracked(o, path);
537
+
538
if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
549
- fprintf(f, "%sSubmodule %s contains modified content\n",
550
- line_prefix, path);
539
+ diff_emit_submodule_modified(o, path);
540
541
if (is_null_oid(one))
542
message = "(new submodule)";
578
}
579
580
output_header:
592
- strbuf_addf(&sb, "%s%sSubmodule %s ", line_prefix, meta, path);
581
+ strbuf_addf(&sb, "Submodule %s ", path);
582
strbuf_add_unique_abbrev(&sb, one->hash, DEFAULT_ABBREV);
583
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
584
strbuf_add_unique_abbrev(&sb, two->hash, DEFAULT_ABBREV);
585
if (message)
597
- strbuf_addf(&sb, " %s%s\n", message, reset);
586
+ strbuf_addf(&sb, " %s\n", message);
587
else
599
- strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
600
- fwrite(sb.buf, sb.len, 1, f);
588
+ strbuf_addf(&sb, "%s:\n", fast_backward ? " (rewind)" : "");
589
+ diff_emit_submodule_header(o, sb.buf);
590
591
strbuf_release(&sb);
592
}
593
605
-void show_submodule_summary(FILE *f, const char *path,
606
- const char *line_prefix,
594
+void show_submodule_summary(struct diff_options *o, const char *path,
595
struct object_id *one, struct object_id *two,
608
- unsigned dirty_submodule, const char *meta,
609
- const char *del, const char *add, const char *reset)
596
+ unsigned dirty_submodule)
597
{
598
struct rev_info rev;
599
struct commit *left = NULL, *right = NULL;
600
struct commit_list *merge_bases = NULL;
601
615
- show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
616
- meta, reset, &left, &right, &merge_bases);
602
+ show_submodule_header(o, path, one, two, dirty_submodule,
603
+ &left, &right, &merge_bases);
604
605
/*
606
* If we don't have both a left and a right pointer, there is no
612
613
/* Treat revision walker failure the same as missing commits */
614
if (prepare_submodule_summary(&rev, path, left, right, merge_bases)) {
628
- fprintf(f, "%s(revision walker failed)\n", line_prefix);
615
+ diff_emit_submodule_error(o, "(revision walker failed)\n");
616
goto out;
617
}
618
632
- print_submodule_summary(&rev, f, line_prefix, del, add, reset);
619
+ print_submodule_summary(&rev, o);
620
621
out:
622
if (merge_bases)
625
clear_commit_marks(right, ~0);
626
}
627
641
-void show_submodule_inline_diff(FILE *f, const char *path,
642
- const char *line_prefix,
628
+void show_submodule_inline_diff(struct diff_options *o, const char *path,
629
struct object_id *one, struct object_id *two,
644
- unsigned dirty_submodule, const char *meta,
645
- const char *del, const char *add, const char *reset,
646
- const struct diff_options *o)
630
+ unsigned dirty_submodule)
631
{
632
const struct object_id *old = &empty_tree_oid, *new = &empty_tree_oid;
633
struct commit *left = NULL, *right = NULL;
634
struct commit_list *merge_bases = NULL;
651
- struct strbuf submodule_dir = STRBUF_INIT;
635
struct child_process cp = CHILD_PROCESS_INIT;
636
+ struct strbuf sb = STRBUF_INIT;
637
654
- show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
655
- meta, reset, &left, &right, &merge_bases);
638
+ show_submodule_header(o, path, one, two, dirty_submodule,
639
+ &left, &right, &merge_bases);
640
641
/* We need a valid left and right commit to display a difference */
642
if (!(left || is_null_oid(one)) ||
648
if (right)
649
new = two;
650
667
- fflush(f);
651
cp.git_cmd = 1;
652
cp.dir = path;
670
- cp.out = dup(fileno(f));
653
+ cp.out = -1;
654
cp.no_stdin = 1;
655
656
/* TODO: other options may need to be passed here. */
657
argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL);
658
+ argv_array_pushf(&cp.args, "--color=%s", want_color(o->use_color) ?
659
+ "always" : "never");
660
676
- argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
661
if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
662
argv_array_pushf(&cp.args, "--src-prefix=%s%s/",
663
o->b_prefix, path);
680
argv_array_push(&cp.args, oid_to_hex(new));
681
682
prepare_submodule_repo_env(&cp.env_array);
699
- if (run_command(&cp))
700
- fprintf(f, "(diff failed)\n");
683
+ if (start_command(&cp))
684
+ diff_emit_submodule_error(o, "(diff failed)\n");
685
+
686
+ while (strbuf_getwholeline_fd(&sb, cp.out, '\n') != EOF)
687
+ diff_emit_submodule_pipethrough(o, sb.buf, sb.len);
688
+
689
+ if (finish_command(&cp))
690
+ diff_emit_submodule_error(o, "(diff failed)\n");
691
692
done:
703
- strbuf_release(&submodule_dir);
693
+ strbuf_release(&sb);
694
if (merge_bases)
695
free_commit_list(merge_bases);
696
if (left)