From patchwork Sat Sep 9 06:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11099EEB580 for ; Sat, 9 Sep 2023 06:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235280AbjIIGQ0 (ORCPT ); Sat, 9 Sep 2023 02:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbjIIGQZ (ORCPT ); Sat, 9 Sep 2023 02:16:25 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ED281BEA for ; Fri, 8 Sep 2023 23:16:21 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401da71b7c5so31121915e9.2 for ; Fri, 08 Sep 2023 23:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240180; x=1694844980; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+QYVVdHrPAWl2KKMbyC9DOr1zeJak0o0M7WgUlM5b6c=; b=X+fXcxZY/krVyh+BPh+XDtx7pPMaD8R6J6hQvo1M2MEcCcZasYokcvtByLXGgQr2Kj oCfXe0DvuQ4aITsJAMkZmaO+Svg29A6BXuH9Bu//Mb3zXLeLI/J0IXk6CXVDqE9viA8V MV1Pjhp0vDid7Vyp3d5DPZ3vAHpUhoLJ2Zgqq30B2TCvbI2tZS1cvdwMTkwCIJcIHjaP M6qjVBJ6I3jg57ju+ZwoDFW1lM0fpfw6dIzgn8+Ov7IFuqkftfz97p6LRb9mGJ5PlWkc h+eDga/ViuQYPbyPSRcA3BI7LA6WvDP48K9e/AARLVsyICZZsmJmBNxnD6Sl+KWj3oov ljLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240180; x=1694844980; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+QYVVdHrPAWl2KKMbyC9DOr1zeJak0o0M7WgUlM5b6c=; b=mC4wdFFfQiaymgqQnNoJIqavFk/I67w+tlO7f7Lo/t+ydhYLi0MXen+AgPt1i+YZhb +UMcgtbFeNOpt5nLf8Dtens2il6zDrCFNqfRxw33vkOEYimxk36mqq8I3KI1WsACRo6Z YO4KKZU49Ls1X3FQ+0JMff9LsbXO0y1AaFz+AJ/EA7FmsM10Pgw/ESmnHuPuV4fYWzbV tE1nz6KGDgJ9j2hezBzbO+ts9J0t8ADHD0+b1ZJHShCzS1oNHOB5ACW6Y4d5JT+cHsms EnHNLip+vakbr+zU3fDqiYYDL61f2iYP8dxMRqj+FJNtcepoYPL98/gzGNl06OQtive4 CY8Q== X-Gm-Message-State: AOJu0YzIwjyMvAlL+8EQfKfqlV+ki8H77EUXQnDeTXueWoA8zVfCdwtR XL7JdtVsBrIEI73e8gWS9nHQvL0wOXo= X-Google-Smtp-Source: AGHT+IFwNjYkJTadWXiDpnxx3rTpIIzZCq5u7d/FHmznAYjVR3+LaUQa3ADQKhU48jkZ44QvZeeQiQ== X-Received: by 2002:a1c:4b03:0:b0:401:264b:5df7 with SMTP id y3-20020a1c4b03000000b00401264b5df7mr3821786wma.35.1694240179461; Fri, 08 Sep 2023 23:16:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f7-20020a7bcd07000000b00401c595fcc7sm6899922wmj.11.2023.09.08.23.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:19 -0700 (PDT) Message-ID: <4f116d2550f6cf218477560a9e25dbe4c384a2a6.1694240177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:12 +0000 Subject: [PATCH v2 1/6] trailer: separate public from internal portion of trailer_iterator Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver The fields here are not meant to be used by downstream callers, so put them behind an anonymous struct named as "internal" to warn against their use. This follows the pattern in 576de3d956 (unpack_trees: start splitting internal fields from public API, 2023-02-27). Signed-off-by: Linus Arver --- trailer.c | 10 +++++----- trailer.h | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/trailer.c b/trailer.c index f408f9b058d..de4bdece847 100644 --- a/trailer.c +++ b/trailer.c @@ -1220,14 +1220,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) strbuf_init(&iter->key, 0); strbuf_init(&iter->val, 0); opts.no_divider = 1; - trailer_info_get(&iter->info, msg, &opts); - iter->cur = 0; + trailer_info_get(&iter->internal.info, msg, &opts); + iter->internal.cur = 0; } int trailer_iterator_advance(struct trailer_iterator *iter) { - while (iter->cur < iter->info.trailer_nr) { - char *trailer = iter->info.trailers[iter->cur++]; + while (iter->internal.cur < iter->internal.info.trailer_nr) { + char *trailer = iter->internal.info.trailers[iter->internal.cur++]; int separator_pos = find_separator(trailer, separators); if (separator_pos < 1) @@ -1245,7 +1245,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) void trailer_iterator_release(struct trailer_iterator *iter) { - trailer_info_release(&iter->info); + trailer_info_release(&iter->internal.info); strbuf_release(&iter->val); strbuf_release(&iter->key); } diff --git a/trailer.h b/trailer.h index 795d2fccfd9..ab2cd017567 100644 --- a/trailer.h +++ b/trailer.h @@ -119,8 +119,10 @@ struct trailer_iterator { struct strbuf val; /* private */ - struct trailer_info info; - size_t cur; + struct { + struct trailer_info info; + size_t cur; + } internal; }; /* From patchwork Sat Sep 9 06:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91046EEB581 for ; Sat, 9 Sep 2023 06:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237543AbjIIGQ1 (ORCPT ); Sat, 9 Sep 2023 02:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbjIIGQ0 (ORCPT ); Sat, 9 Sep 2023 02:16:26 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F195B1BC5 for ; Fri, 8 Sep 2023 23:16:21 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-403012f276dso4176475e9.0 for ; Fri, 08 Sep 2023 23:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240180; x=1694844980; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3R6TUptbEq8L+7sFDFnVsmQFyJZ01GJ9BerfsfkEvVw=; b=dVFHUDRaSFGx0z6s07hYlNS/pyCPK0AMEHVduVitZq4FVn6nQYWtU+FMxiIq380oZI 4foo1j+xNQT844g5K72SzgXL21TP4HpNqur5Op98lkq/0iYfEhtI9OAvqhcRasWdcTTU IiMBhOehEROF7Hrxvs7vNdh/hGWy3qElEY02HiRAbsr9xRmsvY8TGn+bjwf2PLL9Avcu CsIHaLbSKIF0GOPOamUhUvg/f6y5otvD2nc9cDJxVy0YzSheKwsnPB0fn7P0WWi3fghX 2bCWgQoN/T27IFEJ082qLInH4TUGC4UbvvAM3RzkCgegOOR2lZiD7FFEexmzQ3zcwFUQ cDfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240180; x=1694844980; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3R6TUptbEq8L+7sFDFnVsmQFyJZ01GJ9BerfsfkEvVw=; b=N0FO1+moCrLDB+98BcSS+VW6XDZaZalwBICCSPwaVn8WNqSlH4cRifFS/H10jHvkAW uvwYI8MyiS91t5S30DNQC2K6GzP7nIBTS7NHXH3iWX9yF4rfgnEswZAdwR9p9FX85rvG m1L5f6r9p7KqEBF31nxioIX5HxijXTZ5d3Po7tYYDDwKqtgsp0ZHHnmWvemWcp7ENRva 8ADYlByaLoMBR5LVXl6X7WvV4zOlqVsvZ/MEQ3FPCUsufbM2ln1WVe9h3Gpt2r3JtNPs 1Yph/ZfbsoM3JxzZUewKBQqSYx/rB8RWmfjN0VdVOujkCghIU6KGEHuYzvrtym167Dk+ HIIw== X-Gm-Message-State: AOJu0Yz/ZJl3uLHFNTZQfiN2dAHXsZk7Geg5MmeGWzwj/Cd/EFaaIJ/w qNWOAWAFGOhhKd+UA9yrV9Hc+2Ol55E= X-Google-Smtp-Source: AGHT+IEo3A/wCZ16UoBcr+LOZ0b64oyb+QBIj89uLbI9n5j0vlNtE3H2i0EV2GGUokZUhV2he9Y/Ww== X-Received: by 2002:a05:600c:d3:b0:402:95a0:b2ae with SMTP id u19-20020a05600c00d300b0040295a0b2aemr3520447wmm.32.1694240180032; Fri, 08 Sep 2023 23:16:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u5-20020a05600c00c500b003fe2de3f94fsm3640215wmm.12.2023.09.08.23.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:19 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:13 +0000 Subject: [PATCH v2 2/6] trailer: split process_input_file into separate pieces Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver Currently, process_input_file does three things: (1) parse the input string for trailers, (2) print text before the trailers, and (3) calculate the position of the input where the trailers end. Rename this function to parse_trailers(), and make it only do (1). The caller of this function, process_trailers, becomes responsible for (2) and (3). These items belong inside process_trailers because they are both concerned with printing the surrounding text around trailers (which is already one of the immediate concerns of process_trailers). Signed-off-by: Linus Arver --- trailer.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/trailer.c b/trailer.c index de4bdece847..2c56cbc4a2e 100644 --- a/trailer.c +++ b/trailer.c @@ -961,28 +961,24 @@ static void unfold_value(struct strbuf *val) strbuf_release(&out); } -static size_t process_input_file(FILE *outfile, - const char *str, - struct list_head *head, - const struct process_trailer_options *opts) +/* + * Parse trailers in "str", populating the trailer info and "head" + * linked list structure. + */ +static void parse_trailers(struct trailer_info *info, + const char *str, + struct list_head *head, + const struct process_trailer_options *opts) { - struct trailer_info info; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; size_t i; - trailer_info_get(&info, str, opts); - - /* Print lines before the trailers as is */ - if (!opts->only_trailers) - fwrite(str, 1, info.trailer_start - str, outfile); + trailer_info_get(info, str, opts); - if (!opts->only_trailers && !info.blank_line_before_trailer) - fprintf(outfile, "\n"); - - for (i = 0; i < info.trailer_nr; i++) { + for (i = 0; i < info->trailer_nr; i++) { int separator_pos; - char *trailer = info.trailers[i]; + char *trailer = info->trailers[i]; if (trailer[0] == comment_line_char) continue; separator_pos = find_separator(trailer, separators); @@ -1002,10 +998,6 @@ static size_t process_input_file(FILE *outfile, strbuf_detach(&val, NULL)); } } - - trailer_info_release(&info); - - return info.trailer_end - str; } static void free_all(struct list_head *head) @@ -1054,6 +1046,7 @@ void process_trailers(const char *file, { LIST_HEAD(head); struct strbuf sb = STRBUF_INIT; + struct trailer_info info; size_t trailer_end; FILE *outfile = stdout; @@ -1064,8 +1057,16 @@ void process_trailers(const char *file, if (opts->in_place) outfile = create_in_place_tempfile(file); + parse_trailers(&info, sb.buf, &head, opts); + trailer_end = info.trailer_end - sb.buf; + /* Print the lines before the trailers */ - trailer_end = process_input_file(outfile, sb.buf, &head, opts); + if (!opts->only_trailers) + fwrite(sb.buf, 1, info.trailer_start - sb.buf, outfile); + + if (!opts->only_trailers && !info.blank_line_before_trailer) + fprintf(outfile, "\n"); + if (!opts->only_input) { LIST_HEAD(arg_head); @@ -1076,6 +1077,7 @@ void process_trailers(const char *file, print_all(outfile, &head, opts); free_all(&head); + trailer_info_release(&info); /* Print the lines after the trailers as is */ if (!opts->only_trailers) From patchwork Sat Sep 9 06:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA6A6EEB57F for ; Sat, 9 Sep 2023 06:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239991AbjIIGQa (ORCPT ); Sat, 9 Sep 2023 02:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235990AbjIIGQ0 (ORCPT ); Sat, 9 Sep 2023 02:16:26 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C8B1BEE for ; Fri, 8 Sep 2023 23:16:22 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-401b393df02so32034755e9.1 for ; Fri, 08 Sep 2023 23:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240181; x=1694844981; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8oqDlv0pYbnxTSwUOs2MM78aq6xaarznF51jwKGW4Rk=; b=AYKooOcrufu5C1/ip1l+MOcH1ywI6ObKvDPY/6LY6JRiUkfN+aMbASuZi8zS6QlF0t TQ59cGG2s1xchBiSNJbi/XPaZLYmV71AgE0AL3AtL0AuY7CfARSZL6WiDuePiUoWV9xS QW4YuqQLI29YLCbCXmOe0Ha6LW/Ag5B/Z6ssG+JUNt6tIU18PL4Eeb9YIIv95cOBZgTn 5nh90y/aSpFFKlxglXQkqA9VUkFv/IqqryBn2fQW0nB8oGdBb2WEU9rAHstxp7AuopRl LF3TSnjbNyvWDs589YrSEsLoNTL7g9Wws24YH7Uz6EwK3BhDEBnubs+siTcyMDQcmzJH /GVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240181; x=1694844981; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8oqDlv0pYbnxTSwUOs2MM78aq6xaarznF51jwKGW4Rk=; b=QzzpaOnK6fe64/+c4Bz7uGrb17KV8mJi+A0H3zPruzA8CqXuYDRgxOo8eeL2/Fjeos gBMDzS1bxyONfAaD9gsPEW9FTvneeLsWmG8r45+3kUntBRheoslNnVtMoy7lXP5XigkV MQE0UaQUrfitSwrdFR0jcQ7pHMqnL8cDHA2ZRxtsssWw2tdwutV489SYvFvDQVDPVJ0W LZZ51n4tjRiVS9JSO7+gguJv90C/srKOvfxq9XuqTQbPfYGp3/uIlVwI+wAI4XTqd0JC To6vCPlKXW1+uEMRnBk4E06BNoAetW+bWK8oJJIggfLosHJhl/HheKXdivTNT1bfwxgJ YgUg== X-Gm-Message-State: AOJu0Yw2yuE4mJIafKn/mjeTgKO/V4ysMnPqr1viz8KkpwiyVBuHr6gN NGL/lUc4PkMVrgNPGdm2LO5Ai4IEETk= X-Google-Smtp-Source: AGHT+IHSgL4iv/aOdLe2E87JTJZhpEEXYCXzApd7RuYNh8+bHvdqeJetkNjRyHvJyK0wRlMKP8AO/w== X-Received: by 2002:a1c:ed08:0:b0:401:d803:6242 with SMTP id l8-20020a1ced08000000b00401d8036242mr3840042wmh.27.1694240180957; Fri, 08 Sep 2023 23:16:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w3-20020a05600c014300b003fefe70ec9csm6857951wmm.10.2023.09.08.23.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:20 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:14 +0000 Subject: [PATCH v2 3/6] trailer: split process_command_line_args into separate functions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver Previously, process_command_line_args did two things: (1) parse trailers from the configuration, and (2) parse trailers defined on the command line. Separate (1) outside to a new function, parse_trailers_from_config. Rename the remaining logic to parse_trailers_from_command_line_args. Signed-off-by: Linus Arver --- trailer.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/trailer.c b/trailer.c index 2c56cbc4a2e..b6de5d9cb2d 100644 --- a/trailer.c +++ b/trailer.c @@ -711,30 +711,35 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val, list_add_tail(&new_item->list, arg_head); } -static void process_command_line_args(struct list_head *arg_head, - struct list_head *new_trailer_head) +static void parse_trailers_from_config(struct list_head *config_head) { struct arg_item *item; - struct strbuf tok = STRBUF_INIT; - struct strbuf val = STRBUF_INIT; - const struct conf_info *conf; struct list_head *pos; - /* - * In command-line arguments, '=' is accepted (in addition to the - * separators that are defined). - */ - char *cl_separators = xstrfmt("=%s", separators); - /* 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); if (item->conf.command) - add_arg_item(arg_head, + add_arg_item(config_head, xstrdup(token_from_item(item, NULL)), xstrdup(""), &item->conf, NULL); } +} + +static void parse_trailers_from_command_line_args(struct list_head *arg_head, + struct list_head *new_trailer_head) +{ + struct strbuf tok = STRBUF_INIT; + struct strbuf val = STRBUF_INIT; + const struct conf_info *conf; + struct list_head *pos; + + /* + * In command-line arguments, '=' is accepted (in addition to the + * separators that are defined). + */ + char *cl_separators = xstrfmt("=%s", separators); /* Add an arg item for each trailer on the command line */ list_for_each(pos, new_trailer_head) { @@ -1069,8 +1074,11 @@ void process_trailers(const char *file, if (!opts->only_input) { + LIST_HEAD(config_head); LIST_HEAD(arg_head); - process_command_line_args(&arg_head, new_trailer_head); + parse_trailers_from_config(&config_head); + parse_trailers_from_command_line_args(&arg_head, new_trailer_head); + list_splice(&config_head, &arg_head); process_trailers_lists(&head, &arg_head); } From patchwork Sat Sep 9 06:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41962EEB57F for ; Sat, 9 Sep 2023 06:16:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235990AbjIIGQd (ORCPT ); Sat, 9 Sep 2023 02:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233290AbjIIGQ1 (ORCPT ); Sat, 9 Sep 2023 02:16:27 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DE291BD3 for ; Fri, 8 Sep 2023 23:16:23 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-401b5516104so29327205e9.2 for ; Fri, 08 Sep 2023 23:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240181; x=1694844981; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=G0clGRogIIw7XeXpgA3wV1NJMDeWtrzEiRUflXCU6ms=; b=a8MRNz3Xm0faz+ILIcGEJ7BTljjTcjAH6SX7cso6y1sRiY4O5GqsmbZ9orCcAIMZ3X IO6QKwlULmuCXXQp9MDJRapnJeN61OEGNSRqWQ++pz1GEfqutyDeezkddOye5jS70JYS IRs4nRdzsFcZvJz/sdNwbvddTEgN7II2emjGZb5UnTjEvLn2JjRrYFFFDR5w4rx9CB9E YC1Op6J9IphQxHtDAciOmat1swTmyx8hGFFUf+94rVBwLx2VxO1Fpd6AACdrlyjnR8hW X8RioeKjthsZAyLuVSUkT8+wIcTfeUj7jgzKZn/OB6oMdnL+XibZosYG7AOggsXZ7if2 lpkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240181; x=1694844981; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G0clGRogIIw7XeXpgA3wV1NJMDeWtrzEiRUflXCU6ms=; b=hnk0rMiffAOCG6vrRRRNiFYtxvLNpwEJJXB5VD3I2kqkP4v6gkB8XEbnsUeZxvsf0s HMo9VDXUFHkI1B5c3EFG8ppgUsyVmUet6kOkcEJhHm0MvouIHdsnR4JL+WNPhmOkEm8+ HPX6A3hM4wBgZ5uwfGdbFs5OUyEOi4nJtFjs846e6tmwHyowY5F7Kv7t6EmbEhMKi/ms IpikWAJ2qtNFD4tRoi2qdwF0FFIOeahZNWUbDmdNHt4t4jlsmWBa3AUlNby0LqUV6LAR mytURVy2joXhwTORO5K0QjwtmAPbDeMgitkG1clV59sJSE49sl1S6l28hj192fVIgyym m0pA== X-Gm-Message-State: AOJu0YwdAjg9Pd6HTht7+dl+sdL6Jfcm3vSsGD7qo2TTR0QcOxlfZsTm pQ4fR5mDToc331Kkk1lPi2RsP7wDH44= X-Google-Smtp-Source: AGHT+IFdT0zwBqkUR7aWBmOf0r7gUKF+VemEmvT2wqDE/C1BuqY4yp82VQgJU+/DpnuQQ91hocVNdg== X-Received: by 2002:a05:600c:3b1f:b0:401:b204:3b85 with SMTP id m31-20020a05600c3b1f00b00401b2043b85mr3436554wms.36.1694240181664; Fri, 08 Sep 2023 23:16:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c249200b003fe1a96845bsm6922256wms.2.2023.09.08.23.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:21 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:15 +0000 Subject: [PATCH v2 4/6] trailer: teach find_patch_start about --no-divider Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver Currently, find_patch_start only finds the start of the patch part of the input (by looking at the "---" divider) for cases where the "--no-divider" flag has not been provided. If the user provides this flag, we do not rely on find_patch_start at all and just call strlen() directly on the input. Instead, make find_patch_start aware of "--no-divider" and make it handle that case as well. This means we no longer need to call strlen at all and can just rely on the existing code in find_patch_start. By forcing callers to consider this important option, we avoid the kind of mistake described in be3d654343 (commit: pass --no-divider to interpret-trailers, 2023-06-17). This patch will make unit testing a bit more pleasant in this area in the future when we adopt a unit testing framework, because we would not have to test multiple functions to check how finding the start of a patch part works (we would only need to test find_patch_start). Signed-off-by: Linus Arver --- trailer.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/trailer.c b/trailer.c index b6de5d9cb2d..f646e484a23 100644 --- a/trailer.c +++ b/trailer.c @@ -812,14 +812,14 @@ static ssize_t last_line(const char *buf, size_t len) * Return the position of the start of the patch or the length of str if there * is no patch in the message. */ -static size_t find_patch_start(const char *str) +static size_t find_patch_start(const char *str, int no_divider) { const char *s; for (s = str; *s; s = next_line(s)) { const char *v; - if (skip_prefix(s, "---", &v) && isspace(*v)) + if (!no_divider && skip_prefix(s, "---", &v) && isspace(*v)) return s - str; } @@ -1109,11 +1109,7 @@ void trailer_info_get(struct trailer_info *info, const char *str, ensure_configured(); - if (opts->no_divider) - patch_start = strlen(str); - else - patch_start = find_patch_start(str); - + patch_start = find_patch_start(str, opts->no_divider); trailer_end = find_trailer_end(str, patch_start); trailer_start = find_trailer_start(str, trailer_end); From patchwork Sat Sep 9 06:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2789EEB57F for ; Sat, 9 Sep 2023 06:16:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241512AbjIIGQg (ORCPT ); Sat, 9 Sep 2023 02:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238338AbjIIGQ2 (ORCPT ); Sat, 9 Sep 2023 02:16:28 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6535B1BC5 for ; Fri, 8 Sep 2023 23:16:24 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401d24f1f27so30844245e9.1 for ; Fri, 08 Sep 2023 23:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240182; x=1694844982; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=S9TBO22WdmhUcup4vB+50zpiXLDf7pi6UKvkIeRRTsQ=; b=eCnKfkhnL8VFtCVBhD+A92OpOyN7hWrMN9LjkGbGaZblgf8s2zOpsB+t1Qf0YcRW8A DQ2oyQV3pLiZxbpsAbRRk93ASh8BxdFH2VEsrzjRpofLdEI6YcHf1Iy4DFXj3kvnJ0z8 TJEyF/OT7og3c5YYcXRrodbaCE5PUfBIC+WSb8XD/spxot1ysVN9/Ush7TuoQJ6Mosb2 XQ7Ln5b08D54EiC7sExgnwPdO38slHzrKKRCl5LYblL8xJBFpWwpF9fNdQCmGOUV179o nZDV5ApYB7M2vr9zxhQt7b3psTLhSKjoDdRTWhq7o/nFbiyLpY5wwHM8HkHkZ7nIG/Tz JTmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240182; x=1694844982; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S9TBO22WdmhUcup4vB+50zpiXLDf7pi6UKvkIeRRTsQ=; b=nYa+YlZQz3f1ffl7RrQIhrJo3UCmYxqrr36dmTPMCcJO2iuI6FDqlxD91qC5nfRb4u OgsINCY3TIN4k/yjag5EzPkaq6SUBjOBpsxawydp7EJD6qMMjMGDta6BHmWmaeOH9TkD LjJd758Wa8X/unyaPuo3iEJ4NvQtx6iKwov8qaQDzPh5VEjr52PAaXsy68RyhXazE5FE ydtFXTulT1jD9Ra7hFG4Xvb11YNzGIF07K4twacFuIrIfPiAHN831cxV6fiJ+tE4PU00 lY7hMYxhx4NCFYbXuGspkkcXm2KY4bvMu4GsyGwbgRurnWra7wSFpGKlXBL1sXtKFRCg 0Uug== X-Gm-Message-State: AOJu0Yw5wdVPIzqowfN9tpZ2HakuwwljUyouxn4OLkxHR4IZMMU4Dmgz eV/um9M/e8dZR3ORVgmX9J0PXt7epu8= X-Google-Smtp-Source: AGHT+IFwgCEUDH3y9uQIhABHNhegEBgNdIa1Lww/MayM9lAWMGvTHKDk1wSZzSspUDj3vlqrKJq7BQ== X-Received: by 2002:a7b:c01a:0:b0:401:d3dd:c3c with SMTP id c26-20020a7bc01a000000b00401d3dd0c3cmr3590582wmb.39.1694240182407; Fri, 08 Sep 2023 23:16:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p11-20020a1c740b000000b003ff013a4fd9sm3701856wmc.7.2023.09.08.23.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:22 -0700 (PDT) Message-ID: <52958c3557c34992df59e9c10f098f457526702c.1694240177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:16 +0000 Subject: [PATCH v2 5/6] trailer: rename *_DEFAULT enums to *_UNSPECIFIED Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver Do not use *_DEFAULT as a suffix to the enums, because the word "default" is overloaded. The following are two examples of the ambiguity of the word "default": (1) "Default" can mean using the "default" values that are hardcoded in trailer.c as default_conf_info.where = WHERE_END; default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR; default_conf_info.if_missing = MISSING_ADD; in ensure_configured(). These values are referred to as "the default" in the docs for interpret-trailers. These defaults are used if no "trailer.*" configurations are defined. (2) "Default" can also mean the "trailer.*" configurations themselves, because these configurations are used by "default" (ahead of the hardcoded defaults in (1)) if no command line arguments are provided. This concept of defaulting back to the configurations was introduced in 0ea5292e6b (interpret-trailers: add options for actions, 2017-08-01). In addition, the corresponding *_DEFAULT values are chosen when the user provides the "--no-where", "--no-if-exists", or "--no-if-missing" flags on the command line. These "--no-*" flags are used to clear previously provided flags of the form "--where", "--if-exists", and "--if-missing". Using these "--no-*" flags undoes the specifying of these flags (if any), so using the word "UNSPECIFIED" is more natural here. So instead of using "*_DEFAULT", use "*_UNSPECIFIED" because this signals to the reader that the *_UNSPECIFIED value by itself carries no meaning (it's a zero value and by itself does not "default" to anything, necessitating the need to have some other way of getting to a useful value). Signed-off-by: Linus Arver --- trailer.c | 17 ++++++++++------- trailer.h | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/trailer.c b/trailer.c index f646e484a23..6ad2fbca942 100644 --- a/trailer.c +++ b/trailer.c @@ -388,7 +388,7 @@ static void process_trailers_lists(struct list_head *head, int trailer_set_where(enum trailer_where *item, const char *value) { if (!value) - *item = WHERE_DEFAULT; + *item = WHERE_UNSPECIFIED; else if (!strcasecmp("after", value)) *item = WHERE_AFTER; else if (!strcasecmp("before", value)) @@ -405,7 +405,7 @@ int trailer_set_where(enum trailer_where *item, const char *value) int trailer_set_if_exists(enum trailer_if_exists *item, const char *value) { if (!value) - *item = EXISTS_DEFAULT; + *item = EXISTS_UNSPECIFIED; else if (!strcasecmp("addIfDifferent", value)) *item = EXISTS_ADD_IF_DIFFERENT; else if (!strcasecmp("addIfDifferentNeighbor", value)) @@ -424,7 +424,7 @@ int trailer_set_if_exists(enum trailer_if_exists *item, const char *value) int trailer_set_if_missing(enum trailer_if_missing *item, const char *value) { if (!value) - *item = MISSING_DEFAULT; + *item = MISSING_UNSPECIFIED; else if (!strcasecmp("doNothing", value)) *item = MISSING_DO_NOTHING; else if (!strcasecmp("add", value)) @@ -586,7 +586,10 @@ static void ensure_configured(void) if (configured) return; - /* Default config must be setup first */ + /* + * Default config must be setup first. These defaults are used if there + * are no "trailer.*" or "trailer..*" options configured. + */ default_conf_info.where = WHERE_END; default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR; default_conf_info.if_missing = MISSING_ADD; @@ -701,11 +704,11 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val, new_item->value = val; duplicate_conf(&new_item->conf, conf); if (new_trailer_item) { - if (new_trailer_item->where != WHERE_DEFAULT) + if (new_trailer_item->where != WHERE_UNSPECIFIED) new_item->conf.where = new_trailer_item->where; - if (new_trailer_item->if_exists != EXISTS_DEFAULT) + if (new_trailer_item->if_exists != EXISTS_UNSPECIFIED) new_item->conf.if_exists = new_trailer_item->if_exists; - if (new_trailer_item->if_missing != MISSING_DEFAULT) + if (new_trailer_item->if_missing != MISSING_UNSPECIFIED) new_item->conf.if_missing = new_trailer_item->if_missing; } list_add_tail(&new_item->list, arg_head); diff --git a/trailer.h b/trailer.h index ab2cd017567..a689d768c79 100644 --- a/trailer.h +++ b/trailer.h @@ -5,14 +5,14 @@ #include "strbuf.h" enum trailer_where { - WHERE_DEFAULT, + WHERE_UNSPECIFIED, WHERE_END, WHERE_AFTER, WHERE_BEFORE, WHERE_START }; enum trailer_if_exists { - EXISTS_DEFAULT, + EXISTS_UNSPECIFIED, EXISTS_ADD_IF_DIFFERENT_NEIGHBOR, EXISTS_ADD_IF_DIFFERENT, EXISTS_ADD, @@ -20,7 +20,7 @@ enum trailer_if_exists { EXISTS_DO_NOTHING }; enum trailer_if_missing { - MISSING_DEFAULT, + MISSING_UNSPECIFIED, MISSING_ADD, MISSING_DO_NOTHING }; From patchwork Sat Sep 9 06:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13377989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F58DEEB581 for ; Sat, 9 Sep 2023 06:16:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241795AbjIIGQe (ORCPT ); Sat, 9 Sep 2023 02:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238426AbjIIGQ3 (ORCPT ); Sat, 9 Sep 2023 02:16:29 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13BDE1BEA for ; Fri, 8 Sep 2023 23:16:25 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31c7912416bso2833379f8f.1 for ; Fri, 08 Sep 2023 23:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694240183; x=1694844983; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=YK2z70GM8Fp4oC98UaS8TS5iRN8Wgk4+ZVqIY4alM2I=; b=J3vNOhwCgy07upl/fec0V94lZ2NHk/Fi79HToFYo1TZiXwXTEmaAuZ/ERW6x2x7dq1 nVmJUbSNmkBOY1BqPF9fNefUdidJJepelStIXwS5R5CmNmfSWPY4Lx3BGsKwuXej8Z60 kOYG/Ce45E2p7lesIHf+EDZ47C+pJbRpe5ybHIwlx9B55VJcwq0ViAldLim6prxhYcXE kKRxO20lhVJTQfDV92PLG9Zp01RrK0R2wHrPiU9JYvGvmL2nr45W4WvTu93YSlNkhkgs 9qj6f5Xh0jwhKyeuA8LHZEX9hQF6ibKKdD7tyfAgIHlQBC8BYr0SflWuHcJkNyq96gRe 8KkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694240183; x=1694844983; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YK2z70GM8Fp4oC98UaS8TS5iRN8Wgk4+ZVqIY4alM2I=; b=J3OS9Fb7/3c+PhKyno5lvHN8Oc2LciX6dpXWKfHYha+VRdMm41SitRZvHZFMH+uQoi 3D7dlZzSRMWnfuk9/4nPe0fkNJ4zJ3/meI1R4GBDVWeTznbR/rDsM5I4Sf+lyzHubOFf DAP9P22Kq09SNAQ+WQs8ZDDSGpvzadNHjTSp36nL2F/KJydcKyiNoWfSIzQpU+u7XvVQ /iv5mIAXSAmojrSQAF5Hct3W5/RhGprSSpH0M+tewNZk0Lj2DDws605q6M5uEbgC+BYQ FA0jhd7dn+Xh6zHj9RIF/a0X+OIop3WuU3StDTgvotuYB2JrE4raHjWKMFJs4I87iE0b ED0Q== X-Gm-Message-State: AOJu0YzTkPCka4A2ZgrIar/aL4BDhVafLkgWDgLJ/VrVRiraZ8aXwjKG e+RnxfnDawwfm6/fJ+57/ygIhtFvHGU= X-Google-Smtp-Source: AGHT+IGneyhP2tfsfDTsNrrlOcUEgz/RgYKuRxddMVhjy8h7FBtlIaBowOEXp8CoDU5jAbopjS82KA== X-Received: by 2002:a5d:42ca:0:b0:31c:6409:df17 with SMTP id t10-20020a5d42ca000000b0031c6409df17mr3450161wrr.41.1694240183372; Fri, 08 Sep 2023 23:16:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 14-20020a056000154e00b0031f8be5b41bsm825731wry.5.2023.09.08.23.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 23:16:22 -0700 (PDT) Message-ID: <0463066ebe0889b72b6a1f6c344f2de127458391.1694240177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 09 Sep 2023 06:16:17 +0000 Subject: [PATCH v2 6/6] trailer: use offsets for trailer_start/trailer_end Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Glen Choo , Christian Couder , Phillip Wood , Linus Arver , Linus Arver Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Linus Arver From: Linus Arver Previously these fields in the trailer_info struct were of type "const char *" and pointed to positions in the input string directly (to the start and end positions of the trailer block). Use offsets to make the intended usage less ambiguous. We only need to reference the input string in format_trailer_info(), so update that function to take a pointer to the input. Signed-off-by: Linus Arver --- trailer.c | 17 ++++++++--------- trailer.h | 7 +++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/trailer.c b/trailer.c index 6ad2fbca942..00326720e81 100644 --- a/trailer.c +++ b/trailer.c @@ -1055,7 +1055,6 @@ void process_trailers(const char *file, LIST_HEAD(head); struct strbuf sb = STRBUF_INIT; struct trailer_info info; - size_t trailer_end; FILE *outfile = stdout; ensure_configured(); @@ -1066,11 +1065,10 @@ void process_trailers(const char *file, outfile = create_in_place_tempfile(file); parse_trailers(&info, sb.buf, &head, opts); - trailer_end = info.trailer_end - sb.buf; /* Print the lines before the trailers */ if (!opts->only_trailers) - fwrite(sb.buf, 1, info.trailer_start - sb.buf, outfile); + fwrite(sb.buf, 1, info.trailer_start, outfile); if (!opts->only_trailers && !info.blank_line_before_trailer) fprintf(outfile, "\n"); @@ -1092,7 +1090,7 @@ void process_trailers(const char *file, /* Print the lines after the trailers as is */ if (!opts->only_trailers) - fwrite(sb.buf + trailer_end, 1, sb.len - trailer_end, outfile); + fwrite(sb.buf + info.trailer_end, 1, sb.len - info.trailer_end, outfile); if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) @@ -1104,7 +1102,7 @@ void process_trailers(const char *file, void trailer_info_get(struct trailer_info *info, const char *str, const struct process_trailer_options *opts) { - int patch_start, trailer_end, trailer_start; + size_t patch_start, trailer_end = 0, trailer_start = 0; struct strbuf **trailer_lines, **ptr; char **trailer_strings = NULL; size_t nr = 0, alloc = 0; @@ -1139,8 +1137,8 @@ void trailer_info_get(struct trailer_info *info, const char *str, info->blank_line_before_trailer = ends_with_blank_line(str, trailer_start); - info->trailer_start = str + trailer_start; - info->trailer_end = str + trailer_end; + info->trailer_start = trailer_start; + info->trailer_end = trailer_end; info->trailers = trailer_strings; info->trailer_nr = nr; } @@ -1155,6 +1153,7 @@ void trailer_info_release(struct trailer_info *info) static void format_trailer_info(struct strbuf *out, const struct trailer_info *info, + const char *msg, const struct process_trailer_options *opts) { size_t origlen = out->len; @@ -1164,7 +1163,7 @@ static void format_trailer_info(struct strbuf *out, if (!opts->only_trailers && !opts->unfold && !opts->filter && !opts->separator && !opts->key_only && !opts->value_only && !opts->key_value_separator) { - strbuf_add(out, info->trailer_start, + strbuf_add(out, msg + info->trailer_start, info->trailer_end - info->trailer_start); return; } @@ -1219,7 +1218,7 @@ void format_trailers_from_commit(struct strbuf *out, const char *msg, struct trailer_info info; trailer_info_get(&info, msg, opts); - format_trailer_info(out, &info, opts); + format_trailer_info(out, &info, msg, opts); trailer_info_release(&info); } diff --git a/trailer.h b/trailer.h index a689d768c79..13fbf0dcd12 100644 --- a/trailer.h +++ b/trailer.h @@ -37,11 +37,10 @@ struct trailer_info { int blank_line_before_trailer; /* - * Pointers to the start and end of the trailer block found. If there - * is no trailer block found, these 2 pointers point to the end of the - * input string. + * Offsets to the trailer block start and end positions in the input + * string. If no trailer block is found, these are set to 0. */ - const char *trailer_start, *trailer_end; + size_t trailer_start, trailer_end; /* * Array of trailers found.