From patchwork Thu Aug 10 21:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349925 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 DD239C04A94 for ; Thu, 10 Aug 2023 21:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjHJVRJ (ORCPT ); Thu, 10 Aug 2023 17:17:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjHJVRE (ORCPT ); Thu, 10 Aug 2023 17:17:04 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7852737 for ; Thu, 10 Aug 2023 14:17:02 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fe8242fc4dso4862955e9.1 for ; Thu, 10 Aug 2023 14:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702220; x=1692307020; 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=X27AHtAaaLMRBge6NBtgXIT5pSQ1Or9c6MvqCht4s4Y=; b=jOhsOkyS+8Smy/l9Py6fsMt2XNWvIY/ycmvWrn2ZW85JgJ/RTOx5wRAGB0Kjpgh1t4 grAfLKYrxMH9ReyJetEvT5IE6YL8+oYGU99zVAgHcvEZTI3TNkWWnfdtIf/NlKrRfJSJ CULeO9WDTEbeyivrVj2aVDwEn7nfbGtx1+J7aPrh+03u4AgYaw8IodSXrJduSKJ4hHir WSSgKm0QWqx7fs3zZkCne/fE9pfAUTH0G8hw8V0cgXD773WEJCxhMxT5cV2rcztW/41v 38UcxEYLmIrA9gULTxIHeiHhXreq9PLa1WOLOAg3WN/MAykERH0IAfnoEYhQOZAgZJfH zKPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702220; x=1692307020; 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=X27AHtAaaLMRBge6NBtgXIT5pSQ1Or9c6MvqCht4s4Y=; b=ZPdyTmJvEucAYa0aUjN6F/UwDvFVnS4074IgAPAw94poSwCRIMYsl4A5JZ8GSsNGwU lZ73sHrLxybbiPGRsgvccGJBGgUitZFfr4qLxN/Z2sItEQhEzg0rGxpt3xLaMmnrXbiR 2WI+qY67HfSAGFx6yRDpUwDg3EUJF8pMkkZqzc5VFdNOAvlMx+rJ4rhQW0JG8TZ18ikn XTfP/bRABx/kvFPN5BX4IgvLSxjUhmX5Gh56xrCK8XraVzVuxy68C7SVlyx6WxFCU6ZO nXsAr+sEoLiqgWYn3AdWuJD/NCEqodY8anFYTfkBcpiy6Vxui5S2/rv/cQ2nrWbJfgZq PyVw== X-Gm-Message-State: AOJu0YzOin2MIExnFpPBFH2CMc8lxE+f1EFLn4rllhx1LdG+sqs907le XdCbwPnwVH4Tu6KCwcsd1ltFUOiO4kAZ5w== X-Google-Smtp-Source: AGHT+IFxdgiQhpWnAMR+2sHCQcZtYsyE7Bw7CTnz5DROr+I/p7OljoxOMiqTlpVz+aPL9mnRlnUjnA== X-Received: by 2002:a05:600c:2909:b0:3fe:2b8c:9f00 with SMTP id i9-20020a05600c290900b003fe2b8c9f00mr61823wmd.24.1691702220306; 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.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:16:59 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Junio C Hamano , Andy Koppe Subject: [PATCH v3 1/7] pretty-formats: define "literal formatting code" Date: Thu, 10 Aug 2023 22:16:13 +0100 Message-ID: <20230810211619.19055-1-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230715160730.4046-1-andy.koppe@gmail.com> References: <20230715160730.4046-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Junio C Hamano The description for a %(trailer) option already uses this term without having a definition anywhere in the document, and we are about to add another one in %(decorate) that uses it. Signed-off-by: Junio C Hamano Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 3b71334459..5e1432951b 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -122,7 +122,9 @@ The placeholders are: - Placeholders that expand to a single literal character: '%n':: newline '%%':: a raw '%' -'%x00':: print a byte from a hex code +'%x00':: '%x' followed by two hexadecimal digits is replaced with a + byte with the hexadecimal digits' value (we will call this + "literal formatting code" in the rest of this document). - Placeholders that affect formatting of later placeholders: '%Cred':: switch color to red From patchwork Thu Aug 10 21:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349926 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 BB573C001DE for ; Thu, 10 Aug 2023 21:17:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjHJVRL (ORCPT ); Thu, 10 Aug 2023 17:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbjHJVRE (ORCPT ); Thu, 10 Aug 2023 17:17:04 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E018273D for ; Thu, 10 Aug 2023 14:17:03 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe2d218eedso12822095e9.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=0cqgnUnHxpyEoIsWq8VCsc0YDDVEWbhJtt64G58uiVk=; b=mPt/mvPL6tEgV/uO+jU7kPrPixnCT+lJy58UUR4KJJrm+K3fGIBkuy8/2VxtANIxOJ TJ4/7jvqYKKvraKnAJDsEt/ksRnNj6NqVJuOllKT750QDS8sbLf6VTJMnZFvLSCQ/bO2 g+8NnNJfbo9x5Sdh6aT1tlapOM88dm+lke0gcRiCCi1vZiqjNDgYY5tNC7ig2M2/sDfQ CnJhSkG9XzopGnIXOBJeuaufe/zwpW90wiZWak1WJDddPXpks/GW0nnnMBJbV+u6UIyz tQkgAmp5JRSVJpA8cpSHGsRSjhBihWAqZpAfyp35GImme0NEun78/SU0Enx/ilyP6+nM pVBg== 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=0cqgnUnHxpyEoIsWq8VCsc0YDDVEWbhJtt64G58uiVk=; b=NMgWCxRkjxpAgJwcKS5LDQVp8OgCa1uQR6Ip9y9WulEMKy7compZ1f9iJXcRFjLq1l sZe76w0ivLVtofe7FO+v+Z1CuLRYMTYbSV9JFtZiFpfTBDiwif8f7VDRR/l+DmMF0ePb hlTmvdGbM0QP4ncD6CEky69ky6pfPaRxEh6y0jN7wJdhty/yh25whxUBe+i34PlPZipA qaI+6+IvLy/T9xztuF8640bVupDHMFrK71vEmNohun5jlId7lD2KTYxf96UAt9I3Sgzd GtfxymEATcbsURzcDoFlaQem9ZePifkDv/QisFWRnu6f+eXMq3KyOsjh+FHWWU+IVmLc 1PjA== X-Gm-Message-State: AOJu0YwySKQrjDTaToavUVa64mG3JmAjt8s/9ZLCfmQvOz4sGhZl3h1D ERK9W0GqxdPIprvepChVf2V+l5NEU14W1w== X-Google-Smtp-Source: AGHT+IGDeALhN901pCsIilOEh7zfh52YnDrgzbosbWRVVf9wlpgVTaPq5TAhWYsZZbXIDlebhAWAKg== X-Received: by 2002:a1c:f702:0:b0:3fb:403d:90c5 with SMTP id v2-20020a1cf702000000b003fb403d90c5mr37807wmh.39.1691702221636; Thu, 10 Aug 2023 14:17:01 -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:01 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v3 3/7] decorate: refactor format_decorations() Date: Thu, 10 Aug 2023 22:16:15 +0100 Message-ID: <20230810211619.19055-3-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 Rename the format_decorations_extended function to format_decorations and drop the format_decorations wrapper macro. Pass the prefix, suffix and separator strings as a single 'struct format_decorations' pointer argument instead of separate arguments. Use default values defined in the function when either the struct pointer or any of the struct fields are NULL. This is to ease extension with additional options. Signed-off-by: Andy Koppe --- log-tree.c | 23 +++++++++++++++++------ log-tree.h | 15 ++++++++------- pretty.c | 6 ++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/log-tree.c b/log-tree.c index 208c69cbb7..cd12c26c29 100644 --- a/log-tree.c +++ b/log-tree.c @@ -303,14 +303,12 @@ 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; @@ -319,10 +317,23 @@ void format_decorations_extended(struct strbuf *sb, const char *color_reset = decorate_get_color(use_color, DECORATION_NONE); + const char *prefix = " ("; + const char *suffix = ")"; + const char *separator = ", "; + decoration = get_name_decoration(&commit->object); if (!decoration) return; + if (opts) { + if (opts->prefix) + prefix = opts->prefix; + if (opts->suffix) + suffix = opts->suffix; + if (opts->separator) + separator = opts->separator; + } + current_and_HEAD = current_pointed_by_HEAD(decoration); while (decoration) { /* @@ -370,7 +381,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 bdb6432815..14898de8ac 100644 --- a/log-tree.h +++ b/log-tree.h @@ -13,17 +13,18 @@ struct decoration_filter { struct string_list *exclude_ref_config_pattern; }; +struct decoration_options { + char *prefix; + char *suffix; + char *separator; +}; + 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 718530bbab..24fb82a5a2 100644 --- a/pretty.c +++ b/pretty.c @@ -1537,10 +1537,12 @@ 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){.prefix = "", + .suffix = ""}); return 1; case 'S': /* tag/branch like --source */ if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources)) From patchwork Thu Aug 10 21:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349928 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 E89D5C001DE for ; Thu, 10 Aug 2023 21:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjHJVRP (ORCPT ); Thu, 10 Aug 2023 17:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjHJVRF (ORCPT ); Thu, 10 Aug 2023 17:17:05 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB23F2D40 for ; Thu, 10 Aug 2023 14:17:04 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fe1a17f983so11828655e9.3 for ; Thu, 10 Aug 2023 14:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702223; x=1692307023; 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=s1Xj5UebKAlbiXHIurjVUfY3O8Y0z5fQmFB76s4cJKw=; b=qtn2apozDUS6oYmL5ekLwJv0aOP7ZkdWk5i3Iz69QacGlnjgHAEXXOY6uc6kVAKJWh sSFaU2bKhaGd5fSGaQ1emOB+qhv6b6CysxbZ05/5FSi9cNzZx3Cv+Dc5hEF9sKn0hVgv XTGJwp1D51ak6YP9UGZzPx6H0jvSRvWPrqZqLEHbdXvnDt466hLPwbXclqxA+JgkZ/bw Gg78OAdimlPA9D4C0oiVssM7Df6+7WOhOUWd3gf8ilizCvpoBFcp5ZwHnjoU9U036hLi Y/Cq+bIvSs9PJie5fmKAynObuesjBHbBGLmAR/U7cStn9R747BtVe5Hqw6gkeW0D2HhP Uvkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702223; x=1692307023; 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=s1Xj5UebKAlbiXHIurjVUfY3O8Y0z5fQmFB76s4cJKw=; b=WFoTBJPzp5lxsmki8G0heDYUcyP7pLJBcDwnF7798WxcuEt9747fT1tdh5TTrqRROJ UepRacenL5jlS7NwpNhrPIvvKBQ6GXMIrTT/pSIm4OFfghrI3pPtlMYI6rtEw4XbKMcb vTicG5/NmCnoL5amCEkfSsGKdvI6dyV1wkvV24ZGC1oFeR8l6c9Llj4Vf6YDXOywcq2u WYQj1OZPwIFiNqBwTo2VTIoxfYLIUVWHXhzcrXn9jumRza33LyYmH8UoAUTO8Plc3vDN kICJpQlJ71RlDYEOp+ZjPOChsfogPwxqefhTSR36TPcO80lbckpEc3V3ZAnDh8yetaBh 0NxQ== X-Gm-Message-State: AOJu0YyNrfbs5/t8FhgIFAWmBVRibQR6igXrK3+IyJM/bRIAWCSs3gDQ cX4sdD3jxDWGgZGq4qocPOwXqpkXhwSmOg== X-Google-Smtp-Source: AGHT+IGllt1ljQXdEGpz9PLL36Cbc8o6801RwB9zS27kCJcqIU/o0NC6txyjW3zTfnCAQgp+HvjbXg== X-Received: by 2002:a1c:4c14:0:b0:3fe:18a3:b3c with SMTP id z20-20020a1c4c14000000b003fe18a30b3cmr62504wmf.12.1691702222975; 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.02 (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 5/7] decorate: color each token separately Date: Thu, 10 Aug 2023 22:16:17 +0100 Message-ID: <20230810211619.19055-5-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 Wrap "tag:" prefixes and the arrows in "HEAD -> branch" annotations in their own color sequences, because otherwise tag names or arrows can end up uncolored when %w width formatting breaks lines just before them. Use the commit color for arrows, for visual consistency with the '(', ',' and ')' symbols used as prefix, separator and suffix, which are also colored with the commit color. Amend test t4207-log-decoration-colors.sh accordingly. Signed-off-by: Andy Koppe --- log-tree.c | 14 +++++++--- t/t4207-log-decoration-colors.sh | 44 ++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/log-tree.c b/log-tree.c index 7c6d3f1ac3..3b62dca048 100644 --- a/log-tree.c +++ b/log-tree.c @@ -342,26 +342,34 @@ void format_decorations(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { + 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); } - strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); - if (decoration->type == DECORATION_REF_TAG) + if (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); + strbuf_addstr(sb, color_reset); if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { + strbuf_addstr(sb, color_commit); strbuf_addstr(sb, " -> "); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); + strbuf_addstr(sb, color_reset); } - strbuf_addstr(sb, color_reset); prefix = separator; } diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index ded33a82e2..21986a866d 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -53,15 +53,17 @@ cmp_filtered_decorations () { # to this test since it does not contain any decoration, hence --first-parent 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_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_commit} -> ${c_reset}${c_branch}main${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 && @@ -76,12 +78,14 @@ test_expect_success 'test coloring with replace-objects' ' git replace HEAD~1 HEAD~2 && 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_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_commit} -> ${c_reset}${c_branch}main${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 && @@ -100,13 +104,15 @@ test_expect_success 'test coloring with grafted commit' ' git replace --graft HEAD HEAD~2 && 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_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_commit} -> ${c_reset}${c_branch}main${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:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349927 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 B8E74C001B0 for ; Thu, 10 Aug 2023 21:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbjHJVRN (ORCPT ); Thu, 10 Aug 2023 17:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjHJVRG (ORCPT ); Thu, 10 Aug 2023 17:17:06 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AAAB2737 for ; Thu, 10 Aug 2023 14:17:05 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fe2fb9b4d7so11892665e9.1 for ; Thu, 10 Aug 2023 14:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702224; x=1692307024; 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=t5jdDghUh+ntpNaTgiUA1G9d3WmUYHo8Y8TrvRAc3/k=; b=RvWEEwjzjIX/5M/8h9Hm+IUsYiuc0mgx9Nhou040EiQ548CeHoDnLPudUB43sSzxDz wXful6m5NO9hE2o1/DDWYUWiydWv6pVprvBRmtJdvXZTp159/bBdcT+BsMf0pyPW48wf u529vhYNgk5JXswkfokT48aqmi5TaQOKuXAOrggxmho3SEXq7yQxcOM0F7Uspbxfjwwi AzfaEmwzJh9OaAHkogZg4qWZFEwtraSR4l10pDlC4LPLUMdRtG/ZAtI2Y3Ix7XAhzWVf J+gTkvL6qzPUNGrNaFgwtuz2jRWkm/Zvf/O+ohsdybI7olaYf8jTwHKp2MjFgKGfYIdk octw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702224; x=1692307024; 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=t5jdDghUh+ntpNaTgiUA1G9d3WmUYHo8Y8TrvRAc3/k=; b=MGPcMzqNv+0WymQMRujtO5qNXBeY85L5ho3pN/HjmBgqgdkCLLn/vQ30IcvQji9eSF 96yGDzSdyBYxqcROFHsZuCrFUJhoVkrnbb+w+kV9gWbeSbcXlRAZySR1vD3pIdGqLO0V fIT0eYXl8EWkuJGLbAKfMjN5rfv2OJxV+foPlGPtgudpWluScpSHA8dKzBN5H1GmWn9E GKTZsz9w54w4jHOmyeKFcc/JMrFeWXLKKzMlyKPO+fgF9wAwBIYnJa5kvu0QhGtH91bu wCoFp6TPH9I4AgI4mHzq0mvcI6WlKH/sAKh3M42nWOTm1JhzXj+VyRNxozhAWJe/Q3jz xMAw== X-Gm-Message-State: AOJu0YxyuMgOOc0jAV3ygmy8+0UVOpNr8AsvcUGA58Sp1569VZ0cpzJh HQH0nyjsYSj28q6Kp5vS34G6S2GZ123weQ== X-Google-Smtp-Source: AGHT+IHOUe29WINjDlgEj2Jh56oR9zMN1KbGJRj+N2Q8QRAyxaToIjoK4GFryZeSQCPXLlZeAaiHmQ== X-Received: by 2002:a05:600c:259:b0:3fe:2102:8083 with SMTP id 25-20020a05600c025900b003fe21028083mr37407wmj.26.1691702223692; Thu, 10 Aug 2023 14:17:03 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:17:03 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v3 6/7] pretty: add %(decorate[:]) format Date: Thu, 10 Aug 2023 22:16:18 +0100 Message-ID: <20230810211619.19055-6-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 Add %(decorate[:]) format that lists ref names similarly to the %d format, but which allows the otherwise fixed prefix, suffix and separator strings to be customized. Omitted options default to the strings used in %d. Rename expand_separator() function used to expand %x literal formatting codes to expand_string_arg(), as it is now used on strings other than separators. Examples: - %(decorate) is equivalent to %d. - %(decorate:prefix=,suffix=) is equivalent to %D. - %(decorate:prefix=[,suffix=],separator=%x3B) produces a list enclosed in square brackets and separated by semicolons. Test the format in t4205-log-pretty-formats.sh and document it in pretty-formats.txt. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 10 ++++++ pretty.c | 59 +++++++++++++++++++++++++++++--- t/t4205-log-pretty-formats.sh | 27 +++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 851a9878e6..709d85af21 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -224,6 +224,16 @@ 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. +'%(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 "{nbsp}`(`". +** 'suffix=': Shown after the list of ref names. Defaults to "`)`". +** 'separator=': Shown between ref names. Defaults to "`,`{nbsp}". + '%(describe[:])':: human-readable name, like linkgit:git-describe[1]; empty string for undescribable commits. The `describe` string may be followed by a colon and diff --git a/pretty.c b/pretty.c index 24fb82a5a2..d972051543 100644 --- a/pretty.c +++ b/pretty.c @@ -1252,8 +1252,8 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud) return 0; } -static struct strbuf *expand_separator(struct strbuf *sb, - const char *argval, size_t arglen) +static struct strbuf *expand_string_arg(struct strbuf *sb, + const char *argval, size_t arglen) { char *fmt = xstrndup(argval, arglen); const char *format = fmt; @@ -1301,9 +1301,9 @@ int format_set_trailers_options(struct process_trailer_options *opts, opts->filter_data = filter_list; opts->only_trailers = 1; } else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) { - opts->separator = expand_separator(sepbuf, argval, arglen); + opts->separator = expand_string_arg(sepbuf, argval, arglen); } else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) { - opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen); + opts->key_value_separator = expand_string_arg(kvsepbuf, argval, arglen); } else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) && !match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) && !match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) && @@ -1384,6 +1384,40 @@ 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)) { + struct strbuf sb = STRBUF_INIT; + + expand_string_arg(&sb, argval, arglen); + *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)) + ; +} + +static void free_decoration_options(const struct decoration_options *opts) +{ + free(opts->prefix); + free(opts->suffix); + free(opts->separator); +} + static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ const char *placeholder, void *context) @@ -1640,6 +1674,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 dd9035aa38..6ba399c5be 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -576,6 +576,33 @@ 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; tag: bar; qux ]" >expect3 && + git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B )" \ + -1 >actual3 && + test_cmp expect3 actual3 && + + # Try with a typo (in "separator"), in which case the placeholder should + # not be replaced. + echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && + git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ + -1 >actual4 && + test_cmp expect4 actual4 +' + cat >trailers < Acked-by: A U Thor From patchwork Thu Aug 10 21:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13349929 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 985BDC001B0 for ; Thu, 10 Aug 2023 21:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjHJVRQ (ORCPT ); Thu, 10 Aug 2023 17:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjHJVRG (ORCPT ); Thu, 10 Aug 2023 17:17:06 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5402738 for ; Thu, 10 Aug 2023 14:17:05 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fe2ba3e260so12119075e9.2 for ; Thu, 10 Aug 2023 14:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691702224; x=1692307024; 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=wa3zRENbvH4ytqyYszeqvnw3rUiLuRWy51egRlc9+Tc=; b=aiHKnvrujRnl/F+GuBgqiUwxtgtKajJF4jL6+k2LQKHq5TRtAW/UtIfB/03iRKSUPp pEVIYFRmXhtOwUdmXWHOGG2WxOI9MV30uBwKa77kKezqaz/sum6lrJY7X154+0IFPCHD mq3U3iF2E0thzLngONhZzVaDZY4cZ53Z4w8svrJTpAhrZkNNrQToMDptpbCd4Mo/aSNv ljturMsHrPHFhHDkBrgHIcMrJZP9cbKaFHSQJorOX2ts60+7oSXzbBcBakbSWhO4CbDR eB75l6NJbxyVdPoSft75rJmyaY4tflf7j1y3bMSiKj+BCgJPkdpb7uIQwGsKnri/O/zA AusA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691702224; x=1692307024; 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=wa3zRENbvH4ytqyYszeqvnw3rUiLuRWy51egRlc9+Tc=; b=JGhOKk0XKWs2dgoJjn/VZnxeaOZTm5t2mj2AduCWF27a4BB+x9CKIWCsPQ1NWkY294 orL8mExd3mXvec3MloYWrgSVRwYrNLRcbH7kYw9rg9wjyG0Kkc56/SMngeXXnznmEce5 8B4/4gaSExZeOe9iKx3s2hCEffIk+Hz3k304k2hMCyBZJmu8m2HH9MOKuPpbSezZUFpR dN8azNkNY0D9DehgU+QQxE6+9VL18WC2Car6CpgI6F4WPk60WH8jzLJD/iRiXWDJ2ASs kcHVKqtL0hsILQkyvyig44yjUE1Ftkwuw+zG4IU13/s7Njtt+9bJvnQpvUBiYB+usQZb ieJQ== X-Gm-Message-State: AOJu0YyVjwXOfoGlVEsW7/hHz4z8s4qAQqiqHbOix+E/qzP4W4KXyw3V cWS+UiCWCQA/xSPXXIKGoUAjiyZNai7umA== X-Google-Smtp-Source: AGHT+IE+PB6ZikPnBlTQKStbiwvV6eJRd4M0tKXc+rDjkX4u23PI2+4wEp/pVfXIoYpw/sRovqUPTg== X-Received: by 2002:a05:600c:2482:b0:3fc:5bcc:a909 with SMTP id 2-20020a05600c248200b003fc5bcca909mr102378wms.2.1691702224428; Thu, 10 Aug 2023 14:17:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:17:04 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH v3 7/7] pretty: add pointer and tag options to %(decorate) Date: Thu, 10 Aug 2023 22:16:19 +0100 Message-ID: <20230810211619.19055-7-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 Add pointer and tag options to %(decorate) format, to allow to override the " -> " string used to show where HEAD points and the "tag: " string used to mark tags. Document in pretty-formats.txt and test in t4205-log-pretty-formats.sh. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 9 +++++++++ log-tree.c | 12 +++++++++--- log-tree.h | 2 ++ pretty.c | 6 +++++- t/t4205-log-pretty-formats.sh | 7 ++++++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 709d85af21..d38b4ab566 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -233,6 +233,15 @@ parentheses (`%x29`), due to their role in the option syntax. ** 'prefix=': Shown before the list of ref names. Defaults to "{nbsp}`(`". ** 'suffix=': Shown after the list of ref names. Defaults to "`)`". ** 'separator=': Shown between ref names. Defaults to "`,`{nbsp}". +** 'pointer=': Shown between HEAD and the branch it points to, if any. + Defaults to "{nbsp}`->`{nbsp}". +** 'tag=': Shown before tag names. Defaults to "`tag:`{nbsp}". + ++ +For example, to produce decorations with no wrapping +or tag annotations, and spaces as separators: ++ +`%(decorate:prefix=,suffix=,tag=,separator= )` '%(describe[:])':: human-readable name, like linkgit:git-describe[1]; empty string for diff --git a/log-tree.c b/log-tree.c index 3b62dca048..504da6b519 100644 --- a/log-tree.c +++ b/log-tree.c @@ -317,6 +317,8 @@ void format_decorations(struct strbuf *sb, const char *prefix = " ("; const char *suffix = ")"; const char *separator = ", "; + const char *pointer = " -> "; + const char *tag = "tag: "; decoration = get_name_decoration(&commit->object); if (!decoration) @@ -329,6 +331,10 @@ void format_decorations(struct strbuf *sb, suffix = opts->suffix; if (opts->separator) separator = opts->separator; + if (opts->pointer) + pointer = opts->pointer; + if (opts->tag) + tag = opts->tag; } color_commit = diff_get_color(use_color, DIFF_COMMIT); @@ -351,9 +357,9 @@ void format_decorations(struct strbuf *sb, strbuf_addstr(sb, color_reset); } - if (decoration->type == DECORATION_REF_TAG) { + if (*tag && decoration->type == DECORATION_REF_TAG) { strbuf_addstr(sb, color); - strbuf_addstr(sb, "tag: "); + strbuf_addstr(sb, tag); strbuf_addstr(sb, color_reset); } @@ -364,7 +370,7 @@ void format_decorations(struct strbuf *sb, if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, " -> "); + strbuf_addstr(sb, pointer); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); diff --git a/log-tree.h b/log-tree.h index 14898de8ac..41c776fea5 100644 --- a/log-tree.h +++ b/log-tree.h @@ -17,6 +17,8 @@ struct decoration_options { char *prefix; char *suffix; char *separator; + char *pointer; + char *tag; }; int parse_decorate_color_config(const char *var, const char *slot_name, const char *value); diff --git a/pretty.c b/pretty.c index d972051543..5effbe9ad9 100644 --- a/pretty.c +++ b/pretty.c @@ -1407,7 +1407,9 @@ static void parse_decoration_options(const char **arg, { 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, "separator", &opts->separator) || + parse_decoration_option(arg, "pointer", &opts->pointer) || + parse_decoration_option(arg, "tag", &opts->tag)) ; } @@ -1416,6 +1418,8 @@ static void free_decoration_options(const struct decoration_options *opts) free(opts->prefix); free(opts->suffix); free(opts->separator); + free(opts->pointer); + free(opts->tag); } static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 6ba399c5be..16626e4fe9 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -600,7 +600,12 @@ test_expect_success 'pretty format %decorate' ' echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ -1 >actual4 && - test_cmp expect4 actual4 + test_cmp expect4 actual4 && + + echo "HEAD->foo bar qux" >expect5 && + git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \ + -1 >actual5 && + test_cmp expect5 actual5 ' cat >trailers <