Re: [RFC/PATCH 1/9] ref-filter: add %(refname:lalignX) option

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

 



On Thu, Jun 25, 2015 at 6:43 PM, Karthik Nayak <karthik.188@xxxxxxxxx> wrote:
> Add support for %(refname:lalignX) where X is a number.
> This will print a shortened refname aligned to the left
> followed by spaces for a total length of X characters.
> If X is less than the shortened refname size, the entire
> shortened refname is printed.
>
> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx>
> Mentored-by: Matthieu Moy <matthieu.moy@xxxxxxxxxxxxxxx>
> Signed-off-by: Karthik Nayak <karthik.188@xxxxxxxxx>
> ---
>  ref-filter.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 00d06bf..299b048 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -695,7 +695,22 @@ static void populate_value(struct ref_array_item *ref)
>                         int num_ours, num_theirs;
>
>                         formatp++;
> -                       if (!strcmp(formatp, "short"))
> +                       if (starts_with(formatp, "lalign")) {
> +                               const char *valp;
> +                               int val;
> +
> +                               skip_prefix(formatp, "lalign", &valp);
> +                               val = atoi(valp);
> +                               refname = shorten_unambiguous_ref(refname,
> +                                                                 warn_ambiguous_refs);
> +                               if (val > strlen(refname)) {
> +                                       struct strbuf buf = STRBUF_INIT;
> +                                       strbuf_addstr(&buf, refname);
> +                                       strbuf_addchars(&buf, ' ', val - strlen(refname));

We don't forbid non-ascii characters in refname so you probably want
to use utf8_width() here instead of strlen()

> +                                       free((char *)refname);
> +                                       refname = strbuf_detach(&buf, NULL);
> +                               }
> +                       } else if (!strcmp(formatp, "short"))
>                                 refname = shorten_unambiguous_ref(refname,
>                                                       warn_ambiguous_refs);
>                         else if (!strcmp(formatp, "track") &&
> --
> 2.4.4
>
> --
> 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]