Skip to content

Commit

Permalink
Merge pull request #366 from dscho/features/scalar-2.32.0
Browse files Browse the repository at this point in the history
Integrate Scalar (ported to C) into vfs-2.32.0
  • Loading branch information
dscho authored and derrickstolee committed Nov 15, 2021
2 parents 77dff8d + 14439a3 commit c82b384
Show file tree
Hide file tree
Showing 18 changed files with 2,744 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]

env:
DEVELOPER: 1
INCLUDE_SCALAR: YesPlease

jobs:
ci-config:
Expand Down
9 changes: 9 additions & 0 deletions Documentation/config/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,12 @@ core.abbrev::
If set to "no", no abbreviation is made and the object names
are shown in their full length.
The minimum length is 4.

core.configWriteLockTimeoutMS::
When processes try to write to the config concurrently, it is likely
that one process "wins" and the other process(es) fail to lock the
config file. By configuring a timeout larger than zero, Git can be
told to try to lock the config again a couple times within the
specified timeout. If the timeout is configure to zero (which is the
default), Git will fail immediately when the config is already
locked.
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,10 @@ ifndef PAGER_ENV
PAGER_ENV = LESS=FRX LV=-c
endif

ifneq (,$(INCLUDE_SCALAR))
EXTRA_PROGRAMS += contrib/scalar/scalar$X
endif

QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =

Expand Down Expand Up @@ -2502,6 +2506,10 @@ endif
.PHONY: objects
objects: $(OBJECTS)

SCALAR_SOURCES := contrib/scalar/scalar.c contrib/scalar/json-parser.c
SCALAR_OBJECTS := $(SCALAR_SOURCES:c=o)
OBJECTS += $(SCALAR_OBJECTS)

dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))

Expand Down Expand Up @@ -2639,6 +2647,13 @@ $(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)

bin-wrappers/scalar: contrib/scalar/Makefile
$(QUIET_SUBDIR0)contrib/scalar $(QUIET_SUBDIR1) ../../bin-wrappers/scalar

git-gvfs-helper$X: gvfs-helper.o http.o GIT-LDFLAGS $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
Expand All @@ -2662,14 +2677,23 @@ Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
.PHONY: doc man man-perl html info pdf
doc: man-perl
$(MAKE) -C Documentation all
ifneq (,$(INCLUDE_SCALAR))
$(QUIET_SUBDIR0)contrib/scalar $(QUIET_SUBDIR1) scalar.html scalar.1
endif

man: man-perl
$(MAKE) -C Documentation man
ifneq (,$(INCLUDE_SCALAR))
$(QUIET_SUBDIR0)contrib/scalar $(QUIET_SUBDIR1) scalar.1
endif

man-perl: perl/build/man/man3/Git.3pm

html:
$(MAKE) -C Documentation html
ifneq (,$(INCLUDE_SCALAR))
$(QUIET_SUBDIR0)contrib/scalar $(QUIET_SUBDIR1) scalar.html
endif

info:
$(MAKE) -C Documentation info
Expand Down Expand Up @@ -2923,6 +2947,10 @@ endif

test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))

ifneq (,$(INCLUDE_SCALAR))
test_bindir_programs += bin-wrappers/scalar
endif

all:: $(TEST_PROGRAMS) $(test_bindir_programs)

bin-wrappers/%: wrap-for-bin.sh
Expand All @@ -2943,6 +2971,9 @@ export TEST_NO_MALLOC_CHECK

test: all
$(MAKE) -C t/ all
ifneq (,$(INCLUDE_SCALAR))
$(MAKE) -C contrib/scalar/t
endif

perf: all
$(MAKE) -C t/perf/ all
Expand Down Expand Up @@ -3077,6 +3108,9 @@ install: all
$(INSTALL) $(INSTALL_STRIP) $(install_bindir_xprograms) '$(DESTDIR_SQ)$(bindir_SQ)'
$(INSTALL) $(BINDIR_PROGRAMS_NO_X) '$(DESTDIR_SQ)$(bindir_SQ)'

ifneq (,$(INCLUDE_SCALAR))
$(INSTALL) contrib/scalar/scalar$X '$(DESTDIR_SQ)$(bindir_SQ)'
endif
ifdef MSVC
# We DO NOT install the individual foo.o.pdb files because they
# have already been rolled up into the exe's pdb file.
Expand Down Expand Up @@ -3169,6 +3203,10 @@ install-doc: install-man-perl

install-man: install-man-perl
$(MAKE) -C Documentation install-man
ifneq (,$(INCLUDE_SCALAR))
$(MAKE) -C contrib/scalar scalar.1
$(INSTALL) contrib/scalar/scalar.1 '$(DESTDIR_SQ)$(mandir_SQ)/man1'
endif

install-man-perl: man-perl
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mandir_SQ)/man3'
Expand All @@ -3177,6 +3215,10 @@ install-man-perl: man-perl

install-html:
$(MAKE) -C Documentation install-html
ifneq (,$(INCLUDE_SCALAR))
$(MAKE) -C contrib/scalar scalar.html
$(INSTALL) contrib/scalar/scalar.html '$(DESTDIR_SQ)$(htmldir)'
endif

