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); +}