From patchwork Fri Feb 16 23:09:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560877 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33DAA39856 for ; Fri, 16 Feb 2024 23:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124957; cv=none; b=POpq6xAkJA6r4S9A6IY+SD1TBPLZwQhdST+bYvfEygXi29vTmWxipOuyWTVQ8JytnAWfKoXozIOCiWIPTuWhT7IXaxBbA7hW0XlZUnQJ1StUSabjPoQwinPgcOaIZ66A/bP9RjrirGGBPQlf2Rlv8w0jTqy6BXyaUqONLhCaFA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124957; c=relaxed/simple; bh=VtcouaHw6ztbGb3EWtk4zEbxwTZdAZDIvLKHObqns28=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=FxAfZiwe8d8KiebdLPkFKu36Tldbm3IaXKELwnEAs8JSCgXurFZPH5FlX2eUZ3nqJFkLs6FxOzMPQFPQ3wIP809oENxODzJCVYS7W6va5CyqGf+c1IyBwhYwmxT+js+tbCyr6ci/p2RAG1S1BAl0IU92pvByE03WRnnTARa7XwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UaOqITZd; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UaOqITZd" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40fd2f7ef55so20756645e9.0 for ; Fri, 16 Feb 2024 15:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124954; x=1708729754; 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=aNGSXY0lACUj57g92wZ8kTjwAhEGXfhsU6tUIWHtlMI=; b=UaOqITZdnwxE6rOFTPzRFW8nIS9qNptH0ekYljucWVRB5YBC1L55pba0Dg4uiQZrm9 jVgVg/XSbvkD7UOSta7xgUOD+dh/0RTlzWx5zKhOcq5hy51vOWOv5aKSnzM+J53yrCO8 e2SXQw8HKaiN4yyiF40fQxPmRLF66UNlg+TfP4tPkkOXYxNsXbZbgkhnbc/f9ACJdKxq lxQQ9YPFzuo6w/z7AkVT8qUdpSs4eoP+7xsdxqCcvoC06YgDhGFCHjTqcqd2irZvuqJD /yRiHblMu+RGHhau6/yin7D4oM3deWF5RDWB0nqhI2kZF4O51n/KTl7e3ZgaLGYG/J8P T5EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124954; x=1708729754; 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=aNGSXY0lACUj57g92wZ8kTjwAhEGXfhsU6tUIWHtlMI=; b=HMk2GtsLW6Wb1aWgVrrgq9blU8Jt5g66sGwHDCcPzYUrHIHYHxHqOSuxG1b4hqZ5k6 t++b32JPpzj5DIJTpP5wqIrtsZabcZvFL8AoqmRagmsEhvdawwVYJp/mvp7oxawtwXR3 4rUtTw33xzpz8YFycCo3ZU5qSD3zjGmq7RT9fodVaOhP06nvD6+2Nw3MBw8IIQ4yaZ5Y 8uoWjGW0uOvvWzCO3nUSkzK0pO9Gjh9BPboxrTQlq6o5kHhylXcJr4/qB2Jk+HfpkLDW 15Zxcw9rKPY4CqvbLvdb6iSYr9GzhXi5pbHfquIJKXdJL5RiipxU4Bh0LTbejv0BoUZH 3UuQ== X-Gm-Message-State: AOJu0YyktmZPtheB3wW5d115URdPTR5fwDSbDrkBKqMK47KYaqOUEGh0 tflKJMqVJTJScsxeIWuvb/vPY9e1wnEXCHwGTubLks2iCS1thpjhkvsEWpM9 X-Google-Smtp-Source: AGHT+IHK8quNm/DAJ2O2dBDtnuDjqBn1rR7O0JkANoKcLF1HZNXJOszi2rTO+UMOdLjR+wn9MhqTcQ== X-Received: by 2002:a05:600c:511b:b0:412:5652:138f with SMTP id o27-20020a05600c511b00b004125652138fmr573749wms.16.1708124953587; Fri, 16 Feb 2024 15:09:13 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 23-20020a05600c231700b00410b0ce91b1sm3484836wmo.25.2024.02.16.15.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:13 -0800 (PST) Message-ID: <652df25f30ecc8227bef5109b0f7b47817386b13.1708124951.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:02 +0000 Subject: [PATCH v5 1/9] trailer: free trailer_info _after_ all related usage Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver In de7c27a186 (trailer: use offsets for trailer_start/trailer_end, 2023-10-20), we started using trailer block offsets in trailer_info. In particular, we dropped the use of a separate stack variable "size_t trailer_end", in favor of accessing the new "trailer_block_end" member of trailer_info (as "info.trailer_block_end"). At that time, we forgot to also move the trailer_info_release(&info); line to be _after_ this new use of the trailer_info struct. Move it now. Note that even without this patch, we didn't have leaks or any other problems because trailer_info_release() only frees memory allocated on the heap. The "trailer_block_end" member was allocated on the stack back then (as it is now) so it was still safe to use for all this time. Reported-by: Junio C Hamano Signed-off-by: Linus Arver --- trailer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 3a0710a4583..e1d83390b66 100644 --- a/trailer.c +++ b/trailer.c @@ -1111,13 +1111,12 @@ 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) fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile); + trailer_info_release(&info); if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) From patchwork Fri Feb 16 23:09:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560878 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E4014831E for ; Fri, 16 Feb 2024 23:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124958; cv=none; b=RjDuZJKcSTK73jo4PCUuA5+AEa1GlrpCWob6qqkI9nmg8ubRNa+bWSgAYnnUzrzjRJ1h1ZLAgLt4lKNJo1k6BMvjR4D1als/hTYpcqiRHdRMln5EpP/8yDw33kC4A70J78IXfprrIDbocZE2pKgeZehS/y245L9wHsm4cmp41OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124958; c=relaxed/simple; bh=drUD39xUc8WM+utEVxXTiU0Dg0IS66wVnv7Mt5VGK2A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=O/bHTvyupoIhr0WI31eBj/wamqha8mDyCTFe8cia9MrNL7KS2rYPOM962dNA1gjTZ74NFzNxHUhLzplnDMO6wi3gLuWlYWTZ2IyZbd++JVOuhnDcLvCLuAOLPOOyGhy8I3rfd7LmZYO7bVvSxXO21TCcBE8TgtGnkVECo2IcBSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HR8R653T; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HR8R653T" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-412568b5c1eso1800695e9.1 for ; Fri, 16 Feb 2024 15:09:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124954; x=1708729754; 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=duyinlY0QkJJiADy/N5wKycwy0BLJrkHINGYsEMmQcA=; b=HR8R653TW3DTuSZ4B4PUP/Fe1rLcAd5krmhVOkjFrKMAJQ8S5Dkg7OrJy9mIiVCHKx O20numvKRzqObAiwM/HhBFHZRWXEOHJsuHWuDHkkvxLTpb0Wesqlf1YMWsAoVU96Roqw z+oShHgHDxLZk9qYP2qHNP2XP7UVxXRZfieAIrUmvX4mgo5NFwdDnZoFNgbBZIyoK1CP xt5VFHCnaOXM8Z+zGz7pfpMeyVI2lG1vYheY5uhoGgvegM4sbaZ/krruRLrwkad+tDTA AjwJiUITpNXF+r9JrOCnRbdRtglibMJVOxGdsKgU0W2BW6vkr+dQBwXe2MfNth6uA0Bd 2X5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124954; x=1708729754; 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=duyinlY0QkJJiADy/N5wKycwy0BLJrkHINGYsEMmQcA=; b=i+GcVAYRfHbttt/rqQIjzj9+Qz3pQy4jVXZA+UQgpMD7Mf1AcC2vfl2/h5lzlXQWbv 39gG51Z6cHf8msBkJXFlCPepxSWyFjSkDVGXjhzItWhcMb1+m2JP1Ql/TlW28Ihvxe+E E/d2+T/BcsyXfPxN2RrfjU32Ph8d0Jb1/ScwyAeMpEvtaX+pHGG045QsINqEruVMAzBF pA3LOiYy4CW7mzob55ZHYy4dhCOthxdKr0Xv1z2j74Plg2cMs+J77+iUbTUGiCYFDqeN E4S/4rBRqXgb45ybPEewXSgtDSVWaTlYOkh4MdT4RkG3bsbaeJr5jGCWxrRZAydfBMr/ eplg== X-Gm-Message-State: AOJu0Yz07E4K6EARQrnNw1meT7Uc1VLV+6PCDvDeXmJhlTzgLF6Smzz1 5wL+Ndq84NaxVYSmOiB1XOvHp6mFVHOqiaHn+J8Cc2HAPfSs/ZGGXWSRaQTo X-Google-Smtp-Source: AGHT+IFtw07uu7fAnrUl3Di81WjGJp98PVi+cJKMyf4604os4bTCRvjjFMNirrUmX4MXFsNdnJ0eOQ== X-Received: by 2002:a05:600c:3515:b0:412:4a57:388c with SMTP id h21-20020a05600c351500b004124a57388cmr1879806wmq.14.1708124954118; Fri, 16 Feb 2024 15:09:14 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z3-20020a1c4c03000000b004120675e057sm1688016wmf.0.2024.02.16.15.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:13 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:03 +0000 Subject: [PATCH v5 2/9] shortlog: add test for de-duplicating folded trailers Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver The shortlog builtin was taught to use the trailer iterator interface in 47beb37bc6 (shortlog: match commit trailers with --group, 2020-09-27). The iterator always unfolds values and this has always been the case since the time the iterator was first introduced in f0939a0eb1 (trailer: add interface for iterating over commit trailers, 2020-09-27). Add a comment line to remind readers of this behavior. The fact that the iterator always unfolds values is important (at least for shortlog) because unfolding allows it to recognize both folded and unfolded versions of the same trailer for de-duplication. Capture the existing behavior in a new test case to guard against regressions in this area. This test case is based off of the existing "shortlog de-duplicates trailers in a single commit" just above it. Now if we were to remove the call to unfold_value(&iter->val); inside the iterator, this new test case will break. Signed-off-by: Linus Arver --- t/t4201-shortlog.sh | 32 ++++++++++++++++++++++++++++++++ trailer.c | 1 + 2 files changed, 33 insertions(+) diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index d7382709fc1..f698d0c9ad2 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -312,6 +312,38 @@ test_expect_success 'shortlog de-duplicates trailers in a single commit' ' test_cmp expect actual ' +# Trailers that have unfolded (single line) and folded (multiline) values which +# are otherwise identical are treated as the same trailer for de-duplication. +test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' ' + git commit --allow-empty -F - <<-\EOF && + subject one + + this message has two distinct values, plus a repeat (folded) + + Repeated-trailer: Foo foo foo + Repeated-trailer: Bar + Repeated-trailer: Foo + foo foo + EOF + + git commit --allow-empty -F - <<-\EOF && + subject two + + similar to the previous, but without the second distinct value + + Repeated-trailer: Foo foo foo + Repeated-trailer: Foo + foo foo + EOF + + cat >expect <<-\EOF && + 2 Foo foo foo + 1 Bar + EOF + git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual && + test_cmp expect actual +' + test_expect_success 'shortlog can match multiple groups' ' git commit --allow-empty -F - <<-\EOF && subject one diff --git a/trailer.c b/trailer.c index e1d83390b66..f74915bd8cd 100644 --- a/trailer.c +++ b/trailer.c @@ -1270,6 +1270,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) strbuf_reset(&iter->val); parse_trailer(&iter->key, &iter->val, NULL, trailer, separator_pos); + /* Always unfold values during iteration. */ unfold_value(&iter->val); return 1; } From patchwork Fri Feb 16 23:09:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560879 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD1C41487C5 for ; Fri, 16 Feb 2024 23:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124959; cv=none; b=XOGO0ugI2J7x4azsT8wEPdsuqT7kIEVthZIMGw/dUJG3E9YpJF6tqR5Gah+EwNpgF4F65yfVXwCtMk/11IJYtuOs0Re27MDWvZmlqhsLjhGH0+FyxCQzTz8QJuap709S3gwYP78hoA5pwOthkWUfe0U307id9xyauOjg1Bqfhdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124959; c=relaxed/simple; bh=avfyyuClJLJU2yE+T/eicbZ3hY9bhE4GunGon0T+5KA=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=X1pQYOJafIQdOOqqgSN+34KhDCGmT4Fe2yWD86OsQ12hzA3BkEHMF1PjPW9DMVhGPxdmDKfa3E3FqbPlU2V/PwHhVyPbnvsA8cLZnoAHemUhP+++JkRXZ2qx0Vf+ea4JSG/sQzbx3mCzcCiY/vpX5+V82j/lX8e+Ma3oV4BuAgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IqoxGQ3C; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IqoxGQ3C" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so945825f8f.1 for ; Fri, 16 Feb 2024 15:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124955; x=1708729755; 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=7RlPQ7lvsukyjl8KrER6rCMtmPCthZw0L1uxO7Jp9gM=; b=IqoxGQ3C/61ryjKgb7jOH7MCr2kzH/XU/ZtGjc+Hon8s5pfpazQi54xC49VdfVZ6J4 rD2hCL7jcso0yNzk1z5ykqR38qZ/iewkj+Wcu03xEdehV4VAfm1Jhm+WSBD71a0J3Tap sjexfiC//MTtKvhVa/RBIZW3d0AAHbKEH3VabOw8ahXI4nKQ6uIVWx0aozlxLZykoPN3 jTlJIuvqw2BjhavKabtYXRMiQkrjXV90EZYTOF8jT5FoUdTcBGTDQDcfFFkn+m3XiaUB 0Al/insdYGNiD9fm6zrCu90Gx6Ll8P3ILlsoHykWRxZdz3Bhr0SREJEYW0hRQqbh0fBM F8fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124955; x=1708729755; 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=7RlPQ7lvsukyjl8KrER6rCMtmPCthZw0L1uxO7Jp9gM=; b=IiT7gOOP613P4xwB9oM0aHFv2TWKHnE/mimfupyJn4w4/sMNHA1ja8Miqk2QlvmVIx Bkjx4yg+06Dt2PYf38LzlFnGQTNmlKCNAuAjTi+LYaMtlCaKuFqQnkwsYN8JU2G51j58 tU0exLlmwnyVVzD/4Omofy5PWx8TGznSw2+pWB34ImAz8CP3GArUq+TCSCtH5PRzLisf P064cO3KGQ9LjpfeDWzC+l8iCix13IrBwXTBtStOkHEDdMZv/25BOIv2fwB+Rfat6gPa mhjgifD1OZDqKR25ewI4xmQG/a7j3taAuhF89Xj9e0ODEFp2UuFnrTsWfd6advwxTRUK ZXqQ== X-Gm-Message-State: AOJu0YyCWrwVNXGWBkF2RJ+09ktW+M4JqVSQar5wGIJLzeEqxnfkNrzB 13PGledJN3I8qifa5sET13X8URAkuKIrb7FcMzadva0YA6tnj7mTDJzipvSm X-Google-Smtp-Source: AGHT+IEpm0eARyutingpdSotzOBszoBWEGK5o8eE0tT16sbojViU/A7qSsjE4pfU4TlmFp96cf4fug== X-Received: by 2002:a5d:5266:0:b0:33b:6585:9ab7 with SMTP id l6-20020a5d5266000000b0033b65859ab7mr4891545wrc.46.1708124955543; Fri, 16 Feb 2024 15:09:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h5-20020a05600016c500b0033d200aff9asm2620473wrf.56.2024.02.16.15.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:14 -0800 (PST) Message-ID: <4372af244f02b71cc70f3a8e1b5591b3b9fec93a.1708124951.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:04 +0000 Subject: [PATCH v5 3/9] trailer: prepare to expose functions as part of API Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver In the next patch, we will move "process_trailers" from trailer.c to builtin/interpret-trailers.c. That move will necessitate the growth of the trailer.h API, forcing us to expose some additional functions in trailer.h. Rename relevant functions so that they include the term "trailer" in their name, so that clients of the API will be able to easily identify them by their "trailer" moniker, just like all the other functions already exposed by trailer.h. Take the opportunity to start putting trailer processing options (opts) as the first parameter. This will be the pattern going forward in this series. Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 4 ++-- trailer.c | 26 +++++++++++++------------- trailer.h | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 033bd1556cf..85a3413baf5 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -132,11 +132,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) if (argc) { int i; for (i = 0; i < argc; i++) - process_trailers(argv[i], &opts, &trailers); + interpret_trailers(&opts, &trailers, argv[i]); } else { if (opts.in_place) die(_("no input file given for in-place editing")); - process_trailers(NULL, &opts, &trailers); + interpret_trailers(&opts, &trailers, NULL); } new_trailers_clear(&trailers); diff --git a/trailer.c b/trailer.c index f74915bd8cd..916175707d8 100644 --- a/trailer.c +++ b/trailer.c @@ -163,12 +163,12 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val) fprintf(outfile, "%s%c %s\n", tok, separators[0], val); } -static void print_all(FILE *outfile, struct list_head *head, - const struct process_trailer_options *opts) +static void format_trailers(const struct process_trailer_options *opts, + struct list_head *trailers, FILE *outfile) { struct list_head *pos; struct trailer_item *item; - list_for_each(pos, head) { + list_for_each(pos, trailers) { item = list_entry(pos, struct trailer_item, list); if ((!opts->trim_empty || strlen(item->value) > 0) && (!opts->only_trailers || item->token)) @@ -589,7 +589,7 @@ static int git_trailer_config(const char *conf_key, const char *value, return 0; } -static void ensure_configured(void) +static void trailer_config_init(void) { if (configured) return; @@ -1035,10 +1035,10 @@ static void parse_trailers(struct trailer_info *info, } } -static void free_all(struct list_head *head) +static void free_trailers(struct list_head *trailers) { struct list_head *pos, *p; - list_for_each_safe(pos, p, head) { + list_for_each_safe(pos, p, trailers) { list_del(pos); free_trailer_item(list_entry(pos, struct trailer_item, list)); } @@ -1075,16 +1075,16 @@ static FILE *create_in_place_tempfile(const char *file) return outfile; } -void process_trailers(const char *file, - const struct process_trailer_options *opts, - struct list_head *new_trailer_head) +void interpret_trailers(const struct process_trailer_options *opts, + struct list_head *new_trailer_head, + const char *file) { LIST_HEAD(head); struct strbuf sb = STRBUF_INIT; struct trailer_info info; FILE *outfile = stdout; - ensure_configured(); + trailer_config_init(); read_input_file(&sb, file); @@ -1110,8 +1110,8 @@ void process_trailers(const char *file, process_trailers_lists(&head, &arg_head); } - print_all(outfile, &head, opts); - free_all(&head); + format_trailers(opts, &head, outfile); + free_trailers(&head); /* Print the lines after the trailers as is */ if (!opts->only_trailers) @@ -1134,7 +1134,7 @@ void trailer_info_get(struct trailer_info *info, const char *str, size_t nr = 0, alloc = 0; char **last = NULL; - ensure_configured(); + trailer_config_init(); end_of_log_message = find_end_of_log_message(str, opts->no_divider); trailer_block_start = find_trailer_block_start(str, end_of_log_message); diff --git a/trailer.h b/trailer.h index 1644cd05f60..37033e631a1 100644 --- a/trailer.h +++ b/trailer.h @@ -81,9 +81,9 @@ struct process_trailer_options { #define PROCESS_TRAILER_OPTIONS_INIT {0} -void process_trailers(const char *file, - const struct process_trailer_options *opts, - struct list_head *new_trailer_head); +void interpret_trailers(const struct process_trailer_options *opts, + struct list_head *new_trailer_head, + const char *file); void trailer_info_get(struct trailer_info *info, const char *str, const struct process_trailer_options *opts); From patchwork Fri Feb 16 23:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560880 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 718C91487E4 for ; Fri, 16 Feb 2024 23:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124960; cv=none; b=gGDHg1LT76dWNrN3i910HjztesWcpKWb5q6+6vHAdqyZa5j+Z5nMUcGUB5ZnYukghJWtGkhMUwWcRPlXWKmeVnfnusIEUQDGu7kjxbXMkkOSZbOyRNtFnZtfTl6jPcuMntAZAVhlDKd0S89+zRiz+bGOgepNaETTurF/2AM5o7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124960; c=relaxed/simple; bh=iQq/mzoDTFVBBW11XhOGyw7hHLmxOQ8KAtf6x2O4BrM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Os2M42TR3sc2Wd4N841G0PGVr/ijvBtrI/K3QoAUa2FLKke3ShM6LcTVjH8mfVOPmQP7xs6BSSvmbP91umxPMm71IM44aLTlg07JVvwXzR1anlazTrCHef4GfogcqF4iQHrvfbQYQrDWqjqzEiMXBp0S271lD2VmHd3pvnUOkrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Aeyv0drq; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Aeyv0drq" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-33d2b354c72so75308f8f.1 for ; Fri, 16 Feb 2024 15:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124956; x=1708729756; 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=W7YLMZ14+/mfS/Pyujjr2LPLJJm5ibHbnFQgiuGM6mk=; b=Aeyv0drqrFJbepv7pJz7lS736M0PYElYiHdqWN32dAHmJtiPUcoiCabxUTAS1vZQf1 ou4NncES6r1bmVBYyfznLDZjjORx6jwuUS286KBoS0Rad8AYwCcsneQarJrVZTAk9H1C qwQW7kcwkEmU2b4UC0sXim9Hmhjeto+usNBUcxOBmcfb7Emy2b2B96pfF1/YVdilRQuK Hwd9OZpfWcJTAtLEn7GxEGQngkqsZnutmn/NPy/jmscAo8bTRl13WpuewKyAERKGOqwv do0jOaSsgHVHmu7VXbBpSzY7Yl80/OyNze5uRCXbmqDQWcudPidYRCcsnIPpZ1zJfpr1 8q8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124956; x=1708729756; 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=W7YLMZ14+/mfS/Pyujjr2LPLJJm5ibHbnFQgiuGM6mk=; b=FQI0dzO0XXtHezq3PUBXiG6oZoBLdMaUxw/Lil1MTkWbMsoBGU5Ls8NCVGY7vOWrRF LNkBu7KSLYXNYorctx4NrEoKfNmrkj0xZFYY8XqichQ38cprfUu6pioEncRJV6xRAvD5 6rlaMXsaCMR71hja6MDzP1uiALZDZmlqESssdH4q4ML2Opr3d+eYYt9Ub+ZQnecqr2qt 4MuLDz5qlVgk+R+tEjeuR0aJXXM8fc5E8tl2QsEYxeFSJyXxgvaoiAPYyY8ILi6ilk6K //89qcj8eJvCoVY55di5HjDTKalcaY12Wqa59d5rFcuyvZbgCnlrteDorqkkdYyPEpEM C33g== X-Gm-Message-State: AOJu0Yyxxm6rQndg2vjclNlZWN1fGspkrqxHiZ2v7Pd8rietzyKZKklY uVeW0IRopC59We/wZdRF//EFCWeYUzB11WFj6PfSK7CLqRNdy+MYkh0NU9+I X-Google-Smtp-Source: AGHT+IG7nX5Pk7fm5YxK0ohSUbTJzR1JlpaD7PXT0jiVRxeVxg17M2aONzmCgJCp9WtIU0T+kj4muQ== X-Received: by 2002:adf:e646:0:b0:33d:247a:ba10 with SMTP id b6-20020adfe646000000b0033d247aba10mr1509451wrn.43.1708124956392; Fri, 16 Feb 2024 15:09:16 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u4-20020adfcb04000000b0033d24eab9c3sm1575520wrh.76.2024.02.16.15.09.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:15 -0800 (PST) Message-ID: <4073b8eb5101ea49d8e79b40822aaa42ca87d24d.1708124951.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:05 +0000 Subject: [PATCH v5 4/9] trailer: move interpret_trailers() to interpret-trailers.c Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver The interpret-trailers.c builtin is the only place we need to call interpret_trailers(), so move its definition there (together with a few helper functions called only by it) and remove its external declaration from . Several helper functions that are called by interpret_trailers() remain in trailer.c because other callers in the same file still call them. Declare them in so that interpret_trailers() (now in builtin/interpret-trailers.c) can continue calling them as a trailer API user. This enriches with a more granular API, which can then be unit-tested in the future (because interpret_trailers() by itself does too many things to be able to be easily unit-tested). Take this opportunity to demote some file-handling functions out of the trailer API implementation, as these have nothing to do with trailers. Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 93 +++++++++++++++++++++++++++ trailer.c | 119 ++++------------------------------- trailer.h | 20 +++++- 3 files changed, 123 insertions(+), 109 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 85a3413baf5..d1cf0aa33a2 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -9,6 +9,7 @@ #include "gettext.h" #include "parse-options.h" #include "string-list.h" +#include "tempfile.h" #include "trailer.h" #include "config.h" @@ -91,6 +92,98 @@ static int parse_opt_parse(const struct option *opt, const char *arg, return 0; } +static struct tempfile *trailers_tempfile; + +static FILE *create_in_place_tempfile(const char *file) +{ + struct stat st; + struct strbuf filename_template = STRBUF_INIT; + const char *tail; + FILE *outfile; + + if (stat(file, &st)) + die_errno(_("could not stat %s"), file); + if (!S_ISREG(st.st_mode)) + die(_("file %s is not a regular file"), file); + if (!(st.st_mode & S_IWUSR)) + die(_("file %s is not writable by user"), file); + + /* Create temporary file in the same directory as the original */ + tail = strrchr(file, '/'); + if (tail) + strbuf_add(&filename_template, file, tail - file + 1); + strbuf_addstr(&filename_template, "git-interpret-trailers-XXXXXX"); + + trailers_tempfile = xmks_tempfile_m(filename_template.buf, st.st_mode); + strbuf_release(&filename_template); + outfile = fdopen_tempfile(trailers_tempfile, "w"); + if (!outfile) + die_errno(_("could not open temporary file")); + + return outfile; +} + +static void read_input_file(struct strbuf *sb, const char *file) +{ + if (file) { + if (strbuf_read_file(sb, file, 0) < 0) + die_errno(_("could not read input file '%s'"), file); + } else { + if (strbuf_read(sb, fileno(stdin), 0) < 0) + die_errno(_("could not read from stdin")); + } +} + +static void interpret_trailers(const struct process_trailer_options *opts, + struct list_head *new_trailer_head, + const char *file) +{ + LIST_HEAD(head); + struct strbuf sb = STRBUF_INIT; + struct trailer_info info; + FILE *outfile = stdout; + + trailer_config_init(); + + read_input_file(&sb, file); + + if (opts->in_place) + outfile = create_in_place_tempfile(file); + + parse_trailers(opts, &info, sb.buf, &head); + + /* Print the lines before the trailers */ + if (!opts->only_trailers) + fwrite(sb.buf, 1, info.trailer_block_start, outfile); + + if (!opts->only_trailers && !info.blank_line_before_trailer) + fprintf(outfile, "\n"); + + + if (!opts->only_input) { + LIST_HEAD(config_head); + LIST_HEAD(arg_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); + } + + format_trailers(opts, &head, outfile); + free_trailers(&head); + + /* 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); + trailer_info_release(&info); + + if (opts->in_place) + if (rename_tempfile(&trailers_tempfile, file)) + die_errno(_("could not rename temporary file to %s"), file); + + strbuf_release(&sb); +} + int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) { struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; diff --git a/trailer.c b/trailer.c index 916175707d8..d23afa0a65c 100644 --- a/trailer.c +++ b/trailer.c @@ -5,7 +5,6 @@ #include "string-list.h" #include "run-command.h" #include "commit.h" -#include "tempfile.h" #include "trailer.h" #include "list.h" /* @@ -163,8 +162,8 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val) fprintf(outfile, "%s%c %s\n", tok, separators[0], val); } -static void format_trailers(const struct process_trailer_options *opts, - struct list_head *trailers, FILE *outfile) +void format_trailers(const struct process_trailer_options *opts, + struct list_head *trailers, FILE *outfile) { struct list_head *pos; struct trailer_item *item; @@ -366,8 +365,8 @@ static int find_same_and_apply_arg(struct list_head *head, return 0; } -static void process_trailers_lists(struct list_head *head, - struct list_head *arg_head) +void process_trailers_lists(struct list_head *head, + struct list_head *arg_head) { struct list_head *pos, *p; struct arg_item *arg_tok; @@ -589,7 +588,7 @@ static int git_trailer_config(const char *conf_key, const char *value, return 0; } -static void trailer_config_init(void) +void trailer_config_init(void) { if (configured) return; @@ -719,7 +718,7 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val, list_add_tail(&new_item->list, arg_head); } -static void parse_trailers_from_config(struct list_head *config_head) +void parse_trailers_from_config(struct list_head *config_head) { struct arg_item *item; struct list_head *pos; @@ -735,8 +734,8 @@ static void parse_trailers_from_config(struct list_head *config_head) } } -static void parse_trailers_from_command_line_args(struct list_head *arg_head, - struct list_head *new_trailer_head) +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; @@ -775,17 +774,6 @@ static void parse_trailers_from_command_line_args(struct list_head *arg_head, free(cl_separators); } -static void read_input_file(struct strbuf *sb, const char *file) -{ - if (file) { - if (strbuf_read_file(sb, file, 0) < 0) - die_errno(_("could not read input file '%s'"), file); - } else { - if (strbuf_read(sb, fileno(stdin), 0) < 0) - die_errno(_("could not read from stdin")); - } -} - static const char *next_line(const char *str) { const char *nl = strchrnul(str, '\n'); @@ -1000,10 +988,10 @@ static void unfold_value(struct strbuf *val) * 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) +void parse_trailers(const struct process_trailer_options *opts, + struct trailer_info *info, + const char *str, + struct list_head *head) { struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; @@ -1035,7 +1023,7 @@ static void parse_trailers(struct trailer_info *info, } } -static void free_trailers(struct list_head *trailers) +void free_trailers(struct list_head *trailers) { struct list_head *pos, *p; list_for_each_safe(pos, p, trailers) { @@ -1044,87 +1032,6 @@ static void free_trailers(struct list_head *trailers) } } -static struct tempfile *trailers_tempfile; - -static FILE *create_in_place_tempfile(const char *file) -{ - struct stat st; - struct strbuf filename_template = STRBUF_INIT; - const char *tail; - FILE *outfile; - - if (stat(file, &st)) - die_errno(_("could not stat %s"), file); - if (!S_ISREG(st.st_mode)) - die(_("file %s is not a regular file"), file); - if (!(st.st_mode & S_IWUSR)) - die(_("file %s is not writable by user"), file); - - /* Create temporary file in the same directory as the original */ - tail = strrchr(file, '/'); - if (tail) - strbuf_add(&filename_template, file, tail - file + 1); - strbuf_addstr(&filename_template, "git-interpret-trailers-XXXXXX"); - - trailers_tempfile = xmks_tempfile_m(filename_template.buf, st.st_mode); - strbuf_release(&filename_template); - outfile = fdopen_tempfile(trailers_tempfile, "w"); - if (!outfile) - die_errno(_("could not open temporary file")); - - return outfile; -} - -void interpret_trailers(const struct process_trailer_options *opts, - struct list_head *new_trailer_head, - const char *file) -{ - LIST_HEAD(head); - struct strbuf sb = STRBUF_INIT; - struct trailer_info info; - FILE *outfile = stdout; - - trailer_config_init(); - - read_input_file(&sb, file); - - if (opts->in_place) - outfile = create_in_place_tempfile(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); - - if (!opts->only_trailers && !info.blank_line_before_trailer) - fprintf(outfile, "\n"); - - - if (!opts->only_input) { - LIST_HEAD(config_head); - LIST_HEAD(arg_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); - } - - format_trailers(opts, &head, outfile); - free_trailers(&head); - - /* 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); - trailer_info_release(&info); - - if (opts->in_place) - if (rename_tempfile(&trailers_tempfile, file)) - die_errno(_("could not rename temporary file to %s"), file); - - strbuf_release(&sb); -} - void trailer_info_get(struct trailer_info *info, const char *str, const struct process_trailer_options *opts) { diff --git a/trailer.h b/trailer.h index 37033e631a1..c292d44b62f 100644 --- a/trailer.h +++ b/trailer.h @@ -81,15 +81,29 @@ struct process_trailer_options { #define PROCESS_TRAILER_OPTIONS_INIT {0} -void interpret_trailers(const struct process_trailer_options *opts, - struct list_head *new_trailer_head, - const char *file); +void parse_trailers_from_config(struct list_head *config_head); + +void parse_trailers_from_command_line_args(struct list_head *arg_head, + struct list_head *new_trailer_head); + +void process_trailers_lists(struct list_head *head, + struct list_head *arg_head); + +void parse_trailers(const struct process_trailer_options *, + struct trailer_info *, + const char *str, + struct list_head *head); void trailer_info_get(struct trailer_info *info, const char *str, const struct process_trailer_options *opts); void trailer_info_release(struct trailer_info *info); +void trailer_config_init(void); +void format_trailers(const struct process_trailer_options *, + struct list_head *trailers, FILE *outfile); +void free_trailers(struct list_head *); + /* * Format the trailers from the commit msg "msg" into the strbuf "out". * Note two caveats about "opts": From patchwork Fri Feb 16 23:09:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560881 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26DFA1487F3 for ; Fri, 16 Feb 2024 23:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124960; cv=none; b=lJTrS1GMACeClJfy2kdL3qi/D7F5v6Fxc7SuB+fW0ekz4XYpNiYXluL4L5o1CJ3C/5v+2d2YyhqcGysZSavTQ12d5zqKe89O/nxlrhdJKx43IZMh4GY5Uq0iB2GRwARJvk42dg89jWgvmKWWa+Ur4uM5cSEAi5xB12er4CD3t1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124960; c=relaxed/simple; bh=g4ZLlEfPTK41Ntq9qyqJcpRFH6ZejOoGqeqQiTtEIFg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=SDfeyD6dKuAYNvVFTcDx2+TDSM1dBDZTuqD7FJsAMfW5SIql+xEMyxUEfLpiIs036SlSE7r1RoGracuTfak6hB77ZEgFp0nzaLEnRuCaEqYw3pWSgeKkMisp2fqn6XzULSGwY58eg1tliS4NpQwOF+9GQyfmfBHrhZWVFevLKd8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l0IMC3vp; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l0IMC3vp" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-33b28aadb28so1428413f8f.3 for ; Fri, 16 Feb 2024 15:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124957; x=1708729757; 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=rEPOGsPtHiV1uwINVtFI7NqdmubuPt+bwMAT2mZoxp4=; b=l0IMC3vpP5K3FakpOaaDNs5487EjIqel6uCglEBnflxfQqLt75sKTrbCLQo114I/Fr rpywohVcooVVwfc+c2gL4qsuaFx+qvG9JluOjarT3dtI5txBPey7XeAKCGuYFGn0rDe6 cKAhO9wtz+3o5SijjQTYjaJb/MbgeSel+vBruWHS09L2aVVd7wgxJ7rvDr5RoR0V/Cge LSVuAn4mC+12QPUk0Cov1AYBzwLzSeidk+3YLf35ruSSo91SKR+6Pnyibui/SVOiGL8L Yiz7EjttMMS8BfGX+pM8ufDa0dcjkcpLyrS4RkP9UPAAEPu4a/Tw3BTCNe21lm8g6qrr RJ/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124957; x=1708729757; 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=rEPOGsPtHiV1uwINVtFI7NqdmubuPt+bwMAT2mZoxp4=; b=AxCnd72Ag8Z9LLkEDr+dfzZs70pWffD/5S2QuihhdHRV6SLf16s+mA+AyJYGVAihuI Z4zWov34GyVD4Fohc+sex1lkaCTASTXHTbb6hR5X82fboRxMy7DXbexJ+DiO1ccU0N8r /mg2qOdikSsw9TaSzM4pdWovjp9T5hSHnhqKFpFWl9f2QU8Gtcm4CyIKgittV5jTWieY 9KjjvntEqmrg16YhyIlp9ZM2GIf55X/ckqeyU4N+3lwdnsDfclHyzYSQVKk84768sP5b sHoTh8UDddzok47v5AbJWqTxYpSsqKxJz18dlcldSWW2umApRWETG+x7k4NnmDO7tJ38 QoQw== X-Gm-Message-State: AOJu0YzIzJ/m9X0M68qCEIJ1sxYSqcW7j8PcUR/m8n1FN4zoT4j3PLCZ dgslwYZbnJGgQtkbH6WUKwITlG7HCGmg2WbBJAuCKPi1oGy4nmlhuVBC1wUm X-Google-Smtp-Source: AGHT+IEu/tw7aetr5SRUMrJVmld8baz8PtD2Ix5Mzmal16qmv2oyKG17T3XIvydbP3KEtn4I8tvcFA== X-Received: by 2002:a05:6000:154b:b0:33d:2848:79b6 with SMTP id 11-20020a056000154b00b0033d284879b6mr797196wry.45.1708124957110; Fri, 16 Feb 2024 15:09:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n14-20020a5d420e000000b0033d282c7537sm735922wrq.23.2024.02.16.15.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:16 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:06 +0000 Subject: [PATCH v5 5/9] trailer: start preparing for formatting unification Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Currently there are two functions for formatting trailers in : void format_trailers(const struct process_trailer_options *, struct list_head *trailers, FILE *outfile); void format_trailers_from_commit(struct strbuf *out, const char *msg, const struct process_trailer_options *opts); and although they are similar enough (even taking the same process_trailer_options struct pointer) they are used quite differently. One might intuitively think that format_trailers_from_commit() builds on top of format_trailers(), but this is not the case. Instead format_trailers_from_commit() calls format_trailer_info() and format_trailers() is never called in that codepath. This is a preparatory refactor to help us deprecate format_trailers() in favor of format_trailer_info() (at which point we can rename the latter to the former). When the deprecation is complete, both format_trailers_from_commit(), and the interpret-trailers builtin will be able to call into the same helper function (instead of format_trailers() and format_trailer_info(), respectively). Unifying the formatters is desirable because it simplifies the API. Reorder parameters for format_trailers_from_commit() to prefer const struct process_trailer_options *opts as the first parameter, because these options are intimately tied to formatting trailers. And take struct strbuf *out last, because it's an "out parameter" (something that the caller wants to use as the output of this function). Signed-off-by: Linus Arver --- pretty.c | 2 +- ref-filter.c | 2 +- trailer.c | 11 ++++++----- trailer.h | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pretty.c b/pretty.c index cf964b060cd..bdbed4295aa 100644 --- a/pretty.c +++ b/pretty.c @@ -1759,7 +1759,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ goto trailer_out; } if (*arg == ')') { - format_trailers_from_commit(sb, msg + c->subject_off, &opts); + format_trailers_from_commit(&opts, msg + c->subject_off, sb); ret = arg - placeholder + 1; } trailer_out: diff --git a/ref-filter.c b/ref-filter.c index 35b989e1dfe..d358953b0ce 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1985,7 +1985,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp struct strbuf s = STRBUF_INIT; /* Format the trailer info according to the trailer_opts given */ - format_trailers_from_commit(&s, subpos, &atom->u.contents.trailer_opts); + format_trailers_from_commit(&atom->u.contents.trailer_opts, subpos, &s); v->s = strbuf_detach(&s, NULL); } else if (atom->u.contents.option == C_BARE) diff --git a/trailer.c b/trailer.c index d23afa0a65c..5025be97899 100644 --- a/trailer.c +++ b/trailer.c @@ -1083,10 +1083,10 @@ void trailer_info_release(struct trailer_info *info) free(info->trailers); } -static void format_trailer_info(struct strbuf *out, +static void format_trailer_info(const struct process_trailer_options *opts, const struct trailer_info *info, const char *msg, - const struct process_trailer_options *opts) + struct strbuf *out) { size_t origlen = out->len; size_t i; @@ -1144,13 +1144,14 @@ static void format_trailer_info(struct strbuf *out, } -void format_trailers_from_commit(struct strbuf *out, const char *msg, - const struct process_trailer_options *opts) +void format_trailers_from_commit(const struct process_trailer_options *opts, + const char *msg, + struct strbuf *out) { struct trailer_info info; trailer_info_get(&info, msg, opts); - format_trailer_info(out, &info, msg, opts); + format_trailer_info(opts, &info, msg, out); trailer_info_release(&info); } diff --git a/trailer.h b/trailer.h index c292d44b62f..c6d3ee49bbf 100644 --- a/trailer.h +++ b/trailer.h @@ -115,8 +115,9 @@ void free_trailers(struct list_head *); * only the trailer block itself, even if the "only_trailers" option is not * set. */ -void format_trailers_from_commit(struct strbuf *out, const char *msg, - const struct process_trailer_options *opts); +void format_trailers_from_commit(const struct process_trailer_options *opts, + const char *msg, + struct strbuf *out); /* * An interface for iterating over the trailers found in a particular commit From patchwork Fri Feb 16 23:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560882 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9A4A148FE3 for ; Fri, 16 Feb 2024 23:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124961; cv=none; b=g263MoGkLSXyQ93DeeFb4aNu/6maegMsCFnJsHjj9sXLp6QYfhObt6qOG2ZNdXEef+eawPjOYzOHqm2cPJDjyulIVMC7pJ4yhgyUsZLhsl8jRxxgsy0S1TWFGFjrNXuB6RpvjRdE6+pmKTgc1LuUYqEoucKSY/cs+/IrB6kxdZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124961; c=relaxed/simple; bh=MFEKYSEG3HI7mYG1ysXMfdUDr+XakqitFvOBDN2YbE4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=cH7rE2hT3B3PJbotFtGQaV9rKyxLxR4zD6HDv7o4wU5vWLGXwaaTDRLiqCAw/2bhNQ4naWjba6JX/fyZBzQeOcTuWHcRCbqw7Aa6YDayOAprsiCJlTpEVf9knfMj3jHmhvBOJSs+L+lxBRC58xqka6NWN51rrGPUbzP2LM6HI0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I9Qw2gFb; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I9Qw2gFb" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41232741dc4so8336335e9.3 for ; Fri, 16 Feb 2024 15:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124958; x=1708729758; 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=pJrVXdhG6CJ81DpqPJ6pqi09B31r6z24wJf30UQFHbg=; b=I9Qw2gFb4ijZAh235azWqSVtiBMfqYpR9TlmnmdpfSw3OTIgod9lR+ruQpTeX0KQqw 8z0m6MpqAkoJ72Q7suuN56i1jjiCuH9V3FrmdzhOLTX/yjrMYLXaTKag6hMlGmckvYCS 3haAFF4VP39pQYNA1B0Dglip/tQplGp14sltqdQnD6Mbo2e+kp0dTcLCE+/OJL02BcFe tsNpRvDlkylbxpJR2OSf5I8oJDYRSrDkwDsa07qJzbcb45GMHTNjJutFdBr5ogrtW612 APafYs2EbwWWN6JPnwTzO9QGmGYXVfSkcBpOL/OHjU1D/JTlAr9d46V7Ue8KL3VzGdTZ h8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124958; x=1708729758; 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=pJrVXdhG6CJ81DpqPJ6pqi09B31r6z24wJf30UQFHbg=; b=W8RPwJhdRTHHbb1BMRy96coVwa3QALd+D+G/QE9YXFKUZ1FNymhDNgqqUK94cTSvqb h4ugMLC4bRy8QDL3PRD1vYswFd0pULmTdr6vKbtz+iAVZ2HwIrEKNqOuW2N34iSS6Zww +0AZdBo5z7aJNqu6ZHU64LKZAZcf8dyV7bZ4+OzmJuVh+NS1VRVyD1Cm4M5DZyKSHFaJ ChDPkG56BAGxUJUY+D7+aGJT4TxJc5xvTvZ1X0Np4t5gtPQJQAFX9QbG6ACLvlsVKVGg sC/bTShAWI2qkAhCMNWfQs08a9kwAAoT6f6wpiAS8+0N2RrSVlbuEkGNyDd7lTm7oyHi /5IA== X-Gm-Message-State: AOJu0Yxic/41yeZMee3sVTBxt0rMSs7L9nw5/mM45omCtM0b2ahL46qx g1n/vZAMhTWvwM4/ck9re8ZFA93msC8z2sI295vb3M1ICuTKXXlhN+n5MfMk X-Google-Smtp-Source: AGHT+IEE2OQGr8w7/OfYtVNZI4ri4+9T7IZxdayWlPcjamrLfPQxM3GZDJ2ReyOk90KdtPE9Zwxq9g== X-Received: by 2002:a5d:5646:0:b0:33d:13ee:1699 with SMTP id j6-20020a5d5646000000b0033d13ee1699mr3340197wrw.66.1708124957871; Fri, 16 Feb 2024 15:09:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e6-20020adffd06000000b0033cf60e268fsm3275591wrr.116.2024.02.16.15.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:17 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:07 +0000 Subject: [PATCH v5 6/9] trailer_info_get(): reorder parameters Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. Take const struct process_trailer_options *opts as the first parameter, because these options are required for parsing trailers (e.g., whether to treat "---" as the end of the log message). And take struct trailer_info *info last, because it's an "out parameter" (something that the caller wants to use as the output of this function). Signed-off-by: Linus Arver --- sequencer.c | 2 +- trailer.c | 11 ++++++----- trailer.h | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sequencer.c b/sequencer.c index 3cc88d8a800..8e199fc8a47 100644 --- a/sequencer.c +++ b/sequencer.c @@ -332,7 +332,7 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob, sb->buf[sb->len - ignore_footer] = '\0'; } - trailer_info_get(&info, sb->buf, &opts); + trailer_info_get(&opts, sb->buf, &info); if (ignore_footer) sb->buf[sb->len - ignore_footer] = saved_char; diff --git a/trailer.c b/trailer.c index 5025be97899..f92d844361a 100644 --- a/trailer.c +++ b/trailer.c @@ -997,7 +997,7 @@ void parse_trailers(const struct process_trailer_options *opts, struct strbuf val = STRBUF_INIT; size_t i; - trailer_info_get(info, str, opts); + trailer_info_get(opts, str, info); for (i = 0; i < info->trailer_nr; i++) { int separator_pos; @@ -1032,8 +1032,9 @@ void free_trailers(struct list_head *trailers) } } -void trailer_info_get(struct trailer_info *info, const char *str, - const struct process_trailer_options *opts) +void trailer_info_get(const struct process_trailer_options *opts, + const char *str, + struct trailer_info *info) { size_t end_of_log_message = 0, trailer_block_start = 0; struct strbuf **trailer_lines, **ptr; @@ -1150,7 +1151,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, { struct trailer_info info; - trailer_info_get(&info, msg, opts); + trailer_info_get(opts, msg, &info); format_trailer_info(opts, &info, msg, out); trailer_info_release(&info); } @@ -1161,7 +1162,7 @@ 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->internal.info, msg, &opts); + trailer_info_get(&opts, msg, &iter->internal.info); iter->internal.cur = 0; } diff --git a/trailer.h b/trailer.h index c6d3ee49bbf..410c61b62be 100644 --- a/trailer.h +++ b/trailer.h @@ -94,8 +94,9 @@ void parse_trailers(const struct process_trailer_options *, const char *str, struct list_head *head); -void trailer_info_get(struct trailer_info *info, const char *str, - const struct process_trailer_options *opts); +void trailer_info_get(const struct process_trailer_options *, + const char *str, + struct trailer_info *); void trailer_info_release(struct trailer_info *info); From patchwork Fri Feb 16 23:09:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560883 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0C0D148FF0 for ; Fri, 16 Feb 2024 23:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124962; cv=none; b=iP+cYVpU8AAzD0hNDJQPofgtn3Zbap1wLI4fqVeo9cZI6Piz0xFpuaOY/8BsuzJfxLYjJlhbEF3CO2QIBNS3BCeCd+zzDMEO09bfMKVKicsOsJxhzPTfbPUvMwX+KWz89PevZ4pskNLz2Qi+XVSBLbEAD4gzz35t2mCmBd+YHS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124962; c=relaxed/simple; bh=ttUB/lGc31VezpwkxCUqYNd8Tz9/24eZbrL+BweDCnY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=NGIrNFwxMLjjkwuoR9puZYhRffnKig+16QVzo9VwzmOvIj1b9qfo0xpY+pVspDMmUHVDwmg3VuKz9w4F4xiFV9XIAZ68AR77om34cjcSM7EXEpTTTJ4hE4HE3Uy5cyfrKV4l/OkKHwDNK/LXfdpjgKiGkkSc1TdUGxBpecEwf0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rx6JCOWA; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rx6JCOWA" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33d01faf711so1133355f8f.1 for ; Fri, 16 Feb 2024 15:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124958; x=1708729758; 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=s2ChbUKr39IIl/empUwfg3AmHJCZvdutzce068y7PcQ=; b=Rx6JCOWATuGz85pOd43DDiGSCnfg/wcf6x0++rOqPzPjmn1ho6YMj5DMW4A+cH1D9S kQXg58Rt0czxNYaOviursFLt6z5pItCy8mRsGckPDTmhccl9wUpyDmBeIgIbtSlikoB1 qtjjE/UJbdeMe9uIilkFoWqKwzoZtcCm0rt63j5b1sIgXLs9K3bZFUBlrLm2TJeoRSgm h4QUcONGgl22f6HShVIE7kPozTTAwjtYraSlp97xRHa7diEFR6vo//cPZRdqL7ncEKuo XfYQojYl7NjGalu9Lozkan4tIL0bXv8FuO18CSIvdSrihUcpPsxd0hUZv3YSF6QqqAjz LGkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124958; x=1708729758; 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=s2ChbUKr39IIl/empUwfg3AmHJCZvdutzce068y7PcQ=; b=UnA5meVaQWIgWnS17Dwzt3hEzNrniy7Hhyjl/6LqcQYpO0zFjB5LwSydqM6SGs8Y7Z tkUneGHWjTCmijizDuNwf9kDu4rh7RoUpeVmrI5mA8k9rGZ4DhRfRNNt6ibTy5g8tR7B wwgt48FhIx6cfoMAIpb6qWtRg34Aa1vnK2mX+aJe2zoIka/n+ES/yMIFLwsm6965/rkz EJ5EXgKG2skP+NyCFIZ7NaJcYjwcHJ2kdqmUCAUFC9zR/bi5JTYPVJh7ALocw8j93R2/ sJTApdL7CwD2ZeQbtvV/qQ1Ph13gaavy693Efuihw6Teq8n5L+gTNLTt425BYoRPta8K +cAg== X-Gm-Message-State: AOJu0YyAc5E7bx1hhWaCJWUL9m22zeH2nVQU0NbFa6rTSa4ihjPGE6WA U7Zt9Z+ZRXuV37wJKIn9Trs+T3tQNf7ffoalQDjEIcEYdZUuAf8CRuklAXkh X-Google-Smtp-Source: AGHT+IF52iuoaupResgiuofNIsI35DauqtKjPHf2pU/sv6i2pUlSENHebKboGOQgPdusv9JXWx4nrA== X-Received: by 2002:adf:f2ce:0:b0:33b:139e:9110 with SMTP id d14-20020adff2ce000000b0033b139e9110mr4117435wrp.36.1708124958605; Fri, 16 Feb 2024 15:09:18 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y19-20020a1c4b13000000b00412156abf32sm3502714wma.16.2024.02.16.15.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:18 -0800 (PST) Message-ID: <9dc912b5bc5ff07fedc0dd217b5ecb8a1eb10cc3.1708124951.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:08 +0000 Subject: [PATCH v5 7/9] format_trailers(): use strbuf instead of FILE Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. Make format_trailers() also write to a strbuf, to align with format_trailers_from_commit() which also does the same. Doing this makes format_trailers() behave similar to format_trailer_info() (which will soon help us replace one with the other). Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 6 +++++- trailer.c | 13 +++++++------ trailer.h | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index d1cf0aa33a2..11f4ce9e4a2 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -140,6 +140,7 @@ static void interpret_trailers(const struct process_trailer_options *opts, { LIST_HEAD(head); struct strbuf sb = STRBUF_INIT; + struct strbuf trailer_block = STRBUF_INIT; struct trailer_info info; FILE *outfile = stdout; @@ -169,8 +170,11 @@ static void interpret_trailers(const struct process_trailer_options *opts, process_trailers_lists(&head, &arg_head); } - format_trailers(opts, &head, outfile); + /* Print trailer block. */ + format_trailers(opts, &head, &trailer_block); free_trailers(&head); + fwrite(trailer_block.buf, 1, trailer_block.len, outfile); + strbuf_release(&trailer_block); /* Print the lines after the trailers as is */ if (!opts->only_trailers) diff --git a/trailer.c b/trailer.c index f92d844361a..cbd643cd1fe 100644 --- a/trailer.c +++ b/trailer.c @@ -144,12 +144,12 @@ static char last_non_space_char(const char *s) return '\0'; } -static void print_tok_val(FILE *outfile, const char *tok, const char *val) +static void print_tok_val(struct strbuf *out, const char *tok, const char *val) { char c; if (!tok) { - fprintf(outfile, "%s\n", val); + strbuf_addf(out, "%s\n", val); return; } @@ -157,13 +157,14 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val) if (!c) return; if (strchr(separators, c)) - fprintf(outfile, "%s%s\n", tok, val); + strbuf_addf(out, "%s%s\n", tok, val); else - fprintf(outfile, "%s%c %s\n", tok, separators[0], val); + strbuf_addf(out, "%s%c %s\n", tok, separators[0], val); } void format_trailers(const struct process_trailer_options *opts, - struct list_head *trailers, FILE *outfile) + struct list_head *trailers, + struct strbuf *out) { struct list_head *pos; struct trailer_item *item; @@ -171,7 +172,7 @@ void format_trailers(const struct process_trailer_options *opts, item = list_entry(pos, struct trailer_item, list); if ((!opts->trim_empty || strlen(item->value) > 0) && (!opts->only_trailers || item->token)) - print_tok_val(outfile, item->token, item->value); + print_tok_val(out, item->token, item->value); } } diff --git a/trailer.h b/trailer.h index 410c61b62be..1d106b6dd40 100644 --- a/trailer.h +++ b/trailer.h @@ -102,7 +102,8 @@ void trailer_info_release(struct trailer_info *info); void trailer_config_init(void); void format_trailers(const struct process_trailer_options *, - struct list_head *trailers, FILE *outfile); + struct list_head *trailers, + struct strbuf *out); void free_trailers(struct list_head *); /* From patchwork Fri Feb 16 23:09:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560884 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89CF6149006 for ; Fri, 16 Feb 2024 23:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124963; cv=none; b=BTQUgU6O3iAkQ4iFQHRfUwULKun7qipmNCM7QvHshteM86H4pAvWG0tpowNVBT9DZUsQutp0Plbj9ycpjDiHiHekf3Xrcbk2uir55G/bVGZAB4vUhPkaInW1Vbu4U2o/IecDoPwrlACe+GFKTQMTtGvFqBW65gARDxkq8d0P7BA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124963; c=relaxed/simple; bh=8zW5s9dVw12pr9fbZJS4z8TlV+Q1EwM2vdLxdUNtO1o=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=NA6jCzdzZjRyz9jLGnylxG/Q8AbhpieFMuAT9wCNyqS+Q8YvD2lNNsYyYfGb3apW86+h/66VQWEfarYA8j3+nG+Kwlme05ziZVKPgkTPAb9bF9JwHza/wI+xo9WwBhGJSN4pj5nmnFKd2BV4yXRLiMWDz+qq0AKgFLKNJjIIEU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hOi0k5rF; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hOi0k5rF" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-41258904302so1019225e9.3 for ; Fri, 16 Feb 2024 15:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124959; x=1708729759; 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=KVmCHXSxcIJ8BC25Gubr/EV2nNjiB4Aj4jeRQHFX7BQ=; b=hOi0k5rFc5TupScZlaEyWajM2KmJWSIZYB5lIxUrC70t3dpj2X0j5LuiVvY2Za6myS QZ4s5HUBgKIXGPMJYzX0Howb93rxawOMihQYBLE9zHZRqIm2Eg9p4CllY0MrPYyCRBu6 f5xGQZW1VMKj2XCS9/Tu5dM5RLbFjEjwLeEE2qhQ55xroSLfjiCUWg5C/F5mM6rd2Pyu sAo6koz84AOca/GHjxX7ORlGRNmvJVEwoMlDXfXrG7mO01iy/gTHBLF3TIj+xxHNmmkZ trsgQcgDMQJ9IEGJlS/iZ7W/tU9KjaLPQRuaQVjomhrVytzGEK4TfeSpBdaP8gP3X589 fppQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124959; x=1708729759; 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=KVmCHXSxcIJ8BC25Gubr/EV2nNjiB4Aj4jeRQHFX7BQ=; b=QUf6XdYCJOoBKP9nChBeXL6tB0aQOAOuR12C7EvqSQGba3ghl2vRblPImoYCtP9Fqm RmjjEJQgh3GX5OOfaPnoCzzM391gk5G+5z6m5HS2ZYNKyn9uYvlXwEeVs01vPw6446qY OcAeU6Vh5pHj0LHgGA6vrvhf0KENOBU7lB5Rt6jG2Iivuzeaka4L1Whjo4mnxqnNJ/x+ ZFq+I0+s4G9h9uZ7KOZFwhGNFuioj+O69hNkan8aPhQfO6D90zg8K1OftxTapGtstEJp TkLz8d1y6w2R/r+BpV6Q5AJtrrX5bNoDiKbu7xuPte5/PmfFZyX/h+glCNSBeOWR4mRf 8rxg== X-Gm-Message-State: AOJu0YyNC/AQYitFWTXwA7xiNgoOXwOiXVoxS7feP9v1nkKuDKWUfTvb b7hzmSaI+4xRmWtxv4s3D8gb2OJ/HBPDG9S00xM4enmXqndBlbOXrr5r03Dt X-Google-Smtp-Source: AGHT+IE6OLmQHR8vjMsueb9U5o5ZWVTrU+w/QdYP0RC4Tp6N7kwLGuh+ixSELdpdJufZxzt2OOrznA== X-Received: by 2002:a05:600c:1c1e:b0:412:1615:7343 with SMTP id j30-20020a05600c1c1e00b0041216157343mr5042285wms.5.1708124959367; Fri, 16 Feb 2024 15:09:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k3-20020a056000004300b0033b79d385f6sm3311559wrx.47.2024.02.16.15.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:18 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:09 +0000 Subject: [PATCH v5 8/9] format_trailer_info(): move "fast path" to caller Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. This allows us to drop the "msg" parameter from format_trailer_info(), so that it take 3 parameters, similar to format_trailers() which also takes 3 parameters: void format_trailers(const struct process_trailer_options *opts, struct list_head *trailers, struct strbuf *out) The short-term goal is to make format_trailer_info() be smart enough to deprecate format_trailers(). And then ultimately we will rename format_trailer_info() to format_trailers(). Signed-off-by: Linus Arver --- trailer.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/trailer.c b/trailer.c index cbd643cd1fe..e92d0154d90 100644 --- a/trailer.c +++ b/trailer.c @@ -1087,21 +1087,11 @@ void trailer_info_release(struct trailer_info *info) static void format_trailer_info(const struct process_trailer_options *opts, const struct trailer_info *info, - const char *msg, struct strbuf *out) { size_t origlen = out->len; size_t i; - /* If we want the whole block untouched, we can take the fast path. */ - if (!opts->only_trailers && !opts->unfold && !opts->filter && - !opts->separator && !opts->key_only && !opts->value_only && - !opts->key_value_separator) { - strbuf_add(out, msg + info->trailer_block_start, - info->trailer_block_end - info->trailer_block_start); - return; - } - for (i = 0; i < info->trailer_nr; i++) { char *trailer = info->trailers[i]; ssize_t separator_pos = find_separator(trailer, separators); @@ -1153,7 +1143,15 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, struct trailer_info info; trailer_info_get(opts, msg, &info); - format_trailer_info(opts, &info, msg, out); + /* If we want the whole block untouched, we can take the fast path. */ + if (!opts->only_trailers && !opts->unfold && !opts->filter && + !opts->separator && !opts->key_only && !opts->value_only && + !opts->key_value_separator) { + strbuf_add(out, msg + info.trailer_block_start, + info.trailer_block_end - info.trailer_block_start); + } else + format_trailer_info(opts, &info, out); + trailer_info_release(&info); } From patchwork Fri Feb 16 23:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13560885 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76CF414A089 for ; Fri, 16 Feb 2024 23:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124964; cv=none; b=QE2rGSY0+Y4v6DUPD3OpjkABLzAzGu/f3nooVc18pG9aMYWvjJVbA6wwf6Ig57WUdDzl1Zq6hsHYlrx4B8ONweycLwyt7vTYbb4EPFv/GdX4AlRPBUUblSKu+08hLDJFmzBtAIPuhHf4f/QA3gHCUMr9H0d74E+V9bgiTW5Y/kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708124964; c=relaxed/simple; bh=1AnNkl+0zcRfBspDz4HCBHqgL6cIQ3kapJT3IfgrPl8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=W0PeSTH2MqHAVrJzESJT/Drg3sJmd0ZSYTgzQ10eudhtiesRW/ONlaTcJFhsLcLmOjOqRaPNMpezpfE9g2fmPmO7Z0tzzvHXRyXJrODj9UthFp5VH0nEWQUJS56WKbhSV1fBfXFqFys0cRyADs/n+gkbWWr940ruaI999eOIOm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Uj3kR5mp; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uj3kR5mp" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33d118a181fso1150262f8f.1 for ; Fri, 16 Feb 2024 15:09:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708124960; x=1708729760; 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=FyOrpV5KvK6K/5vJwLnuuHInkEOKWOETatb7vpt358Y=; b=Uj3kR5mpkG1gbutdGUTUHxT4qoOLM1AIDehPhynqv4CVaRoPk5p6iMXzmYd6bcFyCd uXEzLMNesVw8AQ2+1d6cN4NX2Z2qDnM7JVP9YeLJWWBgZgy3O/V8feJ0aI8UBrVGvqKA ViPuTocyR0u9pm5Ie64GOHtloiUt2WdnX4CwGFdY1JnVUvFcb2UYp3I7I6EHY3t4Jxy4 Ij66ND9z9K5FfpJdZOet3d3ELNij7GFtW/Wv9LDHFC9MkmxdZ2M269HXcRBh2L1JJSYq uGpg7M+hiyn976Rvj5YiX4UHePdxMujGJdBIQgV5hQfr6pJKkhF8DZH4LPRC8G+baoXX zgcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708124960; x=1708729760; 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=FyOrpV5KvK6K/5vJwLnuuHInkEOKWOETatb7vpt358Y=; b=Z8H3MP/SYeqGmYRP2Yxc1qlL0nkPGd7YraONwf8bprGRSHqGJ3j4CppYWT+ILKP8iE 9nPP+Oma6TKMJ3+Wogh37l9tv4LD2BAwZVD68iPCe5kgi0fMEkW4wSISbtxVCt8JQ0hu rRZqu0+f3Wsw8drO7T0e2AYEz6zMr/mI400oWfe+8sRDG21TWMT274kZ7+7GdLksqLdP jrjQx1qZcljGzjDng4BUfZEyoLn0R+Gk/rN5zqkRtPlDrjh/CwGbzz9SaheUBsb4rwjk el4Lz1nUbb0fEczw+pnoytL7YIlRu9n7L2qyASqCCCtMYlWqonCSx2VYZCIpBjEvyG0N y29A== X-Gm-Message-State: AOJu0YzmLkAsCNoZwUF0rrwCEcD5ilputBjNvzT5NRy+ja1aLLowSWws mbIwoxPqo5/xqp4XpS4VOeCTP6O9Nr9BpIwqsfQPPYQA0/53M+H4ioHzryiq X-Google-Smtp-Source: AGHT+IGgpnaJS2kndC6cEUdaDpMeV8UjbKlS84h9ofHZXeMhf9wVNR39aQKfmaTcMlCGL9PYfqujOA== X-Received: by 2002:a05:6000:1143:b0:33d:2071:9b85 with SMTP id d3-20020a056000114300b0033d20719b85mr1866167wrx.19.1708124960612; Fri, 16 Feb 2024 15:09:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f9-20020adff8c9000000b0033ce40eee9fsm3288993wrq.58.2024.02.16.15.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:09:19 -0800 (PST) Message-ID: <7c656b3f77546ae917ff192031c62d4521d9df8c.1708124951.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 16 Feb 2024 23:09:10 +0000 Subject: [PATCH v5 9/9] format_trailers_from_commit(): indirectly call trailer_info_get() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Christian Couder , Kristoffer Haugsbakk , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. Instead of calling trailer_info_get() directly, call parse_trailers() which already calls trailer_info_get(). This change is a NOP because format_trailer_info() only looks at the "trailers" string array, not the trailer_item objects which parse_trailers() populates. In a future patch, we'll change format_trailer_info() to use the parsed trailer_item objects instead of the string array. Signed-off-by: Linus Arver --- trailer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trailer.c b/trailer.c index e92d0154d90..e6665c99cc3 100644 --- a/trailer.c +++ b/trailer.c @@ -1140,9 +1140,11 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, const char *msg, struct strbuf *out) { + LIST_HEAD(trailers); struct trailer_info info; - trailer_info_get(opts, msg, &info); + parse_trailers(opts, &info, msg, &trailers); + /* If we want the whole block untouched, we can take the fast path. */ if (!opts->only_trailers && !opts->unfold && !opts->filter && !opts->separator && !opts->key_only && !opts->value_only && @@ -1152,6 +1154,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, } else format_trailer_info(opts, &info, out); + free_trailers(&trailers); trailer_info_release(&info); }