Re: [PATCH 2/5] pretty: allow formatting names as initials
On Thu, Sep 29, 2016 at 10:31:30AM -0700, Junio C Hamano wrote: > > 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 ;-) Heh, true. In case it was not clear, these were mostly quick-and-dirty patches. I think the right test is probably '!isspace()". -Peff
Re: [PATCH 2/5] pretty: allow formatting names as initials
Jeff King 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 > --- > 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;
[PATCH 2/5] pretty: allow formatting names as initials
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 --- 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. 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; -- 2.10.0.566.g5365f87