From patchwork Fri Mar 27 00:48:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461475 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 DF4E617D4 for ; Fri, 27 Mar 2020 00:49:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC8C220719 for ; Fri, 27 Mar 2020 00:49:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nYwSiIzt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbgC0AtG (ORCPT ); Thu, 26 Mar 2020 20:49:06 -0400 Received: from mail-wm1-f47.google.com ([209.85.128.47]:53178 "EHLO mail-wm1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbgC0AtG (ORCPT ); Thu, 26 Mar 2020 20:49:06 -0400 Received: by mail-wm1-f47.google.com with SMTP id z18so9819010wmk.2 for ; Thu, 26 Mar 2020 17:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1Ao+d/tKNKgUrYNtOhoOth8Mw9Bm9lN98qlt1FAbRb8=; b=nYwSiIztOZXPjJpdfjjSqcoyXjzD6YLsEp5IQIC928u/xWcqg6oxkZhDuEj0PcVXS9 AdsT4Sf42ZRUkV++WzouCHNozQFhMo0E1v5ye7L1b4v3fsWHuP0VrP6ZWfmbrI1nhH/s Wz+NOk6xtxSR7tgKjjiL1KewQT4RDtwFtKNUSMEfyNJPafyf6/pegNOT1okQfuN3PImc UUEcRvNYblYturA8tqFmNlRdOuqFBvEfkUAAQXsQcqLklIwrANKxioO+ShgiFczXaiKA 8V+CQHflVIJ0G9HwCz+90XjV4f73ChpuBTu8rZv+6TQ24u0z/rrvEXCzXhRTyVMqVCyD Ll7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1Ao+d/tKNKgUrYNtOhoOth8Mw9Bm9lN98qlt1FAbRb8=; b=k3o+HKvbZg4N9sjVHWQfv6liqPapnXJVr6RDK1DSUr8/aGQ48Hm+VPDvqUPjJT0Jnt 6K8NtzayZ8feTEUmPebuM3pxdnhl244/3ALMqelcGsqcpBwk604t5PGF6JVZRjgm8PK5 ANFpuNJqbgVO/3litK2GdbrEk+yIddTDgg+dcNrrys86abGZgufcyqd1bswn7q+xjplP f6Tzi+qEkPjMbLw8lGEOEBsnP/b82zWquxuJRZJ3segbJfcnOsTOA84NvkLJmV2ghFka 8vGtagkgj5/mLGfeUMI1/RvSrdxnoYnStMGTSZvv8buMpLQTsp635ONcQeCvsFUr54+S 9gEQ== X-Gm-Message-State: ANhLgQ0UJXLxzzw9fqd9XixQ+nDLt4y7K8eZcXXEyAx/q22lRnBy+hat ZZmRFdsSwZoquy0YfRtwFqqG3qGK X-Google-Smtp-Source: ADFU+vthYfErFwMwTIW7rX9nDWzPnIKKfxOSGnBCwJiMNXxgIxrjdLDK+3R0yamsOf08w3etO4QntQ== X-Received: by 2002:a1c:f213:: with SMTP id s19mr2606964wmc.116.1585270144923; Thu, 26 Mar 2020 17:49:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n186sm5425029wme.25.2020.03.26.17.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:04 -0700 (PDT) Message-Id: <1dc36eb33f7879f5553c2bb28c516022d040e12b.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:45 +0000 Subject: [PATCH v3 02/18] unpack-trees: remove unused error type Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren commit 08402b0409 ("merge-recursive: distinguish "removed" and "overwritten" messages", 2010-08-11) split ERROR_WOULD_LOSE_UNTRACKED into both ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN ERROR_WOULD_LOSE_UNTRACKED_REMOVED and also split ERROR_WOULD_LOSE_ORPHANED into both ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN ERROR_WOULD_LOSE_ORPHANED_REMOVED However, despite the split only three of these four types were used. ERROR_WOULD_LOSE_ORPHANED_REMOVED was not put into use when it was introduced and nothing else has used it in the intervening decade either. Remove it. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 4 ---- unpack-trees.h | 1 - 2 files changed, 5 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index 0d0eec0221e..f72a7a21f9c 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -49,8 +49,6 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { /* ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN */ "Working tree file '%s' would be overwritten by sparse checkout update.", - /* ERROR_WOULD_LOSE_ORPHANED_REMOVED */ - "Working tree file '%s' would be removed by sparse checkout update.", /* ERROR_WOULD_LOSE_SUBMODULE */ "Submodule '%s' cannot checkout new HEAD.", @@ -172,8 +170,6 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, _("Cannot update sparse checkout: the following entries are not up to date:\n%s"); msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] = _("The following working tree files would be overwritten by sparse checkout update:\n%s"); - msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] = - _("The following working tree files would be removed by sparse checkout update:\n%s"); msgs[ERROR_WOULD_LOSE_SUBMODULE] = _("Cannot update submodule:\n%s"); diff --git a/unpack-trees.h b/unpack-trees.h index ae1557fb804..6d7c7b6c2e0 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -24,7 +24,6 @@ enum unpack_trees_error_types { ERROR_BIND_OVERLAP, ERROR_SPARSE_NOT_UPTODATE_FILE, ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN, - ERROR_WOULD_LOSE_ORPHANED_REMOVED, ERROR_WOULD_LOSE_SUBMODULE, NB_UNPACK_TREES_ERROR_TYPES }; From patchwork Fri Mar 27 00:48:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461485 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 1CD3C161F for ; Fri, 27 Mar 2020 00:49:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F18C120719 for ; Fri, 27 Mar 2020 00:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MMQ1m1jG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727677AbgC0AtJ (ORCPT ); Thu, 26 Mar 2020 20:49:09 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38832 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgC0AtI (ORCPT ); Thu, 26 Mar 2020 20:49:08 -0400 Received: by mail-wr1-f68.google.com with SMTP id s1so9467956wrv.5 for ; Thu, 26 Mar 2020 17:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zt+2CXqAsbTAAMaUm+8IRelHfOj3odtzLDFgT1D3YRM=; b=MMQ1m1jGYvPY5pGuwInS6+pMvyWYJTrWUR3Pm2xgrtIPWos3vQxcUV7evvvFLW/Ton mvWPGqp8C2BSkqIXelMwEuu9GzIuDw6gUtnA/7tz55AC0KloKB05H5Omw5MWFKMN9P7F xC96aLGq9kkHpYTPsx9+iiqxst13xAbmU8cJZXnAKxeQSso+ywV4ZkP4bzKT9KK+z0hB VnQCKIr5iCBfXnmGOWONvwfKrhtZriPp1NjKJ0kzR0Xy13LTy1s3e/WcDFirhLhfdQQS QLkkP8iT9/NzA6IjzUyfJ+0gyjU/mz6VWYosxtwXfNC28fblsMaaS4srcfd0YMVDgcra lfXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zt+2CXqAsbTAAMaUm+8IRelHfOj3odtzLDFgT1D3YRM=; b=Fc4zvZT3UjWCAmCXaH25Ci/taY9kRAZz1D9OzoS+FOiZKqPwt39gmXon5ynoD5IqjZ VxQNGgykUygiWnUWWNyhJP4k5WTw9REE0biXlfX+RvV4AsDoOBffQoplAWI8nQE361Y0 EEiGI/3FsEBvxTXDpkrMpzoiTE7R9roqwlPkwjjpR4vdUD1FeUYjSG4bfmh+PiMVbIB4 Qh3Rt4MRBp2IrwuCYUob1qBSkyJQNXpoDcJZMJcN8kbD/NNJpLzXuJRgzPRtR8LjM4qC wj0omvm31HIghFs7+OEOXzzaT6qrODqqIImDawTx6F3uQr/gBbCzW8WSEQphH+glGj10 ywkA== X-Gm-Message-State: ANhLgQ2vSPu1S/9WriXpqNxKcB4I7JKsz2yhHckgefMg7YITUbSzHtQV swnsbFkTfGkSP2QpDFgYgscv+ZEX X-Google-Smtp-Source: ADFU+vu1VPxa5XFIHdPHev/2VfGWwQxY4jdY3uLoKvcFxC9lKqYyk/LeojazYNXPM1+9ierkx4++tw== X-Received: by 2002:adf:e8cc:: with SMTP id k12mr12413555wrn.144.1585270145669; Thu, 26 Mar 2020 17:49:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q3sm5693331wru.87.2020.03.26.17.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:05 -0700 (PDT) Message-Id: <97a95e91d8f2d71df59d7fa9911d8974d2199a38.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:46 +0000 Subject: [PATCH v3 03/18] unpack-trees: simplify verify_absent_sparse() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren verify_absent_sparse() was introduced in commit 08402b0409 ("merge-recursive: distinguish "removed" and "overwritten" messages", 2010-08-11), and has always had exactly one caller which always passes error_type == ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN. This function then checks whether error_type is this value, and if so, sets it instead to ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN. It has been nearly a decade and no other caller has been created, and no other value has ever been passed, so just pass the expected value to begin with. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index f72a7a21f9c..3af2e126abf 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -506,7 +506,7 @@ static int apply_sparse_checkout(struct index_state *istate, ce->ce_flags &= ~CE_UPDATE; } if (was_skip_worktree && !ce_skip_worktree(ce)) { - if (verify_absent_sparse(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) + if (verify_absent_sparse(ce, ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN, o)) return -1; ce->ce_flags |= CE_UPDATE; } @@ -2026,11 +2026,7 @@ static int verify_absent_sparse(const struct cache_entry *ce, enum unpack_trees_error_types error_type, struct unpack_trees_options *o) { - enum unpack_trees_error_types orphaned_error = error_type; - if (orphaned_error == ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN) - orphaned_error = ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN; - - return verify_absent_1(ce, orphaned_error, o); + return verify_absent_1(ce, error_type, o); } static int merged_entry(const struct cache_entry *ce, From patchwork Fri Mar 27 00:48:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461481 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 24850161F for ; Fri, 27 Mar 2020 00:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06B522074D for ; Fri, 27 Mar 2020 00:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KOF6exrq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727696AbgC0AtK (ORCPT ); Thu, 26 Mar 2020 20:49:10 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43433 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727612AbgC0AtJ (ORCPT ); Thu, 26 Mar 2020 20:49:09 -0400 Received: by mail-wr1-f67.google.com with SMTP id m11so3573673wrx.10 for ; Thu, 26 Mar 2020 17:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=cSY3A29VDuvvW7D6Nnb0e/FmTcYIDqSKYtNcN0V6bgA=; b=KOF6exrq3DivLx413UQB/XvRJ6KNjM1/tbxzYFMtADSVpc0Ia2MgwOpgNh3q75USup ew4QuBmHZb3lrWqRIqL6QdmqYuJrSEdXS9oZwNAtehqSA7gRT6sWmmfGhieBUTwNyzuc yfFltEHh7Q0iv/lNqAZe6amiqBTw2qyfIHkq3v03cBowICBf94DMaH+7KKWwXx2NTqag sbkP3fALBFmLbkX+drfQQvfYP5/zfOtxZshNbYHEw/JghL6va1o1vuDj9CQe06o405AK InpFUMvcKGLaa3bLmQHlnAGKkcZVdonaSNRilyBjzFlvHfQ0tobs1dneniQ49n20Uihx WY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=cSY3A29VDuvvW7D6Nnb0e/FmTcYIDqSKYtNcN0V6bgA=; b=iPmMwD4OuotFwzhntWT5W0R9NneaUgYWU5w2BOpyR+OgjnpamoRkb1Q6xg/1muN8tZ vatL874Ji2LlE/XoUulxWAzpdMObhYUj1Oak1WsaEx6VIGFZSPz0ucRY8VtP2G1DIjoO IbaEgd7WIjLXZ+b4VxetkqY2buTlPHt+FMCI/OMV7RvuZHCUaiXvvgK6xLGme1zBW1C+ PiNXWbmvkBA1+2PYB3CgeJFaV/ew/xHMPvtB38Kc+cDK16utapDeHzYb+ES9YQBXs4U3 GE3s1AdOZhb1m5a2UBz1qIitqsnzQJq0G2S9o4lDVGW9dMONYEgQA+tdzg2WsU8mF6ia snFg== X-Gm-Message-State: ANhLgQ1JakT0hQlGwNq3elnBj7Wd1f3Yb25bItkMgTI60rQVemCnL4ta PwTa7uu5mScsGAYpjwYOQypmnWXx X-Google-Smtp-Source: ADFU+vta3O2Hozw87DzcaVUQ71inpfyrpXLUevCZtpIoK1+3UxdxQcABImhD8zaBiv25dOgL1PYW5A== X-Received: by 2002:adf:eb51:: with SMTP id u17mr12895894wrn.29.1585270146376; Thu, 26 Mar 2020 17:49:06 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n2sm5516102wrr.62.2020.03.26.17.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:06 -0700 (PDT) Message-Id: <1ce5dbe9c68c6a5377bab22297b3c8d684d2b16c.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:47 +0000 Subject: [PATCH v3 04/18] unpack-trees: simplify pattern_list freeing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren commit e091228e17 ("sparse-checkout: update working directory in-process", 2019-11-21) allowed passing a pre-defined set of patterns to unpack_trees(). However, if o->pl was NULL, it would still read the existing patterns and use those. If those patterns were read into a data structure that was allocated, naturally they needed to be free'd. However, despite the same function being responsible for knowing about both the allocation and the free'ing, the logic for tracking whether to free the pattern_list was hoisted to an outer function with an additional flag in unpack_trees_options. Put the logic back in the relevant function and discard the now unnecessary flag. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 1 - unpack-trees.c | 6 ++++-- unpack-trees.h | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 740da4b6d54..d102a9697fd 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -122,7 +122,6 @@ static int update_working_directory(struct pattern_list *pl) o.dst_index = r->index; o.skip_sparse_checkout = 0; o.pl = pl; - o.keep_pattern_list = !!pl; resolve_undo_clear_index(r->index); setup_work_tree(); diff --git a/unpack-trees.c b/unpack-trees.c index 3af2e126abf..d2863fa0310 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1503,6 +1503,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options int i, ret; static struct cache_entry *dfc; struct pattern_list pl; + int free_pattern_list = 0; if (len > MAX_UNPACK_TREES) die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); @@ -1519,6 +1520,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options else o->pl = &pl; free(sparse); + free_pattern_list = 1; } memset(&o->result, 0, sizeof(o->result)); @@ -1686,9 +1688,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options o->src_index = NULL; done: - trace_performance_leave("unpack_trees"); - if (!o->keep_pattern_list) + if (free_pattern_list) clear_pattern_list(&pl); + trace_performance_leave("unpack_trees"); return ret; return_failed: diff --git a/unpack-trees.h b/unpack-trees.h index 6d7c7b6c2e0..d3516267f36 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -58,8 +58,7 @@ struct unpack_trees_options { quiet, exiting_early, show_all_errors, - dry_run, - keep_pattern_list; + dry_run; const char *prefix; int cache_bottom; struct dir_struct *dir; From patchwork Fri Mar 27 00:48:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461483 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 8772B17D4 for ; Fri, 27 Mar 2020 00:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69BDD2074D for ; Fri, 27 Mar 2020 00:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SpTq9zwE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727685AbgC0AtK (ORCPT ); Thu, 26 Mar 2020 20:49:10 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38834 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726067AbgC0AtJ (ORCPT ); Thu, 26 Mar 2020 20:49:09 -0400 Received: by mail-wr1-f68.google.com with SMTP id s1so9468009wrv.5 for ; Thu, 26 Mar 2020 17:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Qyv7zF5hcZg/DzLYC2a8W4SsgN0Hb1faAJoIvnhgBzs=; b=SpTq9zwENXZGjfUpms5YF/SNKRsfGAsk7WNCWNnlL6QcneFwadPViPdzh9IecOOH0C zPEIAxUJ9BTWQoIxRuO1i9teaBh49Vc3zm1/U3fUNCXzRZ6DhY1zDh2ayL1fBGE3184X XgBnz53ylut63dO5F+Fd/bbsjy/CArGa4E7fMOeaLjn5tGByCBesnyImogZqEa4eIChB vxlOZABc2NQqNC0elIMrrmrObwt/DI58u7Rf+PU9PqfZinzWmykAy5KvKrAjF1CdD6Ay /AAFlIZY45XxeMEOBMsyLhzgjqLc9+mGMyR2JHM+E0HyKTGxwTHkgU6BSfl0tCGyjnU/ IsPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Qyv7zF5hcZg/DzLYC2a8W4SsgN0Hb1faAJoIvnhgBzs=; b=HldndtXIYcKn3wgx3llLGO7EBn1ajmoPHLKvqolCpS89jlDQIWIc/2tbXyyEQJGxnJ Pd+gtS0f+/+fJ2CFptiKJCQDLiRklTfqbNk+TQQXRz5ciPS6RkQEE3rT+FwQWXSYh3IN WdaOivdSQOWfgLuGmOPUoSLwt5BWsPlmO8XHpEAjnZKb30aNTJiWkM7Pl3oWx1jh53uZ dQ/MmPTvmuH1qYELPQTPaCaRBBuTvrRMc+slY6798RRKVKdcjLyIsw9Rx3zA4iGTwpQL rfqgLPa8+PyAB/oAy+tGb3KkizdsFplFj3UMtBWEwpQfF2kxyNXLvJ4B3M7ABFFHoSq8 9hHA== X-Gm-Message-State: ANhLgQ3z2yDqyqiBb5pbfeSstC7tTUKQLWjq7TertavH+u3l+radqwAf V4GRNRYs6yNumswEvRIoJHYODVy4 X-Google-Smtp-Source: ADFU+vs+iwY9Jp4CX5EeRLPOyX8D0Fihx98QqQ2HpVXoXbi+b0QvnQ/ckWF+n1TB221jrasrmZFTnw== X-Received: by 2002:adf:ea84:: with SMTP id s4mr12835399wrm.392.1585270147109; Thu, 26 Mar 2020 17:49:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b11sm5890811wrq.26.2020.03.26.17.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:06 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:48 +0000 Subject: [PATCH v3 05/18] t1091: make some tests a little more defensive against failures Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- t/t1091-sparse-checkout-builtin.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 44a91205d60..8607a8e6d1a 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -278,6 +278,7 @@ test_expect_success 'cone mode: add parent path' ' ' test_expect_success 'revert to old sparse-checkout on bad update' ' + test_when_finished git -C repo sparse-checkout disable && test_when_finished git -C repo reset --hard && git -C repo sparse-checkout set deep && echo update >repo/deep/deeper2/a && @@ -328,6 +329,7 @@ test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' ' test_expect_success 'cone mode: set with core.ignoreCase=true' ' + rm repo/.git/info/sparse-checkout && git -C repo sparse-checkout init --cone && git -C repo -c core.ignoreCase=true sparse-checkout set folder1 && cat >expect <<-\EOF && From patchwork Fri Mar 27 00:48:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461479 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 1F669161F for ; Fri, 27 Mar 2020 00:49:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0080E20719 for ; Fri, 27 Mar 2020 00:49:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QPDE5ssl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727702AbgC0AtL (ORCPT ); Thu, 26 Mar 2020 20:49:11 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34993 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbgC0AtJ (ORCPT ); Thu, 26 Mar 2020 20:49:09 -0400 Received: by mail-wm1-f68.google.com with SMTP id m3so10606454wmi.0 for ; Thu, 26 Mar 2020 17:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=oRl/+uTmfJN6FxLa/jXKO0a4rPGDCzDcacd+tS7ExEU=; b=QPDE5sslJQdANtpEL1PoTPiO8McqVGvwXF+dpmxxUkeYD9A7ZVDmaq8FJVPAQo1k6r T5Ey/eaW/rdyDe3RLp1e1PuudZ52KJx/vuTKHTExUJ+VUCHWAiiyUX9jl4eZPo4zc/H7 GWYzr2taBiqjmR7+dIdcTEx3Qvp6TcHj8z6z70RzyFyxabNytMsj1KQ10Hpl9ohXVvOm pZolrTYsRjktcNZZ1kPXCG3qN+xMMbbZY0t6RqFGcR2/Wp/nMsoMV7gd6pE54Jpw13Pe thiw6t13b/u/cDmWejMs1YPZ80tyocURab3+6OFwRzKK9IA9zA8DSVm2bNeq/uvC7Wch 0xAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=oRl/+uTmfJN6FxLa/jXKO0a4rPGDCzDcacd+tS7ExEU=; b=RHhhXwhR3i77k3FZuipZw6TqDOSac6+/2U+QqUCIGRzsOEpL4yTUUPBkQ3gbRnU4cW NMd39OTG8swvtoM5dcv7gYIIWjb0+5Yh+QfbIbd0xBwuIoJbC0wcUGO8racoysR2Cd/U DTHhpBJnarFRusko1nJHFfejW8sZbV2qbwOwLaJVyUUkosSz8HLUZOEfI+GdZTGjaEQm rGB00TEc1l5qoDHPa0xl2/yuYUet4HNsUJn/IbmguOT7bh2H0RHmDQMHNVCsrLbqr2Oy SzSN1eymDXmzoHNbUdHtLWqKP2IK4zPJvmT97zehFUVRomQBRimMwnH0pGWm7C5jgETG ZL5w== X-Gm-Message-State: ANhLgQ3Ur5avv07SI36XRv4hmne7h+oTxCHbHP7y2MX3K1AlMUzqThm9 WlB3RS+zGBWQT08DWFdZzQ2mFozt X-Google-Smtp-Source: ADFU+vtpXiJWZbdiRdgGBl0efMek6MnjCR2FrDTBfMnP+VjLWkzKGYsV3HoH9Y+xWXYwMhYQNcAf6w== X-Received: by 2002:a05:600c:2283:: with SMTP id 3mr2499201wmf.157.1585270147937; Thu, 26 Mar 2020 17:49:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n124sm5461157wma.11.2020.03.26.17.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:07 -0700 (PDT) Message-Id: <555eedf538030b9c9560a2f9d3cbd0ad1db026d5.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:49 +0000 Subject: [PATCH v3 06/18] unpack-trees: allow check_updates() to work on a different index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren check_updates() previously assumed it was working on o->result. We want to use this function in combination with a different index_state, so take the intended index_state as a parameter. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index d2863fa0310..dde50047a82 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -353,12 +353,12 @@ static void report_collided_checkout(struct index_state *index) string_list_clear(&list, 0); } -static int check_updates(struct unpack_trees_options *o) +static int check_updates(struct unpack_trees_options *o, + struct index_state *index) { unsigned cnt = 0; int errs = 0; struct progress *progress; - struct index_state *index = &o->result; struct checkout state = CHECKOUT_INIT; int i; @@ -1665,7 +1665,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } } - ret = check_updates(o) ? (-2) : 0; + ret = check_updates(o, &o->result) ? (-2) : 0; if (o->dst_index) { move_index_extensions(&o->result, o->src_index); if (!ret) { From patchwork Fri Mar 27 00:48:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461487 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 20D8B161F for ; Fri, 27 Mar 2020 00:49:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02C9320719 for ; Fri, 27 Mar 2020 00:49:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NYlLjRAj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727714AbgC0AtN (ORCPT ); Thu, 26 Mar 2020 20:49:13 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33088 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727666AbgC0AtK (ORCPT ); Thu, 26 Mar 2020 20:49:10 -0400 Received: by mail-wm1-f68.google.com with SMTP id w25so6110291wmi.0 for ; Thu, 26 Mar 2020 17:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=iD+URmCch3dlpKunooFhgiXiFTPoxlpEZUdcXCIDs+s=; b=NYlLjRAjlns1Hlx2RSPy3NUa20Jl8SydbsD5Uz1xepr0MjGz76Ajgz1lAeOEIrOeON VTI31OyXqZf3Yvdc9khb7VPbXkybQNmt9zCpnnqBRm5kAk0BvWHk6iq+HheW1/zpmxZf DtxFinI5CIxXC+nm6a/zOM+pwxKuRiuVcze1No3B3tYs+3V0fN/ovqXxbi678QDbF56w StL/8bvmsjtwoS0VAo6MzIt/rJCmmrlgPZpIF0Ra1O2HPbX0zgUzSlWdIrY5TvOX1JEM LD45mWn0Zr6kDHNbPEgdcuUyjTma9fPdcUy71XSXUndVmcJIYQh8kCX7X/bc1LlPt9M5 FuAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=iD+URmCch3dlpKunooFhgiXiFTPoxlpEZUdcXCIDs+s=; b=aWv0fkFzOhXV9aqqxxNpAOjHF63SMUDr0jo+cJxC9rs37OFR5tcSet3YOx7mMf527m qjUluEj4/MjAoQ4PLbXZjqhawr5ELavCkbxJ1jwaYNV2gwQa6CHuCrTkt+N0znd0k6aM 4BTozWvs9jj3REjJB20Oz+9fV+7uQOGHsOFH4COY3qf4GA79d99Sr1vjNdkW5A4NdXjt J+UjRudslG0E1uZo64aCRXtyHMAyZNFfOjGGUqomLM7prBl8ffW/F8TR/gdAiImK9Ax0 QLzVzz5Opz0j+LS61nfaRHkJjq/zue6the5Ka+O5KUi7g6fk5K9sE2hhPQ6oTwCxKoXV pccQ== X-Gm-Message-State: ANhLgQ3nEcHUhTYFpmaP+GR7QvksR0CVQ7kQzCgmuHNnx8hEkrnGyAQC ZncOs/KsVQss58DVOPy8icQfmT76 X-Google-Smtp-Source: ADFU+vtLawSlUE9UCmud61Az3T6clXQA4RTdY2qOuNg/CUKQRAukjvVaL5DCPv3RQacyuXyh9L7Gag== X-Received: by 2002:a1c:6608:: with SMTP id a8mr2519184wmc.113.1585270148664; Thu, 26 Mar 2020 17:49:08 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a14sm6026647wrv.76.2020.03.26.17.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:08 -0700 (PDT) Message-Id: <10ec70fa697e060ddc65c1245f73e37612edefc2.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:50 +0000 Subject: [PATCH v3 07/18] unpack-trees: do not mark a dirty path with SKIP_WORKTREE Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren If a path is dirty, removing from the working tree risks losing data. As such, we want to make sure any such path is not marked with SKIP_WORKTREE. While the current callers of this code detect this case and re-populate with a previous set of sparsity patterns, we want to allow some paths to be marked with SKIP_WORKTREE while others are left unmarked without it being considered an error. The reason this shouldn't be considered an error is that SKIP_WORKTREE has always been an advisory-only setting; merge and rebase for example were free to materialize paths and clear the SKIP_WORKTREE bit in order to accomplish their work even though they kept the SKIP_WORKTREE bit set for other paths. Leaving dirty working files in the working tree is thus a natural extension of what we have already been doing. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unpack-trees.c b/unpack-trees.c index dde50047a82..e8e794880ab 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -500,8 +500,11 @@ static int apply_sparse_checkout(struct index_state *istate, * also stat info may have lost after merged_entry() so calling * verify_uptodate() again may fail */ - if (!(ce->ce_flags & CE_UPDATE) && verify_uptodate_sparse(ce, o)) + if (!(ce->ce_flags & CE_UPDATE) && + verify_uptodate_sparse(ce, o)) { + ce->ce_flags &= ~CE_SKIP_WORKTREE; return -1; + } ce->ce_flags |= CE_WT_REMOVE; ce->ce_flags &= ~CE_UPDATE; } From patchwork Fri Mar 27 00:48:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461489 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 50478161F for ; Fri, 27 Mar 2020 00:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31CEE2074D for ; Fri, 27 Mar 2020 00:49:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="togpbffl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727725AbgC0AtO (ORCPT ); Thu, 26 Mar 2020 20:49:14 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44548 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbgC0AtM (ORCPT ); Thu, 26 Mar 2020 20:49:12 -0400 Received: by mail-wr1-f65.google.com with SMTP id m17so9414117wrw.11 for ; Thu, 26 Mar 2020 17:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=yBv5qNEPdqGZgAGt3McRF7qBENlsktMTkf1A68Bjr4I=; b=togpbfflm0wC5SOT/8N1xZ1+mfmFySwiyIwLqlXUrgvzRLkHRKPpGZmk4U6Hn+Z1TW gVC/NaqkWiK2FMxEKXLthDFHN++LwMxRY62bbuYGlSySDvYrAJyVvOsXC+xgULtyuBpO 9XyMyVT97fzGynyW+GOGrQQCPvyWrJtxOtynrkWxA0TGQLd44TD/wY2oldRZoG67HXwa igfjqonZr3AhJMCEOYI9eRy/dzl4KWygSo8WmpianIKQ/DTaAWuH04WyuhsCm3f6vmSV 3AfxTpuMmhyb5WooWBXHCz2YQo3gxn6WXUjkC3vEtU1zyDiLOsxPkJZ2q30fIwVi1pU3 cPUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=yBv5qNEPdqGZgAGt3McRF7qBENlsktMTkf1A68Bjr4I=; b=l+F0tb4m9G5f6iGHTyxaaxwlf5aB6HfurPcc39142oLf9fkLGbmuMV6WFsqmuO5bGc bWzPY2EH9LIWgjpCcFmsmZJQSuYs+2tSFZREmS9kU5963QiySlRKDd1iuh0ARYgFur3p PpKQNpW4Os7Jjdmd/dilAfEDRNy2kxEtjNdfJkzSrU5jXvZ6iSGj9B5TpaYlJmCu1q2E CUmtJk40JRqL8+xtPoYZXsiOltAHBz9oqkd84l4eZyWPbqZ4v+wtAdoY0bFom7rCcOBU Gk/pF/Wwcv8BGooDXpOvj3YTcl9PCdTE963Gv0U/InCf0+s2ro73uQXOZCPxuvY8wAx5 lYBg== X-Gm-Message-State: ANhLgQ15WlO8iam2+ZWMDmsBPEF8WDQUR4wbj3FFrnG3FUu7hCZX08eE ksW0FU23aROozVMvt0YMaYB1zB04 X-Google-Smtp-Source: ADFU+vtJq/qd12NUqSS+OZ0LJBOlFSabBQ9SwbGvCd6OyyAsS+C57mEsFdatKvik8az8N7nI63RAGg== X-Received: by 2002:adf:9dca:: with SMTP id q10mr11823379wre.11.1585270149392; Thu, 26 Mar 2020 17:49:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e1sm6078419wrx.90.2020.03.26.17.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:09 -0700 (PDT) Message-Id: <8ed2f4e49ed80626292013f55dc5164f0eaad98b.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:51 +0000 Subject: [PATCH v3 08/18] unpack-trees: pull sparse-checkout pattern reading into a new function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Create a populate_from_existing_patterns() function for reading the path_patterns from $GIT_DIR/info/sparse-checkout so that we can re-use it elsewhere. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index e8e794880ab..4733e7eaf89 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1492,6 +1492,20 @@ static void mark_new_skip_worktree(struct pattern_list *pl, clear_ce_flags(istate, select_flag, skip_wt_flag, pl, show_progress); } +static void populate_from_existing_patterns(struct unpack_trees_options *o, + struct pattern_list *pl) +{ + char *sparse = git_pathdup("info/sparse-checkout"); + + pl->use_cone_patterns = core_sparse_checkout_cone; + if (add_patterns_from_file_to_list(sparse, "", 0, pl, NULL) < 0) + o->skip_sparse_checkout = 1; + else + o->pl = pl; + free(sparse); +} + + static int verify_absent(const struct cache_entry *, enum unpack_trees_error_types, struct unpack_trees_options *); @@ -1512,18 +1526,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); trace_performance_enter(); - memset(&pl, 0, sizeof(pl)); if (!core_apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; if (!o->skip_sparse_checkout && !o->pl) { - char *sparse = git_pathdup("info/sparse-checkout"); - pl.use_cone_patterns = core_sparse_checkout_cone; - if (add_patterns_from_file_to_list(sparse, "", 0, &pl, NULL) < 0) - o->skip_sparse_checkout = 1; - else - o->pl = &pl; - free(sparse); + memset(&pl, 0, sizeof(pl)); free_pattern_list = 1; + populate_from_existing_patterns(o, &pl); } memset(&o->result, 0, sizeof(o->result)); From patchwork Fri Mar 27 00:48:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461491 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 F06E917D4 for ; Fri, 27 Mar 2020 00:49:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9450206E6 for ; Fri, 27 Mar 2020 00:49:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ItWyjDUx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727729AbgC0AtQ (ORCPT ); Thu, 26 Mar 2020 20:49:16 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53031 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727703AbgC0AtM (ORCPT ); Thu, 26 Mar 2020 20:49:12 -0400 Received: by mail-wm1-f67.google.com with SMTP id z18so9819219wmk.2 for ; Thu, 26 Mar 2020 17:49:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ds+B2/zRCxUQ8qA+wVd6G4oQ9CD/PVmlzJAwt9YJ1hc=; b=ItWyjDUxGcJRyTnTwu8Gx8IRw2Z/mZuZF8zYLtroLon0vOwnu7EkGyHXYH2m7zhTss 2x7TnYrQTvTJ6QV4yGLFocp62pHxPd/B9X8HAbGf8h3h/Jmjd6gyPfq/8F7ih2L998gj y+x2ujQzk0DIo8Al9PpEUDCGSXVUX89/e+i9oB90PZWAAaqS6KNDwx9Tr2aeMzA/zqqo zl7Jo/M16TGfgO7/d/CbrZPFa165xS8uVCUltpc5QT3f9/CeZb3MBKD5kaLbgcyZnEZV fSkfZIFeB6L8BQecXW8Nk2c2f9eILInLBVJEdkP+rS2+pA57unnqvcjsMJenPJ+1V0CV eX9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ds+B2/zRCxUQ8qA+wVd6G4oQ9CD/PVmlzJAwt9YJ1hc=; b=ggWJbVZoUrTSJmvSfKDlsFFHw5h/tuLwIygQzgFwWg/+0FEmKPKOL3wTE3rMhAVVZU saH+z3O/ca/WUr4NXSzFKDYmDSY4oqTuLMM0EN2n38teycQOV7JxWlJIvsK/nOg1Enuu DLtu4Mlj/Vd3Jr/0xiqv445ysIis7lNhrL7f2v0hdON8zaGKXS6nhtT9KQ1Q943EQ/4Q 8aXuftnxNcACqqo35TUw3Lk6u0mKuZrT10fI3NIGzmj5OgCMFQjjFJrLtj2NaLjX5tEZ XwRTa++RFk5zbfLoMHkiWuIqwgXEQbL9UmxWym9mL0N9oI8eNLfk+1QXJcyh3auC7yrX vdLQ== X-Gm-Message-State: ANhLgQ25Cz6YzOC/eMDvUJU73ha2d9MCbtahYMxMLH8EVii8oUjuBpyo wZmJi8LszoJg1Plw+I3VzosGhIZ1 X-Google-Smtp-Source: ADFU+vtCgsozCFb3xYbeKE+rvRtil/pWvNReGtNp9kicCG+/nyPRXc4ZHQKWSK2zayBPToVXGm/xaQ== X-Received: by 2002:a1c:f205:: with SMTP id s5mr2592471wmc.101.1585270150358; Thu, 26 Mar 2020 17:49:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n2sm5516292wrr.62.2020.03.26.17.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:10 -0700 (PDT) Message-Id: <3a1f084641eb47515b5a41ed4409a36128913309.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:52 +0000 Subject: [PATCH v3 09/18] unpack-trees: add a new update_sparsity() function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Previously, the only way to update the SKIP_WORKTREE bits for various paths was invoking `git read-tree -mu HEAD` or calling the same code that this codepath invoked. This however had a number of problems if the index or working directory were not clean. First, let's consider the case: Flipping SKIP_WORKTREE -> !SKIP_WORKTREE (materializing files) If the working tree was clean this was fine, but if there were files or directories or symlinks or whatever already present at the given path then the operation would abort with an error. Let's label this case for later discussion: A) There is an untracked path in the way Now let's consider the opposite case: Flipping !SKIP_WORKTREE -> SKIP_WORKTREE (removing files) If the index and working tree was clean this was fine, but if there were any unclean paths we would run into problems. There are three different cases to consider: B) The path is unmerged C) The path has unstaged changes D) The path has staged changes (differs from HEAD) If any path fell into case B or C, then the whole operation would be aborted with an error. With sparse-checkout, the whole operation would be aborted for case D as well, but for its predecessor of using `git read-tree -mu HEAD` directly, any paths that fell into case D would be removed from the working copy and the index entry for that path would be reset to match HEAD -- which looks and feels like data loss to users (only a few are even aware to ask whether it can be recovered, and even then it requires walking through loose objects trying to match up the right ones). Refusing to remove files that have unsaved user changes is good, but refusing to work on any other paths is very problematic for users. If the user is in the middle of a rebase or has made modifications to files that bring in more dependencies, then for their build to work they need to update the sparse paths. This logic has been preventing them from doing so. Sometimes in response, the user will stage the files and re-try, to no avail with sparse-checkout or to the horror of losing their changes if they are using its predecessor of `git read-tree -mu HEAD`. Add a new update_sparsity() function which will not error out in any of these cases but behaves as follows for the special cases: A) Leave the file in the working copy alone, clear the SKIP_WORKTREE bit, and print a warning (thus leaving the path in a state where status will report the file as modified, which seems logical). B) Do NOT mark this path as SKIP_WORKTREE, and leave it as unmerged. C) Do NOT mark this path as SKIP_WORKTREE and print a warning about the dirty path. D) Mark the path as SKIP_WORKTREE, but do not revert the version stored in the index to match HEAD; leave the contents alone. I tried a different behavior for A (leave the SKIP_WORKTREE bit set), but found it very surprising and counter-intuitive (e.g. the user sees it is present along with all the other files in that directory, tries to stage it, but git add ignores it since the SKIP_WORKTREE bit is set). A & C seem like optimal behavior to me. B may be as well, though I wonder if printing a warning would be an improvement. Some might be slightly surprised by D at first, but given that it does the right thing with `git commit` and even `git commit -a` (`git add` ignores entries that are marked SKIP_WORKTREE and thus doesn't delete them, and `commit -a` is similar), it seems logical to me. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ unpack-trees.h | 9 ++++++ 2 files changed, 86 insertions(+) diff --git a/unpack-trees.c b/unpack-trees.c index 4733e7eaf89..a5bc0a3a16d 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1714,6 +1714,83 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options goto done; } +/* + * Update SKIP_WORKTREE bits according to sparsity patterns, and update + * working directory to match. + * + * CE_NEW_SKIP_WORKTREE is used internally. + */ +enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) +{ + enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS; + struct pattern_list pl; + int i, empty_worktree; + unsigned old_show_all_errors; + int free_pattern_list = 0; + + old_show_all_errors = o->show_all_errors; + o->show_all_errors = 1; + + /* Sanity checks */ + if (!o->update || o->index_only || o->skip_sparse_checkout) + BUG("update_sparsity() is for reflecting sparsity patterns in working directory"); + if (o->src_index != o->dst_index || o->fn) + BUG("update_sparsity() called wrong"); + + trace_performance_enter(); + + /* If we weren't given patterns, use the recorded ones */ + if (!o->pl) { + memset(&pl, 0, sizeof(pl)); + free_pattern_list = 1; + populate_from_existing_patterns(o, &pl); + if (o->skip_sparse_checkout) + goto skip_sparse_checkout; + } + + /* Set NEW_SKIP_WORKTREE on existing entries. */ + mark_all_ce_unused(o->src_index); + mark_new_skip_worktree(o->pl, o->src_index, 0, + CE_NEW_SKIP_WORKTREE, o->verbose_update); + + /* Then loop over entries and update/remove as needed */ + ret = UPDATE_SPARSITY_SUCCESS; + empty_worktree = 1; + for (i = 0; i < o->src_index->cache_nr; i++) { + struct cache_entry *ce = o->src_index->cache[i]; + + if (apply_sparse_checkout(o->src_index, ce, o)) + ret = UPDATE_SPARSITY_WARNINGS; + + if (!ce_skip_worktree(ce)) + empty_worktree = 0; + } + + /* + * Sparse checkout is meant to narrow down checkout area + * but it does not make sense to narrow down to empty working + * tree. This is usually a mistake in sparse checkout rules. + * Do not allow users to do that. + */ + if (o->src_index->cache_nr && empty_worktree) { + unpack_failed(o, "Sparse checkout leaves no entry on working directory"); + ret = UPDATE_SPARSITY_INDEX_UPDATE_FAILURES; + goto done; + } + +skip_sparse_checkout: + if (check_updates(o, o->src_index)) + ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; + +done: + display_error_msgs(o); + o->show_all_errors = old_show_all_errors; + if (free_pattern_list) + clear_pattern_list(&pl); + trace_performance_leave("update_sparsity"); + return ret; +} + /* Here come the merge functions */ static int reject_merge(const struct cache_entry *ce, diff --git a/unpack-trees.h b/unpack-trees.h index d3516267f36..5cf41ef5b53 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -88,6 +88,15 @@ struct unpack_trees_options { int unpack_trees(unsigned n, struct tree_desc *t, struct unpack_trees_options *options); +enum update_sparsity_result { + UPDATE_SPARSITY_SUCCESS = 0, + UPDATE_SPARSITY_WARNINGS = 1, + UPDATE_SPARSITY_INDEX_UPDATE_FAILURES = -1, + UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2 +}; + +enum update_sparsity_result update_sparsity(struct unpack_trees_options *options); + int verify_uptodate(const struct cache_entry *ce, struct unpack_trees_options *o); From patchwork Fri Mar 27 00:48:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461493 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 F26B217D4 for ; Fri, 27 Mar 2020 00:49:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA9F72074D for ; Fri, 27 Mar 2020 00:49:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mWANxgG3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbgC0AtS (ORCPT ); Thu, 26 Mar 2020 20:49:18 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55743 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbgC0AtN (ORCPT ); Thu, 26 Mar 2020 20:49:13 -0400 Received: by mail-wm1-f67.google.com with SMTP id z5so9796990wml.5 for ; Thu, 26 Mar 2020 17:49:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Ft+lD/pmj9/I+0sLX5XALEw9YiuI86o5omHSTW9DEQ4=; b=mWANxgG3o63g42leRGwPHiCNEwGJ3HdUu6yYsbay3uAe2iULh8T3b2z/asw/SVRkVC UzhBrJlajcU4clJOFbwwbDlCeAOn440n2yMKHTxh6aS5pGg7xXd/lO4UYi4Z+q9FzdS2 ZFf3pt7NBQT2gfJgrBaOvhFLa4VIHf/EU0FFh4Gh844mEKOTC0OXkgQ+bidEpVQqoXAM x8oz5lPl57OYhaH9M1hYT7k4hienn5x1EFjDnGxCXHe60VCWI9HSr07qnrqERmDglK3z AtAI+bPe7KVDhshaE4o1vxfG1aWoDBdOkwMPcznnRO2H/2XICAJQBoxOF/zl33IFctjP +nTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Ft+lD/pmj9/I+0sLX5XALEw9YiuI86o5omHSTW9DEQ4=; b=uDJP/kXYw3X/ZIM0r/SwFiaqaS7Ektk2x7XWPkGNLvFwQygNzTDspHS/m0U00xrdx9 2RZjJULkk3jwM7e1/xE0XoErBYtT3NhVEiSzOXyMG7bSOGQYdUVrxWXFV3aJYYFgXb0L Bhxo9i5egF9hJrg24UqFJwfMglHNTdlCvpxfI/JxMxR7R3eBdUdQ8oU6SFv6GnISGmWV P5jo4Jdhxa/rqZfZMSxXjECQCeuXcMkD+gAsM9QerYnYVY7kNEXv9szlQ1oc4/viUthq 9d618iSpGTxs1lpG5Nm63JtC+tqVJeCZgfLOIUwVqXv1F8dv763uRY6j3kCkgPsJH2oW pRcg== X-Gm-Message-State: ANhLgQ2byNAJVMuToUlYmM+kphAiSrHH+Zp9uYcAvYm9a4PHnpDBHexT 0QAQ8hBDKFUbPNBskMbbHkvQCew9 X-Google-Smtp-Source: ADFU+vs6glfSAayUdaHd0Wcc1Ty0EnjCeWBvQCxy01Ifm156ky7Zk9Bb3bRgQLCAZ0PnbsKr9Ph0gg== X-Received: by 2002:a7b:c004:: with SMTP id c4mr2585571wmb.108.1585270150959; Thu, 26 Mar 2020 17:49:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g128sm5947174wmf.27.2020.03.26.17.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:10 -0700 (PDT) Message-Id: <9040ac97175a8a5e525285b5c0ff41060621a72e.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:53 +0000 Subject: [PATCH v3 10/18] sparse-checkout: use new update_sparsity() function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Remove the equivalent of 'git read-tree -mu HEAD' in the sparse-checkout codepaths for setting the SKIP_WORKTREE bits and instead use the new update_sparsity() function. Note that when an issue is hit, the error message splits 'error' and 'Cannot update sparse checkout' on separate lines. For now, we use two greps to find both pieces of the error message but subsequent commits will clean up the messages reported to the user. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 40 ++++++++---------------------- t/t1091-sparse-checkout-builtin.sh | 39 +++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index d102a9697fd..a55c60d7594 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -94,49 +94,35 @@ static int sparse_checkout_list(int argc, const char **argv) static int update_working_directory(struct pattern_list *pl) { - int result = 0; + enum update_sparsity_result result; struct unpack_trees_options o; struct lock_file lock_file = LOCK_INIT; - struct object_id oid; - struct tree *tree; - struct tree_desc t; struct repository *r = the_repository; - if (repo_read_index_unmerged(r)) - die(_("you need to resolve your current index first")); - - if (get_oid("HEAD", &oid)) - return 0; - - tree = parse_tree_indirect(&oid); - parse_tree(tree); - init_tree_desc(&t, tree->buffer, tree->size); - memset(&o, 0, sizeof(o)); o.verbose_update = isatty(2); - o.merge = 1; o.update = 1; - o.fn = oneway_merge; o.head_idx = -1; o.src_index = r->index; o.dst_index = r->index; o.skip_sparse_checkout = 0; o.pl = pl; - resolve_undo_clear_index(r->index); setup_work_tree(); - cache_tree_free(&r->index->cache_tree); - repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR); - core_apply_sparse_checkout = 1; - result = unpack_trees(1, &t, &o); + result = update_sparsity(&o); - if (!result) { - prime_cache_tree(r, r->index, tree); + if (result == UPDATE_SPARSITY_WARNINGS) + /* + * We don't do any special handling of warnings from untracked + * files in the way or dirty entries that can't be removed. + */ + result = UPDATE_SPARSITY_SUCCESS; + if (result == UPDATE_SPARSITY_SUCCESS) write_locked_index(r->index, &lock_file, COMMIT_LOCK); - } else + else rollback_lock_file(&lock_file); return result; @@ -303,8 +289,6 @@ static int sparse_checkout_init(int argc, const char **argv) }; repo_read_index(the_repository); - require_clean_work_tree(the_repository, - N_("initialize sparse-checkout"), NULL, 1, 0); argc = parse_options(argc, argv, NULL, builtin_sparse_checkout_init_options, @@ -559,8 +543,6 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix, }; repo_read_index(the_repository); - require_clean_work_tree(the_repository, - N_("set sparse-checkout patterns"), NULL, 1, 0); argc = parse_options(argc, argv, prefix, builtin_sparse_checkout_set_options, @@ -576,8 +558,6 @@ static int sparse_checkout_disable(int argc, const char **argv) struct strbuf match_all = STRBUF_INIT; repo_read_index(the_repository); - require_clean_work_tree(the_repository, - N_("disable sparse-checkout"), NULL, 1, 0); memset(&pl, 0, sizeof(pl)); hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 8607a8e6d1a..a991e0a80d5 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -277,16 +277,23 @@ test_expect_success 'cone mode: add parent path' ' check_files repo a deep folder1 ' -test_expect_success 'revert to old sparse-checkout on bad update' ' +test_expect_success 'not-up-to-date does not block rest of sparsification' ' test_when_finished git -C repo sparse-checkout disable && test_when_finished git -C repo reset --hard && git -C repo sparse-checkout set deep && + echo update >repo/deep/deeper2/a && cp repo/.git/info/sparse-checkout expect && - test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err && - test_i18ngrep "cannot set sparse-checkout patterns" err && - test_cmp repo/.git/info/sparse-checkout expect && - check_files repo/deep a deeper1 deeper2 + test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect && + + git -C repo sparse-checkout set deep/deeper1 2>err && + + test_i18ngrep "Cannot update sparse checkout" err && + test_cmp expect repo/.git/info/sparse-checkout && + check_files repo/deep a deeper1 deeper2 && + check_files repo/deep/deeper1 a deepest && + check_files repo/deep/deeper1/deepest a && + check_files repo/deep/deeper2 a ' test_expect_success 'revert to old sparse-checkout on empty update' ' @@ -316,16 +323,28 @@ test_expect_success '.gitignore should not warn about cone mode' ' test_i18ngrep ! "disabling cone patterns" err ' -test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' ' +test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' ' git clone repo dirty && echo dirty >dirty/folder1/a && - test_must_fail git -C dirty sparse-checkout init && - test_must_fail git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && - test_must_fail git -C dirty sparse-checkout disable && + + git -C dirty sparse-checkout init 2>err && + test_i18ngrep "error" err && + test_i18ngrep "Cannot update sparse checkout" err && + + git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && + test_i18ngrep "error" err && + test_i18ngrep "Cannot update sparse checkout" err && + test_path_is_file dirty/folder1/a && + + git -C dirty sparse-checkout disable 2>err && + test_must_be_empty err && + git -C dirty reset --hard && git -C dirty sparse-checkout init && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && - git -C dirty sparse-checkout disable + test_path_is_missing dirty/folder1/a && + git -C dirty sparse-checkout disable && + test_path_is_file dirty/folder1/a ' test_expect_success 'cone mode: set with core.ignoreCase=true' ' From patchwork Fri Mar 27 00:48:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461495 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 EBCBE161F for ; Fri, 27 Mar 2020 00:49:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDF622074D for ; Fri, 27 Mar 2020 00:49:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="riO6IS1F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727750AbgC0AtS (ORCPT ); Thu, 26 Mar 2020 20:49:18 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51789 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727705AbgC0AtO (ORCPT ); Thu, 26 Mar 2020 20:49:14 -0400 Received: by mail-wm1-f65.google.com with SMTP id c187so9836098wme.1 for ; Thu, 26 Mar 2020 17:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=9VVyl+Vdnkvmj6zrKAQbeNDIBw+QaEFYlwMoweYT/mY=; b=riO6IS1FX3D28lk6CSw1H4dD2c65R+5SglAUfpEOLssEpu9oIiEGaHYTsg6ZdqmxvV 1cWsoRANqzXkdsfWvYFIl9r8q7XAEtburqeTKAyfSe8FSzduAOkzr5dk4nhB7wVDQWLa PN2OEWrTBAmkcwzSu1u0YvazrRdcF/EOe5asmNc0M+AUkXlx58MpcujsQ2AuqLNYXmmV UQ1fu87EBW+8ejRfo0q8CYvyc/c+gRBYsyW4zdz4vFWVBqm/3DxhHF6b1PVcJaGcBLkT b536BSXeksAIE7B6J5RmMytoB2D53TCrc2FkND/7swpknRgrS+WG80fhGcAuguqgtT8p hLPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=9VVyl+Vdnkvmj6zrKAQbeNDIBw+QaEFYlwMoweYT/mY=; b=DvPRLh5WIRUCBhfvanYejJx78uC5RFUd2SlodfI1xzuGlY2Eh3wsI57b9OcfyxH28Y vgJwhRBhvFbUtrV4OZMby+iEiKdS3Om3UebVuphrwLfIcZmYcklUAYHLDnRTLuXc8utm 3i9v1Cmeu3WCl0F0qK70AtHzXr7hLDxa0nY4O3PJTvH8z3FS7aZaE1RXtEs9kxl5m0hi WTrijAKdzi+Y6VZFGtkqKnLzO0XfJnW15tZdN916a9+d6q+QUvpHjycpk72tqjWHwUzM N4E8StSoosiuIIpejviF4mAXoANbKhuLOBGYA+5tEcYTkYxwWsi+3+YRqWVG4oylHWCg P9MQ== X-Gm-Message-State: ANhLgQ1gQndA8yLZ1sIqaAsLYQq6qG0HdrlV45xSv027Jnt/i+hoVCrY /7xKKvKFgobIME5eK2eMAslc3ACY X-Google-Smtp-Source: ADFU+vvhwitDrvKWhkpAFYeJUvzAaUm4zF0lM79TP2Gn1z2zb6BAJtf3KivVZQLQiNug4J46hdL5xA== X-Received: by 2002:a1c:b356:: with SMTP id c83mr2814428wmf.10.1585270151896; Thu, 26 Mar 2020 17:49:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k84sm5947629wmk.2.2020.03.26.17.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:11 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:54 +0000 Subject: [PATCH v3 11/18] sparse-checkout: use improved unpack_trees porcelain messages Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren setup_unpack_trees_porcelain() provides much improved error/warning messages; instead of a message that assumes that there is only one path with a given problem despite being used by code that intentionally is grouping and showing errors together, it uses a message designed to be used with groups of paths. For example, this transforms error: Entry ' folder1/a folder2/a ' not uptodate. Cannot update sparse checkout. into error: Cannot update sparse checkout: the following entries are not up to date: folder1/a folder2/a In the past the suboptimal messages were never actually triggered because we would error out if the working directory wasn't clean before we even called unpack_trees(). The previous commit changed that, though, so let's use the better error messages. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 2 ++ t/t1091-sparse-checkout-builtin.sh | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index a55c60d7594..aa81199f85d 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -112,7 +112,9 @@ static int update_working_directory(struct pattern_list *pl) repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR); + setup_unpack_trees_porcelain(&o, "sparse-checkout"); result = update_sparsity(&o); + clear_unpack_trees_porcelain(&o); if (result == UPDATE_SPARSITY_WARNINGS) /* diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index a991e0a80d5..9bc65d32f07 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -328,12 +328,10 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' echo dirty >dirty/folder1/a && git -C dirty sparse-checkout init 2>err && - test_i18ngrep "error" err && - test_i18ngrep "Cannot update sparse checkout" err && + test_i18ngrep "error.*Cannot update sparse checkout" err && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && - test_i18ngrep "error" err && - test_i18ngrep "Cannot update sparse checkout" err && + test_i18ngrep "error.*Cannot update sparse checkout" err && test_path_is_file dirty/folder1/a && git -C dirty sparse-checkout disable 2>err && From patchwork Fri Mar 27 00:48:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461509 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 06EE7161F for ; Fri, 27 Mar 2020 00:49:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDEDC2074D for ; Fri, 27 Mar 2020 00:49:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="duX2OsKj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727755AbgC0AtX (ORCPT ); Thu, 26 Mar 2020 20:49:23 -0400 Received: from mail-wr1-f53.google.com ([209.85.221.53]:36668 "EHLO mail-wr1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727719AbgC0AtP (ORCPT ); Thu, 26 Mar 2020 20:49:15 -0400 Received: by mail-wr1-f53.google.com with SMTP id 31so9474204wrs.3 for ; Thu, 26 Mar 2020 17:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=diEoLJ+RCZcUMznOcM44HHVtmUhP2+nSzdW3yYAozHw=; b=duX2OsKjDuzbQixs7ksuCUTlIV+PcKwDBZB8Fm73RvaFWWAKLoMJZMoFMvyLyw26wS 63YiZVUJT1Hj4oy413slDjfKPqeF7+WG4W5pmOjS1SLNrLf5qJDhzBsRHebJ8vcCCQ4R n6vUUBkRH9ITmVhgB0tC8kMkBupn7FX5R+pzQuXg292DPIWAh/+9/Z/zqTQbY4faeqEu 9R2t7myGZk500n9aBk489LJqYlWwGL2QLVwo91UYaOtYsQotLuN5GnF/f/EYh/zqIInU HIK2+p01G2UNEXUjjlLku6ByBgIoIgRcbFJx7umrVnVo2GhV4i+iOxGoixzVJdleAaPu i6MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=diEoLJ+RCZcUMznOcM44HHVtmUhP2+nSzdW3yYAozHw=; b=BlciutAnNxCwqWTbo0zpMy3hMrY49KaifZMjqQnB7lf9OH9AqaDGujZbmyWLmmSnKN 1BikIptffcaeMM3Hi6BNaxu9YJDS2VJermlyfewWQE7p3rf/wBX1aX1IG/4pa9CJkA7h X5w5Pqb1sHRs97MFEUu+TrFuyvgnOicZs5WjjCIplmRFIFFlorzJakBTgtqpF17xT/Ra ixQzIzHSBo2W1FWBZ7AZSNl9Lp8GC+/pk6nDvYDDpu9TcnFtYPX48uA/y/ykl3AlXBW6 NrXqXkcKVASkAmt0yR9qf0vop5YQ3OGhGQNiS28oHPECVRgVCPH6gvOcyN0n4+SKat4/ S6sw== X-Gm-Message-State: ANhLgQ0nLbpioWdlyH9WDRx2+ovGM0Nzc+JaDbRfeLzvWXcTPxG5Eg+Q 8to/vsiL45O+lsZuIE+nkCd/82T2 X-Google-Smtp-Source: ADFU+vtUZ2ZVgymZna+ZaY17qg9579Ve4gW2Dk4Wcm0GZLqdUa+YM7d0It2+2k8tVGwqLqbxyENfkQ== X-Received: by 2002:a5d:53ce:: with SMTP id a14mr1102609wrw.129.1585270152526; Thu, 26 Mar 2020 17:49:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z203sm5980649wmg.12.2020.03.26.17.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:12 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:55 +0000 Subject: [PATCH v3 12/18] unpack-trees: move ERROR_WOULD_LOSE_SUBMODULE earlier Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren A minor change, but we want to convert the sparse messages to warnings and this allows us to group warnings and errors. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 12 ++++++------ unpack-trees.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index a5bc0a3a16d..eeac309e30e 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -43,15 +43,14 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { /* ERROR_BIND_OVERLAP */ "Entry '%s' overlaps with '%s'. Cannot bind.", + /* ERROR_WOULD_LOSE_SUBMODULE */ + "Submodule '%s' cannot checkout new HEAD.", + /* ERROR_SPARSE_NOT_UPTODATE_FILE */ "Entry '%s' not uptodate. Cannot update sparse checkout.", /* ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN */ "Working tree file '%s' would be overwritten by sparse checkout update.", - - - /* ERROR_WOULD_LOSE_SUBMODULE */ - "Submodule '%s' cannot checkout new HEAD.", }; #define ERRORMSG(o,type) \ @@ -166,12 +165,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, */ msgs[ERROR_BIND_OVERLAP] = _("Entry '%s' overlaps with '%s'. Cannot bind."); + msgs[ERROR_WOULD_LOSE_SUBMODULE] = + _("Cannot update submodule:\n%s"); + msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] = _("Cannot update sparse checkout: the following entries are not up to date:\n%s"); msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] = _("The following working tree files would be overwritten by sparse checkout update:\n%s"); - msgs[ERROR_WOULD_LOSE_SUBMODULE] = - _("Cannot update submodule:\n%s"); opts->show_all_errors = 1; /* rejected paths may not have a static buffer */ diff --git a/unpack-trees.h b/unpack-trees.h index 5cf41ef5b53..3e996a6c0a9 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -22,9 +22,9 @@ enum unpack_trees_error_types { ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, ERROR_WOULD_LOSE_UNTRACKED_REMOVED, ERROR_BIND_OVERLAP, + ERROR_WOULD_LOSE_SUBMODULE, ERROR_SPARSE_NOT_UPTODATE_FILE, ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN, - ERROR_WOULD_LOSE_SUBMODULE, NB_UNPACK_TREES_ERROR_TYPES }; From patchwork Fri Mar 27 00:48:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461497 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 CAA3C161F for ; Fri, 27 Mar 2020 00:49:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADA662074D for ; Fri, 27 Mar 2020 00:49:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CQTD4Rvf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727752AbgC0AtT (ORCPT ); Thu, 26 Mar 2020 20:49:19 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45292 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbgC0AtP (ORCPT ); Thu, 26 Mar 2020 20:49:15 -0400 Received: by mail-wr1-f68.google.com with SMTP id t7so9415095wrw.12 for ; Thu, 26 Mar 2020 17:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pmWJR9CFy0G549gUQSywKDSK51q+vKpVHdR5OKt//mI=; b=CQTD4RvfO85nIo1VMZAaBe+udX17QP0DmWCr3EO0fw3Cdem35gm9IrmupStChQir78 1lW8+hcVy1mhBSG4iRHcI/wAyoTe8A65pP/yEbwCdCz28n/n/FDdHHB2LUSSS+7nZDNm 21IhZuXBFQXZ25so9aGvpm5OOF4ZPXFRCttRHWCujKYFILawJOjxE7Y0Lcwomx94dzum YxXoue4pvlTlMg1mqWuHEHKjS2n/NpSVynKu1Wpq09b4ep79Cg6dk5YwToyfelrlg1uf Q7WgWSVdPs9ltW+5YIC/O06hgCVfjZGiLHAFfZ19jcylLvrbgOlqBW8FXVgesWjg7uwV X8Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pmWJR9CFy0G549gUQSywKDSK51q+vKpVHdR5OKt//mI=; b=ntkOaDD+Bj9AUSO+l71CPj2tT92keB/V2mF8C8ZCqOUNGIpi9JNL4f+zmQ4z9FKTwj uv4IWdtrDMsEZp7slcatAMY1L4oAQ8+rqa+N1jweOtqtLfvBlOydnIp25P3nAC6/rbrk GX9X+qPWzMsB+c2qIBZy6cf8je/a1sc2dE/fdWz2r1JKQfLYmNPHY/baCofn6TmBBntJ Reixs/oG5/1MQMmc/AO43bl/EYZBE3uPNftp3z2xT4n7Qxiyz20EIGlj0lxCs8hxl9XK TKvVUs9eWs1WzM7nDqRY1hY7GPtCB9ngsbwQoc+Ph+l5rNfOlt+cW8spEqoYR8cjoAtg apiw== X-Gm-Message-State: ANhLgQ3ZBz60VT1wzHuzWqEiGFpRZs8vWOUFpD7z36txec6j0SDlF+SM hXQesBWrd3PSFDc6hp3VKuh8riUz X-Google-Smtp-Source: ADFU+vtPXatbsU0l/ZJ+gNZUKzAcxtMeLju8WiNngc1vtfGZS4+OBSDONUJVNnwQNSiDYeOLnXt1Aw== X-Received: by 2002:adf:9346:: with SMTP id 64mr11837311wro.174.1585270153227; Thu, 26 Mar 2020 17:49:13 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z16sm6028879wrr.56.2020.03.26.17.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:12 -0700 (PDT) Message-Id: <90c514e220ba22e8fe63c33fd9c8cb9a67d21e64.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:56 +0000 Subject: [PATCH v3 13/18] unpack-trees: rename ERROR_* fields meant for warnings to WARNING_* Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren We want to treat issues with setting the SKIP_WORKTREE bit as a warning rather than an error; rename the enum values to reflect this intent as a simple step towards that goal. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- unpack-trees.c | 12 ++++++------ unpack-trees.h | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index eeac309e30e..2a2306c5c28 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -46,10 +46,10 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { /* ERROR_WOULD_LOSE_SUBMODULE */ "Submodule '%s' cannot checkout new HEAD.", - /* ERROR_SPARSE_NOT_UPTODATE_FILE */ + /* WARNING_SPARSE_NOT_UPTODATE_FILE */ "Entry '%s' not uptodate. Cannot update sparse checkout.", - /* ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN */ + /* WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN */ "Working tree file '%s' would be overwritten by sparse checkout update.", }; @@ -168,9 +168,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, msgs[ERROR_WOULD_LOSE_SUBMODULE] = _("Cannot update submodule:\n%s"); - msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] = + msgs[WARNING_SPARSE_NOT_UPTODATE_FILE] = _("Cannot update sparse checkout: the following entries are not up to date:\n%s"); - msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] = + msgs[WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN] = _("The following working tree files would be overwritten by sparse checkout update:\n%s"); opts->show_all_errors = 1; @@ -509,7 +509,7 @@ static int apply_sparse_checkout(struct index_state *istate, ce->ce_flags &= ~CE_UPDATE; } if (was_skip_worktree && !ce_skip_worktree(ce)) { - if (verify_absent_sparse(ce, ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN, o)) + if (verify_absent_sparse(ce, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, o)) return -1; ce->ce_flags |= CE_UPDATE; } @@ -1875,7 +1875,7 @@ int verify_uptodate(const struct cache_entry *ce, static int verify_uptodate_sparse(const struct cache_entry *ce, struct unpack_trees_options *o) { - return verify_uptodate_1(ce, o, ERROR_SPARSE_NOT_UPTODATE_FILE); + return verify_uptodate_1(ce, o, WARNING_SPARSE_NOT_UPTODATE_FILE); } /* diff --git a/unpack-trees.h b/unpack-trees.h index 3e996a6c0a9..aac1ad4b014 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -23,9 +23,11 @@ enum unpack_trees_error_types { ERROR_WOULD_LOSE_UNTRACKED_REMOVED, ERROR_BIND_OVERLAP, ERROR_WOULD_LOSE_SUBMODULE, - ERROR_SPARSE_NOT_UPTODATE_FILE, - ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN, - NB_UNPACK_TREES_ERROR_TYPES + + WARNING_SPARSE_NOT_UPTODATE_FILE, + WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, + + NB_UNPACK_TREES_ERROR_TYPES, }; /* From patchwork Fri Mar 27 00:48:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461505 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 2FD0017D4 for ; Fri, 27 Mar 2020 00:49:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 090C02074D for ; Fri, 27 Mar 2020 00:49:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DunIPbsG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbgC0At0 (ORCPT ); Thu, 26 Mar 2020 20:49:26 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54082 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbgC0AtP (ORCPT ); Thu, 26 Mar 2020 20:49:15 -0400 Received: by mail-wm1-f65.google.com with SMTP id b12so9809701wmj.3 for ; Thu, 26 Mar 2020 17:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Po/t2SpEj8V7Cmf0oy4tXZLbrv+hONGPyxyRP/bfk54=; b=DunIPbsGv+tYHsoPLlqCDolSfbE/U0IaxhmpXRuH4c30P27ido2Q3Y0yzpBTB2HR0l SsnKRy6YM0snTc9Q5SoYrvut3wj7f6D2tAbBzLfvUtzwEAjO3E3l5ZnVUJADkODAEY7d xJn43a1of6N2fJRCApkEEs5CK5PGgfUTGKhSTy9qUC4PHKYBA4/WesmDfVUs3We1fVsL S3DZHTCaz3L03TPr+5ik3e9we0MPCgWu+62/N2nOm5o969inV0XVnLS5W6Tc//hLzd92 RFRjb5fNsAsCDaLkjj52wqgZTmtbbB5SorQjIWleQCMJf8TNQzQsh2GyRY+OgtS3lqkd urvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Po/t2SpEj8V7Cmf0oy4tXZLbrv+hONGPyxyRP/bfk54=; b=BOwLoymtZNqmt8ivKRIwlr2fiHi8lmEOgBt/DSkrWlD8tSpYE7hgdSaPUNEkjDC31H VDds/b7ooYLPO/8hXrbhkEs4Mp41qAD/RT/qVvJawVMw+loIXn2/SLS3j8wxyD4agNFZ Zoe5r1pSjey9ZvPbujrp1+1oms4q78hRbW+NZGy3GnvBtbZ5laA8PXCQRzN0zFGBG3Rl sJaksUPJAto5B+SQP5ciNbx8KFZUzjNY8X1c7lfleuTDCRbMFvWwjfaXqrxj1ScrHTJ3 0r7muXCwlmAziWU5u58H95/9RGIIaCcQEiVTwsmSJOe6zGpdDliVDwOrpqLRFjI1V2We IgVQ== X-Gm-Message-State: ANhLgQ34DrGm0AcbStHsNGXQ3QCYTQAchusIpO/uMXqfmmj/CYu7kJQv kMfJZ996Q/b6lhvUJmgqUDWn0IaL X-Google-Smtp-Source: ADFU+vv8M/Wyw7ONBElaV7Vb3zYnbTSx9hoKKq2rvlEhl7lY58ichLQsgODSUZ/ID2/+haWnwg2OWQ== X-Received: by 2002:a1c:7e43:: with SMTP id z64mr2541935wmc.45.1585270153954; Thu, 26 Mar 2020 17:49:13 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v21sm5498445wmj.8.2020.03.26.17.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:13 -0700 (PDT) Message-Id: <5676e890f65d3b804e2642c7c57532cbcc1d6673.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:57 +0000 Subject: [PATCH v3 14/18] unpack-trees: split display_error_msgs() into two Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren display_error_msgs() is never called to show messages of both ERROR_* and WARNING_* types at the same time; it is instead called multiple times, separately for each type. Since we want to display these types differently, make two slightly different versions of this function. A subsequent commit will further modify unpack_trees() and how it calls the new display_warning_msgs(). Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- t/t1091-sparse-checkout-builtin.sh | 4 +-- unpack-trees.c | 50 +++++++++++++++++++++++++----- unpack-trees.h | 8 +++-- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 9bc65d32f07..ed5e9059969 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -328,10 +328,10 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' echo dirty >dirty/folder1/a && git -C dirty sparse-checkout init 2>err && - test_i18ngrep "error.*Cannot update sparse checkout" err && + test_i18ngrep "warning.*Cannot update sparse checkout" err && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && - test_i18ngrep "error.*Cannot update sparse checkout" err && + test_i18ngrep "warning.*Cannot update sparse checkout" err && test_path_is_file dirty/folder1/a && git -C dirty sparse-checkout disable 2>err && diff --git a/unpack-trees.c b/unpack-trees.c index 2a2306c5c28..f9a5626a670 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -24,7 +24,7 @@ * situation better. See how "git checkout" and "git merge" replaces * them using setup_unpack_trees_porcelain(), for example. */ -static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { +static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { /* ERROR_WOULD_OVERWRITE */ "Entry '%s' would be overwritten by merge. Cannot merge.", @@ -46,6 +46,9 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { /* ERROR_WOULD_LOSE_SUBMODULE */ "Submodule '%s' cannot checkout new HEAD.", + /* NB_UNPACK_TREES_ERROR_TYPES; just a meta value */ + "", + /* WARNING_SPARSE_NOT_UPTODATE_FILE */ "Entry '%s' not uptodate. Cannot update sparse checkout.", @@ -222,7 +225,7 @@ static int add_rejected_path(struct unpack_trees_options *o, /* * Otherwise, insert in a list for future display by - * display_error_msgs() + * display_(error|warning)_msgs() */ string_list_append(&o->unpack_rejects[e], path); return -1; @@ -233,13 +236,16 @@ static int add_rejected_path(struct unpack_trees_options *o, */ static void display_error_msgs(struct unpack_trees_options *o) { - int e, i; - int something_displayed = 0; + int e; + unsigned error_displayed = 0; for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) { struct string_list *rejects = &o->unpack_rejects[e]; + if (rejects->nr > 0) { + int i; struct strbuf path = STRBUF_INIT; - something_displayed = 1; + + error_displayed = 1; for (i = 0; i < rejects->nr; i++) strbuf_addf(&path, "\t%s\n", rejects->items[i].string); error(ERRORMSG(o, e), super_prefixed(path.buf)); @@ -247,10 +253,36 @@ static void display_error_msgs(struct unpack_trees_options *o) } string_list_clear(rejects, 0); } - if (something_displayed) + if (error_displayed) fprintf(stderr, _("Aborting\n")); } +/* + * display all the warning messages stored in a nice way + */ +static void display_warning_msgs(struct unpack_trees_options *o) +{ + int e; + unsigned warning_displayed = 0; + for (e = NB_UNPACK_TREES_ERROR_TYPES + 1; + e < NB_UNPACK_TREES_WARNING_TYPES; e++) { + struct string_list *rejects = &o->unpack_rejects[e]; + + if (rejects->nr > 0) { + int i; + struct strbuf path = STRBUF_INIT; + + warning_displayed = 1; + for (i = 0; i < rejects->nr; i++) + strbuf_addf(&path, "\t%s\n", rejects->items[i].string); + warning(ERRORMSG(o, e), super_prefixed(path.buf)); + strbuf_release(&path); + } + string_list_clear(rejects, 0); + } + if (warning_displayed) + fprintf(stderr, _("After fixing the above paths, you may want to run `git sparse-checkout reapply`.\n")); +} static int check_submodule_move_head(const struct cache_entry *ce, const char *old_id, const char *new_id, @@ -1705,8 +1737,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options return ret; return_failed: - if (o->show_all_errors) + if (o->show_all_errors) { display_error_msgs(o); + display_warning_msgs(o); + } mark_all_ce_unused(o->src_index); ret = unpack_failed(o, NULL); if (o->exiting_early) @@ -1783,7 +1817,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; done: - display_error_msgs(o); + display_warning_msgs(o); o->show_all_errors = old_show_all_errors; if (free_pattern_list) clear_pattern_list(&pl); diff --git a/unpack-trees.h b/unpack-trees.h index aac1ad4b014..dae948205f9 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -24,10 +24,12 @@ enum unpack_trees_error_types { ERROR_BIND_OVERLAP, ERROR_WOULD_LOSE_SUBMODULE, + NB_UNPACK_TREES_ERROR_TYPES, + WARNING_SPARSE_NOT_UPTODATE_FILE, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, - NB_UNPACK_TREES_ERROR_TYPES, + NB_UNPACK_TREES_WARNING_TYPES, }; /* @@ -66,13 +68,13 @@ struct unpack_trees_options { struct dir_struct *dir; struct pathspec *pathspec; merge_fn_t fn; - const char *msgs[NB_UNPACK_TREES_ERROR_TYPES]; + const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; struct argv_array msgs_to_free; /* * Store error messages in an array, each case * corresponding to a error message type */ - struct string_list unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES]; + struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; int head_idx; int merge_size; From patchwork Fri Mar 27 00:48:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461503 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 6B8BB161F for ; Fri, 27 Mar 2020 00:49:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4CC4D20719 for ; Fri, 27 Mar 2020 00:49:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g+0Q+kyv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbgC0AtZ (ORCPT ); Thu, 26 Mar 2020 20:49:25 -0400 Received: from mail-wr1-f48.google.com ([209.85.221.48]:38891 "EHLO mail-wr1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727733AbgC0AtS (ORCPT ); Thu, 26 Mar 2020 20:49:18 -0400 Received: by mail-wr1-f48.google.com with SMTP id s1so9468220wrv.5 for ; Thu, 26 Mar 2020 17:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=LfbkNunChhVGUGhHG02K+M4rVbdDfPpixKCG62qfiI4=; b=g+0Q+kyvL8rERE8c6XRJVZBvxNqx/Fi3bfqmieRtA61OXcsUozjGShT1/M1LXsAlwU i5Y3RvZBXtFVKReWErdLOjycRZWK0wottDm2Kbqts8wzbSxwgGafbDgYrRYEs2Hd5BWV uwG5ElAqnuQ1sb2XRf3ZpGh2dXMPdnnuHDMuYFcptaxkIwivwDyr01KyJQ453I2TYuNJ eZEGigdS5XbROw9oF9uWpdWBewwtGF3q4CXQT9+2HX6LJ7PUBDIK3SWsQxLNh47/gzJu UIgbyddrSw1dDAugGhlmKTK9Nag76WdhQILslWjszFFm39UABW1UDBh/wEvVlZeIqPM5 HYgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=LfbkNunChhVGUGhHG02K+M4rVbdDfPpixKCG62qfiI4=; b=UmYzyFsErpx0NrBURmcMlWtNDamNzzhF0/AaUcDte09TakOoHm9V7yLWYIAImKa32X KWCz+leQ5KjlBHZcTxTBO+wcdV7YWLo3SCr2GBscVlpy1zgRUZ8K+AFhsNHZdDFqqbn4 dz9JqIlvH+5NqY+LhjCXM50Rxud1Fj/eWIABfrCG94kaIAWudwtKAChLhYHo+vMNJMVP EUbM1ZnUfKA6gS/EcM4jFT8XWX+v3YBjtjZnc2Yf+fjqo/DfH3Ll2v7aqghkxvYEQw2C XAHe7tVPP1s10KlKNX0o7nPT1XlKdLojBGjI0ptqOqlEiFcj9oTEudMLcbtFUVsh1k6h J3lA== X-Gm-Message-State: ANhLgQ0By4J089oF66cfveWbsEIs+lBDbQk8QAPeE8GO3ioMKT5ggdv2 JP1vbHqrFh/I+Ap9JnA/6vKqHnDZ X-Google-Smtp-Source: ADFU+vvu6yiXs2xUQiEBWtlPI4YqfpVckNpAFIMASnWimOE8wFWwkeXCV3/O7RWydudXsF3xorNPSw== X-Received: by 2002:a5d:6187:: with SMTP id j7mr12537858wru.419.1585270154792; Thu, 26 Mar 2020 17:49:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v8sm6001955wrw.2.2020.03.26.17.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:14 -0700 (PDT) Message-Id: <74e13ccee408757beb8ae3bb1dddea8d34ef56bb.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:58 +0000 Subject: [PATCH v3 15/18] unpack-trees: make sparse path messages sound like warnings Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren The messages for problems with sparse paths are phrased as errors that cause the operation to abort, even though we are not making the operation abort. Reword the messages to make sense in their new context. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- t/t1091-sparse-checkout-builtin.sh | 6 +++--- unpack-trees.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index ed5e9059969..afbde89e605 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -288,7 +288,7 @@ test_expect_success 'not-up-to-date does not block rest of sparsification' ' git -C repo sparse-checkout set deep/deeper1 2>err && - test_i18ngrep "Cannot update sparse checkout" err && + test_i18ngrep "The following paths are not up to date" err && test_cmp expect repo/.git/info/sparse-checkout && check_files repo/deep a deeper1 deeper2 && check_files repo/deep/deeper1 a deepest && @@ -328,10 +328,10 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' echo dirty >dirty/folder1/a && git -C dirty sparse-checkout init 2>err && - test_i18ngrep "warning.*Cannot update sparse checkout" err && + test_i18ngrep "warning.*The following paths are not up to date" err && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && - test_i18ngrep "warning.*Cannot update sparse checkout" err && + test_i18ngrep "warning.*The following paths are not up to date" err && test_path_is_file dirty/folder1/a && git -C dirty sparse-checkout disable 2>err && diff --git a/unpack-trees.c b/unpack-trees.c index f9a5626a670..484d30a53a7 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -50,10 +50,10 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { "", /* WARNING_SPARSE_NOT_UPTODATE_FILE */ - "Entry '%s' not uptodate. Cannot update sparse checkout.", + "Path '%s' not uptodate; will not remove from working tree.", /* WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN */ - "Working tree file '%s' would be overwritten by sparse checkout update.", + "Path '%s' already present; will not overwrite with sparse update.", }; #define ERRORMSG(o,type) \ @@ -172,9 +172,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, _("Cannot update submodule:\n%s"); msgs[WARNING_SPARSE_NOT_UPTODATE_FILE] = - _("Cannot update sparse checkout: the following entries are not up to date:\n%s"); + _("The following paths are not up to date and were left despite sparse patterns:\n%s"); msgs[WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN] = - _("The following working tree files would be overwritten by sparse checkout update:\n%s"); + _("The following paths were already present and thus not updated despite sparse patterns:\n%s"); opts->show_all_errors = 1; /* rejected paths may not have a static buffer */ From patchwork Fri Mar 27 00:48:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461499 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 6FDF117EA for ; Fri, 27 Mar 2020 00:49:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 492BA206E6 for ; Fri, 27 Mar 2020 00:49:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XVAtKdH+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727766AbgC0AtX (ORCPT ); Thu, 26 Mar 2020 20:49:23 -0400 Received: from mail-wr1-f50.google.com ([209.85.221.50]:39703 "EHLO mail-wr1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727731AbgC0AtR (ORCPT ); Thu, 26 Mar 2020 20:49:17 -0400 Received: by mail-wr1-f50.google.com with SMTP id p10so9466428wrt.6 for ; Thu, 26 Mar 2020 17:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=vfhTeXNId9siyDVXX6qMBmAKDzvOw+NBbx2t6dun4ZI=; b=XVAtKdH+4tx1a35FWidcBOQ3EMRQMZgvilE7ROTTWa6O6RMOXEuQ7Ke2ZgDcz0nJoc JYursvPmFCE6TOfkSILZ43FiC60NrYFJA6PzmF4Th4VKWTIw5hgCztm40Tv66Gp4mGCV f55Mh+CPXTGvnYyAsL8uPJz00uIcdTZKWvXUV6u+k66QHKKyAarep7gXtnrWSM/h91Pj gq6J7ILE3AV10pR99g8gdAIEWWP4A+pyekOyxkc25lfFMeYVoat25P4SVenDr2KXUIw1 v5ajuQBE9Js6l8VYtYb63GdBbJpuQY4FvN2KdqL/zSgMM63C00fzc7Wtn5h/03qtsxku q5XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=vfhTeXNId9siyDVXX6qMBmAKDzvOw+NBbx2t6dun4ZI=; b=ph2Mo7Nh+eJ4pa1qTOGOgpgoJ4lLZZQS74bISvOMmL6X+iWRsJNHr8eUxqKfISeu3T ZiaW1b0IIMQtBEg7UVub/pWLplfGPlBaEC8uwwwWOYd5+oPdIgYm8qiZzaXaZuTmobhL YJCbm8cvhQU4k1L7yAs2n/4/JzRgUm8DHkH+HyPzuYfmLLUQQwxemH31ki6O71+1x7iq fcBva33B+cSz5p7XRAj2F2OxMc7XB6c9ju2AU7u7XJctW72F2X9tGMZfDOFmOJx6slo1 Y8JXKtQx+0WlvnjGw0jLpqs93kBXYZVKBdseKLqQRGT+WpqC3iOphsusX955KnFblBF3 M1AA== X-Gm-Message-State: ANhLgQ2vxPJbcif5kApFDknt4Rya6azUCLIRfjmsYZh/HJoFKBEcDS5v hxCzO5U7YvuorNUEEw9xqLpXP50Q X-Google-Smtp-Source: ADFU+vsQfXnGpunzVrU68uCLMBWwrgL8mP1jqEQsAo0USttldlSfjBAm8Fd4fHXNg4SmOjZae5sZ7Q== X-Received: by 2002:adf:df82:: with SMTP id z2mr11451101wrl.46.1585270155584; Thu, 26 Mar 2020 17:49:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t126sm6155599wmb.27.2020.03.26.17.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:15 -0700 (PDT) Message-Id: <5d9e8a9d27e13670b56fe05dc36c066ec766b390.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:48:59 +0000 Subject: [PATCH v3 16/18] unpack-trees: provide warnings on sparse updates for unmerged paths too Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren When sparse-checkout runs to update the list of sparsity patterns, it gives warnings if it can't remove paths from the working tree because those files have dirty changes. Add a similar warning for unmerged paths as well. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- t/t1091-sparse-checkout-builtin.sh | 25 +++++++++++++++++++++++++ unpack-trees.c | 30 ++++++++++++++++++++++++++++++ unpack-trees.h | 1 + 3 files changed, 56 insertions(+) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index afbde89e605..8e2976bc7b8 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -345,6 +345,31 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' test_path_is_file dirty/folder1/a ' +test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged status' ' + git clone repo unmerged && + + cat >input <<-EOF && + 0 0000000000000000000000000000000000000000 folder1/a + 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a + EOF + git -C unmerged update-index --index-info err && + test_i18ngrep "warning.*The following paths are unmerged" err && + + git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err && + test_i18ngrep "warning.*The following paths are unmerged" err && + test_path_is_file dirty/folder1/a && + + git -C unmerged sparse-checkout disable 2>err && + test_i18ngrep "warning.*The following paths are unmerged" err && + + git -C unmerged reset --hard && + git -C unmerged sparse-checkout init && + git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* && + git -C unmerged sparse-checkout disable +' + test_expect_success 'cone mode: set with core.ignoreCase=true' ' rm repo/.git/info/sparse-checkout && git -C repo sparse-checkout init --cone && diff --git a/unpack-trees.c b/unpack-trees.c index 484d30a53a7..dec044339df 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -52,6 +52,9 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { /* WARNING_SPARSE_NOT_UPTODATE_FILE */ "Path '%s' not uptodate; will not remove from working tree.", + /* WARNING_SPARSE_UNMERGED_FILE */ + "Path '%s' unmerged; will not remove from working tree.", + /* WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN */ "Path '%s' already present; will not overwrite with sparse update.", }; @@ -173,6 +176,8 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, msgs[WARNING_SPARSE_NOT_UPTODATE_FILE] = _("The following paths are not up to date and were left despite sparse patterns:\n%s"); + msgs[WARNING_SPARSE_UNMERGED_FILE] = + _("The following paths are unmerged and were left despite sparse patterns:\n%s"); msgs[WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN] = _("The following paths were already present and thus not updated despite sparse patterns:\n%s"); @@ -548,6 +553,23 @@ static int apply_sparse_checkout(struct index_state *istate, return 0; } +static int warn_conflicted_path(struct index_state *istate, + int i, + struct unpack_trees_options *o) +{ + char *conflicting_path = istate->cache[i]->name; + int count = 0; + + add_rejected_path(o, WARNING_SPARSE_UNMERGED_FILE, conflicting_path); + + /* Find out how many higher stage entries at same path */ + while (++count < istate->cache_nr && + !strcmp(conflicting_path, + istate->cache[i+count]->name)) + /* do nothing */; + return count; +} + static inline int call_unpack_fn(const struct cache_entry * const *src, struct unpack_trees_options *o) { @@ -1793,6 +1815,14 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) for (i = 0; i < o->src_index->cache_nr; i++) { struct cache_entry *ce = o->src_index->cache[i]; + + if (ce_stage(ce)) { + /* -1 because for loop will increment by 1 */ + i += warn_conflicted_path(o->src_index, i, o) - 1; + ret = UPDATE_SPARSITY_WARNINGS; + continue; + } + if (apply_sparse_checkout(o->src_index, ce, o)) ret = UPDATE_SPARSITY_WARNINGS; diff --git a/unpack-trees.h b/unpack-trees.h index dae948205f9..0f7424aec61 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -27,6 +27,7 @@ enum unpack_trees_error_types { NB_UNPACK_TREES_ERROR_TYPES, WARNING_SPARSE_NOT_UPTODATE_FILE, + WARNING_SPARSE_UNMERGED_FILE, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, NB_UNPACK_TREES_WARNING_TYPES, From patchwork Fri Mar 27 00:49:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461507 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 23DFB17D4 for ; Fri, 27 Mar 2020 00:49:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1E502074D for ; Fri, 27 Mar 2020 00:49:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mo7vUede" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727773AbgC0AtY (ORCPT ); Thu, 26 Mar 2020 20:49:24 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39013 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727732AbgC0AtT (ORCPT ); Thu, 26 Mar 2020 20:49:19 -0400 Received: by mail-wm1-f65.google.com with SMTP id a9so10571232wmj.4 for ; Thu, 26 Mar 2020 17:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DluivwQB0UWgRj4ycznmh9I5VdagHc5AZ2URTnRPllw=; b=Mo7vUedeqXVVSoMaPsdM5NBZnIVAMxvZrw13q5m1Rm+20TKofLDrtNcN+luXyVg4/J d1AVdJ4N3dH039YnuSTcjQPHqkwPlfRcKLbkAL93aWMQEriJzQHhkmSbm/6VFT2G0vT4 EB69sV4Gu0GRvv1Iv1rvyglShaHF6K5YPdzT8PcSH+MhWggu6rzmKFaqTanU94ArF9Dn pWNAEGZ/q/bruzgeTdL0kpHc4E5n6UXBskJ5oMJA4o0443WCOTDwCLJTH4uvUGTXwdXT GxojfPmnEyNg9N1U5xvYm6qZWxXZoN8OwpCk99uWF1hYMxXmSbX7OxnMOyETktL6dfOW 5HfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=DluivwQB0UWgRj4ycznmh9I5VdagHc5AZ2URTnRPllw=; b=B5CUfVFNjRKiNJulka2LaO64sKtuhg4CIWRKPWEn7f/ZmYvl9NSggM8C9rU8GIskFL q8CNDpcNA07OKvSatQfRqvqHAo4AJtJjV/ZDfrAJMsqciTWiAUpg3BnLzjcmwON+a8Z4 SzhjqR5svlU48tXT6YppvGmMAGQqFzhSUZalCcvo29/d0Rn+TDNXcLI/8eDjm5vJEUz8 UooQgNiVQHWOMmN/MJ8gfg9vqZhaHlBn/6LRLsx+P93ZQ/MlKCejD0lzowYsjTMD/e0N muZlaV6bz/rwSafCwlCRrDUEpk9H2bKqcct79fyGo75GvcQJC/fvisb8ZQv9ApBjiAM3 8i+w== X-Gm-Message-State: ANhLgQ3GvHYam34lLIr6YTtEAmgRiaU6x0p5OQz4VFCC+qsDJBOUovMS JmGqOS3fFHGFN4/yNM/UQCThTiSW X-Google-Smtp-Source: ADFU+vv9zmQXykX9bei4VBiZYu8vVbbA36x+/8CRBIeuS8Xel35Ntn3cuRw31d+0kpZVudskfiv0bA== X-Received: by 2002:a05:600c:2048:: with SMTP id p8mr2623437wmg.58.1585270156234; Thu, 26 Mar 2020 17:49:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o9sm6038032wrx.48.2020.03.26.17.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:15 -0700 (PDT) Message-Id: <844306c3e86ef67591cc086decb2b760e7d710a3.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:49:00 +0000 Subject: [PATCH v3 17/18] unpack-trees: failure to set SKIP_WORKTREE bits always just a warning Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Setting and clearing of the SKIP_WORKTREE bit is not only done when users run 'sparse-checkout'; other commands such as 'checkout' also run through unpack_trees() which has logic for handling this special bit. As such, we need to consider how they handle special cases. A couple comparison points should help explain the rationale for changing how unpack_trees() handles these bits: Ignoring sparse checkouts for a moment, if you are switching branches and have dirty changes, it is only considered an error that will prevent the branch switching from being successful if the dirty file happens to be one of the paths with different contents. SKIP_WORKTREE has always been considered advisory; for example, if rebase or merge need or even want to materialize a path as part of their work, they have always been allowed to do so regardless of the SKIP_WORKTREE setting. This has been used for unmerged paths, but it was often used for paths it wasn't needed just because it made the code simpler. It was a best-effort consideration, and when it materialized paths contrary to the SKIP_WORKTREE setting, it was never required to even print a warning message. In the past if you trying to run e.g. 'git checkout' and: 1) you had a path that was materialized and had some dirty changes 2) the path was listed in $GITDIR/info/sparse-checkout 3) this path did not different between the current and target branches then despite the comparison points above, the inability to set SKIP_WORKTREE was treated as a *hard* error that would abort the checkout operation. This is completely inconsistent with how SKIP_WORKTREE is handled elsewhere, and rather annoying for users as leaving the paths materialized in the working copy (with a simple warning) should present no problem at all. Downgrade any errors from inability to toggle the SKIP_WORKTREE bit to a warning and allow the operations to continue. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- t/t1011-read-tree-sparse-checkout.sh | 11 +++++----- t/t2018-checkout-branch.sh | 22 ++++++++++++++++++++ unpack-trees.c | 31 ++++++++++++++-------------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index eb44bafb593..63223e13bd1 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -233,18 +233,19 @@ test_expect_success 'read-tree --reset removes outside worktree' ' test_must_be_empty result ' -test_expect_success 'print errors when failed to update worktree' ' +test_expect_success 'print warnings when some worktree updates disabled' ' echo sub >.git/info/sparse-checkout && git checkout -f init && mkdir sub && touch sub/added sub/addedtoo && - test_must_fail git checkout top 2>actual && + # Use -q to suppress "Previous HEAD position" and "Head is now at" msgs + git checkout -q top 2>actual && cat >expected <<\EOF && -error: The following untracked working tree files would be overwritten by checkout: +warning: The following paths were already present and thus not updated despite sparse patterns: sub/added sub/addedtoo -Please move or remove them before you switch branches. -Aborting + +After fixing the above paths, you may want to run `git sparse-checkout reapply`. EOF test_i18ncmp expected actual ' diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index bbca7ef8da6..21583154d8e 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -238,4 +238,26 @@ test_expect_success 'checkout -b after clone --no-checkout does a checkout of HE test_path_is_file dest/a.t ' +test_expect_success 'checkout -b to a new branch preserves mergeable changes despite sparse-checkout' ' + test_when_finished " + git reset --hard && + git checkout branch1-scratch && + test_might_fail git branch -D branch3 && + git config core.sparseCheckout false && + rm .git/info/sparse-checkout" && + + test_commit file2 && + + echo stuff >>file1 && + echo file2 >.git/info/sparse-checkout && + git config core.sparseCheckout true && + + CURHEAD=$(git rev-parse HEAD) && + do_checkout branch3 $CURHEAD && + + echo file1 >expect && + git diff --name-only >actual && + test_cmp expect actual +' + test_done diff --git a/unpack-trees.c b/unpack-trees.c index dec044339df..b43f3e775ad 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1701,23 +1701,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * correct CE_NEW_SKIP_WORKTREE */ if (ce->ce_flags & CE_ADDED && - verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) { - if (!o->show_all_errors) - goto return_failed; - ret = -1; - } + verify_absent(ce, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, o)) + ret = 1; + + if (apply_sparse_checkout(&o->result, ce, o)) + ret = 1; - if (apply_sparse_checkout(&o->result, ce, o)) { - if (!o->show_all_errors) - goto return_failed; - ret = -1; - } if (!ce_skip_worktree(ce)) empty_worktree = 0; - } - if (ret < 0) - goto return_failed; /* * Sparse checkout is meant to narrow down checkout area * but it does not make sense to narrow down to empty working @@ -1728,6 +1720,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory"); goto done; } + if (ret == 1) { + /* + * Inability to sparsify or de-sparsify individual + * paths is not an error, but just a warning. + */ + if (o->show_all_errors) + display_warning_msgs(o); + ret = 0; + } } ret = check_updates(o, &o->result) ? (-2) : 0; @@ -1759,10 +1760,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options return ret; return_failed: - if (o->show_all_errors) { + if (o->show_all_errors) display_error_msgs(o); - display_warning_msgs(o); - } mark_all_ce_unused(o->src_index); ret = unpack_failed(o, NULL); if (o->exiting_early) From patchwork Fri Mar 27 00:49:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11461501 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 081B317D4 for ; Fri, 27 Mar 2020 00:49:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD4752074D for ; Fri, 27 Mar 2020 00:49:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UgT2nQKb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbgC0AtX (ORCPT ); Thu, 26 Mar 2020 20:49:23 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35285 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727738AbgC0AtS (ORCPT ); Thu, 26 Mar 2020 20:49:18 -0400 Received: by mail-wr1-f66.google.com with SMTP id d5so9513343wrn.2 for ; Thu, 26 Mar 2020 17:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OttmbKGh36mHnQ3eYZNtWdbQwMVIlgJ3cC1xR2/jBUI=; b=UgT2nQKbq2RbPKu/BCXAxFtSCdy4U9mAoc3JtSF0yRf53DX0sgFgHnXoMOG8e2sMky rz6rEk9UGsH46zHZK5hJrnK8gSrdhaktFeuOmVem42+bWrrNVWBDJV4nf0FlMd6Bw5zc 3jid7cxXAbp0MB8Gu004w8tCEOdnEzumY7m8M9afuMAFGHiwPclSiNLggBD2OSZ94hxa RO9xXv1m8sKtLH1bcpc/aMfU1jFpfmWCXHeCLqD9bMy5jU++u4fKGWxdMiBqf0EtADC/ PyqQgbOJdFJZAalzlyJf4qN7cXCH/NZct0HWdCfeQPsGQIauHihoK2nOoEXpJE13IZiy YNXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OttmbKGh36mHnQ3eYZNtWdbQwMVIlgJ3cC1xR2/jBUI=; b=L4nLpWVXShF8HBtMcVkt2gNR9yn/9U9o9XchfppRnFFqGbxkSGYC2dGXgoac2tb2rj ASJvcfIfq5zM2BspPBIMAKkUZZ563yjwGKycsrodlu18rsG4Q/2v0VYok4q2D0xTE9FY 2QT/CCQTFWgKIMq4wYrsEsj6kHZHgImOyC/LP8HVtmMY2QcaZPcuJsDCgJwlzJ9/ljXS LUroHSHNunnEjV7WkANZ7hNzv4TXsnVx7mW8Wqaa1hxDunrAUTx5GcnaVmC3HGPSOutU scmE8f7D9XGD2g1aVyApwXmYcgH7QxTFT6T6HDeXv8layhVd0S75gaUD2EgyUuM5mwBZ q9ZQ== X-Gm-Message-State: ANhLgQ31KT13kMD970mO47gWDt/QRFxNUCYzoHZfBLgfz+iZqRUC5NM0 0gUYGV6n5yN8mdBKnldPh3Jl5pQp X-Google-Smtp-Source: ADFU+vuI58pq14WiAODk1sXCb6T/y8vn7HzDk8CH1JJ2I+m6RpKhfCkSqWlZLREwVxfe77y+45C3rw== X-Received: by 2002:adf:f2c7:: with SMTP id d7mr11847743wrp.184.1585270156862; Thu, 26 Mar 2020 17:49:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10sm5671375wrq.95.2020.03.26.17.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 17:49:16 -0700 (PDT) Message-Id: <93dbdd78acf5f703126695aff0e27024a6b725c0.1585270142.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Fri, 27 Mar 2020 00:49:01 +0000 Subject: [PATCH v3 18/18] sparse-checkout: provide a new reapply subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren If commands like merge or rebase materialize files as part of their work, or a previous sparse-checkout command failed to update individual files due to dirty changes, users may want a command to simply 'reapply' the sparsity rules. Provide one. Reviewed-by: Derrick Stolee Signed-off-by: Elijah Newren --- Documentation/git-sparse-checkout.txt | 10 +++++++ builtin/sparse-checkout.c | 10 ++++++- t/t1091-sparse-checkout-builtin.sh | 41 +++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index c0342e53938..1a3ace60820 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -70,6 +70,16 @@ C-style quoted strings. `core.sparseCheckoutCone` is enabled, the given patterns are interpreted as directory names as in the 'set' subcommand. +'reapply:: + Reapply the sparsity pattern rules to paths in the working tree. + Commands like merge or rebase can materialize paths to do their + work (e.g. in order to show you a conflict), and other + sparse-checkout commands might fail to sparsify an individual file + (e.g. because it has unstaged changes or conflicts). In such + cases, it can make sense to run `git sparse-checkout reapply` later + after cleaning up affected paths (e.g. resolving conflicts, undoing + or committing changes, etc.). + 'disable':: Disable the `core.sparseCheckout` config setting, and restore the working directory to include all files. Leaves the sparse-checkout diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index aa81199f85d..95d08824172 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -18,7 +18,7 @@ static const char *empty_base = ""; static char const * const builtin_sparse_checkout_usage[] = { - N_("git sparse-checkout (init|list|set|add|disable) "), + N_("git sparse-checkout (init|list|set|add|reapply|disable) "), NULL }; @@ -554,6 +554,12 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix, return modify_pattern_list(argc, argv, m); } +static int sparse_checkout_reapply(int argc, const char **argv) +{ + repo_read_index(the_repository); + return update_working_directory(NULL); +} + static int sparse_checkout_disable(int argc, const char **argv) { struct pattern_list pl; @@ -603,6 +609,8 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix) return sparse_checkout_set(argc, argv, prefix, REPLACE); if (!strcmp(argv[0], "add")) return sparse_checkout_set(argc, argv, prefix, ADD); + if (!strcmp(argv[0], "reapply")) + return sparse_checkout_reapply(argc, argv); if (!strcmp(argv[0], "disable")) return sparse_checkout_disable(argc, argv); } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 8e2976bc7b8..dee99eeec30 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -370,6 +370,47 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat git -C unmerged sparse-checkout disable ' +test_expect_success 'sparse-checkout reapply' ' + git clone repo tweak && + + echo dirty >tweak/deep/deeper2/a && + + cat >input <<-EOF && + 0 0000000000000000000000000000000000000000 folder1/a + 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a + EOF + git -C tweak update-index --index-info err && + test_i18ngrep "warning.*The following paths are not up to date" err && + test_i18ngrep "warning.*The following paths are unmerged" err && + + git -C tweak sparse-checkout set folder2 deep/deeper1 2>err && + test_i18ngrep "warning.*The following paths are not up to date" err && + test_i18ngrep "warning.*The following paths are unmerged" err && + + git -C tweak sparse-checkout reapply 2>err && + test_i18ngrep "warning.*The following paths are not up to date" err && + test_path_is_file tweak/deep/deeper2/a && + test_i18ngrep "warning.*The following paths are unmerged" err && + test_path_is_file tweak/folder1/a && + + git -C tweak checkout HEAD deep/deeper2/a && + git -C tweak sparse-checkout reapply 2>err && + test_i18ngrep ! "warning.*The following paths are not up to date" err && + test_path_is_missing tweak/deep/deeper2/a && + test_i18ngrep "warning.*The following paths are unmerged" err && + test_path_is_file tweak/folder1/a && + + git -C tweak add folder1/a && + git -C tweak sparse-checkout reapply 2>err && + test_must_be_empty err && + test_path_is_missing tweak/deep/deeper2/a && + test_path_is_missing tweak/folder1/a && + + git -C tweak sparse-checkout disable +' + test_expect_success 'cone mode: set with core.ignoreCase=true' ' rm repo/.git/info/sparse-checkout && git -C repo sparse-checkout init --cone &&