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

Re: question: how to ignore extral CR when diff dos format files with 'color=auto'

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 28, 2008, 02:47 UTC
Message-ID
<7v7ia1kg8s.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vbpzdkgy9.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> ...  I suspect
> that combined-diff output routines have the same issue that you need to
> fix the same way, but I didn't look.
Now I looked.  The combine-diff part should look like this, I think.
diff --git i/combine-diff.c w/combine-diff.c
index 534be38..de83c69 100644
--- i/combine-diff.c
+++ w/combine-diff.c
@@ -496,6 +496,18 @@ static int hunk_comment_line(const char *bol)
 	return (isalpha(ch) || ch == '_' || ch == '$');
 }
 
+static void show_line_to_eol(const char *line, int len, const char *reset)
+{
+	int saw_cr_at_eol = 0;
+	if (len < 0)
+		len = strlen(line);
+	saw_cr_at_eol = (len && line[len-1] == '\r');
+
+	printf("%.*s%s%s\n", len - saw_cr_at_eol, line,
+	       reset,
+	       saw_cr_at_eol ? "\r" : "");
+}
+
 static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 		       int use_color)
 {
@@ -589,7 +601,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 					else
 						putchar(' ');
 				}
-				printf("%s%s\n", ll->line, c_reset);
+				show_line_to_eol(ll->line, -1, c_reset);
 				ll = ll->next;
 			}
 			if (cnt < lno)
@@ -613,7 +625,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
 					putchar(' ');
 				p_mask <<= 1;
 			}
-			printf("%.*s%s\n", sl->len, sl->bol, c_reset);
+			show_line_to_eol(sl->bol, sl->len, c_reset);
 		}
 	}
 }
Previous: Junio C Hamano
Message 6 of 6 in “question: how to ignore extral CR when diff dos format files with 'color=auto'”
  1. goooguoAug 26, 2008
  2. goooguoAug 27, 2008
  3. Junio C HamanoAug 27, 2008
  4. goooguoAug 28, 2008
  5. Junio C HamanoAug 28, 2008
  6. Junio C HamanoAug 28, 2008

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.