From patchwork Mon Dec 6 15:55:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE0CEC433F5 for ; Mon, 6 Dec 2021 16:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377100AbhLFQOI (ORCPT ); Mon, 6 Dec 2021 11:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388642AbhLFQNj (ORCPT ); Mon, 6 Dec 2021 11:13:39 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65873C00FDF6 for ; Mon, 6 Dec 2021 07:56:05 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id a18so23439390wrn.6 for ; Mon, 06 Dec 2021 07:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=xAocT7yf/kpTiA/n7n7/FZSdVz7wIVtS4qeC06FPkFk=; b=hGGnzyUwWi3ZRfGMulAy86bbARfuzwmgddFR/DEzZ4fX7q8/pk0ni6ctpeKDelguKp +VhV9CHThE7zs+Dnuxg0iYgz+UPbZ9ZeKOkheTPh25GMzMJfShiJvVbEZlpiBRM35BOu ldVU8KkVfvF2dfGWOuXzOEuee6eVlsGYbkDt3L38kiR4LrWucSpWMw+brnfEPpIJsQ3w ZuOjoeAVJAgzZ7kNb0IbQTo4xxrzqpJUxKKxPqV56Vixo+v6O44L3CbyByKXKBTCjYzY 58AEsp/TLJd+d4yBdRkRaVkqN1oGa+BAigLhOXMnpTzOWVUDh9HQ0Er8nl/93hORyJMF LbPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=xAocT7yf/kpTiA/n7n7/FZSdVz7wIVtS4qeC06FPkFk=; b=wJ0bHBjWA7DkSw36Oq8/OxsOMm4zu2NzUACQti7O1teGCrrUcwFS8fR/seMdHAMgsO SqQexNM3ETQvn4OtSxefHxOPKuElUM6MbsU1HXQHrMePOrWa0dZBwPvjGbHCZW7n14et vPvyd2i/gIZePjWN1VRGS3n0/lKvGaS9M74ob+CEBn9mpqeOBdBBDvnNvJ5z3syytjyc Z2SP2QXpGr/qlGY4ZljAh5vEoR6xSuGL0toOxBD+qtwkdPo8Hj8wfBmjXCqQTuhJICbZ BKypTdcemSBPdFCaQU2knjjy5+GOtUBEkaSbQIFyJw+oEsfHXzq9u9ZeoQ6OoGOwvrBl SF9Q== X-Gm-Message-State: AOAM531dOTIZGyWNqVxIrAcRbceKdb2Q317iaDAL4CwHVobtweE63PkO 71o8PAgC13igKXR6jplSU0u/msNwLAI= X-Google-Smtp-Source: ABdhPJzPncM8u2fd/LY9kBpu0LD4gkoSw/skzFYNkmTF1zDtQDYecudzl3nexHEQhDr5/pEWdKXvqA== X-Received: by 2002:adf:f749:: with SMTP id z9mr45102424wrp.379.1638806163341; Mon, 06 Dec 2021 07:56:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o12sm12477908wmq.12.2021.12.06.07.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:03 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 06 Dec 2021 15:55:55 +0000 Subject: [PATCH v6 1/7] git: ensure correct git directory setup with -h Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Ensure correct git directory setup when -h is passed with commands. This specifically applies to repos with special help text configuration variables and to commands run with -h outside a repository. This will also protect against test failures in the upcoming change to BUG in prepare_repo_settings if no git directory exists. Note: this diff is better seen when ignoring whitespace changes. Co-authored-by: Junio C Hamano Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- git.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/git.c b/git.c index 60c2784be45..eb6890087c3 100644 --- a/git.c +++ b/git.c @@ -421,27 +421,30 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) int status, help; struct stat st; const char *prefix; + int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY)); - prefix = NULL; help = argc == 2 && !strcmp(argv[1], "-h"); - if (!help) { - if (p->option & RUN_SETUP) - prefix = setup_git_directory(); - else if (p->option & RUN_SETUP_GENTLY) { - int nongit_ok; - prefix = setup_git_directory_gently(&nongit_ok); - } - precompose_argv_prefix(argc, argv, NULL); - if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) && - !(p->option & DELAY_PAGER_CONFIG)) - use_pager = check_pager_config(p->cmd); - if (use_pager == -1 && p->option & USE_PAGER) - use_pager = 1; - - if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) && - startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */ - trace_repo_setup(prefix); + if (help && (run_setup & RUN_SETUP)) + /* demote to GENTLY to allow 'git cmd -h' outside repo */ + run_setup = RUN_SETUP_GENTLY; + + if (run_setup & RUN_SETUP) { + prefix = setup_git_directory(); + } else if (run_setup & RUN_SETUP_GENTLY) { + int nongit_ok; + prefix = setup_git_directory_gently(&nongit_ok); + } else { + prefix = NULL; } + precompose_argv_prefix(argc, argv, NULL); + if (use_pager == -1 && run_setup && + !(p->option & DELAY_PAGER_CONFIG)) + use_pager = check_pager_config(p->cmd); + if (use_pager == -1 && p->option & USE_PAGER) + use_pager = 1; + if (run_setup && startup_info->have_repository) + /* get_git_dir() may set up repo, avoid that */ + trace_repo_setup(prefix); commit_pager_choice(); if (!help && get_super_prefix()) { From patchwork Mon Dec 6 15:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7AE2C433EF for ; Mon, 6 Dec 2021 16:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386388AbhLFQOK (ORCPT ); Mon, 6 Dec 2021 11:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388644AbhLFQNj (ORCPT ); Mon, 6 Dec 2021 11:13:39 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D093DC00FDF8 for ; Mon, 6 Dec 2021 07:56:05 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso10765213wml.1 for ; Mon, 06 Dec 2021 07:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=4Zmi/zzQ7Z2fnIcb8ViOTaN12hJk+N9kU0ajrJ/wfXc=; b=pm7fAAXnIeKBbA0/lH9x8TMkupg40P4JHBzpNHH+1pLXciuen0bfRuJLbpnA4AuS2g dI9YLjlEfvbsQmusIRlxXtAQ3/ez93UGjK+lxox0e4yRmCTsI32m7xebmL0I+P/I7Cn5 kvWnt/f5nOKWibFpRaEIH1VYQZsnrhvY0U34xXZLVje5VA23fqNLOWLtrA20emXEo8rj Qaqoz1mQ++bHY0qFGwOpt/C6pNNxRPo1a3Lt7kt73Ai3vI3BMf6rnV4WWMyo2jZeOqG1 etWfzVieqqQebzXrzME/313+bq2IoimiAtdBWTYDavCnyn/9WO9BI/c35TLH4LxhGYI8 LVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4Zmi/zzQ7Z2fnIcb8ViOTaN12hJk+N9kU0ajrJ/wfXc=; b=7Ft03odIYtxVmwUSockJ7k5/yqkT29eleEMjf4EM0iHGPDbLL3eVFk/23oB7mQuyeb IXJLZ75M9VYnkcCYyxf6+HjPEGEZIJnON6B4HvKQRaC/W7iBgvrWsKdUT6WCn2XdGJ7R bpHATRy+keGpc9CTEKdNf0qQZmx/lbfgoA4ANRtBi2NIWVj54eYAWFVe73+PhPiApQaI 5J7lf1gdfd+WrCCVgTlbctrCVwJrIspJsL9Nxj774/CZSS9e00mRZrHlawLEGjIrQ34E zi2qw0JDpRRjmDJHF7az7Bi9F0TMa5Y0kc99xbXoxchYiFO8+5ICT/JpYyRkUHZenEUl AovA== X-Gm-Message-State: AOAM531sXHfJn4u9FyektC0KEMssEQWXi8A8cnGW+uVurivHthQWS10P XHvwixv4MYCnrpYTTixuB5B8gimyvoc= X-Google-Smtp-Source: ABdhPJxZc+2Fu209qOzh4PnilcGaxOZsXO18TbBad9tyQsGmZ3ZHv17mXeX1tSru6GMc5WOOC7EPqg== X-Received: by 2002:a05:600c:3584:: with SMTP id p4mr39629944wmq.109.1638806164278; Mon, 06 Dec 2021 07:56:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r8sm14452472wrz.43.2021.12.06.07.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:03 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 06 Dec 2021 15:55:56 +0000 Subject: [PATCH v6 2/7] commit-graph: return if there is no git directory Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Return early if git directory does not exist. This will protect against test failures in the upcoming change to BUG in prepare_repo_settings if no git directory exists. Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- commit-graph.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commit-graph.c b/commit-graph.c index 2706683acfe..265c010122e 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -632,10 +632,13 @@ static int prepare_commit_graph(struct repository *r) struct object_directory *odb; /* + * Early return if there is no git dir or if the commit graph is + * disabled. + * * This must come before the "already attempted?" check below, because * we want to disable even an already-loaded graph file. */ - if (r->commit_graph_disabled) + if (!r->gitdir || r->commit_graph_disabled) return 0; if (r->objects->commit_graph_attempted) From patchwork Mon Dec 6 15:55:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C7F9C433F5 for ; Mon, 6 Dec 2021 16:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385715AbhLFQON (ORCPT ); Mon, 6 Dec 2021 11:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388685AbhLFQNk (ORCPT ); Mon, 6 Dec 2021 11:13:40 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DCABC00FDFA for ; Mon, 6 Dec 2021 07:56:06 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id y196so8528816wmc.3 for ; Mon, 06 Dec 2021 07:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=GqJ+NP7XuZ5yK3anRqCNkO4r/4BS6AKv/7hp/KRrfXQ=; b=npU6dyFJrIsRd2pl0C8Uz2xGdQwW66sWJnuCAWGjSqC8fNHkuNY7z98hFUD1vivmbt GMPBKixbTZILcQdfdClclRzCtX75drOmS4Iw+9JmLqXjRxn46ZHLXmmCgTJazq42Abl7 F4W/2+kDC0q2usBl2g5kAwR8VJx/1nZsXRrj3txFLm2IWL6IcuWiVFTK8j+9aQ9EKQk3 VkIMg+J+xWTal/cOLS5JH0M1qGlPuFe0mBvKw9euzJ/nHrVYzTnLABXSpC8oKjplbaIR hmnpOobFJ/SotOJdoUTp898OZOZlRrk2oeHXJy48qxB2ch37+XYQzCHc5a/BmdCDyLqH Z/eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=GqJ+NP7XuZ5yK3anRqCNkO4r/4BS6AKv/7hp/KRrfXQ=; b=7Y2GAC3+GuV2OyTet4vU6FGls6LiKy2rK7hHp9z88MQyJBd7Egenaye0Yo7KbsA4eM BHSFFG99N65yY05SjTnh3/4vxYRNMDQW50RRzGn7vpCqpTZbpv0TM7UZ8NhNwE35LUtT cgv8MBg43voy5H0NhF9z1fsZiKsh+jzNVF941WfSnPSE3qCCRVhLlPUYTMRKd4h53Eu1 30N9XpMGCV5zh9zTAlKyoKQysMRDqsjP1TJ/Jir9PsK9t/AMSRnL3BT+znzKU6LKf0Ga DrirlABIrEkY3Qz5LyUUSe9wmm6nS9CLsFykW4LWMdopLsO3oRj502D2+kuC0rXMjcfe tfSg== X-Gm-Message-State: AOAM532VslhQ8Yss8efwmpJiNsLjoDqd4OwAYZhtZKyrFakiktQPnS/z iMtV5CrQuKaMMa0Xc0yZXMtaLbyO4wA= X-Google-Smtp-Source: ABdhPJz0sdlEQXWEi3FafDmCrtvLKUtalKsgYYO/NpWv9Fxb9Hs2hsIxAJgicsvm6ngFTGMf1eWtig== X-Received: by 2002:a1c:90:: with SMTP id 138mr39491688wma.27.1638806165047; Mon, 06 Dec 2021 07:56:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g19sm14521351wmg.12.2021.12.06.07.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:04 -0800 (PST) Message-Id: <7b1fab86a4a15f33b37ac3364a599c3f5237bf21.1638806161.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Dec 2021 15:55:57 +0000 Subject: [PATCH v6 3/7] test-read-cache: set up repo after git directory Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Move repo setup to occur after git directory is set up. This will protect against test failures in the upcoming change to BUG in prepare_repo_settings if no git directory exists. Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- t/helper/test-read-cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index b52c174acc7..0d9f08931a1 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -39,8 +39,6 @@ int cmd__read_cache(int argc, const char **argv) int table = 0, expand = 0; initialize_the_repository(); - prepare_repo_settings(r); - r->settings.command_requires_full_index = 0; for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) { if (skip_prefix(*argv, "--print-and-refresh=", &name)) @@ -56,6 +54,9 @@ int cmd__read_cache(int argc, const char **argv) setup_git_directory(); git_config(git_default_config, NULL); + prepare_repo_settings(r); + r->settings.command_requires_full_index = 0; + for (i = 0; i < cnt; i++) { repo_read_index(r); From patchwork Mon Dec 6 15:55:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D095C433EF for ; Mon, 6 Dec 2021 16:10:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385672AbhLFQOP (ORCPT ); Mon, 6 Dec 2021 11:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388756AbhLFQNn (ORCPT ); Mon, 6 Dec 2021 11:13:43 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D99EC00FDFD for ; Mon, 6 Dec 2021 07:56:07 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id o29so8538772wms.2 for ; Mon, 06 Dec 2021 07:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=gH3g4kfU8Y2PYneljW76tLyHpoW5kOXX5YMI78kGvl8=; b=lNX8P0W8EH6326aMCKDC6VWnMpMCbPI3DsiFIbgiDBRJlVBZ2X/0SCnYMFD4EmdnAV y7BhrbIyr6VAFOMkVdh8yt3S43GJQ0sHbpDwqSUcj+zsyVRypQvTs8bLF1enB5/RIwxZ Ks+7xqaxwfd5c7cIXK3l1goDFnWRbJiWjhpvHwhMD9j0vLV4AywwMGAgAqwS8VZ450qb 9i8TLus/yyzbtaZIOq0Kg7zGPKkZ+bvtvmtSeFel41v2hZJdn1bEP8VUNNexoMnmJ6Tl R3oEvNFOSfmrSrT9MMOZEj/kRbh439L6qfOIku+0C9d3Tp2Ex9EOkV7EGtpg6z0UXCvN +JwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=gH3g4kfU8Y2PYneljW76tLyHpoW5kOXX5YMI78kGvl8=; b=DODNx6jvsecKQrcOnykgMUkttWGwPAGK5AW2v/sjM3gB393z751PXdlcsWGwRzenJq n/MYzaiu5QQ9XfBEaDnPXvAvNB4xjvBpGgYgbQKL5XL6S3xGvNpnfRt8jjH77FzKyaW8 v7JSG1401eek104Nvqc84+zfHJzaa2CepsiymyPmAOVpPkt40I/bdynfPNAu/QGY+kwi p35lFZvSu7sdtoYjxmHLxUAvVsbMOZqUONRRG2QlFt4Y4+YjlR2odm+W95gGdmMrdh0t PPljto1vxMfQxQ915/UueaXj7Joix2+JyCRoWccdOvj0+DXq2O8NHferqBRUhJ9OZHot U7Iw== X-Gm-Message-State: AOAM531zirDS7Proy4qT694GCyDoWgjHCUEbMES1/2N3ItGgpsG8v3/n 8W2t+YtTsya5vhqrCJ94UV8ReHICtOk= X-Google-Smtp-Source: ABdhPJx/o81ryeM9gdyMvWjnAXcx0mkNLcZyPFxtU6zhFGwA579pMEjPAyI+QL6Yh0IBt5COI8ZS9g== X-Received: by 2002:a05:600c:4ed2:: with SMTP id g18mr39357973wmq.18.1638806165897; Mon, 06 Dec 2021 07:56:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u23sm12478162wru.21.2021.12.06.07.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:05 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 06 Dec 2021 15:55:58 +0000 Subject: [PATCH v6 4/7] repo-settings: prepare_repo_settings only in git repos Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Check whether git directory exists before adding any repo settings. If it does not exist, BUG with the message that one cannot add settings for an uninitialized repository. If it does exist, proceed with adding repo settings. Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- repo-settings.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/repo-settings.c b/repo-settings.c index b93e91a212e..00ca5571a1a 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -17,6 +17,9 @@ void prepare_repo_settings(struct repository *r) char *strval; int manyfiles; + if (!r->gitdir) + BUG("Cannot add settings for uninitialized repository"); + if (r->settings.initialized++) return; From patchwork Mon Dec 6 15:55:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD5C7C433F5 for ; Mon, 6 Dec 2021 16:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358778AbhLFQO3 (ORCPT ); Mon, 6 Dec 2021 11:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389075AbhLFQNp (ORCPT ); Mon, 6 Dec 2021 11:13:45 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1611EC0D940A for ; Mon, 6 Dec 2021 07:56:08 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id a9so23351528wrr.8 for ; Mon, 06 Dec 2021 07:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2WvfLHDRn5PtUSv8R0fF8N/KMYsMG9QkL9V0gTjzwPo=; b=q5apoVE8X7L/Ig4RnqblGgD8dbcDUVetJPw+ntEd081/ftMCc9t+BBC1aPjTPX7uKz u6Nxj1nxq7y/xbuGNPYjqjVTV9AKmtxNBWFglu6PRo/sca+RYqLz2ytdxg0wQpvx9Zhf +Shbtk+qMzsEIs9CPh1NFMvhKILK2SJZmZiueOXwfK4XA9dSJz+QudVur6dkGLq9pERV HCd9WCcLbuOIwKVfIpOJnju53h+ZzLxLxbPxY0NfluqqjT2xmeyY7az2V36hAjo4HFuh 23+qDqrSN8X17RrTjONTkuZqTFKgFSHa64DyP9X/hjrvoOfx0pE0KEWmvSrchUpBqN6s /WEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2WvfLHDRn5PtUSv8R0fF8N/KMYsMG9QkL9V0gTjzwPo=; b=FVm/4cnYvikoq8rXiutV2pCtB45/f5GMVPTGbtOjmI+zYhVE9IOKaOAzAzX2JvnCqB a9NPL10a8bCOCQ1qPCsvd767gMZmtWJEu7OQsZdfw0hhM6wD5+YvI+iO0u5mj2hDxs0V JzwBYXFx/xGY6n5RtG/OMIF49cALe6mSxtfGhEiqMFCl26tlcUPZfzxHk+NrXzhZQ4Hn UMKS7rEP+gcXfONalF2f61valldECjBzGGIhcjHKldQb0WqWhQdj3RXFjq5KUSNz/efk uTdwceFdEYJhReDZzuU5TH3xSVJlifucwI7bXHmsRRXT2rIw1fQP3v/oLxpxT6jI3eEK 2rHQ== X-Gm-Message-State: AOAM530EEZ9xp6ZyaeDYJ+DSu12FFO7Pz3Y3sWwL6QEd/5R/Tr9mGa0a 8hE5IU6FjX+ziqru808YwB8dwF7UMHA= X-Google-Smtp-Source: ABdhPJzkxMzG6bZXaTUfHbsZocaJaoJuhXdMvn9b1LGB2w6BlapJ1qucWz7f3fP5hhaHK/TfO9vYyA== X-Received: by 2002:a5d:52c2:: with SMTP id r2mr44863137wrv.548.1638806166611; Mon, 06 Dec 2021 07:56:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g16sm13720364wmq.20.2021.12.06.07.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:06 -0800 (PST) Message-Id: <2a1524a7e9ac267a550d5b88c02f853fe36fe08c.1638806161.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Dec 2021 15:55:59 +0000 Subject: [PATCH v6 5/7] diff: replace --staged with --cached in t1092 tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Replace uses of the synonym --staged in t1092 tests with --cached (which is the real and preferred option). This will allow consistency in the new tests to be added with the upcoming change to enable the sparse index for diff. Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- t/t1092-sparse-checkout-compatibility.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 77e302a0ef3..203a594fa45 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -371,7 +371,7 @@ test_expect_success 'checkout and reset --hard' ' test_all_match git reset --hard update-folder2 ' -test_expect_success 'diff --staged' ' +test_expect_success 'diff --cached' ' init_repos && write_script edit-contents <<-\EOF && @@ -380,10 +380,10 @@ test_expect_success 'diff --staged' ' run_on_all ../edit-contents && test_all_match git diff && - test_all_match git diff --staged && + test_all_match git diff --cached && test_all_match git add README.md && test_all_match git diff && - test_all_match git diff --staged + test_all_match git diff --cached ' # NEEDSWORK: sparse-checkout behaves differently from full-checkout when @@ -400,8 +400,8 @@ test_expect_success 'diff with renames and conflicts' ' test_all_match git checkout rename-base && test_all_match git checkout $branch -- . && test_all_match git status --porcelain=v2 && - test_all_match git diff --staged --no-renames && - test_all_match git diff --staged --find-renames || return 1 + test_all_match git diff --cached --no-renames && + test_all_match git diff --cached --find-renames || return 1 done ' @@ -420,8 +420,8 @@ test_expect_success 'diff with directory/file conflicts' ' test_all_match git checkout $branch && test_all_match git checkout rename-base -- . && test_all_match git status --porcelain=v2 && - test_all_match git diff --staged --no-renames && - test_all_match git diff --staged --find-renames || return 1 + test_all_match git diff --cached --no-renames && + test_all_match git diff --cached --find-renames || return 1 done ' From patchwork Mon Dec 6 15:56:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6510FC433F5 for ; Mon, 6 Dec 2021 16:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358940AbhLFQOc (ORCPT ); Mon, 6 Dec 2021 11:14:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389100AbhLFQNq (ORCPT ); Mon, 6 Dec 2021 11:13:46 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC8EAC0D940E for ; Mon, 6 Dec 2021 07:56:08 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id a9so23351627wrr.8 for ; Mon, 06 Dec 2021 07:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Y3sRj9BcOkWbh+b8jgq9VmCE85Gg045cO6ZEqcMJtB4=; b=C7Kp3mXsUWlUgSbmWY5fv0kSOv6DHqGhdi6Y6bs6xPi9PnQoXJIrPpLionUaeZKovy vLoqq4KTnrQwkrT113yWejxnrI7nPTyfQ2Kt5TvUlBwftEWXTh6siS0DS8BJrEdg2EGV 0eZYncF4heTfDtaOm4Yev479JfNJn/u2QroBBF8HER2YlmBbkGN/mVx5Cbt5nLrZqQmM 3UgdUQQgyAcBBPkDGcHZ17wUKRDcWNUbPNszCRJoUlGrVIpBHc08iOvjjxVOnQZMC+UW xR5JWiVRiqbDtlrn4Met8bC+/RU7HI2okPDU+ONrfJFywCPySEU4yFO25KWojP3AEGnN WbmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Y3sRj9BcOkWbh+b8jgq9VmCE85Gg045cO6ZEqcMJtB4=; b=6LO4of8CS7sLVrjOPlqa5EF0AjJPI30G30SFRAQK6augolWkYxJb2xq3UqpbbAl7qu nToMcXCHL1gldQYMpm1XPiLCsnXD89oNQ82AVfrmZbK/P1dRqSgftlKhOrjL3dQigWXV BRS5Pjh45ZcefdWAo10wTnkGPRiSPuvo6kN3K6k+D7pXQC3NmN9UGIPxAEY+yODZSFL0 LmtxqMF2UpFoN5lS3Ob125cxxOjlPz+JWJc9bN1qO9WvBgSkv9NpNI9sNux1yKHnIdPO ROQMzFgHe+utrOfkmFgPjTJ5wwXcLw9051HK0Jl6HsrFL2L0/q0O06LnNr/juB0qjUCV C32A== X-Gm-Message-State: AOAM530dZceR6yyyAJgp+irAvv9M+d5kmdp6+wccj5fkYuRBte102COc wMFBmGZxc+GQJjuFcvIZPVjtZlqZ0l4= X-Google-Smtp-Source: ABdhPJz63FM+hD6E+pix7Pg3Kcc1787E8qWsHb0z8QzhtSEV3yZFo3LJ6EfKfPbnY131tca6m/wm+Q== X-Received: by 2002:adf:e54a:: with SMTP id z10mr42697488wrm.328.1638806167418; Mon, 06 Dec 2021 07:56:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r17sm12830392wmq.11.2021.12.06.07.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:06 -0800 (PST) Message-Id: <897611682af64ba6bd0d2dfcfeae56cfe953c45e.1638806161.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Dec 2021 15:56:00 +0000 Subject: [PATCH v6 6/7] diff: enable and test the sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Enable the sparse index within the 'git diff' command. Its implementation already safely integrates with the sparse index because it shares code with the 'git status' and 'git checkout' commands that were already integrated. For more details see: d76723ee53 (status: use sparse-index throughout, 2021-07-14) 1ba5f45132 (checkout: stop expanding sparse indexes, 2021-06-29) The most interesting thing to do is to add tests that verify that 'git diff' behaves correctly when the sparse index is enabled. These cases are: 1. The index is not expanded for 'diff' and 'diff --staged' 2. 'diff' and 'diff --staged' behave the same in full checkout, sparse checkout, and sparse index repositories in the following partially-staged scenarios (i.e. the index, HEAD, and working directory differ at a given path): 1. Path is within sparse-checkout cone 2. Path is outside sparse-checkout cone 3. A merge conflict exists for paths outside sparse-checkout cone The `p2000` tests demonstrate a ~44% execution time reduction for 'git diff' and a ~86% execution time reduction for 'git diff --staged' using a sparse index: Test before after ------------------------------------------------------------- 2000.30: git diff (full-v3) 0.33 0.34 +3.0% 2000.31: git diff (full-v4) 0.33 0.35 +6.1% 2000.32: git diff (sparse-v3) 0.53 0.31 -41.5% 2000.33: git diff (sparse-v4) 0.54 0.29 -46.3% 2000.34: git diff --cached (full-v3) 0.07 0.07 +0.0% 2000.35: git diff --cached (full-v4) 0.07 0.08 +14.3% 2000.36: git diff --cached (sparse-v3) 0.28 0.04 -85.7% 2000.37: git diff --cached (sparse-v4) 0.23 0.03 -87.0% Co-authored-by: Derrick Stolee Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- builtin/diff.c | 5 +++ t/perf/p2000-sparse-operations.sh | 2 ++ t/t1092-sparse-checkout-compatibility.sh | 46 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/builtin/diff.c b/builtin/diff.c index dd8ce688ba7..fa4683377eb 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -437,6 +437,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix) prefix = setup_git_directory_gently(&nongit); + if (!nongit) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } + if (!no_index) { /* * Treat git diff with at least one path outside of the diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh index bfd332120c8..5cf94627383 100755 --- a/t/perf/p2000-sparse-operations.sh +++ b/t/perf/p2000-sparse-operations.sh @@ -113,5 +113,7 @@ test_perf_on_all git checkout -f - test_perf_on_all git reset test_perf_on_all git reset --hard test_perf_on_all git reset -- does-not-exist +test_perf_on_all git diff +test_perf_on_all git diff --cached test_done diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 203a594fa45..abfb4994bb9 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -846,6 +846,52 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' ' ) ' +test_expect_success 'sparse index is not expanded: diff' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + + # Add file within cone + test_sparse_match git sparse-checkout set deep && + run_on_all ../edit-contents deep/testfile && + test_all_match git add deep/testfile && + run_on_all ../edit-contents deep/testfile && + + test_all_match git diff && + test_all_match git diff --cached && + ensure_not_expanded diff && + ensure_not_expanded diff --cached && + + # Add file outside cone + test_all_match git reset --hard && + run_on_all mkdir newdirectory && + run_on_all ../edit-contents newdirectory/testfile && + test_sparse_match git sparse-checkout set newdirectory && + test_all_match git add newdirectory/testfile && + run_on_all ../edit-contents newdirectory/testfile && + test_sparse_match git sparse-checkout set && + + test_all_match git diff && + test_all_match git diff --cached && + ensure_not_expanded diff && + ensure_not_expanded diff --cached && + + # Merge conflict outside cone + # The sparse checkout will report a warning that is not in the + # full checkout, so we use `run_on_all` instead of + # `test_all_match` + run_on_all git reset --hard && + test_all_match git checkout merge-left && + test_all_match test_must_fail git merge merge-right && + + test_all_match git diff && + test_all_match git diff --cached && + ensure_not_expanded diff && + ensure_not_expanded diff --cached +' + # NEEDSWORK: a sparse-checkout behaves differently from a full checkout # in this scenario, but it shouldn't. test_expect_success 'reset mixed and checkout orphan' ' From patchwork Mon Dec 6 15:56:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12658831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4477BC433EF for ; Mon, 6 Dec 2021 16:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359017AbhLFQOd (ORCPT ); Mon, 6 Dec 2021 11:14:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389106AbhLFQNt (ORCPT ); Mon, 6 Dec 2021 11:13:49 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1605C0D9411 for ; Mon, 6 Dec 2021 07:56:09 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id i5so23463110wrb.2 for ; Mon, 06 Dec 2021 07:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zAyiLu7NKqiK1xZtBC/at22Yvf3tgxEoUxqg4XC6F30=; b=PGMObh9lkjbnYcxJUQJKhmT3m5LQHq0VPG1j8kX4umd8ZDlLY4FBe1UGyvh6NhSic9 gX861lyTjJSHF64oesHQmVM5E2sNMsU5MO4UViUoEyYb3ybJsOd1Ynlh7ELqd3BZaiao AbAk4HiKxQ9TCJ3HTN72FBC4KPiZVpyimnz/k5kFoUdO6hZV/8G8KGTLMb1lFY1kQ9Mv 8V4JY6V0zfneJnT1e3DFEBQtP1hIU6t4mizT1Qz78bgu43aLY/PlSxVS5fo99Mjw06x1 eNnWueo4P0hcQ+/Uh/xctUy6+/p6wLMlZ8U9j5yLFvZcUYfeHBbg+g0uhKeIUaMz45Wg ywaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zAyiLu7NKqiK1xZtBC/at22Yvf3tgxEoUxqg4XC6F30=; b=W/L3N4ix7fT99kuqnhIDV1g8T3Fn+UbQkvOxCBm8iKbKMB4Q/1T9Oo5jMSsYotvwmZ oU371js6MDIOyeg22DXC3EF7Ef0KGrfR81SbYIKd7DzPAugRDIgNmh+hoPbrGLFuL2Jr xvrugFHLEYAha/p3rlJMIsXYzWXDVNdYd3BlKgrpHqxnHGDgQnSoFM9LZrGH7ifNx2Is tkqFwH1ZjDZlMvGEaOrd+uq7cLdx1178sCgKY3kIHp9cjo4C0La8wwhnBUQSCDczzZnH jt/wnANddcma1Lzz85e67wnzlnbhOfgDkpASauNKc0o4pQqDseBqGezjDXMbwdd59ffo FxRw== X-Gm-Message-State: AOAM530/0xb2CyyWnYxLxlA+EEth+tS8KamVXTRDdsSXy/TMQy6M5A4m /yHlilfOMrP69Nnj1+d4ypDavJhU7ZI= X-Google-Smtp-Source: ABdhPJwKHChSuxM3A8S4lZgwnLdbSRxeWFXYOlPEwV3xWtAvtH/1/KMiPaYNfOGBkta5HvvpRPrHvg== X-Received: by 2002:a05:6000:23a:: with SMTP id l26mr44147453wrz.215.1638806168164; Mon, 06 Dec 2021 07:56:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d1sm11179654wrz.92.2021.12.06.07.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 07:56:07 -0800 (PST) Message-Id: <85bcbaa1771c97a0f6ca3cc03c80f02ee2f84061.1638806161.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Dec 2021 15:56:01 +0000 Subject: [PATCH v6 7/7] blame: enable and test the sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, gitster@pobox.com, newren@gmail.com, Taylor Blau , Lessley Dennington , Lessley Dennington Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Lessley Dennington From: Lessley Dennington Enable the sparse index for the 'git blame' command. The index was already not expanded with this command, so the most interesting thing to do is to add tests that verify that 'git blame' behaves correctly when the sparse index is enabled and that its performance improves. More specifically, these cases are: 1. The index is not expanded for 'blame' when given paths in the sparse checkout cone at multiple levels. 2. Performance measurably improves for 'blame' with sparse index when given paths in the sparse checkout cone at multiple levels. The `p2000` tests demonstrate a ~60% execution time reduction when running 'blame' for a file two levels deep and and a ~30% execution time reduction for a file three levels deep. Test before after ---------------------------------------------------------------- 2000.62: git blame f2/f4/a (full-v3) 0.31 0.32 +3.2% 2000.63: git blame f2/f4/a (full-v4) 0.29 0.31 +6.9% 2000.64: git blame f2/f4/a (sparse-v3) 0.55 0.23 -58.2% 2000.65: git blame f2/f4/a (sparse-v4) 0.57 0.23 -59.6% 2000.66: git blame f2/f4/f3/a (full-v3) 0.77 0.85 +10.4% 2000.67: git blame f2/f4/f3/a (full-v4) 0.78 0.81 +3.8% 2000.68: git blame f2/f4/f3/a (sparse-v3) 1.07 0.72 -32.7% 2000.99: git blame f2/f4/f3/a (sparse-v4) 1.05 0.73 -30.5% We do not include paths outside the sparse checkout cone because blame does not support blaming files that are not present in the working directory. This is true in both sparse and full checkouts. Signed-off-by: Lessley Dennington Reviewed-by: Elijah Newren --- builtin/blame.c | 3 ++ t/perf/p2000-sparse-operations.sh | 2 + t/t1092-sparse-checkout-compatibility.sh | 49 ++++++++++++++++++------ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 641523ff9af..33e411d2203 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -940,6 +940,9 @@ parse_done: revs.diffopt.flags.follow_renames = 0; argc = parse_options_end(&ctx); + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + if (incremental || (output_option & OUTPUT_PORCELAIN)) { if (show_progress > 0) die(_("--progress can't be used with --incremental or porcelain formats")); diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh index 5cf94627383..cb777c74a24 100755 --- a/t/perf/p2000-sparse-operations.sh +++ b/t/perf/p2000-sparse-operations.sh @@ -115,5 +115,7 @@ test_perf_on_all git reset --hard test_perf_on_all git reset -- does-not-exist test_perf_on_all git diff test_perf_on_all git diff --cached +test_perf_on_all git blame $SPARSE_CONE/a +test_perf_on_all git blame $SPARSE_CONE/f3/a test_done diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index abfb4994bb9..6187a997b7d 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -442,21 +442,36 @@ test_expect_success 'log with pathspec outside sparse definition' ' test_expect_success 'blame with pathspec inside sparse definition' ' init_repos && - test_all_match git blame a && - test_all_match git blame deep/a && - test_all_match git blame deep/deeper1/a && - test_all_match git blame deep/deeper1/deepest/a + for file in a \ + deep/a \ + deep/deeper1/a \ + deep/deeper1/deepest/a + do + test_all_match git blame $file + done ' -# TODO: blame currently does not support blaming files outside of the -# sparse definition. It complains that the file doesn't exist locally. -test_expect_failure 'blame with pathspec outside sparse definition' ' +# Without a revision specified, blame will error if passed any file that +# is not present in the working directory (even if the file is tracked). +# Here we just verify that this is also true with sparse checkouts. +test_expect_success 'blame with pathspec outside sparse definition' ' init_repos && + test_sparse_match git sparse-checkout set && - test_all_match git blame folder1/a && - test_all_match git blame folder2/a && - test_all_match git blame deep/deeper2/a && - test_all_match git blame deep/deeper2/deepest/a + for file in a \ + deep/a \ + deep/deeper1/a \ + deep/deeper1/deepest/a + do + test_sparse_match test_must_fail git blame $file && + cat >expect <<-EOF && + fatal: Cannot lstat '"'"'$file'"'"': No such file or directory + EOF + # We compare sparse-checkout-err and sparse-index-err in + # `test_sparse_match`. Given we know they are the same, we + # only check the content of sparse-index-err here. + test_cmp expect sparse-index-err + done ' test_expect_success 'checkout and reset (mixed)' ' @@ -892,6 +907,18 @@ test_expect_success 'sparse index is not expanded: diff' ' ensure_not_expanded diff --cached ' +test_expect_success 'sparse index is not expanded: blame' ' + init_repos && + + for file in a \ + deep/a \ + deep/deeper1/a \ + deep/deeper1/deepest/a + do + ensure_not_expanded blame $file + done +' + # NEEDSWORK: a sparse-checkout behaves differently from a full checkout # in this scenario, but it shouldn't. test_expect_success 'reset mixed and checkout orphan' '