install-info:
$(MAKE) -C Documentation install-info
Expand Down Expand Up @@ -3315,6 +3357,9 @@ endif
ifndef NO_TCLTK
$(MAKE) -C gitk-git clean
$(MAKE) -C git-gui clean
endif
ifneq (,$(INCLUDE_SCALAR))
$(MAKE) -C contrib/scalar clean
endif
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
$(RM) GIT-USER-AGENT GIT-PREFIX
Expand Down
2 changes: 2 additions & 0 deletions builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ static const char *cmd_to_page(const char *git_cmd)
return git_cmd;
else if (is_git_command(git_cmd))
return xstrfmt("git-%s", git_cmd);
else if (!strcmp("scalar", git_cmd))
return xstrdup(git_cmd);
else
return xstrfmt("git%s", git_cmd);
}
Expand Down
5 changes: 5 additions & 0 deletions ci/run-test-slice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ make --quiet -C t T="$(cd t &&
# Run the git subtree tests only if main tests succeeded
test 0 != "$1" || make -C contrib/subtree test

if test 0 = "$1" && test -n "$INCLUDE_SCALAR"
then
make -C contrib/scalar/t
fi

check_unignored_build_artifacts
8 changes: 7 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2999,6 +2999,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
const char *value_pattern,
unsigned flags)
{
static unsigned long timeout_ms = ULONG_MAX;
int fd = -1, in_fd = -1;
int ret;
struct lock_file lock = LOCK_INIT;
Expand All @@ -3019,11 +3020,16 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
if (!config_filename)
config_filename = filename_buf = git_pathdup("config");

if ((long)timeout_ms < 0 &&
git_config_get_ulong("core.configWriteLockTimeoutMS", &timeout_ms))
timeout_ms = 0;

/*
* The lock serves a purpose in addition to locking: the new
* contents of .git/config will be written into it.
*/
fd = hold_lock_file_for_update(&lock, config_filename, 0);
fd = hold_lock_file_for_update_timeout(&lock, config_filename, 0,
timeout_ms);
if (fd < 0) {
error_errno(_("could not lock config file %s"), config_filename);
ret = CONFIG_NO_LOCK;
Expand Down
15 changes: 14 additions & 1 deletion contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,13 @@ if(CURL_FOUND)
target_link_libraries(git-gvfs-helper http_obj common-main ${CURL_LIBRARIES} )
endif()

if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "")
add_executable(scalar ${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c ${CMAKE_SOURCE_DIR}/contrib/scalar/json-parser.c)
target_link_libraries(scalar common-main)
set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/contrib/scalar)
set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/contrib/scalar)
endif()

parse_makefile_for_executables(git_builtin_extra "BUILT_INS")

option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins")
Expand Down Expand Up @@ -1003,7 +1010,6 @@ if(CURL_FOUND)
endif()
endif()


foreach(script ${wrapper_scripts})
file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
Expand All @@ -1023,6 +1029,13 @@ string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})

if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "")
file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
string(REPLACE "@@PROG@@" "contrib/scalar/scalar${EXE_EXTENSION}" content "${content}")
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/scalar ${content})
endif()

#options for configuring test options
option(PERL_TESTS "Perform tests that use perl" ON)
option(PYTHON_TESTS "Perform tests that use python" ON)
Expand Down
5 changes: 5 additions & 0 deletions contrib/scalar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*.xml
/*.1
/*.html
/*.exe
/scalar
71 changes: 71 additions & 0 deletions contrib/scalar/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
CC = cc
RM = rm -f
MV = mv

CFLAGS = -g -O2 -Wall
LDFLAGS =
EXTLIBS = -lz

DESTDIR_SQ = $(subst ','\'',$(DESTDIR))

QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =

ifneq ($(findstring s,$(MAKEFLAGS)),s)
ifndef V
QUIET_CC = @echo ' ' CC $@;
QUIET_LINK = @echo ' ' LINK $@;
QUIET_GEN = @echo ' ' GEN $@;
QUIET_SUBDIR0 = +@subdir=
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
$(MAKE) $(PRINT_DIR) -C $$subdir
QUIET = @

export V
export QUIET_GEN
export QUIET_BUILT_IN
endif
endif

all:

include ../../config.mak.uname
-include ../../config.mak.autogen
-include ../../config.mak

TARGETS = scalar$(X) scalar.o json-parser.o
GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a

all: scalar$X ../../bin-wrappers/scalar

$(GITLIBS):
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@)

$(TARGETS): $(GITLIBS) scalar.c json-parser.c json-parser.h
$(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@)

clean:
$(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

scalar.html scalar.1: scalar.txt
$(QUIET_SUBDIR0)../../Documentation$(QUIET_SUBDIR1) \
MAN_TXT=../contrib/scalar/scalar.txt \
../contrib/scalar/$@
$(QUIET)test scalar.1 != "$@" || mv ../../Documentation/$@ .

.PHONY: all clean test docs FORCE
Loading

0 comments on commit c82b384

Please sign in to comment.