From patchwork Sun Oct 25 21:26:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 078B2C388F7 for ; Sun, 25 Oct 2020 22:42:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5394222EC for ; Sun, 25 Oct 2020 22:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420320AbgJYWmP (ORCPT ); Sun, 25 Oct 2020 18:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420312AbgJYWmO (ORCPT ); Sun, 25 Oct 2020 18:42:14 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F15C0613CE for ; Sun, 25 Oct 2020 15:42:14 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-Jw; Sun, 25 Oct 2020 22:27:16 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 01/21] trailer: change token_{from,matches}_item into taking conf_info Date: Sun, 25 Oct 2020 22:26:32 +0100 Message-Id: <20201025212652.3003036-2-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-Jw; Sun, 25 Oct 2020 22:27:16 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false These functions don't use anything from the arg_item except the conf, so make them take conf as argument instead. This will allow them to be used on other things that has a conf_info. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/trailer.c b/trailer.c index 3f7391d793..efb88c2008 100644 --- a/trailer.c +++ b/trailer.c @@ -574,20 +574,20 @@ static void ensure_configured(void) configured = 1; } -static const char *token_from_item(struct arg_item *item, char *tok) +static const char *token_from_conf(const struct conf_info *conf, char *tok) { - if (item->conf.key) - return item->conf.key; + if (conf->key) + return conf->key; if (tok) return tok; - return item->conf.name; + return conf->name; } -static int token_matches_item(const char *tok, struct arg_item *item, size_t tok_len) +static int token_matches_conf(const char *tok, const struct conf_info *conf, size_t tok_len) { - if (!strncasecmp(tok, item->conf.name, tok_len)) + if (!strncasecmp(tok, conf->name, tok_len)) return 1; - return item->conf.key ? !strncasecmp(tok, item->conf.key, tok_len) : 0; + return conf->key ? !strncasecmp(tok, conf->key, tok_len) : 0; } /* @@ -650,11 +650,11 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, *conf = &default_conf_info; list_for_each(pos, &conf_head) { item = list_entry(pos, struct arg_item, list); - if (token_matches_item(tok->buf, item, tok_len)) { + if (token_matches_conf(tok->buf, &item->conf, tok_len)) { char *tok_buf = strbuf_detach(tok, NULL); if (conf) *conf = &item->conf; - strbuf_addstr(tok, token_from_item(item, tok_buf)); + strbuf_addstr(tok, token_from_conf(&item->conf, tok_buf)); free(tok_buf); break; } @@ -710,7 +710,7 @@ static void process_command_line_args(struct list_head *arg_head, item = list_entry(pos, struct arg_item, list); if (item->conf.command) add_arg_item(arg_head, - xstrdup(token_from_item(item, NULL)), + xstrdup(token_from_conf(&item->conf, NULL)), xstrdup(""), &item->conf, NULL); } @@ -879,7 +879,7 @@ static size_t find_trailer_start(const char *buf, size_t len) list_for_each(pos, &conf_head) { struct arg_item *item; item = list_entry(pos, struct arg_item, list); - if (token_matches_item(bol, item, + if (token_matches_conf(bol, &item->conf, separator_pos)) { recognized_prefix = 1; break; From patchwork Sun Oct 25 21:26:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C1D8C5517A for ; Sun, 25 Oct 2020 22:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50DD5222EC for ; Sun, 25 Oct 2020 22:42:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420300AbgJYWmG (ORCPT ); Sun, 25 Oct 2020 18:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420293AbgJYWmD (ORCPT ); Sun, 25 Oct 2020 18:42:03 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08568C0613CE for ; Sun, 25 Oct 2020 15:42:03 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-Oy; Sun, 25 Oct 2020 22:27:16 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 02/21] trailer: don't use 'struct arg_item' for storing config Date: Sun, 25 Oct 2020 22:26:33 +0100 Message-Id: <20201025212652.3003036-3-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-Oy; Sun, 25 Oct 2020 22:27:16 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false The '--trailer' options given to 'git interpret-trailers' are store in the suitably named 'struct arg_item'. The configuration done in 'trailer..xyz' was also stored in that struct. Even though it only needs the "conf_info" part of it. This commit creates a separate struct for conf_info_item No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/trailer.c b/trailer.c index efb88c2008..ca7a823af6 100644 --- a/trailer.c +++ b/trailer.c @@ -19,6 +19,11 @@ struct conf_info { enum trailer_if_missing if_missing; }; +struct conf_info_item { + struct list_head list; + struct conf_info conf; +}; + static struct conf_info default_conf_info; struct trailer_item { @@ -432,16 +437,16 @@ static void duplicate_conf(struct conf_info *dst, const struct conf_info *src) dst->command = xstrdup_or_null(src->command); } -static struct arg_item *get_conf_item(const char *name) +static struct conf_info *get_conf_item(const char *name) { struct list_head *pos; - struct arg_item *item; + struct conf_info_item *item; /* Look up item with same name */ list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); + item = list_entry(pos, struct conf_info_item, list); if (!strcasecmp(item->conf.name, name)) - return item; + return &item->conf; } /* Item does not already exists, create it */ @@ -451,7 +456,7 @@ static struct arg_item *get_conf_item(const char *name) list_add_tail(&item->list, &conf_head); - return item; + return &item->conf; } enum trailer_info_type { TRAILER_KEY, TRAILER_COMMAND, TRAILER_WHERE, @@ -502,7 +507,6 @@ static int git_trailer_default_config(const char *conf_key, const char *value, v static int git_trailer_config(const char *conf_key, const char *value, void *cb) { const char *trailer_item, *variable_name; - struct arg_item *item; struct conf_info *conf; char *name = NULL; enum trailer_info_type type; @@ -527,8 +531,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb) if (!name) return 0; - item = get_conf_item(name); - conf = &item->conf; + conf = get_conf_item(name); free(name); switch (type) { @@ -630,7 +633,7 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, const struct conf_info **conf, const char *trailer, ssize_t separator_pos) { - struct arg_item *item; + struct conf_info_item *item; size_t tok_len; struct list_head *pos; @@ -649,7 +652,7 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, if (conf) *conf = &default_conf_info; list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); + item = list_entry(pos, struct conf_info_item, list); if (token_matches_conf(tok->buf, &item->conf, tok_len)) { char *tok_buf = strbuf_detach(tok, NULL); if (conf) @@ -693,7 +696,7 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val, static void process_command_line_args(struct list_head *arg_head, struct list_head *new_trailer_head) { - struct arg_item *item; + struct conf_info_item *item; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; const struct conf_info *conf; @@ -707,7 +710,7 @@ static void process_command_line_args(struct list_head *arg_head, /* Add an arg item for each configured trailer with a command */ list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); + item = list_entry(pos, struct conf_info_item, list); if (item->conf.command) add_arg_item(arg_head, xstrdup(token_from_conf(&item->conf, NULL)), @@ -877,8 +880,8 @@ static size_t find_trailer_start(const char *buf, size_t len) if (recognized_prefix) continue; list_for_each(pos, &conf_head) { - struct arg_item *item; - item = list_entry(pos, struct arg_item, list); + struct conf_info_item *item; + item = list_entry(pos, struct conf_info_item, list); if (token_matches_conf(bol, &item->conf, separator_pos)) { recognized_prefix = 1; From patchwork Sun Oct 25 21:26:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A895C4363A for ; Sun, 25 Oct 2020 22:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C57E222EC for ; Sun, 25 Oct 2020 22:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1419786AbgJYWlq (ORCPT ); Sun, 25 Oct 2020 18:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1418775AbgJYWlp (ORCPT ); Sun, 25 Oct 2020 18:41:45 -0400 X-Greylist: delayed 1799 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 25 Oct 2020 15:41:45 PDT Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A630C061755 for ; Sun, 25 Oct 2020 15:41:45 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-T4; Sun, 25 Oct 2020 22:27:16 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 03/21] doc: mention canonicalization in git i-t manual Date: Sun, 25 Oct 2020 22:26:34 +0100 Message-Id: <20201025212652.3003036-4-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXo-0007u5-T4; Sun, 25 Oct 2020 22:27:16 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Signed-off-by: Anders Waldenborg --- Documentation/git-interpret-trailers.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt index 96ec6499f0..a4be8aed66 100644 --- a/Documentation/git-interpret-trailers.txt +++ b/Documentation/git-interpret-trailers.txt @@ -25,6 +25,11 @@ Otherwise, this command applies the arguments passed using the `--trailer` option, if any, to the commit message part of each input file. The result is emitted on the standard output. +When trailers read from input they will be changed into "canonical" +form if the trailer has a corresponding 'trailer..key' +configuration value. This means that it will use the exact spelling +(upper case vs lower case and separator) defined in configuration. + Some configuration variables control the way the `--trailer` arguments are applied to each commit message and the way any existing trailer in the commit message is changed. They also make it possible to From patchwork Sun Oct 25 21:26:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2644C4363A for ; Sun, 25 Oct 2020 22:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 964ED222EC for ; Sun, 25 Oct 2020 22:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420273AbgJYWlz (ORCPT ); Sun, 25 Oct 2020 18:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420265AbgJYWly (ORCPT ); Sun, 25 Oct 2020 18:41:54 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A78AC061755 for ; Sun, 25 Oct 2020 15:41:54 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-27; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 04/21] pretty: allow using aliases in %(trailer:key=xyz) Date: Sun, 25 Oct 2020 22:26:35 +0100 Message-Id: <20201025212652.3003036-5-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-27; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Signed-off-by: Anders Waldenborg --- Documentation/pretty-formats.txt | 4 +++- pretty.c | 5 ++++- t/t4205-log-pretty-formats.sh | 6 ++++++ trailer.c | 7 +++++-- trailer.h | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 84bbc7439a..1714fa447d 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -256,7 +256,9 @@ endif::git-rev-list[] ** 'key=': only show trailers with specified key. Matching is done case-insensitively and trailing colon is optional. If option is given multiple times trailer lines matching any of the keys are - shown. This option automatically enables the `only` option so that + shown. If `trailer..key` configuration option is set 'token' + can be used as an alias for showing trailers with the value in + key. This option automatically enables the `only` option so that non-trailer lines in the trailer block are hidden. If that is not desired it can be disabled with `only=false`. E.g., `%(trailers:key=Reviewed-by)` shows trailer lines with key diff --git a/pretty.c b/pretty.c index 7a7708a0ea..3c374abffe 100644 --- a/pretty.c +++ b/pretty.c @@ -1135,7 +1135,7 @@ static int match_placeholder_bool_arg(const char *to_parse, const char *candidat return 1; } -static int format_trailer_match_cb(const struct strbuf *key, void *ud) +static int format_trailer_match_cb(const struct strbuf *key, const char *alias, void *ud) { const struct string_list *list = ud; const struct string_list_item *item; @@ -1144,6 +1144,9 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud) if (key->len == (uintptr_t)item->util && !strncasecmp(item->string, key->buf, key->len)) return 1; + if (alias && strlen(alias) == (uintptr_t)item->util && + !strncasecmp(item->string, alias, (uintptr_t)item->util)) + return 1; } return 0; } diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 204c149d5a..757575d3f6 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -676,6 +676,12 @@ test_expect_success 'pretty format %(trailers:key=foo) multiple keys' ' test_cmp expect actual ' +test_expect_success 'pretty format %(trailers:key=foo) alias in config' ' + git -c trailer.ab.key=Acked-by log --no-walk --pretty="format:%(trailers:key=ab)" >actual && + echo "Acked-by: A U Thor " >expect && + test_cmp expect actual +' + test_expect_success '%(trailers:key=nonexistent) becomes empty' ' git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual && echo "xx" >expect && diff --git a/trailer.c b/trailer.c index ca7a823af6..8c0687a529 100644 --- a/trailer.c +++ b/trailer.c @@ -1148,8 +1148,11 @@ static void format_trailer_info(struct strbuf *out, struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; - parse_trailer(&tok, &val, NULL, trailer, separator_pos); - if (!opts->filter || opts->filter(&tok, opts->filter_data)) { + const struct conf_info *conf; + + parse_trailer(&tok, &val, &conf, trailer, separator_pos); + if (!opts->filter || + opts->filter(&tok, conf ? conf->name : NULL, opts->filter_data)) { if (opts->unfold) unfold_value(&val); diff --git a/trailer.h b/trailer.h index cd93e7ddea..b362b0d44d 100644 --- a/trailer.h +++ b/trailer.h @@ -73,7 +73,7 @@ struct process_trailer_options { int no_divider; int value_only; const struct strbuf *separator; - int (*filter)(const struct strbuf *, void *); + int (*filter)(const struct strbuf *, const char *alias, void *); void *filter_data; }; From patchwork Sun Oct 25 21:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7F4BC5517A for ; Sun, 25 Oct 2020 22:42:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3C42222EC for ; Sun, 25 Oct 2020 22:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420321AbgJYWmP (ORCPT ); Sun, 25 Oct 2020 18:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420311AbgJYWmM (ORCPT ); Sun, 25 Oct 2020 18:42:12 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD92C061755 for ; Sun, 25 Oct 2020 15:42:12 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-77; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 05/21] trailer: rename 'free_all' to 'free_all_trailer_items' Date: Sun, 25 Oct 2020 22:26:36 +0100 Message-Id: <20201025212652.3003036-6-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-77; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 8c0687a529..227df1c0ef 100644 --- a/trailer.c +++ b/trailer.c @@ -990,7 +990,7 @@ static size_t process_input_file(FILE *outfile, return info.trailer_end - str; } -static void free_all(struct list_head *head) +static void free_all_trailer_items(struct list_head *head) { struct list_head *pos, *p; list_for_each_safe(pos, p, head) { @@ -1057,7 +1057,7 @@ void process_trailers(const char *file, print_all(outfile, &head, opts); - free_all(&head); + free_all_trailer_items(&head); /* Print the lines after the trailers as is */ if (!opts->only_trailers) From patchwork Sun Oct 25 21:26:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D27C4363A for ; Sun, 25 Oct 2020 22:11:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 449BD222C2 for ; Sun, 25 Oct 2020 22:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1419149AbgJYWLs (ORCPT ); Sun, 25 Oct 2020 18:11:48 -0400 Received: from 0x63.nu ([109.74.10.199]:54914 "EHLO 0x63.nu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1419146AbgJYWLr (ORCPT ); Sun, 25 Oct 2020 18:11:47 -0400 X-Greylist: delayed 2673 seconds by postgrey-1.27 at vger.kernel.org; Sun, 25 Oct 2020 18:11:47 EDT Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-CH; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 06/21] t4205: add test for trailer in log with nonstandard separator Date: Sun, 25 Oct 2020 22:26:37 +0100 Message-Id: <20201025212652.3003036-7-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-CH; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Signed-off-by: Anders Waldenborg --- t/t4205-log-pretty-formats.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 757575d3f6..42544fb07a 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -757,6 +757,18 @@ test_expect_success 'pretty format %(trailers) combining separator/key/valueonly test_cmp expect actual ' +test_expect_success 'pretty format %(trailers) with nonstandard separator' ' + git commit --allow-empty -F - <<-\EOF && + Some fix + + Closes #1234 + EOF + + git -c "trailer.separators=:#" log --no-walk --pretty="format:%s% (trailers:key=Closes)" >actual && + echo "Some fix Closes: 1234" >expect && + test_cmp expect actual +' + test_expect_success 'trailer parsing not fooled by --- line' ' git commit --allow-empty -F - <<-\EOF && this is the subject From patchwork Sun Oct 25 21:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC0B8C388F7 for ; Sun, 25 Oct 2020 22:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DA72223BD for ; Sun, 25 Oct 2020 22:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420264AbgJYWlw (ORCPT ); Sun, 25 Oct 2020 18:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420258AbgJYWlv (ORCPT ); Sun, 25 Oct 2020 18:41:51 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 312D1C061755 for ; Sun, 25 Oct 2020 15:41:51 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-HV; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 07/21] trailer: simplify 'arg_item' lifetime Date: Sun, 25 Oct 2020 22:26:38 +0100 Message-Id: <20201025212652.3003036-8-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-HV; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false 'struct arg_item' are created from config and '--trailers' arguments in 'git interpret-trailers'. Then they were freed as they were processed. This made it harder to reason about and ensure that all of them were properly freed in all cases. This commit extends the lifetime by not doing any freeing during processing but rather freeing the whole list afterwards. This make it clearer and will allow keeping a reference to the config stored in the arg item. The drawback is that there is extra memory allocation as previously the strings could be donated to the trailer_item when that is created. Now they have to be copied. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/trailer.c b/trailer.c index 227df1c0ef..047781463a 100644 --- a/trailer.c +++ b/trailer.c @@ -177,13 +177,11 @@ static void print_all(FILE *outfile, struct list_head *head, } } -static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok) +static struct trailer_item *trailer_from_arg(const struct arg_item *arg_tok) { struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1); - new_item->token = arg_tok->token; - new_item->value = arg_tok->value; - arg_tok->token = arg_tok->value = NULL; - free_arg_item(arg_tok); + new_item->token = xstrdup(arg_tok->token); + new_item->value = xstrdup(arg_tok->value); return new_item; } @@ -274,7 +272,6 @@ static void apply_arg_if_exists(struct trailer_item *in_tok, { switch (arg_tok->conf.if_exists) { case EXISTS_DO_NOTHING: - free_arg_item(arg_tok); break; case EXISTS_REPLACE: apply_item_command(in_tok, arg_tok); @@ -290,15 +287,11 @@ static void apply_arg_if_exists(struct trailer_item *in_tok, apply_item_command(in_tok, arg_tok); if (check_if_different(in_tok, arg_tok, 1, head)) add_arg_to_input_list(on_tok, arg_tok); - else - free_arg_item(arg_tok); break; case EXISTS_ADD_IF_DIFFERENT_NEIGHBOR: apply_item_command(in_tok, arg_tok); if (check_if_different(on_tok, arg_tok, 0, head)) add_arg_to_input_list(on_tok, arg_tok); - else - free_arg_item(arg_tok); break; default: BUG("trailer.c: unhandled value %d", @@ -314,7 +307,6 @@ static void apply_arg_if_missing(struct list_head *head, switch (arg_tok->conf.if_missing) { case MISSING_DO_NOTHING: - free_arg_item(arg_tok); break; case MISSING_ADD: where = arg_tok->conf.where; @@ -364,15 +356,13 @@ static int find_same_and_apply_arg(struct list_head *head, static void process_trailers_lists(struct list_head *head, struct list_head *arg_head) { - struct list_head *pos, *p; + struct list_head *pos; struct arg_item *arg_tok; - list_for_each_safe(pos, p, arg_head) { + list_for_each(pos, arg_head) { int applied = 0; arg_tok = list_entry(pos, struct arg_item, list); - list_del(pos); - applied = find_same_and_apply_arg(head, arg_tok); if (!applied) @@ -999,6 +989,15 @@ static void free_all_trailer_items(struct list_head *head) } } +static void free_all_arg_items(struct list_head *head) +{ + struct list_head *pos, *p; + list_for_each_safe(pos, p, head) { + list_del(pos); + free_arg_item(list_entry(pos, struct arg_item, list)); + } +} + static struct tempfile *trailers_tempfile; static FILE *create_in_place_tempfile(const char *file) @@ -1035,6 +1034,7 @@ void process_trailers(const char *file, struct list_head *new_trailer_head) { LIST_HEAD(head); + LIST_HEAD(arg_head); struct strbuf sb = STRBUF_INIT; size_t trailer_end; FILE *outfile = stdout; @@ -1050,7 +1050,6 @@ void process_trailers(const char *file, trailer_end = process_input_file(outfile, sb.buf, &head, opts); if (!opts->only_input) { - LIST_HEAD(arg_head); process_command_line_args(&arg_head, new_trailer_head); process_trailers_lists(&head, &arg_head); } @@ -1058,6 +1057,7 @@ void process_trailers(const char *file, print_all(outfile, &head, opts); free_all_trailer_items(&head); + free_all_arg_items(&arg_head); /* Print the lines after the trailers as is */ if (!opts->only_trailers) From patchwork Sun Oct 25 21:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4D6C388F7 for ; Sun, 25 Oct 2020 22:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 977EE222C2 for ; Sun, 25 Oct 2020 22:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420287AbgJYWmA (ORCPT ); Sun, 25 Oct 2020 18:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420281AbgJYWl6 (ORCPT ); Sun, 25 Oct 2020 18:41:58 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF8AC061755 for ; Sun, 25 Oct 2020 15:41:58 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-ML; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 08/21] trailer: keep track of conf in trailer_item Date: Sun, 25 Oct 2020 22:26:39 +0100 Message-Id: <20201025212652.3003036-9-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-ML; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Signed-off-by: Anders Waldenborg --- trailer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/trailer.c b/trailer.c index 047781463a..0986d4267e 100644 --- a/trailer.c +++ b/trailer.c @@ -34,6 +34,7 @@ struct trailer_item { */ char *token; char *value; + const struct conf_info *conf; }; struct arg_item { @@ -182,6 +183,7 @@ static struct trailer_item *trailer_from_arg(const struct arg_item *arg_tok) struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1); new_item->token = xstrdup(arg_tok->token); new_item->value = xstrdup(arg_tok->value); + new_item->conf = &arg_tok->conf; return new_item; } @@ -655,11 +657,12 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, } static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, - char *val) + char *val, const struct conf_info *conf) { struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1); new_item->token = tok; new_item->value = val; + new_item->conf = conf; list_add_tail(&new_item->list, head); return new_item; } @@ -959,19 +962,22 @@ static size_t process_input_file(FILE *outfile, continue; separator_pos = find_separator(trailer, separators); if (separator_pos >= 1) { - parse_trailer(&tok, &val, NULL, trailer, + const struct conf_info *conf; + parse_trailer(&tok, &val, &conf, trailer, separator_pos); if (opts->unfold) unfold_value(&val); add_trailer_item(head, strbuf_detach(&tok, NULL), - strbuf_detach(&val, NULL)); + strbuf_detach(&val, NULL), + conf); } else if (!opts->only_trailers) { strbuf_addstr(&val, trailer); strbuf_strip_suffix(&val, "\n"); add_trailer_item(head, NULL, - strbuf_detach(&val, NULL)); + strbuf_detach(&val, NULL), + NULL); } } From patchwork Sun Oct 25 21:26:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36F7BC4363A for ; Sun, 25 Oct 2020 22:41:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06111222EC for ; Sun, 25 Oct 2020 22:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420280AbgJYWl6 (ORCPT ); Sun, 25 Oct 2020 18:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420274AbgJYWlz (ORCPT ); Sun, 25 Oct 2020 18:41:55 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A977DC061755 for ; Sun, 25 Oct 2020 15:41:55 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-Rg; Sun, 25 Oct 2020 22:27:17 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 09/21] trailer: refactor print_tok_val into taking item Date: Sun, 25 Oct 2020 22:26:40 +0100 Message-Id: <20201025212652.3003036-10-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXp-0007u5-Rg; Sun, 25 Oct 2020 22:27:17 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/trailer.c b/trailer.c index 0986d4267e..71921e70ce 100644 --- a/trailer.c +++ b/trailer.c @@ -147,22 +147,22 @@ static char last_non_space_char(const char *s) return '\0'; } -static void print_tok_val(FILE *outfile, const char *tok, const char *val) +static void print_item(FILE *outfile, const struct trailer_item *item) { char c; - if (!tok) { - fprintf(outfile, "%s\n", val); + if (!item->token) { + fprintf(outfile, "%s\n", item->value); return; } - c = last_non_space_char(tok); + c = last_non_space_char(item->token); if (!c) return; if (strchr(separators, c)) - fprintf(outfile, "%s%s\n", tok, val); + fprintf(outfile, "%s%s\n", item->token, item->value); else - fprintf(outfile, "%s%c %s\n", tok, separators[0], val); + fprintf(outfile, "%s%c %s\n", item->token, separators[0], item->value); } static void print_all(FILE *outfile, struct list_head *head, @@ -174,7 +174,7 @@ static void print_all(FILE *outfile, struct list_head *head, item = list_entry(pos, struct trailer_item, list); if ((!opts->trim_empty || strlen(item->value) > 0) && (!opts->only_trailers || item->token)) - print_tok_val(outfile, item->token, item->value); + print_item(outfile, item); } } From patchwork Sun Oct 25 21:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28B45C4363A for ; Sun, 25 Oct 2020 22:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E36C6222C2 for ; Sun, 25 Oct 2020 22:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420283AbgJYWl7 (ORCPT ); Sun, 25 Oct 2020 18:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420276AbgJYWl5 (ORCPT ); Sun, 25 Oct 2020 18:41:57 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21193C061755 for ; Sun, 25 Oct 2020 15:41:57 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-0D; Sun, 25 Oct 2020 22:27:18 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 10/21] trailer: move trailer token canonicalization print time Date: Sun, 25 Oct 2020 22:26:41 +0100 Message-Id: <20201025212652.3003036-11-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-0D; Sun, 25 Oct 2020 22:27:18 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Now that config is stored on the trailer_item it can easily be accessed print time and the changing of the token into the configured (canonical) spelling can be done print time instead. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/trailer.c b/trailer.c index 71921e70ce..d6882155be 100644 --- a/trailer.c +++ b/trailer.c @@ -149,20 +149,24 @@ static char last_non_space_char(const char *s) static void print_item(FILE *outfile, const struct trailer_item *item) { - char c; - - if (!item->token) { - fprintf(outfile, "%s\n", item->value); - return; + if (item->token) { + const char *tok = item->token; + const struct conf_info *conf = item->conf; + char c; + + if (conf && conf->key) + tok = conf->key; + + c = last_non_space_char(tok); + if (!c) + return; + if (strchr(separators, c)) + fputs(tok, outfile); + else + fprintf(outfile, "%s%c ", tok, separators[0]); } - c = last_non_space_char(item->token); - if (!c) - return; - if (strchr(separators, c)) - fprintf(outfile, "%s%s\n", item->token, item->value); - else - fprintf(outfile, "%s%c %s\n", item->token, separators[0], item->value); + fprintf(outfile, "%s\n", item->value); } static void print_all(FILE *outfile, struct list_head *head, @@ -569,15 +573,6 @@ static void ensure_configured(void) configured = 1; } -static const char *token_from_conf(const struct conf_info *conf, char *tok) -{ - if (conf->key) - return conf->key; - if (tok) - return tok; - return conf->name; -} - static int token_matches_conf(const char *tok, const struct conf_info *conf, size_t tok_len) { if (!strncasecmp(tok, conf->name, tok_len)) @@ -646,11 +641,8 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, list_for_each(pos, &conf_head) { item = list_entry(pos, struct conf_info_item, list); if (token_matches_conf(tok->buf, &item->conf, tok_len)) { - char *tok_buf = strbuf_detach(tok, NULL); if (conf) *conf = &item->conf; - strbuf_addstr(tok, token_from_conf(&item->conf, tok_buf)); - free(tok_buf); break; } } @@ -706,7 +698,7 @@ static void process_command_line_args(struct list_head *arg_head, item = list_entry(pos, struct conf_info_item, list); if (item->conf.command) add_arg_item(arg_head, - xstrdup(token_from_conf(&item->conf, NULL)), + xstrdup(item->conf.name), xstrdup(""), &item->conf, NULL); } From patchwork Sun Oct 25 21:26:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4127FC4363A for ; Sun, 25 Oct 2020 22:42:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F586222C2 for ; Sun, 25 Oct 2020 22:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420308AbgJYWmM (ORCPT ); Sun, 25 Oct 2020 18:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420299AbgJYWmG (ORCPT ); Sun, 25 Oct 2020 18:42:06 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2111C061755 for ; Sun, 25 Oct 2020 15:42:05 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-4C; Sun, 25 Oct 2020 22:27:18 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 11/21] trailer: remember separator used in input Date: Sun, 25 Oct 2020 22:26:42 +0100 Message-Id: <20201025212652.3003036-12-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-4C; Sun, 25 Oct 2020 22:27:18 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false This will in later commits make it easier to allow configuration to decide if separator should be canonicalized or displayed as it was in input. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/trailer.c b/trailer.c index d6882155be..1592e6c998 100644 --- a/trailer.c +++ b/trailer.c @@ -34,6 +34,7 @@ struct trailer_item { */ char *token; char *value; + char *used_separator; const struct conf_info *conf; }; @@ -125,6 +126,7 @@ static void free_trailer_item(struct trailer_item *item) { free(item->token); free(item->value); + free(item->used_separator); free(item); } @@ -616,18 +618,26 @@ static ssize_t find_separator(const char *line, const char *separators) * * If separator_pos is -1, interpret the whole trailer as a token. */ -static void parse_trailer(struct strbuf *tok, struct strbuf *val, +static void parse_trailer(struct strbuf *tok, struct strbuf *val, struct strbuf *sep, const struct conf_info **conf, const char *trailer, ssize_t separator_pos) { struct conf_info_item *item; - size_t tok_len; struct list_head *pos; if (separator_pos != -1) { - strbuf_add(tok, trailer, separator_pos); - strbuf_trim(tok); - strbuf_addstr(val, trailer + separator_pos + 1); + size_t sep_spacing_begin = separator_pos; + size_t sep_spacing_end = separator_pos + 1; + + while (sep_spacing_begin > 0 && trailer[sep_spacing_begin - 1] == ' ') + sep_spacing_begin--; + while (trailer[sep_spacing_end] == ' ') + sep_spacing_end++; + + strbuf_add(tok, trailer, sep_spacing_begin); + if (sep) + strbuf_add(sep, trailer + sep_spacing_begin, sep_spacing_end - sep_spacing_begin); + strbuf_addstr(val, trailer + sep_spacing_end); strbuf_trim(val); } else { strbuf_addstr(tok, trailer); @@ -635,12 +645,11 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, } /* Lookup if the token matches something in the config */ - tok_len = token_len_without_separator(tok->buf, tok->len); if (conf) *conf = &default_conf_info; list_for_each(pos, &conf_head) { item = list_entry(pos, struct conf_info_item, list); - if (token_matches_conf(tok->buf, &item->conf, tok_len)) { + if (token_matches_conf(tok->buf, &item->conf, tok->len)) { if (conf) *conf = &item->conf; break; @@ -649,11 +658,12 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, } static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, - char *val, const struct conf_info *conf) + char *val, char *separator, const struct conf_info *conf) { struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1); new_item->token = tok; new_item->value = val; + new_item->used_separator = separator; new_item->conf = conf; list_add_tail(&new_item->list, head); return new_item; @@ -717,7 +727,7 @@ static void process_command_line_args(struct list_head *arg_head, (int) sb.len, sb.buf); strbuf_release(&sb); } else { - parse_trailer(&tok, &val, &conf, tr->text, + parse_trailer(&tok, &val, NULL, &conf, tr->text, separator_pos); add_arg_item(arg_head, strbuf_detach(&tok, NULL), @@ -936,6 +946,7 @@ static size_t process_input_file(FILE *outfile, struct trailer_info info; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; + struct strbuf sep = STRBUF_INIT; size_t i; trailer_info_get(&info, str, opts); @@ -955,13 +966,14 @@ static size_t process_input_file(FILE *outfile, separator_pos = find_separator(trailer, separators); if (separator_pos >= 1) { const struct conf_info *conf; - parse_trailer(&tok, &val, &conf, trailer, + parse_trailer(&tok, &val, &sep, &conf, trailer, separator_pos); if (opts->unfold) unfold_value(&val); add_trailer_item(head, strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL), + strbuf_detach(&sep, NULL), conf); } else if (!opts->only_trailers) { strbuf_addstr(&val, trailer); @@ -969,6 +981,7 @@ static size_t process_input_file(FILE *outfile, add_trailer_item(head, NULL, strbuf_detach(&val, NULL), + NULL, NULL); } } @@ -1148,7 +1161,7 @@ static void format_trailer_info(struct strbuf *out, const struct conf_info *conf; - parse_trailer(&tok, &val, &conf, trailer, separator_pos); + parse_trailer(&tok, &val, NULL, &conf, trailer, separator_pos); if (!opts->filter || opts->filter(&tok, conf ? conf->name : NULL, opts->filter_data)) { if (opts->unfold) @@ -1209,7 +1222,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) strbuf_reset(&iter->key); strbuf_reset(&iter->val); - parse_trailer(&iter->key, &iter->val, NULL, + parse_trailer(&iter->key, &iter->val, NULL, NULL, trailer, separator_pos); unfold_value(&iter->val); return 1; From patchwork Sun Oct 25 21:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48947C4363A for ; Sun, 25 Oct 2020 22:42:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B0B1222C2 for ; Sun, 25 Oct 2020 22:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420305AbgJYWmH (ORCPT ); Sun, 25 Oct 2020 18:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420281AbgJYWmE (ORCPT ); Sun, 25 Oct 2020 18:42:04 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75CBCC061755 for ; Sun, 25 Oct 2020 15:42:04 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-9d; Sun, 25 Oct 2020 22:27:18 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 12/21] trailer: handle configured nondefault separators explicitly Date: Sun, 25 Oct 2020 22:26:43 +0100 Message-Id: <20201025212652.3003036-13-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-9d; Sun, 25 Oct 2020 22:27:18 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Instead of parsing out separator from configuration when it is printed, do this parsing when reading the configuration so it can be stored separately and "conf->key" will contain the actual key only. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 59 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/trailer.c b/trailer.c index 1592e6c998..102eca0127 100644 --- a/trailer.c +++ b/trailer.c @@ -13,6 +13,7 @@ struct conf_info { char *name; char *key; + char *nondefault_separator; char *command; enum trailer_where where; enum trailer_if_exists if_exists; @@ -140,32 +141,21 @@ static void free_arg_item(struct arg_item *item) free(item); } -static char last_non_space_char(const char *s) -{ - int i; - for (i = strlen(s) - 1; i >= 0; i--) - if (!isspace(s[i])) - return s[i]; - return '\0'; -} - static void print_item(FILE *outfile, const struct trailer_item *item) { if (item->token) { const char *tok = item->token; + const char *sep = (char []){separators[0], ' ', '\0'}; const struct conf_info *conf = item->conf; - char c; - if (conf && conf->key) - tok = conf->key; + if (conf) { + if (conf->key) + tok = conf->key; + if (conf->nondefault_separator) + sep = conf->nondefault_separator; + } - c = last_non_space_char(tok); - if (!c) - return; - if (strchr(separators, c)) - fputs(tok, outfile); - else - fprintf(outfile, "%s%c ", tok, separators[0]); + fprintf(outfile, "%s%s", tok, sep); } fprintf(outfile, "%s\n", item->value); @@ -502,6 +492,34 @@ static int git_trailer_default_config(const char *conf_key, const char *value, v return 0; } +static void git_trailer_config_key(const char *conf_key, const char *value, struct conf_info *conf) +{ + const char *end = value + strlen(value) - 1; + + while (end > value && isspace(*end)) + end--; + + if (end == value) { + warning(_("Ignoring empty token for key '%s'"), conf_key); + return; + } + + if (strchr(separators, *end)) { + const char *token_end = end - 1; + while (token_end > value && isspace(*token_end)) + token_end--; + if (token_end == value) { + warning(_("Ignoring empty token for key '%s'"), conf_key); + return; + } + + conf->key = xstrndup(value, token_end - value + 1); + conf->nondefault_separator = xstrdup(token_end + 1); + } else { + conf->key = xstrdup(value); + } +} + static int git_trailer_config(const char *conf_key, const char *value, void *cb) { const char *trailer_item, *variable_name; @@ -536,7 +554,8 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb) case TRAILER_KEY: if (conf->key) warning(_("more than one %s"), conf_key); - conf->key = xstrdup(value); + + git_trailer_config_key (conf_key, value, conf); break; case TRAILER_COMMAND: if (conf->command) From patchwork Sun Oct 25 21:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A630C5517A for ; Sun, 25 Oct 2020 22:41:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0D56222C2 for ; Sun, 25 Oct 2020 22:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420261AbgJYWlv (ORCPT ); Sun, 25 Oct 2020 18:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420258AbgJYWlt (ORCPT ); Sun, 25 Oct 2020 18:41:49 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA267C061755 for ; Sun, 25 Oct 2020 15:41:49 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-Fn; Sun, 25 Oct 2020 22:27:18 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 13/21] trailer: add option to make canonicalization optional Date: Sun, 25 Oct 2020 22:26:44 +0100 Message-Id: <20201025212652.3003036-14-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-Fn; Sun, 25 Oct 2020 22:27:18 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false Adds a new `--(no-)canonicalize` option to interpret-trailers. By default it is on unless `--parse` option is given. When option is on trailer tokens and separators get canonicalized to the form they have in config (if there is any config for that trailer). This is same behavior as before this patch, which allows this behavior to be disabled with `--no-canonicalize`. `--parse` now also implies `--no-canonicalize`, if previous behavior with canonicalization also in parse mode is wanted it needs to be combined with `--parse --canonicalize` Signed-off-by: Anders Waldenborg --- Documentation/git-interpret-trailers.txt | 5 ++- builtin/interpret-trailers.c | 3 ++ t/t7513-interpret-trailers.sh | 52 ++++++++++++++++++++++++ trailer.c | 10 +++-- trailer.h | 1 + 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt index a4be8aed66..a9e6816525 100644 --- a/Documentation/git-interpret-trailers.txt +++ b/Documentation/git-interpret-trailers.txt @@ -129,13 +129,16 @@ OPTIONS --parse:: A convenience alias for `--only-trailers --only-input - --unfold`. + --unfold --no-canonicalize`. --no-divider:: Do not treat `---` as the end of the commit message. Use this when you know your input contains just the commit message itself (and not an email or the output of `git format-patch`). +--no-canonicalize:: + Disable canonicalization of input trailers. + CONFIGURATION VARIABLES ----------------------- diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 84748eafc0..51678657a3 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -81,6 +81,7 @@ static int parse_opt_parse(const struct option *opt, const char *arg, v->only_trailers = 1; v->only_input = 1; v->unfold = 1; + v->canonicalize = 0; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); return 0; @@ -105,6 +106,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")), OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply config rules")), OPT_BOOL(0, "unfold", &opts.unfold, N_("join whitespace-continued values")), + OPT_BOOL(0, "canonicalize", &opts.canonicalize, N_("canonicalize spelling for trailers with config")), OPT_CALLBACK_F(0, "parse", &opts, NULL, N_("set parsing options"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_parse), OPT_BOOL(0, "no-divider", &opts.no_divider, N_("do not treat --- specially")), @@ -112,6 +114,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) N_("trailer(s) to add"), option_parse_trailer), OPT_END() }; + opts.canonicalize = 1; git_config(git_default_config, NULL); diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 6602790b5f..4b3a2484b5 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -99,6 +99,58 @@ test_expect_success 'with config option on the command line' ' test_cmp expected actual ' +test_expect_success 'spelling and separators are canonicalized from configs with key' ' + cat >patch <<-\EOF && + non-trailer-line + + ReviEweD-bY :abc + ReviEwEd-bY) rst + ReviEweD-BY ; xyz + aCked-bY) only separator gets normalized + EOF + cat >expected <<-\EOF && + Reviewed-By: abc + Reviewed-By: rst + Reviewed-By: xyz + aCked-bY: only separator gets normalized + EOF + git \ + -c "trailer.separators=:);" \ + -c "trailer.rb.key=Reviewed-By" \ + -c "trailer.Acked-By.ifmissing=doNothing" \ + interpret-trailers --only-trailers --only-input patch >actual && + test_cmp expected actual +' + +test_expect_success 'spelling and separators are not canonicalized with --parse or --no-canonicalize' ' + cat >patch <<-\EOF && + non-trailer-line + + ReviEweD-bY :abc + ReviEwEd-bY) rst + ReviEweD-BY ; xyz + aCked-bY) not normalized + EOF + cat >expected <<-\EOF && + ReviEweD-bY :abc + ReviEwEd-bY) rst + ReviEweD-BY ; xyz + aCked-bY) not normalized + EOF + git \ + -c "trailer.separators=:);" \ + -c "trailer.rb.key=Reviewed-By" \ + -c "trailer.Acked-By.ifmissing=doNothing" \ + interpret-trailers --parse patch >actual && + test_cmp expected actual && + git \ + -c "trailer.separators=:);" \ + -c "trailer.rb.key=Reviewed-By" \ + -c "trailer.Acked-By.ifmissing=doNothing" \ + interpret-trailers --only-trailers --only-input --no-canonicalize patch >actual && + test_cmp expected actual +' + test_expect_success 'with only a title in the message' ' cat >expected <<-\EOF && area: change diff --git a/trailer.c b/trailer.c index 102eca0127..110d3ed226 100644 --- a/trailer.c +++ b/trailer.c @@ -141,14 +141,18 @@ static void free_arg_item(struct arg_item *item) free(item); } -static void print_item(FILE *outfile, const struct trailer_item *item) +static void print_item(FILE *outfile, const struct trailer_item *item, + const struct process_trailer_options *opts) { if (item->token) { const char *tok = item->token; const char *sep = (char []){separators[0], ' ', '\0'}; const struct conf_info *conf = item->conf; - if (conf) { + if (!opts->canonicalize && item->used_separator) + sep = item->used_separator; + + if (opts->canonicalize && conf) { if (conf->key) tok = conf->key; if (conf->nondefault_separator) @@ -170,7 +174,7 @@ static void print_all(FILE *outfile, struct list_head *head, item = list_entry(pos, struct trailer_item, list); if ((!opts->trim_empty || strlen(item->value) > 0) && (!opts->only_trailers || item->token)) - print_item(outfile, item); + print_item(outfile, item, opts); } } diff --git a/trailer.h b/trailer.h index b362b0d44d..aad856da8c 100644 --- a/trailer.h +++ b/trailer.h @@ -72,6 +72,7 @@ struct process_trailer_options { int unfold; int no_divider; int value_only; + int canonicalize; const struct strbuf *separator; int (*filter)(const struct strbuf *, const char *alias, void *); void *filter_data; From patchwork Sun Oct 25 21:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 899BBC5517A for ; Sun, 25 Oct 2020 22:41:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55F60222EC for ; Sun, 25 Oct 2020 22:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420270AbgJYWly (ORCPT ); Sun, 25 Oct 2020 18:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420265AbgJYWlw (ORCPT ); Sun, 25 Oct 2020 18:41:52 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E9B7C061755 for ; Sun, 25 Oct 2020 15:41:52 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-U4; Sun, 25 Oct 2020 22:27:18 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 14/21] trailer: move skipping of blank lines to own loop when finding trailer Date: Sun, 25 Oct 2020 22:26:45 +0100 Message-Id: <20201025212652.3003036-15-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXq-0007u5-U4; Sun, 25 Oct 2020 22:27:18 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/trailer.c b/trailer.c index 110d3ed226..937cf1edeb 100644 --- a/trailer.c +++ b/trailer.c @@ -829,7 +829,6 @@ static size_t find_trailer_start(const char *buf, size_t len) { const char *s; ssize_t end_of_title, l; - int only_spaces = 1; int recognized_prefix = 0, trailer_lines = 0, non_trailer_lines = 0; /* * Number of possible continuation lines encountered. This will be @@ -856,6 +855,12 @@ static size_t find_trailer_start(const char *buf, size_t len) * consists of at least 25% trailers. */ for (l = last_line(buf, len); + l >= end_of_title; + l = last_line(buf, l)) { + if (!is_blank_line(buf + l) && buf[l] != comment_line_char) + break; + } + for (; l >= end_of_title; l = last_line(buf, l)) { const char *bol = buf + l; @@ -868,8 +873,6 @@ static size_t find_trailer_start(const char *buf, size_t len) continue; } if (is_blank_line(bol)) { - if (only_spaces) - continue; non_trailer_lines += possible_continuation_lines; if (recognized_prefix && trailer_lines * 3 >= non_trailer_lines) @@ -878,7 +881,6 @@ static size_t find_trailer_start(const char *buf, size_t len) return next_line(bol) - buf; return len; } - only_spaces = 0; for (p = git_generated_prefixes; *p; p++) { if (starts_with(bol, *p)) { From patchwork Sun Oct 25 21:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A850CC388F7 for ; Sun, 25 Oct 2020 22:42:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 840AB222EC for ; Sun, 25 Oct 2020 22:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420315AbgJYWmO (ORCPT ); Sun, 25 Oct 2020 18:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420309AbgJYWmL (ORCPT ); Sun, 25 Oct 2020 18:42:11 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2343C0613D0 for ; Sun, 25 Oct 2020 15:42:10 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-2A; Sun, 25 Oct 2020 22:27:19 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 15/21] trailer: factor out classify_trailer_line Date: Sun, 25 Oct 2020 22:26:46 +0100 Message-Id: <20201025212652.3003036-16-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-2A; Sun, 25 Oct 2020 22:27:19 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 123 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 49 deletions(-) diff --git a/trailer.c b/trailer.c index 937cf1edeb..21877e4c06 100644 --- a/trailer.c +++ b/trailer.c @@ -821,6 +821,53 @@ static size_t find_patch_start(const char *str) return s - str; } +enum trailer_classification { + GIT_GENERATED_PREFIX, + CONFIGURED_TRAILER, + TRAILER, + CONTINUATION, + NON_TRAILER, + COMMENT, + BLANK, +}; + +static enum trailer_classification classify_trailer_line(const char *line) +{ + const char **p; + ssize_t separator_pos; + + if (line[0] == comment_line_char) + return COMMENT; + + if (is_blank_line(line)) + return BLANK; + + if (isspace(line[0])) + return CONTINUATION; + + for (p = git_generated_prefixes; *p; p++) + if (starts_with(line, *p)) + return GIT_GENERATED_PREFIX; + + + separator_pos = find_separator(line, separators); + if (separator_pos >= 1) { + struct list_head *pos; + + list_for_each(pos, &conf_head) { + struct conf_info_item *item; + item = list_entry(pos, struct conf_info_item, list); + if (token_matches_conf(line, &item->conf, + separator_pos)) + return CONFIGURED_TRAILER; + } + + return TRAILER; + } + + return NON_TRAILER; +} + /* * Return the position of the first trailer line or len if there are no * trailers. @@ -864,59 +911,37 @@ static size_t find_trailer_start(const char *buf, size_t len) l >= end_of_title; l = last_line(buf, l)) { const char *bol = buf + l; - const char **p; - ssize_t separator_pos; - if (bol[0] == comment_line_char) { - non_trailer_lines += possible_continuation_lines; - possible_continuation_lines = 0; - continue; - } - if (is_blank_line(bol)) { - non_trailer_lines += possible_continuation_lines; - if (recognized_prefix && - trailer_lines * 3 >= non_trailer_lines) - return next_line(bol) - buf; - else if (trailer_lines && !non_trailer_lines) - return next_line(bol) - buf; - return len; - } - - for (p = git_generated_prefixes; *p; p++) { - if (starts_with(bol, *p)) { + switch (classify_trailer_line(bol)) { + case GIT_GENERATED_PREFIX: + case CONFIGURED_TRAILER: + recognized_prefix = 1; + /* fallthrough */ + case TRAILER: trailer_lines++; possible_continuation_lines = 0; - recognized_prefix = 1; - goto continue_outer_loop; - } - } - - separator_pos = find_separator(bol, separators); - if (separator_pos >= 1 && !isspace(bol[0])) { - struct list_head *pos; - - trailer_lines++; - possible_continuation_lines = 0; - if (recognized_prefix) - continue; - list_for_each(pos, &conf_head) { - struct conf_info_item *item; - item = list_entry(pos, struct conf_info_item, list); - if (token_matches_conf(bol, &item->conf, - separator_pos)) { - recognized_prefix = 1; - break; - } - } - } else if (isspace(bol[0])) - possible_continuation_lines++; - else { - non_trailer_lines++; - non_trailer_lines += possible_continuation_lines; - possible_continuation_lines = 0; + break; + case CONTINUATION: + possible_continuation_lines++; + break; + case NON_TRAILER: + non_trailer_lines++; + non_trailer_lines += possible_continuation_lines; + possible_continuation_lines = 0; + break; + case COMMENT: + non_trailer_lines += possible_continuation_lines; + possible_continuation_lines = 0; + break; + case BLANK: + non_trailer_lines += possible_continuation_lines; + if (recognized_prefix && + trailer_lines * 3 >= non_trailer_lines) + return next_line(bol) - buf; + else if (trailer_lines && !non_trailer_lines) + return next_line(bol) - buf; + return len; } -continue_outer_loop: - ; } return len; From patchwork Sun Oct 25 21:26:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 777DAC4363A for ; Sun, 25 Oct 2020 22:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46021222C2 for ; Sun, 25 Oct 2020 22:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420291AbgJYWmC (ORCPT ); Sun, 25 Oct 2020 18:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420276AbgJYWmA (ORCPT ); Sun, 25 Oct 2020 18:42:00 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06F3CC061755 for ; Sun, 25 Oct 2020 15:42:00 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-7O; Sun, 25 Oct 2020 22:27:19 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 16/21] t7513: add failing test for configured trailing line classification Date: Sun, 25 Oct 2020 22:26:47 +0100 Message-Id: <20201025212652.3003036-17-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-7O; Sun, 25 Oct 2020 22:27:19 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false This testcases shows why prefix matching shouldn't be used when using configured trailers to classify lines as trailers or not. Signed-off-by: Anders Waldenborg --- t/t7513-interpret-trailers.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 4b3a2484b5..b1e9a9e6d1 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -239,6 +239,35 @@ test_expect_success 'with non-trailer lines mixed with a configured trailer' ' test_cmp expected actual ' +# This fails because "c:/windows/tmp/stuff/temp.txt" is classified as +# a trailer line because "c" is a prefix of "Confirmed-By". Therefore +# the new trailer is appended to that (non-trailer) block rather than +# creating a new block. It also canonicalize the "trailer" to +# "Confirmed-By: /windows/tmp/stuff/temp.txt" +test_expect_failure 'with non-trailer lines mixed with prefix of configured trailer' ' + cat >patch <<-\EOF && + some subject + + This is clearly not a trailer line. But + on next line there is a a windows path + c:/windows/tmp/stuff/temp.txt but that + should not make this classify as a trailer block + EOF + cat >expected <<-\EOF && + some subject + + This is clearly not a trailer line. But + on next line there is a a windows path + c:/windows/tmp/stuff/temp.txt but that + should not make this classify as a trailer block + + t: v + EOF + test_config trailer.confirmedby.key "Confirmed-By" && + git interpret-trailers --trailer "t: v" patch >actual && + test_cmp expected actual +' + test_expect_success 'with non-trailer lines mixed with a non-configured trailer' ' cat >patch <<-\EOF && From patchwork Sun Oct 25 21:26:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6168BC388F7 for ; Sun, 25 Oct 2020 22:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35107222EC for ; Sun, 25 Oct 2020 22:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420296AbgJYWmD (ORCPT ); Sun, 25 Oct 2020 18:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420281AbgJYWmB (ORCPT ); Sun, 25 Oct 2020 18:42:01 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72062C0613CE for ; Sun, 25 Oct 2020 15:42:01 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-Oa; Sun, 25 Oct 2020 22:27:19 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 17/21] trailer: don't treat line with prefix of known trailer as known Date: Sun, 25 Oct 2020 22:26:48 +0100 Message-Id: <20201025212652.3003036-18-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-Oa; Sun, 25 Oct 2020 22:27:19 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false E.g if "Closes" is a configured trailer a line starting with "c:" shouldn't be treated as a recognized trailer when looking for trailer block. Signed-off-by: Anders Waldenborg --- t/t7513-interpret-trailers.sh | 7 +------ trailer.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index b1e9a9e6d1..6ddc2f5573 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -239,12 +239,7 @@ test_expect_success 'with non-trailer lines mixed with a configured trailer' ' test_cmp expected actual ' -# This fails because "c:/windows/tmp/stuff/temp.txt" is classified as -# a trailer line because "c" is a prefix of "Confirmed-By". Therefore -# the new trailer is appended to that (non-trailer) block rather than -# creating a new block. It also canonicalize the "trailer" to -# "Confirmed-By: /windows/tmp/stuff/temp.txt" -test_expect_failure 'with non-trailer lines mixed with prefix of configured trailer' ' +test_expect_success 'with non-trailer lines mixed with prefix of configured trailer' ' cat >patch <<-\EOF && some subject diff --git a/trailer.c b/trailer.c index 21877e4c06..d75d240e10 100644 --- a/trailer.c +++ b/trailer.c @@ -831,10 +831,20 @@ enum trailer_classification { BLANK, }; +static int starts_with_separator(const char *buf) +{ + while (*buf == ' ' || *buf == '\t') + buf++; + if (!*buf) + return 0; + return !!strchr(separators, *buf); +} + static enum trailer_classification classify_trailer_line(const char *line) { const char **p; ssize_t separator_pos; + struct list_head *pos; if (line[0] == comment_line_char) return COMMENT; @@ -849,19 +859,17 @@ static enum trailer_classification classify_trailer_line(const char *line) if (starts_with(line, *p)) return GIT_GENERATED_PREFIX; - - separator_pos = find_separator(line, separators); - if (separator_pos >= 1) { - struct list_head *pos; - - list_for_each(pos, &conf_head) { - struct conf_info_item *item; - item = list_entry(pos, struct conf_info_item, list); - if (token_matches_conf(line, &item->conf, - separator_pos)) + list_for_each(pos, &conf_head) { + struct conf_info_item *item = list_entry(pos, struct conf_info_item, list); + const char *conftrailer = item->conf.key ? item->conf.key : item->conf.name; + if (istarts_with(line, conftrailer)) { + if (starts_with_separator (line + strlen (conftrailer))) return CONFIGURED_TRAILER; } + } + separator_pos = find_separator(line, separators); + if (separator_pos >= 1) { return TRAILER; } From patchwork Sun Oct 25 21:26:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75553C388F7 for ; Sun, 25 Oct 2020 22:42:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 475CE222EC for ; Sun, 25 Oct 2020 22:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420317AbgJYWmO (ORCPT ); Sun, 25 Oct 2020 18:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420307AbgJYWmJ (ORCPT ); Sun, 25 Oct 2020 18:42:09 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D5BC0613CE for ; Sun, 25 Oct 2020 15:42:08 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-Um; Sun, 25 Oct 2020 22:27:19 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 18/21] trailer: factor out config lookup to separate function Date: Sun, 25 Oct 2020 22:26:49 +0100 Message-Id: <20201025212652.3003036-19-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXr-0007u5-Um; Sun, 25 Oct 2020 22:27:19 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/trailer.c b/trailer.c index d75d240e10..02061877b4 100644 --- a/trailer.c +++ b/trailer.c @@ -605,6 +605,20 @@ static int token_matches_conf(const char *tok, const struct conf_info *conf, siz return conf->key ? !strncasecmp(tok, conf->key, tok_len) : 0; } +static const struct conf_info *lookup_conf_for_tok(const struct strbuf *tok) +{ + struct conf_info_item *item; + struct list_head *pos; + + list_for_each(pos, &conf_head) { + item = list_entry(pos, struct conf_info_item, list); + if (token_matches_conf(tok->buf, &item->conf, tok->len)) { + return &item->conf; + } + } + return &default_conf_info; +} + /* * If the given line is of the form * "..." or "...", return the @@ -645,9 +659,6 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, struct strbuf const struct conf_info **conf, const char *trailer, ssize_t separator_pos) { - struct conf_info_item *item; - struct list_head *pos; - if (separator_pos != -1) { size_t sep_spacing_begin = separator_pos; size_t sep_spacing_end = separator_pos + 1; @@ -667,17 +678,8 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, struct strbuf strbuf_trim(tok); } - /* Lookup if the token matches something in the config */ if (conf) - *conf = &default_conf_info; - list_for_each(pos, &conf_head) { - item = list_entry(pos, struct conf_info_item, list); - if (token_matches_conf(tok->buf, &item->conf, tok->len)) { - if (conf) - *conf = &item->conf; - break; - } - } + *conf = lookup_conf_for_tok (tok); } static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, From patchwork Sun Oct 25 21:26:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72A19C388F7 for ; Sun, 25 Oct 2020 22:41:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49EF9222EC for ; Sun, 25 Oct 2020 22:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420254AbgJYWlr (ORCPT ); Sun, 25 Oct 2020 18:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1418775AbgJYWlq (ORCPT ); Sun, 25 Oct 2020 18:41:46 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC11C061755 for ; Sun, 25 Oct 2020 15:41:46 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-31; Sun, 25 Oct 2020 22:27:20 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 19/21] trailer: move config lookup out of parse_trailer Date: Sun, 25 Oct 2020 22:26:50 +0100 Message-Id: <20201025212652.3003036-20-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-31; Sun, 25 Oct 2020 22:27:20 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false This may be seen as making it worse adding code duplication. But will hopefully make different handling for config lookups easier. No functional change intended. Signed-off-by: Anders Waldenborg --- trailer.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/trailer.c b/trailer.c index 02061877b4..0db3bba3b1 100644 --- a/trailer.c +++ b/trailer.c @@ -656,8 +656,7 @@ static ssize_t find_separator(const char *line, const char *separators) * If separator_pos is -1, interpret the whole trailer as a token. */ static void parse_trailer(struct strbuf *tok, struct strbuf *val, struct strbuf *sep, - const struct conf_info **conf, const char *trailer, - ssize_t separator_pos) + const char *trailer, ssize_t separator_pos) { if (separator_pos != -1) { size_t sep_spacing_begin = separator_pos; @@ -677,9 +676,6 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val, struct strbuf strbuf_addstr(tok, trailer); strbuf_trim(tok); } - - if (conf) - *conf = lookup_conf_for_tok (tok); } static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, @@ -752,8 +748,9 @@ static void process_command_line_args(struct list_head *arg_head, (int) sb.len, sb.buf); strbuf_release(&sb); } else { - parse_trailer(&tok, &val, NULL, &conf, tr->text, + parse_trailer(&tok, &val, NULL, tr->text, separator_pos); + conf = lookup_conf_for_tok(&tok); add_arg_item(arg_head, strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL), @@ -1026,8 +1023,9 @@ static size_t process_input_file(FILE *outfile, separator_pos = find_separator(trailer, separators); if (separator_pos >= 1) { const struct conf_info *conf; - parse_trailer(&tok, &val, &sep, &conf, trailer, + parse_trailer(&tok, &val, &sep, trailer, separator_pos); + conf = lookup_conf_for_tok(&tok); if (opts->unfold) unfold_value(&val); add_trailer_item(head, @@ -1221,7 +1219,8 @@ static void format_trailer_info(struct strbuf *out, const struct conf_info *conf; - parse_trailer(&tok, &val, NULL, &conf, trailer, separator_pos); + parse_trailer(&tok, &val, NULL, trailer, separator_pos); + conf = lookup_conf_for_tok(&tok); if (!opts->filter || opts->filter(&tok, conf ? conf->name : NULL, opts->filter_data)) { if (opts->unfold) @@ -1282,7 +1281,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) strbuf_reset(&iter->key); strbuf_reset(&iter->val); - parse_trailer(&iter->key, &iter->val, NULL, NULL, + parse_trailer(&iter->key, &iter->val, NULL, trailer, separator_pos); unfold_value(&iter->val); return 1; From patchwork Sun Oct 25 21:26:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 365BEC4363A for ; Sun, 25 Oct 2020 22:41:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02852222EC for ; Sun, 25 Oct 2020 22:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420259AbgJYWlt (ORCPT ); Sun, 25 Oct 2020 18:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1418775AbgJYWls (ORCPT ); Sun, 25 Oct 2020 18:41:48 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA7AC061755 for ; Sun, 25 Oct 2020 15:41:48 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-8E; Sun, 25 Oct 2020 22:27:20 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 20/21] trailer: add failing tests for matching trailers against input Date: Sun, 25 Oct 2020 22:26:51 +0100 Message-Id: <20201025212652.3003036-21-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-8E; Sun, 25 Oct 2020 22:27:20 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false These tests shows problematic cases where input trailers matches config. Signed-off-by: Anders Waldenborg --- t/t7513-interpret-trailers.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 6ddc2f5573..a99d6d7e3b 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -151,6 +151,41 @@ test_expect_success 'spelling and separators are not canonicalized with --parse test_cmp expected actual ' +# Matching currently is prefix matching, causing "This-trailer" to be normalized too +test_expect_failure 'config option matches exact only' ' + cat >patch <<-\EOF && + + This-trailer: a + b + This-trailer-exact: b + c + This-trailer-exact-plus-some: c + d + EOF + cat >expected <<-\EOF && + This-trailer: a b + THIS-TRAILER-EXACT: b c + This-trailer-exact-plus-some: c d + EOF + git -c "trailer.tte.key=THIS-TRAILER-EXACT" interpret-trailers --only-input --only-trailers --unfold patch >actual && + test_cmp expected actual +' + +# Matching currently uses the config key even if key value is different +test_expect_failure 'config option matches exact only' ' + cat >patch <<-\EOF && + + Ticket: 1234 + Reference-ticket: 99 + EOF + cat >expected <<-\EOF && + Ticket: 1234 + Reference-Ticket: 99 + EOF + git -c "trailer.ticket.key=Reference-Ticket" interpret-trailers --only-input --only-trailers patch >actual && + test_cmp expected actual +' + test_expect_success 'with only a title in the message' ' cat >expected <<-\EOF && area: change From patchwork Sun Oct 25 21:26:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Waldenborg X-Patchwork-Id: 11855557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65903C4363A for ; Sun, 25 Oct 2020 22:42:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D135222EC for ; Sun, 25 Oct 2020 22:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1420332AbgJYWmT (ORCPT ); Sun, 25 Oct 2020 18:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1420303AbgJYWmH (ORCPT ); Sun, 25 Oct 2020 18:42:07 -0400 Received: from 0x63.nu (0x63.nu [IPv6:2a02:750:9::199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B073C061755 for ; Sun, 25 Oct 2020 15:42:07 -0700 (PDT) Received: from ip6-localhost ([::1] helo=localhost.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-DU; Sun, 25 Oct 2020 22:27:20 +0100 From: Anders Waldenborg To: git@vger.kernel.org Cc: Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com Subject: [PATCH 21/21] trailer: only do prefix matching for configured trailers on commandline Date: Sun, 25 Oct 2020 22:26:52 +0100 Message-Id: <20201025212652.3003036-22-anders@0x63.nu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201025212652.3003036-1-anders@0x63.nu> References: <20201025212652.3003036-1-anders@0x63.nu> MIME-Version: 1.0 X-SA-Exim-Connect-IP: ::1 X-SA-Exim-Mail-From: anders@0x63.nu X-SA-Exim-Scanned: No (on st.localdomain) by 0x63.nu with esmtp (Exim 4.90_1) (envelope-from ) id 1kWnXs-0007u5-DU; Sun, 25 Oct 2020 22:27:20 +0100 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org ); SAEximRunCond expanded to false If there is a trailer "foobar" in configuration a trailer "foo" in input shouldn't match that, except in `--trailer` arguments as a shortcut. Signed-off-by: Anders Waldenborg --- t/t7513-interpret-trailers.sh | 17 +++++++++++++---- trailer.c | 14 +++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index a99d6d7e3b..9e06fa4454 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -151,8 +151,7 @@ test_expect_success 'spelling and separators are not canonicalized with --parse test_cmp expected actual ' -# Matching currently is prefix matching, causing "This-trailer" to be normalized too -test_expect_failure 'config option matches exact only' ' +test_expect_success 'config option matches exact only' ' cat >patch <<-\EOF && This-trailer: a @@ -171,8 +170,7 @@ test_expect_failure 'config option matches exact only' ' test_cmp expected actual ' -# Matching currently uses the config key even if key value is different -test_expect_failure 'config option matches exact only' ' +test_expect_success 'config option matches exact only' ' cat >patch <<-\EOF && Ticket: 1234 @@ -550,6 +548,17 @@ test_expect_success 'with config setup' ' test_cmp expected actual ' +test_expect_success 'trailer on commandline can be prefix of configured' ' + cat >expected <<-\EOF && + + Acked-by: 10 + EOF + git interpret-trailers --trailer "A=10" empty >actual && + test_cmp expected actual +' + + + test_expect_success 'with config setup and ":=" as separators' ' git config trailer.separators ":=" && git config trailer.ack.key "Acked-by= " && diff --git a/trailer.c b/trailer.c index 0db3bba3b1..b00b35ea0e 100644 --- a/trailer.c +++ b/trailer.c @@ -605,14 +605,18 @@ static int token_matches_conf(const char *tok, const struct conf_info *conf, siz return conf->key ? !strncasecmp(tok, conf->key, tok_len) : 0; } -static const struct conf_info *lookup_conf_for_tok(const struct strbuf *tok) +static const struct conf_info *lookup_conf_for_tok(const struct strbuf *tok, int strict) { struct conf_info_item *item; struct list_head *pos; list_for_each(pos, &conf_head) { item = list_entry(pos, struct conf_info_item, list); - if (token_matches_conf(tok->buf, &item->conf, tok->len)) { + if (strict) { + const char *match = item->conf.key ? item->conf.key : item->conf.name; + if (!strcasecmp(match, tok->buf)) + return &item->conf; + } else if (token_matches_conf(tok->buf, &item->conf, tok->len)) { return &item->conf; } } @@ -750,7 +754,7 @@ static void process_command_line_args(struct list_head *arg_head, } else { parse_trailer(&tok, &val, NULL, tr->text, separator_pos); - conf = lookup_conf_for_tok(&tok); + conf = lookup_conf_for_tok(&tok, 0); add_arg_item(arg_head, strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL), @@ -1025,7 +1029,7 @@ static size_t process_input_file(FILE *outfile, const struct conf_info *conf; parse_trailer(&tok, &val, &sep, trailer, separator_pos); - conf = lookup_conf_for_tok(&tok); + conf = lookup_conf_for_tok(&tok, 1); if (opts->unfold) unfold_value(&val); add_trailer_item(head, @@ -1220,7 +1224,7 @@ static void format_trailer_info(struct strbuf *out, const struct conf_info *conf; parse_trailer(&tok, &val, NULL, trailer, separator_pos); - conf = lookup_conf_for_tok(&tok); + conf = lookup_conf_for_tok(&tok, 1); if (!opts->filter || opts->filter(&tok, conf ? conf->name : NULL, opts->filter_data)) { if (opts->unfold)