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

[PATCH v2 4/5] avoid trailing whitespace in zero-change diffstat lines

From
Jeff King <peff@peff.net>
Date
Jun 14, 2008, 07:27 UTC
Message-ID
<20080614072745.GD17536@sigill.intra.peff.net>
In-Reply-To
<20080614072214.GA9975@sigill.intra.peff.net>

In some cases, we produce a diffstat line even though no lines have changed (e.g., because of an exact rename). In this case, there is no +/- "graph" after the number of changed lines. However, we output the space separator unconditionally, meaning that these lines contained a trailing space character.

This isn't a huge problem, but in cleaning up the output we are able to eliminate some trailing whitespace from a test vector.

Signed-off-by: Jeff King <peff@peff.net>
---
This is identical to the original 3/4.
 diff.c                |    3 ++-
 t/t4016-diff-quote.sh |   14 +++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/diff.c b/diff.c
index 62fdc54..f77f9e9 100644
--- a/diff.c
+++ b/diff.c
@@ -922,7 +922,8 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
 			total = add + del;
 		}
 		show_name(options->file, prefix, name, len, reset, set);
-		fprintf(options->file, "%5d ", added + deleted);
+		fprintf(options->file, "%5d%s", added + deleted,
+				added + deleted ? " " : "");
 		show_graph(options->file, '+', add, add_c, reset);
 		show_graph(options->file, '-', del, del_c, reset);
 		fprintf(options->file, "\n");
diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh
index 0950250..f07035a 100755
--- a/t/t4016-diff-quote.sh
+++ b/t/t4016-diff-quote.sh
@@ -53,13 +53,13 @@ test_expect_success 'git diff --summary -M HEAD' '
 '
 
 cat >expect <<\EOF
- pathname.1 => "Rpathname\twith HT.0"            |    0 
- pathname.3 => "Rpathname\nwith LF.0"            |    0 
- "pathname\twith HT.3" => "Rpathname\nwith LF.1" |    0 
- pathname.2 => Rpathname with SP.0               |    0 
- "pathname\twith HT.2" => Rpathname with SP.1    |    0 
- pathname.0 => Rpathname.0                       |    0 
- "pathname\twith HT.0" => Rpathname.1            |    0 
+ pathname.1 => "Rpathname\twith HT.0"            |    0
+ pathname.3 => "Rpathname\nwith LF.0"            |    0
+ "pathname\twith HT.3" => "Rpathname\nwith LF.1" |    0
+ pathname.2 => Rpathname with SP.0               |    0
+ "pathname\twith HT.2" => Rpathname with SP.1    |    0
+ pathname.0 => Rpathname.0                       |    0
+ "pathname\twith HT.0" => Rpathname.1            |    0
  7 files changed, 0 insertions(+), 0 deletions(-)
 EOF
 test_expect_success 'git diff --stat -M HEAD' '
-- 
1.5.6.rc2.183.g04614
Previous: Jeff KingNext: Jeff King
Message 13 of 19 in “t/.gitattributes: only ignore whitespace errors in test files”
  1. t/.gitattributes: only ignore whitespace errors in test filesLea Wiemann, Jun 12, 2008
  2. Jeff KingJun 13, 2008
  3. t/.gitattributes: only ignore whitespace errors in test filesLea Wiemann, Jun 13, 2008
  4. Junio C HamanoJun 13, 2008
  5. Jeff KingJun 14, 2008
  6. 1/4 fix whitespace violations in test scriptsJeff King, Jun 14, 2008
  7. Jeff KingJun 14, 2008
  8. Junio C HamanoJun 14, 2008
  9. Jeff KingJun 14, 2008
  10. 1/5 fix whitespace violations in test scriptsJeff King, Jun 14, 2008
  11. 2/5 mask necessary whitespace policy violations in test scriptsJeff King, Jun 14, 2008
  12. 3/5 avoid whitespace on empty line in automatic usage messageJeff King, Jun 14, 2008
  13. 4/5 avoid trailing whitespace in zero-change diffstat linesJeff King, Jun 14, 2008
  14. 5/5 enable whitespace checking of test scriptsJeff King, Jun 14, 2008
  15. 2/4 mask necessary whitespace policy violations in test scriptsJeff King, Jun 14, 2008
  16. 3/4 avoid trailing whitespace in zero-change diffstat linesJeff King, Jun 14, 2008
  17. Junio C HamanoJun 14, 2008
  18. Jeff KingJun 14, 2008
  19. 4/4 enable whitespace checking of test scriptsJeff King, Jun 14, 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.