From patchwork Sat Aug 5 05:04:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13342515 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 12060EB64DD for ; Sat, 5 Aug 2023 05:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjHEFEs (ORCPT ); Sat, 5 Aug 2023 01:04:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjHEFEo (ORCPT ); Sat, 5 Aug 2023 01:04:44 -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 39F904ED3 for ; Fri, 4 Aug 2023 22:04:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-31771bb4869so2485115f8f.0 for ; Fri, 04 Aug 2023 22:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691211881; x=1691816681; 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=n+OogCcDE6SBXq8d85cFls+RFceySrodLASDp6pcyd4=; b=UvB4bFktUuhRclRpCkJAmN9/ckuk9AUDIJSpQTwiZ7ONx7Ns6VI38ZX5hKSYx7eUQD cLnWAH1X6FA5TR70ReRzgIZ7GhM9kaeU6TUYOd6QGtjYQcP0FF9Yr2j73cECASyA7pei y35RgpCLW6lcLKg9EjZIgJGt6aQvmujpVsdM/bbkn+Vn/I9mfsSoiBWAvIgHnH3wfDWS xsprBB37WnlbJmpgGvsvKhyWAgYTDaKoBIAkNzM/nIxej8SzaF1Dp90wwjRI0ly84Upn +EmQmgIpbmkpjoXXMvGj41IDDJYgYDWfh21FHWaR28TQ7m4Fni7t8bE+rcXaam3bJGu3 /vJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691211881; x=1691816681; 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=n+OogCcDE6SBXq8d85cFls+RFceySrodLASDp6pcyd4=; b=SQj35d0Dp6CgmEsNSPWlODkAQpbd3vAasPNsI9cxMO3aKwBR6tNZc5HEeAaagecte9 TEJy9nSJkCP3Snh7GG31qrmkjcOngN1EbMp3V4n6+u73/gLBoEOkMAVvxDaUaZtF3F+F zwbrQYqCRCLjfcXFNEilKBXugQk3GNc3NE6I4d6TVnbVluoropzuatOmaGCv8TdBTUnP qLcVuQ/5FcpCISBkS6fHJOSDeCU2+A9omq4w8lNfAfN/ahHUVDa4C8yHbMUn1PI5Zy3e ictZm6Cp43vmEHiwepzYfjYD4aJTR9lSdVF3ftV8QBa90qyQr7oOzDbB7pcQWhxx5YhR s0lA== X-Gm-Message-State: AOJu0YxcP/DAyc/IwRsFUuPO4hI/w+zme5IQJp9pdYoPFgOG7c7RlEPa Hgd8Z9TbXiAVM4BaTpZ9VnQbAukzbyY= X-Google-Smtp-Source: AGHT+IGpuhFHq2HvvizFLuKxAMN5fYGb8uyeLi/Mws5tY8cKtsD6Mb7bSmb5ZhvojHQn9dktZ4Zfjg== X-Received: by 2002:adf:e909:0:b0:317:3f70:9dc4 with SMTP id f9-20020adfe909000000b003173f709dc4mr2577453wrm.31.1691211881391; Fri, 04 Aug 2023 22:04:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c17-20020adfe711000000b00317afc7949csm4112592wrm.50.2023.08.04.22.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:04:41 -0700 (PDT) Message-ID: <0bce4d4b0d5650edf477cbbcc9f4e467b7981426.1691211879.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 05 Aug 2023 05:04:35 +0000 Subject: [PATCH 1/5] trailer: separate public from internal portion of trailer_iterator Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 "__private_to_trailer_c__do_not_use" to warn against their use. Internally, use a "#define" to keep the code tidy. Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- trailer.c | 12 +++++++----- trailer.h | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/trailer.c b/trailer.c index f408f9b058d..dff3fafe865 100644 --- a/trailer.c +++ b/trailer.c @@ -1214,20 +1214,22 @@ void format_trailers_from_commit(struct strbuf *out, const char *msg, trailer_info_release(&info); } +#define private __private_to_trailer_c__do_not_use + void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) { struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; 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->private.info, msg, &opts); + iter->private.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->private.cur < iter->private.info.trailer_nr) { + char *trailer = iter->private.info.trailers[iter->private.cur++]; int separator_pos = find_separator(trailer, separators); if (separator_pos < 1) @@ -1245,7 +1247,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->private.info); strbuf_release(&iter->val); strbuf_release(&iter->key); } diff --git a/trailer.h b/trailer.h index 795d2fccfd9..db57e028650 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; + } __private_to_trailer_c__do_not_use; }; /* From patchwork Sat Aug 5 05:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13342516 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 2D9D5C001DE for ; Sat, 5 Aug 2023 05:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjHEFE6 (ORCPT ); Sat, 5 Aug 2023 01:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjHEFEp (ORCPT ); Sat, 5 Aug 2023 01:04:45 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9143C4ED6 for ; Fri, 4 Aug 2023 22:04:43 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3178dd81ac4so2305884f8f.3 for ; Fri, 04 Aug 2023 22:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691211882; x=1691816682; 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=A8CTofYNZZM9A5a0ncF2B46mjObmCWt2hkkcf9PsnLU=; b=pPYjuEfxrNSZeGfv6SdAZlyQRnO6jFXpmDpYYQJQy+Vk7uZy/GPuqqTxFCfMthx8Sw s9j61SEkN3rJSPogjm/bLuh2AstOMVA8D0sGafsjKDAgHgVYQ4xVog/9zeRUmO9QF1Ze O0/oed41ATP/HJCK3+Za8H8Hs6zc4D2uhQk/wpm1Tlthpk2eWoNawfU22QErDOUYOmV4 rkgxPo0qVR5TVQ3D3H4kJ2d/aj8lmsgDaVifsyjqJquyrieVCwvSal9tm/rzeKCmAyF6 rLuP8yFH9emOgjlp9+uDk4uq799+9aXMQRBucGcx29JQcyMXDSte/7wcE9wcyxfS0a/Y wP0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691211882; x=1691816682; 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=A8CTofYNZZM9A5a0ncF2B46mjObmCWt2hkkcf9PsnLU=; b=J5KCzrsaPAjAzJQc12CCvZxB93le/VDh5knyaPY61J4j2pkDapw/3v/ayB1X2sG+E8 MAQ3i3CBGPye0r6TtonSO8A764TRmTwA90PiRU+XW5Xb0WgSnKkpxeAG4A30F/mPIxso eu/wa2wyJqeJyYgUaWR/UvZUcGkNToosYboBb+ZD+leSscNDe7cix+yTX+4fjxDvdP/+ Q98AqaAw2rVOfcXICUb1NMHccKp96Fq2Qunegvy+z+3yzg1qpbowbykuFEURWQ7oCf31 69pV74gy0NN+M54SkaHr+Qtn/vSuMNZeMyXiX5A6086bEsupkIqlNdi+K/OPgI+VPR+X wLHg== X-Gm-Message-State: AOJu0Yw+HXXixNdJb+NjwVs3zq4Fz13gD8OOvyDw8l/QbbUnA304mMar fahxoCUbOQmukLH4mHkfToQupgHWU28= X-Google-Smtp-Source: AGHT+IEH2YDWSUnhEgfWCGgR+98w6FawDbtFktZAaEwW0rwhcX5E0pG0uL5OEd/UV2sidXjqSrU53w== X-Received: by 2002:adf:e253:0:b0:317:5e73:7594 with SMTP id bl19-20020adfe253000000b003175e737594mr2855909wrb.28.1691211881854; Fri, 04 Aug 2023 22:04:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z12-20020adff1cc000000b0031434c08bb7sm4126639wro.105.2023.08.04.22.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:04:41 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Sat, 05 Aug 2023 05:04:36 +0000 Subject: [PATCH 2/5] trailer: split process_input_file into separate pieces Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/trailer.c b/trailer.c index dff3fafe865..16fbba03d07 100644 --- a/trailer.c +++ b/trailer.c @@ -961,28 +961,23 @@ 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" and populate the "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); @@ -1003,9 +998,7 @@ static size_t process_input_file(FILE *outfile, } } - trailer_info_release(&info); - - return info.trailer_end - str; + trailer_info_release(info); } static void free_all(struct list_head *head) @@ -1054,6 +1047,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 +1058,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); From patchwork Sat Aug 5 05:04: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: 13342518 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 136CCC001DB for ; Sat, 5 Aug 2023 05:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjHEFFD (ORCPT ); Sat, 5 Aug 2023 01:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjHEFEp (ORCPT ); Sat, 5 Aug 2023 01:04:45 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC6564ED8 for ; Fri, 4 Aug 2023 22:04:44 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fe1489ced6so4773736e87.0 for ; Fri, 04 Aug 2023 22:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691211883; x=1691816683; 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=yVU3Q/+XSVqi+X/JV8eH4hrNkFtGZzIN3enFRILoyHI=; b=iborR6Jannnm4FAn8+UUB0jEYE6Lb9gzBLgyjZJB26Q6y8aHqOLe2zzCN9tXdOCcpv Zoqq06I3+XzGkmtvPELT8/Ifc9yMfKcE4Isubr8VwHxOGTZPHYrSzzefaUZRr+IUVFSl he2OV89usx/uJMdKsC1isdJbfcWyQeyErbmsff0EcIDaTcLZC+mwDR8BZNYwHT6Nfbnt +3Ldr/Rg0kHwMDQ7HVjYuMKoJ7XWN3TupA5qkWKBlPEdu2XGqMNk+gz9TEtU2NPaEBbs GI03dXlcFx5OoaK3c4BKSy82KX61BLRvXYjqXd0t7F+bEZtoDM/wCmOUr67O8banIsqg 1xdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691211883; x=1691816683; 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=yVU3Q/+XSVqi+X/JV8eH4hrNkFtGZzIN3enFRILoyHI=; b=llHtMY+apEfRrK+cKuiaWQLrOzw1o96XXyZjtKvKZ3AiIZXqojLJUNvbLkefurPY6S Rn/YoZ61g1i1p86T9QNm5Y938v+59pnW0vYDuXJeDJ3LXlpPuMaWbJx6JPGPamNZ3oP4 S4gqmAt6nK+BhfcZ7RGq1kVFuNEvyjATPju+zhzZGyNwIYB467Cb7v7j37yHVxnfJJlH gELDw999hPV6d63Bl9cmBdmPNkJLJpi93i+iwUK/5qGcxgzbNG3KS1hWGkGWl8EvlJDD QhxKOnhoHwjosjKj+hS1ptlNnq9RCnenJ4FD9xFtvinNqyVBzfyrJxjOtM4DusCfoelC n80g== X-Gm-Message-State: AOJu0YxPdt3Vs4REIW6imaYQpvNCtx/3oDlKY1tQCQMAZg8Y0KWbakWN zkn7q/XISTkTEAndg6TDIloxnkTC4Vw= X-Google-Smtp-Source: AGHT+IGIofkhhTDpAg9urek4os0132okhfK4Ap3iDJ0hFOPvVDK2muQ5u+iyzY+1XtcX/tEGPBQZiQ== X-Received: by 2002:a05:6512:36cd:b0:4f9:571d:c50e with SMTP id e13-20020a05651236cd00b004f9571dc50emr2361575lfs.36.1691211882540; Fri, 04 Aug 2023 22:04:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o1-20020adfeac1000000b00317643a93f4sm4125652wrn.96.2023.08.04.22.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:04:42 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Sat, 05 Aug 2023 05:04:37 +0000 Subject: [PATCH 3/5] trailer: split process_command_line_args into separate functions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 these concerns into parse_trailers_from_config and parse_trailers_from_command_line_args, respectively. Remove (now redundant) process_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 16fbba03d07..89246a0d395 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) { @@ -1070,8 +1075,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 Aug 5 05:04: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: 13342517 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 AB983EB64DD for ; Sat, 5 Aug 2023 05:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbjHEFFA (ORCPT ); Sat, 5 Aug 2023 01:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjHEFEp (ORCPT ); Sat, 5 Aug 2023 01:04:45 -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 ECC234EDA for ; Fri, 4 Aug 2023 22:04:44 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe4a89e7efso9102355e9.3 for ; Fri, 04 Aug 2023 22:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691211883; x=1691816683; 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=2JqhnDTFQwgL25RJZUSWy6/RPTmoNhSBdaCeoROhT58=; b=dZz0Sncd7/UvybU8alI2I+d4APbUTvC+2HwDHsSUNv3LUP4WuxE7c3y8PS0zaND2J9 gicfei3BBCOwEC+VBKeJ4bElb77S8H9CotPwOlSz4WeqemBsw1vrbcPNuM2X8dQ9s+MG XUFe6mkUPejOyHAKtFoVseb7E1kVNY4X0PMQehzpegCK/CoHqUuA6RaVRKlgQC61VXqA J4aMAwfslKd02dGqb8x+EVa5t5JgyvMdkBTjxFKmK5e13Zr3YATphKnSJDOk9H8O+SBp NKXe9uvWmfw+dDwzGsB0pzJyL6OF0BHmQ8q67XhrAInSr/j4qWQY+guHqUU5YB7IJAfU MOoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691211883; x=1691816683; 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=2JqhnDTFQwgL25RJZUSWy6/RPTmoNhSBdaCeoROhT58=; b=KO4Whz/Kj8sk4jaPFLhpzo19GskaUoTa4SA6BWiKokto4no+cVg2iD8CC0s5R0NlaU rHCPrf5LQflu/w6tmc2I8exaOi7sZZx1bGR35l525noa8BL1xuQhgNOxymoGFrH03o90 AXo7y4Jdx2e/8wUXNwtPOoZbyV6r/KO/2R9jegDdqUvZxi+QqVjjRb/I2KjT+QAYENY8 RjJlXUPe2pMMS1nm4j8IRm8wt/9lQlwRlyOg8UFu3wkJsiBMkOqGJCzRgCxJFN2mN12r Zxwp2NR1R+pYliHGuYqz7fk6pwGfM/yBZD8WI6iz4qGR1EBHM5kAQnWICOoYXhirXRbS oThQ== X-Gm-Message-State: AOJu0YwVUnhH/5KjAuROW9kVaXl4EFkANsTntoTcSeeouSFIwBjPR+BV 5/K1SLLFzNVG96+cgee9sRybbiz9Q8I= X-Google-Smtp-Source: AGHT+IEUdFlLj+HquwJp2LgC3sT7PbmT/HWO1wiZlvdS1jDr2MU60tGlfpW/Dx6z5X2pL3BzfCMToA== X-Received: by 2002:a05:600c:ad2:b0:3f8:b6c:84aa with SMTP id c18-20020a05600c0ad200b003f80b6c84aamr2480906wmr.24.1691211883245; Fri, 04 Aug 2023 22:04:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 25-20020a05600c029900b003fba2734f1esm8283046wmk.1.2023.08.04.22.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:04:43 -0700 (PDT) Message-ID: <1fc060041db11b3df881cb2c7bd60630dc011a15.1691211879.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 05 Aug 2023 05:04:38 +0000 Subject: [PATCH 4/5] trailer: teach find_patch_start about --no-divider Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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. 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 89246a0d395..3b9ce199636 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 Aug 5 05:04: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: 13342519 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 41F1BEB64DD for ; Sat, 5 Aug 2023 05:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjHEFFG (ORCPT ); Sat, 5 Aug 2023 01:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbjHEFEr (ORCPT ); Sat, 5 Aug 2023 01:04:47 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8CF11B for ; Fri, 4 Aug 2023 22:04:45 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe32016bc8so24186475e9.1 for ; Fri, 04 Aug 2023 22:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691211884; x=1691816684; 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=k1qMRW4vQEU0fI5SxPOedS4wZ4GleVwAJsylDKgKOHQ=; b=DKeyjGHQFHVEpwilVmaJFrdzjpVKjnWEC3tRRjoAmzJMms/KED9OoQDqayX9Ho03vU k+S3bX8+SSTblEHss+TWOEl6mbZHxkfZ++HUQL4WwIdiOF2FBtRLWrFm39YV1MrXv8N0 6U4gaEJTW1NW8Af6yj95jVJZ8GkRoA4VOQEy8axsUuxnayQXhvKVT8cJyj7vA4qeTceb cebOwjI9y7pa5TKTJ+HsFdkCxfRaz59KuGxrkVY7OxZ3WLZ0RurPiLLkXhgPJD3Mo/to jRXAxP/NxlIgBm2kO4UulPXOkCHbJNAI8hIuzlmXOrxjFN0EBYZrb1CkvW39Lv6t07rj 81ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691211884; x=1691816684; 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=k1qMRW4vQEU0fI5SxPOedS4wZ4GleVwAJsylDKgKOHQ=; b=QXXX2rbSTfQYAieql98LHnCdXMSm4z/4REUZppEbsCzI731FlVFP3CyOVwjoP2WZ6s eYeNZHYvO7q4jsmwhIknGNWHcvP/pQB2odj9gYigm61QWrw2mwAo4bASoJR3Z4IIWO2c b43uEoFu9e8bni82bCAs5S7k+c8tesiS/TvDF+8aXyw5Kp1qMowmy/6IWtHqU0fgaes2 wuoZ7iKT8IfsuryVZVb+98ANtIt+8qsqlxWYZoIOkV2QR8eVFc6CipI2yYUICW/ButHR jJZlkwgfhiZSY+xTUQjSJDk7LCkEfZuOCLnkc1Kty52vSzOjxAJveb+1wb3WCeGSa9KF VHiA== X-Gm-Message-State: AOJu0YyL9l1AF2eyVKQXfZRJFGGFqe2HXF90NA1BbMtzMSNkZVrNn4mu tPjXfNXPhQ7Qx9iioLGRcnQEGmTf94c= X-Google-Smtp-Source: AGHT+IEAW2MxTbE2jKNgS8Sj7APz0R5hn6s1Dxs1RR9yuHRaC+ywmN6Do1/sRSugTaXwqBPrcx7TSw== X-Received: by 2002:a1c:ed03:0:b0:3f8:f1db:d206 with SMTP id l3-20020a1ced03000000b003f8f1dbd206mr2477729wmh.25.1691211884009; Fri, 04 Aug 2023 22:04:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l7-20020a7bc347000000b003fbdbd0a7desm8348699wmj.27.2023.08.04.22.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:04:43 -0700 (PDT) Message-ID: <7c9b63c26164b037272fde689bb3150b30aa7528.1691211879.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 05 Aug 2023 05:04:39 +0000 Subject: [PATCH 5/5] trailer: rename *_DEFAULT enums to *_UNSPECIFIED Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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. 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 3b9ce199636..c49826decae 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 db57e028650..924cf5405c6 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 };