From: Yoshioka Tsuneo <yoshiokatsuneo@gmail.com>
To: Duy Nguyen <pclouds@gmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH v3] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.
Date: Tue, 15 Oct 2013 12:46:11 +0300 [thread overview]
Message-ID: <09553ADF-AE8C-460C-AC7B-1B4C26F6F6B2@gmail.com> (raw)
In-Reply-To: <CACsJy8Cg5M8dHSMW+giwYB2016jZhryyxET0kxkLDX7xk=B47w@mail.gmail.com>
Hello Duy
Thank you very much your suggestion.
As you suggested, I tried to reuse intermediate result of pprint_rename(), instead of
parsing the output again.
I just posted the new patch as "PATCH v4"
Thanks !
---
Tsuneo Yoshioka (吉岡 恒夫)
yoshiokatsuneo@gmail.com
On Oct 14, 2013, at 10:04 PM, Duy Nguyen <pclouds@gmail.com> wrote:
> On Sun, Oct 13, 2013 at 3:48 AM, Yoshioka Tsuneo
> <yoshiokatsuneo@gmail.com> wrote:
>> "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 | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
>> 1 file changed, 51 insertions(+), 7 deletions(-)
>>
>> diff --git a/diff.c b/diff.c
>> index a04a34d..3aeaf3e 100644
>> --- a/diff.c
>> +++ b/diff.c
>> @@ -1643,13 +1643,57 @@ 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) {
>
> This looks iffy. What if " => " is part of the path name?
> file->is_renamed would be a more reliable sign. In that case I think
> you just need an ellipsis version of pprint_rename() (i.e. drop the
> result of previous pprint_rename() on the floor and create a new
> string with "..." and " => " in your pprint_ellipsis_rename or
> something)
>
>> + int prefix_len = (name_width - 4) / 2;
>> + int f_omit;
>> + int f_brace = 0;
>> + 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;
>> + if (name[0] == '{') {
>> + prefix_len -= 1;
>> + f_brace = 1;
>> + }
>> + }
>> + prefix_len = ((prefix_len >= 0) ? prefix_len : 0);
>> + 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%s => ", (f_brace ? "{" : ""), (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
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> Duy
next prev parent reply other threads:[~2013-10-15 9:47 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=09553ADF-AE8C-460C-AC7B-1B4C26F6F6B2@gmail.com \
--to=yoshiokatsuneo@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).