Re: [PATCH 2/5] pretty: allow formatting names as initials

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

 



Jeff King <peff@xxxxxxxx> writes:

> Initials are shorter and often unique enough in a
> per-project setting, so they can be used to give a more
> informative version of --oneline.
>
> The 'S' in the placeholder is for "short" (and 's' is
> already taken by DATE_SHORT), but obviously that's pretty
> arcane.
>
> Possibly there should be more customization of initials,
> asking for only 2-letter initials, etc.
>
> Signed-off-by: Jeff King <peff@xxxxxxxx>
> ---
> When I first tested it with "git log --format=%aS" I had to wonder "who
> the heck is ntnd?". So using only the first-and-last would match the git
> project's practice better, at least.

And there is also "isalpha() good enough?" question.

I think we have a few Chinese and Hangul as well as Cyrillic names
in our history, some of them having outside-ascii first letters.
One of the more prolific contributor's initial is ÆAB ;-)

>  pretty.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/pretty.c b/pretty.c
> index c532c17..de62405 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -674,6 +674,23 @@ static int mailmap_name(const char **email, size_t *email_len,
>  	return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
>  }
>  
> +static void format_initials(struct strbuf *out, const char *name, size_t len)
> +{
> +	int initial = 1;
> +	size_t i;
> +
> +	for (i = 0; i < len; i++) {
> +		char c = name[i];
> +		if (isspace(c)) {
> +			initial = 1;
> +			continue;
> +		}
> +		if (initial && isalpha(c))
> +			strbuf_addch(out, tolower(c));
> +		initial = 0;
> +	}
> +}
> +
>  static size_t format_person_part(struct strbuf *sb, char part,
>  				 const char *msg, int len,
>  				 const struct date_mode *dmode)
> @@ -702,6 +719,10 @@ static size_t format_person_part(struct strbuf *sb, char part,
>  		strbuf_add(sb, mail, maillen);
>  		return placeholder_len;
>  	}
> +	if (part == 'S') {
> +		format_initials(sb, name, namelen);
> +		return placeholder_len;
> +	}
>  
>  	if (!s.date_begin)
>  		goto skip;




[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]