From patchwork Fri Mar 15 06:55: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: 13593078 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 5573C1A28C for ; Fri, 15 Mar 2024 06:55:10 +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=1710485712; cv=none; b=gRdwlVuHp6Uegwy6G9ebCyH6cJ/faohtDPJ7BKFHpab15nAK5TLUCTtfPWSzVpKw7mMxmM24lrCjfGBpAK1u+RuANwVTIQxW2/bWI/HqzYlo+3zvBf0a7786dF/4n4gAc4rujfdGSV1R53O7WpTBzpy0XCrv28dCbm17/YF4TTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485712; c=relaxed/simple; bh=CaV5//R+1IDNvQTEfb+cf+iLcDdEC/LFK0OcO4P7fVc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=BsWsXSRUZVDtYQH33F3vGzaFjv75bTKZOgYjzYAN/JEXgIEWC/cA9E0xOvUbj7ladBxxzrGgrSLS7/tjl45Yb5TGJug/PzCdVRrNG0ULv1A1e4If5J2yDh69shcbzPPneFwwm50kwNVNod8lR0orU6SjoTmauF5p9aE5sm6QhX0= 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=DZvBttYg; 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="DZvBttYg" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-41400332550so3491435e9.1 for ; Thu, 14 Mar 2024 23:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710485708; x=1711090508; 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=VBqZeTF96LmZA1H72v7h3g3APJVx/350gPQNI10tnMg=; b=DZvBttYg+IXolX6+qiXi41xLBR+aCbR2DSgUD1hasSyHNpxrtuGrV32OKZAh6R3lhr u5adamQZiuf+q2o+tqDRJZ80ZaTqx69w4D4VAGhtdwekF1tEy3tyCFV1VIdmc1RSl4so KhgQr5bEdmd8GZ9QCguzb23muze5htdJgfCI16k3QtGIVRgKAmLTMoneZu12ET0NVQzn 4+8IuyFzxtDEds9C4PNdPp3wC/mYmFZBcBRudHtdBCCT3qH2d2aGtOkd8WwXeCgUHK3g ZiP2XWiGDYgQV//AN+Z9rHzjrLqrvY7OCTcX4idSRkBbd8WWPXafrktciK8+RO/Beol6 xbQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710485708; x=1711090508; 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=VBqZeTF96LmZA1H72v7h3g3APJVx/350gPQNI10tnMg=; b=hFMFiSrLOfFgkF7bOjR9Bp0T5ICcapRTqC/FrhWC5+dUVKgBa700uR98a3+znHYGsL ORJ3Jdi6TXTym2G/J69j+QKnj4fC+iYy5qUtxG5RCe2NdJsXT5RKp53vMi5CbnoyTh0g 8VxyzTFYatWzuP/6LKP2opRYgugpcsOhHlbYNkCgEcTMAekhzL4g7Ahe8EPw74u+stFH LBL5ewSieb3hIzozfZ8ZwMOC4I4i5GRvn7nWsstZamgSjSmI3zrDxsqbxElgEjNuS+om IsLLk0UNFDcZqWYRrARLmR5N78I/YUYG3YLZDwRFgR1q2+n0/2sCIokQrKOqQE6ZThZk s1kw== X-Gm-Message-State: AOJu0YwGwb9hAvXxh2lqo2gVIKBHHG1PSbkGHsTymC6astWoz3VXqjaY XD+y+eT0JfxmyAL/JiYmZr+pfFTG077mzG77wkaPS0UsJpQW5P8V8TXxlmg3 X-Google-Smtp-Source: AGHT+IEaDQr9TG6/d+m9eZgRPIo0GJGcXvl+dapFIhIyDXKolF4ZoRVceiaL+R64Id/lV7I5E9KzIQ== X-Received: by 2002:a05:600c:4e94:b0:413:15ec:6f25 with SMTP id f20-20020a05600c4e9400b0041315ec6f25mr1987684wmq.25.1710485707594; Thu, 14 Mar 2024 23:55:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v15-20020a05600c470f00b004128fa77216sm8063497wmo.1.2024.03.14.23.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:55:07 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 15 Mar 2024 06:55:01 +0000 Subject: [PATCH 1/5] 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 [ ]" , "Christian Couder [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, 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. We will continue to make improvements, culminating in the renaming of format_trailer_info() to format_trailers(), at which point the unification of these formatters will be complete. In order to avoid breaking t4205 and t6300, flip *_success to *_failure in the affected test cases. Add a temporary "test_trailer_option_expect_failure" wrapper which we will use along with "test_expect_failure" in the next commit to avoid breaking tests. When the dust settles with the refactors a few more commits later, we will drop the use of *_failure to make the tests truly pass again. When the preparatory refactors are complete, we'll be able to drop the use of *_failure that we introduce here. Signed-off-by: Linus Arver --- t/t4205-log-pretty-formats.sh | 12 ++++++------ t/t6300-for-each-ref.sh | 16 ++++++++++++++-- trailer.c | 21 ++++++++++----------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index e3d655e6b8b..339e0c892ef 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -675,7 +675,7 @@ test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trail test_cmp expect actual ' -test_expect_success '%(trailers:unfold) unfolds trailers' ' +test_expect_failure '%(trailers:unfold) unfolds trailers' ' git log --no-walk --pretty="%(trailers:unfold)" >actual && { unfold actual && { echo "Acked-by: A U Thor " && @@ -752,7 +752,7 @@ test_expect_success '%(trailers:key) without value is error' ' test_cmp expect actual ' -test_expect_success '%(trailers:keyonly) shows only keys' ' +test_expect_failure '%(trailers:keyonly) shows only keys' ' git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && test_write_lines \ "Signed-off-by" \ @@ -774,7 +774,7 @@ test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' test_cmp expect actual ' -test_expect_success '%(trailers:valueonly) shows only values' ' +test_expect_failure '%(trailers:valueonly) shows only values' ' git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && test_write_lines \ "A U Thor " \ @@ -813,7 +813,7 @@ test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separa test_cmp expect actual ' -test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' +test_expect_failure 'pretty format %(trailers:key_value_separator) changes key-value separator' ' git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && ( printf "XSigned-off-by\0A U Thor \n" && @@ -824,7 +824,7 @@ test_expect_success 'pretty format %(trailers:key_value_separator) changes key-v test_cmp expect actual ' -test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' +test_expect_failure 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && ( printf "XSigned-off-by\0A U Thor \n" && diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index eb6c8204e8b..2688dcc7b9e 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -1446,7 +1446,19 @@ test_trailer_option () { ' } -test_trailer_option '%(trailers:unfold) unfolds trailers' \ +# Just like test_trailer_option, but expect failure instead of success. +test_trailer_option_expect_failure () { + title=$1 option=$2 + cat >expect + test_expect_failure "$title" ' + git for-each-ref --format="%($option)" refs/heads/main >actual && + test_cmp expect actual && + git for-each-ref --format="%(contents:$option)" refs/heads/main >actual && + test_cmp expect actual + ' +} + +test_trailer_option_expect_failure '%(trailers:unfold) unfolds trailers' \ 'trailers:unfold' <<-EOF $(unfold $(grep patch.description 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); @@ -1126,13 +1126,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, @@ -1151,7 +1150,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, &trailer_objects, out); free_trailers(&trailer_objects); trailer_info_release(&info); From patchwork Fri Mar 15 06:55: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: 13593079 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.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 0B6611A5AC for ; Fri, 15 Mar 2024 06:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485713; cv=none; b=GsmVSOW7GrMTSOY7Z1Yxc0P6NujRAsyKvGAgQqoryuR7W4YHp/cej1MnchF4uENiIcKAmK9F8jqigMSd0XjzNM/vcmPdZb5or57WAs5r+mDSkY6MEjrLv6FZohZno8DLm2pHUIDjw3uDUFeeBDaJmaubHIfO6e+KAVNvaKpAmYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485713; c=relaxed/simple; bh=JavJ6KCiiAQXm+ynkOcmLx3ghWRqMHQmDDEGFzgTiaI=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Ze+Y3+FanwRAZcJjGcpDo2vKw/8h8sgJANl7OWddAJxAfdtW8nc6vWqNLcBJoEAaB4hlQ4o+D7TMDZ2w+TtMdik7E1kwjusPKSL1OfaicEzGmrGNV8cT1up8P9SmrX/5U6RdhMVT7OeSBpsvGeFBgy9SVvYoNDtx58b6GWzNlFs= 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=FzSqZf8G; arc=none smtp.client-ip=209.85.167.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="FzSqZf8G" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-513d212f818so1764414e87.2 for ; Thu, 14 Mar 2024 23:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710485709; x=1711090509; 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=AB8UPD4LBLRuKnNbNnRabZe0AVzRirc1GhW5gbYWJFc=; b=FzSqZf8GIy8MOlAux0ud3+PqFH9CCDPOQ0Gno7f7r8gamEQBPcFd0WK5UwJhW18mgz c3Ju5oclMupEfWiap2ESHocob39r7rWQ43xZoDlktupdNxiZGenF0elf8WwBiyEZec+f VedyYJbNuuCKnpTE3UuxogkfCJnAgv/QEmeQWXuWNlIQnEbCOO7tWl56/7NP0gNHe3b8 9wRSXX06BDjw3YwBIRfzYIxP1/10ASJCpGNbI58D2w9mgxuFx3Jy9POh7IxfMK18AAm7 +Yx7RLoK+KEpsSSJtMF6rcTsLjfRmbEiT++xF4Wg7CpMsqJ4FuZhDP6sIe+YYDlR/9tS V2bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710485709; x=1711090509; 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=AB8UPD4LBLRuKnNbNnRabZe0AVzRirc1GhW5gbYWJFc=; b=FbTeoIEYRbLsULo95INez2D0GM/arKvxLi+wGIifGfDNIUjT8e1F8XV7LbgkS6bSWi copRWXBUzI45mf4QAaegArhqQDdxyPg6s0koeVFCphkkhYATaMJba6DvqYE65L6nV9jH Gv0zlWBQ+yL8s9FhwtbZejHdKOFX+5OOu8h5PxchZV0RznC5o1O55eIY5Jiw8TBBeGUj vb66yQeJdyvFTlut8Cwp02Ha1JNhW2x57gPL+GTvIsKUqSfosCLmV6MWhKlObHD3NnBD sUbPD/DSk+rp+qN0Hw4QGn8ptzrGUNiQuV6cNjNPLoZkZebnIWEG3x/gjonbeiPqlczv 7P+g== X-Gm-Message-State: AOJu0YwQLBCY4jev5r4uNITWl8X0uxaeo0XQjSZ67LXzlEuNXuzpCWHs HRZMeZyK2ZcJrKa7essKpUWTVKY/kb+WCvlBMhMBBqo8CrEjAJN4FmYlmPJF X-Google-Smtp-Source: AGHT+IHJ8LYZny5+04m6FjYyeunFmbS2Zesp15LySouHRYQU2Tep8+kugSLr2iBO+J0QTlNuYqseAA== X-Received: by 2002:a19:2d51:0:b0:513:82e2:4193 with SMTP id t17-20020a192d51000000b0051382e24193mr801894lft.10.1710485709395; Thu, 14 Mar 2024 23:55:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z18-20020adfec92000000b0033e7de97214sm2428136wrn.40.2024.03.14.23.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:55:07 -0700 (PDT) Message-ID: <5f9e444197468d065264b85c8cf7434df0e08070.1710485706.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 15 Mar 2024 06:55:02 +0000 Subject: [PATCH 2/5] 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 [ ]" , "Christian Couder [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, 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 a74f05db55c..2c0dd8ac829 100644 --- a/trailer.c +++ b/trailer.c @@ -1101,9 +1101,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 Fri Mar 15 06:55: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: 13593080 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 7AE6F1B297 for ; Fri, 15 Mar 2024 06:55:13 +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=1710485715; cv=none; b=g2qC0oyv21uBfQ5sAqQpHu90nIPu28UC4fCGPMehBXXZAQSkJ64r1m+tt/zoLCmP38mfBjs8QahEqxrHsEMcQ2+0op9+Fxi8lARK3zR2Unx3Vf7IF8Op6mb+if0bmd+0Lw7LmlAky0mcMhdBj5X4NfxHDG+WDF6/NCpNmcXrJKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485715; c=relaxed/simple; bh=QnwRLwEvbitMKBzd4A1nGelZtwIiuHvmYrqFFicGnPY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=bbApP4VadXr4MUPgUGSFbxpoDPKfKX3kL3rl3cxWxmYbKCgKuU5erqz14qLZl8S+NRf9MUAVBm8BZGIauqOyVCKqNOXPUoEnQFTp0mcamfOmQpZz5o7NxPPvMAwhThmB4y4cejsGl4fIVSl30GVBXs9J6OBwXFPfnEmuIGFdS2k= 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=UGDQ18vN; 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="UGDQ18vN" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33e99b639e0so1083142f8f.0 for ; Thu, 14 Mar 2024 23:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710485711; x=1711090511; 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=utqsz+B8Wo6UOPNQ8UYwXBY6NQSAFkEdixNQ1BTbGn0=; b=UGDQ18vN3yxEHzueD/Lm6AUd6ADvOMUO/AAzzZ5ouSK0HJW6gM6Elvgyp9NDDYgQLg PTkAn1utlGX1iikZ0JMdloaSDzSuDnw2EYnB3ZD+8RdbNGJUZjvURNKA0MpQ6R6EfcI2 YyyfjcWBVKtpKoZb8kxktEKBToCEzK7v+PerRrFwQciqKTTfAzshJvTwjIA7d/t738Yu 1b9EhPXUVhH7J+rKSLqPsnX/CVqM4JrkJfAvwSzUlXkqQhs+QKuHoMUmA15iSq/nYqFA Jmu9pPv95rH05uk8P6dOhxaxOlYgZSUYL7xB5J8NjTbzlnwwNRJDI/xdxNAnrzQaadrB JvAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710485711; x=1711090511; 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=utqsz+B8Wo6UOPNQ8UYwXBY6NQSAFkEdixNQ1BTbGn0=; b=n5+EyS7EaH0zhIZD0UhdaJavmFMfA1bFmJ/YweC62GSC/yRO6eH1OvTQJHNou7kaEr CnWAhsdTfQ9ng/vL7ON4kwzc2dvaMG/inBsTNke7q0+MOYdXQFMTt0ZHc0V5WQIINJu5 L7wq3peU69h1GVC8P/LjOf5UI1GG7v+WpeJwyzjoMgJdyrzdpCLFMpqTjP6SEDjfoC42 WQgJPRBEBZbdct3mzkjkPkHfbcITRSr2Oyg3jVNpIE5z3mz5D7jdenWeSOd1y6KQ1LaH 0U6thaqcMcYchCTTEABwvXUolkOSMcvcUze5Gr9VS5pQq9pH5Hdjq4xzWDRHLYqvUCnt 7gcQ== X-Gm-Message-State: AOJu0YyrLI6ELFxI3JSBsD7h3Zh/S23fdPZaLK9d/SNEtXcjG0gjIfVf FysA8Okg58Nbln9bUpeILKiUsOvY5qvwBNCrurkXSmbiNWqVbFqrk1ScHQ5G X-Google-Smtp-Source: AGHT+IEQoBYMTZtuKKiIrWjEAR4C9RKoHEPTF5/U3RNOq/mkURUaJ1DUrU/BobO5N1ymD26YKAD2Zw== X-Received: by 2002:adf:f04a:0:b0:33e:652b:d6cf with SMTP id t10-20020adff04a000000b0033e652bd6cfmr2808921wro.29.1710485710761; Thu, 14 Mar 2024 23:55:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n8-20020a5d6608000000b0033e45930f35sm2452401wru.6.2024.03.14.23.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:55:09 -0700 (PDT) Message-ID: <259a4edcfa5138053255dbade411ef151617bb1b.1710485706.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 15 Mar 2024 06:55:03 +0000 Subject: [PATCH 3/5] 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 [ ]" , "Christian Couder [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, 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 can pass again without the need to hide failures with *_failure, so flip the affected test cases back to *_success. Now, format_trailer_info() is in better shape to supersede format_trailers(), which we'll do in the next commit. Signed-off-by: Linus Arver --- t/t4205-log-pretty-formats.sh | 12 ++++++------ t/t6300-for-each-ref.sh | 16 ++-------------- trailer.c | 5 +++-- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 339e0c892ef..e3d655e6b8b 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -675,7 +675,7 @@ test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trail test_cmp expect actual ' -test_expect_failure '%(trailers:unfold) unfolds trailers' ' +test_expect_success '%(trailers:unfold) unfolds trailers' ' git log --no-walk --pretty="%(trailers:unfold)" >actual && { unfold actual && { echo "Acked-by: A U Thor " && @@ -752,7 +752,7 @@ test_expect_success '%(trailers:key) without value is error' ' test_cmp expect actual ' -test_expect_failure '%(trailers:keyonly) shows only keys' ' +test_expect_success '%(trailers:keyonly) shows only keys' ' git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && test_write_lines \ "Signed-off-by" \ @@ -774,7 +774,7 @@ test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' test_cmp expect actual ' -test_expect_failure '%(trailers:valueonly) shows only values' ' +test_expect_success '%(trailers:valueonly) shows only values' ' git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && test_write_lines \ "A U Thor " \ @@ -813,7 +813,7 @@ test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separa test_cmp expect actual ' -test_expect_failure 'pretty format %(trailers:key_value_separator) changes key-value separator' ' +test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && ( printf "XSigned-off-by\0A U Thor \n" && @@ -824,7 +824,7 @@ test_expect_failure 'pretty format %(trailers:key_value_separator) changes key-v test_cmp expect actual ' -test_expect_failure 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' +test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && ( printf "XSigned-off-by\0A U Thor \n" && diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 2688dcc7b9e..eb6c8204e8b 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -1446,19 +1446,7 @@ test_trailer_option () { ' } -# Just like test_trailer_option, but expect failure instead of success. -test_trailer_option_expect_failure () { - title=$1 option=$2 - cat >expect - test_expect_failure "$title" ' - git for-each-ref --format="%($option)" refs/heads/main >actual && - test_cmp expect actual && - git for-each-ref --format="%(contents:$option)" refs/heads/main >actual && - test_cmp expect actual - ' -} - -test_trailer_option_expect_failure '%(trailers:unfold) unfolds trailers' \ +test_trailer_option '%(trailers:unfold) unfolds trailers' \ 'trailers:unfold' <<-EOF $(unfold $(grep patch.description separator); } strbuf_addstr(out, item->value); - if (opts->separator) { + if (opts->separator) strbuf_rtrim(out); - } + else + strbuf_addch(out, '\n'); } } } From patchwork Fri Mar 15 06:55: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: 13593081 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A51CF1B582 for ; Fri, 15 Mar 2024 06:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485715; cv=none; b=OVCdQ7FkX2PjeREHG099Fe7EybQanzdaZEuTZC86EZqXu65pYqpvRFwkd3fbHICvd128I2fnmRwCdZT38+YuQf1idnrRDjSyqAmzRHTWeej8oBx2/ZRNQuIirHhHRZb29Nqjh9Qj7nxjCqd3b/+LeTDstJrZTlkN3vCcE5dE4j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485715; c=relaxed/simple; bh=G0NGK4cxJQSAkZENR16sA7TlS1M6+v/XNrRg/guMruI=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Ndy66n0iKfw+GeQHYMCICN/tgyywbn0PDLqTzMU9Qm3JEooEsQRh8/DvOEZ4jIGzrr9DyMEAmWUN+QTJwqvsbKcoAr7P9Uh4TrhCOWAtxqmOj+PwflPnrnyDcN+tb/nyePTrpjxJ52VvzKqHnx2jM3BKgqLazaZkoLHQ+BP8bFw= 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=cP24/QMi; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cP24/QMi" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-414037f37cfso255995e9.0 for ; Thu, 14 Mar 2024 23:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710485711; x=1711090511; 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=3cRfiy6uaxZupXSiPyjOp8LihUUZ97Kig+lbsSWYMIc=; b=cP24/QMiB+vktM8t8DEJQzMGhcphRuBwvAupEjr4bb9Dd8E7qN9xIybwznVsNrJ4ql QnktgiTXRSeFv6x1GkJIFxpXrWAZXAYXjU6WsXZ9wwX7i3lUvmOjiuC7gxw3nCMQADFw TnL1698uX6efGjBd09M3dOcfUkDBNxuEJNi0voL3VFQ8kU3LSWyl8eUjqynP2uQHMfd6 QWNsPCeN6rD6l5/VPOWp70XZ9WUhmMxuNJ9uwNXn1V3/EdZOTDkc+s+brOHeJKB08M0j HvfS/jDqrtuaJw7QRszaRnCpZCszKHfBgMsN9PoUlv+mOw7llWin1EDaFwHOOQBR/0Qp Hvfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710485711; x=1711090511; 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=3cRfiy6uaxZupXSiPyjOp8LihUUZ97Kig+lbsSWYMIc=; b=Wer53V+NihfEQbmY0hC4P6yh4GbH25QJ9DYTzTmT4duVPUDJXdyCJ6AuiSsBabjTFC aCu8su2yvByLjaXt/oycPXWSrJNMlokIqz3RaVeo2thOje7ECnnXMiEJHLvI5jQe7evG 4RxNAAMHmTakma+dJKGhj1BjKrUPm0M7grvzVgsEdfCETS8Ws/dAkPmbmTStWpRAOJ4x UR61G3gqjNDSgoCN7B/s+8Naa+VfnRoxWtOmKp40DxdXgoNpDhLC1FbA8WbyZpjewhVq C0F5tRhsFWjCUq5IIWKXniw68xx5FI/x6e90xIn7mdgx604T+BEr713VjwQ+yttK0YIC kb7Q== X-Gm-Message-State: AOJu0YwrCaE5jjWt0txhjuNtQL9foA3lDSKmpQZYwYrrifEsHyFWcqqI OEjeAYyjBEuHON++t7KjwrSkSMUaUROKvCDZGTS2aoq1mCw7xPkBtIAl/GEq X-Google-Smtp-Source: AGHT+IHiZrz2knMAPp6fyWEBQ4lDRgw/AOfGle+NOvHkmYPj639a0otKOfCXgPSezx8egT0vSvvzCg== X-Received: by 2002:a05:600c:4e0c:b0:413:fecb:9240 with SMTP id b12-20020a05600c4e0c00b00413fecb9240mr1008306wmq.35.1710485711359; Thu, 14 Mar 2024 23:55:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r3-20020a05600c35c300b004132960286esm4796839wmq.34.2024.03.14.23.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:55:11 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 15 Mar 2024 06:55:04 +0000 Subject: [PATCH 4/5] 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 [ ]" , "Christian Couder [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, 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 In order to avoid breakages in t7502 and t7513, we have to steal the features present in format_trailers(). Namely, we have to teach format_trailer_info() as follows: (1) make it aware of opts->trim_empty, and (2) make it avoid hardcoding ": " as the separator and space (which can result in double-printing these characters). For (2), make it 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. Helped-by: Junio C Hamano Helped-by: Christian Couder Signed-off-by: Linus Arver --- builtin/interpret-trailers.c | 2 +- trailer.c | 54 ++++++++++++------------------------ trailer.h | 2 +- 3 files changed, 19 insertions(+), 39 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 fe8b0819d55..43d5baef9ce 100644 --- a/trailer.c +++ b/trailer.c @@ -144,38 +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); -} - -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)); @@ -1084,9 +1052,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; @@ -1100,6 +1068,15 @@ static 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); @@ -1108,8 +1085,11 @@ static 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); 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 Fri Mar 15 06:55: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: 13593082 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.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 4E18E1B5BF for ; Fri, 15 Mar 2024 06:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485717; cv=none; b=pOYpvZluVHbn9wEQAH34sFuOvVbMF8ihIatB64WAyNwoBpefORAWyruSUj3hPNdgQP1XUi5VlRbBQ+AugIs6z//ekksxtqHKx5rT22sLRjA3sdTCM6rFNIFhkB15oWfpFoykRVjnt88B7mfp16dpG/S0Rw2ClgsS9Rsw9ydm260= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710485717; c=relaxed/simple; bh=bB5ZnAkvcSD7SZmz4//9/FaojLD8KfUsJcMG5y/Sb90=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=GpHJZ2v5Bf8pEv9sndExvY0kWEP4EagLg0FVnn6H0eAjAAqtzeE1cah3Ao56LH+H1Oz4NIYXmvTNVceZsrqeezXdNlfV13UMqxGCzcf9ASo0yKGxLiOkE07MZNoSgjAQWMsdfvzWgQUULV8URDdNLIgHRWUs1aBDJGcnEivPXOo= 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=bZ7rPZZE; arc=none smtp.client-ip=209.85.167.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="bZ7rPZZE" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51320ca689aso2037924e87.2 for ; Thu, 14 Mar 2024 23:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710485713; x=1711090513; 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=AvFfpyMwYJrJtcCYZDHtOZ1OtFNfSKrtlGzpxaHvq7w=; b=bZ7rPZZEIwgQNwH+5uTyJPAEUCH7ps8ICW3ctHJsWmnQ6bNS1OZi/HzpUjVPWmw98n 9yGLkY7Y5omqC9nLqOeLKAMIpeQFPV8qsOkdAtsATpQgJN7QNhY6X3OGQ/Qv+VD9VKj4 CGYg4Di3kATFZkJix/bwtcWK3/CLMtURi0XLs8z/JJbCBFieNvIMHvH2Lg/9K2TNzkSd KQbyObWQl7k25WKAjEMlCSZcZ+6JZl0vxukFbXM5omwsFfDlsCJiWtVIKOQMW1nZV5Dx R8HDEFIR1m5gpIhIdRyFruk86GFckRWAWSpkGzjhn8ZTyMi9HEjsLmqxq98zGz1+vFWt Stvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710485713; x=1711090513; 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=AvFfpyMwYJrJtcCYZDHtOZ1OtFNfSKrtlGzpxaHvq7w=; b=eu9rYBsdyT8jHNz6ayoU06f651JIbM/xYq2AQWrhSB/DzKkY/NArN60+vMj+LTqVpS MQvCX/brOkQwg6uYjpowqyjzchmk7mQgZ2aOpgMUG3C2pvTbw00QFW5w9b+BfzE6UaGe fTThiUJgX2H3XnAKe0dXD2KbE99MK+9jCq4lVe3I5//TvPbXgSg0hMIJ7fehfjlzprQj 7tNlPLpHt+iUfyfozVt+W/TtvW+9TrfnJcgR6ppmiaEkFg4m/Twtl9neqMyxCDocfrzd /WGA5M3qD+bWpCRyiB/s9YFE7bZypIM77nxYV1nunljzwdVrTmtP340vQOT+X1R2beuu pHpQ== X-Gm-Message-State: AOJu0YxsnoCl4KBwB5fSAOqstANFBTV5iQ01hO6vbumSLRr5uC7OiZRE JgN9xEVnB5zis6ZtJ6aMreDg/N+iqYi9g6YENn1beCyw6ioRTpdb1TkUjjQJ X-Google-Smtp-Source: AGHT+IFw1slWXku3UUX1kTRG5+0yea3nzXS/IEEJPBgstQZBpvwUcxxO2LizDkd9AvDv/0IRXfpT9g== X-Received: by 2002:a19:7409:0:b0:513:4766:2713 with SMTP id v9-20020a197409000000b0051347662713mr1530617lfe.59.1710485712707; Thu, 14 Mar 2024 23:55:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j16-20020a05600c191000b00413f035d58esm4754426wmq.10.2024.03.14.23.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:55:11 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Fri, 15 Mar 2024 06:55:05 +0000 Subject: [PATCH 5/5] 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 [ ]" , "Christian Couder [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, 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(). Those caveats come from a388b10fc1 (pretty: move trailer formatting to trailer.c, 2017-08-15) where it says: pretty: move trailer formatting to trailer.c The next commit will add many features to the %(trailer) placeholder in pretty.c. We'll need to access some internal functions of trailer.c for that, so our options are either: 1. expose those functions publicly or 2. make an entry point into trailer.c to do the formatting Doing (2) ends up exposing less surface area, though do note that caveats in the docstring of the new function. which suggests format_trailers_from_commit() started out from pretty.c and did not have access to all of the trailer implementation internals, and was never intended to replace (unify) the formatting machinery in trailer.c. The refactors leading up to this commit (as well as additional refactors that will follow) expose additional functions publicly, and is therefore choosing option (1) as described in a388b10fc1. 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 43d5baef9ce..3e4dab9c065 100644 --- a/trailer.c +++ b/trailer.c @@ -1052,9 +1052,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; @@ -1128,7 +1128,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, &trailer_objects, out); + format_trailers(opts, &trailer_objects, out); free_trailers(&trailer_objects); 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);