diff: print line prefix for --name-only output

If you run "git log --graph --name-only", the pathnames are not indented to go along with their matching commits (unlike all of the other diff formats). We need to output the line prefix for each item before writing it. The tests cover both --name-status and --name-only. The former actually gets this right already, because it builds on the --raw format functions. It's only --name-only which uses its own code (and this fix mirrors the code in diff_flush_raw()). Note that the tests don't follow our usual style of setting up the "expect" output inside the test block. This matches the surrounding style, but more importantly it is easier to read: we don't have to worry about embedded single-quotes, and the leading indentation is more obvious. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 8, 2017 at 15:31 UTC f5022b5fedb405c6bbb0b3e7c5a3a7f507279ef5
2 files changed +49
diff.c
+1
@@ -4353,6 +4353,7 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
4353 name_a = p->two->path;
4354 name_b = NULL;
4355 strip_prefix(opt->prefix_length, &name_a, &name_b);
4356 + fprintf(opt->file, "%s", diff_line_prefix(opt));
4357 write_name_quoted(name_a, opt->file, opt->line_termination);
4358 }
4359 }
t/t4202-log.sh
+48
@@ -867,6 +867,54 @@ test_expect_success 'log --graph with diff and stats' '
867 test_i18ncmp expect actual.sanitized
868 '
869
870 +cat >expect <<-\EOF
871 +* reach
872 +|
873 +| A reach.t
874 +* Merge branch 'tangle'
875 +* Merge branch 'side'
876 +|\
877 +| * side-2
878 +|
879 +| A 2
880 +* Second
881 +|
882 +| A one
883 +* sixth
884 +
885 + D a/two
886 +EOF
887 +
888 +test_expect_success 'log --graph with --name-status' '
889 + git log --graph --format=%s --name-status tangle..reach >actual &&
890 + sanitize_output <actual >actual.sanitized &&
891 + test_cmp expect actual.sanitized
892 +'
893 +
894 +cat >expect <<-\EOF
895 +* reach
896 +|
897 +| reach.t
898 +* Merge branch 'tangle'
899 +* Merge branch 'side'
900 +|\
901 +| * side-2
902 +|
903 +| 2
904 +* Second
905 +|
906 +| one
907 +* sixth
908 +
909 + a/two
910 +EOF
911 +
912 +test_expect_success 'log --graph with --name-only' '
913 + git log --graph --format=%s --name-only tangle..reach >actual &&
914 + sanitize_output <actual >actual.sanitized &&
915 + test_cmp expect actual.sanitized
916 +'
917 +
918 test_expect_success 'dotdot is a parent directory' '
919 mkdir -p a/b &&
920 ( echo sixth && echo fifth ) >expect &&