From patchwork Wed Nov 17 14:19:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 069D4C4332F for ; Wed, 17 Nov 2021 14:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFC7361A79 for ; Wed, 17 Nov 2021 14:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238351AbhKQOW1 (ORCPT ); Wed, 17 Nov 2021 09:22:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234203AbhKQOWY (ORCPT ); Wed, 17 Nov 2021 09:22:24 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E50EC061764 for ; Wed, 17 Nov 2021 06:19:26 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id t30so4993920wra.10 for ; Wed, 17 Nov 2021 06:19:26 -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=wIr3am6SCsIbgGZvNtNpnMILEzX+zX3D0DVgxD6BgPw=; b=BJQS2kzyqs8UXv66u1WcoSBRVSe7EUfkr9uq8s43uVX7ZSL7Ss33cD7JaBdrP177YM D8WUzN2bUDpTLMfK9H0xIdyq33UcExWcCCjyvrG694CTkVr06ZQj7rdP2oxzsvKVU4pB Evs2lRNKv142gVALS3ZkGAoGxfb2Hs4tDXt0BFWHrCTFU2B8Py9lynZjngLp3P1OJC2z ZyuBcmC1NHgHmAQDPS3qfax4pq5OHt4PdNsxiFZzPzvVsUuMSTfJ8LzDoUA9xYJl0LSq uEZ6JWEVn+rRXQM1UkkHIRHrk35ybmb4hmSxx/q2SYa1W1M+qQEOxTBP8O0YUTSjMdtw xbPQ== 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=wIr3am6SCsIbgGZvNtNpnMILEzX+zX3D0DVgxD6BgPw=; b=bJluZNbJ4JSFCHxzpBqL/1r8EvT4wejaq32tCu4qSTXGHkleHkO9mb1xeSX6aaKV6B 5rYlISLlIvhSApvoWH/f7kxGnzQx4QlD11B95q7EmmPZCJELSeDzdIB2Zxy9aAK0C1ps bXImkai5EOLdm/wacGaa1sLu9tVNjTkt6a+wkGebZghsriDYj1NQlwzTY8xDrP+OkqSl 0kaQB9cJhUVsHEYBy8mSCyGqCLO1jzywRcFt/ZK7WyjtCOPt2ulOCB+ONi0rAKizYiSO tfW0hPNGyeSBb9gUz+14wBGDN3kT1HX6hH5lPwRl0qFlQFZwpFfczJ3grBStL/yX6DWm 3Gqg== X-Gm-Message-State: AOAM533gLbMT514ex+4xO8UG16yXfy0MATOCT4LtOfTcW/lRqb8lVDCx SCsRrI7XeV/kSYLw8xeSPFWQqZYEUuw= X-Google-Smtp-Source: ABdhPJzQljNH8oK4avo5+CEtkoOYM7lwrf/6EE5KqBM7m+o7dBtblerYxF07kKxoHFiV4wtcYOB8WA== X-Received: by 2002:adf:e484:: with SMTP id i4mr20393477wrm.49.1637158764465; Wed, 17 Nov 2021 06:19:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j19sm28413wra.5.2021.11.17.06.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:24 -0800 (PST) Message-Id: <3aa095dc824ea7f659e6c11aa2c21be6cadbe985.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:06 +0000 Subject: [PATCH v7 01/17] 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 , 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 | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 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..7898a683ba5 --- /dev/null +++ b/contrib/scalar/README.md @@ -0,0 +1,71 @@ +# Scalar - an opinionated repository management tool + +Scalar is an add-on to Git, helping Git scale to very large repositories and +worktrees. 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 + init` 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, but there is no plan to integrate them +into Git's source tree: + +- `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 Wed Nov 17 14:19:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3FE5C433EF for ; Wed, 17 Nov 2021 14:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4D1161BD3 for ; Wed, 17 Nov 2021 14:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238373AbhKQOWi (ORCPT ); Wed, 17 Nov 2021 09:22:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238360AbhKQOWb (ORCPT ); Wed, 17 Nov 2021 09:22:31 -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 25E14C061570 for ; Wed, 17 Nov 2021 06:19:33 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id u1so4984537wru.13 for ; Wed, 17 Nov 2021 06:19: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=9Ejg+jt4xVscGt18Qdg892vaZletSiZ1QxqdhJa+MTg=; b=JJd+QqkJ24YmItHdVDO8PUAqd2Ow1W7uXgxWfp++MXa+OyGYjkgeuKDzBFA33oSX3R C/r2jmOY6KATSYMiROxUKPVC1R5XfOi0WN5T0JyKQjTUeZc4c9Rcr391eYsn0frbP6RR qGUdewJicveyt/u0U0ZqVeO/1NfJ7Io2DNguSElwnBE/UJ2/IQUL0239IkoVWnq2Vk0o 8uu+Ey6mhYkh0+fTspHHSeOSqZ9sLSMjiqQs4HCcmdIT2Ie4cTg7+tAv8r3zylljCPzA bs2FJAG2oSFRlm/4oZZwt2va09TSyha/dpMeYHx4s982V5QmE6cWU9vI1OkpWCheq9nG DWjQ== 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=UDPUHKQUqrHa9UJNBl+t03EmWwDhK6FZiQ72xge7a5t0ZBc38h+TLyXPMnvjR+tGjA 7H84edkS15zMekz45SzekKqWLi6IbP2E9maPOy08IxKDmEbXDFEhyqrrCcuvC3g0dEjP cg6RnGS3ibA1wWJfmTowI3xS6e+Nlq6PCm23UqgaCLkEn36VLQUkMJzqt50oUC9r4cdF GexscaSRZmaERI+x7BTubLvaZ/DiLrgerclykbpw8YrXQld+JX8T1GqtzaIDr/Mrr54M TzbyALBUa5f0flbPM3OQbuNxjd7DRJY8CdYSiu+kFJDwzdiYSJ+b1q902yKrmHLIB7Km HMWQ== X-Gm-Message-State: AOAM5317lVJLVEOREMnrlWsC6gDZqIE3bF7r3xZ5rOcZhii/cnrSwr4Y IzemgmLNcMC9ZbOM1F8jhIDMNMlF2r8= X-Google-Smtp-Source: ABdhPJxNNN/79dCAc9fEfUJyYmJl0KLtjfcS81mUild960zoRDzC+Yh3xt/S5U9Y4mwsXkCN63mi5g== X-Received: by 2002:adf:a1d4:: with SMTP id v20mr21135059wrv.190.1637158771491; Wed, 17 Nov 2021 06:19:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e7sm20418wrg.31.2021.11.17.06.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:24 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:07 +0000 Subject: [PATCH v7 02/17] scalar: create a rudimentary executable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The idea of Scalar (https://github.com/microsoft/scalar), and before that, of VFS for Git, has always been to prove that Git _can_ scale, and to upstream whatever strategies have been demonstrated to help. With this patch, we start the journey from that C# project to move what is left to Git's own `contrib/` directory, reimplementing it in pure C, with the intention to facilitate integrating the functionality into core Git all while maintaining backwards-compatibility for existing Scalar users (which will be much easier when both live in the same worktree). It has always been the plan to contribute all of the proven strategies back to core Git. For example, while the virtual filesystem provided by VFS for Git helped the team developing the Windows operating system to move onto Git, while trying to upstream it we realized that it cannot be done: getting the virtual filesystem to work (which we only managed to implement fully on Windows, but not on, say, macOS or Linux), and the required server-side support for the GVFS protocol, made this not quite feasible. The Scalar project learned from that and tackled the problem with different tactics: instead of pretending to Git that the working directory is fully populated, it _specifically_ teaches Git about partial clone (which is based on VFS for Git's cache server), about sparse checkout (which VFS for Git tried to do transparently, in the file system layer), and regularly runs maintenance tasks to keep the repository in a healthy state. With partial clone, sparse checkout and `git maintenance` having been upstreamed, there is little left that `scalar.exe` does which `git.exe` cannot do. One such thing is that `scalar clone ` will automatically set up a partial, sparse clone, and configure known-helpful settings from the start. So let's bring this convenience into Git's tree. The idea here is that you can (optionally) build Scalar via make -C contrib/scalar/ 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 Wed Nov 17 14:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17CA4C433EF for ; Wed, 17 Nov 2021 14:20:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F034161A79 for ; Wed, 17 Nov 2021 14:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238415AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238365AbhKQOWg (ORCPT ); Wed, 17 Nov 2021 09:22:36 -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 DB41FC061202 for ; Wed, 17 Nov 2021 06:19:33 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id n33-20020a05600c502100b0032fb900951eso4931873wmr.4 for ; Wed, 17 Nov 2021 06:19: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=8D4/O9BIeJDyx7UkKc8qSSrWGbYPXQcqw1HfHqLPa9c=; b=qRfzNiY5A+H60JN8L5xV8K3xES9+sg925F6K525z7v42jfVTuZSb3jpNnTJvBqDFK6 nYVDCmkTyY87XH8yBeWXKRgAArSDr3lIJ7zRzcVXDfBJqwlf+aF52Uwvk1axdeLnvpF3 pA+r17BvL1SL0UWkAAsv2UDEAkTPGI5rLC8bcAZdVJmB3ecElaWR8Jr6Prv4PWP4Xkwf ONsylAjgXaX2JULj5au5PIh/NsoU90eEAn1xfzpCLWl2aOD0KHKsvo11PNCZKZrYdDqk BU23vZhsW04fI4ydO/0BLhEt/VN0stky6lNTSZPk9IBDjnYb3fCcRfZ803MGBl2yLgD5 H9rg== 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=lw+kx2iSS2cbqdpbYNhgTcAv2tO5jyqoS1Q9N7+q3mYE9G/U/bTgm8Jz13hVTpTIU9 kBUAcPvcsP4dddV5sKwGVdUmJ5YfbhiUnQTcBTLzA1VVt3uHe3BOvxDiRIg498WxbVWZ fcsLstSNY5GxhWdF9XMXMrPeUHS7EtHgG5ukYwCP7vvOOkl+Jd4vHzh+JItDsg/rQzw5 L6GfF2DcXJiHoWGkoRXPX8LSO4a3806+CBO1oSaYLUyb9wnQFVfmY3EnyNTjn1HBeku1 YcLyCxqZDnPYtmAFSv7i1yuYk07shxUFTeMn+tc5fxOu+efYlyAMHvZ83tCCKHiJO+Ya MBfQ== X-Gm-Message-State: AOAM531rLKQyaaYJaC85SsuvUtv4XbfO5AzwTq/OhzCK/MGhfL6HzhT1 mSUCDj4bTqn+afV9ZgPNjeSbxlebDcI= X-Google-Smtp-Source: ABdhPJy9HhBI2I8rAlDGleZOpSVfaaIPxlrSn/KfcRdvGwzTfM9aljjwlCsZ8Cbi7NHGLar4g7XRCw== X-Received: by 2002:a1c:1b08:: with SMTP id b8mr67687wmb.28.1637158772248; Wed, 17 Nov 2021 06:19:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c6sm7429314wmq.46.2021.11.17.06.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:31 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:08 +0000 Subject: [PATCH v7 03/17] scalar: start documenting the command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin 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 Wed Nov 17 14:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F0E4C433F5 for ; Wed, 17 Nov 2021 14:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1429463212 for ; Wed, 17 Nov 2021 14:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238387AbhKQOXA (ORCPT ); Wed, 17 Nov 2021 09:23:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238382AbhKQOWm (ORCPT ); Wed, 17 Nov 2021 09:22:42 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 891E3C061207 for ; Wed, 17 Nov 2021 06:19:34 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id k37-20020a05600c1ca500b00330cb84834fso4935593wms.2 for ; Wed, 17 Nov 2021 06:19:34 -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=Akciwy8yIK6b0oNUc0Zol46Zl8/n5LsQh75GeSTHyzB1qYLFmgewIytB0T2VKvUIbr kSLtgRh1gyKwcxd3kWASVglPuotsr+bv6urMkPkxlFLA5Hv8/HN1Bv+29+mRyBwHHu0i lTM0MLBxOfUEHUYJ24KDIufxjiBR5TWAIWiEjq7m2iHP5Oj4XF0lOytvFzVwi2YOEhx4 0POro/j7443felxahLGV/oIyX6UbVb9zDjbHEV18cA/cXetGwc7IwhHdlqVfQ1SPf1r4 nZIO9X+NskvigKnCmru32zLmRnh0vFmFB9yu0rCpnvjorRAgEdpNiNrCAnP3Po2qawIi Re2g== 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=5M/bReuFWYzS2xWyQRvJvLhgBI/Zo8RmV4E60IGtqxYKIi0EnSTU0/XPY2pHmoOmK6 ubQgz3TCYuKeGnXVvmtM9b3VgHOyUL9wiBBPmjokFfnzfgWBBkqU/Zw6IbUvvjrlekwu A0h/9xdmWF4i+zEv7rpT2rZB5Xy5+VzpjrvXAGQtQHGaAcb0ohjCwlEO2PTrpZepF0Tx RLAG1wgYqXDptkaBDIW1fpJsdQXLqvT+dgsHR51JNzkbyqYtjlXT0k17iBklzHPMNXp6 y0OsEQxjWeSHWaktTQr2qzP5e7TCJnz7uOJjr+SFivQ6/uE/854o4eJs5ynjn4i1nB+E b4yA== X-Gm-Message-State: AOAM533tVMmbAIjjxo8AqIU/NEznquwmi26l6SvKGBhITBdl+Kfjz5NO 881GtyOZCEWrbcwyHjPvu8ypXGONnLw= X-Google-Smtp-Source: ABdhPJyv50S7Qc9PV7AclhB5wRcVOqtUoW5msl15BpXnpN4MPoL7e4CtfCtOUGsVcj4P+PKlZbZUeA== X-Received: by 2002:a7b:c341:: with SMTP id l1mr54297wmj.60.1637158772952; Wed, 17 Nov 2021 06:19:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t189sm5597988wma.8.2021.11.17.06.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:32 -0800 (PST) Message-Id: <9da1616849e6aa33e68ae68876217eef07e503bc.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:09 +0000 Subject: [PATCH v7 04/17] scalar: create test infrastructure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To test the Scalar command, create a test script in contrib/scalar/t that is executed as `make -C contrib/scalar test`. Since Scalar has no meaningful capabilities yet, the only test is rather simple. We will add more tests in subsequent commits that introduce corresponding, new functionality. Note: This test script is intended to test `scalar` only lightly, even after all of the functionality is implemented. A more comprehensive functional (or: integration) test suite can be found at https://github.com/microsoft/scalar; It is used in the workflow https://github.com/microsoft/git/blob/HEAD/.github/workflows/scalar-functional-tests.yml in Microsoft's Git fork. This test suite performs end-to-end tests with a real remote repository, and is run as part of the regular CI 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 Wed Nov 17 14:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF24FC433EF for ; Wed, 17 Nov 2021 14:20:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8AEC61A79 for ; Wed, 17 Nov 2021 14:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238444AbhKQOXC (ORCPT ); Wed, 17 Nov 2021 09:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238375AbhKQOWn (ORCPT ); Wed, 17 Nov 2021 09:22:43 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34353C06120C for ; Wed, 17 Nov 2021 06:19:35 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id i5so5055822wrb.2 for ; Wed, 17 Nov 2021 06:19: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=uhb/QROHr1fftnLBMPf7ahiE/BQ2/n7oC7jxd7xCuug=; b=NoJGGxqFqYm8OnyRY7bmBADyfvMgOIdggSTS+DFryWWhnOiHo52Rz6gvkKnCtJuEGw EsB3478GuStu7OS0k2qYsy0nNjU6TBNME6U4ZmP0j55ctfg7M/9cMn0MdWrjNL3v0ugd rd48OjeKzjawssSTirWVN6fAyJdJs6tlZbI8tXSJvzRu5IDsyJ90zrxLtfqUA5eZpUU5 Zo+sP0XyqZOLQw3IBRpUwQcuR6nnWFG2omjPtEYv26RDaQ4CB99MVsKz2cGM3E2U1Rx5 cXxhD0lDp0fNG1XaoO418ezUt+nGOrFoJK8fS+0jG863dSu6opMsUsrvFmeolqq5V9AD wJkw== 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=uhb/QROHr1fftnLBMPf7ahiE/BQ2/n7oC7jxd7xCuug=; b=qntx/VD/L2MiK6cl9EdBUmnX+YdfRz8libDC83NFMshEs0hrS/dYZKsz1D9RhPBMXp F+tJM2JQJMj9LZU5mwN3arGzCXhIpv6/ZrVG3C+X508gn/YMhm8KZJDKkSe9pvemARjz UdAzhKWTE0C9VVLeuA62jiyzhcgMsaIU0ocs8k0LJi4KrbnQT2UI01hfCRiq2xT19p70 l+UbRyq1q0SDJ9Xa+/+PGSuVzl1KNIN0r7IyNGr3nfLhvXam9/FnddnWPIiJ4eqe7uf+ VdFov9N5xgiSVZJsRmil5s9UyVpwquujdmbAEQd+CgYa8ZCshcB22V7ZRBQUgtAsHk3F eiLA== X-Gm-Message-State: AOAM532dpRd52FrWvpGciIky9MVjhZraM5OO0iKrSkk48mooPZPV98MH gjOERjIlDD/5DrNtpU2pZtNYiV32BKM= X-Google-Smtp-Source: ABdhPJyUN/DeQ6tN3A0d3rkuiknLysmq09KqG7/sO3+1qzsmbvXOhXDbm6aJC8pp3GdLtmtGoLcgFA== X-Received: by 2002:a5d:4a44:: with SMTP id v4mr20608604wrs.246.1637158773590; Wed, 17 Nov 2021 06:19:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g13sm9950wrd.57.2021.11.17.06.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:33 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:10 +0000 Subject: [PATCH v7 05/17] cmake: optionally build `scalar`, too Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The CMake configuration unfortunately does not let us encapsulate all (or at least the vast majority) of Scalar's build definition in the `contrib/scalar/` subdirectory. To alleviate that somewhat, we guard the inclusion of Scalar via the `INCLUDE_SCALAR` environment variable. Signed-off-by: Johannes Schindelin --- contrib/buildsystems/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index fd1399c440f..dd7496b0322 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -729,6 +729,13 @@ if(CURL_FOUND) endif() endif() +if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "") + add_executable(scalar ${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c) + target_link_libraries(scalar common-main) + set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/contrib/scalar) + set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/contrib/scalar) +endif() + parse_makefile_for_executables(git_builtin_extra "BUILT_INS") option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins") @@ -953,6 +960,13 @@ string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}") file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content}) +if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "") + file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) + string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") + string(REPLACE "@@PROG@@" "contrib/scalar/scalar${EXE_EXTENSION}" content "${content}") + file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/scalar ${content}) +endif() + #options for configuring test options option(PERL_TESTS "Perform tests that use perl" ON) option(PYTHON_TESTS "Perform tests that use python" ON) From patchwork Wed Nov 17 14:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 065B1C433F5 for ; Wed, 17 Nov 2021 14:20:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCAE963212 for ; Wed, 17 Nov 2021 14:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238670AbhKQOXn (ORCPT ); Wed, 17 Nov 2021 09:23:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238362AbhKQOW6 (ORCPT ); Wed, 17 Nov 2021 09:22:58 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3B1FC06120F for ; Wed, 17 Nov 2021 06:19:35 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id u1so4984896wru.13 for ; Wed, 17 Nov 2021 06:19: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=YGW/Iv+hj4Jo4PNf8rajEZsMbDt9HNnlI+ygkUeyL4U=; b=hr1csCwjQngNhgvXeHZpBPuZ8JXrB67HJ4Fkahqg+ZOTeAKRPH0CYhE55LVYx5FlqD gM+kzoM3mIcrOfe5ZFQAwcZvo8goFsreWyBeLhX0j8ypXndwffOFlxgHzK27u/+TBuTa M8XL6VctRbvrnPNITOArgEK3qaE3NbZe8WvB9dhBBtSD95OJj1+8DvDvzpRWrRVtXOp7 AjL/1I5q/xoFAD9x32A4LHLqjdMEAG98Sad0OodfboiJLe7g1O115sS3yfXgPXzkgoZA R3P7lWjUZUKaQ7I85r+iEX8ACqV2p4rUjLcWg17qk/WvwbZziFAK1CAp/NQR440m+mVg mnWg== 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=YGW/Iv+hj4Jo4PNf8rajEZsMbDt9HNnlI+ygkUeyL4U=; b=bkqTuxMVrTwfwB0MSOFvZ2H9amgGDmZQzvVwpWo+XZd/mLuQPfcvUmS28hJh2SXzYX loiCf1n2qWwYVxTD6bVUG3FWyjE+KcQHkT9cMFCUXojtSNf2/0z+N0ET7oS7Y3XR9vSE hz2tXwnaKr40tywLDyJv4Zx2pX+f6UkePUJl8G0FnaS2wPaL40FFhru8u31AcRYSGo/y MnVP8b0qhLUkHXfW3PBwE+n6gnO5qlAn3oIobszzoAxYQnN5cPeoYMq7gCAUB/Lqq879 s/GKg+hNqZKhhYGBX0SJbEXRc34DtdbqycNXZ9WrbLeHNeI4t7rRkKFjAl2zVQN9M+s7 M1hw== X-Gm-Message-State: AOAM533kcKLiFQVQ3KlVFROwOlDG/t91hFjoJLb46NTZGS79BqZKysc7 J7qClwcRtJTUrlN3OcudpnNTmKhJnro= X-Google-Smtp-Source: ABdhPJwSx+hShqtsTku4xtPhbZgjn7pZpZ7vrca10L/nNK3ZPYwrLFcWYuiJ9dqqsvOKWDhkKc+Qdw== X-Received: by 2002:a05:6000:4b:: with SMTP id k11mr19859513wrx.86.1637158774467; Wed, 17 Nov 2021 06:19:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o63sm5941046wme.2.2021.11.17.06.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:34 -0800 (PST) Message-Id: <1b0328fa236a35c2427b82f53c32944e513580d3.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:11 +0000 Subject: [PATCH v7 06/17] ci: also run the `scalar` tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Since Scalar depends on `libgit.a`, it makes sense to ensure in the CI and the PR builds that it does not get broken in case of industrious refactorings of the core Git code. Signed-off-by: Johannes Schindelin --- .github/workflows/main.yml | 15 +++++++++++++++ ci/run-build-and-tests.sh | 1 + ci/run-test-slice.sh | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ed6a9e8076..6eda6be895d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -89,6 +89,13 @@ jobs: HOME: ${{runner.workspace}} NO_PERL: 1 run: . /etc/profile && ci/make-test-artifacts.sh artifacts + - name: build Scalar + shell: bash + run: | + make -C contrib/scalar && + mkdir -p artifacts/bin-wrappers artifacts/contrib/scalar && + cp contrib/scalar/scalar.exe artifacts/contrib/scalar/ && + cp bin-wrappers/scalar artifacts/bin-wrappers/ - name: zip up tracked files run: git archive -o artifacts/tracked.tar.gz HEAD - name: upload tracked files and build artifacts @@ -157,6 +164,8 @@ jobs: run: compat\vcbuild\vcpkg_copy_dlls.bat release - name: generate Visual Studio solution shell: bash + env: + INCLUDE_SCALAR: YesPlease run: | cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/x64-windows \ -DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON @@ -170,6 +179,12 @@ jobs: run: | mkdir -p artifacts && eval "$(make -n artifacts-tar INCLUDE_DLLS_IN_ARTIFACTS=YesPlease ARTIFACTS_DIRECTORY=artifacts NO_GETTEXT=YesPlease 2>&1 | grep ^tar)" + - name: copy Scalar + shell: bash + run: | + mkdir -p artifacts/bin-wrappers artifacts/contrib/scalar && + cp contrib/scalar/scalar.exe artifacts/contrib/scalar/ && + cp bin-wrappers/scalar artifacts/bin-wrappers/ - name: zip up tracked files run: git archive -o artifacts/tracked.tar.gz HEAD - name: upload tracked files and build artifacts diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index cc62616d806..07cedd25ff1 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -49,6 +49,7 @@ linux-gcc-4.8|pedantic) make test ;; esac +make -C contrib/scalar test check_unignored_build_artifacts diff --git a/ci/run-test-slice.sh b/ci/run-test-slice.sh index f8c2c3106a2..b741fd8f361 100755 --- a/ci/run-test-slice.sh +++ b/ci/run-test-slice.sh @@ -14,4 +14,9 @@ make --quiet -C t T="$(cd t && ./helper/test-tool path-utils slice-tests "$1" "$2" t[0-9]*.sh | tr '\n' ' ')" +if test 0 = "$1" +then + make -C contrib/scalar test +fi + check_unignored_build_artifacts From patchwork Wed Nov 17 14:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12624671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E497CC433F5 for ; Wed, 17 Nov 2021 14:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9D8563214 for ; Wed, 17 Nov 2021 14:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238618AbhKQOX3 (ORCPT ); Wed, 17 Nov 2021 09:23:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238409AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C514AC061220 for ; Wed, 17 Nov 2021 06:19:36 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id y196so2373533wmc.3 for ; Wed, 17 Nov 2021 06:19: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=JfgQPeGK48E/0q8Fkiq5e3N8uuCWy/bAHbpQUBIoNJs=; b=m/He2wt0FrcfxCkdAA8OHPzXk5svjcOhi/Jl4+5//zEdzvlCzJZU0B8IIOWzVXbaKc SNubjDTsTCkYFnep4IlpWxSm9X/GeueebZg7YAf6GF+BjgG7urK0MBastLZE/p9SOce7 /gns3lxcBtFK2Nj/Cp/2cuGOibyDPdLU4TV0c3e9PDUvCPRCHkygvJJZX2yE33vgxO5Z HAacbTn21i9OfmossM+GIHv7dM8I53IbAywyrwGZmFAk96ZqK/uvoMtdeb4FvkbUcSLA Mi/Wcw+IgR6O1p/kbLohzVpEijtiE5nly/yYdhKR5/x1sT8EAhctrcPHqszgNUtUTj99 vd4Q== 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=JfgQPeGK48E/0q8Fkiq5e3N8uuCWy/bAHbpQUBIoNJs=; b=kc02e/yzaJPBXpcN2ilA1d+rG/Q8j9+uCUttfp0ROav7xNuFZU5Ccu92Lqs52SMDNQ 3AGrCsdgPu+c4KUiyqLcqkuX1JTSatLocsG1hwaaRwO1+xKr8F1RjxahLay8dD7ouXKk XJqixRHuiHPLHckmSMpI/4qy0KfUEd45zXoebzuD80DsFebqUi5oqtU3euGcMuK/o+ji w4XX6u1u4um7Pti1xO0UvYGxaeeaf16vIHbj7BTUqpiaxxQXCW4ch+mx4L71BhoAXYKl yZyqHz4uA9xu0yhOn09gtL2+7PxKUfIWpQBGqk/4fLwwQ+Q/F4f2zGfKp1BcitGF0X9U tXTg== X-Gm-Message-State: AOAM530f2TcrN5wvsiKWq5YXDVhqi3D2VvME+Jq7wuKUaaz1ecxm/Cjy sj7o+cLpstkH7/qVeDnBZSSNax+cp28= X-Google-Smtp-Source: ABdhPJwk2qzaUMTHy22Wu0SEkuOfp0EjHyWYQe60waOYNgmdT3n605rBVc+emV+aa8nFSTEAqe+O1Q== X-Received: by 2002:a1c:1fd6:: with SMTP id f205mr40978wmf.98.1637158775116; Wed, 17 Nov 2021 06:19:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t189sm5598062wma.8.2021.11.17.06.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:34 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:12 +0000 Subject: [PATCH v7 07/17] scalar: 'register' sets recommended config and starts maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Let's start implementing the `register` command. With this commit, recommended settings are configured upon `scalar register`, and Git's background maintenance is started. The recommended config settings may very well change in the future. For example, once the built-in FSMonitor is available, we will want to enable it upon `scalar register`. For that reason, we explicitly support running `scalar register` in an already-registered enlistment. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 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..03d5f84c764 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", "false" }, + { "pack.useBitmaps", "false" }, + { "pack.useSparse", "true" }, + { "receive.autoGC", "false" }, + { "reset.quiet", "true" }, + { "feature.manyFiles", "false" }, + { "feature.experimental", "false" }, + { "fetch.unpackLimit", "1" }, + { "fetch.writeCommitGraph", "false" }, +#ifdef WIN32 + { "http.sslBackend", "schannel" }, +#endif + { "status.aheadBehind", "false" }, + { "commitGraph.generationVersion", "1" }, + { "core.autoCRLF", "false" }, + { "core.safeCRLF", "false" }, + { "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 Wed Nov 17 14:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12624663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA891C4321E for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAA4961C32 for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238515AbhKQOXO (ORCPT ); Wed, 17 Nov 2021 09:23:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238414AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D971C061227 for ; Wed, 17 Nov 2021 06:19:37 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso4940951wms.3 for ; Wed, 17 Nov 2021 06:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qaR47xznf9Xy5jW3JgfZrlmIasnjgC8KJcW13Zq+3oA=; b=Vo1O2dOqL1pxDQZ3rXUOMR91BmsdhWS7GF/25aiKhetlOZuiqMdXouUaimZBNKsUGM 6InmltzSvoyD4B4tBUx5dTFZml+/XXNFUcXy0rqs/xS8sTIPU2aprDWiqTJ5s6FI5CMY WFpUw5Cd3Ew/StiVUSGB2d6N4l+LuDsEDVpIfQ+qu+16HiHiZtTiSPtAXV6bro6CIHAx FHS7cleY38gylYIttQP3VZzKGf5N1iuECwjAnZgP4kGotn3glKRSK4phjicRK3eSvnwj W55cwwATXeptcZ+2zjjfmuOWNdDhH/VpSBPjYEYbFe1cS8UZKISPwLClb+3agopMV4cZ tunQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qaR47xznf9Xy5jW3JgfZrlmIasnjgC8KJcW13Zq+3oA=; b=b5HKkM3QuuyHgo8sMxJ6EXZ2X1pLKNhnnnAHNXGHIiDbLxFKgIM53rv/uYVfpHeg+/ F0jt4feVhtuhQjXtlhQVxMA3RPgpH/T2Td16WysUTJLtXTKL1bbGMFA04cjR3/OxnqZe DRZ8ntqA59bD7hsZZjV14wdAkJLHaT+3UA2P6ppHKRPSINcjz4Bw3j0sw1k3OsQp0tGb SFO8dNLg7WGbCMfoAu89h7Ma1XO68tU9lq+UynTwf3yp791aC6yKkMdVrbSKqIuJ+bej HXAVxc6S/GGMReD5UIlnWsZYiK2VWE2TFJ1/SIuQzvI+3SLFAVPArCzO025rzVbnPVMe dpLg== X-Gm-Message-State: AOAM532Wg0fb8kICGV6xQipHozAFjbit1gnXdxLOemHk3yBov9Op0aRH WbFIVd6cK57Aa8zenlb6GWel44BYd4c= X-Google-Smtp-Source: ABdhPJz1F3kwyFYUKMz7Vl8ahb8gclauQet2OASFAyrQRwVstBd+XP8uijkzODvp+sgnMKin+7QYzQ== X-Received: by 2002:a05:600c:5101:: with SMTP id o1mr79902170wms.81.1637158775815; Wed, 17 Nov 2021 06:19:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i15sm6728642wmq.18.2021.11.17.06.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:35 -0800 (PST) Message-Id: <9fea89cd161bfa6facdc142402b2098d2de463ef.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:13 +0000 Subject: [PATCH v7 08/17] scalar: 'unregister' stops background maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Just like `scalar register` starts the scheduled background maintenance, `scalar unregister` stops it. Note that we use `git maintenance start` in `scalar register`, but we do not use `git maintenance stop` in `scalar unregister`: this would stop maintenance for _all_ repositories, not just for the one we want to unregister. The `unregister` command also removes the corresponding entry from the `[scalar]` section in the global Git config. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 50 ++++++++++++++++++++++++++++++++------- contrib/scalar/scalar.txt | 8 +++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 03d5f84c764..bab0271c37d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -198,12 +198,12 @@ static int set_recommended_config(void) return 0; } -static int start_maintenance(void) +static int toggle_maintenance(int enable) { - return run_git("maintenance", "start", NULL); + return run_git("maintenance", enable ? "start" : "unregister", NULL); } -static int add_enlistment(void) +static int add_or_remove_enlistment(int add) { int res; @@ -214,24 +214,39 @@ static int add_enlistment(void) "scalar.repo", the_repository->worktree, NULL); /* - * If the setting is already there, then do nothing. + * If we want to add and the setting is already there, then do nothing. + * If we want to remove and the setting is not there, then do nothing. */ - if (!res) + if ((add && !res) || (!add && res)) return 0; - return run_git("config", "--global", "--add", + return run_git("config", "--global", add ? "--add" : "--unset", + add ? "--no-fixed-value" : "--fixed-value", "scalar.repo", the_repository->worktree, NULL); } static int register_dir(void) { - int res = add_enlistment(); + int res = add_or_remove_enlistment(1); if (!res) res = set_recommended_config(); if (!res) - res = start_maintenance(); + res = toggle_maintenance(1); + + return res; +} + +static int unregister_dir(void) +{ + int res = 0; + + if (toggle_maintenance(0) < 0) + res = -1; + + if (add_or_remove_enlistment(0) < 0) + res = -1; return res; } @@ -254,11 +269,30 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_unregister(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar unregister []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return unregister_dir(); +} + static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { { "register", cmd_register }, + { "unregister", cmd_unregister }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 568987064b2..d9a79984492 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] scalar register [] +scalar unregister [] DESCRIPTION ----------- @@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +Unregister +~~~~~~~~~~ + +unregister []:: + Remove the specified repository from the list of repositories + registered with Scalar and stop the scheduled background maintenance. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Wed Nov 17 14:19:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB4CCC43219 for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5A7863222 for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238481AbhKQOXK (ORCPT ); Wed, 17 Nov 2021 09:23:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238360AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F60C061570 for ; Wed, 17 Nov 2021 06:19:38 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so2240721wme.4 for ; Wed, 17 Nov 2021 06:19: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=uLWWlghNT753Rcq+QFeAaezw69rdNihpNbSkEQ0YgSo=; b=QOGiULk6QziP6QhSvwI8ia3WJlAP8d/WTFm3JrvpBkRwE/MTkpThAArbK9h6rj9wM1 lt2oBTm+J7ujmtAqCl1VeWoRucUJ7J+Gu7gp3d7+Fq7bYzw2EsjlHveeV779REtXrlzg ewPewfwsNqI+vJ/VEsi7Ohwp9FCuohDKTyl9kVZS62d/pw8zDk9ZEb9FE8nd+AEkRfnF 6FDfy8g94phDxIWZBY7rt6f/z1XeA7IXMOpKE7gm1VwyDrwVGBja752h6gAb6GduQOYI eDLxQ33zm3MUIgpLK7BcbdzExNzXPsWk+3lSQ89WVRcQ0jUMt2ICW/VCcGoa3EjDVzI+ w8sg== 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=uLWWlghNT753Rcq+QFeAaezw69rdNihpNbSkEQ0YgSo=; b=Mmh/2ReT9WVXgTXvWHXSYG7UngCc4zZCH45/No6mhVkSoQ4rh6vTQ3scll9ggUAlwm u5FiylNjhMT2ozd9HWBN/stBQKG7z82SQgZPzSBttPxs3AAdBPBgU6Uu8YmQWqlxS7p7 GwiCw0Cw7zMxD/JZ/QSVzgBuidKfI3SEYznlw0awWiUor1h5eRPMwHlVXozJalCSQkpZ sl8UMy66HGF7mZc7jx8rkG/+dzpoKqINYUFySk5Xx8QXjwsMO9SuZb5Xg6OmprNK1SY5 QRuD7D9aBx4JSLhPx+cbIn+voGw07uZgca84dSnf1evMH9/18GD2rtSz8bJGh2mW7jCS 2JPA== X-Gm-Message-State: AOAM530jxXXsg1EHBslKfwFHn/PgSHdWRiu9zlQOG6NMaAiz1gzckRnf k1Ss/1EBSVgJ+hkXJwLXrFMPRU4wW5U= X-Google-Smtp-Source: ABdhPJxkE7qNMRJW8K89evBZSukrvJUjfF8OuL3dUVcsadGqO1EJiiJmh39NKCq7zEQbruSAGq03gQ== X-Received: by 2002:a1c:f213:: with SMTP id s19mr80011509wmc.169.1637158776554; Wed, 17 Nov 2021 06:19:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j19sm29100wra.5.2021.11.17.06.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:36 -0800 (PST) Message-Id: <5e077bf892b5fadb46bcf7c31cc2a4c6cf6b6200.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:14 +0000 Subject: [PATCH v7 09/17] scalar: let 'unregister' handle a deleted enlistment directory gracefully Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When a user deleted an enlistment manually, let's be generous and _still_ unregister it. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 46 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 15 +++++++++++ 2 files changed, 61 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index bab0271c37d..097d3bd478b 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 Wed Nov 17 14:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12624659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94EABC433F5 for ; Wed, 17 Nov 2021 14:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BAE661A79 for ; Wed, 17 Nov 2021 14:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238464AbhKQOXF (ORCPT ); Wed, 17 Nov 2021 09:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238417AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -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 D2A52C06122C for ; Wed, 17 Nov 2021 06:19:38 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso4941024wms.3 for ; Wed, 17 Nov 2021 06:19: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=97iVUlZN97wuaA47a0t2uiGKid4HTvg3w7rjoSoQOX8=; b=Y3sWOq46uM3NDM5UijyYrn6ARWoQESw4H9jP8jqhA62dX/yzI3oJ4VFELFMoUPVI9Z yCKtXL54kTz9tY115rMh/Ac/41CgpCx2mcSECXXutSS0S8Y4qqPUSBMzkofze9nL095v KbfxshwM0XTt0W5s4eW/zLKpHeLaslHpN/E7g+/+a4aHySHbj+sFLQjsabAEOZq1KRgH V+jRCEYi/OfvjJC3f2E4zZeyzgDm1zWqO7K+PgnfJCWPQADsteN6ivpbagG2h8Tn/sDp zstuMaQnBbhJQMddYDeRDPu8B2Wf4MieWjRnIetElacYrh32tU+oKbwLAwQIVqPwH8ek roXQ== 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=97iVUlZN97wuaA47a0t2uiGKid4HTvg3w7rjoSoQOX8=; b=hnopXO/pQOweVtlAiJJLTGgpxhbb6rVxbukKOLqH1GJbC4MKwRtenFh58YVlyy+W8g uMYwguUX0qvjcA5zSxANWqYiahj2tRHYzcC6V0y30d5feJUPvpf+OP8v6HDkOQ443o5r EDZvNSHhQmI4Qkjzquv52lM4IfjSCKn04Ynu+eBuztGtZmI2Q+jlLdTAGKmup/UBE16Z FIe1yvgvMxtd8LhU4Nm1xh2c/OJ6F0HTyUjg3yQSlLM8SppGMLC7QNyHI65ZtscCTcZ8 w5cKT5ksd8zsHkdpEmR7hWyXGuc+Ozc/fbFVBVVaj73KcNlRa0nt9JIi/WQkG34z5tj5 krsg== X-Gm-Message-State: AOAM5317y1R2w9i7Xn3wg41okzMI3UCY1oVn4sDERBv18NMoS/FfScY6 jtmFzuhJEbLIYTFnKy0xajK73p3+UYw= X-Google-Smtp-Source: ABdhPJyF0n68O1O90RXJLpV26xfJQ7hmm+hod+wqcJQuUmf03eLWKQZLv1kPmqNgbo22rxqnbabtDg== X-Received: by 2002:a1c:a5c7:: with SMTP id o190mr6739wme.186.1637158777285; Wed, 17 Nov 2021 06:19:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3sm25749wrp.8.2021.11.17.06.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:36 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:15 +0000 Subject: [PATCH v7 10/17] scalar: implement 'scalar list' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The produced list simply consists of those repositories registered under the multi-valued `scalar.repo` config setting in the user's Git config. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 11 +++++++++++ contrib/scalar/scalar.txt | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 097d3bd478b..4feacd8d62b 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 Wed Nov 17 14:19: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: 12624661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8786EC433EF for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 642BD61C32 for ; Wed, 17 Nov 2021 14:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238473AbhKQOXH (ORCPT ); Wed, 17 Nov 2021 09:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238423AbhKQOW7 (ORCPT ); Wed, 17 Nov 2021 09:22:59 -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 B64F4C06122F for ; Wed, 17 Nov 2021 06:19:39 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id c4so5020705wrd.9 for ; Wed, 17 Nov 2021 06:19: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=r61DTTjZtGcp+DyKnMUP3/d+tsXMFXvUlmG/yKPaWRs=; b=NT9zf+kF2Az3oD8VrYnCFQLQEg9Jz8gGirxNg6gmMLOCWHfSB1GBLUwS9E4JM8YjyO JeERLtCD/5XRGDCSim68FdZpBtjDALn0ntiqKRFxBS9wLGwVUX2wRe493TRZn4Ajvp0+ 9G7COIFDBEj5ez7WFScZ/6oQTPQ+EjB7A1v59OJt1A8OhFU1SaxElLENFpOEEhkls6dd RGC5J5qbQk0PUXg6BZwNBIHbTtgI/Qc1/MyIf0ykRkY8BEh2sFyIMk+MWWjTYdAFmo23 Hy1o/xrB5ju/V1TvUUJ2SF1kuyD3q16DA4Kd2tI0yhXaIgnDLcCECGiRX1mEQC4J6NUK xZtg== 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=r61DTTjZtGcp+DyKnMUP3/d+tsXMFXvUlmG/yKPaWRs=; b=GaRzTkTR/Ob7zdZrgCWL0UYvwkF6qrJUTpiUI96zoRiLIHoSlfc5SodaQLwABzvTKq ov4r9sUq3O9YhCoxFbmH/4ld5TdcOUPGsstDtOdBGoCSUo9S2EjB1kpug0zHys4ikQlQ JFqe5Cl/51Mi1yuMq0w2GJ00aNKXFGbP7rB9WRGC/YOYTNiKUTWhNQYrOXPU5meA0LAR bI5HBTCof9V7+vsGOqUtpds50jH1daDK7P+i/DAM/RqGQaZ6Y0py56D2UB6CJ3gZOInx k6Jlg/ZdbwPlJF0o4CC96aBN18j6B7i0EWB3Vc4sbNNtVM5/LWf/9BPuun3t/5QawA3P xcPQ== X-Gm-Message-State: AOAM533Cj/U+SnCZrXEAPbI3UeoTYZUIwhT4VrHfKkj0C9Mt1UDJJPaZ /t8vRcchvtcEBzApWL1JkOvE2dKAWkk= X-Google-Smtp-Source: ABdhPJx4nxc8UTdRBE2rzjKCI16iOUOL8jZ0IQOmkHZ441KtZ1XBOzBoLH1qlqlSZabh6JVXnLJ62w== X-Received: by 2002:a5d:534b:: with SMTP id t11mr20381303wrv.75.1637158777949; Wed, 17 Nov 2021 06:19:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v8sm941wrd.84.2021.11.17.06.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:37 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:16 +0000 Subject: [PATCH v7 11/17] scalar: implement the `clone` subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This implements Scalar's opinionated `clone` command: it tries to use a partial clone and sets up a sparse checkout by default. In contrast to `git clone`, `scalar clone` sets up the worktree in the `src/` subdirectory, to encourage a separation between the source files and the build output (which helps Git tremendously because it avoids untracked files that have to be specifically ignored when refreshing the index). Also, it registers the repository for regular, scheduled maintenance, and configures a flurry of configuration settings based on the experience and experiments of the Microsoft Windows and the Microsoft Office development teams. Note: since the `scalar clone` command is by far the most commonly called `scalar` subcommand, we document it at the top of the manual page. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 201 +++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 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 4feacd8d62b..43f83dde33b 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 Wed Nov 17 14:19: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: 12624667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DC3AC4167B for ; Wed, 17 Nov 2021 14:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65AB861C32 for ; Wed, 17 Nov 2021 14:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238586AbhKQOXZ (ORCPT ); Wed, 17 Nov 2021 09:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238394AbhKQOXB (ORCPT ); Wed, 17 Nov 2021 09:23:01 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 898A0C061234 for ; Wed, 17 Nov 2021 06:19:40 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso4950190wml.1 for ; Wed, 17 Nov 2021 06:19: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=aNTH9FlmLUV1D0smRDtl/JcI0aq3IqqJlw7lcxaJwfw=; b=azciEDic9RN5YjI/oumXeipsNZ8P/3dkLai1/Yjxdh2kX5u3WoBfJDeHDe7/+oNSHB Qa9dYA3YrowtPToynfww6qNyS89EM4SD8HbUuijXF2nBv8OM1nJkroMHbylBhUT94TQf I00uJALM6N0qLT2dewAGdHZAJVPlaJ8VNi81FMmFZf1wFBv6EvBejIXuHe6qhvzjCzhJ Xr+vzzfTHgo9OWnbLQVGjjHhYpiqPn8l927kxgixZEs7d0Ujhpyueyt4NTLtasOz/J0/ G5Fv9xkGdRNint0SXgaUPeIzwkmjtNiIRrBNcIjy2k1PiGLaL8f+oEWrRL2PTl0IT4OW bHgA== 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=aNTH9FlmLUV1D0smRDtl/JcI0aq3IqqJlw7lcxaJwfw=; b=aoKytNnT0rkj9WROhzVaMFpQOf58oBZvgKXUkry9cH2Uvisy6J/gMFg/tpQPK4DLGn MgimVXD/wj1zmgCdidORc8kDzjCPg30aV9HTMzVSmjBsL0uTs443a0VF8kZwHYDw83Gh 70R9QE/M6+r4qiAM7d1TXmefUJWoZCspgow86QC2n7DN4yumD7kFUTFLYYahU7E22B8I badvLBDkcJJ6L0BAW6Zve/GbP5Y3UUvK81wYnsCk720T90rSJ+3VYzeYgmNgXBfRJfmA jEMu5yKQ0lIQZA1TBMQvyJ0vwHyxcsf8L9M9yXW+sKdkhP/3c3fOTOGfTi7N2MdkFnTy 7/6Q== X-Gm-Message-State: AOAM532vJLP1IMOZOhX8REkpp7cl4OQ6Jikw/a4jKus0ZxfGGdebuyZu oJVyJxKgT48fwHkadopJHOtU9g1pqoA= X-Google-Smtp-Source: ABdhPJy9p2ki+9ATI1iql5oMuuO7/KowJO2kJHp0SRBnnVtf3qrsr32xQnqa3RlnaWpV8okBr/1Scw== X-Received: by 2002:a05:600c:4fca:: with SMTP id o10mr18075496wmq.175.1637158778774; Wed, 17 Nov 2021 06:19:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h3sm3581wrv.69.2021.11.17.06.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:38 -0800 (PST) Message-Id: <2677bcff335a7e408f5ea786343e765e71837ba7.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:17 +0000 Subject: [PATCH v7 12/17] scalar: teach 'clone' to support the --single-branch option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Just like `git clone`, the `scalar clone` command now also offers to restrict the clone to a single branch. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 9 +++++++-- contrib/scalar/scalar.txt | 12 +++++++++++- contrib/scalar/t/t9099-scalar.sh | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 43f83dde33b..516a75be3c4 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 Wed Nov 17 14:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12624679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3388C433F5 for ; Wed, 17 Nov 2021 14:22:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DADD361BE3 for ; Wed, 17 Nov 2021 14:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238533AbhKQOXP (ORCPT ); Wed, 17 Nov 2021 09:23:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238398AbhKQOXB (ORCPT ); Wed, 17 Nov 2021 09:23:01 -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 21A1CC0611FE for ; Wed, 17 Nov 2021 06:19:41 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id a9so5018787wrr.8 for ; Wed, 17 Nov 2021 06:19: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=5J6efhqLKwPw37BZdtrl+rmUFh3AZSA48OGeWE6mV7E=; b=kXlipG4VI2VLGJdSMTo1s5d2DiVyJaBjZCwSWPctVuLZ72lN6w8sGOi+4FLcrJplG1 ZTMcczRRdVsqNDP+xSUB+fTddcWg2wcZz5A8WsKlFpK0q37UgviWAaZwwL/jZhuYknK7 00BzZPPp+e+AYWFp/KK5Pb+rDyzLOcqAcnG8gazFm2+lFiBiraOIjr465lJzDO6KzCX1 HzuTJFcyh2FCwbwLPZ3hGHXqWfDv2ntoeThjgIt+lMe/rvnm3u2CqaiLRfa1vd6O6R+o n5OVazQpM0Ykaqrv0Qf73DP/jAjjUxxfCgnR2KeCdyuLH/aBDpopoS42MgNgBhMhQoho zrKg== 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=5J6efhqLKwPw37BZdtrl+rmUFh3AZSA48OGeWE6mV7E=; b=gorcWeV9N5h0yWLCHGyaknmiJomNpP0QMUU6vTyTaVdcgs3p4B8M8INQwVFn1njGC/ RGfpMl5RK/l3BU/2M1erAYRD9tz4fcDIvHqEfgv9cqvu4SynoOLgkOTuMmHELmF8LXN8 ERTP83w40dZ4a5hkVTFzfuz7M5x9xOhYh2M+6rf9S1qJ9HufZLmPoH275WSr6JJFSMxx q08tDCQKAoxc9/mXQA6395rC2CgheLXeGqS8AhOlU4Q/6TKeYE7u95V4Q0rDPoqkOcgK eYxBR7TMmJew5DS7eae2jS1Jteul5R/k+1goHPRcJhd5ODwmKsk72I+YOnu35p5wM3sj JbhQ== X-Gm-Message-State: AOAM532ECn2uRXpvJ3xDZl3zdaB4OohuVnbpLLvBP/dJw1+a8Wr4GiSy OqGQ6yBgT2OoF4Mny+yBaB3JZv6cgZE= X-Google-Smtp-Source: ABdhPJzaNrUXtG401eZOXY5UJqe0cDDgFIEe4uyOCh1gSi5K+Ld/XyojMiQVVFmEjBi5SXz/5mIpfQ== X-Received: by 2002:adf:d84c:: with SMTP id k12mr20702103wrl.24.1637158779559; Wed, 17 Nov 2021 06:19:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l26sm6616939wms.15.2021.11.17.06.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:39 -0800 (PST) Message-Id: <99affb84284e3c8f868104bde98de8446f57b309.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:18 +0000 Subject: [PATCH v7 13/17] scalar: implement the `run` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Note: this subcommand is provided primarily for backwards-compatibility, for existing Scalar uses. It is mostly just a shim for `git maintenance`, mapping task names from the way Scalar called them to the way Git calls them. The reason why those names differ? The background maintenance was first implemented in Scalar, and when it was contributed as a patch series implementing the `git maintenance` command, reviewers suggested better names, those suggestions were accepted before the patches were integrated into core Git. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 64 +++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 19 ++++++++++++ 2 files changed, 83 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 516a75be3c4..ca524576011 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 Wed Nov 17 14:19:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E665C433EF for ; Wed, 17 Nov 2021 14:20:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3344D63247 for ; Wed, 17 Nov 2021 14:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238597AbhKQOX1 (ORCPT ); Wed, 17 Nov 2021 09:23:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238439AbhKQOXB (ORCPT ); Wed, 17 Nov 2021 09:23:01 -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 0A7FBC061195 for ; Wed, 17 Nov 2021 06:19:42 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id d5so5077612wrc.1 for ; Wed, 17 Nov 2021 06:19: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=m7FNXGAFF5pKL7d91XTp2X+SrZe8ykWkptqO9g88h1Y=; b=aoi9YRqnRR+s+MrrD46beMVbEwwCQO1bqSbtF6flEEFxgE4JAUWtVM3gXhs+z2E9iM ZDSLGWzQLAFppecd6Q7/paDqz9RGvH7StfaEDZWjIdj/vXBTRrNs8JoaFu44BCry/bXt Fpm1e2xoYhF6SvKyCX/W15oK7ke5eHGIkm3PWFqMbR/cjtzpgN0LSIbFu7FrwwdTjfLu KeOuK3JKYiiyQ1mcl9c0MgehHiS1mMzM4iPKIMuuE4pwJVvkpNRhRPKRS24Gy5EDWL0y IUt2H8HtUP4QWi5UGqQ29uodal+ksvHD0xSjI9dqljnM7UwDOrvCD01yCHPLi4kl5PPq jexA== 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=m7FNXGAFF5pKL7d91XTp2X+SrZe8ykWkptqO9g88h1Y=; b=ecfoRVos5A7xVDJjJ4crfJFNXCPdhoF1+c3uWh/m/3uev9G+5BiFAQKijP/X1GHHgs o5GC6ByPz4o53fs5nIG8H4x6MFl5JBaCgl+4+6UhpXMKwLJTe7OEBgSfrl8NU75/Ftkm TPVCB75XiN1r6Hr8w6i5V24k+puohnWDOzYCniPGUhUiuM35xhXSSXNvnmJowfD2zaoW wa7FBaUWtMLbUj9WeL/wuoJgxqE7j4LN2S3UoohGelPallecM+/WaTaR6bDP1KVSx/Ay X4vMTbFJ7cHMcT+ih1SGX+CdVlhDFT6rm2CHyVsiYB34aIRxnPGzqPtVq0uIZlX9Ovhp pvDQ== X-Gm-Message-State: AOAM530MIQlv5FyjPBiwmOEAeFs94eedTCUzSY2f+LVadq+3MmceNP6C 9EMt9B8+ILx7/YclSE0Zrla3iF+LcKQ= X-Google-Smtp-Source: ABdhPJwiNDIixFoF9Kzz7qpc2cTfIs5hzDWgGayqJNCl5eCBAITKKoucf9bOa4Qj6Lsxo+tcgoCPkg== X-Received: by 2002:adf:fe8b:: with SMTP id l11mr20268926wrr.228.1637158780305; Wed, 17 Nov 2021 06:19:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f19sm7631252wmq.34.2021.11.17.06.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:40 -0800 (PST) Message-Id: <69e2242240be441122e6526e55ffbff516cedba7.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:19 +0000 Subject: [PATCH v7 14/17] scalar: allow reconfiguring an existing enlistment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This comes in handy during Scalar upgrades, or when config settings were messed up by mistake. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 79 +++++++++++++++++++++----------- contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 8 ++++ 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index ca524576011..b799decbc2f 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -108,18 +108,20 @@ static int run_git(const char *arg, ...) return res; } -static int set_recommended_config(void) +static int set_recommended_config(int reconfigure) { struct { const char *key; const char *value; + int overwrite_on_reconfigure; } config[] = { - { "am.keepCR", "true" }, - { "core.FSCache", "true" }, - { "core.multiPackIndex", "true" }, - { "core.preloadIndex", "true" }, + /* Required */ + { "am.keepCR", "true", 1 }, + { "core.FSCache", "true", 1 }, + { "core.multiPackIndex", "true", 1 }, + { "core.preloadIndex", "true", 1 }, #ifndef WIN32 - { "core.untrackedCache", "true" }, + { "core.untrackedCache", "true", 1 }, #else /* * Unfortunately, Scalar's Functional Tests demonstrated @@ -133,28 +135,29 @@ static int set_recommended_config(void) * Therefore, with a sad heart, we disable this very useful * feature on Windows. */ - { "core.untrackedCache", "false" }, + { "core.untrackedCache", "false", 1 }, #endif - { "core.logAllRefUpdates", "true" }, - { "credential.https://dev.azure.com.useHttpPath", "true" }, - { "credential.validate", "false" }, /* GCM4W-only */ - { "gc.auto", "0" }, - { "gui.GCWarning", "false" }, - { "index.threads", "true" }, - { "index.version", "4" }, - { "merge.stat", "false" }, - { "merge.renames", "false" }, - { "pack.useBitmaps", "false" }, - { "pack.useSparse", "true" }, - { "receive.autoGC", "false" }, - { "reset.quiet", "true" }, - { "feature.manyFiles", "false" }, - { "feature.experimental", "false" }, - { "fetch.unpackLimit", "1" }, - { "fetch.writeCommitGraph", "false" }, + { "core.logAllRefUpdates", "true", 1 }, + { "credential.https://dev.azure.com.useHttpPath", "true", 1 }, + { "credential.validate", "false", 1 }, /* GCM4W-only */ + { "gc.auto", "0", 1 }, + { "gui.GCWarning", "false", 1 }, + { "index.threads", "true", 1 }, + { "index.version", "4", 1 }, + { "merge.stat", "false", 1 }, + { "merge.renames", "false", 1 }, + { "pack.useBitmaps", "false", 1 }, + { "pack.useSparse", "true", 1 }, + { "receive.autoGC", "false", 1 }, + { "reset.quiet", "true", 1 }, + { "feature.manyFiles", "false", 1 }, + { "feature.experimental", "false", 1 }, + { "fetch.unpackLimit", "1", 1 }, + { "fetch.writeCommitGraph", "false", 1 }, #ifdef WIN32 - { "http.sslBackend", "schannel" }, + { "http.sslBackend", "schannel", 1 }, #endif + /* Optional */ { "status.aheadBehind", "false" }, { "commitGraph.generationVersion", "1" }, { "core.autoCRLF", "false" }, @@ -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 Wed Nov 17 14:19:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E24AC433EF for ; Wed, 17 Nov 2021 14:22:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC6B561BE3 for ; Wed, 17 Nov 2021 14:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238484AbhKQOZP (ORCPT ); Wed, 17 Nov 2021 09:25:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238446AbhKQOXC (ORCPT ); Wed, 17 Nov 2021 09:23:02 -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 CB5ACC0611A6 for ; Wed, 17 Nov 2021 06:19:42 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id r8so5022149wra.7 for ; Wed, 17 Nov 2021 06:19: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=vm/dhDtJBmVuRxe+hDMgC9L6CFNXEm12z46YWE+zzbA=; b=TsRTQblhT8uYqBc/Q+UugXPYqDPUaWr2qdpnOuH2YaJI5da+YHJP5+snYOblDAmccI aPQenOrk5jAsm+utR/s3mBw14mBNUFlAErLOavLXsh37yKIQkeGUB+aKTKckxjgv4GAx dgk3zL5/nSqbgjyF8wpaelB1q/QNXjBvH0MVwxGSsPBnoNhDsEmqg+N7e9BcJ2Y27+bF ycwoLnL/RBZLRXQvDWS6zesd2pRC7qDFUt8Q28BT8+l80zt1/htTXKt9qwWYlurcYpnb Vgwt0ZeGUEcn1UNn4WZ5ESHynQfHsTJK1ta4emJvSVAXe5DdouKuIyHCWavsLw6f+oVO d5DA== 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=vm/dhDtJBmVuRxe+hDMgC9L6CFNXEm12z46YWE+zzbA=; b=ARnSCa59eS532HBAVngAdy5gpqMxl+ABeEspj4mjeDaKv4P8Lo6sVENosaXeOySKJA WXKs/pz9ubKxum48XSdZ73DgbtC/9a9MygSEHeq8IEt7Qn3MZ/Dubbg/AxKCJnzhsOGm 67oK8axR0Uvo5mulx744i405x9RfTK9fTdGY1MFbgWqid1Ffz3kh5EJKjatzRiX4eFFA nqwiOimJSudK9ZEa50C8Z7EgR1ojmszJCxEULffTgCZRmaViT/2ugKLAhAdNiU1ZZo0F PPDaDFma05UbF3Vr+QMCXv+S9zoSY7ilUv5QAYo/e1oOj9tdw8rOIUZZU9HQbGQuEDPu Pzhg== X-Gm-Message-State: AOAM531mspOm709m2yn4Y+PFudoATdz22R2fWiAgLKn8EqJschsowxYJ QEE4Vzqf3Q9j4IDECwWJqg6KZhQ8++c= X-Google-Smtp-Source: ABdhPJxSmAc3HMql+o4ICFLoTyjgIukRo02D3NFFzgUKXTOPHYksiO6rGHcJP2NSl+m9jmYEEZoeCg== X-Received: by 2002:a5d:5186:: with SMTP id k6mr20966389wrv.146.1637158781195; Wed, 17 Nov 2021 06:19:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l5sm5682187wml.20.2021.11.17.06.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:40 -0800 (PST) Message-Id: <0068c18aa624166706abbbd6e7f8a0bd04372637.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:20 +0000 Subject: [PATCH v7 15/17] scalar: teach 'reconfigure' to optionally handle all registered enlistments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin After a Scalar upgrade, it can come in really handy if there is an easy way to reconfigure all Scalar enlistments. This new option offers this functionality. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 61 ++++++++++++++++++++++++++++++-- contrib/scalar/scalar.txt | 9 +++-- contrib/scalar/t/t9099-scalar.sh | 3 ++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index b799decbc2f..71ca573f3af 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 Wed Nov 17 14:19:21 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: 12624673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEA58C433F5 for ; Wed, 17 Nov 2021 14:20:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF52563214 for ; Wed, 17 Nov 2021 14:20:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238643AbhKQOXd (ORCPT ); Wed, 17 Nov 2021 09:23:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238445AbhKQOXC (ORCPT ); Wed, 17 Nov 2021 09:23:02 -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 B1754C061A0E for ; Wed, 17 Nov 2021 06:19:43 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id i5so5056603wrb.2 for ; Wed, 17 Nov 2021 06:19: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=9DF8xacLLxcfovMqJ/eqpmiu+Qris70HYXyQdV96HVg=; b=TLtaWIyyQTwiRz2jP5VYqXPtU6rLM6qlAZwy47x/tfO6oVUaw7udnF5Mdgo0QxqIE8 AdoBwxnLLClw52dG/7nrTCchGej/+c6TxMMazDm8yapMMygSoMb+8nudCLIiG133xdjA l+8ABhQ7a0Yu2CS40FZG/l5s034bpXB37W6pPJj2j5jiQKua6fDfMg9fSpRX21sg3Uij ZGs8L370milMMSeLWGnhwEtyqo52Ff3czV93q9CkEPAsqfaP0N07JHrUlCdmAmvnfRe/ Plbu/EmdBjA+oY17c0Hh/GLNXF31X2+tfAms2Nca4JSvWKijKLIdU3LdzpM4PwKqpRjm J8wA== 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=9DF8xacLLxcfovMqJ/eqpmiu+Qris70HYXyQdV96HVg=; b=gjrceh2O8ySEkCIxJh8kqdoie6Cv0Z/oXsgE2beD8KckKDsq3Lmzm2jX46KD+l68Ry 6heVWIx5uB2fsbGL6mjX9z0/QngC9MLPgg9PgMj0G8PA9UiDOIpMkhw6CJlM33VTVlOL OVtloQRhEiv8ZNX5UhCgTvrmPU72X8L6N2wOkdiEhWxq+/H8I4VGJncBEO8r7HCTfQVY NGAx3VMXaVnb2AxPq1XM1zNZMI8nFLZ8yuLNJ5JzPYBGaGtNdz2K7HQ4Q0qfMI5+RoMo frz0DOSGkCObDSPi5d1J/ugl+mvMlbKO20JxtmJuVUNHa7QnWUCQUojsMnn3a3HakA0y qteg== X-Gm-Message-State: AOAM532qKRpEzDP/0Jx9LWdU6Wp827GVwONnpFuBTUu4btyGezO/3Bnc 51qhhLBBpIaovz4/Be+8umhzpJQew28= X-Google-Smtp-Source: ABdhPJyplnFcc7NkakP6rJ1K57M/KCAG2q7Unv2+3Ek7rjxydk9l6fZ5jIZz2kUuQ1rEN0u9NOLhuw== X-Received: by 2002:a05:6000:1043:: with SMTP id c3mr19844009wrx.64.1637158782063; Wed, 17 Nov 2021 06:19:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s13sm5813729wmc.47.2021.11.17.06.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:41 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:21 +0000 Subject: [PATCH v7 16/17] scalar: implement the `delete` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Matthew John Cheetham Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew John Cheetham From: Matthew John Cheetham Delete an enlistment by first unregistering the repository and then deleting the enlistment directory (usually the directory containing the worktree `src/` directory). On Windows, if the current directory is inside the enlistment's directory, change to the parent of the enlistment directory, to allow us to delete the enlistment (directories used by processes e.g. as current working directories cannot be deleted on Windows). Co-authored-by: Victoria Dye Signed-off-by: Matthew John Cheetham Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 63 ++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 9 +++++ 3 files changed, 80 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 71ca573f3af..c53697ad6a0 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 Wed Nov 17 14:19:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12624677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F873C433FE for ; Wed, 17 Nov 2021 14:21:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AFCE63212 for ; Wed, 17 Nov 2021 14:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238731AbhKQOX5 (ORCPT ); Wed, 17 Nov 2021 09:23:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238451AbhKQOXC (ORCPT ); Wed, 17 Nov 2021 09:23:02 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80328C079782 for ; Wed, 17 Nov 2021 06:19:44 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso4950372wml.1 for ; Wed, 17 Nov 2021 06:19: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=2WSVpdckOKo8sTzLhexO457CfG7Z/d/GCqQg3H5ly1Q=; b=UZKDhMCH/YkGWXYGtoH8Dbh7IlDH+H8eOxmcZFmjHvQgE9aMPonFAy8CC/WEFd0ZL7 vUb+17H6PcMQlG9pwj0GgZZWD7LKTEhG7APy65mHngrLQVi7HnKNCyYDPIj6uURxeCJS RoA4BfxMnbypb7ONXVphFitR7iME1U9LRiv+hY7YnnRCIzadunbEtqaVevesb9EgP6ba HgkRKkuNEyxuPaqxEShHh5kC3mfQGMZpoNxjXmwZwSzggcCdA3A624Z9ldotmbzJI9pL 7ZVLsRXhMCzzRVaptc1qRHbkSTGugGej3ja8LXLAc9yDvG6jo2ri4qy2JZhV7TROmdb7 1ylA== 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=2WSVpdckOKo8sTzLhexO457CfG7Z/d/GCqQg3H5ly1Q=; b=ePA5/FlWCpegLJ3eIJCr8l4Fsw275ZsGEiiTrJO0EEPrZjEJC8LUXxxnY1cRDbYONs hXKqoZbBf/T/bXjVh3EDxzyBWcYta8Qf+kNjH/C8FCay+KimJPnUDv9ggDOgKSLvVEbE b4SlXA+ZD3nLb0hXrd9aY47WrMPomioOZYrUA/NjqoXDScYobe4Fmo4LKnIL6Z7d6Pbj 76eSurnNbJ3h8NqBn98f7GPFLOe3bm/lKUSI7yGjhpa5xRqFuVfFXsZYW1O5AQr0V2O4 0yKSbu8lygd6w/B1t6KYglCgPCx+Bw0uelOHW5Sl1LpQAew6WR9AX21u0thqr+HExdIX yFNw== X-Gm-Message-State: AOAM532Vw5pZpRNRVcaDEQ/l7cbFDtgaWLFr8GKznLyiTNc9Su4HO8Wc rOWs+VQJO1RIzKzQAmqHzlUiPGzqv4s= X-Google-Smtp-Source: ABdhPJy2q5g0ojrxoy1Lb6JIhCucYa3qSb61g4a7MKcuRW/2BDD9aXurRGrguwaHYkX1W+dDmvuTIQ== X-Received: by 2002:a05:600c:2e46:: with SMTP id q6mr71314wmf.6.1637158782964; Wed, 17 Nov 2021 06:19:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h2sm20608wrz.23.2021.11.17.06.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 06:19:42 -0800 (PST) Message-Id: <96a803416b531cd7a85cdb68e54d0a7d58ddcbe8.1637158762.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 17 Nov 2021 14:19:22 +0000 Subject: [PATCH v7 17/17] scalar: implement the `version` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The .NET version of Scalar has a `version` command. This was necessary because it was versioned independently of Git. Since Scalar is now tightly coupled with Git, it does not make sense for them to show different versions. Therefore, it shows the same output as `git version`. For backwards-compatibility with the .NET version, `scalar version` prints to `stderr`, though (`git version` prints to `stdout` instead). Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index c53697ad6a0..1fc4965bebb 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}, };