Re: [PATCH v3] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 13, 2013 at 3:48 AM, Yoshioka Tsuneo
<yoshiokatsuneo@xxxxxxxxx> 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@xxxxxxxxx>
> ---
>  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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]