Skip to content

Commit 5d6a9f4

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Fix "git diff --stat" with long filenames
When we cut off the front of a filename to make it fit on the line, we add a "..." in front. However, the way the "git diff" code was written, we will never reset the prefix back to the empty string, so every single filename afterwards will have the "..." prefix, whether appropriate or not. You can see this with "git diff v2.6.16.." on the current kernel tree, since there are filenames with long names that changed there: [ snip snip ] Documentation/filesystems/vfs.txt | 229 .../firmware_class/firmware_sample_driver.c | 3 .../firmware_sample_firmware_class.c | 1 ...Documentation/fujitsu/frv/kernel-ABI.txt | 192 ...Documentation/hwmon/w83627hf | 4 [ snip snip ] notice how the two Documentation/firmware** filenames caused the "..." to be added, but then the later filenames don't want it, and it also screws up the alignment of the line numbering afterwards. Trivially fixed by moving the declaration (and initial setting) of the "prefix" variable into the for-loop where it is used. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f8ba655 commit 5d6a9f4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ static const char minuses[]= "--------------------------------------------------
239239

240240
static void show_stats(struct diffstat_t* data)
241241
{
242-
char *prefix = "";
243242
int i, len, add, del, total, adds = 0, dels = 0;
244243
int max, max_change = 0, max_len = 0;
245244
int total_files = data->nr;
@@ -261,6 +260,7 @@ static void show_stats(struct diffstat_t* data)
261260
}
262261

263262
for (i = 0; i < data->nr; i++) {
263+
char *prefix = "";
264264
char *name = data->files[i]->name;
265265
int added = data->files[i]->added;
266266
int deleted = data->files[i]->deleted;

0 commit comments

Comments
 (0)