From patchwork Fri Dec 3 21:15: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: 12655787 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 DA626C433EF for ; Fri, 3 Dec 2021 21:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383188AbhLCVTi (ORCPT ); Fri, 3 Dec 2021 16:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353164AbhLCVTf (ORCPT ); Fri, 3 Dec 2021 16:19:35 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 861EEC061751 for ; Fri, 3 Dec 2021 13:16:10 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id n33-20020a05600c502100b0032fb900951eso5832424wmr.4 for ; Fri, 03 Dec 2021 13:16:10 -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=rooMQHv/GtYad0Sn9rHuPSMWvnhkO0/WC7D6rGtcQo8=; b=M/xhpBx3lEjEPDiZNKtsp6IpqOVcdIYzrNsY1KXOle4f8Zvbj7UsKynGVGrr49Pyyx k3WouJolxLSxMInfEVjArP+o9v5jFCoefPa81gVJPlveDMvdp3bbSQgr0SLHZDharlwa dW2nEiPNRDsYI+gutoocXFeDf8rYGJ5YDYUglwWwHU5e1SmWMP7k3QA2yH9UEi6K+dvG Pe64R5zVfOUVu13hXy+fY+iRhtCiH7Me7mMAthGy3OoOourPpa9DYdQO6BjRF7cRVHSa TwnpZ8PYEeVLtFVNkWjWdi3hyOqVy0tvyJsoxkjgYaqIRWZQRT6VdACa9RbdG0TTatRJ uMyQ== 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=rooMQHv/GtYad0Sn9rHuPSMWvnhkO0/WC7D6rGtcQo8=; b=KR1xIxiKUnme9dNuMSZntA/3LZWjVB1QS/OqScrEQWG/2k46nPu2RKWawDtPifClvn Sb5srdxcWLgUWq22ZG5Ccdi/VN3DouvP44cNL87w8i6nLjMCNS3aTGhZoctPBEbZgSUB 4rCJrN7QY7t3wVamIYWi20wlDGa73XrUtUpF1/m92FrFP5zuKA6A2tXFa8oWa+nEXG/8 TbNFmCNVpvrYIaeVzRXCG3qbESEEOXGJ8ko2YeA4O2tjGOKstB12NeEHT8jM0edai6uv 4krRwJRRepFBoGbr5y5f/yMlb9DNuyApop9fYMpm9ofE+X2GQZE+AZoK3s+JKMV5v2+N hY7A== X-Gm-Message-State: AOAM530aeafov9FabMCeLDkxKwpBAXXoS+ph6Qe9mvMUzzcvp26oPgbK U0QsggjLFfIKv8EKg8HVF+uhRg/usTw= X-Google-Smtp-Source: ABdhPJw9secPtrYxT7jIdUUJwtxcTgUX8Ct/Lc8/b9f3f2WXJ+5ijYunH0mo3NiGjd1/2+WKphsVRA== X-Received: by 2002:a1c:7910:: with SMTP id l16mr18259707wme.36.1638566168883; Fri, 03 Dec 2021 13:16:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i15sm7104934wmq.18.2021.12.03.13.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:08 -0800 (PST) Message-Id: <09c2ff9f89833b3ac918a399e10d1b6abe71b339.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:15:59 +0000 Subject: [PATCH v5 1/7] git: esnure 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 --- git.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/git.c b/git.c index 60c2784be45..03a2dfa5174 100644 --- a/git.c +++ b/git.c @@ -421,27 +421,28 @@ 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); } + 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 Fri Dec 3 21:16: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: 12655789 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 487F5C433FE for ; Fri, 3 Dec 2021 21:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383196AbhLCVTj (ORCPT ); Fri, 3 Dec 2021 16:19:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383182AbhLCVTg (ORCPT ); Fri, 3 Dec 2021 16:19:36 -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 98571C061353 for ; Fri, 3 Dec 2021 13:16:11 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id p27-20020a05600c1d9b00b0033bf8532855so3170683wms.3 for ; Fri, 03 Dec 2021 13:16:11 -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=cSH7cOtj50LHKXW2qAngoAwe/N6Nsz0dLhcE1QMcy0c=; b=TzxByrxq5PAGV1ckbWkYWOwftRUhNdzvX2xWjWnkqtlTGwsFR+S213AhHg7cix21Me zARoTx5Ek8FRTs0ZrPjLOwfGvubzq4Zk5z57PTAzcWl0yykDzbLBq0KBR5n906GEzWhw G10gu+MIl/SWUeAE0X68YBsWBj3babUyjfFwvqAupdNAkbhoajidLei7Fu8c2OhvFApt YhV7Lxd0gL0U9C/DZYYmLn2U4c8euwMkSigp21oryHXDZsAx9Pu0RwdGatahTmuc/v5L xi8rQVsF4OQ7A5TANHh8kuECasTQG7xzUGxm38VS2jxlD2DGZqa9bmIzsHCLqY1mb8+z wwLw== 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=cSH7cOtj50LHKXW2qAngoAwe/N6Nsz0dLhcE1QMcy0c=; b=vat4H1UL+jyoqCMBWm+i//fzeSORi8Szm97R7A3aZ6tw82WF86ZgfnRBhwLS3ug/Lq NY9u/oqNAScjtTPuLJiI7B4DOQNZidhCsRaF/HxCeOrF48/kcW+AAe/FzXAFbcW7s3Gp ZTi6NUgxzTzgaqxHoPaLhzgjnZblnKbNgUw1PnOz1N0zFq+x3ZKt/mO71Pp1zJ5pH4dQ elvF9PnN+/IX9j74AcYwbXem3afPQWf0Tc3n0xC1x/nkoLFAjnPh6uuF6t9QexQ/NA24 y+3xqc2EE0FlbhiWZJC42lX3M7r0r5pdViPRWV2SgxDAXfavJP3JU95weN7SQ5RjKvhl 4FuQ== X-Gm-Message-State: AOAM533/sYPFO2cxep4mqCX+mtAfUotxkWRyV/rAkWao5AcucZMlmDsw PSo/TXnfYTYlMxdGmGZ26X3r+DYoca8= X-Google-Smtp-Source: ABdhPJyv8S1+2er+ZcHEBFKprNxlpU1hQqB8bzHOCr4znXemL+UoN2jutnhFbV+Y8c5sAbql1QUX6w== X-Received: by 2002:a1c:770e:: with SMTP id t14mr17724735wmi.173.1638566169941; Fri, 03 Dec 2021 13:16:09 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 10sm4916450wrb.75.2021.12.03.13.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:09 -0800 (PST) Message-Id: <9e53a6435e4e7bdde941875fac6742288947b5e0.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:00 +0000 Subject: [PATCH v5 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 --- 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 Fri Dec 3 21:16: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: 12655793 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 6E4F4C433EF for ; Fri, 3 Dec 2021 21:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383206AbhLCVTm (ORCPT ); Fri, 3 Dec 2021 16:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383184AbhLCVTh (ORCPT ); Fri, 3 Dec 2021 16:19:37 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7268BC061354 for ; Fri, 3 Dec 2021 13:16:12 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id u17so1017679wrt.3 for ; Fri, 03 Dec 2021 13:16:12 -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=E1LqB2ItbJrSpS1f5tW0UwcDQSSnyHdQE50whFsxMpQ=; b=n7G7uVR6HbhFa/sx5b92uhpdDPUwN4bWvNzEiOmnCoCB6K9T7IH/YMYmQw5+SZsc9Q 0+8GqVKKRquxJzfGx3FDeOxRM27K1BMSz0beXbFD50V4/WlXVyV0GjMmjDrSAuxQL6ex ALqip5NgM4xVa2KC+IqlOdal5vF/Wdfsb8ZZBiNxc7VeEx69FQcZifvZQtTBdw6bEL3m IMwJeZLhFkCHiQvYZctXYDJ6lUmhK7VBvoCPTdAxE5g5d76C0eRDHTXQ0+F46Z1qsXFu 2zhfd8HhBKreHpzVxcggo7I2pt05c/ueF5ezxZLvetNUnbQjrN5xTVEPrx1T5+OH8ecU D1Wg== 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=E1LqB2ItbJrSpS1f5tW0UwcDQSSnyHdQE50whFsxMpQ=; b=hgrdF7+e6VeYbdebQVrzzfkgOYm5Sl6aF3Qy5OUZoatdLAoz9mdugoa0vwC64IEWzd hHtfm1JSL5a3+zFeASfQ8uchLZiDteisJb9W3TtnUc7stJVJg7f30uZlSdouCjGyspQX ShP0TiPwf+oL9ayslMY4HhBN0AgUABZgiFiV5+AjC+ggC9d6E/L9yoaar9AfdtGVMSOC /bZfxdkA73zdfOb6Ye4xd1JeNdovaYbXh5AgvaIZOxaoBFkS7sTRP5uSOTfgEYBDrnIY 0jFCkT0nn+/YJI/HLBldxC41UVqaiP0Pp2s1Yh1k3i0q13WmufatNB5xNh8wI917Rle7 WBKQ== X-Gm-Message-State: AOAM533tN8BXuGq9vuno3j0yZ7LEFVTqWX/H4sTIWhRt4clC7x9l5AeD t9MH+8PPgN95BypeF4ED+5WAZfVQoKc= X-Google-Smtp-Source: ABdhPJxLE43rHLl/fU9N1PEKAfuJMFXwqL0k4PgQP0X62mQ1gRk+fSrbye7U2T+XmaLwvWhddYF6iw== X-Received: by 2002:a5d:66c5:: with SMTP id k5mr24442049wrw.621.1638566170975; Fri, 03 Dec 2021 13:16:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 138sm6254243wma.17.2021.12.03.13.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:10 -0800 (PST) Message-Id: <219a4158b6a0f14e8cfc5b74108282968a2d8ed6.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:01 +0000 Subject: [PATCH v5 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 --- 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 Fri Dec 3 21:16:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12655791 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 3CF1CC433F5 for ; Fri, 3 Dec 2021 21:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383190AbhLCVTk (ORCPT ); Fri, 3 Dec 2021 16:19:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383185AbhLCVTi (ORCPT ); Fri, 3 Dec 2021 16:19:38 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BEB2C061359 for ; Fri, 3 Dec 2021 13:16:13 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id k37-20020a05600c1ca500b00330cb84834fso5864624wms.2 for ; Fri, 03 Dec 2021 13:16:13 -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=qnnARUJEEm3sGTd8Pw36NMYQWEiig9WLeH2Su3z30Pk=; b=VGBuCvEW/5wnWRYq95/UMiJemL3bFC6HjxhjSIlEn+x4XEjEthlREGmiuHBBxRbpqJ ya8t60BhLsvFDeiLUWGAN5ZZYbTRkHsOoN73VuBsTYhOfG3f1ZNsWQQuaqbAb4yrt+CM bjAd7mlWBPPRNUrlU52oOibLJGlqVkyYVFLwDjWgpnG7N3+NAIYc48uLYjn5Svfhdu8I a3Goztzo88Sokqgf+pMkxSoDIwUrwAa3/ZXZPRLilyaKqy5JOLWyAhw0wXbgrPj4IJQ/ WlsCVJOp6NNJhn/r48QY3NMHaynwTLapu/cZufv5Pcw9WdQOfiXWtomZvQfoEwciLzc/ s+zw== 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=qnnARUJEEm3sGTd8Pw36NMYQWEiig9WLeH2Su3z30Pk=; b=4uBDvj5hx1MFQwCJnFzLuEwPME4R4B9E43GxOL290ttNwRpaCuQQo9/RhOyOI0JinF uVRH0s/Z3EOF9yNZCpuke/+ZK/PsAmAgxtSK89wPsqLXhL2M4FRgzE9S4QRhtBpz49LT 1e+28ibgccM9PHsOP/ZkuE1K4Z66uoQ/nMe4VblJmkqTNOZKJatoH8iSOPhY3iwBDwj8 NGrUnLnIa+BahYSwntDdkPEdE6zyhskiCIDOLM4MYMFJ+IfNEJ/qqRtoP10DSO1jpJyj 4jONsAbSnoMU02EnugxiQJi15yUNV9p1ZhV3x6EpqQ+rsSB76aRHcgDHYDWCNupKkGW/ bj/Q== X-Gm-Message-State: AOAM531MLN1a1pgroObkGGJqTTZn4A2133xH/7QM7bf2TYC2ZOnQ+Tfk 5Zm+O1sq2Uj6Q3zszxCtEEITE/BGFwQ= X-Google-Smtp-Source: ABdhPJzlcGDAFPBt/0XvRVYube6Rw5m7OTX2c8MUtCBi4iyONNA06KuIxLik3m8EYfXi83Tp+MQjuw== X-Received: by 2002:a05:600c:b46:: with SMTP id k6mr18239451wmr.45.1638566171903; Fri, 03 Dec 2021 13:16:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t11sm3791848wrz.97.2021.12.03.13.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:11 -0800 (PST) Message-Id: <4d8d58c473b51cac6645a7d71336e995c1f3d28b.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:02 +0000 Subject: [PATCH v5 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 Reported-by: Ævar Arnfjörð Bjarmason Signed-off-by: Lessley Dennington --- 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 Fri Dec 3 21:16:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12655795 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 5AE2CC433F5 for ; Fri, 3 Dec 2021 21:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383199AbhLCVTn (ORCPT ); Fri, 3 Dec 2021 16:19:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383193AbhLCVTj (ORCPT ); Fri, 3 Dec 2021 16:19:39 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F4FC061354 for ; Fri, 3 Dec 2021 13:16:14 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id u1so8263961wru.13 for ; Fri, 03 Dec 2021 13:16:14 -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=1xcvpy3GEbejXob77lGP4eiVvSIRlP14kwXnA4hYMvk=; b=Z7PUhpexz34MxL67S7/aD8PZd7XgeVq1FkwGXz0NT5hfRqv1cWFMlTyKSZh0IXJfAa uK77HV56lDIHfwMUCU+eQWGceiOSe/8QMXgu9HYTHGTzrKxAmgXsGF9fnwPXX5OUwEti h4LoHmsYSTC47z0vUvbF2LUkyimSChzkhkjL3wFjz86kui0KuPlzz65ZG93iHAv4dHqZ Cg5+NF1e9s8QIZPUMTQvVvK9HnBA/aZpup6wtFnyI+h3gpvoxHhxRphI2jCBB6JRQNf9 Q9X21ROy79S7tQxj/1fFL3V5kVMQdrWm91/9n/lTcplJMVvYI0K9lr0IA8q/0NhxeuLM 74EA== 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=1xcvpy3GEbejXob77lGP4eiVvSIRlP14kwXnA4hYMvk=; b=EewJ9YqJJCa78sZ5Z8BW2kSyUOsvdT7c0x0729zLz/kUNMubOmpIMJ1/5TktaeiVGb fxaYFtmWqAZxAz1rAENBeDXxtl4Z7jLsC4d1dTIR3bem3S9uNVnNGX0KQd+M5+HUaU0C bacQq8ONFQy11Tf5it8t6tTKbf4VJI/lIypvil6iWqM5HKV2kgRPrCMnDBm07M7pFbdY hejutampGnVCxYl5GlgHj9AMfSoGUZ/qaLzQyrGqUzN6iYPyPewWG0aq7PwSKc9IP/NU o+bspkOHsHSloW+o2iPV+A9tV00Z/PzLpEYygzt7gA/wTlWjO6LzEvKjTewjtdU+tzSz +5AQ== X-Gm-Message-State: AOAM533cUa9uWk125AsVxcPfqN7fgl0pdO2tFECP0MzJlJPgZRFEtzcs 67yDLu0xV2zEsFeppbwBhZIO3IgvosY= X-Google-Smtp-Source: ABdhPJys2GGc7Ex8PgVVMWR5eFQ8OZU8U6d5NMvu4x5WSFlQy/eiLd9KgufWRERwg5SMOVft5UBL3A== X-Received: by 2002:a5d:4492:: with SMTP id j18mr24374032wrq.397.1638566172986; Fri, 03 Dec 2021 13:16:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n32sm3572381wms.42.2021.12.03.13.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:12 -0800 (PST) Message-Id: <85e3e5c78e741496a1c99ccc84e59b16fa0a7158.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:03 +0000 Subject: [PATCH v5 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 --- 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 Fri Dec 3 21:16:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12655797 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 15425C433FE for ; Fri, 3 Dec 2021 21:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383208AbhLCVTo (ORCPT ); Fri, 3 Dec 2021 16:19:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383198AbhLCVTk (ORCPT ); Fri, 3 Dec 2021 16:19:40 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 715BDC0611F7 for ; Fri, 3 Dec 2021 13:16:15 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id k37-20020a05600c1ca500b00330cb84834fso5864691wms.2 for ; Fri, 03 Dec 2021 13:16:15 -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=KJSSw8wLQl29emn+b7bo5RHNpEJ8F+oMMnMemV7dCdQ=; b=ZYhf0dRh4N5peUDIWGt4EIPr9EjW46XcR3+HtAE4rssrkitgA8w6W8M4RlATPXgF+e +8jQPoJZ+MtHYzo7vi4zRMh4wt3OCNfeWSTEdcyLlBKp1/fyQYC0c3SWXt1JZqimhQYm /w68TvU1/CquJa7bWfc5C+4D8PV4B4gVSqYJ5JmHyQLWgU8/jz7JRAIzENrX+0e0xkHJ TfdiI0PT5925ISrM+JdbQHO4EK7l9OY7+oS6xyBLV3xoVS+jz/VKYmb9h/rIJ96s91Wg 7sT6hC+ZYabEUYHcFdeKTf2Yj+EXDxQTcFanFOcWAl0ZmmO8QLvu+EWuJ7hk0LJG4EK5 uIEg== 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=KJSSw8wLQl29emn+b7bo5RHNpEJ8F+oMMnMemV7dCdQ=; b=cr7MZuSJL8P2LsSmlDC9pvcX1D8ID8XZVOyPijlu3kTYZX3VKyGCtFD25ckboe25tH z43pfv5WNkZ08ERyHra3Lhtr8DgdCS6CjKWlIFQZsPs554UfHFKRgQkPyM/wzQ5ZJ9AP hwKsVS8JPrITUDpVhaRWhfdypx1kxAEeSiOdTCXFPWI2XinfMZX7QUTX1SMrKGu6ZEgC XcpjVaCkbhbPhDbA44byn6gHod3wvMgT2/sHD6KJQWM7ig4hz3YxREr48SEiyDkss8UL AaPc733n+odaLUjg9w0fap5clnbmHMsf0KSXQP2MWjlJ3aFUedS8+wI6+gcuwzFgSDQL dl7w== X-Gm-Message-State: AOAM533ASlLp+9TCebYBK7dyqMa+hJN3pSUZJSuWYmihq6PODBKqRcEC QLa+498DwbxKHfC80qnc/YOl/f2Z6zM= X-Google-Smtp-Source: ABdhPJwMNrI6AUTBIpgeuRjIJA/vPVYSIgQRNYezIjGcMWLHvJoFuGpXhNZu5Red4tJreDmIG95E4g== X-Received: by 2002:a05:600c:24c:: with SMTP id 12mr17565400wmj.124.1638566173859; Fri, 03 Dec 2021 13:16:13 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z6sm4445079wmp.9.2021.12.03.13.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:13 -0800 (PST) Message-Id: <4f16366e5adfd47094f971f8611533a85955aa54.1638566165.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:04 +0000 Subject: [PATCH v5 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: Derrick Stolee Signed-off-by: Lessley Dennington --- 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 Fri Dec 3 21:16:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lessley Dennington X-Patchwork-Id: 12655799 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 B4BDFC433F5 for ; Fri, 3 Dec 2021 21:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383210AbhLCVTp (ORCPT ); Fri, 3 Dec 2021 16:19:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383192AbhLCVTk (ORCPT ); Fri, 3 Dec 2021 16:19:40 -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 57416C061353 for ; Fri, 3 Dec 2021 13:16:16 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso5834683wms.3 for ; Fri, 03 Dec 2021 13:16:16 -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=uU/hEQjnAF5FZQWZ40iR+eukDquJq7jW0O71gy/5HiE=; b=GRSmw3RC6PnJXzquc4iFxOGxXs7P/oIvtRsDywHPWZBRrSnEilEbh2660njl9UWbjW jy1333C5Yq66TGNQAEX7L6zQMRHVK+Q7B/hNRXNR2HRN+rxqPjnEaYLS1/7hGkxdaum2 JxSpKR5j4/o9STBeJoo6nVL3kACxFN0h/y/dCjURewP8ykAnOVaQxIhoHT2W8KS8qaEn lk2JIBS92DyL9so72RuQfC1ynlCLtj3ah6CNtnzPEcLsYp1VJMyWGhKqWC/WbuowBMM7 5g6jEvGskM+YRGKdr5Jo8KGX9pKvS91yaBEykspZ6HWBAQ3ucg7LuPIF3mlAhjZXf0X8 G8nQ== 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=uU/hEQjnAF5FZQWZ40iR+eukDquJq7jW0O71gy/5HiE=; b=fEYJZbXuCWfDGYoy8Fj6bF2gwt7NFpni/G1co8G94A8QXjY0kSTQegXIBAMAnUvjaL 6ErnCYOVQZ0D4yZcWfTifVYnlTgxw4DFil7Vg0ZYhWMi9rQST01pFXqa8apwCvg8Wtlk FUAOkYCc7T0tdiqMrMX3czx5qBHth4bo+wLymRdgyg2fwyXmepQk4xoF2yGgfn+1HSoq EzfEXi3cMwQxl7AD6ZrYx9p7Fp0QC9w9WU282Sq5NTXzpo+YTepNNwkND5IkzaOknlDl u0i3lk0jrdQNCT1e1RbAQIbt1OG+bQ7cBQ1ODQZPhQS78EVx5jYkLCUgvQN+zETITHBh EDAg== X-Gm-Message-State: AOAM530DvrrsyX1bbXIcWYL2ktAXOVMDhDl9UNGg0Y7hYT2ygq/7RWwo TUAAfUxXkvPXCWPig1hTI1Rc3N+oCz8= X-Google-Smtp-Source: ABdhPJx1wJUeVbcbbRzs/aIL97yuodHIbUZYSyP/oZ5LsV0EIRrpMVAzxdRrrF4J+LoT+KwJnSU7Wg== X-Received: by 2002:a1c:1fcf:: with SMTP id f198mr17745909wmf.66.1638566174778; Fri, 03 Dec 2021 13:16:14 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l11sm3461555wrp.61.2021.12.03.13.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 13:16:14 -0800 (PST) Message-Id: <0453237873422a3919200b3f641b7847d44f0efa.1638566166.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 21:16:05 +0000 Subject: [PATCH v5 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 --- 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' '