From patchwork Tue Feb 6 05:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546634 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 7C29D745DE for ; Tue, 6 Feb 2024 05:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196355; cv=none; b=a+zI246Mc+5Jgj3RET9B3p5sp8YzxzxJ0HzcwTo8ztfKStQO6yH8K+UKGIpJ422v+VBhsHALRSWbVTqAP0LrmgYvJxq1214h4QCZbK1zijpQv398QHENM5KmVweaC81q6hc4ST0hywLUCRcSYLljgAyLXDaaIobsLtQ/6FSyI80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196355; c=relaxed/simple; bh=VtcouaHw6ztbGb3EWtk4zEbxwTZdAZDIvLKHObqns28=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=VMldLPmth0emoBiHAOOMuXnaH1qjEePNJFDz0bHxklCobqMm9eoPdYSkVHf1M507yRgiTr8duvR11H9UGrKy7uZXBWXeo8+Srxfqo8ruFC6it6qGBaf/gf1btSh8sdumiYx3aDvnkpq2K0AVHqLl/3NPpRepOOl7VLZ6Tr5+ahs= 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=meQJ7EEF; arc=none smtp.client-ip=209.85.128.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="meQJ7EEF" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40fe00cb134so5696975e9.3 for ; Mon, 05 Feb 2024 21:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196351; x=1707801151; 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=meQJ7EEFtzOhHnRGiZWxKElLxtAwMX6WQ0zMTPNPhWWqPrAmhQ7L/ZvVAXYzHVFuTP 6c/O/fsWwcWEes/y9FrxPYBq8J5wpnkbl47ttCk+B1EEAtS0FqjzFFvwYl8y3uV0ucNz rnD8wDVCuL+YM+9xe1WXDcvXsctkNOtS/6E28nAliWms12ijXY9HCVbfx1QJaDQ96dzk faypP7YE8nDzof3ZbmYJEsHtXlXE5Emab8+19U/yDtzjYfROvbqJzIPmqHLpip/gxn44 SpAhDHBVVbLzvel55+DANcAGozV8k0hmD2HQ5UBB+LsBERyqNfjcGNqw1Q3+19yo3c33 2HGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196351; x=1707801151; 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=BueVCH7PVMK9T6asbOs2mwpBpTJyCBedWjP+gYqqXsvRxM+v6AffyJqqXvhJTwHje4 SK8IPGUJiyYp9yYqIPv4/1Pkc8pPMmYR7hZXtSBaFbdqQM/oj8yQmjl6bgQCjcVFbUgl siDANADW2DziFDODgbw9kOYXngMYLKIakFQ5DPbbfCpUwkTdCiahNOhTVjThElkLIImB PQ0Pgjc/1kM9NWYNYUSXeLmcHALOWo8Tw2Gfv1GHyKeg0/aB/518wWH2y4KNAGlTPpJQ 1wP4MPQtld623OKrfYsRdPcU+1B78IMkD9vzJoqBOGnbH4taRDzsNj6LIECpjNG/lTXY eHTg== X-Gm-Message-State: AOJu0YyGXiOj2cJ5ZxIJoNyUR860j3YOMXEubC4VP4W7rbaQ8yXnGogX NVCZDlaLVoTVaiBifuWMI6n5RiWnIsQUjlQUtTFKBZsPs+Rc2z431kOFipWV X-Google-Smtp-Source: AGHT+IGGvMFx0mNqw2qWcBMs7XO1/kvFFaGPjJF0tL0a8KNOz2FX1r2JdoOrF2chWZE1LBsLpjwa9w== X-Received: by 2002:a05:600c:450c:b0:40e:f222:9e52 with SMTP id t12-20020a05600c450c00b0040ef2229e52mr1103662wmo.40.1707196350847; Mon, 05 Feb 2024 21:12:30 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUCk2VGcxpCV4La+E4/wbbMPEKH0FKiwL3HB9mZKwSGN7H8j1wSEuhXnN1LKX3TUdeCuyLh4KGbjG3owjE0TuTO7sU3zyK3kBqzm9fOGCkpIeIPxP3HRcHuXFlXpsysqeLJZqKDjD7d3PHLhunC1yGcOCH46IyiESCZxr+F8HBTB73bWAsXgh5PicIO9qyWV2x0hYWu2yjXZA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n3-20020a05600c4f8300b0040fc26183e8sm649606wmq.8.2024.02.05.21.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:30 -0800 (PST) Message-ID: <652df25f30ecc8227bef5109b0f7b47817386b13.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:01 +0000 Subject: [PATCH v4 01/28] 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" , 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 Tue Feb 6 05:12: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: 13546635 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 A22375B1F2 for ; Tue, 6 Feb 2024 05:12:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196356; cv=none; b=PlmGiXWTd6P2GsM5WmvU8f2Ab4AOXHu1Xx/NHIVibMTxb8ukGkzpF/jtjxfIMqd/inQWYcknVyWV8TnS9qnLTmUttDYDD3jhmb99ok+KYRTlpHfgnxUGGYHcE3t1isWqU8MPF1wBI3GDTgG8/cytEcNaUjhPTSRuAxx9vrtClfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196356; c=relaxed/simple; bh=drUD39xUc8WM+utEVxXTiU0Dg0IS66wVnv7Mt5VGK2A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rsj3xJhyAvUcAuIi8glbqWczKN2yVwB/Vlu38WrMEiQhJ6IDJPi4TahkgeHmFrMqzzKX2WNc8NGtib10s3u4tIROpUV2qOVWRU24wv9zmSuX7lDGNax8lto2BvxNRiAbWHQeTPnBOY98LvpCx0Eq9QvX3LAZNOAyn5+4SbqRTj8= 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=WgB3OhxK; arc=none smtp.client-ip=209.85.128.41 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="WgB3OhxK" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40fe2ed8746so1627885e9.3 for ; Mon, 05 Feb 2024 21:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196351; x=1707801151; 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=WgB3OhxKC7cRm45KM7WRjoSLRvR63sKuGBwrBS2AZLyuVCoNhbQqkhM8UovaSGCoCg 2J/kmsVqHr7RERPbLZQl4RM0DmPAiIN9QKMoZCNPA9C86H06ckkKCxg8G23WSaIDqRkR OxCcazO451r2Udu0xf0dL0Rfs8131mAm/LKWB3goqDXYhAUITMLM/hYgERWCijpo/+eT B+m2dH1l8TVGmBn05ZAU1SI1HllG2QCDZYrwu2/eO7vg9DZNbHPGEtAku4LWIrotl9Sa 8gVPzNBwXcA9QktQKwTz1UsVfGVLJRp+U8fyCXw4KOTwotMBHqJvcSQPRPP3PWOSYOX2 xegg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196351; x=1707801151; 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=hqOHDT5L6rwOsHJebFQfGQ2/PtjhSTTVQEHd9ITrfjL2HSSiHQJgzyzN9KkMGnUrhC 8BdLM464uGNv3fLxlxRQoSamABK3PZbQUPrrB025WPKMkNMXSgCYbsZkAOYFxHUBxYLo JqdUomaIUCgY+nrTpnAZ1sETJa1ig6yiEi+SUxARiPPEZ1peazykhcqHwJVePAu2F5iA w6CjR7+HfIKnZ4wO7Ps+Ocp4TpgIng1Ybyhw5j2e/IXx7wtoRrAq4acjZ7zCE8SeNoyU Uf3XbU6CPN4nRgpA3FsWdzAoKxbMQh1F9mYwQXuC4VqufM4lHv0xsbj4aPqMih886sTI rZNA== X-Gm-Message-State: AOJu0Yzn/D8xGSqnAuEOTU23V5mSVc+FGL0i2mlh7rt5IbF4lCsA4YOW APJbriWEbhdgQcUL4/QGVtsb4e+FfGMxHrU6239tNCw48KVupILZ2Mu+Bnn7 X-Google-Smtp-Source: AGHT+IHjgzXZX0qa7njq3T0MC1DUHVFq8LmLhi6Ce5BJbMNwNZAFG5kSBUB7iOoDxuMf5aPY25E7uA== X-Received: by 2002:a05:600c:1d20:b0:40f:e1ec:5d41 with SMTP id l32-20020a05600c1d2000b0040fe1ec5d41mr715051wms.32.1707196351378; Mon, 05 Feb 2024 21:12:31 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXUAm/PNhQ4CrYJ1QtnQTkWcwzzZZdpo2abIRF48N+laSFcfLwwo26CkKpZqCxby6ekcGTXgpzlWtymzTe37v2K1P7xTRQGz77IBLA98DzVm+fTmu32fT6BgY5OM2cJv5GL5S+PBoAUpncVa4JwOAJ5B3+dwXrTQipN08VPRn1TPP2PwyOkavmQOPReq6vkWBzLql49zNSOtg== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id fs20-20020a05600c3f9400b0040fd3d8ce5csm637912wmb.16.2024.02.05.21.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:31 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:02 +0000 Subject: [PATCH v4 02/28] 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" , 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 Tue Feb 6 05:12: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: 13546636 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 B784678695 for ; Tue, 6 Feb 2024 05:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196357; cv=none; b=WutqplBSa8nceUVQcozgS4T/U1ZEBvJB2MjWnBZHpTZ8FsIleywQFCLfbu6Dm9sYqyu+PCx9+vwhnh+EKn4rH3KYx/8+qHmomIR0wyYHV8eODQ/p3PwJ6BJW1L/8d5B1Rx0jo/P6ZhVolLm+jiRqjmTbWfyASp3s7vVmBjjgK8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196357; 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=k5UGOxJKZFNSSfhaK+26ti2utF/tGn79fYy+OmbV0Rx8vxqFaupt0rp+T4zGIneQK3N7dPdhHEereHGT8M8KYBjw/VeCD95IUYVImH8nX29wpGdAKT2pY5u4AXa5ZObIbCZwARUtZ2kstuxyz6Kur/Os9nmObZR74HkUuezefaw= 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=WROVa1xj; arc=none smtp.client-ip=209.85.128.44 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="WROVa1xj" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40fe2e746bdso1728785e9.3 for ; Mon, 05 Feb 2024 21:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196353; x=1707801153; 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=WROVa1xjCdjf7iJ5vnQuBasVl9BndTNHNrvEqwP1Spg2TVwINYxrdSrloGCr5LeRhV bz7i7DWBHjP6K1hhF2AOdf1/d5GM0r+YfjMPMfRTnLM3HWQQ0OsVDWUATeY3X9kzc/EL 7auSFuDn8ZwQh1hrafYUudp8ZLk06hNDI3+kQwDrUx3vAFyWjB4uwdNWrtvCTLYVPc0L HZkPUYl8IeMBEceTT/Jnll4JpaaYWQD1lKBOxHzoIriwXtyOEBRkiPE2P2KgL2PSIObG 4cAI8LUidlPF41JfTyRKnbdhsJ7P7BPrSQlRhb2GaOMfcvG7Z9EZoaXqCMJbLo/Turct d1Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196353; x=1707801153; 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=KW0wHWZW5UaS85LJTerfD1ipFeG7z6zfefR7JEjRlZUm3NmSzKd/8Vx6HyyJbVFfAY 0FJ9Jj+uG1Q0vw9Vp5YTozaiLKxZIGX/BqyT8l/JI8I94fKJOX1dG4M59YgZNcItcdQe vMp7AE2Dsl3tU3D/qmj7RlV43qpRmNoYvnCQHvSFHpbutEQhYAhuKmxVtIYl24SKD5B2 teng+8HS+wOe73XmTMHy6KTKKbBkHzzps8++/JC8cfM1HDGPr4lMlgMs9aIcFI7YCMHf ZLCQYjo7F1+G8pkPuhC/wuazV2MRlWloWcMYIV15xrgEj54VOifNm1tBm1vOQ0PWBC1Z GB6A== X-Gm-Message-State: AOJu0Yxs5pi8cI2iDUXUCD65s9pCqQISCVgqPzXGmbVDjsjuFTQ4pJqW 6Rumo4iq1+Q4jKkxqRJD79ORjucCiBDhq6NQ+0uxCDj8loqrIe6w7RPyq8pL X-Google-Smtp-Source: AGHT+IGzKATZlDMdCkVdW1GiSJibQJtECI4cdhRl4N/kOLKwKwSK5FAf/vS2hQl9ZNbUjxyokdOcqw== X-Received: by 2002:a05:600c:46ce:b0:40f:e506:cc6d with SMTP id q14-20020a05600c46ce00b0040fe506cc6dmr182652wmo.14.1707196353428; Mon, 05 Feb 2024 21:12:33 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWF6/Nk9lczWslpFEg2g46oXnCoa/VYJOwkOkqCCBcKlFA37va7WC3WJIMb2BsiJStRMyup1vVUwBIYsKBtkVZBJPvJIPa1fSMEiH9RSAignfZgfax8gyiq2kj6eqCrnXyU9cGMPVs/LtPZv86hp3YkqCVovRvTAAyZQL6yuZiY9kZi2rwzIv9tZh8uDYN1wy5svF+64KUR/A== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j16-20020a05600c191000b0040e527602c8sm653898wmq.9.2024.02.05.21.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:31 -0800 (PST) Message-ID: <4372af244f02b71cc70f3a8e1b5591b3b9fec93a.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:03 +0000 Subject: [PATCH v4 03/28] 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" , 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 Tue Feb 6 05:12: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: 13546638 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 080977A709 for ; Tue, 6 Feb 2024 05:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196359; cv=none; b=ivUY8seepoPmkw7UeucxNtfWm8A/B6DH6+ExMwVZaPBHkdkD6J5YDHA0Ca8Uc+VisjuW5+NJE6RFhDQJhDzORoadk/LGLkBgk/dyCfvauhgJmrCa2JATPLBx+cKhcg6kfwlHPTE84uaHDVFFf2BviT8U3ANQGBzZv/FGMsdDY1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196359; c=relaxed/simple; bh=iQq/mzoDTFVBBW11XhOGyw7hHLmxOQ8KAtf6x2O4BrM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=beWlw7650GJ69b0X816I81EFnqp5WuqazvIRa99imnkPTb8VYTebEbr4m/lNUmLzbT0p76bJ7cYJbr4xX8GwQMTCE1jlo6v6hVyLMNliMd0K87bsAUXOZXhROqiQ5e3UnEzoIHrcPotZ/SCC3fpjMVturhxKprDi6QqVVUmDXbU= 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=jeMAc3HS; arc=none smtp.client-ip=209.85.128.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="jeMAc3HS" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40fb3b5893eso42221145e9.0 for ; Mon, 05 Feb 2024 21:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196354; x=1707801154; 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=jeMAc3HSKgxhVz5ZAZwDycwV83R/W/nRVGNNXm5E2uKWvXUr2xOwD4qGKcriwiwhpj 2QHOYFKrECks6ChcThB/LTI1BvONo7zWJPk3fOz1HsPNeIaDXej/Yu7EzLjLzShVIn+f tT4rgn1BP4+Y8yNeqMio2Vw4sfTvauJk8EbwRtZFJdmzch1Dxcujtwg3nEAyNhhEB6sh rhxEzLerK3nTzxmBWCGvcxzORezcnR8BIZvIp9I6X+wHH99ID8wIbRYViHLvjk9DZKkA 1Dh5fSnput1W4DYxDr8rJ3U6cXhpq92lvpvzI0jQ/rHhDEw2MBb7VInLVGR86ri44hAd Ovaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196354; x=1707801154; 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=opx6K1xJYSROyhCaIe0s6rqYmlH9rLFppk8F1Z0fJ+eRAm3PMQB19UTQ2Irnr9VhSl m0Rp36PO1y5p9Isbhh/2vbLcYPkmyuGZ/9UpoHQxCeLiJ1dnUwUb9RwK8wTRx2iHEbIX YYf+H2pqEU/+hpISEJZ3Js7m6BySdSVR+EamYu0JuqHJCV/ll/w0GADXn3+YvZ0Si6Ea oS7GWkr3jvU9CFZE/7R6Zi2DKZk7Jquf3cOMXxx/QTWOAotz/gHbS/Aig8ZhYV+rK3dj Ip+I4zqdK+GWKFc7FfbMJPFEcgTFsqzWOwiXBQo73O7yRol7ImCK9Da8BC6h8cB5zNdo 72Cg== X-Gm-Message-State: AOJu0YyohchFIrknEk+U9zihnFN+gxO2xs++GerQoLzbDUd/FShmVA22 ZuyMmVYRAfC5yu+YcII11GIiDXGMwoOt5wN1/qffmGNPF4b2VP6apZLY7/k6 X-Google-Smtp-Source: AGHT+IFwZx8fLYSsJ/NLCe+BmdFcbdU0fkqV6ax5KzRvmRPa+NDv4SdT3G5Ptz7uNLAEmfCS2Ph14Q== X-Received: by 2002:a05:600c:4307:b0:40f:b166:7687 with SMTP id p7-20020a05600c430700b0040fb1667687mr1197099wme.15.1707196354516; Mon, 05 Feb 2024 21:12:34 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUfLOtdhNMIlAyHp+ERpK/7RdTgMdOgGBVakquVVvdh5p3VMyVfjVqz4tGy/I8UAuU9NZt54YpkPjOs0OoNI2WnXQOftm9yvRWIbLPoSpPkUUfHfCC6l/3c8+0Uapg2mgeGOznZ92IfsX0j3QIwrkh5P8w16yrHW21XMdkRuP+Fx7GNjqxEGpK2zLZJZ0n/vc29rMHgXxN3CA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4-20020a05600c1d8400b0040fe930b52esm16743wms.9.2024.02.05.21.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:33 -0800 (PST) Message-ID: <4073b8eb5101ea49d8e79b40822aaa42ca87d24d.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:04 +0000 Subject: [PATCH v4 04/28] 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" , 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 Tue Feb 6 05:12: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: 13546639 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 2DDE27A728 for ; Tue, 6 Feb 2024 05:12:37 +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=1707196359; cv=none; b=YIPmfeKbzJV7zccvqSR1K536nDcU537vcBCmJD/SSV/JFQA+vgolxlyIe1Jpok+kPXMpuE1OaiiAG1uW8+a2IgnPYD96QHkswuk4gO+pwl/Axsao9CyYFDx/mSadtEFN7B5JvMI6gc0Xw+wWUEAdYLbT+VB7yh/rlf+KnvAfKVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196359; c=relaxed/simple; bh=g4ZLlEfPTK41Ntq9qyqJcpRFH6ZejOoGqeqQiTtEIFg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=XayOM4tBMPL2wq0lzSBGNt5fg5ENxc8Rirw71daqlSJCNid9lmSW5sNREatHrAWN9CcMrImD08atIRomR1tYjAehYy7nVbiNLkgyB9DpraFE4eCMOHUBF5AnOZD/e+uMyWTE6fTQBfciFeh6bZ5k7HPQLrb0EjGpnI6nixQhrjU= 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=TS6wHNJA; 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="TS6wHNJA" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40fe33fb7a1so964785e9.2 for ; Mon, 05 Feb 2024 21:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196355; x=1707801155; 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=TS6wHNJAjDFVng31xtjFE8oCsW1MZFB2DvKhyBgPBdxUWJLfVhk4P/hbbZpbNk45IM /18N9eP22qg8XaCAVqSzD/cELywPGOog2upnTqxCHuGEXu/unnY/nn5j2LwCkV+47IhJ PZKK9S7cg2hKhgomezuLyRUjfWM37q4PZaz7o6MkFcoAc9x483DYOrRJjdjWV3M70z8i fNxDRMS4gp0hG278yw+mAUbfWmFE/FmMnthopEz4Mg78j7la45IxVbX+EbBv0RxERRVw gJU8yrZgSz+0d7s2KR+F6hLJxwwv/J6bEDrYqEznPGNxDt/cLKVi7VxcWXlIEkFP9OG+ SU+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196355; x=1707801155; 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=jvQspVbNr70qnBS2vbahVsb6+C0dl0sTVnJngLpjTVJG77TWPG4VYCxJNBh6rYquV1 5RGPb/CJsd/88N5KV3bgoXE9p18d5ug96NF6FKyBRzlTr/alYVFhQbJwGVwDrA7byPSP x42cqHqRS0H2PK3rHelb9gX1iKkPBKnmA77Tb0hPMzdUiM5xmBJBDtUqQJINeGfVsE0R xoPbegFjuJ15gwZnys9EHisilaTFqawcXKVRcWQFTCNYGFw14xYZ6XrWdOcMwE1SXumK Z1d3sVsI+ip12P4TDQbE0eLx24+cb05a/C6/zIMiz/UCDVo3W2/LFSi6CH+ItpgmEbK5 nMlA== X-Gm-Message-State: AOJu0YwpA/qqdECCuZIUqzu+zvBj4m8esqYMvLhyuR4vGNUf6SbNm7I3 Jm3VUOrcZShz1gFsKSAnp/PpiBm35VUMtb1SUXyIvButYda1TNeO/vUBvogd X-Google-Smtp-Source: AGHT+IGG+wE5EE5/GxutCT6plm5xVG0wq07kbQQqFXEAFiB7PFTDEtt3hq2NyzzRB0TxFokw3r+meQ== X-Received: by 2002:a5d:4565:0:b0:33b:1786:f911 with SMTP id a5-20020a5d4565000000b0033b1786f911mr342531wrc.54.1707196355636; Mon, 05 Feb 2024 21:12:35 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWT/SVfvJtOGUWIVrWDaSU7QGXyKDkAmfyJ19hdDEQgHSbrILveaspGIw2/w3FiJ3mbnmixP5rBMpwgz8PR307KpY8RKt1nJEyNGPKOcGnLahc69woDtR5I/N++HON+TM1jReur7cF8/eN2V3wJ8ZFAQLzCSXZY0aFmpED74LGBhImqBCsO0qHrOWvFaWlp/JXNtpFwRA5I2A== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m9-20020a056000008900b0033b484c3dacsm224287wrx.57.2024.02.05.21.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:34 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:05 +0000 Subject: [PATCH v4 05/28] 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" , 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 Tue Feb 6 05:12: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: 13546640 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.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 4D43C7A730 for ; Tue, 6 Feb 2024 05:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196360; cv=none; b=CPcdTdi+UKht5uBXQNecHA2mxC9ffsM8BZLUnAjOaas3Z54L2oamhXV6FmQ+vo4/1bklFKkmWLiPHKtW3vhO+e20Wesns09P4ZTkoGkwcsZRsMemZXAof9ZhnmZV1zrxjnk8Hp89FWSeo15lTAUGxJCYTHgcPV7w9zRQ2ZFGljU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196360; c=relaxed/simple; bh=MFEKYSEG3HI7mYG1ysXMfdUDr+XakqitFvOBDN2YbE4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=rfgssfVwM2BuaSDn1Lheu4PDBixOosFOBCKDJ2B2jaB6QUDCdtdvFPWh6OhlfaoZknoCNi6iIo3N91Yfs3N4zfwKcy6LF7xK4/GB08n2zjdMrk6dFQNcBltJKuuH28/qYyoBnlY9fRrovvANid0wjOuWtzD7xmloKMqQmJVUcf0= 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=CGX4Z/jV; arc=none smtp.client-ip=209.85.221.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="CGX4Z/jV" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-339289fead2so342746f8f.3 for ; Mon, 05 Feb 2024 21:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196356; x=1707801156; 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=CGX4Z/jVDkOZUTb7jSzgq14s4EpxVRfvjVHeW3HmBiPUrTgilqjaeaJnBjeehO6jx5 Ux5Jm/CYtByw/faSFUImxDuP6LdCgtR+QhN03oI3J+saNr19+jdG4/OcqhFuANxtGdvV 9W7TrOyRxpAC5CGuKRxG9EuskaAv7hKs/1BBwQOsNSs4/TdaxogSm1l7sVi0EZaPgrjC ThtjtbpsoC4GyzTiL+bdccQyUybG/gBM03dFxrL/tIr8qAlExTEbqFZcZZgbLl/L4qmI 8HNV3QAWEG5J+3TYdky853Z7q5nEIwCZYXC3PDrPVFxiihghKjNPQKWiOUh5TcmsE4sp yZjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196356; x=1707801156; 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=QburNCB9o1g9zwHO/cWm3u3R6IuF+9Zvz/JScZiM6reJ/Tgihnvr84zhUPd+8LF83U Tq1QqvAWkXqd2DI9mR4BgIYmAfkr/X9FsL9tks4+sEn7+zZ8FTVEcEHmryRjdhv4E+hi FJ+vnw2FZ/fJNEY6pO0fxtgdDwlXaMsEOoQfhkYCF6AnJHY8GHFjgPfzQTAQM5A4DJav 2m6j6hn3Df8zJw8z6E0OcDvKIBRi205NlwQ6HueYQ3cHA505bCHZ4AW996YiJocZrPVV u8rtIYcC4M6o3jOxiOKh344HB/yAB3ltFvv0nPlrxlrK7SflZuX5cOaREwW9C2cvwrKr kLUg== X-Gm-Message-State: AOJu0YwnKB6SDfpWcRVmLUki489cpnUbWdAFggLPdi4DPjYuwBD/kdEw MUoumurEUhLlWCKHFO0h2tghxN2Qegs9YMhXsP/ChJYeznxhHHO9nPx8ADGZ X-Google-Smtp-Source: AGHT+IHG7YVpG5do6pjLeu2RIzE5j5fK7ka3M2CUpel6a5A+kVZSsr5jMO6dn9JesrTXhjqL1zc51A== X-Received: by 2002:adf:e788:0:b0:33a:ff92:6e2b with SMTP id n8-20020adfe788000000b0033aff926e2bmr449125wrm.4.1707196356120; Mon, 05 Feb 2024 21:12:36 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXA1FforoaRiVcP09G0w/qDh67rrjyG32hJOn9teBbPiZBJfE0lNHN305kAXqCg8FOpaliePgCbkjS43hMdn6XevKy7/JwF5RFoTZD9z+GlLhj0SUWj/O7oxQGbSl/ZyHnV+dxz0pqP+TyMtV5pDIdJ7lb8J8r+FVPphDMKIID/hEW6eHzJiG1l1OWkUAPQwXQBs2c7J5SByw== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g15-20020a05600c310f00b0040fd0f7d267sm637055wmo.44.2024.02.05.21.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:35 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:06 +0000 Subject: [PATCH v4 06/28] 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" , 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 Tue Feb 6 05:12: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: 13546641 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 65D757C088 for ; Tue, 6 Feb 2024 05:12:39 +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=1707196361; cv=none; b=uwqq+aQlo2CUKhBGniUNvOAqrwJPBNgC01vFzVZgL0atJpOoS5SvtDaWfVSXSQCR3fTTvt2zMJz/4C/y/qR3ZVo9BtVFtvIUnQ4bT0X4Mxe+pMtTRoJC5WdBCN0iz9fbT7m7m2PeI1b2izjC+EbEcF2iZajk/oQv+LnFJL4Tozw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196361; 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=X+/nD+BR+P2xvYmiJsvP5XUcsZrg43a+sQHAzPaOa3cxWbJzAVcc4VX8DL4PE900O2GbCaviB0IFqjtAFEvy555Vn06WISHMLrJ//u5c/zW3MmQLl/9zc1ja+fz8zxOYfkywyOVYh+yq893KuFvvtOSpLYlbMP2Ni82mKpKwu/w= 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=VFd0FZCI; 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="VFd0FZCI" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-40fc6343bd2so34058145e9.1 for ; Mon, 05 Feb 2024 21:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196357; x=1707801157; 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=VFd0FZCIEV1vRxXhO+EL1RQP2yl+PiQuI9GMRcmVZ2+DsAJUOxA0ne0LqDZXih06s/ Im13Fad2we5hhqAUnCdM/+i2oIeanW8U9oWpeFQ7BPHcK8BlC7x7+hwJcGwr/CttWgQm LMWC1mQe6wIFbLP2zxutr7yzsdRG2HpQnX973P3hb+TemItJIe+50bWYj5MWr133C4FM +Wcj3hXqCX2Yxbodx6lj7hKtmcFBivUrMhl8V0TQzDklOofPq8KY60rSnBCp9SCld6Sj 7sbUPpHm0nur+gOJUDCbeRoik3Go8D8+yWx2u+6M4Zt/l+vpB8chn2BXfsmsnWxpd9bz me+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196357; x=1707801157; 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=wvqqXLWqdu7exUCGPDyCx2e8tknt7wk0iTwtiSeZs+zycJcX9Wdgltbv2fG0dRkyJ3 XN8zE9EGdefxsZ58ETNtcwiWOTYNvNMqPd8DwbMlBvWT4daFnQ6HXEQQMRgB1WrTfmnF enGiJ2Ipwf5wP1HPv+Ql5gYlBpikCusAPgEXrxWKGI9y8fxqIZXplajen4eAciKYUcFq tJBYJ1szhe54+A6DOz4jTvvGIECgqtOZPGZFOHpxcZTnGoUOCjvvUkxIzORDwhYnQ7MC HbMM+hwAkCaIgXOAIQI1fg97Cl/3gjoWfmJiLQ3kjvWytHDnMa0zrAzCXitYGe2xqA0s YrCA== X-Gm-Message-State: AOJu0YzkgEFp3CAy0YPoluGpFhfp+T11JbZZq35P1139YwSeGeR446I8 c5ltdKd/RYusf6v/tCEC6SA9xtNCvA15Rb9HVJYeBIBSoAW+VyoWW6g7G4xL X-Google-Smtp-Source: AGHT+IEIqAQZOXUSPOhwTacddVPVpn8MRdrpnheX/fhLegU+NYz0eevVyEzVx9+LMW8T8MOUsvJHGQ== X-Received: by 2002:a5d:4704:0:b0:33b:3b88:e357 with SMTP id y4-20020a5d4704000000b0033b3b88e357mr344203wrq.35.1707196357074; Mon, 05 Feb 2024 21:12:37 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWd+RvLS//n1xE4zigFL34V3SVvBX8oYN1D8Zz1BSNiaR4t1V6uUfMHsSIwUD3sy6cOVTSuVvWH5e1jX2UUpa8YENGD4ZAbEck+JsZi1Fb5n4+qicwvP0kqOP+VI/8wcTYlyCfcbKE0KSxnAhX8geHjJDHlyRaoo6gad7zXcb3ioVOIcHvQftRhHfPYU/kY39wtSXjkXb3w0g== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jq16-20020a05600c55d000b0040fb0bf6abesm639803wmb.29.2024.02.05.21.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:36 -0800 (PST) Message-ID: <9dc912b5bc5ff07fedc0dd217b5ecb8a1eb10cc3.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:07 +0000 Subject: [PATCH v4 07/28] 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" , 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 Tue Feb 6 05:12: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: 13546642 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 5621A7C0B6 for ; Tue, 6 Feb 2024 05:12:40 +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=1707196362; cv=none; b=hkolGZGVlPLwjUhcUSF5kaoZxJEZwUROGcio0Nkd53PalqqZm4ORPTbjI174bAUP4qUtjUJKLu7yZEpsFThnwp+mIG3mynm33A/4oL1FClakSgex9LXGqwTs7uozXTeFtAmtvML9qpweo6YIClnPp7MQZz1oGl7KANDeO/uDeRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196362; c=relaxed/simple; bh=8zW5s9dVw12pr9fbZJS4z8TlV+Q1EwM2vdLxdUNtO1o=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jeE7UlcHd2bLopDWCvavJypVSEyRn3CF0vu1MOE+9wxkgwI8xEdHu0ZtDNvXejU0vjclepNGeqqnuTWgbFXR8zsxgThHwnd1qErthDbCMcAx5wA5vALCMkuMmjsqlfjljMWVb8a9LSwu02eZHEt1WpKWFztiiBw+H2/FD0dIuoI= 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=npGwSMxG; 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="npGwSMxG" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33b13332ca7so3199325f8f.2 for ; Mon, 05 Feb 2024 21:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196358; x=1707801158; 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=npGwSMxGZmNZbN6nyHSk/9QQbZATFHyTxySpLmyy0WDSu5CKMg3SBcO/Q0UIRaGYfP A493YS/1O3ijhdAONYe4L7IRYTpj1U+PCnoe3WUb3k1s/0efZPJfdM8b4vHl7J7fkHet bFCvRwwq+j93ZbpoDxPiWUTig+nx+fWlxuHgLs/Zc54y9WWfNuTNJF3QbiFm9SgEJM+0 13iZMQXqv9SLhVkE2e9rKdWilTObFGymjVuc3PQwXNfxsVQrpsDaWeI8284VrBZtFdrN YEicxGs9yT+kFXXnxUmDuriAJjw+7n257/sse4I3xt3Dx06t6JJH3cXPMqBWrsH0GAup Jb8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196358; x=1707801158; 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=bZDXrgp1eELmuNA1ClWXBdXgfpRgAwwj9oGJP98BbuAi8Vaxk/b7VIz2Qz5/mXUJiu iNLJYHIT/vB16lRkmfA9Zjss4RtZAw37XzBcPap6aYgatV5paliyETngQj+0oNjPsxU9 WI+hWxzGdVHjhV/ZFC+loBXblVbPQTCTjplyxHQdzppu0+uOW52geq/Cn9yUN2iPtJqL w2vs7Fa4KVmF/0ebVjDPD4QtcI5+JUkuH44YBEbHhD2zcPja9jQH6Q4+B7H1SmRQ8dsA jIgAS9bwJ5sSMN+poII79fmDFxCa/7koo1/kjaqO9uMGou0nCyq/sT/qptBZ/lQdkXqc B0zg== X-Gm-Message-State: AOJu0YwUNHDrxdh5s+1IoIV7MgEeHBNog9E45/1QKtbDh6iaSxH2i6Ca TAe0VbI477o541CKlHMGGtJPvoPHQHVH6h5Qe79E+d+35I6GQlnGYu1vHiMk X-Google-Smtp-Source: AGHT+IFPA6ySMuwoPUCvvXKUGaDOOPZb78hxdg95P/CSH+BShheLZQzHWy8L1mO5mVmrQXpV+FgkKQ== X-Received: by 2002:adf:ea49:0:b0:33a:f27b:7fc1 with SMTP id j9-20020adfea49000000b0033af27b7fc1mr427523wrn.31.1707196358204; Mon, 05 Feb 2024 21:12:38 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVbgqB3ZOndMv1LkvSIpHa+B/kvFWb39cG5HF2jYDk3c0C2upxQKuEq2I9p9TAXqMi4Ha0DX7NMfLk4xDA+6ewGdsgMs091ouAnPU13F7CgyuOD4kH9/jKHrjjdzlutLv7FiBq1QfbYTIKPaHXbwO7j1afWzxrJfBnVvvBqhLofikMzdJX5oSngz2Ge6Jhf2mPpxT6bEe2x6g== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n8-20020a5d4c48000000b0033afe816977sm1048148wrt.66.2024.02.05.21.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:37 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:08 +0000 Subject: [PATCH v4 08/28] 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" , 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 Tue Feb 6 05:12: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: 13546643 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 56F607CF0E for ; Tue, 6 Feb 2024 05:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196362; cv=none; b=E9SN8tfxoIFnVN6JTj575m8aJ6EM+DmHoMg1CyLP6QgbeC757Ji8o7IxcIK4PZmQhEzS7dr11Z4+uWTEyowsuSb2tbdcBraS2z63KWmXDlejT398bylX47m0k3eoErewrEUpUi8MF9cWrkVkYXlopnZOEUEsmYjjIt+WGfBoDlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196362; c=relaxed/simple; bh=xEjCtEwH8053b8FmPyEdmUirelnDF6WIWGEupqxMwvY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Ck5V92cAOK7yizVbH8VLV+kTPcxUmViiJFvP7fxZJwQKm2eyx8evxv7FYpycSomFFnDFem6ChtJaKCrmr173j/Jp5aOV6tkK9IgCUQmFhCwZtgZKuXjw0eKr4eim6HqQY9EwcJqRkrlokqP2CVppLvQwyHHUk+3b2lun5+uxAMI= 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=f5EVBdmv; arc=none smtp.client-ip=209.85.128.45 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="f5EVBdmv" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40efcb37373so3902535e9.2 for ; Mon, 05 Feb 2024 21:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196359; x=1707801159; 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=yxs7mFyDPThYA0V3QkOpNhWsLeMxmasJHGkliFUZuUg=; b=f5EVBdmvHYD0nK7XmTvr4ieHKA+KEq6hNZ4h0PFh6kUUcCL90A87LjhAPVQfhv1avO NJoznrAgutoD2j/DW2dyfpljcnplTGQjVewIJDR6fUKi0vxheDD/EbSbCqidoHehihyb hoWC9wlxWVL+FDNh+dJypBJRbo0OjLX2gXq6TbNlqxT+kMEwvLhXJ85vVaIy/ElnZHld WyTnbU32aBIxPD2cNGG2LDcx1uTwobzeC/zBm3E+O9KqNnfjRruL2ATsbfKu6C+yOOqA l6QDWL1CLF5LtWG4QJvfEZ+KBy/jNFxBTU83kqFHDpa3WBYpV4ufvY8wHPCZ3ja8agWm Kgog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196359; x=1707801159; 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=yxs7mFyDPThYA0V3QkOpNhWsLeMxmasJHGkliFUZuUg=; b=IwpMxyas+h+d0/hmN1O3e/xVzME7nfv04ySVoVQT28/OHenolTAoAzBltGmHt2BZ5r yZ9gTQKEy3vOr1E/fxKaNLHh57GI6w+LBNyi00o2UTNd6Q5Ba9SqRX2WxQH4a3s9kseq FKlL2pn1NN0/8e578R88PO5sUVYAWVkhvPzGkSWUt5WPI/sUgo7RF+62L32CIGNvpyva 0tjnZP9cuur5Zpqcuc7esSGS1tYUinqQ7T2VQuPQ99QyNr2BQATP3YwQCaK8yN4nJyGS GtNwawsGXe0jFCgR6IDqZouOkXQiLencdC5ayFQCMQvRk6c2AuHbQGwRbS0sWsCXUe9V 3NkQ== X-Gm-Message-State: AOJu0Yxbf56ll+IDRHftmcb/s+8MtP52BO6x1g9/ERdomX89qfo0MjOf 4w4mI1G3gDhEhGUUM3vTRCrhXT7cTAXbr3In0aCEkkg1AZK2vX+gvrTYKTo5 X-Google-Smtp-Source: AGHT+IHsyidatQ99DjaotlBsJWhQDmd/dLqQ2s1UwbGjmYo1NYapBAORNLMrdBxIwtpK3W1Bl9D1+Q== X-Received: by 2002:a05:600c:5249:b0:40f:d22e:f9e9 with SMTP id fc9-20020a05600c524900b0040fd22ef9e9mr1337646wmb.10.1707196358969; Mon, 05 Feb 2024 21:12:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXiCCbl0RsldZOrbtPqwiedBYoCo5BolTZQjTsAtpxRVzVWYSRUvmqgXn2/Pn9CZB3NrbqQhieUJUYURl4Z4lsdW50AKDMhRvh6nrHHIHT4ojQu7YLckxEnmvjYiRsMmLOllA4r5BlELiYdtQHxmdRdXwnbYHaW3gdNNahCAKt6jZGRiycTU0aLREUJEggCzLKhU58nvbAucA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h13-20020a05600c314d00b0040fdc7f4fcdsm658917wmo.4.2024.02.05.21.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:38 -0800 (PST) Message-ID: <6906910417aefafd296997548b77038222883753.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:09 +0000 Subject: [PATCH v4 09/28] 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" , 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 the next 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); } From patchwork Tue Feb 6 05:12: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: 13546644 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 1A3437CF23 for ; Tue, 6 Feb 2024 05:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196363; cv=none; b=PVLmZ7BzqNm+FYzv15vERQckgj0M1vFUBnLJGeadBPqbg437Nr4Dn1TQYrhUjxjP2N15s97ZcBzCmC26Wj31s3VxU5aYkOKQKShtbaem/ZQboXqXczh/qzrxkU9U63YIF4dEF16c0tjm2bQ1WIiOwtdDGEFS5+v3nOSrpWHTJ5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196363; c=relaxed/simple; bh=jvQWPxf7kpxSJj/54NmB40/CUhVRrZoz5BssuSfyvSc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ReCfO8kBqsDC0kfwiPYYc5sGU5hI4AA38HA52FNF+EmIHoJuQszdurrk/eesY7kQdU0dSeORhsr3ZFMlIMwmgvpNxAErnmoQ8FWvkdjVwn9RjC/Y9EuvGwHq187xeXLLymfwO5qZamgQKzIM1p7L6UFnb0W+wJn7PtYjgvFQvi8= 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=g98ztMlc; arc=none smtp.client-ip=209.85.128.45 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="g98ztMlc" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fe00cb134so5697535e9.3 for ; Mon, 05 Feb 2024 21:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196360; x=1707801160; 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=QIw1jmLJIxWt2mChf3XzMatF0mxGbl45fmiYLc5det4=; b=g98ztMlcUJZLUpuO5qcmq1c/9uipw5dRsYsl7Y2pfzp+rW/L9BK1YaQkrmGMZxRLnf DQoIm/qyLsojs4JN8W3gKfxGL41YfkCxZooLrkrWzJzaJ5+BcziRDv3EIVWjWUd4e9Jq VORWOgY30UUjqnOxC2rvcHNhVOoVTSku7nc/IThu81+9afZw8uEK9eNX//BQ0cbB/pYd G1rlAi2YVyX8nYVx/RfM4iDUlXkWOT3Phh16vGMC2FU1Plwu9Ym5eWz+IZdYLXGrYUS7 Tyf+AWIGgmPGn3KBH3dRN8hfnopvyh32Fcie4fyH3wdV+PatLHstBfrFnsZNr4mt9k9h Y+cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196360; x=1707801160; 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=QIw1jmLJIxWt2mChf3XzMatF0mxGbl45fmiYLc5det4=; b=ezy40xygUAKNerinmRn/D8+ETUndNUrl3FJnjEPxHKu/JmNk/cT+buuHe86a5Ol8t8 19GEHjY69m43NqDdO0scy5PMhxWS8sZuUtBchJJT6MNRE+TmtwNFfmlgbzWAHp+4FBC+ fgOnQECA/5LSkbcQKZQfgI8yZJAluOW4YVmyhLVC+QiYNuF0y26IwowHHMez3WaKngnh H9cshgCSbP0H2dXPLQdLonJ+k02zGkhp3clJIlW1Hp3LZm9caHrtIkZGmxKLY2rmt+Xs fqWgmpNPs2NVxgJhgFNKjvkm7zHpJQ9MfqxpErDJ/5epJBEkCCAfYufI+2gwgJsHcLkF 4Kig== X-Gm-Message-State: AOJu0YyEbT2akZWTZHEbsfcQ+QCeogq3/JzDLKZ8Xt33Pkd+elSZaXZS TBNI+hqOkwdGOB8gRV5AldGO9XdjavnsBo2dYj41QqEsBc2lnugYr606iWit X-Google-Smtp-Source: AGHT+IGYxE+xYLZN4Yru/kemyHyGbd/gL2BjIZkfyhmNj0bD2jkBBhAGrXMmd2PzRfvv1MWeBCuKSg== X-Received: by 2002:a05:600c:3502:b0:40e:f5d0:8517 with SMTP id h2-20020a05600c350200b0040ef5d08517mr1130564wmq.33.1707196360231; Mon, 05 Feb 2024 21:12:40 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU4Y4ShnGy5Fu1eAWdyYsgwNUh6LVEwTJP+TuR4b7xBSidJD6W+XEI5GhxmRKfqOfmt5l5PzJSB/K6Vk5RWlIjq86LrOPW3cyIk2Gi1VJSHNmViLK/xB0sBP8OsyPkICIR6eW05VnxetoMWHl7tmL5O/uyewJksBWG4n67+4T0GG4U2sXeUcWb9nIu6LXlR1Nfu3nP/HJlMig== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4-20020a05600c1d8400b0040fe930b52esm16990wms.9.2024.02.05.21.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:39 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:10 +0000 Subject: [PATCH v4 10/28] format_trailer_info(): use trailer_item objects 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. Make format_trailer_info() operate on trailer_item objects, not the raw string array. This breaks t4205 and t6300. We will continue to make improvements until the test suite passes again, ultimately renaming format_trailer_info() to format_trailers(), at which point the unification of these formatters will be complete. Signed-off-by: Linus Arver --- trailer.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/trailer.c b/trailer.c index e6665c99cc3..6333dfe1c11 100644 --- a/trailer.c +++ b/trailer.c @@ -1086,21 +1086,21 @@ void trailer_info_release(struct trailer_info *info) } static void format_trailer_info(const struct process_trailer_options *opts, - const struct trailer_info *info, + struct list_head *trailers, struct strbuf *out) { size_t origlen = out->len; - size_t i; - - for (i = 0; i < info->trailer_nr; i++) { - char *trailer = info->trailers[i]; - ssize_t separator_pos = find_separator(trailer, separators); + struct list_head *pos; + struct trailer_item *item; - if (separator_pos >= 1) { + list_for_each(pos, trailers) { + item = list_entry(pos, struct trailer_item, list); + if (item->token) { struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; + strbuf_addstr(&tok, item->token); + strbuf_addstr(&val, item->value); - parse_trailer(&tok, &val, NULL, trailer, separator_pos); if (!opts->filter || opts->filter(&tok, opts->filter_data)) { if (opts->unfold) unfold_value(&val); @@ -1127,13 +1127,12 @@ static void format_trailer_info(const struct process_trailer_options *opts, if (opts->separator && out->len != origlen) { strbuf_addbuf(out, opts->separator); } - strbuf_addstr(out, trailer); + strbuf_addstr(out, item->value); if (opts->separator) { strbuf_rtrim(out); } } } - } void format_trailers_from_commit(const struct process_trailer_options *opts, @@ -1152,7 +1151,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, strbuf_add(out, msg + info.trailer_block_start, info.trailer_block_end - info.trailer_block_start); } else - format_trailer_info(opts, &info, out); + format_trailer_info(opts, &trailers, out); free_trailers(&trailers); trailer_info_release(&info); From patchwork Tue Feb 6 05:12:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546645 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 06EE77D3F2 for ; Tue, 6 Feb 2024 05:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196364; cv=none; b=ja4qMPcyK7QZmVaUtyC30Z8xNyTAhDZJLk5k7higwNjokpJaOldGdMGjdUCpzQD9ZYUlVFWZg+k/taeGb7PHzl2J1X3fKXp3YeRW1dQfZ11Q9at2TQkUimzuytJJbRWZZXe91uKwjpFhHszzveLZI5U9l8KcpxQ5izG4K6bJ5eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196364; c=relaxed/simple; bh=hFYWqf/eNtAVR2xBEDUlIu9gKkRnsIbQ80K31A2J3Nk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=DD5C0DcFpeSqYufZk7Fst5GstrBFwFCVCSvo9785f9/5si8V7EncEVDnujQ5jjyGYdANMXaK598A/GdXrt476KJjxk9hRQioOTxITUiu9DzUyMaJ63jWakLbGhuSZHQ5kN5vIifs7qk6bxL0ax9iASHyEYntJ9s9NzjqxqaaV9A= 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=HQJ+ob0X; arc=none smtp.client-ip=209.85.221.44 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="HQJ+ob0X" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-33b409fc4aeso952851f8f.1 for ; Mon, 05 Feb 2024 21:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196361; x=1707801161; 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=bu3C6QYFVde3gn9amt7IKrmgfKcfRFijD1kT5Q6lcwI=; b=HQJ+ob0XQlSyagPpsLP3cQebLgvttWz/8jt157ZKzD23ef4PEE5aBfnvmh5wC9k2JU +isSog1IQOyp8z89QQeF9tE6y3/3n/L8RYD0E8KOjuj8FH7TIO7MdYUhwwK+BBcxPhzo FWlLBLfSl+1o4b8LWNba4G9WIAgBGUW8554LZOC1lcJngoso33GlgnzdEhHfA9QJDIU7 Ml1Jn9sXr097xEMAi9LoQdxO0/bg/114HVit+jMnSaYEHuGf9mHP5Sgji1i4nAuhSUnC stQ0/Lhte30fcHZYD5aAtOZo7tKhoagDacmH3Ldk4f8FEwvPKJ/OEZvJ9tf6Le7dJ2l4 o4Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196361; x=1707801161; 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=bu3C6QYFVde3gn9amt7IKrmgfKcfRFijD1kT5Q6lcwI=; b=npKywFojWt8vqTxnEi/TRO4/eB493G78NSzjps6ZaUg6RoCzXpOwsZfcXuF17gnRES /g0bGd2A2hI1WLD6E1i198vOCy+A7dgcVyR1ZZjg5YIYPLy6egDKY5exhE/C4kJfCjIq UOIh82ZrZP5UofW25x24tqalKs52K6iOFtvN6DZemjmi24pEDEem1Gp+LtMv7qTJlOda mLIJLgTB9Z8KzGVOX3EQnaQYo71sLKOA26z+m9G4lfHI0fOi6EkypULrqp7bppu1aQXp x0FnZB5/Oj6taqHpf8jh7ANkSDVC52gGrWK0moXM5vjRHmRp8mRfY9kJnu3Kf5VXBf+e +Fmw== X-Gm-Message-State: AOJu0YzdpLcbfxw/nP5oR/WmIqZovEtMWKOvdrtWtIPvUCUH4CJkfNAr 3UKtMqrUi79f44UNZVqf+A/oD49NETcUyojhUxvIj0WI2n+diGv2PtYYZ/K2 X-Google-Smtp-Source: AGHT+IHGFk9hlSWq8mmWafuCoN6q0DsXd/QPQNk7OOp1wN9Nw1mNNOInDC69n3Y23PSuHkNujFWBCA== X-Received: by 2002:adf:fecf:0:b0:33b:3ad8:22c5 with SMTP id q15-20020adffecf000000b0033b3ad822c5mr368128wrs.68.1707196360899; Mon, 05 Feb 2024 21:12:40 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWAITre0R28baAOmBVLmmvaqdQktV/5wURO0rKgAHNRouKUp7eQNN395PaVBfYHlU3YOKq83RnAkFqb2Kri54evyjkQ/CjP3Kld7q0JBIF/ojyllb3wJU/Pom/ZsWwOvrpU0gVBaV/dVEPVZNprYu8dpw81ep1NzO58ly8OW/4BET9r5CI9dKAgSDLnliDuIDPiTgpt3X2Q7Q== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q12-20020adff78c000000b0033ae4df3cf4sm1060630wrp.40.2024.02.05.21.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:40 -0800 (PST) Message-ID: <457f2a839d5da9da225e842275bbf8b15f194f1f.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:11 +0000 Subject: [PATCH v4 11/28] format_trailer_info(): drop redundant unfold_value() 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is another preparatory refactor to unify the trailer formatters. In the last patch we made format_trailer_info() use trailer_item objects instead of the "trailers" string array. This means that the call to unfold_value() here is redundant because the trailer_item objects are already unfolded in parse_trailers() which is a dependency of our caller, format_trailers_from_commit(). Remove the redundant call. Signed-off-by: Linus Arver --- trailer.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/trailer.c b/trailer.c index 6333dfe1c11..12cae5b73d2 100644 --- a/trailer.c +++ b/trailer.c @@ -1102,9 +1102,6 @@ static void format_trailer_info(const struct process_trailer_options *opts, strbuf_addstr(&val, item->value); if (!opts->filter || opts->filter(&tok, opts->filter_data)) { - if (opts->unfold) - unfold_value(&val); - if (opts->separator && out->len != origlen) strbuf_addbuf(out, opts->separator); if (!opts->value_only) From patchwork Tue Feb 6 05:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546646 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 5B74E745E6 for ; Tue, 6 Feb 2024 05:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196365; cv=none; b=NvqUuCo60q+wDfE7nPCC3uNITGWcdk8v3h3YhqM6y4cjy4vubaVrIwar2X11Mj7JTxuF7oNWomM5uVdZNUXZvxsAThMjqzgXrw1NmDWAyB8gXndkaQG6PwWKj1Kjz1VtYOvILUa3mg1admPTM1Q0eC5bj1ipKq/eUuy7jW2zZjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196365; c=relaxed/simple; bh=MAUZuXKcVV+ZwGP6aGQG2JUwVo4pOZNJXxi299Qu5Eo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=kWDFByeypgBQsoD+dBIi8Q8N/o6jWtSZxLe7QmKKbXgUGuoqq03Dgl9QQSRpZ/k4DNjs0HU17rWgGY+bfw9X5/xFUaawzQk3o18HH5vr+WqKz16lIWIjM/LIIjm8Ezuiaaadx6OyveWD7omoBjvCBX7DTwMP3jHwgWxGxp+gt2o= 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=SeAayx6r; arc=none smtp.client-ip=209.85.128.44 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="SeAayx6r" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-40fe282b8e2so1987125e9.2 for ; Mon, 05 Feb 2024 21:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196361; x=1707801161; 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=/k8UYAywJQQ83aTCDk0e2w+uJAEUxmObItRX55s2ycs=; b=SeAayx6rS0zl0/lPzg6WBcnjc9wJwquavdKstG1UihqK5v0zXcn2mpJM6c9tAdPB4F Mtqah0fgg6l6/E7fKxu1da/vzE7gztfPvJAfnEh3qs1HMxqWuxb+KHkD0gx5XvMwpQC/ IgfsxRA1y+xEP87SDxcMU4Leb7XahBEZiXfSgqsZrpVzeVsXL0Es+Z0Hpj2n6PfoGdr6 bQdyygoMA5wEamv0iCrPxj8HFS42YAalC0sHpNhkGddahMNjsAPBxTaWfs5jof6npssI c9RDN37k0ZpQXHTEm33wGhHy/jIvLqYzMjgUBBp+duCAMxmd++CmNPtgj5PAAL0dbMLB glNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196361; x=1707801161; 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=/k8UYAywJQQ83aTCDk0e2w+uJAEUxmObItRX55s2ycs=; b=GFcooKBRAvGKPisHotDeeUk00gpeX2TIXoT16fj2aD8/ZXxPF7/UpRLeF253PRkfae hr+nucrFK0hhGH0f+sBZTx/gih9ALtPinrvbR6AXvfFgYr9YXC/PnvzfKQIrESAyt0BB v8A52baoBed1PDVKmkzPMrVUC9PMBtqAJCUeE2ubbTigot2DW+jjPbfNHTKnZWheG0ua yrzLmGimL8DeydW6VWw0L9eU8s/lwET90zYwdKVyzc4dtavt/tokr10vhkrmFk4MiiYy Wzs0r62KXr5hN9oQoVvcJqzYqygplNLc72lvNAKEVPmHfrtZsgHfAvHdMHI1KTafE2Mr LjCQ== X-Gm-Message-State: AOJu0Ywh5VHkl5E/+v4y265m3fgYo+MjF7gSYtnyHBwg2DYQRw4Lx+f7 +2tgFfPRi5h4htnrTBUJUX92FgfsZUo5ueiRIQFI1g5nz7dSiKP4599FUDby X-Google-Smtp-Source: AGHT+IFKgA9VYjXrVrEhTxJcJ6m+TqsDwQeyK+do8lI6Lsh/Y3i9tyaGiyanA6oCTjCBE9u9e+Z/DA== X-Received: by 2002:a05:600c:354b:b0:40e:befe:37f3 with SMTP id i11-20020a05600c354b00b0040ebefe37f3mr826076wmq.4.1707196361370; Mon, 05 Feb 2024 21:12:41 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWKtZj5yJn0X+So1aRdSahTDUu92KmwLqUq6kN3Q75nGaKm167ELzrmaJUdOnDEBwpuWITZJPbSNh6on07hWaH1cA+GJLdlQjxEs8wBUKqnRiBFRDeKNnakaRVwZB/YIvy7f8cpdd9f1gwPeQKr9DB6xVItpVHy8D0vOv3dpyJZ+uZPDojXTOv5GiwSYT8p3M1QnPpARxsSJg== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o27-20020a05600c511b00b0040fdb244485sm640761wms.40.2024.02.05.21.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:41 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:12 +0000 Subject: [PATCH v4 12/28] format_trailer_info(): append newline for non-trailer lines 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This wraps up the preparatory refactors to unify the trailer formatters. Two patches ago we made format_trailer_info() use trailer_item objects instead of the "trailers" string array. The strings in the array include trailing newlines, because the string array is split up with trailer_lines = strbuf_split_buf(str + trailer_block_start, end_of_log_message - trailer_block_start, '\n', 0); in trailer_info_get() and strbuf_split_buf() includes the terminator (in this case the newline character '\n') for each split-up substring. And before we made the transition to use trailer_item objects for it, format_trailer_info() called parse_trailer() (which trims newlines) for trailer lines but did _not_ call parse_trailer() for non-trailer lines. So for trailer lines it had to add back the trimmed newline like this if (!opts->separator) strbuf_addch(out, '\n'); But for non-trailer lines it didn't have to add back the newline because it could just reuse same string in the "trailers" string array (which again, already included the trailing newline). Now that format_trailer_info() uses trailer_item objects for all cases, it can't rely on "trailers" string array anymore. And so it must be taught to add a newline back when printing non-trailer lines, just like it already does for trailer lines. Do so now. The test suite passes again, so format_trailer_info() is in better shape supersede format_trailers(), which we'll do in the next patch. Signed-off-by: Linus Arver --- trailer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trailer.c b/trailer.c index 12cae5b73d2..0774a544c4f 100644 --- a/trailer.c +++ b/trailer.c @@ -1125,9 +1125,10 @@ static void format_trailer_info(const struct process_trailer_options *opts, strbuf_addbuf(out, opts->separator); } strbuf_addstr(out, item->value); - if (opts->separator) { + if (opts->separator) strbuf_rtrim(out); - } + else + strbuf_addch(out, '\n'); } } } From patchwork Tue Feb 6 05:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546647 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 4607F7E110 for ; Tue, 6 Feb 2024 05:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196366; cv=none; b=DI0oHzy6WOOrj7wjS1y5qKAw8kaCHJvnC0vGQiwWvE25RZQDSUfCX20xngOgGZJ/fnPFh09erZzfnbqS1arsRRwRsJrggXQsC5aWCiDt/BnKwynkt+qVd9mKPqjEsX2Wfwq1KwpC4YWFRNDryP5UMc2PpNyN4H4Teui47TwYEaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196366; c=relaxed/simple; bh=ux9G7jdICdkTx6s80B42U9sW2MuPWuHpMMUNYcISqgQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=pUgw6VJSRBChyzxUf8x/PIf0a2zdmusl+zHD82VHEz/CIpfL0dbttk7pAH3pqP+BaWeFS3g/LBQ/58FqcBShTms4aFBzYWkDClfQ5jg7oBmff+uKYlQLjaQJzHqQVxQDHMmwQGM1yQHP8328Sb4n33Q/KpowGlfaiOp6I+9C7Z8= 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=j4IIJqxZ; arc=none smtp.client-ip=209.85.128.45 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="j4IIJqxZ" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fb3b5893eso42221705e9.0 for ; Mon, 05 Feb 2024 21:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196362; x=1707801162; 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=Eu8VZfWN0T7GOuc0qSL8pko+jJUToSbuTDb/wyxAQqE=; b=j4IIJqxZ9NyuRIhx7NfMCIxDeuO/xANOd8bBiyfriBuM7ZLEVFQ9zXol2JKiBqdHtL LbkfGnlUCL59IspuKNWph89DMuonpHgwpuwaqcdifzQCKdPfpXI4VtxEvx8xHCy54TTD eg1kFryko6nEHwK4375NXfpXMtpCkySYQjPnPe+/SfpBvaDWaQm4jd2Ke+kxSAtIeZaN qoqqAFge8PmL2wln1QMFJQdkbomjgUqAVW2vJQI/znNcnO5NQ+L1jClZHwTvuqvGIeNS I8eardAn6AakqnQCcmVIoDFYPUNajF+Hrw/hzXyPsz0e1oZ/4gbYq/dRo+kSC90NgrRW 2Ayw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196362; x=1707801162; 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=Eu8VZfWN0T7GOuc0qSL8pko+jJUToSbuTDb/wyxAQqE=; b=ry5pEp7H01hGiKGM8AJyyz9P59h3BJ+GhdkNBeSfyKJ9B0i50ojeOt9j7BynK8pGuB rKMc6Nn5Mrh2kSpDqs/KbJyVgORuhtfddoPxJby9hTpJAAAq8IofbftuBHmhekSz6ePu gD57yOmVmVAAelIQ0lHp35OI0HAL05qPldgjggh5/YnfCuAQifuSJKlRUZXuPb3KqZ5S Rp/tjeAMKeE/tGFIDFJjhUVIdWPsBlS8Eypi5zbXArY5fvCPYZwWwbrnFnBebpaT9V9B JRyyX7YvMdyCRY9PTCkN1y3QpqlcB4M0gd/mHwZAjgwje5IXhSftXt9qGaNt2grRRyxy vBdw== X-Gm-Message-State: AOJu0YzmKPwJQW4bS+cxMttFn/DfZX6EYPFjGpBFu+98zLdfKzEzyLz/ niVoTZsXnIUyVGz5aiCA2IFHVL+zlPNm61iyXwoe+hexv4yDPY8a5W8h8UMK X-Google-Smtp-Source: AGHT+IGqHmVrC0t8bWe2AqbF3qj/0K9pZshwr6FWcMUWPNKm5IzPIKRQdq4vtReXVmWDgznTnwCBaw== X-Received: by 2002:adf:f690:0:b0:33b:17c5:f25a with SMTP id v16-20020adff690000000b0033b17c5f25amr360566wrp.64.1707196362071; Mon, 05 Feb 2024 21:12:42 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUcFz0M/zC8l5ROa7Cn46+ZKvH1OtZ1ppwUUjP0HjolA1OP/E3LsAh/fC3G7AmzPlxgaUKIGBm+OOXymmiqe1kT4/CQGhTXMra+WzcHemg4jRaOihGL6fPlIfJfSzwhPybZq7vVpHtWe2C2Q7m5mxJpHNVuijtX1EumussxIYpmGOuo7jeubvxQQIqnX1KSVgU0D/tCy82tTA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z2-20020a5d6542000000b0033b35da3842sm1057792wrv.28.2024.02.05.21.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:41 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:13 +0000 Subject: [PATCH v4 13/28] trailer: begin 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Now that the preparatory refactors are over, we can replace the call to format_trailers() in interpret-trailers with format_trailer_info(). This unifies the trailer formatting machinery, but at the cost of breaking tests. More specifically, this patch breaks t7502 and t7513, but only because we haven't fully stolen the features present in format_trailers() (which knows about opts->trim_empty) and print_tok_val() (which has non-hardcoded printing of the separator and space). We will teach format_trailer_info() these features in the next two patches to make all tests pass again. Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 2 +- trailer.c | 12 ++++++------ trailer.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 11f4ce9e4a2..f57af0db37b 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -171,7 +171,7 @@ static void interpret_trailers(const struct process_trailer_options *opts, } /* Print trailer block. */ - format_trailers(opts, &head, &trailer_block); + format_trailer_info(opts, &head, &trailer_block); free_trailers(&head); fwrite(trailer_block.buf, 1, trailer_block.len, outfile); strbuf_release(&trailer_block); diff --git a/trailer.c b/trailer.c index 0774a544c4f..f4defad3dae 100644 --- a/trailer.c +++ b/trailer.c @@ -162,9 +162,9 @@ static void print_tok_val(struct strbuf *out, const char *tok, const char *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, - struct strbuf *out) +static void format_trailers(const struct process_trailer_options *opts, + struct list_head *trailers, + struct strbuf *out) { struct list_head *pos; struct trailer_item *item; @@ -1085,9 +1085,9 @@ void trailer_info_release(struct trailer_info *info) free(info->trailers); } -static void format_trailer_info(const struct process_trailer_options *opts, - struct list_head *trailers, - struct strbuf *out) +void format_trailer_info(const struct process_trailer_options *opts, + struct list_head *trailers, + struct strbuf *out) { size_t origlen = out->len; struct list_head *pos; diff --git a/trailer.h b/trailer.h index 1d106b6dd40..3c13006a4c1 100644 --- a/trailer.h +++ b/trailer.h @@ -101,7 +101,7 @@ void trailer_info_get(const struct process_trailer_options *, void trailer_info_release(struct trailer_info *info); void trailer_config_init(void); -void format_trailers(const struct process_trailer_options *, +void format_trailer_info(const struct process_trailer_options *, struct list_head *trailers, struct strbuf *out); void free_trailers(struct list_head *); From patchwork Tue Feb 6 05:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546648 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 5B3A47E574 for ; Tue, 6 Feb 2024 05:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196366; cv=none; b=m9cCsB8aeYq7yp33lyPnpWRCPu47S8V9sSuqYiYweOBtdIsuFbU6edCF+EZXdxpIRNqd8sILjNUKgxYozC/IvSpHKK0whrb/WLNwU3GUEyGpY2BO3sWz4C/w/nypQAcGpaD3afR2QJE+f5S7VqTtMDBQRZ4DQEl38/MM/6sdlkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196366; c=relaxed/simple; bh=xg9DmrlP8CZiA29lppB385p+cV6w4th3X+6z9RyxKVw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=oMtlhmSEtOHPvYmfjrIveGA5xB70Dq8tcNZ9g2z5k88GyKtg92oe4ogjI6IrUKTnVgAa+G4Yhfq8yzWSRYICXZnXMDUN8eTgR8FO5PaISgzESOWof++/Kd+mwq2dSBBIt919Ok3l1vXCl5TcDlOYTZ+6jM8E06kAFg2s3yoFoQ4= 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=Y0ef1FKB; arc=none smtp.client-ip=209.85.221.41 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="Y0ef1FKB" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33b0f36b808so3357292f8f.3 for ; Mon, 05 Feb 2024 21:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196363; x=1707801163; 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=xS9QkJvX6g6toL4d2+AnC/AfdgHX48SvVCnk6yON2dk=; b=Y0ef1FKB0jqUkJUCTL8b+6tWU3DOQ76taAJEOM4ebXf9RxWkXTNPXvHRFKcDy4YyMe uoZnokp7jEYyCwkSeqq7SIM7CjRuWL2N0Sm+dM5E0r5GSxkNraaCEkj9f/JaOJKiDQAz 91JuGXSbk0IGCWiY2U0JwWnJ8KSKFDg8cL0DWbFoxeHB2ENrQWpuAa8/UtJzzkxwD1O1 l+hfWL6kY6l+CSa8jUXyrgutQGogNwUN9Ht5vEccdjpiWiwSrNaQLiqL7Mlha6x/l9rj aDsFNpYZjwlR4DuN+zqkNv0RBdT6RVAp3+uEyROE33AeEYqIkmXO6cLFQjROyi6be69f HNOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196363; x=1707801163; 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=xS9QkJvX6g6toL4d2+AnC/AfdgHX48SvVCnk6yON2dk=; b=VbT33/ZnMVnQRNr33XteWERT1A6FOByjdBNn3ZCXePlBoT1NJ97QWRD8vgWLT9ajxU 01lBRwLrAwAvYMumA1LmpiITBLCMNplLRXC+Ap+oxSwgJPuLoXVjh57y7bJb4el/hjgp oy5eQ1KtlX9RMaaDRMz5O4ax9t/0S+JUtiKuRrppMsG0js6MHvaFkTdulACr5X2tXg9q UA4N7TNFZ5KM9sRJ5XPNznmBpzLJwrhdp4yiFMmSyHpXmlIEnBBp8oQXnqRIKtavKZ3Z fjKuMVcdQHXLOv4arDigYYjoyepdhX/LAA2s2wlRjw7r/ruRpozq8fmlFRikeQoyUjyH gsNw== X-Gm-Message-State: AOJu0YyUAaQxZ/Cr2BueqZOT3++B8nABxYClezktcYkY5H1f1+LFXj36 SYLoYC7yjGNSPDpWFgozfP8V/28TUE4V6TLc3pKzp8DPrOw2QGBLLgQG66YF X-Google-Smtp-Source: AGHT+IHM1UYfv0rm+O0/ypxNyT5o5LwAuQpCQBx40cv+a4HLV4qlhYtAHCvBFpgJFjlbH5fam7evKg== X-Received: by 2002:a05:6000:184a:b0:33b:3559:2815 with SMTP id c10-20020a056000184a00b0033b35592815mr482312wri.0.1707196363164; Mon, 05 Feb 2024 21:12:43 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUdOy7TQkpFtOEz2FteLj10aj3VG42u3nqvrYQYC9KH5+U+6MB4eaOal0vZNNdX60b7ybSLIrNzwFV/rMjAMXK76kevj1e4lRqDIff//FcRRbgLpVjKJRxp9P4FZXIm8FsGsrje62hXT1h9d1Fb5ka3janACfDsFEmnmIO0dCdRrHOpYf2nVFo/1HreTq5asudws2q8zm1+Ow== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u21-20020a05600c139500b0040e813f1f31sm645646wmf.25.2024.02.05.21.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:42 -0800 (PST) Message-ID: <11f854399db2b0da5d82cad910c3b86ca9c2e0db.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:14 +0000 Subject: [PATCH v4 14/28] format_trailer_info(): teach it about opts->trim_empty 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This fixes 4 tests in t7513 to go from t7513-interpret-trailers.sh (Wstat: 256 (exited 1) Tests: 94 Failed: 55) Failed tests: 2-5, 8, 14, 24-28, 31-37, 43-62, 66-74 77-80, 82-85 to t7513-interpret-trailers.sh (Wstat: 256 (exited 1) Tests: 94 Failed: 51) Failed tests: 2-5, 14, 24-28, 31-32, 36-37, 43-62, 66-74 77-80, 82-85 . The next patch will fix the remaining broken test cases in t7513 and t7502. Even though the next patch fixes the vast majority of these test cases, we have to position that patch after this one to avoid breaking the build because of the way these patches delete relevant (and obsolete) code. Signed-off-by: Linus Arver --- trailer.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/trailer.c b/trailer.c index f4defad3dae..c28b6c11cc5 100644 --- a/trailer.c +++ b/trailer.c @@ -162,20 +162,6 @@ static void print_tok_val(struct strbuf *out, const char *tok, const char *val) strbuf_addf(out, "%s%c %s\n", tok, separators[0], val); } -static void format_trailers(const struct process_trailer_options *opts, - struct list_head *trailers, - struct strbuf *out) -{ - struct list_head *pos; - struct trailer_item *item; - 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)) - print_tok_val(out, item->token, item->value); - } -} - static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok) { struct trailer_item *new_item = xcalloc(1, sizeof(*new_item)); @@ -1101,6 +1087,15 @@ void format_trailer_info(const struct process_trailer_options *opts, strbuf_addstr(&tok, item->token); strbuf_addstr(&val, item->value); + /* + * Skip key/value pairs where the value was empty. This + * can happen from trailers specified without a + * separator, like `--trailer "Reviewed-by"` (no + * corresponding value). + */ + if (opts->trim_empty && !strlen(item->value)) + continue; + if (!opts->filter || opts->filter(&tok, opts->filter_data)) { if (opts->separator && out->len != origlen) strbuf_addbuf(out, opts->separator); From patchwork Tue Feb 6 05:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546649 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 9BE4B745E6 for ; Tue, 6 Feb 2024 05:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196368; cv=none; b=cECx6l6LZIeYYnpg/uozb0O38EUEsiZ3LQXn8W+xcp0HaC8a6FEnPk1y6uy0XbCXm8XTN3xF/c3DhsevXXwY0gkoo3L6KDB2lkLuzrHGWNNvGWH9wM6Tv4tZYWBj9fVcZe9gdhn/Fx/BtomgqGaY/ym0QmfhuQO+z2fPGFWJZ4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196368; c=relaxed/simple; bh=X8jODAoXyhVFsxb2e0JL8oWln9j8Q7N31oMJJSNpMto=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=tKHYlNykupmyCyYtt74aKEADcbf3WFGcaUN/NfQVarIXesYaHZfXZ5cjQ65uFKfO6w4utp9xaXVlSxdcxIXvtuzUsDhOqKOZ5MiX7ED6pSF9Cdj/yUQHrXUvYQqbWnX2H6kpIgKwRlUNP/BTuOVEiXLS1JZMIb+7BqhOqr916yc= 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=V5Vjaids; arc=none smtp.client-ip=209.85.128.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="V5Vjaids" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40fdffc3831so5986575e9.1 for ; Mon, 05 Feb 2024 21:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196364; x=1707801164; 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=bgfULWLl0d1IFcFtlIoerafH18ezJHxLxJaAx6L9xXs=; b=V5VjaidsAMbthNYskMiPKbcntnlbodJecNx6mRkOenDXfRxafbwS3/ST/2oqMbo/kh uBvfX9eCtFdDFgJqZQHf7iLqeKavuPQQlE10qI1T5m2rK7fxAQMyFI/NGUQpa9LjUeSx pYBNH8bToaiQUzDxQt3Ea/3GmXysv0lWK5nBDT3afhLVwX+GxQfGYX7iylK4k/sdk7yL stuRKp/KNIjekEMVCPIqRa9uL96S14vOADr/RyU/brJFdk+LnLHzXblqMGcvJyi0iAQp tfnIAu4lnE2RtU/rlKuVQrEmDw5REdWVayZxInE4dQBAZuALXS3kx/z0I76zhcJf8Ats Acjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196364; x=1707801164; 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=bgfULWLl0d1IFcFtlIoerafH18ezJHxLxJaAx6L9xXs=; b=t+3BW6nam7LfxYfSILTZQgmVyPKJ7Yu/RItJCvPWNn7H0/t2wj9SpPhkX0qqWZkgwm Bgv0/I+4a04wtPIJsAfSAQEWV/yRIGHLdTqGPJTFV27DORLz/BOFfBHb8sznMlu8OWW3 83gFSQLh0mvx9lgxm+SCtnRhJ1gCFQGkAbi9b4BfkBCvQcOAyf2uzhXkpup+NdJZ+bON enrzE2xsn3RiYrHxyTdJkL9FfrrufkfLWzQxbd9dlO+NOw60J7yVtBH5ZwBLMdIqYTMH 5NmJjjzy8KVaQ3QySzqE16FAJiTPOy4Q8+NnnZ9twL/jy+3Q+vrQEBfiwuTBj05r7bB3 Sdtg== X-Gm-Message-State: AOJu0Yw/W/d4uPoKN2YGWYDa5AmYO/xR2/Kqh3zwqVGICA1GeNwqMIWe VgrYlo5Dus216f0WC1nlvDsG3/3eDtQBxgcKisV6kM3290qFYJ20r9lq+rgy X-Google-Smtp-Source: AGHT+IGEGb9eWqcTp21oGu8EnbB2uCqbHNgXyLkZl0JSySl7lfwW5nsPF2JrzIJkpjeeal77yQzXTA== X-Received: by 2002:a05:600c:5254:b0:40f:d2f7:6e34 with SMTP id fc20-20020a05600c525400b0040fd2f76e34mr1128878wmb.33.1707196364228; Mon, 05 Feb 2024 21:12:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVU3OEku8Iam3UD1m3UjjUROfGH9VOv62KvUFZW9LYjSfUns5v3daUMqY8/Pki5Ky1Qfy/Brkv/evjJuSrvEoYuWPi5nxb1Xd0aPGoPxP2hfWLc0Vm2ym59qsR3hQTx51V2b7JMPdPi28sLVM4mIM8yISkzvO1Y046jIVDbRcaA+JYbNNqXfwqSpUe1uEdZwKvO8/MkXSrLeA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m7-20020a05600c4f4700b0040efb445698sm657196wmq.5.2024.02.05.21.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:43 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:15 +0000 Subject: [PATCH v4 15/28] format_trailer_info(): avoid double-printing the separator 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Do not hardcode the printing of ": " as the separator and space (which can result in double-printing these characters); instead only print the separator and space if we cannot find any recognized separator somewhere in the key (yes, keys may have a trailing separator in it --- we will eventually fix this design but not now). Do so by copying the code out of print_tok_val(), and deleting the same function. The test suite passes again with this change. Signed-off-by: Linus Arver --- trailer.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/trailer.c b/trailer.c index c28b6c11cc5..5c42a19943a 100644 --- a/trailer.c +++ b/trailer.c @@ -144,24 +144,6 @@ static char last_non_space_char(const char *s) return '\0'; } -static void print_tok_val(struct strbuf *out, const char *tok, const char *val) -{ - char c; - - if (!tok) { - strbuf_addf(out, "%s\n", val); - return; - } - - c = last_non_space_char(tok); - if (!c) - return; - if (strchr(separators, c)) - strbuf_addf(out, "%s%s\n", tok, val); - else - strbuf_addf(out, "%s%c %s\n", tok, separators[0], val); -} - static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok) { struct trailer_item *new_item = xcalloc(1, sizeof(*new_item)); @@ -1104,8 +1086,11 @@ void format_trailer_info(const struct process_trailer_options *opts, if (!opts->key_only && !opts->value_only) { if (opts->key_value_separator) strbuf_addbuf(out, opts->key_value_separator); - else - strbuf_addstr(out, ": "); + else { + char c = last_non_space_char(tok.buf); + if (c && !strchr(separators, c)) + strbuf_addf(out, "%c ", separators[0]); + } } if (!opts->key_only) strbuf_addbuf(out, &val); From patchwork Tue Feb 6 05:12:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546650 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 C66017E59C for ; Tue, 6 Feb 2024 05:12:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196369; cv=none; b=P2OwR1IV1xW6zMM8rO9au0So0sFgBDUh/bESZqCWnwHJ1xIvMZZIFJrB4Ca+5X+URpl3peljWe/IxR1nYj45qYvGXIBYwHn28AeEyPHO2+BuEsZJWXFTGbBqKgLlyr/iMSKz14qwj5TsSdxyNOqZIZigbCLrWHteITcEqYyUjeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196369; c=relaxed/simple; bh=3QBod3B1n038BlgbObVjc68fbhnSBc9pvZJY+URzakc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=sdh1U2iqdqQXqSuSMefhXOEEdwz7AprFvhHwEGtj/DPRLGZfcppCY3Od7g/8rU/JZD3GEjqri+BRLP0kzAGyAujrTCtkZeq3cTWR2UNaaa1HY4Gg0Bt9hdUB/RgUqGlySinLe4SG0HHKIcjSLAbbkUj5weBq9ncvm3DTLkuL8vw= 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=OywSLDyr; arc=none smtp.client-ip=209.85.221.44 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="OywSLDyr" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-33929364bdaso3190000f8f.2 for ; Mon, 05 Feb 2024 21:12:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196365; x=1707801165; 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=7Du40f09+tzKNtNcLoTuwc85Ub2+RD+11x9pcKQ3b0s=; b=OywSLDyrD67vRUkavhYnNR7vMIq20YpJrI3FLPoCgpEl6XaoY3Df+Er5XLiTR8P9Ib FXbvAx5UuySlqTDaW+kQWj3UN3piQtVXuZT+tlheRsPDjmlJIqW0vOseAo3uAu9nVC4y F0VdeEqGMMLDEkT/tyCfbyyXxfhnH3R8cFcHlmwGS8y5CmDgYisNirkVbdJ/2zmeYpvp RH0gXwHLkkjViFk5Gfr7+GzLJmWMewRFh+YHnDCuZr3gHYSHeDslu+MxgEuZOsDhHoIv cE0UeD2RpSqjyK5Fd3JTkiQO3KgGdoDiyIaFAhYOtHyNVRtHH88Bj8sffYy90TOQBRBu dN/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196365; x=1707801165; 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=7Du40f09+tzKNtNcLoTuwc85Ub2+RD+11x9pcKQ3b0s=; b=I2jZQcK8dO+P1soULfq1wkk9aRI5RqbKNxeqBalnQBRNSQ1czXTaE4FrEdcNiU9/Wa XUXk3uW0iCrHGvkScJiI1DM+Se8Ulwh0sXneJoQdAszdVfL3TCba3inB2mr/cemZPJOb gIgUZ8uD/4WTV9PrcVLJiPrEClnc/phItlvmbNInbw/ftHVDwgiv190Ab+/njaNo5A6c LAakEH0tQI0byEaonbmwVVXZ+h7khWGhbbmiwgqOanU/CfOs8tyDU17HRe7gBTadF+MZ UxNJqcp2JdIZNGyV7MvtMSz6GPiEtWyeChF25+CkFUkkoP3C+nm9hGOlAItlLaswOgZ0 T8og== X-Gm-Message-State: AOJu0YzenJyRJ28s7zn12O0ANjGFxYCvMlfb60rpjzBXP2FW9xV5wyMY KaqihEdddqgNnD4aIDHENSkzUujF5nMCPZFdGqr47zOG92LGRi+0w2An1gU9 X-Google-Smtp-Source: AGHT+IE2Z6skIl75ogNSpgizdfPn0xqGzE74huSLGWrOVxhD7vXUBFAi5id+TGci+1bzvVxwyLGnEg== X-Received: by 2002:adf:cc85:0:b0:33b:3773:d93b with SMTP id p5-20020adfcc85000000b0033b3773d93bmr357257wrj.46.1707196365446; Mon, 05 Feb 2024 21:12:45 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXm+gDs+jqRbcQvjvvIwb52s5iRADZCNk5r2VaTlNPfGSTbNaJdi1hyR4eP+789xqqmow9yG7AyPALuAIBBEG3DakfuRiVzksq2lBZfvczoCUi30D5OnvtXlUcKUDRsN6BWNT0THeFCw/W2r6tiL48+A2UwFlrNCP4fBepZO9xH3CVArJ/AmkB0wwyOA97yrN510arP8mhO3g== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4-20020a05600c1d8400b0040fe930b52esm17167wms.9.2024.02.05.21.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:44 -0800 (PST) Message-ID: <31725832224e3d6b14066af8a87eaf4ab589179e.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:16 +0000 Subject: [PATCH v4 16/28] trailer: finish 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Rename format_trailer_info() to format_trailers(). Finally, both interpret-trailers and format_trailers_from_commit() can call "format_trailers()"! Update the comment in to remove the (now obsolete) caveats about format_trailers_from_commit(). Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 2 +- trailer.c | 8 ++++---- trailer.h | 15 ++++----------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index f57af0db37b..11f4ce9e4a2 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -171,7 +171,7 @@ static void interpret_trailers(const struct process_trailer_options *opts, } /* Print trailer block. */ - format_trailer_info(opts, &head, &trailer_block); + format_trailers(opts, &head, &trailer_block); free_trailers(&head); fwrite(trailer_block.buf, 1, trailer_block.len, outfile); strbuf_release(&trailer_block); diff --git a/trailer.c b/trailer.c index 5c42a19943a..4f3318802d1 100644 --- a/trailer.c +++ b/trailer.c @@ -1053,9 +1053,9 @@ void trailer_info_release(struct trailer_info *info) free(info->trailers); } -void format_trailer_info(const struct process_trailer_options *opts, - struct list_head *trailers, - struct strbuf *out) +void format_trailers(const struct process_trailer_options *opts, + struct list_head *trailers, + struct strbuf *out) { size_t origlen = out->len; struct list_head *pos; @@ -1129,7 +1129,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, strbuf_add(out, msg + info.trailer_block_start, info.trailer_block_end - info.trailer_block_start); } else - format_trailer_info(opts, &trailers, out); + format_trailers(opts, &trailers, out); free_trailers(&trailers); trailer_info_release(&info); diff --git a/trailer.h b/trailer.h index 3c13006a4c1..9f42aa75994 100644 --- a/trailer.h +++ b/trailer.h @@ -101,23 +101,16 @@ void trailer_info_get(const struct process_trailer_options *, void trailer_info_release(struct trailer_info *info); void trailer_config_init(void); -void format_trailer_info(const struct process_trailer_options *, +void format_trailers(const struct process_trailer_options *, struct list_head *trailers, struct strbuf *out); void free_trailers(struct list_head *); /* - * Format the trailers from the commit msg "msg" into the strbuf "out". - * Note two caveats about "opts": - * - * - this is primarily a helper for pretty.c, and not - * all of the flags are supported. - * - * - this differs from process_trailers slightly in that we always format - * only the trailer block itself, even if the "only_trailers" option is not - * set. + * Convenience function to format the trailers from the commit msg "msg" into + * the strbuf "out". Reuses format_trailers() internally. */ -void format_trailers_from_commit(const struct process_trailer_options *opts, +void format_trailers_from_commit(const struct process_trailer_options *, const char *msg, struct strbuf *out); From patchwork Tue Feb 6 05:12:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546651 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 7D6C87E764 for ; Tue, 6 Feb 2024 05:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196370; cv=none; b=Qap7NljSxNZ7FxtYhV+hWyeqycD4F7sEBSSbOhtva/8NNYvPlTU65sM7UDcof1hZVrIKVrTuJQ3VGlibBXyMfHNEiQNcnlW3fZ20aHOTdFwuLQU5tXl4e3fukii4haq0XiZXESarlVdyeQFiyS/P282GL0hYnh80wgijjiFqW/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196370; c=relaxed/simple; bh=MEYiwAN/ulo59GN6jIJNn05hE6VFyk9IQhxQU8/XIAo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=V6eUS1NMA1GbICEDNK2I8W1TFEkxADZTtthFk6VTosS21HNEWShlJaslnAPLz6ZpRK9psILFPuLXDZ7O3ihrx0pdPfiGH8DY8J5fJsQ7YuSrbBjDgH98VrQkl64m22xipg9sIwn+BCaL3RGnlwVaq9wGdXdYkW8L/b3OXP8lRVU= 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=DFwkkXWm; arc=none smtp.client-ip=209.85.128.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="DFwkkXWm" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40fe2d3d5cbso1667755e9.2 for ; Mon, 05 Feb 2024 21:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196366; x=1707801166; 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=dA0UYy8RBrNV+cHfrIRf8ezv4EVkB43oJyzX4fmFLIA=; b=DFwkkXWm+/GZaNrASEhYWIgTTCmkCXviZeeGlOTsggnLpepf0m5GqcJNADznFZifWp sd3VgfmE4kfz0RfOi7eh1/0S4WZgaog4QTd6G72p7KWiPeKdwZ87K1gsxYU34X3RBDDh DcJEQbyYvVvafRdvn1XaN35Cqf9j1TL2ZkA/sUnyo8NYWPifEs59RgvO0biJpHSnwDTw KAEHi6o8gYWsP8hFtiMgZVwyMG1umlEOEslzhEZPFbGLaUV0qo407hQgOsUrwpvjWg5S 7sgr6QsqcfbCwHicz3RwEP/8GPx6wZd/rodveCqN2TEI0zSmEckKuMsmLbRom41InfDI ZWhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196366; x=1707801166; 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=dA0UYy8RBrNV+cHfrIRf8ezv4EVkB43oJyzX4fmFLIA=; b=QJoPB3HMsMaXIzVl/6yqPCtMsRNLQie620N4xXrvwNrHBWZGyZfiA+JUFYGBjqp+B0 LTi8vPxUl2iK3dp6rvNL7+8EGBLnR3qpjk3xR4exDzuytMUbgWTD+I7z5b78BxwTSeWg Zwx9eKBQcUz7c7+jNS8aqL47bL9D/BT9uf2as8do3/C5/KVouhPToBArAwRnS08h2NSq 9/vTMc+nwlQ7J3rfCEfAyRaaHij53MNnUEebx4cfcP4wsAMsF0+oGhmJ7YyJE+Rfw4x0 fZqZeD17MyW8+eX+ySGYfnbTai1MnbYFoq0d0UsnS3Ht9pKsn+D+fE1D9VYYyN1ilJeR vq6g== X-Gm-Message-State: AOJu0YzflU7QkQML7C2pHbeIoycgjq+XgK19e+HDb52RjP6lcaLw6pe+ e79fu+98Uev5I0AWq7GCACVlOLRJLrwdk3HetvLCeKWmx9QdKmoMXVQADGFC X-Google-Smtp-Source: AGHT+IEQXhcR65PYy9Vz2XPpBmZ+KEa3NjDbS69giMEirMG5bvI0jwvOCqgaoUIHAX2v/jb1vOPy+w== X-Received: by 2002:a05:600c:5109:b0:40e:ac4f:7156 with SMTP id o9-20020a05600c510900b0040eac4f7156mr1308169wms.5.1707196366618; Mon, 05 Feb 2024 21:12:46 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVaJQxhfDHKgxa/LspvwuOnl3bu8rfh80lyP7jVFJiEeOPMPA20IjPN8/I0LqJzxJB7Ml6pGuzyVmCVhY9rD/QfhHZEgbzsX5G4ny9dYr9n3qh9NaWZixWvwrwo/BfygdeZ/sqv/UFXXczTnzqACz7V6j+6+G9wZedK4FY4sTiO5/HgnOWipCOqLIFoUS1fJ8pvud5Mowlunw== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o3-20020a05600c378300b0040fd24653d4sm636290wmr.36.2024.02.05.21.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:45 -0800 (PST) Message-ID: <6f17c022b15479191a1a965d762b6b8a956532e4.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:17 +0000 Subject: [PATCH v4 17/28] trailer: teach iterator about non-trailer lines 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Previously the iterator did not iterate over non-trailer lines. This was somewhat unfortunate, because trailer blocks could have non-trailer lines in them since 146245063e (trailer: allow non-trailers in trailer block, 2016-10-21), which was before the iterator was created in f0939a0eb1 (trailer: add interface for iterating over commit trailers, 2020-09-27). So if trailer API users wanted to iterate over all lines in a trailer block (including non-trailer lines), they could not use the iterator and were forced to use the lower-level trailer_info struct directly (which provides a raw string array that includes all lines in the trailer block). Change the iterator's behavior so that we also iterate over non-trailer lines, instead of skipping over them. The new "raw" member of the iterator allows API users to access previously inaccessible non-trailer lines. Reword the variable "trailer" to just "line" because this variable can now hold both trailer lines _and_ non-trailer lines. The new "raw" member is important because anyone currently not using the iterator is using trailer_info's raw string array directly to access lines to check what the combined key + value looks like. If we didn't provide a "raw" member here, iterator users would have to re-construct the unparsed line by concatenating the key and value back together again --- which places an undue burden for iterator users. The next patch demonstrates the use of the iterator in sequencer.c as an example of where "raw" will be useful, so that it can start using the iterator. For the existing use of the iterator in builtin/shortlog.c, we don't have to change the code there because that code does trailer_iterator_init(&iter, body); while (trailer_iterator_advance(&iter)) { const char *value = iter.val.buf; if (!string_list_has_string(&log->trailers, iter.key.buf)) continue; ... and the if (!string_list_has_string(&log->trailers, iter.key.buf)) condition already skips over non-trailer lines (iter.key.buf is empty for non-trailer lines, making the comparison still work unmodified even with this patch). Signed-off-by: Linus Arver --- trailer.c | 12 +++++------- trailer.h | 8 ++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/trailer.c b/trailer.c index 4f3318802d1..2cc4a910411 100644 --- a/trailer.c +++ b/trailer.c @@ -1147,17 +1147,15 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) int trailer_iterator_advance(struct trailer_iterator *iter) { - while (iter->internal.cur < iter->internal.info.trailer_nr) { - char *trailer = iter->internal.info.trailers[iter->internal.cur++]; - int separator_pos = find_separator(trailer, separators); - - if (separator_pos < 1) - continue; /* not a real trailer */ + if (iter->internal.cur < iter->internal.info.trailer_nr) { + char *line = iter->internal.info.trailers[iter->internal.cur++]; + int separator_pos = find_separator(line, separators); + iter->raw = line; strbuf_reset(&iter->key); strbuf_reset(&iter->val); parse_trailer(&iter->key, &iter->val, NULL, - trailer, separator_pos); + line, separator_pos); /* Always unfold values during iteration. */ unfold_value(&iter->val); return 1; diff --git a/trailer.h b/trailer.h index 9f42aa75994..ebafa3657e4 100644 --- a/trailer.h +++ b/trailer.h @@ -125,6 +125,14 @@ void format_trailers_from_commit(const struct process_trailer_options *, * trailer_iterator_release(&iter); */ struct trailer_iterator { + /* + * Raw line (e.g., "foo: bar baz") before being parsed as a trailer + * key/val pair as part of a trailer block. A trailer block can be + * either 100% trailer lines, or mixed in with non-trailer lines (in + * which case at least 25% must be trailer lines). + */ + const char *raw; + struct strbuf key; struct strbuf val; From patchwork Tue Feb 6 05:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546652 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 C812B7E76A for ; Tue, 6 Feb 2024 05:12:49 +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=1707196371; cv=none; b=J5El6slhrueg5bEn+WL/3o0aVbXSPCmma2CVlj7+wyi6AfPg7XK58bCVH1RFwFsqc2yirzETdEy1wqlqK+h7nffVTz4tWMVf2b3jUnZxRUMMFOI86cudXK5ZyJ2y2PaD+nw1QBs0poospYjm6Fx7rkYaij3Nvz2AjwV36xd1XdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196371; c=relaxed/simple; bh=9hvSa8WrDHCUaihb+X5z+TWaHXI6gtvLgDz/ok8BOjQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=cPW25tscIml0f9sLFK9tn2dXMUPV51ErprLVRAA5pA6OoLQJOVVEFs60qfXD6s/GxrqnQlmgyaoilGBur3YXD4t5132E76RpKu2JAvGyTaFarMZKLEKHil27zy37RNjQayp3tdD5E4g0GXXzMnOQbvJasrVJOfRgbtjJFt++4H4= 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=m3ry4/gr; 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="m3ry4/gr" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40f02b8d176so45266625e9.1 for ; Mon, 05 Feb 2024 21:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196367; x=1707801167; 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=X5Zzk0WUsCLkmxXmChJvEQeJowFe443M24XcTYF5Rvg=; b=m3ry4/gr5FNtJD4uwnNysUgLZJAQiqJBdwvlJk2NWaXWY+gNgWqOpp1y2kIMpUd5cR roD8qHP8UE3ZpTiCV0umZ1hX2KhgUwapANn9RJkt0iWIJ9MeH6yxquTqETXRD6ZRTB6j a+PA8IxpVSJ3hyyONkj3BnAIZRX05cQV6UIP95xHbrIFxZdjElPeVDceD4rU9cvSrCPQ B1GODHPWLNf+mdGPTUAiKpqz7tiR25XF4vAn9+8kaNV1cePxEfzbR6fRFHggy3yvlkPG pVihRnzhfJ3NYQU7cGSz/hVBwauBHJ6RHerzBy6T2ltvUSvj7ottqcVBfMvTS+1hGIQW kOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196367; x=1707801167; 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=X5Zzk0WUsCLkmxXmChJvEQeJowFe443M24XcTYF5Rvg=; b=P96u5MefomSK1IRJcuImit13u2fDltd5tDii8hGFamub7UW0bQQJH98v9TdFqBbwLs H88TDRrIRxZc8Tlo5gkisLQLf1uZrd9sfSWCHnN0MUNYtbYnsph9K5q3YMTVKHFDzYXx dOma7iQtxyPL9zGNcgI/XVHHa7x3kUKHR9BPztwSksRAsY5jOINpiU5LPRvYL1qBGkr3 C+L95wWHTUzyFshgcn9G+hvrgT0PDSgDaLgy/FQSwMC9KazwP1rWU9Ls8ZoJ/XZcSPgL jzamZi726ls8y6ep2/Qf7YSE0MBuvZ1H9T04k59Ctp4FlvdOLnsM6Eq4j+huoHSjqU8/ ZMTg== X-Gm-Message-State: AOJu0YzW9sZQc5GRcNb8qJhCQPRiFSi4apqoAenCfj79bbH9/lZb5hv7 VYVw7oR33VZFaWoUS1RauKV/fSX2Nx/nQ0VvCkXoWTDRyu0e7BiDZKvaWE4O X-Google-Smtp-Source: AGHT+IHo+eviqWNUG8yjz+CzSK96AtTtRoo6nJU85MnXGPaePUbka/x/ZUuZ0oBbL5gMVMgRkks+1A== X-Received: by 2002:a05:600c:4691:b0:40f:d84c:ac68 with SMTP id p17-20020a05600c469100b0040fd84cac68mr1211348wmo.11.1707196367387; Mon, 05 Feb 2024 21:12:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWC1oMhNyi5ZJTkk+6wDpVBwKH/Oebndc0IizUxFHG4/sZm+UsVGeb2ECgf0LyBQo1QKVkzBuSQxqDCMBsZ0HXJhVie4jA6Bsw5JVly4UWWzi1CXbMbdse2h3PANiRnA9gheROeRzrwff2JEuoaI4QghL4nAgqqutgPpTMmDJlLhrr5K58Ri1Hv3GodVmue9x+Htq6kxY5dhQ== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h10-20020a05600c350a00b0040ee0abd8f1sm647987wmq.21.2024.02.05.21.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:46 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:18 +0000 Subject: [PATCH v4 18/28] sequencer: use the trailer iterator 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This patch allows for the removal of "trailer_info_get()" from the trailer.h API, which will be in the next patch. Instead of calling "trailer_info_get()", which is a low-level function in the trailers implementation (trailer.c), call trailer_iterator_advance(), which was specifically designed for public consumption in f0939a0eb1 (trailer: add interface for iterating over commit trailers, 2020-09-27). Avoiding "trailer_info_get()" means we don't have to worry about options like "no_divider" (relevant for parsing trailers). We also don't have to check for things like "info.trailer_start == info.trailer_end" to see whether there were any trailers (instead we can just check to see whether the iterator advanced at all). Note how we have to use "iter.raw" in order to get the same behavior as before when we iterated over the unparsed string array (trailers[]) in trailer_info. Signed-off-by: Linus Arver --- sequencer.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8e199fc8a47..35462a6a9d9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -319,35 +319,32 @@ static const char *get_todo_path(const struct replay_opts *opts) static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob, size_t ignore_footer) { - struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; - struct trailer_info info; - size_t i; + struct trailer_iterator iter; + size_t i = 0; int found_sob = 0, found_sob_last = 0; char saved_char; - opts.no_divider = 1; - if (ignore_footer) { saved_char = sb->buf[sb->len - ignore_footer]; sb->buf[sb->len - ignore_footer] = '\0'; } - trailer_info_get(&opts, sb->buf, &info); + trailer_iterator_init(&iter, sb->buf); if (ignore_footer) sb->buf[sb->len - ignore_footer] = saved_char; - if (info.trailer_block_start == info.trailer_block_end) - return 0; + while (trailer_iterator_advance(&iter)) { + i++; + if (sob && !strncmp(iter.raw, sob->buf, sob->len)) + found_sob = i; + } + trailer_iterator_release(&iter); - for (i = 0; i < info.trailer_nr; i++) - if (sob && !strncmp(info.trailers[i], sob->buf, sob->len)) { - found_sob = 1; - if (i == info.trailer_nr - 1) - found_sob_last = 1; - } + if (!i) + return 0; - trailer_info_release(&info); + found_sob_last = (int)i == found_sob; if (found_sob_last) return 3; From patchwork Tue Feb 6 05:12:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546653 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 256D07E779 for ; Tue, 6 Feb 2024 05:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196372; cv=none; b=OlPPKdmqXMiHBmdCMd9kJE8ktnddMmGEpQy54614EH/Lxm8/YEl406HmZUAWjYuYu2GOazhNkVv/jCDkQOoqe55BkNKcwCSdzTjhQdNpxB0GK+uCFaLBwJ/cxeMGhCe4Two4U1INTmdxoy0EXPWGKBqW3uwVbPWn5jsDCgXkfR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196372; c=relaxed/simple; bh=vkbKYwZLShFNS6jl17IRtYOQxsLMPMAPqkoC/CuTQIk=; h=Message-ID:In-Reply-To:References:From:Date:Subject:MIME-Version: Content-Type:To:Cc; b=jWEuyPaFEch4rfAC92cIBkyLHiJwQGp1CX8Vl9z2I5uGhfZbIuJPkg+S/P3tq/xviMdFqpYBafIxm9jSb6rddZFjeVUxMtvzjnAheCAzuuH77QFaTOvC3h60Wz2pI7q2Bo/eQUX2ymjBY7Qi47BISfOntRc6euj7fGhzwouQ17Q= 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=nq+xbTEB; arc=none smtp.client-ip=209.85.128.45 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="nq+xbTEB" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fdf17fa89so840365e9.0 for ; Mon, 05 Feb 2024 21:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196368; x=1707801168; darn=vger.kernel.org; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=VstlCU1v4Fa1Y7Z0SF2X9KG815ulMMhkP/c2T5TQIdc=; b=nq+xbTEBT7d2YdAIhzah0Ztg9GoFuc4zN1+5Epg5Wn3AKV4wvfEOpSQ3NNAkVsTTaQ LDsS0QI808Zq6IbmSdvWu5gg7lRKjVOX1447n3smdbeqDxs10TLECzaMycIcf0zBCJn4 lLrO25ET6WJvmvncBLAly2a9DbUzUGSRKyXnWa6TKYjuXbgJ2uxgtyDdPFykM9gDFy14 4C5lBW/KJFFYBODBu+iq6A9Mbj3hAts/c4OuoKYQwjijjiBRErjrStu5etVWl5Thuhx0 fGFkZktz+R8rIkN1jKz+fUzT1YXrjyBZXIXGYKo/iKUZ4CdftRXgqBpGFeZZ/kOCbC+V EjWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196368; x=1707801168; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VstlCU1v4Fa1Y7Z0SF2X9KG815ulMMhkP/c2T5TQIdc=; b=tnywJIuALcLRJFX/s1iQR0TnQ+dRohr6hEWS5tRoGta3jX4vhV6ekpIx59lgNBRB4E GXbXbw3pl096swceDiIeYcLtrGjbdjyxZaavBE9JBd7/azJG6H/zJWYd3BctpnIa2vPH b9ou+cltQx/1nr+uKIJmKbWzAJumx/B3hwEO6FoWpWnJuoumcNMf2C+y8T1qbCapENpV mRfQzo9Gs4V6Niz+nrvRelj8Qim8dwwzobCT+Iw+A44Zrw1L9TpMj1GkNvZJ9nQghxLc 53B7pEwkeZRU5x10arGx3cLKATBkhKOAss/cTMNdSmZeqERtfkSEmn8RzecAVQxeVsSS ojkg== X-Gm-Message-State: AOJu0YypCN+QotpaasoRavP+y2jA+4D+a5z3oU65s9ceOY9t0CNQakUX n7I2ewDQH4qg3HELhJ7LJT6g2ZwOS0M78Okos4wULRzLDovGU3+07qLLRySl X-Google-Smtp-Source: AGHT+IHDrSyX2LlrOCb05gS7A9pEI07XPicoVS4arnR6IihCGO3hYf9wuWjVyW7Q7qjUjEg1muD9mQ== X-Received: by 2002:a05:600c:3111:b0:40f:e0ef:a174 with SMTP id g17-20020a05600c311100b0040fe0efa174mr732673wmo.8.1707196367901; Mon, 05 Feb 2024 21:12:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXnAbR/97jVEFGy2lfkwd/gPcFP7dXUyuc2w4PtczAws0N9qNRTfhmuKrWLZcmAntMwvJ4sy+0BfWoeSc1LriGU7/KKlVO2j2ZwL5xYwEQ0RNuOdFluJ9Nj6XzUii8pUlO2yMO/+EZj7GT3/XKNWPTLUwsa+XBQNZerROIlhWyFh80qGwjsuWFBCoP6k0N4Ga5GftJ0lywi0w== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d22-20020a05600c34d600b0040e3bdff98asm653852wmq.23.2024.02.05.21.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:47 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:19 +0000 Subject: [PATCH v4 19/28] trailer: make trailer_info struct private Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Christian Couder , Junio C Hamano , Emily Shaffer , Josh Steadmon , "Randall S. Becker" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver In 13211ae23f (trailer: separate public from internal portion of trailer_iterator, 2023-09-09) we moved trailer_info behind an anonymous struct to discourage use by trailer.h API users. However it still left open the possibility of external use of trailer_info itself. Now that there are no external users of trailer_info, we can make this struct private. Make this struct private by putting its definition inside trailer.c. This has two benefits: (1) it makes the surface area of the public facing interface (trailer.h) smaller, and (2) external API users are unable to peer inside this struct (because it is only ever exposed as an opaque pointer). There are a couple disadvantages: (A) every time the member of the struct is accessed an extra pointer dereference must be done, and (B) for users of trailer_info outside trailer.c, this struct can no longer be allocated on the stack and may only be allocated on the heap (because its definition is hidden away in trailer.c) and appropriately deallocated by the user. This patch believes that the benefits outweight the advantages for designing APIs, as explained below. Making trailer_info private exposes existing deficiencies in the API. This is because users of this struct had full access to its internals, so there wasn't much need to actually design it to be "complete" in the sense that API users only needed to use what was provided by the API. For example, the location of the trailer block (start/end offsets relative to the start of the input text) was accessible by looking at these struct members directly. Now that the struct is private, we have to expose new API functions to allow clients to access this information (see builtin/interpret-trailers.c). The idea in this patch to hide implementation details behind an "opaque pointer" is also known as the "pimpl" (pointer to implementation) idiom in C++ and is a common pattern in that language (where, for example, abstract classes only have pointers to concrete classes). However, the original inspiration to use this idiom does not come from C++, but instead the book "C Interfaces and Implementations: Techniques for Creating Reusable Software" [1]. This book recommends opaque pointers as a good design principle for designing C libraries, using the term "interface" as the functions defined in *.h (header) files and "implementation" as the corresponding *.c file which define the interfaces. The book says this about opaque pointers: ... clients can manipulate such pointers freely, but they can’t dereference them; that is, they can’t look at the innards of the structure pointed to by them. Only the implementation has that privilege. Opaque pointers hide representation details and help catch errors. In our case, "struct trailer_info" is now hidden from clients, and the ways in which this opaque pointer can be used is limited to the richness of . In other words, exclusively controls exactly how "trailer_info" pointers are to be used. [1] Hanson, David R. "C Interfaces and Implementations: Techniques for Creating Reusable Software". Addison Wesley, 1997. p. 22 Helped-by: Junio C Hamano Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 12 +++--- trailer.c | 81 ++++++++++++++++++++++++++++-------- trailer.h | 40 +++++------------- 3 files changed, 80 insertions(+), 53 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 11f4ce9e4a2..6bf8cec005a 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -141,7 +141,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; + struct trailer_info *info; FILE *outfile = stdout; trailer_config_init(); @@ -151,13 +151,13 @@ static void interpret_trailers(const struct process_trailer_options *opts, if (opts->in_place) outfile = create_in_place_tempfile(file); - parse_trailers(opts, &info, sb.buf, &head); + info = parse_trailers(opts, sb.buf, &head); /* Print the lines before the trailers */ if (!opts->only_trailers) - fwrite(sb.buf, 1, info.trailer_block_start, outfile); + fwrite(sb.buf, 1, trailer_block_start(info), outfile); - if (!opts->only_trailers && !info.blank_line_before_trailer) + if (!opts->only_trailers && !blank_line_before_trailer_block(info)) fprintf(outfile, "\n"); @@ -178,8 +178,8 @@ static void interpret_trailers(const struct process_trailer_options *opts, /* 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); + fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile); + trailer_info_release(info); if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) diff --git a/trailer.c b/trailer.c index 2cc4a910411..cc211dfeeae 100644 --- a/trailer.c +++ b/trailer.c @@ -11,6 +11,27 @@ * Copyright (c) 2013, 2014 Christian Couder */ +struct trailer_info { + /* + * True if there is a blank line before the location pointed to by + * trailer_block_start. + */ + int blank_line_before_trailer; + + /* + * Offsets to the trailer block start and end positions in the input + * string. If no trailer block is found, these are both set to the + * "true" end of the input (find_end_of_log_message()). + */ + size_t trailer_block_start, trailer_block_end; + + /* + * Array of trailers found. + */ + char **trailers; + size_t trailer_nr; +}; + struct conf_info { char *name; char *key; @@ -953,20 +974,26 @@ static void unfold_value(struct strbuf *val) strbuf_release(&out); } +static struct trailer_info *trailer_info_new(void) +{ + struct trailer_info *info = xcalloc(1, sizeof(*info)); + return info; +} + /* * Parse trailers in "str", populating the trailer info and "head" * linked list structure. */ -void parse_trailers(const struct process_trailer_options *opts, - struct trailer_info *info, - const char *str, - struct list_head *head) +struct trailer_info *parse_trailers(const struct process_trailer_options *opts, + const char *str, + struct list_head *head) { + struct trailer_info *info; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; size_t i; - trailer_info_get(opts, str, info); + info = trailer_info_get(opts, str); for (i = 0; i < info->trailer_nr; i++) { int separator_pos; @@ -990,6 +1017,8 @@ void parse_trailers(const struct process_trailer_options *opts, strbuf_detach(&val, NULL)); } } + + return info; } void free_trailers(struct list_head *trailers) @@ -1001,10 +1030,25 @@ void free_trailers(struct list_head *trailers) } } -void trailer_info_get(const struct process_trailer_options *opts, - const char *str, - struct trailer_info *info) +size_t trailer_block_start(struct trailer_info *info) +{ + return info->trailer_block_start; +} + +size_t trailer_block_end(struct trailer_info *info) +{ + return info->trailer_block_end; +} + +int blank_line_before_trailer_block(struct trailer_info *info) +{ + return info->blank_line_before_trailer; +} + +struct trailer_info *trailer_info_get(const struct process_trailer_options *opts, + const char *str) { + struct trailer_info *info = trailer_info_new(); size_t end_of_log_message = 0, trailer_block_start = 0; struct strbuf **trailer_lines, **ptr; char **trailer_strings = NULL; @@ -1043,6 +1087,8 @@ void trailer_info_get(const struct process_trailer_options *opts, info->trailer_block_end = end_of_log_message; info->trailers = trailer_strings; info->trailer_nr = nr; + + return info; } void trailer_info_release(struct trailer_info *info) @@ -1051,6 +1097,7 @@ void trailer_info_release(struct trailer_info *info) for (i = 0; i < info->trailer_nr; i++) free(info->trailers[i]); free(info->trailers); + free(info); } void format_trailers(const struct process_trailer_options *opts, @@ -1118,21 +1165,19 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, struct strbuf *out) { LIST_HEAD(trailers); - struct trailer_info info; - - parse_trailers(opts, &info, msg, &trailers); + struct trailer_info *info = parse_trailers(opts, 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 && !opts->key_value_separator) { - strbuf_add(out, msg + info.trailer_block_start, - info.trailer_block_end - info.trailer_block_start); + strbuf_add(out, msg + info->trailer_block_start, + info->trailer_block_end - info->trailer_block_start); } else format_trailers(opts, &trailers, out); free_trailers(&trailers); - trailer_info_release(&info); + trailer_info_release(info); } void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) @@ -1141,14 +1186,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) strbuf_init(&iter->key, 0); strbuf_init(&iter->val, 0); opts.no_divider = 1; - trailer_info_get(&opts, msg, &iter->internal.info); + iter->internal.info = trailer_info_get(&opts, msg); iter->internal.cur = 0; } int trailer_iterator_advance(struct trailer_iterator *iter) { - if (iter->internal.cur < iter->internal.info.trailer_nr) { - char *line = iter->internal.info.trailers[iter->internal.cur++]; + if (iter->internal.cur < iter->internal.info->trailer_nr) { + char *line = iter->internal.info->trailers[iter->internal.cur++]; int separator_pos = find_separator(line, separators); iter->raw = line; @@ -1165,7 +1210,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) void trailer_iterator_release(struct trailer_iterator *iter) { - trailer_info_release(&iter->internal.info); + trailer_info_release(iter->internal.info); strbuf_release(&iter->val); strbuf_release(&iter->key); } diff --git a/trailer.h b/trailer.h index ebafa3657e4..a63e97a2663 100644 --- a/trailer.h +++ b/trailer.h @@ -4,6 +4,8 @@ #include "list.h" #include "strbuf.h" +struct trailer_info; + enum trailer_where { WHERE_DEFAULT, WHERE_END, @@ -29,27 +31,6 @@ int trailer_set_where(enum trailer_where *item, const char *value); int trailer_set_if_exists(enum trailer_if_exists *item, const char *value); int trailer_set_if_missing(enum trailer_if_missing *item, const char *value); -struct trailer_info { - /* - * True if there is a blank line before the location pointed to by - * trailer_block_start. - */ - int blank_line_before_trailer; - - /* - * Offsets to the trailer block start and end positions in the input - * string. If no trailer block is found, these are both set to the - * "true" end of the input (find_end_of_log_message()). - */ - size_t trailer_block_start, trailer_block_end; - - /* - * Array of trailers found. - */ - char **trailers; - size_t trailer_nr; -}; - /* * A list that represents newly-added trailers, such as those provided * with the --trailer command line option of git-interpret-trailers. @@ -89,14 +70,15 @@ void parse_trailers_from_command_line_args(struct list_head *arg_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); +struct trailer_info *parse_trailers(const struct process_trailer_options *, + const char *str, + struct list_head *head); +struct trailer_info *trailer_info_get(const struct process_trailer_options *, + const char *str); -void trailer_info_get(const struct process_trailer_options *, - const char *str, - struct trailer_info *); +size_t trailer_block_start(struct trailer_info *); +size_t trailer_block_end(struct trailer_info *); +int blank_line_before_trailer_block(struct trailer_info *); void trailer_info_release(struct trailer_info *info); @@ -138,7 +120,7 @@ struct trailer_iterator { /* private */ struct { - struct trailer_info info; + struct trailer_info *info; size_t cur; } internal; }; From patchwork Tue Feb 6 05:12:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546654 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 AADCE7E77D for ; Tue, 6 Feb 2024 05:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196372; cv=none; b=LRgDOTPFxTPQMPwsZhjWLlt+tJNo7NvKzBrXywuzEnZ22BanelNC+QWDgKGVTD4mt6WB5wkZufL39kvZ3x/wO9ko9Iqp2aZCh6hYGJabGW9eoHT/gPEm8ygXOfTiyJHH+YX8HYq897Qp+L9qSYx5MH4fDNUmTYKfy+j7OH69WfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196372; c=relaxed/simple; bh=L/PfwCBDS3iBUexjSiaprzNAGD5mnvdV6fBrBWMlh3w=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=cipyZl2GtWESnI/6/+XvjhKNLCehQLElVd3bBVC+S3DLUGhm6p2uLNrRJcx+mBAyW7tCKS42LI9gMsEA999PBornSlQD4NJnJaeGAtAqF/9NyjP++dSI/r/dMI688PUZOyZGH3Agp7giiUS8DMe2pR0rggcjMgjQOW9vNap4iIg= 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=k7j0no80; arc=none smtp.client-ip=209.85.221.41 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="k7j0no80" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33b466bc363so161932f8f.3 for ; Mon, 05 Feb 2024 21:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196369; x=1707801169; 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=sJ77xYvtQ4dxzJ/uMX/TtwFJK9uq0GF7IwJD2rw/TAk=; b=k7j0no80//kFkwMLOLzkV0I7F7Z/qLRLPt67I9c6tyVqnyJK7K1C2sFsz5BjTOO5s6 pzaczIR6nwYaoL1rpomK13AFeWpSivAx7GgUGv/mRy8FElH4vICbXfJzXrgYKLXBB55r 9pcvZqlw/Kr2mC5y+3WwP8s1JofmIU3FvIMRbbWJnLjglTN2Di4BP82+FDkUeWPYzFHR VOpiWpEfcBji2nzSOwIAXrR4uHZuqq9+Lgb+dAudfqvtvxNkSEJQ+2f8eH9j0vZbeb2w 8v2NrKe4sClyhMVemQY2ah53ZaxOQHKBNY+Yq3TCvUlgDqdLKx8X8jzJs0Q8R0TcVUNN 5Ldw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196369; x=1707801169; 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=sJ77xYvtQ4dxzJ/uMX/TtwFJK9uq0GF7IwJD2rw/TAk=; b=v2VvoyYEQUX4MgfnYtUOjFkD9xmlJYSwaQgsixOypW1BpW3LOqtOcf9FgOwWQQolwl 2DowZUgSv0DsWInmIenatn5kcy1FsoQ0aZpTgiayw3gXUaAzllEcs5Cdq6ws0qWs6niw uBYO1tbJZcjRWwGwPb/v33QlPE60kvJV0llqvQjM9dXPSHPWV4REZdoPsKtr734El7ZN giBHLpjNOAHLHJcSn/kpnyJBmlsbfoF6s7KVJ/+7ZA96lUs4B60XvrutKjKJt7pHYkNC 3JBK5BSevl0Z5mSNTeiQyvT6UNmquOVGf9LCMlHfKprsQatJzK1egTts4CFHARbxRKZy eovA== X-Gm-Message-State: AOJu0YzFfW6Y6uLUNbLvekqscuPnJ1rAPhMe9h+kytUnbKCNvMqeITr9 ZwCaw95cXojOIo8Ozzh825KQbr2vBk5yFWwH7ZNxVh7nvb/hzEU/jmfjqQnF X-Google-Smtp-Source: AGHT+IHOBSpETwCSsCKIpFYfn2aRkd4JMWQjVzfIMMeXYL3apsjAaMdxW/hOCLL5oU6WGehamSRyOw== X-Received: by 2002:a5d:4051:0:b0:33b:27cf:21f4 with SMTP id w17-20020a5d4051000000b0033b27cf21f4mr280142wrp.48.1707196368865; Mon, 05 Feb 2024 21:12:48 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXT9Pn3sZ6+II5nn0Y7qWF4TT+wvVa/605YB5f1Jt4xUp8ir5HhySHDALHkRPtGwQRp+MNhQghUfD8g+bDbUYuW98lkBIZEc6TZgYNouRxVsBMETFrhRYmtIdL+EvEb7miTvzKDs0woZPIIZPuVYSOpcjWL9pA5SBLWuKme5U/vCqi/4iRvKyke9b7D+ZKOYIo/2TyBkkUMMQ== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q3-20020a5d5743000000b0033b41af645asm1056533wrw.108.2024.02.05.21.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:48 -0800 (PST) Message-ID: <607ae7a90cd9a2e69733c62ef44bb6c0893e0079.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:20 +0000 Subject: [PATCH v4 20/28] trailer: retire trailer_info_get() from 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Make it "static" to be file-scoped to trailer.c, because no one outside of trailer.c uses it. Remove its declaration from . We have to also reposition it to be above parse_trailers(), which depends on it. Signed-off-by: Linus Arver --- trailer.c | 92 +++++++++++++++++++++++++++---------------------------- trailer.h | 2 -- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/trailer.c b/trailer.c index cc211dfeeae..36e49ab7cf5 100644 --- a/trailer.c +++ b/trailer.c @@ -980,6 +980,52 @@ static struct trailer_info *trailer_info_new(void) return info; } +static struct trailer_info *trailer_info_get(const struct process_trailer_options *opts, + const char *str) +{ + struct trailer_info *info = trailer_info_new(); + size_t end_of_log_message = 0, trailer_block_start = 0; + struct strbuf **trailer_lines, **ptr; + char **trailer_strings = NULL; + size_t nr = 0, alloc = 0; + char **last = NULL; + + 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); + + trailer_lines = strbuf_split_buf(str + trailer_block_start, + end_of_log_message - trailer_block_start, + '\n', + 0); + for (ptr = trailer_lines; *ptr; ptr++) { + if (last && isspace((*ptr)->buf[0])) { + struct strbuf sb = STRBUF_INIT; + strbuf_attach(&sb, *last, strlen(*last), strlen(*last)); + strbuf_addbuf(&sb, *ptr); + *last = strbuf_detach(&sb, NULL); + continue; + } + ALLOC_GROW(trailer_strings, nr + 1, alloc); + trailer_strings[nr] = strbuf_detach(*ptr, NULL); + last = find_separator(trailer_strings[nr], separators) >= 1 + ? &trailer_strings[nr] + : NULL; + nr++; + } + strbuf_list_free(trailer_lines); + + info->blank_line_before_trailer = ends_with_blank_line(str, + trailer_block_start); + info->trailer_block_start = trailer_block_start; + info->trailer_block_end = end_of_log_message; + info->trailers = trailer_strings; + info->trailer_nr = nr; + + return info; +} + /* * Parse trailers in "str", populating the trailer info and "head" * linked list structure. @@ -1045,52 +1091,6 @@ int blank_line_before_trailer_block(struct trailer_info *info) return info->blank_line_before_trailer; } -struct trailer_info *trailer_info_get(const struct process_trailer_options *opts, - const char *str) -{ - struct trailer_info *info = trailer_info_new(); - size_t end_of_log_message = 0, trailer_block_start = 0; - struct strbuf **trailer_lines, **ptr; - char **trailer_strings = NULL; - size_t nr = 0, alloc = 0; - char **last = NULL; - - 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); - - trailer_lines = strbuf_split_buf(str + trailer_block_start, - end_of_log_message - trailer_block_start, - '\n', - 0); - for (ptr = trailer_lines; *ptr; ptr++) { - if (last && isspace((*ptr)->buf[0])) { - struct strbuf sb = STRBUF_INIT; - strbuf_attach(&sb, *last, strlen(*last), strlen(*last)); - strbuf_addbuf(&sb, *ptr); - *last = strbuf_detach(&sb, NULL); - continue; - } - ALLOC_GROW(trailer_strings, nr + 1, alloc); - trailer_strings[nr] = strbuf_detach(*ptr, NULL); - last = find_separator(trailer_strings[nr], separators) >= 1 - ? &trailer_strings[nr] - : NULL; - nr++; - } - strbuf_list_free(trailer_lines); - - info->blank_line_before_trailer = ends_with_blank_line(str, - trailer_block_start); - info->trailer_block_start = trailer_block_start; - info->trailer_block_end = end_of_log_message; - info->trailers = trailer_strings; - info->trailer_nr = nr; - - return info; -} - void trailer_info_release(struct trailer_info *info) { size_t i; diff --git a/trailer.h b/trailer.h index a63e97a2663..1b7422fa2b0 100644 --- a/trailer.h +++ b/trailer.h @@ -73,8 +73,6 @@ void process_trailers_lists(struct list_head *head, struct trailer_info *parse_trailers(const struct process_trailer_options *, const char *str, struct list_head *head); -struct trailer_info *trailer_info_get(const struct process_trailer_options *, - const char *str); size_t trailer_block_start(struct trailer_info *); size_t trailer_block_end(struct trailer_info *); From patchwork Tue Feb 6 05:12:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546655 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 DF7317E764 for ; Tue, 6 Feb 2024 05:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196373; cv=none; b=uiAByUxurnHY6K9bY89rsxMXGMGh0R/EF0IRulL2m0ij5UCEup/3N59xtAoll4/n49lMbG8/nhQ9oBVgJngLpg5hnL68w/EaXpZfYISIXcDbPo7rJlJVQMvnUeMK/ETjhI3Dq7By57LiMUyqCdCwRa1+GxBVlQsArU5OTmtM/os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196373; c=relaxed/simple; bh=6QL/Sn9w4wAaofC5ZJ/XnQWkFTDIITPXeGJ3bFQXdZU=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=bc8agJY//xsnj1xs2jmWxunzM5xuMxOPNLFW3MOS2J817rf6GlyTiBg7aeC708FgUuCIFWmuTyi7SpP7nO0MBdhvn8qvp/qXEww6RsjMSHnU7Fm8ImivWgk0/6OsIDczGmV0bC2oa4qZWu10WJyrIFOfr7U7eOadaVguBnRAUzI= 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=LXvGb9ZO; arc=none smtp.client-ip=209.85.221.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="LXvGb9ZO" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3392b045e0aso257120f8f.2 for ; Mon, 05 Feb 2024 21:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196369; x=1707801169; 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=l/7iEkelNpOUguRvsEE9eynfw8YnY6LsMa0XK+YcgpE=; b=LXvGb9ZOP3A8wVY1Jfk+AVxrGvFzNtzhOUCiBnjzARlmT/m6pMdbNsRyN22Bx+wlA/ CNisVZRN31buE9TVlWxUbc+nQwTJhQDzK4zROnQvU9YK0TnoyaTbyLTe0cjK0rf4W7r4 BBi/XZ3WNDaQwngkg+izqE6faEb+OqLuQEWhDJzP33avJC4KkGbwcKABMbn0eLqM1Fx8 +pP7Ehs6aouMGENyRCae3yL2ZwJwYHeLYVM/V6MpJUDMiS7sb20pYEedjA3i55TDz4He TRNq4A6GdU3vp1nhJJs/Gqn6HHMt5OQ03TtufpFxYsDryF5PyuZugOYuo+vD5oJcdJad IJ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196369; x=1707801169; 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=l/7iEkelNpOUguRvsEE9eynfw8YnY6LsMa0XK+YcgpE=; b=NUrcpau4dfGfJZqzDUQ4sYVaGrxTk+c8wjewsxQZBN73gwBRDm3cJONuUKUh51bWIN R/R0VOC3sZwZCaHpCgrZj90+EES8kTIHbKNkZHxz731Xru04JAzVlbMWUZAjnuGCtoZZ iWExJHws7gFTu5IbZYchLrt+Ar3++WeRtruY5SeuLSlQElhouPcmAU/07RLqqz+gbiK/ 9iGuHfmwPsonbD1HS+MIlpXgc/FUO9OulYfT6GR1zKfZpmysU4dckR20jcXXaOVGe2Ac 4jS6PtuuhXr0oj3loFsjNHLHpg8wL9ZM6EF7Y1AmIWTBoxzC7pl5WVgG7yAG0vx3NQqk o/dw== X-Gm-Message-State: AOJu0YwiI+ONceUoY/N7QJYYqwtcdEtsdk4/1VAM+BazoVdLm8A4xyK/ d9ek2ohbyyQ7R24Yeo1suj2v7+q9HG8Frs0YwcMVokb8Lo88TuBVYX3XrZVv X-Google-Smtp-Source: AGHT+IH36lg042NmUUxL3wLaoSfgwbz7p3N3nqR0dCT9IpKSTPa56fRznPWLhcqX0IPCfRJen2cLmg== X-Received: by 2002:a5d:5510:0:b0:33b:2194:d2ec with SMTP id b16-20020a5d5510000000b0033b2194d2ecmr468261wrv.57.1707196369508; Mon, 05 Feb 2024 21:12:49 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVoQS5C0zjH5g5+2mynMExW+XqgJjMksd+IYuecmfxXnPcH2eVPt/27IcXzeKVLQveqjFF7okZMDKQghFYfq5jlSuaFojd2rHXIrBrHlz6KHHNEuhWtaWBm4Kfd8dulHAIYgsKUhnMVKCvzZSSY7Ys1Uws6KYFig7pJQUz5+HyMJaux5LSR+Tti2x85uwZHLqvu/Ue9jiJhWQ== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y8-20020adff148000000b0033b40a3f92asm1069755wro.25.2024.02.05.21.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:49 -0800 (PST) Message-ID: <38f4b4c4135dfebc06c2b1d5c56854af4b07fedc.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:21 +0000 Subject: [PATCH v4 21/28] trailer: spread usage of "trailer_block" language 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Deprecate the "trailer_info" struct name and replace it with "trailer_block". The main reason is to help readability, because "trailer_info" on the surface sounds like it's about a single trailer when in reality it is a collection of contiguous lines, at least 25% of which are trailers. Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 25 +++++----- trailer.c | 97 ++++++++++++++++++------------------ trailer.h | 18 +++---- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 6bf8cec005a..f76841c5280 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -140,8 +140,8 @@ 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; + struct strbuf tb = STRBUF_INIT; + struct trailer_block *trailer_block; FILE *outfile = stdout; trailer_config_init(); @@ -151,13 +151,13 @@ static void interpret_trailers(const struct process_trailer_options *opts, if (opts->in_place) outfile = create_in_place_tempfile(file); - info = parse_trailers(opts, sb.buf, &head); + trailer_block = parse_trailers(opts, sb.buf, &head); - /* Print the lines before the trailers */ + /* Print the lines before the trailer block */ if (!opts->only_trailers) - fwrite(sb.buf, 1, trailer_block_start(info), outfile); + fwrite(sb.buf, 1, trailer_block_start(trailer_block), outfile); - if (!opts->only_trailers && !blank_line_before_trailer_block(info)) + if (!opts->only_trailers && !blank_line_before_trailer_block(trailer_block)) fprintf(outfile, "\n"); @@ -171,15 +171,16 @@ static void interpret_trailers(const struct process_trailer_options *opts, } /* Print trailer block. */ - format_trailers(opts, &head, &trailer_block); + format_trailers(opts, &head, &tb); free_trailers(&head); - fwrite(trailer_block.buf, 1, trailer_block.len, outfile); - strbuf_release(&trailer_block); + fwrite(tb.buf, 1, tb.len, outfile); + strbuf_release(&tb); - /* Print the lines after the trailers as is */ + /* Print the lines after the trailer block as is. */ if (!opts->only_trailers) - fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile); - trailer_info_release(info); + fwrite(sb.buf + trailer_block_end(trailer_block), 1, + sb.len - trailer_block_end(trailer_block), outfile); + trailer_block_release(trailer_block); if (opts->in_place) if (rename_tempfile(&trailers_tempfile, file)) diff --git a/trailer.c b/trailer.c index 36e49ab7cf5..49bf26e3211 100644 --- a/trailer.c +++ b/trailer.c @@ -11,19 +11,20 @@ * Copyright (c) 2013, 2014 Christian Couder */ -struct trailer_info { +struct trailer_block { /* * True if there is a blank line before the location pointed to by - * trailer_block_start. + * "start". */ int blank_line_before_trailer; /* - * Offsets to the trailer block start and end positions in the input - * string. If no trailer block is found, these are both set to the - * "true" end of the input (find_end_of_log_message()). + * The locations of the start and end positions of the trailer block + * found, as offsets from the beginning of the source text from which + * this trailer block was parsed. If no trailer block is found, these + * are both set to 0. */ - size_t trailer_block_start, trailer_block_end; + size_t start, end; /* * Array of trailers found. @@ -974,16 +975,16 @@ static void unfold_value(struct strbuf *val) strbuf_release(&out); } -static struct trailer_info *trailer_info_new(void) +static struct trailer_block *trailer_block_new(void) { - struct trailer_info *info = xcalloc(1, sizeof(*info)); - return info; + struct trailer_block *trailer_block = xcalloc(1, sizeof(*trailer_block)); + return trailer_block; } -static struct trailer_info *trailer_info_get(const struct process_trailer_options *opts, - const char *str) +static struct trailer_block *trailer_block_get(const struct process_trailer_options *opts, + const char *str) { - struct trailer_info *info = trailer_info_new(); + struct trailer_block *trailer_block = trailer_block_new(); size_t end_of_log_message = 0, trailer_block_start = 0; struct strbuf **trailer_lines, **ptr; char **trailer_strings = NULL; @@ -1016,34 +1017,34 @@ static struct trailer_info *trailer_info_get(const struct process_trailer_option } strbuf_list_free(trailer_lines); - info->blank_line_before_trailer = ends_with_blank_line(str, - trailer_block_start); - info->trailer_block_start = trailer_block_start; - info->trailer_block_end = end_of_log_message; - info->trailers = trailer_strings; - info->trailer_nr = nr; + trailer_block->blank_line_before_trailer = ends_with_blank_line(str, + trailer_block_start); + trailer_block->start = trailer_block_start; + trailer_block->end = end_of_log_message; + trailer_block->trailers = trailer_strings; + trailer_block->trailer_nr = nr; - return info; + return trailer_block; } /* - * Parse trailers in "str", populating the trailer info and "head" - * linked list structure. + * Parse trailers in "str", populating the trailer_block info and "head" linked + * list structure. */ -struct trailer_info *parse_trailers(const struct process_trailer_options *opts, - const char *str, - struct list_head *head) +struct trailer_block *parse_trailers(const struct process_trailer_options *opts, + const char *str, + struct list_head *head) { - struct trailer_info *info; + struct trailer_block *trailer_block; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; size_t i; - info = trailer_info_get(opts, str); + trailer_block = trailer_block_get(opts, str); - for (i = 0; i < info->trailer_nr; i++) { + for (i = 0; i < trailer_block->trailer_nr; i++) { int separator_pos; - char *trailer = info->trailers[i]; + char *trailer = trailer_block->trailers[i]; if (trailer[0] == comment_line_char) continue; separator_pos = find_separator(trailer, separators); @@ -1064,7 +1065,7 @@ struct trailer_info *parse_trailers(const struct process_trailer_options *opts, } } - return info; + return trailer_block; } void free_trailers(struct list_head *trailers) @@ -1076,28 +1077,28 @@ void free_trailers(struct list_head *trailers) } } -size_t trailer_block_start(struct trailer_info *info) +size_t trailer_block_start(struct trailer_block *trailer_block) { - return info->trailer_block_start; + return trailer_block->start; } -size_t trailer_block_end(struct trailer_info *info) +size_t trailer_block_end(struct trailer_block *trailer_block) { - return info->trailer_block_end; + return trailer_block->end; } -int blank_line_before_trailer_block(struct trailer_info *info) +int blank_line_before_trailer_block(struct trailer_block *trailer_block) { - return info->blank_line_before_trailer; + return trailer_block->blank_line_before_trailer; } -void trailer_info_release(struct trailer_info *info) +void trailer_block_release(struct trailer_block *trailer_block) { size_t i; - for (i = 0; i < info->trailer_nr; i++) - free(info->trailers[i]); - free(info->trailers); - free(info); + for (i = 0; i < trailer_block->trailer_nr; i++) + free(trailer_block->trailers[i]); + free(trailer_block->trailers); + free(trailer_block); } void format_trailers(const struct process_trailer_options *opts, @@ -1165,19 +1166,19 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, struct strbuf *out) { LIST_HEAD(trailers); - struct trailer_info *info = parse_trailers(opts, msg, &trailers); + struct trailer_block *trailer_block = parse_trailers(opts, 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 && !opts->key_value_separator) { - strbuf_add(out, msg + info->trailer_block_start, - info->trailer_block_end - info->trailer_block_start); + strbuf_add(out, msg + trailer_block->start, + trailer_block->end - trailer_block->start); } else format_trailers(opts, &trailers, out); free_trailers(&trailers); - trailer_info_release(info); + trailer_block_release(trailer_block); } void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) @@ -1186,14 +1187,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg) strbuf_init(&iter->key, 0); strbuf_init(&iter->val, 0); opts.no_divider = 1; - iter->internal.info = trailer_info_get(&opts, msg); + iter->internal.trailer_block = trailer_block_get(&opts, msg); iter->internal.cur = 0; } int trailer_iterator_advance(struct trailer_iterator *iter) { - if (iter->internal.cur < iter->internal.info->trailer_nr) { - char *line = iter->internal.info->trailers[iter->internal.cur++]; + if (iter->internal.cur < iter->internal.trailer_block->trailer_nr) { + char *line = iter->internal.trailer_block->trailers[iter->internal.cur++]; int separator_pos = find_separator(line, separators); iter->raw = line; @@ -1210,7 +1211,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) void trailer_iterator_release(struct trailer_iterator *iter) { - trailer_info_release(iter->internal.info); + trailer_block_release(iter->internal.trailer_block); strbuf_release(&iter->val); strbuf_release(&iter->key); } diff --git a/trailer.h b/trailer.h index 1b7422fa2b0..76e6d941a07 100644 --- a/trailer.h +++ b/trailer.h @@ -4,7 +4,7 @@ #include "list.h" #include "strbuf.h" -struct trailer_info; +struct trailer_block; enum trailer_where { WHERE_DEFAULT, @@ -70,15 +70,15 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head, void process_trailers_lists(struct list_head *head, struct list_head *arg_head); -struct trailer_info *parse_trailers(const struct process_trailer_options *, - const char *str, - struct list_head *head); +struct trailer_block *parse_trailers(const struct process_trailer_options *, + const char *str, + struct list_head *head); -size_t trailer_block_start(struct trailer_info *); -size_t trailer_block_end(struct trailer_info *); -int blank_line_before_trailer_block(struct trailer_info *); +size_t trailer_block_start(struct trailer_block *); +size_t trailer_block_end(struct trailer_block *); +int blank_line_before_trailer_block(struct trailer_block *); -void trailer_info_release(struct trailer_info *info); +void trailer_block_release(struct trailer_block *); void trailer_config_init(void); void format_trailers(const struct process_trailer_options *, @@ -118,7 +118,7 @@ struct trailer_iterator { /* private */ struct { - struct trailer_info *info; + struct trailer_block *trailer_block; size_t cur; } internal; }; From patchwork Tue Feb 6 05:12:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546656 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 DC8D97E76A for ; Tue, 6 Feb 2024 05:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196374; cv=none; b=MtcupnmhalUXD6XRclOA6SiLCVbq/LecaWsmnJagv9X35dPkvzYoW68RAozVaVq38iRQEPEXLo0knAKEarf5KqUt82nVR0vHzmghKp9IP4OzBmL0Z0yk1A4xEJPl1EChb4PiaYWP6YlqK6t9tGM3jp9lDZ1Jiq0dbtg1xdlTbcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196374; c=relaxed/simple; bh=cchuHLnSL+nGTYzHvQIYLFQ5zeCmzJCmvph+zCqjTgU=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Ydpms+AI7YAt5WcqFkIWfp2KzLqXr9RhvbmALSxamfTO7myuEXNZHIACHrbWtsDmWEbS13tqu46qK0I4MD+omY85Hkcg9YLm2xvrAgJzpcTtHZIz0URxOzvARCiWi486QqT5LbM37b4wWyja7vRLWJoCdJWR413hGq6LUmP588w= 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=PYnn7ThH; arc=none smtp.client-ip=209.85.167.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="PYnn7ThH" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-511234430a4so9102939e87.3 for ; Mon, 05 Feb 2024 21:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196371; x=1707801171; 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=O6Zj2YOYhr0LYMrWK0exJg+gp07Yzh6Kzf0Hh53kln0=; b=PYnn7ThHeygLWyYj+9Dr9sJ3WFnYr8wDTAdMNREfBhqBdSOUuq/7axaYz/CqVvBHjf JDegOsW5P3SAQ2IZuMrB3Z6mJtPozGi6cw78HFhPhJ+9xSdm61rr2CuFaAaY4I4emZYS uFU+3aeatTw4R2L7tBFwrBUuSlclw/U+/kGAwPO0/0ehmmn/uJUrS7NxatDG56LHbBbg S0proz1XgH+DqQtP+QH9WlextgpS6n9W1oJsOFbX8NfNckoVS9RmFz2/lexaUu3HtsyH oOxBGgwe0qRYK2/hxbRdboEn0i3wlCkXuPLSKRJ4y+kWlNQJJo4eEzd7Oo0S+DO7uPA5 PRpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196371; x=1707801171; 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=O6Zj2YOYhr0LYMrWK0exJg+gp07Yzh6Kzf0Hh53kln0=; b=gY0Ds293VZmJd5AAI9oDmaFAbA5lxBTnmb3Xxoh9ABvjREDmKep15IZUkXO2oHKmQQ 9PX8YzA4ZMTUiBGeJlrOuRGRFdWFI9r2hbxOAUp2m3n1SwiQcTAu3by12xLvNjWgG8fi T8qHXlF1vd1AEOicmRNq35Vley20jgr1Ab0ecUqKJmaQp4E0rim4buUQtihmas3VUsFg rzmved0xCyKYy31FxUPMELagrCfNPyxzIDB0RWxQH3axjugpA/e9Wy9UNS/tL2o6XJu4 6p21KMt8Tkn/0iNoXsbi55/I48ntCc7ohUSCCduI4ZUQBGsxeWim4/neMlT5/nU2MPF3 bQug== X-Gm-Message-State: AOJu0YzDLNiDLe1TnwaPnhIiIdnrXCr9hVdZuq1Ghlf5hOpuA1zi79yF +FDpxQscAi7StoifFYFML2n7ziG0KE2OYdYNoNMrHsAC5+DPpnEPzASr7h5W X-Google-Smtp-Source: AGHT+IEV9R6+vQP1nqvv07+1avySMgHbjggEPlw94naSByP1qYeF+2ikP+Cr7zdZgf/iQ98l11cdUQ== X-Received: by 2002:a05:6512:31c6:b0:511:5e45:1150 with SMTP id j6-20020a05651231c600b005115e451150mr610139lfe.61.1707196370734; Mon, 05 Feb 2024 21:12:50 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWsA90ncBSe87U5gEu57pF/qa9C+Rc3PwF/bb0grfkkYazC4WFZDSl8sUYBQQV0lvCo4YpUQ5GqF2AbbMMcXUHUi1N3MDd7fbUI7UvOYUj6NXZI6y348wqO+0KoWJ0gkVIgn689IVep511fET+t5+BWoIb8VW1juMvNJt+bSxVzE9QHXhXZtx04jzINBvUnbLMBDoQ8V/Lr1Q== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m7-20020a05600c4f4700b0040efb445698sm657484wmq.5.2024.02.05.21.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:49 -0800 (PST) Message-ID: <94bf182e3ffbf8ed6e20cd77b2e46e5b83c44d34.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:22 +0000 Subject: [PATCH v4 22/28] trailer: prepare to delete "parse_trailers_from_command_line_args()" 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Expose more functions in the trailer.h API, in preparation for deleting parse_trailers_from_command_line_args() from the trailers implementation, because it should not be concerned with command line arguments (as they have nothing to do with trailers themselves). Indeed, the interpret-trailers builtin is the only caller of this function inside Git. Rename add_arg_item() to trailer_add_arg_item() to expose it as an API function. Rename new_trailers_clear() to free_new_trailers() because it will be promoted into an API function; the API already has free_trailers(), so using the "free_*" naming style will keep it consistent. Also rename "conf_info" to "trailer_conf" for readability, dropping the low-value "_info" suffix as we did earlier in this series for "trailer_info" to "trailer_block". Helped-by: Josh Steadmon Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 6 +-- trailer.c | 86 ++++++++++++++++++------------------ trailer.h | 13 ++++++ 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index f76841c5280..f674b5f4b9e 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -45,7 +45,7 @@ static int option_parse_if_missing(const struct option *opt, return trailer_set_if_missing(opt->value, arg); } -static void new_trailers_clear(struct list_head *trailers) +static void free_new_trailers(struct list_head *trailers) { struct list_head *pos, *tmp; struct new_trailer_item *item; @@ -64,7 +64,7 @@ static int option_parse_trailer(const struct option *opt, struct new_trailer_item *item; if (unset) { - new_trailers_clear(trailers); + free_new_trailers(trailers); return 0; } @@ -237,7 +237,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) interpret_trailers(&opts, &trailers, NULL); } - new_trailers_clear(&trailers); + free_new_trailers(&trailers); return 0; } diff --git a/trailer.c b/trailer.c index 49bf26e3211..3b8f0ba103c 100644 --- a/trailer.c +++ b/trailer.c @@ -33,7 +33,7 @@ struct trailer_block { size_t trailer_nr; }; -struct conf_info { +struct trailer_conf { char *name; char *key; char *command; @@ -43,7 +43,7 @@ struct conf_info { enum trailer_if_missing if_missing; }; -static struct conf_info default_conf_info; +static struct trailer_conf default_trailer_conf; struct trailer_item { struct list_head list; @@ -59,7 +59,7 @@ struct arg_item { struct list_head list; char *token; char *value; - struct conf_info conf; + struct trailer_conf conf; }; static LIST_HEAD(conf_head); @@ -210,7 +210,7 @@ static int check_if_different(struct trailer_item *in_tok, return 1; } -static char *apply_command(struct conf_info *conf, const char *arg) +static char *apply_command(struct trailer_conf *conf, const char *arg) { struct strbuf cmd = STRBUF_INIT; struct strbuf buf = STRBUF_INIT; @@ -424,7 +424,8 @@ int trailer_set_if_missing(enum trailer_if_missing *item, const char *value) return 0; } -static void duplicate_conf(struct conf_info *dst, const struct conf_info *src) +void duplicate_trailer_conf(struct trailer_conf *dst, + const struct trailer_conf *src) { *dst = *src; dst->name = xstrdup_or_null(src->name); @@ -447,7 +448,7 @@ static struct arg_item *get_conf_item(const char *name) /* Item does not already exists, create it */ CALLOC_ARRAY(item, 1); - duplicate_conf(&item->conf, &default_conf_info); + duplicate_trailer_conf(&item->conf, &default_trailer_conf); item->conf.name = xstrdup(name); list_add_tail(&item->list, &conf_head); @@ -482,17 +483,17 @@ static int git_trailer_default_config(const char *conf_key, const char *value, variable_name = strrchr(trailer_item, '.'); if (!variable_name) { if (!strcmp(trailer_item, "where")) { - if (trailer_set_where(&default_conf_info.where, + if (trailer_set_where(&default_trailer_conf.where, value) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); } else if (!strcmp(trailer_item, "ifexists")) { - if (trailer_set_if_exists(&default_conf_info.if_exists, + if (trailer_set_if_exists(&default_trailer_conf.if_exists, value) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); } else if (!strcmp(trailer_item, "ifmissing")) { - if (trailer_set_if_missing(&default_conf_info.if_missing, + if (trailer_set_if_missing(&default_trailer_conf.if_missing, value) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); @@ -511,7 +512,7 @@ static int git_trailer_config(const char *conf_key, const char *value, { const char *trailer_item, *variable_name; struct arg_item *item; - struct conf_info *conf; + struct trailer_conf *conf; char *name = NULL; enum trailer_info_type type; int i; @@ -585,9 +586,9 @@ void trailer_config_init(void) return; /* Default config must be setup first */ - default_conf_info.where = WHERE_END; - default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR; - default_conf_info.if_missing = MISSING_ADD; + default_trailer_conf.where = WHERE_END; + default_trailer_conf.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR; + default_trailer_conf.if_missing = MISSING_ADD; git_config(git_trailer_default_config, NULL); git_config(git_trailer_config, NULL); configured = 1; @@ -620,7 +621,7 @@ static int token_matches_item(const char *tok, struct arg_item *item, size_t tok * distinguished from the non-well-formed-line case (in which this function * returns -1) because some callers of this function need such a distinction. */ -static ssize_t find_separator(const char *line, const char *separators) +ssize_t find_separator(const char *line, const char *separators) { int whitespace_found = 0; const char *c; @@ -645,28 +646,28 @@ static ssize_t find_separator(const char *line, const char *separators) * * If separator_pos is -1, interpret the whole trailer as a token. */ -static void parse_trailer(struct strbuf *tok, struct strbuf *val, - const struct conf_info **conf, const char *trailer, - ssize_t separator_pos) +void parse_trailer(const char *line, ssize_t separator_pos, + struct strbuf *tok, struct strbuf *val, + const struct trailer_conf **conf) { struct arg_item *item; size_t tok_len; struct list_head *pos; if (separator_pos != -1) { - strbuf_add(tok, trailer, separator_pos); + strbuf_add(tok, line, separator_pos); strbuf_trim(tok); - strbuf_addstr(val, trailer + separator_pos + 1); + strbuf_addstr(val, line + separator_pos + 1); strbuf_trim(val); } else { - strbuf_addstr(tok, trailer); + strbuf_addstr(tok, line); strbuf_trim(tok); } /* Lookup if the token matches something in the config */ tok_len = token_len_without_separator(tok->buf, tok->len); if (conf) - *conf = &default_conf_info; + *conf = &default_trailer_conf; list_for_each(pos, &conf_head) { item = list_entry(pos, struct arg_item, list); if (token_matches_item(tok->buf, item, tok_len)) { @@ -690,14 +691,14 @@ static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, return new_item; } -static void add_arg_item(struct list_head *arg_head, char *tok, char *val, - const struct conf_info *conf, - const struct new_trailer_item *new_trailer_item) +void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, + const struct trailer_conf *conf, + const struct new_trailer_item *new_trailer_item) { struct arg_item *new_item = xcalloc(1, sizeof(*new_item)); new_item->token = tok; new_item->value = val; - duplicate_conf(&new_item->conf, conf); + duplicate_trailer_conf(&new_item->conf, conf); if (new_trailer_item) { if (new_trailer_item->where != WHERE_DEFAULT) new_item->conf.where = new_trailer_item->where; @@ -718,10 +719,10 @@ void parse_trailers_from_config(struct list_head *config_head) list_for_each(pos, &conf_head) { item = list_entry(pos, struct arg_item, list); if (item->conf.command) - add_arg_item(config_head, - xstrdup(token_from_item(item, NULL)), - xstrdup(""), - &item->conf, NULL); + trailer_add_arg_item(config_head, + xstrdup(token_from_item(item, NULL)), + xstrdup(""), + &item->conf, NULL); } } @@ -730,7 +731,7 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head, { struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; - const struct conf_info *conf; + const struct trailer_conf *conf; struct list_head *pos; /* @@ -753,12 +754,11 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head, (int) sb.len, sb.buf); strbuf_release(&sb); } else { - parse_trailer(&tok, &val, &conf, tr->text, - separator_pos); - add_arg_item(arg_head, - strbuf_detach(&tok, NULL), - strbuf_detach(&val, NULL), - conf, tr); + parse_trailer(tr->text, separator_pos, &tok, &val, &conf); + trailer_add_arg_item(arg_head, + strbuf_detach(&tok, NULL), + strbuf_detach(&val, NULL), + conf, tr); } } @@ -1044,20 +1044,19 @@ struct trailer_block *parse_trailers(const struct process_trailer_options *opts, for (i = 0; i < trailer_block->trailer_nr; i++) { int separator_pos; - char *trailer = trailer_block->trailers[i]; - if (trailer[0] == comment_line_char) + char *line = trailer_block->trailers[i]; + if (line[0] == comment_line_char) continue; - separator_pos = find_separator(trailer, separators); + separator_pos = find_separator(line, separators); if (separator_pos >= 1) { - parse_trailer(&tok, &val, NULL, trailer, - separator_pos); + parse_trailer(line, separator_pos, &tok, &val, NULL); if (opts->unfold) unfold_value(&val); add_trailer_item(head, strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL)); } else if (!opts->only_trailers) { - strbuf_addstr(&val, trailer); + strbuf_addstr(&val, line); strbuf_strip_suffix(&val, "\n"); add_trailer_item(head, NULL, @@ -1200,8 +1199,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter) iter->raw = line; strbuf_reset(&iter->key); strbuf_reset(&iter->val); - parse_trailer(&iter->key, &iter->val, NULL, - line, separator_pos); + parse_trailer(line, separator_pos, &iter->key, &iter->val, NULL); /* Always unfold values during iteration. */ unfold_value(&iter->val); return 1; diff --git a/trailer.h b/trailer.h index 76e6d941a07..f80f8f7e63f 100644 --- a/trailer.h +++ b/trailer.h @@ -5,6 +5,7 @@ #include "strbuf.h" struct trailer_block; +struct trailer_conf; enum trailer_where { WHERE_DEFAULT, @@ -45,6 +46,12 @@ struct new_trailer_item { enum trailer_if_missing if_missing; }; +void duplicate_trailer_conf(struct trailer_conf *dst, + const struct trailer_conf *src); +void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, + const struct trailer_conf *conf, + const struct new_trailer_item *new_trailer_item); + struct process_trailer_options { int in_place; int trim_empty; @@ -70,6 +77,12 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head, void process_trailers_lists(struct list_head *head, struct list_head *arg_head); +ssize_t find_separator(const char *line, const char *separators); + +void parse_trailer(const char *line, ssize_t separator_pos, + struct strbuf *tok, struct strbuf *val, + const struct trailer_conf **); + struct trailer_block *parse_trailers(const struct process_trailer_options *, const char *str, struct list_head *head); From patchwork Tue Feb 6 05:12:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546657 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 DBFF67A737 for ; Tue, 6 Feb 2024 05:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196375; cv=none; b=PHnHQuwmZVh2IsjRnwBUWyXlpaH2RwOG43ro48+2ibTkKfsXPycVgJn+PPqzd58ai+YdoFGu9Tm2rCCBR8s9ubWuJ4CR55bEXR2nb1lE0u4msCTfNjL2dn/aOGplUM0rjXlno4/GZMDz0bAjxbQkS873I+sejnmDOGWN3oOL53k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196375; c=relaxed/simple; bh=Tvoc962DK84h7XfF7yeSpNbE+8NFwvB32afkrqbKmWQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=OpnQH4lW+6azrurUTqi1u0kaDaWMReaAo08L6uI5THNI/scqdMdUy45G14Vw3jYgZ8qFMMi21YRe4kwdWWpJ5gs+7g9ZiK1tVN0sG9b2gKJQnEahLXxyVE1ouHWHxPjA1LjP19h2j7A/vOvCUGO6j2MxLqhfboqIEhwcFVQtF4o= 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=byEBuUjF; arc=none smtp.client-ip=209.85.128.43 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="byEBuUjF" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40fc654a718so32916145e9.2 for ; Mon, 05 Feb 2024 21:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196371; x=1707801171; 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=N6+NQd5nEV2eczt7YhKu1bosuM3eQgb4jedizSfu40Q=; b=byEBuUjF/ISZGM22BgQrt6dQcK3hN0zaQ9WB9tGhNOzGAgT/76ggtL4ZVWPEwiDNEz cV7hvKzhWmlWBsqdOs01vp3Rquko5HdTCzHoapd4s8D3DPwjsV5pLUSpo56RWp07dsZU mJAn1nxydwUPMInANbuMhoJg9f3/Fm9THgt0rpQndsgTfvDKsDLAmKAZkXGxIG69oZjM Qgdyyl8o1PYaJOOxIUkHRucQtcb+VSn/RjJar8oT4YQ9+syE0ozXtHUtxayDj8KIGmb1 tCyLpjchjz/HSFbh1t5h86N8zEilHa7mtrAuV7gn7OqxGP5Jv7vqHr3wc3SYuqwA4ohY f7Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196371; x=1707801171; 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=N6+NQd5nEV2eczt7YhKu1bosuM3eQgb4jedizSfu40Q=; b=FcHoqPzHcWBAoL2//c2D+6wEBEiojo+qQ/dLyDJPvRpzPMxoLSJ5boFJCdH4It6P8g h+gbgcYb7o5xdn1/Xd2gM7LwSlmwnTXQO66xrxi0VIFD5wRfLHIuaDJzKH6wCIGjzXYp 9NeaJ1XzmU4L1iviwkIEQP465VxbqXMhm+ZazQwxyNVgpNsmH84aU1usaJsTa8BpGiUM +TWp45wiqQG9bH4wdN+/d685UfzyxIU3i37Bnj4q0BeQT9hCNDcxnXGK6U/4Zgivm/47 QnrqOj0CpT8seO9AoobSUpEKppfZmMFtCVJ5LgLwCi5CjEHUqnSAvE2kZXQ6Zh98DRsU RnqQ== X-Gm-Message-State: AOJu0YxL/efoNr/VJdVZFPhMD465Dq0i4o8mcSmMZZcTeiyVZkUz5EXl fwBeYX0ZMocxKjfrewfNSe0Qx4v+tXxbPa9UFGcctc0dN5HECc821DKBy33/ X-Google-Smtp-Source: AGHT+IGvadSFOuQU9a2UtKEBxhCF2XPtFxEqNXaU+NfleMDKZXtk+tvvYw6R4Zv34p8i4sXCHIIJoA== X-Received: by 2002:a05:600c:4f54:b0:40f:dc51:1882 with SMTP id m20-20020a05600c4f5400b0040fdc511882mr1237560wmq.8.1707196371539; Mon, 05 Feb 2024 21:12:51 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXwzzUgqL7ob/r4BFIskt6377vcv9kBRwN4+HAjjawIxtmaPkOIv3+7KhL7y6bbwBPydP1/kCZQLKaW1wxL0V1rAVayzTrdqzpiHdTuEpIxcUNPLPHlvSFaAFA37TZ7IbRIEb5v7/E0IUYADCRWiFb1P9eAM1thiObsA1L6b9FU6giJq3Gn8w8MXFZtKLpwvBBS+bfI4Gi0Nw== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h8-20020a05600c314800b0040ee8765901sm641415wmo.43.2024.02.05.21.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:51 -0800 (PST) Message-ID: <3bfe4809ecbc5aa0ea52daee7684289398cb88d4.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:23 +0000 Subject: [PATCH v4 23/28] trailer: add new helper functions to 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is a preparatory refactor for deprecating "new_trailer_item" from the API (which will let us deprecate parse_trailers_from_command_line_args()). Expose new helper functions from the API, because we'll be calling them from interpret-trailers.c soon when we move parse_trailers_from_command_line_args() there. Move free_new_trailers() from the builtin to trailer.c because later on we will adjust it to free arg_item structs, which are private to trailer.c. Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 12 --------- trailer.c | 49 ++++++++++++++++++++++++++++++++++++ trailer.h | 8 ++++++ 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index f674b5f4b9e..9169c320921 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -45,18 +45,6 @@ static int option_parse_if_missing(const struct option *opt, return trailer_set_if_missing(opt->value, arg); } -static void free_new_trailers(struct list_head *trailers) -{ - struct list_head *pos, *tmp; - struct new_trailer_item *item; - - list_for_each_safe(pos, tmp, trailers) { - item = list_entry(pos, struct new_trailer_item, list); - list_del(pos); - free(item); - } -} - static int option_parse_trailer(const struct option *opt, const char *arg, int unset) { diff --git a/trailer.c b/trailer.c index 3b8f0ba103c..9b8cb94c021 100644 --- a/trailer.c +++ b/trailer.c @@ -66,6 +66,11 @@ static LIST_HEAD(conf_head); static char *separators = ":"; +const char *trailer_default_separators(void) +{ + return separators; +} + static int configured; #define TRAILER_ARG_STRING "$ARG" @@ -424,6 +429,29 @@ int trailer_set_if_missing(enum trailer_if_missing *item, const char *value) return 0; } +void trailer_set_conf_where(enum trailer_where where, + struct trailer_conf *conf) +{ + conf->where = where; +} + +void trailer_set_conf_if_exists(enum trailer_if_exists if_exists, + struct trailer_conf *conf) +{ + conf->if_exists = if_exists; +} + +void trailer_set_conf_if_missing(enum trailer_if_missing if_missing, + struct trailer_conf *conf) +{ + conf->if_missing = if_missing; +} + +struct trailer_conf *new_trailer_conf(void) +{ + return xcalloc(1, sizeof(struct trailer_conf)); +} + void duplicate_trailer_conf(struct trailer_conf *dst, const struct trailer_conf *src) { @@ -434,6 +462,15 @@ void duplicate_trailer_conf(struct trailer_conf *dst, dst->cmd = xstrdup_or_null(src->cmd); } +void free_trailer_conf(struct trailer_conf *conf) +{ + free(conf->name); + free(conf->key); + free(conf->command); + free(conf->cmd); + free(conf); +} + static struct arg_item *get_conf_item(const char *name) { struct list_head *pos; @@ -1076,6 +1113,18 @@ void free_trailers(struct list_head *trailers) } } +void free_new_trailers(struct list_head *trailers) +{ + struct list_head *pos, *tmp; + struct new_trailer_item *item; + + list_for_each_safe(pos, tmp, trailers) { + item = list_entry(pos, struct new_trailer_item, list); + list_del(pos); + free(item); + } +} + size_t trailer_block_start(struct trailer_block *trailer_block) { return trailer_block->start; diff --git a/trailer.h b/trailer.h index f80f8f7e63f..a2569c10451 100644 --- a/trailer.h +++ b/trailer.h @@ -46,8 +46,14 @@ struct new_trailer_item { enum trailer_if_missing if_missing; }; +void trailer_set_conf_where(enum trailer_where, struct trailer_conf *); +void trailer_set_conf_if_exists(enum trailer_if_exists, struct trailer_conf *); +void trailer_set_conf_if_missing(enum trailer_if_missing, struct trailer_conf *); + +struct trailer_conf *new_trailer_conf(void); void duplicate_trailer_conf(struct trailer_conf *dst, const struct trailer_conf *src); +const char *trailer_default_separators(void); void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, const struct trailer_conf *conf, const struct new_trailer_item *new_trailer_item); @@ -98,6 +104,8 @@ void format_trailers(const struct process_trailer_options *, struct list_head *trailers, struct strbuf *out); void free_trailers(struct list_head *); +void free_new_trailers(struct list_head *); +void free_trailer_conf(struct trailer_conf *); /* * Convenience function to format the trailers from the commit msg "msg" into From patchwork Tue Feb 6 05:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546658 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 1ECBE7F49D for ; Tue, 6 Feb 2024 05:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196376; cv=none; b=UaRBAVfTFGWwWdWvzZw9IlsZgRhGYGAsLErJ2EUjBpk02j4o2JVsdrD/ZuWPOhYIiJ3qIgVG7szfVRR0iZlfsdHnnkDMpLR61fu9kXy6cQj2xBP2PkwiZd83LVrNUM9RzfWAW6dNCLDKNoWxUMHm9IHoa+nQaOVdNUYwa1KqODM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196376; c=relaxed/simple; bh=g9UlVwtI1LDXpmXGclI49NRsg4MbiMGfDL1LQrY7AIo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Nr3/UKJg5PWPQ1fd9KwVYYo5L5So6Vw8aiy5Wjrm06D3k0BwRn6JK/x3GLrTE5uiZq5F7VSmI/dDyEGDf8Qc4ID2JVG0+7A1sjovCnmUwJ+oWTyu6doR2e7zxmiYQPdss4Kxn9e9KriHZwVGdRvoJNhLZjLU/b+ZsUtVnQuj9EQ= 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=dl8yVMps; arc=none smtp.client-ip=209.85.128.43 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="dl8yVMps" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40fd280421aso22400375e9.3 for ; Mon, 05 Feb 2024 21:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196372; x=1707801172; 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=MOREw6q372qtoCRNyAiB9WUVEqb0ov38KcUfz5lCeOg=; b=dl8yVMpsUXd0SEoZRXOOmuMZQjdH17lrrq3y9WSUmq+IXns4m3qWed4dusRtQsQKJm i5bN5yQ/vpbPIOeAGooYXMW/bSkBS3mPJa4jl9wTBp8RzV+UxvuYmOprknl03RQxwgnB 7YlsP4PS/We/Bccft40/iIERTRh1OnK6iu/Jk9ZoiQjs+2xiuWMbbv4iK3bwwn0vf3Lh opnOu4YmoEXKSdY57GUz61oOMincdJeNTu4kqfiRRuwTlseYxYYhIbX7KzqJP+v/CAdW rs77cbaD5LvU+WAaNZ1rnT8ypiDWQI7C4fAGlDEscXOtlT19mAEIHYHXTlL20KwEvomg 482A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196372; x=1707801172; 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=MOREw6q372qtoCRNyAiB9WUVEqb0ov38KcUfz5lCeOg=; b=Z3CI7HNLAZUrpLgWMvtslcO0EPGifNy48SFMS+YrL+5IAnGnWDr7fJdnuCQK4wKWLY ZnehYxNT60HwPTc2thkILCmXGiibbnlY2xe/YiJD8Z2yKugtBk+JN2ipaJCVDHTihN63 2v5ZG8jXUJm8/smxly46bOolhTL15o73bg2FZeBFMNEQHbg3cC+siQnRSjxmiEU72Om4 cWVJ2/pc64CByGIfv+LUJ7hsybcWO61IYcQK23AG/hseNFTAy3ma5Mp0/o0nk5kf6Ymi uupZQe/T3+0ZCo+Nfw7vOfyQ5Nrsw67HV3qH2yj8fLJMf2+ggrtR0BuWDJoKnYotf3QZ UaOw== X-Gm-Message-State: AOJu0YzrfxXe+2eGvnMINwMLt57fddORDa2wPRWec6R5rH1JWkV5vOLM WQ1ik6ciu+ADz+NBC6AjRE6HU2LxKarV6BgNM/O8wlwjwM6dx7XZsO5SjYBh X-Google-Smtp-Source: AGHT+IEPky0KU8N7zTF1zeZ1Zs9RLiX1/bo+GUbl+a8FrtmMnqOrPMzvp9uzvtHx5kuQ31g1lcaVOw== X-Received: by 2002:a05:600c:1551:b0:40f:24e:d480 with SMTP id f17-20020a05600c155100b0040f024ed480mr1170079wmg.18.1707196372691; Mon, 05 Feb 2024 21:12:52 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUjPceNVeSlbgrsOpz6VZxEsTrVv8jnFtBdw5iHmaYQaN1OQCtzvK1ly5EIECewzpd5wqmlMU15Tx/VWbgOu3ZtZswqffLQd3B/Fol0iqQoyj1FzUt6NlzV46G5awC29NLpfLM9O44RTDnbxk2RSjFP/Tt7R/frqAsvL4bgWJJ40LNekpOuXhBsfI1j1/Brv8+vF8zr4zh4jA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g19-20020a05600c4ed300b0040fd2f3dc0esm639458wmq.45.2024.02.05.21.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:51 -0800 (PST) Message-ID: <80e1958bb8d5d4e74fc9d4334b99d149ae2bcab1.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:24 +0000 Subject: [PATCH v4 24/28] trailer_add_arg_item(): drop new_trailer_item 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver This is a preparatory refactor for deprecating "new_trailer_item" from the API. Instead of preserving the where/if_exists/if_missing information inside the new_trailer_item struct in parse_trailers_from_command_line_args() (only to look inside it again later on in trailer_add_arg_item()), pass this information directly as a trailer_conf which trailer_add_arg_item() already knows how to handle. This reduces the number of parameters we have to pass to trailer_add_arg_item() without any behavioral change. In the next patch we'll be able to delete "new_trailer_item" altogether. Signed-off-by: Linus Arver --- trailer.c | 29 +++++++++++++++++------------ trailer.h | 3 +-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/trailer.c b/trailer.c index 9b8cb94c021..6ab5cf7e5d7 100644 --- a/trailer.c +++ b/trailer.c @@ -729,21 +729,12 @@ static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, } void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, - const struct trailer_conf *conf, - const struct new_trailer_item *new_trailer_item) + const struct trailer_conf *conf) { struct arg_item *new_item = xcalloc(1, sizeof(*new_item)); new_item->token = tok; new_item->value = val; duplicate_trailer_conf(&new_item->conf, conf); - if (new_trailer_item) { - if (new_trailer_item->where != WHERE_DEFAULT) - new_item->conf.where = new_trailer_item->where; - if (new_trailer_item->if_exists != EXISTS_DEFAULT) - new_item->conf.if_exists = new_trailer_item->if_exists; - if (new_trailer_item->if_missing != MISSING_DEFAULT) - new_item->conf.if_missing = new_trailer_item->if_missing; - } list_add_tail(&new_item->list, arg_head); } @@ -759,7 +750,7 @@ void parse_trailers_from_config(struct list_head *config_head) trailer_add_arg_item(config_head, xstrdup(token_from_item(item, NULL)), xstrdup(""), - &item->conf, NULL); + &item->conf); } } @@ -791,11 +782,25 @@ void parse_trailers_from_command_line_args(struct list_head *arg_head, (int) sb.len, sb.buf); strbuf_release(&sb); } else { + struct trailer_conf *conf_current = new_trailer_conf(); parse_trailer(tr->text, separator_pos, &tok, &val, &conf); + duplicate_trailer_conf(conf_current, conf); + + /* + * Override conf_current with settings specified via CLI flags. + */ + if (tr->where != WHERE_DEFAULT) + trailer_set_conf_where(tr->where, conf_current); + if (tr->if_exists != EXISTS_DEFAULT) + trailer_set_conf_if_exists(tr->if_exists, conf_current); + if (tr->if_missing != MISSING_DEFAULT) + trailer_set_conf_if_missing(tr->if_missing, conf_current); + trailer_add_arg_item(arg_head, strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL), - conf, tr); + conf_current); + free_trailer_conf(conf_current); } } diff --git a/trailer.h b/trailer.h index a2569c10451..32fc93beb33 100644 --- a/trailer.h +++ b/trailer.h @@ -55,8 +55,7 @@ void duplicate_trailer_conf(struct trailer_conf *dst, const struct trailer_conf *src); const char *trailer_default_separators(void); void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, - const struct trailer_conf *conf, - const struct new_trailer_item *new_trailer_item); + const struct trailer_conf *conf); struct process_trailer_options { int in_place; From patchwork Tue Feb 6 05:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546659 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 B00C77F7C4 for ; Tue, 6 Feb 2024 05:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196377; cv=none; b=S2Aw8pg1Z0xn6qOi1+TB1JPAEoRNI8yk3IEig5+A7s09Drzs97mW/QOqIE1FH1IKf1/bsOmOE/aAHUTXnDBz8MuIkSfmcuVpYn6KyQfk+IZU0oVwdPhh22cQakTFvh2rf7UYiKOwLZXM19RMF5GZkjutKeowoIAfjdoQP4R3Vgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196377; c=relaxed/simple; bh=rNuRlQZTLSbeS2GM2ocNousd05NDbYtnIeWdJKaGJrQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=BUSKgH+5MzdCBNEun3Ngiwvcoem3XVx0Y2BXh4etCDUPDeubCglYbqf2UyPr0pnB1pp7iUcD3aEeSphMVeQqP1lBbLLDcq/qksIz8tiWzUENVHOflbTGp7E3u+NVJnqZzFqXxGEs2zD876Ds2Kxd1wQcyqPA0pYgIyla31R4iiw= 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=R9WLGGYF; arc=none smtp.client-ip=209.85.128.45 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="R9WLGGYF" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40fd280421aso22400405e9.3 for ; Mon, 05 Feb 2024 21:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196374; x=1707801174; 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=Y9YbuTac7HerLgW3Z92WF4EFJF1mMxRQHEPVw3mxxg8=; b=R9WLGGYFHHAfEexyzObP3m7mRE5cF5OTi52qsOdyCSxiV8o52YkPa3BDDJQRqw/R55 uvODk9r1rrYtlFIfWSlu5pMx6XM7+ybp4pUOAQ0U6AZlMbsEyfGjZZZC3KSER34+PRIs 4ZjC+OFbSsMjP7k8Gs0CqhTWyhex2+gy96AogXIqY/3z/wPxaEoffUo3PRCsnUss0wi3 bbByx12Nw5UdicOylYMgecuyIU4qTuD5kkd6l/LghdUPan/eWCwDB9qTlqldSyJhS/qz 6HpGpYJIj5Xkb8nD6bGOjexPL4EEZFWy2Sgsh+yeCmSJFWS3xHD/1/MNU2bssizUVust 4EHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196374; x=1707801174; 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=Y9YbuTac7HerLgW3Z92WF4EFJF1mMxRQHEPVw3mxxg8=; b=viuuOYuNKqOB8iX8u9OdKBx9femw1Ns9a2BZRxPcVAwBlATYm3HkFtekQ2dD5Y20vR l9Qy6tck6Rrxzah2cgZXvceH233OUv7jNWlP9bUM1n1QIRY5TenYbcq7yDdQfV2Pnf2t V128SW54zslbVRXipO/KNCDQhYod8N/5ZceEiMecLhOGyxWJDQtj/fpdsUZuFHrs4dbm e6HlKwDHXgaTlcSalzEbLPvUhObcYM6z4nYb0oW2CnSuO0VWoztPgJMGNzVwxGH6cKgG pmpT0Qb9SYHJX9XHU7iHw+FLMNnSdOg2WlDIcTu3Z76s2UJNhpn2pjgOpPNHlMHoLNeo wnCA== X-Gm-Message-State: AOJu0YwcuIKKybkw1PPPcsYDmN/TFmuo5U/601dYvCx7XEUQMMLGV/xX X6HNt2/AF0O4G3yqLtKPuC9QHCabFHQgf/cBgB5Qs2hR/Dg4rXdXyORbmczU X-Google-Smtp-Source: AGHT+IHSIqsuL2VWazlUSBeM8y/uyDmr+56u7iFaDd6D4ZpjwnUZKt5hXurYo34XhmLj8L6EUMbAWA== X-Received: by 2002:a05:600c:19c8:b0:40f:b691:d3c1 with SMTP id u8-20020a05600c19c800b0040fb691d3c1mr1101687wmq.30.1707196373820; Mon, 05 Feb 2024 21:12:53 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXHB0UlTB/JO+8WTG3riV1ghR2c5HsYP4VaLCKwztxSsWxKJJ5tTb/fcsb4R3VaVT+fFR4+vtF+MR5tq2QWUu+0EKUIWJnhS2HyB0xCsCVAvaVHZNhcw+9SWYFzLR8b88q4Q/W6kO1bc7m66pzhr+AmOKShjzOoYlTsd4dN47CxMo5bbYip+PyrggzGZWF8fGif3lQswrUB3g== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c020800b0040faf3df118sm642998wmi.32.2024.02.05.21.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:53 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:25 +0000 Subject: [PATCH v4 25/28] trailer: deprecate "new_trailer_item" struct from 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Previously, the "new_trailer_item" struct served only one purpose --- to capture the unparsed raw string in "--trailer ", as well as the current state of the "where", "if_exists", and "if_missing" global variables at the time that the "--trailer " CLI argument was encountered. In addition, the previous CLI argument handling behavior was to capture the string in all "--trailer " arguments and to collect them (via option_parse_trailer()) into the "new_trailer_head" list. We would then iterate over this list again in parse_trailers_from_command_line_args() and convert these "new_trailer_item" objects into "arg_item" objects. Skip this intermediate storage of "new_trailer_item" objects in favor of just storing "arg_item" objects. Remove the looping behavior of parse_trailers_from_command_line_args() so that it parses a single "--trailer ..." argument at a time. Rename it to parse_trailer_from_command_line_arg() to reflect this new behavior of only looking at one string (not multiple strings) at a time. Make option_parse_trailer() call parse_trailer_from_command_line_arg() so that the CLI arguments it sees are parsed immediately without the need for intermediate storage. Delete "new_trailer_item", because we don't need it any more. In the next patch we will retire parse_trailer_from_command_line_arg() as well, combining it with option_parse_trailer(). Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 29 +++++-------- trailer.c | 81 +++++++++++++++++------------------- trailer.h | 21 +++------- 3 files changed, 54 insertions(+), 77 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 9169c320921..943be5b360e 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -49,7 +49,6 @@ static int option_parse_trailer(const struct option *opt, const char *arg, int unset) { struct list_head *trailers = opt->value; - struct new_trailer_item *item; if (unset) { free_new_trailers(trailers); @@ -59,12 +58,8 @@ static int option_parse_trailer(const struct option *opt, if (!arg) return -1; - item = xmalloc(sizeof(*item)); - item->text = arg; - item->where = where; - item->if_exists = if_exists; - item->if_missing = if_missing; - list_add_tail(&item->list, trailers); + parse_trailer_from_command_line_arg(arg, where, if_exists, if_missing, trailers); + return 0; } @@ -132,8 +127,6 @@ static void interpret_trailers(const struct process_trailer_options *opts, struct trailer_block *trailer_block; FILE *outfile = stdout; - trailer_config_init(); - read_input_file(&sb, file); if (opts->in_place) @@ -148,15 +141,8 @@ static void interpret_trailers(const struct process_trailer_options *opts, if (!opts->only_trailers && !blank_line_before_trailer_block(trailer_block)) 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); - } + if (!opts->only_input) + process_trailers_lists(&head, new_trailer_head); /* Print trailer block. */ format_trailers(opts, &head, &tb); @@ -180,6 +166,7 @@ static void interpret_trailers(const struct process_trailer_options *opts, int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) { struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; + LIST_HEAD(configured_trailers); LIST_HEAD(trailers); struct option options[] = { @@ -205,6 +192,10 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); + trailer_config_init(); + + if (!opts.only_input) + parse_trailers_from_config(&configured_trailers); argc = parse_options(argc, argv, prefix, options, git_interpret_trailers_usage, 0); @@ -215,6 +206,8 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) git_interpret_trailers_usage, options); + list_splice(&configured_trailers, &trailers); + if (argc) { int i; for (i = 0; i < argc; i++) diff --git a/trailer.c b/trailer.c index 6ab5cf7e5d7..0893175553a 100644 --- a/trailer.c +++ b/trailer.c @@ -754,57 +754,54 @@ 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 parse_trailer_from_command_line_arg(const char *line, + enum trailer_where where, + enum trailer_if_exists if_exists, + enum trailer_if_missing if_missing, + struct list_head *arg_head) { struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; const struct trailer_conf *conf; - struct list_head *pos; /* * In command-line arguments, '=' is accepted (in addition to the * separators that are defined). */ - char *cl_separators = xstrfmt("=%s", separators); + char *cl_separators = xstrfmt("=%s", trailer_default_separators()); - /* Add an arg item for each trailer on the command line */ - list_for_each(pos, new_trailer_head) { - struct new_trailer_item *tr = - list_entry(pos, struct new_trailer_item, list); - ssize_t separator_pos = find_separator(tr->text, cl_separators); + /* Add an arg item for a trailer from the command line */ + ssize_t separator_pos = find_separator(line, cl_separators); + free(cl_separators); - if (separator_pos == 0) { - struct strbuf sb = STRBUF_INIT; - strbuf_addstr(&sb, tr->text); - strbuf_trim(&sb); - error(_("empty trailer token in trailer '%.*s'"), - (int) sb.len, sb.buf); - strbuf_release(&sb); - } else { - struct trailer_conf *conf_current = new_trailer_conf(); - parse_trailer(tr->text, separator_pos, &tok, &val, &conf); - duplicate_trailer_conf(conf_current, conf); + if (separator_pos == 0) { + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(&sb, line); + strbuf_trim(&sb); + error(_("empty trailer token in trailer '%.*s'"), + (int) sb.len, sb.buf); + strbuf_release(&sb); + } else { + struct trailer_conf *conf_current = new_trailer_conf(); + parse_trailer(line, separator_pos, &tok, &val, &conf); + duplicate_trailer_conf(conf_current, conf); - /* - * Override conf_current with settings specified via CLI flags. - */ - if (tr->where != WHERE_DEFAULT) - trailer_set_conf_where(tr->where, conf_current); - if (tr->if_exists != EXISTS_DEFAULT) - trailer_set_conf_if_exists(tr->if_exists, conf_current); - if (tr->if_missing != MISSING_DEFAULT) - trailer_set_conf_if_missing(tr->if_missing, conf_current); - - trailer_add_arg_item(arg_head, - strbuf_detach(&tok, NULL), - strbuf_detach(&val, NULL), - conf_current); - free_trailer_conf(conf_current); - } + /* + * Override conf_current with settings specified via CLI flags. + */ + if (where != WHERE_DEFAULT) + trailer_set_conf_where(where, conf_current); + if (if_exists != EXISTS_DEFAULT) + trailer_set_conf_if_exists(if_exists, conf_current); + if (if_missing != MISSING_DEFAULT) + trailer_set_conf_if_missing(if_missing, conf_current); + + trailer_add_arg_item(arg_head, + strbuf_detach(&tok, NULL), + strbuf_detach(&val, NULL), + conf_current); + free_trailer_conf(conf_current); } - - free(cl_separators); } static const char *next_line(const char *str) @@ -1120,13 +1117,11 @@ void free_trailers(struct list_head *trailers) void free_new_trailers(struct list_head *trailers) { - struct list_head *pos, *tmp; - struct new_trailer_item *item; + struct list_head *pos, *p; - list_for_each_safe(pos, tmp, trailers) { - item = list_entry(pos, struct new_trailer_item, list); + list_for_each_safe(pos, p, trailers) { list_del(pos); - free(item); + free_arg_item(list_entry(pos, struct arg_item, list)); } } diff --git a/trailer.h b/trailer.h index 32fc93beb33..2848a0d086c 100644 --- a/trailer.h +++ b/trailer.h @@ -32,20 +32,6 @@ int trailer_set_where(enum trailer_where *item, const char *value); int trailer_set_if_exists(enum trailer_if_exists *item, const char *value); int trailer_set_if_missing(enum trailer_if_missing *item, const char *value); -/* - * A list that represents newly-added trailers, such as those provided - * with the --trailer command line option of git-interpret-trailers. - */ -struct new_trailer_item { - struct list_head list; - - const char *text; - - enum trailer_where where; - enum trailer_if_exists if_exists; - enum trailer_if_missing if_missing; -}; - void trailer_set_conf_where(enum trailer_where, struct trailer_conf *); void trailer_set_conf_if_exists(enum trailer_if_exists, struct trailer_conf *); void trailer_set_conf_if_missing(enum trailer_if_missing, struct trailer_conf *); @@ -76,8 +62,11 @@ struct process_trailer_options { 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 parse_trailer_from_command_line_arg(const char *line, + enum trailer_where where, + enum trailer_if_exists if_exists, + enum trailer_if_missing if_missing, + struct list_head *arg_head); void process_trailers_lists(struct list_head *head, struct list_head *arg_head); From patchwork Tue Feb 6 05:12:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546660 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 B3AE47F7CE for ; Tue, 6 Feb 2024 05:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196378; cv=none; b=YE/+TJdfWnpLcXf1litVG+JwTGft2JY4f8mcHY9YfrmVUTjV7io8nx7ycHVa1zPmnS8fwJxHBAPL+IVF2dsPkGdVQmDdl6sUxcOU9lo6Ux21WBmzOFvcEypcdAEMPYOYlTXU4sluIdJbHWl+5c26Dt2RRJOPxwYK+U5bc1Gn2w0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196378; c=relaxed/simple; bh=BuQAR+jkxrONEeSjMqIA8PGIumwHlVSGcCn9KO9rHo4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=CkqWanChyJSk+rZc8cXNneVy9utxDFYMgxZVgX9fpu7bMXaOJkaBrk2vJBEuYOpky3KJ6E/Yx9d5omJN5R0e5FCr/3OtSBznUju4QkM61ksA8yghe0A/0lSAx5lQzr6lm+1uMkoi2XDEdx4bnY3qKL/bktOiO36J7VppIcMUnAs= 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=hXVv2uY5; arc=none smtp.client-ip=209.85.128.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="hXVv2uY5" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40fd280421aso22400475e9.3 for ; Mon, 05 Feb 2024 21:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196375; x=1707801175; 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=DbYSM0cx3UEb9I9IhPru1zYtRMz/t9vgM512SrneoUg=; b=hXVv2uY5wfKj93BukmxIxXBRw64qyu9ONjbtoETM8vSTMGf/PyiFDbkly7FrW9AsLB /QkxsXoBF3ReDXH3Q+e8+ha4BLE/pjp1V0ba/LoVUQePWF3/LgqtTcT5bniCeP5JQW/P mdsOCCF7Gm6dTEDnZEMW6qZYO5S/LQzljocYfjLtq0RhLxV1UAETP2FLwXNHB8Jy9Cyd aR1s3iWhh9hXMf/chgCOqghaRwfBtZPu8dLXOx5Cpw5uh+XkxYtFXwlxIAv/cmsp57oE a5N39kGMtxkRJTOsxm0s9G26d+3tFjjaUTy/+MneDjpJeuB0OOVntyNpB6VPsidjr5jB 7gvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196375; x=1707801175; 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=DbYSM0cx3UEb9I9IhPru1zYtRMz/t9vgM512SrneoUg=; b=kutXuDmHdIZHVxB3Eq5dYKTwmsrdUe+/XoO00JYT9C8bdWSGpRft2XIuqwGS/dpdf0 KxgKb03counEDktGq9/q5RNnbZJ5kLw4SgNuzcvlb/+nERNmmLXLjXR5J96QMOAu0ARt lBYxVsHS9jmJuezp4KBFJis3xayCvaXH5KWq9VIC52QmIdXYsGkY3Q+UqAHEkkUEQmQd WRcqfz+B45+jULbbOIFQcZMpI+2iz9XS2J3ZwCKBAuuXGX4xpFa8512qyM6K6hFYQ7XD CkL4QObVJcvslzZOoDgLTqqjdHHmVbD1uwF1mNQjcKQxaz7fH7Yh9TjDmSAuPiy43Bvq 8W2Q== X-Gm-Message-State: AOJu0YwnktTqD6OUec1bishCF6gXyZuvCNNsXsf05YwYsOaF99NMT/HS v4V/ys0DKN3L7Dak6uj8L9/x2JnTGUhCZ28qUWZKew+CxxI7kCsyD9wFbV19 X-Google-Smtp-Source: AGHT+IG4tL5o7udfnYJgR5/j5fPzdtgipXdWMS23amvibMvTgyJb+NnvRdIs+eb5vZTPQs7ANHpp1g== X-Received: by 2002:a05:600c:5254:b0:40f:d2f7:6e34 with SMTP id fc20-20020a05600c525400b0040fd2f76e34mr1129082wmb.33.1707196374566; Mon, 05 Feb 2024 21:12:54 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWAfjsOa/jz54c1Iwbve2ToiTdOJ/Wz01pWjEYz7ccuVs6h9HcerpPchkNn/iYT6liQmVkrrjzd+8w2FmWQjVXPPHgq/Wp4rNeszGcuL04LxkuRk/xJ3M3ensSuaP/Tc5U08bT1c6WZ0FiIfakv2AdJ/LSVwhr5CE7fVRF2v45KiwCOJstACqZgbG0TvbEO1H5zmwp5e0PJ5Q== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id fs20-20020a05600c3f9400b0040fd3d8ce5csm638823wmb.16.2024.02.05.21.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:54 -0800 (PST) Message-ID: <9720526dd8a63b916c75fe9d6322ee13c8b36621.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:26 +0000 Subject: [PATCH v4 26/28] trailer: unify "--trailer ..." arg handling 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver Move the logic of parse_trailer_from_command_line_arg() into option_parse_trailer(), because that is the only caller and there's no benefit in keeping these two separate. Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 42 +++++++++++++++++++++++++++++- trailer.c | 50 ------------------------------------ trailer.h | 6 ----- 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 943be5b360e..9657b0d067c 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -49,6 +49,11 @@ static int option_parse_trailer(const struct option *opt, const char *arg, int unset) { struct list_head *trailers = opt->value; + struct strbuf tok = STRBUF_INIT; + struct strbuf val = STRBUF_INIT; + const struct trailer_conf *conf; + ssize_t separator_pos; + static char *cl_separators; if (unset) { free_new_trailers(trailers); @@ -58,7 +63,42 @@ static int option_parse_trailer(const struct option *opt, if (!arg) return -1; - parse_trailer_from_command_line_arg(arg, where, if_exists, if_missing, trailers); + /* + * In command-line arguments, '=' is accepted (in addition to the + * separators that are defined). + */ + cl_separators = xstrfmt("=%s", trailer_default_separators()); + separator_pos = find_separator(arg, cl_separators); + free(cl_separators); + + if (separator_pos == 0) { + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(&sb, arg); + strbuf_trim(&sb); + error(_("empty trailer token in trailer '%.*s'"), + (int) sb.len, sb.buf); + strbuf_release(&sb); + } else { + struct trailer_conf *conf_current = new_trailer_conf(); + parse_trailer(arg, separator_pos, &tok, &val, &conf); + duplicate_trailer_conf(conf_current, conf); + + /* + * Override conf_current with settings specified via CLI flags. + */ + if (where != WHERE_DEFAULT) + trailer_set_conf_where(where, conf_current); + if (if_exists != EXISTS_DEFAULT) + trailer_set_conf_if_exists(if_exists, conf_current); + if (if_missing != MISSING_DEFAULT) + trailer_set_conf_if_missing(if_missing, conf_current); + + trailer_add_arg_item(trailers, + strbuf_detach(&tok, NULL), + strbuf_detach(&val, NULL), + conf_current); + free_trailer_conf(conf_current); + } return 0; } diff --git a/trailer.c b/trailer.c index 0893175553a..b0b067ab12c 100644 --- a/trailer.c +++ b/trailer.c @@ -754,56 +754,6 @@ void parse_trailers_from_config(struct list_head *config_head) } } -void parse_trailer_from_command_line_arg(const char *line, - enum trailer_where where, - enum trailer_if_exists if_exists, - enum trailer_if_missing if_missing, - struct list_head *arg_head) -{ - struct strbuf tok = STRBUF_INIT; - struct strbuf val = STRBUF_INIT; - const struct trailer_conf *conf; - - /* - * In command-line arguments, '=' is accepted (in addition to the - * separators that are defined). - */ - char *cl_separators = xstrfmt("=%s", trailer_default_separators()); - - /* Add an arg item for a trailer from the command line */ - ssize_t separator_pos = find_separator(line, cl_separators); - free(cl_separators); - - if (separator_pos == 0) { - struct strbuf sb = STRBUF_INIT; - strbuf_addstr(&sb, line); - strbuf_trim(&sb); - error(_("empty trailer token in trailer '%.*s'"), - (int) sb.len, sb.buf); - strbuf_release(&sb); - } else { - struct trailer_conf *conf_current = new_trailer_conf(); - parse_trailer(line, separator_pos, &tok, &val, &conf); - duplicate_trailer_conf(conf_current, conf); - - /* - * Override conf_current with settings specified via CLI flags. - */ - if (where != WHERE_DEFAULT) - trailer_set_conf_where(where, conf_current); - if (if_exists != EXISTS_DEFAULT) - trailer_set_conf_if_exists(if_exists, conf_current); - if (if_missing != MISSING_DEFAULT) - trailer_set_conf_if_missing(if_missing, conf_current); - - trailer_add_arg_item(arg_head, - strbuf_detach(&tok, NULL), - strbuf_detach(&val, NULL), - conf_current); - free_trailer_conf(conf_current); - } -} - static const char *next_line(const char *str) { const char *nl = strchrnul(str, '\n'); diff --git a/trailer.h b/trailer.h index 2848a0d086c..af55032625d 100644 --- a/trailer.h +++ b/trailer.h @@ -62,12 +62,6 @@ struct process_trailer_options { void parse_trailers_from_config(struct list_head *config_head); -void parse_trailer_from_command_line_arg(const char *line, - enum trailer_where where, - enum trailer_if_exists if_exists, - enum trailer_if_missing if_missing, - struct list_head *arg_head); - void process_trailers_lists(struct list_head *head, struct list_head *arg_head); From patchwork Tue Feb 6 05:12:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546661 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 C4C6F7F7E3 for ; Tue, 6 Feb 2024 05:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196379; cv=none; b=eojyPQxpGFv6WuSu7gMoQzAliyA0l1OxrE5poYJMHcv3nOFlGinBgWi6lMbChsRq1HteS9z3aaRVmduoHFeoOQ5T871So5HEK19vYZf0UTbHTXO2CbQdg9+uDpwOAq2K5YQYcHCFXnTwQJDTof5XDjAScOiMqbvfwNuB9jZP9zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196379; c=relaxed/simple; bh=4ojxVCLvl/0BVMM4BAtn7SlHZ2bqCKXcmT1eehLO8qw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=XUmd6MZi+d20DV9YdkbrZf2ygiY58ooC1a4rMjvYKwXanh3KDIE8SJxFx6qvrvPmLp9K6DTRWvXU6bMjXGuQlHudrND9z71+igxnoBVkkpcUZ1vWbWtuLoRQH6T5qy8DQ6oNjEy8qOQjle793oRBASNtFPnpKQ80EjFoxe0ovi0= 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=UwA1O7uk; arc=none smtp.client-ip=209.85.128.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="UwA1O7uk" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40fdb18ffc7so15725535e9.1 for ; Mon, 05 Feb 2024 21:12:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196375; x=1707801175; 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=6VV0U3+FYAd67IGQzkTU0p/Z66m/307SlJ71XzJ+kPw=; b=UwA1O7ukTHRQxC/Rzv7KTiN/65J7Pb3N6phVLZqjuff2kseUWx9jEf20G9H/5vrmTH ZnxvFbt88JlJPPdHSlVKWHLDekdvo7FU213WnZhC3p/EfqvAUBg9r2DGZCuvyEgH1xsg bYz+7RMxPosrREdxCYlp3B6y3EwTLjwModygjMfF1sEQtKc13R5kZIMieqp7q1EYtTUf xeHKWl4WIIGg0SY4jgHhj+DNRlENZv3mVsYAVI6OIiae6A1aTyBebRe5YkhiceGZsXO5 WK7/bVTeVI4dXgn8qXJFyky3OsLAdI1Kw0M7uCs55UkIqdDn0gwBoEnk2jfvylq3t+vC 5+tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196375; x=1707801175; 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=6VV0U3+FYAd67IGQzkTU0p/Z66m/307SlJ71XzJ+kPw=; b=ZVtIlA1Io8mwWI/nGPG5k99THKQ32CRey5pTzMF+uieSU+DMvfxw1f1wjXMrh9HkOK vPdjJb8Tu5L58sXZh/TJlEScMiodf066fZz72U6TrByBPsVAI9xyGqZ/n+qaCIZHt1xz 02dX+lNEiSzFYmxYEHTmlaF0pVL/0vXbU5PozoXfQqyLE8iCqqggXEQNRaSm5eOvh5DN /OZry4pnnkq39tJKp3B1bLdMLyVBoQzPACSCU/MdGjW+ZCaQlSTdy6Fa7HDy10d/JfnO vSU2fu25Zx/SSuzkLayVc5FAdJN7jSqEvUsFVz4SIzbELcOceHxfmrCcgnBi5AyCHYGs lckw== X-Gm-Message-State: AOJu0YxYPO0iwT1If7Aku28s5un0q/cZq8Z5LkxMT0q6e7yfy0SJ3jbv tuFQOcc3riKZwby5D74l3LC9OjlQE2CFtEh8Cta8QjyvjCatE+HwGUL1HMcV X-Google-Smtp-Source: AGHT+IGm1wb5jBJ7DLClnzo8U1XPC2td2KQzlUioukiCQLUqi4wZCuQMBkjETMkPgV3h+eozCZaT6g== X-Received: by 2002:a05:600c:4fcf:b0:40e:f111:f259 with SMTP id o15-20020a05600c4fcf00b0040ef111f259mr642254wmq.37.1707196375401; Mon, 05 Feb 2024 21:12:55 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVs7ht76je91G62MrWQA2lscBNKY6j58QZfSu6Kb5qDIw7OwnO183kNUtGVsnrWs7kxcXBgd3F/ZU7nsCDuAwm9Pe+FXbJ9hlubdwIjZwtDsRmJnziPW3XiqyGqup/XoOD7rtY5YPeMxOrFh5Rzx4rQseEDUJ6rkBuQTTBtebdqSr2hzf7TDzaAHKm1uyAuw5CVXwZ2qP6eHA== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t9-20020a05600c450900b0040fa661ee82sm653438wmo.44.2024.02.05.21.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:54 -0800 (PST) Message-ID: <26df2514acbf4d51f40f4b1b9f33a357fa424ac7.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:27 +0000 Subject: [PATCH v4 27/28] trailer_set_*(): put out parameter at the end 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver The new trailer_config_set_*() functions which were introduced a few patches ago put the out parameter (the variable being mutated) at the end of the parameter list. Put the out parameter at the end for these functions for these existing trailer_set_*() functions for consistency. This also avoids confusion for API users because otherwise these two sets of functions look rather similar in even though they have completely different out parameters. Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 6 +++--- trailer.c | 24 ++++++++++++------------ trailer.h | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 9657b0d067c..d0c09d1d73b 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -28,21 +28,21 @@ static int option_parse_where(const struct option *opt, const char *arg, int unset UNUSED) { /* unset implies NULL arg, which is handled in our helper */ - return trailer_set_where(opt->value, arg); + return trailer_set_where(arg, opt->value); } static int option_parse_if_exists(const struct option *opt, const char *arg, int unset UNUSED) { /* unset implies NULL arg, which is handled in our helper */ - return trailer_set_if_exists(opt->value, arg); + return trailer_set_if_exists(arg, opt->value); } static int option_parse_if_missing(const struct option *opt, const char *arg, int unset UNUSED) { /* unset implies NULL arg, which is handled in our helper */ - return trailer_set_if_missing(opt->value, arg); + return trailer_set_if_missing(arg, opt->value); } static int option_parse_trailer(const struct option *opt, diff --git a/trailer.c b/trailer.c index b0b067ab12c..7b0bdfcb27e 100644 --- a/trailer.c +++ b/trailer.c @@ -380,7 +380,7 @@ void process_trailers_lists(struct list_head *head, } } -int trailer_set_where(enum trailer_where *item, const char *value) +int trailer_set_where(const char *value, enum trailer_where *item) { if (!value) *item = WHERE_DEFAULT; @@ -397,7 +397,7 @@ int trailer_set_where(enum trailer_where *item, const char *value) return 0; } -int trailer_set_if_exists(enum trailer_if_exists *item, const char *value) +int trailer_set_if_exists(const char *value, enum trailer_if_exists *item) { if (!value) *item = EXISTS_DEFAULT; @@ -416,7 +416,7 @@ int trailer_set_if_exists(enum trailer_if_exists *item, const char *value) return 0; } -int trailer_set_if_missing(enum trailer_if_missing *item, const char *value) +int trailer_set_if_missing(const char *value, enum trailer_if_missing *item) { if (!value) *item = MISSING_DEFAULT; @@ -520,18 +520,18 @@ static int git_trailer_default_config(const char *conf_key, const char *value, variable_name = strrchr(trailer_item, '.'); if (!variable_name) { if (!strcmp(trailer_item, "where")) { - if (trailer_set_where(&default_trailer_conf.where, - value) < 0) + if (trailer_set_where(value, + &default_trailer_conf.where) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); } else if (!strcmp(trailer_item, "ifexists")) { - if (trailer_set_if_exists(&default_trailer_conf.if_exists, - value) < 0) + if (trailer_set_if_exists(value, + &default_trailer_conf.if_exists) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); } else if (!strcmp(trailer_item, "ifmissing")) { - if (trailer_set_if_missing(&default_trailer_conf.if_missing, - value) < 0) + if (trailer_set_if_missing(value, + &default_trailer_conf.if_missing) < 0) warning(_("unknown value '%s' for key '%s'"), value, conf_key); } else if (!strcmp(trailer_item, "separators")) { @@ -600,15 +600,15 @@ static int git_trailer_config(const char *conf_key, const char *value, conf->cmd = xstrdup(value); break; case TRAILER_WHERE: - if (trailer_set_where(&conf->where, value)) + if (trailer_set_where(value, &conf->where)) warning(_("unknown value '%s' for key '%s'"), value, conf_key); break; case TRAILER_IF_EXISTS: - if (trailer_set_if_exists(&conf->if_exists, value)) + if (trailer_set_if_exists(value, &conf->if_exists)) warning(_("unknown value '%s' for key '%s'"), value, conf_key); break; case TRAILER_IF_MISSING: - if (trailer_set_if_missing(&conf->if_missing, value)) + if (trailer_set_if_missing(value, &conf->if_missing)) warning(_("unknown value '%s' for key '%s'"), value, conf_key); break; default: diff --git a/trailer.h b/trailer.h index af55032625d..4193bedbae4 100644 --- a/trailer.h +++ b/trailer.h @@ -28,9 +28,9 @@ enum trailer_if_missing { MISSING_DO_NOTHING }; -int trailer_set_where(enum trailer_where *item, const char *value); -int trailer_set_if_exists(enum trailer_if_exists *item, const char *value); -int trailer_set_if_missing(enum trailer_if_missing *item, const char *value); +int trailer_set_where(const char *, enum trailer_where *); +int trailer_set_if_exists(const char *, enum trailer_if_exists *); +int trailer_set_if_missing(const char *, enum trailer_if_missing *); void trailer_set_conf_where(enum trailer_where, struct trailer_conf *); void trailer_set_conf_if_exists(enum trailer_if_exists, struct trailer_conf *); From patchwork Tue Feb 6 05:12:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver X-Patchwork-Id: 13546662 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 8B0517F7EB for ; Tue, 6 Feb 2024 05:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196382; cv=none; b=RW+KfsyoJ+EsdzDhgp+ChZbeaneN04sg0LBuGRqENKPqEocoX1x9dW5etgiX69KghH23FGG90oUYR8svqknGMWgr70veq7W3cQktVRINUlgLdrVqstWbVCrw1PQ33BGqbS+1pzY7zwRIedCW+O9UqXDtN0Trh0yZMgt3+sTqgmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707196382; c=relaxed/simple; bh=HqdNNuOgcRUWIv4Bu3L5mG+r+C1sEdxhxaniETYFe+A=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=RPVa3ovRWr/VDVMmchOHCURm3ePnh4VLhu7OPDdrOwUGFrmXATNLt0sYLEu9psYK/CsNZZd6MHctoDmP7Q4+ZzPNrzaA1sRYmuMSEANVG/ThmozF3fmDJMYWOS2gtNhL0iP2glzGnQTlgk21dIdsRrFzaZ015kuVJ2WxSfRLrhY= 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=DaWObl4o; arc=none smtp.client-ip=209.85.221.45 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="DaWObl4o" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33b28aadb28so2018733f8f.3 for ; Mon, 05 Feb 2024 21:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707196376; x=1707801176; 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=elLYb457565nc6G7ZZ9IQ5rTIuXVp4ECY0kiErw5pvg=; b=DaWObl4oYAOPEGqwlbVTiE3hMvulZ83DmDwcjLeQP7j5tR9knz3nUjY0cHUiU1L2XO xvIVM5JN0GiKJ2MBN82qssaGf8PBJsVC3irNoPeB2XSgnSnOLus008zeFFC4rBTLYZW8 E6hnojBBVUC/zPhGhDVw9bBsPSnO1TENGnNb/QXtWXZiP0EKAKP0BPrJgXyoDz1pd6wO RYI3RpJQDJHt0K3VaJvD2EuUOR56724ZZwbkxeeS42tV7sDZcnXVD2U8DygjEYYYShZy Hu8llCq5pP02R92awRAYnvuOZeXNMkceevQu+srBW+JzXNDl1IqfVOM5aMTIX4aw9LU3 ayRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707196376; x=1707801176; 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=elLYb457565nc6G7ZZ9IQ5rTIuXVp4ECY0kiErw5pvg=; b=rM5VSg8iTtCJKwQGupMwmdz2YO7UywtPoevNzGR9uK4hxBLdxirR2QtXbuAG0ZTfOY K8GgvYHrpGSJSQ/CTdr0nyebyQ8rXH3t7oQHf3/dophODMy9qnRL4zT4QD2w3uYStS9F OiLQGWljPmMSrKszD3AP9IAuTbVTbDzg7FvWP6QVuuxGAX0zKVdIltdgembFaVPFbwW5 u+WVOjN3ydLMYG8yqU4Qr3GKumL/q/9qph/A+P3IPZe1wfqzxRwVyFtrUqVdjhAGBLNK AkEtPyy/FwU7JnnYxwmmsh9JZkIlcx7g9dxPOeUYsz6iEuHbA7ticWeGJBci9DeOiSpQ zoEQ== X-Gm-Message-State: AOJu0Yx7AiIiOiPpVRSY5KRHCsp3UqUsiE84DcTf4lwPzMBFMn0rtnGP 1ajiIc3MFiPvIZ5M7+nrPRn28+jsfBLvG6RIif2gk6beAh0HbY9hP62C51B6 X-Google-Smtp-Source: AGHT+IHVdZ6ZYCy5kW3kI2gMJP55m3YP2R/vcWxax4GtBsMwYUZ55CyUmaiW6eRdIus8Fbnkruac0w== X-Received: by 2002:a5d:4b8e:0:b0:33b:1763:947d with SMTP id b14-20020a5d4b8e000000b0033b1763947dmr411858wrt.2.1707196376544; Mon, 05 Feb 2024 21:12:56 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXRAHY8C2d2cKErDjNQgxklv/jGsb4KSnGZV2m2B34yY6rteyMS/AfQdPz3bOy32jHE5IqLCVgbD9a9h1t2K2ZQKUGAT5bKWHB7/RXHSMKKAX0yiR6RgbR2wot+VG8QDxdMn/GLmNsDX1yQt4eq2aUb1b+9khOs4VKd59eX2frevl4y/2m5YnQsIGuOJBq08I9UwmT7DM4c4g== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l4-20020adffe84000000b0033929310ae4sm1051065wrr.73.2024.02.05.21.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 21:12:55 -0800 (PST) Message-ID: <14927038d855020f9ae7594ad5cc646257613cc1.1707196348.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 05:12:28 +0000 Subject: [PATCH v4 28/28] trailer: introduce "template" term for readability 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" , Linus Arver , Linus Arver From: Linus Arver From: Linus Arver The term "arg_item" is ambiguous because we use it to hold data for (1) trailers specified as command line arguments (in builtin/interpret-trailers.c), and (2) trailers specified in configuration, and these are both used to ultimately insert new trailers (based on the contents of arg_item, acting as a kind of template) into some other set of existing trailers (such as those found in a trailer block inside a log message) that have already been parsed. Rename "arg_item" to "trailer_template". This necessitates further renames to make the functions that act on these templates match the data structures (parameters) they act on: - [*] add_arg_to_input_list() to apply_template_to_trailers() - [*] apply_arg_if_exists() to maybe_add_if_exists() - [*] apply_arg_if_missing() to maybe_add_if_missing() - apply_command() to run_command_from_template() - [*] apply_item_command() to populate_template_value() - free_arg_item() to free_template() (non-API function) - free_new_trailers() to free_trailer_templates() (API function) - get_conf_item() to get_or_add_template_by() - option_parse_trailer() to option_parse_trailer_template() - parse_trailers_from_config() to parse_trailer_templates_from_config() - [*] process_trailers_lists() to apply_trailer_templates() - token_from_item() to token_from_template() - token_matches_item to token_matches_template - [*] trailer_add_arg_item() to add_trailer_template() - trailer_from_arg() to trailer_from() - [*] check_if_different() (reorder parameters only) - [*] find_same_and_apply_arg() (reorder parameters only) Reorder parameters to prefer input parameters toward the beginning and out parameters at the end; these functions have been marked with an asterisk ([*]). This removes the "arg" terminology (standing for "CLI arguments") from the trailer implementation, which makes sense because trailers themselves have nothing to do with CLI argument handling. Also note that these renames expose the previously liberal use of "trailer" to mean both trailers we read from the input text (trailer block) and trailer templates that are defined as CLI args or configurations. Some functions implied a single action when they could do two different things, so introduce words like "maybe" and "or" to make their behavior more explicit. In summary this patch renames and reorders parameters for readability, without any behavioral change. We don't rename find_same_and_apply_arg(), because it will be refactored soon. For parse_trailers_from_config() (renamed to parse_trailer_templates_from_config()), add a NEEDSWORK discussion about how the deprecated trailer.*.command configuration option is oddly more featureful than trailer.*.cmd (if we were to remove support for trailer.*.command, users would not be able to replicate the behavior with trailer.*.cmd and would lose out on functionality). Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 50 +++--- trailer.c | 290 +++++++++++++++++++---------------- trailer.h | 12 +- 3 files changed, 193 insertions(+), 159 deletions(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index d0c09d1d73b..d3d2544c5f1 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -45,10 +45,14 @@ static int option_parse_if_missing(const struct option *opt, return trailer_set_if_missing(arg, opt->value); } -static int option_parse_trailer(const struct option *opt, - const char *arg, int unset) +/* + * Interpret "--trailer ..." as trailer templates (trailers we want to add into + * the input text). + */ +static int option_parse_trailer_template(const struct option *opt, + const char *arg, int unset) { - struct list_head *trailers = opt->value; + struct list_head *templates = opt->value; struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; const struct trailer_conf *conf; @@ -56,7 +60,7 @@ static int option_parse_trailer(const struct option *opt, static char *cl_separators; if (unset) { - free_new_trailers(trailers); + free_trailer_templates(templates); return 0; } @@ -93,10 +97,10 @@ static int option_parse_trailer(const struct option *opt, if (if_missing != MISSING_DEFAULT) trailer_set_conf_if_missing(if_missing, conf_current); - trailer_add_arg_item(trailers, - strbuf_detach(&tok, NULL), + add_trailer_template(strbuf_detach(&tok, NULL), strbuf_detach(&val, NULL), - conf_current); + conf_current, + templates); free_trailer_conf(conf_current); } @@ -158,10 +162,10 @@ static void read_input_file(struct strbuf *sb, const char *file) } static void interpret_trailers(const struct process_trailer_options *opts, - struct list_head *new_trailer_head, + struct list_head *templates, const char *file) { - LIST_HEAD(head); + LIST_HEAD(trailers_from_sb); struct strbuf sb = STRBUF_INIT; struct strbuf tb = STRBUF_INIT; struct trailer_block *trailer_block; @@ -172,7 +176,7 @@ static void interpret_trailers(const struct process_trailer_options *opts, if (opts->in_place) outfile = create_in_place_tempfile(file); - trailer_block = parse_trailers(opts, sb.buf, &head); + trailer_block = parse_trailers(opts, sb.buf, &trailers_from_sb); /* Print the lines before the trailer block */ if (!opts->only_trailers) @@ -182,11 +186,11 @@ static void interpret_trailers(const struct process_trailer_options *opts, fprintf(outfile, "\n"); if (!opts->only_input) - process_trailers_lists(&head, new_trailer_head); + apply_trailer_templates(templates, &trailers_from_sb); /* Print trailer block. */ - format_trailers(opts, &head, &tb); - free_trailers(&head); + format_trailers(opts, &trailers_from_sb, &tb); + free_trailers(&trailers_from_sb); fwrite(tb.buf, 1, tb.len, outfile); strbuf_release(&tb); @@ -206,8 +210,8 @@ static void interpret_trailers(const struct process_trailer_options *opts, int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) { struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; - LIST_HEAD(configured_trailers); - LIST_HEAD(trailers); + LIST_HEAD(configured_templates); + LIST_HEAD(templates); struct option options[] = { OPT_BOOL(0, "in-place", &opts.in_place, N_("edit files in place")), @@ -226,8 +230,8 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, "parse", &opts, NULL, N_("alias for --only-trailers --only-input --unfold"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_parse), OPT_BOOL(0, "no-divider", &opts.no_divider, N_("do not treat \"---\" as the end of input")), - OPT_CALLBACK(0, "trailer", &trailers, N_("trailer"), - N_("trailer(s) to add"), option_parse_trailer), + OPT_CALLBACK(0, "trailer", &templates, N_("trailer"), + N_("trailer(s) to add"), option_parse_trailer_template), OPT_END() }; @@ -235,30 +239,30 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix) trailer_config_init(); if (!opts.only_input) - parse_trailers_from_config(&configured_trailers); + parse_trailer_templates_from_config(&configured_templates); argc = parse_options(argc, argv, prefix, options, git_interpret_trailers_usage, 0); - if (opts.only_input && !list_empty(&trailers)) + if (opts.only_input && !list_empty(&templates)) usage_msg_opt( _("--trailer with --only-input does not make sense"), git_interpret_trailers_usage, options); - list_splice(&configured_trailers, &trailers); + list_splice(&configured_templates, &templates); if (argc) { int i; for (i = 0; i < argc; i++) - interpret_trailers(&opts, &trailers, argv[i]); + interpret_trailers(&opts, &templates, argv[i]); } else { if (opts.in_place) die(_("no input file given for in-place editing")); - interpret_trailers(&opts, &trailers, NULL); + interpret_trailers(&opts, &templates, NULL); } - free_new_trailers(&trailers); + free_trailer_templates(&templates); return 0; } diff --git a/trailer.c b/trailer.c index 7b0bdfcb27e..cdb235c27b5 100644 --- a/trailer.c +++ b/trailer.c @@ -55,14 +55,14 @@ struct trailer_item { char *value; }; -struct arg_item { +struct trailer_template { struct list_head list; char *token; char *value; struct trailer_conf conf; }; -static LIST_HEAD(conf_head); +static LIST_HEAD(templates_from_conf); static char *separators = ":"; @@ -105,7 +105,7 @@ static size_t token_len_without_separator(const char *token, size_t len) return len; } -static int same_token(struct trailer_item *a, struct arg_item *b) +static int same_token(struct trailer_item *a, struct trailer_template *b) { size_t a_len, b_len, min_len; @@ -119,12 +119,12 @@ static int same_token(struct trailer_item *a, struct arg_item *b) return !strncasecmp(a->token, b->token, min_len); } -static int same_value(struct trailer_item *a, struct arg_item *b) +static int same_value(struct trailer_item *a, struct trailer_template *b) { return !strcasecmp(a->value, b->value); } -static int same_trailer(struct trailer_item *a, struct arg_item *b) +static int same_trailer(struct trailer_item *a, struct trailer_template *b) { return same_token(a, b) && same_value(a, b); } @@ -151,15 +151,15 @@ static void free_trailer_item(struct trailer_item *item) free(item); } -static void free_arg_item(struct arg_item *item) +static void free_template(struct trailer_template *template) { - free(item->conf.name); - free(item->conf.key); - free(item->conf.command); - free(item->conf.cmd); - free(item->token); - free(item->value); - free(item); + free(template->conf.name); + free(template->conf.key); + free(template->conf.command); + free(template->conf.cmd); + free(template->token); + free(template->value); + free(template); } static char last_non_space_char(const char *s) @@ -171,36 +171,36 @@ static char last_non_space_char(const char *s) return '\0'; } -static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok) +static struct trailer_item *trailer_from(struct trailer_template *template) { struct trailer_item *new_item = xcalloc(1, sizeof(*new_item)); - new_item->token = arg_tok->token; - new_item->value = arg_tok->value; - arg_tok->token = arg_tok->value = NULL; - free_arg_item(arg_tok); + new_item->token = template->token; + new_item->value = template->value; + template->token = template->value = NULL; + free_template(template); return new_item; } -static void add_arg_to_input_list(struct trailer_item *on_tok, - struct arg_item *arg_tok) +static void apply_template_to_trailers(struct trailer_template *template, + struct trailer_item *on_tok) { - int aoe = after_or_end(arg_tok->conf.where); - struct trailer_item *to_add = trailer_from_arg(arg_tok); + int aoe = after_or_end(template->conf.where); + struct trailer_item *to_add = trailer_from(template); if (aoe) list_add(&to_add->list, &on_tok->list); else list_add_tail(&to_add->list, &on_tok->list); } -static int check_if_different(struct trailer_item *in_tok, - struct arg_item *arg_tok, - int check_all, - struct list_head *head) +static int check_if_different(struct trailer_template *template, + struct trailer_item *in_tok, + struct list_head *head, + int check_all) { - enum trailer_where where = arg_tok->conf.where; + enum trailer_where where = template->conf.where; struct list_head *next_head; do { - if (same_trailer(in_tok, arg_tok)) + if (same_trailer(in_tok, template)) return 0; /* * if we want to add a trailer after another one, @@ -215,7 +215,8 @@ static int check_if_different(struct trailer_item *in_tok, return 1; } -static char *apply_command(struct trailer_conf *conf, const char *arg) +static char *run_command_from_template(struct trailer_conf *conf, + const char *arg) { struct strbuf cmd = STRBUF_INIT; struct strbuf buf = STRBUF_INIT; @@ -250,133 +251,142 @@ static char *apply_command(struct trailer_conf *conf, const char *arg) return result; } -static void apply_item_command(struct trailer_item *in_tok, struct arg_item *arg_tok) +/* + * Prepare the template by running the command (if any) requested by the + * template in order to populate the template's value field. + */ +static void populate_template_value(struct trailer_template *template, + struct trailer_item *in_tok) { - if (arg_tok->conf.command || arg_tok->conf.cmd) { + if (template->conf.command || template->conf.cmd) { + /* + * Determine argument to pass into the command. + */ const char *arg; - if (arg_tok->value && arg_tok->value[0]) { - arg = arg_tok->value; + if (template->value && template->value[0]) { + arg = template->value; } else { if (in_tok && in_tok->value) arg = xstrdup(in_tok->value); else arg = xstrdup(""); } - arg_tok->value = apply_command(&arg_tok->conf, arg); + template->value = run_command_from_template(&template->conf, + arg); free((char *)arg); } } -static void apply_arg_if_exists(struct trailer_item *in_tok, - struct arg_item *arg_tok, +static void maybe_add_if_exists(struct trailer_template *template, + struct trailer_item *in_tok, struct trailer_item *on_tok, - struct list_head *head) + struct list_head *trailers) { - switch (arg_tok->conf.if_exists) { + switch (template->conf.if_exists) { case EXISTS_DO_NOTHING: - free_arg_item(arg_tok); + free_template(template); break; case EXISTS_REPLACE: - apply_item_command(in_tok, arg_tok); - add_arg_to_input_list(on_tok, arg_tok); + populate_template_value(template, in_tok); + apply_template_to_trailers(template, on_tok); list_del(&in_tok->list); free_trailer_item(in_tok); break; case EXISTS_ADD: - apply_item_command(in_tok, arg_tok); - add_arg_to_input_list(on_tok, arg_tok); + populate_template_value(template, in_tok); + apply_template_to_trailers(template, on_tok); break; case EXISTS_ADD_IF_DIFFERENT: - apply_item_command(in_tok, arg_tok); - if (check_if_different(in_tok, arg_tok, 1, head)) - add_arg_to_input_list(on_tok, arg_tok); + populate_template_value(template, in_tok); + if (check_if_different(template, in_tok, trailers, 1)) + apply_template_to_trailers(template, on_tok); else - free_arg_item(arg_tok); + free_template(template); break; case EXISTS_ADD_IF_DIFFERENT_NEIGHBOR: - apply_item_command(in_tok, arg_tok); - if (check_if_different(on_tok, arg_tok, 0, head)) - add_arg_to_input_list(on_tok, arg_tok); + populate_template_value(template, in_tok); + if (check_if_different(template, on_tok, trailers, 0)) + apply_template_to_trailers(template, on_tok); else - free_arg_item(arg_tok); + free_template(template); break; default: BUG("trailer.c: unhandled value %d", - arg_tok->conf.if_exists); + template->conf.if_exists); } } -static void apply_arg_if_missing(struct list_head *head, - struct arg_item *arg_tok) +static void maybe_add_if_missing(struct trailer_template *template, + struct list_head *trailers) { enum trailer_where where; struct trailer_item *to_add; - switch (arg_tok->conf.if_missing) { + switch (template->conf.if_missing) { case MISSING_DO_NOTHING: - free_arg_item(arg_tok); + free_template(template); break; case MISSING_ADD: - where = arg_tok->conf.where; - apply_item_command(NULL, arg_tok); - to_add = trailer_from_arg(arg_tok); + where = template->conf.where; + populate_template_value(template, NULL); + to_add = trailer_from(template); if (after_or_end(where)) - list_add_tail(&to_add->list, head); + list_add_tail(&to_add->list, trailers); else - list_add(&to_add->list, head); + list_add(&to_add->list, trailers); break; default: BUG("trailer.c: unhandled value %d", - arg_tok->conf.if_missing); + template->conf.if_missing); } } -static int find_same_and_apply_arg(struct list_head *head, - struct arg_item *arg_tok) +static int find_same_and_apply_arg(struct trailer_template *template, + struct list_head *trailers) { struct list_head *pos; struct trailer_item *in_tok; struct trailer_item *on_tok; - enum trailer_where where = arg_tok->conf.where; + enum trailer_where where = template->conf.where; int middle = (where == WHERE_AFTER) || (where == WHERE_BEFORE); int backwards = after_or_end(where); struct trailer_item *start_tok; - if (list_empty(head)) + if (list_empty(trailers)) return 0; - start_tok = list_entry(backwards ? head->prev : head->next, + start_tok = list_entry(backwards ? trailers->prev : trailers->next, struct trailer_item, list); - list_for_each_dir(pos, head, backwards) { + list_for_each_dir(pos, trailers, backwards) { in_tok = list_entry(pos, struct trailer_item, list); - if (!same_token(in_tok, arg_tok)) + if (!same_token(in_tok, template)) continue; on_tok = middle ? in_tok : start_tok; - apply_arg_if_exists(in_tok, arg_tok, on_tok, head); + maybe_add_if_exists(template, in_tok, on_tok, trailers); return 1; } return 0; } -void process_trailers_lists(struct list_head *head, - struct list_head *arg_head) +void apply_trailer_templates(struct list_head *templates, + struct list_head *trailers) { struct list_head *pos, *p; - struct arg_item *arg_tok; + struct trailer_template *template; - list_for_each_safe(pos, p, arg_head) { + list_for_each_safe(pos, p, templates) { int applied = 0; - arg_tok = list_entry(pos, struct arg_item, list); + template = list_entry(pos, struct trailer_template, list); list_del(pos); - applied = find_same_and_apply_arg(head, arg_tok); + applied = find_same_and_apply_arg(template, trailers); if (!applied) - apply_arg_if_missing(head, arg_tok); + maybe_add_if_missing(template, trailers); } } @@ -471,26 +481,26 @@ void free_trailer_conf(struct trailer_conf *conf) free(conf); } -static struct arg_item *get_conf_item(const char *name) +static struct trailer_template *get_or_add_template_by(const char *name) { struct list_head *pos; - struct arg_item *item; + struct trailer_template *template; - /* Look up item with same name */ - list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); - if (!strcasecmp(item->conf.name, name)) - return item; + /* Look up template with same name. */ + list_for_each(pos, &templates_from_conf) { + template = list_entry(pos, struct trailer_template, list); + if (!strcasecmp(template->conf.name, name)) + return template; } - /* Item does not already exists, create it */ - CALLOC_ARRAY(item, 1); - duplicate_trailer_conf(&item->conf, &default_trailer_conf); - item->conf.name = xstrdup(name); + /* Template does not already exist; create it. */ + CALLOC_ARRAY(template, 1); + duplicate_trailer_conf(&template->conf, &default_trailer_conf); + template->conf.name = xstrdup(name); - list_add_tail(&item->list, &conf_head); + list_add_tail(&template->list, &templates_from_conf); - return item; + return template; } enum trailer_info_type { TRAILER_KEY, TRAILER_COMMAND, TRAILER_CMD, @@ -548,7 +558,7 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb UNUSED) { const char *trailer_item, *variable_name; - struct arg_item *item; + struct trailer_template *template; struct trailer_conf *conf; char *name = NULL; enum trailer_info_type type; @@ -573,8 +583,8 @@ static int git_trailer_config(const char *conf_key, const char *value, if (!name) return 0; - item = get_conf_item(name); - conf = &item->conf; + template = get_or_add_template_by(name); + conf = &template->conf; free(name); switch (type) { @@ -631,20 +641,22 @@ void trailer_config_init(void) configured = 1; } -static const char *token_from_item(struct arg_item *item, char *tok) +static const char *token_from_template(struct trailer_template *template, char *tok) { - if (item->conf.key) - return item->conf.key; + if (template->conf.key) + return template->conf.key; if (tok) return tok; - return item->conf.name; + return template->conf.name; } -static int token_matches_item(const char *tok, struct arg_item *item, size_t tok_len) +static int token_matches_template(const char *tok, + struct trailer_template *template, + size_t tok_len) { - if (!strncasecmp(tok, item->conf.name, tok_len)) + if (!strncasecmp(tok, template->conf.name, tok_len)) return 1; - return item->conf.key ? !strncasecmp(tok, item->conf.key, tok_len) : 0; + return template->conf.key ? !strncasecmp(tok, template->conf.key, tok_len) : 0; } /* @@ -687,7 +699,7 @@ void parse_trailer(const char *line, ssize_t separator_pos, struct strbuf *tok, struct strbuf *val, const struct trailer_conf **conf) { - struct arg_item *item; + struct trailer_template *template; size_t tok_len; struct list_head *pos; @@ -705,13 +717,13 @@ void parse_trailer(const char *line, ssize_t separator_pos, tok_len = token_len_without_separator(tok->buf, tok->len); if (conf) *conf = &default_trailer_conf; - list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); - if (token_matches_item(tok->buf, item, tok_len)) { + list_for_each(pos, &templates_from_conf) { + template = list_entry(pos, struct trailer_template, list); + if (token_matches_template(tok->buf, template, tok_len)) { char *tok_buf = strbuf_detach(tok, NULL); if (conf) - *conf = &item->conf; - strbuf_addstr(tok, token_from_item(item, tok_buf)); + *conf = &template->conf; + strbuf_addstr(tok, token_from_template(template, tok_buf)); free(tok_buf); break; } @@ -728,29 +740,41 @@ static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, return new_item; } -void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, - const struct trailer_conf *conf) +void add_trailer_template(char *tok, char *val, const struct trailer_conf *conf, + struct list_head *templates) { - struct arg_item *new_item = xcalloc(1, sizeof(*new_item)); - new_item->token = tok; - new_item->value = val; - duplicate_trailer_conf(&new_item->conf, conf); - list_add_tail(&new_item->list, arg_head); + struct trailer_template *template = xcalloc(1, sizeof(*template)); + template->token = tok; + template->value = val; + duplicate_trailer_conf(&template->conf, conf); + list_add_tail(&template->list, templates); } -void parse_trailers_from_config(struct list_head *config_head) +void parse_trailer_templates_from_config(struct list_head *config_head) { - struct arg_item *item; + struct trailer_template *template; struct list_head *pos; - /* Add an arg item for each configured trailer with a command */ - list_for_each(pos, &conf_head) { - item = list_entry(pos, struct arg_item, list); - if (item->conf.command) - trailer_add_arg_item(config_head, - xstrdup(token_from_item(item, NULL)), - xstrdup(""), - &item->conf); + /* + * Get configured templates with a ".command" option. + * + * NEEDSWORK: If the interpret-trailers builtin sees a + * "trailer.foo.command = ..." setting, then the "foo" trailer will + * always be inserted, even if "--trailer foo" is not provided. + * Considering how ".command" is deprecated, it is a bit strange to see + * it getting special treatment like this over ".cmd". Instead, we + * should add a new option that explicitly lets the user decide if the + * configured trailer should always be added automatically, or if it + * should only be added if "--trailer foo" is provided (default). + * Then we can collect configured trailers that have either ".command" + * or ".cmd" below, instead of just ".command". + */ + list_for_each(pos, &templates_from_conf) { + template = list_entry(pos, struct trailer_template, list); + if (template->conf.command) + add_trailer_template(xstrdup(token_from_template(template, + NULL)), + xstrdup(""), &template->conf, config_head); } } @@ -906,10 +930,16 @@ static size_t find_trailer_block_start(const char *buf, size_t len) possible_continuation_lines = 0; if (recognized_prefix) continue; - list_for_each(pos, &conf_head) { - struct arg_item *item; - item = list_entry(pos, struct arg_item, list); - if (token_matches_item(bol, item, + /* + * The templates here are not used for actually + * adding trailers anywhere, but instead to help us + * identify trailer lines by comparing their keys with + * those found in configured templates. + */ + list_for_each(pos, &templates_from_conf) { + struct trailer_template *template; + template = list_entry(pos, struct trailer_template, list); + if (token_matches_template(bol, template, separator_pos)) { recognized_prefix = 1; break; @@ -1065,13 +1095,13 @@ void free_trailers(struct list_head *trailers) } } -void free_new_trailers(struct list_head *trailers) +void free_trailer_templates(struct list_head *trailer_templates) { struct list_head *pos, *p; - list_for_each_safe(pos, p, trailers) { + list_for_each_safe(pos, p, trailer_templates) { list_del(pos); - free_arg_item(list_entry(pos, struct arg_item, list)); + free_template(list_entry(pos, struct trailer_template, list)); } } diff --git a/trailer.h b/trailer.h index 4193bedbae4..2a21d74c263 100644 --- a/trailer.h +++ b/trailer.h @@ -40,8 +40,8 @@ struct trailer_conf *new_trailer_conf(void); void duplicate_trailer_conf(struct trailer_conf *dst, const struct trailer_conf *src); const char *trailer_default_separators(void); -void trailer_add_arg_item(struct list_head *arg_head, char *tok, char *val, - const struct trailer_conf *conf); +void add_trailer_template(char *tok, char *val, const struct trailer_conf *, + struct list_head *templates); struct process_trailer_options { int in_place; @@ -60,10 +60,10 @@ struct process_trailer_options { #define PROCESS_TRAILER_OPTIONS_INIT {0} -void parse_trailers_from_config(struct list_head *config_head); +void parse_trailer_templates_from_config(struct list_head *config_head); -void process_trailers_lists(struct list_head *head, - struct list_head *arg_head); +void apply_trailer_templates(struct list_head *templates, + struct list_head *trailers_head); ssize_t find_separator(const char *line, const char *separators); @@ -86,8 +86,8 @@ void format_trailers(const struct process_trailer_options *, struct list_head *trailers, struct strbuf *out); void free_trailers(struct list_head *); -void free_new_trailers(struct list_head *); void free_trailer_conf(struct trailer_conf *); +void free_trailer_templates(struct list_head *); /* * Convenience function to format the trailers from the commit msg "msg" into