From patchwork Fri Dec 3 13:34:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ED74C433FE for ; Fri, 3 Dec 2021 13:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352522AbhLCNh6 (ORCPT ); Fri, 3 Dec 2021 08:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241579AbhLCNh6 (ORCPT ); Fri, 3 Dec 2021 08:37:58 -0500 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 DF42AC06173E for ; Fri, 3 Dec 2021 05:34:33 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id d24so5923688wra.0 for ; Fri, 03 Dec 2021 05:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=uQJ4Fsl7CqY1kSfF5905tSksE/gGYx0P1d+aDxCpFio=; b=J2jOHkIafDyCO9wAnS2gmvnPk4CX9eSP5u7YrNhQX9VPr3QxNIohReAq2GoLt9ZpP7 +XFDobvR/jTOBYAsblg2huCi2L8JXOrLsoDaPxcL3filcMgD3OLCReR0MZfSVkS8JmFs WxohLQTq/jAOnRCqfL9CSf64hjtu8kYRqZVV0/8O2qrdD63O064X+o7oVO9h9mEMsLCL DUrFf6sVtiYeqJvyi4H4WJdKlEy2x57bNsnzZBJv3qEFMHYFADHgdoxgpXuxZU5SPAUW vZiOhJQrqSqhdIrmhIF18SnMGuI1GbdtNOyVazm2xZzd3wBQ8Fbo1dXOzC78DliT+WFq IjGg== 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=uQJ4Fsl7CqY1kSfF5905tSksE/gGYx0P1d+aDxCpFio=; b=3f4w+kJjPmReNDCUKFEUAj7JrJ367RjzlQz16c4QpgwUu7ZQwIDtygh21GK5lt5/+6 RYZJymVZ1z/ZWTizJmEfkdCJ1aMCAIbRsoMJC7crJWc57VeFk14NfSZ+Clz+eSYjp2IP Fs+1DNh9OnUyLpfAsBUvjMWGp4SGCE3sLfAx/Cz+nsGAV3z56yCicDS7R54j9HEyS63F gM6gmGRbGFVQjBwG0XocXx6jboBTPIXoW10jg52gLZC5A8SH/D1c3BcppCMIlXaK5gim dXjvlMiexBKoWsDkhugsiRi1RTriZgYEY82wS8FxW8v+TxWTKNBm6mDxFZgzJ1bhk7LP NXAA== X-Gm-Message-State: AOAM531a/gk/94uUjYHAbwiQLt2VrBTO7te01/kRfn1U8m80OhnyLi6G vAtSU5SBRVySULEZv9b6ZsteceibSPE= X-Google-Smtp-Source: ABdhPJz3kyxajDRnzQvfE95TujViNADLqbrmR2lSm6GSNbLRVeVffYKEi0HAXP4nJF3DVjRzOSa5VA== X-Received: by 2002:adf:8b0e:: with SMTP id n14mr20500395wra.281.1638538472180; Fri, 03 Dec 2021 05:34:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k27sm5288175wms.41.2021.12.03.05.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:31 -0800 (PST) Message-Id: <3a2e28275f112d114bbd3ba046f440c5f917fc32.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:15 +0000 Subject: [PATCH v10 01/15] scalar: add a README with a roadmap 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 , Matt Rogers , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The Scalar command will be contributed incrementally, over a bunch of patch series. Let's document what Scalar is about, and then describe the patch series that are planned. Signed-off-by: Johannes Schindelin --- contrib/scalar/README.md | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 contrib/scalar/README.md diff --git a/contrib/scalar/README.md b/contrib/scalar/README.md new file mode 100644 index 00000000000..634b5771ed3 --- /dev/null +++ b/contrib/scalar/README.md @@ -0,0 +1,82 @@ +# Scalar - an opinionated repository management tool + +Scalar is an add-on to Git that helps users take advantage of advanced +performance features in Git. Originally implemented in C# using .NET Core, +based on the learnings from the VFS for Git project, most of the techniques +developed by the Scalar project have been integrated into core Git already: + +* partial clone, +* commit graphs, +* multi-pack index, +* sparse checkout (cone mode), +* scheduled background maintenance, +* etc + +This directory contains the remaining parts of Scalar that are not (yet) in +core Git. + +## Roadmap + +The idea is to populate this directory via incremental patch series and +eventually move to a top-level directory next to `gitk-git/` and to `git-gui/`. The +current plan involves the following patch series: + +- `scalar-the-beginning`: The initial patch series which sets up + `contrib/scalar/` and populates it with a minimal `scalar` command that + demonstrates the fundamental ideas. + +- `scalar-c-and-C`: The `scalar` command learns about two options that can be + specified before the command, `-c =` and `-C `. + +- `scalar-diagnose`: The `scalar` command is taught the `diagnose` subcommand. + +- `scalar-and-builtin-fsmonitor`: The built-in FSMonitor is enabled in `scalar + register` and in `scalar clone`, for an enormous performance boost when + working in large worktrees. This patch series necessarily depends on Jeff + Hostetler's FSMonitor patch series to be integrated into Git. + +- `scalar-gentler-config-locking`: Scalar enlistments are registered in the + user's Git config. This usually does not represent any problem because it is + rare for a user to register an enlistment. However, in Scalar's functional + tests, Scalar enlistments are created galore, and in parallel, which can lead + to lock contention. This patch series works around that problem by re-trying + to lock the config file in a gentle fashion. + +- `scalar-extra-docs`: Add some extensive documentation that has been written + in the original Scalar project (all subject to discussion, of course). + +- `optionally-install-scalar`: Now that Scalar is feature (and documentation) + complete and is verified in CI builds, let's offer to install it. + +- `move-scalar-to-toplevel`: Now that Scalar is complete, let's move it next to + `gitk-git/` and to `git-gui/`, making it a top-level command. + +The following two patch series exist in Microsoft's fork of Git and are +publicly available. There is no current plan to upstream them, not because I +want to withhold these patches, but because I don't think the Git community is +interested in these patches. + +There are some interesting ideas there, but the implementation is too specific +to Azure Repos and/or VFS for Git to be of much help in general (and also: my +colleagues tried to upstream some patches already and the enthusiasm for +integrating things related to Azure Repos and VFS for Git can be summarized in +very, very few words). + +These still exist mainly because the GVFS protocol is what Azure Repos has +instead of partial clone, while Git is focused on improving partial clone: + +- `scalar-with-gvfs`: The primary purpose of this patch series is to support + existing Scalar users whose repositories are hosted in Azure Repos (which + does not support Git's partial clones, but supports its predecessor, the GVFS + protocol, which is used by Scalar to emulate the partial clone). + + Since the GVFS protocol will never be supported by core Git, this patch + series will remain in Microsoft's fork of Git. + +- `run-scalar-functional-tests`: The Scalar project developed a quite + comprehensive set of integration tests (or, "Functional Tests"). They are the + sole remaining part of the original C#-based Scalar project, and this patch + adds a GitHub workflow that runs them all. + + Since the tests partially depend on features that are only provided in the + `scalar-with-gvfs` patch series, this patch cannot be upstreamed. From patchwork Fri Dec 3 13:34:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C92D8C433F5 for ; Fri, 3 Dec 2021 13:34:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352541AbhLCNiE (ORCPT ); Fri, 3 Dec 2021 08:38:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241579AbhLCNh7 (ORCPT ); Fri, 3 Dec 2021 08:37:59 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30151C06173E for ; Fri, 3 Dec 2021 05:34:35 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so2238354wmd.1 for ; Fri, 03 Dec 2021 05:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=9Ejg+jt4xVscGt18Qdg892vaZletSiZ1QxqdhJa+MTg=; b=XG6erWuzzmLDqF05yBpPIep4hxAGyWCTv5Aj59kl2HcLdM51f71J+yAQlOm6Lzkgi0 gfmtMlGoRP9xUAi+WS8FzWrJVy6u05EoFB4Iqb1aBCH1CJkq9afEQxfVxDz0ncd4zAVr YxRSvB6HRhK/OBtqW74KHNB3+NOY8qIflKIgkiYp3R3Zs+oVm9u+9MV23SHeMkL+ZcaT xoxeIo6etOlgkOCwBp8wx9ysW60KAnA2C2Z05IPfAAgfNTBruVwxp9SONtohsmjkU4vC HRDXZdNGCAVxo0TF2kXuibI2Dsourx24iQUqbfkZSFrF5RjYWnlH9doKZ+P1CMUTpPZd dLOw== 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=9Ejg+jt4xVscGt18Qdg892vaZletSiZ1QxqdhJa+MTg=; b=sOASOrgbZKx2DzuseKfQBlaP/hyddjhccD1YLhednEqVKnO6kLGSIPQiOZJgXthhyf yijZ44rqbzFCedBZMyA2d/ss+njKoQAn1oGm9IfTKzuCa0Rj+SQL3yHiEfH0jZwNgMNR BtdJOJcQOyO4kvaw36we8eZpA9zz32BRD5P+MPx56XRLKSu4Pm4vrYsETQAZNd+gmdCv QBWn9TOHm30mM0aLDd7LmDO9SnlGKVCpWIgX3MY20ra1Hq9mlOx0LAmDFyS+VEwGg1De 8ZqKVYV7moROUfcqy8YCoeKIaMYtck0Au6fQmR4dAyG0n3WukeoMC1USegy+3TEZk11l B0Lg== X-Gm-Message-State: AOAM531hwmuY/O465raemsMSd040dKpv5QHNNmQDqrcMOKcgtdzje3Wq yk3koNJCCuYqKkmL+MimVJzv9AxAU68= X-Google-Smtp-Source: ABdhPJy845csRs4PwtvB42RhkYEWReiZdRKyyBx1UnX6gUp3Td6siGoxx2ss9eXa6T9NE9V5e+MQSw== X-Received: by 2002:a05:600c:35c8:: with SMTP id r8mr15056268wmq.8.1638538473382; Fri, 03 Dec 2021 05:34:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y142sm2734397wmc.40.2021.12.03.05.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:32 -0800 (PST) Message-Id: <50160d61a41c182d9b8c6c859975f89415de8482.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:16 +0000 Subject: [PATCH v10 02/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 , Matt Rogers , 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/ 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 12be39ac497..fe898aeea08 100644 --- a/Makefile +++ b/Makefile @@ -2456,6 +2456,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) @@ -2589,6 +2594,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..f6f0036f0fa --- /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: $(GITLIBS) 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 Fri Dec 3 13:34:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C1EBC433EF for ; Fri, 3 Dec 2021 13:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352567AbhLCNiF (ORCPT ); Fri, 3 Dec 2021 08:38:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352570AbhLCNiA (ORCPT ); Fri, 3 Dec 2021 08:38:00 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4434C061757 for ; Fri, 3 Dec 2021 05:34:35 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso4893484wml.1 for ; Fri, 03 Dec 2021 05:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8D4/O9BIeJDyx7UkKc8qSSrWGbYPXQcqw1HfHqLPa9c=; b=fUV1ZZi7NaASypORHB1ciBBsriOeZH41S2aQ4v/372holRIpSrSyXIx5C+1uhTypjh EqOeFNJzwagAJHJsQGLx3xhWXDONKlytxlwPcPHoKd2mXJ9x59E9C7BD78vBHTgnVdim vANlO+yg8SgEe5tC7Ryzcb4TQbsn2X/g1eCMvbSVZ3rPIs9AWNgAThms3ndZOWQHVdIT X1RTkpXUvHfAIYPRDS1FaqikDvAJ5UjPFP/AHUWZumvrFjgSwSUbiNIHoCSNgnDPemY5 BNvuXh4NAhoMMf2tGLbB1TKFh7dducztIFeghX5XTpk0RAdNoooDHRwd6sVHq+skW/Au jZvg== 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=8D4/O9BIeJDyx7UkKc8qSSrWGbYPXQcqw1HfHqLPa9c=; b=dAR5yWNzPK0RZL5tLLYFJnOVu5ueAMhblfoGE06naamSXvrnJAKOYU/Rl4WlOR60Ts auxKtRcDqlV0mStBYmvK1WCNys55XiW2NGJCJ1A8/Il+vogOP/9CDwjz2Vl8Nt/JjHoI OSFgVbjLXIeWC0uT1OchAp2JcexftB4Msz20QIwz8ktepM/vFBTR9kfgBgPDv6JJ65ON kL3znHnzxlDNir+kiN1d1iMdU8lxUy7PTkb+dl/PUS6b62uCaFuK6q+zBosLzODtKgYA u9GjI8d4DEc7SDvix3lSqt9hlJXJ3ET5kDdPzvaQzVWBTSK95oKgs7v+LZx3ojf/b0Tu 0PzA== X-Gm-Message-State: AOAM53303aoTI33dD5LVjRyAdBXoheyGYMVyOJfc6H0a/VGTjHMOkKfB CF799ckuz3oZ5hdAz5+0N+IQYZsqfjs= X-Google-Smtp-Source: ABdhPJw81e8lSXvvEwzHNhtepjeQRJ6kndOjMZHDhWgFFLyuQL+PIabPl7CU29Qc6isMnGMC2ISCCA== X-Received: by 2002:a05:600c:190b:: with SMTP id j11mr14866467wmq.112.1638538474379; Fri, 03 Dec 2021 05:34:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u15sm2254602wmq.13.2021.12.03.05.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:33 -0800 (PST) Message-Id: <74cd64109319748e532339017b3b76a4823f9c86.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:17 +0000 Subject: [PATCH v10 03/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 , Matt Rogers , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Let's build up the documentation for the Scalar command along with the patches that implement its functionality. Note: To discourage the feature-incomplete documentation from being mistaken for the complete thing, we do not yet provide any way to build HTML or manual pages from the text file. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 contrib/scalar/scalar.txt 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 Fri Dec 3 13:34:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64E55C433F5 for ; Fri, 3 Dec 2021 13:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381096AbhLCNiH (ORCPT ); Fri, 3 Dec 2021 08:38:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381025AbhLCNiB (ORCPT ); Fri, 3 Dec 2021 08:38:01 -0500 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 0FBEEC06173E for ; Fri, 3 Dec 2021 05:34:37 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id d9so5806806wrw.4 for ; Fri, 03 Dec 2021 05:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=urTN5i86EXuc5a/mSz2OtPkPDT42VYR77j7zOne496I=; b=P5rKOdJJnR1C0SQnJAtgC3yYtSBE0EtU/cwCh2F5117443+bj/AqMXora5LyHTWJkD SeFIIdFLrMqhu2y9mfL6QT1V9kFokl5JPwuzngzlGTncWSPRZY+E0FVHkI10JzQ4cmLZ u7lj6n9BaZZqWJlONw1bcU3IMclA7+UyEkGTOXAND3OcAOsA8FqUVArpWRv/IOZU9qMs w0st5YhvE98SAYQk9GKYCxG7ZI2DsVvasC6DhSq4ahNJsO3jMYnx7j+5uTKXq0f2OUXd dN0Nhdl5Bfd2L+bqXFW+NMKaVl6Smb/7JBC2slsgVVDrL4lfmuV1myZ/tvZucXzY69Bg ihXw== 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=urTN5i86EXuc5a/mSz2OtPkPDT42VYR77j7zOne496I=; b=y4mynnU8cWLReDB+YvkCBSWfaYhmk2XeGNKgBdMNgwIOxXNlTySDHlQUIzsY9d7rmV 6VDRBsdCvMK0aPhG0J6Gcb6KhgMoYWX9ypgyWYR/RLwDXchr1V9p4pWagdrigghVknpL L/SFpFyDcjz2ay9XBb/apUAcdmgaHysB3Mpg1ggr+PwN3hZ/uB+5WMsy7PGNWRfDAVp8 72fhbJq8rmZaoCnz3gmu0KdIk3fNty4TaDiDXjzONOQBVNlqWuKbuzgnyFVV7CnDLNu9 9yc9ESZrcGKdV0k29YDuV6HSp2RIwm2FJ4n6lTrSgxwWfaPh+o5XurpdDkAayXJLNpjB 52XA== X-Gm-Message-State: AOAM530uXNYfbORhVMdpfKzQALI1MgoSpFC9DXRNvIWVaRe0GDViDquV o1Q5PYFtw3Uq+bSVQZowq4mtXQ40Lgw= X-Google-Smtp-Source: ABdhPJwwPDaK1X2fj9Kxp1Kur/b7EdnefoyMR5MET08JjqnU7DK8Sbnqcv27CE4+MhuEddEzD6mj4w== X-Received: by 2002:adf:f542:: with SMTP id j2mr21298111wrp.616.1638538475385; Fri, 03 Dec 2021 05:34:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k37sm2795942wms.21.2021.12.03.05.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:34 -0800 (PST) Message-Id: <37231a4dd07833807639c8a650185569d0c99af2.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:18 +0000 Subject: [PATCH v10 04/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 , Matt Rogers , 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 and PR builds in that fork. 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 f6f0036f0fa..231b1ee1796 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 @@ -20,7 +21,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 ../../,,$@) @@ -29,6 +30,16 @@ $(TARGETS): $(GITLIBS) scalar.c $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) clean: - $(RM) $(TARGETS) + $(RM) $(TARGETS) ../../bin-wrappers/scalar -.PHONY: $(GITLIBS) all clean FORCE +../../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 + +.PHONY: $(GITLIBS) all clean 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 Fri Dec 3 13:34:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12655203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBB93C433EF for ; Fri, 3 Dec 2021 13:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381043AbhLCNiI (ORCPT ); Fri, 3 Dec 2021 08:38:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381040AbhLCNiC (ORCPT ); Fri, 3 Dec 2021 08:38:02 -0500 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 E59DFC061759 for ; Fri, 3 Dec 2021 05:34:37 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id j3so5833024wrp.1 for ; Fri, 03 Dec 2021 05:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=FDPAGLN+MKZZkOW+Qb6CXrxMnZi1OvSX5uuaWig4Y0I=; b=E4xHZnSZSAoGZEIT5ILl4NuZ06aCVHBIFzU4eOgr3MpPo/soP6bdm8+/xMWmRf3wL7 Juf6RHPivv2Ak4g8ODCx8pD8Ega7RTdm5ArFpUtQFa0aN0viQVjG9zGSfqGIUgOyM9lP YKkWI99nSTTkl6XGD5wz7pTubhpeDTs44UaWPVLZ0F7c7tRFxON0UX0DV3NQd/fCleRU aHPG+SYE9p71Nm9GzeoFcuZAW56Ti45S1aBKl6vwfV+vso3llIzi6L6VGvQMsD0fFAdP rvFuDqKJ+ryp9WDHAL6Z2ms6lRN2dHa6ykZbIu3CZsMGiUDOReXZR/VZzUfbMI60hHRZ l68A== 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=FDPAGLN+MKZZkOW+Qb6CXrxMnZi1OvSX5uuaWig4Y0I=; b=DhAoAFkUIeScmJDfP2AN8HWPv5R1fA89BQPJ5oWAlgERZwDNYVU6YX7O04GQ1+s+QF hE5DtkPEd5+eoCUo/XO/5hgwzyj6NCmndh8jYXS2DXmUMZhIqM5MNXUWqZQqkntS7LIy WHNOGncQ5WYSPQ3ubhxqnclFFHVPuCn9zgJ+Pfopqzj2xEXKmUJfGpVOVwWj4qYb1N86 YI9B4qNaomyBBtPs/T3wP1kOVDQVUNAxb8lDCetbTxD3N65ZWQNpcnUS8Rc6iTiMiMqa Yj1P3hw/r0DzThWh4dY4iw7/+0BSE98yxq5Lbwcv3kuapYfrS4N9IsR6Emgb+JnqBerQ Zy+Q== X-Gm-Message-State: AOAM532ph3HNOSwC4+OOlquAJ8dcBGxh31eZu3h/VMgBU+4SiiIJNUvf UrHSlPH2XcjQ7SDSKojLssq8FZ4E4rg= X-Google-Smtp-Source: ABdhPJx7N0U4izaP3atTQ9Lzt53+hAuQk6QQUlrAU7cyB8Nqhg6V1uRe0Nqw6V7k4cLaSyVnhrGOoA== X-Received: by 2002:a5d:5988:: with SMTP id n8mr21674804wri.309.1638538476308; Fri, 03 Dec 2021 05:34:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r17sm2918425wmq.11.2021.12.03.05.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:35 -0800 (PST) Message-Id: <4439ab4de0bc3f48a6bdcf4b5165b16fad792ebd.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:19 +0000 Subject: [PATCH v10 05/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 , Matt Rogers , 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 | 249 ++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 18 ++- 2 files changed, 266 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7cff29e0fcd..55a304442d4 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -5,11 +5,260 @@ #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", "true" }, + { "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" }, + { "fetch.showForcedUpdates", "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 Fri Dec 3 13:34:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12655205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1D4EC433F5 for ; Fri, 3 Dec 2021 13:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381116AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381060AbhLCNiF (ORCPT ); Fri, 3 Dec 2021 08:38:05 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B888AC06175A for ; Fri, 3 Dec 2021 05:34:38 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id v11so5707622wrw.10 for ; Fri, 03 Dec 2021 05:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=RfUF/RYS/teZLMILSS48GFBpV9FtCRub18a9JOXeUIU=; b=gLubrGDW+AwbySKXDCTMPCdwGprvVV3vx9sZTNGQUabQgI01ByIla+LSi0GxB0yggh k8d3TVAcNRMOxCBIJXYXIT4LRiyMpn2lRb+aWDmCYlzFzx9GYflnkM12Md28TbU2uiz9 Ewq2WCOIIXeLYqzYGxGz75WGMD0PHFUQYLUBMSamZDNne2LoFGlaHlAyjfGo18/H7S7V 96i7PC+TvFpeefD4ffpQSMTnA7AKT/STaEzl5otKp1meZSNYEzBEKsa5pvXwu/kGjR0O 3tNFblBm0L5pZcICU/EgW1AzBJrEYN6nWhwZHFtv5v3oCRZCxx3Ha5InM2c+CI6uB10B dbfg== 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=RfUF/RYS/teZLMILSS48GFBpV9FtCRub18a9JOXeUIU=; b=3vEwhD/S6XLYJw2jJ2uiWtzXOrXGWQkAHNYcdQylzqC/OA+NVhtv6blbig/ONuqyyD YWm/MiZ20KGIOfAlwWafS70M+j7UNHNQMq201ZkbasCAFMfBq+KcUC4oIZdj671gusyL yJn9M6g7ux+W5RfojdwVrNTEP5bF3bV6XrpLnOWMELOMHRvHcCLDQUJK6SM58YNENE+z ql3405PoWZ58XAdAsVkB+C187DW+I3yLzKSQYYQbhWe4QrV9k6HrDVL1ZWUoBmp82EiP DL7Fxwwim3AQomv7GIhvzyQJWIM0cMuZQ8miNxDW3dv3FNUnsz40YFpuRpJIqrPiM50p 3cSg== X-Gm-Message-State: AOAM532+YcK64iTJT4HqTDV7G8ji+RFsjAAY/FQ/txfLeHGrZFR5sAJ5 7gtMYYv6Zm1PtoXpWjNeI47MBHQPUwY= X-Google-Smtp-Source: ABdhPJxsftngAc9YYYolBcYwTTBZsPyoeyzYpssTfVZ23nMZM2TyhPtgb6o7zZEGYoLNu7eiGI6mtA== X-Received: by 2002:adf:ef52:: with SMTP id c18mr22031886wrp.162.1638538477104; Fri, 03 Dec 2021 05:34:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p12sm3372149wrr.10.2021.12.03.05.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:36 -0800 (PST) Message-Id: <376056066a09f19eae4e7bfade076c210a9944a6.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:20 +0000 Subject: [PATCH v10 06/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 , Matt Rogers , 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 55a304442d4..9ab9dffe3ac 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -198,12 +198,12 @@ static int set_recommended_config(void) return 0; } -static int start_maintenance(void) +static int toggle_maintenance(int enable) { - return run_git("maintenance", "start", NULL); + return run_git("maintenance", enable ? "start" : "unregister", NULL); } -static int add_enlistment(void) +static int add_or_remove_enlistment(int add) { int res; @@ -214,24 +214,39 @@ static int add_enlistment(void) "scalar.repo", the_repository->worktree, NULL); /* - * If the setting is already there, then do nothing. + * If we want to add and the setting is already there, then do nothing. + * If we want to remove and the setting is not there, then do nothing. */ - if (!res) + if ((add && !res) || (!add && res)) return 0; - return run_git("config", "--global", "--add", + return run_git("config", "--global", add ? "--add" : "--unset", + add ? "--no-fixed-value" : "--fixed-value", "scalar.repo", the_repository->worktree, NULL); } static int register_dir(void) { - int res = add_enlistment(); + int res = add_or_remove_enlistment(1); if (!res) res = set_recommended_config(); if (!res) - res = start_maintenance(); + res = toggle_maintenance(1); + + return res; +} + +static int unregister_dir(void) +{ + int res = 0; + + if (toggle_maintenance(0) < 0) + res = -1; + + if (add_or_remove_enlistment(0) < 0) + res = -1; return res; } @@ -254,11 +269,30 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_unregister(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar unregister []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return unregister_dir(); +} + static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { { "register", cmd_register }, + { "unregister", cmd_unregister }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 568987064b2..d9a79984492 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] scalar register [] +scalar unregister [] DESCRIPTION ----------- @@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +Unregister +~~~~~~~~~~ + +unregister []:: + Remove the specified repository from the list of repositories + registered with Scalar and stop the scheduled background maintenance. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Fri Dec 3 13:34:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9B9EC433FE for ; Fri, 3 Dec 2021 13:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381115AbhLCNiP (ORCPT ); Fri, 3 Dec 2021 08:38:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352570AbhLCNiG (ORCPT ); Fri, 3 Dec 2021 08:38:06 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2162C06175B for ; Fri, 3 Dec 2021 05:34:39 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id a9so5750957wrr.8 for ; Fri, 03 Dec 2021 05:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=uF47jrxySOx1RCAW8JfnsQEtxQMXRg+E9VpSAZcKnVw=; b=HsCbSU93wiGyN3PRS9Kz4juvCZ6JLWQTbFpFkGleqiX3B4F234vGfwsivlipts8/Pp mHsKpj3hYXOC1SzQOdMWz+V5sQfIUdWtpt8RrZtJXcpm52m5gXrAtJvaxjDpPk7UWIyC 2s0FK0H8Usxdbxc9Eqnb4JOYDAVB2otlTwFfZGE4QT8xgd6xiWwYKbjdWFDbxC1eAl6/ hZM3mnmO8fL0eLlVC4pSH34mLQ8qaof0fsrCOx7o2nqoQrvkevei3uzUynhCNpVGvoRU JG+y2aa5FD5DPstgfekpTGpgWRus7p5z7qN9HJ4cEcgoz8Pj/tCIAks8pNz/6cFZXtJV YxfA== 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=uF47jrxySOx1RCAW8JfnsQEtxQMXRg+E9VpSAZcKnVw=; b=sw+kyHTKiwRb/0GwlzWi6F0m3g421LE/VRSC0rBNrNMyxhWAjXEYoZod/oTtquoqhp lvb7eKJdh7/zxrx6YhidMTsyrNZ0qeyCbSFTyV93RJer/bBbfwBKn4ZqfbMnpEPOwNFu NpLFcNucQtInlZiD20CoCGh6M4hoEjqZgxbOfHM4Qz/3sCn9J6F2W2p7DsbDnTTTkN9k ja2iGUU70njHX9EmMB/A6QCKnQGjYMTYZ9AurErl7GeBUKLMHQBBO9QvJAxkHAWjvHvl P1s2SFjYF5dOfEUi7ZGn27BMpQqwcqiU0Xf62/7MCzz+N0ACV0cI0vyolnTRw5U+Nmt4 RTqg== X-Gm-Message-State: AOAM530cRIph9+QDf+XFMta9saPAk/F+Lq5ovSKQR9RqLF10kvrgH12p t9+FsiyGF9y5CHh+cTabnyffh4Xvles= X-Google-Smtp-Source: ABdhPJx0s+N78CwtZ8ZeS4qegotyMOhB6ApkuL7lVm1mvfDtz+A6EmkF/XLnn9qh6XPMqZKcNpvkig== X-Received: by 2002:a05:6000:1a8b:: with SMTP id f11mr21262427wry.409.1638538478078; Fri, 03 Dec 2021 05:34:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p62sm2666705wmp.10.2021.12.03.05.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:37 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:21 +0000 Subject: [PATCH v10 07/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 , Matt Rogers , 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 9ab9dffe3ac..ec783e72ef3 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -269,6 +269,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[] = { @@ -282,6 +300,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 Fri Dec 3 13:34:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12655209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49450C433F5 for ; Fri, 3 Dec 2021 13:34:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381167AbhLCNiQ (ORCPT ); Fri, 3 Dec 2021 08:38:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381067AbhLCNiG (ORCPT ); Fri, 3 Dec 2021 08:38:06 -0500 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 A1706C06175C for ; Fri, 3 Dec 2021 05:34:40 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id v11so5707848wrw.10 for ; Fri, 03 Dec 2021 05:34:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=AdTnGWdf70EJL03j4oz0mW5N6Ss1tIPbDoMbKCDSoeQ=; b=MogfFNzXhsw8yRSl4NN17wBhPX1yCdF3eZRMu5eztXTiaULHsehdQH/pmLXuTfiELk SKfJfSBA2ZcjAhg98m6sUwxJpCHW0DqQ6rbhauLYtl8BY2zJsI7gy28lI5xS+daqtnPl joQ3L3HGeL0D3QlfXbQpbaLmXrc02RsBgAWaSMIl2sqD1Y2aCLzjOxGlqzwphzYeGzDB v/LsmsBKAoDLzF5gY5bekFg8H98K1fWXARN8C6mFXwX6xdcxCmACmwT0K2XJ++mM0X7O DO3vCeEL6ONL725RzfBnFsFP/+YNuDLOuq+UfcJkXui88qgN766KIa7PHCiPtikB3PNF edag== 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=AdTnGWdf70EJL03j4oz0mW5N6Ss1tIPbDoMbKCDSoeQ=; b=LyTpiEmXSj18zPco62KZwCXA3if1oD17vVwdod6Vo2C+l3RLR7nMjPDyyutPChIqDY 2q/nhHEX3VyLO8oV764BSGqcRSK6Dg8PnUStdMjWjxTgT5fivIqtlldV1T2j8nKiOYgv hExkLTWEXnmQh39yQZ+cLH4jnEJPTUVoejvnYGwxYX7qguGiUMNbyV1EVNymeIBJvMaB KbvupbG5gJku1s3qDbJxsfYK5kHaKwyi6kRF84kEj6lkcF9mUQ8fdZTHNFsvo3Ialj0n eMaGgmIGJ9APK7pPJhF8VPAmCs1sKDKKtSHpUMeY3jNktqXWjMWP0NpLCVt4V0eVCwj+ DRMQ== X-Gm-Message-State: AOAM532K7u7bYD6raj2TAardMzxW7ftEglewKK3l/yWKrjkb9+2jsLPv a3TDbMU8LFufrySQwz8whkgKzUmyLkQ= X-Google-Smtp-Source: ABdhPJz8T72sWyIaJobQ1oINBxXqluSLXE0y04lOcX/FDIKuHQ3UQIbbzM8SyFSDMHB9TGYbZW/c7g== X-Received: by 2002:a5d:6d8c:: with SMTP id l12mr21759251wrs.435.1638538478996; Fri, 03 Dec 2021 05:34:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o4sm5920992wmq.31.2021.12.03.05.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:38 -0800 (PST) Message-Id: <3f8b0abd7d67da77f7b8013814269549bd3ed878.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:22 +0000 Subject: [PATCH v10 08/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 , Matt Rogers , 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 ec783e72ef3..65da885c5ac 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -251,6 +251,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[] = { @@ -337,6 +347,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 Fri Dec 3 13:34:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 249CAC4332F for ; Fri, 3 Dec 2021 13:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381081AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381031AbhLCNiG (ORCPT ); Fri, 3 Dec 2021 08:38:06 -0500 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 7A360C06175E for ; Fri, 3 Dec 2021 05:34:41 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id a9so5751207wrr.8 for ; Fri, 03 Dec 2021 05:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dJoH1g3lf14FbbkcbC9UpnDZthqLHd7bJjcDeRBOdX8=; b=eP21pqctwf/mDW9Qeb202AfBCadqU2Fho5uvnMH/7ZtUI6OItypAang/9Yd0k2R8Pg wGVE7un5IUOEhvDBMH4PLkn7FSjzGZukumasObqqG6KV85QTS3BRw1HiHP9RQ9Jq5Qtu fcb9SsFjlDL7q3hhXGYLCXIeR9BucjGgMuggqUhW7HtOBYzvo3ykhoYQ+tXg86v+EKe7 6+A0oXncFBfMeMwwmWiaFiRbXleqrTqLHGZiZfgvnMX8kFF5CymFvI7T5XSCJP+WGDLC 1Rj43/gZKCwVmTSd8XCczcwqA1yKLSrQsCgj2gMbkQcY4fCjyAgXsZZRpLGaai8lKmSM RZtg== 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=dJoH1g3lf14FbbkcbC9UpnDZthqLHd7bJjcDeRBOdX8=; b=ybGEzaQKrGa+7agqL/XBpiHqvOntcvV5poiW3KuQI+92oEvZMkpG3EgRsezESpOn00 t3ArTZjN/O+hWjBiJoDMTXhhDjKl1tYNfaZzCd4gR02brHsLQUAA0nrrNWoyCf049fWp xxk90YjNupVP1SxNI3GUYUi76HRrt+zJOJJZNu0gcbKmljyh8kTorpb+0wU1ApZYRo5p HXz/2WLzcM380njxpia7XO7nQlasYX/0Tt4xM4Ki7XF6NoKyh2N1piTnJ7AcdldKJqUf JTi/GyrkFxL87UvixOo5luxTpNpRrdJ5g4uFy9fsR8+x8V8wSlOi6W8HatVBarGGIH6F wxcg== X-Gm-Message-State: AOAM53186eykYkQqd6N5FcwuOjzU+Ev+mFvd/h8KWK5Q6WyEw0NzYEOn JMwyMUAdE6VRAZrqk44K6D/1rXCr9XE= X-Google-Smtp-Source: ABdhPJyRPkd0z8Q7dpCfFs4L3hfm/gzqIEDvwokbLC4jgFC+X9JrUBzs+pO1DGz5l4Bn3s8z2IIh5Q== X-Received: by 2002:a5d:58f9:: with SMTP id f25mr21529252wrd.206.1638538479859; Fri, 03 Dec 2021 05:34:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q4sm2560532wrs.56.2021.12.03.05.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:39 -0800 (PST) Message-Id: <60659c4719678891dc98207e666d1da548c2259d.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:23 +0000 Subject: [PATCH v10 09/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 , Matt Rogers , 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 | 32 ++++- contrib/scalar/t/t9099-scalar.sh | 32 +++++ 3 files changed, 262 insertions(+), 3 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 65da885c5ac..60a9466421b 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 @@ -251,6 +252,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) @@ -347,6 +547,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..e8730967f16 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,37 @@ 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 +90,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..984d69e8f75 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,launchctl:true,schtasks:true" +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 Fri Dec 3 13:34:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFC87C433EF for ; Fri, 3 Dec 2021 13:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381171AbhLCNiR (ORCPT ); Fri, 3 Dec 2021 08:38:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381095AbhLCNiH (ORCPT ); Fri, 3 Dec 2021 08:38:07 -0500 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 30B3AC061761 for ; Fri, 3 Dec 2021 05:34:42 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id l16so5734191wrp.11 for ; Fri, 03 Dec 2021 05:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zMOqWXrQqZ2IHpZK6hFdtyVBHSAW6HN1jJsmuhexxWc=; b=Eq8S1TwMAJmIW52/lbqXYKHKD3jjAwbYfz7kn+xNCOBJQAYNkpOwjdYKfIMaDkxHLR rOLdiL9zqRMPhHiM1tEw0wkTjnKj+tCFzb/Q/QzZxeTus/sEEzPUFtI/U0FkWsVEpmjP mgGaOKg2Tjzo0vGUfoTOIYNUfmAS6KsvGWJzHQTg8Uvgy1ixpcWHxdrGDjQ0r59BinuQ DIIRgWQUV3s+oNCW0Zim7qdfL4q2xalKvQuQ+DlDdc2ZDaxJ1sbV2XPZA9fWZe3nWB9t cGcJ03n1xgn2C3F3gQDLi0MoVAlO2B6duEGFTu/BzzRN0mPs0yqHySKXEIwMBwiL3kPR AQgA== 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=zMOqWXrQqZ2IHpZK6hFdtyVBHSAW6HN1jJsmuhexxWc=; b=uG/GMde3o5oX1o9Jck1sEbVpelIpDuCqthkR0+hyKBXv0oDsGc7WzpD9+eEK2XzDlr VveeuaMbJ85JwkR3X8/t86robQbaUJDEbrUpnVdI4YmeNu8CGKHPWztWMuPIAKiHJCef 0zYK6RWM3g8OsHU4XREQ+3mJlkocgmJfAopcIM3Sa307B/IBJ/tRPMqsRRONtUTRFLZG N5OQQQojchZp0xlzriVElMDLvxRq66uu6ilOgwIsZRQU1BIGAdQdFT587ap8nm1iGdIR if5hlmxPMUJdLIQxYK7RwVkAdf/FbMFXrPg3toqJ2v4pqxmNK8rDu2D6uFpmlqub07hG yjpg== X-Gm-Message-State: AOAM5332ehxOK1PhzHnofh+qeU1qRjoXuny7SuNxZpZR/fMKHDCtXKRV Bedjh2ndGAk8OPQ/6mWOq3ECUh9G2pA= X-Google-Smtp-Source: ABdhPJyjyJcwDv9pWjhRmSxPbhW+6i4pXMNCsDoPKTmoIaTyn2CKUHZUPJ/J1lAQUndYrLX001My3A== X-Received: by 2002:a5d:658c:: with SMTP id q12mr21990578wru.34.1638538480598; Fri, 03 Dec 2021 05:34:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l8sm5853285wmc.40.2021.12.03.05.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:40 -0800 (PST) Message-Id: <45aca840764d1e4f99b5dc1e1a0c5e8b1532da03.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:24 +0000 Subject: [PATCH v10 10/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 , Matt Rogers , 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 60a9466421b..61b66e48aa8 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -327,12 +327,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[] = { @@ -403,7 +406,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 e8730967f16..56f744a4aa9 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 [] @@ -57,6 +57,16 @@ 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 984d69e8f75..f60e086d6f9 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 Fri Dec 3 13:34:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12655215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1816FC433F5 for ; Fri, 3 Dec 2021 13:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381130AbhLCNiU (ORCPT ); Fri, 3 Dec 2021 08:38:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381105AbhLCNiM (ORCPT ); Fri, 3 Dec 2021 08:38:12 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29D55C0613DD for ; Fri, 3 Dec 2021 05:34:43 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 133so2418558wme.0 for ; Fri, 03 Dec 2021 05:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=b0RrJffSAoUtbuQrA9X8iAnoDmAsgu/iVcj3rdu+reU=; b=qEeMbd2F0CJRaDIdvciLIotTBQXPQt8b9ExeGerJOdbo/5kAeR0x5MG44zCLpUirSf kyWno2aYvfI4PSgczDuQZN5MxWIRmBY2AWCBgWfkRf+muthRwRORg5c4v2zWwiq3GUH2 rH0dwWNRuUreOnoJcxSB0FulOh3td9KZ4ZDnghDOCnsGdjomK4DjvU7PqNkwTQJ85rsA rlEitWXNf+YXDt7Xk3zP9VlBMunjM2DZAFXduEi9FV03L0z7P/b8Sc6cb8tL+8EUUQX1 AUMzbY/m1tD1KT+UysVfqBenykhgKws77GUNZ0Jp1wRBO3crjoB/q5tqlBWeHnRYtelY ydkw== 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=b0RrJffSAoUtbuQrA9X8iAnoDmAsgu/iVcj3rdu+reU=; b=b/sKVJkidQ7ThEtpOEatflq9AXDSSjLq+m1GT5dvVZu+Lm1808GvIk5M9Rj4sTCLYZ BuZHFb6rJKkvD14TGMyXe0AxNWVWjidsU/M0gV/ZIlPunNll6ern5a4g6uWov+DxasYv k8MR7EAdmcqOx+KvzUA6mWTRjPES9bQgKeM3o8aUnWJJh3Z4U0cXCsNpGhmPbeBpNPtq HNSh3HwgtC3xi/VdK14/Ro6I+HkMyn/x2UzP0PwGwcXbMsRzFZptwNn78DP+lJtCjGyW 1A2o70Hrc3SM6KyXmfkXS0/1pOa+hQ8wE7m5d0d9Jt9e0eFQln0e5AR1LWbW5yemKTSl vG3g== X-Gm-Message-State: AOAM532HQ4lNpn0EcRVhjUx/vNJBAqA+JRgoZUGcJLQJR/GIJtr+taF0 gxn/jp1WvoXZ31jxquj59xppiKXTRY8= X-Google-Smtp-Source: ABdhPJx3Fn2Yx8/5f/yiLfysDyI3jRTW4Qrbunj3vsdCimBfqOw910RLjTlMHzWR6g+zegyYUaau2Q== X-Received: by 2002:a7b:ce16:: with SMTP id m22mr14980667wmc.137.1638538481589; Fri, 03 Dec 2021 05:34:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f7sm6438146wmg.6.2021.12.03.05.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:41 -0800 (PST) Message-Id: <15e649a173429732974c5c5d795565f360984095.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:25 +0000 Subject: [PATCH v10 11/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 , Matt Rogers , 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 61b66e48aa8..fa900e4373f 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -484,6 +484,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; @@ -556,6 +619,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 56f744a4aa9..39143b08324 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 ----------- @@ -98,6 +99,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 Fri Dec 3 13:34:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C75C433FE for ; Fri, 3 Dec 2021 13:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381125AbhLCNiV (ORCPT ); Fri, 3 Dec 2021 08:38:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381112AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 287DBC061758 for ; Fri, 3 Dec 2021 05:34:44 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id o29so2376695wms.2 for ; Fri, 03 Dec 2021 05:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Zl2vUbDhqmmWJ8RnUA4Mik2HNxETj5S1M012xd3a9wU=; b=PCZ8mMTjKY4jPSpwYaRUgkuwb8oUEjj366Qe/QIAwriM9djyPaDbBB6skDJqWjvF4H Mn1NPzYA50waiA/LGDlFXrpwrJV3/z6ETH26LN9pv9l1+DGQEMB8zIL0rjee3gCx7s5z IFr2z4hM+X4yJzTOk2aBJVq8TTNz9Z5oZ3kA22UDsd86mCw6HoYnJhqt02rg/DDfPabb lUHESebtqvqFVr2xneCNNKCPz6seRM+yMhDgqpKTKwASfVZ6wKNiwPhvPOTyOucANOwo LsMzRkUtWIUJrdC13oqkcWO3xM+2au3HCO8vGOPf9dm7JomdjRSXlzL9IrgxOB/vMGu8 pbiw== 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=Zl2vUbDhqmmWJ8RnUA4Mik2HNxETj5S1M012xd3a9wU=; b=nIt7F/ONNQfEfXn0k5gdORG8TQJibsLaueZFjkPno4+J669o6rTX8ZTG5FLoogy5Tx 9xBuF87wtNOmaNQGdXwrosFiB+oKMYFawiyULsMHD5bXQA7O9pe5dXC08Vzf9P5kjqmk dHr1tjVlqFZKockPXB2C5LvMkHy5FQBIfHKD7+IylcyDho/Q8NvLRSNsPodmJszCKIkg egk8RLIwfjmLOzU019tL1/KUsdkoQmXOPAFUvpzMURXGIrZp7nBRrwBXxCztNAprBfiT eDt+e9dt7HGgOQTzlwlYsKFbSqMuRydwe9FC08NKcj3/t4it4Zo7ZLQsaJU213IfBTbr pIjw== X-Gm-Message-State: AOAM530mK5ufpiIiC00e1xLdKkT5wM04xsLuFF54EXOehXOXEKo1ylSO fem0hg2nOOv+pgaxcYtswtpYkZRZrhM= X-Google-Smtp-Source: ABdhPJyd4ejDy3zWCWKQ9k595a9UZINNBqvoaKJrwYs1XDYvBEd2bc74cMv/Owf7BYABgQLwrOD8Jw== X-Received: by 2002:a1c:43c2:: with SMTP id q185mr14610552wma.30.1638538482394; Fri, 03 Dec 2021 05:34:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l11sm2545981wrp.61.2021.12.03.05.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:42 -0800 (PST) Message-Id: <2a3fb40bd9a4a3aa18a8265a50d4c52a06705a9f.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:26 +0000 Subject: [PATCH v10 12/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 , Matt Rogers , 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 fa900e4373f..d7306b43cae 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", "true" }, - { "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", "true", 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" }, @@ -166,7 +169,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) @@ -231,7 +235,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); @@ -419,7 +423,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))) { @@ -484,6 +488,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[] = { @@ -620,6 +642,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 39143b08324..89fd7901585 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 ----------- @@ -117,6 +118,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 f60e086d6f9..fb5e2efee0a 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 Fri Dec 3 13:34:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EB95C433F5 for ; Fri, 3 Dec 2021 13:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381133AbhLCNiW (ORCPT ); Fri, 3 Dec 2021 08:38:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381060AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BC45C0613F2 for ; Fri, 3 Dec 2021 05:34:45 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id m25-20020a7bcb99000000b0033aa12cdd33so4536306wmi.1 for ; Fri, 03 Dec 2021 05:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=EnAo9DzhsdMVbWYI2vdFvzuNwGGFw58Qp+EsKM7jcZU=; b=FU6u/ZTy7FVpuM403JiJKiQluzB2H3n4D7CB+qeiK1utbt62xDJdSxjFhyFIjcfPD5 eMIw74TO/hFKczltWKFDgGsAjMT2MeDMPLv/ONaQ7QMlvJ/qWYO0Hp6uUEZ5py/kODMg OioBpxBCDzWVR2XK3CzAsSt33MwsZdSOcumO04lKxRxb/q35mPV93JhAzNfYz+nZHt9t JXyj/4M4Cb5OdjPpRS64QqhgdNWmopKnZI8TCcK4S4c7VbOijtZRi0W+KtD0sD8dUhc/ ZOP6NwPufO9GX5S+xXTEADpE4mvVFBvOhGZuTu/WwqpBnl8MeCvBQr7NtAjCFpUFJUHa RnnA== 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=EnAo9DzhsdMVbWYI2vdFvzuNwGGFw58Qp+EsKM7jcZU=; b=BASkMfxyRSdkm3Q67T4WkHyMozQszoTp+nM/sOBrR93+TvzCOxLLbmrt8EPIvutx86 XOGdcyjRsnpZXZkht7LsDRBaU6biuNwrWHdMSSZiaecWD0vnRLI45OzKZ5jyu/1l2S1d UNQCLL6+43713UJr5clR4TMUCbBBlo8ZujwWeeKlKnD8/YXE1zx//iBlkYerOwrG/e00 uk+5TXD9Mahm5RdRH57iDBcrMs32E2I3HeJ+BeIP//uACB38fFZxnCkutMEVTI1OHNLC oer/A6hDQmq2Ow1lGLb07XDVX8AoI4GBJASVGXsBWLFzLKikPFzl3aI1ItSk/UBfk1MH BNmg== X-Gm-Message-State: AOAM532yONlsZAicpOHO6nxW+r9iewCTOtw0U1njAFQLgUV5DeIkuGYr XnXSaiq2AC7Ev00MQCZIClITazUpTLY= X-Google-Smtp-Source: ABdhPJyFSRqZImQir8sdDahqY+ZVR7GvaL8dgL2lY6SEAj0af0HOwERjMa4oHRwBJ11zL9IlDOvi3A== X-Received: by 2002:a7b:c2f7:: with SMTP id e23mr15120833wmk.92.1638538483301; Fri, 03 Dec 2021 05:34:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y7sm2620633wrw.55.2021.12.03.05.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:42 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:27 +0000 Subject: [PATCH v10 13/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 , Matt Rogers , 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 d7306b43cae..305b080663b 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -488,22 +488,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 89fd7901585..737cf563c1a 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 -------- @@ -125,6 +125,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 fb5e2efee0a..58af546fd84 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 Fri Dec 3 13:34:28 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: 12655221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57D35C433EF for ; Fri, 3 Dec 2021 13:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381136AbhLCNiX (ORCPT ); Fri, 3 Dec 2021 08:38:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381120AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 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 E8F35C0613F4 for ; Fri, 3 Dec 2021 05:34:45 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id a18so5790696wrn.6 for ; Fri, 03 Dec 2021 05:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dywTmLrB9oe3ZROlnvpiXOATJJ0fOgNh7eK+EgeoRDQ=; b=R5kXSD7qjKsK7jOOGBcOLBqHrWY/8PFg3+tTV/628aG5V9YLImGW+B12ItfoB6TReR UwsN44f8w2UC0RSXHO6J3AL7Oq/JpBy83ScuknooQTTQxUaXpB0h3ffAI7lOEoivWSKj iLE9z5LI4Xihg8oneFupwbuKqWg+akQtdy8XtxisnZTlp9d8CTpd8sDkW13UtepwBZsf R1HN+sc7RAoNtSYFJ/q5SD6rBXWC09ZBeoKgvEgcfjVnhm69g7O9Bgol9xvwXF/q1ih9 et7Ovr5yJ32YC/OR6CsqmdVDYB/paZxfnV9GE9KJSIr094zH4vx4dkM/LXVZVoHzNFxq ddpw== 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=dywTmLrB9oe3ZROlnvpiXOATJJ0fOgNh7eK+EgeoRDQ=; b=AX//USvDFvzyY8dr5pbPfJxy/Ndoq1edTu049UX0/vckCK22uhzTJv/g0EYmvUJ7gx GW6g1BIJl1Oj84kveMKYjWJnDt3GXSnVDJfsuH7lqRndCcU5bqKFt7Gfkl/O1IW+D1BD vq8FiWAPGQ7alVD7HE04ZtwKMrbA7jDX+Gis5le/5bwx3bM2Rozf0kKx/1RXcSh6Av7Z x4bQRVAsvSmARHObepuNs7RLHeeAnBKl9I8mhBlpafUbwnd1fVq/8JfAejyVr6aFvyUm 5YwFhLc+ocSW5KKKcdWfxHPQFqGWP3uO0c7QujREwJbqAQ9LuSVZWaIcx1vBwvWZYLMy cNhg== X-Gm-Message-State: AOAM531MESsPaCnkMonZPtJw1DURJSfLr893NOfpz8Nuq/nA3LgtjuOA Tg6q6pzPxPk0KrJ0LrPDCbpxQnqudm4= X-Google-Smtp-Source: ABdhPJz+l4jwC7J6xBql4Kf4x0tqsDSiMJ1oZky4S14WiSzsJeGJrHUfoRqr5vFXdYUjooefB5DGMw== X-Received: by 2002:a05:6000:2a2:: with SMTP id l2mr21607973wry.110.1638538484359; Fri, 03 Dec 2021 05:34:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y12sm2624700wrn.73.2021.12.03.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:43 -0800 (PST) Message-Id: <8b69462b906437c16f3f46300279674ad2455bba.1638538470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:28 +0000 Subject: [PATCH v10 14/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 , Matt Rogers , 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 305b080663b..d4303c7c4a2 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 @@ -328,6 +330,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; @@ -688,6 +717,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 **); @@ -698,6 +760,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 737cf563c1a..f416d637289 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 ----------- @@ -128,6 +129,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 58af546fd84..2e1502ad45e 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 Fri Dec 3 13:34:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12655223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21138C433EF for ; Fri, 3 Dec 2021 13:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381154AbhLCNiY (ORCPT ); Fri, 3 Dec 2021 08:38:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381076AbhLCNiN (ORCPT ); Fri, 3 Dec 2021 08:38:13 -0500 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 C5D81C0613FD for ; Fri, 3 Dec 2021 05:34:46 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id o13so5716191wrs.12 for ; Fri, 03 Dec 2021 05:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OV69YLrfn+4NmtmyV55tOgEZ82XpKu32hPU3F6o5+x4=; b=oVEZdvdf3UdETbk98H/hQKl+vN1GW7FNBj93Eu1ip8nn6ivnHqDPmmFoG5BsZj+DLm PJBnETpGGuD2YamjF0I8FuOmPjB68UjiF3fSqH4m1jHcFyU0hB1rUiQSqTzkvjIW1Qyd yLwX6zw7m8hgMrFF9wAG48ewxcv+/AXrGOLsUVx7ZcR8LeHgptCMU26s70U6bSeXLEoo 5UqUa/UCCLeWq8C0VcmpVBjgXMvwwMwouSJjKhtpXjHAJEpCQuaj2phAYnV43ly+D+wG aTvqVhsdj/0fJqFJ27zCxCKX6U/f0UaC3aP9mTZ0LFHTAy804pxr0RiPT9njhJBH9xTr qtyw== 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=OV69YLrfn+4NmtmyV55tOgEZ82XpKu32hPU3F6o5+x4=; b=zIleBi8Ko5xm8EwpNeYOXXA1LU1UopIjglR1sAuCzl6ZygZ2aIo2vNpFXow3ReCAbn KMBpm+OCeaE5BcokJmUa97eF94Z1GP51Z3SgJrH3gSi0IvO9jO08emv1mxIbd9U1xKv7 7vmtqni1DxdbgvTiiLFz3gFgQ4WlpeDYpvZWbmaNQ91+gFEGgyg+Yy6Uvuk7SrIWlhSw hHcCjFdR21dMQAXgZ6vWhfbgfCOU1Yuk4lb+d9BBfNtWFKh4EcC6P/3JP5WVBtfgwbYf woYEDPv+SRNnbAsPa8cOZVPYM1/ri7NwmktK6ctzBAsdvEfGSQ+VmR+KQx9QCqPvQmas rGkA== X-Gm-Message-State: AOAM531QVCTtqVyFNA5Lnq/UvA+GfboN5VTwbtb0TYxaiMvUb3pdaejV dG+61MK3riAOgLMTGJ6qPH1yq+AqqPw= X-Google-Smtp-Source: ABdhPJytagIthqwTo0Dr8N5mbEQM19GqxX4qeq412W83GGdTlcFO1mo7xCKSIvo3sKF5mZ9IcbhMYw== X-Received: by 2002:a05:6000:1289:: with SMTP id f9mr20969143wrx.329.1638538485244; Fri, 03 Dec 2021 05:34:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b10sm2727591wrt.36.2021.12.03.05.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:34:44 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 03 Dec 2021 13:34:29 +0000 Subject: [PATCH v10 15/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 , Matt Rogers , 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 d4303c7c4a2..1ce9c2b00e8 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 @@ -357,6 +358,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; @@ -750,6 +760,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 **); @@ -761,6 +799,7 @@ static struct { { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, { "delete", cmd_delete }, + { "version", cmd_version }, { NULL, NULL}, };