From patchwork Thu Aug 18 21:40:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 529F8C28B2B for ; Thu, 18 Aug 2022 21:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347085AbiHRVlE (ORCPT ); Thu, 18 Aug 2022 17:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347033AbiHRVk7 (ORCPT ); Thu, 18 Aug 2022 17:40:59 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B570ABD28E for ; Thu, 18 Aug 2022 14:40:57 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id z14-20020a7bc7ce000000b003a5db0388a8so3197464wmk.1 for ; Thu, 18 Aug 2022 14:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=hQq/+3jqAtLxzZd6175GBBSWucnabx+T9S8n8vEc/7E=; b=L8efHFyuJ3TZEsqRQNepNyYoswRLVN4qYd6ht99yVjC/cuThw6esFBvukoRBTk++iV kCCjUahSUylhOxaFG4twlBTBqbfdXMgwIp5k8gzHkxaA7uPiWNqRfuxIFrty0Rdx6pgU eeGHxc2vvaJDxtk89TR6GzHJmH+im3rmbg4P8JxeciV3iLgaoinBPd6chTggYBy9kAVV +8XZW2qncVnACqNz+kgHCJAD01MPjYNQ08Ko4vsk5dL/STOscFzVTRXwh211VCSTogyl EnpYe8+3So1BmKC1mx4ZNHUsTjO3Fc3V/9FAHftQSTZkJHUBqv/QOrVbimfl4jO/9uUX Eq6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=hQq/+3jqAtLxzZd6175GBBSWucnabx+T9S8n8vEc/7E=; b=DpBhLfZ3K2exTBYe8sVP0kf/g6b14/kAn2t0dRjthmtK4ljekQs3knFIC1gePfp0Gw IXr8WuG0W3e3rcRaCY5eVO/dvodQX9zSuSroB/fArBKarP6YvWQzkT63JpToz9PSD6In +FODi0Nz7NVTBqYl7BX4YPFcG8VBO5V9NhQ9CjwwNNkdeWJ3AK2LUshABRAjzNx3+Mku 42JctZaGrtfm2RN/jubjwfP6QsrDSbnK+K+9JlqH+RTTvE48UQ4oLYhXK5m6IPSPV1mR jF0r+XUfIO2C2tZPnhGqezbgDH4CBG6a6q+UWw25xRR8zCYawdQZ6uVYrduiVfXHeu3w p14w== X-Gm-Message-State: ACgBeo2aaLAk6MIniEwZA9QxGlKFIN7r6T4+k3m8WKPiYWkCNvBdzGyv XSNKRG5vCE4or51kVDnNI8DDX7IrGxA= X-Google-Smtp-Source: AA6agR6S9PT/FbJttXFunhb7MD0inQQ7RAVwZJZfCrTvSJUs0X9mSM2qqNkkaBm4VgVbOphsxXh3Jw== X-Received: by 2002:a05:600c:1e8d:b0:3a5:e37f:6fd2 with SMTP id be13-20020a05600c1e8d00b003a5e37f6fd2mr6130353wmb.33.1660858855908; Thu, 18 Aug 2022 14:40:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k6-20020a5d6d46000000b00225221fd286sm2342201wri.114.2022.08.18.14.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:40:55 -0700 (PDT) Message-Id: <2f6cad8361324cecdb0ee7b13a96477a8317c358.1660858853.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:46 +0000 Subject: [PATCH v3 1/8] scalar: constrain enlistment search Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Make the search for repository and enlistment root in 'setup_enlistment_directory()' more constrained to simplify behavior and adhere to 'GIT_CEILING_DIRECTORIES'. Previously, 'setup_enlistment_directory()' would check whether the provided path (or current working directory) '' or its subdirectory '/src' was a repository root. If not, the process would repeat on the parent of '' until the repository was found or it reached the root of the filesystem. This meant that a user could specify a path *anywhere* inside an enlistment (including paths not in the repository contained within the enlistment) and it would be found. The downside to this process is that the search would not account for 'GIT_CEILING_DIRECTORIES', so the upward search could result in modifying repository contents past 'GIT_CEILING_DIRECTORIES'. Similarly, operations like 'scalar delete' could end up unintentionally deleting the parent of a repo if its root was named 'src'. To make this 'setup_enlistment_directory()' both adhere to 'GIT_CEILING_DIRECTORIES' and avoid unwanted deletions, the search for an enlistment directory is simplified to: - if '/src' is a repository root, '' is the enlistment root - if '' is either the repository root or contained within a repository, the repository root is the enlistment root Now, only 'setup_git_directory()' (called by 'setup_enlistment_directory()') searches upwards from the 'scalar' specified path, enforcing 'GIT_CEILING_DIRECTORIES' in the process. Additionally, 'scalar delete /src' will not delete '' (if users would like to delete it, they can still specify the enlistment root with 'scalar delete '). This is true of any 'scalar' operation; users can invoke 'scalar' on the enlistment root, but paths must otherwise be inside the repository to be valid. To help clarify the updated behavior, new tests are added to 't9099-scalar.sh'. Finally, this change leaves 'strbuf_parent_directory()' with only a single, WIN32-specific caller in 'delete_enlistment()'. Rather than wrap 'strbuf_parent_directory()' in '#ifdef WIN32' to avoid the "unused function" compiler error, move the contents of 'strbuf_parent_directory()' into 'delete_enlistment()' and remove the function. Helped-by: Derrick Stolee Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 82 +++++++++++------------------- contrib/scalar/t/t9099-scalar.sh | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 54 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 97e71fe19cd..92b648f3511 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -14,29 +14,14 @@ #include "archive.h" #include "object-store.h" -/* - * Remove the deepest subdirectory in the provided path string. Path must not - * include a trailing path separator. Returns 1 if parent directory found, - * otherwise 0. - */ -static int strbuf_parent_directory(struct strbuf *buf) -{ - size_t len = buf->len; - size_t offset = offset_1st_component(buf->buf); - char *path_sep = find_last_dir_sep(buf->buf + offset); - strbuf_setlen(buf, path_sep ? path_sep - buf->buf : offset); - - return buf->len < len; -} - static void setup_enlistment_directory(int argc, const char **argv, const char * const *usagestr, const struct option *options, struct strbuf *enlistment_root) { struct strbuf path = STRBUF_INIT; - char *root; - int enlistment_found = 0; + int enlistment_is_repo_parent = 0; + size_t len; if (startup_info->have_repository) BUG("gitdir already set up?!?"); @@ -49,51 +34,36 @@ static void setup_enlistment_directory(int argc, const char **argv, strbuf_add_absolute_path(&path, argv[0]); if (!is_directory(path.buf)) die(_("'%s' does not exist"), path.buf); + if (chdir(path.buf) < 0) + die_errno(_("could not switch to '%s'"), path.buf); } else if (strbuf_getcwd(&path) < 0) die(_("need a working directory")); strbuf_trim_trailing_dir_sep(&path); - do { - const size_t len = path.len; - - /* check if currently in enlistment root with src/ workdir */ - strbuf_addstr(&path, "/src"); - if (is_nonbare_repository_dir(&path)) { - if (enlistment_root) - strbuf_add(enlistment_root, path.buf, len); - - enlistment_found = 1; - break; - } - /* reset to original path */ - strbuf_setlen(&path, len); - - /* check if currently in workdir */ - if (is_nonbare_repository_dir(&path)) { - if (enlistment_root) { - /* - * If the worktree's directory's name is `src`, the enlistment is the - * parent directory, otherwise it is identical to the worktree. - */ - root = strip_path_suffix(path.buf, "src"); - strbuf_addstr(enlistment_root, root ? root : path.buf); - free(root); - } + /* check if currently in enlistment root with src/ workdir */ + len = path.len; + strbuf_addstr(&path, "/src"); + if (is_nonbare_repository_dir(&path)) { + enlistment_is_repo_parent = 1; + if (chdir(path.buf) < 0) + die_errno(_("could not switch to '%s'"), path.buf); + } + strbuf_setlen(&path, len); - enlistment_found = 1; - break; - } - } while (strbuf_parent_directory(&path)); + setup_git_directory(); - if (!enlistment_found) - die(_("could not find enlistment root")); + if (!the_repository->worktree) + die(_("Scalar enlistments require a worktree")); - if (chdir(path.buf) < 0) - die_errno(_("could not switch to '%s'"), path.buf); + if (enlistment_root) { + if (enlistment_is_repo_parent) + strbuf_addbuf(enlistment_root, &path); + else + strbuf_addstr(enlistment_root, the_repository->worktree); + } strbuf_release(&path); - setup_git_directory(); } static int run_git(const char *arg, ...) @@ -431,6 +401,8 @@ static int delete_enlistment(struct strbuf *enlistment) { #ifdef WIN32 struct strbuf parent = STRBUF_INIT; + size_t offset; + char *path_sep; #endif if (unregister_dir()) @@ -441,8 +413,10 @@ static int delete_enlistment(struct strbuf *enlistment) * Change the current directory to one outside of the enlistment so * that we may delete everything underneath it. */ - strbuf_addbuf(&parent, enlistment); - strbuf_parent_directory(&parent); + offset = offset_1st_component(enlistment->buf); + path_sep = find_last_dir_sep(enlistment->buf + offset); + strbuf_add(&parent, enlistment->buf, + path_sep ? path_sep - enlistment->buf : offset); if (chdir(parent.buf) < 0) die_errno(_("could not switch to '%s'"), parent.buf); strbuf_release(&parent); diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 10b1172a8aa..c069cffebfe 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -17,6 +17,91 @@ test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' +test_expect_success 'scalar invoked on enlistment root' ' + test_when_finished rm -rf test src deeper && + + for enlistment_root in test src deeper/test + do + git init ${enlistment_root}/src && + + # Register + scalar register ${enlistment_root} && + scalar list >out && + grep "$(pwd)/${enlistment_root}/src\$" out && + + # Delete (including enlistment root) + scalar delete $enlistment_root && + test_path_is_missing $enlistment_root && + scalar list >out && + ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1 + done +' + +test_expect_success 'scalar invoked on enlistment src repo' ' + test_when_finished rm -rf test src deeper && + + for enlistment_root in test src deeper/test + do + git init ${enlistment_root}/src && + + # Register + scalar register ${enlistment_root}/src && + scalar list >out && + grep "$(pwd)/${enlistment_root}/src\$" out && + + # Delete (will not include enlistment root) + scalar delete ${enlistment_root}/src && + test_path_is_dir $enlistment_root && + scalar list >out && + ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1 + done +' + +test_expect_success 'scalar invoked when enlistment root and repo are the same' ' + test_when_finished rm -rf test src deeper && + + for enlistment_root in test src deeper/test + do + git init ${enlistment_root} && + + # Register + scalar register ${enlistment_root} && + scalar list >out && + grep "$(pwd)/${enlistment_root}\$" out && + + # Delete (will not include enlistment root) + scalar delete ${enlistment_root} && + test_path_is_missing $enlistment_root && + scalar list >out && + ! grep "^$(pwd)/${enlistment_root}\$" out && + + # Make sure we did not accidentally delete the trash dir + test_path_is_dir "$TRASH_DIRECTORY" || return 1 + done +' + +test_expect_success 'scalar repo search respects GIT_CEILING_DIRECTORIES' ' + test_when_finished rm -rf test && + + git init test/src && + mkdir -p test/src/deep && + GIT_CEILING_DIRECTORIES="$(pwd)/test/src" && + ! scalar register test/src/deep 2>err && + grep "not a git repository" err +' + +test_expect_success 'scalar enlistments need a worktree' ' + test_when_finished rm -rf bare test && + + git init --bare bare/src && + ! scalar register bare/src 2>err && + grep "Scalar enlistments require a worktree" err && + + git init test/src && + ! scalar register test/src/.git 2>err && + grep "Scalar enlistments require a worktree" err +' + test_expect_success 'scalar unregister' ' git init vanish/src && scalar register vanish/src && From patchwork Thu Aug 18 21:40:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73BB8C00140 for ; Thu, 18 Aug 2022 21:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244314AbiHRVlI (ORCPT ); Thu, 18 Aug 2022 17:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345730AbiHRVk7 (ORCPT ); Thu, 18 Aug 2022 17:40:59 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BD3FBD741 for ; Thu, 18 Aug 2022 14:40:59 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ba1so3142564wrb.5 for ; Thu, 18 Aug 2022 14:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=Pmssy3NMTu/rhL8RVFQSIiSxL7vJcmdwCs/n+zYEl+0=; b=gNbfHMIIM8jDCrD9+jiSK2MzDqg3tDoybh23xSXm1BfFuZnXv+RpxqxsaIs9XPEvy7 OXZ93QMIMpsyZ63vuHEsIelOW3vCoRynN7aH86sPJ9L62WSxVPVOAvyZOCNwn/dqM/bl BqjnffZaDFCsiqiJ9A8MCmQ58xU0eT8bwaqbb5RcNiOc7fu8XBc7mFsD1vyGokyJcRR4 +57l+fHLzDJtMPQfaSYYzU+tskvtvb91cOFCeWNsqX/IRH12vsSfzPK4DQBFrbUg+Tjv IejqDq1LKULNC8Iq/1I0ajBdNvsAOn+7Gqa9PAE0/Rl7Mb57W5FYN0Bd9x9YQF+TRfH2 g0IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=Pmssy3NMTu/rhL8RVFQSIiSxL7vJcmdwCs/n+zYEl+0=; b=hmwqSj0/qSH1iZ6IJTticyZzA7VWQIo17gni4P64RSqWCM96uVN2t38sroDxa8jSR/ 4NKnmgulsgBAwsOFb134TCdNmLnpPL3oN2PvMTO1HYgivEO4YWMpeld+/AmBn/S9fkRo MC8V4cOxg3Tpsl8WjP+35dzFfkgh0sdTJSTxj+7gPqaXzMw3C0mowbEqQuMVDKam2DKj iQGTnw3cGeVTtQOkWBWn1aG2jQ5XrbvIC5aIXMBCCaAcCxMb6GOFJ3hMvxh9BpQS0Q2/ DniINCwOFCj5ManjVGP9AI9SdJTYyicOM3Hf6+QvdQOhqFJYr9OwaPxIF0IwleJteLSz e+RA== X-Gm-Message-State: ACgBeo05lzNmESrdzo2BT3aboZQjF6mhPUA44hp7M5jpA/0YteNC0T09 mgPSj5+wCYagJd0wzAW5STT4JKUF4PA= X-Google-Smtp-Source: AA6agR4/L4jeSJxSAUbycGGZCMv9u3ZNSnZXL5z19gvHOxb4NvSD333+zOg4wQJdpg3oJSlyCFvHyw== X-Received: by 2002:a5d:5989:0:b0:221:7c34:3943 with SMTP id n9-20020a5d5989000000b002217c343943mr2425847wri.441.1660858857332; Thu, 18 Aug 2022 14:40:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id az14-20020a05600c600e00b003a536d5aa2esm3474032wmb.11.2022.08.18.14.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:40:56 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:47 +0000 Subject: [PATCH v3 2/8] scalar-unregister: handle error codes greater than 0 Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye When 'scalar unregister' tries to disable maintenance and remove an enlistment, ensure that the return value is nonzero if either operation produces *any* nonzero return value, not just when they return a value less than 0. Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 92b648f3511..8ef8dd55041 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -223,10 +223,10 @@ static int unregister_dir(void) { int res = 0; - if (toggle_maintenance(0) < 0) + if (toggle_maintenance(0)) res = -1; - if (add_or_remove_enlistment(0) < 0) + if (add_or_remove_enlistment(0)) res = -1; return res; From patchwork Thu Aug 18 21:40:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D8E3C00140 for ; Thu, 18 Aug 2022 21:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347120AbiHRVlQ (ORCPT ); Thu, 18 Aug 2022 17:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347042AbiHRVlB (ORCPT ); Thu, 18 Aug 2022 17:41:01 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E854CBD28E for ; Thu, 18 Aug 2022 14:40:59 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e20so2655543wri.13 for ; Thu, 18 Aug 2022 14:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=tO6ZbNs8LLi+N880DSRDbPP1BK3ZQOfn9Rv9llB5YB8=; b=cnIxuYUWgqYULgjeB5eq7Ebhef8Ho5ehdAags91PlRjctgGO2oEme34LXBFDKjyMMd m2LLMnc3NG2lYUUbfflB494Rf0mzqSf5wpmt0Qn0TkDr2+EH5hI1bXsbKUvnMezTp3ib VUY9FhD303O0AhvBl5E6oLimgFgeFarcewhmLICj7sXN9F6G5e4hAvRnWHbPcmlsg+Nl qWoUOSaTSwu8qwx2gLm4tCDIRTqhFkmrRzKBHsvsv6Wze1iDe7QHiOUk0OgFFezsyZri qp2pcit9l7TW2zEt7Wb7zwE4fGx/4ymfqwhmADUdxA/G1Lmtmj7WIG3M4pfYzOgzxNQi GVAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=tO6ZbNs8LLi+N880DSRDbPP1BK3ZQOfn9Rv9llB5YB8=; b=1BMfdaB29jn0vifWbsC2dbFrO8thdPu76E5bS/vLcb/+rUHAiYZ6E6wmk4nG+Bdt2o EnItSGy3k6BrulJdiEpaNx5ClUp64O7NWQtMGusFjd3qjV72pzcBTNgxbt30qUlkWvqo dktvKG8EMu2HVx/nu/LuvdWDaaFRS8nAKISN1HGaOFhKgW9I2RNDDJZOSoc9XRy+OyE2 2jij5JtpCgHAYqQlYsIiAXI1ABLNUEcctqVmfY7H767AcxrAWzI88WYTvY1LJ43ggLa4 0eVBKdePTxFSAI1E24YD0NwE3bzNTD4Qkk+FFgHvpG78TC5w0I5zM61jRYSGwY181HNB bJxQ== X-Gm-Message-State: ACgBeo2L1gig0oEXFBUhsz4sp1YgJHvgSGIOChUJ+ovf7n6gEnSrdM1g uAHlSjZxzPMo6llio7gX39MJprViCBw= X-Google-Smtp-Source: AA6agR45YWCKNyjRyqPbl3MfiP6lT36nT1Sy2WxjXQZ87sEM29/CgVu6iK5IxzZSO/rB8sucUYTwiw== X-Received: by 2002:a5d:4204:0:b0:225:382f:a8be with SMTP id n4-20020a5d4204000000b00225382fa8bemr265896wrq.379.1660858858187; Thu, 18 Aug 2022 14:40:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4-20020a05600c3b0400b003a5ffec0b91sm3353599wms.30.2022.08.18.14.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:40:57 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:48 +0000 Subject: [PATCH v3 3/8] scalar-[un]register: clearly indicate source of error Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye When a step in 'register_dir()' or 'unregister_dir()' fails, indicate which step failed with an error message, rather than silently assigning a nonzero return code. Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 8ef8dd55041..7be2a938b0c 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -208,15 +208,16 @@ static int add_or_remove_enlistment(int add) static int register_dir(void) { - int res = add_or_remove_enlistment(1); + if (add_or_remove_enlistment(1)) + return error(_("could not add enlistment")); - if (!res) - res = set_recommended_config(0); + if (set_recommended_config(0)) + return error(_("could not set recommended config")); - if (!res) - res = toggle_maintenance(1); + if (toggle_maintenance(1)) + return error(_("could not turn on maintenance")); - return res; + return 0; } static int unregister_dir(void) @@ -224,10 +225,10 @@ static int unregister_dir(void) int res = 0; if (toggle_maintenance(0)) - res = -1; + res = error(_("could not turn off maintenance")); if (add_or_remove_enlistment(0)) - res = -1; + res = error(_("could not remove enlistment")); return res; } From patchwork Thu Aug 18 21:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8454EC00140 for ; Thu, 18 Aug 2022 21:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347088AbiHRVlS (ORCPT ); Thu, 18 Aug 2022 17:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347050AbiHRVlB (ORCPT ); Thu, 18 Aug 2022 17:41:01 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6AE5BD292 for ; Thu, 18 Aug 2022 14:41:00 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r16so3144398wrm.6 for ; Thu, 18 Aug 2022 14:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=jCcEN1Fq7Sov4sFy7+377W2MPZQJ/v3rAKdOKIPYXKw=; b=H3uARC2I2XEK7ItT+pNF0hxmjY2Erksholt9loPxeWDt4Li15jeXs+ZDV0Bsije7vi T4tIgmRCLNLWbP2Jx2l5PmUAL47w7CmVKxItN2PnmmjFe0JBTCPu2UPNmEi7VDC/7s1V FNAjshsxUiD3BJuKSCHZ6BYFE9x5DKiDfOHMviBZSACJqM0mGWcvQTIHfXpBFG33xyAO fFG8Zw6E4wsFprN8aHFjYPt75lkFD892yBliFtdkvHDIfqej+gJgd/MNoSfv1pn7gIpU CZB9FXBXRcFgTnIVMyZKyd2dFIXxP+vPxyov80rNbI+t11/P/U4TOib9iuvEJ7zxaFe5 PmSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=jCcEN1Fq7Sov4sFy7+377W2MPZQJ/v3rAKdOKIPYXKw=; b=046iIR4NiKHKYmoRETod3K/D5WBuoamWZtevNBmwASZH4ASh0apHxZRN+6eQA044+T BCJ1okg/JnJNMnPpOr33NfF4xQOfZ+yFu86SqrAB3qP4GdwSIh8wW+yCft5Y4+4rCTPt Ehdo/iwGhPeRX9WwcpzMf31MKsW7i5V+9y72UoCwIaSQQ06u6lrP6mKlGFJq6eu0NGSp tojS6vHa6W5MnD2wLMFhhfsleOdQumzTYyW0qcuP2rUcW+axX2mfe4wy70STiL66n2DG GXj/aKVQUR/9Ke8030nXLG5QMzzEK/I/yMKQvLlrylbOvuGX5TDlulrcuM8diIIeRBZm Z3TQ== X-Gm-Message-State: ACgBeo1hpgiwm5ibYh9BBfn8NOjXBpIRJam4775WnahrY3iT0xSHO6b3 NMWZcAddadKnD+nYIhrfQzSSmEL4CIY= X-Google-Smtp-Source: AA6agR4ey2MPfXm6yrhyKtLahYozv+IyYkgpf/lidhA4CNGG3u7pU+Uo2YVtp7sUPQS0FPOIFcLhBQ== X-Received: by 2002:a5d:588f:0:b0:220:761a:6894 with SMTP id n15-20020a5d588f000000b00220761a6894mr2642477wrf.406.1660858859074; Thu, 18 Aug 2022 14:40:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z17-20020a5d4411000000b002252e5a6841sm2342177wrq.57.2022.08.18.14.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:40:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:49 +0000 Subject: [PATCH v3 4/8] scalar-delete: do not 'die()' in 'delete_enlistment()' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Rather than exiting with 'die()' when 'delete_enlistment()' encounters an error, return an error code with the appropriate message. There's no need for an abrupt exit with 'die()' in 'delete_enlistment()' because its only caller ('cmd_delete()') properly cleans up allocated resources and returns the 'delete_enlistment()' return value as its own exit code. Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7be2a938b0c..6de4d5b3721 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -407,7 +407,7 @@ static int delete_enlistment(struct strbuf *enlistment) #endif if (unregister_dir()) - die(_("failed to unregister repository")); + return error(_("failed to unregister repository")); #ifdef WIN32 /* @@ -418,13 +418,16 @@ static int delete_enlistment(struct strbuf *enlistment) path_sep = find_last_dir_sep(enlistment->buf + offset); strbuf_add(&parent, enlistment->buf, path_sep ? path_sep - enlistment->buf : offset); - if (chdir(parent.buf) < 0) - die_errno(_("could not switch to '%s'"), parent.buf); + if (chdir(parent.buf) < 0) { + int res = error_errno(_("could not switch to '%s'"), parent.buf); + strbuf_release(&parent); + return res; + } strbuf_release(&parent); #endif if (remove_dir_recursively(enlistment, 0)) - die(_("failed to delete enlistment directory")); + return error(_("failed to delete enlistment directory")); return 0; } From patchwork Thu Aug 18 21:40:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 189F9C00140 for ; Thu, 18 Aug 2022 21:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347122AbiHRVlZ (ORCPT ); Thu, 18 Aug 2022 17:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347083AbiHRVlC (ORCPT ); Thu, 18 Aug 2022 17:41:02 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD7A3BD745 for ; Thu, 18 Aug 2022 14:41:01 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id k17so1459144wmr.2 for ; Thu, 18 Aug 2022 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=hpH7rRcpB5r5+82dVfRT2fIzHmCKUiujRgzjMBEYDl4=; b=Dt0PxXgWnD9fZ7r+c/21MxnSte6wewHrpmY9YtgjJlBlFca+eXttmzkFN+hxXP1DeN CoXyRcX/1up6aQh3SZ0ofUWDbOhLpicbI3tGh7gJXc89RiQNB3FnrkJ0HAQqW7sSkIls 72MGc/ENVvopJ4QnFUEYOXqnbdnWRHT2N0pZtym3duDpXrOF6HrEhMMo8IZZcLsfJfEw xGyEKbWeIdHJDOvPCxBCSB4Ta3TsoTtgQZVPAuJ50zg+Bn0COP1JcudVocn3Vk81cAqe fDbhiKL7ZSJRRBEgdBt0dXb8/zS1PL9y99LnOO6G7rRWY8jS87eQPNfIQGDcBC6k5WlV qpOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=hpH7rRcpB5r5+82dVfRT2fIzHmCKUiujRgzjMBEYDl4=; b=nMRh7cVP/qO+bCkzUTaCO+x6C5/73puFAVU0ME2OoDlfMEC6x259DgfRrDgViHyHdc eAWDn+lslY+x2Ltc1zFo0g3McQWkr7+wdFGOCEJZBD0O4MyycBJT98foYtRz/5QDjd0Y JE+u6XjLC59LhZKiomLYvA8ygmVlCy2W+lmvpmc4H/QBlIQjfZ68kcqRRqRirLxnzNxb UPRhHL1gR83phagFe24it8R/eg1OkNtoRkv1z85ccKc/FB8tOrIaO78afppkiObhI8th qYZ2UAmyhJColbA6K6L38IN9RMe4yOkofnQAv8O9rYesBgGmhyXuLngny+E7AonJXFOu XBVQ== X-Gm-Message-State: ACgBeo0SAdJm7bSA6/glJ9lvhdERecQ2yKqcFRhJ0chVX5TdTk+mgD7p hPVNsQ5j3fH2cF7/SRDYH/LS9NZxAhc= X-Google-Smtp-Source: AA6agR7qJWfv6cQdstLayM27+aKl/0IMpKBQPZaHi2Xa3tj+tLd9kZxz/whBAY8X3LKI61vM+zCK+A== X-Received: by 2002:a7b:c5c3:0:b0:3a6:14f3:8ea7 with SMTP id n3-20020a7bc5c3000000b003a614f38ea7mr2899524wmk.76.1660858859943; Thu, 18 Aug 2022 14:40:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z13-20020a5d44cd000000b00222ed7ea203sm2302217wrr.100.2022.08.18.14.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:40:59 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:50 +0000 Subject: [PATCH v3 5/8] scalar: move config setting logic into its own function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Create function 'set_scalar_config()' to contain the logic used in setting Scalar-defined Git config settings, including how to handle reconfiguring & overwriting existing values. This function allows future patches to set config values in parts of 'scalar.c' other than 'set_recommended_config()'. Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 6de4d5b3721..836a4c48fab 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -85,13 +85,33 @@ static int run_git(const char *arg, ...) return res; } +struct scalar_config { + const char *key; + const char *value; + int overwrite_on_reconfigure; +}; + +static int set_scalar_config(const struct scalar_config *config, int reconfigure) +{ + char *value = NULL; + int res; + + if ((reconfigure && config->overwrite_on_reconfigure) || + git_config_get_string(config->key, &value)) { + trace2_data_string("scalar", the_repository, config->key, "created"); + res = git_config_set_gently(config->key, config->value); + } else { + trace2_data_string("scalar", the_repository, config->key, "exists"); + res = 0; + } + + free(value); + return res; +} + static int set_recommended_config(int reconfigure) { - struct { - const char *key; - const char *value; - int overwrite_on_reconfigure; - } config[] = { + struct scalar_config config[] = { /* Required */ { "am.keepCR", "true", 1 }, { "core.FSCache", "true", 1 }, @@ -145,17 +165,9 @@ static int set_recommended_config(int reconfigure) char *value; for (i = 0; config[i].key; i++) { - if ((reconfigure && config[i].overwrite_on_reconfigure) || - git_config_get_string(config[i].key, &value)) { - trace2_data_string("scalar", the_repository, config[i].key, "created"); - if (git_config_set_gently(config[i].key, - config[i].value) < 0) - return error(_("could not configure %s=%s"), - config[i].key, config[i].value); - } else { - trace2_data_string("scalar", the_repository, config[i].key, "exists"); - free(value); - } + if (set_scalar_config(config + i, reconfigure)) + return error(_("could not configure %s=%s"), + config[i].key, config[i].value); } /* From patchwork Thu Aug 18 21:40:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew John Cheetham X-Patchwork-Id: 12948006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14AC8C32774 for ; Thu, 18 Aug 2022 21:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347121AbiHRVlV (ORCPT ); Thu, 18 Aug 2022 17:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347077AbiHRVlC (ORCPT ); Thu, 18 Aug 2022 17:41:02 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832AEBD4FB for ; Thu, 18 Aug 2022 14:41:01 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id m10-20020a05600c3b0a00b003a603fc3f81so1626253wms.0 for ; Thu, 18 Aug 2022 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=yzuv2QdF3zhXvvaGFJV0cq1X+N533hHlFfCUZvCGatQ=; b=P65jm6sx+GE+yO1ThFGDwWSTCuA9SMEkIbOalIyiUPmfVD1ks7JfzEVKzCsmyHtu8S QeO1ycQ4LqTaX52p9N+1SzbZ6HiuhFvSF9mfb6DNv7yGw7RPiXWvrERaMfUhoXf9I1wL gRpbojU+MZ0lEnUbJyTMtSiVUCUhNKxijnfVWrat66GSPNR6l3UGOQf9InGGPxs3hSkb YUTJVLZG00Cs79OvqQIIcRpjPyQFN3MgNwxrtXHugFcLQ6Dt2QZ2xJN2hRV04xanfJPI JXMulTdPcaFKpXuDQH80T7aqkT5WRCUG6hYW+2hXIFC+6Qtmjz8iOwjDUzMHidNLBkYN DA5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=yzuv2QdF3zhXvvaGFJV0cq1X+N533hHlFfCUZvCGatQ=; b=8QiPidnM/UL5+NZvGJuv+cX5Y0YlDuvCLshnkeqU0cbBMf0RnpoEmftMEZRv5T786E nkBQSBDmCOy+DMIcs+AAfrYZvqowcUvVI88fXhp+Ar8PN+/UAM032HcuK1Qsn71kc0UU NjAHPA13U/6k9G0kdKmJF+I1rgMSiFGMuyfBHlnrzA/U93GnkqvpXY5NioJgVo0i36no e+yP6euhgaqdWuW8TGE7QyHlAMwd+W5myQaHSRZfBQmAiicRYsLcVPcgapV7YkWnOStr AzmgTJpHYN6kWyg0Wlh11i6M3w6W2XV1mmy12yDgsMplbtBA9nRQk4hl/+/e+x9JHsll Kx2A== X-Gm-Message-State: ACgBeo266xYIHQcnGrwUBZRadyXgr2XG0UBGezB3A0WTdOGobYgidZfR 0iXGcicQHdsedQFTphlf+DRkMomegZo= X-Google-Smtp-Source: AA6agR72yJRjLrpFcOlzv0tvv8xcHBWIWZEBTHI+H74GGhF3w2d+G7CNG5LBBIEsfuSD4My+HfJOWg== X-Received: by 2002:a05:600c:4f01:b0:3a6:12a6:8d7 with SMTP id l1-20020a05600c4f0100b003a612a608d7mr5956663wmq.107.1660858860914; Thu, 18 Aug 2022 14:41:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm3798830wmq.42.2022.08.18.14.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:41:00 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:51 +0000 Subject: [PATCH v3 6/8] scalar: enable built-in FSMonitor on `register` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Matthew John Cheetham Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew John Cheetham From: Matthew John Cheetham Using the built-in FSMonitor makes many common commands quite a bit faster. So let's teach the `scalar register` command to enable the built-in FSMonitor and kick-start the fsmonitor--daemon process (for convenience). For simplicity, we only support the built-in FSMonitor (and no external file system monitor such as e.g. Watchman). Helped-by: Junio C Hamano Helped-by: Derrick Stolee Signed-off-by: Matthew John Cheetham Signed-off-by: Johannes Schindelin Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 30 ++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 836a4c48fab..73cd5b1fd0c 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -7,6 +7,9 @@ #include "parse-options.h" #include "config.h" #include "run-command.h" +#include "simple-ipc.h" +#include "fsmonitor-ipc.h" +#include "fsmonitor-settings.h" #include "refs.h" #include "dir.h" #include "packfile.h" @@ -109,6 +112,12 @@ static int set_scalar_config(const struct scalar_config *config, int reconfigure return res; } +static int have_fsmonitor_support(void) +{ + return fsmonitor_ipc__is_supported() && + fsm_settings__get_reason(the_repository) == FSMONITOR_REASON_OK; +} + static int set_recommended_config(int reconfigure) { struct scalar_config config[] = { @@ -170,6 +179,13 @@ static int set_recommended_config(int reconfigure) config[i].key, config[i].value); } + if (have_fsmonitor_support()) { + struct scalar_config fsmonitor = { "core.fsmonitor", "true" }; + if (set_scalar_config(&fsmonitor, reconfigure)) + return error(_("could not configure %s=%s"), + fsmonitor.key, fsmonitor.value); + } + /* * The `log.excludeDecoration` setting is special because it allows * for multiple values. @@ -218,6 +234,16 @@ static int add_or_remove_enlistment(int add) "scalar.repo", the_repository->worktree, NULL); } +static int start_fsmonitor_daemon(void) +{ + assert(have_fsmonitor_support()); + + if (fsmonitor_ipc__get_state() != IPC_STATE__LISTENING) + return run_git("fsmonitor--daemon", "start", NULL); + + return 0; +} + static int register_dir(void) { if (add_or_remove_enlistment(1)) @@ -229,6 +255,10 @@ static int register_dir(void) if (toggle_maintenance(1)) return error(_("could not turn on maintenance")); + if (have_fsmonitor_support() && start_fsmonitor_daemon()) { + return error(_("could not start the FSMonitor daemon")); + } + return 0; } diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index c069cffebfe..365eab9b54f 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -102,6 +102,14 @@ test_expect_success 'scalar enlistments need a worktree' ' grep "Scalar enlistments require a worktree" err ' +test_expect_success FSMONITOR_DAEMON 'scalar register starts fsmon daemon' ' + git init test/src && + test_must_fail git -C test/src fsmonitor--daemon status && + scalar register test/src && + git -C test/src fsmonitor--daemon status && + test_cmp_config -C test/src true core.fsmonitor +' + test_expect_success 'scalar unregister' ' git init vanish/src && scalar register vanish/src && From patchwork Thu Aug 18 21:40:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12948009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16E38C28B2B for ; Thu, 18 Aug 2022 21:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347124AbiHRVl2 (ORCPT ); Thu, 18 Aug 2022 17:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346097AbiHRVlP (ORCPT ); Thu, 18 Aug 2022 17:41:15 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66078BD74C for ; Thu, 18 Aug 2022 14:41:03 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id u14so3131384wrq.9 for ; Thu, 18 Aug 2022 14:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=mVZa75vdeexj9hvzw+Wn4JTLrvo13EP5x/B/OGDiGZ4=; b=NKzDvsR1ipZ4CUr+hVTgl+YpbBJP5++GPEbx4NZv2iDqDAzmv/beObECzIpZsTLHnq nDU2eWOKrucDwCgXPZK1BJGBVU6ZOQ26sGDickxJ7y9nzhH2NEIMD5Bw56tLA0UFA6kQ WMCB58H0STi3jYjS8+D91i+g/jpJF+d94aYOyLVlfemvokcca3Yqoi0M56DYF7kA/ssp Zpk8DpWyGhsGrHBbcWGaHak/4Hs9MLAvlQ4Dl0PX53MYdDyZAxZtjjyXQ55o0IcT8bmP YoonVNMrjB7deusKlpU7Te+0IB1mEilOBn6gh279xdRv+RswacqLrE5OPZ1+VtFETQft bbyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=mVZa75vdeexj9hvzw+Wn4JTLrvo13EP5x/B/OGDiGZ4=; b=k2PYbF1JkpOLvXznJwM9lo2f1yoaRRm/woCEVbHHmcnUuSsZtvbrOhYJxDwcm3xd4G AqvrS3XkJngcbpaJlWL5DAmYcSLr6UlV8uLLk99+ZYctZ8q2B7C6tUAGAVG+cUbDW1E/ f+yUi2Uxm2kXOLvf7RRXV1Hu73LcFhWt3/VkqsRztnxHeOGMtS/byx6jDAhkeIJyt9ag 9l/xFydNyKVUqWiIwtAIRSdp1Wedej80yqTITI04MRyggPWV7FgCQmdwIR8HE9AwsyaI PrQL6HGz54Ini8kk5g3d/yKzeldJVLbIK8kjsYSCLYg1P5XIIBj3rNmomf29VQz68+NV 73Yg== X-Gm-Message-State: ACgBeo0NaTJqlIsJuety7m904+ADwJU+g1/kZy7s+fCZio1jnA0TWDGW oWqIlCsxWubtxkcCzSelafiIjC+Q/f8= X-Google-Smtp-Source: AA6agR5lp5zgT37FIN+mwRhS94AAURKRPkIoK7A6EjTQNOHG4B4fd4kVtoqBtNbujgdgtsEMUCCFDg== X-Received: by 2002:a5d:47c4:0:b0:21f:e92:7ba1 with SMTP id o4-20020a5d47c4000000b0021f0e927ba1mr2523096wrc.408.1660858861799; Thu, 18 Aug 2022 14:41:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a14-20020adfed0e000000b0022511d35d5bsm2446418wro.12.2022.08.18.14.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:41:01 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:52 +0000 Subject: [PATCH v3 7/8] scalar unregister: stop FSMonitor daemon Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Especially on Windows, we will need to stop that daemon, just in case that the directory needs to be removed (the daemon would otherwise hold a handle to that directory, preventing it from being deleted). Helped-by: Junio C Hamano Signed-off-by: Johannes Schindelin Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 73cd5b1fd0c..07c3f7dd6b6 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -244,6 +244,16 @@ static int start_fsmonitor_daemon(void) return 0; } +static int stop_fsmonitor_daemon(void) +{ + assert(have_fsmonitor_support()); + + if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) + return run_git("fsmonitor--daemon", "stop", NULL); + + return 0; +} + static int register_dir(void) { if (add_or_remove_enlistment(1)) @@ -468,6 +478,9 @@ static int delete_enlistment(struct strbuf *enlistment) strbuf_release(&parent); #endif + if (have_fsmonitor_support() && stop_fsmonitor_daemon()) + return error(_("failed to stop the FSMonitor daemon")); + if (remove_dir_recursively(enlistment, 0)) return error(_("failed to delete enlistment directory")); From patchwork Thu Aug 18 21:40:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12948007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96D38C00140 for ; Thu, 18 Aug 2022 21:41:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347077AbiHRVlW (ORCPT ); Thu, 18 Aug 2022 17:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345730AbiHRVlP (ORCPT ); Thu, 18 Aug 2022 17:41:15 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47816BD747 for ; Thu, 18 Aug 2022 14:41:03 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e20so2655673wri.13 for ; Thu, 18 Aug 2022 14:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=zYjewUCZigt4BLK5UfZbPXOdu2JYJk63IMi8RktRvQI=; b=K7DGYUmKzU6s4FHSvg2YMWqxB0namCMuYiK9antuTUYlun4+GAdcKCMTVfp2zj7NZ4 OAz2ZeJK32DP0yptzx10o+o38Lk6NO5oyIGJECki1at7Uqk4m2jO/OEcv9479Ve1hgXZ dbAhTr1kBjGWD/YElqV/x0XO7A6j9qyCp7XvrMZDkwhs4yNV0H7CfovTqPCb0wm/TNI9 pCAS8QEmj0A6RwHp6xz+1DW7ow52uUm9oXra2z0mSLJOrvzWtas3sdSbHo6FY7SFAw57 psya8OQ31CfmZhUBFLRadQtLYgWt9J3NuRo8DO49zgUOxohDyRhIdhajKUQqzVLZMlns 1tqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=zYjewUCZigt4BLK5UfZbPXOdu2JYJk63IMi8RktRvQI=; b=kL885cxRNe9VsGlM+52MgcxmaX5vu+UyQmspQmujgHstuMhPCROOCSdaHgOcTpeS3l 0t/rl6T5yHo8CpQupkV7QHPBACudb+dTgFEnonQF8XgiP26B0wdWNYs1veoipLTTPxSK H89rJdylxe1cvNbdWsnZxSzDnjIli60DmQw7z1Lg5wIts5aCe13JZVltvSiGQRHQ7/2P XWknrTRnluwg86/7kRkHadSO2oa29RwNhPXtqOQQq+LIr5RnQpYDNYkkYDvvemXi4BsP mxDGv96UMLzEFrT2w4DdvQ01Yr/SXoM62SXgwigHYWXpaeVFXspJaoFtbBrmNiUNfPI4 3j6Q== X-Gm-Message-State: ACgBeo3umVLJncxJH2v9t4FGuSBDRp+Nat80TPV+4CnIzl8rpEUrV/0M F6j4ErLbjYXdp4fL8QdIOjb2xvtzknE= X-Google-Smtp-Source: AA6agR5kvaXHo0IePVs/Iv3Mr9cZvWCvMYN0i08Fqtj2erz0fa4e5vjL0jKdMSY7KRKJSpTAAnFKWw== X-Received: by 2002:a05:6000:2a9:b0:222:c186:caa5 with SMTP id l9-20020a05600002a900b00222c186caa5mr2611718wry.91.1660858862578; Thu, 18 Aug 2022 14:41:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q22-20020a1ce916000000b003a531c7aa66sm3407435wmc.1.2022.08.18.14.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 14:41:02 -0700 (PDT) Message-Id: <7cee014e2d2b9140a81125928d388af732783143.1660858853.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 18 Aug 2022 21:40:53 +0000 Subject: [PATCH v3 8/8] scalar: update technical doc roadmap with FSMonitor support Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: johannes.schindelin@gmx.de, mjcheetham@outlook.com, gitster@pobox.com, Derrick Stolee , Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Update the Scalar roadmap to reflect completion of enabling the built-in FSMonitor in Scalar. Note that implementation of 'scalar help' was moved to the final set of changes to move Scalar out of 'contrib/'. This is due to a dependency on changes to 'git help', as all changes to the main Git tree *exclusively* implemented to support Scalar are part of that series. Signed-off-by: Victoria Dye --- Documentation/technical/scalar.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Documentation/technical/scalar.txt b/Documentation/technical/scalar.txt index 08bc09c225a..047390e46eb 100644 --- a/Documentation/technical/scalar.txt +++ b/Documentation/technical/scalar.txt @@ -84,13 +84,13 @@ series have been accepted: - `scalar-diagnose`: The `scalar` command is taught the `diagnose` subcommand. +- 'scalar-add-fsmonitor: Enable the built-in FSMonitor in Scalar + enlistments. At the end of this series, Scalar should be feature-complete + from the perspective of a user. + Roughly speaking (and subject to change), the following series are needed to "finish" this initial version of Scalar: -- Finish Scalar features: Enable the built-in FSMonitor in Scalar enlistments - and implement `scalar help`. At the end of this series, Scalar should be - feature-complete from the perspective of a user. - - Generalize features not specific to Scalar: In the spirit of making Scalar configure only what is needed for large repo performance, move common utilities into other parts of Git. Some of this will be internal-only, but one @@ -98,9 +98,12 @@ Roughly speaking (and subject to change), the following series are needed to repository. - Move Scalar to toplevel: Move Scalar out of `contrib/` and into the root of - `git`, including updates to build and install it with the rest of Git. This - change will incorporate Scalar into the Git CI and test framework, as well as - expand regression and performance testing to ensure the tool is stable. + `git`. This includes a variety of related updates, including: + - building & installing Scalar in the Git root-level 'make [install]'. + - builing & testing Scalar as part of CI. + - moving and expanding test coverage of Scalar (including perf tests). + - implementing 'scalar help'/'git help scalar' to display scalar + documentation. Finally, there are two additional patch series that exist in Microsoft's fork of Git, but there is no current plan to upstream them. There are some interesting