{"thread":{"id":"4104","subject":"Fix \"git diff --stat\" with long filenames","startedAt":"2006-05-08T16:46:53Z","lastAt":"2006-05-08T16:46:53Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"19718","messageId":"Pine.LNX.4.64.0605080942410.3718@g5.osdl.org","threadId":"4104","inReplyTo":null,"subject":"Fix \"git diff --stat\" with long filenames","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-05-08T16:46:53Z","receivedAt":"2006-05-08T16:46:53Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nWhen we cut off the front of a filename to make it fit on the line, we add \na \"...\" in front. However, the way the \"git diff\" code was written, we \nwill never reset the prefix back to the empty string, so every single \nfilename afterwards will have the \"...\" prefix, whether appropriate or \nnot.\n\nYou can see this with \"git diff v2.6.16..\" on the current kernel tree, \nsince there are filenames with long names that changed there:\n\n [ snip snip ]\n Documentation/filesystems/vfs.txt                  |  229 \n .../firmware_class/firmware_sample_driver.c        |    3 \n .../firmware_sample_firmware_class.c               |    1 \n ...Documentation/fujitsu/frv/kernel-ABI.txt           |  192 \n ...Documentation/hwmon/w83627hf                       |    4 \n [ snip snip ]\n\nnotice how the two Documentation/firmware** filenames caused the \"...\" to \nbe added, but then the later filenames don't want it, and it also screws \nup the alignment of the line numbering afterwards.\n\nTrivially fixed by moving the declaration (and initial setting) of the \n\"prefix\" variable into the for-loop where it is used.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/diff.c b/diff.c\nindex c845c87..5315270 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -296,7 +296,6 @@ static const char minuses[]= \"----------\n \n static void show_stats(struct diffstat_t* data)\n {\n-\tchar *prefix = \"\";\n \tint i, len, add, del, total, adds = 0, dels = 0;\n \tint max, max_change = 0, max_len = 0;\n \tint total_files = data->nr;\n@@ -318,6 +317,7 @@ static void show_stats(struct diffstat_t\n \t}\n \n \tfor (i = 0; i < data->nr; i++) {\n+\t\tchar *prefix = \"\";\n \t\tchar *name = data->files[i]->name;\n \t\tint added = data->files[i]->added;\n \t\tint deleted = data->files[i]->deleted;\n"}]}