From patchwork Thu Oct 7 10:58:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541553 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 8017FC4332F for ; Thu, 7 Oct 2021 10:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 673DB61037 for ; Thu, 7 Oct 2021 10:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233691AbhJGLBH (ORCPT ); Thu, 7 Oct 2021 07:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbhJGLBG (ORCPT ); Thu, 7 Oct 2021 07:01:06 -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 97B6EC061755 for ; Thu, 7 Oct 2021 03:59:12 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id u18so17820325wrg.5 for ; Thu, 07 Oct 2021 03:59:12 -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=d7tE7OKJnf1/1FO5mmq9qQzcQMwNEj8WJ6NJNRAMJTk=; b=TswI9F5P9JKVg/4Swad5nUe47HlpfsznaVhkS1mydGuMfLw/7hk3NaJ8nZknDnl+r4 qahNWCrR6NvjIgr4vvJdGJvjf4G8ouYJaTjFt49F/9gbYbYg2MOYe75Bso90Okp+b9rI B/VLB0vZIpu2zad26RdVUSYF5v3Y7CxlfzyjQ5h6o2FbHpCZOuf8kmTBAZG9eHWcUNrQ 6Xhes4BFrEop8aJQGWncW8ukGKEWkt/r91IOYnO2YvFWyWN+Sqqyf/0ms3PiUk8w1vh9 XTyUeGxRY3y6pANMXeq4HWSsiDItljgSxdIhLgKOecJOQTaQyVlsi3EzLe6Dl6OpWhQ8 Q98Q== 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=d7tE7OKJnf1/1FO5mmq9qQzcQMwNEj8WJ6NJNRAMJTk=; b=M5mqIHhyI+j5Cyt7SnOUsvpC0AtAePBJG6foOnLWvPqwu8Bl01nN4TecwBKr0h2rjf iNfuy7Zjc4D6XKvy/Ec1lp8rJlM+I3wSBjYfXk25r4f/cMU04fp8JmXzlgLWLlln2HxM F4mZHQQd6zT4/YuGFNgO2/h6XEiVOIDWeWjAGX50eIZgELR2tA1y4eMlLSuaD2ZOcMjc RgYGtVzd8femxDhsfHgK7MjkzTtxEJ2ZkKNr1Szy0Lh6v075sabVa2TrgZ+phR49bY1I 5BB9+9iAFEu8TkygbUojFwTJyaSB3EI+T44i+isxb7eV+stPuRtkJkZrqF7hQIPyc8fC digA== X-Gm-Message-State: AOAM532J0bqipzYpf6yPD0B6f5w0QOuPWlyFo5YIRXd02SXrYCOCl68e 85ukVIVN09hs2blRj3ySwFyp+XmrFGI= X-Google-Smtp-Source: ABdhPJwgiE1i4ebqhraOmWC90bncAqey4Sdv+R6+aLY9/Uz8pUfyoq9dx/vd9gdtNk0uxmeek9TiWA== X-Received: by 2002:a1c:f402:: with SMTP id z2mr15697149wma.53.1633604351198; Thu, 07 Oct 2021 03:59:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c9sm8369373wmb.41.2021.10.07.03.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:10 -0700 (PDT) Message-Id: <7119a8efc214ada2c372693731193043ea97dabc.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:58:55 +0000 Subject: [PATCH v5 01/15] scalar: create a rudimentary executable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The idea of Scalar (https://github.com/microsoft/scalar), and before that, of VFS for Git, has always been to prove that Git _can_ scale, and to upstream whatever strategies have been demonstrated to help. With this patch, we start the journey from that C# project to move what is left to Git's own `contrib/` directory, reimplementing it in pure C, with the intention to facilitate integrating the functionality into core Git all while maintaining backwards-compatibility for existing Scalar users (which will be much easier when both live in the same worktree). It has always been the plan to contribute all of the proven strategies back to core Git. For example, while the virtual filesystem provided by VFS for Git helped the team developing the Windows operating system to move onto Git, while trying to upstream it we realized that it cannot be done: getting the virtual filesystem to work (which we only managed to implement fully on Windows, but not on, say, macOS or Linux), and the required server-side support for the GVFS protocol, made this not quite feasible. The Scalar project learned from that and tackled the problem with different tactics: instead of pretending to Git that the working directory is fully populated, it _specifically_ teaches Git about partial clone (which is based on VFS for Git's cache server), about sparse checkout (which VFS for Git tried to do transparently, in the file system layer), and regularly runs maintenance tasks to keep the repository in a healthy state. With partial clone, sparse checkout and `git maintenance` having been upstreamed, there is little left that `scalar.exe` does which `git.exe` cannot do. One such thing is that `scalar clone ` will automatically set up a partial, sparse clone, and configure known-helpful settings from the start. So let's bring this convenience into Git's tree. The idea here is that you can (optionally) build Scalar via make -C contrib/scalar/Makefile This will build the `scalar` executable and put it into the contrib/scalar/ subdirectory. The slightly awkward addition of the `contrib/scalar/*` bits to the top-level `Makefile` are actually really required: we want to link to `libgit.a`, which means that we will need to use the very same `CFLAGS` and `LDFLAGS` as the rest of Git. An early development version of this patch tried to replicate all the conditional code in `contrib/scalar/Makefile` (e.g. `NO_POLL`) just like `contrib/svn-fe/Makefile` used to do before it was retired. It turned out to be quite the whack-a-mole game: the SHA-1-related flags, the flags enabling/disabling `compat/poll/`, `compat/regex/`, `compat/win32mmap.c` & friends depending on the current platform... To put it mildly: it was a major mess. Instead, this patch makes minimal changes to the top-level `Makefile` so that the bits in `contrib/scalar/` can be compiled and linked, and adds a `contrib/scalar/Makefile` that uses the top-level `Makefile` in a most minimal way to do the actual compiling. Note: With this commit, we only establish the infrastructure, no Scalar functionality is implemented yet; We will do that incrementally over the next few commits. Signed-off-by: Johannes Schindelin --- Makefile | 9 +++++++++ contrib/scalar/.gitignore | 2 ++ contrib/scalar/Makefile | 34 ++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 contrib/scalar/.gitignore create mode 100644 contrib/scalar/Makefile create mode 100644 contrib/scalar/scalar.c diff --git a/Makefile b/Makefile index c3565fc0f8f..a12cac1b68b 100644 --- a/Makefile +++ b/Makefile @@ -2444,6 +2444,11 @@ OBJECTS += $(FUZZ_OBJS) ifndef NO_CURL OBJECTS += http.o http-walker.o remote-curl.o endif + +SCALAR_SOURCES := contrib/scalar/scalar.c +SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o) +OBJECTS += $(SCALAR_OBJECTS) + .PHONY: objects objects: $(OBJECTS) @@ -2586,6 +2591,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS) +contrib/scalar/scalar$X: $(SCALAR_OBJECTS) GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \ + $(filter %.o,$^) $(LIBS) + $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore new file mode 100644 index 00000000000..ff3d47e84d0 --- /dev/null +++ b/contrib/scalar/.gitignore @@ -0,0 +1,2 @@ +/*.exe +/scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile new file mode 100644 index 00000000000..40c03ad10e1 --- /dev/null +++ b/contrib/scalar/Makefile @@ -0,0 +1,34 @@ +QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir +QUIET_SUBDIR1 = + +ifneq ($(findstring s,$(MAKEFLAGS)),s) +ifndef V + QUIET_SUBDIR0 = +@subdir= + QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ + $(MAKE) $(PRINT_DIR) -C $$subdir +else + export V +endif +endif + +all: + +include ../../config.mak.uname +-include ../../config.mak.autogen +-include ../../config.mak + +TARGETS = scalar$(X) scalar.o +GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a + +all: scalar$X + +$(GITLIBS): + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) + +$(TARGETS): $(GITLIBS) scalar.c + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) + +clean: + $(RM) $(TARGETS) + +.PHONY: all clean FORCE diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c new file mode 100644 index 00000000000..7cff29e0fcd --- /dev/null +++ b/contrib/scalar/scalar.c @@ -0,0 +1,36 @@ +/* + * The Scalar command-line interface. + */ + +#include "cache.h" +#include "gettext.h" +#include "parse-options.h" + +static struct { + const char *name; + int (*fn)(int, const char **); +} builtins[] = { + { NULL, NULL}, +}; + +int cmd_main(int argc, const char **argv) +{ + struct strbuf scalar_usage = STRBUF_INIT; + int i; + + if (argc > 1) { + argv++; + argc--; + + for (i = 0; builtins[i].name; i++) + if (!strcmp(builtins[i].name, argv[0])) + return !!builtins[i].fn(argc, argv); + } + + strbuf_addstr(&scalar_usage, + N_("scalar []\n\nCommands:\n")); + for (i = 0; builtins[i].name; i++) + strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); + + usage(scalar_usage.buf); +} From patchwork Thu Oct 7 10:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541555 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 9A543C43217 for ; Thu, 7 Oct 2021 10:59:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C2EA61037 for ; Thu, 7 Oct 2021 10:59:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240477AbhJGLBJ (ORCPT ); Thu, 7 Oct 2021 07:01:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232709AbhJGLBG (ORCPT ); Thu, 7 Oct 2021 07:01:06 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34668C061746 for ; Thu, 7 Oct 2021 03:59:13 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t8so17907051wri.1 for ; Thu, 07 Oct 2021 03:59:13 -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=j2bGVjqPT7Pn8kjChLvmqQS0Jlg6df0AQr+Wz7oQLNA=; b=FuFUjrih1uom7nc1pblDQqKxyO1yn3Vu6nJGoImkmTUMaxpN8Woanadly83tqm09yH XTIXiG2c56v2NLkLxr8Pe//DUYqtsug6TnLCT2evGeE66X2dVZoJIR+6R7lvFety+ENI xfkkFpuXAgsOf//3uYtIbxG1GOUaZZStPkrTi8l40hRxVJvzgcNmav/gAH4jpqMCH4Wi dcDp98eX8sQwg3LG+xaTCfN/VxGYERQ9JhdcVn/5oICTrx7GhD6N2CfRE8qgKGq3UKJw 2BHRsOK6bdBttU5nwTX+n3Xhc1WxDsJcvqfYs30Jk5n0U1O0WdjkfL4Pvj3AeN4cPKE+ BV4Q== 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=j2bGVjqPT7Pn8kjChLvmqQS0Jlg6df0AQr+Wz7oQLNA=; b=dcMckdvRgaGVtUp4BS+nJAJH0cG77WfEUMi+bWRdLcwiXVe7YU6cRjBes3niqk2M4r RYERM7xixO3O6vhjtNfDX8ha8q2VP7c219rbvsUk/tFaj46JiQzbJKgeWAE9R4NQ2h42 vVdzVCbC3HJ80m1Qk1gk3aIXIMR1FF6Uh1UvJjOoG6ItcjGx/SH5rVPiId2Uw9rNyEqY KMu1Wqo/8+omnm2FFVjASSUSyPtgxfY1ENrBv4u5k/vYUbdnDj14rG322ureuN/vWVNQ DR1lnGD7UR0BG3DCa6lYH/aNklEDt4DDbVTodFtoKPAQ101O7NyhAuu7B0mt1b7qAGDO sCng== X-Gm-Message-State: AOAM531pD4KXOPSyw6sEk6JETj0B5c0zb8v+DGxARDaGFjmFhXD5HiXm Rro7gQfiBC6icrBdE0bxZTwe7bBWuPs= X-Google-Smtp-Source: ABdhPJxdQbJMGKVerE29Z7aaO+2ItEd+9oBKSJ+InavbfJTC5dBAGRw4/TxEHw/aKJRr0rNAQwYRLQ== X-Received: by 2002:a7b:c056:: with SMTP id u22mr3892321wmc.15.1633604351797; Thu, 07 Oct 2021 03:59:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w5sm23360256wra.87.2021.10.07.03.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:11 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 07 Oct 2021 10:58:56 +0000 Subject: [PATCH v5 02/15] scalar: start documenting the command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This commit establishes the infrastructure to build the manual page for the `scalar` command. Signed-off-by: Johannes Schindelin --- contrib/scalar/.gitignore | 3 +++ contrib/scalar/Makefile | 14 +++++++++++++- contrib/scalar/scalar.txt | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 contrib/scalar/scalar.txt diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore index ff3d47e84d0..00441073f59 100644 --- a/contrib/scalar/.gitignore +++ b/contrib/scalar/.gitignore @@ -1,2 +1,5 @@ +/*.xml +/*.1 +/*.html /*.exe /scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index 40c03ad10e1..85c186634e9 100644 --- a/contrib/scalar/Makefile +++ b/contrib/scalar/Makefile @@ -6,6 +6,7 @@ ifndef V QUIET_SUBDIR0 = +@subdir= QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ $(MAKE) $(PRINT_DIR) -C $$subdir + QUIET = @ else export V endif @@ -30,5 +31,16 @@ $(TARGETS): $(GITLIBS) scalar.c clean: $(RM) $(TARGETS) + $(RM) scalar.1 scalar.html scalar.xml -.PHONY: all clean FORCE +docs: scalar.html scalar.1 + +scalar.html: | scalar.1 # prevent them from trying to build `doc.dep` in parallel + +scalar.html scalar.1: scalar.txt + $(QUIET_SUBDIR0)../../Documentation$(QUIET_SUBDIR1) \ + MAN_TXT=../contrib/scalar/scalar.txt \ + ../contrib/scalar/$@ + $(QUIET)test scalar.1 != "$@" || mv ../../Documentation/$@ . + +.PHONY: all clean docs FORCE diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt new file mode 100644 index 00000000000..5f7131861a5 --- /dev/null +++ b/contrib/scalar/scalar.txt @@ -0,0 +1,38 @@ +scalar(1) +========= + +NAME +---- +scalar - an opinionated repository management tool + +SYNOPSIS +-------- +[verse] +scalar [] + +DESCRIPTION +----------- + +Scalar is an opinionated repository management tool. By creating new +repositories or registering existing repositories with Scalar, your Git +experience will speed up. Scalar sets advanced Git config settings, +maintains your repositories in the background, and helps reduce data sent +across the network. + +An important Scalar concept is the enlistment: this is the top-level directory +of the project. It usually contains the subdirectory `src/` which is a Git +worktree. This encourages the separation between tracked files (inside `src/`) +and untracked files, such as build artifacts (outside `src/`). When registering +an existing Git worktree with Scalar whose name is not `src`, the enlistment +will be identical to the worktree. + +The `scalar` command implements various subcommands, and different options +depending on the subcommand. + +SEE ALSO +-------- +linkgit:git-maintenance[1]. + +Scalar +--- +Associated with the linkgit:git[1] suite From patchwork Thu Oct 7 10:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541557 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 B52F7C433EF for ; Thu, 7 Oct 2021 10:59:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C9B160F58 for ; Thu, 7 Oct 2021 10:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240519AbhJGLBN (ORCPT ); Thu, 7 Oct 2021 07:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbhJGLBI (ORCPT ); Thu, 7 Oct 2021 07:01:08 -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 55C5BC061746 for ; Thu, 7 Oct 2021 03:59:14 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u18so17820547wrg.5 for ; Thu, 07 Oct 2021 03:59:14 -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=tEEtHAQ8UCYDaO4A/Ch4X+sM3t0MfBKstGjJxvTXvA8=; b=ZyAUZgxxOSg34ObH3RNP0zaADZeYhR9vyxIefcbG0aC2eX315vEAPPNgbvm8FyVskX Qt6Syj6oNG5/LA5Z0rIaBDx5Cs4PcFV+bxJ/w90Di4X+Wex2LHOyI5RXpjSzCV0FBmUR Tx0lVOF7hnJ2WJqh/XevWyUD5G5QyzSMSMRGEyR/rnxJrNUcROafwfVSSwjxe4wr270S brtsA7CO053rKMiJa7WQgH3aoQbyCMIpDHV7UJxepvOO7gO2H5NKI/JZHLXcrcNVPcpI 5awb79k0JOISeAvTi3z6EZuSSP8J2LPB04d+9WcI9wutVBXAZqMgfPaqvRGU+ogoTHFp LCLg== 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=tEEtHAQ8UCYDaO4A/Ch4X+sM3t0MfBKstGjJxvTXvA8=; b=ZS9iFeP6XoL3zZyQt8u/oH48xHLGFlFN0/p2SpLa7CiIzfqHofsjm77w5rZiOZjYpl vCQrgGCT58KiAn890ubDYqB5krHNFnOqUvuupphK3/Ac55dJ4rGu1OkS+XIKdckKKtjW UdQ5/noYjNRcd259A7zwQevi7765O2LXzkFBHHEa/dMPpHjfmNITY1C0LzpHiZ0dcEV3 xPy7TS06ljZPC+ac+hhnAH2xi0Hm/1F9v2JL9uyDKOipu3iSr3vPXTl79pkCmpyvqic/ QRy98b64KUV5gBxw+SoFdIakyQ8VhyVyf8ZutzfPFVRIHLOQcVa+Fo6gZZkrTe8wfzOp bc/Q== X-Gm-Message-State: AOAM531BWXkz3uTBSQR9OZUod1o5rrVfDzP0Hb9moc9KMGiQM4DjL+zT 8gjgZoTwbM+rbvqni3BC9nhZiUd4D6Y= X-Google-Smtp-Source: ABdhPJwnUbgNupYq05fKiSGat1BtyGzKwRa1ThakzKWoF7xkoFJ1ys9uhD26ofzKlMbJUOHFNdbmRg== X-Received: by 2002:adf:ab03:: with SMTP id q3mr4719361wrc.396.1633604352924; Thu, 07 Oct 2021 03:59:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k26sm11662225wms.39.2021.10.07.03.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:12 -0700 (PDT) Message-Id: <9eeb66d5b5d47a6498518657c7ba608e2bc78114.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:58:57 +0000 Subject: [PATCH v5 03/15] scalar: create test infrastructure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To test the Scalar command, create a test script in contrib/scalar/t that is executed as `make -C contrib/scalar test`. Since Scalar has no meaningful capabilities yet, the only test is rather simple. We will add more tests in subsequent commits that introduce corresponding, new functionality. Note: this test script is intended to test `scalar` only lightly, even after all of the functionality is implemented. A more comprehensive functional (or: integration) test suite can be found at https://github.com/microsoft/scalar; It is used in the workflow https://github.com/microsoft/git/blob/HEAD/.github/workflows/scalar-functional-tests.yml in Microsoft's Git fork. This test suite performs end-to-end tests with a real remote repository, and is run as part of the regular CI builds. Since those tests require some functionality supported only by Microsoft's Git fork ("GVFS protocol"), there is no intention to port that fuller test suite to `contrib/scalar/`. Signed-off-by: Johannes Schindelin --- contrib/scalar/Makefile | 17 +++++-- contrib/scalar/t/Makefile | 78 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 17 +++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 contrib/scalar/t/Makefile create mode 100755 contrib/scalar/t/t9099-scalar.sh diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index 85c186634e9..8620042f281 100644 --- a/contrib/scalar/Makefile +++ b/contrib/scalar/Makefile @@ -3,6 +3,7 @@ QUIET_SUBDIR1 = ifneq ($(findstring s,$(MAKEFLAGS)),s) ifndef V + QUIET_GEN = @echo ' ' GEN $@; QUIET_SUBDIR0 = +@subdir= QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ $(MAKE) $(PRINT_DIR) -C $$subdir @@ -21,7 +22,7 @@ include ../../config.mak.uname TARGETS = scalar$(X) scalar.o GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a -all: scalar$X +all: scalar$X ../../bin-wrappers/scalar $(GITLIBS): $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) @@ -30,9 +31,19 @@ $(TARGETS): $(GITLIBS) scalar.c $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) clean: - $(RM) $(TARGETS) + $(RM) $(TARGETS) ../../bin-wrappers/scalar $(RM) scalar.1 scalar.html scalar.xml +../../bin-wrappers/scalar: ../../wrap-for-bin.sh Makefile + @mkdir -p ../../bin-wrappers + $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ + -e 's|@@BUILD_DIR@@|$(shell cd ../.. && pwd)|' \ + -e 's|@@PROG@@|contrib/scalar/scalar$(X)|' < $< > $@ && \ + chmod +x $@ + +test: all + $(MAKE) -C t + docs: scalar.html scalar.1 scalar.html: | scalar.1 # prevent them from trying to build `doc.dep` in parallel @@ -43,4 +54,4 @@ scalar.html scalar.1: scalar.txt ../contrib/scalar/$@ $(QUIET)test scalar.1 != "$@" || mv ../../Documentation/$@ . -.PHONY: all clean docs FORCE +.PHONY: all clean docs test FORCE diff --git a/contrib/scalar/t/Makefile b/contrib/scalar/t/Makefile new file mode 100644 index 00000000000..6170672bb37 --- /dev/null +++ b/contrib/scalar/t/Makefile @@ -0,0 +1,78 @@ +# Run scalar tests +# +# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin +# + +-include ../../../config.mak.autogen +-include ../../../config.mak + +SHELL_PATH ?= $(SHELL) +PERL_PATH ?= /usr/bin/perl +RM ?= rm -f +PROVE ?= prove +DEFAULT_TEST_TARGET ?= test +TEST_LINT ?= test-lint + +ifdef TEST_OUTPUT_DIRECTORY +TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results +else +TEST_RESULTS_DIRECTORY = ../../../t/test-results +endif + +# Shell quote; +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) +PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) +TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) + +T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) + +all: $(DEFAULT_TEST_TARGET) + +test: $(TEST_LINT) + $(MAKE) aggregate-results-and-cleanup + +prove: $(TEST_LINT) + @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS) + $(MAKE) clean-except-prove-cache + +$(T): + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) + +clean-except-prove-cache: + $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)' + $(RM) -r valgrind/bin + +clean: clean-except-prove-cache + $(RM) .prove + +test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax + +test-lint-duplicates: + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ + test -z "$$dups" || { \ + echo >&2 "duplicate test numbers:" $$dups; exit 1; } + +test-lint-executable: + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \ + test -z "$$bad" || { \ + echo >&2 "non-executable tests:" $$bad; exit 1; } + +test-lint-shell-syntax: + @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T) + +aggregate-results-and-cleanup: $(T) + $(MAKE) aggregate-results + $(MAKE) clean + +aggregate-results: + for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \ + echo "$$f"; \ + done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh + +valgrind: + $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" + +test-results: + mkdir -p test-results + +.PHONY: $(T) aggregate-results clean valgrind diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh new file mode 100755 index 00000000000..16f2b72b126 --- /dev/null +++ b/contrib/scalar/t/t9099-scalar.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +test_description='test the `scalar` command' + +TEST_DIRECTORY=$PWD/../../../t +export TEST_DIRECTORY + +# Make it work with --no-bin-wrappers +PATH=$PWD/..:$PATH + +. ../../../t/test-lib.sh + +test_expect_success 'scalar shows a usage' ' + test_expect_code 129 scalar -h +' + +test_done From patchwork Thu Oct 7 10:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12541559 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 44BE2C433EF for ; Thu, 7 Oct 2021 10:59:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 203E261037 for ; Thu, 7 Oct 2021 10:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240356AbhJGLBY (ORCPT ); Thu, 7 Oct 2021 07:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240291AbhJGLBI (ORCPT ); Thu, 7 Oct 2021 07:01:08 -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 12260C061755 for ; Thu, 7 Oct 2021 03:59:15 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id i12so5181846wrb.7 for ; Thu, 07 Oct 2021 03:59:15 -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=zmNapYoSF08hozpeOeKMiT/esyUmD9Bsx0bmoobd/Rw=; b=oaWR3vk6v8ZAWD73wmRo64mzELhaVG6ACRH4hC5DrmqW+RO69Qi1wqQnihegvy2MQk hrstBRcwRtyiCrPu1s6yioDKPVYBmTOiuW0jcKWRwUZjLB1oFzOiDojbvgsv3sDshiJ0 uPwCerhnSfVCPIBlPDJljS/c5qaajB5VDxaClrpLVx5Lt2gZdPH9ERaaowg4flTbOxnh oIY0QMqR6AYc8a3yzcrAsgmCAIyktGw0caO7JcXdtidbrY4gt0Yo3Z8Bj9Utig7K2QQn QIy3aSjoDIEygEiQnbaVZ5dZ+GKJxcljil9+TE2QSXDMqMaAPutzUwXswCGPA30TdkBE 9GsA== 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=zmNapYoSF08hozpeOeKMiT/esyUmD9Bsx0bmoobd/Rw=; b=kN8NIk10fdDVuqg8NzX8X9vfVfkmDpPCcXlRZwZ/KR33l/yvM5fpJ4wlxSs3BIIaYF Nx9TYOfcDn2HwlFv1RHkMsDQoQgHxse4PtEF9N4f8dCESsk0AtOlgmMNyZ1WaXW8THzu thD3FPyerUErC2+lzjdUV2O9kk4Vbrr+zIDd/2UOg4cMiNJjhFEpkiEqqOKoW527l3PH YARDaor7pNepyKLhVW6vQb0FGLUv9OMIL5K2scyeV0OL6PRgHjz94tQBk0YxL1qCQ6Az nn03HDzz8lRhyh1p21tVSJa7tQY9veyZFVb0Y9Hg/iWMUUG79DZhBYsZlVOYhXqO5Bid oyLA== X-Gm-Message-State: AOAM530sfZrSsoalR7u6aGMMhlaG+AHWKRV5YPqWauIQhnXpK30J2r35 4KPWQMr59WEdZeaf+WuIIcCo9E2NzYU= X-Google-Smtp-Source: ABdhPJxd9cHp30MhoJsAd9VNnBF/R6uW2HGq3lgVc/+RpW2Un6vYsTv0eP0ZrhzWnHOF3CMjEdTJKw== X-Received: by 2002:adf:bc48:: with SMTP id a8mr4635248wrh.397.1633604353594; Thu, 07 Oct 2021 03:59:13 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a25sm7937075wmj.34.2021.10.07.03.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:13 -0700 (PDT) Message-Id: <8ebfa51ae15ef98e2488138cd3be748d35100a3d.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:58:58 +0000 Subject: [PATCH v5 04/15] scalar: 'register' sets recommended config and starts maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= 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 From: Derrick Stolee Let's start implementing the `register` command. With this commit, recommended settings are configured upon `scalar register`, and Git's background maintenance is started. The recommended config settings may very well change in the future. For example, once the built-in FSMonitor is available, we will want to enable it upon `scalar register`. For that reason, we explicitly support running `scalar register` in an already-registered enlistment. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 248 ++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 18 ++- 2 files changed, 265 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7cff29e0fcd..38721d671ba 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -5,11 +5,259 @@ #include "cache.h" #include "gettext.h" #include "parse-options.h" +#include "config.h" +#include "run-command.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; + + if (startup_info->have_repository) + BUG("gitdir already set up?!?"); + + if (argc > 1) + usage_with_options(usagestr, options); + + /* find the worktree, determine its corresponding root */ + if (argc == 1) + strbuf_add_absolute_path(&path, argv[0]); + 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); + } + + enlistment_found = 1; + break; + } + } while (strbuf_parent_directory(&path)); + + if (!enlistment_found) + die(_("could not find enlistment root")); + + if (chdir(path.buf) < 0) + die_errno(_("could not switch to '%s'"), path.buf); + + strbuf_release(&path); + setup_git_directory(); +} + +static int run_git(const char *arg, ...) +{ + struct strvec argv = STRVEC_INIT; + va_list args; + const char *p; + int res; + + va_start(args, arg); + strvec_push(&argv, arg); + while ((p = va_arg(args, const char *))) + strvec_push(&argv, p); + va_end(args); + + res = run_command_v_opt(argv.v, RUN_GIT_CMD); + + strvec_clear(&argv); + return res; +} + +static int set_recommended_config(void) +{ + struct { + const char *key; + const char *value; + } config[] = { + { "am.keepCR", "true" }, + { "core.FSCache", "true" }, + { "core.multiPackIndex", "true" }, + { "core.preloadIndex", "true" }, +#ifndef WIN32 + { "core.untrackedCache", "true" }, +#else + /* + * Unfortunately, Scalar's Functional Tests demonstrated + * that the untracked cache feature is unreliable on Windows + * (which is a bummer because that platform would benefit the + * most from it). For some reason, freshly created files seem + * not to update the directory's `lastModified` time + * immediately, but the untracked cache would need to rely on + * that. + * + * Therefore, with a sad heart, we disable this very useful + * feature on Windows. + */ + { "core.untrackedCache", "false" }, +#endif + { "core.logAllRefUpdates", "true" }, + { "credential.https://dev.azure.com.useHttpPath", "true" }, + { "credential.validate", "false" }, /* GCM4W-only */ + { "gc.auto", "0" }, + { "gui.GCWarning", "false" }, + { "index.threads", "true" }, + { "index.version", "4" }, + { "merge.stat", "false" }, + { "merge.renames", "false" }, + { "pack.useBitmaps", "false" }, + { "pack.useSparse", "true" }, + { "receive.autoGC", "false" }, + { "reset.quiet", "true" }, + { "feature.manyFiles", "false" }, + { "feature.experimental", "false" }, + { "fetch.unpackLimit", "1" }, + { "fetch.writeCommitGraph", "false" }, +#ifdef WIN32 + { "http.sslBackend", "schannel" }, +#endif + { "status.aheadBehind", "false" }, + { "commitGraph.generationVersion", "1" }, + { "core.autoCRLF", "false" }, + { "core.safeCRLF", "false" }, + { NULL, NULL }, + }; + int i; + char *value; + + for (i = 0; config[i].key; i++) { + if (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); + } + } + + /* + * The `log.excludeDecoration` setting is special because it allows + * for multiple values. + */ + if (git_config_get_string("log.excludeDecoration", &value)) { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "created"); + if (git_config_set_multivar_gently("log.excludeDecoration", + "refs/prefetch/*", + CONFIG_REGEX_NONE, 0)) + return error(_("could not configure " + "log.excludeDecoration")); + } else { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "exists"); + free(value); + } + + return 0; +} + +static int start_maintenance(void) +{ + return run_git("maintenance", "start", NULL); +} + +static int add_enlistment(void) +{ + int res; + + if (!the_repository->worktree) + die(_("Scalar enlistments require a worktree")); + + res = run_git("config", "--global", "--get", "--fixed-value", + "scalar.repo", the_repository->worktree, NULL); + + /* + * If the setting is already there, then do nothing. + */ + if (!res) + return 0; + + return run_git("config", "--global", "--add", + "scalar.repo", the_repository->worktree, NULL); +} + +static int register_dir(void) +{ + int res = add_enlistment(); + + if (!res) + res = set_recommended_config(); + + if (!res) + res = start_maintenance(); + + return res; +} + +static int cmd_register(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar register []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return register_dir(); +} static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "register", cmd_register }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 5f7131861a5..568987064b2 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar [] +scalar register [] DESCRIPTION ----------- @@ -29,6 +29,22 @@ will be identical to the worktree. The `scalar` command implements various subcommands, and different options depending on the subcommand. +COMMANDS +-------- + +Register +~~~~~~~~ + +register []:: + Adds the enlistment's repository to the list of registered repositories + and starts background maintenance. If `` is not provided, + then the enlistment associated with the current working directory is + registered. ++ +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. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Thu Oct 7 10:58:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12541561 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 3AA31C433EF for ; Thu, 7 Oct 2021 10:59:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2132861037 for ; Thu, 7 Oct 2021 10:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240429AbhJGLBZ (ORCPT ); Thu, 7 Oct 2021 07:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240452AbhJGLBJ (ORCPT ); Thu, 7 Oct 2021 07:01:09 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92CC5C061760 for ; Thu, 7 Oct 2021 03:59:15 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r10so17792871wra.12 for ; Thu, 07 Oct 2021 03:59:15 -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=SJgwnf3rJRV5fMleXZ2nSdcJHBhDnyI3ULuJxOiFMCg=; b=CszVpZPLQc4YvCkfcY9fTReH1XIdegWpnHjsspTsQSYcWTlzEn3DqMjER/tVxWp9k/ teY3DThA21iDkYte9WVTcGKIkDqQ3NuhmObZSA+PKNH90NySIJmyyLxyjUMM9t2QM+xG Imc1lL2mEws/vae5ziC0WOXJX4G2wKWpelUR3sGOt+AsZMxzL6rvhTcgbL6ZoZ839+nF rs2WMuhtVrYiA71UFyEgL/Tp1sNYr9QyMx7hGlDLu6zTHqdUZAl4naf9MffgMZ6Bp/Hv U+31QEWZwrWvQ/IjZkP543ldWQdg8tvx7rPygYWxVBW6MbpfzNcwX6REK5VTqO4cKOLm Rrxw== 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=SJgwnf3rJRV5fMleXZ2nSdcJHBhDnyI3ULuJxOiFMCg=; b=Psp/fWdI8LSS89dzvRtJFx5P4/3p4YgpQRy9GS3/fkxcWl7sb+G/VTArIu98tK1bVK ZvizkmjynTqcYkv+WOhW+T+Uk6nxC8rnEYmX+mUIvyTQK91L5Qp/qt1RvjOkOmorLxFZ wskJbnhDdJZCDMhBde98ee0GXXq9T53RJLJVV/Ed8P3aIh/Qv6z7mZcxybFccNAKCtYB WxRLNlwEJnjTbHYffwowjncDfdY4aQLhKNgzv3tTXEJwvEJ6wpNhytMxVbTQdBd5Tyyi EMh1I5+us/bA0B6YQDEYYVeb3/t+WeZDdtR4vOb2DwQW5BEoUt2oxgZEhBfphXiqUazr V6iw== X-Gm-Message-State: AOAM530eJ1j6NewW88t+DLil9J9sCOGv6CBplMG7XaPhxz8q1FKYm/em dG099rl7FMgG2pP4uL696v2bO7nsMO4= X-Google-Smtp-Source: ABdhPJz+r1Wpe0hiNXZZjRrM6Yl8y7V9uiZEZq420Ap676HbMTDf/zTKJrVExaCF2s/ZMcp192kHVg== X-Received: by 2002:a1c:d7:: with SMTP id 206mr15597615wma.116.1633604354226; Thu, 07 Oct 2021 03:59:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j27sm9778901wms.6.2021.10.07.03.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:13 -0700 (PDT) Message-Id: <51b5fc577c9ea7d8f5f7f7c676e9b2c25b65f71c.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:58:59 +0000 Subject: [PATCH v5 05/15] scalar: 'unregister' stops background maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= 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 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 38721d671ba..fc55404230d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -197,12 +197,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; @@ -213,24 +213,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; } @@ -253,11 +268,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]. From patchwork Thu Oct 7 10:59:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541563 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 4E90EC433EF for ; Thu, 7 Oct 2021 10:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36FC760F58 for ; Thu, 7 Oct 2021 10:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240960AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240953AbhJGLBV (ORCPT ); Thu, 7 Oct 2021 07:01:21 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CE02C061764 for ; Thu, 7 Oct 2021 03:59:16 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id v17so17761779wrv.9 for ; Thu, 07 Oct 2021 03:59:16 -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=dZbBihr8P478PPKLNmEh1kp6VSl3WRtsE74oahy/YaE=; b=GHzdJeWw48r2sl1XZ6GQeWxxMT536PAWHLXhWJh1mRFkAscxRO9YLz9NeTSO/mwSxo AvM1YnpIGrih//aVcSvSbClZu+Snua5JgkMXjLAJWHaAzZzYeN0rL0L8ZEpieAZidoo2 u0mlW1wrjL9XU8+B0/hNNd7KnC+dBES4V/iTOeP1nTQhN2lP8qsw6tvdQXCQF+iC3NSb DS0sWd39Ax+EY20D7AbX1Jemu67zAr8oNka5cYpV34cWuoK9mLJ2RE2hZc53515AfEHn bFMEeIzXF1QyWshXqP0WUSInpjQrYOwvopzmFmPhQE9So9Frsbug3CJkqAmeTsAgkkLW TlnQ== 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=dZbBihr8P478PPKLNmEh1kp6VSl3WRtsE74oahy/YaE=; b=EZvZ3SKXNiXf75anlJVJy9YXYHVmuk8Am2G2/fjcaipUO4ibDTOejo7TgzvoAlPsWK MnYbmkfi37gfs4X8DZ/VeouOoy9TkI1ktaVDyunJmWYLMBx6pfvGYtkyoWvFFgsi9dcF ICDXgxiBInYJVpXMnPCgI7LhmUyCM5acvlmQYg69VdjpdLj67qLC8uJ1aPj5/OhxhvIt kKXRZa8saoTflBKIyMnAHsIVK51Gk10OjuXd1rIN0jpJFDSEAva6ktgUQ5nShz0Iofu1 G3PSvXXWURxbEnyY5pLoN+j+ddg+aBMDlQ1s+52foFomo2g5LXGJfDmm+K+w+5N/g/q0 myrw== X-Gm-Message-State: AOAM533Z2BiPXrRkJtauuC16JfbbIQFT8bxf0b3sUQZM8D4A8ZXdwv6l 6aWz5JX1Ou2OrmuEHrv7p4HM+snJSMI= X-Google-Smtp-Source: ABdhPJx+vJPkgPfvWgIBAglYwXi1j442sOgr6ajyu3VXL5Zp3y++CnX01s3k4LCWJRXzfwTBso6JfQ== X-Received: by 2002:a7b:c3cf:: with SMTP id t15mr9138490wmj.120.1633604354860; Thu, 07 Oct 2021 03:59:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r205sm4551710wma.3.2021.10.07.03.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:14 -0700 (PDT) Message-Id: <0041477374edb0a6f32d15cab18d99075e5ac60c.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:00 +0000 Subject: [PATCH v5 06/15] scalar: let 'unregister' handle a deleted enlistment directory gracefully Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When a user deleted an enlistment manually, let's be generous and _still_ unregister it. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 46 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 15 +++++++++++ 2 files changed, 61 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index fc55404230d..dc84ce0d5b2 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -268,6 +268,24 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int remove_deleted_enlistment(struct strbuf *path) +{ + int res = 0; + strbuf_realpath_forgiving(path, path->buf, 1); + + if (run_git("config", "--global", + "--unset", "--fixed-value", + "scalar.repo", path->buf, NULL) < 0) + res = -1; + + if (run_git("config", "--global", + "--unset", "--fixed-value", + "maintenance.repo", path->buf, NULL) < 0) + res = -1; + + return res; +} + static int cmd_unregister(int argc, const char **argv) { struct option options[] = { @@ -281,6 +299,34 @@ static int cmd_unregister(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, usage, 0); + /* + * Be forgiving when the enlistment or worktree does not even exist any + * longer; This can be the case if a user deleted the worktree by + * mistake and _still_ wants to unregister the thing. + */ + if (argc == 1) { + struct strbuf src_path = STRBUF_INIT, workdir_path = STRBUF_INIT; + + strbuf_addf(&src_path, "%s/src/.git", argv[0]); + strbuf_addf(&workdir_path, "%s/.git", argv[0]); + if (!is_directory(src_path.buf) && !is_directory(workdir_path.buf)) { + /* remove possible matching registrations */ + int res = -1; + + strbuf_strip_suffix(&src_path, "/.git"); + res = remove_deleted_enlistment(&src_path) && res; + + strbuf_strip_suffix(&workdir_path, "/.git"); + res = remove_deleted_enlistment(&workdir_path) && res; + + strbuf_release(&src_path); + strbuf_release(&workdir_path); + return res; + } + strbuf_release(&src_path); + strbuf_release(&workdir_path); + } + setup_enlistment_directory(argc, argv, usage, options, NULL); return unregister_dir(); diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 16f2b72b126..ef0e8d680d5 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -14,4 +14,19 @@ test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' +test_expect_success 'scalar unregister' ' + git init vanish/src && + scalar register vanish/src && + git config --get --global --fixed-value \ + maintenance.repo "$(pwd)/vanish/src" && + scalar list >scalar.repos && + grep -F "$(pwd)/vanish/src" scalar.repos && + rm -rf vanish/src/.git && + scalar unregister vanish && + test_must_fail git config --get --global --fixed-value \ + maintenance.repo "$(pwd)/vanish/src" && + scalar list >scalar.repos && + ! grep -F "$(pwd)/vanish/src" scalar.repos +' + test_done From patchwork Thu Oct 7 10:59:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12541565 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 5B193C433F5 for ; Thu, 7 Oct 2021 10:59:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F63C60F58 for ; Thu, 7 Oct 2021 10:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241023AbhJGLBe (ORCPT ); Thu, 7 Oct 2021 07:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241008AbhJGLBX (ORCPT ); Thu, 7 Oct 2021 07:01:23 -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 C315CC061767 for ; Thu, 7 Oct 2021 03:59:16 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r10so17793041wra.12 for ; Thu, 07 Oct 2021 03:59:16 -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=QyrukTNVfouEeAzxOv26evBXhIGqbMFj9uesv2a/2bw=; b=HnrLKe6j4tkDBeQL40F0WdypaxoWKP+MJTJQr9OpzDaXUA6apmzyGANMnSjlbcD3zX Dn+r1TAHLtDKc0WTjpHLmDpQa8ZAENjxL5NUcpNLdyTX1eppWBLLOYy2yJOvn282mu54 CXaRpt4GvAnS11ZxYjPyUCv6Nav1pCgDgy9u3Mm4xERZIGfOXm1gz9o00ARAy5YOjY48 yHgEpfxvksFGmqvX+kxuSYn3XFBsk1YSbAbuK6gEEj0DGdkwpypMEhwpyJ1x/n0OhAhA SPTUt9fudAro6spsyAYk3yokOQd0ZcS4fg4dqmPGO9Rw4ImFhC01+O/bAYK7sQ2Ff24j ofcQ== 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=QyrukTNVfouEeAzxOv26evBXhIGqbMFj9uesv2a/2bw=; b=TRjdilxbcPfSrrfKkXcMjxGrSv8/F75cuVKL3yUkdt5IFqMYrpF6x5usVFV9p5mmLi X1tGhx2jTy08Wjo/HdX6CeUM3iSuc6NbbIfGM/GWTAN6Dq6DPdMAE2Agmy2RWGcV08JS vWUOsDo1SEJifeOHxACBju37bn1d2N4XKxEfG9XCFo2+VTSW9NsFC2TIEeE4W+3v1l8w /GBBpcwybfbCMSMrofrMX9uhUOLKISKdRdu23OQijb4R89WJtoFVTY2owlWNXuh6pwe3 Y0S5tSfreZTQCuerdurRig0+alLFlotTTK6TBP+wxPVSQoNTp8lvXIK+UxdmEr/OSmYo ZqkQ== X-Gm-Message-State: AOAM533O4dKwzBD0EwgnDDS0Hecgd/9v1ZXa9k6Zo0oWoby1xfMMEfK/ neP6Y3Are5kSVVfYAr8mUD3VYEqppm8= X-Google-Smtp-Source: ABdhPJxxFSrs15D5q16TgFG81rRkULz8EN2r71jk7kRdxV7fDCKtlEzL8kAQ+2Y0CK/5YvCQf998Hw== X-Received: by 2002:a5d:47c3:: with SMTP id o3mr4571972wrc.25.1633604355415; Thu, 07 Oct 2021 03:59:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l12sm17507662wro.14.2021.10.07.03.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:15 -0700 (PDT) Message-Id: <12efa86e4cb3e09b18e002b8a0cfaf0c27f939b0.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:01 +0000 Subject: [PATCH v5 07/15] scalar: implement 'scalar list' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= 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 From: Derrick Stolee The produced list simply consists of those repositories registered under the multi-valued `scalar.repo` config setting in the user's Git config. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 11 +++++++++++ contrib/scalar/scalar.txt | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index dc84ce0d5b2..d13eb951c3d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -250,6 +250,16 @@ static int unregister_dir(void) return res; } +static int cmd_list(int argc, const char **argv) +{ + if (argc != 1) + die(_("`scalar list` does not take arguments")); + + if (run_git("config", "--global", "--get-all", "scalar.repo", NULL) < 0) + return -1; + return 0; +} + static int cmd_register(int argc, const char **argv) { struct option options[] = { @@ -336,6 +346,7 @@ static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, { NULL, NULL}, diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index d9a79984492..f93e3d00efd 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,6 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] +scalar list scalar register [] scalar unregister [] @@ -28,11 +29,19 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. +depending on the subcommand. With the exception of `list`, all subcommands +expect to be run in an enlistment. COMMANDS -------- +List +~~~~ + +list:: + List enlistments that are currently registered by Scalar. This + subcommand does not need to be run inside an enlistment. + Register ~~~~~~~~ From patchwork Thu Oct 7 10:59:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541567 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 5059CC433FE for ; Thu, 7 Oct 2021 10:59:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C82A60F58 for ; Thu, 7 Oct 2021 10:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241052AbhJGLBf (ORCPT ); Thu, 7 Oct 2021 07:01:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240998AbhJGLBX (ORCPT ); Thu, 7 Oct 2021 07:01:23 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE911C061768 for ; Thu, 7 Oct 2021 03:59:17 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id v17so17761960wrv.9 for ; Thu, 07 Oct 2021 03:59:17 -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=7S8PwvTeu58NSKErU1b7kjsFSTnWwK1jeDD6xKAb9Ck=; b=Z3v3QkPZp7UF5K/hzGnzc+7hjMkqxjjbSPeKWtECwb4qasDiBAB6ER/NyL80RjtkYi RzvzEnvnZm3F3U2NnTXFmhJbMJt+8yIIhjNGoWT4BGQmMa9v1ZVU0sRziGGvZjDju7hh 4uK+n7Nj5hKRmd9bmLj+bvqHGaYl5iqr/zZol0I5VeoAkq9huvAyP8eYnJSxjO75rCLZ o16U5Kroox7OOumc2ealRpa148AL8+QABZmhtcqxwfMinc8MhYBN/W0Y3pEHQLvcCfOn EWOi6/NCGMsAuK7VZqTa3ip4Tztfy0xvrPvHaC1MKeVulQryRPhYfrz6hkWSbnE9EQ0f PDEA== 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=7S8PwvTeu58NSKErU1b7kjsFSTnWwK1jeDD6xKAb9Ck=; b=yKo8WPNOqY751WVZsXtffPygxz1cBmMiION/hiqgvbaFzmal1Srq+xUhCGiXXsQrol rPqW71nPaBXwAR9Vn7R8Fcyl7ohCkxCL524vwhAvoR6OQ5rbeIqYBrM+NsB7HIs98vcy i3IIxdk8uspI63feVU1+PlJ8C1Lqjg0WuI3atVlnPeZ9MrydkmLeNp7hiy7D+PG0EcvL U4eHWvlWbKlYHSTqfJl5tD2ZEH7vbmZt77ipup1T09SNZi8awX9U4oZLcsoMgaanGIpa BWaUuuVzFRyGIu/ahwTAKhgf80vro74KoG+A2doO6F174MfVvpChJTbQ3VrkVK2C0n9F F9rA== X-Gm-Message-State: AOAM533vmPnN+k0xb8WK9rszfRkA5IjW1J6WmFZsqfJ9G6JIxE81queK EhL18WeteX+XJ8Vsg6nPo3ID7BafypQ= X-Google-Smtp-Source: ABdhPJwhxmcGH+iqwgsEKbAAq4KnAxN33KO1a20QCOqAx0CCTvakPtjZ0r7+0CMC/gEltSRZP4Gc7Q== X-Received: by 2002:a05:600c:1c9e:: with SMTP id k30mr3795617wms.74.1633604356204; Thu, 07 Oct 2021 03:59:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u17sm9654656wrw.85.2021.10.07.03.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:15 -0700 (PDT) Message-Id: <670891d14cca3cd3ec01a61a1cb4726cfdcdc0a0.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:02 +0000 Subject: [PATCH v5 08/15] scalar: implement the `clone` subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This implements Scalar's opinionated `clone` command: it tries to use a partial clone and sets up a sparse checkout by default. In contrast to `git clone`, `scalar clone` sets up the worktree in the `src/` subdirectory, to encourage a separation between the source files and the build output (which helps Git tremendously because it avoids untracked files that have to be specifically ignored when refreshing the index). Also, it registers the repository for regular, scheduled maintenance, and configures a flurry of configuration settings based on the experience and experiments of the Microsoft Windows and the Microsoft Office development teams. Note: since the `scalar clone` command is by far the most commonly called `scalar` subcommand, we document it at the top of the manual page. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 201 +++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 31 ++++- contrib/scalar/t/t9099-scalar.sh | 32 +++++ 3 files changed, 261 insertions(+), 3 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index d13eb951c3d..0401462b9b3 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -7,6 +7,7 @@ #include "parse-options.h" #include "config.h" #include "run-command.h" +#include "refs.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -250,6 +251,205 @@ static int unregister_dir(void) return res; } +/* printf-style interface, expects `=` argument */ +static int set_config(const char *fmt, ...) +{ + struct strbuf buf = STRBUF_INIT; + char *value; + int res; + va_list args; + + va_start(args, fmt); + strbuf_vaddf(&buf, fmt, args); + va_end(args); + + value = strchr(buf.buf, '='); + if (value) + *(value++) = '\0'; + res = git_config_set_gently(buf.buf, value); + strbuf_release(&buf); + + return res; +} + +static char *remote_default_branch(const char *url) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + + cp.git_cmd = 1; + strvec_pushl(&cp.args, "ls-remote", "--symref", url, "HEAD", NULL); + if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { + const char *line = out.buf; + + while (*line) { + const char *eol = strchrnul(line, '\n'), *p; + size_t len = eol - line; + char *branch; + + if (!skip_prefix(line, "ref: ", &p) || + !strip_suffix_mem(line, &len, "\tHEAD")) { + line = eol + (*eol == '\n'); + continue; + } + + eol = line + len; + if (skip_prefix(p, "refs/heads/", &p)) { + branch = xstrndup(p, eol - p); + strbuf_release(&out); + return branch; + } + + error(_("remote HEAD is not a branch: '%.*s'"), + (int)(eol - p), p); + strbuf_release(&out); + return NULL; + } + } + warning(_("failed to get default branch name from remote; " + "using local default")); + strbuf_reset(&out); + + child_process_init(&cp); + cp.git_cmd = 1; + strvec_pushl(&cp.args, "symbolic-ref", "--short", "HEAD", NULL); + if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { + strbuf_trim(&out); + return strbuf_detach(&out, NULL); + } + + strbuf_release(&out); + error(_("failed to get default branch name")); + return NULL; +} + +static int cmd_clone(int argc, const char **argv) +{ + const char *branch = NULL; + int full_clone = 0; + struct option clone_options[] = { + OPT_STRING('b', "branch", &branch, N_(""), + N_("branch to checkout after clone")), + OPT_BOOL(0, "full-clone", &full_clone, + N_("when cloning, create full working directory")), + OPT_END(), + }; + const char * const clone_usage[] = { + N_("scalar clone [] [--] []"), + NULL + }; + const char *url; + char *enlistment = NULL, *dir = NULL; + struct strbuf buf = STRBUF_INIT; + int res; + + argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0); + + if (argc == 2) { + url = argv[0]; + enlistment = xstrdup(argv[1]); + } else if (argc == 1) { + url = argv[0]; + + strbuf_addstr(&buf, url); + /* Strip trailing slashes, if any */ + while (buf.len > 0 && is_dir_sep(buf.buf[buf.len - 1])) + strbuf_setlen(&buf, buf.len - 1); + /* Strip suffix `.git`, if any */ + strbuf_strip_suffix(&buf, ".git"); + + enlistment = find_last_dir_sep(buf.buf); + if (!enlistment) { + die(_("cannot deduce worktree name from '%s'"), url); + } + enlistment = xstrdup(enlistment + 1); + } else { + usage_msg_opt(_("You must specify a repository to clone."), + clone_usage, clone_options); + } + + if (is_directory(enlistment)) + die(_("directory '%s' exists already"), enlistment); + + dir = xstrfmt("%s/src", enlistment); + + strbuf_reset(&buf); + if (branch) + strbuf_addf(&buf, "init.defaultBranch=%s", branch); + else { + char *b = repo_default_branch_name(the_repository, 1); + strbuf_addf(&buf, "init.defaultBranch=%s", b); + free(b); + } + + if ((res = run_git("-c", buf.buf, "init", "--", dir, NULL))) + goto cleanup; + + if (chdir(dir) < 0) { + res = error_errno(_("could not switch to '%s'"), dir); + goto cleanup; + } + + setup_git_directory(); + + /* common-main already logs `argv` */ + trace2_def_repo(the_repository); + + if (!branch && !(branch = remote_default_branch(url))) { + res = error(_("failed to get default branch for '%s'"), url); + goto cleanup; + } + + if (set_config("remote.origin.url=%s", url) || + set_config("remote.origin.fetch=" + "+refs/heads/*:refs/remotes/origin/*") || + set_config("remote.origin.promisor=true") || + set_config("remote.origin.partialCloneFilter=blob:none")) { + res = error(_("could not configure remote in '%s'"), dir); + goto cleanup; + } + + if (!full_clone && + (res = run_git("sparse-checkout", "init", "--cone", NULL))) + goto cleanup; + + if (set_recommended_config()) + return error(_("could not configure '%s'"), dir); + + if ((res = run_git("fetch", "--quiet", "origin", NULL))) { + warning(_("partial clone failed; attempting full clone")); + + if (set_config("remote.origin.promisor") || + set_config("remote.origin.partialCloneFilter")) { + res = error(_("could not configure for full clone")); + goto cleanup; + } + + if ((res = run_git("fetch", "--quiet", "origin", NULL))) + goto cleanup; + } + + if ((res = set_config("branch.%s.remote=origin", branch))) + goto cleanup; + if ((res = set_config("branch.%s.merge=refs/heads/%s", + branch, branch))) + goto cleanup; + + strbuf_reset(&buf); + strbuf_addf(&buf, "origin/%s", branch); + res = run_git("checkout", "-f", "-t", buf.buf, NULL); + if (res) + goto cleanup; + + res = register_dir(); + +cleanup: + free(enlistment); + free(dir); + strbuf_release(&buf); + return res; +} + static int cmd_list(int argc, const char **argv) { if (argc != 1) @@ -346,6 +546,7 @@ static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "clone", cmd_clone }, { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f93e3d00efd..d65fb5f1491 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,6 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] +scalar clone [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -29,12 +30,36 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `list`, all subcommands -expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone` and `list`, all +subcommands expect to be run in an enlistment. COMMANDS -------- +Clone +~~~~~ + +clone [] []:: + Clones the specified repository, similar to linkgit:git-clone[1]. By + default, only commit and tree objects are cloned. Once finished, the + worktree is located at `/src`. ++ +The sparse-checkout feature is enabled (except when run with `--full-clone`) +and the only files present are those in the top-level directory. Use +`git sparse-checkout set` to expand the set of directories you want to see, +or `git sparse-checkout disable` to expand to all files (see +linkgit:git-sparse-checkout[1] for more details). You can explore the +subdirectories outside your sparse-checkout by using `git ls-tree HEAD`. + +-b :: +--branch :: + Instead of checking out the branch pointed to by the cloned + repository's HEAD, check out the `` branch instead. + +--[no-]full-clone:: + A sparse-checkout is initialized by default. This behavior can be + turned off via `--full-clone`. + List ~~~~ @@ -64,7 +89,7 @@ unregister []:: SEE ALSO -------- -linkgit:git-maintenance[1]. +linkgit:git-clone[1], linkgit:git-maintenance[1]. Scalar --- diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index ef0e8d680d5..295398f62cc 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -10,6 +10,9 @@ PATH=$PWD/..:$PATH . ../../../t/test-lib.sh +GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt" +export GIT_TEST_MAINT_SCHEDULER + test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' @@ -29,4 +32,33 @@ test_expect_success 'scalar unregister' ' ! grep -F "$(pwd)/vanish/src" scalar.repos ' +test_expect_success 'set up repository to clone' ' + test_commit first && + test_commit second && + test_commit third && + git switch -c parallel first && + mkdir -p 1/2 && + test_commit 1/2/3 && + git config uploadPack.allowFilter true && + git config uploadPack.allowAnySHA1InWant true +' + +test_expect_success 'scalar clone' ' + second=$(git rev-parse --verify second:second.t) && + scalar clone "file://$(pwd)" cloned && + ( + cd cloned/src && + + git config --get --global --fixed-value maintenance.repo \ + "$(pwd)" && + + test_path_is_missing 1/2 && + test_must_fail git rev-list --missing=print $second && + git rev-list $second && + git cat-file blob $second >actual && + echo "second" >expect && + test_cmp expect actual + ) +' + test_done From patchwork Thu Oct 7 10:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541571 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 EA0B9C433EF for ; Thu, 7 Oct 2021 10:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D245061037 for ; Thu, 7 Oct 2021 10:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241010AbhJGLBi (ORCPT ); Thu, 7 Oct 2021 07:01:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241015AbhJGLBX (ORCPT ); Thu, 7 Oct 2021 07:01:23 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45741C06176A for ; Thu, 7 Oct 2021 03:59:18 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id m22so17895025wrb.0 for ; Thu, 07 Oct 2021 03:59:18 -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=nuo8isn2sktkYIyb4u24OUKLGBSW6my5q9JQrT0km/A=; b=D2ArNKSXXT8Bzt625SySurdB9FuOJGlXHF0yjKe/7SVx6kajq8N5fhXAKz3kJXpD1G lOiLX2sRephW/EhfTVvJg2ljFAEipnUXouxrECpxniCbGEvt7BZ6usVDWQ9PoAdkuBS0 hodYytSnj7ceuBTwR+HzqnBJRD6JB58rryubhGKRf9llxFQ+SHH5KjNrlmNycuYoCr7l ozGicgmSgESUR4CG39SXcrGBsiCAnNHIe8+WSt2uUpk7L58PFP9sjVZgJt5STwG08iDZ VXJf1ziFEmkdXWogKB7lWQV8/LVub7wtXEF+TdH4jDU+GaIax1gYA8mnbSjbrZegSE8L zLUw== 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=nuo8isn2sktkYIyb4u24OUKLGBSW6my5q9JQrT0km/A=; b=2K5e1Ca9FHcIB6tyJrHBUXlaHVLQSemGMjU/IsvscyKLPyB7RuRoPpGK81iusbHe5k FJQMt/EwwFxKq0cbDepbt28JFRdqWM12D8sABJB0HDAMiNdbbLz2MXDZCTxxQ4YdqXsm N1Xq7rqeuBDZ/Al3yGp5WdLIJ4qF4d0Pth21EcCMtJWJt1YD8qtupe2k1B++xm4QR2sp 6twskabUnHDaxS4vawdZT996znDHyJICmfesGL1gjv8+NbuYTz5ZtsXaX++3oDSBfKqk BxHApC9oXw3Kz5qyj/PmxsHNUeqe3osdZzanVoSKw6BHyaWnkpecu7b4LQdWgAchoyXA vnAA== X-Gm-Message-State: AOAM531H0dml4HO2YmGQmrMai4upOY+xU68WUultjJSnc2wPPNbnx2l9 Bjgc4jcdZizCrLQy/8EoondMibnc58s= X-Google-Smtp-Source: ABdhPJxbmB/2Nxk9CnYkBPMaJw78RihzTBxDePI1d+LaLAui3jlRZSI52KwyeXt9Bo6Z7CW79rNtgA== X-Received: by 2002:a05:600c:4f4e:: with SMTP id m14mr15650229wmq.5.1633604356853; Thu, 07 Oct 2021 03:59:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t15sm14468675wru.6.2021.10.07.03.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:16 -0700 (PDT) Message-Id: <03b8385ebb5ceae12eaff138606e877216a6f833.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:03 +0000 Subject: [PATCH v5 09/15] scalar: teach 'clone' to support the --single-branch option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Just like `git clone`, the `scalar clone` command now also offers to restrict the clone to a single branch. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 9 +++++++-- contrib/scalar/scalar.txt | 12 +++++++++++- contrib/scalar/t/t9099-scalar.sh | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 0401462b9b3..754e19d781d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -326,12 +326,15 @@ static char *remote_default_branch(const char *url) static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; - int full_clone = 0; + int full_clone = 0, single_branch = 0; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), OPT_BOOL(0, "full-clone", &full_clone, N_("when cloning, create full working directory")), + OPT_BOOL(0, "single-branch", &single_branch, + N_("only download metadata for the branch that will " + "be checked out")), OPT_END(), }; const char * const clone_usage[] = { @@ -402,7 +405,9 @@ static int cmd_clone(int argc, const char **argv) if (set_config("remote.origin.url=%s", url) || set_config("remote.origin.fetch=" - "+refs/heads/*:refs/remotes/origin/*") || + "+refs/heads/%s:refs/remotes/origin/%s", + single_branch ? branch : "*", + single_branch ? branch : "*") || set_config("remote.origin.promisor=true") || set_config("remote.origin.partialCloneFilter=blob:none")) { res = error(_("could not configure remote in '%s'"), dir); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index d65fb5f1491..46999cf7c84 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar clone [--branch ] [--full-clone] [] +scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -56,6 +56,16 @@ subdirectories outside your sparse-checkout by using `git ls-tree HEAD`. Instead of checking out the branch pointed to by the cloned repository's HEAD, check out the `` branch instead. +--[no-]single-branch:: + Clone only the history leading to the tip of a single branch, either + specified by the `--branch` option or the primary branch remote's + `HEAD` points at. ++ +Further fetches into the resulting repository will only update the +remote-tracking branch for the branch this option was used for the initial +cloning. If the HEAD at the remote did not point at any branch when +`--single-branch` clone was made, no remote-tracking branch is created. + --[no-]full-clone:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 295398f62cc..9a35ab4fde6 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' ' test_expect_success 'scalar clone' ' second=$(git rev-parse --verify second:second.t) && - scalar clone "file://$(pwd)" cloned && + scalar clone "file://$(pwd)" cloned --single-branch && ( cd cloned/src && git config --get --global --fixed-value maintenance.repo \ "$(pwd)" && + git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual && + echo "refs/remotes/origin/parallel" >expect && + test_cmp expect actual && + test_path_is_missing 1/2 && test_must_fail git rev-list --missing=print $second && git rev-list $second && From patchwork Thu Oct 7 10:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12541569 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 71B66C433F5 for ; Thu, 7 Oct 2021 10:59:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A7E961058 for ; Thu, 7 Oct 2021 10:59:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240666AbhJGLBg (ORCPT ); Thu, 7 Oct 2021 07:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241021AbhJGLBX (ORCPT ); Thu, 7 Oct 2021 07:01:23 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4911C06176D for ; Thu, 7 Oct 2021 03:59:18 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id s15so17816278wrv.11 for ; Thu, 07 Oct 2021 03:59:18 -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=r16GA9XdAq44eQzQb75Q58Xi22aaWnk4iW8ItzuXDOo=; b=ne+1WmptBbC79sLzrcFp+MaoEcR1miDJliJTRPiSRp+BEZV3j+4axO82SdeSISx0lN 2JeSp0pmpYMMcJ8D35YqKw1bjQ9A5rf9+359aYTrpuUlSntLonOX2/TkSteS1Zs6fmOE qZMxmQkjcLyslqck2zalKFmGjaOJYWzn4a4EUST8cTuHNbDKvH3mBdoUewFABsRmHndf ke2l4SKvdaYIeieqYarG6sTVsG1qaZ7vStlJ36LY4+3xzyanPOM3TWICGFy74b6lXWPR UzusLhVulA4RePRFHQXTvkfbyY0hlRXH2o+m4tLCYQFRQWAm0jqBRoX9IbcVKWlIo3Gj roRw== 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=r16GA9XdAq44eQzQb75Q58Xi22aaWnk4iW8ItzuXDOo=; b=cWvf+sgo5+vOqyg5j/DcF6W82pUI35994S+MjPYz2oGb/BPqn3LiPYsIaPvp3DbWby 3lFlw2OygKVVdrORImzVEqVG2F60BSr6kEeqILTLpIJYAEq1vjaPAdwKp2GGTf2vLu/Y SIJOpd+2aDY6nF44aqnNylCZXLJkG3Yatsg3Bl340ZZUe8fwpv0DvEz3Gr8jKAriDJZa /s5uZGz6iC7yCnCLEogNd2We4LEc67L/9/9NQ3XVNcLJghv+pBxqgChsZCLm5Zt1ug80 fu9JSR0bHeRVAI1sIZ1oqsJlQTH+J8F6PgmJPP6j2QiGs3gTYUBYzkxMRv4SaiYbIvIc CAUA== X-Gm-Message-State: AOAM533JmbBna2pxYaR2v+qXc+DWOiAp3ErNMKnwmEai97D8jzzlPByR Qwcjzz8K6A094vzrzZVacY1Vx76FeuY= X-Google-Smtp-Source: ABdhPJwQ2XHU3qjz1yfcWPcsNxbXvieR/Cl45+kVDi9J02kG1uBZ+YK5cn6HkcjHN/kEno3IkYvQbw== X-Received: by 2002:adf:8b15:: with SMTP id n21mr4585626wra.373.1633604357481; Thu, 07 Oct 2021 03:59:17 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p14sm8041998wmc.18.2021.10.07.03.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:17 -0700 (PDT) Message-Id: <5a0b3843f986246d33f5ea3c63e5d67619348816.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:04 +0000 Subject: [PATCH v5 10/15] scalar: implement the `run` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= 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 From: Derrick Stolee Note: this subcommand is provided primarily for backwards-compatibility, for existing Scalar uses. It is mostly just a shim for `git maintenance`, mapping task names from the way Scalar called them to the way Git calls them. The reason why those names differ? The background maintenance was first implemented in Scalar, and when it was contributed as a patch series implementing the `git maintenance` command, reviewers suggested better names, those suggestions were accepted before the patches were integrated into core Git. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 64 +++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 19 ++++++++++++ 2 files changed, 83 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 754e19d781d..d9631287e12 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -483,6 +483,69 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_run(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + struct { + const char *arg, *task; + } tasks[] = { + { "config", NULL }, + { "commit-graph", "commit-graph" }, + { "fetch", "prefetch" }, + { "loose-objects", "loose-objects" }, + { "pack-files", "incremental-repack" }, + { NULL, NULL } + }; + struct strbuf buf = STRBUF_INIT; + const char *usagestr[] = { NULL, NULL }; + int i; + + strbuf_addstr(&buf, N_("scalar run []\nTasks:\n")); + for (i = 0; tasks[i].arg; i++) + strbuf_addf(&buf, "\t%s\n", tasks[i].arg); + usagestr[0] = buf.buf; + + argc = parse_options(argc, argv, NULL, options, + usagestr, 0); + + if (!argc) + usage_with_options(usagestr, options); + + if (!strcmp("all", argv[0])) { + i = -1; + } else { + for (i = 0; tasks[i].arg && strcmp(tasks[i].arg, argv[0]); i++) + ; /* keep looking for the task */ + + if (i > 0 && !tasks[i].arg) { + error(_("no such task: '%s'"), argv[0]); + usage_with_options(usagestr, options); + } + } + + argc--; + argv++; + setup_enlistment_directory(argc, argv, usagestr, options, NULL); + strbuf_release(&buf); + + if (i == 0) + return register_dir(); + + if (i > 0) + return run_git("maintenance", "run", + "--task", tasks[i].task, NULL); + + if (register_dir()) + return -1; + for (i = 1; tasks[i].arg; i++) + if (run_git("maintenance", "run", + "--task", tasks[i].task, NULL)) + return -1; + return 0; +} + static int remove_deleted_enlistment(struct strbuf *path) { int res = 0; @@ -555,6 +618,7 @@ static struct { { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, + { "run", cmd_run }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 46999cf7c84..f139a14445d 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -12,6 +12,7 @@ scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar unregister [] +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] DESCRIPTION ----------- @@ -97,6 +98,24 @@ unregister []:: Remove the specified repository from the list of repositories registered with Scalar and stop the scheduled background maintenance. +Run +~~~ + +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) []:: + Run the given maintenance task (or all tasks, if `all` was specified). + Except for `all` and `config`, this subcommand simply hands off to + linkgit:git-maintenance[1] (mapping `fetch` to `prefetch` and + `pack-files` to `incremental-repack`). ++ +These tasks are run automatically as part of the scheduled maintenance, +as soon as the repository is registered with Scalar. It should therefore +not be necessary to run this subcommand manually. ++ +The `config` task is specific to Scalar and configures all those +opinionated default settings that make Git work more efficiently with +large repositories. As this task is run as part of `scalar clone` +automatically, explicit invocations of this task are rarely needed. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. From patchwork Thu Oct 7 10:59:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541573 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 35DE1C433F5 for ; Thu, 7 Oct 2021 10:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2177B61037 for ; Thu, 7 Oct 2021 10:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241058AbhJGLBj (ORCPT ); Thu, 7 Oct 2021 07:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbhJGLBc (ORCPT ); Thu, 7 Oct 2021 07:01:32 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B67EC061770 for ; Thu, 7 Oct 2021 03:59:19 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id s15so17816346wrv.11 for ; Thu, 07 Oct 2021 03:59:19 -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=zGssjCUMokN6LywI6vj6tG7mE1c4jNsC+AwuvBfiN/U=; b=f3OPHif0IVtmx3+IoVfQmA5QzXIztrXOtL2o/e45CiNE2khpJJbk/QIl4ZKEX01Xxq VXRWyGCmVFOf/Hpqqy+6RMX5uZPjM87Y/jZP0AaYDC2JiiNnDprwzHxBxJ4f0mvSyU58 2du6bLcFJHKU+0/mcpPazs1UU0MsNWkaHAV06vdEVb04Al5nqZIxFIMg7O/rvsf4VqaA +zAcqovUtp/lT5+fWEz2NG8z2lPVGZarJd3BZfKFzlo5x8gH8hBNOLpaU7y8Au82j91n Nb0R3m9rLPBjmxqeDruZMdxOXREMlSZC03Icy0U6nyXfiXpi2vQoet9PTvGDO00Sciud lUpg== 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=zGssjCUMokN6LywI6vj6tG7mE1c4jNsC+AwuvBfiN/U=; b=06lRsbsTLw9lcSxJp/I0lD6RSqKdeezYMdkEGn4/JBVuXtvMtZzuX4TLOJZuKkijGI QCOQ/x6+VLGvZ2PqmFMBosb5GuxA5d/5xSDbnScLwh6roLQosrhzbYDeFLZZONCyObjG k4hEG4Iw0/FOTARgV2nWUyqQuAWZ66re1pOVmpaKGCrjBU0CM83Cay6TEeeqVwiPr3c4 aW1EK7xZlhdQKjZbexwXgk6zef8qyuSbehtPLOVMPHMv2Syx0CHKo7K5/rau3qNX/YMY LoN99iWqizYGcb8028Lt7e5JrNufJQ/P5NPg8X0i9yA1+NRd9vn6SJ0c3yWus1YUcBb3 bJ7w== X-Gm-Message-State: AOAM532PXzlTJ988iIVeauD8jFQcDxHOjYmtsssfKhjVx1yCf1hcabHC j/YzbmP2W5O1MNo4Mtf5eaaUGjkWOZA= X-Google-Smtp-Source: ABdhPJx6nK7R/oZ0ZiyHr3ffiJbHsrF2A+eweNNIOWbBXzFkCvw66Cm6WVivBbBnigpqjs7YLnrecg== X-Received: by 2002:adf:bb08:: with SMTP id r8mr4568242wrg.247.1633604358080; Thu, 07 Oct 2021 03:59:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h18sm9494673wmq.23.2021.10.07.03.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:17 -0700 (PDT) Message-Id: <6d9aaeb05fae09f577ce9d7cb1e008b2625c67ed.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:05 +0000 Subject: [PATCH v5 11/15] scalar: allow reconfiguring an existing enlistment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This comes in handy during Scalar upgrades, or when config settings were messed up by mistake. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 79 +++++++++++++++++++++----------- contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 8 ++++ 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index d9631287e12..6bebba0b51f 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -108,18 +108,20 @@ static int run_git(const char *arg, ...) return res; } -static int set_recommended_config(void) +static int set_recommended_config(int reconfigure) { struct { const char *key; const char *value; + int overwrite_on_reconfigure; } config[] = { - { "am.keepCR", "true" }, - { "core.FSCache", "true" }, - { "core.multiPackIndex", "true" }, - { "core.preloadIndex", "true" }, + /* Required */ + { "am.keepCR", "true", 1 }, + { "core.FSCache", "true", 1 }, + { "core.multiPackIndex", "true", 1 }, + { "core.preloadIndex", "true", 1 }, #ifndef WIN32 - { "core.untrackedCache", "true" }, + { "core.untrackedCache", "true", 1 }, #else /* * Unfortunately, Scalar's Functional Tests demonstrated @@ -133,28 +135,29 @@ static int set_recommended_config(void) * Therefore, with a sad heart, we disable this very useful * feature on Windows. */ - { "core.untrackedCache", "false" }, + { "core.untrackedCache", "false", 1 }, #endif - { "core.logAllRefUpdates", "true" }, - { "credential.https://dev.azure.com.useHttpPath", "true" }, - { "credential.validate", "false" }, /* GCM4W-only */ - { "gc.auto", "0" }, - { "gui.GCWarning", "false" }, - { "index.threads", "true" }, - { "index.version", "4" }, - { "merge.stat", "false" }, - { "merge.renames", "false" }, - { "pack.useBitmaps", "false" }, - { "pack.useSparse", "true" }, - { "receive.autoGC", "false" }, - { "reset.quiet", "true" }, - { "feature.manyFiles", "false" }, - { "feature.experimental", "false" }, - { "fetch.unpackLimit", "1" }, - { "fetch.writeCommitGraph", "false" }, + { "core.logAllRefUpdates", "true", 1 }, + { "credential.https://dev.azure.com.useHttpPath", "true", 1 }, + { "credential.validate", "false", 1 }, /* GCM4W-only */ + { "gc.auto", "0", 1 }, + { "gui.GCWarning", "false", 1 }, + { "index.threads", "true", 1 }, + { "index.version", "4", 1 }, + { "merge.stat", "false", 1 }, + { "merge.renames", "false", 1 }, + { "pack.useBitmaps", "false", 1 }, + { "pack.useSparse", "true", 1 }, + { "receive.autoGC", "false", 1 }, + { "reset.quiet", "true", 1 }, + { "feature.manyFiles", "false", 1 }, + { "feature.experimental", "false", 1 }, + { "fetch.unpackLimit", "1", 1 }, + { "fetch.writeCommitGraph", "false", 1 }, #ifdef WIN32 - { "http.sslBackend", "schannel" }, + { "http.sslBackend", "schannel", 1 }, #endif + /* Optional */ { "status.aheadBehind", "false" }, { "commitGraph.generationVersion", "1" }, { "core.autoCRLF", "false" }, @@ -165,7 +168,8 @@ static int set_recommended_config(void) char *value; for (i = 0; config[i].key; i++) { - if (git_config_get_string(config[i].key, &value)) { + 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) @@ -230,7 +234,7 @@ static int register_dir(void) int res = add_or_remove_enlistment(1); if (!res) - res = set_recommended_config(); + res = set_recommended_config(0); if (!res) res = toggle_maintenance(1); @@ -418,7 +422,7 @@ static int cmd_clone(int argc, const char **argv) (res = run_git("sparse-checkout", "init", "--cone", NULL))) goto cleanup; - if (set_recommended_config()) + if (set_recommended_config(0)) return error(_("could not configure '%s'"), dir); if ((res = run_git("fetch", "--quiet", "origin", NULL))) { @@ -483,6 +487,24 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_reconfigure(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar reconfigure []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); +} + static int cmd_run(int argc, const char **argv) { struct option options[] = { @@ -619,6 +641,7 @@ static struct { { "register", cmd_register }, { "unregister", cmd_unregister }, { "run", cmd_run }, + { "reconfigure", cmd_reconfigure }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f139a14445d..f4e4686e8c8 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,6 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] +scalar reconfigure DESCRIPTION ----------- @@ -116,6 +117,13 @@ opinionated default settings that make Git work more efficiently with large repositories. As this task is run as part of `scalar clone` automatically, explicit invocations of this task are rarely needed. +Reconfigure +~~~~~~~~~~~ + +After a Scalar upgrade, or when the configuration of a Scalar enlistment +was somehow corrupted or changed by mistake, this subcommand allows to +reconfigure the enlistment. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 9a35ab4fde6..e6d74a06ca0 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -65,4 +65,12 @@ test_expect_success 'scalar clone' ' ) ' +test_expect_success 'scalar reconfigure' ' + git init one/src && + scalar register one && + git -C one/src config core.preloadIndex false && + scalar reconfigure one && + test true = "$(git -C one/src config core.preloadIndex)" +' + test_done From patchwork Thu Oct 7 10:59:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541577 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 2B84AC433EF for ; Thu, 7 Oct 2021 10:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14E8F60F58 for ; Thu, 7 Oct 2021 10:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241047AbhJGLBt (ORCPT ); Thu, 7 Oct 2021 07:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240626AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E780C061772 for ; Thu, 7 Oct 2021 03:59:20 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id o20so17775157wro.3 for ; Thu, 07 Oct 2021 03:59:19 -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=argkibHjUQ9fS/MNRyNYx0ks0Fl/uHUjHr6yTHx1viE=; b=KdG/IfQPme3p58PDKkK8RUfXxYWBuTC34JccgzPkKh+bzSty0/PQLRAQFDl/wE6veP T3NxymUKu+iEHNpIuokeRU2sG/nyY2zYkIiNwNZaV5GtBM7y3Se0ZJctS8dwMsnjeYk6 XnSJBHIEsm/XeKiJaT3uGNc8DvnLg0xeq/JnvXl4YRkOh5jnax5pWpqHkvXCt+ggjsHA Kv7y8mr7KCF/xr2/a+69Lw+qFv/RLVLq4NNLqA/tbUIxX9p2qLDcIDBweAKh/m0AiJpb d+RHvoX4aW+yYWHs8q/6ve9VHW8Bsg9AI8+mpz/SJWiX3QQ3D+UbVgakL9ahVZOXJL8+ J+Ow== 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=argkibHjUQ9fS/MNRyNYx0ks0Fl/uHUjHr6yTHx1viE=; b=CKWzq7SE0SMrJz2+16TvQATFTLVyyA/fNIkYp8co6rnO13uYVxXKLfG74CgdHDReFA MZot3a2EY+QC9enshgRMuHhMORSJF4oYQ/RuWLx4/YGzGZSs4PiF3ALG0glgzPCqJiMs XXHBv/BhSNlxR3yufzwRrZMACQCuUD88xLuTow/oh1gvLwTv+eRzRq7Y4+B8d0H6Y72y qQaXgGUum3nms1CZiRrF3t6saudJD7pi/r4nafv/B6jCqoPfrulgGFz66CZtRPuOjjTd J/tKE3A7yV3OCJFtgQdjwXMm48T55eqPSYLKKcJnqM4rCswA/ZSCmvh9tWz9TnTpxdNO LSog== X-Gm-Message-State: AOAM5339Dqxgsm3hwZp/ir3PFJT8+fOFlfnKj4AvnG8JcnMaSL17OymC aWZrt8TdaM1eKItC5JkGDWfYIzJYkA4= X-Google-Smtp-Source: ABdhPJxf5crLtB8zsr9HF/jhU05OB5elZ/oO+cTR3xps2MZMQ616tsvnMedTtlPySey5iHGVX1cRuw== X-Received: by 2002:a1c:7418:: with SMTP id p24mr15902380wmc.59.1633604358655; Thu, 07 Oct 2021 03:59:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n15sm24679958wrg.58.2021.10.07.03.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:18 -0700 (PDT) Message-Id: <2967d7f1425e06f15e3f696fa873b952b128df51.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:06 +0000 Subject: [PATCH v5 12/15] scalar: teach 'reconfigure' to optionally handle all registered enlistments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin After a Scalar upgrade, it can come in really handy if there is an easy way to reconfigure all Scalar enlistments. This new option offers this functionality. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 61 ++++++++++++++++++++++++++++++-- contrib/scalar/scalar.txt | 9 +++-- contrib/scalar/t/t9099-scalar.sh | 3 ++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 6bebba0b51f..234a7dce479 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -487,22 +487,77 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int get_scalar_repos(const char *key, const char *value, void *data) +{ + struct string_list *list = data; + + if (!strcmp(key, "scalar.repo")) + string_list_append(list, value); + + return 0; +} + static int cmd_reconfigure(int argc, const char **argv) { + int all = 0; struct option options[] = { + OPT_BOOL('a', "all", &all, + N_("reconfigure all registered enlistments")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure []"), + N_("scalar reconfigure [--all | ]"), NULL }; + struct string_list scalar_repos = STRING_LIST_INIT_DUP; + int i, res = 0; + struct repository r = { NULL }; + struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT; argc = parse_options(argc, argv, NULL, options, usage, 0); - setup_enlistment_directory(argc, argv, usage, options, NULL); + if (!all) { + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); + } + + if (argc > 0) + usage_msg_opt(_("--all or , but not both"), + usage, options); + + git_config(get_scalar_repos, &scalar_repos); - return set_recommended_config(1); + for (i = 0; i < scalar_repos.nr; i++) { + const char *dir = scalar_repos.items[i].string; + + strbuf_reset(&commondir); + strbuf_reset(&gitdir); + + if (chdir(dir) < 0) { + warning_errno(_("could not switch to '%s'"), dir); + res = -1; + } else if (discover_git_directory(&commondir, &gitdir) < 0) { + warning_errno(_("git repository gone in '%s'"), dir); + res = -1; + } else { + git_config_clear(); + + the_repository = &r; + r.commondir = commondir.buf; + r.gitdir = gitdir.buf; + + if (set_recommended_config(1) < 0) + res = -1; + } + } + + string_list_clear(&scalar_repos, 1); + strbuf_release(&commondir); + strbuf_release(&gitdir); + + return res; } static int cmd_run(int argc, const char **argv) diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f4e4686e8c8..2fa96fcabc6 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,7 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] -scalar reconfigure +scalar reconfigure [ --all | ] DESCRIPTION ----------- @@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `clone` and `list`, all -subcommands expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone`, `list` and +`reconfigure --all`, all subcommands expect to be run in an enlistment. COMMANDS -------- @@ -124,6 +124,9 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment was somehow corrupted or changed by mistake, this subcommand allows to reconfigure the enlistment. +With the `--all` option, all enlistments currently registered with Scalar +will be reconfigured. Use this option after each Scalar upgrade. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index e6d74a06ca0..5fe7fabd0e5 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -70,6 +70,9 @@ test_expect_success 'scalar reconfigure' ' scalar register one && git -C one/src config core.preloadIndex false && scalar reconfigure one && + test true = "$(git -C one/src config core.preloadIndex)" && + git -C one/src config core.preloadIndex false && + scalar reconfigure -a && test true = "$(git -C one/src config core.preloadIndex)" ' From patchwork Thu Oct 7 10:59:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew John Cheetham X-Patchwork-Id: 12541579 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 2AB9BC433F5 for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13C4361038 for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241090AbhJGLBw (ORCPT ); Thu, 7 Oct 2021 07:01:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240643AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -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 9ACFBC061775 for ; Thu, 7 Oct 2021 03:59:20 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id s15so17816486wrv.11 for ; Thu, 07 Oct 2021 03:59:20 -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=kICDSfcRYpWtR/TkrbdlrrkyOK3hh+156uSWJrG1Tkk=; b=Codkc+Sipxh0QBnP4TlitSLaLMIn6yP2RW3nihQdAPFSowLEZ2H1QPB2zcO8BEc/mM GW/fcd1raIDI5c63ko8XLvH11JGJ/ZZ49AOviEqDB+eIY3NZFNh5i6q9BYr2bgptaYB/ k+C4cr7chVC/ppOf9kc1B6XfJbs1boAYLLk3uLPxalSrfBRhUJFg0pqfCLPH/6JfOSnh raGZ/hNRzkAAo6NjF6L6LejYlaPmuzcsQUcwvX8a/xpYlrmLrLC4dlRfI8ftwQ5USXia Sk6PYmAta2z/zkbuxvj2XLfxG+a8O5bRT8y/tgUXxnhTmHjvixE0UMH0wGrWgZtkhoVE qy7A== 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=kICDSfcRYpWtR/TkrbdlrrkyOK3hh+156uSWJrG1Tkk=; b=TpHH5LNqb3+ulAc+Vb8/LeAUNqI2LTsD5sLxmJ9V22hO1rKDrnvVMCcPIIJlBuRY4+ kKA9ejsutbCzT4WWrJIWryT/61QifTP/i7HeZjbm+IzoejtR957Lur5FrD2ykZlHYP75 Il7lWdd8wrTjLaaERuVr3/q7PsTR6F4lua2XGwBV0d3MGXtB8033a3IOS5QYiRocqHEj 4x0YWkdauLG8/WjdjE/qDJeAhpMapEJvvTPnk4mjdWPNxpAXRL265TNaW+HAzateo96i aAZgemQRhEADIDIT2uFZwSf+yoqWBPLwxPPYe8utNo1sYyBtfU9eXDsKvkaYhoEQEOB1 HtiA== X-Gm-Message-State: AOAM533KZnsu/G/pUS2I729phasRGpGEMfKQ2iayfNKmxxxwRgVevBCe xmH4UOcdM/m/i8B8JhawTUQRA7fCKis= X-Google-Smtp-Source: ABdhPJymxRabFsBfRKXuwRaU2aHhF+ZlxfF16+dfRxaLDfH8NxTWoS1jejz64bP9aDwtcJE/X4qABw== X-Received: by 2002:adf:a30b:: with SMTP id c11mr4480916wrb.289.1633604359273; Thu, 07 Oct 2021 03:59:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x17sm23963280wrc.51.2021.10.07.03.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:18 -0700 (PDT) Message-Id: <8069cc536fedce2c4707efa87832bc06b443060f.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:07 +0000 Subject: [PATCH v5 13/15] scalar: implement the `delete` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Matthew John Cheetham Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew John Cheetham From: Matthew John Cheetham Delete an enlistment by first unregistering the repository and then deleting the enlistment directory (usually the directory containing the worktree `src/` directory). On Windows, if the current directory is inside the enlistment's directory, change to the parent of the enlistment directory, to allow us to delete the enlistment (directories used by processes e.g. as current working directories cannot be deleted on Windows). Co-authored-by: Victoria Dye Signed-off-by: Matthew John Cheetham Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 63 ++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 9 +++++ 3 files changed, 80 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 234a7dce479..8aaeca7cc64 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -8,6 +8,8 @@ #include "config.h" #include "run-command.h" #include "refs.h" +#include "dir.h" +#include "packfile.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -327,6 +329,33 @@ static char *remote_default_branch(const char *url) return NULL; } +static int delete_enlistment(struct strbuf *enlistment) +{ +#ifdef WIN32 + struct strbuf parent = STRBUF_INIT; +#endif + + if (unregister_dir()) + die(_("failed to unregister repository")); + +#ifdef WIN32 + /* + * 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); + if (chdir(parent.buf) < 0) + die_errno(_("could not switch to '%s'"), parent.buf); + strbuf_release(&parent); +#endif + + if (remove_dir_recursively(enlistment, 0)) + die(_("failed to delete enlistment directory")); + + return 0; +} + static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; @@ -687,6 +716,39 @@ static int cmd_unregister(int argc, const char **argv) return unregister_dir(); } +static int cmd_delete(int argc, const char **argv) +{ + char *cwd = xgetcwd(); + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar delete "), + NULL + }; + struct strbuf enlistment = STRBUF_INIT; + int res = 0; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + if (argc != 1) + usage_with_options(usage, options); + + setup_enlistment_directory(argc, argv, usage, options, &enlistment); + + if (dir_inside_of(cwd, enlistment.buf) >= 0) + res = error(_("refusing to delete current working directory")); + else { + close_object_store(the_repository->objects); + res = delete_enlistment(&enlistment); + } + strbuf_release(&enlistment); + free(cwd); + + return res; +} + static struct { const char *name; int (*fn)(int, const char **); @@ -697,6 +759,7 @@ static struct { { "unregister", cmd_unregister }, { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, + { "delete", cmd_delete }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 2fa96fcabc6..6fc57707718 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -14,6 +14,7 @@ scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] scalar reconfigure [ --all | ] +scalar delete DESCRIPTION ----------- @@ -127,6 +128,13 @@ reconfigure the enlistment. With the `--all` option, all enlistments currently registered with Scalar will be reconfigured. Use this option after each Scalar upgrade. +Delete +~~~~~~ + +delete :: + This subcommand lets you delete an existing Scalar enlistment from your + local file system, unregistering the repository. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 5fe7fabd0e5..7e8771d0eff 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -76,4 +76,13 @@ test_expect_success 'scalar reconfigure' ' test true = "$(git -C one/src config core.preloadIndex)" ' +test_expect_success 'scalar delete without enlistment shows a usage' ' + test_expect_code 129 scalar delete +' + +test_expect_success 'scalar delete with enlistment' ' + scalar delete cloned && + test_path_is_missing cloned +' + test_done From patchwork Thu Oct 7 10:59:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541575 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 859D1C433F5 for ; Thu, 7 Oct 2021 10:59:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 707A661037 for ; Thu, 7 Oct 2021 10:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241065AbhJGLBn (ORCPT ); Thu, 7 Oct 2021 07:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240896AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -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 31174C061779 for ; Thu, 7 Oct 2021 03:59:21 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id t2so17760838wrb.8 for ; Thu, 07 Oct 2021 03:59:21 -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=cq7xpzv9Jt0r+m3QH1PsZIBW9iGrieo+DLK5++RfiqM=; b=Dou5n6Hyoz+rWNUBWzRibf4LkcfLrhXggwhJqCtOtYLIEic1QNvP3ehmVyt2856s15 j3CKi7JaEAvAmNUWejP37TvbX7DyzPhG/cS49WSdZTJvS3lhSJfOK166Gqf7LY2DFM24 TVZocrpzIgmvfW9UT2Rbc0+jXSXiceKwKRYVrdGHo0XjXYq0GWps8KYjC6DeV+PNaYDi vTcL5aevo3EKerkETM5rrABWD8fBZfqGvDraHKwEhoGX55OykX/uuZ8P98seCAmyjAOW 5uvMk1dYIHLMkh2j1cOpr1+fEYKGgg8vw6qmmh3c3XHWNbeRNAf8l/lp+vsn0RZ5lNqs JiMQ== 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=cq7xpzv9Jt0r+m3QH1PsZIBW9iGrieo+DLK5++RfiqM=; b=Av6WML4HKeN5k4XLUejNBfG+6d9Dq4SfgHFwu3rGbZSWsiox+M8xgWQ2g7UQ3eNNH7 I7neYuHLixmVd5R6qYYLPJM/4ER5/CQbzEPyR2hQ272lrTlBVDWWOUz7c3HhZ4qaitAs loGyQWNDznS3190KESHY9Oq2xGqyPezFusjQfZszykIGwU55sfIrV5XWdO1TdWsBbE/z xXSco0OCrf31eQSddQfA8LrDIMGyYI3tuzGkskFy/kEaWSeWScSe9ud3SgSq1neucOAz lMpskpS5fAG5Xfx473GdXkbxOf9mLNO0tG0Xh7O1707ytBwKAAMcued+rnnqnGldFVIL /GSQ== X-Gm-Message-State: AOAM53059/8mtM3Zdj1GgiPE7rzeR6OxxnOtXsXmdVoqI5PCCzji+ztk XU4dSS0GmUJZkTH4RzIfRx15uFzoB1E= X-Google-Smtp-Source: ABdhPJyPaT1z8Eb1TNe1XaiFAmdQ+T/x2XE2azy5KqDwHC0Kmc1lAeu3AxjB62oKiQSqY/6KgXR8iA== X-Received: by 2002:a05:600c:3550:: with SMTP id i16mr3814971wmq.153.1633604359848; Thu, 07 Oct 2021 03:59:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h15sm16243235wrt.0.2021.10.07.03.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:19 -0700 (PDT) Message-Id: <2ecfaa5d0fe7fecde35e409900b2dfb78b02a96b.1633604349.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:08 +0000 Subject: [PATCH v5 14/15] scalar: implement the `version` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The .NET version of Scalar has a `version` command. This was necessary because it was versioned independently of Git. Since Scalar is now tightly coupled with Git, it does not make sense for them to show different versions. Therefore, it shows the same output as `git version`. For backwards-compatibility with the .NET version, `scalar version` prints to `stderr`, though (`git version` prints to `stdout` instead). Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 8aaeca7cc64..b2e92cf63b5 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -10,6 +10,7 @@ #include "refs.h" #include "dir.h" #include "packfile.h" +#include "help.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -356,6 +357,15 @@ static int delete_enlistment(struct strbuf *enlistment) return 0; } +/* + * Dummy implementation; Using `get_version_info()` would cause a link error + * without this. + */ +void load_builtin_commands(const char *prefix, struct cmdnames *cmds) +{ + die("not implemented"); +} + static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; @@ -749,6 +759,34 @@ static int cmd_delete(int argc, const char **argv) return res; } +static int cmd_version(int argc, const char **argv) +{ + int verbose = 0, build_options = 0; + struct option options[] = { + OPT__VERBOSE(&verbose, N_("include Git version")), + OPT_BOOL(0, "build-options", &build_options, + N_("include Git's build options")), + OPT_END(), + }; + const char * const usage[] = { + N_("scalar verbose [-v | --verbose] [--build-options]"), + NULL + }; + struct strbuf buf = STRBUF_INIT; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + if (argc != 0) + usage_with_options(usage, options); + + get_version_info(&buf, build_options); + fprintf(stderr, "%s\n", buf.buf); + strbuf_release(&buf); + + return 0; +} + static struct { const char *name; int (*fn)(int, const char **); @@ -760,6 +798,7 @@ static struct { { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, { "delete", cmd_delete }, + { "version", cmd_version }, { NULL, NULL}, }; From patchwork Thu Oct 7 10:59:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541581 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 CDF57C433FE for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7EB660F58 for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241103AbhJGLBy (ORCPT ); Thu, 7 Oct 2021 07:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241037AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB04FC06177C for ; Thu, 7 Oct 2021 03:59:21 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id m22so17895455wrb.0 for ; Thu, 07 Oct 2021 03:59:21 -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=HBNrd8h57EHcdKdkPIOTjFextPdmOMJpWyQiiEj8UK8=; b=AfjQviz+f0ERne/L/DYtjD7LME0F261U2q4zqA2/gkdkfXT8M9sXLSuoNMuUTdWhbq aHPb5JKJVH6JlPYG4CVndAI3D5+fLdbyi5wlaIy/usgDK4gD4WWYoEOVJ9+JJIufP0BS lElYer92zuldDmOC7XjlrdKjhxAkxTU0P7umLBibWHT6oL4RkaI5zarUpmsHUczwW1Lk Ledvy5FIIt1Zr3h/2crirGdZXm7dsdJbIagkgovbEzN0Gq8FDCFplOetqLR1B9Oc5Wc3 Idu/Qt1ERBzE39WpX6dXq2DUCK+aQV1ua9YTb/5l9pDGE/V/PLW4hHTiqLQVmrbLBaCd V5Og== 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=HBNrd8h57EHcdKdkPIOTjFextPdmOMJpWyQiiEj8UK8=; b=PVNprEQrSU66wXeE5lF4juBKyrMFHE6ZVthDEFcVbcA4UUxxrgfO9jvdKw2xCmDXKp HXlxk5IVZ4DSwDGxON7ha3IxzmcnFLebEKhCB2WJdf8oDIgRb0CuDVSvIkFLwOCyb+5W 5DIjMhZSaWnHhEoZzJzksbhy6iwtY8qPYEbUysHmsbFaYkv/sdbHd0xyzasAwSZxEYg3 lKPDBLK3wWl5McDlANklgMA/Oo2chkKsjiYwigvSfZUoXNCdQzDOa1fZGAxw94zLsAP8 2Yg9kpW+3ArlXX34FCa0Eyfk8tr+sH9mDHmsJrZKgRhX37X84EXBNVvPRpQgbH9v0RMX Jghw== X-Gm-Message-State: AOAM530He5HnZXCGyqRKZTK0DnF3Nq6BlNSb7+E3e7oYUF7NsrHye5pQ Phhs/Z5UqBLb8msCJX6ns8zLij9U5Z0= X-Google-Smtp-Source: ABdhPJzezEkLDGjmy+8uTprBNFTR4pIvZn4KYMeJl9uiC7oaBCTLvNTprpUpR0jX8IJh8ZAZEQIsTw== X-Received: by 2002:a1c:f002:: with SMTP id a2mr15425519wmb.79.1633604360426; Thu, 07 Oct 2021 03:59:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m14sm7765523wmi.47.2021.10.07.03.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:20 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:09 +0000 Subject: [PATCH v5 15/15] scalar: accept -C and -c options before the subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `git` executable has these two very useful options: -C : switch to the specified directory before performing any actions -c =: temporarily configure this setting for the duration of the specified scalar subcommand With this commit, we teach the `scalar` executable the same trick. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 22 +++++++++++++++++++++- contrib/scalar/scalar.txt | 10 ++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index b2e92cf63b5..6c496318bd4 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -807,6 +807,25 @@ int cmd_main(int argc, const char **argv) struct strbuf scalar_usage = STRBUF_INIT; int i; + while (argc > 1 && *argv[1] == '-') { + if (!strcmp(argv[1], "-C")) { + if (argc < 3) + die(_("-C requires a ")); + if (chdir(argv[2]) < 0) + die_errno(_("could not change to '%s'"), + argv[2]); + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-c")) { + if (argc < 3) + die(_("-c requires a = argument")); + git_config_push_parameter(argv[2]); + argc -= 2; + argv += 2; + } else + break; + } + if (argc > 1) { argv++; argc--; @@ -817,7 +836,8 @@ int cmd_main(int argc, const char **argv) } strbuf_addstr(&scalar_usage, - N_("scalar []\n\nCommands:\n")); + N_("scalar [-C ] [-c =] " + " []\n\nCommands:\n")); for (i = 0; builtins[i].name; i++) strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 6fc57707718..3a80f829edc 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -36,6 +36,16 @@ The `scalar` command implements various subcommands, and different options depending on the subcommand. With the exception of `clone`, `list` and `reconfigure --all`, all subcommands expect to be run in an enlistment. +The following options can be specified _before_ the subcommand: + +-C :: + Before running the subcommand, change the working directory. This + option imitates the same option of linkgit:git[1]. + +-c =:: + For the duration of running the specified subcommand, configure this + setting. This option imitates the same option of linkgit:git[1]. + COMMANDS --------