git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/6 v2] Make git log --graph looks better with -p and other diff options

From
Jeff King <peff@peff.net>
Date
May 20, 2010, 13:24 UTC
Message-ID
<20100520132425.GA5504@coredump.intra.peff.net>
In-Reply-To
<20100520123650.GA7665@sigill.intra.peff.net>
On Thu, May 20, 2010 at 08:36:50AM -0400, Jeff King wrote:
>   git log --graph --oneline --summary 212f0ba
> 
> Summary lines for some reason don't get properly indented or prefixed
> with branch lines.

This is my naive attempt at fixing it just by copying your other changes. However, it seems to sometimes put several copies of the prefix in front of summary lines (and sometimes the next commit line!?). So clearly there is something about the output prefix code that I don't quite understand.

Maybe this is helpful, and maybe not. :)
diff --git a/diff.c b/diff.c
index 3a1e05a..656f40b 100644
--- a/diff.c
+++ b/diff.c
@@ -3460,27 +3460,41 @@ static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_fil
 	show_mode_change(file, p, 0);
 }
 
-static void diff_summary(FILE *file, struct diff_filepair *p)
+static void diff_summary(struct diff_options *opt, struct diff_filepair *p)
 {
+	FILE *file = opt->file;
+	char *line_prefix = "";
+
+	if (opt->output_prefix) {
+		struct strbuf *buf = opt->output_prefix(file, opt->output_prefix_data);
+		line_prefix = buf->buf;
+	}
+
 	switch(p->status) {
 	case DIFF_STATUS_DELETED:
+		fputs(line_prefix, file);
 		show_file_mode_name(file, "delete", p->one);
 		break;
 	case DIFF_STATUS_ADDED:
+		fputs(line_prefix, file);
 		show_file_mode_name(file, "create", p->two);
 		break;
 	case DIFF_STATUS_COPIED:
+		fputs(line_prefix, file);
 		show_rename_copy(file, "copy", p);
 		break;
 	case DIFF_STATUS_RENAMED:
+		fputs(line_prefix, file);
 		show_rename_copy(file, "rename", p);
 		break;
 	default:
 		if (p->score) {
+			fputs(line_prefix, file);
 			fputs(" rewrite ", file);
 			write_name_quoted(p->two->path, file, ' ');
 			fprintf(file, "(%d%%)\n", similarity_index(p));
 		}
+		fputs(line_prefix, file);
 		show_mode_change(file, p, !p->score);
 		break;
 	}
@@ -3692,7 +3706,7 @@ void diff_flush(struct diff_options *options)
 
 	if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
 		for (i = 0; i < q->nr; i++)
-			diff_summary(options->file, q->queue[i]);
+			diff_summary(options, q->queue[i]);
 		separator++;
 	}
 
Previous: Jeff KingNext: Bo Yang
Message 9 of 10 in “Make git log --graph looks better with -p and other diff options”
  1. 0/6 Make git log --graph looks better with -p and other diff optionsBo Yang, May 20, 2010
  2. 1/6 Add a prefix output callback to diff output.Bo Yang, May 20, 2010
  3. 2/6 Output the graph columns at the end of the commit message.Bo Yang, May 20, 2010
  4. 3/6 diff.c: Output the text graph padding before each diff line.Bo Yang, May 20, 2010
  5. 4/6 Emit a whole line once a time.Bo Yang, May 20, 2010
  6. 5/6 Register a callback for graph output.Bo Yang, May 20, 2010
  7. 6/6 Make --color-words work well with --graph.Bo Yang, May 20, 2010
  8. Jeff KingMay 20, 2010
  9. Jeff KingMay 20, 2010
  10. Bo YangMay 21, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.