Re: [PATCH v3] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.
- From
Yoshioka Tsuneo <yoshiokatsuneo@gmail.com>
- Date
- Oct 15, 2013, 09:46 UTC
- Message-ID
- <09553ADF-AE8C-460C-AC7B-1B4C26F6F6B2@gmail.com>
- 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:
Show 103 quoted lines
> 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