From patchwork Fri Sep 22 19:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396372 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 934A4CE7AB7 for ; Fri, 22 Sep 2023 19:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231743AbjIVTu5 (ORCPT ); Fri, 22 Sep 2023 15:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbjIVTuz (ORCPT ); Fri, 22 Sep 2023 15:50:55 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1522A1A3 for ; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3226cc3e324so1763974f8f.3 for ; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412247; x=1696017047; 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=lNeAeV5WYF/PhqL8M2+1bH8AtYyxpC3fM/4hGfg3lYD7YE23W/Zj+gFwk/dFewIvAl qRqGSpDlnvTwnNSR1WeVsqbB1qlaVTpb2FazDF7njJnwsloXje5qqOGtAT0SPBT1LvRr qmFPLtz4tfBbA8G3UlkACvy3vzgFdW42qn7oUKGxgkGsmuM9X4uplAekxGLcWUwcba9F Ue18HOBM9/SQGQR97WNZPdEy9WWyx8ahJn+bQjN5dGJmAot+VT0ELM1zKOOntGN/wzpL z+HUNwaElA2cWYTL/mbO3Z/rfBpX7c6ugJjwLXaUAW6xdkDrYr/8G1ndi97+SbYoc8Mw eKDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412247; x=1696017047; 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=Y0OEE+h28iG9Tz8fW/1M6b1jP9uP8F2Bv895TN+E+AJOpYpTYSSDnewy7Qpb6HxG+W dwaTNjDjPMcVLdu/St8Rq7yHWT9VdekRQdMj4piEmXJVhtLbn3Q7I/A0Y5z4a729j7UQ RI40Gvr7EF2gbxwQJB0NJmGK3WyK+JZCNlyPcNvF/A1LlmojP/MShiltVQUHQqi6cOhz G42pJ1ZwxijG7iJ6D0JRQRTSqVo/+WOpRzFmfgA+EK8t+t6DTBcyCPy5joJAhl2/7bfv AQyi+cSeEX08UjkYIWHHxklMRk9a4OkVU1vBA0hizYnoMaz6W+nXIYP+g1vDSq8kOBc2 y5fg== X-Gm-Message-State: AOJu0YyFTmIw5fmbsHaCmg8fB8j/BqzHPgAzMJuZ17ZvphE9p9u3KbvA 0nM51+UijplkpTSm10ydy3A2+Z915ns= X-Google-Smtp-Source: AGHT+IGCxOAKpZzv6NfeHxCNesJXZ+OeInK5MdUDE6xOKtWc0RPPASLzkviSZ/0YCBjcceGZC932ug== X-Received: by 2002:adf:ef83:0:b0:317:f714:3be6 with SMTP id d3-20020adfef83000000b00317f7143be6mr481523wro.61.1695412247244; Fri, 22 Sep 2023 12:50:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d21-20020adfa355000000b0031c5dda3aedsm2958220wrb.95.2023.09.22.12.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:47 -0700 (PDT) Message-ID: <4f116d2550f6cf218477560a9e25dbe4c384a2a6.1695412245.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:37 +0000 Subject: [PATCH v3 1/9] 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 Fri Sep 22 19:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396373 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 37E81CE7AB8 for ; Fri, 22 Sep 2023 19:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbjIVTu5 (ORCPT ); Fri, 22 Sep 2023 15:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231668AbjIVTu4 (ORCPT ); Fri, 22 Sep 2023 15:50:56 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B966919B for ; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3214de9cd8bso2378508f8f.2 for ; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412248; x=1696017048; 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=GZhoAiJrnV/QO3ImVWD9twmRgpX1tMiS/r+r62sWX8KnY2nR32QTsFad57iuOiXNv7 PIoCBpN3P0bZlWZf1JMtuuadq0pBlS/iV2TDoY6N8aNFHuuzK5Y1da5b+bcAnKgnmRlU uyj3kr5pz8HRp2i3Dl6QOKRP7lT2kME8QsGIHj4Ev/XhJ5/bp6bYBvqYBIWsraIr4rKP SwB935iMISvP2+/7OmWI52TClyh4lh8V57xEkeuyXKOq7fZKJ/9VyfQM3h2CP5KJCctd O+SMSSdnNMcyuXUyve62BcMdkoZ4xD1Eyy4AcWrizTPbKwkrguJoxI7flHqFlSr5T8NX a9jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412248; x=1696017048; 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=hp7/uTe2EWQ17eAO5qXxYQseILwUdCf2wHVIHQBHSaTig7teripr5y0/bmg5p2cwX+ 2MsKMCh40Mi7gjmzHJq/k+8ywlImZaPbBJZjczmem0JxjHXKeX3xCwyHNR6tyqGAz8f+ R6cEetuAGUU4QYufCofLoDw/P9pk0xrNe5SI365cMyuTCSPgzgaUxhxZ7rq0fl7tdxZQ 3tUNeC2TxzXJQ+fbTHgxVpvu4g6VcjiHS645jsJ4h9Jbwa5/PxaUMjNweBQzf3dy6lWX n6Oi3JtJmYATUfK4Rm/5ZcQyGSAPsZ7WujZ7bwDlvbxLxNdxv9g2UE+j+UofRwyvkBec GVrw== X-Gm-Message-State: AOJu0YxulfTH+Eae0ix8UCjlVvSIEjaPvAePbdREX9n8UQoyRHs97IlB d0Fgp2cn1XHIAY96JzaoC7t19kkr0p4= X-Google-Smtp-Source: AGHT+IFyzo6hFpjdIdWN0qykJ0x70HkFj830YP3T0vKrp61BpKLjzPHF7GycHk8wcnNeOCTK1SqJBQ== X-Received: by 2002:a5d:5605:0:b0:317:5351:e428 with SMTP id l5-20020a5d5605000000b003175351e428mr786628wrv.4.1695412248017; Fri, 22 Sep 2023 12:50:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s17-20020a5d69d1000000b003141e629cb6sm5172525wrw.101.2023.09.22.12.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:47 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:38 +0000 Subject: [PATCH v3 2/9] 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 Fri Sep 22 19:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396375 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 BCDB5CE7AB8 for ; Fri, 22 Sep 2023 19:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232062AbjIVTvB (ORCPT ); Fri, 22 Sep 2023 15:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbjIVTu5 (ORCPT ); Fri, 22 Sep 2023 15:50:57 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD5E919E for ; Fri, 22 Sep 2023 12:50:50 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-403012f27e1so29576665e9.1 for ; Fri, 22 Sep 2023 12:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412249; x=1696017049; 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=hwLgmzFqfTZR69fwTMvzdaL04/5R87SSfuWd9VfpVaxp9vnKoiI8Mj8Pz2ovGehd8/ w/Tovm/gadgi0KXjajZh3VZ1MY3h61K2CkdcplbKgaJ38YBlwIn5dDClNWnZ+11ocB8r R5IpoLNKZDvdfLWkYh+5giQ0EhrTQDmBL+u4+dsywNgdw8Jx7/rB89g6aDMtaMi5S6Du 33RXuHbZIjqtL+3dOWertfz5fm9K4jm0M5Vd2oL48gMRJL+4NzF+q46e1HyxQPFMelIk amnRK/pSpMmKFUr4mA5sm5hClRNfkmazIyQsizsenAsE+wSzilFkdzPwNfd8JXt0Y3KU xIhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412249; x=1696017049; 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=NFkX202h9xaDMBX+lLkgMhjJiSATW90W1lEc+YUK4wahxb/9T/VpEX9z83O/a/cJ1J oRB/qzoInrGKtRLr3RG5wnY9B0lDtKbckSaS+zjaMUtwdEIJmWzYQyYiJgKbzciW9zvg H3ClCvaZkW56rt5FdSo4TDkdy7lJyMHsDZ46XJCkWnalntoSxtmzIObOwxC4Gkz5zXSd 0j3sZkrVQgy+eOymMXixCrqfOwixacB284W5cj4dwF+E9DplxqaidGQVNa0dv6eK8Ym0 RFCjA0a7s9HCR6gVKGC+fmlj1XQK4vJmklACHlTphzaCTyIIwya+WkVUthvT6Rh+hdg6 VIsg== X-Gm-Message-State: AOJu0YwC6gjs76N0CZvP0Y9KFtket3a90fbCToPqy4vnVI4Joe9gBopr fIljnvsgiBQ8clynojjdSMbCNY8OiDk= X-Google-Smtp-Source: AGHT+IECFTVbExb5zSRQftBy0ey7ROgeVXOLhg7rF0TzqDmxGGKhMlfIWm+0CBG81FOOMOH1qBj0Yg== X-Received: by 2002:a05:600c:446:b0:405:34e4:e754 with SMTP id s6-20020a05600c044600b0040534e4e754mr197805wmb.32.1695412248737; Fri, 22 Sep 2023 12:50:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c05cb00b003fc06169ab3sm3386177wmd.20.2023.09.22.12.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:48 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:39 +0000 Subject: [PATCH v3 3/9] 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 Fri Sep 22 19:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396376 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 8B482CE7ABB for ; Fri, 22 Sep 2023 19:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbjIVTvD (ORCPT ); Fri, 22 Sep 2023 15:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbjIVTu5 (ORCPT ); Fri, 22 Sep 2023 15:50:57 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 785ED1A5 for ; Fri, 22 Sep 2023 12:50:51 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so2595421f8f.3 for ; Fri, 22 Sep 2023 12:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412250; x=1696017050; 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=PmgqWi7Cs5VukM9Vh3fswTlGXwbBtsWGyteqiqH/Gdg=; b=guI8NbHXuo4SAbktQgbfAw356lbedAlZLv6MT0aEroab7qN26LXT0wGvIQIgoHzS4h nQYBbLcnRCEFW81ZDLPlGEbDsBqNOZGRQonejr/pLPE5mGorZxzRg/1DXvM96kjotYlJ MQqBVueHwZnyLZXRDXphY+ivh0Qv7rzQA8SoU9Eo4z8pt6js5oSxAQR0YIQ36PY1Qnx2 1fA4enKXMY5L0a5lX/bQJrfuf83KSHIzD+bTEuVbXh+xSCpSORzFGNvCy/6rRXPdHte0 0jjLRCmG/M+x/Su6UBVFxZ3wAOz0bO5gjtKlxQyLqvNzudyvJ8h4T4kWv2j9P/jQZKa6 oSZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412250; x=1696017050; 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=PmgqWi7Cs5VukM9Vh3fswTlGXwbBtsWGyteqiqH/Gdg=; b=d+c4LmBuilPaBVgg1lt9F9CGxuj84IFL12hPK7K9uNpcT+4BkEjsAFMN7ByWEKS8IJ 6cAl+kW2M7f5GNx3GI58uO2mAQDY9mSMPyqS5dYIuNdN98f25Kbz4Clxc/PLe6peTY0S NqZ7N0NNEMBwIv9/jzTEXe8/gfaJHFKk980+6ZTH3KyNEKy1C6h62XonRUMIbH/DSiQh 4cE2N1yoGY9NsyiFDgSX+q/Qpro75MwAVSmJU7w1ZAP8/+VgpvLm1ysqqzeLqIqc8Q8t fpV77Zwax30DiKh1lu2eWAkNS7ZvlXZhoTIYNZRBKfWacHgpmwysGbIMzePQZ2HbzxaH 5WWA== X-Gm-Message-State: AOJu0Yxf6Dczv+5YOs6rCF1kkGpJ48flxyMfDqn/MzvHmuGRcZtlHyiG WXFX/LhlHlxs2qSaSmELJyZCT3U+W5E= X-Google-Smtp-Source: AGHT+IGfn3Iea6vjy7I5uGpKs1/2d43+xoyLaWCytEbSU+7r1AGdSid2tGIqaF8W5XeYv5mWkRMW0Q== X-Received: by 2002:a5d:4011:0:b0:320:371:afbf with SMTP id n17-20020a5d4011000000b003200371afbfmr650423wrp.10.1695412249413; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p2-20020a5d68c2000000b0031431fb40fasm5197699wrw.89.2023.09.22.12.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Message-ID: <47186a09b24522bacf459006330fd469766072f2.1695412245.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:40 +0000 Subject: [PATCH v3 4/9] 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 b6de5d9cb2d..0b66effceb5 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 Fri Sep 22 19:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396377 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 AD650CE7AB7 for ; Fri, 22 Sep 2023 19:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232460AbjIVTvF (ORCPT ); Fri, 22 Sep 2023 15:51:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbjIVTvA (ORCPT ); Fri, 22 Sep 2023 15:51:00 -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 C49C119B for ; Fri, 22 Sep 2023 12:50:51 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4054f790190so4682635e9.2 for ; Fri, 22 Sep 2023 12:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412250; x=1696017050; 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=fRKoNjL6jWlrxhawWelEmzgUZflZ7tZTbZMWzcAmXJQ=; b=l2cUOdOu4lSH7FzjmfnjacGmyDSvRoWuYKsJAHCvBW7dk/F48gqTOL60mvOK+1CY8h due+7LmuM++jTAN70THJJv007QPEuJZ7x8uxGt9RqjCSpqCWM+bJNBMUjezfVEoEcHPU fojpAFXkh9i/VDEAT9xPpeSFlE+WLqYKk2T1QqTlkOnXOpi8PuDgLQY3Or4aqi/Qhvsi 0W2Zf2raR3ZyCe1vyOY01rNbEuwpYwSIZXko6CxBqUrgJT/xoTl1Cn9n0iTG4QrDwf1V VtQpHdW3QHJLRaUQzm2hqrx7d5jwy6DLo0ie+UkEEKIjzZ0GLanp89cuEOukVz6Olkx5 A1LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412250; x=1696017050; 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=fRKoNjL6jWlrxhawWelEmzgUZflZ7tZTbZMWzcAmXJQ=; b=KFx5w77KleBmB2zlW5R1Vr99uTd6Vb80mcCsgFM2FWMZAGR9WRtIyvm1jLzuVzqwJZ Ks+XAVTvB8jch3mzcT3tcAfqmowkQgIdQHuZ7rGzAZpKh3y42YLbj5EDzzFvXwT4mYGK TKpbFTv68FGIOx+74VU3NdSwuuzDgskqB7ntm7nh+IQ3ASbd6Xow7Nij/x3ZndLs4uxS lPmAfg6uppooA2EjzbjCZysHT4i7ltlbsHeuNciie7dKfj/KLZyIyqrNMvfqWHCr/Iuq Z9zgQgJXgzevVoCmZzLOyygkG6CA4WXCBSgRX+/t5NGo7iRoKD/EZqENdQy6V1/QpRL2 Hc4A== X-Gm-Message-State: AOJu0Yx0DOxjnw6Pb494QJeEi5g4BeU7PekR6c91O97Pj/RnfGTZTDit wY6gXjTDQrNV0hIZGk9e9Pif3lTnLkw= X-Google-Smtp-Source: AGHT+IGDKmmq2m1cEqm6ZAHRffpqlmbNhKqOHnyF+DWiNmEdmL//B/xFRzBKShl5QF/TSNHYUCHWIw== X-Received: by 2002:a5d:49c1:0:b0:31f:fa1d:898 with SMTP id t1-20020a5d49c1000000b0031ffa1d0898mr499954wrs.47.1695412249971; Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a8-20020a056000100800b003197efd1e7bsm5141739wrx.114.2023.09.22.12.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:49 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:41 +0000 Subject: [PATCH v3 5/9] commit: ignore_non_trailer computes number of bytes to ignore 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 ignore_non_trailer() returns the _number of bytes_ that should be ignored from the end of the log message. It does not by itself "ignore" anything. Rename this function to remove the leading "ignore" verb, to sound more like a quantity than an action. Signed-off-by: Linus Arver --- builtin/commit.c | 2 +- builtin/merge.c | 2 +- commit.c | 2 +- commit.h | 4 ++-- trailer.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 7da5f924484..d1785d32db1 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -900,7 +900,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, strbuf_stripspace(&sb, '\0'); if (signoff) - append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0); + append_signoff(&sb, ignored_log_message_bytes(sb.buf, sb.len), 0); if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); diff --git a/builtin/merge.c b/builtin/merge.c index de68910177f..6cbbebca13d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -891,7 +891,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) _(no_scissors_editor_comment), comment_line_char); } if (signoff) - append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0); + append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0); write_merge_heads(remoteheads); write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len); if (run_commit_hook(0 < option_edit, get_index_file(), NULL, diff --git a/commit.c b/commit.c index b3223478bc2..4440fbabb83 100644 --- a/commit.c +++ b/commit.c @@ -1769,7 +1769,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len * Returns the number of bytes from the tail to ignore, to be fed as * the second parameter to append_signoff(). */ -size_t ignore_non_trailer(const char *buf, size_t len) +size_t ignored_log_message_bytes(const char *buf, size_t len) { size_t boc = 0; size_t bol = 0; diff --git a/commit.h b/commit.h index 28928833c54..1cc872f225f 100644 --- a/commit.h +++ b/commit.h @@ -294,8 +294,8 @@ const char *find_header_mem(const char *msg, size_t len, const char *find_commit_header(const char *msg, const char *key, size_t *out_len); -/* Find the end of the log message, the right place for a new trailer. */ -size_t ignore_non_trailer(const char *buf, size_t len); +/* Find the number of bytes to ignore from the end of a log message. */ +size_t ignored_log_message_bytes(const char *buf, size_t len); typedef int (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra, void *cb_data); diff --git a/trailer.c b/trailer.c index 0b66effceb5..185b3e2707f 100644 --- a/trailer.c +++ b/trailer.c @@ -931,7 +931,7 @@ continue_outer_loop: /* Return the position of the end of the trailers. */ static size_t find_trailer_end(const char *buf, size_t len) { - return len - ignore_non_trailer(buf, len); + return len - ignored_log_message_bytes(buf, len); } static int ends_with_blank_line(const char *buf, size_t len) From patchwork Fri Sep 22 19:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396378 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 B687DCE7AB7 for ; Fri, 22 Sep 2023 19:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbjIVTvJ (ORCPT ); Fri, 22 Sep 2023 15:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjIVTvA (ORCPT ); Fri, 22 Sep 2023 15:51:00 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6891AB for ; Fri, 22 Sep 2023 12:50:52 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-31c8321c48fso2893342f8f.1 for ; Fri, 22 Sep 2023 12:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412251; x=1696017051; 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=VYXXRIc3EYjIisAKYJNnEVEWQxe8YlHyuNCTiVa/+Gk=; b=KI3hWUWCEfDr1iEAs94hf63mhDpjGguqS12ZMERMuPFlWvDfVP6d9hlkSNHFyn/8dc vkDZ3vMwGFSt3MYGZ4yS8gyXA30uUFbOdh/m4aaeqsPJM6lsRLFPcytsKDUYwOYkqLx6 M+Pa60eOEQ5NWFHwAcAYaHdu607WJ2hohqMqW3/2/a6UYRef0G5x0V/X0WBLndMlLiU7 Ia7/bog6YE5RVK3/maMQgzB9kl25jlsm8SFHzy4nv5lc8gpAjFU09SC2QwoNgmmh8MD1 9+jNvLYp7yVT4LPMkKGXOEc+nFFvViW1MrAcBNnP95zvsaNqw8ju5Q0eSbrQQYOZwRlk 3pBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412251; x=1696017051; 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=VYXXRIc3EYjIisAKYJNnEVEWQxe8YlHyuNCTiVa/+Gk=; b=YCR7EdOLAH0GjnXsw2cGd10s3MCWd3/HUbdFE6RAggaipcV4uER/o6LfGwu0BdT+XZ Oe4mexrT790Ceil/FJqZ9Pn2u+NVvffTt1GQVMOMbxnA5jUR5w8YSORgEgdvESyqKJEy KLD9ah6EsFfBynetpMlVla1cpKIo5PhUXZ1MssselMMZrzqQdPjkluU0tYWjks/aQsYD yIEeh2N6b9NdofgDQDZ8L3hmcyR1oK150Xv7meYteUm52Xz2ATDkH8PcIAgNfxOYWSNX wlr+xqQUmzCoyVfuwi2jj76ZnC8/6HcACNw/SJPFGgRD5Ln+lq/+OPINoC3jikf56eXZ fHjg== X-Gm-Message-State: AOJu0YwnN0SncNoUVDCLbgPK8UgxxDqCuJT912s2bcPhRNTmJDi5F3FX QzuhQu6y6qnpjt1sQR6TF1acwuh0ksI= X-Google-Smtp-Source: AGHT+IEWwiR0i1jUu9Q8g3E3U9U8SNp97Byta2Wtfb6ikalZz/ewzvVfCZUo5TnjXpw5xwkx9meInw== X-Received: by 2002:adf:ec04:0:b0:317:6734:c2ae with SMTP id x4-20020adfec04000000b003176734c2aemr2820142wrn.11.1695412250715; Fri, 22 Sep 2023 12:50:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e24-20020a5d5958000000b00317ab75748bsm5183099wri.49.2023.09.22.12.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:50 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:42 +0000 Subject: [PATCH v3 6/9] trailer: find the end of the log message 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, trailer_info_get() computed the trailer block end position by (1) checking for the opts->no_divider flag and optionally calling find_patch_start() to find the "patch start" location (patch_start), and (2) calling find_trailer_end() to find the end of the trailer block using patch_start as a guide, saving the return value into "trailer_end". The logic in (1) was awkward because the variable "patch_start" is misleading if there is no patch in the input. The logic in (2) was misleading because it could be the case that no trailers are in the input (yet we are setting a "trailer_end" variable before even searching for trailers, which happens later in find_trailer_start()). The name "find_trailer_end" was misleading because that function did not look for any trailer block itself --- instead it just computed the end position of the log message in the input where the end of the trailer block (if it exists) would be (because trailer blocks must always come after the end of the log message). Combine the logic in (1) and (2) together into find_patch_start() by renaming it to find_end_of_log_message(). The end of the log message is the starting point which find_trailer_start() needs to start searching backward to parse individual trailers (if any). Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- trailer.c | 61 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/trailer.c b/trailer.c index 185b3e2707f..9da89df9d8a 100644 --- a/trailer.c +++ b/trailer.c @@ -812,21 +812,47 @@ 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. + * Find the end of the log message as an offset from the start of the input + * (where callers of this function are interested in looking for a trailers + * block in the same input). We have to consider two categories of content that + * can come at the end of the input which we want to ignore (because they don't + * belong in the log message): + * + * (1) the "patch part" which begins with a "---" divider and has patch + * information (like the output of git-format-patch), and + * + * (2) any trailing comment lines, blank lines like in the output of "git + * commit -v", or stuff below the "cut" (scissor) line. + * + * As a formula, the situation looks like this: + * + * INPUT = LOG MESSAGE + IGNORED + * + * where IGNORED can be either of the two categories described above. It may be + * that there is nothing to ignore. Now it may be the case that the LOG MESSAGE + * contains a trailer block, but that's not the concern of this function. */ -static size_t find_patch_start(const char *str) +static size_t find_end_of_log_message(const char *input, int no_divider) { + size_t end; + const char *s; - for (s = str; *s; s = next_line(s)) { + /* Assume the naive end of the input is already what we want. */ + end = strlen(input); + + /* Optionally skip over any patch part ("---" line and below). */ + for (s = input; *s; s = next_line(s)) { const char *v; - if (skip_prefix(s, "---", &v) && isspace(*v)) - return s - str; + if (!no_divider && skip_prefix(s, "---", &v) && isspace(*v)) { + end = s - input; + break; + } } - return s - str; + /* Skip over other ignorable bits. */ + return end - ignored_log_message_bytes(input, end); } /* @@ -928,12 +954,6 @@ continue_outer_loop: return len; } -/* Return the position of the end of the trailers. */ -static size_t find_trailer_end(const char *buf, size_t len) -{ - return len - ignored_log_message_bytes(buf, len); -} - static int ends_with_blank_line(const char *buf, size_t len) { ssize_t ll = last_line(buf, len); @@ -1104,7 +1124,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; + int end_of_log_message, trailer_start; struct strbuf **trailer_lines, **ptr; char **trailer_strings = NULL; size_t nr = 0, alloc = 0; @@ -1112,16 +1132,11 @@ 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); - - trailer_end = find_trailer_end(str, patch_start); - trailer_start = find_trailer_start(str, trailer_end); + end_of_log_message = find_end_of_log_message(str, opts->no_divider); + trailer_start = find_trailer_start(str, end_of_log_message); trailer_lines = strbuf_split_buf(str + trailer_start, - trailer_end - trailer_start, + end_of_log_message - trailer_start, '\n', 0); for (ptr = trailer_lines; *ptr; ptr++) { @@ -1144,7 +1159,7 @@ 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_end = str + end_of_log_message; info->trailers = trailer_strings; info->trailer_nr = nr; } From patchwork Fri Sep 22 19:50:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396380 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 53FC5CE7AB7 for ; Fri, 22 Sep 2023 19:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232691AbjIVTv0 (ORCPT ); Fri, 22 Sep 2023 15:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbjIVTvH (ORCPT ); Fri, 22 Sep 2023 15:51:07 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41DD91A2 for ; Fri, 22 Sep 2023 12:50:53 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-405361bb9cdso23075785e9.0 for ; Fri, 22 Sep 2023 12:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412251; x=1696017051; 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=kHe98kkGbtTIzTXMF6lyNU0pFHVIK5w2W2RAaqYV3uI=; b=YGz+w65ncLzlU9lcNWK3dO1eZ+6bTKsChpS+xao9CoAxXHKD0kXqSS+oAyoRb90USW hB0t3/W8fKi/0mlbEFqSpmdiiyDSeC8t9152skf4pwIkY/+mm2tIDr87kpfEvekKSMHy Opia4S3pJVBbHH/q4sP5pHiPdJyjjmlBBvTclBqE64k/fzPA5RvFF5i2hR50x8WNAs/y gB2Fv2B9AUwpmNLclMJp27BftccrgHhJdZev1FqRXlkMFHi9Os8trKi15GFzqSUngpJ3 dvdavefYlmoCdrNFbw9ddXP/Elq2K8E/h8B87nj1WD23a4PpMBADBeK+2ji2qjuiobLf rQ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412251; x=1696017051; 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=kHe98kkGbtTIzTXMF6lyNU0pFHVIK5w2W2RAaqYV3uI=; b=jJXIttQG6YeRRxXavTKUDCeGgIbm6ytaR+WAhJahrSPnxULmAvArrEEhsV8UtEnCZw cIGhKX5bK45zU6TghP56/uUyanmbi6NSJW61uZXt28i7jRvq+6SpMHVJpJYvubDoLpeg DBrnFlkOd082Qo2kvp48PQxxALMCzEgyDLWBVg32nsSM5U8mXlsiSEWlS7bjpdUOtrxT e0vpxpaZUcAXNCVWAN+tQZ+X4M+pUfoCBpo0S9Esv8fdY7h1Fab/jvv+Oj58BuMi1vq9 7iJSpktC7t+fbhXNbnGcWaFwMl0R/Y3W7oJfrl5R+rfx0TYJ6ci9nF1dQsqyBOw+33kn P7TA== X-Gm-Message-State: AOJu0YxhkLW0hpmfK1hSgZtC6LBmEt2wVqCFmdQ5tfrrF99aQhvwVvx3 l694XSknWgQEiGmVSbw4gRLpK9ecuvc= X-Google-Smtp-Source: AGHT+IEqX2W4sHE0tXK8y29U6YBV4qayNmM/2n6rNBBf4iqTNJW5Ap+f4NF2vKRjZBXjW+t8ujMLxQ== X-Received: by 2002:a05:600c:2108:b0:404:7480:d821 with SMTP id u8-20020a05600c210800b004047480d821mr231229wml.37.1695412251513; Fri, 22 Sep 2023 12:50:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l4-20020a5d4804000000b003179b3fd837sm5143759wrq.33.2023.09.22.12.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:51 -0700 (PDT) Message-ID: <091805eb7d93efa6fbe3831bcddd2a6fdc033388.1695412245.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:43 +0000 Subject: [PATCH v3 7/9] 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. While we're at it, rename trailer_start to trailer_block_start to be more explicit about these offsets (that they are for the entire trailer block including other trailers). Ditto for trailer_end. Signed-off-by: Linus Arver --- sequencer.c | 2 +- trailer.c | 29 ++++++++++++++--------------- trailer.h | 13 ++++++++----- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/sequencer.c b/sequencer.c index adc9cfb4df3..77362f5cd5d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -331,7 +331,7 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob, if (ignore_footer) sb->buf[sb->len - ignore_footer] = saved_char; - if (info.trailer_start == info.trailer_end) + if (info.trailer_block_start == info.trailer_block_end) return 0; for (i = 0; i < info.trailer_nr; i++) diff --git a/trailer.c b/trailer.c index 9da89df9d8a..471c2722536 100644 --- a/trailer.c +++ b/trailer.c @@ -859,7 +859,7 @@ static size_t find_end_of_log_message(const char *input, int no_divider) * Return the position of the first trailer line or len if there are no * trailers. */ -static size_t find_trailer_start(const char *buf, size_t len) +static size_t find_trailer_block_start(const char *buf, size_t len) { const char *s; ssize_t end_of_title, l; @@ -1075,7 +1075,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(); @@ -1086,11 +1085,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_block_start, outfile); if (!opts->only_trailers && !info.blank_line_before_trailer) fprintf(outfile, "\n"); @@ -1112,7 +1110,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_block_end, 1, sb.len - info.trailer_block_end, outfile); if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) @@ -1124,7 +1122,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 end_of_log_message, trailer_start; + size_t end_of_log_message = 0, trailer_block_start = 0; struct strbuf **trailer_lines, **ptr; char **trailer_strings = NULL; size_t nr = 0, alloc = 0; @@ -1133,10 +1131,10 @@ void trailer_info_get(struct trailer_info *info, const char *str, ensure_configured(); end_of_log_message = find_end_of_log_message(str, opts->no_divider); - trailer_start = find_trailer_start(str, end_of_log_message); + trailer_block_start = find_trailer_block_start(str, end_of_log_message); - trailer_lines = strbuf_split_buf(str + trailer_start, - end_of_log_message - trailer_start, + trailer_lines = strbuf_split_buf(str + trailer_block_start, + end_of_log_message - trailer_block_start, '\n', 0); for (ptr = trailer_lines; *ptr; ptr++) { @@ -1157,9 +1155,9 @@ void trailer_info_get(struct trailer_info *info, const char *str, strbuf_list_free(trailer_lines); info->blank_line_before_trailer = ends_with_blank_line(str, - trailer_start); - info->trailer_start = str + trailer_start; - info->trailer_end = str + end_of_log_message; + trailer_block_start); + info->trailer_block_start = trailer_block_start; + info->trailer_block_end = end_of_log_message; info->trailers = trailer_strings; info->trailer_nr = nr; } @@ -1174,6 +1172,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; @@ -1183,8 +1182,8 @@ 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, - info->trailer_end - info->trailer_start); + strbuf_add(out, msg + info->trailer_block_start, + info->trailer_block_end - info->trailer_block_start); return; } @@ -1238,7 +1237,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..4dcb9080327 100644 --- a/trailer.h +++ b/trailer.h @@ -32,16 +32,19 @@ int trailer_set_if_missing(enum trailer_if_missing *item, const char *value); struct trailer_info { /* * True if there is a blank line before the location pointed to by - * trailer_start. + * trailer_block_start. */ 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 both set to the + * "true" end of the input, per find_true_end_of_input(). + * + * NOTE: This will be changed so that these point to 0 in the next + * patch if no trailers are found. */ - const char *trailer_start, *trailer_end; + size_t trailer_block_start, trailer_block_end; /* * Array of trailers found. From patchwork Fri Sep 22 19:50:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396381 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 EDF94CE7ABA for ; Fri, 22 Sep 2023 19:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232967AbjIVTv3 (ORCPT ); Fri, 22 Sep 2023 15:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232543AbjIVTvI (ORCPT ); Fri, 22 Sep 2023 15:51:08 -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 2C6161B2 for ; Fri, 22 Sep 2023 12:50:54 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-405524e6769so1667165e9.1 for ; Fri, 22 Sep 2023 12:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412252; x=1696017052; 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=jIjzqide8w4bht+LrQY9bA4gqXbbebQ/O7VplvZnCaQ=; b=igPG0e0VqsVb6r7NuGB9UA/h9DdGWPp1Xpv3ywPE2xTBb1Ye/iyitVaKthvdNJtqYc TPQEsWi+f7L4PBrVkqjn4nsjBulFpG/9QHL5IUbqVk2HqiqRC1BwfSj++W1TvrReGHe7 gkXzHL/DOFFzKjNlJCqFULp5dNPay788f5BW9Z6eZTdteBE4Dq/2UF+OG61KwMzbCqCT 3fh4zFFbJiabE5aVl5JeKJuUi3nXMMWvHXIhduQz8p6tAXTWPvYIA9FIWwi13iIoWU3a kiYrl7THef3fsO3q2HuS8vszUcqCo6nTc2bjCIv4cbofAWKAm2dJyYATT7WwSg21DgbG +Dgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412252; x=1696017052; 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=jIjzqide8w4bht+LrQY9bA4gqXbbebQ/O7VplvZnCaQ=; b=Jm1+GQVHJVxMslV+GfgJgACDqPjt2pbOdxfkZRPNd2HCynSLccjcc6KlRK8SuQab8P uxz4vCek2gnpXik2H7TpQVit12FI2ST1kUXoFt3NkfwrG2terZzCDp9VnoyI2iN+Rp9x tmWdW44Cb5Eh7KrNsl4TFLqAZWOWr/yS0URAf8iohXWlOOs7xuK4LdmefLDrCxYIv24S Oy90Vm1iFDKUvdriVTNkruofRFstovhAbNY75zSpUAKOG8KiUb8/CYP4NL9MeJhRlLWY in93nx3FbKewQUk9fAKZeVIUhbLs6mhLmuOsuAjbnKwOHVM973GIKXHvxZThwuKPYit1 Tqyg== X-Gm-Message-State: AOJu0Yx5h7r655P1WqoDvWphUUuIPkS7a7VHrMgziiC+JzbxRCuKa/dI w8JgcDRkyDfmt1pTF7rk0wu7O6ICUAY= X-Google-Smtp-Source: AGHT+IFAGVFXllfQBUciGDVQtWgGBZ4ssrL/ec2K0o0CIN3Ce/k0Et60A9bED8Oiwpvt8+z/CWikWA== X-Received: by 2002:a05:600c:8608:b0:400:140c:6083 with SMTP id ha8-20020a05600c860800b00400140c6083mr2679574wmb.2.1695412252170; Fri, 22 Sep 2023 12:50:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j9-20020a05600c300900b003fe407ca05bsm4148022wmh.37.2023.09.22.12.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:51 -0700 (PDT) Message-ID: <1762f78a613f4a744e76ad515b6d27ca9bea47ed.1695412245.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:44 +0000 Subject: [PATCH v3 8/9] trailer: only use trailer_block_* variables if trailers were found 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 variables were overloaded to act as the end of the log message even if no trailers were found. Remove the overloaded meaning by adding a new end_of_log_message field to the trailer_info struct. The trailer_info struct consumers now only refer to the trailer_block_start and trailer_block_end fields if trailers were found (trailer_nr > 0), and otherwise refer to the end_of_log_message. Signed-off-by: Linus Arver --- trailer.c | 31 +++++++++++++++++++++++-------- trailer.h | 12 +++++++----- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/trailer.c b/trailer.c index 471c2722536..9a3837be770 100644 --- a/trailer.c +++ b/trailer.c @@ -1086,9 +1086,14 @@ void process_trailers(const char *file, parse_trailers(&info, sb.buf, &head, opts); - /* Print the lines before the trailers */ - if (!opts->only_trailers) - fwrite(sb.buf, 1, info.trailer_block_start, outfile); + /* Print the lines before the trailers (if any) as is. */ + if (!opts->only_trailers) { + if (info.trailer_nr) { + fwrite(sb.buf, 1, info.trailer_block_start, outfile); + } else { + fwrite(sb.buf, 1, info.end_of_log_message, outfile); + } + } if (!opts->only_trailers && !info.blank_line_before_trailer) fprintf(outfile, "\n"); @@ -1108,9 +1113,14 @@ void process_trailers(const char *file, free_all(&head); trailer_info_release(&info); - /* Print the lines after the trailers as is */ - if (!opts->only_trailers) - fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile); + /* Print the lines after the trailers (if any) as is. */ + if (!opts->only_trailers) { + if (info.trailer_nr) { + fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile); + } else { + fwrite(sb.buf + info.end_of_log_message, 1, sb.len - info.end_of_log_message, outfile); + } + } if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) @@ -1156,8 +1166,13 @@ void trailer_info_get(struct trailer_info *info, const char *str, info->blank_line_before_trailer = ends_with_blank_line(str, trailer_block_start); - info->trailer_block_start = trailer_block_start; - info->trailer_block_end = end_of_log_message; + info->trailer_block_start = 0; + info->trailer_block_end = 0; + if (nr) { + info->trailer_block_start = trailer_block_start; + info->trailer_block_end = end_of_log_message; + } + info->end_of_log_message = end_of_log_message; info->trailers = trailer_strings; info->trailer_nr = nr; } diff --git a/trailer.h b/trailer.h index 4dcb9080327..5e2843d320a 100644 --- a/trailer.h +++ b/trailer.h @@ -38,14 +38,16 @@ struct trailer_info { /* * Offsets to the trailer block start and end positions in the input - * string. If no trailer block is found, these are both set to the - * "true" end of the input, per find_true_end_of_input(). - * - * NOTE: This will be changed so that these point to 0 in the next - * patch if no trailers are found. + * string. If no trailer block is found, these are set to 0. */ size_t trailer_block_start, trailer_block_end; + /* + * Offset to the end of the log message in the input (may not be the + * same as the end of the input). + */ + size_t end_of_log_message; + /* * Array of trailers found. */ From patchwork Fri Sep 22 19:50:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13396379 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 336EACE7AB8 for ; Fri, 22 Sep 2023 19:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232179AbjIVTvL (ORCPT ); Fri, 22 Sep 2023 15:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjIVTvB (ORCPT ); Fri, 22 Sep 2023 15:51:01 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F2991B4 for ; Fri, 22 Sep 2023 12:50:54 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-405524e6769so1667235e9.1 for ; Fri, 22 Sep 2023 12:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695412253; x=1696017053; 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=ulgQYUGi+JBz8qvi42GHcPiDQBz2Gpnh8r/yTU3Dk3Q=; b=DMK4ncxC2eUQ/Pd1fewf05tC4d1M1O4HAim/Q8tUaGx4QzH0d4SO6AHDtNvsKziVN2 MlyyaP1d3Tcj/qgSQxtFgVaxVWNjvQeDR6pm2J2UYtJzMA/6A0dprFT3YVVcDgtacXMz up+xp6hck3OwuvFGTQ0T4EcWEEcdG7OQ24Lz3cJb4H3PvjcV0LLDsOov95UuT9a8AxcT 9xg7/EjcQJNzthlUOWWRnlEOaXllAevkpnIrL/Fh8sAGMGHRwK8BcOmh97h5qye6OkFR Z8V6dOwu8L4XVpkkC1kgi/0rOOt+xkrfL9kD7H5MU3xYVN8ij41CSZu0SjGQBAxJxnSQ brTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695412253; x=1696017053; 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=ulgQYUGi+JBz8qvi42GHcPiDQBz2Gpnh8r/yTU3Dk3Q=; b=VW3x0mpGqdhUQVmBUK+KbKI6M/tEBR9amcxfkacCdvheeNbFtRcWAmi7jwHlcd1j17 FBe7k0RzjjTG2kag+MjJkZDYsEDdhkS3hIykeXsvxL11JHP8BZapLakNu/bdZh5ytg3l VX9r4hDUwsLs3izHURoXJW10OVqgnuMtlKQG1waKQCYEtGXE8LYRZkFwGGFLEuhhKfBQ pndDEkb3zxrBjJ/nD85Z55Ip0jtCM/z2a0lrg4famwtUej6OGiFp3EuJ/g+Dinb5WC86 BzfvxA47lw7vsf7H04cN7Rn7cpP/TW4UeMrTcrEKEQ70LF79P6hj6QdSCJyWfiO0trD5 O2xQ== X-Gm-Message-State: AOJu0YwODKJd46BebRXht7h2nXaH/ywobisdKCccnrNJQCbBKpnSU8JA HUg+dAra/oAa/RAnLsaOp3G6rS0DMlc= X-Google-Smtp-Source: AGHT+IEpdEmTqWTg/iDm/DigGWVsUaT9/UY1FJVTTjqh0LqPbx+41YYFEAgiI+8DhqW6DyGyy/2XzA== X-Received: by 2002:a7b:cc88:0:b0:405:409e:1fcb with SMTP id p8-20020a7bcc88000000b00405409e1fcbmr449150wma.5.1695412252739; Fri, 22 Sep 2023 12:50:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s9-20020a05600c45c900b0040550c20cbcsm414506wmo.24.2023.09.22.12.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:50:52 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 22 Sep 2023 19:50:45 +0000 Subject: [PATCH v3 9/9] trailer: make stack variable names match field names 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 Signed-off-by: Linus Arver --- trailer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/trailer.c b/trailer.c index 9a3837be770..739acafc4e9 100644 --- a/trailer.c +++ b/trailer.c @@ -1134,8 +1134,8 @@ void trailer_info_get(struct trailer_info *info, const char *str, { size_t end_of_log_message = 0, trailer_block_start = 0; struct strbuf **trailer_lines, **ptr; - char **trailer_strings = NULL; - size_t nr = 0, alloc = 0; + char **trailers = NULL; + size_t trailer_nr = 0, alloc = 0; char **last = NULL; ensure_configured(); @@ -1155,12 +1155,12 @@ void trailer_info_get(struct trailer_info *info, const char *str, *last = strbuf_detach(&sb, NULL); continue; } - ALLOC_GROW(trailer_strings, nr + 1, alloc); - trailer_strings[nr] = strbuf_detach(*ptr, NULL); - last = find_separator(trailer_strings[nr], separators) >= 1 - ? &trailer_strings[nr] + ALLOC_GROW(trailers, trailer_nr + 1, alloc); + trailers[trailer_nr] = strbuf_detach(*ptr, NULL); + last = find_separator(trailers[trailer_nr], separators) >= 1 + ? &trailers[trailer_nr] : NULL; - nr++; + trailer_nr++; } strbuf_list_free(trailer_lines); @@ -1168,13 +1168,13 @@ void trailer_info_get(struct trailer_info *info, const char *str, trailer_block_start); info->trailer_block_start = 0; info->trailer_block_end = 0; - if (nr) { + if (trailer_nr) { info->trailer_block_start = trailer_block_start; info->trailer_block_end = end_of_log_message; } info->end_of_log_message = end_of_log_message; - info->trailers = trailer_strings; - info->trailer_nr = nr; + info->trailers = trailers; + info->trailer_nr = trailer_nr; } void trailer_info_release(struct trailer_info *info)