{"thread":{"id":"1360","subject":"[PATCH] Make git-apply --stat less butt-ugly with long filenames","startedAt":"2005-07-29T03:37:23Z","lastAt":"2005-07-29T03:37:23Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6545","messageId":"Pine.LNX.4.58.0507282031180.3307@g5.osdl.org","threadId":"1360","inReplyTo":null,"subject":"[PATCH] Make git-apply --stat less butt-ugly with long filenames","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-07-29T03:37:23Z","receivedAt":"2005-07-29T03:37:23Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nWhen git-apply was printing out long filenames, it used to just truncate\nthem to show the last \"max_len\" characters of the filename. Which can be\nreally quite ugly (note the two filenames that have just been silently \ntruncated from the beginning - it looks even worse when there are lots \nof them, like there were in the current v2.6.13-rc4 cris arch update):\n\n Documentation/video4linux/README.saa7134           |    9\n Documentation/video4linux/bttv/Cards               |   74\n umentation/video4linux/hauppauge-wintv-cx88-ir.txt |   54\n Documentation/video4linux/lifeview.txt             |   42\n mentation/video4linux/not-in-cx2388x-datasheet.txt |   41\n Documentation/w1/w1.generic                        |  107\n\nWith this patch it now looks like so:\n\n Documentation/video4linux/README.saa7134           |    9\n Documentation/video4linux/bttv/Cards               |   74\n .../video4linux/hauppauge-wintv-cx88-ir.txt        |   54\n Documentation/video4linux/lifeview.txt             |   42\n .../video4linux/not-in-cx2388x-datasheet.txt       |   41\n Documentation/w1/w1.generic                        |  107\n\nie we've made it clear with an ellipsis that we've cut off something from \nthe beginning, and it also tries to do it cleanly at a subdirectory level.\n\nSigned-off-by: Linus \"good taste\" Torvalds <torvalds@osdl.org>\n---\ndiff --git a/apply.c b/apply.c\n--- a/apply.c\n+++ b/apply.c\n@@ -737,6 +737,7 @@ static const char minuses[]= \"----------\n \n static void show_stats(struct patch *patch)\n {\n+\tconst char *prefix = \"\";\n \tchar *name = patch->new_name;\n \tint len, max, add, del, total;\n \n@@ -750,8 +751,15 @@ static void show_stats(struct patch *pat\n \tmax = max_len;\n \tif (max > 50)\n \t\tmax = 50;\n-\tif (len > max)\n+\tif (len > max) {\n+\t\tchar *slash;\n+\t\tprefix = \"...\";\n+\t\tmax -= 3;\n \t\tname += len - max;\n+\t\tslash = strchr(name, '/');\n+\t\tif (slash)\n+\t\t\tname = slash;\n+\t}\n \tlen = max;\n \n \t/*\n@@ -770,7 +778,7 @@ static void show_stats(struct patch *pat\n \t\tadd = (add * max + max_change / 2) / max_change;\n \t\tdel = total - add;\n \t}\n-\tprintf(\" %-*s |%5d %.*s%.*s\\n\",\n+\tprintf(\" %s%-*s |%5d %.*s%.*s\\n\", prefix,\n \t\tlen, name, patch->lines_added + patch->lines_deleted,\n \t\tadd, pluses, del, minuses);\n }\n"}]}