From patchwork Fri Mar 26 02:40:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= X-Patchwork-Id: 12165639 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=-20.8 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,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 A616DC433C1 for ; Fri, 26 Mar 2021 02:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A7AB61A42 for ; Fri, 26 Mar 2021 02:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbhCZClV (ORCPT ); Thu, 25 Mar 2021 22:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbhCZCkx (ORCPT ); Thu, 25 Mar 2021 22:40:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06208C06174A for ; Thu, 25 Mar 2021 19:40:53 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id y124-20020a1c32820000b029010c93864955so4114324wmy.5 for ; Thu, 25 Mar 2021 19:40:52 -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=rtpZSf9kLrMAxrGnGcXqeP8HmTBX5KVYrwxGNDtBbmc=; b=bbaSLfSd5fAXFB2CQJNvOXTaPv0qGM+qdT8hDsdNkiUQTdRrC2f1DvL0TZIVJLm2CL XO2Rnk3G741ONc/tBmKOc4fpiRstjprQoHmvC/kGpP20AVbEXLRyLIuXVSaSWOoUQbDc ts8V9kxVO5SY6Dt5fxC/KbvK1kDNv2r1UG2eD37HKfTpxFXoPgIcu6nHgNaWZlXDyzyO 7czORnXzEBGovnkAlrMV6aesym61xMONqFveK5kLTNyEBsagsIl0yg2BLQzAtaBvHn7h c3YYxkmJoiVsK3YCfDMBQmA3yuCBkVD0Q0gjFTZ2jg4YzkiQYlmFPTD6N3RHOBP4mup6 F0Qg== 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=rtpZSf9kLrMAxrGnGcXqeP8HmTBX5KVYrwxGNDtBbmc=; b=NvIcWDbWiFfCO6JxRB73Iu9xVKyhIlu5Zj10Y8LV8AXhfUr1VuBjli3U3ndqAbReLf Y9cdeDOzIUba6PthOPvp+PgBLAf2dcs20Ubvf5TUf1p2v9zy81dgkMtB+CdbRRtyFrAD K7T1rLa95SaRscPtqTOiO5e9bNcRkrYnfhoDR/8fXar6lavyL82gwzMRf57E9bpuXDWP HosBtDyOb55Phgvcxfx6XBC5a6NFBlnlCNXuKhjma90W8DguwMTgvUfXh5zWRHMgH4dx ZHBHI/DUsBfx1ZJ6FKyWAjeXBkowuJunLHZ6AwGGDVFUPSjkQSeOGBf9tJQY654+0jk9 cVDw== X-Gm-Message-State: AOAM533WH3vJaX72iBpJWXqPmQoNPN1kXUSNlG/MCLbbjmvvoftR4JgM sJUjOLU9XZH2iR3bJegAhE5+mmmf4brAtbdI/ao= X-Google-Smtp-Source: ABdhPJxmiUEqO9PY3l+Cyvg1UgRIWPUSaZe5lgayKKQRziUJL3+PrhScRbAPUS6oDWarJrhHkyGbnQ== X-Received: by 2002:a1c:771a:: with SMTP id t26mr10818814wmi.60.1616726451352; Thu, 25 Mar 2021 19:40:51 -0700 (PDT) Received: from localhost.localdomain ([2a02:85f:2a0a:9300:501f:ca6d:3b18:1e72]) by smtp.googlemail.com with ESMTPSA id i10sm10020226wrs.11.2021.03.25.19.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 19:40:50 -0700 (PDT) From: " =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= " X-Google-Original-From: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= To: git Cc: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= , Junio C Hamano , Bagas Sanjaya , Stavros Ntentos <133706+stdedos@users.noreply.github.com> Subject: [RFC PATCH v1 1/2] pathspec: warn: long and short forms are incompatible Date: Fri, 26 Mar 2021 04:40:04 +0200 Message-Id: <20210326024005.26962-2-stdedos+git@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326024005.26962-1-stdedos+git@gmail.com> References: <20210326024005.26962-1-stdedos+git@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Namely, `!` and any other long magic form (e.g. `glob`) cannot be combined to one entry. Issue a warning when such thing happens, and hint to the solution. Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- pathspec.c | 19 +++++++++++++++++++ pathspec.h | 1 + t/t6132-pathspec-exclude.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/pathspec.c b/pathspec.c index 7a229d8d22..374c529569 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,3 +1,5 @@ +#include +#include #include "cache.h" #include "config.h" #include "dir.h" @@ -586,6 +588,8 @@ void parse_pathspec(struct pathspec *pathspec, for (i = 0; i < n; i++) { entry = argv[i]; + check_mishandled_exclude(entry); + init_pathspec_item(item + i, flags, prefix, prefixlen, entry); if (item[i].magic & PATHSPEC_EXCLUDE) @@ -739,3 +743,18 @@ int match_pathspec_attrs(const struct index_state *istate, return 1; } + +void check_mishandled_exclude(const char *entry) { + size_t entry_len = strlen(entry); + char flags[entry_len]; + char path[entry_len]; + + if (sscanf(entry, ":!(%4096[^)])%4096s", &flags, &path) != 2) { + return; + } + if (count_slashes(flags) > 0) { + return; + } + + warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); +} diff --git a/pathspec.h b/pathspec.h index 454ce364fa..879d4e82c6 100644 --- a/pathspec.h +++ b/pathspec.h @@ -157,5 +157,6 @@ char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); +void check_mishandled_exclude(const char* pathspec_entry); #endif /* PATHSPEC_H */ diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 30328b87f0..b32ddb2a56 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -244,4 +244,37 @@ test_expect_success 'grep --untracked PATTERN :(exclude)*FILE' ' test_cmp expect-grep actual-grep ' +cat > expected_warn <<"EOF" +Pathspec provided matches `:!(...)` +EOF +test_expect_success 'warn pathspec :!(...) skips the parenthesized magics' ' + git log --oneline --format=%s -- '"'"':!(glob)**/file'"'"' >actual 2>warn && + cat <expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + cat actual && + cat warn && + test_cmp expect actual && + grep -Ff expected_warn warn +' + +test_expect_success 'do not warn that pathspec :!(...) skips the parenthesized magics (if parenthesis would not be part of the magic)' ' + git log --oneline --format=%s -- '"'"':!(gl/ob)/file'"'"' >actual 2>warn && + cat <expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + test_cmp expect actual && + ! grep -Ff expected_warn warn +' + test_done From patchwork Fri Mar 26 02:40:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= X-Patchwork-Id: 12165637 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 E9E25C433DB for ; Fri, 26 Mar 2021 02:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C273661A45 for ; Fri, 26 Mar 2021 02:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbhCZClV (ORCPT ); Thu, 25 Mar 2021 22:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhCZClC (ORCPT ); Thu, 25 Mar 2021 22:41:02 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53BA3C06174A for ; Thu, 25 Mar 2021 19:41:02 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id z2so4202286wrl.5 for ; Thu, 25 Mar 2021 19:41:02 -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=jkDLve32JMC0r0BHgItMQAqLWUo+dvr45+IA4gmeZNs=; b=V0wBFgU72TebJ8lCYryX4W3Xt6qFSZFDntsWAv7D4DsTEHJ7nVdUmH3IaNEOb2fmd7 WTex+fwjdbfQE7KGXzGWRaq2EJ5+avl59NTiihK7GCjV5dORxRHiqvVbj6P2cwWVvfU8 gGANwQiisFZiCpLWRosBpfl5gWCF8J3QTqOZ/L726YZVIxbq0CJ7a1yxcr4LUaioPNdV eFP5WJtwclLjgFc/bUxNy48pflIKajP/AX1RDq/wRPoAA3XsQA1wqvW2Zvv4oSCkwkLZ JqcwtTYyNMvf1bLdW1D7AWi5NP1EiZzzOvehXw1OCUxfqVjP4127C62Y/MIP/Rjt0IRU Tw/g== 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=jkDLve32JMC0r0BHgItMQAqLWUo+dvr45+IA4gmeZNs=; b=kd50NGSFvuCBpbtytIH9eNZekxU6noTfME8Bx2WkQZlI5yk9Oc1E/rWiOS7KCdDV1j 4nKBWn7O856bQO+dKqU835x+U6oYp4qDMojpiOQyF48jq7CTY0wNEWc1lZIUMTl6+0pn 7jHVigkYpNtZ7VFxJMOxhu6ekc/4noDKQnFNFXtUKyT/OBmdew0dyFI/xmGQfbnljXRy 5omSgdxr601LN5xRV56P3LFXVcQ1ruYYEpymEqW8jny9nZIZotWpbp/iz+g9b4rb6H+f rV+B3CZhSPl4FX3MoC92rW4/CQCsaHmIRvxwTISN2qbhnbuaR5WRCI13r/hOsKaB+lgH 47DQ== X-Gm-Message-State: AOAM531mPTfUJVsmeCnmzQ5Jvl30n4xmU6yeIek9TNJexd49XbddWjwV kwg89A0SOOGo1lF0Aw54nHGQSQOdZ2QA2P/789w= X-Google-Smtp-Source: ABdhPJz1htPYigC5x8X3iWfEggydJTAp43CugUZSNj/3qgWZvMdMteEX5sX728h0k69XR1xdFOlq9g== X-Received: by 2002:a05:6000:1b0f:: with SMTP id f15mr12134278wrz.171.1616726460732; Thu, 25 Mar 2021 19:41:00 -0700 (PDT) Received: from localhost.localdomain ([2a02:85f:2a0a:9300:501f:ca6d:3b18:1e72]) by smtp.googlemail.com with ESMTPSA id i10sm10020226wrs.11.2021.03.25.19.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 19:41:00 -0700 (PDT) From: " =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= " X-Google-Original-From: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= To: git Cc: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= , Junio C Hamano , Bagas Sanjaya , Stavros Ntentos <133706+stdedos@users.noreply.github.com> Subject: [RFC PATCH v1 2/2] fixup! pathspec: warn: long and short forms are incompatible Date: Fri, 26 Mar 2021 04:40:05 +0200 Message-Id: <20210326024005.26962-3-stdedos+git@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326024005.26962-1-stdedos+git@gmail.com> References: <20210326024005.26962-1-stdedos+git@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> malloc and stuff --- pathspec.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pathspec.c b/pathspec.c index 374c529569..4ac8bfdc06 100644 --- a/pathspec.c +++ b/pathspec.c @@ -7,6 +7,7 @@ #include "attr.h" #include "strvec.h" #include "quote.h" +#include "git-compat-util.h" /* * Finds which of the given pathspecs match items in the index. @@ -745,16 +746,20 @@ int match_pathspec_attrs(const struct index_state *istate, } void check_mishandled_exclude(const char *entry) { + char *flags, *path; size_t entry_len = strlen(entry); - char flags[entry_len]; - char path[entry_len]; - if (sscanf(entry, ":!(%4096[^)])%4096s", &flags, &path) != 2) { - return; - } - if (count_slashes(flags) > 0) { - return; + flags = xstrdup(entry); + memset(flags, '\0', entry_len); + path = xstrdup(entry); + memset(path, '\0', entry_len); + + if (sscanf(entry, ":!(%4096[^)])%4096s", flags, path) == 2) { + if (count_slashes(flags) == 0) { + warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); + } } - warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); + FREE_AND_NULL(flags); + FREE_AND_NULL(path); }