From patchwork Sat Jul 15 16:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13314573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1314C001B0 for ; Sat, 15 Jul 2023 16:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbjGOQHu (ORCPT ); Sat, 15 Jul 2023 12:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjGOQHs (ORCPT ); Sat, 15 Jul 2023 12:07:48 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9276D2D51 for ; Sat, 15 Jul 2023 09:07:46 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-992acf67388so379454166b.1 for ; Sat, 15 Jul 2023 09:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689437265; x=1692029265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vk2KqKEW9sbhSYz7GpJZM4lmutNfIf4SmEpOAgqqBqs=; b=UgmT/UlkSsF5JEeJhOI3aUhwMiO9vgTXtNYlEe43Jsv8M1DRv2hx/hiR8y/oZoe4dl b0OpYNZqEkoWX0r0zQxABqdGpKvdznN9QwhvTpvdqdlukCF3E0UZmmwU7MitkDTpswfQ 4BMlGd3ld7I6cWlIG3/z97q8PK3LXIykK8SNsz2Z+0z0jEuvdivW9WninV51qaypwJ1R 2DWMMdONxjX5FOER/dc+QYy9t34IrwPRFINOdpDI4ot7EWnO/WXHSL2pra0sy0fKUkIt 4JTM0BYUSxbywpSLeZ8KVz8VHUqcg8itHQSnZNH02Jo+LroYcPQP1gZNLkkFlTfIWO8R K5Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689437265; x=1692029265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vk2KqKEW9sbhSYz7GpJZM4lmutNfIf4SmEpOAgqqBqs=; b=P8C/R8yo59thyI7txH6Ed2U2F1XykdZ9FgZap60IyArKcmAc8F4m+w2+dJdQpOUOKe C4XhyH3s8fdtZp3BYA63l4Fm0TEQtbKJGcA+1cu+P6E/lheasZPIiloVBX1XU4eXK+Ud LUJzFVdeULKRBnwt578itb4LsORq3E6TczW8C1fNu4OERwPM6pf1Ktbzsq/y6qbextpz /gb1vpXaSrE6+pOCnwyuFmBMt1Lg988M6UxLIk8CyAuLQHEQN2ijSg5cqj0Pb/vz56S5 hmwSPDluYbDgxhHCTMc3BJLyhs2Ko3o87c9pTOupkZ0KF/10TlzDSzG6eFFm8R3behfs hbrg== X-Gm-Message-State: ABy/qLZucbsWzqJsde5NuJZWzMQztg9Y8iZagQKnW2UJIIlvBA1c3Q9t qn4+uvjn6KKuiysezDC7IfLgmMfibfM= X-Google-Smtp-Source: APBJJlG+LJGWkNYrdmIkWLqSYwcQwR6b6cSzT2d4KJjrjFJR1/6JjzeMyuNkdOPLL3TZ+aUvEar1Tw== X-Received: by 2002:a17:906:314c:b0:957:1df0:9cbf with SMTP id e12-20020a170906314c00b009571df09cbfmr5552247eje.19.1689437264679; Sat, 15 Jul 2023 09:07:44 -0700 (PDT) Received: from localhost.localdomain (host-92-6-81-118.as13285.net. [92.6.81.118]) by smtp.gmail.com with ESMTPSA id z2-20020a1709063ac200b009944e955e19sm2266851ejd.30.2023.07.15.09.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 09:07:44 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v2] pretty: add %(decorate[:]) format Date: Sat, 15 Jul 2023 17:07:29 +0100 Message-ID: <20230715160730.4046-1-andy.koppe@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230715103758.3862-1-andy.koppe@gmail.com> References: <20230715103758.3862-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This lists ref names in the same way as the %d decoration format, but allows all the otherwise fixed strings printed around the ref names to be customized, namely prefix, suffix, separator, the "tag:" annotation and the arrow used to show where HEAD points. Examples: - %(decorate) is equivalent to %d. - %(decorate:prefix=,suffix=) is equivalent to %D. - %(decorate:prefix=,suffix=,separator= ,tag=,arrow=->) produces a space-separated list without wrapping, tag annotations or spaces around the arrow. - %(decorate:prefix=[,suffix=],separator=%x2C,arrow=%x2C,tag=) produces a comma-separated list enclosed in square brackets where the arrow is replaced by a comma as well. Add functions parse_decoration_option(), parse_decoration_options() and free_decoration_options() to help implement the format. Test it in t4205-log-pretty-formats.sh and document it in pretty-formats.txt. Refactor format_decorations() to take a struct decoration_options argument specifying those strings, whereby NULL entries select the default. Avoid emitting color sequences for empty strings. Wrap tag annotations in separate color sequences from tag names, because otherwise tag names can end up uncolored when %w width formatting breaks lines between annotation and name. Amend t4207-log-decoration-colors.sh accordingly. Signed-off-by: Andy Koppe Signed-off-by: Junio C Hamano --- Corrected mistakes in commit description. Documentation/pretty-formats.txt | 19 ++++++++- log-tree.c | 69 ++++++++++++++++++++------------ log-tree.h | 17 ++++---- pretty.c | 62 +++++++++++++++++++++++++++- t/t4205-log-pretty-formats.sh | 21 ++++++++++ t/t4207-log-decoration-colors.sh | 32 +++++++++------ 6 files changed, 171 insertions(+), 49 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 3b71334459..c08aba15af 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -222,7 +222,22 @@ The placeholders are: linkgit:git-rev-list[1]) '%d':: ref names, like the --decorate option of linkgit:git-log[1] '%D':: ref names without the " (", ")" wrapping. -'%(describe[:options])':: human-readable name, like +'%(decorate[:])':: ref names with custom decorations. + The `decorate` string may be followed by a colon + and zero or more comma-separated options. + Option values may contain literal formatting codes. + These must be used for commas (`%x2C`) and closing + parentheses (`%x29`), due to their role in the option + syntax. ++ +** 'prefix=': Shown before the list of ref names. Defaults to " (". +** 'suffix=': Shown after the list of ref names. Defaults to ")". +** 'separator=': Shown between ref names. Defaults to ", ". +** 'arrow=': Shown between HEAD and the branch it points to, if any. + Defaults to " \-> ". +** 'tag=': Shown before tag names. Defaults to "tag: ". + +'%(describe[:])':: human-readable name, like linkgit:git-describe[1]; empty string for undescribable commits. The `describe` string may be followed by a colon and zero or more @@ -281,7 +296,7 @@ endif::git-rev-list[] '%gE':: reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%gs':: reflog subject -'%(trailers[:options])':: display the trailers of the body as +'%(trailers[:])':: display the trailers of the body as interpreted by linkgit:git-interpret-trailers[1]. The `trailers` string may be followed by a colon diff --git a/log-tree.c b/log-tree.c index f4b22a60cc..4b46884ef6 100644 --- a/log-tree.c +++ b/log-tree.c @@ -301,27 +301,34 @@ static void show_name(struct strbuf *sb, const struct name_decoration *decoratio /* * The caller makes sure there is no funny color before calling. - * format_decorations_extended makes sure the same after return. + * format_decorations ensures the same after return. */ -void format_decorations_extended(struct strbuf *sb, +void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color, - const char *prefix, - const char *separator, - const char *suffix) + const struct decoration_options *opts) { - const struct name_decoration *decoration; - const struct name_decoration *current_and_HEAD; - const char *color_commit = - diff_get_color(use_color, DIFF_COMMIT); - const char *color_reset = - decorate_get_color(use_color, DECORATION_NONE); + const char *color_commit, *color_reset; + const char *prefix, *suffix, *separator, *arrow, *tag; + + const struct name_decoration *current_and_HEAD; + const struct name_decoration *decoration = + get_name_decoration(&commit->object); - decoration = get_name_decoration(&commit->object); if (!decoration) return; + color_commit = diff_get_color(use_color, DIFF_COMMIT); + color_reset = decorate_get_color(use_color, DECORATION_NONE); + + prefix = (opts && opts->prefix) ? opts->prefix : " ("; + suffix = (opts && opts->suffix) ? opts->suffix : ")"; + separator = (opts && opts->separator) ? opts->separator : ", "; + arrow = (opts && opts->arrow) ? opts->arrow : " -> "; + tag = (opts && opts->tag) ? opts->tag : "tag: "; + current_and_HEAD = current_pointed_by_HEAD(decoration); + while (decoration) { /* * When both current and HEAD are there, only @@ -329,20 +336,29 @@ void format_decorations_extended(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, prefix); - strbuf_addstr(sb, color_reset); - strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); - if (decoration->type == DECORATION_REF_TAG) - strbuf_addstr(sb, "tag: "); + const char *color = + decorate_get_color(use_color, decoration->type); + if (*prefix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, prefix); + strbuf_addstr(sb, color_reset); + } + + if (*tag && decoration->type == DECORATION_REF_TAG) { + strbuf_addstr(sb, color); + strbuf_addstr(sb, tag); + strbuf_addstr(sb, color_reset); + } + strbuf_addstr(sb, color); show_name(sb, decoration); - if (current_and_HEAD && + if (*arrow && current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { - strbuf_addstr(sb, " -> "); + strbuf_addstr(sb, arrow); strbuf_addstr(sb, color_reset); - strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); + strbuf_addstr(sb, decorate_get_color( + use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); } strbuf_addstr(sb, color_reset); @@ -351,9 +367,12 @@ void format_decorations_extended(struct strbuf *sb, } decoration = decoration->next; } - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, suffix); - strbuf_addstr(sb, color_reset); + + if (*suffix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, suffix); + strbuf_addstr(sb, color_reset); + } } void show_decorations(struct rev_info *opt, struct commit *commit) @@ -368,7 +387,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit) } if (!opt->show_decorations) return; - format_decorations(&sb, commit, opt->diffopt.use_color); + format_decorations(&sb, commit, opt->diffopt.use_color, NULL); fputs(sb.buf, opt->diffopt.file); strbuf_release(&sb); } diff --git a/log-tree.h b/log-tree.h index e7e4641cf8..39ab06a3ca 100644 --- a/log-tree.h +++ b/log-tree.h @@ -13,17 +13,20 @@ struct decoration_filter { struct string_list *exclude_ref_config_pattern; }; +struct decoration_options { + char *prefix; + char *suffix; + char *separator; + char *arrow; + char *tag; +}; + int parse_decorate_color_config(const char *var, const char *slot_name, const char *value); int log_tree_diff_flush(struct rev_info *); int log_tree_commit(struct rev_info *, struct commit *); void show_log(struct rev_info *opt); -void format_decorations_extended(struct strbuf *sb, const struct commit *commit, - int use_color, - const char *prefix, - const char *separator, - const char *suffix); -#define format_decorations(strbuf, commit, color) \ - format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")") +void format_decorations(struct strbuf *sb, const struct commit *commit, + int use_color, const struct decoration_options *opts); void show_decorations(struct rev_info *opt, struct commit *commit); void log_write_email_headers(struct rev_info *opt, struct commit *commit, const char **extra_headers_p, diff --git a/pretty.c b/pretty.c index 0bb938021b..a59b7f0dbc 100644 --- a/pretty.c +++ b/pretty.c @@ -1373,6 +1373,46 @@ static size_t parse_describe_args(const char *start, struct strvec *args) return arg - start; } + +static int parse_decoration_option(const char **arg, + const char *name, + char **opt) +{ + const char *argval; + size_t arglen; + + if (match_placeholder_arg_value(*arg, name, arg, &argval, &arglen)) { + char *val = xstrndup(argval, arglen); + struct strbuf sb = STRBUF_INIT; + + strbuf_expand(&sb, val, strbuf_expand_literal_cb, NULL); + free(val); + *opt = strbuf_detach(&sb, NULL); + return 1; + } + return 0; +} + +static void parse_decoration_options(const char **arg, + struct decoration_options *opts) +{ + while (parse_decoration_option(arg, "prefix", &opts->prefix) || + parse_decoration_option(arg, "suffix", &opts->suffix) || + parse_decoration_option(arg, "separator", &opts->separator) || + parse_decoration_option(arg, "arrow", &opts->arrow) || + parse_decoration_option(arg, "tag", &opts->tag)) + ; +} + +static void free_decoration_options(const struct decoration_options *opts) +{ + free(opts->prefix); + free(opts->suffix); + free(opts->separator); + free(opts->arrow); + free(opts->tag); +} + static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ const char *placeholder, void *context) @@ -1526,10 +1566,11 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ strbuf_addstr(sb, get_revision_mark(NULL, commit)); return 1; case 'd': - format_decorations(sb, commit, c->auto_color); + format_decorations(sb, commit, c->auto_color, NULL); return 1; case 'D': - format_decorations_extended(sb, commit, c->auto_color, "", ", ", ""); + format_decorations(sb, commit, c->auto_color, + &(struct decoration_options){"", ""}); return 1; case 'S': /* tag/branch like --source */ if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources)) @@ -1627,6 +1668,23 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ return 2; } + if (skip_prefix(placeholder, "(decorate", &arg)) { + struct decoration_options opts = { NULL }; + size_t ret = 0; + + if (*arg == ':') { + arg++; + parse_decoration_options(&arg, &opts); + } + if (*arg == ')') { + format_decorations(sb, commit, c->auto_color, &opts); + ret = arg - placeholder + 1; + } + + free_decoration_options(&opts); + return ret; + } + /* For the rest we have to parse the commit header. */ if (!c->commit_header_parsed) { msg = c->message = diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 4cf8a77667..5ea937648a 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -576,6 +576,27 @@ test_expect_success 'clean log decoration' ' test_cmp expected actual1 ' +test_expect_success 'pretty format %decorate' ' + git checkout -b foo && + git commit --allow-empty -m "new commit" && + git tag bar && + git branch qux && + echo " (HEAD -> foo, tag: bar, qux)" >expect1 && + git log --format="%(decorate)" -1 >actual1 && + test_cmp expect1 actual1 && + echo "HEAD -> foo, tag: bar, qux" >expect2 && + git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 && + test_cmp expect2 actual2 && + echo "HEAD->foo bar qux" >expect3 && + git log --format="%(decorate:prefix=,suffix=,separator= ,arrow=->,tag=)" \ + -1 >actual3 && + test_cmp expect3 actual3 && + echo "[HEAD,foo,bar,qux]" >expect4 && + git log --format="%(decorate:prefix=[,suffix=],separator=%x2C,arrow=%x2C,tag=)" \ + -1 >actual4 && + test_cmp expect4 actual4 +' + cat >trailers < Acked-by: A U Thor diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index ded33a82e2..3a4eedc494 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -55,13 +55,15 @@ test_expect_success 'commit decorations colored correctly' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ ${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_commit}, \ ${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1 - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset} \ -On main: Changes to A.t - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_stash}refs/stash${c_reset}${c_commit})${c_reset} On main: Changes to A.t + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && @@ -78,10 +80,12 @@ test_expect_success 'test coloring with replace-objects' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ ${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: D${c_reset}${c_commit})${c_reset} D - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: C${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_commit}, \ ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && @@ -102,11 +106,13 @@ test_expect_success 'test coloring with grafted commit' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ ${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: D${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit}, \ ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && From patchwork Thu Aug 10 21:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC77AC001DE for ; Thu, 10 Aug 2023 21:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbjHJVRH (ORCPT ); Thu, 10 Aug 2023 17:17:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjHJVRE (ORCPT ); Thu, 10 Aug 2023 17:17:04 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9ED92738 for ; Thu, 10 Aug 2023 14:17:02 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe501e0b4cso12703075e9.1 for ; Thu, 10 Aug 2023 14:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702221; x=1692307021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/5q7I3edJAB5k9KZ5royy8m/gT9lYVzk+KhH4I1gZl0=; b=C/pNR7wMBWAWcUnJ3O86Dhm1OyTqBVY7+afZRB59rBaxbUh4Vvz3wTaJz9m7v4UFOE KZhOSkd4sU2MMhKQYaXgk/LBG0b+5HbVVXh3aOavGs5cGBcQzcSk/VbspesoUmXVl1+X Gc3qQRkmYuN9FGRLVIAgxNupmdh+MI5qqOo5jQZbpL75HVOPk7oh7V3YAp/9uhE5zZJw iwXf5On3ALfb5lIiLCpLsDYjhXcey1Ym3Vmyp61B7/swQAaGfGnRM1KH47b12XDt8hs/ IHquVaZXdel4bFXZ9swlqvNXrEFet85fD3UgIdJuQ1R4Hn5PCwCSvm1WzLNrvgjfDz7t /90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702221; x=1692307021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/5q7I3edJAB5k9KZ5royy8m/gT9lYVzk+KhH4I1gZl0=; b=YMDgfV2bjNkjhRBvzs4JQGeq+6RovjHQvDATBUzoM+x1zIczs+MmOsoQWkOkwPU0pt U+5YQNjkA2WtCepGPdx/qXKOzQ7pf+Iy8Vb9YPzcaLUeBvuAVuaNzWw1AEiFj8i1rFzj PQdtMuIC7okwhBrIIxtc+TVN3A81J6k46ULBa4++I9zh67Uy4SZgJlqV3ulbN8/po89S KoTMYGVtSKjC/X1YUgtct3LJ1h0W66eUVKLuLCcL7v80G9rbuoNCKaXhdZVQdcngaO0u ZqJaHA3NZ0nwIxb1ES8jyQ5Ks3oqsgpsSanLL1l63XHvEz8ASamSaVFlJno2BBaq+iGS FpMA== X-Gm-Message-State: AOJu0Yzs9k9bRLWijoXaXUU/f3WU+Xg9pJ0aAixrl4NAzTgudBQzCskw C5zMjOb0J1DBpK11s+wSuJEciQ6aUyRmKA== X-Google-Smtp-Source: AGHT+IG6eLZWcFYqqWJa/fLRmfXOMLLKhWS3kzn78K0rHsW9PRmGtt7W6pXzCwYJ/kwBqKQJkLr86g== X-Received: by 2002:a05:600c:21cd:b0:3fb:a506:5656 with SMTP id x13-20020a05600c21cd00b003fba5065656mr24661wmj.32.1691702220921; Thu, 10 Aug 2023 14:17:00 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b003fe24da493dsm3169864wmf.41.2023.08.10.14.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:17:00 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v3 2/7] pretty-formats: enclose options in angle brackets Date: Thu, 10 Aug 2023 22:16:14 +0100 Message-ID: <20230810211619.19055-2-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230810211619.19055-1-andy.koppe@gmail.com> References: <20230715160730.4046-1-andy.koppe@gmail.com> <20230810211619.19055-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Enclose the 'options' placeholders in the %(describe) and %(trailers) format specifiers in angle brackets to clarify that they are placeholders rather than keywords. Also remove the indentation from their descriptions, instead of increasing it to account for the extra two angle bracket in the headings. The indentation isn't required by asciidoc, it doesn't reflect how the output text is formatted, and it's inconsistent with the following bullet points that are at the same level in the output. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 5e1432951b..851a9878e6 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -224,13 +224,11 @@ The placeholders are: linkgit:git-rev-list[1]) '%d':: ref names, like the --decorate option of linkgit:git-log[1] '%D':: ref names without the " (", ")" wrapping. -'%(describe[:options])':: human-readable name, like - linkgit:git-describe[1]; empty string for - undescribable commits. The `describe` string - may be followed by a colon and zero or more - comma-separated options. Descriptions can be - inconsistent when tags are added or removed at - the same time. +'%(describe[:])':: +human-readable name, like linkgit:git-describe[1]; empty string for +undescribable commits. The `describe` string may be followed by a colon and +zero or more comma-separated options. Descriptions can be inconsistent when +tags are added or removed at the same time. + ** 'tags[=]': Instead of only considering annotated tags, consider lightweight tags as well. @@ -283,13 +281,11 @@ endif::git-rev-list[] '%gE':: reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%gs':: reflog subject -'%(trailers[:options])':: display the trailers of the body as - interpreted by - linkgit:git-interpret-trailers[1]. The - `trailers` string may be followed by a colon - and zero or more comma-separated options. - If any option is provided multiple times the - last occurrence wins. +'%(trailers[:])':: +display the trailers of the body as interpreted by +linkgit:git-interpret-trailers[1]. The `trailers` string may be followed by +a colon and zero or more comma-separated options. If any option is provided +multiple times, the last occurrence wins. + ** 'key=': only show trailers with specified . Matching is done case-insensitively and trailing colon is optional. If option is From patchwork Thu Aug 10 21:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EE43C001B0 for ; Thu, 10 Aug 2023 21:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjHJVRI (ORCPT ); Thu, 10 Aug 2023 17:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjHJVRE (ORCPT ); Thu, 10 Aug 2023 17:17:04 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A05273E for ; Thu, 10 Aug 2023 14:17:03 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe1e1142caso12340755e9.0 for ; Thu, 10 Aug 2023 14:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702222; x=1692307022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gxI3WHdBfrfL/L4IrOiNozyXFte3Y9bjt+cYin8E1qo=; b=fwrWJ+HyzaStfmVGQBUrSf3TIpc0j30+vo8alc9YK/vZKs+nJeDejCKeyW0r+mI5oi /chGToEtiutbfyDabBGvRpTZBopUPYcf72QGhQt0EeXL9cVqEYeDa873yOcOE2hpj+GE BODB6k9bOdq9vRA11B1/ynMxLvtKdkIVejhVkEAvznfBNZVBxza0mqPvtOR+TVH2cenf DwBPg2CUXVHA5j+o+OfkdxdfGVAsXRhZgPrPo4OfCAfRBo+Moj9MkUpj7a8aHAp54avc 9+Og9/4S3ctufjdo8pJFKNfosa072RIGNxmtQVxkwUOFdOgxr1iRMsdpSwSf6jIsb/Q/ XbDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702222; x=1692307022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gxI3WHdBfrfL/L4IrOiNozyXFte3Y9bjt+cYin8E1qo=; b=eYA168jwRrpAcsx6HNWK3N+7vEutX6RHOE2Oai0McrSXQYUxlNA3qPd5mZhHBfyeD2 teY0Y6w8GntbWszGO0gdI8rF6q7VNKBmBtpsnwHldArOlkzGig9Sl0LfgYwVPNl6VkjX 0A1GveWTnQHMf/iJiZJ4D4vYh/lybGoC8aT3aQlZLIbE8eVz9R+EVRgmNNXkAXkfm9IG JXzQ5wJuMjIEMXzwI7n5XLRhNCgKsIZ4PPyGywM4rz6p7nPcGT9NntAC08VX8OAy7gYt Jyjw/zIyybZBXtWpfEB7zdMGFtxKpVmlEgf92Bft0ij7Byk1mboSwcCloCOTZq/FpClC seBA== X-Gm-Message-State: AOJu0Yw/V5/Lza95HOuoK1qTO8KjqSiUsje07XOY6JC+Gv//b+T9Covp DubxOfJxDV78z9qN/qu1D23oRt8FOsDc6w== X-Google-Smtp-Source: AGHT+IG3zp6EgfTKz7790RTWRKj7seIfNecj5EUmANnvYzvn8Gi7dgAHf9FCVgKVu0mViEeGa5c4mA== X-Received: by 2002:a7b:cd0b:0:b0:3fb:b008:2003 with SMTP id f11-20020a7bcd0b000000b003fbb0082003mr56083wmj.38.1691702222328; Thu, 10 Aug 2023 14:17:02 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c229300b003fe24da493dsm3169864wmf.41.2023.08.10.14.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:17:02 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v3 4/7] decorate: avoid some unnecessary color overhead Date: Thu, 10 Aug 2023 22:16:16 +0100 Message-ID: <20230810211619.19055-4-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230810211619.19055-1-andy.koppe@gmail.com> References: <20230715160730.4046-1-andy.koppe@gmail.com> <20230810211619.19055-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In format_decorations(), don't obtain color sequences if there are no decorations, and don't emit color sequences around empty strings. Signed-off-by: Andy Koppe --- log-tree.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/log-tree.c b/log-tree.c index cd12c26c29..7c6d3f1ac3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -312,10 +312,7 @@ void format_decorations(struct strbuf *sb, { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; - const char *color_commit = - diff_get_color(use_color, DIFF_COMMIT); - const char *color_reset = - decorate_get_color(use_color, DECORATION_NONE); + const char *color_commit, *color_reset; const char *prefix = " ("; const char *suffix = ")"; @@ -334,6 +331,9 @@ void format_decorations(struct strbuf *sb, separator = opts->separator; } + color_commit = diff_get_color(use_color, DIFF_COMMIT); + color_reset = decorate_get_color(use_color, DECORATION_NONE); + current_and_HEAD = current_pointed_by_HEAD(decoration); while (decoration) { /* @@ -342,9 +342,12 @@ void format_decorations(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, prefix); - strbuf_addstr(sb, color_reset); + if (*prefix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, prefix); + strbuf_addstr(sb, color_reset); + } + strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); if (decoration->type == DECORATION_REF_TAG) strbuf_addstr(sb, "tag: "); @@ -364,9 +367,11 @@ void format_decorations(struct strbuf *sb, } decoration = decoration->next; } - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, suffix); - strbuf_addstr(sb, color_reset); + if (*suffix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, suffix); + strbuf_addstr(sb, color_reset); + } } void show_decorations(struct rev_info *opt, struct commit *commit)