From patchwork Tue Jul 7 17:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11649453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4A1960D for ; Tue, 7 Jul 2020 17:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC86D20738 for ; Tue, 7 Jul 2020 17:41:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vJKugMxd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728215AbgGGRlI (ORCPT ); Tue, 7 Jul 2020 13:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727791AbgGGRlH (ORCPT ); Tue, 7 Jul 2020 13:41:07 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D656BC061755 for ; Tue, 7 Jul 2020 10:41:06 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id o11so46159767wrv.9 for ; Tue, 07 Jul 2020 10:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m71lrX61e+aCQr+85KIVfoH5ZMC6+CdHbQ7a0/48h7o=; b=vJKugMxd9R898+gOd2QH+efeP330JzPBSvrSBzGjk9Wop/KcMJ1WjIB+YIyEz/tnHU CDOXg793IGGDeJuT4fzvwHWU7+qHehFxdg11wMrz0M37mqwn/Q7GQo6AKs7xguQ3PwTo 5kUQcPOBwsb7lCCyLG6h0EY9QELBDP7MEHIUHafy9NrRD9KQQoTBKFhS1R0ZH3XUyw5m mqidu2PFvFKmsxXif6gfNjTe/CiUc1GGL6Z7wZSI2FXtTkpPoy8fn4FKeJ+q9Bfl6WEn lLYjp7d7P1Zz1jrdPamEcypO8lW6B0A5GsQpH6bAs3/JGoNtbbYgLxNkqaNFIdeXUPx5 L30w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m71lrX61e+aCQr+85KIVfoH5ZMC6+CdHbQ7a0/48h7o=; b=sMfmaKT8Kw5CCx+ZC1ePT/uSv0aSsTQKK/5t8jLjz1v9qe5oHHCt9ECodDLEyEeVYB IuMxWzexpdAUyYI+3pg16134917fuPvrl1wgFb4OSFlHNtQRYo4ZZKV3k6hV+cVMpcxP XqUzTvMrGazo7jFMm4TqJ3K13kbCd3gGKAG+GPPbbOmnzP5R+qsRUfj8bHoaywlczyFC zGbYOANisRygofXLpNyX6Bjrv2EAZAPTvM2uTN2QkY44Zhn+d0s0Bi8Pc72GN4VFKJD9 o06nDvKi3qQjUnFz8GEv20Qy1D7pZQUig4po79Zw3oIvQ3O/QXWIAcimzrr8ICjQfy9A Uewg== X-Gm-Message-State: AOAM531V3ucbIjiAIu6bAKKz/JB/cr4aAWeQYz8ZAhuIGhHKbb4zw25I Yvu6fbVKbKhVUgjE4tn90d21Xy5QgyI= X-Google-Smtp-Source: ABdhPJweBPKaYPs+oJKOD+lYHGBcEgY0BW1tP61Ha8UPy0bOLimZby6+n/oXUEZXmm6eI252zpleLg== X-Received: by 2002:adf:e6cb:: with SMTP id y11mr53441530wrm.282.1594143665363; Tue, 07 Jul 2020 10:41:05 -0700 (PDT) Received: from localhost.localdomain ([185.228.230.97]) by smtp.gmail.com with ESMTPSA id c194sm1977405wme.8.2020.07.07.10.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 10:41:04 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Christian Couder Subject: [PATCH v3 1/4] Documentation: clarify %(contents:XXXX) doc Date: Tue, 7 Jul 2020 19:40:46 +0200 Message-Id: <20200707174049.21714-2-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.460.g66f3a24dd5 In-Reply-To: <20200707174049.21714-1-chriscool@tuxfamily.org> References: <20200707174049.21714-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's avoid a big dense paragraph by using an unordered list for the %(contents:XXXX) format specifiers. Suggested-by: Jeff King Signed-off-by: Christian Couder --- Documentation/git-for-each-ref.txt | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 6dcd39f6f6..2db9779d54 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -232,12 +232,24 @@ Fields that have name-email-date tuple as its value (`author`, `committer`, and `tagger`) can be suffixed with `name`, `email`, and `date` to extract the named component. -The complete message in a commit and tag object is `contents`. -Its first line is `contents:subject`, where subject is the concatenation -of all lines of the commit message up to the first blank line. The next -line is `contents:body`, where body is all of the lines after the first -blank line. The optional GPG signature is `contents:signature`. The -first `N` lines of the message is obtained using `contents:lines=N`. +The complete message of a commit or tag object is `contents`. This +field can also be used in the following ways: + +contents:subject:: + The "subject" of the commit or tag message. It's actually the + concatenation of all lines of the commit message up to the + first blank line. + +contents:body:: + The "body" of the commit or tag message. It's made of the + lines after the first blank line. + +contents:signature:: + The optional GPG signature. + +contents:lines=N:: + The first `N` lines of the message. + Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1] are obtained as `trailers` (or by using the historical alias `contents:trailers`). Non-trailer lines from the trailer block can be omitted From patchwork Tue Jul 7 17:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11649455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B13E660D for ; Tue, 7 Jul 2020 17:41:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 947E020708 for ; Tue, 7 Jul 2020 17:41:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pXb+PtoE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728232AbgGGRlI (ORCPT ); Tue, 7 Jul 2020 13:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728191AbgGGRlI (ORCPT ); Tue, 7 Jul 2020 13:41:08 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD30C08C5DC for ; Tue, 7 Jul 2020 10:41:08 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id k6so46141125wrn.3 for ; Tue, 07 Jul 2020 10:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8/QOL2CY+p1TjyeFrdFEZbE80qydYNU4SiBXwcS64jE=; b=pXb+PtoEcjKG5UCccX4XZyKVNckf5D4sPGXSLegr3U1DLdRCbiRaOZEpk15PZBmaH1 gQM5+sVT/ez/4Ah5CW/BY2jPae4S1GqXX5k30kvEFLS/O6qFkRRlGmnGs6dbMU4tCOzk qdBVJjemOJOCuUWte9fdMu152iiGhNnE1Tz1QfqKCDBXi3wdQzOwDYqRz9q2yBaifoPJ swX42F59JhjapVnvQVLcBq9NOKLpG8Tgdi5VK0Rbg/mKNHtVVNkGExKavv5j5eVK4Igm nFT2LDlH/MsX7S4K2n+QsEyUjis3giis9O0p3sCJ4FbePeMAfhpp09qoGL6uLahjSYxH 55UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8/QOL2CY+p1TjyeFrdFEZbE80qydYNU4SiBXwcS64jE=; b=sh+t/kmv9wRAHatQe//0wGDe6rRx+bDMYgq/Vfq+G2vxM0+e62zPHv40z3Jmn6X3c1 gTIzXCpVPPSHKo1Y+pvFn5fc45gHeQIAxF2hX+i+2UJcyB+8CEOuD7jWWMxMs/tdLPZ5 ZGE1k9Qpvl4r8pk5tKF1Of3k/lrGnsKCyH6GBWH5ghCNxLleJxlO9RZaz+wB5x8836yG fOi63MU+LM+T1r+G+IRZCHtNWtDzENKM72r55pPxWSKbUh7OjJCcMxCs6ToIWPo64jfo oeSRty1ju6tWjWWpFs9u1HcIYZgC1fJbM7tkw8L+uUtQ8V69Z14xrlHyB7ltoZsputK2 e8Cw== X-Gm-Message-State: AOAM531Wji3iwhod6X7Wxo2tnaLjc7l1JOTzBVX7zQdyappgUQTmD1Jb 4armabItUCXp9wdyh6YXMbTdXYf1D9U= X-Google-Smtp-Source: ABdhPJxEKraBVDTsLUodULaVQfNR9eKyLYdqlszxY3S2P5X+idSBDILlkHTX0cCGCcKQi3vl3qWdfQ== X-Received: by 2002:adf:f0c5:: with SMTP id x5mr54929931wro.396.1594143666552; Tue, 07 Jul 2020 10:41:06 -0700 (PDT) Received: from localhost.localdomain ([185.228.230.97]) by smtp.gmail.com with ESMTPSA id c194sm1977405wme.8.2020.07.07.10.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 10:41:06 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Christian Couder Subject: [PATCH v3 2/4] Documentation: clarify 'complete message' Date: Tue, 7 Jul 2020 19:40:47 +0200 Message-Id: <20200707174049.21714-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.460.g66f3a24dd5 In-Reply-To: <20200707174049.21714-1-chriscool@tuxfamily.org> References: <20200707174049.21714-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In Documentation/git-for-each-ref.txt let's clarify what we mean by "complete message". Signed-off-by: Christian Couder --- Documentation/git-for-each-ref.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 2db9779d54..788258c3ad 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -232,8 +232,9 @@ Fields that have name-email-date tuple as its value (`author`, `committer`, and `tagger`) can be suffixed with `name`, `email`, and `date` to extract the named component. -The complete message of a commit or tag object is `contents`. This -field can also be used in the following ways: +The complete message (subject, body, trailers and signature) of a +commit or tag object is `contents`. This field can also be used in the +following ways: contents:subject:: The "subject" of the commit or tag message. It's actually the From patchwork Tue Jul 7 17:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11649457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDCB360D for ; Tue, 7 Jul 2020 17:41:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A413320738 for ; Tue, 7 Jul 2020 17:41:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uefRSr6Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728265AbgGGRlK (ORCPT ); Tue, 7 Jul 2020 13:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728191AbgGGRlK (ORCPT ); Tue, 7 Jul 2020 13:41:10 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9F7C061755 for ; Tue, 7 Jul 2020 10:41:09 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z2so23848699wrp.2 for ; Tue, 07 Jul 2020 10:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D0cA3C0eG7kggyL8SeHset03gOJsYQxzQOj2Aw+eoHU=; b=uefRSr6ZMZQbO0zqqvDVrUrU7vtFudGGaaPC//eFzzCUn6f0l/l1C54vYCzAngLQP0 kMdcaw+Oee0p/nztNIU9kHMdx+3gqm581ACw2S+pd/OMp5l+rPWJqT0XVDOxfE4Jp8su +72Umi34L0sBIQOrNsjPXuasV5vYi2xIrZZV9rJlNs2eMSbASMEGKyjRYZUAWW+SPNaA XIb85PB2wzfVhJ9eNVOrMwlJVXu1ENwx9lM0EnnlJIr+BEoAbd7ajnPz3uFTOnixPW6L 5t0DQY5WH6GJrxNytaCLR6BBSp1u/z6BbZoHp7rL9j2jmJJDbHTMSRqfsokTIZHLfZpV F5tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D0cA3C0eG7kggyL8SeHset03gOJsYQxzQOj2Aw+eoHU=; b=KwIqlDzcjf4OVSB5iry4RVyBV/Qcg6zstPXDbU7ZfGzz9r4MWaCwSX38aWMfJOoSg0 QF7Xbryx1YL2nYW3RVE1OkigK0Cxxqkfpbq3hsooYoPMVBLT7IZtk/qujV4ONvkcUXoh tj3QA1ATNmsdRFpzrfGDLIvUSw7J0kkUJt3QeZpnmglHxHbayHBDZpf5Yp2NgC71oFos rMB2DDV31TqbvLmO3CisrTzISO5fQa4GmO3DDwh6FVQO1p8yxMmB/pNYW1gYofnEYDZJ GAFMd28e4Fg7ocVVwFf8c94+d33gMHRbX24XtflKsW0eKODwNXn0dAiQhFDO9t/RQPPQ vGmA== X-Gm-Message-State: AOAM532wQ8zCV+WLehSbz5bDzwFgZSZHeIzVd8Rx513LIwamvVzc7lLK XUYD9p00BYI49Dr3THm4mHSA+tRuYiw= X-Google-Smtp-Source: ABdhPJyyFEhMcV10tUnWvxpIWi9JntQD3CLOzZXIoH5NVJbYJXwVd1oVE3XV8dmcEOXjRlrcx9/VjA== X-Received: by 2002:adf:f04c:: with SMTP id t12mr52045546wro.382.1594143668082; Tue, 07 Jul 2020 10:41:08 -0700 (PDT) Received: from localhost.localdomain ([185.228.230.97]) by smtp.gmail.com with ESMTPSA id c194sm1977405wme.8.2020.07.07.10.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 10:41:07 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Christian Couder Subject: [PATCH v3 3/4] t6300: test refs pointing to tree and blob Date: Tue, 7 Jul 2020 19:40:48 +0200 Message-Id: <20200707174049.21714-4-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.460.g66f3a24dd5 In-Reply-To: <20200707174049.21714-1-chriscool@tuxfamily.org> References: <20200707174049.21714-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Adding tests for refs pointing to tree and blob shows that we care about testing both positive ("see, my shiny new toy does work") and negative ("and it won't do nonsensical things when given an input it is not designed to work with") cases. Signed-off-by: Christian Couder --- t/t6300-for-each-ref.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index da59fadc5d..371e45e5ad 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -650,6 +650,28 @@ test_atom refs/tags/signed-long contents "subject line body contents $sig" +test_expect_success 'set up refs pointing to tree and blob' ' + git update-ref refs/mytrees/first refs/heads/master^{tree} && + git ls-tree refs/mytrees/first one >one_info && + test $(cut -d" " -f2 one_info) = "blob" && + blob_hash=$(cut "-d " -f1 one_info | cut -d" " -f3) && + git update-ref refs/myblobs/first "$blob_hash" +' + +test_atom refs/mytrees/first subject "" +test_atom refs/mytrees/first contents:subject "" +test_atom refs/mytrees/first body "" +test_atom refs/mytrees/first contents:body "" +test_atom refs/mytrees/first contents:signature "" +test_atom refs/mytrees/first contents "" + +test_atom refs/myblobs/first subject "" +test_atom refs/myblobs/first contents:subject "" +test_atom refs/myblobs/first body "" +test_atom refs/myblobs/first contents:body "" +test_atom refs/myblobs/first contents:signature "" +test_atom refs/myblobs/first contents "" + test_expect_success 'set up multiple-sort tags' ' for when in 100000 200000 do From patchwork Tue Jul 7 17:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11649459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEC3413BD for ; Tue, 7 Jul 2020 17:41:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF37320738 for ; Tue, 7 Jul 2020 17:41:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dlAH8ABh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728305AbgGGRlO (ORCPT ); Tue, 7 Jul 2020 13:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728191AbgGGRlO (ORCPT ); Tue, 7 Jul 2020 13:41:14 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2037CC061755 for ; Tue, 7 Jul 2020 10:41:14 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id f18so38057818wrs.0 for ; Tue, 07 Jul 2020 10:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rFLvt3WUQ34Pwh87a7G9wDA/qQQvPUws3hMQRTDa0mk=; b=dlAH8ABh5fKIktjVQNsUaWGrMyKuOd/3iKFVI19yGZzKWerkEa0d2o0V5NYrWTtTMh 85R/0sNAzoz/JAam+EOJCp2nYFeTQ7eVJWDjx+V8Se7Dfjbq1je8uF+Y9oYf3F6uH5vV /q+UEQ+yTfXG5foAu9HRT+zan/5kPfuKqU6S6s/kpHCH/lOh0kZFK7XYIB0Az3jP3qIg csu9w0PeJFO5apaLU9Ch6dwXq0K+8DYM18M3NpeqjaxaOIv9LsVpXb1uag/rkJEZyhJ0 y5V6nRiZoogHHnfo+jyiLsTAc2Tx0VKdvaYehUSqWH6BgW6oSoC1K5mZ8QkNRHXbXSp0 e2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rFLvt3WUQ34Pwh87a7G9wDA/qQQvPUws3hMQRTDa0mk=; b=W5yclSr7s7QcKYdcm3aBo2TwSazJWwVfk6GYiHCR02Zi+bW/7H65MsH8DVTbEubzRV URuhUu/eue99+lO4Wt749/7u/nmb4iZU66hP/KW5RgMYHldpdeYtqTdVAhmmW0w2XdzD JDBqDmBNUJoTXy8awTsYcOspe02UVQW/z4NEFhsoeOXwnr/6vf8G4hpxnhyHjGqri9B5 4jneKR2mONSvdvpTX+oeaVPjYeA6XpGZsWgOAO4tNjN6Vfkh24N83oN7UQIyONSGwHd0 cctXihNKLaXBWfMlNZZu5rjTbl2gqSBPkWTsTFwghWPxe3ZT4AeVHtQ2tGH0BVcDZgoz dvjA== X-Gm-Message-State: AOAM531SkjfIiSupr3x5hX48+39wD/H+my752SYvSMKDluopeYWdiFPB ldTLcBeQX+QWAU8DnCMuAr16Ujpo8lA= X-Google-Smtp-Source: ABdhPJxZ7shE2eks4GJQ6udp3ECvA1asoYjPTx1i+C/a10VZ1lvLgj8FYZnpVnk+82YqSJGO8Of46g== X-Received: by 2002:adf:e482:: with SMTP id i2mr54144653wrm.75.1594143672447; Tue, 07 Jul 2020 10:41:12 -0700 (PDT) Received: from localhost.localdomain ([185.228.230.97]) by smtp.gmail.com with ESMTPSA id c194sm1977405wme.8.2020.07.07.10.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 10:41:12 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Christian Couder Subject: [PATCH v3 4/4] ref-filter: add support for %(contents:size) Date: Tue, 7 Jul 2020 19:40:49 +0200 Message-Id: <20200707174049.21714-5-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.460.g66f3a24dd5 In-Reply-To: <20200707174049.21714-1-chriscool@tuxfamily.org> References: <20200707174049.21714-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's useful and efficient to be able to get the size of the contents directly without having to pipe through `wc -c`. Also the result of the following: `git for-each-ref --format='%(contents)' refs/heads/my-branch | wc -c` is off by one as `git for-each-ref` appends a newline character after the contents, which can be seen by comparing its output with the output from `git cat-file`. As with %(contents), %(contents:size) is silently ignored, if a ref points to something other than a commit or a tag: ``` $ git update-ref refs/mytrees/first HEAD^{tree} $ git for-each-ref --format='%(contents)' refs/mytrees/first $ git for-each-ref --format='%(contents:size)' refs/mytrees/first ``` Signed-off-by: Christian Couder --- Documentation/git-for-each-ref.txt | 3 +++ ref-filter.c | 7 ++++++- t/t6300-for-each-ref.sh | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 788258c3ad..049bc93e6a 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -236,6 +236,9 @@ The complete message (subject, body, trailers and signature) of a commit or tag object is `contents`. This field can also be used in the following ways: +contents:size:: + The size in bytes of the complete message. + contents:subject:: The "subject" of the commit or tag message. It's actually the concatenation of all lines of the commit message up to the diff --git a/ref-filter.c b/ref-filter.c index 8447cb09be..8ec28f0535 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -127,7 +127,8 @@ static struct used_atom { unsigned int nobracket : 1, push : 1, push_remote : 1; } remote_ref; struct { - enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB, C_TRAILERS } option; + enum { C_BARE, C_BODY, C_BODY_DEP, C_LENGTH, + C_LINES, C_SIG, C_SUB, C_TRAILERS } option; struct process_trailer_options trailer_opts; unsigned int nlines; } contents; @@ -338,6 +339,8 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato atom->u.contents.option = C_BARE; else if (!strcmp(arg, "body")) atom->u.contents.option = C_BODY; + else if (!strcmp(arg, "size")) + atom->u.contents.option = C_LENGTH; else if (!strcmp(arg, "signature")) atom->u.contents.option = C_SIG; else if (!strcmp(arg, "subject")) @@ -1253,6 +1256,8 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) v->s = copy_subject(subpos, sublen); else if (atom->u.contents.option == C_BODY_DEP) v->s = xmemdupz(bodypos, bodylen); + else if (atom->u.contents.option == C_LENGTH) + v->s = xstrfmt("%ld", strlen(subpos)); else if (atom->u.contents.option == C_BODY) v->s = xmemdupz(bodypos, nonsiglen); else if (atom->u.contents.option == C_SIG) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 371e45e5ad..b580e27a32 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -125,6 +125,7 @@ test_atom head contents:body '' test_atom head contents:signature '' test_atom head contents 'Initial ' +test_atom head contents:size '8' test_atom head HEAD '*' test_atom tag refname refs/tags/testtag @@ -170,6 +171,7 @@ test_atom tag contents:body '' test_atom tag contents:signature '' test_atom tag contents 'Tagging at 1151968727 ' +test_atom tag contents:size '22' test_atom tag HEAD ' ' test_expect_success 'Check invalid atoms names are errors' ' @@ -580,6 +582,7 @@ test_atom refs/tags/subject-body contents 'the subject line first body line second body line ' +test_atom refs/tags/subject-body contents:size '51' test_expect_success 'create tag with multiline subject' ' cat >msg <<-\EOF && @@ -606,6 +609,7 @@ second subject line first body line second body line ' +test_atom refs/tags/multiline contents:size '73' test_expect_success GPG 'create signed tags' ' git tag -s -m "" signed-empty && @@ -622,6 +626,16 @@ sig='-----BEGIN PGP SIGNATURE----- -----END PGP SIGNATURE----- ' +# We cannot use test_atom to check contents:size of signed tags due to sanitize_pgp +test_tag_contents_size_pgp () { + ref="$1" + test_expect_success $PREREQ "basic atom: $ref contents:size" " + git cat-file tag $ref | tail -n +6 | wc -c >expected && + git for-each-ref --format='%(contents:size)' $ref >actual && + test_cmp expected actual + " +} + PREREQ=GPG test_atom refs/tags/signed-empty subject '' test_atom refs/tags/signed-empty contents:subject '' @@ -629,6 +643,7 @@ test_atom refs/tags/signed-empty body "$sig" test_atom refs/tags/signed-empty contents:body '' test_atom refs/tags/signed-empty contents:signature "$sig" test_atom refs/tags/signed-empty contents "$sig" +test_tag_contents_size_pgp refs/tags/signed-empty test_atom refs/tags/signed-short subject 'subject line' test_atom refs/tags/signed-short contents:subject 'subject line' @@ -637,6 +652,7 @@ test_atom refs/tags/signed-short contents:body '' test_atom refs/tags/signed-short contents:signature "$sig" test_atom refs/tags/signed-short contents "subject line $sig" +test_tag_contents_size_pgp refs/tags/signed-short test_atom refs/tags/signed-long subject 'subject line' test_atom refs/tags/signed-long contents:subject 'subject line' @@ -649,6 +665,7 @@ test_atom refs/tags/signed-long contents "subject line body contents $sig" +test_tag_contents_size_pgp refs/tags/signed-long test_expect_success 'set up refs pointing to tree and blob' ' git update-ref refs/mytrees/first refs/heads/master^{tree} && @@ -664,6 +681,7 @@ test_atom refs/mytrees/first body "" test_atom refs/mytrees/first contents:body "" test_atom refs/mytrees/first contents:signature "" test_atom refs/mytrees/first contents "" +test_atom refs/mytrees/first contents:size "" test_atom refs/myblobs/first subject "" test_atom refs/myblobs/first contents:subject "" @@ -671,6 +689,7 @@ test_atom refs/myblobs/first body "" test_atom refs/myblobs/first contents:body "" test_atom refs/myblobs/first contents:signature "" test_atom refs/myblobs/first contents "" +test_atom refs/myblobs/first contents:size "" test_expect_success 'set up multiple-sort tags' ' for when in 100000 200000