From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 042571F8C6 for ; Wed, 8 Sep 2021 19:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350984AbhIHT0G (ORCPT ); Wed, 8 Sep 2021 15:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350585AbhIHTZ7 (ORCPT ); Wed, 8 Sep 2021 15:25:59 -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 87B51C06175F for ; Wed, 8 Sep 2021 12:24:51 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j17-20020a05600c1c1100b002e754875260so2340228wms.4 for ; Wed, 08 Sep 2021 12:24:51 -0700 (PDT) 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=IkkeDf4dwAribAhlx2PhCXXfAwpmH50TJZppSlNsCLU=; b=bc16jrevq+1mSSKh2XSJYG3iuuRWRCdWnkIbC4MsYqTxgtbqJLxri4TgkERNpwsGt1 3bOQjdE+mLJPnH+5geXb8iQ2e79RULmW3DiO0Hk5CgS8FzBhCZt93eA20bUB0DPeNkXk AeF+JpvLPdQh/b/gEKI3staHz/AcNGy8fnRZ6mcGXCU1HGxWhRtW81ZbrSTnhS7S0nGm GAzbrcMyNB9lY5zfuN+oA01643Bjwe3nSNTC5+Q8IATHN2NM6YmhTgPA412/wwz7lRPx Yo7oRnZOObjFE394ORAmmBLvb7fSBwAszqGgZA66WK4UplFcUy8h8ZSYyyL8joFe8QLA RWdg== 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=IkkeDf4dwAribAhlx2PhCXXfAwpmH50TJZppSlNsCLU=; b=udkEmtxhX2c+jJwbyvFeSg3NRK1aQI7xONieNZYRwjLynDV719/lZTlVxvrX1LqZ3k 614klRbywrrGNQ8XGcELd5AsT8AFN+PCmc0v5+vcJQnqluM7FGzyJwzl8F7Q5egUwevf r+fTrU3FQRGxUtrX8GMDb3JBKBrk2OP/bpDChmrFaUHk72e9BkR1vHJudYDv/Ih1YJiN wWMS9WK6dSk18rfnNXT9ofkaeRoFkYFbDz/J3XGC1QJoh121tUerX+qFM1fb5XxCwaTv pAJCfhsZPKV8sStWy+aJ+q6jqbraVbZAbsYToF9qEa7UP6dTzNj/4eUBsfAfDdN7WFpb wu3w== X-Gm-Message-State: AOAM531rIaV+kwSzpzmvOYuIhhaaF8tnP38Q5xnUutUL5rxvw3UhUwRN PTGe56GZLbaZ1Wl1WS1Jmk3OjRHaNyM= X-Google-Smtp-Source: ABdhPJzS66ZkpaQ8j2Qq7KI7pmPWLwZBlYZ8rWq3Zv4xst48FBfEAYDNjunHvLUyTIQYZXtT3oaBVw== X-Received: by 2002:a1c:f606:: with SMTP id w6mr5173480wmc.42.1631129090197; Wed, 08 Sep 2021 12:24:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g11sm22512wrx.30.2021.09.08.12.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:49 -0700 (PDT) Message-Id: <6142f75875b8245c93230e141be3664253e2137b.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Wed, 08 Sep 2021 19:24:35 +0000 Subject: [PATCH v3 05/15] 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 , 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 0e627bb100e..2b5c52a25f5 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -204,12 +204,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; @@ -220,24 +220,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; } @@ -260,11 +275,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