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 X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D13CEC433F5 for ; Fri, 3 Sep 2021 17:55:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B637F60F90 for ; Fri, 3 Sep 2021 17:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350306AbhICRz7 (ORCPT ); Fri, 3 Sep 2021 13:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350211AbhICRzy (ORCPT ); Fri, 3 Sep 2021 13:55:54 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DD22C061575 for ; Fri, 3 Sep 2021 10:54:54 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id u9so9277835wrg.8 for ; Fri, 03 Sep 2021 10:54:54 -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=Hy2+pjpQTDoKc9lk0ORGbogH38zksdNUJD8tqAxhWuVlFVXnTV0a/CN3+tMXhKurRe ddltDjuf3E9vjsUcWEWUj+61W/I3yByapOPebaz+om5LC1ddH5q5xsq+yZftHivmEKK5 1FSAJQQ0bfWZqLwcAkovvTaIN9k++JUNSe8eR44dN4LwnfzUSivL8OJXRoUXzIk9TJHF rK1KzPYXmoiXWaX0vS0lF7Ovd46FXWpeajec+wQloY4XSUzoR+NZpEDQgmpESmbaSLix VniqsJ1OorHMpxCXAEqgDajuIHZgf76yOiIp4HATFEFeHJ+bjVrMX8NE659uk3TMPYhg RBDg== 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=IkkeDf4dwAribAhlx2PhCXXfAwpmH50TJZppSlNsCLU=; b=XwIZXlDgdLwvDzbFx69w7fE98cyyQ8tcv4XWqm1G8SZZVftEHD3+wRdGnFU2s0nugr FWI+Us8O6erhpH1f6zDf6EBvqAImEdr4O2lTcOYJRtaTCdIbw8VcObG+iyPBZ0WrZoXD EGfqSTuZKbuTqmeZd9iYUek6YW08GlA4a5NxiCKUsYjwmRyDv7J1+LktwtvY2jzedbdh R+/e19ZrSZSXBcHZn9eoj1Lq0EzFdP8xaV2/L/xau9rPesdvRwDfwP8F1//q8mMCmdQJ vapsv+ekLrgc/x32MZNmSKqpQ8dxdoYJxpBsbQXMoRdbIcmlcOE7plW6TJD1uP7y1QI0 x2BA== X-Gm-Message-State: AOAM530Y14Tus9A9v9+IHOXOp8lDxM02iKeYHbtN/XP5XfiT1sYqVqSX pqhb6/6Hj7fMqYpxI66iT64qJGLgHqM= X-Google-Smtp-Source: ABdhPJzj5QogOh/PDDzdt5YrD4wQFh3fHkQFBP0x0uZpfynv4U4n75IKi29NytLKJq70AbwHUfA1Kg== X-Received: by 2002:a5d:5642:: with SMTP id j2mr320067wrw.264.1630691693238; Fri, 03 Sep 2021 10:54:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o2sm5731324wrh.13.2021.09.03.10.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 10:54:52 -0700 (PDT) Message-Id: <6142f75875b8245c93230e141be3664253e2137b.1630691688.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 03 Sep 2021 17:54:37 +0000 Subject: [PATCH v2 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 , 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