From patchwork Wed Sep 2 06:17:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749871 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 E750B166C for ; Wed, 2 Sep 2020 06:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C90CD2078B for ; Wed, 2 Sep 2020 06:18:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="M8+yVh6J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbgIBGSB (ORCPT ); Wed, 2 Sep 2020 02:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgIBGR7 (ORCPT ); Wed, 2 Sep 2020 02:17:59 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42DBC061244 for ; Tue, 1 Sep 2020 23:17:58 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id f11so388576qvw.3 for ; Tue, 01 Sep 2020 23:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OwHyUezafLtE2AXnzr/cZDF+mCgHLxtf+oKcpVzOsn4=; b=M8+yVh6JnkOuQJDS+Ycc2FLsp3uZB8UqD3x1v5/7LKt8z6uV10z6v6jreYl7+Tz6y5 Gc/xKTcXPYxevldsZspFSVKm/eEDNc3m4eDffrtImeLraDj+/dKcyZvjkKTl9umGtO4R ++vAV26PUzM9riA48OqkI+C4YYuK4Vjz1AMmi9GlZ5CzG+JoMWsW6qc8xgZz41so+dG4 ZalFVxJI1THQJiC8o1OOA6qo2hp5ngOVP8z+mJTLPtAUfs5WFna5E0vtY6aPE9CG4oJq 8pTRjTvV1Ican/xfoj6WVjlstQOeKriSo/t5pNLBVizGWoemmVXtpYgvotDMbigK/ZFi pXkA== 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=OwHyUezafLtE2AXnzr/cZDF+mCgHLxtf+oKcpVzOsn4=; b=fJnoK1y6bQ45XIOejGYNS25gtYl9pWFndKCdkDF6uEeQ9geD/UdThuzX91nufNlG/o uajLgwK0FEZBWE79XoCE5Q1amTVvBneDy550lfVqXKRaMB+XZ1PI2JCh5j8dyCNDzk7k wrWB08kOixyk+xYjSJqcqr+VV7WxblwF2LAIRsmNojHjN4v03H5x2UuLkHcRXoirvvL+ nwXJCZ6ng3tNIUzAnjVeXnHnzDllm2OfNHE6UtwljthA671G4Vg7+Gyr7ufoi3o0og20 z3q9f3rzysKkpBRd4aJNythxkhhfTSwvRcyax6j08gG6zC8TSAekpZqQpQJqnHaIfR1U CEbA== X-Gm-Message-State: AOAM5334LUoPg4MazAEcbLHLvEs5gjq9skPtRhJ1X8MvsnUbriy5A/38 JaF+krf+n76Je1rVFcyysmhFWb1brYWx/Q== X-Google-Smtp-Source: ABdhPJwamy8SYmluQ9WlOVkg2MC+2tmf9nQ5W54FXaglM0RKFS8mdprc1anYrCjfrjyHPbt7yoaTLQ== X-Received: by 2002:a05:6214:1108:: with SMTP id e8mr5622051qvs.237.1599027477668; Tue, 01 Sep 2020 23:17:57 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:17:56 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 1/8] doc: grep: unify info on configuration variables Date: Wed, 2 Sep 2020 03:17:30 -0300 Message-Id: <70c9a4e7415f532c2aa6fdd460a927b5e677cd97.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Explanations about the configuration variables for git-grep are duplicated in "Documentation/git-grep.txt" and "Documentation/config/grep.txt", which can make maintenance difficult. The first also contains a definition not present in the latter (grep.fullName). To avoid problems like this, let's unify the information in the second file and include it in the first. Signed-off-by: Matheus Tavares --- Documentation/config/grep.txt | 10 ++++++++-- Documentation/git-grep.txt | 36 ++++++----------------------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index 44abe45a7c..dd51db38e1 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -16,8 +16,14 @@ grep.extendedRegexp:: other than 'default'. grep.threads:: - Number of grep worker threads to use. - See `grep.threads` in linkgit:git-grep[1] for more information. + Number of grep worker threads to use. See `--threads` +ifndef::git-grep[] + in linkgit:git-grep[1] +endif::git-grep[] + for more information. + +grep.fullName:: + If set to true, enable `--full-name` option by default. grep.fallbackToNoIndex:: If set to true, fall back to git grep --no-index if git grep diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index a7f9bc99ea..9bdf807584 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -41,34 +41,8 @@ characters. An empty string as search expression matches all lines. CONFIGURATION ------------- -grep.lineNumber:: - If set to true, enable `-n` option by default. - -grep.column:: - If set to true, enable the `--column` option by default. - -grep.patternType:: - Set the default matching behavior. Using a value of 'basic', 'extended', - 'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`, - `--fixed-strings`, or `--perl-regexp` option accordingly, while the - value 'default' will return to the default matching behavior. - -grep.extendedRegexp:: - If set to true, enable `--extended-regexp` option by default. This - option is ignored when the `grep.patternType` option is set to a value - other than 'default'. - -grep.threads:: - Number of grep worker threads to use. If unset (or set to 0), Git will - use as many threads as the number of logical cores available. - -grep.fullName:: - If set to true, enable `--full-name` option by default. - -grep.fallbackToNoIndex:: - If set to true, fall back to git grep --no-index if git grep - is executed outside of a git repository. Defaults to false. - +:git-grep: 1 +include::config/grep.txt[] OPTIONS ------- @@ -269,8 +243,10 @@ providing this option will cause it to die. found. --threads :: - Number of grep worker threads to use. - See `grep.threads` in 'CONFIGURATION' for more information. + Number of grep worker threads to use. If not provided (or set to + 0), Git will use as many worker threads as the number of logical + cores available. The default value can also be set with the + `grep.threads` configuration. -f :: Read patterns from , one per line. From patchwork Wed Sep 2 06:17:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749875 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 A69BF109A for ; Wed, 2 Sep 2020 06:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DEE0207DE for ; Wed, 2 Sep 2020 06:18:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="m6Ctl2IJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgIBGSH (ORCPT ); Wed, 2 Sep 2020 02:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgIBGSD (ORCPT ); Wed, 2 Sep 2020 02:18:03 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59A4C061244 for ; Tue, 1 Sep 2020 23:18:02 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id x12so2817476qtp.1 for ; Tue, 01 Sep 2020 23:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0VberAqpc1x0Z+mFJnxBDTxTAo9C56gpsKF8M/TTdK4=; b=m6Ctl2IJe4lXVt6Dvv3mYdPq7KMPE0LFjF1uJ0jmf7lIVOT6Nqx2ClOIs5AEOgr0cs b9Tqiaw9ChyUD7EGwGKEobNk4RxbWSQ5OCRX/xMhcdkZaAkSN/FeZ+p/er1f4YkSzB6A C59XPNBxQ3bOBE50XYwklNj3MyEkd27r2EZknAQBlASP5nWIME8cRTfT/WM8xfYE39cs /6sUo/xt1yhI7uArCK5clNo9r4vgWAUz1BaCQ2Il0ZyQmfygU9Ux6BtFC55AKHA5YOkV e3v/4n4bPuxyC4wzriiFzltj+62rBb/SvkA0BRddWgdUK1TvNS7wXW/gjRe/LB+Z1fQi nl6A== 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=0VberAqpc1x0Z+mFJnxBDTxTAo9C56gpsKF8M/TTdK4=; b=PN6N/cUpEqptOtKwwbxW/yMCcrRWk3RWa3cDXHaxYz4PSPtfx0wttOtuoLrVlJrHvE 1RzROAnJUQP1GpfNmETItfTTz1NAigHudsuaVLfFajy7SGBtCOrvmkHVK9VGCVqK1uBO akpFmP7tlss6sTl1TXPbuAPdVGQvHikt33y58NOFoWeXb9FE3zZZT5LNMTRnsjyfWVD5 ZFceyKgOcIa0qwuX73oD0lUDdGHLkLMR94Pl6Rit4PEu0DLLlLSCqUQS0iqMSVjt8goS T1FdJwqUaMDYFMeC0SFGZlUa4vdUVPQmhF3AMlmSvpKod3BFkEgSrqoAfgw4yRd8Xd4s qv8g== X-Gm-Message-State: AOAM530maSKzUFr25PIDgyCc0uIsTRovMWZ+KODQsnx8kjtMMprAskfU cjbVPaZg6IX7nyvP7yWtAqT6UvhXy4Ir3A== X-Google-Smtp-Source: ABdhPJzNUFa7cwbEL90qw5XoTceTEJjCT2TH70U6toDyMa1uM1JHeK9O6FG+PwPkz+BegAPFJR2MyQ== X-Received: by 2002:aed:2a01:: with SMTP id c1mr208714qtd.24.1599027480927; Tue, 01 Sep 2020 23:18:00 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:00 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 2/8] t1308-config-set: avoid false positives when using test-config Date: Wed, 2 Sep 2020 03:17:31 -0300 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org One test in t1308 expects test-config to fail with exit code 128 due to a parsing error in the config machinery. But test-config might also exit with 128 for any other reason that leads it to call die(). Therefore the test can potentially succeed for the wrong reason. To avoid false positives, let's check test-config's output, in addition to the exit code, and make sure that the cause of the error is the one we expect in this test. Moreover, the test was using the auxiliary function check_config which optionally takes a string to compare the test-config stdout against. Because this string is optional, there is a risk that future callers may also check only the exit code and not the output. To avoid that, make the string parameter of this function mandatory. Signed-off-by: Matheus Tavares --- t/t1308-config-set.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 3a527e3a84..cff17120dc 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -14,10 +14,7 @@ check_config () { expect_code=0 fi && op=$1 key=$2 && shift && shift && - if test $# != 0 - then - printf "%s\n" "$@" - fi >expect && + printf "%s\n" "$@" >expect && test_expect_code $expect_code test-tool config "$op" "$key" >actual && test_cmp expect actual } @@ -130,7 +127,8 @@ test_expect_success 'check line error when NULL string is queried' ' ' test_expect_success 'find integer if value is non parse-able' ' - check_config expect_code 128 get_int lamb.head + test_expect_code 128 test-tool config get_int lamb.head 2>result && + test_i18ngrep "fatal: bad numeric config value '\'none\'' for '\'lamb.head\''" result ' test_expect_success 'find bool value for the entered key' ' From patchwork Wed Sep 2 06:17:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749877 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 3545914E3 for ; Wed, 2 Sep 2020 06:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 192822078B for ; Wed, 2 Sep 2020 06:18:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="SIfRq1b6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726537AbgIBGSL (ORCPT ); Wed, 2 Sep 2020 02:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbgIBGSF (ORCPT ); Wed, 2 Sep 2020 02:18:05 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A7DC061245 for ; Tue, 1 Sep 2020 23:18:04 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id p4so3389755qkf.0 for ; Tue, 01 Sep 2020 23:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i4y+U4GTGlNUPsaLRPbaZMHdUUBXALPwCNHtrAHuNn4=; b=SIfRq1b6IVuFbSvetDrVnTB9dU2ocWtrI0OJmGy20tlLd/uGGRWGdn6D6GnDBF/nI3 BhuFgDzDB6m1m8O4RqegM0heR9ID3yJE0JkvThst5DGlvM5C+4U+vARrDaHX9oc9WyIj P5sYSuikEa3PPSa5vDD1A/Z14p3VdSFRafK2HlYYJBwnZWOuBjfqi3W+a2vjITqcgzEJ O7Ppn+aVtRMggeTSbGXDORC7l5Zf1L9amT2D0/H97CvC+llETABr8aQxr9txlBHLLD6I k5x1Pwm10KjBFSShzmqksaTUXXg88m5qRNvjrta9fLOqOWtMTX3NWjk+CG411t0d9B79 ANkg== 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=i4y+U4GTGlNUPsaLRPbaZMHdUUBXALPwCNHtrAHuNn4=; b=FGrxMeunTUM+Xtzj8pokpJq5AjzLJWFf3N/+sUtFRGDZ0zZWyQGoTSUvH3ew1/PZKI NW7T9X1LsDNPcJVNJKbHKPtScNaVXyECxueI7Jt4k5iqFTUogHucWZJdbSkNFYd6O5oz gev5Kk/yy6/xsuVbBdjXit/xB0BU4msUg/GlzP3PDzlO8pDdDvqjPzr5K3nMVGbxajRX pnfvvXVXrFOh2v4VNLkOtIuGK/Ol0KVfUN/fykk3F3xHsIDtJcQ+LOBkl5vDbbL2xPjg l3JEln2HE2hXJ17fGwRl/g1FySQu6MnDdRInhs7SvubHOeveHowh0R8vU3xlPtCrVRS1 9e5Q== X-Gm-Message-State: AOAM530X83wmKInLODxla9kZU9sSEs0/ichKzC/Z8wYGcEKV65p/UlVN rGutwtsnpFydTMKnoSaupdLsa7M0o3YLRw== X-Google-Smtp-Source: ABdhPJxoXdC9rHHaAiApMUdu8e1zgm+iCHJ915J/KkNzskc/KdD0/ge8p8BJ7Zfp6xkAqAS4eQkOHw== X-Received: by 2002:a37:7bc1:: with SMTP id w184mr5478098qkc.403.1599027483780; Tue, 01 Sep 2020 23:18:03 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:02 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 3/8] t/helper/test-config: be consistent with exit codes Date: Wed, 2 Sep 2020 03:17:32 -0300 Message-Id: <85e1588d6c5431c32fe0262671df1d247d98b83e.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The test-config helper can return at least three different exit codes to reflect the status of the requested operation. And these codes are checked in some of the tests. But there is an inconsistent place in the helper where an usage error returns the same code as a "value not found" error. Let's fix that and, while we are here, document the meaning of each exit code in the file's header. Signed-off-by: Matheus Tavares --- t/helper/test-config.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/t/helper/test-config.c b/t/helper/test-config.c index a6e936721f..9e9d50099a 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -30,6 +30,11 @@ * iterate -> iterate over all values using git_config(), and print some * data for each * + * Exit codes: + * 0: success + * 1: value not found for the given config key + * 2: config file path given as argument is inaccessible or doesn't exist + * * Examples: * * To print the value with highest priority for key "foo.bAr Baz.rock": @@ -80,10 +85,10 @@ int cmd__config(int argc, const char **argv) git_configset_init(&cs); - if (argc < 2) { - fprintf(stderr, "Please, provide a command name on the command-line\n"); - goto exit1; - } else if (argc == 3 && !strcmp(argv[1], "get_value")) { + if (argc < 2) + die("Please, provide a command name on the command-line"); + + if (argc == 3 && !strcmp(argv[1], "get_value")) { if (!git_config_get_value(argv[2], &v)) { if (!v) printf("(NULL)\n"); From patchwork Wed Sep 2 06:17:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749879 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 50C8F109A for ; Wed, 2 Sep 2020 06:18:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37E4D207EA for ; Wed, 2 Sep 2020 06:18:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="hXQaEoKr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbgIBGSR (ORCPT ); Wed, 2 Sep 2020 02:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726489AbgIBGSJ (ORCPT ); Wed, 2 Sep 2020 02:18:09 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4FA1C061245 for ; Tue, 1 Sep 2020 23:18:08 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id cr8so1708932qvb.10 for ; Tue, 01 Sep 2020 23:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gutTMBWQcXZvTvbeTWmzfnFmvj4Welmjr1oQOJ5ojyU=; b=hXQaEoKryn9X7me+IoA4WJgYSggDUPfdVa0tEux+0bcaFvjep4/MMyhp7ibiOGUtcD Jh5+Z7aIq+KsaWGzTgvK+GrSlWMq2lwrW5KF5NQkegoqm+dWUCU9cSUINy/tRh1Wo+Ks IwbWy5A4OmNuYLfFznBVI7cq7bv0H/K8WBcndrvXxfZfvc2p7jJiCN0BGyPnz4efoM6k rVcta2QktcqxDng95zBSQZiY9Zghfp3CJvg597mDNUZGd7V6DM4bMJwpk93GagXueK7r NRGZC4OlpjvOCxKx2jCRH4+sYI2AJF+B3e9N8X0qE79KWUwRmAO1tOmzD9WJNvxPo2mA I7Mg== 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=gutTMBWQcXZvTvbeTWmzfnFmvj4Welmjr1oQOJ5ojyU=; b=MERwGuaAVeVOnskkTKJfQ9y1pFjsOk9Sis6+O1riBpHeQtF1IpVqZb6EaHceTWIHeh dmmqH/HWs2jJ4YK7qjWTjs2nVW+xC1timGugZw8Rg10C2v8hEZUMz/nMmDMeyCgnxWT+ DenJQ3jOcEPqLn85h5DiTg4qYX8xvqmt9qcvIESndXr4adtOg/lEbgbxPyIYo6Jejz6t hFhVggJmLHYzCSHtoTgsu7i+wubOu9biFByPK4lsDeakrr6wdL1p4GY6w9JdJNhiIFmG RvusTXXWHLM9ibSdKDkrqmcZPqxg8C7/jphlypebNJHTRLnPxtewYl9IRvLbzpWKv6WH jIRg== X-Gm-Message-State: AOAM532346gbdcduXdb9sRRbC1o3hayHOHXUHUMVNZ0xvqsOteKgIDyw aPm44h41pdpFxQzMUO/xySuA3NKYQ6PaDw== X-Google-Smtp-Source: ABdhPJxZk+avD2PeGy/L3MsTsHyDRKCVso2FU4c1tAHHBG0Z76bCToyiAC190pt9XsT2HFzJFfXnGQ== X-Received: by 2002:a05:6214:570:: with SMTP id cj16mr5561143qvb.24.1599027486488; Tue, 01 Sep 2020 23:18:06 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:05 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 4/8] t/helper/test-config: check argc before accessing argv Date: Wed, 2 Sep 2020 03:17:33 -0300 Message-Id: <0750191342754bcca398c6fdad522616b0f3fbc3.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Check that we have the expected argc in 'configset_get_value' and 'configset_get_value_multi' before trying to access argv elements. Signed-off-by: Matheus Tavares --- t/helper/test-config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 9e9d50099a..26d9c2ac4c 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -138,7 +138,7 @@ int cmd__config(int argc, const char **argv) printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } - } else if (!strcmp(argv[1], "configset_get_value")) { + } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { @@ -156,7 +156,7 @@ int cmd__config(int argc, const char **argv) printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } - } else if (!strcmp(argv[1], "configset_get_value_multi")) { + } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value_multi")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { From patchwork Wed Sep 2 06:17:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749881 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 2FF16109A for ; Wed, 2 Sep 2020 06:18:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10F2B2078B for ; Wed, 2 Sep 2020 06:18:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="ynwq8t8C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbgIBGSU (ORCPT ); Wed, 2 Sep 2020 02:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgIBGSK (ORCPT ); Wed, 2 Sep 2020 02:18:10 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608B8C061246 for ; Tue, 1 Sep 2020 23:18:10 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id n133so3177328qkn.11 for ; Tue, 01 Sep 2020 23:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dESF7Sm/w3iAeMF9TzCd7uzNUhtLayXGCYW6gi807Ss=; b=ynwq8t8C/k/OJRcO3CGvAbMLhozwhcceEGGGBbx2f/f7WOOcF4I+AmPX0wlz8UJgoV 1Ei4fk+MeF2Y1nM5exr8XVvS5US2smbLbLS8h3nBiDnVAmWlAcM1ncPmB1rp0yjgQUBM 2NCO3vLiVS4sQwPIvgVCoyJWM/FK0n3jYNmprm1Ua0eW0v33ZOd4PHbhDCdXg6cZmRZU RjFwuM7VsJVW6KNzNa7pUG+vJdL2jIUT3JaxeQGr2xd8LMZzb0Vj9TtIj1EPfLRNbZC+ SsG3/ujMgtf3slL8lgjX1+pzJISlDCQ7vmRgMj2BAmbU61LwvMZduTT7iFHcrFuNsydP NS7g== 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=dESF7Sm/w3iAeMF9TzCd7uzNUhtLayXGCYW6gi807Ss=; b=gtsb2CjztqLJ2zENtOEyQ2q6RaQmOT9bFs/FSizBF1XxLucdbAmQ0H/dAvzPHG92pp 4mvohg+CgZwrg5vz7BRHt1lkgmhEYy3J5W1a9zkyPyg7UmBboJgY4AbCcwOE54PIo/2/ qdXcDRjA3sdkN6Z8aw3PdixYqJqwKqnf7VgKsPPnOd97Vxwh6JzBeQJmyyMFskf9xMgx g9kDRa+KtTFNthpSUhABSTgkuhcx2HW3JCGAMqNiIMOpMgNZi6tP/AKHXeS6EOZJkVEA nDnrCOqClizxJgEVo+rvEpCkRd5F9T0LGw9SlUP3chZSi1usbdtM7qN/nrE40oZ2Quc4 sGRw== X-Gm-Message-State: AOAM531u7qTBeBwmok4lW9rU4JDCK7x0/8VsgYyA6IjQlmd3hDfgHx4L d+PIDzVZrI2zMj2jkRBf60YofDvFVWwdQQ== X-Google-Smtp-Source: ABdhPJxiHk3VZaJU+VxcIozUS1s2wtnyjBF4b2O0CYfKf3z2h9B2LIwmRm3zheNClxXEvFnyRibOvQ== X-Received: by 2002:a37:e82:: with SMTP id 124mr5461977qko.77.1599027489173; Tue, 01 Sep 2020 23:18:09 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:08 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 5/8] t/helper/test-config: unify exit labels Date: Wed, 2 Sep 2020 03:17:34 -0300 Message-Id: <56535b0e36e94dc73aa570f4f3c0466305c6432f.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org test-config's main function has three different exit labels, all of which have to perform the same cleanup code before returning. Unify the labels in preparation for the next patch which will increase the cleanup section. Signed-off-by: Matheus Tavares --- t/helper/test-config.c | 51 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 26d9c2ac4c..8fe43e9775 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -69,16 +69,19 @@ static int early_config_cb(const char *var, const char *value, void *vdata) return 0; } +#define TC_VALUE_NOT_FOUND 1 +#define TC_CONFIG_FILE_ERROR 2 + int cmd__config(int argc, const char **argv) { - int i, val; + int i, val, ret = 0; const char *v; const struct string_list *strptr; struct config_set cs; if (argc == 3 && !strcmp(argv[1], "read_early_config")) { read_early_config(early_config_cb, (void *)argv[2]); - return 0; + return ret; } setup_git_directory(); @@ -94,10 +97,9 @@ int cmd__config(int argc, const char **argv) printf("(NULL)\n"); else printf("%s\n", v); - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) { strptr = git_config_get_value_multi(argv[2]); @@ -109,41 +111,38 @@ int cmd__config(int argc, const char **argv) else printf("%s\n", v); } - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_int")) { if (!git_config_get_int(argv[2], &val)) { printf("%d\n", val); - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_bool")) { if (!git_config_get_bool(argv[2], &val)) { printf("%d\n", val); - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_string")) { if (!git_config_get_string_tmp(argv[2], &v)) { printf("%s\n", v); - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]); - goto exit2; + ret = TC_CONFIG_FILE_ERROR; + goto out; } } if (!git_configset_get_value(&cs, argv[2], &v)) { @@ -151,17 +150,17 @@ int cmd__config(int argc, const char **argv) printf("(NULL)\n"); else printf("%s\n", v); - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value_multi")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]); - goto exit2; + ret = TC_CONFIG_FILE_ERROR; + goto out; } } strptr = git_configset_get_value_multi(&cs, argv[2]); @@ -173,27 +172,17 @@ int cmd__config(int argc, const char **argv) else printf("%s\n", v); } - goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); - goto exit1; + ret = TC_VALUE_NOT_FOUND; } } else if (!strcmp(argv[1], "iterate")) { git_config(iterate_cb, NULL); - goto exit0; + } else { + die("%s: Please check the syntax and the function name", argv[0]); } - die("%s: Please check the syntax and the function name", argv[0]); - -exit0: - git_configset_clear(&cs); - return 0; - -exit1: - git_configset_clear(&cs); - return 1; - -exit2: +out: git_configset_clear(&cs); - return 2; + return ret; } From patchwork Wed Sep 2 06:17:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749883 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 1DE23109A for ; Wed, 2 Sep 2020 06:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE20C2078B for ; Wed, 2 Sep 2020 06:18:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="G5yebAdo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgIBGSW (ORCPT ); Wed, 2 Sep 2020 02:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726311AbgIBGSO (ORCPT ); Wed, 2 Sep 2020 02:18:14 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C08AC061247 for ; Tue, 1 Sep 2020 23:18:14 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id x12so2817761qtp.1 for ; Tue, 01 Sep 2020 23:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RDCTjUqGtrqsojg5+9uvNRFT3Rkdj5hAmOW6dYdpW6o=; b=G5yebAdoYNVMwqtgdNl/Cp5xR9Eo7P4XZvrICcMdPbpKrj8GWuYWaYii+g7tezfMzA Pk+y367jCpsYn7VHwkkaGy//Xta2ibA/49MHgRflEajBJo5g/0Ic9r6oWziHYmZ+og2c hh48eLTa8Mb9RocI8EHxCV0Ppeb1r/b9+nD9Eb3houNVA1GIW6Rw/WdM2yjx3y80ITli 4gOpxM6c+0rFio5mDSZkLSY+3hYAIG8MfCOtQdB523ra97a4QIODr9KTgs8ylgTniutR JiiQbjL7lBFBGMjK8b3kuL8UeBWsdXMHFKUW7xWPtobFbNz+JD9rs0sDXeTxJMTeXK2E 1E7g== 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=RDCTjUqGtrqsojg5+9uvNRFT3Rkdj5hAmOW6dYdpW6o=; b=EsIRZyiu9mOdr3zCl3GkYdCSMFGW6xzaWeDpyBd37mg/wsRVyYjXfutpHDcH4a9pW6 3DvDFN5/9a9dyxVXFItrbFX/coCRFJRBmuo2HFWlcyBYg0JPW7rCUdw+lJHUoIC94mjL h8u3XD9xKkUVvA9ynKmykdM4AxA8BGLKyt6mkhhDyfz8rmSg68bEy7wjV7O3WXB09as6 qBnmlw1BV7gfjyCw/6uvKde4xGKg4xn8ABXA0VDklA+n/330RzXFFFkCsMw9M7JqjvE5 JtdE8VF1nO0O6pS83mA5DSpurArTnFW/7HSfVHGB3usKmkyXbGHhF1P8uF8PwErgtQEx hDIg== X-Gm-Message-State: AOAM531+WFyRaBMzHZpr6ndF/YXqBCOwiQb5mZKlgdfda9GNDfy71f6N m/2f2Q3pWPYPHIdRfCUs6uyKjiJ2wLaxig== X-Google-Smtp-Source: ABdhPJyFZevitivj7CGeHOEPSY28WxqkZQqnnuUzB52ykRnWFLEM238Sxg9/8mGeZNw+A7vkdrr4HQ== X-Received: by 2002:ac8:6d32:: with SMTP id r18mr5517491qtu.246.1599027493061; Tue, 01 Sep 2020 23:18:13 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:12 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 6/8] config: correctly read worktree configs in submodules Date: Wed, 2 Sep 2020 03:17:35 -0300 Message-Id: <3e02e1bd248438e0b435a19d857432edcaa15a2c.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The config machinery is not able to read worktree configs from a submodule in a process where the_repository represents the superproject. Furthermore, when extensions.worktreeConfig is set on the superproject, querying for a worktree config in a submodule will, instead, return the value set at the superproject. The problem resides in do_git_config_sequence(). Although the function receives a git_dir string, it uses the_repository->git_dir when making the path to the worktree config file. And when checking if extensions.worktreeConfig is set, it uses the global repository_format_worktree_config variable, which refers to the_repository only. So let's fix this by using the git_dir given to the function and reading the extension value from the right place. Also add a test to avoid any regressions. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Nieder --- config.c | 21 ++++++++++--- t/helper/test-config.c | 62 ++++++++++++++++++++++++++++++++------ t/t2404-worktree-config.sh | 16 ++++++++++ 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/config.c b/config.c index 2bdff4457b..e1e7fab6dc 100644 --- a/config.c +++ b/config.c @@ -1747,11 +1747,22 @@ static int do_git_config_sequence(const struct config_options *opts, ret += git_config_from_file(fn, repo_config, data); current_parsing_scope = CONFIG_SCOPE_WORKTREE; - if (!opts->ignore_worktree && repository_format_worktree_config) { - char *path = git_pathdup("config.worktree"); - if (!access_or_die(path, R_OK, 0)) - ret += git_config_from_file(fn, path, data); - free(path); + if (!opts->ignore_worktree && repo_config && opts->git_dir) { + struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; + struct strbuf buf = STRBUF_INIT; + + read_repository_format(&repo_fmt, repo_config); + + if (!verify_repository_format(&repo_fmt, &buf) && + repo_fmt.worktree_config) { + char *path = mkpathdup("%s/config.worktree", opts->git_dir); + if (!access_or_die(path, R_OK, 0)) + ret += git_config_from_file(fn, path, data); + free(path); + } + + strbuf_release(&buf); + clear_repository_format(&repo_fmt); } current_parsing_scope = CONFIG_SCOPE_COMMAND; diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 8fe43e9775..2924c09c21 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -2,12 +2,20 @@ #include "cache.h" #include "config.h" #include "string-list.h" +#include "submodule-config.h" +#include "parse-options.h" /* * This program exposes the C API of the configuration mechanism * as a set of simple commands in order to facilitate testing. * - * Reads stdin and prints result of command to stdout: + * Usage: test-tool config [--submodule=] [] + * + * If --submodule= is given, will operate on the submodule at the + * given . This option is not valid for the commands: read_early_config, + * configset_get_value and configset_get_value_multi. + * + * Possible cmds are: * * get_value -> prints the value with highest priority for the entered key * @@ -72,14 +80,34 @@ static int early_config_cb(const char *var, const char *value, void *vdata) #define TC_VALUE_NOT_FOUND 1 #define TC_CONFIG_FILE_ERROR 2 +static const char *test_config_usage[] = { + "test-tool config [--submodule=] []", + NULL +}; + int cmd__config(int argc, const char **argv) { int i, val, ret = 0; const char *v; const struct string_list *strptr; struct config_set cs; + struct repository subrepo, *repo = the_repository; + const char *subrepo_path = NULL; + + struct option options[] = { + OPT_STRING(0, "submodule", &subrepo_path, "path", + "run on the submodule at "), + OPT_END() + }; + + argc = parse_options(argc, argv, NULL, options, test_config_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_STOP_AT_NON_OPTION); + if (argc < 2) + die("Please, provide a command name on the command-line"); if (argc == 3 && !strcmp(argv[1], "read_early_config")) { + if (subrepo_path) + die("cannot use --submodule with read_early_config"); read_early_config(early_config_cb, (void *)argv[2]); return ret; } @@ -88,11 +116,18 @@ int cmd__config(int argc, const char **argv) git_configset_init(&cs); - if (argc < 2) - die("Please, provide a command name on the command-line"); + if (subrepo_path) { + const struct submodule *sub; + + sub = submodule_from_path(the_repository, &null_oid, subrepo_path); + if (!sub || repo_submodule_init(&subrepo, the_repository, sub)) + die("invalid argument to --submodule: '%s'", subrepo_path); + + repo = &subrepo; + } if (argc == 3 && !strcmp(argv[1], "get_value")) { - if (!git_config_get_value(argv[2], &v)) { + if (!repo_config_get_value(repo, argv[2], &v)) { if (!v) printf("(NULL)\n"); else @@ -102,7 +137,7 @@ int cmd__config(int argc, const char **argv) ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) { - strptr = git_config_get_value_multi(argv[2]); + strptr = repo_config_get_value_multi(repo, argv[2]); if (strptr) { for (i = 0; i < strptr->nr; i++) { v = strptr->items[i].string; @@ -116,27 +151,31 @@ int cmd__config(int argc, const char **argv) ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_int")) { - if (!git_config_get_int(argv[2], &val)) { + if (!repo_config_get_int(repo, argv[2], &val)) { printf("%d\n", val); } else { printf("Value not found for \"%s\"\n", argv[2]); ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_bool")) { - if (!git_config_get_bool(argv[2], &val)) { + if (!repo_config_get_bool(repo, argv[2], &val)) { printf("%d\n", val); } else { + printf("Value not found for \"%s\"\n", argv[2]); ret = TC_VALUE_NOT_FOUND; } } else if (argc == 3 && !strcmp(argv[1], "get_string")) { - if (!git_config_get_string_tmp(argv[2], &v)) { + if (!repo_config_get_string_tmp(repo, argv[2], &v)) { printf("%s\n", v); } else { printf("Value not found for \"%s\"\n", argv[2]); ret = TC_VALUE_NOT_FOUND; } } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value")) { + if (subrepo_path) + die("cannot use --submodule with configset_get_value"); + for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { @@ -155,6 +194,9 @@ int cmd__config(int argc, const char **argv) ret = TC_VALUE_NOT_FOUND; } } else if (argc >= 3 && !strcmp(argv[1], "configset_get_value_multi")) { + if (subrepo_path) + die("cannot use --submodule with configset_get_value_multi"); + for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { @@ -177,12 +219,14 @@ int cmd__config(int argc, const char **argv) ret = TC_VALUE_NOT_FOUND; } } else if (!strcmp(argv[1], "iterate")) { - git_config(iterate_cb, NULL); + repo_config(repo, iterate_cb, NULL); } else { die("%s: Please check the syntax and the function name", argv[0]); } out: git_configset_clear(&cs); + if (repo != the_repository) + repo_clear(repo); return ret; } diff --git a/t/t2404-worktree-config.sh b/t/t2404-worktree-config.sh index 9536d10919..1e32c93735 100755 --- a/t/t2404-worktree-config.sh +++ b/t/t2404-worktree-config.sh @@ -78,4 +78,20 @@ test_expect_success 'config.worktree no longer read without extension' ' test_cmp_config -C wt2 shared this.is ' +test_expect_success 'correctly read config.worktree from submodules' ' + test_unconfig extensions.worktreeConfig && + git init sub && + ( + cd sub && + test_commit A && + git config extensions.worktreeConfig true && + git config --worktree wtconfig.sub test-value + ) && + git submodule add ./sub && + git commit -m "add sub" && + echo test-value >expect && + test-tool config --submodule=sub get_value wtconfig.sub >actual && + test_cmp expect actual +' + test_done From patchwork Wed Sep 2 06:17:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749885 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 AD9B314E3 for ; Wed, 2 Sep 2020 06:18:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CD642078B for ; Wed, 2 Sep 2020 06:18:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="sif4C9Nq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbgIBGSY (ORCPT ); Wed, 2 Sep 2020 02:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbgIBGSU (ORCPT ); Wed, 2 Sep 2020 02:18:20 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 915E9C061244 for ; Tue, 1 Sep 2020 23:18:19 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id w186so3395518qkd.1 for ; Tue, 01 Sep 2020 23:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UF6C88903hKDDHik13yeH62wpFrYGOwCxVe0dPt1sJE=; b=sif4C9Nqm93E1JOimzm4sEZfRDmxv7Yht0yBvKQ+pTshPR231z9BlE/UeUjUi2Gns4 QkIHP0Lkx+6hD7dGFBQFX01PLKwSGw+gJJk6ZfmtB2VwjojWoVcFGJjPH0QgohDwD2Mu R8ZM8WLKjc0s0fgZ8sAhIJO3tgu9uq+FXhuiTYhtyaASc2hWzpfN7qvZIbSJSKFlofyS xwGeiWAHkMxYvcP+GuJBKHEW0/ktvjFDJazBgpjpeFkQqNTuBzgN/zGUlX+FMq6Bhyrp sWyDuWoWc6yMLpwKL8Z/sSubDxYLZ3NwrW+78H1Vh/f6Gj+gzgXO/T1br727ZtOZBJnK /zlQ== 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=UF6C88903hKDDHik13yeH62wpFrYGOwCxVe0dPt1sJE=; b=Ifsgw2fbeNTEQP9AQ+MgQQNzMi1vSroMIPZpYI1yLRM0LuEK+BSKzsIBGbM1+WL6R3 GB7cQs+LRKH0XJRV54//aF9qDvTt5eBNCmd4ZD9H4aF3nv5b2bGD46bBwMDze+mPiszE SnFnIRZ3ZrOBWAjQd3kOvG8CiKumGbS27/7gqVt99kd6w48iUKv5OvQAzz7vcngvDx1w a3rWjtmQ/frLtxg3ESi2QJ2OJDC4BFIPKCuWOcPNR5r3e2AEuW3tEYP1USMy/WdmYEbR u7gIcCJgD6TH8VutkyrmqA7eFiPvAtXm2q15i2/CcMDHPutf1U1XeNhBBi0yz/fe6lT5 d30w== X-Gm-Message-State: AOAM533At+FATmaK9wFWgo1SbP0Ila+Ua9aFFoxz3TgEm/Sm0Ln83LFB pU8JfXR/Ml1GbvtIYrywCy022TIY5Z/IiQ== X-Google-Smtp-Source: ABdhPJzg0tZ0aQUzNBXBiWfdX6rCRXZk5ge1mseM0i4MUb/XEhXgAUkrAkclpwjsbmLQ1Xg0N6Svmw== X-Received: by 2002:a05:620a:1257:: with SMTP id a23mr5418994qkl.207.1599027498158; Tue, 01 Sep 2020 23:18:18 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:17 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 7/8] grep: honor sparse checkout patterns Date: Wed, 2 Sep 2020 03:17:36 -0300 Message-Id: <902556a7b60974539ea2ce390bfd8f161d998270.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org One of the main uses for a sparse checkout is to allow users to focus on the subset of files in a repository in which they are interested. But git-grep currently ignores the sparsity patterns and reports all matches found outside this subset, which kind of goes in the opposite direction. There are some use cases for ignoring the sparsity patterns and the next commit will add an option to obtain this behavior, but here we start by making grep honor the sparsity boundaries in every case where this is relevant: - git grep in worktree - git grep --cached - git grep $REVISION For the worktree and cached cases, we iterate over paths without the SKIP_WORKTREE bit set, and limit our searches to these paths. For the $REVISION case, we limit the paths we search to those that match the sparsity patterns. (We do not check the SKIP_WORKTREE bit for the $REVISION case, because $REVISION may contain paths that do not exist in HEAD and thus for which we have no SKIP_WORKTREE bit to consult. The sparsity patterns tell us how the SKIP_WORKTREE bit would be set if we were to check out $REVISION, so we consult those. Also, we don't use the sparsity patterns with the worktree or cached cases, both because we have a bit we can check directly and more efficiently, and because unmerged entries from a merge or a rebase could cause more files to temporarily be present than the sparsity patterns would normally select.) Note that there is a special case here: `git grep $TREE`. In this case, we cannot know whether $TREE corresponds to the root of the repository or some sub-tree, and thus there is no way for us to know which sparsity patterns, if any, apply. So the $TREE case will not use sparsity patterns or any SKIP_WORKTREE bits and will instead always search all files within the $TREE. Signed-off-by: Matheus Tavares --- builtin/grep.c | 125 ++++++++++++++++++-- t/t7011-skip-worktree-reading.sh | 9 -- t/t7817-grep-sparse-checkout.sh | 195 +++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+), 17 deletions(-) create mode 100755 t/t7817-grep-sparse-checkout.sh diff --git a/builtin/grep.c b/builtin/grep.c index f58979bc3f..a32815de0a 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -410,7 +410,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int cached); static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, struct tree_desc *tree, struct strbuf *base, int tn_len, - int check_attr); + int is_root_tree); static int grep_submodule(struct grep_opt *opt, const struct pathspec *pathspec, @@ -508,6 +508,10 @@ static int grep_cache(struct grep_opt *opt, for (nr = 0; nr < repo->index->cache_nr; nr++) { const struct cache_entry *ce = repo->index->cache[nr]; + + if (ce_skip_worktree(ce)) + continue; + strbuf_setlen(&name, name_base_len); strbuf_addstr(&name, ce->name); @@ -520,8 +524,7 @@ static int grep_cache(struct grep_opt *opt, * cache entry are identical, even if worktree file has * been modified, so use cache version instead */ - if (cached || (ce->ce_flags & CE_VALID) || - ce_skip_worktree(ce)) { + if (cached || (ce->ce_flags & CE_VALID)) { if (ce_stage(ce) || ce_intent_to_add(ce)) continue; hit |= grep_oid(opt, &ce->oid, name.buf, @@ -552,9 +555,76 @@ static int grep_cache(struct grep_opt *opt, return hit; } -static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, - struct tree_desc *tree, struct strbuf *base, int tn_len, - int check_attr) +static struct pattern_list *get_sparsity_patterns(struct repository *repo) +{ + struct pattern_list *patterns; + char *sparse_file; + int sparse_config, cone_config; + + if (repo_config_get_bool(repo, "core.sparsecheckout", &sparse_config) || + !sparse_config) { + return NULL; + } + + sparse_file = repo_git_path(repo, "info/sparse-checkout"); + patterns = xcalloc(1, sizeof(*patterns)); + + if (repo_config_get_bool(repo, "core.sparsecheckoutcone", &cone_config)) + cone_config = 0; + patterns->use_cone_patterns = cone_config; + + if (add_patterns_from_file_to_list(sparse_file, "", 0, patterns, NULL)) { + if (file_exists(sparse_file)) { + warning(_("failed to load sparse-checkout file: '%s'"), + sparse_file); + } + free(sparse_file); + free(patterns); + return NULL; + } + + free(sparse_file); + return patterns; +} + +static int path_in_sparse_checkout(struct strbuf *path, int prefix_len, + unsigned int entry_mode, + struct index_state *istate, + struct pattern_list *sparsity, + enum pattern_match_result parent_match, + enum pattern_match_result *match) +{ + int dtype = DT_UNKNOWN; + int is_dir = S_ISDIR(entry_mode); + + if (parent_match == MATCHED_RECURSIVE) { + *match = parent_match; + return 1; + } + + if (is_dir && !is_dir_sep(path->buf[path->len - 1])) + strbuf_addch(path, '/'); + + *match = path_matches_pattern_list(path->buf, path->len, + path->buf + prefix_len, &dtype, + sparsity, istate); + if (*match == UNDECIDED) + *match = parent_match; + + if (is_dir) + strbuf_trim_trailing_dir_sep(path); + + if (*match == NOT_MATCHED && + (!is_dir || (is_dir && sparsity->use_cone_patterns))) + return 0; + + return 1; +} + +static int do_grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, + struct tree_desc *tree, struct strbuf *base, int tn_len, + int check_attr, struct pattern_list *sparsity, + enum pattern_match_result default_sparsity_match) { struct repository *repo = opt->repo; int hit = 0; @@ -570,6 +640,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, while (tree_entry(tree, &entry)) { int te_len = tree_entry_len(&entry); + enum pattern_match_result sparsity_match = 0; if (match != all_entries_interesting) { strbuf_addstr(&name, base->buf + tn_len); @@ -586,6 +657,19 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, strbuf_add(base, entry.path, te_len); + if (sparsity) { + struct strbuf path = STRBUF_INIT; + strbuf_addstr(&path, base->buf + tn_len); + + if (!path_in_sparse_checkout(&path, old_baselen - tn_len, + entry.mode, repo->index, + sparsity, default_sparsity_match, + &sparsity_match)) { + strbuf_setlen(base, old_baselen); + continue; + } + } + if (S_ISREG(entry.mode)) { hit |= grep_oid(opt, &entry.oid, base->buf, tn_len, check_attr ? base->buf + tn_len : NULL); @@ -602,8 +686,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, strbuf_addch(base, '/'); init_tree_desc(&sub, data, size); - hit |= grep_tree(opt, pathspec, &sub, base, tn_len, - check_attr); + hit |= do_grep_tree(opt, pathspec, &sub, base, tn_len, + check_attr, sparsity, sparsity_match); free(data); } else if (recurse_submodules && S_ISGITLINK(entry.mode)) { hit |= grep_submodule(opt, pathspec, &entry.oid, @@ -621,6 +705,31 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, return hit; } +/* + * Note: sparsity patterns and paths' attributes will only be considered if + * is_root_tree has true value. (Otherwise, we cannot properly perform pattern + * matching on paths.) + */ +static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, + struct tree_desc *tree, struct strbuf *base, int tn_len, + int is_root_tree) +{ + struct pattern_list *patterns = NULL; + int ret; + + if (is_root_tree) + patterns = get_sparsity_patterns(opt->repo); + + ret = do_grep_tree(opt, pathspec, tree, base, tn_len, is_root_tree, + patterns, 0); + + if (patterns) { + clear_pattern_list(patterns); + free(patterns); + } + return ret; +} + static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, struct object *obj, const char *name, const char *path) { diff --git a/t/t7011-skip-worktree-reading.sh b/t/t7011-skip-worktree-reading.sh index 37525cae3a..26852586ac 100755 --- a/t/t7011-skip-worktree-reading.sh +++ b/t/t7011-skip-worktree-reading.sh @@ -109,15 +109,6 @@ test_expect_success 'ls-files --modified' ' test -z "$(git ls-files -m)" ' -test_expect_success 'grep with skip-worktree file' ' - git update-index --no-skip-worktree 1 && - echo test > 1 && - git update-index 1 && - git update-index --skip-worktree 1 && - rm 1 && - test "$(git grep --no-ext-grep test)" = "1:test" -' - echo ":000000 100644 $ZERO_OID $EMPTY_BLOB A 1" > expected test_expect_success 'diff-index does not examine skip-worktree absent entries' ' setup_absent && diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh new file mode 100755 index 0000000000..b3109e3479 --- /dev/null +++ b/t/t7817-grep-sparse-checkout.sh @@ -0,0 +1,195 @@ +#!/bin/sh + +test_description='grep in sparse checkout + +This test creates a repo with the following structure: + +. +|-- a +|-- b +|-- dir +| `-- c +|-- sub +| |-- A +| | `-- a +| `-- B +| `-- b +`-- sub2 + `-- a + +Where the outer repository has non-cone mode sparsity patterns, sub is a +submodule with cone mode sparsity patterns and sub2 is a submodule that is +excluded by the superproject sparsity patterns. The resulting sparse checkout +should leave the following structure in the working tree: + +. +|-- a +|-- sub +| `-- B +| `-- b +`-- sub2 + `-- a + +But note that sub2 should have the SKIP_WORKTREE bit set. +' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo "text" >a && + echo "text" >b && + mkdir dir && + echo "text" >dir/c && + + git init sub && + ( + cd sub && + mkdir A B && + echo "text" >A/a && + echo "text" >B/b && + git add A B && + git commit -m sub && + git sparse-checkout init --cone && + git sparse-checkout set B + ) && + + git init sub2 && + ( + cd sub2 && + echo "text" >a && + git add a && + git commit -m sub2 + ) && + + git submodule add ./sub && + git submodule add ./sub2 && + git add a b dir && + git commit -m super && + git sparse-checkout init --no-cone && + git sparse-checkout set "/*" "!b" "!/*/" "sub" && + + git tag -am tag-to-commit tag-to-commit HEAD && + tree=$(git rev-parse HEAD^{tree}) && + git tag -am tag-to-tree tag-to-tree $tree && + + test_path_is_missing b && + test_path_is_missing dir && + test_path_is_missing sub/A && + test_path_is_file a && + test_path_is_file sub/B/b && + test_path_is_file sub2/a +' + +# The test below checks a special case: the sparsity patterns exclude '/b' +# and sparse checkout is enabled, but the path exists in the working tree (e.g. +# manually created after `git sparse-checkout init`). In this case, grep should +# skip it. +test_expect_success 'grep in working tree should honor sparse checkout' ' + cat >expect <<-EOF && + a:text + EOF + echo "new-text" >b && + test_when_finished "rm b" && + git grep "text" >actual && + test_cmp expect actual +' + +test_expect_success 'grep unmerged file despite not matching sparsity patterns' ' + cat >expect <<-EOF && + b:modified-b-in-branchX + b:modified-b-in-branchY + EOF + test_when_finished "test_might_fail git merge --abort && \ + git checkout master" && + + git sparse-checkout disable && + git checkout -b branchY master && + test_commit modified-b-in-branchY b && + git checkout -b branchX master && + test_commit modified-b-in-branchX b && + + git sparse-checkout init && + test_path_is_missing b && + test_must_fail git merge branchY && + git grep "modified-b" >actual && + test_cmp expect actual +' + +test_expect_success 'grep --cached should honor sparse checkout' ' + cat >expect <<-EOF && + a:text + EOF + git grep --cached "text" >actual && + test_cmp expect actual +' + +test_expect_success 'grep should honor sparse checkout' ' + commit=$(git rev-parse HEAD) && + cat >expect_commit <<-EOF && + $commit:a:text + EOF + cat >expect_tag-to-commit <<-EOF && + tag-to-commit:a:text + EOF + git grep "text" $commit >actual_commit && + test_cmp expect_commit actual_commit && + git grep "text" tag-to-commit >actual_tag-to-commit && + test_cmp expect_tag-to-commit actual_tag-to-commit +' + +test_expect_success 'grep should ignore sparsity patterns' ' + commit=$(git rev-parse HEAD) && + tree=$(git rev-parse HEAD^{tree}) && + cat >expect_tree <<-EOF && + $tree:a:text + $tree:b:text + $tree:dir/c:text + EOF + cat >expect_tag-to-tree <<-EOF && + tag-to-tree:a:text + tag-to-tree:b:text + tag-to-tree:dir/c:text + EOF + git grep "text" $tree >actual_tree && + test_cmp expect_tree actual_tree && + git grep "text" tag-to-tree >actual_tag-to-tree && + test_cmp expect_tag-to-tree actual_tag-to-tree +' + +# Note that sub2/ is present in the worktree but it is excluded by the sparsity +# patterns, so grep should not recurse into it. +test_expect_success 'grep --recurse-submodules should honor sparse checkout in submodule' ' + cat >expect <<-EOF && + a:text + sub/B/b:text + EOF + git grep --recurse-submodules "text" >actual && + test_cmp expect actual +' + +test_expect_success 'grep --recurse-submodules --cached should honor sparse checkout in submodule' ' + cat >expect <<-EOF && + a:text + sub/B/b:text + EOF + git grep --recurse-submodules --cached "text" >actual && + test_cmp expect actual +' + +test_expect_success 'grep --recurse-submodules should honor sparse checkout in submodule' ' + commit=$(git rev-parse HEAD) && + cat >expect_commit <<-EOF && + $commit:a:text + $commit:sub/B/b:text + EOF + cat >expect_tag-to-commit <<-EOF && + tag-to-commit:a:text + tag-to-commit:sub/B/b:text + EOF + git grep --recurse-submodules "text" $commit >actual_commit && + test_cmp expect_commit actual_commit && + git grep --recurse-submodules "text" tag-to-commit >actual_tag-to-commit && + test_cmp expect_tag-to-commit actual_tag-to-commit +' + +test_done From patchwork Wed Sep 2 06:17:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11749887 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 832AB14E3 for ; Wed, 2 Sep 2020 06:18:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 591DA2078B for ; Wed, 2 Sep 2020 06:18:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="wXHumi9g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726625AbgIBGSm (ORCPT ); Wed, 2 Sep 2020 02:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgIBGSk (ORCPT ); Wed, 2 Sep 2020 02:18:40 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B42DC061244 for ; Tue, 1 Sep 2020 23:18:40 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id t20so2817508qtr.8 for ; Tue, 01 Sep 2020 23:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wql2jSbmB/wKgLMAMdl4Eiy44fK9XQwDEfPhW74A0uA=; b=wXHumi9gw3gMyCCdM+jbd5UzTS7WVx+WYe2kGGzifgIE+jajD4NPZqNW7cgEnM8hBF /qmcme2kgYiTVJddxqnqjHp8s/iTzvDYW59r5P80uGw4L9EThHvmNSD26ke+e8ncA6hY mhNGdN0KDtkEr7QDT0MZs7QxA2WurSN3bRTAbApMMgjQXnP9rXgNsubRp3jRkfeOCj// PT0kQh6RgZnQEXFWwu2c8HuU84aDmxG+SNqdNf3B6g8rAK98b/a6Lkn7J2a+Bzl+vl8F aKSlHxrZnhyh9gT0AJ8iT1gpKcObRco7QkINjgiwXP1o5j6HG+BO79kw+StEaN1Jf2M0 4ttg== 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=wql2jSbmB/wKgLMAMdl4Eiy44fK9XQwDEfPhW74A0uA=; b=OHMpXjBDIq5PfXGjBbo0TXlUHJKafZEe4AvY4YwoJhxYJ/ceG0Sfkd5gekS2NyU627 fBbjDJaZCBheqnsNxtwozlJAuk6Rjgf/Zp048Pf9NH1BxUdJS5BgfJA1SPO9gLdzUjCZ RUMWW0aXseMvJbuDgA6diYGB6PyEdHrKkL98LcWlQFTtKGaJuHsrxroVYDUPGgCUWTC4 giHnVAVMSazxgMfPf+oVQ2pxrD9paThZrvR8Fqc+l2K22sZINtRwK+uwtvAVrJQ50QPG k6nTwGzZH+pkjeJfhs2mNtT7P7s50ONGe/glCvKmCQD3BSfyfR4KoVV7VYD8uoiW7Up/ 4/bg== X-Gm-Message-State: AOAM532tc61Av8/G6GSLHqJiAM4JdiPf8pQRNfJxyZGs7NKEWqtLdkam S1Uk1t6e0pqceBXQX4hR/fuP5X++cBMkUQ== X-Google-Smtp-Source: ABdhPJx0s6n56jhHqaNJCHMdOhKNbFj33Tan0LK9h4sMkr0yLWHG8r9r2aWYtKxjnUfBHOqGPN+GWQ== X-Received: by 2002:aed:2ce5:: with SMTP id g92mr5279887qtd.204.1599027518784; Tue, 01 Sep 2020 23:18:38 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:81:83eb::1001]) by smtp.gmail.com with ESMTPSA id x28sm3731234qki.55.2020.09.01.23.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 23:18:38 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: gitster@pobox.com, stolee@gmail.com, newren@gmail.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH v5 8/8] config: add setting to ignore sparsity patterns in some cmds Date: Wed, 2 Sep 2020 03:17:37 -0300 Message-Id: <70e7d7b90c22452d018acf6fe2a1825813b6448e.1599026986.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When sparse checkout is enabled, some users expect the output of certain commands (such as grep, diff, and log) to be also restricted within the sparsity patterns. This would allow them to effectively work only on the subset of files in which they are interested; and allow some commands to possibly perform better, by not considering uninteresting paths. For this reason, we taught grep to honor the sparsity patterns, in the previous patch. But, on the other hand, allowing grep and the other commands mentioned to optionally ignore the patterns also make for some interesting use cases. E.g. using grep to search for a function documentation that resides outside the sparse checkout. In any case, there is no current way for users to configure the behavior they want for these commands. Aiming to provide this flexibility, let's introduce the sparse.restrictCmds setting (and the analogous --[no]-restrict-to-sparse-paths global option). The default value is true. For now, grep is the only one affected by this setting, but the goal is to have support for more commands, in the future. Helped-by: Elijah Newren Signed-off-by: Matheus Tavares --- Documentation/config.txt | 2 + Documentation/config/grep.txt | 8 ++ Documentation/config/sparse.txt | 20 ++++ Documentation/git.txt | 4 + Makefile | 1 + builtin/grep.c | 13 ++- contrib/completion/git-completion.bash | 2 + git.c | 5 + sparse-checkout.c | 18 ++++ sparse-checkout.h | 11 +++ t/t7817-grep-sparse-checkout.sh | 132 ++++++++++++++++++++++++- t/t9902-completion.sh | 4 +- 12 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 Documentation/config/sparse.txt create mode 100644 sparse-checkout.c create mode 100644 sparse-checkout.h diff --git a/Documentation/config.txt b/Documentation/config.txt index 3042d80978..3b6e0901b8 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -438,6 +438,8 @@ include::config/sequencer.txt[] include::config/showbranch.txt[] +include::config/sparse.txt[] + include::config/splitindex.txt[] include::config/ssh.txt[] diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index dd51db38e1..a3275ab4b7 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -28,3 +28,11 @@ grep.fullName:: grep.fallbackToNoIndex:: If set to true, fall back to git grep --no-index if git grep is executed outside of a git repository. Defaults to false. + +ifdef::git-grep[] +sparse.restrictCmds:: + See base definition in linkgit:git-config[1]. grep honors + sparse.restrictCmds by limiting searches to the sparsity paths in three + cases: when searching the working tree, when searching the index with + --cached, and when searching a specified commit. +endif::git-grep[] diff --git a/Documentation/config/sparse.txt b/Documentation/config/sparse.txt new file mode 100644 index 0000000000..494761526e --- /dev/null +++ b/Documentation/config/sparse.txt @@ -0,0 +1,20 @@ +sparse.restrictCmds:: + Only meaningful in conjunction with core.sparseCheckout. This option + extends sparse checkouts (which limit which paths are written to the + working tree), so that output and operations are also limited to the + sparsity paths where possible and implemented. The purpose of this + option is to (1) focus output for the user on the portion of the + repository that is of interest to them, and (2) enable potentially + dramatic performance improvements, especially in conjunction with + partial clones. ++ +When this option is true (default), some git commands may limit their behavior +to the paths specified by the sparsity patterns, or to the intersection of +those paths and any (like `*.c`) that the user might also specify on the +command line. When false, the affected commands will work on full trees, +ignoring the sparsity patterns. For now, only git-grep honors this setting. ++ +Note: commands which export, integrity check, or create history will always +operate on full trees (e.g. fast-export, format-patch, fsck, commit, etc.), +unaffected by any sparsity patterns. Also, writing commands such as +sparse-checkout and read-tree will not be affected by this configuration. diff --git a/Documentation/git.txt b/Documentation/git.txt index 2fc92586b5..d857509573 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -180,6 +180,10 @@ If you just want to run git as if it was started in `` then use Do not perform optional operations that require locks. This is equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. +--[no-]restrict-to-sparse-paths:: + Overrides the sparse.restrictCmds configuration (see + linkgit:git-config[1]) for this execution. + --list-cmds=group[,group...]:: List commands by group. This is an internal/experimental option and may change or be removed in the future. Supported diff --git a/Makefile b/Makefile index 65f8cfb236..778c9e499e 100644 --- a/Makefile +++ b/Makefile @@ -982,6 +982,7 @@ LIB_OBJS += sha1-name.o LIB_OBJS += shallow.o LIB_OBJS += sideband.o LIB_OBJS += sigchain.o +LIB_OBJS += sparse-checkout.o LIB_OBJS += split-index.o LIB_OBJS += stable-qsort.o LIB_OBJS += strbuf.o diff --git a/builtin/grep.c b/builtin/grep.c index a32815de0a..3fa364e91c 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -25,6 +25,7 @@ #include "submodule-config.h" #include "object-store.h" #include "packfile.h" +#include "sparse-checkout.h" static char const * const grep_usage[] = { N_("git grep [] [-e] [...] [[--] ...]"), @@ -498,6 +499,7 @@ static int grep_cache(struct grep_opt *opt, int nr; struct strbuf name = STRBUF_INIT; int name_base_len = 0; + int sparse_paths_only = restrict_to_sparse_paths(repo); if (repo->submodule_prefix) { name_base_len = strlen(repo->submodule_prefix); strbuf_addstr(&name, repo->submodule_prefix); @@ -509,7 +511,7 @@ static int grep_cache(struct grep_opt *opt, for (nr = 0; nr < repo->index->cache_nr; nr++) { const struct cache_entry *ce = repo->index->cache[nr]; - if (ce_skip_worktree(ce)) + if (sparse_paths_only && ce_skip_worktree(ce)) continue; strbuf_setlen(&name, name_base_len); @@ -715,9 +717,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, int is_root_tree) { struct pattern_list *patterns = NULL; + int sparse_paths_only = restrict_to_sparse_paths(opt->repo); int ret; - if (is_root_tree) + if (is_root_tree && sparse_paths_only) patterns = get_sparsity_patterns(opt->repo); ret = do_grep_tree(opt, pathspec, tree, base, tn_len, is_root_tree, @@ -1258,6 +1261,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix) if (!use_index || untracked) { int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude; + + if (opt_restrict_to_sparse_paths >= 0) { + die(_("--[no-]restrict-to-sparse-paths is incompatible" + " with --no-index and --untracked")); + } + hit = grep_directory(&opt, &pathspec, use_exclude, use_index); } else if (0 <= opt_exclude) { die(_("--[no-]exclude-standard cannot be used for tracked contents")); diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9147fba3d5..de12766a70 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3402,6 +3402,8 @@ __git_main () --namespace= --no-replace-objects --help + --restrict-to-sparse-paths + --no-restrict-to-sparse-paths " ;; *) diff --git a/git.c b/git.c index 8bd1d7551d..81206b424c 100644 --- a/git.c +++ b/git.c @@ -5,6 +5,7 @@ #include "run-command.h" #include "alias.h" #include "shallow.h" +#include "sparse-checkout.h" #define RUN_SETUP (1<<0) #define RUN_SETUP_GENTLY (1<<1) @@ -311,6 +312,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) } else { exit(list_cmds(cmd)); } + } else if (!strcmp(cmd, "--restrict-to-sparse-paths")) { + opt_restrict_to_sparse_paths = 1; + } else if (!strcmp(cmd, "--no-restrict-to-sparse-paths")) { + opt_restrict_to_sparse_paths = 0; } else { fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); diff --git a/sparse-checkout.c b/sparse-checkout.c new file mode 100644 index 0000000000..96c5ed5446 --- /dev/null +++ b/sparse-checkout.c @@ -0,0 +1,18 @@ +#include "cache.h" +#include "config.h" +#include "sparse-checkout.h" + +int opt_restrict_to_sparse_paths = -1; + +int restrict_to_sparse_paths(struct repository *repo) +{ + int ret; + + if (opt_restrict_to_sparse_paths >= 0) + return opt_restrict_to_sparse_paths; + + if (repo_config_get_bool(repo, "sparse.restrictcmds", &ret)) + ret = 1; + + return ret; +} diff --git a/sparse-checkout.h b/sparse-checkout.h new file mode 100644 index 0000000000..a4805e443a --- /dev/null +++ b/sparse-checkout.h @@ -0,0 +1,11 @@ +#ifndef SPARSE_CHECKOUT_H +#define SPARSE_CHECKOUT_H + +struct repository; + +extern int opt_restrict_to_sparse_paths; + +/* Whether or not cmds should restrict behavior on sparse paths, in this repo */ +int restrict_to_sparse_paths(struct repository *repo); + +#endif /* SPARSE_CHECKOUT_H */ diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh index b3109e3479..f93a4f71d1 100755 --- a/t/t7817-grep-sparse-checkout.sh +++ b/t/t7817-grep-sparse-checkout.sh @@ -80,10 +80,10 @@ test_expect_success 'setup' ' test_path_is_file sub2/a ' -# The test below checks a special case: the sparsity patterns exclude '/b' +# The two tests below check a special case: the sparsity patterns exclude '/b' # and sparse checkout is enabled, but the path exists in the working tree (e.g. # manually created after `git sparse-checkout init`). In this case, grep should -# skip it. +# skip the file by default, but not with --no-restrict-to-sparse-paths. test_expect_success 'grep in working tree should honor sparse checkout' ' cat >expect <<-EOF && a:text @@ -93,6 +93,16 @@ test_expect_success 'grep in working tree should honor sparse checkout' ' git grep "text" >actual && test_cmp expect actual ' +test_expect_success 'grep w/ --no-restrict-to-sparse-paths for sparsely excluded but present paths' ' + cat >expect <<-EOF && + a:text + b:new-text + EOF + echo "new-text" >b && + test_when_finished "rm b" && + git --no-restrict-to-sparse-paths grep "text" >actual && + test_cmp expect actual +' test_expect_success 'grep unmerged file despite not matching sparsity patterns' ' cat >expect <<-EOF && @@ -157,7 +167,7 @@ test_expect_success 'grep should ignore sparsity patterns' ' ' # Note that sub2/ is present in the worktree but it is excluded by the sparsity -# patterns, so grep should not recurse into it. +# patterns, so grep should only recurse into it with --no-restrict-to-sparse-paths. test_expect_success 'grep --recurse-submodules should honor sparse checkout in submodule' ' cat >expect <<-EOF && a:text @@ -166,6 +176,15 @@ test_expect_success 'grep --recurse-submodules should honor sparse checkout in s git grep --recurse-submodules "text" >actual && test_cmp expect actual ' +test_expect_success 'grep --recurse-submodules should search in excluded submodules w/ --no-restrict-to-sparse-paths' ' + cat >expect <<-EOF && + a:text + sub/B/b:text + sub2/a:text + EOF + git --no-restrict-to-sparse-paths grep --recurse-submodules "text" >actual && + test_cmp expect actual +' test_expect_success 'grep --recurse-submodules --cached should honor sparse checkout in submodule' ' cat >expect <<-EOF && @@ -192,4 +211,111 @@ test_expect_success 'grep --recurse-submodules should honor sparse test_cmp expect_tag-to-commit actual_tag-to-commit ' +for cmd in 'git --no-restrict-to-sparse-paths grep' \ + 'git -c sparse.restrictCmds=false grep' \ + 'git -c sparse.restrictCmds=true --no-restrict-to-sparse-paths grep' +do + + test_expect_success "$cmd --cached should ignore sparsity patterns" ' + cat >expect <<-EOF && + a:text + b:text + dir/c:text + EOF + $cmd --cached "text" >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd should ignore sparsity patterns" ' + commit=$(git rev-parse HEAD) && + cat >expect_commit <<-EOF && + $commit:a:text + $commit:b:text + $commit:dir/c:text + EOF + cat >expect_tag-to-commit <<-EOF && + tag-to-commit:a:text + tag-to-commit:b:text + tag-to-commit:dir/c:text + EOF + $cmd "text" $commit >actual_commit && + test_cmp expect_commit actual_commit && + $cmd "text" tag-to-commit >actual_tag-to-commit && + test_cmp expect_tag-to-commit actual_tag-to-commit + ' +done + +test_expect_success 'grep --recurse-submodules --cached w/ --no-restrict-to-sparse-paths' ' + cat >expect <<-EOF && + a:text + b:text + dir/c:text + sub/A/a:text + sub/B/b:text + sub2/a:text + EOF + git --no-restrict-to-sparse-paths grep --recurse-submodules --cached \ + "text" >actual && + test_cmp expect actual +' + +test_expect_success 'grep --recurse-submodules w/ --no-restrict-to-sparse-paths' ' + commit=$(git rev-parse HEAD) && + cat >expect_commit <<-EOF && + $commit:a:text + $commit:b:text + $commit:dir/c:text + $commit:sub/A/a:text + $commit:sub/B/b:text + $commit:sub2/a:text + EOF + cat >expect_tag-to-commit <<-EOF && + tag-to-commit:a:text + tag-to-commit:b:text + tag-to-commit:dir/c:text + tag-to-commit:sub/A/a:text + tag-to-commit:sub/B/b:text + tag-to-commit:sub2/a:text + EOF + git --no-restrict-to-sparse-paths grep --recurse-submodules "text" \ + $commit >actual_commit && + test_cmp expect_commit actual_commit && + git --no-restrict-to-sparse-paths grep --recurse-submodules "text" \ + tag-to-commit >actual_tag-to-commit && + test_cmp expect_tag-to-commit actual_tag-to-commit +' + +test_expect_success 'should respect the sparse.restrictCmds values from submodules' ' + cat >expect <<-EOF && + a:text + sub/A/a:text + sub/B/b:text + EOF + test_config -C sub sparse.restrictCmds false && + git grep --cached --recurse-submodules "text" >actual && + test_cmp expect actual +' + +test_expect_success 'should propagate --[no]-restrict-to-sparse-paths to submodules' ' + cat >expect <<-EOF && + a:text + b:text + dir/c:text + sub/A/a:text + sub/B/b:text + sub2/a:text + EOF + test_config -C sub sparse.restrictCmds true && + git --no-restrict-to-sparse-paths grep --cached --recurse-submodules "text" >actual && + test_cmp expect actual +' + +for opt in '--untracked' '--no-index' +do + test_expect_success "--[no]-restrict-to-sparse-paths and $opt are incompatible" " + test_must_fail git --restrict-to-sparse-paths grep $opt . 2>actual && + test_i18ngrep 'restrict-to-sparse-paths is incompatible with' actual + " +done + test_done diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 8425b9a531..a8c2ac9d70 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1928,6 +1928,8 @@ test_expect_success 'double dash "git" itself' ' --namespace= --no-replace-objects Z --help Z + --restrict-to-sparse-paths Z + --no-restrict-to-sparse-paths Z EOF ' @@ -1970,7 +1972,7 @@ test_expect_success 'general options' ' test_completion "git --nam" "--namespace=" && test_completion "git --bar" "--bare " && test_completion "git --inf" "--info-path " && - test_completion "git --no-r" "--no-replace-objects " + test_completion "git --no-rep" "--no-replace-objects " ' test_expect_success 'general options plus command' '