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

[PATCH 2/4] diff.c: split emit_line() from the first char and the rest of the line

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 15, 2009, 06:15 UTC
Message-ID
<1252995306-32329-3-git-send-email-gitster@pobox.com>
In-Reply-To
<1252995306-32329-1-git-send-email-gitster@pobox.com>

A new helper function emit_line_0() takes the first line of diff output (typically "-", " ", or "+") separately from the remainder of the line. No other functional changes.

This change will make it easier to reuse the logic when emitting the rewrite diff, as we do not want to copy a line only to add "+"/"-"/" " immediately before its first character when we produce rewrite diff output.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index 7548966..b5c2574 100644
--- a/diff.c
+++ b/diff.c
@@ -377,7 +377,8 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
 	ecbdata->blank_at_eof_in_postimage = (at - l2) + 1;
 }
 
-static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
+static void emit_line_0(FILE *file, const char *set, const char *reset,
+			int first, const char *line, int len)
 {
 	int has_trailing_newline, has_trailing_carriage_return;
 
@@ -389,6 +390,7 @@ static void emit_line(FILE *file, const char *set, const char *reset, const char
 		len--;
 
 	fputs(set, file);
+	fputc(first, file);
 	fwrite(line, len, 1, file);
 	fputs(reset, file);
 	if (has_trailing_carriage_return)
@@ -397,6 +399,12 @@ static void emit_line(FILE *file, const char *set, const char *reset, const char
 		fputc('\n', file);
 }
 
+static void emit_line(FILE *file, const char *set, const char *reset,
+		      const char *line, int len)
+{
+	emit_line_0(file, set, reset, line[0], line+1, len-1);
+}
+
 static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line, int len)
 {
 	if (!((ecbdata->ws_rule & WS_BLANK_AT_EOF) &&
-- 
1.6.5.rc1.54.g4aad
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 7 in “Colouring whitespace errors in diff -B output”
  1. 0/4 Colouring whitespace errors in diff -B outputJunio C Hamano, Sep 15, 2009
  2. 1/4 diff.c: shuffling code aroundJunio C Hamano, Sep 15, 2009
  3. 2/4 diff.c: split emit_line() from the first char and the rest of the lineJunio C Hamano, Sep 15, 2009
  4. 3/4 diff.c: emit_add_line() takes only the rest of the lineJunio C Hamano, Sep 15, 2009
  5. 4/4 diff -B: colour whitespace errorsJunio C Hamano, Sep 15, 2009
  6. Nanako ShiraishiSep 15, 2009
  7. Junio C HamanoSep 15, 2009

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.