From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA891C4321E for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAA4961C32 for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238515AbhKQOXO (ORCPT ); Wed, 17 Nov 2021 09:23:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238414AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D971C061227 for ; Wed, 17 Nov 2021 06:19:37 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso4940951wms.3 for ; Wed, 17 Nov 2021 06:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qaR47xznf9Xy5jW3JgfZrlmIasnjgC8KJcW13Zq+3oA=; b=Vo1O2dOqL1pxDQZ3rXUOMR91BmsdhWS7GF/25aiKhetlOZuiqMdXouUaimZBNKsUGM 6InmltzSvoyD4B4tBUx5dTFZml+/XXNFUcXy0rqs/xS8sTIPU2aprDWiqTJ5s6FI5CMY WFpUw5Cd3Ew/StiVUSGB2d6N4l+LuDsEDVpIfQ+qu+16HiHiZtTiSPtAXV6bro6CIHAx FHS7cleY38gylYIttQP3VZzKGf5N1iuECwjAnZgP4kGotn3glKRSK4phjicRK3eSvnwj W55cwwATXeptcZ+2zjjfmuOWNdDhH/VpSBPjYEYbFe1cS8UZKISPwLClb+3agopMV4cZ tunQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qaR47xznf9Xy5jW3JgfZrlmIasnjgC8KJcW13Zq+3oA=; b=b5HKkM3QuuyHgo8sMxJ6EXZ2X1pLKNhnnnAHNXGHIiDbLxFKgIM53rv/uYVfpHeg+/ F0jt4feVhtuhQjXtlhQVxMA3RPgpH/T2Td16WysUTJLtXTKL1bbGMFA04cjR3/OxnqZe DRZ8ntqA59bD7hsZZjV14wdAkJLHaT+3UA2P6ppHKRPSINcjz4Bw3j0sw1k3OsQp0tGb SFO8dNLg7WGbCMfoAu89h7Ma1XO68tU9lq+UynTwf3yp791aC6yKkMdVrbSKqIuJ+bej HXAVxc6S/GGMReD5UIlnWsZYiK2VWE2TFJ1/SIuQzvI+3SLFAVPArCzO025rzVbnPVMe dpLg== X-Gm-Message-State: AOAM532Wg0fb8kICGV6xQipHozAFjbit1gnXdxLOemHk3yBov9Op0aRH WbFIVd6cK57Aa8zenlb6GWel44BYd4c= X-Google-Smtp-Source: ABdhPJz1F3kwyFYUKMz7Vl8ahb8gclauQet2OASFAyrQRwVstBd+XP8uijkzODvp+sgnMKin+7QYzQ== X-Received: by 2002:a05:600c:5101:: with SMTP id o1mr79902170wms.81.1637158775815; Wed, 17 Nov 2021 06:19:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i15sm6728642wmq.18.2021.11.17.06.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:35 -0800 (PST) Message-Id: <9fea89cd161bfa6facdc142402b2098d2de463ef.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Wed, 17 Nov 2021 14:19:13 +0000 Subject: [PATCH v7 08/17] scalar: 'unregister' stops background maintenance Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?UTF-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Just like `scalar register` starts the scheduled background maintenance, `scalar unregister` stops it. Note that we use `git maintenance start` in `scalar register`, but we do not use `git maintenance stop` in `scalar unregister`: this would stop maintenance for _all_ repositories, not just for the one we want to unregister. The `unregister` command also removes the corresponding entry from the `[scalar]` section in the global Git config. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 50 ++++++++++++++++++++++++++++++++------- contrib/scalar/scalar.txt | 8 +++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 03d5f84c764..bab0271c37d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -198,12 +198,12 @@ static int set_recommended_config(void) return 0; } -static int start_maintenance(void) +static int toggle_maintenance(int enable) { - return run_git("maintenance", "start", NULL); + return run_git("maintenance", enable ? "start" : "unregister", NULL); } -static int add_enlistment(void) +static int add_or_remove_enlistment(int add) { int res; @@ -214,24 +214,39 @@ static int add_enlistment(void) "scalar.repo", the_repository->worktree, NULL); /* - * If the setting is already there, then do nothing. + * If we want to add and the setting is already there, then do nothing. + * If we want to remove and the setting is not there, then do nothing. */ - if (!res) + if ((add && !res) || (!add && res)) return 0; - return run_git("config", "--global", "--add", + return run_git("config", "--global", add ? "--add" : "--unset", + add ? "--no-fixed-value" : "--fixed-value", "scalar.repo", the_repository->worktree, NULL); } static int register_dir(void) { - int res = add_enlistment(); + int res = add_or_remove_enlistment(1); if (!res) res = set_recommended_config(); if (!res) - res = start_maintenance(); + res = toggle_maintenance(1); + + return res; +} + +static int unregister_dir(void) +{ + int res = 0; + + if (toggle_maintenance(0) < 0) + res = -1; + + if (add_or_remove_enlistment(0) < 0) + res = -1; return res; } @@ -254,11 +269,30 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_unregister(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar unregister []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return unregister_dir(); +} + static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { { "register", cmd_register }, + { "unregister", cmd_unregister }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 568987064b2..d9a79984492 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] scalar register [] +scalar unregister [] DESCRIPTION ----------- @@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +Unregister +~~~~~~~~~~ + +unregister []:: + Remove the specified repository from the list of repositories + registered with Scalar and stop the scheduled background maintenance. + SEE ALSO -------- linkgit:git-maintenance[1]. -- gitgitgadget