diff options
Diffstat (limited to 'contrib')
42 files changed, 1185 insertions, 1509 deletions
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 185f56f414..2f6e0197ff 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -54,7 +54,7 @@ set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON) if(NOT WIN32) - set(USE_VCPKG OFF CACHE BOOL FORCE) + set(USE_VCPKG OFF CACHE BOOL "" FORCE) endif() if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) @@ -77,7 +77,7 @@ if(USE_VCPKG) set(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file") endif() -find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin") +find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin" "$ENV{LOCALAPPDATA}/Programs/Git/bin") if(NOT SH_EXE) message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one." "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/") @@ -108,7 +108,6 @@ project(git #TODO gitk git-gui gitweb #TODO Enable NLS on windows natively -#TODO Add pcre support #macros for parsing the Makefile for sources and scripts macro(parse_makefile_for_sources list_var regex) @@ -160,6 +159,14 @@ if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID ST find_package(Intl) endif() +find_package(PkgConfig) +if(PkgConfig_FOUND) + pkg_check_modules(PCRE2 libpcre2-8) + if(PCRE2_FOUND) + add_compile_definitions(USE_LIBPCRE2) + endif() +endif() + if(NOT Intl_FOUND) add_compile_definitions(NO_GETTEXT) if(NOT Iconv_FOUND) @@ -180,6 +187,9 @@ endif() if(Intl_FOUND) include_directories(SYSTEM ${Intl_INCLUDE_DIRS}) endif() +if(PCRE2_FOUND) + include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS}) +endif() if(WIN32 AND NOT MSVC)#not required for visual studio builds @@ -260,7 +270,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0 USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP - UNICODE _UNICODE HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) + HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c @@ -277,7 +287,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY ) - list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c) + list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") @@ -297,9 +307,21 @@ if(SUPPORTS_SIMPLE_IPC) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c) + + add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-darwin.c) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c) + + add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) + list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c) endif() endif() @@ -592,7 +614,7 @@ unset(CMAKE_REQUIRED_INCLUDES) #programs set(PROGRAMS_BUILT git git-daemon git-http-backend git-sh-i18n--envsubst - git-shell) + git-shell scalar) if(NOT CURL_FOUND) list(APPEND excluded_progs git-http-fetch git-http-push) @@ -700,6 +722,10 @@ endif() if(Iconv_FOUND) target_link_libraries(common-main ${Iconv_LIBRARIES}) endif() +if(PCRE2_FOUND) + target_link_libraries(common-main ${PCRE2_LIBRARIES}) + target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS}) +endif() if(WIN32) target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res) add_dependencies(common-main git-rc) @@ -735,6 +761,9 @@ target_link_libraries(git-sh-i18n--envsubst common-main) add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c) target_link_libraries(git-shell common-main) +add_executable(scalar ${CMAKE_SOURCE_DIR}/scalar.c) +target_link_libraries(scalar common-main) + if(CURL_FOUND) add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c) @@ -881,7 +910,7 @@ list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/") #install foreach(program ${PROGRAMS_BUILT}) -if(program STREQUAL "git" OR program STREQUAL "git-shell") +if(program MATCHES "^(git|git-shell|scalar)$") install(TARGETS ${program} RUNTIME DESTINATION bin) else() @@ -955,7 +984,7 @@ endif() #wrapper scripts set(wrapper_scripts - git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext) + git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext scalar) set(wrapper_test_scripts test-fake-ssh test-tool) @@ -996,7 +1025,6 @@ set(NO_PERL ) set(NO_PTHREADS ) set(NO_PYTHON ) set(PAGER_ENV "LESS=FRX LV=-c") -set(DC_SHA1 YesPlease) set(RUNTIME_PREFIX true) set(NO_GETTEXT ) @@ -1032,7 +1060,6 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n") -file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n") @@ -1045,18 +1072,14 @@ endif() #Make the tests work when building out of the source tree get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE) if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH}) - file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt) - string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE}) #Setting the build directory in test-lib.sh before running tests file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake - "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n" - "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n" - "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\"\" content \"\${content}\")\n" - "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})") + "file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \"${CMAKE_BINARY_DIR}\")") #misc copies - file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/) + file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/) file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/) - file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/) + file(GLOB mergetools "${CMAKE_SOURCE_DIR}/mergetools/*") + file(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/) file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) endif() @@ -1066,8 +1089,12 @@ file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh") #test foreach(tsh ${test_scipts}) add_test(NAME ${tsh} - COMMAND ${SH_EXE} ${tsh} + COMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t) endforeach() +# This test script takes an extremely long time and is known to time out even +# on fast machines because it requires in excess of one hour to run +set_tests_properties("${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh" PROPERTIES TIMEOUT 4000) + endif()#BUILD_TESTING diff --git a/contrib/coccinelle/.gitignore b/contrib/coccinelle/.gitignore index d3f29646dc..1d45c0a40c 100644 --- a/contrib/coccinelle/.gitignore +++ b/contrib/coccinelle/.gitignore @@ -1 +1 @@ -*.patch* +*.patch diff --git a/contrib/coccinelle/README b/contrib/coccinelle/README index f0e80bd7f0..d1daa1f626 100644 --- a/contrib/coccinelle/README +++ b/contrib/coccinelle/README @@ -41,3 +41,52 @@ There are two types of semantic patches: This allows to expose plans of pending large scale refactorings without impacting the bad pattern checks. + +Git-specific tips & things to know about how we run "spatch": + + * The "make coccicheck" will piggy-back on + "COMPUTE_HEADER_DEPENDENCIES". If you've built a given object file + the "coccicheck" target will consider its depednency to decide if + it needs to re-run on the corresponding source file. + + This means that a "make coccicheck" will re-compile object files + before running. This might be unexpected, but speeds up the run in + the common case, as e.g. a change to "column.h" won't require all + coccinelle rules to be re-run against "grep.c" (or another file + that happens not to use "column.h"). + + To disable this behavior use the "SPATCH_USE_O_DEPENDENCIES=NoThanks" + flag. + + * To speed up our rules the "make coccicheck" target will by default + concatenate all of the *.cocci files here into an "ALL.cocci", and + apply it to each source file. + + This makes the run faster, as we don't need to run each rule + against each source file. See the Makefile for further discussion, + this behavior can be disabled with "SPATCH_CONCAT_COCCI=". + + But since they're concatenated any <id> in the <rulname> (e.g. "@ + my_name", v.s. anonymous "@@") needs to be unique across all our + *.cocci files. You should only need to name rules if other rules + depend on them (currently only one rule is named). + + * To speed up incremental runs even more use the "spatchcache" tool + in this directory as your "SPATCH". It aimns to be a "ccache" for + coccinelle, and piggy-backs on "COMPUTE_HEADER_DEPENDENCIES". + + It caches in Redis by default, see it source for a how-to. + + In one setup with a primed cache "make coccicheck" followed by a + "make clean && make" takes around 10s to run, but 2m30s with the + default of "SPATCH_CONCAT_COCCI=Y". + + With "SPATCH_CONCAT_COCCI=" the total runtime is around ~6m, sped + up to ~1m with "spatchcache". + + Most of the 10s (or ~1m) being spent on re-running "spatch" on + files we couldn't cache, as we didn't compile them (in contrib/* + and compat/* mostly). + + The absolute times will differ for you, but the relative speedup + from caching should be on that order. diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci index 9a4f00cb1b..aa75937950 100644 --- a/contrib/coccinelle/array.cocci +++ b/contrib/coccinelle/array.cocci @@ -1,60 +1,58 @@ @@ -expression dst, src, n, E; +type T; +T *dst_ptr; +T *src_ptr; +expression n; @@ - memcpy(dst, src, n * sizeof( -- E[...] -+ *(E) - )) +- memcpy(dst_ptr, src_ptr, (n) * \( sizeof(T) +- \| sizeof(*(dst_ptr)) +- \| sizeof(*(src_ptr)) +- \| sizeof(dst_ptr[...]) +- \| sizeof(src_ptr[...]) +- \) ) ++ COPY_ARRAY(dst_ptr, src_ptr, n) @@ type T; -T *ptr; -T[] arr; -expression E, n; +T *dst_ptr; +T[] src_arr; +expression n; @@ -( - memcpy(ptr, E, -- n * sizeof(*(ptr)) -+ n * sizeof(T) - ) -| - memcpy(arr, E, -- n * sizeof(*(arr)) -+ n * sizeof(T) - ) -| - memcpy(E, ptr, -- n * sizeof(*(ptr)) -+ n * sizeof(T) - ) -| - memcpy(E, arr, -- n * sizeof(*(arr)) -+ n * sizeof(T) - ) -) +- memcpy(dst_ptr, src_arr, (n) * \( sizeof(T) +- \| sizeof(*(dst_ptr)) +- \| sizeof(*(src_arr)) +- \| sizeof(dst_ptr[...]) +- \| sizeof(src_arr[...]) +- \) ) ++ COPY_ARRAY(dst_ptr, src_arr, n) @@ type T; -T *dst_ptr; +T[] dst_arr; T *src_ptr; +expression n; +@@ +- memcpy(dst_arr, src_ptr, (n) * \( sizeof(T) +- \| sizeof(*(dst_arr)) +- \| sizeof(*(src_ptr)) +- \| sizeof(dst_arr[...]) +- \| sizeof(src_ptr[...]) +- \) ) ++ COPY_ARRAY(dst_arr, src_ptr, n) + +@@ +type T; T[] dst_arr; T[] src_arr; expression n; @@ -( -- memcpy(dst_ptr, src_ptr, (n) * sizeof(T)) -+ COPY_ARRAY(dst_ptr, src_ptr, n) -| -- memcpy(dst_ptr, src_arr, (n) * sizeof(T)) -+ COPY_ARRAY(dst_ptr, src_arr, n) -| -- memcpy(dst_arr, src_ptr, (n) * sizeof(T)) -+ COPY_ARRAY(dst_arr, src_ptr, n) -| -- memcpy(dst_arr, src_arr, (n) * sizeof(T)) +- memcpy(dst_arr, src_arr, (n) * \( sizeof(T) +- \| sizeof(*(dst_arr)) +- \| sizeof(*(src_arr)) +- \| sizeof(dst_arr[...]) +- \| sizeof(src_arr[...]) +- \) ) + COPY_ARRAY(dst_arr, src_arr, n) -) @@ type T; diff --git a/contrib/coccinelle/equals-null.cocci b/contrib/coccinelle/equals-null.cocci new file mode 100644 index 0000000000..92c7054013 --- /dev/null +++ b/contrib/coccinelle/equals-null.cocci @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +@@ +expression e; +statement s; +@@ +if ( +( +!e +| +- e == NULL ++ !e +) + ) + {...} +else s + +@@ +expression e; +statement s; +@@ +if ( +( +e +| +- e != NULL ++ e +) + ) + {...} +else s diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci index 4490069df9..6fb9eb6e88 100644 --- a/contrib/coccinelle/free.cocci +++ b/contrib/coccinelle/free.cocci @@ -2,13 +2,21 @@ expression E; @@ - if (E) +( free(E); +| + free_commit_list(E); +) @@ expression E; @@ - if (!E) +( free(E); +| + free_commit_list(E); +) @@ expression E; @@ -16,3 +24,22 @@ expression E; - free(E); + FREE_AND_NULL(E); - E = NULL; + +@@ +expression E; +@@ +- if (E) +- { + free_commit_list(E); + E = NULL; +- } + +@@ +expression E; +statement S; +@@ +- if (E) { ++ if (E) + S + free_commit_list(E); +- } diff --git a/contrib/coccinelle/hashmap.cocci b/contrib/coccinelle/hashmap.cocci index d69e120ccf..c5dbb4557b 100644 --- a/contrib/coccinelle/hashmap.cocci +++ b/contrib/coccinelle/hashmap.cocci @@ -1,4 +1,4 @@ -@ hashmap_entry_init_usage @ +@@ expression E; struct hashmap_entry HME; @@ diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci new file mode 100644 index 0000000000..8520f03128 --- /dev/null +++ b/contrib/coccinelle/index-compatibility.cocci @@ -0,0 +1,139 @@ +// the_index.* variables +@@ +identifier AC = active_cache; +identifier ACC = active_cache_changed; +identifier ACT = active_cache_tree; +@@ +( +- AC ++ the_index.cache +| +- ACC ++ the_index.cache_changed +| +- ACT ++ the_index.cache_tree +) + +@@ +identifier AN = active_nr; +identifier f != prepare_to_commit; +@@ + f(...) {<... +- AN ++ the_index.cache_nr + ...>} + +// "the_repository" simple cases +@@ +@@ +( +- read_cache_unmerged ++ repo_read_index_unmerged +| +- hold_locked_index ++ repo_hold_locked_index +) + ( ++ the_repository, + ...) + +// "the_repository" special-cases +@@ +@@ +( +- read_cache_preload ++ repo_read_index_preload +) + ( ++ the_repository, + ... ++ , 0 + ) + +// "the_index" simple cases +@@ +@@ +( +- is_cache_unborn ++ is_index_unborn +| +- unmerged_cache ++ unmerged_index +| +- rename_cache_entry_at ++ rename_index_entry_at +| +- chmod_cache_entry ++ chmod_index_entry +| +- cache_file_exists ++ index_file_exists +| +- cache_name_is_other ++ index_name_is_other +| +- unmerge_cache_entry_at ++ unmerge_index_entry_at +| +- add_to_cache ++ add_to_index +| +- add_file_to_cache ++ add_file_to_index +| +- add_cache_entry ++ add_index_entry +| +- remove_file_from_cache ++ remove_file_from_index +| +- ce_match_stat ++ ie_match_stat +| +- ce_modified ++ ie_modified +| +- resolve_undo_clear ++ resolve_undo_clear_index +) + ( ++ &the_index, + ...) + +@@ +@@ +( +- refresh_and_write_cache ++ repo_refresh_and_write_index +) + ( ++ the_repository, + ... ++ , NULL, NULL, NULL + ) + +// "the_index" special-cases +@@ +@@ +( +- read_cache_from ++ read_index_from +) + ( ++ &the_index, + ... ++ , get_git_dir() + ) + +@@ +@@ +( +- refresh_cache ++ refresh_index +) + ( ++ &the_index, + ... ++ , NULL, NULL, NULL + ) diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci new file mode 100644 index 0000000000..01f875d006 --- /dev/null +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -0,0 +1,24 @@ +// "the_repository" simple cases +@@ +@@ +( +- read_cache ++ repo_read_index +) + ( ++ the_repository, + ...) + +// "the_index" simple cases +@@ +@@ +( +- discard_cache ++ discard_index +| +- cache_name_pos ++ index_name_pos +) + ( ++ &the_index, + ...) diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci index ddf4f22bd7..01f8d6935b 100644 --- a/contrib/coccinelle/object_id.cocci +++ b/contrib/coccinelle/object_id.cocci @@ -1,18 +1,6 @@ @@ struct object_id OID; @@ -- is_null_sha1(OID.hash) -+ is_null_oid(&OID) - -@@ -struct object_id *OIDPTR; -@@ -- is_null_sha1(OIDPTR->hash) -+ is_null_oid(OIDPTR) - -@@ -struct object_id OID; -@@ - hashclr(OID.hash) + oidclr(&OID) diff --git a/contrib/coccinelle/preincr.cocci b/contrib/coccinelle/preincr.cocci index 7fe1e8d2d9..ae42cb0730 100644 --- a/contrib/coccinelle/preincr.cocci +++ b/contrib/coccinelle/preincr.cocci @@ -1,4 +1,4 @@ -@ preincrement @ +@@ identifier i; @@ - ++i > 1 diff --git a/contrib/coccinelle/spatchcache b/contrib/coccinelle/spatchcache new file mode 100755 index 0000000000..29e9352d8a --- /dev/null +++ b/contrib/coccinelle/spatchcache @@ -0,0 +1,304 @@ +#!/bin/sh +# +# spatchcache: a poor-man's "ccache"-alike for "spatch" in git.git +# +# This caching command relies on the peculiarities of the Makefile +# driving "spatch" in git.git, in particular if we invoke: +# +# make +# # See "spatchCache.cacheWhenStderr" for why "--very-quiet" is +# # used +# make coccicheck SPATCH_FLAGS=--very-quiet +# +# We can with COMPUTE_HEADER_DEPENDENCIES (auto-detected as true with +# "gcc" and "clang") write e.g. a .depend/grep.o.d for grep.c, when we +# compile grep.o. +# +# The .depend/grep.o.d will have the full header dependency tree of +# grep.c, and we can thus cache the output of "spatch" by: +# +# 1. Hashing all of those files +# 2. Hashing our source file, and the *.cocci rule we're +# applying +# 3. Running spatch, if suggests no changes (by far the common +# case) we invoke "spatchCache.getCmd" and +# "spatchCache.setCmd" with a hash SHA-256 to ask "does this +# ID have no changes" or "say that ID had no changes> +# 4. If no "spatchCache.{set,get}Cmd" is specified we'll use +# "redis-cli" and maintain a SET called "spatch-cache". Set +# appropriate redis memory policies to keep it from growing +# out of control. +# +# This along with the general incremental "make" support for +# "contrib/coccinelle" makes it viable to (re-)run coccicheck +# e.g. when merging integration branches. +# +# Note that the "--very-quiet" flag is currently critical. The cache +# will refuse to cache anything that has output on STDERR (which might +# be errors from spatch), but see spatchCache.cacheWhenStderr below. +# +# The STDERR (and exit code) could in principle be cached (as with +# ccache), but then the simple structure in the Redis cache would need +# to change, so just supply "--very-quiet" for now. +# +# To use this, simply set SPATCH to +# contrib/coccinelle/spatchcache. Then optionally set: +# +# [spatchCache] +# # Optional: path to a custom spatch +# spatch = ~/g/coccicheck/spatch.opt +# +# As well as this trace config (debug implies trace): +# +# cacheWhenStderr = true +# trace = false +# debug = false +# +# The ".depend/grep.o.d" can also be customized, as a string that will +# be eval'd, it has access to a "$dirname" and "$basename": +# +# [spatchCache] +# dependFormat = "$dirname/.depend/${basename%.c}.o.d" +# +# Setting "trace" to "true" allows for seeing when we have a cache HIT +# or MISS. To debug whether the cache is working do that, and run e.g.: +# +# redis-cli FLUSHALL +# <make && make coccicheck, as above> +# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/contrib/coccinelle | sort | uniq -c +# 600 CANTCACHE +# 7365 MISS +# 7365 SET +# +# A subsequent "make cocciclean && make coccicheck" should then have +# all "HIT"'s and "CANTCACHE"'s. +# +# The "spatchCache.cacheWhenStderr" option is critical when using +# spatchCache.{trace,debug} to debug whether something is set in the +# cache, as we'll write to the spatch logs in .build/* we'd otherwise +# always emit a NOCACHE. +# +# Reading the config can make the command much slower, to work around +# this the config can be set in the environment, with environment +# variable name corresponding to the config key. "default" can be used +# to use whatever's the script default, e.g. setting +# spatchCache.cacheWhenStderr=true and deferring to the defaults for +# the rest is: +# +# export GIT_CONTRIB_SPATCHCACHE_DEBUG=default +# export GIT_CONTRIB_SPATCHCACHE_TRACE=default +# export GIT_CONTRIB_SPATCHCACHE_CACHEWHENSTDERR=true +# export GIT_CONTRIB_SPATCHCACHE_SPATCH=default +# export GIT_CONTRIB_SPATCHCACHE_DEPENDFORMAT=default +# export GIT_CONTRIB_SPATCHCACHE_SETCMD=default +# export GIT_CONTRIB_SPATCHCACHE_GETCMD=default + +set -e + +env_or_config () { + env="$1" + shift + if test "$env" = "default" + then + # Avoid expensive "git config" invocation + return + elif test -n "$env" + then + echo "$env" + else + git config $@ || : + fi +} + +## Our own configuration & options +debug=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_DEBUG" --bool "spatchCache.debug") +if test "$debug" != "true" +then + debug= +fi +if test -n "$debug" +then + set -x +fi + +trace=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_TRACE" --bool "spatchCache.trace") +if test "$trace" != "true" +then + trace= +fi +if test -n "$debug" +then + # debug implies trace + trace=true +fi + +cacheWhenStderr=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_CACHEWHENSTDERR" --bool "spatchCache.cacheWhenStderr") +if test "$cacheWhenStderr" != "true" +then + cacheWhenStderr= +fi + +trace_it () { + if test -z "$trace" + then + return + fi + echo "$@" >&2 +} + +spatch=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_SPATCH" --path "spatchCache.spatch") +if test -n "$spatch" +then + if test -n "$debug" + then + trace_it "custom spatchCache.spatch='$spatch'" + fi +else + spatch=spatch +fi + +dependFormat='$dirname/.depend/${basename%.c}.o.d' +dependFormatCfg=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_DEPENDFORMAT" "spatchCache.dependFormat") +if test -n "$dependFormatCfg" +then + dependFormat="$dependFormatCfg" +fi + +set=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_SETCMD" "spatchCache.setCmd") +get=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_GETCMD" "spatchCache.getCmd") + +## Parse spatch()-like command-line for caching info +arg_sp= +arg_file= +args="$@" +spatch_opts() { + while test $# != 0 + do + arg_file="$1" + case "$1" in + --sp-file) + arg_sp="$2" + ;; + esac + shift + done +} +spatch_opts "$@" +if ! test -f "$arg_file" +then + arg_file= +fi + +hash_for_cache() { + # Parameters that should affect the cache + echo "args=$args" + echo "config spatchCache.spatch=$spatch" + echo "config spatchCache.debug=$debug" + echo "config spatchCache.trace=$trace" + echo "config spatchCache.cacheWhenStderr=$cacheWhenStderr" + echo + + # Our target file and its dependencies + git hash-object "$1" "$2" $(grep -E -o '^[^:]+:$' "$3" | tr -d ':') +} + +# Sanity checks +if ! test -f "$arg_sp" && ! test -f "$arg_file" +then + echo $0: no idea how to cache "$@" >&2 + exit 128 +fi + +# Main logic +dirname=$(dirname "$arg_file") +basename=$(basename "$arg_file") +eval "dep=$dependFormat" + +if ! test -f "$dep" +then + trace_it "$0: CANTCACHE have no '$dep' for '$arg_file'!" + exec "$spatch" "$@" +fi + +if test -n "$debug" +then + trace_it "$0: The full cache input for '$arg_sp' '$arg_file' '$dep'" + hash_for_cache "$arg_sp" "$arg_file" "$dep" >&2 +fi +sum=$(hash_for_cache "$arg_sp" "$arg_file" "$dep" | git hash-object --stdin) + +trace_it "$0: processing '$arg_file' with '$arg_sp' rule, and got hash '$sum' for it + '$dep'" + +getret= +if test -z "$get" +then + if test $(redis-cli SISMEMBER spatch-cache "$sum") = 1 + then + getret=0 + else + getret=1 + fi +else + $set "$sum" + getret=$? +fi + +if test "$getret" = 0 +then + trace_it "$0: HIT for '$arg_file' with '$arg_sp'" + exit 0 +else + trace_it "$0: MISS: for '$arg_file' with '$arg_sp'" +fi + +out="$(mktemp)" +err="$(mktemp)" + +set +e +"$spatch" "$@" >"$out" 2>>"$err" +ret=$? +cat "$out" +cat "$err" >&2 +set -e + +nocache= +if test $ret != 0 +then + nocache="exited non-zero: $ret" +elif test -s "$out" +then + nocache="had patch output" +elif test -z "$cacheWhenStderr" && test -s "$err" +then + nocache="had stderr (use --very-quiet or spatchCache.cacheWhenStderr=true?)" +fi + +if test -n "$nocache" +then + trace_it "$0: NOCACHE ($nocache): for '$arg_file' with '$arg_sp'" + exit "$ret" +fi + +trace_it "$0: SET: for '$arg_file' with '$arg_sp'" + +setret= +if test -z "$set" +then + if test $(redis-cli SADD spatch-cache "$sum") = 1 + then + setret=0 + else + setret=1 + fi +else + "$set" "$sum" + setret=$? +fi + +if test "$setret" != 0 +then + echo "FAILED to set '$sum' in cache!" >&2 + exit 128 +fi + +exit "$ret" diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 0970d98ad7..5f06105df6 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -1,4 +1,4 @@ -@ strbuf_addf_with_format_only @ +@@ expression E; constant fmt !~ "%"; @@ diff --git a/contrib/coccinelle/swap.cocci b/contrib/coccinelle/swap.cocci index a0934d1fda..522177afb6 100644 --- a/contrib/coccinelle/swap.cocci +++ b/contrib/coccinelle/swap.cocci @@ -1,4 +1,4 @@ -@ swap_with_declaration @ +@@ type T; identifier tmp; T a, b; diff --git a/contrib/coccinelle/tests/free.c b/contrib/coccinelle/tests/free.c new file mode 100644 index 0000000000..96d4abc0c7 --- /dev/null +++ b/contrib/coccinelle/tests/free.c @@ -0,0 +1,11 @@ +int use_FREE_AND_NULL(int *v) +{ + free(*v); + *v = NULL; +} + +int need_no_if(int *v) +{ + if (v) + free(v); +} diff --git a/contrib/coccinelle/tests/free.res b/contrib/coccinelle/tests/free.res new file mode 100644 index 0000000000..f90fd9f48e --- /dev/null +++ b/contrib/coccinelle/tests/free.res @@ -0,0 +1,9 @@ +int use_FREE_AND_NULL(int *v) +{ + FREE_AND_NULL(*v); +} + +int need_no_if(int *v) +{ + free(v); +} diff --git a/contrib/coccinelle/tests/unused.c b/contrib/coccinelle/tests/unused.c new file mode 100644 index 0000000000..8294d734ba --- /dev/null +++ b/contrib/coccinelle/tests/unused.c @@ -0,0 +1,82 @@ +void test_strbuf(void) +{ + struct strbuf sb1 = STRBUF_INIT; + struct strbuf sb2 = STRBUF_INIT; + struct strbuf sb3 = STRBUF_INIT; + struct strbuf sb4 = STRBUF_INIT; + struct strbuf sb5; + struct strbuf sb6 = { 0 }; + struct strbuf sb7 = STRBUF_INIT; + struct strbuf sb8 = STRBUF_INIT; + struct strbuf *sp1; + struct strbuf *sp2; + struct strbuf *sp3; + struct strbuf *sp4 = xmalloc(sizeof(struct strbuf)); + struct strbuf *sp5 = xmalloc(sizeof(struct strbuf)); + struct strbuf *sp6 = xmalloc(sizeof(struct strbuf)); + struct strbuf *sp7; + + strbuf_init(&sb5, 0); + strbuf_init(sp1, 0); + strbuf_init(sp2, 0); + strbuf_init(sp3, 0); + strbuf_init(sp4, 0); + strbuf_init(sp5, 0); + strbuf_init(sp6, 0); + strbuf_init(sp7, 0); + sp7 = xmalloc(sizeof(struct strbuf)); + + use_before(&sb3); + use_as_str("%s", sb7.buf); + use_as_str("%s", sp1->buf); + use_as_str("%s", sp6->buf); + pass_pp(&sp3); + + strbuf_release(&sb1); + strbuf_reset(&sb2); + strbuf_release(&sb3); + strbuf_release(&sb4); + strbuf_release(&sb5); + strbuf_release(&sb6); + strbuf_release(&sb7); + strbuf_release(sp1); + strbuf_release(sp2); + strbuf_release(sp3); + strbuf_release(sp4); + strbuf_release(sp5); + strbuf_release(sp6); + strbuf_release(sp7); + + use_after(&sb4); + + if (when_strict()) + return; + strbuf_release(&sb8); +} + +void test_other(void) +{ + struct string_list l = STRING_LIST_INIT_DUP; + struct strbuf sb = STRBUF_INIT; + + string_list_clear(&l, 0); + string_list_clear(&sb, 0); +} + +void test_worktrees(void) +{ + struct worktree **w1 = get_worktrees(); + struct worktree **w2 = get_worktrees(); + struct worktree **w3; + struct worktree **w4; + + w3 = get_worktrees(); + w4 = get_worktrees(); + + use_it(w4); + + free_worktrees(w1); + free_worktrees(w2); + free_worktrees(w3); + free_worktrees(w4); +} diff --git a/contrib/coccinelle/tests/unused.res b/contrib/coccinelle/tests/unused.res new file mode 100644 index 0000000000..6d3e745683 --- /dev/null +++ b/contrib/coccinelle/tests/unused.res @@ -0,0 +1,45 @@ +void test_strbuf(void) +{ + struct strbuf sb3 = STRBUF_INIT; + struct strbuf sb4 = STRBUF_INIT; + struct strbuf sb7 = STRBUF_INIT; + struct strbuf *sp1; + struct strbuf *sp3; + struct strbuf *sp6 = xmalloc(sizeof(struct strbuf)); + strbuf_init(sp1, 0); + strbuf_init(sp3, 0); + strbuf_init(sp6, 0); + + use_before(&sb3); + use_as_str("%s", sb7.buf); + use_as_str("%s", sp1->buf); + use_as_str("%s", sp6->buf); + pass_pp(&sp3); + + strbuf_release(&sb3); + strbuf_release(&sb4); + strbuf_release(&sb7); + strbuf_release(sp1); + strbuf_release(sp3); + strbuf_release(sp6); + + use_after(&sb4); + + if (when_strict()) + return; +} + +void test_other(void) +{ +} + +void test_worktrees(void) +{ + struct worktree **w4; + + w4 = get_worktrees(); + + use_it(w4); + + free_worktrees(w4); +} diff --git a/contrib/coccinelle/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci index 2ee702ecf7..747d382ff5 100644 --- a/contrib/coccinelle/the_repository.pending.cocci +++ b/contrib/coccinelle/the_repository.pending.cocci @@ -14,28 +14,12 @@ expression G; @@ expression E; @@ -- has_sha1_file( -+ repo_has_sha1_file(the_repository, - E) - -@@ -expression E; -expression F; -@@ -- has_sha1_file_with_flags( -+ repo_has_sha1_file_with_flags(the_repository, - E) - -@@ -expression E; -@@ - has_object_file( + repo_has_object_file(the_repository, E) @@ expression E; -expression F; @@ - has_object_file_with_flags( + repo_has_object_file_with_flags(the_repository, diff --git a/contrib/coccinelle/unused.cocci b/contrib/coccinelle/unused.cocci new file mode 100644 index 0000000000..d84046f82e --- /dev/null +++ b/contrib/coccinelle/unused.cocci @@ -0,0 +1,43 @@ +// This rule finds sequences of "unused" declerations and uses of a +// variable, where "unused" is defined to include only calling the +// equivalent of alloc, init & free functions on the variable. +@@ +type T; +identifier I; +// STRBUF_INIT, but also e.g. STRING_LIST_INIT_DUP (so no anchoring) +constant INIT_MACRO =~ "_INIT"; +identifier MALLOC1 =~ "^x?[mc]alloc$"; +identifier INIT_ASSIGN1 =~ "^get_worktrees$"; +identifier INIT_CALL1 =~ "^[a-z_]*_init$"; +identifier REL1 =~ "^[a-z_]*_(release|reset|clear|free)$"; +identifier REL2 =~ "^(release|clear|free)_[a-z_]*$"; +@@ + +( +- T I; +| +- T I = { 0 }; +| +- T I = INIT_MACRO; +| +- T I = MALLOC1(...); +| +- T I = INIT_ASSIGN1(...); +) + +<... when != \( I \| &I \) +( +- \( INIT_CALL1 \)( \( I \| &I \), ...); +| +- I = \( INIT_ASSIGN1 \)(...); +| +- I = MALLOC1(...); +) +...> + +( +- \( REL1 \| REL2 \)( \( I \| &I \), ...); +| +- \( REL1 \| REL2 \)( \( &I \| I \) ); +) + ... when != \( I \| &I \) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ba5c395d2d..dc95c34cc8 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -58,6 +58,12 @@ # # When set to "1" suggest all options, including options which are # typically hidden (e.g. '--allow-empty' for 'git commit'). +# +# GIT_COMPLETION_IGNORE_CASE +# +# When set, uses for-each-ref '--ignore-case' to find refs that match +# case insensitively, even on systems with case sensitive file systems +# (e.g., completing tag name "FOO" on "git checkout f<TAB>"). case "$COMP_WORDBREAKS" in *:*) : great ;; @@ -646,6 +652,7 @@ __git_heads () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/heads/$cur_*" "refs/heads/$cur_*/**" } @@ -659,6 +666,7 @@ __git_remote_heads () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/$cur_*" "refs/remotes/$cur_*/**" } @@ -669,6 +677,7 @@ __git_tags () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/tags/$cur_*" "refs/tags/$cur_*/**" } @@ -688,6 +697,7 @@ __git_dwim_remote_heads () # but only output if the branch name is unique __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ --sort="refname:strip=3" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \ uniq -u } @@ -712,6 +722,7 @@ __git_refs () local format refs local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" local match="${4-}" + local umatch="${4-}" local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers __git_find_repo_path @@ -735,12 +746,19 @@ __git_refs () fi fi + if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1" + then + # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility + umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match") + fi + if [ "$list_refs_from" = path ]; then if [[ "$cur_" == ^* ]]; then pfx="$pfx^" fer_pfx="$fer_pfx^" cur_=${cur_#^} match=${match#^} + umatch=${umatch#^} fi case "$cur_" in refs|refs/*) @@ -751,7 +769,7 @@ __git_refs () *) for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do case "$i" in - $match*) + $match*|$umatch*) if [ -e "$dir/$i" ]; then echo "$pfx$i$sfx" fi @@ -765,6 +783,7 @@ __git_refs () ;; esac __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "${refs[@]}" if [ -n "$track" ]; then __git_dwim_remote_heads "$pfx" "$match" "$sfx" @@ -784,15 +803,16 @@ __git_refs () *) if [ "$list_refs_from" = remote ]; then case "HEAD" in - $match*) echo "${pfx}HEAD$sfx" ;; + $match*|$umatch*) echo "${pfx}HEAD$sfx" ;; esac __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/$remote/$match*" \ "refs/remotes/$remote/$match*/**" else local query_symref case "HEAD" in - $match*) query_symref="HEAD" ;; + $match*|$umatch*) query_symref="HEAD" ;; esac __git ls-remote "$remote" $query_symref \ "refs/tags/$match*" "refs/heads/$match*" \ diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 87b2b916c0..57972c2845 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -84,6 +84,10 @@ # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted # by setting GIT_PS1_OMITSPARSESTATE. # +# If you would like to see a notification on the prompt when there are +# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to "yes". The +# prompt will include "|CONFLICT". +# # If you would like to see more information about the identity of # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE # to one of these values: @@ -245,7 +249,8 @@ __git_ps1_show_upstream () # Helper function that is meant to be called from __git_ps1. It # injects color codes into the appropriate gitstring variables used -# to build a gitstring. +# to build a gitstring. Colored variables are responsible for clearing +# their own color. __git_ps1_colorize_gitstring () { if [[ -n ${ZSH_VERSION-} ]]; then @@ -271,22 +276,23 @@ __git_ps1_colorize_gitstring () else branch_color="$bad_color" fi - c="$branch_color$c" + if [ -n "$c" ]; then + c="$branch_color$c$c_clear" + fi + b="$branch_color$b$c_clear" - z="$c_clear$z" - if [ "$w" = "*" ]; then - w="$bad_color$w" + if [ -n "$w" ]; then + w="$bad_color$w$c_clear" fi if [ -n "$i" ]; then - i="$ok_color$i" + i="$ok_color$i$c_clear" fi if [ -n "$s" ]; then - s="$flags_color$s" + s="$flags_color$s$c_clear" fi if [ -n "$u" ]; then - u="$bad_color$u" + u="$bad_color$u$c_clear" fi - r="$c_clear$r" } # Helper function to read the first line of a file into a variable. @@ -506,6 +512,12 @@ __git_ps1 () r="$r $step/$total" fi + local conflict="" # state indicator for unresolved conflicts + if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] && + [[ $(git ls-files --unmerged 2>/dev/null) ]]; then + conflict="|CONFLICT" + fi + local w="" local i="" local s="" @@ -556,6 +568,12 @@ __git_ps1 () local z="${GIT_PS1_STATESEPARATOR-" "}" + b=${b##refs/heads/} + if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then + __git_ps1_branch_name=$b + b="\${__git_ps1_branch_name}" + fi + # NO color option unless in PROMPT_COMMAND mode or it's Zsh if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then @@ -563,14 +581,8 @@ __git_ps1 () fi fi - b=${b##refs/heads/} - if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then - __git_ps1_branch_name=$b - b="\${__git_ps1_branch_name}" - fi - local f="$h$w$i$s$u$p" - local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}" + local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}" if [ $pcmode = yes ]; then if [ "${__git_printf_supports_v-}" != yes ]; then diff --git a/contrib/credential/netrc/git-credential-netrc.perl b/contrib/credential/netrc/git-credential-netrc.perl index bc57cc6588..9fb998ae09 100755 --- a/contrib/credential/netrc/git-credential-netrc.perl +++ b/contrib/credential/netrc/git-credential-netrc.perl @@ -356,7 +356,10 @@ sub read_credential_data_from_stdin { next unless m/^([^=]+)=(.+)/; my ($token, $value) = ($1, $2); - die "Unknown search token $token" unless exists $q{$token}; + + # skip any unknown tokens + next unless exists $q{$token}; + $q{$token} = $value; log_debug("We were given search token $token and value $value"); } diff --git a/contrib/credential/netrc/t-git-credential-netrc.sh b/contrib/credential/netrc/t-git-credential-netrc.sh index 07227d0228..bf2777308a 100755 --- a/contrib/credential/netrc/t-git-credential-netrc.sh +++ b/contrib/credential/netrc/t-git-credential-netrc.sh @@ -3,16 +3,9 @@ cd ../../../t test_description='git-credential-netrc' . ./test-lib.sh + . "$TEST_DIRECTORY"/lib-perl.sh - if ! test_have_prereq PERL; then - skip_all='skipping perl interface tests, perl not available' - test_done - fi - - perl -MTest::More -e 0 2>/dev/null || { - skip_all="Perl Test::More unavailable, skipping test" - test_done - } + skip_all_if_no_Test_More # set up test repository @@ -20,13 +13,10 @@ 'set up test repository' \ 'git config --add gpg.program test.git-config-gpg' - # The external test will outputs its own plan - test_external_has_tap=1 - export PERL5LIB="$GITPERLLIB" - test_external \ - 'git-credential-netrc' \ + test_expect_success 'git-credential-netrc' ' perl "$GIT_BUILD_DIR"/contrib/credential/netrc/test.pl + ' test_done ) diff --git a/contrib/credential/osxkeychain/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c index 0b44a9b7cc..e29cc28779 100644 --- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c +++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c @@ -159,6 +159,11 @@ static void read_credential(void) username = xstrdup(v); else if (!strcmp(buf, "password")) password = xstrdup(v); + /* + * Ignore other lines; we don't know what they mean, but + * this future-proofs us when later versions of git do + * learn new lines, and the helpers are updated to match. + */ } } @@ -168,7 +173,7 @@ int main(int argc, const char **argv) "usage: git credential-osxkeychain <get|store|erase>"; if (!argv[1]) - die(usage); + die("%s", usage); read_credential(); diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c index 5091048f9c..ead6e267c7 100644 --- a/contrib/credential/wincred/git-credential-wincred.c +++ b/contrib/credential/wincred/git-credential-wincred.c @@ -278,8 +278,11 @@ static void read_credential(void) wusername = utf8_to_utf16_dup(v); } else if (!strcmp(buf, "password")) password = utf8_to_utf16_dup(v); - else - die("unrecognized input"); + /* + * Ignore other lines; we don't know what they mean, but + * this future-proofs us when later versions of git do + * learn new lines, and the helpers are updated to match. + */ } } diff --git a/contrib/git-jump/README b/contrib/git-jump/README index 8bcace29d2..3211841305 100644 --- a/contrib/git-jump/README +++ b/contrib/git-jump/README @@ -79,6 +79,14 @@ git jump grep -i foo_bar git config jump.grepCmd "ag --column" -------------------------------------------------- +You can use the optional argument '--stdout' to print the listing to +standard output instead of feeding it to the editor. You can use the +argument with M-x grep on Emacs: + +-------------------------------------------------- +# In Emacs, M-x grep and invoke "git jump --stdout <mode>" +M-x grep<RET>git jump --stdout diff<RET> +-------------------------------------------------- Related Programs ---------------- @@ -100,7 +108,7 @@ Limitations ----------- This script was written and tested with vim. Given that the quickfix -format is the same as what gcc produces, I expect emacs users have a +format is the same as what gcc produces, I expect other tools have a similar feature for iterating through the list, but I know nothing about how to activate it. diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index 92dbd4cde1..40c4b0d111 100755 --- a/contrib/git-jump/git-jump +++ b/contrib/git-jump/git-jump @@ -2,7 +2,7 @@ usage() { cat <<\EOF -usage: git jump <mode> [<args>] +usage: git jump [--stdout] <mode> [<args>] Jump to interesting elements in an editor. The <mode> parameter is one of: @@ -15,12 +15,30 @@ grep: elements are grep hits. Arguments are given to git grep or, if configured, to the command in `jump.grepCmd`. ws: elements are whitespace errors. Arguments are given to diff --check. + +If the optional argument `--stdout` is given, print the quickfix +lines to standard output instead of feeding it to the editor. EOF } open_editor() { editor=`git var GIT_EDITOR` - eval "$editor -q \$1" + case "$editor" in + *emacs*) + # Supported editor values are: + # - emacs + # - emacsclient + # - emacsclient -t + # + # Wait for completion of the asynchronously executed process + # to avoid race conditions in case of "emacsclient". + eval "$editor --eval \"(let ((buf (grep \\\"cat \$1\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\"" + ;; + *) + # assume anything else is vi-compatible + eval "$editor -q \$1" + ;; + esac } mode_diff() { @@ -64,15 +82,36 @@ mode_ws() { git diff --check "$@" } +use_stdout= +while test $# -gt 0; do + case "$1" in + --stdout) + use_stdout=t + ;; + --*) + usage >&2 + exit 1 + ;; + *) + break + ;; + esac + shift +done if test $# -lt 1; then usage >&2 exit 1 fi mode=$1; shift +type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; } + +if test "$use_stdout" = "t"; then + "mode_$mode" "$@" + exit 0 +fi trap 'rm -f "$tmp"' 0 1 2 3 15 tmp=`mktemp -t git-jump.XXXXXX` || exit 1 -type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; } "mode_$mode" "$@" >"$tmp" test -s "$tmp" || exit 0 open_editor "$tmp" diff --git a/contrib/rerere-train.sh b/contrib/rerere-train.sh index 26b724c8c6..bd01e430ef 100755 --- a/contrib/rerere-train.sh +++ b/contrib/rerere-train.sh @@ -75,7 +75,7 @@ do continue fi git checkout -q "$parent1^0" - if git merge $other_parents >/dev/null 2>&1 + if git merge --no-gpg-sign $other_parents >/dev/null 2>&1 then # Cleanly merges continue diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore deleted file mode 100644 index ff3d47e84d..0000000000 --- a/contrib/scalar/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/*.exe -/scalar diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile deleted file mode 100644 index 37f283f35d..0000000000 --- a/contrib/scalar/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# The default target of this Makefile is... -all:: - -# Import tree-wide shared Makefile behavior and libraries -include ../../shared.mak - -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) ../../bin-wrappers/scalar - -$(GITLIBS): - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@) - -$(TARGETS): $(GITLIBS) scalar.c - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@) - -clean: - $(RM) $(TARGETS) ../../bin-wrappers/scalar - -../../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 - -.PHONY: $(GITLIBS) all clean test FORCE diff --git a/contrib/scalar/README.md b/contrib/scalar/README.md deleted file mode 100644 index 634b5771ed..0000000000 --- a/contrib/scalar/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# Scalar - an opinionated repository management tool - -Scalar is an add-on to Git that helps users take advantage of advanced -performance features in Git. Originally implemented in C# using .NET Core, -based on the learnings from the VFS for Git project, most of the techniques -developed by the Scalar project have been integrated into core Git already: - -* partial clone, -* commit graphs, -* multi-pack index, -* sparse checkout (cone mode), -* scheduled background maintenance, -* etc - -This directory contains the remaining parts of Scalar that are not (yet) in -core Git. - -## Roadmap - -The idea is to populate this directory via incremental patch series and -eventually move to a top-level directory next to `gitk-git/` and to `git-gui/`. The -current plan involves the following patch series: - -- `scalar-the-beginning`: The initial patch series which sets up - `contrib/scalar/` and populates it with a minimal `scalar` command that - demonstrates the fundamental ideas. - -- `scalar-c-and-C`: The `scalar` command learns about two options that can be - specified before the command, `-c <key>=<value>` and `-C <directory>`. - -- `scalar-diagnose`: The `scalar` command is taught the `diagnose` subcommand. - -- `scalar-and-builtin-fsmonitor`: The built-in FSMonitor is enabled in `scalar - register` and in `scalar clone`, for an enormous performance boost when - working in large worktrees. This patch series necessarily depends on Jeff - Hostetler's FSMonitor patch series to be integrated into Git. - -- `scalar-gentler-config-locking`: Scalar enlistments are registered in the - user's Git config. This usually does not represent any problem because it is - rare for a user to register an enlistment. However, in Scalar's functional - tests, Scalar enlistments are created galore, and in parallel, which can lead - to lock contention. This patch series works around that problem by re-trying - to lock the config file in a gentle fashion. - -- `scalar-extra-docs`: Add some extensive documentation that has been written - in the original Scalar project (all subject to discussion, of course). - -- `optionally-install-scalar`: Now that Scalar is feature (and documentation) - complete and is verified in CI builds, let's offer to install it. - -- `move-scalar-to-toplevel`: Now that Scalar is complete, let's move it next to - `gitk-git/` and to `git-gui/`, making it a top-level command. - -The following two patch series exist in Microsoft's fork of Git and are -publicly available. There is no current plan to upstream them, not because I -want to withhold these patches, but because I don't think the Git community is -interested in these patches. - -There are some interesting ideas there, but the implementation is too specific -to Azure Repos and/or VFS for Git to be of much help in general (and also: my -colleagues tried to upstream some patches already and the enthusiasm for -integrating things related to Azure Repos and VFS for Git can be summarized in -very, very few words). - -These still exist mainly because the GVFS protocol is what Azure Repos has -instead of partial clone, while Git is focused on improving partial clone: - -- `scalar-with-gvfs`: The primary purpose of this patch series is to support - existing Scalar users whose repositories are hosted in Azure Repos (which - does not support Git's partial clones, but supports its predecessor, the GVFS - protocol, which is used by Scalar to emulate the partial clone). - - Since the GVFS protocol will never be supported by core Git, this patch - series will remain in Microsoft's fork of Git. - -- `run-scalar-functional-tests`: The Scalar project developed a quite - comprehensive set of integration tests (or, "Functional Tests"). They are the - sole remaining part of the original C#-based Scalar project, and this patch - adds a GitHub workflow that runs them all. - - Since the tests partially depend on features that are only provided in the - `scalar-with-gvfs` patch series, this patch cannot be upstreamed. diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c deleted file mode 100644 index 58ca0e56f1..0000000000 --- a/contrib/scalar/scalar.c +++ /dev/null @@ -1,845 +0,0 @@ -/* - * The Scalar command-line interface. - */ - -#include "cache.h" -#include "gettext.h" -#include "parse-options.h" -#include "config.h" -#include "run-command.h" -#include "refs.h" -#include "dir.h" -#include "packfile.h" -#include "help.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(int reconfigure) -{ - struct { - const char *key; - const char *value; - int overwrite_on_reconfigure; - } config[] = { - /* Required */ - { "am.keepCR", "true", 1 }, - { "core.FSCache", "true", 1 }, - { "core.multiPackIndex", "true", 1 }, - { "core.preloadIndex", "true", 1 }, -#ifndef WIN32 - { "core.untrackedCache", "true", 1 }, -#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", 1 }, -#endif - { "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", "true", 1 }, - { "pack.useBitmaps", "false", 1 }, - { "pack.useSparse", "true", 1 }, - { "receive.autoGC", "false", 1 }, - { "feature.manyFiles", "false", 1 }, - { "feature.experimental", "false", 1 }, - { "fetch.unpackLimit", "1", 1 }, - { "fetch.writeCommitGraph", "false", 1 }, -#ifdef WIN32 - { "http.sslBackend", "schannel", 1 }, -#endif - /* Optional */ - { "status.aheadBehind", "false" }, - { "commitGraph.generationVersion", "1" }, - { "core.autoCRLF", "false" }, - { "core.safeCRLF", "false" }, - { "fetch.showForcedUpdates", "false" }, - { NULL, NULL }, - }; - int i; - char *value; - - for (i = 0; config[i].key; i++) { - 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) - 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 toggle_maintenance(int enable) -{ - return run_git("maintenance", enable ? "start" : "unregister", NULL); -} - -static int add_or_remove_enlistment(int add) -{ - 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 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 ((add && !res) || (!add && res)) - return 0; - - 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_or_remove_enlistment(1); - - if (!res) - res = set_recommended_config(0); - - if (!res) - 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; -} - -/* printf-style interface, expects `<key>=<value>` 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 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; -} - -/* - * 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; - int full_clone = 0, single_branch = 0; - struct option clone_options[] = { - OPT_STRING('b', "branch", &branch, N_("<branch>"), - 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[] = { - N_("scalar clone [<options>] [--] <repo> [<dir>]"), - 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/%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); - goto cleanup; - } - - if (!full_clone && - (res = run_git("sparse-checkout", "init", "--cone", NULL))) - goto cleanup; - - if (set_recommended_config(0)) - 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) - 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[] = { - OPT_END(), - }; - const char * const usage[] = { - N_("scalar register [<enlistment>]"), - NULL - }; - - argc = parse_options(argc, argv, NULL, options, - usage, 0); - - setup_enlistment_directory(argc, argv, usage, options, NULL); - - 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 [--all | <enlistment>]"), - 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); - - if (!all) { - setup_enlistment_directory(argc, argv, usage, options, NULL); - - return set_recommended_config(1); - } - - if (argc > 0) - usage_msg_opt(_("--all or <enlistment>, but not both"), - usage, options); - - git_config(get_scalar_repos, &scalar_repos); - - 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) -{ - 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 <task> [<enlistment>]\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; - 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[] = { - OPT_END(), - }; - const char * const usage[] = { - N_("scalar unregister [<enlistment>]"), - NULL - }; - - 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(); -} - -static int cmd_delete(int argc, const char **argv) -{ - char *cwd = xgetcwd(); - struct option options[] = { - OPT_END(), - }; - const char * const usage[] = { - N_("scalar delete <enlistment>"), - 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 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 **); -} builtins[] = { - { "clone", cmd_clone }, - { "list", cmd_list }, - { "register", cmd_register }, - { "unregister", cmd_unregister }, - { "run", cmd_run }, - { "reconfigure", cmd_reconfigure }, - { "delete", cmd_delete }, - { "version", cmd_version }, - { NULL, NULL}, -}; - -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 <directory>")); - 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 <key>=<value> argument")); - git_config_push_parameter(argv[2]); - argc -= 2; - argv += 2; - } else - break; - } - - 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 [-C <directory>] [-c <key>=<value>] " - "<command> [<options>]\n\nCommands:\n")); - for (i = 0; builtins[i].name; i++) - strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); - - usage(scalar_usage.buf); -} diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt deleted file mode 100644 index cf4e5b889c..0000000000 --- a/contrib/scalar/scalar.txt +++ /dev/null @@ -1,155 +0,0 @@ -scalar(1) -========= - -NAME ----- -scalar - an opinionated repository management tool - -SYNOPSIS --------- -[verse] -scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>] -scalar list -scalar register [<enlistment>] -scalar unregister [<enlistment>] -scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>] -scalar reconfigure [ --all | <enlistment> ] -scalar delete <enlistment> - -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. 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 <directory>:: - Before running the subcommand, change the working directory. This - option imitates the same option of linkgit:git[1]. - --c <key>=<value>:: - For the duration of running the specified subcommand, configure this - setting. This option imitates the same option of linkgit:git[1]. - -COMMANDS --------- - -Clone -~~~~~ - -clone [<options>] <url> [<enlistment>]:: - 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 `<enlistment>/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[:<directory>]`. - --b <name>:: ---branch <name>:: - Instead of checking out the branch pointed to by the cloned - repository's HEAD, check out the `<name>` 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`. - -List -~~~~ - -list:: - List enlistments that are currently registered by Scalar. This - subcommand does not need to be run inside an enlistment. - -Register -~~~~~~~~ - -register [<enlistment>]:: - Adds the enlistment's repository to the list of registered repositories - and starts background maintenance. If `<enlistment>` 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. - -Unregister -~~~~~~~~~~ - -unregister [<enlistment>]:: - 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 ) [<enlistment>]:: - 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. - -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. - -With the `--all` option, all enlistments currently registered with Scalar -will be reconfigured. Use this option after each Scalar upgrade. - -Delete -~~~~~~ - -delete <enlistment>:: - 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]. - -Scalar ---- -Associated with the linkgit:git[1] suite diff --git a/contrib/scalar/t/Makefile b/contrib/scalar/t/Makefile deleted file mode 100644 index 01e82e56d1..0000000000 --- a/contrib/scalar/t/Makefile +++ /dev/null @@ -1,81 +0,0 @@ -# Import tree-wide shared Makefile behavior and libraries -include ../../../shared.mak - -# 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 deleted file mode 100755 index 89781568f4..0000000000 --- a/contrib/scalar/t/t9099-scalar.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/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 - -GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt,launchctl:true,schtasks:true" -export GIT_TEST_MAINT_SCHEDULER - -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_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 --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 && - git cat-file blob $second >actual && - echo "second" >expect && - test_cmp expect actual - ) -' - -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)" && - git -C one/src config core.preloadIndex false && - scalar reconfigure -a && - 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_expect_success 'scalar supports -c/-C' ' - test_when_finished "scalar delete sub" && - git init sub && - scalar -C sub -c status.aheadBehind=bogus register && - test -z "$(git -C sub config --local status.aheadBehind)" && - test true = "$(git -C sub config core.preloadIndex)" -' - -test_done diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 1af1d9653e..10c9c87839 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit indent=0 +# Usage: say [MSG...] +say () { + if test -z "$arg_quiet" + then + printf '%s\n' "$*" + fi +} + # Usage: debug [MSG...] debug () { if test -n "$arg_debug" @@ -60,7 +68,7 @@ debug () { # Usage: progress [MSG...] progress () { - if test -z "$GIT_QUIET" + if test -z "$arg_quiet" then if test -z "$arg_debug" then @@ -90,10 +98,18 @@ progress () { assert () { if ! "$@" then - die "assertion failed: $*" + die "fatal: assertion failed: $*" fi } +# Usage: die_incompatible_opt OPTION COMMAND +die_incompatible_opt () { + assert test "$#" = 2 + opt="$1" + arg_command="$2" + die "fatal: the '$opt' flag does not make sense with 'git subtree $arg_command'." +} + main () { if test $# -eq 0 then @@ -139,13 +155,14 @@ main () { allow_addmerge=$arg_split_rejoin ;; *) - die "Unknown command '$arg_command'" + die "fatal: unknown command '$arg_command'" ;; esac # Reset the arguments array for "real" flag parsing. eval "$set_args" # Begin "real" flag parsing. + arg_quiet= arg_debug= arg_prefix= arg_split_branch= @@ -161,22 +178,22 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1 ;; --annotate) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_annotate="$1" shift ;; --no-annotate) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_annotate= ;; -b) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_branch="$1" shift ;; @@ -185,7 +202,7 @@ main () { shift ;; -m) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_message="$1" shift ;; @@ -193,41 +210,41 @@ main () { arg_prefix= ;; --onto) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_onto="$1" shift ;; --no-onto) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_onto= ;; --rejoin) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" ;; --no-rejoin) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" ;; --ignore-joins) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_ignore_joins=1 ;; --no-ignore-joins) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_ignore_joins= ;; --squash) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_squash=1 ;; --no-squash) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_squash= ;; --) break ;; *) - die "Unexpected option: $opt" + die "fatal: unexpected option: $opt" ;; esac done @@ -235,24 +252,24 @@ main () { if test -z "$arg_prefix" then - die "You must provide the --prefix option." + die "fatal: you must provide the --prefix option." fi case "$arg_command" in add) test -e "$arg_prefix" && - die "prefix '$arg_prefix' already exists." + die "fatal: prefix '$arg_prefix' already exists." ;; *) test -e "$arg_prefix" || - die "'$arg_prefix' does not exist; use 'git subtree add'" + die "fatal: '$arg_prefix' does not exist; use 'git subtree add'" ;; esac dir="$(dirname "$arg_prefix/.")" debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {$arg_quiet}" debug "dir: {$dir}" debug "opts: {$*}" debug @@ -265,11 +282,11 @@ cache_setup () { assert test $# = 0 cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" || - die "Can't delete old cachedir: $cachedir" + die "fatal: can't delete old cachedir: $cachedir" mkdir -p "$cachedir" || - die "Can't create new cachedir: $cachedir" + die "fatal: can't create new cachedir: $cachedir" mkdir -p "$cachedir/notree" || - die "Can't create new cachedir: $cachedir/notree" + die "fatal: can't create new cachedir: $cachedir/notree" debug "Using cachedir: $cachedir" >&2 } @@ -325,7 +342,7 @@ cache_set () { test "$oldrev" != "latest_new" && test -e "$cachedir/$oldrev" then - die "cache for $oldrev already exists!" + die "fatal: cache for $oldrev already exists!" fi echo "$newrev" >"$cachedir/$oldrev" } @@ -354,13 +371,47 @@ try_remove_previous () { fi } -# Usage: find_latest_squash DIR +# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY] +process_subtree_split_trailer () { + assert test $# = 2 -o $# = 3 + b="$1" + sq="$2" + repository="" + if test "$#" = 3 + then + repository="$3" + fi + fail_msg="fatal: could not rev-parse split hash $b from commit $sq" + if ! sub="$(git rev-parse --verify --quiet "$b^{commit}")" + then + # if 'repository' was given, try to fetch the 'git-subtree-split' hash + # before 'rev-parse'-ing it again, as it might be a tag that we do not have locally + if test -n "${repository}" + then + git fetch "$repository" "$b" + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || + die "$fail_msg" + else + hint1=$(printf "hint: hash might be a tag, try fetching it from the subtree repository:") + hint2=$(printf "hint: git fetch <subtree-repository> $b") + fail_msg=$(printf "$fail_msg\n$hint1\n$hint2") + die "$fail_msg" + fi + fi +} + +# Usage: find_latest_squash DIR [REPOSITORY] find_latest_squash () { - assert test $# = 1 - debug "Looking for latest squash ($dir)..." + assert test $# = 1 -o $# = 2 + dir="$1" + repository="" + if test "$#" = 2 + then + repository="$2" + fi + debug "Looking for latest squash (dir=$dir, repository=$repository)..." local indent=$(($indent + 1)) - dir="$1" sq= main= sub= @@ -378,8 +429,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || - die "could not rev-parse split hash $b from commit $sq" + process_subtree_split_trailer "$b" "$sq" "$repository" ;; END) if test -n "$sub" @@ -403,14 +453,19 @@ find_latest_squash () { done || exit $? } -# Usage: find_existing_splits DIR REV +# Usage: find_existing_splits DIR REV [REPOSITORY] find_existing_splits () { - assert test $# = 2 + assert test $# = 2 -o $# = 3 debug "Looking for prior splits..." local indent=$(($indent + 1)) dir="$1" rev="$2" + repository="" + if test "$#" = 3 + then + repository="$3" + fi main= sub= local grep_format="^git-subtree-dir: $dir/*\$" @@ -430,8 +485,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || - die "could not rev-parse split hash $b from commit $sq" + process_subtree_split_trailer "$b" "$sq" "$repository" ;; END) debug "Main is: '$main'" @@ -481,7 +535,7 @@ copy_commit () { cat ) | git commit-tree "$2" $3 # reads the rest of stdin - ) || die "Can't copy commit $1" + ) || die "fatal: can't copy commit $1" } # Usage: add_msg DIR LATEST_OLD LATEST_NEW @@ -709,11 +763,11 @@ ensure_clean () { assert test $# = 0 if ! git diff-index HEAD --exit-code --quiet 2>&1 then - die "Working tree has modifications. Cannot add." + die "fatal: working tree has modifications. Cannot add." fi if ! git diff-index --cached HEAD --exit-code --quiet 2>&1 then - die "Index has modifications. Cannot add." + die "fatal: index has modifications. Cannot add." fi } @@ -721,7 +775,7 @@ ensure_clean () { ensure_valid_ref_format () { assert test $# = 1 git check-ref-format "refs/heads/$1" || - die "'$1' does not look like a ref" + die "fatal: '$1' does not look like a ref" } # Usage: process_split_commit REV PARENTS @@ -787,7 +841,7 @@ cmd_add () { if test $# -eq 1 then git rev-parse -q --verify "$1^{commit}" >/dev/null || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" cmd_add_commit "$@" @@ -802,7 +856,7 @@ cmd_add () { cmd_add_repository "$@" else - say >&2 "error: parameters were '$*'" + say >&2 "fatal: parameters were '$*'" die "Provide either a commit or a repository and commit." fi } @@ -834,7 +888,7 @@ cmd_add_commit () { git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? - headrev=$(git rev-parse HEAD) || exit $? + headrev=$(git rev-parse --verify HEAD) || exit $? if test -n "$headrev" && test "$headrev" != "$rev" then headp="-p $headrev" @@ -857,17 +911,22 @@ cmd_add_commit () { say >&2 "Added dir '$dir'" } -# Usage: cmd_split [REV] +# Usage: cmd_split [REV] [REPOSITORY] cmd_split () { if test $# -eq 0 then rev=$(git rev-parse HEAD) - elif test $# -eq 1 + elif test $# -eq 1 -o $# -eq 2 then rev=$(git rev-parse -q --verify "$1^{commit}") || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" else - die "You must provide exactly one revision. Got: '$*'" + die "fatal: you must provide exactly one revision, and optionnally a repository. Got: '$*'" + fi + repository="" + if test "$#" = 2 + then + repository="$2" fi if test -n "$arg_split_rejoin" @@ -891,7 +950,7 @@ cmd_split () { done || exit $? fi - unrevs="$(find_existing_splits "$dir" "$rev")" || exit $? + unrevs="$(find_existing_splits "$dir" "$rev" "$repository")" || exit $? # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. @@ -910,7 +969,7 @@ cmd_split () { latest_new=$(cache_get latest_new) || exit $? if test -z "$latest_new" then - die "No new revisions were found" + die "fatal: no new revisions were found" fi if test -n "$arg_split_rejoin" @@ -931,7 +990,7 @@ cmd_split () { then if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new" then - die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'." + die "fatal: branch '$arg_split_branch' is not an ancestor of commit '$latest_new'." fi action='Updated' else @@ -945,20 +1004,25 @@ cmd_split () { exit 0 } -# Usage: cmd_merge REV +# Usage: cmd_merge REV [REPOSITORY] cmd_merge () { - test $# -eq 1 || - die "You must provide exactly one revision. Got: '$*'" + test $# -eq 1 -o $# -eq 2 || + die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'" rev=$(git rev-parse -q --verify "$1^{commit}") || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" + repository="" + if test "$#" = 2 + then + repository="$2" + fi ensure_clean if test -n "$arg_addmerge_squash" then - first_split="$(find_latest_squash "$dir")" || exit $? + first_split="$(find_latest_squash "$dir" "$repository")" || exit $? if test -z "$first_split" then - die "Can't squash-merge: '$dir' was never added." + die "fatal: can't squash-merge: '$dir' was never added." fi set $first_split old=$1 @@ -986,19 +1050,21 @@ cmd_merge () { cmd_pull () { if test $# -ne 2 then - die "You must provide <repository> <ref>" + die "fatal: you must provide <repository> <ref>" fi + repository="$1" + ref="$2" ensure_clean - ensure_valid_ref_format "$2" - git fetch "$@" || exit $? - cmd_merge FETCH_HEAD + ensure_valid_ref_format "$ref" + git fetch "$repository" "$ref" || exit $? + cmd_merge FETCH_HEAD "$repository" } # Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF cmd_push () { if test $# -ne 2 then - die "You must provide <repository> <refspec>" + die "fatal: you must provide <repository> <refspec>" fi if test -e "$dir" then @@ -1013,13 +1079,13 @@ cmd_push () { fi ensure_valid_ref_format "$remoteref" localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") || - die "'$localrevname_presplit' does not refer to a commit" + die "fatal: '$localrevname_presplit' does not refer to a commit" echo "git push using: " "$repository" "$refspec" - localrev=$(cmd_split "$localrev_presplit") || die + localrev=$(cmd_split "$localrev_presplit" "$repository") || die git push "$repository" "$localrev":"refs/heads/$remoteref" else - die "'$dir' must already exist. Try 'git subtree add'." + die "fatal: '$dir' must already exist. Try 'git subtree add'." fi } diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 9cddfa2654..004abf415b 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git subtree' [<options>] -P <prefix> add <local-commit> 'git subtree' [<options>] -P <prefix> add <repository> <remote-ref> -'git subtree' [<options>] -P <prefix> merge <local-commit> +'git subtree' [<options>] -P <prefix> merge <local-commit> [<repository>] 'git subtree' [<options>] -P <prefix> split [<local-commit>] [verse] @@ -76,7 +76,7 @@ add <repository> <remote-ref>:: only a single commit from the subproject, rather than its entire history. -merge <local-commit>:: +merge <local-commit> [<repository>]:: Merge recent changes up to <local-commit> into the <prefix> subtree. As with normal 'git merge', this doesn't remove your own local changes; it just merges those @@ -88,8 +88,13 @@ If you use '--squash', the merge direction doesn't always have to be forward; you can use this command to go back in time from v2.5 to v2.4, for example. If your merge introduces a conflict, you can resolve it in the usual ways. ++ +When using '--squash', and the previous merge with '--squash' merged an +annotated tag of the subtree repository, that tag needs to be available locally. +If <repository> is given, a missing tag will automatically be fetched from that +repository. -split [<local-commit>]:: +split [<local-commit>] [<repository>]:: Extract a new, synthetic project history from the history of the <prefix> subtree of <local-commit>, or of HEAD if no <local-commit> is given. The new history @@ -109,6 +114,11 @@ settings passed to 'split' (such as '--annotate') are the same. Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so 'git merge' and friends will work as expected. ++ +When a previous merge with '--squash' merged an annotated tag of the +subtree repository, that tag needs to be available locally. +If <repository> is given, a missing tag will automatically be fetched from that +repository. pull <repository> <remote-ref>:: Exactly like 'merge', but parallels 'git pull' in that diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile index 276898eb6b..4655e0987b 100644 --- a/contrib/subtree/t/Makefile +++ b/contrib/subtree/t/Makefile @@ -47,10 +47,11 @@ pre-clean: $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' clean-except-prove-cache: - $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)' + $(RM) -r 'trash directory'.* $(RM) -r valgrind/bin clean: clean-except-prove-cache + $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' $(RM) .prove test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 1c1f76f04a..341c169eca 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -43,6 +43,30 @@ last_commit_subject () { git log --pretty=format:%s -1 } +# Upon 'git subtree add|merge --squash' of an annotated tag, +# pre-2.32.0 versions of 'git subtree' would write the hash of the tag +# (sub1 below), instead of the commit (sub1^{commit}) in the +# "git-subtree-split" trailer. +# We immitate this behaviour below using a replace ref. +# This function creates 3 repositories: +# - $1 +# - $1-sub (added as subtree "sub" in $1) +# - $1-clone (clone of $1) +test_create_pre2_32_repo () { + subtree_test_create_repo "$1" && + subtree_test_create_repo "$1-sub" && + test_commit -C "$1" main1 && + test_commit -C "$1-sub" --annotate sub1 && + git -C "$1" subtree add --prefix="sub" --squash "../$1-sub" sub1 && + tag=$(git -C "$1" rev-parse FETCH_HEAD) && + commit=$(git -C "$1" rev-parse FETCH_HEAD^{commit}) && + git -C "$1" log -1 --format=%B HEAD^2 >msg && + test_commit -C "$1-sub" --annotate sub2 && + git clone --no-local "$1" "$1-clone" && + new_commit=$(cat msg | sed -e "s/$commit/$tag/" | git -C "$1-clone" commit-tree HEAD^2^{tree}) && + git -C "$1-clone" replace HEAD^2 $new_commit +} + test_expect_success 'shows short help text for -h' ' test_expect_code 129 git subtree -h >out 2>err && test_must_be_empty err && @@ -264,6 +288,13 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende ) ' +test_expect_success 'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' + test_create_pre2_32_repo "$test_count" && + git -C "$test_count-clone" fetch "../$test_count-sub" sub2 && + test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD && + git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub" +' + # # Tests for 'git subtree split' # @@ -277,7 +308,7 @@ test_expect_success 'split requires option --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_fail git subtree split >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -296,7 +327,7 @@ test_expect_success 'split requires path given by option --prefix must exist' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -551,6 +582,12 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ) ' +test_expect_success 'split after annotated tag was added/merged with --squash pre-v2.32.0' ' + test_create_pre2_32_repo "$test_count" && + test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD && + git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub" +' + # # Tests for 'git subtree pull' # @@ -570,7 +607,7 @@ test_expect_success 'pull requires option --prefix' ' cd "$test_count" && test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_be_empty out && test_cmp expected err ) @@ -584,7 +621,7 @@ test_expect_success 'pull requires path given by option --prefix must exist' ' ( test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err && - echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_be_empty out && test_cmp expected err ) @@ -630,6 +667,11 @@ test_expect_success 'pull rejects flags for split' ' ) ' +test_expect_success 'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' + test_create_pre2_32_repo "$test_count" && + git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2 +' + # # Tests for 'git subtree push' # @@ -643,7 +685,7 @@ test_expect_success 'push requires option --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -662,7 +704,7 @@ test_expect_success 'push requires path given by option --prefix must exist' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -953,6 +995,12 @@ test_expect_success 'push "sub dir"/ with a local rev' ' ) ' +test_expect_success 'push after annotated tag was added/merged with --squash pre-v2.32.0' ' + test_create_pre2_32_repo "$test_count" && + test_create_commit "$test_count-clone" sub/main-sub1 && + git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline +' + # # Validity checking # diff --git a/contrib/vscode/README.md b/contrib/vscode/README.md index 8202d62035..f383c95e1f 100644 --- a/contrib/vscode/README.md +++ b/contrib/vscode/README.md @@ -6,7 +6,11 @@ code editor which runs on your desktop and is available for [Windows](https://code.visualstudio.com/docs/setup/windows), [macOS](https://code.visualstudio.com/docs/setup/mac) and [Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages, -it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools). +it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools) with +[debugging support](https://code.visualstudio.com/docs/editor/debugging) + +To get help about "how to personalize your settings" read: +[How to set up your settings](https://code.visualstudio.com/docs/getstarted/settings) To start developing Git with VS Code, simply run the Unix shell script called `init.sh` in this directory, which creates the configuration files in diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index 27de94994b..521d303722 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -25,8 +25,12 @@ cat >.vscode/settings.json.new <<\EOF || "editor.detectIndentation": false, "editor.insertSpaces": false, "editor.tabSize": 8, - "editor.wordWrap": "wordWrapColumn", - "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + }, + "[txt]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, "files.trimTrailingWhitespace": true }, "files.associations": { @@ -271,7 +275,6 @@ cat >.vscode/launch.json.new <<EOF || "stopAtEntry": false, "cwd": "\${workspaceFolder}", "environment": [], - "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "$GDBPATH", "setupCommands": [ |
