From patchwork Wed Aug 19 12:52:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724011 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 B8A8B913 for ; Wed, 19 Aug 2020 12:52:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1021206B5 for ; Wed, 19 Aug 2020 12:52:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jVn70fap" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbgHSMwo (ORCPT ); Wed, 19 Aug 2020 08:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728497AbgHSMwg (ORCPT ); Wed, 19 Aug 2020 08:52:36 -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 B1906C061383 for ; Wed, 19 Aug 2020 05:52:35 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id 88so21431131wrh.3 for ; Wed, 19 Aug 2020 05:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OS2sRKB34GpX+DjHnAPxp4cG4XQ9WPhbPQMol2NtnuM=; b=jVn70fapFRniwTidcQNdDzGgeIpNtcQsrpHrJFmj2+rltmmco28F7fNWvaNMnefimv UqVWsMyLrDkMUaqDxSgMy8YdApi4hB8SobeGGIm95h0NU0IUXxJTqEYVrLfSQwRWvKko rBx5yZWmKe/kFLhNGU31BFqK401mlLGdaCPqSeoi07cmeEj1900Kqz6N8D4zjEdiHvVS hxXQFszLWhMJFVGF1KC8x9KEMrYsBiGZ7kMLQVV3nnMiAD2kOOhDa3UfH5GaZm3/pYhu K1qEC8DlyvXgOP/lsiIHRnOvCkxO4yZ9MJdC++5nzauxw1o1y6hZy+kS3gOTEeFmjwp5 tAPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OS2sRKB34GpX+DjHnAPxp4cG4XQ9WPhbPQMol2NtnuM=; b=qNru9mC8PrtH8D/F8siOR/EXxDUpCl1P2HjfJoXEODrSr0YCU6xbYhiNQ5+6jfC3KK HMIIgTPDbuMt9i3wCuf6BoZl9QfZD65tt4d95lmYf3iVtvgWYu+xpqEuv9byotaf1jZB LvkFUorT44lTu2nIMiIbSlX4CJbafoV7coU9W3hQ7fwephxhhmJd9X+DOJoWABWttGmm oQ00IgvB39N3XDsvNsavhtz8UFwUsuH+9VhJJyjaVxgcjrvSmE2+D1BU2tPWCAP3HyPR BfOMCXXz6rODRYjpXfGJholVGx//imvIOsfXQGqc0HGSuE2ovIq9SgboC4QOCr8u4AbO 4peQ== X-Gm-Message-State: AOAM530+2ndBOpLd8S3a9Ys+SFjjQgPqlzsH3ao6Hv1HrvhQ5WGD26YJ raEHAO12XTCiabO77hTSEzVs1NTH55A= X-Google-Smtp-Source: ABdhPJw6OMiHQKzR4rlHxThtm1s4ie2MN8xtU1gDugXOy1Dx9j5Gv+nTCnnH7VCXK5SAYftMA/QklQ== X-Received: by 2002:adf:edc3:: with SMTP id v3mr4037601wro.193.1597841554219; Wed, 19 Aug 2020 05:52:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m126sm5319271wmf.3.2020.08.19.05.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 05:52:33 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 19 Aug 2020 12:52:30 +0000 Subject: [PATCH 1/2] t6300: unify %(trailers) and %(contents:trailers) tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Currently, there are different tests for testing %(trailers) and %(contents:trailers) causing redundant copy. Its time to get rid of duplicate code. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- t/t6300-for-each-ref.sh | 50 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index a83579fbdf..495848c881 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -776,60 +776,39 @@ test_expect_success 'set up trailers for next test' ' ' test_expect_success '%(trailers:unfold) unfolds trailers' ' - git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual && { unfold expect && + git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual && + test_cmp expect actual && + git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual && test_cmp expect actual ' test_expect_success '%(trailers:only) shows only "key: value" trailers' ' - git for-each-ref --format="%(trailers:only)" refs/heads/master >actual && { grep -v patch.description expect && + git for-each-ref --format="%(trailers:only)" refs/heads/master >actual && + test_cmp expect actual && + git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual && test_cmp expect actual ' test_expect_success '%(trailers:only) and %(trailers:unfold) work together' ' - git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual && - git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse && - test_cmp actual reverse && { grep -v patch.description expect && - test_cmp expect actual -' - -test_expect_success '%(contents:trailers:unfold) unfolds trailers' ' - git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual && - { - unfold expect && - test_cmp expect actual -' - -test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' ' - git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual && - { - grep -v patch.description expect && - test_cmp expect actual -' - -test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' ' + git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual && + git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse && + test_cmp actual reverse && + test_cmp expect actual && git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual && git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse && test_cmp actual reverse && - { - grep -v patch.description expect && test_cmp expect actual ' @@ -839,14 +818,7 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' ' fatal: unknown %(trailers) argument: unsupported EOF test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual && - test_i18ncmp expect actual -' - -test_expect_success '%(contents:trailers) rejects unknown trailers arguments' ' - # error message cannot be checked under i18n - cat >expect <<-EOF && - fatal: unknown %(trailers) argument: unsupported - EOF + test_i18ncmp expect actual && test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual && test_i18ncmp expect actual ' From patchwork Wed Aug 19 12:52:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724015 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 408EF913 for ; Wed, 19 Aug 2020 12:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2685D2076E for ; Wed, 19 Aug 2020 12:52:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jHNnncat" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728509AbgHSMwt (ORCPT ); Wed, 19 Aug 2020 08:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728499AbgHSMwl (ORCPT ); Wed, 19 Aug 2020 08:52:41 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8CEC061342 for ; Wed, 19 Aug 2020 05:52:38 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id k8so2087231wma.2 for ; Wed, 19 Aug 2020 05:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dhSXO96eNbE8BNCNl6hYMwdun53Sh6Cltd2mM1S05F4=; b=jHNnncatIW1p5/JMG3D+vbeYUG7pXeC+zXE/Ui5JLNay+MpC/+CENG221xmXuoQExG TPymoQFMC7xc8EXTDIXoSKzVF522Rq8BkdT1+rXbs1gnBxH/4cAfwIlewrf46UlbnDZH Oo2lEyYGV5UHs2Wr6R1EA0WeXmO8XP7xERoF17O0qX1OKRTf2sGe7EVBr/hpFMA8MMDc UMvaiP0ZPAjjGWbe+XdOFvA8caSFsgqdkJTp3lvug82Q8XXxueJ0lnY6o4zNTg2stZVS XUqvUV79xcRiVhX5H+3NNOrF3ULtXvX0gC77R8avMfYDqPXA2aHW95fdipWU8gvD7Mkx yBUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dhSXO96eNbE8BNCNl6hYMwdun53Sh6Cltd2mM1S05F4=; b=OU4YFOJ/DZpW+0ukI5mKt7uYRTr68ZlBI5YdBAlhuWxiKPIQfT+5r/vlt9kmTpWkvh dXinDdFlODPhJOAIVAX5J6Y9akr2i7VjQmgMlOKvJlaHJOt4GfreUw/u0cNBOGO+Nuuy sDtX+zkl8C6+y6XcE9WGMpY/3oCJFmV7C4+skkkQ3CT78k+KF0KWFfWSEqh036jmzWBD 12u+DE1YqVZgc32vWjtgGQiteZAund/4pUdiVkBKq+ee+rgZ0usKdaY4hnNHqa6KiA6+ kO0MLVtpakmFYnxFZtQWQcNezRycOEqWN6+HpureCdXK2SDJkaSKpKJaACvrMxvCb018 SaIw== X-Gm-Message-State: AOAM533wKIm7QwhCaPYQJuae+TY18j/RNClXfKX2V+KEAkoG05ixcqQN a6TaSO66j2ffObVaWwoQtsZlapi0Rcs= X-Google-Smtp-Source: ABdhPJys1s/+MwBzQrU5z1ZeK1MQsD4pSB5zqCoWS1igZzSkuMXSf+AMWDQrYiZ9wrGXE1JHiayMwQ== X-Received: by 2002:a1c:f70a:: with SMTP id v10mr4797866wmh.39.1597841556554; Wed, 19 Aug 2020 05:52:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 6sm5481005wmf.4.2020.08.19.05.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 05:52:34 -0700 (PDT) Message-Id: <7daf9335a501b99c29e299f72823fcb7e549e748.1597841551.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 19 Aug 2020 12:52:31 +0000 Subject: [PATCH 2/2] ref-filter: 'contents:trailers' show error if `:` is missing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma The 'contents' atom does not show any error if used with 'trailers' atom and semicolon is missing before trailers arguments. e.g %(contents:trailersonly) works, while it shouldn't. It is definitely not an expected behavior. Let's fix this bug. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- ref-filter.c | 21 ++++++++++++++++++--- t/t6300-for-each-ref.sh | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index ba85869755..dc31fbbe51 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -332,6 +332,22 @@ static int trailers_atom_parser(const struct ref_format *format, struct used_ato return 0; } +static int check_format_field(const char *arg, const char *field, const char **option) +{ + const char *opt; + if (skip_prefix(arg, field, &opt)) { + if (*opt == '\0') { + *option = NULL; + return 1; + } + else if (*opt == ':') { + *option = ++opt; + return 1; + } + } + return 0; +} + static int contents_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -345,9 +361,8 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato atom->u.contents.option = C_SIG; else if (!strcmp(arg, "subject")) atom->u.contents.option = C_SUB; - else if (skip_prefix(arg, "trailers", &arg)) { - skip_prefix(arg, ":", &arg); - if (trailers_atom_parser(format, atom, *arg ? arg : NULL, err)) + else if (check_format_field(arg, "trailers", &arg)) { + if (trailers_atom_parser(format, atom, arg, err)) return -1; } else if (skip_prefix(arg, "lines=", &arg)) { atom->u.contents.option = C_LINES; diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 495848c881..cb1508cef5 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -823,6 +823,15 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' ' test_i18ncmp expect actual ' +test_expect_success 'if arguments, %(contents:trailers) shows error if semicolon is missing' ' + # error message cannot be checked under i18n + cat >expect <<-EOF && + fatal: unrecognized %(contents) argument: trailersonly + EOF + test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual && + test_i18ncmp expect actual +' + test_expect_success 'basic atom: head contents:trailers' ' git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual && sanitize_pgp actual.clean &&