threads / patch / 32179

patchdiff: Fixes shortstat number of files

Subject: [PATCH] diff: Fixes shortstat number of files

## tl;dr

One message between Nov 23, 2012 and Nov 23, 2012. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Antoine Pelisse· Nov 23, 2012, 21:27 UTC · lore

There is a discrepancy between the last line of `git diff --stat` and `git diff --shortstat` in case of a merge. The unmerged files are actually counted twice, thus doubling the value of "file changed".

In fact, while stat decrements number of files when seeing an unmerged file, shortstat doesn't.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
 diff.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Show changes to diff.c +2 −3
diff --git a/diff.c b/diff.c
index e89a201..5c6bcbd 100644
--- a/diff.c
+++ b/diff.c
@@ -1704,9 +1704,8 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
 		int added = data->files[i]->added;
 		int deleted= data->files[i]->deleted;
 
-		if (data->files[i]->is_unmerged)
-			continue;
-		if (!data->files[i]->is_renamed && (added + deleted == 0)) {
+		if (data->files[i]->is_unmerged ||
+		  (!data->files[i]->is_renamed && (added + deleted == 0))) {
 			total_files--;
 		} else if (!data->files[i]->is_binary) { /* don't count bytes */
 			adds += added;
-- 
1.7.9.5

← back to recent threads