From patchwork Fri Mar 1 00:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577786 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 E99F3631 for ; Fri, 1 Mar 2024 00:14:50 +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=1709252092; cv=none; b=f8ZF0u1wQ8P0vTVVqodQLmXGGqqsYs9PBuPPjlN9pC78jSbS9dtrNwJhqEQnaySjaNWz5rdMPgZ53zIhGuL2QzrV9MmOeZ8+iGISQ5aKfm2jCmo93ccdQ40kPScJYkdhFHjkS2h+VK66C3ki3RZiGN2gnOOi7RSOTEHuT1EFPVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252092; c=relaxed/simple; bh=VtcouaHw6ztbGb3EWtk4zEbxwTZdAZDIvLKHObqns28=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=GGh9jvvbrT5ULnglC4PVD554kA5RDwCoxu52+zfKl99UzDg+73BYs3g58swWu4ZRzdIWFXGwC934USu3SKVb9XdLchRTiwroLjLH4RGsD9mgy6Hu/Ma1T9iwvBJriUjEK69R1aURRfB7MqpYfTsCy4v4zL8/XRL6/Xbzq5Bd2Mw= 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=YwPAtIJY; 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="YwPAtIJY" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-33d61e39912so733696f8f.3 for ; Thu, 29 Feb 2024 16:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252088; x=1709856888; 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=YwPAtIJYi1R3Cr1chA+igQSgEVYNgxG61MeQb/tBnMXDyXZ4WgxKN8dpfdjUFJjREM AVY0hepwQDGlGt88xEWrGyamRx4K8sOPWfP21xjCV5ZeDRUPvz4ZihOwT83f0Ab2e5Eh V95F7L+tBkthwh8P7OoQNCU7Q6d6IZg9B+U7D1VO+eU9D0kGBCKxObIQd2nQHjCey7Rc JJUiwqXCD/vTiS/04GCgslBZUUzXDkq3VnNSYCGorI3l1qJG2HQuXMiqzAw9eCb+Fwn3 uj/TmNCMPu3RiCL7kdrbY7LpjM5ulkmfGKOUVT5D5G0WX3kzm+kBiWaQJAofNBNibr3K Dwmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252088; x=1709856888; 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=pemBMvOl3X7O8TAjlkZVBIJK5URUeTl46wYQhWcmQkj/wigMcxyZkQHPOIvq+fo1s2 zlAopsZ6eK5vaQTkP2lNPhvPT8IUYc+RnqSAQenLS069Q9PCDEgai7CAxpR16gv7KJYH qBFPqZfsBsEfumyU3VljWOD/yNzDUHgjUfIrEqddhChszBKITwWUdjuEPPFQsJp7rt1U j85nElFHyVA1Z06cXdqF35aozySXHhAELALXkqURWLHIIvzDis9pIqT5m9CpTfmo3LIK whptAY06Y2Cm0xDJD5LklZWOcMRSKbJUoh7127BwyITOaz5W+AE7RpvH5BTQH/0r5WEC igGw== X-Gm-Message-State: AOJu0YyWBlhUfRjQ6RPBRkI7KEg8KOZVlRsLiJDTvBsXiMm8Rhfh8UHJ My4bEDhKaHjXZTYHORW3wgeuI3autzwonUmQBFHrlHmrynniglACm1MnTCpL X-Google-Smtp-Source: AGHT+IHbhtQUPLo4alJnaYtOc94s9dIgkZmcwQsaZZy3yLclfzHkKj8TqOXUx3YTAyAVX6+5syDbpw== X-Received: by 2002:a5d:59a1:0:b0:33d:f719:83c3 with SMTP id p1-20020a5d59a1000000b0033df71983c3mr103716wrr.34.1709252088492; Thu, 29 Feb 2024 16:14:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d7-20020adf9c87000000b0033d640c8942sm3029263wre.10.2024.02.29.16.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:48 -0800 (PST) Message-ID: <652df25f30ecc8227bef5109b0f7b47817386b13.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:38 +0000 Subject: [PATCH v6 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 Mar 1 00:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577787 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 E372B64B for ; Fri, 1 Mar 2024 00:14:51 +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=1709252093; cv=none; b=IDOTDV3xpVYLfsb7AzYpnhBDcK32cdXQZyXFTOJNELixMyhwDtOUfqXD3jTt4maRcqeIZcF2TKd7pv7taS6SlHOulRk1Ok9eFrbbinjddEeQMLl9gw6+HiIymrl39yc+WQa7kmqLcIgAj1fS2Gx1noq5jbOBwhPEEJhR7mxMhRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252093; c=relaxed/simple; bh=drUD39xUc8WM+utEVxXTiU0Dg0IS66wVnv7Mt5VGK2A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=QOaKYrlvh0c5k4gbMh9lvQq3sqRgjaly3Jo0DjeqXSqJs6/xPnj3DZqInmK/ZMtf7y0kxHVMtkzs+ALvRRSEFTcSi3aAlkThiceFgqd+0oBOluNUmgvATyBPCqaV3d9tMSv4Wmj6DkCpnGy3nWhBi2yLow3NZ+eGT64g3lIvUhA= 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=YMc0fcFa; 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="YMc0fcFa" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33d61e39912so733699f8f.3 for ; Thu, 29 Feb 2024 16:14:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252089; x=1709856889; 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=YMc0fcFa+Q8g5ZKvib+rx7g2oqHStJJEdgIbZfsARqRfOWZZBo8//ltQuSGxnu+2g8 FS1EER8ucaYQxD25ltrkaGh4cyCtsyawpVCw6Nn4idYvIiHpnaFONE1YJMKdmdd0GzZ0 +Gp8gA6/9bjeCTReMwPvSocxV5a4G/KnhbHNjT1PItq0eugm5l7AHWR6RYnSAIXTC0bY cAeCKOoLxKsk8lVw8PkTNaGfp41CmmQHthIMHV1U9JsZJNdNisgMi+krQYqWvGZNWQeC sCOiN37wq/nioEnCIk5fAK310+Iw2EOdqEbQDoXyBoS88G+VGsupmCdDbQphnJSDiYxQ SE9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252089; x=1709856889; 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=lRNjcM+L0OdHSs6EIhGoRo2HKzo0RwpsvUpCC9DZ4tG9ZLWFO5cFBeSSepIzAu58/C htijGwRycsnr6DaZI1x0Kyqpq1FRTayyux7GxcZu6bdCMB6D9sVI4dQyBwgXu9q5nCEn 7JtRPK+PdhGnpRDfdzQOCS8n63I57b2w/otAiC4UZy9npkbQro05Ygbmlo8I6+fCeK3u pCy04aKIS1t/XF7UEzAetrcebj6o/le4a+TzL/QR7SAe+/aIJXUFUxjr4ZHiv8Xz4YZU obMFf9AEDa0rlE77uXioOsyKLipmXnPnzOL+mPVn3EgPa6GK2TzZDmjt3JqJX+b6uLtQ rL9A== X-Gm-Message-State: AOJu0YwTC9fgYfUKxQEw49d32X0Gfx/kM6wLcM4qb2BKCSVr6EwtG4z6 bo/UED+SabDiP+TJ90Bo6Yb5hVo1HG3cgxgxIW/ST0qoua+HvJItBIEiv80N X-Google-Smtp-Source: AGHT+IGSbqXB5Kx2WvpT4yL98u1nVkzlTem2mh8UiQKVa+RaRJZTJYVbCw9h4St0DDdWM1ckA/n6OA== X-Received: by 2002:a05:6000:1110:b0:33d:754c:86cf with SMTP id z16-20020a056000111000b0033d754c86cfmr90019wrw.35.1709252089093; Thu, 29 Feb 2024 16:14:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ba16-20020a0560001c1000b0033d9c7eb63csm3109966wrb.84.2024.02.29.16.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:48 -0800 (PST) Message-ID: In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:39 +0000 Subject: [PATCH v6 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 Mar 1 00:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577788 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 530CDED8 for ; Fri, 1 Mar 2024 00:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252095; cv=none; b=MuwfiddD8IddB0CZuCcyfTjJrGZk9Sh5HRlPNd/5L2g0im+0PcwqqjU9tj5id1xAsDDi1jYNLnGb48T7yAEBwQgLsktGBoOiWWQpBwtPJ/Gc/tNo8Ropj1wSoBE0sFMztC3Js6pkoXdqU2PXXgE00JSpAaeguRZ3nMny/cz/8RE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252095; c=relaxed/simple; bh=KrgqE/DqtBdnF5UcVUcyQPPUaEPega7CNl+eGmY8ISs=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ZFS3FwJ5m/u8wi1MnhZ8eTj6FCC6h46u/oMz86A8KCscKcFhyzDdabFFWW/6kyUXqe0xYpBuisRVShQovUX04cNvpXRZhfkgLdGBwxBLJKsv011LUY625Wx9wTsS/ie1QE9kbeu5pXmHjLi3nZ7BddgfDNopfPHgXKLR9BrH01A= 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=H4HIBtBD; arc=none smtp.client-ip=209.85.208.182 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="H4HIBtBD" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d220e39907so20125451fa.1 for ; Thu, 29 Feb 2024 16:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252091; x=1709856891; 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=zubBGtsYBdmw3zY1wlEueEZhB+/ZFVqVRx3Jc2MCUBE=; b=H4HIBtBD2mG9V0v5WROkbqWpEmYuTfnRQBLK6YC3J9wPb9QZrIlDtNifecjRZ5/3L2 XjmzEnlE52s6ijzwnvYI5B3rg4UfNKTz9ua8NVZ/SWjrZrfaxePtSH0scTiuEucelaKA rWiAT+N3xzK6ofH1hscsv9/38oeS2yLyzDGYavurS03YAtdsySe7gnxlvdPNfYKubjx0 odWhW3mPQbvUKYF06HG8T7HXQwHR7Ek2F6cOC9J2u2HF7A/SklT/tna++RixPjmRVpUt D8ZvYACqqP63BPwz2ICnBumQhkbIPtbBFETgMysN3E8NNcSApcDPJKgM9OJKNRJZUkrB saLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252091; x=1709856891; 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=zubBGtsYBdmw3zY1wlEueEZhB+/ZFVqVRx3Jc2MCUBE=; b=qN1is+8kyswKSAdtk0wjUTAFPZfl9knxUHHe27kam0muelwsJXElCza1KznYqkMHIa uDwKcWAcrLK24MNGYR+ZoGqOVGHNqjXSWWMh3RXH89ADAkTzsgrO32BZeWhMJQeKqrWQ GTrIcVB6vAyCwCcDk3VinmBtRU1Gxpw/Zz4D99qZ0MkRLuHMT6oOSx29xhjLQZuIZlo3 +m7+rTh+ebMmyjp6L/QcMONxSvK1kNd5yg5p67GOlJTpE5n+ZXNhL2kYVgAVOQTqf7x7 0xWuZV5Y9FsIw6ZVBKaLzw9qETiTaZxHwJ5asNUk6MUr1iVjk8WJFhsWFqJVe3TR5N6e FeMA== X-Gm-Message-State: AOJu0Yyzuk85f7wTQW2ebLgt/h2XsmqD7Jjce3RcNLNGIp2xrxWJ1hId 8zIOxXzc2UVhHd7upf4gcQ+L3IBMavjCydpBTsLjL/EqwIYlLJyUQBIQ0Kq2 X-Google-Smtp-Source: AGHT+IF4wlug6PkQ5GBUlQyZ/jW/qhKOB8v+FHvFBcuDFQ779PD6ejTPXBe1VTOzTgXVWZDN/gxBqA== X-Received: by 2002:a05:651c:507:b0:2d2:f5fa:f37e with SMTP id o7-20020a05651c050700b002d2f5faf37emr3121549ljp.51.1709252090603; Thu, 29 Feb 2024 16:14:50 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jj2-20020a05600c6a0200b004120537210esm6564678wmb.46.2024.02.29.16.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:49 -0800 (PST) Message-ID: <7b1d739cddb3b7e974ccb8d05d99e5fc8df61910.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:40 +0000 Subject: [PATCH v6 3/9] trailer: rename functions to use 'trailer' 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 Rename process_trailers() to interpret_trailers(), because it matches the name for the builtin command of the same name (git-interpret-trailers), which is the sole user of process_trailers(). In a following commit, we will move "interpret_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. Rename `struct list_head *head` to `struct list_head *trailers` because "head" conveys no additional information beyond the "list_head" type. 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. Parameters like `FILE *outfile` should be last because they are a kind of 'out' parameter, so put such parameters at the end. This will be the pattern going forward in this series. Helped-by: Junio C Hamano Helped-by: Christian Couder 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 Mar 1 00:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577790 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 5B38210E9 for ; Fri, 1 Mar 2024 00:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252096; cv=none; b=Uc72Djyvsox1OoobSlnk9oj4LfQWE/phopN31+C+VPqtNhFuIh5nkm61id0XROj9Z84bir7vE3pqTgfQTthglNR9V7dnatVcVSYitCWsR8CnECeJGIobEz4YqdsWpfkmZHphDENhfHNbF9D+Q/1F44NLrRbMRdFS1NzF4Z/iguA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252096; c=relaxed/simple; bh=iQq/mzoDTFVBBW11XhOGyw7hHLmxOQ8KAtf6x2O4BrM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=qie23rlmFBjTjRHBWHZghYaDUXd1OdbO30EfE9vVvGULYkmmcGf6nUjGG/39BthYDyPWXlGTS//sohPadG2rnwYt+tM5z9HzViLOm6Az0LIS0/7gLrdqSLrt9XC/jPNJnimFCLsOEA2V/CVtGcskSu6HzYgkdK9D1KqpexqJ8So= 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=FrBF0EeO; arc=none smtp.client-ip=209.85.128.42 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="FrBF0EeO" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-412af1c91f3so11162725e9.1 for ; Thu, 29 Feb 2024 16:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252091; x=1709856891; 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=FrBF0EeO+uN3fJkWm941Vc0h1NdUNyj9wBwzJ0lIlW2xnlHsIRn8LXHIF92oPSJ/LM ucA2pTrSE0VzRQrCpXfQff5k99pkYbIKIew+m8eoD6wbyYXr4HJi5HbY9z+fuR7/g+XE lXTntjAaDnmmWu2l7WBg2oRvirFLpepLUUhpitF4MBmZxxxel9hfR9QpF3ZHY+hy+NNs RB2BuizpIB7KLmkiOVcOCbjSBOLxYri62L0J/D/v9KfanfPlvf3Lf9PJKFGKs6wtr4Mf nCd5rnw11xYmEkvDS18H+KRSK+u+YsyebgQmRIktAK62saqATuU2k+uH4DUC2XnF/SVr Jzuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252091; x=1709856891; 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=wvDO9yN1BzhhjHB/FewNYMc7cRR6J0eZaC7NJT61iCDEr8XI62NToLDUIf2sQmNTAd HakHDfiRZTbez3Es+wc/952Kp3Hz0sUpaWlyR7Q0ICW+UTLNANFpZK3yvDGMDDEHCQiD zQFvd0jbfeBzLuk3qsGv0UBTOGH4BJkmLZIlwTiaWkuTavDfeLkwuP98XITH5KA6ZkQT 6lS3qoULru4LYV9nnPEnVa8n2StbKpityXppfsZO/xSWzF7j0/dvbr1J0efUTsNEiOZJ BffanEnjNHm1fVHL8TSHAdRqtVDZr/cr4EA4IGEeOJCnUlDfZoAqTHpgxkviggjL7s9q 4WUA== X-Gm-Message-State: AOJu0YzdHQ1h/sX7JMjsSUBf+IN+TfCgEjiRHKTKobE8KnRf0RCYdDXa 8CIzS2z01CtUth+daMcDJW30LO43t4dcvbuVpMPfiXa9PCeE1XiionZnXLBp X-Google-Smtp-Source: AGHT+IFu8saFHZ8bNzBZJ/fE1TUf12ZPM4dtirubsT6Km3iEMbsrzoOAZ/d3p4h/sSwhHdeb94/cSg== X-Received: by 2002:a05:600c:3645:b0:412:b30b:e47b with SMTP id y5-20020a05600c364500b00412b30be47bmr136377wmq.27.1709252091235; Thu, 29 Feb 2024 16:14:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f12-20020a05600c4e8c00b00412ae4b45b3sm6839060wmq.30.2024.02.29.16.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:50 -0800 (PST) Message-ID: <7ac4da3019ac4210e304a066275745a0a93630df.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:41 +0000 Subject: [PATCH v6 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 Mar 1 00:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577789 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.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 ABCC917D2 for ; Fri, 1 Mar 2024 00:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252096; cv=none; b=Zzqm8hRyZdljkEY9xTgZEqaTdAcF1FeEgbYAqJ2J4DfZJczSDqhkEF4kSFmmgteodzEVTxebs+FvQVEUhF22+uBqqN8sfDxsiaCU7XvY+GRTnxJzmXG/nHNSmNgCd8/7If0PKq6umxk3dqbxd6xpJk9VSS2CN270NQV+eWxSlQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252096; c=relaxed/simple; bh=fiifOQ30GqMvHhI9/LOQ6AWtcFKC8Ys0gKUdEDybgGk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=COhblFnI8NLguWfP65dIS5hO0u9ThGFX8ArRVsrcwed6CU0xV3jSwaGyUnYyt3M7xQYTe/Pwo7/9LLUxX4RHLF+bWBTAbOlbHlpTQKFxty0C+yKiOzdOPlmPJ70whFZcibB2jdXauup9y5LawXhd+VLqFFfDlqrwPGMsPy1czxU= 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=Cl9dHH7g; arc=none smtp.client-ip=209.85.128.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="Cl9dHH7g" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-412c23551e2so5442805e9.1 for ; Thu, 29 Feb 2024 16:14:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252092; x=1709856892; 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=ZrctyrePLkHINnJUdYYp8v79VB8peoiGPur5KFwl0dA=; b=Cl9dHH7gM33M2uZvPl9/wZZqaS8ghqSRxdzXFE7BGQ4QtyuRCkDHP4ZcZvP8nubxQF hrxT0CnDKMJUcvhpme3TX0qDQPKZRLS0d2CgxGQi2pXLpq8L49r8LvgKdeLmS0ASlWc8 jMlJjhlsD9ZnwavvJNLM/XrYGx1UXag5xTIYrQLrDnK9905na3crDb8ZXJr4lA8vaWfu RuiPZ+gW0oh7p41YHU+wD0VZYs1ov7Rkv3TPrxrywjUWxUfGNU9kbNjTxixN7qLRWtvT iuylX7Ds7dRW9AQ/5BowMcP76fknVq6P3euVc07rtRtjx5rQPoXyOnXjsdF7BL7QCGpC 46zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252092; x=1709856892; 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=ZrctyrePLkHINnJUdYYp8v79VB8peoiGPur5KFwl0dA=; b=jq51pvu2QC4D+i/flBUjqdkjaEsHEAQNvWJgfh8FQoVuBQTPJmlGt/l/uqHl+tzwc6 w5xDbF8+x8GKMMMaXXR8Sfn2Cu+yTSVqDOvOgAq30aNmxucVppF5EuPQANMMOekVlO3T wl3w0xBixTE4GEqDxxosNTXeEuoB6Ow1PeJpfoOFEHf0YhDwWx/3MxyIIWNQvMVZ6iGv Ho6fu0fQy4rBD6Xoxj21ZS9BtMyvrkrGs9qI+BZvOttCZQhcKTXoo72faGoKNRzzdfbF y4QYNDEL8FGEqznKW5kQwHghIH6FM5iik4lJRhpUMxgS+ReFeOjQqO1ajQlVXzrmUz1Z s84g== X-Gm-Message-State: AOJu0YyKwd94YCblsbhpEiNs2hiW8IgusV6S1HsMDl1tsm46QhKTff2i 4fdq+oVrWYE+mdrZ8CJUpqRAbwSJU22qvOMyJsORqPuonZGZOJ+bOzVrmLpi X-Google-Smtp-Source: AGHT+IFk9zqJ0XVFaxEmPt2/zOYksAKSGDDNuK52qT3/WKtbNsHFwvYOOPRwyYOD48rkUHiLnlKQ5g== X-Received: by 2002:a05:600c:1c28:b0:412:b6a7:ecf1 with SMTP id j40-20020a05600c1c2800b00412b6a7ecf1mr94361wms.0.1709252092240; Thu, 29 Feb 2024 16:14:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f12-20020a05600c4e8c00b00412ae4b45b3sm6839086wmq.30.2024.02.29.16.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:51 -0800 (PST) Message-ID: <47c994ce025e5574454234b686c41b7b9170cf13.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:42 +0000 Subject: [PATCH v6 5/9] trailer: reorder format_trailers_from_commit() 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 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). Similarly, reorder parameters for format_trailer_info(), because later on we will unify the two together. 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 Mar 1 00:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577791 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 76490631 for ; Fri, 1 Mar 2024 00:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252097; cv=none; b=hM0KdFopMkojSDdLjaJrsBfDA1OUfsdzleGXFMy0pdogGCsv2blVqiJz96DLU9HWvStgJUeGs+wRkg5gF9gITKjOTpZ8yoCAzX2gfLw2yNNpMr7TYxM/+nPRVZHHsXy2P5OWN7cys61WCF/3sowiZDNYzmy9uzf04t0RArJtlI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252097; c=relaxed/simple; bh=MFEKYSEG3HI7mYG1ysXMfdUDr+XakqitFvOBDN2YbE4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=XWewxkTWZ+i+AmEVSyGq++zzCxq2ZqkLNen59P77ayioCcS3SbW7RxPBGyayOpEUO4uDOdd0mvkg2Bo8Tk7Tw0BfaeGQ4I6YQlENgneuwSDNZibeYjuZ/yF+b43NiFHub81qfhWgtOkZQI9cN7tOSpyWlRzNeroj+4E2/7zec7E= 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=B1FhwzVQ; arc=none smtp.client-ip=209.85.208.179 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="B1FhwzVQ" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d27fef509eso19927041fa.3 for ; Thu, 29 Feb 2024 16:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252093; x=1709856893; 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=B1FhwzVQ5XJefnp8cmSHWlDdncp1rwrFbPPNOzyjEHlJtKuhmoqq11iqw59vUu7wB9 A8Vdx0xcscLCboyUUGBBYvHsZppRulsYdPbdQLgo87f5/QfBF60gvkmlKW+j33gVDviW 02lbQNeCUvMAJ1nlkmK3ThQcRKYc0FqUF5EsHJRMxBOXPUjITfqBw1aIUJK7HNKoGjO9 EnCrn7HGHfKUaFHKFykyC50pVXKU3crKEXe+SyRMLLqz1aBMYtQGcrLM5QDqY0yxtWGz XSaced8ctdTsVuc7IoYsU3h7MZb8bEjWpUDuXXuTEeHpVGcARSlFf++PQIx3agwmomeH eJPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252093; x=1709856893; 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=VJak+MvKU3ST9UWtQRoh0LP0CZXXzFNew5QiMZLj41037EDfZqDkKuL8oadhwjufGA 4FmU+F1KSvgX/3iMLOIDzraT6cT3kYb2k7v+E566IRYZ8wHijdCrIW1WYWcXonfZLbcO HbhWIbeW8M8BqVU1JnfwwRzv/wxqJKUsE2ra7kUZ4JziSfvQANtWnDu0u7RU4/aL2rfq j8ZSu/mChaUVnPc+OiVluPjB/OYZ/GO58UE/Ifvj4ExoHCJu0Vt5Akx0ws64aWxZKtfn 9CuLJnjTReRV+ic3m4l/KbdfBop6p4q0I5yM67K012P9rltwLGN2OaU6oMpP9Qi+iusU Wz9Q== X-Gm-Message-State: AOJu0YzK1wiNfDuqscw207VuzGT+kxprYnMrehICCX1ofX/eFIj0Xno8 kROJOkzvKW4eY6ieCE2fCtu8IbWslIR+K95ZATH6uQ+Ww3YY878o3oauFJvx X-Google-Smtp-Source: AGHT+IGwc8vstpkrOCmXWdjc3sk6L3/1AeO70thGTDXpQU+ihD+fc4Xrofr0S943N6l+jsgynIl26A== X-Received: by 2002:a2e:a697:0:b0:2d2:42ff:483c with SMTP id q23-20020a2ea697000000b002d242ff483cmr2104006lje.33.1709252092847; Thu, 29 Feb 2024 16:14:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jw21-20020a05600c575500b004126afe04f6sm6630963wmb.32.2024.02.29.16.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:52 -0800 (PST) Message-ID: <7a56558016769a9f29e4b14a73101447195ca128.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:43 +0000 Subject: [PATCH v6 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 Mar 1 00:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577792 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 63E3217D5 for ; Fri, 1 Mar 2024 00:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252098; cv=none; b=druHxWOUsPfjYyqV4xIbh5rUD67Dh4pin9ekRm29bFYkyQDHcthbKTDyRFWOc1xPwfXaC+wUfsyfRD90Xq5B4Kb1inp2QlIhR9WfZqDMT7y40/BNAg//iFmeyMz7sQ2UgTq7NImkcaz0WJmnTVynlr2A32W0Ardbv8CB4lhTviw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252098; 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=UaiZV8zE+7/3WObxf4o8lxRsm3UirbU7xo8DM2cK3A+QiN7vzLxU9057dguTn7Sd+A7HBKNm3EhSxxQpixx02BH6g1ZgltOKOGl4vfs8L9jU2dhoyG9zH68EP8VURA/W3jowf6XGB2p/HNNnOVfLqqffE+BRBhdzFXg7xF3pQgM= 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=EWGFRC5V; arc=none smtp.client-ip=209.85.208.182 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="EWGFRC5V" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d2305589a2so19016371fa.1 for ; Thu, 29 Feb 2024 16:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252094; x=1709856894; 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=EWGFRC5VqRrapUKs8G97jq0taImTLmh/oEJnOFBJ7iN08eUKCJ0a4Sy8OWq1AAiSXj QmCm0f1a07Pe39enXoJjy4LsLqz9sWT4euBNm55Yxy7SHeXOI8AHilbrqSFsUSvtT0rw 5hX8poxJxLnS46TpzLjESelQPuukHH9LVzHASAABNmmZWEYeTqyEsvMn5LFtULh1ybCz Iu1KXkbsoCsyNYboUsIspOPUbPbKKC80IDTsFThGzQzxwPPfT5NYYJyQksmdnpoffr/v N3Jllzq4HwOUxon4in2qTrxmVzYJfztnQ8F4G2kOslFN8L9NZOJDtoAOEALt0pgn+jyD keXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252094; x=1709856894; 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=q/DF1uLiEqudNvktLnhaiy4mkvGIP3QImRIwg+JDK7Dx29yeRJpSoAMCLUuk+0z/3/ Cw3DSeuTmS8fVaZGbgI8PBAqAmWrRoLI5sfjc2LU+b6R9NZCTnSPYdiRFbwRl5bMTn/K 99dnpk5krAxzavMATC/G5+F/bVeiLuWAjLi9Zq7azwKVWWN+HuN8Hg5T/yt8zIl44uXQ zBN42IsP8YgHg9ht/tSHuhX4ZuKQjxsbLMhJE66FvwLkomxSxsKoMwSB8A6d4tFgRdKD tK7oBDjqlq5ut0a8+YZiRBI4nEb4j/tLdfMmC1ORrqjdIbjZFSl/7cpYsajRXHN3fAfI IIRw== X-Gm-Message-State: AOJu0Yzmryv7SR84CNlOu0KUbRYblApJ1HSg+5hWFcJlKbinLSsZXdWA La3Id5yZkVXWj5BuaB8Fswp1iPeH4s3AScK4lCOsCg+u6PQUPJfz5NuVg94k X-Google-Smtp-Source: AGHT+IEsLaDjbxMY7k7gjcOnrOHFMqqSmAFeEBESCBAzzP64ELxA0Y5kRxxsR0fgoxKiW/bpKus2fw== X-Received: by 2002:a05:651c:113:b0:2d2:a8b3:a20e with SMTP id a19-20020a05651c011300b002d2a8b3a20emr2272200ljb.53.1709252094354; Thu, 29 Feb 2024 16:14:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u6-20020a05600c00c600b0041253d0acd6sm6573328wmm.47.2024.02.29.16.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:53 -0800 (PST) Message-ID: <46c7f4c0e81d943bd42b4b4e17aa0c09bc5b518e.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:44 +0000 Subject: [PATCH v6 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 Mar 1 00:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577793 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 8251A2568 for ; Fri, 1 Mar 2024 00:14:57 +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=1709252099; cv=none; b=dnU4T50CdaMeoNfw6mjO0X26Tew5sn8AdFyWRvLFTHoYTxK3OxO3UDofnRnAXTxrQNtLxMMDRqm9xLwW+ZVm0eE+Hhh/XukEq9egaQs+gBvymJulHsBEMnM3vlJH33cuQysx9vVlgbUuLvpZifD8aKmDNvKePh9+OwyE2VYdnQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252099; c=relaxed/simple; bh=8zW5s9dVw12pr9fbZJS4z8TlV+Q1EwM2vdLxdUNtO1o=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rCmGlKlLNCXbxKdPOeSLxKLYq0gzb/niB+02GdpMEZm/QBIXNo8QQ+Qz7RwhiF/mskSKOYuGSkoStqUbAR6/UkF6/OjVjC1a5j4CEOQwfdD41gC26et696rWnm/uZvhQxlwZj40y0wwALxhz0BgRdT5POji8+sNf/B1d65FUhUg= 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=BrCqj0xv; 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="BrCqj0xv" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-33e1878e357so230835f8f.3 for ; Thu, 29 Feb 2024 16:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252095; x=1709856895; 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=BrCqj0xvfOkSNbgE+t5hRO8yCmv8mncae3wPvZ7ivgXmdRVbQNog8hi1XzNSC5WVG/ 8vWmviF7D+FPFLzeyrJy1XuBpmOCndXYKiK/eN4MK9msGPoJlm4OsxyUYO9/YdGsq/+l S/6E8E43ObqulLTFp/5UKhLsKx0o23an2AgmoxX+wEyJ/KJPsEa033fbZoHa14F4KtfY yj5fkJu3aYG0SHNiv9GZxfxZUo5WiUVDh34NLZZiCgg4WIf3AMV7WcdbQHaCxMedELVT jJsDyQZ/KC9LktFWM/IYueINbknJ8ikYDECYM9O/ltVgY9RrtQDqBM1RSFPSwMhgi/4X +YXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252095; x=1709856895; 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=AuJmmyxW27MoOfQvhxAKiph58uVrKR/++zjqC3dCwF1HqywMzVVC+eB4QgC6n8+Mbm RnZWeo1tbGm0DWZAFeW0ZAv5rpWav7yCOUeyJ+Qw2x2U8KvlyTwW77CwGhhf1Crae8+h Pk6g4mwIahwM8dOok8KhYs09Oi4GgzWrom4IdmoViePyaUZ0ybN96WXmYTchTVHtanpp pU+9mOrV/53cMDJpFWiZZ7gfOfAtV5fix3fgn0egCYBK4jUhXAbmYi3GsK5J5kOOvIRf 07g9PYsN6v0+Rg/+5/xpRidSSV6p31yEByNdJ5g2L1HEeGEG5XEwtt70H51M3TPqEaoi VqBA== X-Gm-Message-State: AOJu0Yw6fBdy8MurHQoPKtGrjKI8AUwU3iPIApe8jTSr7U2m/CwL+bja qQMKPsAGuVM2j+ZRj7vr87dLSYOXRnZbCtlBYCkE1Y2MUSNbLHGbAE0CfJA/ X-Google-Smtp-Source: AGHT+IE/qdvAa6/rxXAeCX1KzOSAxGOguTscqG64rn+sgoVmJ6XWse9z8Se4QuWQDINiFFtlIQmG/g== X-Received: by 2002:a05:6000:1970:b0:33d:5548:435e with SMTP id da16-20020a056000197000b0033d5548435emr104219wrb.53.1709252095175; Thu, 29 Feb 2024 16:14:55 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u20-20020adfcb14000000b0033b7ce8b496sm3002433wrh.108.2024.02.29.16.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:54 -0800 (PST) Message-ID: <26b1f19d0e11af0af8c3be8eb88ef97bf6c24fa3.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:45 +0000 Subject: [PATCH v6 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 Mar 1 00:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13577794 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 78D3A2C80 for ; Fri, 1 Mar 2024 00:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252100; cv=none; b=B1RJkLoblAsZRsw03JobyHD1OuLDyKy8gWlSnu6VzHG8HwolPQCm+hU605Y9pAw5VgjK9hh/snvE5CcuYTVC2QCCisUq+UPWARXJi17KFTOwCrLQUpXYTAyWszvlbQcz0jai0oUpRyeja7+1NOHUk0e6cV1X5aoF7NaqNA4JpS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252100; c=relaxed/simple; bh=0wWgk3bHxk1N14jQSztA/JXd4hhftIltaUu5w0KfRpA=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=CKGse8IV1KZWWn1WV/3ZL3eBdibg8L9cJM0Ccrldu/w5zPG4mL9qVk0BBhkkxfaGE9Vn2FTw4tGM4b8k8zRmrMHdW7iL+nsBKvHFrDvUbVdrbQDz581VBoyOkIXjqkJnxnyns7W/83We2A7rtW9/5Vp4VeoeisuG0KRA5MWWElg= 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=Bwmgt/K0; arc=none smtp.client-ip=209.85.167.46 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="Bwmgt/K0" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5132181d54bso1715549e87.3 for ; Thu, 29 Feb 2024 16:14:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709252096; x=1709856896; 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=0WZY+izhWTibPggTpQvAGRY5I2odNhP80Vhz1ebOC3o=; b=Bwmgt/K0Uqn8ezRF+mUdy8jE04LdRhXNabuJYRE/hNTMTVOLai1vI1rXJtQHwPcbXG Wf2osB5UZ5QlxV+Ai4lCb8WiBPsGBcvS9kQAACU9S0dIkXvGC6iBVsx7Z0nogeepCdsJ wQ1/NmeUutXZLYmGgdAMpoPhCXk9mRE11Zpfyc08EiFno8kAXKu42w5FU57SFS3GBsHL 52PlJNMxIN5sP5LYZnaaS75Fwdt677PC+116cecw0bFDyrqb1S43+CawdmwQ6gxIMd0v BwITd0l5+pMC0RvlrqLbsDPgT2toS08Lx+QMUO6m6rVFlI94znTvmq8n9Gqyd8Dezo3k vgEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252096; x=1709856896; 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=0WZY+izhWTibPggTpQvAGRY5I2odNhP80Vhz1ebOC3o=; b=bK++uYcBxEGwEk0gq03BCoWmMxOs64e1AVvVukTCdyc33KEQXxJ2MNORrSSLlOIkO+ hzSieMGfViNRC9YutKL8BvTPws0wWxWxMMDDFiC0TB0v8RLlTpv3c4hTXQmVm3WGNidA FsIGXAdr3gPrGjUMrz5PFB5h+KUkDSTwVcsd5iAHuqAbXpsDHkL4KsCIvsBJf+dT6WaM ak+C/LcnJoKeQEW3KZBbUe5TX2jVpiYjb0vwDz/S2tB+Ll694NV9gdYG4iy7cPR62Qyn qv2PZYNOqAvxCNGwUt6/UAsx9cTvIISkqZHhWlI3iCN3/fQXf1r2MKVBEFDalGmGNVsk jePQ== X-Gm-Message-State: AOJu0YyS7EWAn6oj2x+f3nSWYyMHAGZE21uL4ZGzSwiy8rTG/0A9xt9u h1nxjPGXy01xFgo8nu16cwTx2GjTUXos0NtXqrIiAqnGKFvMqOkeydoiZumb X-Google-Smtp-Source: AGHT+IFuXHumsuzh2Hlgut6PcdJCNYxmv1Ky2Q8azbTEDWMqD4UHCoD+64M/ZhoVsCtHI+UD6LgoOg== X-Received: by 2002:a05:6512:28f:b0:512:e506:1c66 with SMTP id j15-20020a056512028f00b00512e5061c66mr71996lfp.26.1709252096426; Thu, 29 Feb 2024 16:14:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l19-20020a7bc453000000b0041292306f2csm6544676wmi.16.2024.02.29.16.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:14:55 -0800 (PST) Message-ID: <0e884d870c892ef562098e04ebabd38bffca7eb3.1709252086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 01 Mar 2024 00:14:46 +0000 Subject: [PATCH v6 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. For background, note that the "trailers" string array is the `char **trailers` member in `struct trailer_info` and that the trailer_item objects are the elements of the `struct list_head *head` linked list. Currently trailer_info_get() only populates `char **trailers`. And parse_trailers() first calls trailer_info_get() so that it can use the `char **trailers` to populate a list of `struct trailer_item` objects Instead of calling trailer_info_get() directly from format_trailers_from_commit(), make it call parse_trailers() instead because parse_trailers() already calls trailer_info_get(). This change is a NOP because format_trailer_info() (which format_trailers_from_commit() wraps around) only looks at the "trailers" string array, not the trailer_item objects which parse_trailers() populates. For now we do need to create a dummy LIST_HEAD(trailer_objects); because parse_trailers() expects it in its signature. In a future patch, we'll change format_trailer_info() to use the parsed trailer_item objects (trailer_objects) instead of the `char **trailers` 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..798388cbf29 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(trailer_objects); struct trailer_info info; - trailer_info_get(opts, msg, &info); + parse_trailers(opts, &info, msg, &trailer_objects); + /* 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(&trailer_objects); trailer_info_release(&info); }