git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.
@ 2013-10-11 11:24 Yoshioka Tsuneo
  2013-10-11 13:07 ` [PATCH v2] " Yoshioka Tsuneo
  0 siblings, 1 reply; 31+ messages in thread
From: Yoshioka Tsuneo @ 2013-10-11 11:24 UTC (permalink / raw)
  To: git@vger.kernel.org

"git diff -M --stat" can detect rename and show renamed file name like
"foofoofoo => barbarbar", but if destination filename is long the line
is shortened like "...barbarbar" so there is no way to know whether the
file is renamed or existed in the source commit.
This commit makes it visible like "...foo => ...bar".

Signed-off-by: Tsuneo Yoshioka <yoshiokatsuneo@gmail.com>
---
 diff.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 7 deletions(-)

diff --git a/diff.c b/diff.c
index a04a34d..9b55546 100644
--- a/diff.c
+++ b/diff.c
@@ -1643,13 +1643,53 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 		len = name_width;
 		name_len = strlen(name);
 		if (name_width < name_len) {
-			char *slash;
-			prefix = "...";
-			len -= 3;
-			name += name_len - len;
-			slash = strchr(name, '/');
-			if (slash)
-				name = slash;
+			char *arrow = strstr(name, " => ");
+			if(arrow){
+				int prefix_len = (name_width- 4) / 2;
+				int f_omit;
+				char *pre_arrow = alloca(name_width + 10);
+				char *post_arrow = arrow + 4;
+				char *prefix_buf = alloca(name_width + 10);
+				char *pre_arrow_slash = NULL;
+
+				if(arrow - name < prefix_len){
+					prefix_len = (int)(arrow - name);
+					f_omit = 0;
+				}else{
+					prefix_len -= 3;
+					f_omit = 1;
+				}
+				strncpy(pre_arrow, arrow - prefix_len, prefix_len);
+				pre_arrow[prefix_len] = '¥0';
+				pre_arrow_slash = strchr(pre_arrow, '/');
+				if(f_omit && pre_arrow_slash){
+					pre_arrow = pre_arrow_slash;
+				}
+				sprintf(prefix_buf, "%s%s => ", (f_omit ? "..." : ""), pre_arrow);
+				prefix = prefix_buf;
+
+				if(strlen(post_arrow) > name_width - strlen(prefix)){
+					char *post_arrow_slash = NULL;
+
+					post_arrow += strlen(post_arrow) - (name_width - strlen(prefix) - 3);
+					strcat(prefix_buf, "...");
+					post_arrow_slash = strchr(post_arrow, '/');
+					if(post_arrow_slash){
+						post_arrow = post_arrow_slash;
+					}
+					name = post_arrow;
+					name_len = (int) (name_width - strlen(prefix));
+				}
+				len -= strlen(prefix);
+			}else{
+				char *slash = NULL;
+				prefix = "...";
+				len -= 3;
+				name += name_len - len;
+				slash = strchr(name, '/');
+				if (slash)
+					name = slash;
+			}
 		}
 
 		if (file->is_binary) {
-- 
1.8.4.475.g867697c

^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2013-10-22 20:26 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-11 11:24 [PATCH] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible Yoshioka Tsuneo
2013-10-11 13:07 ` [PATCH v2] " Yoshioka Tsuneo
2013-10-11 18:19   ` [spf:guess,mismatch] " Sam Vilain
2013-10-12  5:35     ` Keshav Kini
2013-10-12 20:52       ` Yoshioka Tsuneo
2013-10-12 20:48   ` [PATCH v3] " Yoshioka Tsuneo
2013-10-13 20:29     ` Thomas Rast
2013-10-15  9:46       ` Yoshioka Tsuneo
2013-10-14 19:04     ` Duy Nguyen
2013-10-15  9:46       ` Yoshioka Tsuneo
2013-10-15  9:45     ` [PATCH v4] " Yoshioka Tsuneo
2013-10-15 10:07       ` Felipe Contreras
2013-10-15 10:24         ` Yoshioka Tsuneo
2013-10-15 10:24       ` [PATCH v5] " Yoshioka Tsuneo
2013-10-15 22:54         ` Junio C Hamano
2013-10-15 22:58           ` Keshav Kini
2013-10-16  9:53           ` Yoshioka Tsuneo
2013-10-16  9:53         ` [PATCH v6] " Yoshioka Tsuneo
2013-10-17 19:29           ` Junio C Hamano
2013-10-17 22:08             ` Yoshioka Tsuneo
2013-10-17 22:38               ` Junio C Hamano
2013-10-18  9:35                 ` Yoshioka Tsuneo
2013-10-17 19:53           ` Junio C Hamano
2013-10-17 22:08           ` [PATCH v7] " Yoshioka Tsuneo
2013-10-18  9:35             ` [PATCH v8] " Yoshioka Tsuneo
2013-10-19  6:24               ` Thomas Rast
2013-10-20  1:49                 ` Yoshioka Tsuneo
2013-10-22 18:09                   ` Junio C Hamano
2013-10-22 20:14                     ` Yoshioka Tsuneo
2013-10-22 20:26                       ` Junio C Hamano
2013-10-12 20:48   ` [PATCH v3] " Yoshioka Tsuneo

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).