From patchwork Tue Dec 22 03:58:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipunn Koorapati X-Patchwork-Id: 11985805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E908C433DB for ; Tue, 22 Dec 2020 03:59:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 433EB22CB1 for ; Tue, 22 Dec 2020 03:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726244AbgLVD7D (ORCPT ); Mon, 21 Dec 2020 22:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726103AbgLVD7C (ORCPT ); Mon, 21 Dec 2020 22:59:02 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43273C0613D6 for ; Mon, 21 Dec 2020 19:58:22 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id y23so848915wmi.1 for ; Mon, 21 Dec 2020 19:58:22 -0800 (PST) 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=BVYTgofx2vWv0hLPfqdADHe6fqD8GxjFNi7DELpOj00=; b=JUXHg51/ZMsE2zoV5yNcZrf5CwY3ALUPQpEpyr8WgVYC0A1vCHLR51pTLROhRwj6OR WWsCekA57+x3EyB0c3mSjKmcBLaiQCz6JR3b+IB0mM5U2rlIxhoRDZ0iknmbOnIjzOPj +Bf5kQwSJEQo8LIM/6BI6Ll4mPL1kZHTDh5QLurB/VO31ptI0wUB/x+KFw4vd1CgrDKb X+EaYD+PG1HHuhomagAHA2ppepj6YIsrl1RPxbrXzhZWR6eXgYIEkin3wxs3OYu37ypl e8FLOC+bxhjLlsIQk9BHdA6Wtf2OAHzpywvTNbfp9lbp3yCqT64L6JmAJZnjZ7e9Om/G kGwg== 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=BVYTgofx2vWv0hLPfqdADHe6fqD8GxjFNi7DELpOj00=; b=SfVQuClpQtnbGIX4Hme7E6KzYnNAPNHwzPUa/Cbu2/inCev87QfQKl8UuqbUot6aou EWiWh61+0cw3ynJayuocP8Pko2Jn5rNk/rfCYmsanPp9wbEsBdYZV87L0YphWH5SsnWx /aUZaP5IaesVd/xZmfzw3IEtlyrB29nO7WuhrNUbiTfNH6cxj47lbeYosN7YYs5yYi04 y4Y5lSW+C1PUDFXTaiWOeadF0Jm2UCQj29I6h44cMePsO+ROjdSVZu0h5r1aHYlZDLX/ nZiRy0l4zZduJVyTzeJ7VCnVOe+cWXi+7FbDj6xLrH5wrJ7OizSfztELdDF6tPhuPInU JNrg== X-Gm-Message-State: AOAM530/iWWVihoqdkbPd+CP8IFJeZe9H4Wfkk30mxZTXhCyYEbuDG08 z7AyATnmN4w95tG8z060h6ODbbtrx2U= X-Google-Smtp-Source: ABdhPJzuEwU6KhB7QPMbFhK8pUr4PXnIIrwovsuYFsQrQviuxV4HD8YO98TF2IHTGpVZv4fN7j1pVQ== X-Received: by 2002:a05:600c:25c2:: with SMTP id 2mr20188861wml.170.1608609500373; Mon, 21 Dec 2020 19:58:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q1sm28148075wrj.8.2020.12.21.19.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 19:58:19 -0800 (PST) Message-Id: <48c79dc3d84f55dec4cd2199cc4152e146bee0ba.1608609498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Dec 2020 03:58:16 +0000 Subject: [PATCH v5 1/2] negative-refspec: fix segfault on : refspec Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric Sunshine , Nipunn Koorapati , Nipunn Koorapati Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nipunn Koorapati From: Nipunn Koorapati The logic added to check for negative pathspec match by c0192df630 (refspec: add support for negative refspecs, 2020-09-30) looks at refspec->src assuming it is never NULL, however when remote.origin.push is set to ":", then refspec->src is NULL, causing a segfault within strcmp. Tell git to handle matching refspec by adding the needle to the set of positively matched refspecs, since matching ":" refspecs match anything as src. Add test for matching refspec pushes fetch-negative-refspec both individually and in combination with a negative refspec. Signed-off-by: Nipunn Koorapati Reviewed-by: Jacob Keller --- remote.c | 10 ++++-- t/t5582-fetch-negative-refspec.sh | 51 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/remote.c b/remote.c index 8be67f0892b..4f1a4099f1a 100644 --- a/remote.c +++ b/remote.c @@ -751,9 +751,13 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite if (match_name_with_pattern(key, needle, value, &expn_name)) string_list_append_nodup(&reversed, expn_name); - } else { - if (!strcmp(needle, refspec->src)) - string_list_append(&reversed, refspec->src); + } else if (refspec->matching) { + /* For the special matching refspec, any query should match */ + string_list_append(&reversed, needle); + } else if (!refspec->src) { + BUG("refspec->src should not be null here"); + } else if (!strcmp(needle, refspec->src)) { + string_list_append(&reversed, refspec->src); } } diff --git a/t/t5582-fetch-negative-refspec.sh b/t/t5582-fetch-negative-refspec.sh index 8c61e28fec8..2f3b064d0e7 100755 --- a/t/t5582-fetch-negative-refspec.sh +++ b/t/t5582-fetch-negative-refspec.sh @@ -186,4 +186,55 @@ test_expect_success "fetch --prune with negative refspec" ' ) ' +test_expect_success "push with matching : and negative refspec" ' + # Manually handle cleanup, since test_config is not + # prepared to take arbitrary options like --add + test_when_finished "test_unconfig -C two remote.one.push" && + + # For convenience, we use "master" to refer to the name of + # the branch created by default in the following. + # + # Repositories two and one have branches other than "master" + # but they have no overlap---"master" is the only one that + # is shared between them. And the master branch at two is + # behind the master branch at one by one commit. + git -C two config --add remote.one.push : && + + # A matching push tries to update master, fails due to non-ff + test_must_fail git -C two push one && + + # "master" may actually not be "master"---find it out. + current=$(git symbolic-ref HEAD) && + + # If master is in negative refspec, then the command will not attempt + # to push and succeed. + git -C two config --add remote.one.push "^$current" && + + # With "master" excluded, this push is a no-op. Nothing gets + # pushed and it succeeds. + git -C two push -v one +' + +test_expect_success "push with matching +: and negative refspec" ' + test_when_finished "test_unconfig -C two remote.one.push" && + + # The same set-up as above, whose side-effect was a no-op. + git -C two config --add remote.one.push +: && + + # The push refuses to update the "master" branch that is checked + # out in the "one" repository, even when it is forced with +: + test_must_fail git -C two push one && + + # "master" may actually not be "master"---find it out. + current=$(git symbolic-ref HEAD) && + + # If master is in negative refspec, then the command will not attempt + # to push and succeed + git -C two config --add remote.one.push "^$current" && + + # With "master" excluded, this push is a no-op. Nothing gets + # pushed and it succeeds. + git -C two push -v one +' + test_done From patchwork Tue Dec 22 03:58:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipunn Koorapati X-Patchwork-Id: 11985803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A3C2C433E0 for ; Tue, 22 Dec 2020 03:59:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F9B622ADC for ; Tue, 22 Dec 2020 03:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726263AbgLVD7D (ORCPT ); Mon, 21 Dec 2020 22:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbgLVD7D (ORCPT ); Mon, 21 Dec 2020 22:59:03 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 971C1C061793 for ; Mon, 21 Dec 2020 19:58:22 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id x22so717138wmc.5 for ; Mon, 21 Dec 2020 19:58:22 -0800 (PST) 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=78P5B0EZI5YNm8H+irWULeMUTdacwATcznV9pFTYRBU=; b=hDhwqbDfCHHuswmXRCGol0jbA+/15YNJHGswA5mc5FfP+kwkEhmBf2GE6s+BCJiv81 /XF0ufBt0K15vg18X2SJBASSrqOK0e8iJtTWVtDFzBVMUfO0L7zhV/nWxJ7DHbgZcee0 Lglhfb2wugg509mhovrmfMMDPsfpg25HTjeUPXunEPsBSCuGGM8N4G+lzWznJ6Z6abhL XzQTJNge+hRyDyXIYoXTFrXX4d5Vn1LGHCfWt3L8atMZHCJv94z0p9c1qBb1V+uXHtr2 CyyDDTlQN6rjp4m6ssirETMjNmUg8UqJT6oKPmMc/7sfN+IaSL3HKinHA4I1gFFy9b7p NU/Q== 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=78P5B0EZI5YNm8H+irWULeMUTdacwATcznV9pFTYRBU=; b=Vcb/FeG9iPLpq0XofdNIy5pGr2HuYvFsInVkD7Q6wdH6SeaqgCURT2UTYbahJbhStY eq5WTIcl9WWlmakKYpvVLazAMZbu0saHJxzXFoGsYu2stN4Cb9Xi6LXd4oCXDqWZpfme XR2oCvyobk/45oNbmY4andsY2mbgW47bOgBuV0Ex5e0fU0KlxxeqaQZ8y6Wt9x38tAVU KgrO9NBqq2lY2KI2+Sp2c6FO781kA13FTc1iQjBKqTUDMWr3M4U9xrsoOd1TxyZJq24V i0ASi7JqbErAX65MfVhtzq7YpSIO1ciH2YSO80yBrdmZKmoFk+dBHUtBha5I6WXthefv 9sxQ== X-Gm-Message-State: AOAM532NknXFF4VAtcPqT5xdYOnNZmrADIygvwCLbkAggwwD/asNlcKa SeHpBdq+NYSD6ECzp0+10lgn7qE1aP0= X-Google-Smtp-Source: ABdhPJyd5svtqP0BEo5gsyIRzFyddVJJ1JWFq++5pGKbdlzTD17/p3yqM//OY58zJk1TQbqtrtdJrw== X-Received: by 2002:a1c:c287:: with SMTP id s129mr19692931wmf.79.1608609501266; Mon, 21 Dec 2020 19:58:21 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y11sm24865083wmi.0.2020.12.21.19.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 19:58:20 -0800 (PST) Message-Id: <1f9af0e991c0b84cd00641322f2d76bdc8fbeb29.1608609498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Dec 2020 03:58:17 +0000 Subject: [PATCH v5 2/2] negative-refspec: improve comment on query_matches_negative_refspec Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric Sunshine , Nipunn Koorapati , Nipunn Koorapati Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Nipunn Koorapati From: Nipunn Koorapati Comment did not adequately explain how the two loops work together to achieve the goal of querying for matching of any negative refspec. Signed-off-by: Nipunn Koorapati --- remote.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/remote.c b/remote.c index 4f1a4099f1a..4d150a316ed 100644 --- a/remote.c +++ b/remote.c @@ -736,6 +736,12 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite * item uses the destination. To handle this, we apply pattern * refspecs in reverse to figure out if the query source matches any * of the negative refspecs. + * + * The first loop finds and expands all positive refspecs + * matched by the queried ref. + * + * The second loop checks if any of the results of the first loop + * match any negative refspec. */ for (i = 0; i < rs->nr; i++) { struct refspec_item *refspec = &rs->items[i];