From patchwork Wed Oct 27 08:27:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4279C433FE for ; Wed, 27 Oct 2021 08:27:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B39A460296 for ; Wed, 27 Oct 2021 08:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240899AbhJ0I3t (ORCPT ); Wed, 27 Oct 2021 04:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234444AbhJ0I3r (ORCPT ); Wed, 27 Oct 2021 04:29:47 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 572C8C061745 for ; Wed, 27 Oct 2021 01:27:22 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id e12so2696875wra.4 for ; Wed, 27 Oct 2021 01:27:22 -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=DxsNTF/fCYxs7o7dIpfOPCw2pKhc1azVvDP/GYMSgHc=; b=M0Wp/oT/EiTrOxAm4OvJsafw645AuSwi7ETujYBtXGpoX5gGozXmcTDVE53/42ISWK 09jGrgK7dy+5Uk1p3e+VwTEBrK1lQpu32Rven0gGi35HmT/R7n35ZfPouyzdO0qnksjc BV5Ce+gJOn8L+J2iCCyUqP8SKnyX/ypk4d1oqcwsHQOX6vMjqCQYrOQYOx9+QDYGRuar /U/e7mFZoB2yJxpjI097P5oIot860F0xKHhcIXWtDv7d5AlatPzNmWPkBDEKPXlQuXm8 XhWnhT9jdcbGpR3a8+Df5QqilYSgLpBCCwZ4pqfqBlSA+N3G/kmVEOue/IilOnZOgsn3 Fo2A== 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=DxsNTF/fCYxs7o7dIpfOPCw2pKhc1azVvDP/GYMSgHc=; b=4nseqPdXpCzSXawd4ZTnOxVRCdG4iuy600FA/5fMjubvl9dXrgEnsimlirHIvguDXn 9JjfOFDzF8kFk71sfB/Dna74xldYnpwnzkilUJ/WbuF6weIlPTa3xdwew+2Jl1rZ71f0 aXiT62hJB8v7jjMC3xhLxS7+qoE471RYDyLon7XM9w4E0GaNMnzrUh7XuV0fy9ZMuTAz xXOJNJyEqt/0oCSBHG4WbF75BB9S2tKyAkvK2dbWS0ZECFrC11qomBiyrEbioWh0kiKz NVSGPTz73kNFkBiYiy9K+IAOQK45la4PK/sj01RHQ0MtJEI2gUjJ1VMtEbJqy8Nr2dJ4 2bTQ== X-Gm-Message-State: AOAM530wI28UblO5FnhK+w2emkwISUGBEIWB3RAjauhTwMvyvJwYndxc njajGztowcRsdkIuCj/NVa0WPbwr0WI= X-Google-Smtp-Source: ABdhPJxJ0mCDqlRkV32QKRa6bRyJPOtAPQchCsO0ZnwTeer9bN67xylT5JT9z0tgnHUMCfvywBS31Q== X-Received: by 2002:a5d:4d52:: with SMTP id a18mr38252382wru.406.1635323240949; Wed, 27 Oct 2021 01:27:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i6sm12153929wry.71.2021.10.27.01.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:20 -0700 (PDT) Message-Id: <9b0b00438ecd53fb39d3b378c0c655c8b317959b.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:05 +0000 Subject: [PATCH v6 01/15] scalar: create a rudimentary executable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The idea of Scalar (https://github.com/microsoft/scalar), and before that, of VFS for Git, has always been to prove that Git _can_ scale, and to upstream whatever strategies have been demonstrated to help. With this patch, we start the journey from that C# project to move what is left to Git's own `contrib/` directory, reimplementing it in pure C, with the intention to facilitate integrating the functionality into core Git all while maintaining backwards-compatibility for existing Scalar users (which will be much easier when both live in the same worktree). It has always been the plan to contribute all of the proven strategies back to core Git. For example, while the virtual filesystem provided by VFS for Git helped the team developing the Windows operating system to move onto Git, while trying to upstream it we realized that it cannot be done: getting the virtual filesystem to work (which we only managed to implement fully on Windows, but not on, say, macOS or Linux), and the required server-side support for the GVFS protocol, made this not quite feasible. The Scalar project learned from that and tackled the problem with different tactics: instead of pretending to Git that the working directory is fully populated, it _specifically_ teaches Git about partial clone (which is based on VFS for Git's cache server), about sparse checkout (which VFS for Git tried to do transparently, in the file system layer), and regularly runs maintenance tasks to keep the repository in a healthy state. With partial clone, sparse checkout and `git maintenance` having been upstreamed, there is little left that `scalar.exe` does which `git.exe` cannot do. One such thing is that `scalar clone ` will automatically set up a partial, sparse clone, and configure known-helpful settings from the start. So let's bring this convenience into Git's tree. The idea here is that you can (optionally) build Scalar via make -C contrib/scalar/ This will build the `scalar` executable and put it into the contrib/scalar/ subdirectory. The slightly awkward addition of the `contrib/scalar/*` bits to the top-level `Makefile` are actually really required: we want to link to `libgit.a`, which means that we will need to use the very same `CFLAGS` and `LDFLAGS` as the rest of Git. An early development version of this patch tried to replicate all the conditional code in `contrib/scalar/Makefile` (e.g. `NO_POLL`) just like `contrib/svn-fe/Makefile` used to do before it was retired. It turned out to be quite the whack-a-mole game: the SHA-1-related flags, the flags enabling/disabling `compat/poll/`, `compat/regex/`, `compat/win32mmap.c` & friends depending on the current platform... To put it mildly: it was a major mess. Instead, this patch makes minimal changes to the top-level `Makefile` so that the bits in `contrib/scalar/` can be compiled and linked, and adds a `contrib/scalar/Makefile` that uses the top-level `Makefile` in a most minimal way to do the actual compiling. Note: With this commit, we only establish the infrastructure, no Scalar functionality is implemented yet; We will do that incrementally over the next few commits. Signed-off-by: Johannes Schindelin --- Makefile | 9 +++++++++ contrib/scalar/.gitignore | 2 ++ contrib/scalar/Makefile | 34 ++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 contrib/scalar/.gitignore create mode 100644 contrib/scalar/Makefile create mode 100644 contrib/scalar/scalar.c diff --git a/Makefile b/Makefile index c3565fc0f8f..a12cac1b68b 100644 --- a/Makefile +++ b/Makefile @@ -2444,6 +2444,11 @@ OBJECTS += $(FUZZ_OBJS) ifndef NO_CURL OBJECTS += http.o http-walker.o remote-curl.o endif + +SCALAR_SOURCES := contrib/scalar/scalar.c +SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o) +OBJECTS += $(SCALAR_OBJECTS) + .PHONY: objects objects: $(OBJECTS) @@ -2586,6 +2591,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS) +contrib/scalar/scalar$X: $(SCALAR_OBJECTS) GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \ + $(filter %.o,$^) $(LIBS) + $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore new file mode 100644 index 00000000000..ff3d47e84d0 --- /dev/null +++ b/contrib/scalar/.gitignore @@ -0,0 +1,2 @@ +/*.exe +/scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile new file mode 100644 index 00000000000..f6f0036f0fa --- /dev/null +++ b/contrib/scalar/Makefile @@ -0,0 +1,34 @@ +QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir +QUIET_SUBDIR1 = + +ifneq ($(findstring s,$(MAKEFLAGS)),s) +ifndef V + QUIET_SUBDIR0 = +@subdir= + QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ + $(MAKE) $(PRINT_DIR) -C $$subdir +else + export V +endif +endif + +all: + +include ../../config.mak.uname +-include ../../config.mak.autogen +-include ../../config.mak + +TARGETS = scalar$(X) scalar.o +GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a + +all: scalar$(X) + +$(GITLIBS): + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) + +$(TARGETS): $(GITLIBS) scalar.c + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) + +clean: + $(RM) $(TARGETS) + +.PHONY: $(GITLIBS) all clean FORCE diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c new file mode 100644 index 00000000000..7cff29e0fcd --- /dev/null +++ b/contrib/scalar/scalar.c @@ -0,0 +1,36 @@ +/* + * The Scalar command-line interface. + */ + +#include "cache.h" +#include "gettext.h" +#include "parse-options.h" + +static struct { + const char *name; + int (*fn)(int, const char **); +} builtins[] = { + { NULL, NULL}, +}; + +int cmd_main(int argc, const char **argv) +{ + struct strbuf scalar_usage = STRBUF_INIT; + int i; + + if (argc > 1) { + argv++; + argc--; + + for (i = 0; builtins[i].name; i++) + if (!strcmp(builtins[i].name, argv[0])) + return !!builtins[i].fn(argc, argv); + } + + strbuf_addstr(&scalar_usage, + N_("scalar []\n\nCommands:\n")); + for (i = 0; builtins[i].name; i++) + strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); + + usage(scalar_usage.buf); +} From patchwork Wed Oct 27 08:27:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90889C433F5 for ; Wed, 27 Oct 2021 08:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E98060D42 for ; Wed, 27 Oct 2021 08:27:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240876AbhJ0I3u (ORCPT ); Wed, 27 Oct 2021 04:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240752AbhJ0I3s (ORCPT ); Wed, 27 Oct 2021 04:29:48 -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 DE312C061767 for ; Wed, 27 Oct 2021 01:27:22 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id z81-20020a1c7e54000000b0032cc97975e4so1611529wmc.4 for ; Wed, 27 Oct 2021 01:27:22 -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=iIDxEOzaBWUuwrTlINMFmvZLBskkFAXJw9qE9GmcBzM=; b=M5YJVnVQN+tPJfk3sx4HYblzSi9zqi21KBiQYfAB3psEpDzkUzX/snTwrIbYSzpWxD d4i3aw6YuizePoMNELc4soT3gv+WOuZ4a3plhH+3siBXScqf+/i+nvxMf8TWQFGS3rEg aOkpXoW8cw6G2SZd60OHqJg4uMtaoh4sZNq2Akk8DaZwzncrF56Tmj9HbQ1/6MbWtnaz QW4I7G0zQAyYjUJxFBGZYGXDzbfeJTJd+2h2Ti+IoIOleqT3o1dr8R5rkV5zSRKN0wC3 yl7Ak/RPwykuUFXtVKzHV52/Z54mLwXJa8AGPjUvFXF+d/11x/8Kz1ZGefWwOnyTBdf5 VZPA== 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=iIDxEOzaBWUuwrTlINMFmvZLBskkFAXJw9qE9GmcBzM=; b=PyRO0pkvnmMT+D6jTLXfjA90yKFLOnvUYZdrzQXlyrZFnN/TZhjNuR79X/fq9oggSk ZHUtmUsc+l00nPOeBCcWN+lbWlWDgSYG53hqL4htJGrRgFMnju84KElqmp4rEnT+6Qs5 iAFADvBvKihyBFjp9Oc87RLYy1Z7DZ3kSUHF5hwPpmAmWVPOoOAfVx4Lac7q/6GWp727 rzNCp/DziU0Yi4v93xGOTKJqIBa0wk4w9jgeKdK7/7/r2O341xPJbapMTdpZTcIYgdrJ /jYM83N5qlLnrl+z0/4W85X/PlBNqPG9SgNGZiuIgPs51KgO4jP0GbR4gwzDUEkmp/vt UERg== X-Gm-Message-State: AOAM532aSaTu62Eyl5tMXd6iB102K0suoJFZZqzL2gGQoRre7bOuqZW0 OLoA/m7RscUSJPq00j+RIc5JB9o4Y8w= X-Google-Smtp-Source: ABdhPJw16gjD3lr5xYZkp4ye4KTz+dckyTv999fFJMgbirkNAEu+1WIaEfs6ndSafzGM9qxi1ZiOhw== X-Received: by 2002:a1c:4c17:: with SMTP id z23mr4362554wmf.61.1635323241561; Wed, 27 Oct 2021 01:27:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n11sm11603697wrs.14.2021.10.27.01.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:21 -0700 (PDT) Message-Id: <40fee75968e6bb0940bfa040b917f305fbb6671f.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:06 +0000 Subject: [PATCH v6 02/15] scalar: start documenting the command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This commit establishes the infrastructure to build the manual page for the `scalar` command. Signed-off-by: Johannes Schindelin --- contrib/scalar/.gitignore | 3 +++ contrib/scalar/Makefile | 14 +++++++++++++- contrib/scalar/scalar.txt | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 contrib/scalar/scalar.txt diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore index ff3d47e84d0..00441073f59 100644 --- a/contrib/scalar/.gitignore +++ b/contrib/scalar/.gitignore @@ -1,2 +1,5 @@ +/*.xml +/*.1 +/*.html /*.exe /scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index f6f0036f0fa..e862d3ad8fa 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: $(GITLIBS) 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: $(GITLIBS) 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 Oct 27 08:27:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08B9AC433F5 for ; Wed, 27 Oct 2021 08:27:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFD1F61073 for ; Wed, 27 Oct 2021 08:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240920AbhJ0IaA (ORCPT ); Wed, 27 Oct 2021 04:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240894AbhJ0I3s (ORCPT ); Wed, 27 Oct 2021 04:29:48 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DAC2C061570 for ; Wed, 27 Oct 2021 01:27:23 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id g205-20020a1c20d6000000b0032cc6bbd505so4922054wmg.5 for ; Wed, 27 Oct 2021 01:27:23 -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=irvSoFz4bWwK8LTNUrLAbY+eQw6AILWpIvDq2yAWzZM=; b=pg27w+i+siG7gXF4k8CywV8L19Li7CFE+vIB41bGK1WL8s5dIFCGRUq51Bw97oFGf8 O0em+f7O+5eOy25ygv2dfwrnJbptpZK0vEbikk1JLWEbiuegxt9itJYD2djqglXFcD2V cSqYxUxPzDbH/oehFxU0nJsT8PGR+DIMcY5M8cFRcUILjgJLx3udGW7eIIVdPkCvnnkx jN9A1JweL6L5R3Cpjed9iGHywQPjK0ToImfW2SjS7s+YWOZLaL0o4LjmqpDp79zpuXeU OoMJyaIIV1NOLSYo3/Jt6xVC4nWSSTIZCYeBV7V+SJ6IV2kBAothJxc75c9MB2CvS0E4 dklQ== 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=irvSoFz4bWwK8LTNUrLAbY+eQw6AILWpIvDq2yAWzZM=; b=7wsoofEaTmu0XjrfnF4K0OkBjemEta0J0dOk449URQ3Gc3KdV+yNuEGVvIULVeRDci shihf35iBnuH4G+0ExnQzWPpC9gJmWzGhsq7ThzdzGBf7v/5EsCKCQ5MwtGcP8AA0p2x Qk42EIGhPxkUt2nECoV83LRsS+emiP3Zyx8j7NkmJqglIZbFosvUJAp6ap9+8jwchCLP fGDCNA5nbX/BwXIH+pfXrqzHLohXcSn4RMNH+bZ17Ze69FKPR5Vcyc3Il6IJurfRF6xA W68nlWq5tv7iDeRmh6XCyQKXKfP75io3/wZJfmf8K4o5AosBTDoJ8Rrg4I5oo1wCTTRA 9KVA== X-Gm-Message-State: AOAM530kIv73nXIpjMQcAQYUFhE1uvNfRRgkgvl8cYxmkKBzL2v52L++ rZkja8p78JU/lZRLfen5Vlf1lHswCec= X-Google-Smtp-Source: ABdhPJxF1EbotpDJrKSH1Mw6ctsSeeAuWyBtfqHgi8x0saYn47yEYtyPZZQG5LnxlpLw/Gb0KmnkuA== X-Received: by 2002:a1c:f705:: with SMTP id v5mr4280642wmh.121.1635323242223; Wed, 27 Oct 2021 01:27:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x23sm2760322wmc.8.2021.10.27.01.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:21 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:07 +0000 Subject: [PATCH v6 03/15] scalar: create test infrastructure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To test the Scalar command, create a test script in contrib/scalar/t that is executed as `make -C contrib/scalar test`. Since Scalar has no meaningful capabilities yet, the only test is rather simple. We will add more tests in subsequent commits that introduce corresponding, new functionality. Note: this test script is intended to test `scalar` only lightly, even after all of the functionality is implemented. A more comprehensive functional (or: integration) test suite can be found at https://github.com/microsoft/scalar; It is used in the workflow https://github.com/microsoft/git/blob/HEAD/.github/workflows/scalar-functional-tests.yml in Microsoft's Git fork. This test suite performs end-to-end tests with a real remote repository, and is run as part of the regular CI builds. Since those tests require some functionality supported only by Microsoft's Git fork ("GVFS protocol"), there is no intention to port that fuller test suite to `contrib/scalar/`. Signed-off-by: Johannes Schindelin --- contrib/scalar/Makefile | 17 +++++-- contrib/scalar/t/Makefile | 78 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 17 +++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 contrib/scalar/t/Makefile create mode 100755 contrib/scalar/t/t9099-scalar.sh diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile index e862d3ad8fa..44796572ef4 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: $(GITLIBS) all clean docs FORCE +.PHONY: $(GITLIBS) 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 Oct 27 08:27:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12586635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F38A0C433EF for ; Wed, 27 Oct 2021 08:27:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC9A661073 for ; Wed, 27 Oct 2021 08:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240928AbhJ0IaB (ORCPT ); Wed, 27 Oct 2021 04:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240900AbhJ0I3t (ORCPT ); Wed, 27 Oct 2021 04:29:49 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D016C061745 for ; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id z81-20020a1c7e54000000b0032cc97975e4so1611631wmc.4 for ; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zmNapYoSF08hozpeOeKMiT/esyUmD9Bsx0bmoobd/Rw=; b=ZjxwiDrXulK6XoHGmnMKhVo0TrGFb9NajihgBnl2EcpJnvu03tZc3BtWb5OPoo82oO MONCsD+chngUNkGJWXkeWqpShpt6CI4NfYakoquP9ydoUfMMG/ZCIWKhWrQLqRzjJa7X mP01O4Pj1UxUf46SYwads3KueuWy+yGBUxjMJyOegUY+mopc0CSnJiJMrW1Sz4m/wDV3 NLLKuTVBSRZ7ruSEnZZAq201prj1d3T+WOveuQvQkGJTykM7hwznGwVjynmhqJ7IpU++ 4crsDEVhkOasf46YZn432+C4/lKdOxUMA1LP0v/rm7dyJ93/MTUSIjUbDz4IuTWcW+CH l9pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zmNapYoSF08hozpeOeKMiT/esyUmD9Bsx0bmoobd/Rw=; b=OuWyfgdB9wmLSvKtVjRaDiN+5vUeOI2TTxHOkyqLu3lXhSP9toHHorKapPZflsVVej XNy48UpovGTwz1hwm6jCaK9BG9TjY76KR9uCgQGKFr8tnst91q1AKE0vTpX3F4MDY+CP RJ7ah8vVUSZ64qcT4E1QXwAAWIqSQekYp2SNDlFt1Noy4Erk6HjWqzWVNdgN1GHbcwZB Wz3dAy21e4n2ViAQxUmDUzDlseKVq58QQHAceCz9mDduJ9htFhTNMG/2pRPQ8BJ85HjQ elAneWlMd3k6v6qrnMn8s8tq1BgCKjY0GjcT6uSKE7znkunPWOPjWSfsM0iouutau4Jv MM+g== X-Gm-Message-State: AOAM5314dR7iMQmqgIRYv2/J7tDl0S5kU9REv//ff6MBT89QaQ+Ru8Xq +Zz1z/hCAlYSaqhl/vTxy/FCe58fgaI= X-Google-Smtp-Source: ABdhPJyvD6RAuxgPYKECUaAUq6O0K903oSkZizMjcToXI4SuSKeJPcvUtbQn+RUzfQ8bqV8T8zM4Mw== X-Received: by 2002:a05:600c:22c3:: with SMTP id 3mr4177329wmg.170.1635323242965; Wed, 27 Oct 2021 01:27:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w10sm16217482wrq.88.2021.10.27.01.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:22 -0700 (PDT) Message-Id: <53224e506eaaf45d3385e32f0687f6d1cce5d27e.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:08 +0000 Subject: [PATCH v6 04/15] scalar: 'register' sets recommended config and starts maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Let's start implementing the `register` command. With this commit, recommended settings are configured upon `scalar register`, and Git's background maintenance is started. The recommended config settings may very well change in the future. For example, once the built-in FSMonitor is available, we will want to enable it upon `scalar register`. For that reason, we explicitly support running `scalar register` in an already-registered enlistment. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 248 ++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 18 ++- 2 files changed, 265 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 7cff29e0fcd..38721d671ba 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -5,11 +5,259 @@ #include "cache.h" #include "gettext.h" #include "parse-options.h" +#include "config.h" +#include "run-command.h" + +/* + * Remove the deepest subdirectory in the provided path string. Path must not + * include a trailing path separator. Returns 1 if parent directory found, + * otherwise 0. + */ +static int strbuf_parent_directory(struct strbuf *buf) +{ + size_t len = buf->len; + size_t offset = offset_1st_component(buf->buf); + char *path_sep = find_last_dir_sep(buf->buf + offset); + strbuf_setlen(buf, path_sep ? path_sep - buf->buf : offset); + + return buf->len < len; +} + +static void setup_enlistment_directory(int argc, const char **argv, + const char * const *usagestr, + const struct option *options, + struct strbuf *enlistment_root) +{ + struct strbuf path = STRBUF_INIT; + char *root; + int enlistment_found = 0; + + if (startup_info->have_repository) + BUG("gitdir already set up?!?"); + + if (argc > 1) + usage_with_options(usagestr, options); + + /* find the worktree, determine its corresponding root */ + if (argc == 1) + strbuf_add_absolute_path(&path, argv[0]); + else if (strbuf_getcwd(&path) < 0) + die(_("need a working directory")); + + strbuf_trim_trailing_dir_sep(&path); + do { + const size_t len = path.len; + + /* check if currently in enlistment root with src/ workdir */ + strbuf_addstr(&path, "/src"); + if (is_nonbare_repository_dir(&path)) { + if (enlistment_root) + strbuf_add(enlistment_root, path.buf, len); + + enlistment_found = 1; + break; + } + + /* reset to original path */ + strbuf_setlen(&path, len); + + /* check if currently in workdir */ + if (is_nonbare_repository_dir(&path)) { + if (enlistment_root) { + /* + * If the worktree's directory's name is `src`, the enlistment is the + * parent directory, otherwise it is identical to the worktree. + */ + root = strip_path_suffix(path.buf, "src"); + strbuf_addstr(enlistment_root, root ? root : path.buf); + free(root); + } + + enlistment_found = 1; + break; + } + } while (strbuf_parent_directory(&path)); + + if (!enlistment_found) + die(_("could not find enlistment root")); + + if (chdir(path.buf) < 0) + die_errno(_("could not switch to '%s'"), path.buf); + + strbuf_release(&path); + setup_git_directory(); +} + +static int run_git(const char *arg, ...) +{ + struct strvec argv = STRVEC_INIT; + va_list args; + const char *p; + int res; + + va_start(args, arg); + strvec_push(&argv, arg); + while ((p = va_arg(args, const char *))) + strvec_push(&argv, p); + va_end(args); + + res = run_command_v_opt(argv.v, RUN_GIT_CMD); + + strvec_clear(&argv); + return res; +} + +static int set_recommended_config(void) +{ + struct { + const char *key; + const char *value; + } config[] = { + { "am.keepCR", "true" }, + { "core.FSCache", "true" }, + { "core.multiPackIndex", "true" }, + { "core.preloadIndex", "true" }, +#ifndef WIN32 + { "core.untrackedCache", "true" }, +#else + /* + * Unfortunately, Scalar's Functional Tests demonstrated + * that the untracked cache feature is unreliable on Windows + * (which is a bummer because that platform would benefit the + * most from it). For some reason, freshly created files seem + * not to update the directory's `lastModified` time + * immediately, but the untracked cache would need to rely on + * that. + * + * Therefore, with a sad heart, we disable this very useful + * feature on Windows. + */ + { "core.untrackedCache", "false" }, +#endif + { "core.logAllRefUpdates", "true" }, + { "credential.https://dev.azure.com.useHttpPath", "true" }, + { "credential.validate", "false" }, /* GCM4W-only */ + { "gc.auto", "0" }, + { "gui.GCWarning", "false" }, + { "index.threads", "true" }, + { "index.version", "4" }, + { "merge.stat", "false" }, + { "merge.renames", "false" }, + { "pack.useBitmaps", "false" }, + { "pack.useSparse", "true" }, + { "receive.autoGC", "false" }, + { "reset.quiet", "true" }, + { "feature.manyFiles", "false" }, + { "feature.experimental", "false" }, + { "fetch.unpackLimit", "1" }, + { "fetch.writeCommitGraph", "false" }, +#ifdef WIN32 + { "http.sslBackend", "schannel" }, +#endif + { "status.aheadBehind", "false" }, + { "commitGraph.generationVersion", "1" }, + { "core.autoCRLF", "false" }, + { "core.safeCRLF", "false" }, + { NULL, NULL }, + }; + int i; + char *value; + + for (i = 0; config[i].key; i++) { + if (git_config_get_string(config[i].key, &value)) { + trace2_data_string("scalar", the_repository, config[i].key, "created"); + if (git_config_set_gently(config[i].key, + config[i].value) < 0) + return error(_("could not configure %s=%s"), + config[i].key, config[i].value); + } else { + trace2_data_string("scalar", the_repository, config[i].key, "exists"); + free(value); + } + } + + /* + * The `log.excludeDecoration` setting is special because it allows + * for multiple values. + */ + if (git_config_get_string("log.excludeDecoration", &value)) { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "created"); + if (git_config_set_multivar_gently("log.excludeDecoration", + "refs/prefetch/*", + CONFIG_REGEX_NONE, 0)) + return error(_("could not configure " + "log.excludeDecoration")); + } else { + trace2_data_string("scalar", the_repository, + "log.excludeDecoration", "exists"); + free(value); + } + + return 0; +} + +static int start_maintenance(void) +{ + return run_git("maintenance", "start", NULL); +} + +static int add_enlistment(void) +{ + int res; + + if (!the_repository->worktree) + die(_("Scalar enlistments require a worktree")); + + res = run_git("config", "--global", "--get", "--fixed-value", + "scalar.repo", the_repository->worktree, NULL); + + /* + * If the setting is already there, then do nothing. + */ + if (!res) + return 0; + + return run_git("config", "--global", "--add", + "scalar.repo", the_repository->worktree, NULL); +} + +static int register_dir(void) +{ + int res = add_enlistment(); + + if (!res) + res = set_recommended_config(); + + if (!res) + res = start_maintenance(); + + return res; +} + +static int cmd_register(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar register []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return register_dir(); +} static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "register", cmd_register }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 5f7131861a5..568987064b2 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar [] +scalar register [] DESCRIPTION ----------- @@ -29,6 +29,22 @@ will be identical to the worktree. The `scalar` command implements various subcommands, and different options depending on the subcommand. +COMMANDS +-------- + +Register +~~~~~~~~ + +register []:: + Adds the enlistment's repository to the list of registered repositories + and starts background maintenance. If `` is not provided, + then the enlistment associated with the current working directory is + registered. ++ +Note: when this subcommand is called in a worktree that is called `src/`, its +parent directory is considered to be the Scalar enlistment. If the worktree is +_not_ called `src/`, it itself will be considered to be the Scalar enlistment. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Wed Oct 27 08:27:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12586637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B97C433FE for ; Wed, 27 Oct 2021 08:27:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14B00610A0 for ; Wed, 27 Oct 2021 08:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240934AbhJ0IaD (ORCPT ); Wed, 27 Oct 2021 04:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240901AbhJ0I3u (ORCPT ); Wed, 27 Oct 2021 04:29:50 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3C00C061767 for ; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id y205-20020a1c7dd6000000b0032cc8c2800fso4604723wmc.4 for ; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=SJgwnf3rJRV5fMleXZ2nSdcJHBhDnyI3ULuJxOiFMCg=; b=EjhDZslY2Zo6lKI3ozgmRuxxeCpNgPS97YnmFGSaBFnCKWPbm19Tzo8PEilhnj9DCP ztPcBb/cFzCFknSLQXAZnjZQURpDjtSlVvmksq4N4gVCtEGRnQ9zdyKfNTahLj+2DCcW RsL+xQjnidX5nfHCWFqQJ5HvlTZRChGmn89ocD7u1+4SqCYM9RkIVWQv8OIoMWZjv96u rfMVbAKZfGrkhW3MT67EVjXEcKurN46A6uz8VyL5OzVqy4eCQrX//Doo4sjEz4Yduc8j 0OwbjZOdkoPGB/sJR2w5/EviFbWK6s2vFCkP7FNqZdspDrOj4YBEc7itNfH+8HWO2ST5 TiuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=SJgwnf3rJRV5fMleXZ2nSdcJHBhDnyI3ULuJxOiFMCg=; b=OXgVqXYUQHjgjEFlT/TbUODAT+Bpca73XcdJfNhBCOBOPAVlvH78BB5DwkEmD3uRTZ lT9AmcPZlzD2/9Vzhs7OwtmbA4VmlDsCaJJKBXJvUEQvbBn0N1NalGISFiUjIKZ09AWf EV0SHc6wM0VBPSmlAIKQcZTrxlqIbBBA8f3d0j2dxznmSUflCo683f1NH+ZwzjJHADvw EVBENxu3THEvD14UnCGj5vJJwIF+7a1tBp19mNtwKhoFDQBW6EWqI4YEyGR8YYQaxWgq BoQgH3KwK6EaBaW+TVGKqDoFAUgSVMEMbehagFwVSkap2C8ialdtoo4X7WeFZVjSeaoh lFQg== X-Gm-Message-State: AOAM530UY56XkkwkOoOvG48McU9ghOAias3lXTWbaI4rELsTwu7DpYs1 CZ0QHw/uUi5pzLRMch/pUalQ5JyrvN8= X-Google-Smtp-Source: ABdhPJxLlSrStw7qnjpFxZo0FMF/Qvdzxq4LxWvseNKAXZuAEwlwRbQ+PEhEO/rvoaPSUIgi18WQSg== X-Received: by 2002:a7b:c441:: with SMTP id l1mr4093622wmi.69.1635323243533; Wed, 27 Oct 2021 01:27:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m31sm2714910wms.25.2021.10.27.01.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:23 -0700 (PDT) Message-Id: <3591e53700bbf9e193af4ad8c14793fcc377292e.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:09 +0000 Subject: [PATCH v6 05/15] scalar: 'unregister' stops background maintenance Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Just like `scalar register` starts the scheduled background maintenance, `scalar unregister` stops it. Note that we use `git maintenance start` in `scalar register`, but we do not use `git maintenance stop` in `scalar unregister`: this would stop maintenance for _all_ repositories, not just for the one we want to unregister. The `unregister` command also removes the corresponding entry from the `[scalar]` section in the global Git config. Co-authored-by: Victoria Dye Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 50 ++++++++++++++++++++++++++++++++------- contrib/scalar/scalar.txt | 8 +++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 38721d671ba..fc55404230d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -197,12 +197,12 @@ static int set_recommended_config(void) return 0; } -static int start_maintenance(void) +static int toggle_maintenance(int enable) { - return run_git("maintenance", "start", NULL); + return run_git("maintenance", enable ? "start" : "unregister", NULL); } -static int add_enlistment(void) +static int add_or_remove_enlistment(int add) { int res; @@ -213,24 +213,39 @@ static int add_enlistment(void) "scalar.repo", the_repository->worktree, NULL); /* - * If the setting is already there, then do nothing. + * If we want to add and the setting is already there, then do nothing. + * If we want to remove and the setting is not there, then do nothing. */ - if (!res) + if ((add && !res) || (!add && res)) return 0; - return run_git("config", "--global", "--add", + return run_git("config", "--global", add ? "--add" : "--unset", + add ? "--no-fixed-value" : "--fixed-value", "scalar.repo", the_repository->worktree, NULL); } static int register_dir(void) { - int res = add_enlistment(); + int res = add_or_remove_enlistment(1); if (!res) res = set_recommended_config(); if (!res) - res = start_maintenance(); + res = toggle_maintenance(1); + + return res; +} + +static int unregister_dir(void) +{ + int res = 0; + + if (toggle_maintenance(0) < 0) + res = -1; + + if (add_or_remove_enlistment(0) < 0) + res = -1; return res; } @@ -253,11 +268,30 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_unregister(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar unregister []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return unregister_dir(); +} + static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { { "register", cmd_register }, + { "unregister", cmd_unregister }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 568987064b2..d9a79984492 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] scalar register [] +scalar unregister [] DESCRIPTION ----------- @@ -45,6 +46,13 @@ Note: when this subcommand is called in a worktree that is called `src/`, its parent directory is considered to be the Scalar enlistment. If the worktree is _not_ called `src/`, it itself will be considered to be the Scalar enlistment. +Unregister +~~~~~~~~~~ + +unregister []:: + Remove the specified repository from the list of repositories + registered with Scalar and stop the scheduled background maintenance. + SEE ALSO -------- linkgit:git-maintenance[1]. From patchwork Wed Oct 27 08:27:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8AA0C433F5 for ; Wed, 27 Oct 2021 08:27:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD87C61073 for ; Wed, 27 Oct 2021 08:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240902AbhJ0IaD (ORCPT ); Wed, 27 Oct 2021 04:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240904AbhJ0I3u (ORCPT ); Wed, 27 Oct 2021 04:29:50 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BB2C0613B9 for ; Wed, 27 Oct 2021 01:27:25 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 67-20020a1c1946000000b0030d4c90fa87so1641955wmz.2 for ; Wed, 27 Oct 2021 01:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dZbBihr8P478PPKLNmEh1kp6VSl3WRtsE74oahy/YaE=; b=oiKez90CJpX6HzlDM8VJJv0okebx0ba+VEPhCunPjSEPoZLFB8cYLaSxF5l0gw9uru Sw9W+YDYohnxGBeOHkD5hzvWcVjkVJbVt9pZb1gY4iYiQQahKCjtinzGoDYDDGYMciTo jECXn7wis+2qFybfZrBkkUY/Ai79Cy9sZ8BMk9AQt2zQvPCNC+sdAbWv2QwSbxg9yoru PFFg5O3yDShr91KsjtHLaDTnqO1CSW+nsd4y5uQTWWwF758GiUCSO0NC+prUI/I3KajD CsHZoI76p5Z/tVKAr3ayy4CsKriD9soGgPISZaQ4oBQb0AaSJpjhBgB6Iu9+Jrte8FHD EZ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dZbBihr8P478PPKLNmEh1kp6VSl3WRtsE74oahy/YaE=; b=QRwu9c81vvtzGJwIdjrDlxS3T1hBE6QDfd71KJVvAiRn+JgEWbMYGp6lItnxgtQa8D /cY/QzNeZ1nAp/rmWM80JoWzIXTY4067SyX0g/zBpHcH+fcW22stJOuCuc7UkyNDstFX E6Z5NrS55b651MhvL/zWH2QxU/EKhvmZEbQ7xgoHj0fKUfFEXAN1a6w/OuiY3M8823+e L8T3CMJG3vYphhrj7T+tw20Y/DLf3ssP+rTWaP/kop2d12EEpSNA4Zrn/SuGy0WTsDA9 4Lm16d6yQBZwh3pB3yGf1g8JC51DEb3RTukQO9bTLvuKQJ5EZu2aylQ6IqflJ0M219gL RCZQ== X-Gm-Message-State: AOAM530uEnQPh/f6XzQyM5G16e8fYE/NySVVFMDv75yprU8dG4dVvfsG gz3HvX5elZD3vhZZHBwyNQ3s57KczQQ= X-Google-Smtp-Source: ABdhPJwMS4CbnhWvfHs1mvPBy6lvmkcoaZTX7+YckHUXaqoS9hwFtThjVjdjmicrGsWGzl19tqafKw== X-Received: by 2002:a05:600c:4fd1:: with SMTP id o17mr4308976wmq.110.1635323244139; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 10sm3140024wme.27.2021.10.27.01.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:23 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:10 +0000 Subject: [PATCH v6 06/15] scalar: let 'unregister' handle a deleted enlistment directory gracefully Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When a user deleted an enlistment manually, let's be generous and _still_ unregister it. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 46 ++++++++++++++++++++++++++++++++ contrib/scalar/t/t9099-scalar.sh | 15 +++++++++++ 2 files changed, 61 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index fc55404230d..dc84ce0d5b2 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -268,6 +268,24 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int remove_deleted_enlistment(struct strbuf *path) +{ + int res = 0; + strbuf_realpath_forgiving(path, path->buf, 1); + + if (run_git("config", "--global", + "--unset", "--fixed-value", + "scalar.repo", path->buf, NULL) < 0) + res = -1; + + if (run_git("config", "--global", + "--unset", "--fixed-value", + "maintenance.repo", path->buf, NULL) < 0) + res = -1; + + return res; +} + static int cmd_unregister(int argc, const char **argv) { struct option options[] = { @@ -281,6 +299,34 @@ static int cmd_unregister(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, usage, 0); + /* + * Be forgiving when the enlistment or worktree does not even exist any + * longer; This can be the case if a user deleted the worktree by + * mistake and _still_ wants to unregister the thing. + */ + if (argc == 1) { + struct strbuf src_path = STRBUF_INIT, workdir_path = STRBUF_INIT; + + strbuf_addf(&src_path, "%s/src/.git", argv[0]); + strbuf_addf(&workdir_path, "%s/.git", argv[0]); + if (!is_directory(src_path.buf) && !is_directory(workdir_path.buf)) { + /* remove possible matching registrations */ + int res = -1; + + strbuf_strip_suffix(&src_path, "/.git"); + res = remove_deleted_enlistment(&src_path) && res; + + strbuf_strip_suffix(&workdir_path, "/.git"); + res = remove_deleted_enlistment(&workdir_path) && res; + + strbuf_release(&src_path); + strbuf_release(&workdir_path); + return res; + } + strbuf_release(&src_path); + strbuf_release(&workdir_path); + } + setup_enlistment_directory(argc, argv, usage, options, NULL); return unregister_dir(); diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 16f2b72b126..ef0e8d680d5 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -14,4 +14,19 @@ test_expect_success 'scalar shows a usage' ' test_expect_code 129 scalar -h ' +test_expect_success 'scalar unregister' ' + git init vanish/src && + scalar register vanish/src && + git config --get --global --fixed-value \ + maintenance.repo "$(pwd)/vanish/src" && + scalar list >scalar.repos && + grep -F "$(pwd)/vanish/src" scalar.repos && + rm -rf vanish/src/.git && + scalar unregister vanish && + test_must_fail git config --get --global --fixed-value \ + maintenance.repo "$(pwd)/vanish/src" && + scalar list >scalar.repos && + ! grep -F "$(pwd)/vanish/src" scalar.repos +' + test_done From patchwork Wed Oct 27 08:27:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12586641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7785C433EF for ; Wed, 27 Oct 2021 08:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1D5C60296 for ; Wed, 27 Oct 2021 08:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240911AbhJ0IaE (ORCPT ); Wed, 27 Oct 2021 04:30:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239134AbhJ0I3v (ORCPT ); Wed, 27 Oct 2021 04:29:51 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 055C4C061348 for ; Wed, 27 Oct 2021 01:27:26 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id o14so2636535wra.12 for ; Wed, 27 Oct 2021 01:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=QyrukTNVfouEeAzxOv26evBXhIGqbMFj9uesv2a/2bw=; b=NzA4o8HjFjQyJyKPSEkJ/c+PxzG5K64EY3/lVCbDAaFe6NJE91cJvOuphbuwCVCSPT 5r8GSyKJMZ3272k/AKdDLhoLT5lI5zyJ/+qnpZI4F8Xi+xZ7B3nXxoYMDx3gEbV4b+KW b3eEBCEXsffExZc7wVwQrmRA4W98G9Shjp8GgnjstmKHKXhGMd4YdIH0Hbfy5rNSFijr XbDt0snOXj2dXH7NKnjivvuCxo6iyJXclL6NUoPVAFtpBcuyL2YUNv2KwnQTiTVcqRbL JY8tvOZIEgNiuhUXilLZGLEw4uMfFBhYwy2ZeqkhciM5uP5UkpsNXGVPqQEB6M5VCHBg D8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=QyrukTNVfouEeAzxOv26evBXhIGqbMFj9uesv2a/2bw=; b=UlF5yu69DAUXlhW/CICG5g6VZ6SWD/hTPAQJb1AmZkbHpRB97NeRSVq1oL4bp3B0LJ /Ao8Vv51tW//hSIEynrtPTsEa5A1eByod+pYNr3VPpWN15QIjh/ZX3YtdyUEyaQq5De5 jVHUNK9BnDmy8PG5IAAxiMuxP+ORbe0HJpreRsl9E4ga3Ov/OJvjDLHlk5gQcoGcqaei /pdvEKz67yOYPdEw1l3yoFESIqOvUE/PlwJvh6iliQUw9UNDrFuJxgZSpbg5FyVPVL3u 1Q9S0XGqReA5891cc7v7mqCgJot4MUQK0pc6pzUWkGy7PNYW/OaP/vyCJTi5taidldGC tPbg== X-Gm-Message-State: AOAM531w02WmuKDV8kn8UOYyvHRFCyED8baFuZLr8Fb6GIQ1fo2V19w8 jbE7pYv8q4OMj+sbB6871Znx8ulNmhQ= X-Google-Smtp-Source: ABdhPJzZ9R45H3bHyUZNYqIYic4JLCRGwtTvTdjZWNhHGZkrrHhbI9dSokaAV/uduRH00vFsOMrdGw== X-Received: by 2002:a5d:6b86:: with SMTP id n6mr26876362wrx.334.1635323244700; Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f10sm22969656wri.84.2021.10.27.01.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Message-Id: <136aec439fd7e1c807088b57101df54bf6beb34f.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:11 +0000 Subject: [PATCH v6 07/15] scalar: implement 'scalar list' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The produced list simply consists of those repositories registered under the multi-valued `scalar.repo` config setting in the user's Git config. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 11 +++++++++++ contrib/scalar/scalar.txt | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index dc84ce0d5b2..d13eb951c3d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -250,6 +250,16 @@ static int unregister_dir(void) return res; } +static int cmd_list(int argc, const char **argv) +{ + if (argc != 1) + die(_("`scalar list` does not take arguments")); + + if (run_git("config", "--global", "--get-all", "scalar.repo", NULL) < 0) + return -1; + return 0; +} + static int cmd_register(int argc, const char **argv) { struct option options[] = { @@ -336,6 +346,7 @@ static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, { NULL, NULL}, diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index d9a79984492..f93e3d00efd 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,6 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] +scalar list scalar register [] scalar unregister [] @@ -28,11 +29,19 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. +depending on the subcommand. With the exception of `list`, all subcommands +expect to be run in an enlistment. COMMANDS -------- +List +~~~~ + +list:: + List enlistments that are currently registered by Scalar. This + subcommand does not need to be run inside an enlistment. + Register ~~~~~~~~ From patchwork Wed Oct 27 08:27:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53932C433FE for ; Wed, 27 Oct 2021 08:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 357A960296 for ; Wed, 27 Oct 2021 08:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240896AbhJ0IaJ (ORCPT ); Wed, 27 Oct 2021 04:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240914AbhJ0I37 (ORCPT ); Wed, 27 Oct 2021 04:29:59 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB174C061220 for ; Wed, 27 Oct 2021 01:27:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e12so2697259wra.4 for ; Wed, 27 Oct 2021 01:27:26 -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=THNxuNjkjie3PvkTGFPc/9wWIr7aUZYcqD4lRp2v8cU=; b=AkI+S0nGz5/egVdJ8TbEUs4aZ2zo/eC3OpVnUslAQYEAMhiceIhV16TvNtZ+gx7m3R 0Q80s/gy51NSkuNvYS0de5ynCSyJjecwh7iNI1ME+e/2X7u1S7TkBAg4AWn5T0rsJ9/f MAY/HBg8IryaFkuqkX/oL3nb/nY4uRbCPPle3PTAKKgD0cjwqWgnHQmnc9k6qN9QUjRr ePPt3AHrjpfd2CtIZeglE6CRUnt3U2rKAqYFwyoBLqtWpL6XslXASlArd54CMCzX6aTO 9ydJxKs3U5pGWatbjJazumsik0s3UDhQwTxkSVCcBwitKrduLD0XoncAm0wy0GrOa7SA S8ng== 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=THNxuNjkjie3PvkTGFPc/9wWIr7aUZYcqD4lRp2v8cU=; b=VGxjT593lMG8X0BCCdX/Owz56zrHL1G2sKsm8iMyEOQbz2RVX9pbIDpO0+awaQppAr dDqApSB6Qav95TNQXKczdZm9jc+UxqXrI4JVJlTeU7yso1jFEqCOFIiGQG8hOYVydfzy pG0S2DV/UN4Q/WuI30YpsjB6HBc10C05Hrk9Fa/QvCzJ4oOgsZHRjj4lHLW58Ey4+t2y vkUWuM97y2x0ob5cOlipXIuITDxHYQqn/k6RayH9zn9UYrJS3zjn+aAAQGZMz+jUVVf3 B0/QsVQizN8QGnRUYt4J9G7LwdzcKcujYiT3RpMadZwoSWqBaO36OaNIvMG6ENFWlifE GYaw== X-Gm-Message-State: AOAM5339g6tUnzQ1h/RsHwoA/dbt7ilfFkHuj/5Hk6UIRwgCYp9ETkX7 f9loi10RG7qb0fasX5gcwm77yzzlZK0= X-Google-Smtp-Source: ABdhPJwUgUvABQchQoMirZeMtSCho8VCJSIuZhMcCGyIVzp4ikdxXkk2RrfeiWmCvkqyK8WM0K5Qgg== X-Received: by 2002:a5d:6481:: with SMTP id o1mr38187167wri.60.1635323245320; Wed, 27 Oct 2021 01:27:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l6sm3002899wmq.17.2021.10.27.01.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:24 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:12 +0000 Subject: [PATCH v6 08/15] scalar: implement the `clone` subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This implements Scalar's opinionated `clone` command: it tries to use a partial clone and sets up a sparse checkout by default. In contrast to `git clone`, `scalar clone` sets up the worktree in the `src/` subdirectory, to encourage a separation between the source files and the build output (which helps Git tremendously because it avoids untracked files that have to be specifically ignored when refreshing the index). Also, it registers the repository for regular, scheduled maintenance, and configures a flurry of configuration settings based on the experience and experiments of the Microsoft Windows and the Microsoft Office development teams. Note: since the `scalar clone` command is by far the most commonly called `scalar` subcommand, we document it at the top of the manual page. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 201 +++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 32 ++++- contrib/scalar/t/t9099-scalar.sh | 32 +++++ 3 files changed, 262 insertions(+), 3 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index d13eb951c3d..0401462b9b3 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -7,6 +7,7 @@ #include "parse-options.h" #include "config.h" #include "run-command.h" +#include "refs.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -250,6 +251,205 @@ static int unregister_dir(void) return res; } +/* printf-style interface, expects `=` argument */ +static int set_config(const char *fmt, ...) +{ + struct strbuf buf = STRBUF_INIT; + char *value; + int res; + va_list args; + + va_start(args, fmt); + strbuf_vaddf(&buf, fmt, args); + va_end(args); + + value = strchr(buf.buf, '='); + if (value) + *(value++) = '\0'; + res = git_config_set_gently(buf.buf, value); + strbuf_release(&buf); + + return res; +} + +static char *remote_default_branch(const char *url) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + + cp.git_cmd = 1; + strvec_pushl(&cp.args, "ls-remote", "--symref", url, "HEAD", NULL); + if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { + const char *line = out.buf; + + while (*line) { + const char *eol = strchrnul(line, '\n'), *p; + size_t len = eol - line; + char *branch; + + if (!skip_prefix(line, "ref: ", &p) || + !strip_suffix_mem(line, &len, "\tHEAD")) { + line = eol + (*eol == '\n'); + continue; + } + + eol = line + len; + if (skip_prefix(p, "refs/heads/", &p)) { + branch = xstrndup(p, eol - p); + strbuf_release(&out); + return branch; + } + + error(_("remote HEAD is not a branch: '%.*s'"), + (int)(eol - p), p); + strbuf_release(&out); + return NULL; + } + } + warning(_("failed to get default branch name from remote; " + "using local default")); + strbuf_reset(&out); + + child_process_init(&cp); + cp.git_cmd = 1; + strvec_pushl(&cp.args, "symbolic-ref", "--short", "HEAD", NULL); + if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) { + strbuf_trim(&out); + return strbuf_detach(&out, NULL); + } + + strbuf_release(&out); + error(_("failed to get default branch name")); + return NULL; +} + +static int cmd_clone(int argc, const char **argv) +{ + const char *branch = NULL; + int full_clone = 0; + struct option clone_options[] = { + OPT_STRING('b', "branch", &branch, N_(""), + N_("branch to checkout after clone")), + OPT_BOOL(0, "full-clone", &full_clone, + N_("when cloning, create full working directory")), + OPT_END(), + }; + const char * const clone_usage[] = { + N_("scalar clone [] [--] []"), + NULL + }; + const char *url; + char *enlistment = NULL, *dir = NULL; + struct strbuf buf = STRBUF_INIT; + int res; + + argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0); + + if (argc == 2) { + url = argv[0]; + enlistment = xstrdup(argv[1]); + } else if (argc == 1) { + url = argv[0]; + + strbuf_addstr(&buf, url); + /* Strip trailing slashes, if any */ + while (buf.len > 0 && is_dir_sep(buf.buf[buf.len - 1])) + strbuf_setlen(&buf, buf.len - 1); + /* Strip suffix `.git`, if any */ + strbuf_strip_suffix(&buf, ".git"); + + enlistment = find_last_dir_sep(buf.buf); + if (!enlistment) { + die(_("cannot deduce worktree name from '%s'"), url); + } + enlistment = xstrdup(enlistment + 1); + } else { + usage_msg_opt(_("You must specify a repository to clone."), + clone_usage, clone_options); + } + + if (is_directory(enlistment)) + die(_("directory '%s' exists already"), enlistment); + + dir = xstrfmt("%s/src", enlistment); + + strbuf_reset(&buf); + if (branch) + strbuf_addf(&buf, "init.defaultBranch=%s", branch); + else { + char *b = repo_default_branch_name(the_repository, 1); + strbuf_addf(&buf, "init.defaultBranch=%s", b); + free(b); + } + + if ((res = run_git("-c", buf.buf, "init", "--", dir, NULL))) + goto cleanup; + + if (chdir(dir) < 0) { + res = error_errno(_("could not switch to '%s'"), dir); + goto cleanup; + } + + setup_git_directory(); + + /* common-main already logs `argv` */ + trace2_def_repo(the_repository); + + if (!branch && !(branch = remote_default_branch(url))) { + res = error(_("failed to get default branch for '%s'"), url); + goto cleanup; + } + + if (set_config("remote.origin.url=%s", url) || + set_config("remote.origin.fetch=" + "+refs/heads/*:refs/remotes/origin/*") || + set_config("remote.origin.promisor=true") || + set_config("remote.origin.partialCloneFilter=blob:none")) { + res = error(_("could not configure remote in '%s'"), dir); + goto cleanup; + } + + if (!full_clone && + (res = run_git("sparse-checkout", "init", "--cone", NULL))) + goto cleanup; + + if (set_recommended_config()) + return error(_("could not configure '%s'"), dir); + + if ((res = run_git("fetch", "--quiet", "origin", NULL))) { + warning(_("partial clone failed; attempting full clone")); + + if (set_config("remote.origin.promisor") || + set_config("remote.origin.partialCloneFilter")) { + res = error(_("could not configure for full clone")); + goto cleanup; + } + + if ((res = run_git("fetch", "--quiet", "origin", NULL))) + goto cleanup; + } + + if ((res = set_config("branch.%s.remote=origin", branch))) + goto cleanup; + if ((res = set_config("branch.%s.merge=refs/heads/%s", + branch, branch))) + goto cleanup; + + strbuf_reset(&buf); + strbuf_addf(&buf, "origin/%s", branch); + res = run_git("checkout", "-f", "-t", buf.buf, NULL); + if (res) + goto cleanup; + + res = register_dir(); + +cleanup: + free(enlistment); + free(dir); + strbuf_release(&buf); + return res; +} + static int cmd_list(int argc, const char **argv) { if (argc != 1) @@ -346,6 +546,7 @@ static struct { const char *name; int (*fn)(int, const char **); } builtins[] = { + { "clone", cmd_clone }, { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f93e3d00efd..e8730967f16 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,6 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] +scalar clone [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -29,12 +30,37 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `list`, all subcommands -expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone` and `list`, all +subcommands expect to be run in an enlistment. COMMANDS -------- +Clone +~~~~~ + +clone [] []:: + Clones the specified repository, similar to linkgit:git-clone[1]. By + default, only commit and tree objects are cloned. Once finished, the + worktree is located at `/src`. ++ +The sparse-checkout feature is enabled (except when run with `--full-clone`) +and the only files present are those in the top-level directory. Use +`git sparse-checkout set` to expand the set of directories you want to see, +or `git sparse-checkout disable` to expand to all files (see +linkgit:git-sparse-checkout[1] for more details). You can explore the +subdirectories outside your sparse-checkout by using `git ls-tree +HEAD[:]`. + +-b :: +--branch :: + Instead of checking out the branch pointed to by the cloned + repository's HEAD, check out the `` branch instead. + +--[no-]full-clone:: + A sparse-checkout is initialized by default. This behavior can be + turned off via `--full-clone`. + List ~~~~ @@ -64,7 +90,7 @@ unregister []:: SEE ALSO -------- -linkgit:git-maintenance[1]. +linkgit:git-clone[1], linkgit:git-maintenance[1]. Scalar --- diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index ef0e8d680d5..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 Oct 27 08:27:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50B9AC433EF for ; Wed, 27 Oct 2021 08:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32E0B610A5 for ; Wed, 27 Oct 2021 08:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240960AbhJ0IaK (ORCPT ); Wed, 27 Oct 2021 04:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240919AbhJ0IaA (ORCPT ); Wed, 27 Oct 2021 04:30:00 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D4F2C061226 for ; Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d10so2734259wrb.1 for ; Wed, 27 Oct 2021 01:27:27 -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=aQ+QGgdrhU/K/8kJGcFYpcyWyJs67bJ2MtdVzXvmszA=; b=h7nlveD3Ja8Xyaz+V9fs66JhGXYsM3E9hvxiErhCfsFVPjS1MJ9XKEtIAeTxxIHS0z 6XOS7v7v8BsNL7SLoXzQ8USyMwKaxS7jspvvYZeZTxDbXzVaurnm+MIBybbTiQgM9U7Y yL4rHvPa7IEo7HcajRaq/vr88cByjkBAsAoTAb/VrVvk8Mzsap2H5D3Sg3l9jhHwavKv JFdmciITCNMG/TihHeVo6q374XBm3c+BiFAAjrSQ1QNhUmLwPz6inXXxm7DQPCS47sHC J4DAXrm7LpKQnB1aGuaCJDh7/3tX1nP1IFViwMMzLasO6gzcSmt0gAM1Qsjv5hSTwS3G ZRjA== 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=aQ+QGgdrhU/K/8kJGcFYpcyWyJs67bJ2MtdVzXvmszA=; b=XIeBYPR/4C/3DALDGfUEJn6ZwKjabrzdt767cRmQ90r5YrJoUhI/jn98GZgBWstNYG MjGNQbMPd8g8ZeuJNcFsu+BAnDVtY/FGb/fol/o+LyrlvExC1zgylUsNFTZ9CoVAosrR ytZjx9VORIx9NxOW2Mgide1+nc6F3HoAnYavgNwvOiqziQv3CYkDmQw2FiP6yQVqjQRN OT7EW+CS21KV8Uw++YlY9b7wLirkDeeRuFNYLRHf50Gd+e10N08n8DYAZA+dxJogJpuh EAM7EolOfvL4pVf5eLNdbv/VGKOFmZfBrdvSp5zEEXEZ8dH700XwBkq7K5SMrKYT7hEP TCCA== X-Gm-Message-State: AOAM531MCWtWlMZk9o6O+ja9UznxW0SBj01Rtjxk+02nEq8w70Pdfys0 DqwYF9kAc2btdl4d5A1Sozz/Vd9v4OM= X-Google-Smtp-Source: ABdhPJxKgcAagt4nDaA6UHBKx6NmmKlkm3Ql5Mkf/HK0dxmaHzja4ksOMdrJ8ivIFNd8QgYFPpRgeg== X-Received: by 2002:adf:ef51:: with SMTP id c17mr33053410wrp.28.1635323245894; Wed, 27 Oct 2021 01:27:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x10sm3421748wrt.76.2021.10.27.01.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:25 -0700 (PDT) Message-Id: <5ee54a9e25f00fab14511f81ebdd3ac8e89475a3.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:13 +0000 Subject: [PATCH v6 09/15] scalar: teach 'clone' to support the --single-branch option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Just like `git clone`, the `scalar clone` command now also offers to restrict the clone to a single branch. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 9 +++++++-- contrib/scalar/scalar.txt | 12 +++++++++++- contrib/scalar/t/t9099-scalar.sh | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 0401462b9b3..754e19d781d 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -326,12 +326,15 @@ static char *remote_default_branch(const char *url) static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; - int full_clone = 0; + int full_clone = 0, single_branch = 0; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), OPT_BOOL(0, "full-clone", &full_clone, N_("when cloning, create full working directory")), + OPT_BOOL(0, "single-branch", &single_branch, + N_("only download metadata for the branch that will " + "be checked out")), OPT_END(), }; const char * const clone_usage[] = { @@ -402,7 +405,9 @@ static int cmd_clone(int argc, const char **argv) if (set_config("remote.origin.url=%s", url) || set_config("remote.origin.fetch=" - "+refs/heads/*:refs/remotes/origin/*") || + "+refs/heads/%s:refs/remotes/origin/%s", + single_branch ? branch : "*", + single_branch ? branch : "*") || set_config("remote.origin.promisor=true") || set_config("remote.origin.partialCloneFilter=blob:none")) { res = error(_("could not configure remote in '%s'"), dir); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index e8730967f16..56f744a4aa9 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -8,7 +8,7 @@ scalar - an opinionated repository management tool SYNOPSIS -------- [verse] -scalar clone [--branch ] [--full-clone] [] +scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar list scalar register [] scalar unregister [] @@ -57,6 +57,16 @@ HEAD[:]`. Instead of checking out the branch pointed to by the cloned repository's HEAD, check out the `` branch instead. +--[no-]single-branch:: + Clone only the history leading to the tip of a single branch, either + specified by the `--branch` option or the primary branch remote's + `HEAD` points at. ++ +Further fetches into the resulting repository will only update the +remote-tracking branch for the branch this option was used for the initial +cloning. If the HEAD at the remote did not point at any branch when +`--single-branch` clone was made, no remote-tracking branch is created. + --[no-]full-clone:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 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 Oct 27 08:27:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12586647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B487EC433F5 for ; Wed, 27 Oct 2021 08:27:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F47E61073 for ; Wed, 27 Oct 2021 08:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240980AbhJ0IaO (ORCPT ); Wed, 27 Oct 2021 04:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240926AbhJ0IaB (ORCPT ); Wed, 27 Oct 2021 04:30:01 -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 E98F9C061229 for ; Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d13so2647371wrf.11 for ; Wed, 27 Oct 2021 01:27:27 -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=eLdul3jk7I0UMVOSFxEGqDEf7DigzLk/FEfs6EOhO/A=; b=Ppo08mxcSPHrj8nS61xjMtTK+p/VjbEbtSTnUb3JWPuA26d5YFordwbng1Hnp/Rx+5 5TDCIhhwgcTKhnGBj/VyHKO734PQfcwQ2iqNCOUq7O625jebC2qlZ8IJwMHiisnEqmA6 /gK2U3Wy8Lf8FO4GaTwHq2SKPMMbil5uaHOzkbPbFr+u0s9+vdX4u+HO+fJ6RKBFpfi6 JIH1kDLzwmUBbRvGDDWVkFiXBopEZ+e41CkCBjGA/OuXZWD8RNi0C1wvTzIJjH1MfPaZ BtywerHD/B8FwgKeg5ODlT9/fsI/7tr7HAeUK6SKHykdvBDio5XZAm4KomxPgfRc6f9T q+6w== 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=eLdul3jk7I0UMVOSFxEGqDEf7DigzLk/FEfs6EOhO/A=; b=q67kv2qBaQsCQ80euTn5TuSqQ194pV8pc0Whe68u9w4nkdzoThM/ban2l0p9V9mslf bo1yFBnse5Ym5oaPWr34RfTeOA6H7++O7Nd9SksB7KyTVMibaFE2uSfNDW0tUT6GFcL7 lGOsOyCdJXWAJtW/X76chTZ2//ViFw0YPKaMkskclT3+y2MCoY2oTfevhWdS8ZK2Du3f S1IDNKcpHah9vYf6GSEupZ4IxvJzDqRk4lI8TCjPt/UxNam9e1OeCheR5ylc1znLzhKN HOI7Yyzog005IdE35ssxjyg9eGB2sJ1YKlyK+rcVjIbOdcndWS+YbZtTdC0UyZlBaRW2 hMSA== X-Gm-Message-State: AOAM533b+2ZZhQWAU+lqyxyJmrE1BncXWE8ae6E38dHcFJ9jf41IVh7g AG6VVFkABda0ACJYELASZOeHJoBs8To= X-Google-Smtp-Source: ABdhPJxYdN74YUY8ojmBtnOwHKCRKXnfPfej23xr7K7lXp7zQqj8o6vOuiK1LyeSnAEBx6CiaRcRwg== X-Received: by 2002:adf:d1cd:: with SMTP id b13mr25969989wrd.178.1635323246478; Wed, 27 Oct 2021 01:27:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f1sm1339590wru.12.2021.10.27.01.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:26 -0700 (PDT) Message-Id: <3361eb8f09177f86849cb1c7737780668a313f5a.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:14 +0000 Subject: [PATCH v6 10/15] scalar: implement the `run` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Note: this subcommand is provided primarily for backwards-compatibility, for existing Scalar uses. It is mostly just a shim for `git maintenance`, mapping task names from the way Scalar called them to the way Git calls them. The reason why those names differ? The background maintenance was first implemented in Scalar, and when it was contributed as a patch series implementing the `git maintenance` command, reviewers suggested better names, those suggestions were accepted before the patches were integrated into core Git. Signed-off-by: Derrick Stolee Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 64 +++++++++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 19 ++++++++++++ 2 files changed, 83 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 754e19d781d..d9631287e12 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -483,6 +483,69 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_run(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + struct { + const char *arg, *task; + } tasks[] = { + { "config", NULL }, + { "commit-graph", "commit-graph" }, + { "fetch", "prefetch" }, + { "loose-objects", "loose-objects" }, + { "pack-files", "incremental-repack" }, + { NULL, NULL } + }; + struct strbuf buf = STRBUF_INIT; + const char *usagestr[] = { NULL, NULL }; + int i; + + strbuf_addstr(&buf, N_("scalar run []\nTasks:\n")); + for (i = 0; tasks[i].arg; i++) + strbuf_addf(&buf, "\t%s\n", tasks[i].arg); + usagestr[0] = buf.buf; + + argc = parse_options(argc, argv, NULL, options, + usagestr, 0); + + if (!argc) + usage_with_options(usagestr, options); + + if (!strcmp("all", argv[0])) { + i = -1; + } else { + for (i = 0; tasks[i].arg && strcmp(tasks[i].arg, argv[0]); i++) + ; /* keep looking for the task */ + + if (i > 0 && !tasks[i].arg) { + error(_("no such task: '%s'"), argv[0]); + usage_with_options(usagestr, options); + } + } + + argc--; + argv++; + setup_enlistment_directory(argc, argv, usagestr, options, NULL); + strbuf_release(&buf); + + if (i == 0) + return register_dir(); + + if (i > 0) + return run_git("maintenance", "run", + "--task", tasks[i].task, NULL); + + if (register_dir()) + return -1; + for (i = 1; tasks[i].arg; i++) + if (run_git("maintenance", "run", + "--task", tasks[i].task, NULL)) + return -1; + return 0; +} + static int remove_deleted_enlistment(struct strbuf *path) { int res = 0; @@ -555,6 +618,7 @@ static struct { { "list", cmd_list }, { "register", cmd_register }, { "unregister", cmd_unregister }, + { "run", cmd_run }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 56f744a4aa9..39143b08324 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -12,6 +12,7 @@ scalar clone [--single-branch] [--branch ] [--full-clone] [] scalar unregister [] +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] DESCRIPTION ----------- @@ -98,6 +99,24 @@ unregister []:: Remove the specified repository from the list of repositories registered with Scalar and stop the scheduled background maintenance. +Run +~~~ + +scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) []:: + Run the given maintenance task (or all tasks, if `all` was specified). + Except for `all` and `config`, this subcommand simply hands off to + linkgit:git-maintenance[1] (mapping `fetch` to `prefetch` and + `pack-files` to `incremental-repack`). ++ +These tasks are run automatically as part of the scheduled maintenance, +as soon as the repository is registered with Scalar. It should therefore +not be necessary to run this subcommand manually. ++ +The `config` task is specific to Scalar and configures all those +opinionated default settings that make Git work more efficiently with +large repositories. As this task is run as part of `scalar clone` +automatically, explicit invocations of this task are rarely needed. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. From patchwork Wed Oct 27 08:27:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC6D2C433FE for ; Wed, 27 Oct 2021 08:28:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5C9161073 for ; Wed, 27 Oct 2021 08:28:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240999AbhJ0Ia2 (ORCPT ); Wed, 27 Oct 2021 04:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240912AbhJ0IaE (ORCPT ); Wed, 27 Oct 2021 04:30:04 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64631C06122C for ; Wed, 27 Oct 2021 01:27:28 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id p14so2645330wrd.10 for ; Wed, 27 Oct 2021 01:27:28 -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=jJDYJo44Y8BM7lrDqtg86RWVN1sbIBqsCul47VJJ01s=; b=lgoGWhMGhVIehBsdKGdvBTqsF+12/hVfMyCbqXQEnkXoqUUF7BtwhwPJYx51+N+8Hm 7+oer5YhiTqb0Cafj0nIcVQUUWOGRbj/zMYTSi6FwpdHwkliK/9oLCfF9fRI0sQuJH8B oHkbg1joGA0U50dtj7riuHJMCMIeForPHiBS0jl+grStIXfIPbW+E3i8p3f7mvgDCqSW 96ZxBqwwqmQe16ZTpesfPKFZWuAicHNCB0UsMkhdC/WCd86GW1bkhqnRUkU6Xaf6b009 BVF2kwmf4sGFx3B21EjA2tfaZtpykF5HdBIKnDMBEje2gpnOyg/g7n0h2CcW9/oSKL/A KOZA== 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=jJDYJo44Y8BM7lrDqtg86RWVN1sbIBqsCul47VJJ01s=; b=UmpdTIt+AvdxS7Uwoz4n5JFMPdiSBnIlDr0ZrHkRj/y6DXZJ2XZcYiLVkZ4YkhGbkl jbE/exk8BGD/PfkvCa9BaN+G1myaAiTKF6SD8qrTyUOsndydBA2wR72U+TZUO9gpIVDu Rwo6b3z9D7N/xY7Xt2dRjU601VzgC0sPY4vxgZGBVe+delE2qv1K7Weiy0y/gg3VHaMu cnBhfwZ70iIxnWA6D7rFLNYsKBrkAN/d9s4Bx1wOIa2sdKQZBwlW8LhRovyiS3TIXyJc vyqnlU/IsLNZLIfKo88iEQxzyj+ROOUjsoRnMY6DAEPVY8m/ZsohQqYl2JhwwU/Zb5Wm qIkg== X-Gm-Message-State: AOAM530ZSADo2SIXq9cxs/EOwgRRXKshxU28tSA25RoMOQQiuNcigofW DZ0e8vGG5dK3Ez3Z4fWl6/OQMk37g0E= X-Google-Smtp-Source: ABdhPJwsO3tm4ALp2zLGP0pAXqvLekdhP7yywHCFqRYEA+raV8kRCIxULmXMeiY+jHDcRUBYNZGqvg== X-Received: by 2002:adf:f5c1:: with SMTP id k1mr16061458wrp.96.1635323247061; Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p12sm23056868wrr.67.2021.10.27.01.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:15 +0000 Subject: [PATCH v6 11/15] scalar: allow reconfiguring an existing enlistment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This comes in handy during Scalar upgrades, or when config settings were messed up by mistake. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 79 +++++++++++++++++++++----------- contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 8 ++++ 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index d9631287e12..6bebba0b51f 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -108,18 +108,20 @@ static int run_git(const char *arg, ...) return res; } -static int set_recommended_config(void) +static int set_recommended_config(int reconfigure) { struct { const char *key; const char *value; + int overwrite_on_reconfigure; } config[] = { - { "am.keepCR", "true" }, - { "core.FSCache", "true" }, - { "core.multiPackIndex", "true" }, - { "core.preloadIndex", "true" }, + /* Required */ + { "am.keepCR", "true", 1 }, + { "core.FSCache", "true", 1 }, + { "core.multiPackIndex", "true", 1 }, + { "core.preloadIndex", "true", 1 }, #ifndef WIN32 - { "core.untrackedCache", "true" }, + { "core.untrackedCache", "true", 1 }, #else /* * Unfortunately, Scalar's Functional Tests demonstrated @@ -133,28 +135,29 @@ static int set_recommended_config(void) * Therefore, with a sad heart, we disable this very useful * feature on Windows. */ - { "core.untrackedCache", "false" }, + { "core.untrackedCache", "false", 1 }, #endif - { "core.logAllRefUpdates", "true" }, - { "credential.https://dev.azure.com.useHttpPath", "true" }, - { "credential.validate", "false" }, /* GCM4W-only */ - { "gc.auto", "0" }, - { "gui.GCWarning", "false" }, - { "index.threads", "true" }, - { "index.version", "4" }, - { "merge.stat", "false" }, - { "merge.renames", "false" }, - { "pack.useBitmaps", "false" }, - { "pack.useSparse", "true" }, - { "receive.autoGC", "false" }, - { "reset.quiet", "true" }, - { "feature.manyFiles", "false" }, - { "feature.experimental", "false" }, - { "fetch.unpackLimit", "1" }, - { "fetch.writeCommitGraph", "false" }, + { "core.logAllRefUpdates", "true", 1 }, + { "credential.https://dev.azure.com.useHttpPath", "true", 1 }, + { "credential.validate", "false", 1 }, /* GCM4W-only */ + { "gc.auto", "0", 1 }, + { "gui.GCWarning", "false", 1 }, + { "index.threads", "true", 1 }, + { "index.version", "4", 1 }, + { "merge.stat", "false", 1 }, + { "merge.renames", "false", 1 }, + { "pack.useBitmaps", "false", 1 }, + { "pack.useSparse", "true", 1 }, + { "receive.autoGC", "false", 1 }, + { "reset.quiet", "true", 1 }, + { "feature.manyFiles", "false", 1 }, + { "feature.experimental", "false", 1 }, + { "fetch.unpackLimit", "1", 1 }, + { "fetch.writeCommitGraph", "false", 1 }, #ifdef WIN32 - { "http.sslBackend", "schannel" }, + { "http.sslBackend", "schannel", 1 }, #endif + /* Optional */ { "status.aheadBehind", "false" }, { "commitGraph.generationVersion", "1" }, { "core.autoCRLF", "false" }, @@ -165,7 +168,8 @@ static int set_recommended_config(void) char *value; for (i = 0; config[i].key; i++) { - if (git_config_get_string(config[i].key, &value)) { + if ((reconfigure && config[i].overwrite_on_reconfigure) || + git_config_get_string(config[i].key, &value)) { trace2_data_string("scalar", the_repository, config[i].key, "created"); if (git_config_set_gently(config[i].key, config[i].value) < 0) @@ -230,7 +234,7 @@ static int register_dir(void) int res = add_or_remove_enlistment(1); if (!res) - res = set_recommended_config(); + res = set_recommended_config(0); if (!res) res = toggle_maintenance(1); @@ -418,7 +422,7 @@ static int cmd_clone(int argc, const char **argv) (res = run_git("sparse-checkout", "init", "--cone", NULL))) goto cleanup; - if (set_recommended_config()) + if (set_recommended_config(0)) return error(_("could not configure '%s'"), dir); if ((res = run_git("fetch", "--quiet", "origin", NULL))) { @@ -483,6 +487,24 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int cmd_reconfigure(int argc, const char **argv) +{ + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar reconfigure []"), + NULL + }; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); +} + static int cmd_run(int argc, const char **argv) { struct option options[] = { @@ -619,6 +641,7 @@ static struct { { "register", cmd_register }, { "unregister", cmd_unregister }, { "run", cmd_run }, + { "reconfigure", cmd_reconfigure }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 39143b08324..89fd7901585 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,6 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] +scalar reconfigure DESCRIPTION ----------- @@ -117,6 +118,13 @@ opinionated default settings that make Git work more efficiently with large repositories. As this task is run as part of `scalar clone` automatically, explicit invocations of this task are rarely needed. +Reconfigure +~~~~~~~~~~~ + +After a Scalar upgrade, or when the configuration of a Scalar enlistment +was somehow corrupted or changed by mistake, this subcommand allows to +reconfigure the enlistment. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 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 Oct 27 08:27:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D0CBC433F5 for ; Wed, 27 Oct 2021 08:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67145610A0 for ; Wed, 27 Oct 2021 08:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240937AbhJ0Ia3 (ORCPT ); Wed, 27 Oct 2021 04:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240935AbhJ0IaF (ORCPT ); Wed, 27 Oct 2021 04:30:05 -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 E0BA4C06122D for ; Wed, 27 Oct 2021 01:27:28 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id u18so2685194wrg.5 for ; Wed, 27 Oct 2021 01:27:28 -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=UHdNpleWWnk7QKpjxZS5RZun9iiNN62/yifWwXMPxzA=; b=ScmHLntOiWlE5GVAv7OCZtc4apOYE9xhnU+AXOD/4lafPMtEx+a9mAacm4d0404q93 15kLEuAlXnSACiP7vfrB7kTT2MxGv2Y5jav715pe9+EqvDgSWT/OitHMdNBQiv1GBWad 9O8QjZsjrIY3pP5HfCEJWBeyBrPOoT6xTBcw47ds66WPWqUG/Jiflang8tNdtjjbngTL Ol/8ki44+XPSMPTASWqRgQJ8197NxLKHMoT9tdkz/WzLHcoOej5XFHrCKteYjfxXAWMg gVsH3AC0LGREkhDl819vuZM6cKij2MJ47q0kIVVprzobkFxeoMlLHXLra210it0N4Ndv 64Yg== 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=UHdNpleWWnk7QKpjxZS5RZun9iiNN62/yifWwXMPxzA=; b=T9UznRk3x0CFvLKd6fROh1wxGB2bkKOckjo29BVtzsgmRvLFHb9P/W/+T77SHvoqRH UrmaLN2SZiTd3I2Hv8Je9huxRBLQUYus+kXBzfnuXgS2eBQZVEPX/ZtbPHWRagTxNuZh ZAxPSSanXQEvGs+4HHvDkrrEQcF0VTdofRP7Jd5VC4M2+KmRzMvA804OycNN0CXB0UIz GPA4aymzobfekbVaOHlkLK+7DqYtopv9M+8vnWLUvTa2wiQV127WEJ2dZRoiyFgOQV03 0/ClhK/rwBjWtztDwk/JOAuypbaOZHJU31x7eURVtIsqJiYjKYrsyPhGwcCl876aajts ztUg== X-Gm-Message-State: AOAM530YsvY3E5GCiHkoJLnIAYA+3+4OevD2mkDF0t001mVztqwBO/tN aKFsmXC+yRBMEtWCVw5+RQzd0k4IuKc= X-Google-Smtp-Source: ABdhPJwC7H672A+FmB0Lj8SScQtSPT6BlDN1Jz0CuePCqWoqkAsFEtUR8GogxAEKwUJYRymapfrAWQ== X-Received: by 2002:a5d:4a82:: with SMTP id o2mr39114136wrq.434.1635323247573; Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r10sm13983063wrl.92.2021.10.27.01.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:16 +0000 Subject: [PATCH v6 12/15] scalar: teach 'reconfigure' to optionally handle all registered enlistments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin After a Scalar upgrade, it can come in really handy if there is an easy way to reconfigure all Scalar enlistments. This new option offers this functionality. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 61 ++++++++++++++++++++++++++++++-- contrib/scalar/scalar.txt | 9 +++-- contrib/scalar/t/t9099-scalar.sh | 3 ++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 6bebba0b51f..234a7dce479 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -487,22 +487,77 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int get_scalar_repos(const char *key, const char *value, void *data) +{ + struct string_list *list = data; + + if (!strcmp(key, "scalar.repo")) + string_list_append(list, value); + + return 0; +} + static int cmd_reconfigure(int argc, const char **argv) { + int all = 0; struct option options[] = { + OPT_BOOL('a', "all", &all, + N_("reconfigure all registered enlistments")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure []"), + N_("scalar reconfigure [--all | ]"), NULL }; + struct string_list scalar_repos = STRING_LIST_INIT_DUP; + int i, res = 0; + struct repository r = { NULL }; + struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT; argc = parse_options(argc, argv, NULL, options, usage, 0); - setup_enlistment_directory(argc, argv, usage, options, NULL); + if (!all) { + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); + } + + if (argc > 0) + usage_msg_opt(_("--all or , but not both"), + usage, options); + + git_config(get_scalar_repos, &scalar_repos); - return set_recommended_config(1); + for (i = 0; i < scalar_repos.nr; i++) { + const char *dir = scalar_repos.items[i].string; + + strbuf_reset(&commondir); + strbuf_reset(&gitdir); + + if (chdir(dir) < 0) { + warning_errno(_("could not switch to '%s'"), dir); + res = -1; + } else if (discover_git_directory(&commondir, &gitdir) < 0) { + warning_errno(_("git repository gone in '%s'"), dir); + res = -1; + } else { + git_config_clear(); + + the_repository = &r; + r.commondir = commondir.buf; + r.gitdir = gitdir.buf; + + if (set_recommended_config(1) < 0) + res = -1; + } + } + + string_list_clear(&scalar_repos, 1); + strbuf_release(&commondir); + strbuf_release(&gitdir); + + return res; } static int cmd_run(int argc, const char **argv) diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 89fd7901585..737cf563c1a 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,7 +13,7 @@ scalar list scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] -scalar reconfigure +scalar reconfigure [ --all | ] DESCRIPTION ----------- @@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `clone` and `list`, all -subcommands expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone`, `list` and +`reconfigure --all`, all subcommands expect to be run in an enlistment. COMMANDS -------- @@ -125,6 +125,9 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment was somehow corrupted or changed by mistake, this subcommand allows to reconfigure the enlistment. +With the `--all` option, all enlistments currently registered with Scalar +will be reconfigured. Use this option after each Scalar upgrade. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 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 Oct 27 08:27:17 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: 12586661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2584CC433EF for ; Wed, 27 Oct 2021 08:28:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E06C61090 for ; Wed, 27 Oct 2021 08:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240945AbhJ0Iab (ORCPT ); Wed, 27 Oct 2021 04:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240943AbhJ0IaF (ORCPT ); Wed, 27 Oct 2021 04:30:05 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA920C06122F for ; Wed, 27 Oct 2021 01:27:29 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id j2-20020a1c2302000000b0032ca9b0a057so1620636wmj.3 for ; Wed, 27 Oct 2021 01:27:29 -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=LsnYG1NdA6AzQDz9+MnzYCvyx4uf9jKqkP91nSQVJYA=; b=mkDw/W3FWPlG9YbPz89e1pLmWY8T9xFYmnZASLhB+0cEm3y5eSQCqJRDAoln8a418Y Ov9F8iTuPh4pFSDZPMOkszVQ+BhQDjlwZM7+BAgmeVwzhSOhnOsMVzcGKoloaOmSQTXU 5kLdu5zZe934p32PqOJSby4+J/jsk3ngELOlptCyPvn3PutGQ2VUMUxvGheF7S9gVQLc FTbXKxdlxpl5Lg/xre8vMCZOJstel4BR2j+VH7guwtdiiNUqz3BbEfd7KaIk0gCT/Nyo MipTiPNP2MN6c8dQwlxVs8RLe1Qmm7e9/jzG0EmXYk4tM4bXkdU2XLZJ466RyYp5NgAt KSKw== 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=LsnYG1NdA6AzQDz9+MnzYCvyx4uf9jKqkP91nSQVJYA=; b=HHDOaABNlGQUGvNqRP2tVCAsyRQhqFQaRzicr65LIn+mmt4vKwy55CpiM3io7PuoF1 npDb8925vmnDnmT5hfhQV1slGaSv9AASB/2I4l1GyIviEjpywXRe6Gt5bDqX4CJ0dS1z Ed8vUKfaagCMyKXHb2KszdmZs4JrrbWn16AvPEzHq76ofMHuvGWvDah4/9Mu1cMz7aH0 V7yAPDRMdpEIn3tYnqlNKWogJJLw0+Cf3Z6WM8E17jdEjCQW9ribhDanGTeubISjOo/Z C8BGbVpxNyv8Q2lwLCT9EZzJqg3q1R9PnO1P2DhmRkIGDXua9a+1uQfqQr487bHOtm8j Z0Fg== X-Gm-Message-State: AOAM530Wk1Kz7wfhUEoWKjS5wlB82yB7dlXgJ7u0ScxEe+WEFDYVp+Kv ByL7iITV+Rn2fG1A/WCgxG212ievweQ= X-Google-Smtp-Source: ABdhPJw2SrSlnK4JTxlAQogD7uzi7O97baWzrI6pWYEt76fyYPBoamSNuos1nWX/3kIfsT1p8GxrdQ== X-Received: by 2002:a05:600c:2049:: with SMTP id p9mr2806774wmg.36.1635323248342; Wed, 27 Oct 2021 01:27:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y5sm12139020wrd.75.2021.10.27.01.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:27 -0700 (PDT) Message-Id: <843026d54812dd5408270b4ddc2ba9873819e631.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:17 +0000 Subject: [PATCH v6 13/15] scalar: implement the `delete` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Matthew John Cheetham Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew John Cheetham From: Matthew John Cheetham Delete an enlistment by first unregistering the repository and then deleting the enlistment directory (usually the directory containing the worktree `src/` directory). On Windows, if the current directory is inside the enlistment's directory, change to the parent of the enlistment directory, to allow us to delete the enlistment (directories used by processes e.g. as current working directories cannot be deleted on Windows). Co-authored-by: Victoria Dye Signed-off-by: Matthew John Cheetham Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 63 ++++++++++++++++++++++++++++++++ contrib/scalar/scalar.txt | 8 ++++ contrib/scalar/t/t9099-scalar.sh | 9 +++++ 3 files changed, 80 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 234a7dce479..8aaeca7cc64 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -8,6 +8,8 @@ #include "config.h" #include "run-command.h" #include "refs.h" +#include "dir.h" +#include "packfile.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -327,6 +329,33 @@ static char *remote_default_branch(const char *url) return NULL; } +static int delete_enlistment(struct strbuf *enlistment) +{ +#ifdef WIN32 + struct strbuf parent = STRBUF_INIT; +#endif + + if (unregister_dir()) + die(_("failed to unregister repository")); + +#ifdef WIN32 + /* + * Change the current directory to one outside of the enlistment so + * that we may delete everything underneath it. + */ + strbuf_addbuf(&parent, enlistment); + strbuf_parent_directory(&parent); + if (chdir(parent.buf) < 0) + die_errno(_("could not switch to '%s'"), parent.buf); + strbuf_release(&parent); +#endif + + if (remove_dir_recursively(enlistment, 0)) + die(_("failed to delete enlistment directory")); + + return 0; +} + static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; @@ -687,6 +716,39 @@ static int cmd_unregister(int argc, const char **argv) return unregister_dir(); } +static int cmd_delete(int argc, const char **argv) +{ + char *cwd = xgetcwd(); + struct option options[] = { + OPT_END(), + }; + const char * const usage[] = { + N_("scalar delete "), + NULL + }; + struct strbuf enlistment = STRBUF_INIT; + int res = 0; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + if (argc != 1) + usage_with_options(usage, options); + + setup_enlistment_directory(argc, argv, usage, options, &enlistment); + + if (dir_inside_of(cwd, enlistment.buf) >= 0) + res = error(_("refusing to delete current working directory")); + else { + close_object_store(the_repository->objects); + res = delete_enlistment(&enlistment); + } + strbuf_release(&enlistment); + free(cwd); + + return res; +} + static struct { const char *name; int (*fn)(int, const char **); @@ -697,6 +759,7 @@ static struct { { "unregister", cmd_unregister }, { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, + { "delete", cmd_delete }, { NULL, NULL}, }; diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 737cf563c1a..f416d637289 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -14,6 +14,7 @@ scalar register [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] scalar reconfigure [ --all | ] +scalar delete DESCRIPTION ----------- @@ -128,6 +129,13 @@ reconfigure the enlistment. With the `--all` option, all enlistments currently registered with Scalar will be reconfigured. Use this option after each Scalar upgrade. +Delete +~~~~~~ + +delete :: + This subcommand lets you delete an existing Scalar enlistment from your + local file system, unregistering the repository. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 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 Oct 27 08:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15CF3C433F5 for ; Wed, 27 Oct 2021 08:28:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0197B61073 for ; Wed, 27 Oct 2021 08:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241002AbhJ0Iad (ORCPT ); Wed, 27 Oct 2021 04:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239115AbhJ0IaH (ORCPT ); Wed, 27 Oct 2021 04:30:07 -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 36A32C061232 for ; Wed, 27 Oct 2021 01:27:30 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u18so2685316wrg.5 for ; Wed, 27 Oct 2021 01:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=cq7xpzv9Jt0r+m3QH1PsZIBW9iGrieo+DLK5++RfiqM=; b=oFdw7oeiNKexhnTovaZ2H5pNYmOpnVh100E0hnn/QOak9Lyn0BGEca6avMMqkYqE6+ UlygtapeVIfDKgWB9OfTSCZPHRm7PMGOQXdnOH5XojmCAClactqEZO4VMyzPmW5r0a5P 0yEs2PlnAUPpUx8x1gXHJ3zcBSKC3bwjJUeeHVJnvmbLhZeEoAjUqWpqwSCtc7l1f5n2 pT7D8t5XvnBYgTbSNlITg6Ay2RhSr/dzmlfY1bVviWcbFvwTpv70GJDOsPaSwazJ6VW0 CkDYQzsXQYu202Iqx0qFWKSl40llECamjiAk9byhQ+XCT4QgQ2QwL5e98KwnaRCcNR2b A4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=cq7xpzv9Jt0r+m3QH1PsZIBW9iGrieo+DLK5++RfiqM=; b=nRbwG1iTi4dOG3mLyZ00DkSLyZ/1FDbV9TAaJAb0+STkikXQ7bgyQde7OJKTPYJR0z +GcWkzrZ2+VsZEP8v8ctVfE3ErK422+viZt7AAGm9pqwLsRoiiYz34gpjhOwcJ0QfVqJ CQd4RWWcw1dKJjMLxFhU0CAFv/dt38pH3KzExyfSBMniMAHZrojIdgkLndlhbHHFqwfq 3DcveK5UWWII5dwuv0geuMEqdWtYi/9wNVsmY9lxGtV1X/TDxdNHqI6rt2xX3s8aYGgq 6aOJ2PATF+jrae/45C06dYhlyrew4LAa62IhRZjX3UDRiSg+h+5dC5PpTCFV/4UxQ2+0 68iA== X-Gm-Message-State: AOAM532+aPvnxd04xo/A1CZrFeryooRfB8EWQy+lMVD3glXboyu+W1Vt 8rBjJlXpLGVV/Q/LxXSeNT51p7s38zM= X-Google-Smtp-Source: ABdhPJxwaWxHhsjSU71/Ur9x/+r9c8GERKGelOVcBluu7EdIo9muIeMY7/fQurb8JA53UCV6CHWmag== X-Received: by 2002:adf:b350:: with SMTP id k16mr38497497wrd.368.1635323248877; Wed, 27 Oct 2021 01:27:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g2sm21633262wrb.20.2021.10.27.01.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:28 -0700 (PDT) Message-Id: <5ca169b3f3a0aead986ba2e7bb31ae5678bdc37a.1635323239.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:18 +0000 Subject: [PATCH v6 14/15] scalar: implement the `version` command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The .NET version of Scalar has a `version` command. This was necessary because it was versioned independently of Git. Since Scalar is now tightly coupled with Git, it does not make sense for them to show different versions. Therefore, it shows the same output as `git version`. For backwards-compatibility with the .NET version, `scalar version` prints to `stderr`, though (`git version` prints to `stdout` instead). Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 8aaeca7cc64..b2e92cf63b5 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -10,6 +10,7 @@ #include "refs.h" #include "dir.h" #include "packfile.h" +#include "help.h" /* * Remove the deepest subdirectory in the provided path string. Path must not @@ -356,6 +357,15 @@ static int delete_enlistment(struct strbuf *enlistment) return 0; } +/* + * Dummy implementation; Using `get_version_info()` would cause a link error + * without this. + */ +void load_builtin_commands(const char *prefix, struct cmdnames *cmds) +{ + die("not implemented"); +} + static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; @@ -749,6 +759,34 @@ static int cmd_delete(int argc, const char **argv) return res; } +static int cmd_version(int argc, const char **argv) +{ + int verbose = 0, build_options = 0; + struct option options[] = { + OPT__VERBOSE(&verbose, N_("include Git version")), + OPT_BOOL(0, "build-options", &build_options, + N_("include Git's build options")), + OPT_END(), + }; + const char * const usage[] = { + N_("scalar verbose [-v | --verbose] [--build-options]"), + NULL + }; + struct strbuf buf = STRBUF_INIT; + + argc = parse_options(argc, argv, NULL, options, + usage, 0); + + if (argc != 0) + usage_with_options(usage, options); + + get_version_info(&buf, build_options); + fprintf(stderr, "%s\n", buf.buf); + strbuf_release(&buf); + + return 0; +} + static struct { const char *name; int (*fn)(int, const char **); @@ -760,6 +798,7 @@ static struct { { "run", cmd_run }, { "reconfigure", cmd_reconfigure }, { "delete", cmd_delete }, + { "version", cmd_version }, { NULL, NULL}, }; From patchwork Wed Oct 27 08:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12586665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB1D7C433EF for ; Wed, 27 Oct 2021 08:28:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCBA161073 for ; Wed, 27 Oct 2021 08:28:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241010AbhJ0Iag (ORCPT ); Wed, 27 Oct 2021 04:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240949AbhJ0IaI (ORCPT ); Wed, 27 Oct 2021 04:30:08 -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 C6B9EC061233 for ; Wed, 27 Oct 2021 01:27:30 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j2-20020a1c2302000000b0032ca9b0a057so1620684wmj.3 for ; Wed, 27 Oct 2021 01:27:30 -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=x4VHMf5Ie9TYvQ9UrPa0BHCWFCVGGp9dxV4hFNAFBh4=; b=C1Li2CiyMGhLXyH8mBLhdTW/kL4GoWU7tHU1pBN9PKG426Yj82uf3D10L/s38rGic7 3qzIt6ughxJylFYHWWQ0g0m0/3Sn05WPSVuOLo500Y5I1zCbFeb9ssowL/j4ts+7H1KZ PWG7wgTFQjluNrc4/c8fz7r4+CrE7pMRiZuuiFd1Qr0lbHXVIRORVErwztKLSpsS+1DC BXCuNqa1s1icRbvcQKGBIBbJ0oPXjd3JHxQyBp5K3Cj9dOV6121RESCrHsLKPvnPE4X1 dXq2ttTd/GjPv6eA3Z7E8Xs+/27Hnk6iXbiE0+AmgxQcj1JMk+pLpkshKMd4+Tns/8AJ u3SA== 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=x4VHMf5Ie9TYvQ9UrPa0BHCWFCVGGp9dxV4hFNAFBh4=; b=qD/7fXFtYhpKTQHWGhp6Y8ViOrOb27ldCgvHDd1FRDat4p18tc9d5Y4lhyW5JL6SBA lityJvu2QWvM02tjA0H5g1zYJdhv4xeNgNHHsBE+SllFKXHN+S97lHezTk1RgC5DQHfq 5F40EQRkDZo9KbxMyaTYtbeR6zQJpbcwUto4pIvzgT+I0YhMbeFhoK2fmqDjcx9yCtht fzxcxkc2E6WyDJJIrBmwdQPWix+MP/qby14NC6umwaoUzU9IFnJ8023H/T1mpO0sZuvY l1xq/aBEGkoYw2v7MbCYFptb/mrks4MKXXK+28Me36tVNyEwah67tvf5ZKn/yImrIJMx xwJQ== X-Gm-Message-State: AOAM531XtRHboeuw2gf9WVtL1mKnYUfvIBsWJgSp8ObJmBDWGg/6XkGt qxO1HnxZhkVMtYQ/otnlwVjHceypEFc= X-Google-Smtp-Source: ABdhPJzaVQy03cS3hcZtuQ5gls9jJYge8ALBKo2/5uN3ZELlz+0Pf2D2vAjuLMScrYDVZVmUt1j6Rw== X-Received: by 2002:a7b:c4c4:: with SMTP id g4mr3111886wmk.93.1635323249424; Wed, 27 Oct 2021 01:27:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t6sm15316710wrw.78.2021.10.27.01.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:27:29 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 27 Oct 2021 08:27:19 +0000 Subject: [PATCH v6 15/15] scalar: accept -C and -c options before the subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `git` executable has these two very useful options: -C : switch to the specified directory before performing any actions -c =: temporarily configure this setting for the duration of the specified scalar subcommand With this commit, we teach the `scalar` executable the same trick. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 22 +++++++++++++++++++++- contrib/scalar/scalar.txt | 10 ++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index b2e92cf63b5..6c496318bd4 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -807,6 +807,25 @@ int cmd_main(int argc, const char **argv) struct strbuf scalar_usage = STRBUF_INIT; int i; + while (argc > 1 && *argv[1] == '-') { + if (!strcmp(argv[1], "-C")) { + if (argc < 3) + die(_("-C requires a ")); + if (chdir(argv[2]) < 0) + die_errno(_("could not change to '%s'"), + argv[2]); + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-c")) { + if (argc < 3) + die(_("-c requires a = argument")); + git_config_push_parameter(argv[2]); + argc -= 2; + argv += 2; + } else + break; + } + if (argc > 1) { argv++; argc--; @@ -817,7 +836,8 @@ int cmd_main(int argc, const char **argv) } strbuf_addstr(&scalar_usage, - N_("scalar []\n\nCommands:\n")); + N_("scalar [-C ] [-c =] " + " []\n\nCommands:\n")); for (i = 0; builtins[i].name; i++) strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index f416d637289..cf4e5b889cc 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 --------