Skip to content

Commit 0a43fb2

Browse files
dschogitster
authored andcommitted
scalar: create a rudimentary executable
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 <url>` 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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cd5a9ac commit 0a43fb2

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,11 @@ OBJECTS += $(FUZZ_OBJS)
24502450
ifndef NO_CURL
24512451
OBJECTS += http.o http-walker.o remote-curl.o
24522452
endif
2453+
2454+
SCALAR_SOURCES := contrib/scalar/scalar.c
2455+
SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o)
2456+
OBJECTS += $(SCALAR_OBJECTS)
2457+
24532458
.PHONY: objects
24542459
objects: $(OBJECTS)
24552460

@@ -2583,6 +2588,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
25832588
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
25842589
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
25852590

2591+
contrib/scalar/scalar$X: $(SCALAR_OBJECTS) GIT-LDFLAGS $(GITLIBS)
2592+
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
2593+
$(filter %.o,$^) $(LIBS)
2594+
25862595
$(LIB_FILE): $(LIB_OBJS)
25872596
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
25882597

contrib/scalar/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*.exe
2+
/scalar

contrib/scalar/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
2+
QUIET_SUBDIR1 =
3+
4+
ifneq ($(findstring s,$(MAKEFLAGS)),s)
5+
ifndef V
6+
QUIET_SUBDIR0 = +@subdir=
7+
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
8+
$(MAKE) $(PRINT_DIR) -C $$subdir
9+
else
10+
export V
11+
endif
12+
endif
13+
14+
all:
15+
16+
include ../../config.mak.uname
17+
-include ../../config.mak.autogen
18+
-include ../../config.mak
19+
20+
TARGETS = scalar$(X) scalar.o
21+
GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a
22+
23+
all: scalar$(X)
24+
25+
$(GITLIBS):
26+
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@)
27+
28+
$(TARGETS): $(GITLIBS) scalar.c
29+
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@)
30+
31+
clean:
32+
$(RM) $(TARGETS)
33+
34+
.PHONY: $(GITLIBS) all clean FORCE

contrib/scalar/scalar.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* The Scalar command-line interface.
3+
*/
4+
5+
#include "cache.h"
6+
#include "gettext.h"
7+
#include "parse-options.h"
8+
9+
static struct {
10+
const char *name;
11+
int (*fn)(int, const char **);
12+
} builtins[] = {
13+
{ NULL, NULL},
14+
};
15+
16+
int cmd_main(int argc, const char **argv)
17+
{
18+
struct strbuf scalar_usage = STRBUF_INIT;
19+
int i;
20+
21+
if (argc > 1) {
22+
argv++;
23+
argc--;
24+
25+
for (i = 0; builtins[i].name; i++)
26+
if (!strcmp(builtins[i].name, argv[0]))
27+
return !!builtins[i].fn(argc, argv);
28+
}
29+
30+
strbuf_addstr(&scalar_usage,
31+
N_("scalar <command> [<options>]\n\nCommands:\n"));
32+
for (i = 0; builtins[i].name; i++)
33+
strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name);
34+
35+
usage(scalar_usage.buf);
36+
}

0 commit comments

Comments
 (0)