From patchwork Wed Sep 8 19:24:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8BFCC433FE for ; Wed, 8 Sep 2021 19:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 894AB610FF for ; Wed, 8 Sep 2021 19:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350549AbhIHTZ6 (ORCPT ); Wed, 8 Sep 2021 15:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350001AbhIHTZ5 (ORCPT ); Wed, 8 Sep 2021 15:25:57 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C04C061757 for ; Wed, 8 Sep 2021 12:24:49 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m2so2581567wmm.0 for ; Wed, 08 Sep 2021 12:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=iXLjZUJ4SF7urD3/OFYAEJlIY8QKTaQKSGLrhuMOp/o=; b=CV58o3IfH9jhkCTb+M9elnxUbGWtgYK+pZ8B9iaSMjEef1cIFvW4i1WBB5AwdksVOu NqvVe7HQaUaWyR1FaAZwYKbEK5b6mbRz7lwXilfuTJMi9lYSW8MfkOnt7FWXvYY6v7WZ WXkNFTxY/L3WO0MAVmXJuTvCYSI1odMUNmt+Rbh531vwmmKxcTbrt3AeivVxV6uLpll3 GbYc7h4xpXqziaVbTxBSB8EweaHcOKcjCmjeU1hJl8YfSFZQRdSuC+FepU+sefl67FEe ib7cKd7ezYrgGqmm/j+vaZYMot9OXtP3BS/dkSlxXBYTVw+ENEjURsdtGKmPd9DUfNed c9jQ== 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=iXLjZUJ4SF7urD3/OFYAEJlIY8QKTaQKSGLrhuMOp/o=; b=Cb79RGIquCZRLWirUxaIYTxVkqg/V5UwJ2CLlSOfft+UZZRDYXXOcqnXF1ChxbV1+m IchrEE3V5gXA8ykjvVJPnCNGVnke9J8w7e7GDZkydIpaCOASXzh9mQDJXsP8zJn1eaCY F4lqko8yQo/qjObIXe4C05lGJViUNYTgUroaZalibSEfQJPUJBqscFxhsqqrIKrJQJ+r UcblYN/AkQ/7fSf+FZRMmrinH4sqe5ebzY4I7ZRc7qT6CK86XZiBd5xA+8h6ySd00Rjj Ov0LuVW2wFRW30NDjPVwnHNiDvaGZuXWV+y2RRBSKjSX4nbrK8HNbhT2eCz2pa2geI1J hiLw== X-Gm-Message-State: AOAM533olpp8qACOL7IDouSlHvCKjfRhNaTnlMGfK7yJ4aefENRwUqRd MHVpBX7Q1anADCOPcZ6wTLqNujZ+U9Y= X-Google-Smtp-Source: ABdhPJyqeuw5RSsM345xqbDg1B4NZ7dqG0YHsN/mkPcoh1PSlytsMhNZvB15IDzH1aQwDyjHdvJfmQ== X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr5212126wmk.135.1631129087716; Wed, 08 Sep 2021 12:24:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j14sm25926wrp.21.2021.09.08.12.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:47 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:31 +0000 Subject: [PATCH v3 01/15] scalar: create a rudimentary executable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 was always to 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 that which `git.exe` cannot do. One such thing is that `scalar clone ` will automatically set up a partial, sparse clone, and configure known-helpful settings from the start. So let's bring this convenience into Git's tree. The idea here is that you can (optionally) build Scalar via make -C contrib/scalar/Makefile This will build the `scalar` executable and put it into the contrib/scalar/ subdirectory. The slightly awkward addition of the `contrib/scalar/*` bits to the top-level `Makefile` are actually really required: we want to link to `libgit.a`, which means that we will need to use the very same `CFLAGS` and `LDFLAGS` as the rest of Git. An early development version of this patch tried to replicate all the conditional code in `contrib/scalar/Makefile` (e.g. `NO_POLL`) just like `contrib/svn-fe/Makefile` used to do before it was retired. It turned out to be quite the whack-a-mole game: the SHA-1-related flags, the flags enabling/disabling `compat/poll/`, `compat/regex/`, `compat/win32mmap.c` & friends depending on the current platform... To put it mildly: it was a major mess. Instead, this patch makes minimal changes to the top-level `Makefile` so that the bits in `contrib/scalar/` can be compiled and linked, and adds a `contrib/scalar/Makefile` that uses the top-level `Makefile` in a most minimal way to do the actual compiling. Note: With this commit, we only establish the infrastructure, no Scalar functionality is implemented yet; We will do that incrementally over the next few commits. Signed-off-by: Johannes Schindelin --- Makefile | 8 ++++++++ contrib/scalar/.gitignore | 2 ++ contrib/scalar/Makefile | 34 ++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 contrib/scalar/.gitignore create mode 100644 contrib/scalar/Makefile create mode 100644 contrib/scalar/scalar.c diff --git a/Makefile b/Makefile index c3565fc0f8f..2d5c822f7a8 100644 --- a/Makefile +++ b/Makefile @@ -2447,6 +2447,10 @@ endif .PHONY: objects objects: $(OBJECTS) +SCALAR_SOURCES := contrib/scalar/scalar.c +SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o) +OBJECTS += $(SCALAR_OBJECTS) + dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS)))) @@ -2586,6 +2590,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS) +contrib/scalar/scalar$X: $(SCALAR_OBJECTS) GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \ + $(filter %.o,$^) $(LIBS) + $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore new file mode 100644 index 00000000000..ff3d47e84d0 --- /dev/null +++ b/contrib/scalar/.gitignore @@ -0,0 +1,2 @@ +/*.exe +/scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile new file mode 100644 index 00000000000..40c03ad10e1 --- /dev/null +++ b/contrib/scalar/Makefile @@ -0,0 +1,34 @@ +QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir +QUIET_SUBDIR1 = + +ifneq ($(findstring s,$(MAKEFLAGS)),s) +ifndef V + QUIET_SUBDIR0 = +@subdir= + QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ + $(MAKE) $(PRINT_DIR) -C $$subdir +else + export V +endif +endif + +all: + +include ../../config.mak.uname +-include ../../config.mak.autogen +-include ../../config.mak + +TARGETS = scalar$(X) scalar.o +GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a + +all: scalar$X + +$(GITLIBS): + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) + +$(TARGETS): $(GITLIBS) scalar.c + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) + +clean: + $(RM) $(TARGETS) + +.PHONY: all clean FORCE diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c new file mode 100644 index 00000000000..7cff29e0fcd --- /dev/null +++ b/contrib/scalar/scalar.c @@ -0,0 +1,36 @@ +/* + * The Scalar command-line interface. + */ + +#include "cache.h" +#include "gettext.h" +#include "parse-options.h" + +static struct { + const char *name; + int (*fn)(int, const char **); +} builtins[] = { + { NULL, NULL}, +}; + +int cmd_main(int argc, const char **argv) +{ + struct strbuf scalar_usage = STRBUF_INIT; + int i; + + if (argc > 1) { + argv++; + argc--; + + for (i = 0; builtins[i].name; i++) + if (!strcmp(builtins[i].name, argv[0])) + return !!builtins[i].fn(argc, argv); + } + + strbuf_addstr(&scalar_usage, + N_("scalar []\n\nCommands:\n")); + for (i = 0; builtins[i].name; i++) + strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); + + usage(scalar_usage.buf); +} From patchwork Wed Sep 8 19:24:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D4B0C433F5 for ; Wed, 8 Sep 2021 19:24:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E682961104 for ; Wed, 8 Sep 2021 19:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350582AbhIHTZ7 (ORCPT ); Wed, 8 Sep 2021 15:25:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350510AbhIHTZ6 (ORCPT ); Wed, 8 Sep 2021 15:25:58 -0400 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 976CCC061575 for ; Wed, 8 Sep 2021 12:24:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso2341696wmi.5 for ; Wed, 08 Sep 2021 12:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=j2bGVjqPT7Pn8kjChLvmqQS0Jlg6df0AQr+Wz7oQLNA=; b=iwjuOV6ZWbjZqPodLFr29IGqUrEF+91WpXlvTnx5zQkTiWNONr3zzOhESbprNgcP7m LQKyLPoj+c02TXjZ+cVu71pKq2wKZyAKdlB5DHTkVxcA4VJeyKFEdCD49crw/F2nmojd dga4XbA6duQvC+/0M740El+z/pyjq7ksTieoIWkEuFMxrVF8LIhsannKWC1WtqDoNeTO CnlUW5QuOpPcimXx/+7DCkEZvWoV2XmTOp10PK26Y77xhSUlMgTqzlMAw733sRVRwth2 /aPbhA6vu34xmPo2WS1iPHTSU4ZAj3g3wJCV5V/onhuQYFctJdYD/FaF1mfmqwmrmy1I TncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=j2bGVjqPT7Pn8kjChLvmqQS0Jlg6df0AQr+Wz7oQLNA=; b=tckukNlVHRCljGWgE/48D3ISjXBEp6FKx8kcon9MCS6vWVTInVj4Bglm2GHIdk2gte 9nhfAHb8bppM01R2EkaWveb1M0V7iRAPYhRKZpJ7fgENmn3NBuo9tCpZrHdmnC3sWfEf sl/xyXZn45tj2Crqaa3T5+44xJmgFCOH59O5spvAOPoil6xWTunZAYS7mpIIbjODK/Rn mXjSEioqW/EjfRiYvx+jPnCtwGs9rpq2IXYDPhBQ72H/49nk6+twh2gk78voA51hJiDb 31TdG4seSMve2+b9ZPRlOkyrLyUX6OVJUvN1Bh7Vt3qdAsw2TeAF8+lx28q4LOXExQZp TWCQ== X-Gm-Message-State: AOAM5312RvjOtCqWQT8q+KgXubnaF5u3mZpKWHFS5L5fHlXEAH7GnOCr yFPhaOp4dFPnPtVFHV5wCUEqsRPLWeU= X-Google-Smtp-Source: ABdhPJzndYybyTW92dDBkT16Y1iYdQOkDcNXgKGtwWj5sosUi1If1N+r4G+auv8hp1HZqL5bYef+RQ== X-Received: by 2002:a1c:d2:: with SMTP id 201mr4994586wma.67.1631129088279; Wed, 08 Sep 2021 12:24:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l7sm24207wmj.9.2021.09.08.12.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:47 -0700 (PDT) Message-Id: <4f886575dcfb97d5bbd04fe7551e03935ac0af69.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:32 +0000 Subject: [PATCH v3 02/15] scalar: start documenting the command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This commit establishes the infrastructure to build the manual page for the `scalar` command. Signed-off-by: Johannes Schindelin --- contrib/scalar/.gitignore | 3 +++ contrib/scalar/Makefile | 14 +++++++++++++- contrib/scalar/scalar.txt | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 contrib/scalar/scalar.txt diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore index ff3d47e84d0..00441073f59 100644 --- a/contrib/scalar/.gitignore +++ b/contrib/scalar/.gitignore @@ -1,2 +1,5 @@ +/*.xml +/*.1 +/*.html /*.exe /scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index 40c03ad10e1..85c186634e9 100644 --- a/contrib/scalar/Makefile +++ b/contrib/scalar/Makefile @@ -6,6 +6,7 @@ ifndef V QUIET_SUBDIR0 = +@subdir= QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ $(MAKE) $(PRINT_DIR) -C $$subdir + QUIET = @ else export V endif @@ -30,5 +31,16 @@ $(TARGETS): $(GITLIBS) scalar.c clean: $(RM) $(TARGETS) + $(RM) scalar.1 scalar.html scalar.xml -.PHONY: all clean FORCE +docs: scalar.html scalar.1 + +scalar.html: | scalar.1 # prevent them from trying to build `doc.dep` in parallel + +scalar.html scalar.1: scalar.txt + $(QUIET_SUBDIR0)../../Documentation$(QUIET_SUBDIR1) \ + MAN_TXT=../contrib/scalar/scalar.txt \ + ../contrib/scalar/$@ + $(QUIET)test scalar.1 != "$@" || mv ../../Documentation/$@ . + +.PHONY: all clean docs FORCE diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt new file mode 100644 index 00000000000..5f7131861a5 --- /dev/null +++ b/contrib/scalar/scalar.txt @@ -0,0 +1,38 @@ +scalar(1) +========= + +NAME +---- +scalar - an opinionated repository management tool + +SYNOPSIS +-------- +[verse] +scalar [] + +DESCRIPTION +----------- + +Scalar is an opinionated repository management tool. By creating new +repositories or registering existing repositories with Scalar, your Git +experience will speed up. Scalar sets advanced Git config settings, +maintains your repositories in the background, and helps reduce data sent +across the network. + +An important Scalar concept is the enlistment: this is the top-level directory +of the project. It usually contains the subdirectory `src/` which is a Git +worktree. This encourages the separation between tracked files (inside `src/`) +and untracked files, such as build artifacts (outside `src/`). When registering +an existing Git worktree with Scalar whose name is not `src`, the enlistment +will be identical to the worktree. + +The `scalar` command implements various subcommands, and different options +depending on the subcommand. + +SEE ALSO +-------- +linkgit:git-maintenance[1]. + +Scalar +--- +Associated with the linkgit:git[1] suite From patchwork Wed Sep 8 19:24:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08C08C433F5 for ; Wed, 8 Sep 2021 19:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E866F61104 for ; Wed, 8 Sep 2021 19:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350956AbhIHT0C (ORCPT ); Wed, 8 Sep 2021 15:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350534AbhIHTZ6 (ORCPT ); Wed, 8 Sep 2021 15:25:58 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F47C061757 for ; Wed, 8 Sep 2021 12:24:50 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id n7-20020a05600c3b8700b002f8ca941d89so2339914wms.2 for ; Wed, 08 Sep 2021 12:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=tEEtHAQ8UCYDaO4A/Ch4X+sM3t0MfBKstGjJxvTXvA8=; b=XjyYnYwivZ09dMbyuXDGkyezwBjonLATDErlND/PYW7tfBdjljTYp9krunucnZswhQ 2KlO/WxLqEA/wlouRd3Z7b5dEZfAj+HhDY8EILzP0hZFW379R/qG+qXT8Mn6JPGWV6gc tGAL5m/vBne9XyB0ZL1ycN50CCYy/tkH1QacYHSEFHGbGDrg5JOw03iUyVqHqNQ8riLi 1sc8DdTZIwUzh8aUemHn8V1uXuvARVBczjfDbErgpQirkemdQ1APJaozXVGnt3jJQw9V hI8T+hJajcoVFFHPAkYNxUp3+bTby99pb4PB3tcw2OcujtFPP+N2c4sUxMgsK6z4KG5D Q29Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=tEEtHAQ8UCYDaO4A/Ch4X+sM3t0MfBKstGjJxvTXvA8=; b=h6rQ3+Zw7X42ELE2BBAK2zNbDW7kJBijoh8YXN/wgASd+EqzmK7g7wdktiH5m/Lp4E t7uaTAZ46zvTf0Wr+xY4wa90Cyhob2oeQqbRVpHN8q0mTp3zkJZsolKRQho+ZX1Qu6IK 8vm8/DDBZjgpNAmEmyFtYtF/Vf7TEx0857qOQmee26bYR8rKVX/nReuOcg4vVoTTAMar guvq684dyhQSOhyPdZJ716iTWkjI9VGMa3tUPeLp7V65dZwd9Rm+iaSWx1c74qQI0tMl 5EIMlgSoR6/XrV8u1eBNAtwLB4gGyy2q3QR0baz9PYbcdgQZrkrFryGdIF1hIXYqBh0B g00g== X-Gm-Message-State: AOAM531gT2XNWinrf3Y/0SKJBsOk5BEluowD4q/dhFzy1RKB7oRoSPxG tz3E36SaCBp0IN4baUUZZbH6qgtLGMU= X-Google-Smtp-Source: ABdhPJzVrSv3n6TN48Yej2C0umxKPMa6xrFG3C8UQc+X69Ywp8/qcR5SxtWO+/HYxcQxfLOFDFagZg== X-Received: by 2002:a05:600c:14c6:: with SMTP id i6mr5154746wmh.99.1631129088864; Wed, 08 Sep 2021 12:24:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3sm40951wrv.18.2021.09.08.12.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:48 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:33 +0000 Subject: [PATCH v3 03/15] scalar: create test infrastructure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To test the Scalar command, create a test script in contrib/scalar/t that is executed as `make -C contrib/scalar test`. Since Scalar has no meaningful capabilities yet, the only test is rather simple. We will add more tests in subsequent commits that introduce corresponding, new functionality. Note: this test script is intended to test `scalar` only lightly, even after all of the functionality is implemented. A more comprehensive functional (or: integration) test suite can be found at https://github.com/microsoft/scalar; It is used in the workflow https://github.com/microsoft/git/blob/HEAD/.github/workflows/scalar-functional-tests.yml in Microsoft's Git fork. This test suite performs end-to-end tests with a real remote repository, and is run as part of the regular CI builds. Since those tests require some functionality supported only by Microsoft's Git fork ("GVFS protocol"), there is no intention to port that fuller test suite to `contrib/scalar/`. Signed-off-by: Johannes Schindelin --- contrib/scalar/Makefile | 17 +++++-- contrib/scalar/t/Makefile | 78 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 17 +++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 contrib/scalar/t/Makefile create mode 100755 contrib/scalar/t/t9099-scalar.sh diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index 85c186634e9..8620042f281 100644 --- a/contrib/scalar/Makefile +++ b/contrib/scalar/Makefile @@ -3,6 +3,7 @@ QUIET_SUBDIR1 = ifneq ($(findstring s,$(MAKEFLAGS)),s) ifndef V + QUIET_GEN = @echo ' ' GEN $@; QUIET_SUBDIR0 = +@subdir= QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ $(MAKE) $(PRINT_DIR) -C $$subdir @@ -21,7 +22,7 @@ include ../../config.mak.uname TARGETS = scalar$(X) scalar.o GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a -all: scalar$X +all: scalar$X ../../bin-wrappers/scalar $(GITLIBS): $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) @@ -30,9 +31,19 @@ $(TARGETS): $(GITLIBS) scalar.c $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) clean: - $(RM) $(TARGETS) + $(RM) $(TARGETS) ../../bin-wrappers/scalar $(RM) scalar.1 scalar.html scalar.xml +../../bin-wrappers/scalar: ../../wrap-for-bin.sh Makefile + @mkdir -p ../../bin-wrappers + $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ + -e 's|@@BUILD_DIR@@|$(shell cd ../.. && pwd)|' \ + -e 's|@@PROG@@|contrib/scalar/scalar$(X)|' < $< > $@ && \ + chmod +x $@ + +test: all + $(MAKE) -C t + docs: scalar.html scalar.1 scalar.html: | scalar.1 # prevent them from trying to build `doc.dep` in parallel @@ -43,4 +54,4 @@ scalar.html scalar.1: scalar.txt ../contrib/scalar/$@ $(QUIET)test scalar.1 != "$@" || mv ../../Documentation/$@ . -.PHONY: all clean docs FORCE +.PHONY: all clean docs test FORCE diff --git a/contrib/scalar/t/Makefile b/contrib/scalar/t/Makefile new file mode 100644 index 00000000000..6170672bb37 --- /dev/null +++ b/contrib/scalar/t/Makefile @@ -0,0 +1,78 @@ +# Run scalar tests +# +# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin +# + +-include ../../../config.mak.autogen +-include ../../../config.mak + +SHELL_PATH ?= $(SHELL) +PERL_PATH ?= /usr/bin/perl +RM ?= rm -f +PROVE ?= prove +DEFAULT_TEST_TARGET ?= test +TEST_LINT ?= test-lint + +ifdef TEST_OUTPUT_DIRECTORY +TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results +else +TEST_RESULTS_DIRECTORY = ../../../t/test-results +endif + +# Shell quote; +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) +PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) +TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) + +T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) + +all: $(DEFAULT_TEST_TARGET) + +test: $(TEST_LINT) + $(MAKE) aggregate-results-and-cleanup + +prove: $(TEST_LINT) + @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS) + $(MAKE) clean-except-prove-cache + +$(T): + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) + +clean-except-prove-cache: + $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)' + $(RM) -r valgrind/bin + +clean: clean-except-prove-cache + $(RM) .prove + +test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax + +test-lint-duplicates: + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ + test -z "$$dups" || { \ + echo >&2 "duplicate test numbers:" $$dups; exit 1; } + +test-lint-executable: + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \ + test -z "$$bad" || { \ + echo >&2 "non-executable tests:" $$bad; exit 1; } + +test-lint-shell-syntax: + @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T) + +aggregate-results-and-cleanup: $(T) + $(MAKE) aggregate-results + $(MAKE) clean + +aggregate-results: + for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \ + echo "$$f"; \ + done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh + +valgrind: + $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" + +test-results: + mkdir -p test-results + +.PHONY: $(T) aggregate-results clean valgrind diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh new file mode 100755 index 00000000000..16f2b72b126 --- /dev/null +++ b/contrib/scalar/t/t9099-scalar.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +test_description='test the `scalar` command' + +TEST_DIRECTORY=$PWD/../../../t +export TEST_DIRECTORY + +# Make it work with --no-bin-wrappers +PATH=$PWD/..:$PATH + +. ../../../t/test-lib.sh + +test_expect_success 'scalar shows a usage' ' + test_expect_code 129 scalar -h +' + +test_done From patchwork Wed Sep 8 19:24:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12481759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7573C433EF for ; Wed, 8 Sep 2021 19:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACB94610F8 for ; Wed, 8 Sep 2021 19:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350965AbhIHT0F (ORCPT ); Wed, 8 Sep 2021 15:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350001AbhIHTZ7 (ORCPT ); Wed, 8 Sep 2021 15:25:59 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C67C061575 for ; Wed, 8 Sep 2021 12:24:50 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id b6so4831779wrh.10 for ; Wed, 08 Sep 2021 12:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=b5y4dR7pqaUrtB65kZ7JF9/dDKoxFFqiSg9M6Oebu7I=; b=hlhnjLfq/N1YRb3DaruNH90arENR+P/siwW1hh1YS3WMOMoWdiJmuFuk9TPq7xv0/Y v4eEy+v7/5bdhqCNSTY0D0sMvHUQSK6/cygf+4s2lLSwO4hVWNBu5XRXkgY4PSUBY6/H P8rs93fcCtMc2sgkcUQcjnKd8RzH5QmsT5SfLOhWdz69vynV9kvs/CFnWjgjviMI70wV QFBhk2MOlrZlQikTOr4EZNDwC0t1Vv9ZsQAQeMFGiLe4lc9oKQ9uDea7mukGB/6MMNC5 CuGlkt2iKAZUnIPfrZf5uBLQWLPI4rl+J96AcvMsR7U+CMK639V1gYFqTDBz7ENY2z2V J31Q== 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=b5y4dR7pqaUrtB65kZ7JF9/dDKoxFFqiSg9M6Oebu7I=; b=ee2nZML2gTMJzs7iYntC0ltCCVf3Pl4eCleqREcC5Jhp0o1kAoB7KnMfqUZMS+tjR2 roArTKIM3P0f+lByslLu33RR6N23pl5CB4lsfSUG0DE97xXe9uJGrzxVc4pV6OSHo/Us fnKtSNQhUOYLdI/Tqd0jxhTMZg4tEE5TUg695boLaEWJI0BA74gOBbBIotq2Ir5keewr ovJXv7P3k/iIROfBE/8E3y1VJf8GOKJaXK3DbZSYrxZfXzn0BrffJkLI9Yw5rtCYYJE6 P00Px4RTc8nE3nRGcCAJU/UbpKd4Bxn+NxOi3gD6cDIPTRCVWgwsEAlpUFZPAJ3gONrU U7vQ== X-Gm-Message-State: AOAM531Lkj6eEFAh46bNKXLNpihgeGcpfmEv4p94z/8Fp9pN/SQjZ73g yTjY78Whp8147F1BGtwqZeBoSN4yIyc= X-Google-Smtp-Source: ABdhPJw142aMGo7mWdEwXJ1Wt99zQstwy4KgfrU+NETr2XaAZY146DxiXXb6S7alLWRWiuRi4BIV3w== X-Received: by 2002:adf:b7cd:: with SMTP id t13mr5873846wre.63.1631129089505; Wed, 08 Sep 2021 12:24:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i27sm2844393wmb.40.2021.09.08.12.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:34 +0000 Subject: [PATCH v3 04/15] scalar: 'register' sets recommended config and starts maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 | 255 ++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 18 ++- 2 files changed, 272 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7cff29e0fcd..0e627bb100e 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -5,11 +5,266 @@ #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/.git"); + if (is_git_directory(path.buf)) { + strbuf_strip_suffix(&path, "/.git"); + + 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 */ + strbuf_addstr(&path, "/.git"); + if (is_git_directory(path.buf)) { + strbuf_setlen(&path, len); + + 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; + } + + strbuf_setlen(&path, len); + } while (strbuf_parent_directory(&path)); + + if (!enlistment_found) + die(_("could not find enlistment root")); + + if (chdir(path.buf) < 0) + die_errno(_("could not switch to '%s'"), path.buf); + + strbuf_release(&path); + setup_git_directory(); +} + +static int run_git(const char *arg, ...) +{ + struct strvec argv = STRVEC_INIT; + va_list args; + const char *p; + int res; + + va_start(args, arg); + strvec_push(&argv, arg); + while ((p = va_arg(args, const char *))) + strvec_push(&argv, p); + va_end(args); + + res = run_command_v_opt(argv.v, RUN_GIT_CMD); + + strvec_clear(&argv); + return res; +} + +static int set_recommended_config(void) +{ + struct { + const char *key; + const char *value; + } config[] = { + { "am.keepCR", "true" }, + { "core.FSCache", "true" }, + { "core.multiPackIndex", "true" }, + { "core.preloadIndex", "true" }, +#ifndef WIN32 + { "core.untrackedCache", "true" }, +#else + /* + * Unfortunately, Scalar's Functional Tests demonstrated + * that the untracked cache feature is unreliable on Windows + * (which is a bummer because that platform would benefit the + * most from it). For some reason, freshly created files seem + * not to update the directory's `lastModified` time + * immediately, but the untracked cache would need to rely on + * that. + * + * Therefore, with a sad heart, we disable this very useful + * feature on Windows. + */ + { "core.untrackedCache", "false" }, +#endif + { "core.logAllRefUpdates", "true" }, + { "credential.https://dev.azure.com.useHttpPath", "true" }, + { "credential.validate", "false" }, /* GCM4W-only */ + { "gc.auto", "0" }, + { "gui.GCWarning", "false" }, + { "index.threads", "true" }, + { "index.version", "4" }, + { "merge.stat", "false" }, + { "merge.renames", "false" }, + { "pack.useBitmaps", "false" }, + { "pack.useSparse", "true" }, + { "receive.autoGC", "false" }, + { "reset.quiet", "true" }, + { "feature.manyFiles", "false" }, + { "feature.experimental", "false" }, + { "fetch.unpackLimit", "1" }, + { "fetch.writeCommitGraph", "false" }, +#ifdef WIN32 + { "http.sslBackend", "schannel" }, +#endif + { "status.aheadBehind", "false" }, + { "commitGraph.generationVersion", "1" }, + { "core.autoCRLF", "false" }, + { "core.safeCRLF", "false" }, + { NULL, NULL }, + }; + int i; + char *value; + + for (i = 0; config[i].key; i++) { + if (git_config_get_string(config[i].key, &value)) { + trace2_data_string("scalar", the_repository, config[i].key, "created"); + if (git_config_set_gently(config[i].key, + config[i].value) < 0) + return error(_("could not configure %s=%s"), + config[i].key, config[i].value); + } else { + trace2_data_string("scalar", the_repository, config[i].key, "exists"); + free(value); + } + } + + /* + * The `log.excludeDecoration` setting is special because it allows + * for multiple values. + */ + if (git_config_get_string("log.excludeDecoration", &value)) { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "created"); + if (git_config_set_multivar_gently("log.excludeDecoration", + "refs/prefetch/*", + CONFIG_REGEX_NONE, 0)) + return error(_("could not configure " + "log.excludeDecoration")); + } else { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "exists"); + free(value); + } + + return 0; +} + +static int start_maintenance(void) +{ + return run_git("maintenance", "start", NULL); +} + +static int add_enlistment(void) +{ + int res; + + if (!the_repository->worktree) + die(_("Scalar enlistments require a worktree")); + + res = run_git("config", "--global", "--get", "--fixed-value", + "scalar.repo", the_repository->worktree, NULL); + + /* + * If the setting is already there, then do nothing. + */ + if (!res) + return 0; + + return run_git("config", "--global", "--add", + "scalar.repo", the_repository->worktree, NULL); +} + +static int register_dir(void) +{ + int res = add_enlistment(); + + if (!res) + res = set_recommended_config(); + + if (!res) + res = start_maintenance(); + + return res; +} + +static int cmd_register(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar register []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return register_dir(); +} static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "register", cmd_register }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 5f7131861a5..568987064b2 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar [] +scalar register [] DESCRIPTION ----------- @@ -29,6 +29,22 @@ will be identical to the worktree. The `scalar` command implements various subcommands, and different options depending on the subcommand. +COMMANDS +-------- + +Register +~~~~~~~~ + +register []:: + Adds the enlistment's repository to the list of registered repositories + and starts background maintenance. If `` is not provided, + then the enlistment associated with the current working directory is + registered. ++ +Note: when this subcommand is called in a worktree that is called `src/`, its +parent directory is considered to be the Scalar enlistment. If the worktree is +_not_ called `src/`, it itself will be considered to be the Scalar enlistment. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Wed Sep 8 19:24:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12481761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35DF4C433F5 for ; Wed, 8 Sep 2021 19:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1488061104 for ; Wed, 8 Sep 2021 19:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350984AbhIHT0G (ORCPT ); Wed, 8 Sep 2021 15:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350585AbhIHTZ7 (ORCPT ); Wed, 8 Sep 2021 15:25:59 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87B51C06175F for ; Wed, 8 Sep 2021 12:24:51 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j17-20020a05600c1c1100b002e754875260so2340228wms.4 for ; Wed, 08 Sep 2021 12:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IkkeDf4dwAribAhlx2PhCXXfAwpmH50TJZppSlNsCLU=; b=bc16jrevq+1mSSKh2XSJYG3iuuRWRCdWnkIbC4MsYqTxgtbqJLxri4TgkERNpwsGt1 3bOQjdE+mLJPnH+5geXb8iQ2e79RULmW3DiO0Hk5CgS8FzBhCZt93eA20bUB0DPeNkXk AeF+JpvLPdQh/b/gEKI3staHz/AcNGy8fnRZ6mcGXCU1HGxWhRtW81ZbrSTnhS7S0nGm GAzbrcMyNB9lY5zfuN+oA01643Bjwe3nSNTC5+Q8IATHN2NM6YmhTgPA412/wwz7lRPx Yo7oRnZOObjFE394ORAmmBLvb7fSBwAszqGgZA66WK4UplFcUy8h8ZSYyyL8joFe8QLA RWdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IkkeDf4dwAribAhlx2PhCXXfAwpmH50TJZppSlNsCLU=; b=udkEmtxhX2c+jJwbyvFeSg3NRK1aQI7xONieNZYRwjLynDV719/lZTlVxvrX1LqZ3k 614klRbywrrGNQ8XGcELd5AsT8AFN+PCmc0v5+vcJQnqluM7FGzyJwzl8F7Q5egUwevf r+fTrU3FQRGxUtrX8GMDb3JBKBrk2OP/bpDChmrFaUHk72e9BkR1vHJudYDv/Ih1YJiN wWMS9WK6dSk18rfnNXT9ofkaeRoFkYFbDz/J3XGC1QJoh121tUerX+qFM1fb5XxCwaTv pAJCfhsZPKV8sStWy+aJ+q6jqbraVbZAbsYToF9qEa7UP6dTzNj/4eUBsfAfDdN7WFpb wu3w== X-Gm-Message-State: AOAM531rIaV+kwSzpzmvOYuIhhaaF8tnP38Q5xnUutUL5rxvw3UhUwRN PTGe56GZLbaZ1Wl1WS1Jmk3OjRHaNyM= X-Google-Smtp-Source: ABdhPJzS66ZkpaQ8j2Qq7KI7pmPWLwZBlYZ8rWq3Zv4xst48FBfEAYDNjunHvLUyTIQYZXtT3oaBVw== X-Received: by 2002:a1c:f606:: with SMTP id w6mr5173480wmc.42.1631129090197; Wed, 08 Sep 2021 12:24:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g11sm22512wrx.30.2021.09.08.12.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:49 -0700 (PDT) Message-Id: <6142f75875b8245c93230e141be3664253e2137b.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:35 +0000 Subject: [PATCH v3 05/15] scalar: 'unregister' stops background maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 0e627bb100e..2b5c52a25f5 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -204,12 +204,12 @@ static int set_recommended_config(void) return 0; } -static int start_maintenance(void) +static int toggle_maintenance(int enable) { - return run_git("maintenance", "start", NULL); + return run_git("maintenance", enable ? "start" : "unregister", NULL); } -static int add_enlistment(void) +static int add_or_remove_enlistment(int add) { int res; @@ -220,24 +220,39 @@ static int add_enlistment(void) "scalar.repo", the_repository->worktree, NULL); /* - * If the setting is already there, then do nothing. + * If we want to add and the setting is already there, then do nothing. + * If we want to remove and the setting is not there, then do nothing. */ - if (!res) + if ((add && !res) || (!add && res)) return 0; - return run_git("config", "--global", "--add", + return run_git("config", "--global", add ? "--add" : "--unset", + add ? "--no-fixed-value" : "--fixed-value", "scalar.repo", the_repository->worktree, NULL); } static int register_dir(void) { - int res = add_enlistment(); + int res = add_or_remove_enlistment(1); if (!res) res = set_recommended_config(); if (!res) - res = start_maintenance(); + res = toggle_maintenance(1); + + return res; +} + +static int unregister_dir(void) +{ + int res = 0; + + if (toggle_maintenance(0) < 0) + res = -1; + + if (add_or_remove_enlistment(0) < 0) + res = -1; return res; } @@ -260,11 +275,30 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_unregister(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar unregister []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return unregister_dir(); +} + static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { { "register", cmd_register }, + { "unregister", cmd_unregister }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 568987064b2..d9a79984492 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] scalar register [] +scalar unregister [] DESCRIPTION ----------- @@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +Unregister +~~~~~~~~~~ + +unregister []:: + Remove the specified repository from the list of repositories + registered with Scalar and stop the scheduled background maintenance. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Wed Sep 8 19:24:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 660A2C433EF for ; Wed, 8 Sep 2021 19:25:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DD6E610F8 for ; Wed, 8 Sep 2021 19:25:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351979AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350638AbhIHT0B (ORCPT ); Wed, 8 Sep 2021 15:26:01 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1655EC0613D9 for ; Wed, 8 Sep 2021 12:24:52 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id q11so4849349wrr.9 for ; Wed, 08 Sep 2021 12:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8FE3y0fGxiycG0w1Lwj4WjBo2HVuo6K0aDkta9kvYZ8=; b=gGr21GH8UWfThEiwUSMuewfBZhHx/rehGClI6nveRa3CniWuS7JfWqsemqWBNLECnF IXQg08dv60ZomYOIkcRLwIJpF4BLq0wr5zqw9Onr0nMjBmD0llLq+e5jD/59qQ67wzcx p2rVi4LE3K8vgDHVbAAjQWkZX9gg5n5Yg3RIooaG5PEq8108bwDQnuCYrywFIhiQ/1gg LWWSQeVd951BVue5+b5WjKNdQphd6MrZUYy5YNx3E/xZemt8SE3vHY7CoIh3x8nYC6Iu KUBzOspnoU3LqGizjJxBDVIZ5K4S6hC6QvF2ViRsjMGVpNFsmkXyuw+YuoCpLzWMgCMa 8xDA== 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=8FE3y0fGxiycG0w1Lwj4WjBo2HVuo6K0aDkta9kvYZ8=; b=fbphgWw2IlR0FK+dFUyDg3p/9An7Sen32D3DQf7KCMJ7fAJg+5V+jgeNxdRvXWlDfc cs88fczTbIOo6K3q7H3VfuX4zZv5veUViU8XME8cHW9KxuIsan66eO3i21y6ExgnZqLQ h3LZNaRY2z3LoMz+iixUKiDhz9Y4AidgXnHtkRaQ9eG/Y4fpfoI1okgBTEpcQHJJP+pf 304ArLWFymfmSqJnugLTWbH6ONl12mETQwAiDZ0sNiOXOw93LdgoI0HXel5oBr/2J2Uz qd5FtFsphoSDEB9lZjwlu8IoNrYfNXdQLdPtGBbeJ0dcmSBT62eQ4Hc6mUBmRV27Yya0 hsBw== X-Gm-Message-State: AOAM532Otag79fapJIMJOy2slUtuDUNdOBn9qGzG8scyu2oeegmG3oWQ 63xOaCPHBWwnsRksJCtaejDmON5rTlE= X-Google-Smtp-Source: ABdhPJx40ThqMQlbiyYUu4aP7J3pFpAeYIVhPWdpyBvn084O+TkZMOVgi+2uu5heH2RKcPxUKul/Jw== X-Received: by 2002:a05:6000:1627:: with SMTP id v7mr5653233wrb.195.1631129090770; Wed, 08 Sep 2021 12:24:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k1sm11327wrz.61.2021.09.08.12.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:50 -0700 (PDT) Message-Id: <82dd253154fb8dabd6f344df2196d8e6261d09a5.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:36 +0000 Subject: [PATCH v3 06/15] scalar: let 'unregister' handle a deleted enlistment directory gracefully Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 2b5c52a25f5..d114c038b64 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -275,6 +275,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[] = { @@ -288,6 +306,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 Sep 8 19:24:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12481765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9046C433FE for ; Wed, 8 Sep 2021 19:25:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9374561131 for ; Wed, 8 Sep 2021 19:25:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350958AbhIHT0M (ORCPT ); Wed, 8 Sep 2021 15:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350769AbhIHT0C (ORCPT ); Wed, 8 Sep 2021 15:26:02 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF2F1C06179A for ; Wed, 8 Sep 2021 12:24:52 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id e26so2562367wmk.2 for ; Wed, 08 Sep 2021 12:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=oKygtjLAStTyInzHGfikqfjJckUMFyUKn7JkaG2HLdo=; b=k/0ptA3hK2B4z9QCDDfQsP6iBNpfIph1pYfYjeKn3SqY43kWCgtJ/4Rq2XkGi52A1E 5kzEDImoVo5Q/eHMlDKPfSNZNYzPTtQFzUjpxQs4Ek51wOus3OTP0yf/81R76Te54nG+ ZPy47DAxQ2V1uCVa2Vr6OCWHT14+LqwuA1/lfH3VSnwDxA9AWA75aN+A8p2cOjGohcu+ IODO+4DrxnrrCDtDgoSV5FoblK8K76qmDAl/R/6zqw+5A8d7KSyTbZVDPE3Y+Df/Vlq9 3lqRy3AMu7HL6K9yXV/nHLG99RrqvEb43LqtIxTwYlTtc4dbjouteZuh+QiAPs22dRdJ ZTaw== 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=oKygtjLAStTyInzHGfikqfjJckUMFyUKn7JkaG2HLdo=; b=UsEkoVIeCN1t+koTYa3dWluPOSDPAq6F1TlPxTJLIzzd5URiGkpvx++N+OlmZcDyvh vRHQxfdhrRRpoGOhtbyrpW8uU/OeQnhX5CfRrI4pjTmgrEA15eIiDKtKgRrx7F0MeEYM BaIzr0XI61Tv2gnFPFYqKBzyUBKxFn0Iz4NyEy3LPd3qDZ+KOpkdyuEmzGbbp5oQZ2Cw u7ml2c3HrzXWEi1HGfXBgPJfTMR3YI2GCnp0KV3QJ08kFfc+kRMpPnwCHLP5lFHuiHE6 mSYIuDi8F7NdSfehOSr/KAdiEzbip02mpdAGm4YYjkilH/08Qe5hQm3P9XFqB0dHQEMP 67GA== X-Gm-Message-State: AOAM531FNnRvUSE52c2T/OMXCRUCbLujm7mCjHfBxZP/LOlyWBCB1wdu 0JePjLPMTB6Pc3sD1fyq1+UBo2cfeeU= X-Google-Smtp-Source: ABdhPJzAKsdSYF70+hi/cuOjBoEkz2+4Rh/LhwZ+Mt8kfqWEeJphdnqTz8luCFJt0Jqa8wNKa3UJTA== X-Received: by 2002:a1c:cc05:: with SMTP id h5mr5117672wmb.5.1631129091401; Wed, 08 Sep 2021 12:24:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h8sm2827848wmb.35.2021.09.08.12.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:37 +0000 Subject: [PATCH v3 07/15] scalar: implement 'scalar list' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 d114c038b64..7f5436399da 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -257,6 +257,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[] = { @@ -343,6 +353,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 Sep 8 19:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DCA9C433EF for ; Wed, 8 Sep 2021 19:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EB5E61104 for ; Wed, 8 Sep 2021 19:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350993AbhIHT0O (ORCPT ); Wed, 8 Sep 2021 15:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350948AbhIHT0C (ORCPT ); Wed, 8 Sep 2021 15:26:02 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80648C0613A3 for ; Wed, 8 Sep 2021 12:24:53 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id u9so4846400wrg.8 for ; Wed, 08 Sep 2021 12:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=K16jTI8Yh16y6rC9+wJIFixYjlxIRA+dOy7nzbFIvWs=; b=TYixtAETN69emTc3KvG7FtgSZCFaOKy8YcU6nNj+AWCeQIpv20G58dN9pM1L5f/Xdm SUAbsr5iLuHHUSaHHEku+X/cO75ZMooo0jmdkxB+8oxzaYcelObfYxzEEQct47gCqFYx XpiAcCUd7RbqSx4fAUp3r1XFw7nYMK3VUW1QHHJheHwvzNQNZd7aA0PoywHfAD5Yhu8p yWYl/pq7SVDSGqG7B4k9RO+JuP1TXM4q9CiBc9nz5CG8mP+hmo6WjnmpO7XyNvbeUsGI 9g/BGwHDbHu6JFHv0q7edWZVUyEH22sBe+WBRvjzLaW76Nuxur2h5UyvllQHvhvCInGK LdVw== 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=K16jTI8Yh16y6rC9+wJIFixYjlxIRA+dOy7nzbFIvWs=; b=iB2/1cKk3S+w2+FT7qZGko17/CqmifF+5L/f4o/SauQLuWQUC6cFt5ZsVod4Hd6J8H bWkRGsQpE9Wm+CBsWCjbAl73PM+plmjZNxCKnlG0zTtonvKiyZiR70z0ZnGXsI6PgFNT opfl9H2SKtm2YnoMiLJ69LLGtPnhYORNzilSNvnLfKjEGBdtI+I/f+U5xa5rHWAUirez T293EWLILH3xIAflic/UMiMP7/TmZU0tkB9GrpEH1CO+Zr/u/I0bEMux9tIxQcr/8/8q J6zqhTFLT5uavX9f5L8kL41k+wNdqqn7aU4/n4QhQhbYBaiigwxGEK4NZ4B1sa3mio5w Fl2g== X-Gm-Message-State: AOAM530C0i8zw/hBCtbKo46Bzeb1T2KMDjaFkb7xsw7RiltRI0dOMe76 nPE03k29cppYhzQ7HUZdyP5ySvOxkkk= X-Google-Smtp-Source: ABdhPJy1NGXkgSgJ1w4sPd3a6c7UpbnCcFnB7nQza44hF3BV3b5Tk7UEVMZ7lpPk0w1KShhSrkPRLA== X-Received: by 2002:adf:fac7:: with SMTP id a7mr5792881wrs.341.1631129092139; Wed, 08 Sep 2021 12:24:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i11sm21322wrb.48.2021.09.08.12.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:51 -0700 (PDT) Message-Id: <40dbf61771ece7b798c16560aeef7fa0fcee4ad2.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:38 +0000 Subject: [PATCH v3 08/15] scalar: implement the `clone` subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This implements Scalar's opinionated `clone` command: it tries to use a partial clone and sets up a sparse checkout by default. In contrast to `git clone`, `scalar clone` sets up the worktree in the `src/` subdirectory, to encourage a separation between the source files and the build output (which helps Git tremendously because it avoids untracked files that have to be specifically ignored when refreshing the index). Also, it registers the repository for regular, scheduled maintenance, and configures a flurry of configuration settings based on the experience and experiments of the Microsoft Windows and the Microsoft Office development teams. Note: since the `scalar clone` command is by far the most commonly called `scalar` subcommand, we document it at the top of the manual page. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 201 +++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 31 ++++- contrib/scalar/t/t9099-scalar.sh | 32 +++++ 3 files changed, 261 insertions(+), 3 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7f5436399da..bf18003b297 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 @@ -257,6 +258,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) @@ -353,6 +553,7 @@ static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "clone", cmd_clone }, { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f93e3d00efd..d65fb5f1491 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,6 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] +scalar clone [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -29,12 +30,36 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `list`, all subcommands -expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone` and `list`, all +subcommands expect to be run in an enlistment. COMMANDS -------- +Clone +~~~~~ + +clone [] []:: + Clones the specified repository, similar to linkgit:git-clone[1]. By + default, only commit and tree objects are cloned. Once finished, the + worktree is located at `/src`. ++ +The sparse-checkout feature is enabled (except when run with `--full-clone`) +and the only files present are those in the top-level directory. Use +`git sparse-checkout set` to expand the set of directories you want to see, +or `git sparse-checkout disable` to expand to all files (see +linkgit:git-sparse-checkout[1] for more details). You can explore the +subdirectories outside your sparse-checkout by using `git ls-tree HEAD`. + +-b :: +--branch :: + Instead of checking out the branch pointed to by the cloned + repository's HEAD, check out the `` branch instead. + +--[no-]full-clone:: + A sparse-checkout is initialized by default. This behavior can be + turned off via `--full-clone`. + List ~~~~ @@ -64,7 +89,7 @@ unregister []:: SEE ALSO -------- -linkgit:git-maintenance[1]. +linkgit:git-clone[1], linkgit:git-maintenance[1]. Scalar --- diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index ef0e8d680d5..295398f62cc 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -10,6 +10,9 @@ PATH=$PWD/..:$PATH . ../../../t/test-lib.sh +GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt" +export GIT_TEST_MAINT_SCHEDULER + test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' @@ -29,4 +32,33 @@ test_expect_success 'scalar unregister' ' ! grep -F "$(pwd)/vanish/src" scalar.repos ' +test_expect_success 'set up repository to clone' ' + test_commit first && + test_commit second && + test_commit third && + git switch -c parallel first && + mkdir -p 1/2 && + test_commit 1/2/3 && + git config uploadPack.allowFilter true && + git config uploadPack.allowAnySHA1InWant true +' + +test_expect_success 'scalar clone' ' + second=$(git rev-parse --verify second:second.t) && + scalar clone "file://$(pwd)" cloned && + ( + cd cloned/src && + + git config --get --global --fixed-value maintenance.repo \ + "$(pwd)" && + + test_path_is_missing 1/2 && + test_must_fail git rev-list --missing=print $second && + git rev-list $second && + git cat-file blob $second >actual && + echo "second" >expect && + test_cmp expect actual + ) +' + test_done From patchwork Wed Sep 8 19:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DC2AC433F5 for ; Wed, 8 Sep 2021 19:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8849D61104 for ; Wed, 8 Sep 2021 19:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351008AbhIHT0Q (ORCPT ); Wed, 8 Sep 2021 15:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350963AbhIHT0D (ORCPT ); Wed, 8 Sep 2021 15:26:03 -0400 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 353B9C061575 for ; Wed, 8 Sep 2021 12:24:54 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id n14-20020a05600c3b8e00b002f8bd2f8ab6so2421756wms.5 for ; Wed, 08 Sep 2021 12:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6iE+bMIqkngcQSCxet0E12DWukuDqNQkL7dWIME6eT0=; b=nA/6BE7zqbO55p2zFQ495M/IkAi/AREzUCEYy8xX/zYdXt3cjuc4A0lfBT5NMaLAVc 2PNVfnxtTBpNBWfjMwZlFTelKN+7+t65kRb0vtxervn4n1lo8IG29iOgn/DBNhRCHqGV 8un0Sg/ISe5c75UYhWRma5zKfQhKnX+KhtBVxrK8wXWdbhIREjJZDSXHhl9zdYUBnpMq sY3VZXVveEi8iVkdC9GpDNojQbUtM4cA6jfsETd6119uN6a1FdD95HvVpkSWSNHxUCpl crc6uOvF+h6EtmwSa40o/04Dp+oV8Ovy4n8rhcTDAKeYsW8OKil20PWucpH3EB6kN4bu 0NJw== 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=6iE+bMIqkngcQSCxet0E12DWukuDqNQkL7dWIME6eT0=; b=WqA9F9p/L1pSjnIISlHGcjvKu476qzuv45j65r8g3Bhi6aUD29xGtM9PMsFkONDcCw DDlRfuTCtQIobUGklfoWa1qIuYuOSqsjWdUkEUDVlAd/DgwNjE31TeRttgoIpes9Keh+ F0TfVbHd/SCKaLYbjL/TW64zXtCO3clkSp0vW0mp8JwIhpXkmyJVOyi6SXEepVwSlPSH MEgP22Rx9fbjFWOXs0pvlhLqNnOQXhk4c0arIfSFWpQUwey2NKL2u2fVQfDxLWK95zcF wgiMscgaAGkPGy0ZypM1UQYC8VmEL3H5SGtNf6XWNy9DOjws5QaA5TXBbjkwUhQZK7ir hIug== X-Gm-Message-State: AOAM531mhxPHiKDwStmWw58fYb8pUliDp7dZMvK7z5Lt2mJajw3rXruK 8s2N3UOi+5OKjvsjBO3QizKeJvn0f+c= X-Google-Smtp-Source: ABdhPJyfZ0TjgKwnJf+5KEkHWIzRJa9vjg7osa38yxeEfy4AvnBJ/GXh6CxZZypIISNBKIg13iGqKw== X-Received: by 2002:a05:600c:4786:: with SMTP id k6mr5015435wmo.177.1631129092791; Wed, 08 Sep 2021 12:24:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h15sm31936wrc.19.2021.09.08.12.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:52 -0700 (PDT) Message-Id: <414dbe7d859a39c14063b69d672837e7c99c410e.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:39 +0000 Subject: [PATCH v3 09/15] scalar: teach 'clone' to support the --single-branch option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 bf18003b297..7dd1f28948f 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -333,12 +333,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[] = { @@ -409,7 +412,9 @@ static int cmd_clone(int argc, const char **argv) if (set_config("remote.origin.url=%s", url) || set_config("remote.origin.fetch=" - "+refs/heads/*:refs/remotes/origin/*") || + "+refs/heads/%s:refs/remotes/origin/%s", + single_branch ? branch : "*", + single_branch ? branch : "*") || set_config("remote.origin.promisor=true") || set_config("remote.origin.partialCloneFilter=blob:none")) { res = error(_("could not configure remote in '%s'"), dir); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index d65fb5f1491..46999cf7c84 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar clone [--branch ] [--full-clone] [] +scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -56,6 +56,16 @@ subdirectories outside your sparse-checkout by using `git ls-tree HEAD`. Instead of checking out the branch pointed to by the cloned repository's HEAD, check out the `` branch instead. +--[no-]single-branch:: + Clone only the history leading to the tip of a single branch, either + specified by the `--branch` option or the primary branch remote's + `HEAD` points at. ++ +Further fetches into the resulting repository will only update the +remote-tracking branch for the branch this option was used for the initial +cloning. If the HEAD at the remote did not point at any branch when +`--single-branch` clone was made, no remote-tracking branch is created. + --[no-]full-clone:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 295398f62cc..9a35ab4fde6 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -45,13 +45,17 @@ test_expect_success 'set up repository to clone' ' test_expect_success 'scalar clone' ' second=$(git rev-parse --verify second:second.t) && - scalar clone "file://$(pwd)" cloned && + scalar clone "file://$(pwd)" cloned --single-branch && ( cd cloned/src && git config --get --global --fixed-value maintenance.repo \ "$(pwd)" && + git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual && + echo "refs/remotes/origin/parallel" >expect && + test_cmp expect actual && + test_path_is_missing 1/2 && test_must_fail git rev-list --missing=print $second && git rev-list $second && From patchwork Wed Sep 8 19:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12481771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F03C4332F for ; Wed, 8 Sep 2021 19:25:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 478E0610FF for ; Wed, 8 Sep 2021 19:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351028AbhIHT0R (ORCPT ); Wed, 8 Sep 2021 15:26:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351329AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1CC1C06129E for ; Wed, 8 Sep 2021 12:24:54 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id m9so4888008wrb.1 for ; Wed, 08 Sep 2021 12:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ySiVVFtUbc/3RO5iQimxg9/Yh69Yg4UMoTm1ZkYtGEc=; b=As99HXk74tvTjzabM9mrdkYNMuyMW9sjJjUqhS8ykT+rFh1EmNfCnWhHy3bJTQfRv+ zmjPBKfywq/G1GHfEteMY1Vy1xmBhDO9y1FolIGBUExkNaw8LUutVZUc+9Vv+QR0wiNx /GCXE63Fhp4a6vx/+412lOsJ5lCcronm8aa33aw/ms2oHWOHDJDn6ValDLUfusPiafWt NwUWlz/co2Txe/MVpS9IiJujn6L7wXeorUXSDNZH3lgdhNftgyvwDdBDHwN/bPHpVfxJ Ux/p2KwUm8R5+i3Njo6rXF4jFoU+J88IuwWeI40aIQ76PUEpku7eEg1YxYs4U4RaEwyW 0acg== 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=ySiVVFtUbc/3RO5iQimxg9/Yh69Yg4UMoTm1ZkYtGEc=; b=nmPts6iDzGsrBA4ybL1eyqQjsIKLQMyc5Y7WoPWGB08RqJQTeiEvg9R3cLVvvLGcpG Ve3lbbbosAHNZ7RGcS6moeeYSXb0e3yFhO6wAZqj1llMy+7PNNDBfuW4ZMDS49loOYiL 1M0LfzgdpaNGq2PRj52oynCJV24kJkNKzf2E9Yu6Ny7MbuwYSwlncuXc+BIqFbXbH0G2 wIX5DO4l5ffFVU0PSm3ZUWbgOfE/hSa+YtBFk3APXE0+1nkM4PoGW3FL1bWTozGBNWs+ Q6388kOmTv1nUwCCExOMiDQ4JhVd7uqLdZy8ScGaXvpObVPTVzllJumMSEti8BhWJLHy Altg== X-Gm-Message-State: AOAM530AgeLqNAukdZSmuVAQV+YErh3r4EbU84jT/uKZXnfqOCFCCwXR YuB17R6jdKxvc9HyNEMDMtWM3N+IXIM= X-Google-Smtp-Source: ABdhPJzHkAK6DTBuexZn4mks2MrWeXVIF1jH6E31OlMNWLwyjLvwa3smVfl8KqOGU3wKB7OX/P/HjQ== X-Received: by 2002:adf:d0cf:: with SMTP id z15mr5910933wrh.356.1631129093341; Wed, 08 Sep 2021 12:24:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z5sm2967824wmf.33.2021.09.08.12.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:53 -0700 (PDT) Message-Id: <76de416a64352fc565893d344b41fe7440c59142.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:40 +0000 Subject: [PATCH v3 10/15] scalar: implement the `run` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 7dd1f28948f..8a11f390251 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -490,6 +490,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; @@ -562,6 +625,7 @@ static struct { { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, + { "run", cmd_run }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 46999cf7c84..f139a14445d 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -12,6 +12,7 @@ scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar unregister [] +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] DESCRIPTION ----------- @@ -97,6 +98,24 @@ unregister []:: Remove the specified repository from the list of repositories registered with Scalar and stop the scheduled background maintenance. +Run +~~~ + +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) []:: + Run the given maintenance task (or all tasks, if `all` was specified). + Except for `all` and `config`, this subcommand simply hands off to + linkgit:git-maintenance[1] (mapping `fetch` to `prefetch` and + `pack-files` to `incremental-repack`). ++ +These tasks are run automatically as part of the scheduled maintenance, +as soon as the repository is registered with Scalar. It should therefore +not be necessary to run this subcommand manually. ++ +The `config` task is specific to Scalar and configures all those +opinionated default settings that make Git work more efficiently with +large repositories. As this task is run as part of `scalar clone` +automatically, explicit invocations of this task are rarely needed. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. From patchwork Wed Sep 8 19:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC370C433EF for ; Wed, 8 Sep 2021 19:25:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6C0861104 for ; Wed, 8 Sep 2021 19:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351396AbhIHT0V (ORCPT ); Wed, 8 Sep 2021 15:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351338AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72251C06175F for ; Wed, 8 Sep 2021 12:24:55 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u9so4846491wrg.8 for ; Wed, 08 Sep 2021 12:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7umOn+lbKwQBhvrSkuyvzsamrsCLKijBkTg3WVv+4Q8=; b=LqwtNJ+Kbdh15+VM1IfOsurmR6luyMM/CdDiEet1XrSCGOqYNssqUGGnev65jvUVCL 9KyoVLc+O5TIGbF3KXizkfaKDixw1mw2WtsxiunggsmPGdawSBMf+Z9ocnBwZR/P5veD E/1P4i7IpxqgP+Bjevq+91ysYniUAKZAPuimFq4+G9YTrq0A2A4wMe0KBR75TYvuG4OO otos96ezJFnLYsxYH5J93+/aZfQIzSAwl/IC4fNnNILIJTESr7aPlqdp+rVvz6W7wbFs 4cftNW/Hei7dUvsriwWxXZyeUkJq10fU8Jko8qFnhS603PtKJxacX5sany3s4tGsaf/7 m6JA== 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=7umOn+lbKwQBhvrSkuyvzsamrsCLKijBkTg3WVv+4Q8=; b=5YqphyQ5CD8pzBUNKMWeB4Ue2kfgKkSBLLhbBgS7aD6L1GCe/Gdzjw3IXLwEh088Ho +8bcIi1e0k7cvrvoxcyUpPEIpnNqbtOjbPzKGGBB82QiAQoFMI9ZNOSyOrN8jMnMow34 YqakufeSj4yJy0VUgJLR5eDtrsDoWWQI0kITM9uAjcROm+1TYS+p603jycShDFENUM9b HtGrk5F+Rlf7Ev62xTVdM59bA/eRCGFwvTHvmiClrG+rnEgEH9XQ60qPHQ9KkGHaiqje GPatDU/vWQGBsb8WCQXt9/NW+UzpDmMS31UJKCODtvWN/VepYooo4TtXIEmal/xnCXoA Iu5Q== X-Gm-Message-State: AOAM533aUhf6GURHpQKdrno5h3tG9d8V9FcqX4RL+tdg46wrfAT2MYEK rVdTpC/IZmF3eMKnzertyude6uJTOfE= X-Google-Smtp-Source: ABdhPJwsqeAtq44zfzqOFwcs6r+D7DZmLK3vKDsbVmLH/gqtxmbaiCVd9PYzi3cl7kFSpEMY4Nyr6A== X-Received: by 2002:adf:90cc:: with SMTP id i70mr5786576wri.408.1631129093993; Wed, 08 Sep 2021 12:24:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u25sm2903947wmj.10.2021.09.08.12.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:53 -0700 (PDT) Message-Id: <655a902b9dfc66017bbd6a686158108a56926904.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:41 +0000 Subject: [PATCH v3 11/15] scalar: allow reconfiguring an existing enlistment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 8a11f390251..1fff7eb7c12 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -115,18 +115,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 @@ -140,28 +142,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" }, @@ -172,7 +175,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) @@ -237,7 +241,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); @@ -425,7 +429,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))) { @@ -490,6 +494,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[] = { @@ -626,6 +648,7 @@ static struct { { "register", cmd_register }, { "unregister", cmd_unregister }, { "run", cmd_run }, + { "reconfigure", cmd_reconfigure }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f139a14445d..f4e4686e8c8 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,6 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] +scalar reconfigure DESCRIPTION ----------- @@ -116,6 +117,13 @@ opinionated default settings that make Git work more efficiently with large repositories. As this task is run as part of `scalar clone` automatically, explicit invocations of this task are rarely needed. +Reconfigure +~~~~~~~~~~~ + +After a Scalar upgrade, or when the configuration of a Scalar enlistment +was somehow corrupted or changed by mistake, this subcommand allows to +reconfigure the enlistment. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 9a35ab4fde6..e6d74a06ca0 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -65,4 +65,12 @@ test_expect_success 'scalar clone' ' ) ' +test_expect_success 'scalar reconfigure' ' + git init one/src && + scalar register one && + git -C one/src config core.preloadIndex false && + scalar reconfigure one && + test true = "$(git -C one/src config core.preloadIndex)" +' + test_done From patchwork Wed Sep 8 19:24:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF9D4C433FE for ; Wed, 8 Sep 2021 19:25:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B82761154 for ; Wed, 8 Sep 2021 19:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351617AbhIHT0W (ORCPT ); Wed, 8 Sep 2021 15:26:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351927AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 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 EDA09C0612A5 for ; Wed, 8 Sep 2021 12:24:55 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id n7-20020a05600c3b8700b002f8ca941d89so2340061wms.2 for ; Wed, 08 Sep 2021 12:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=J7uJSeDQcCrUJzr9pKt0D+//b7wikyF2AAgDl56z8es=; b=oSIzmC8qMelC7j2vrJdWeV1J4L4BA1EGpZ/Z/CyECbQaQdthgzLzrNFerwDao9+y9v vs8DZ4M3NsmwU6T/D7D7Mp0P3rqz2BWWag4rWjsGxBqKnvFmRnVKVXrZyBSaeGSNcJUe PZO+VbP9ZrabYC6To0lL0yrcghoB5LvA3vZAloJzpDvYJuyRs5IbCts/BgXfTwIa3goP fwvn6MROg9Jf+ddz9K8SM0b/RnxGlZXyJ9S0gkYNft0TJLrYiJSPjydiqQ7cQfcQB33i j3C9Mze9GU5vQ0HNnQ0dXDffvOVvyXLvxynwfom+ApBptYm9fbY8ORkqB2LNQALG4cSr CRxg== 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=J7uJSeDQcCrUJzr9pKt0D+//b7wikyF2AAgDl56z8es=; b=XTRMWUvEYHEzdEegX4/DNZQS7teoKcrDFKZ1dVFs6iZeRkyW2dlqlY1mhvsfFPXtGY YmI5YDC7QtP1DXnjk8ot/Zbgu3/rJxc6ojQNkEz+cTvd6OFuV1g4/vQN9uni2whr+f5e v86KSx2UWugJjhjd5lKbWgTs8yio8/kL9vHCdk6i0qU2Y/T1hlVzdbWZPMZePD67COke /gMtT/Ji+Nlfncl0v7C6YsiuIByjHIIulI4VbWhPlyShF/lKsnkGxp3dQTCBxDy6BwWN HIACEAg2TofqWGciSq6Oa3TvC4ygV+lhhPWr+Tb/p6kqgyHVqQ21uhjtOHQgGECx80qw IdHg== X-Gm-Message-State: AOAM530svzkfgu9GYVgsPJl/n+6vEImunDj7TvB6ATNfVEqvOthknt/n +4zQSCq8yH5ZM3GoEBLOEdn1GJx8tl0= X-Google-Smtp-Source: ABdhPJzvKES66DE3ezmv+5mZ7THD1+3JdHhzpMD8sWrMAB9uPhy744ZGLiZBpyZus5Dz+mB5oCIu5g== X-Received: by 2002:a7b:c148:: with SMTP id z8mr5097275wmi.147.1631129094560; Wed, 08 Sep 2021 12:24:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d29sm38480wrc.6.2021.09.08.12.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:54 -0700 (PDT) Message-Id: <2d1987bfcda3977bb7822c8158170cd803ebe5f9.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:42 +0000 Subject: [PATCH v3 12/15] scalar: teach 'reconfigure' to optionally handle all registered enlistments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 1fff7eb7c12..67fa5305225 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -494,22 +494,77 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int get_scalar_repos(const char *key, const char *value, void *data) +{ + struct string_list *list = data; + + if (!strcmp(key, "scalar.repo")) + string_list_append(list, value); + + return 0; +} + static int cmd_reconfigure(int argc, const char **argv) { + int all = 0; struct option options[] = { + OPT_BOOL('a', "all", &all, + N_("reconfigure all registered enlistments")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure []"), + N_("scalar reconfigure [--all | ]"), NULL }; + struct string_list scalar_repos = STRING_LIST_INIT_DUP; + int i, res = 0; + struct repository r = { NULL }; + struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT; argc = parse_options(argc, argv, NULL, options, usage, 0); - setup_enlistment_directory(argc, argv, usage, options, NULL); + if (!all) { + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); + } + + if (argc > 0) + usage_msg_opt(_("--all or , but not both"), + usage, options); + + git_config(get_scalar_repos, &scalar_repos); - return set_recommended_config(1); + for (i = 0; i < scalar_repos.nr; i++) { + const char *dir = scalar_repos.items[i].string; + + strbuf_reset(&commondir); + strbuf_reset(&gitdir); + + if (chdir(dir) < 0) { + warning_errno(_("could not switch to '%s'"), dir); + res = -1; + } else if (discover_git_directory(&commondir, &gitdir) < 0) { + warning_errno(_("git repository gone in '%s'"), dir); + res = -1; + } else { + git_config_clear(); + + the_repository = &r; + r.commondir = commondir.buf; + r.gitdir = gitdir.buf; + + if (set_recommended_config(1) < 0) + res = -1; + } + } + + string_list_clear(&scalar_repos, 1); + strbuf_release(&commondir); + strbuf_release(&gitdir); + + return res; } static int cmd_run(int argc, const char **argv) diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f4e4686e8c8..2fa96fcabc6 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,7 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] -scalar reconfigure +scalar reconfigure [ --all | ] DESCRIPTION ----------- @@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `clone` and `list`, all -subcommands expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone`, `list` and +`reconfigure --all`, all subcommands expect to be run in an enlistment. COMMANDS -------- @@ -124,6 +124,9 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment was somehow corrupted or changed by mistake, this subcommand allows to reconfigure the enlistment. +With the `--all` option, all enlistments currently registered with Scalar +will be reconfigured. Use this option after each Scalar upgrade. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index e6d74a06ca0..5fe7fabd0e5 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -70,6 +70,9 @@ test_expect_success 'scalar reconfigure' ' scalar register one && git -C one/src config core.preloadIndex false && scalar reconfigure one && + test true = "$(git -C one/src config core.preloadIndex)" && + git -C one/src config core.preloadIndex false && + scalar reconfigure -a && test true = "$(git -C one/src config core.preloadIndex)" ' From patchwork Wed Sep 8 19:24:43 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: 12481777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EC66C433EF for ; Wed, 8 Sep 2021 19:25:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 578F561104 for ; Wed, 8 Sep 2021 19:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352166AbhIHT0Z (ORCPT ); Wed, 8 Sep 2021 15:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351974AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4FF2C0612A7 for ; Wed, 8 Sep 2021 12:24:56 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so2438319wmq.1 for ; Wed, 08 Sep 2021 12:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=EB3dcG1dPIWxxGn3w/65eB+x5GjyM07hpyUVTAxuSws=; b=arzbUpLO1uFyAHImHC0fbKecAujOwluVnXTfrgLzJs1PfKKWH97QL+O/XRx8B+vBlE WubPFjceP0hPhAzcpmZBtq3Uh7eB6v2ybHzK/Kk4xMka3Tk8d0nJrw9v7KE9GfPyv7RY CmwLgBmoZHRd0FiAPzQSn34uWxcbXL/pmWO2ibH+/jy8w/5eWMWCC7yZ12nqCIlZGTTD csUkYl/jlMMhdqp0aHdXUuRlY+IqWMYl84/jAhusc/sdKSszQAbwImBlcdXCwb62fQvq mh5YwmHEBRXfCmz6CGdbNQXlineSI6Por2E+QcpPv1rlNl5QdxG1iMEFEW1JkcTlyx4j m+ug== 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=EB3dcG1dPIWxxGn3w/65eB+x5GjyM07hpyUVTAxuSws=; b=RxVDbACEJY0Cfb3ogsITs88PnhhMeKyBoc/8GsJdXDdDBLe0mhu1oUyu5oQmZy1NWN nVdI70TThFalu6DSMcNyVGdCG+HECSwlFsu8hFW6rXc3WsY5k/on6EfBNrX612Owo3VR faLmogzdMC/Md+zV8X2bGoslE15g0zxBB8CON13CIEOJIZ3oHWczS2N5/xw9t7bwilg5 DJqqt9wel7qmwMRBFGox3te3hgkvReiO2hgZIpEEK0ygoOpLP0Sku9zhJi9Nj9Cw6Aov XtQ0NVVszY9ld0OAY2MJ0MpRyxU5JJn30lLp21RfPZvhUtU6LMVh6pwbBq7LUbArkOd1 bOfw== X-Gm-Message-State: AOAM530lOtpc6JT1Rb48C9YK0V9l97bJeHKU42bMEk8yH1nXBpjloT/g ca30s7AAtwSSYwv/4klWHdeFPm0O+6Q= X-Google-Smtp-Source: ABdhPJwrH2GLufohxHy8G3DJYgdHK0V1+YxngSEzcKwrMH9dPPdu5ahP+9H3i4oHvnH9j/NVLxjQWg== X-Received: by 2002:a7b:cbc4:: with SMTP id n4mr483149wmi.93.1631129095271; Wed, 08 Sep 2021 12:24:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r2sm25734wrg.31.2021.09.08.12.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:54 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:43 +0000 Subject: [PATCH v3 13/15] scalar: implement the `delete` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 | 55 ++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 8 +++++ contrib/scalar/t/t9099-scalar.sh | 9 ++++++ 3 files changed, 72 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 67fa5305225..00bedb0bf66 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -8,6 +8,7 @@ #include "config.h" #include "run-command.h" #include "refs.h" +#include "dir.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -334,6 +335,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; @@ -694,6 +722,32 @@ static int cmd_unregister(int argc, const char **argv) return unregister_dir(); } +static int cmd_delete(int argc, const char **argv) +{ + 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); + + res = delete_enlistment(&enlistment); + strbuf_release(&enlistment); + + return res; +} + static struct { const char *name; int (*fn)(int, const char **); @@ -704,6 +758,7 @@ static struct { { "unregister", cmd_unregister }, { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, + { "delete", cmd_delete }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 2fa96fcabc6..6fc57707718 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -14,6 +14,7 @@ scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] scalar reconfigure [ --all | ] +scalar delete DESCRIPTION ----------- @@ -127,6 +128,13 @@ reconfigure the enlistment. With the `--all` option, all enlistments currently registered with Scalar will be reconfigured. Use this option after each Scalar upgrade. +Delete +~~~~~~ + +delete :: + This subcommand lets you delete an existing Scalar enlistment from your + local file system, unregistering the repository. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 5fe7fabd0e5..7e8771d0eff 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -76,4 +76,13 @@ test_expect_success 'scalar reconfigure' ' test true = "$(git -C one/src config core.preloadIndex)" ' +test_expect_success 'scalar delete without enlistment shows a usage' ' + test_expect_code 129 scalar delete +' + +test_expect_success 'scalar delete with enlistment' ' + scalar delete cloned && + test_path_is_missing cloned +' + test_done From patchwork Wed Sep 8 19:24:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F902C433FE for ; Wed, 8 Sep 2021 19:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 688E5610F8 for ; Wed, 8 Sep 2021 19:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350769AbhIHT00 (ORCPT ); Wed, 8 Sep 2021 15:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350652AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369B6C0612A9 for ; Wed, 8 Sep 2021 12:24:57 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v10so4872892wrd.4 for ; Wed, 08 Sep 2021 12:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DzWaDgTXC1omxOfvIpIv6ED7EgUWF84GI2Icdo7yhYA=; b=a1hqkVEjG9EepFjUFarM5HydwSo0axIWjnYQFwxViCbOsxRAoViWGnkv6GnQ2d8HOo 4vV6T+q8dCXPhPkTSKI2+NkGxTuEi4lNcr43t+dcqkj/3VSRlyOTgE4clBjw2VbKjaVT MOM1TtwYc+Ou66R3RxUkchDAdzlYUIJsC0tbxnJAlk2b4P1JjF5WpFngNr6KEwUyPmQY fIF1FwH6Yf7UdjaRWU4lm9AacMsDMSw4pyF/66pjDJAoniE383Ne+jxJpN489toHuQZw yNlpT95aIc+/M/mRvpV+uQPU3IniSeH5Sf/XjxE4JT/EHK8t+CcDVIB6PmiZXwjqOcld WM7Q== 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=DzWaDgTXC1omxOfvIpIv6ED7EgUWF84GI2Icdo7yhYA=; b=GC1RPkD9akREt9nBQ24IZ5TldRFPRnqT0hvoCAaZRRlEwlNPZAguZYnTi2/7jpCHng JcCVESdSGInLFdE2GabjsAtduB97Mra0qDHJAMDGvVJd97OPpgAzvq+IuLVO/JKO+Hzj dStXfUXOkGRYXewjyGy4kApCfajSLRgoKYino6tzaLciSmG8EpLRq2Uh0UNjZ11Izc6n i8NlYWaRKF9oPQyiq8Y6cgD3BpfqjeLwhU4beC4ek/3wAMN4geLuwuL4XkpL25p0vAjX OHk3BoI3rYCuRrS+j8+My+jxYvamChzakeBk66DH8urV9bLnYW6XXz8AoKXwM6PlHb5B 5LpA== X-Gm-Message-State: AOAM533DIjsCKsSiq6uTB/p25ZzuW0RAh8C9GRarOkwfuJwgCcOPdCg3 ql+aI5oeaxBzmCsdlNXSgXpIkUdFZEo= X-Google-Smtp-Source: ABdhPJxWAJYZSXeASPGv4rWiHngYjT5dF9IqboCp07Xjth7gwt35Yw7IB5XcpUwlQoOAUWnmvL3xMw== X-Received: by 2002:adf:8b03:: with SMTP id n3mr5751200wra.439.1631129095857; Wed, 08 Sep 2021 12:24:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n4sm20859wra.37.2021.09.08.12.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:55 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:44 +0000 Subject: [PATCH v3 14/15] scalar: implement the `version` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , 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 00bedb0bf66..728166aa97a 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -9,6 +9,7 @@ #include "run-command.h" #include "refs.h" #include "dir.h" +#include "help.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -362,6 +363,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; @@ -748,6 +758,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 **); @@ -759,6 +797,7 @@ static struct { { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, { "delete", cmd_delete }, + { "version", cmd_version }, { NULL, NULL}, }; From patchwork Wed Sep 8 19:24:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12481781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7189FC433EF for ; Wed, 8 Sep 2021 19:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D7AE610F8 for ; Wed, 8 Sep 2021 19:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350455AbhIHT01 (ORCPT ); Wed, 8 Sep 2021 15:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351992AbhIHT0L (ORCPT ); Wed, 8 Sep 2021 15:26:11 -0400 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 D0293C0612AC for ; Wed, 8 Sep 2021 12:24:57 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso1985127wme.4 for ; Wed, 08 Sep 2021 12:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=LhySsHfzZ3Pk6fo/CeRm0RMkRB5eXUuQvBWfa1uVkPg=; b=SIqYEuzDASsR58XiF40VKK/Hor0MluVwtkFnk2k4LHsH9sKxhafqEn3l9iN+xtqzT9 3hQm2BjAz+hfMb2S52sadl3tQADc227///AX/+zCmmgYgkNlessFOjVcHGPzDcYnC96i 3T3nfoLwQ0LcuxjckaETfbWC2eDlQP7Qm0a+E/Li1UInImu0fycyN28EGGOjcXPmYYw2 fDDg2lcZyPjrXnMGxoNzXwjWLYBxC6Tw9PRWbWZh7tCewxXqp+H2z50Q8nVIWL19CaIL QHZL8TSCxjHrO4WwnPim+N6OjFg/mYJ5vuG4m94sm8w1muK7XaZj7ijBw2fYyr3LVguS 2zfA== 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=LhySsHfzZ3Pk6fo/CeRm0RMkRB5eXUuQvBWfa1uVkPg=; b=LWlNIlJvouukmVzXawKqKFC9+DFCMl6wCWQ7rz3uKsYBy80knWOzgcMl1q627XHfgD yguqna8LlIj/XDbWN3EIIY3VkpSgtXvEiij0LodE/vsHiWQE1AXA4RGSstwHo07TVQKU +lCN/oqrT6ppII+5P8xnawbvgU6HbGSElZJFyEtUavl/gW4XQPRyCd68MU24zpeNdhqg kELm+EC3WVu/MNeWqReHhhMSaPA2XpjJklDeQeJdVdiPhH/VelZFEGqVhfoW3Ib1sYP+ MgDjYWHUePGB9NfBlg4exrzusx68OHzneCPauPD95Ywsw5kFTStsVpVaXOwrkgrl52eq 4Nuw== X-Gm-Message-State: AOAM531IfSmgQn0eammG/Tk2XfaNwL18OhfuUGMHrB8khdI7dOGGI7Yw ED/GQvTeOQPC6gElamHiZbBYRJFMHCE= X-Google-Smtp-Source: ABdhPJwkVfXWBFggyTZnCy7HkxPTY/9Qqah72PUQiK+dK2wuUiaVXJpNIiGXkiE9tNbuDqepY4SRSg== X-Received: by 2002:a1c:1d84:: with SMTP id d126mr5047894wmd.160.1631129096473; Wed, 08 Sep 2021 12:24:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h11sm47821wrx.9.2021.09.08.12.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 12:24:56 -0700 (PDT) Message-Id: <7ccc4f8b9b0f5b33aafeac460bcc646e7236aa4a.1631129086.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 08 Sep 2021 19:24:45 +0000 Subject: [PATCH v3 15/15] scalar: accept -C and -c options before the subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `git` executable has these two very useful options: -C : switch to the specified directory before performing any actions -c =: temporarily configure this setting for the duration of the specified scalar subcommand With this commit, we teach the `scalar` executable the same trick. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 22 +++++++++++++++++++++- contrib/scalar/scalar.txt | 10 ++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 728166aa97a..76a77ca1ed0 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -806,6 +806,25 @@ int cmd_main(int argc, const char **argv) struct strbuf scalar_usage = STRBUF_INIT; int i; + while (argc > 1 && *argv[1] == '-') { + if (!strcmp(argv[1], "-C")) { + if (argc < 3) + die(_("-C requires a ")); + if (chdir(argv[2]) < 0) + die_errno(_("could not change to '%s'"), + argv[2]); + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-c")) { + if (argc < 3) + die(_("-c requires a = argument")); + git_config_push_parameter(argv[2]); + argc -= 2; + argv += 2; + } else + break; + } + if (argc > 1) { argv++; argc--; @@ -816,7 +835,8 @@ int cmd_main(int argc, const char **argv) } strbuf_addstr(&scalar_usage, - N_("scalar []\n\nCommands:\n")); + N_("scalar [-C ] [-c =] " + " []\n\nCommands:\n")); for (i = 0; builtins[i].name; i++) strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 6fc57707718..3a80f829edc 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -36,6 +36,16 @@ The `scalar` command implements various subcommands, and different options depending on the subcommand. With the exception of `clone`, `list` and `reconfigure --all`, all subcommands expect to be run in an enlistment. +The following options can be specified _before_ the subcommand: + +-C :: + Before running the subcommand, change the working directory. This + option imitates the same option of linkgit:git[1]. + +-c =:: + For the duration of running the specified subcommand, configure this + setting. This option imitates the same option of linkgit:git[1]. + COMMANDS --------