From d8b8217c8a16944dc61a1553464efabc450a6680 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Tue, 29 Oct 2019 08:09:14 -0400 Subject: pretty: add "%aL" etc. to show local-part of email addresses In many projects the number of contributors is low enough that users know each other and the full email address doesn't need to be displayed. Displaying only the author's username saves a lot of columns on the screen. Existing 'e/E' (as in "%ae" and "%aE") placeholders would show the author's address as "prarit@redhat.com", which would waste columns to show the same domain-part for all contributors when used in a project internal to redhat. Introduce 'l/L' placeholders that strip '@' and domain part from the e-mail address. Signed-off-by: Prarit Bhargava Signed-off-by: Junio C Hamano --- pretty.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index b32f036953..93eb6e8370 100644 --- a/pretty.c +++ b/pretty.c @@ -696,7 +696,7 @@ static size_t format_person_part(struct strbuf *sb, char part, mail = s.mail_begin; maillen = s.mail_end - s.mail_begin; - if (part == 'N' || part == 'E') /* mailmap lookup */ + if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */ mailmap_name(&mail, &maillen, &name, &namelen); if (part == 'n' || part == 'N') { /* name */ strbuf_add(sb, name, namelen); @@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part, strbuf_add(sb, mail, maillen); return placeholder_len; } + if (part == 'l' || part == 'L') { /* local-part */ + const char *at = memchr(mail, '@', maillen); + if (at) + maillen = at - mail; + strbuf_add(sb, mail, maillen); + return placeholder_len; + } if (!s.date_begin) goto skip; -- cgit v1.2.3 From 3e8ed3b93e9b46eb6fe61589482751728865de57 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 19 Nov 2019 16:51:16 -0800 Subject: pretty.c: inline initalize format_context Instead of memsetting and then initializing the fields in the struct, move the initialization of `format_context` to its assignment. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- pretty.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index e4ed14effe..da154affd4 100644 --- a/pretty.c +++ b/pretty.c @@ -1612,14 +1612,14 @@ void repo_format_commit_message(struct repository *r, const char *format, struct strbuf *sb, const struct pretty_print_context *pretty_ctx) { - struct format_commit_context context; + struct format_commit_context context = { + .commit = commit, + .pretty_ctx = pretty_ctx, + .wrap_start = sb->len + }; const char *output_enc = pretty_ctx->output_encoding; const char *utf8 = "UTF-8"; - memset(&context, 0, sizeof(context)); - context.commit = commit; - context.pretty_ctx = pretty_ctx; - context.wrap_start = sb->len; /* * convert a commit message to UTF-8 first * as far as 'format_commit_item' assumes it in UTF-8 -- cgit v1.2.3 From 0df621172d830adf36d4226b98f9cf4006d183a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 19 Nov 2019 16:51:21 -0800 Subject: pretty: provide short date format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the placeholders %as and %cs to format author date and committer date, respectively, without the time part, like --date=short does, i.e. like YYYY-MM-DD. Signed-off-by: René Scharfe Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- pretty.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index da154affd4..61014cc25a 100644 --- a/pretty.c +++ b/pretty.c @@ -731,6 +731,9 @@ static size_t format_person_part(struct strbuf *sb, char part, case 'I': /* date, ISO 8601 strict */ strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(ISO8601_STRICT))); return placeholder_len; + case 's': + strbuf_addstr(sb, show_ident_date(&s, DATE_MODE(SHORT))); + return placeholder_len; } skip: -- cgit v1.2.3 From 618a855083fbd3b8f9491ec8b32b39bdea91868d Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 19 Nov 2019 16:51:23 -0800 Subject: pretty: add struct cmt_fmt_map::default_date_mode_type In a future commit, we plan on having a pretty format which will use a default date format unless otherwise overidden. Add support for this by adding a `default_date_mode_type` member in `struct cmt_fmt_map`. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- pretty.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index 61014cc25a..63fa600276 100644 --- a/pretty.c +++ b/pretty.c @@ -20,6 +20,7 @@ static struct cmt_fmt_map { int is_tformat; int expand_tabs_in_log; int is_alias; + enum date_mode_type default_date_mode_type; const char *user_format; } *commit_formats; static size_t builtin_formats_len; @@ -181,6 +182,8 @@ void get_commit_format(const char *arg, struct rev_info *rev) rev->commit_format = commit_format->format; rev->use_terminator = commit_format->is_tformat; rev->expand_tabs_in_log_default = commit_format->expand_tabs_in_log; + if (!rev->date_mode_explicit && commit_format->default_date_mode_type) + rev->date_mode.type = commit_format->default_date_mode_type; if (commit_format->format == CMIT_FMT_USERFORMAT) { save_user_format(rev, commit_format->user_format, commit_format->is_tformat); -- cgit v1.2.3 From 1f0fc1db8599f87520494ca4f0e3c1b6fabdf997 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 19 Nov 2019 16:51:25 -0800 Subject: pretty: implement 'reference' format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The standard format for referencing other commits within some projects (such as git.git) is the reference format. This is described in Documentation/SubmittingPatches as If you want to reference a previous commit in the history of a stable branch, use the format "abbreviated hash (subject, date)", like this: .... Commit f86a374 (pack-bitmap.c: fix a memleak, 2015-03-30) noticed that ... .... Since this format is so commonly used, standardize it as a pretty format. The tests that are implemented essentially show that the format-string does not change in response to various log options. This is useful because, for future developers, it shows that we've considered the limitations of the "canned format-string" approach and we are fine with them. Based-on-a-patch-by: SZEDER Gábor Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- pretty.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index 63fa600276..5fc8b730d8 100644 --- a/pretty.c +++ b/pretty.c @@ -98,7 +98,9 @@ static void setup_commit_formats(void) { "mboxrd", CMIT_FMT_MBOXRD, 0, 0 }, { "fuller", CMIT_FMT_FULLER, 0, 8 }, { "full", CMIT_FMT_FULL, 0, 8 }, - { "oneline", CMIT_FMT_ONELINE, 1, 0 } + { "oneline", CMIT_FMT_ONELINE, 1, 0 }, + { "reference", CMIT_FMT_USERFORMAT, 1, 0, + 0, DATE_SHORT, "%C(auto)%h (%s, %ad)" }, /* * Please update $__git_log_pretty_formats in * git-completion.bash when you add new formats. -- cgit v1.2.3