summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/README4
-rw-r--r--contrib/buildsystems/CMakeLists.txt208
-rw-r--r--contrib/buildsystems/Generators/Vcxproj.pm15
-rwxr-xr-xcontrib/buildsystems/engine.pl1
-rw-r--r--contrib/coccinelle/.gitignore2
-rw-r--r--contrib/coccinelle/README87
-rw-r--r--contrib/coccinelle/array.cocci89
-rw-r--r--contrib/coccinelle/config_fn_ctx.pending.cocci144
-rw-r--r--contrib/coccinelle/equals-null.cocci30
-rw-r--r--contrib/coccinelle/free.cocci27
-rw-r--r--contrib/coccinelle/git_config_number.cocci27
-rw-r--r--contrib/coccinelle/hashmap.cocci2
-rw-r--r--contrib/coccinelle/index-compatibility.cocci157
-rw-r--r--contrib/coccinelle/object_id.cocci12
-rw-r--r--contrib/coccinelle/preincr.cocci2
-rwxr-xr-xcontrib/coccinelle/spatchcache304
-rw-r--r--contrib/coccinelle/strbuf.cocci8
-rw-r--r--contrib/coccinelle/swap.cocci2
-rw-r--r--contrib/coccinelle/tests/free.c11
-rw-r--r--contrib/coccinelle/tests/free.res9
-rw-r--r--contrib/coccinelle/the_repository.cocci123
-rw-r--r--contrib/coccinelle/the_repository.pending.cocci144
-rw-r--r--contrib/coccinelle/xopen.cocci19
-rw-r--r--contrib/coccinelle/xstrdup_or_null.cocci8
-rw-r--r--contrib/coccinelle/xstrncmpz.cocci28
-rw-r--r--contrib/completion/git-completion.bash628
-rw-r--r--contrib/completion/git-completion.tcsh5
-rw-r--r--contrib/completion/git-prompt.sh147
-rwxr-xr-xcontrib/coverage-diff.sh9
-rw-r--r--contrib/credential/gnome-keyring/.gitignore1
-rw-r--r--contrib/credential/gnome-keyring/Makefile25
-rw-r--r--contrib/credential/gnome-keyring/git-credential-gnome-keyring.c470
-rw-r--r--contrib/credential/libsecret/.gitignore1
-rw-r--r--contrib/credential/libsecret/git-credential-libsecret.c115
-rwxr-xr-xcontrib/credential/netrc/git-credential-netrc.perl5
-rwxr-xr-xcontrib/credential/netrc/t-git-credential-netrc.sh18
-rw-r--r--contrib/credential/osxkeychain/Makefile3
-rw-r--r--contrib/credential/osxkeychain/git-credential-osxkeychain.c390
-rw-r--r--contrib/credential/wincred/git-credential-wincred.c179
-rw-r--r--contrib/diff-highlight/DiffHighlight.pm2
-rw-r--r--contrib/git-jump/README13
-rwxr-xr-xcontrib/git-jump/git-jump49
-rwxr-xr-xcontrib/hg-to-git/hg-to-git.py254
-rw-r--r--contrib/hg-to-git/hg-to-git.txt21
-rw-r--r--contrib/hooks/multimail/CHANGES285
-rw-r--r--contrib/hooks/multimail/CONTRIBUTING.rst60
-rw-r--r--contrib/hooks/multimail/README.Git12
-rw-r--r--contrib/hooks/multimail/README.migrate-from-post-receive-email145
-rw-r--r--contrib/hooks/multimail/README.rst774
-rw-r--r--contrib/hooks/multimail/doc/customizing-emails.rst56
-rw-r--r--contrib/hooks/multimail/doc/gerrit.rst56
-rw-r--r--contrib/hooks/multimail/doc/gitolite.rst118
-rw-r--r--contrib/hooks/multimail/doc/troubleshooting.rst78
-rwxr-xr-xcontrib/hooks/multimail/git_multimail.py4346
-rwxr-xr-xcontrib/hooks/multimail/migrate-mailhook-config274
-rwxr-xr-xcontrib/hooks/multimail/post-receive.example101
-rw-r--r--contrib/mw-to-git/Git/Mediawiki.pm2
-rwxr-xr-xcontrib/mw-to-git/t/t9360-mw-to-git-clone.sh2
-rwxr-xr-xcontrib/mw-to-git/t/t9362-mw-to-git-utf8.sh4
-rwxr-xr-xcontrib/mw-to-git/t/t9363-mw-to-git-export-import.sh2
-rwxr-xr-xcontrib/mw-to-git/t/t9365-continuing-queries.sh2
-rwxr-xr-xcontrib/rerere-train.sh6
-rwxr-xr-xcontrib/subtree/git-subtree.sh279
-rw-r--r--contrib/subtree/git-subtree.txt16
-rw-r--r--contrib/subtree/t/Makefile7
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh104
-rw-r--r--contrib/vscode/README.md6
-rwxr-xr-xcontrib/vscode/init.sh10
-rwxr-xr-xcontrib/workdir/git-new-workdir2
69 files changed, 2711 insertions, 7834 deletions
diff --git a/contrib/README b/contrib/README
index 05f291c..21d3d0e 100644
--- a/contrib/README
+++ b/contrib/README
@@ -23,7 +23,7 @@ This is the same way as how I have been treating gitk, and to a
lesser degree various foreign SCM interfaces, so you know the
drill.
-I expect that things that start their life in the contrib/ area
+I expect things that start their life in the contrib/ area
to graduate out of contrib/ once they mature, either by becoming
projects on their own, or moving to the toplevel directory. On
the other hand, I expect I'll be proposing removal of disused
@@ -31,7 +31,7 @@ and inactive ones from time to time.
If you have new things to add to this area, please first propose
it on the git mailing list, and after a list discussion proves
-there are some general interests (it does not have to be a
+there is general interest (it does not have to be a
list-wide consensus for a tool targeted to a relatively narrow
audience -- for example I do not work with projects whose
upstream is svn, so I have no use for git-svn myself, but it is
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index a878413..804629c 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -43,14 +43,27 @@ NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studi
to use another tool say `ninja` add this to the command line when configuring.
`-G Ninja`
+NOTE: By default CMake will install vcpkg locally to your source tree on configuration,
+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.
+
]]
cmake_minimum_required(VERSION 3.14)
#set the source directory to root of git
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
-if(WIN32)
+
+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)
+endif()
+
+if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
+ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
+endif()
+
+if(USE_VCPKG)
set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
- if(MSVC AND NOT EXISTS ${VCPKG_DIR})
+ if(NOT EXISTS ${VCPKG_DIR})
message("Initializing vcpkg and building the Git's dependencies (this will take a while...)")
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat)
endif()
@@ -64,7 +77,7 @@ if(WIN32)
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/")
@@ -95,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)
@@ -147,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)
@@ -167,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
@@ -176,12 +199,18 @@ if(WIN32 AND NOT MSVC)#not required for visual studio builds
endif()
endif()
-find_program(MSGFMT_EXE msgfmt)
-if(NOT MSGFMT_EXE)
- set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
- if(NOT EXISTS ${MSGFMT_EXE})
- message(WARNING "Text Translations won't be built")
- unset(MSGFMT_EXE)
+if(NO_GETTEXT)
+ message(STATUS "msgfmt not used under NO_GETTEXT")
+else()
+ find_program(MSGFMT_EXE msgfmt)
+ if(NOT MSGFMT_EXE)
+ if(USE_VCPKG)
+ set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
+ endif()
+ if(NOT EXISTS ${MSGFMT_EXE})
+ message(WARNING "Text Translations won't be built")
+ unset(MSGFMT_EXE)
+ endif()
endif()
endif()
@@ -189,7 +218,7 @@ endif()
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
- add_compile_options(/MP)
+ add_compile_options(/MP /std:c11)
endif()
#default behaviour
@@ -198,14 +227,12 @@ add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
SHA1DC_INIT_SAFE_HASH_DEFAULT=0
- SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h"
+ SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
- ETC_GITATTRIBUTES="etc/gitattributes"
- ETC_GITCONFIG="etc/gitconfig"
GIT_EXEC_PATH="libexec/git-core"
GIT_LOCALE_PATH="share/locale"
GIT_MAN_PATH="share/man"
@@ -220,10 +247,15 @@ add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
if(WIN32)
set(FALLBACK_RUNTIME_PREFIX /mingw64)
- add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}")
+ # Move system config into top-level /etc/
+ add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
+ ETC_GITATTRIBUTES="../etc/gitattributes"
+ ETC_GITCONFIG="../etc/gitconfig")
else()
set(FALLBACK_RUNTIME_PREFIX /home/$ENV{USER})
- add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}")
+ add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
+ ETC_GITATTRIBUTES="etc/gitattributes"
+ ETC_GITCONFIG="etc/gitconfig")
endif()
@@ -238,16 +270,24 @@ 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)
- list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c compat/win32/path-utils.c
- compat/win32/pthread.c compat/win32mmap.c compat/win32/syslog.c
- compat/win32/trace2_win32_process_info.c compat/win32/dirent.c
- compat/nedmalloc/nedmalloc.c compat/strdup.c)
+ HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM)
+ list(APPEND compat_SOURCES
+ compat/mingw.c
+ compat/winansi.c
+ compat/win32/flush.c
+ compat/win32/path-utils.c
+ compat/win32/pthread.c
+ compat/win32mmap.c
+ compat/win32/syslog.c
+ compat/win32/trace2_win32_process_info.c
+ compat/win32/dirent.c
+ compat/nedmalloc/nedmalloc.c
+ compat/strdup.c)
set(NO_UNIX_SOCKETS 1)
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")
@@ -263,6 +303,28 @@ else()
endif()
endif()
+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()
+
set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
#header checks
@@ -552,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)
@@ -602,6 +664,13 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h)
endif()
+if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h)
+ message("Generating hook-list.h")
+ execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h)
+endif()
+
include_directories(${CMAKE_BINARY_DIR})
#build
@@ -618,6 +687,12 @@ parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
add_library(xdiff STATIC ${libxdiff_SOURCES})
+#reftable
+parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
+
+list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+add_library(reftable STATIC ${reftable_SOURCES})
+
if(WIN32)
if(NOT MSVC)#use windres when compiling with gcc and clang
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
@@ -640,13 +715,17 @@ endif()
#link all required libraries to common-main
add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
-target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES})
+target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES})
if(Intl_FOUND)
target_link_libraries(common-main ${Intl_LIBRARIES})
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)
@@ -659,6 +738,15 @@ if(WIN32)
else()
message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
endif()
+
+ add_executable(headless-git ${CMAKE_SOURCE_DIR}/compat/win32/headless.c)
+ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ target_link_options(headless-git PUBLIC -municode -Wl,-subsystem,windows)
+ elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS)
+ else()
+ message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
+ endif()
elseif(UNIX)
target_link_libraries(common-main pthread rt)
endif()
@@ -682,6 +770,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)
@@ -752,7 +843,6 @@ foreach(script ${git_shell_scripts})
string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}")
string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}")
string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}")
- string(REPLACE "@@SANE_TEXT_GREP@@" "-a" content "${content}")
string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}")
file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
endforeach()
@@ -829,7 +919,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()
@@ -880,11 +970,44 @@ if(BUILD_TESTING)
add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
target_link_libraries(test-fake-ssh common-main)
+#reftable-tests
+parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
+list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+
+#unit-tests
+add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
+
+parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "")
+foreach(unit_test ${unit_test_PROGRAMS})
+ add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
+ target_link_libraries("${unit_test}" unit-test-lib common-main)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ if(MSVC)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ endif()
+ list(APPEND PROGRAMS_BUILT "${unit_test}")
+
+ # t-basic intentionally fails tests, to validate the unit-test infrastructure.
+ # Therefore, it should only be run as part of t0080, which verifies that it
+ # fails only in the expected ways.
+ #
+ # All other unit tests should be run.
+ if(NOT ${unit_test} STREQUAL "t-basic")
+ add_test(NAME "t.unit-tests.${unit_test}"
+ COMMAND "./${unit_test}"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t/unit-tests/bin)
+ endif()
+endforeach()
+
#test-tool
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
-add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
+add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES})
target_link_libraries(test-tool common-main)
set_target_properties(test-fake-ssh test-tool
@@ -899,7 +1022,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)
@@ -940,7 +1063,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 )
@@ -976,42 +1098,42 @@ 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")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
-if(WIN32)
+if(USE_VCPKG)
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
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()
-file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
+file(GLOB test_scripts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
#test
-foreach(tsh ${test_scipts})
- add_test(NAME ${tsh}
- COMMAND ${SH_EXE} ${tsh}
+foreach(tsh ${test_scripts})
+ string(REGEX REPLACE ".*/(.*)\\.sh" "\\1" test_name ${tsh})
+ add_test(NAME "t.suite.${test_name}"
+ 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("t.suite.t7112-reset-submodule" PROPERTIES TIMEOUT 4000)
+
endif()#BUILD_TESTING
diff --git a/contrib/buildsystems/Generators/Vcxproj.pm b/contrib/buildsystems/Generators/Vcxproj.pm
index d258445..b2e68a1 100644
--- a/contrib/buildsystems/Generators/Vcxproj.pm
+++ b/contrib/buildsystems/Generators/Vcxproj.pm
@@ -76,8 +76,8 @@ sub createProject {
my $libs_release = "\n ";
my $libs_debug = "\n ";
- if (!$static_library) {
- $libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
+ if (!$static_library && $name ne 'headless-git') {
+ $libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib|reftable\/libreftable\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
$libs_debug = $libs_release;
$libs_debug =~ s/zlib\.lib/zlibd\.lib/g;
$libs_debug =~ s/libexpat\.lib/libexpatd\.lib/g;
@@ -230,8 +230,9 @@ EOM
print F << "EOM";
</ItemGroup>
EOM
- if (!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') {
+ if ((!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') && !($name =~ /headless-git/)) {
my $uuid_libgit = $$build_structure{"LIBS_libgit_GUID"};
+ my $uuid_libreftable = $$build_structure{"LIBS_reftable/libreftable_GUID"};
my $uuid_xdiff_lib = $$build_structure{"LIBS_xdiff/lib_GUID"};
print F << "EOM";
@@ -241,6 +242,14 @@ EOM
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
EOM
+ if (!($name =~ /xdiff|libreftable/)) {
+ print F << "EOM";
+ <ProjectReference Include="$cdup\\reftable\\libreftable\\libreftable.vcxproj">
+ <Project>$uuid_libreftable</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ </ProjectReference>
+EOM
+ }
if (!($name =~ 'xdiff')) {
print F << "EOM";
<ProjectReference Include="$cdup\\xdiff\\lib\\xdiff_lib.vcxproj">
diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl
index ed6c459..069be7e 100755
--- a/contrib/buildsystems/engine.pl
+++ b/contrib/buildsystems/engine.pl
@@ -371,6 +371,7 @@ sub handleLinkLine
# exit(1);
foreach (@objfiles) {
my $sourcefile = $_;
+ $sourcefile =~ s/^headless-git\.o$/compat\/win32\/headless.c/;
$sourcefile =~ s/\.o$/.c/;
push(@sources, $sourcefile);
push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
diff --git a/contrib/coccinelle/.gitignore b/contrib/coccinelle/.gitignore
index d3f2964..1d45c0a 100644
--- a/contrib/coccinelle/.gitignore
+++ b/contrib/coccinelle/.gitignore
@@ -1 +1 @@
-*.patch*
+*.patch
diff --git a/contrib/coccinelle/README b/contrib/coccinelle/README
index f0e80bd..055ad0e 100644
--- a/contrib/coccinelle/README
+++ b/contrib/coccinelle/README
@@ -1,7 +1,9 @@
-This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
-semantic patches that might be useful to developers.
+= coccinelle
-There are two types of semantic patches:
+This directory provides Coccinelle (http://coccinelle.lip6.fr/) semantic patches
+that might be useful to developers.
+
+== Types of semantic patches
* Using the semantic transformation to check for bad patterns in the code;
The target 'make coccicheck' is designed to check for these patterns and
@@ -41,3 +43,82 @@ 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.
+
+== Authoring and reviewing coccinelle changes
+
+* When a .cocci is made, both the Git changes and .cocci file should be
+ reviewed. When reviewing such a change, do your best to understand the .cocci
+ changes (e.g. by asking the author to explain the change) and be explicit
+ about your understanding of the changes. This helps us decide whether input
+ from coccinelle experts is needed or not. If you aren't sure of the cocci
+ changes, indicate what changes you actively endorse and leave an Acked-by
+ (instead of Reviewed-by).
+
+* Authors should consider that reviewers may not be coccinelle experts, thus the
+ the .cocci changes may not be self-evident. A plain text description of the
+ changes is strongly encouraged, especially when using more esoteric features
+ of the language.
+
+* .cocci rules should target only the problem it is trying to solve; "collateral
+ damage" is not allowed. Reviewers should look out and flag overly-broad rules.
+
+* Consider the cost-benefit ratio of .cocci changes. In particular, consider the
+ effect on the runtime of "make coccicheck", and how often your .cocci check
+ will catch something valuable. As a rule of thumb, rules that can bail early
+ if a file doesn't have a particular token will have a small impact on runtime,
+ and vice-versa.
+
+* .cocci files used for refactoring should be temporarily kept in-tree to aid
+ the refactoring of out-of-tree code (e.g. in-flight topics). Periodically
+ evaluate the cost-benefit ratio to determine when the file should be removed.
+ For example, consider how many out-of-tree users are left and how much this
+ slows down "make coccicheck".
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci
index 9a4f00c..27a3b47 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;
@@ -96,3 +94,10 @@ expression n != 1;
@@
- ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) )
+ CALLOC_ARRAY(ptr, n)
+
+@@
+expression dst, src, n;
+@@
+-ALLOC_ARRAY(dst, n);
+-COPY_ARRAY(dst, src, n);
++DUP_ARRAY(dst, src, n);
diff --git a/contrib/coccinelle/config_fn_ctx.pending.cocci b/contrib/coccinelle/config_fn_ctx.pending.cocci
new file mode 100644
index 0000000..6d3d100
--- /dev/null
+++ b/contrib/coccinelle/config_fn_ctx.pending.cocci
@@ -0,0 +1,144 @@
+@ get_fn @
+identifier fn, R;
+@@
+(
+(
+git_config_from_file
+|
+git_config_from_file_with_options
+|
+git_config_from_mem
+|
+git_config_from_blob_oid
+|
+read_early_config
+|
+read_very_early_config
+|
+config_with_options
+|
+git_config
+|
+git_protected_config
+|
+config_from_gitmodules
+)
+ (fn, ...)
+|
+repo_config(R, fn, ...)
+)
+
+@ extends get_fn @
+identifier C1, C2, D;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D);
+
+@ extends get_fn @
+@@
+int fn(const char *, const char *,
++ const struct config_context *,
+ void *);
+
+@ extends get_fn @
+// Don't change fns that look like callback fns but aren't
+identifier fn2 != tar_filter_config && != git_diff_heuristic_config &&
+ != git_default_submodule_config && != git_color_config &&
+ != bundle_list_update && != parse_object_filter_config;
+identifier C1, C2, D1, D2, S;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D1) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
+
+@ extends get_fn@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+
+// The previous rules don't catch all callbacks, especially if they're defined
+// in a separate file from the git_config() call. Fix these manually.
+@@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int
+(
+git_ident_config
+|
+urlmatch_collect_fn
+|
+write_one_config
+|
+forbid_remote_url
+|
+credential_config_callback
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+@@
+identifier C1, C2, D, D2, S, fn2;
+@@
+int
+(
+http_options
+|
+git_status_config
+|
+git_commit_config
+|
+git_default_core_config
+|
+grep_config
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
diff --git a/contrib/coccinelle/equals-null.cocci b/contrib/coccinelle/equals-null.cocci
new file mode 100644
index 0000000..92c7054
--- /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 4490069..6fb9eb6 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/git_config_number.cocci b/contrib/coccinelle/git_config_number.cocci
new file mode 100644
index 0000000..7b57dce
--- /dev/null
+++ b/contrib/coccinelle/git_config_number.cocci
@@ -0,0 +1,27 @@
+@@
+identifier C1, C2, C3;
+@@
+(
+(
+git_config_int
+|
+git_config_int64
+|
+git_config_ulong
+|
+git_config_ssize_t
+)
+ (C1, C2
++ , ctx->kvi
+ )
+|
+(
+git_configset_get_value
+|
+git_config_bool_or_int
+)
+ (C1, C2
++ , ctx->kvi
+ , C3
+ )
+)
diff --git a/contrib/coccinelle/hashmap.cocci b/contrib/coccinelle/hashmap.cocci
index d69e120..c5dbb45 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 0000000..31e36cf
--- /dev/null
+++ b/contrib/coccinelle/index-compatibility.cocci
@@ -0,0 +1,157 @@
+// the_index.* variables
+@@
+identifier AC = active_cache;
+identifier AN = active_nr;
+identifier ACC = active_cache_changed;
+identifier ACT = active_cache_tree;
+@@
+(
+- AC
++ the_index.cache
+|
+- AN
++ the_index.cache_nr
+|
+- ACC
++ the_index.cache_changed
+|
+- ACT
++ the_index.cache_tree
+)
+
+// "the_repository" simple cases
+@@
+@@
+(
+- read_cache
++ repo_read_index
+|
+- 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
+|
+- cache_name_pos
++ index_name_pos
+|
+- update_main_cache_tree
++ cache_tree_update
+|
+- discard_cache
++ discard_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
+ )
+
+@@
+expression O;
+@@
+- write_cache_as_tree
++ write_index_as_tree
+ (
+- O,
++ O, &the_index, get_index_file(),
+ ...
+ )
diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci
index ddf4f22..01f8d69 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 7fe1e8d..ae42cb0 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 0000000..29e9352
--- /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 d9ada69..5f06105 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -1,4 +1,4 @@
-@ strbuf_addf_with_format_only @
+@@
expression E;
constant fmt !~ "%";
@@
@@ -15,7 +15,7 @@ constant fmt !~ "%";
@@
expression E;
struct strbuf SB;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SB.buf);
+ strbuf_addbuf(E, &SB);
@@ -23,7 +23,7 @@ format F =~ "s";
@@
expression E;
struct strbuf *SBP;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SBP->buf);
+ strbuf_addbuf(E, SBP);
@@ -44,7 +44,7 @@ struct strbuf *SBP;
@@
expression E1, E2;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E1, "%@F@", E2);
+ strbuf_addstr(E1, E2);
diff --git a/contrib/coccinelle/swap.cocci b/contrib/coccinelle/swap.cocci
index a0934d1..522177a 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 0000000..96d4abc
--- /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 0000000..f90fd9f
--- /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/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
new file mode 100644
index 0000000..765ad68
--- /dev/null
+++ b/contrib/coccinelle/the_repository.cocci
@@ -0,0 +1,123 @@
+// Fully migrated "the_repository" additions
+@@
+@@
+(
+// cache.h
+- get_oid
++ repo_get_oid
+|
+- get_oid_commit
++ repo_get_oid_commit
+|
+- get_oid_committish
++ repo_get_oid_committish
+|
+- get_oid_tree
++ repo_get_oid_tree
+|
+- get_oid_treeish
++ repo_get_oid_treeish
+|
+- get_oid_blob
++ repo_get_oid_blob
+|
+- get_oid_mb
++ repo_get_oid_mb
+|
+- find_unique_abbrev
++ repo_find_unique_abbrev
+|
+- find_unique_abbrev_r
++ repo_find_unique_abbrev_r
+|
+- for_each_abbrev
++ repo_for_each_abbrev
+|
+- interpret_branch_name
++ repo_interpret_branch_name
+|
+- peel_to_type
++ repo_peel_to_type
+// commit-reach.h
+|
+- get_merge_bases
++ repo_get_merge_bases
+|
+- get_merge_bases_many
++ repo_get_merge_bases_many
+|
+- get_merge_bases_many_dirty
++ repo_get_merge_bases_many_dirty
+|
+- in_merge_bases
++ repo_in_merge_bases
+|
+- in_merge_bases_many
++ repo_in_merge_bases_many
+// commit.h
+|
+- parse_commit_internal
++ repo_parse_commit_internal
+|
+- parse_commit
++ repo_parse_commit
+|
+- get_commit_buffer
++ repo_get_commit_buffer
+|
+- unuse_commit_buffer
++ repo_unuse_commit_buffer
+|
+- logmsg_reencode
++ repo_logmsg_reencode
+|
+- get_commit_tree
++ repo_get_commit_tree
+// diff.h
+|
+- diff_setup
++ repo_diff_setup
+// object-store.h
+|
+- read_object_file
++ repo_read_object_file
+|
+- has_object_file
++ repo_has_object_file
+|
+- has_object_file_with_flags
++ repo_has_object_file_with_flags
+// pretty.h
+|
+- format_commit_message
++ repo_format_commit_message
+// packfile.h
+|
+- approximate_object_count
++ repo_approximate_object_count
+// promisor-remote.h
+|
+- promisor_remote_reinit
++ repo_promisor_remote_reinit
+|
+- promisor_remote_find
++ repo_promisor_remote_find
+|
+- has_promisor_remote
++ repo_has_promisor_remote
+// refs.h
+|
+- dwim_ref
++ repo_dwim_ref
+// rerere.h
+|
+- rerere
++ repo_rerere
+// revision.h
+|
+- init_revisions
++ repo_init_revisions
+)
+ (
++ the_repository,
+ ...)
diff --git a/contrib/coccinelle/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci
deleted file mode 100644
index 2ee702e..0000000
--- a/contrib/coccinelle/the_repository.pending.cocci
+++ /dev/null
@@ -1,144 +0,0 @@
-// This file is used for the ongoing refactoring of
-// bringing the index or repository struct in all of
-// our code base.
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- read_object_file(
-+ repo_read_object_file(the_repository,
- E, F, 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,
- E)
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- parse_commit_internal(
-+ repo_parse_commit_internal(the_repository,
- E, F, G)
-
-@@
-expression E;
-expression F;
-@@
-- parse_commit_gently(
-+ repo_parse_commit_gently(the_repository,
- E, F)
-
-@@
-expression E;
-@@
-- parse_commit(
-+ repo_parse_commit(the_repository,
- E)
-
-@@
-expression E;
-expression F;
-@@
-- get_merge_bases(
-+ repo_get_merge_bases(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- get_merge_bases_many(
-+ repo_get_merge_bases_many(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- get_merge_bases_many_dirty(
-+ repo_get_merge_bases_many_dirty(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-@@
-- in_merge_bases(
-+ repo_in_merge_bases(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- in_merge_bases_many(
-+ repo_in_merge_bases_many(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-@@
-- get_commit_buffer(
-+ repo_get_commit_buffer(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-@@
-- unuse_commit_buffer(
-+ repo_unuse_commit_buffer(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- logmsg_reencode(
-+ repo_logmsg_reencode(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-expression G;
-expression H;
-@@
-- format_commit_message(
-+ repo_format_commit_message(the_repository,
- E, F, G, H);
diff --git a/contrib/coccinelle/xopen.cocci b/contrib/coccinelle/xopen.cocci
new file mode 100644
index 0000000..b71db67
--- /dev/null
+++ b/contrib/coccinelle/xopen.cocci
@@ -0,0 +1,19 @@
+@@
+identifier fd;
+identifier die_fn =~ "^(die|die_errno)$";
+@@
+ int fd =
+- open
++ xopen
+ (...);
+- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }
+
+@@
+expression fd;
+identifier die_fn =~ "^(die|die_errno)$";
+@@
+ fd =
+- open
++ xopen
+ (...);
+- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }
diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci
index 8e05d1c..9c1d293 100644
--- a/contrib/coccinelle/xstrdup_or_null.cocci
+++ b/contrib/coccinelle/xstrdup_or_null.cocci
@@ -1,13 +1,5 @@
@@
expression E;
-expression V;
-@@
-- if (E)
-- V = xstrdup(E);
-+ V = xstrdup_or_null(E);
-
-@@
-expression E;
@@
- xstrdup(absolute_path(E))
+ absolute_pathdup(E)
diff --git a/contrib/coccinelle/xstrncmpz.cocci b/contrib/coccinelle/xstrncmpz.cocci
new file mode 100644
index 0000000..ccb39e2
--- /dev/null
+++ b/contrib/coccinelle/xstrncmpz.cocci
@@ -0,0 +1,28 @@
+@@
+expression S, T, L;
+@@
+(
+- strncmp(S, T, L) || S[L]
++ !!xstrncmpz(S, T, L)
+|
+- strncmp(S, T, L) || S[L] != '\0'
++ !!xstrncmpz(S, T, L)
+|
+- strncmp(S, T, L) || T[L]
++ !!xstrncmpz(T, S, L)
+|
+- strncmp(S, T, L) || T[L] != '\0'
++ !!xstrncmpz(T, S, L)
+|
+- !strncmp(S, T, L) && !S[L]
++ !xstrncmpz(S, T, L)
+|
+- !strncmp(S, T, L) && S[L] == '\0'
++ !xstrncmpz(S, T, L)
+|
+- !strncmp(S, T, L) && !T[L]
++ !xstrncmpz(T, S, L)
+|
+- !strncmp(S, T, L) && T[L] == '\0'
++ !xstrncmpz(T, S, L)
+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b50c5d0..75193de 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -28,6 +28,8 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
+# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
+# just like the 'git commit' command.
#
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
@@ -49,10 +51,21 @@
# and git-switch completion (e.g., completing "foo" when "origin/foo"
# exists).
#
+# GIT_COMPLETION_SHOW_ALL_COMMANDS
+#
+# When set to "1" suggest all commands, including plumbing commands
+# which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
+#
# GIT_COMPLETION_SHOW_ALL
#
# 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 ;;
@@ -109,6 +122,40 @@ __git ()
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
}
+# Helper function to read the first line of a file into a variable.
+# __git_eread requires 2 arguments, the file path and the name of the
+# variable, in that order.
+#
+# This is taken from git-prompt.sh.
+__git_eread ()
+{
+ test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
+}
+
+# Runs git in $__git_repo_path to determine whether a pseudoref exists.
+# 1: The pseudo-ref to search
+__git_pseudoref_exists ()
+{
+ local ref=$1
+ local head
+
+ __git_find_repo_path
+
+ # If the reftable is in use, we have to shell out to 'git rev-parse'
+ # to determine whether the ref exists instead of looking directly in
+ # the filesystem to determine whether the ref exists. Otherwise, use
+ # Bash builtins since executing Git commands are expensive on some
+ # platforms.
+ if __git_eread "$__git_repo_path/HEAD" head; then
+ if [ "$head" == "ref: refs/heads/.invalid" ]; then
+ __git show-ref --exists "$ref"
+ return $?
+ fi
+ fi
+
+ [ -f "$__git_repo_path/$ref" ]
+}
+
# Removes backslash escaping, single quotes and double quotes from a word,
# stores the result in the variable $dequoted_word.
# 1: The word to dequote.
@@ -356,7 +403,7 @@ __gitcomp ()
local cur_="${3-$cur}"
case "$cur_" in
- --*=)
+ *=)
;;
--no-*)
local c i=0 IFS=$' \t\n'
@@ -407,21 +454,23 @@ fi
# This function is equivalent to
#
-# __gitcomp "$(git xxx --git-completion-helper) ..."
+# ___git_resolved_builtins=$(git xxx --git-completion-helper)
#
-# except that the output is cached. Accept 1-3 arguments:
+# except that the result of the execution is cached.
+#
+# Accept 1-3 arguments:
# 1: the git command to execute, this is also the cache key
+# (use "_" when the command contains spaces, e.g. "remote add"
+# becomes "remote_add")
# 2: extra options to be added on top (e.g. negative forms)
# 3: options to be excluded
-__gitcomp_builtin ()
+__git_resolve_builtins ()
{
- # spaces must be replaced with underscore for multi-word
- # commands, e.g. "git remote add" becomes remote_add.
local cmd="$1"
local incl="${2-}"
local excl="${3-}"
- local var=__gitcomp_builtin_"${cmd/-/_}"
+ local var=__gitcomp_builtin_"${cmd//-/_}"
local options
eval "options=\${$var-}"
@@ -442,7 +491,24 @@ __gitcomp_builtin ()
eval "$var=\"$options\""
fi
- __gitcomp "$options"
+ ___git_resolved_builtins="$options"
+}
+
+# This function is equivalent to
+#
+# __gitcomp "$(git xxx --git-completion-helper) ..."
+#
+# except that the output is cached. Accept 1-3 arguments:
+# 1: the git command to execute, this is also the cache key
+# (use "_" when the command contains spaces, e.g. "remote add"
+# becomes "remote_add")
+# 2: extra options to be added on top (e.g. negative forms)
+# 3: options to be excluded
+__gitcomp_builtin ()
+{
+ __git_resolve_builtins "$1" "$2" "$3"
+
+ __gitcomp "$___git_resolved_builtins"
}
# Variation of __gitcomp_nl () that appends to the existing list of
@@ -509,13 +575,33 @@ __gitcomp_file ()
true
}
+# Find the current subcommand for commands that follow the syntax:
+#
+# git <command> <subcommand>
+#
+# 1: List of possible subcommands.
+# 2: Optional subcommand to return when none is found.
+__git_find_subcommand ()
+{
+ local subcommand subcommands="$1" default_subcommand="$2"
+
+ for subcommand in $subcommands; do
+ if [ "$subcommand" = "${words[__git_cmd_idx+1]}" ]; then
+ echo $subcommand
+ return
+ fi
+ done
+
+ echo $default_subcommand
+}
+
# Execute 'git ls-files', unless the --committable option is specified, in
# which case it runs 'git diff-index' to find out the files that can be
# committed. It return paths relative to the directory specified in the first
# argument, and using the options specified in the second argument.
__git_ls_files_helper ()
{
- if [ "$2" == "--committable" ]; then
+ if [ "$2" = "--committable" ]; then
__git -C "$1" -c core.quotePath=false diff-index \
--name-only --relative HEAD -- "${3//\\/\\\\}*"
else
@@ -641,6 +727,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_*/**"
}
@@ -654,6 +741,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_*/**"
}
@@ -664,6 +752,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_*/**"
}
@@ -683,6 +772,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
}
@@ -707,6 +797,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
@@ -730,12 +821,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/*)
@@ -744,9 +842,9 @@ __git_refs ()
track=""
;;
*)
- for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
+ for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
case "$i" in
- $match*)
+ $match*|$umatch*)
if [ -e "$dir/$i" ]; then
echo "$pfx$i$sfx"
fi
@@ -760,6 +858,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"
@@ -779,15 +878,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*" \
@@ -1157,7 +1257,7 @@ __git_aliased_command ()
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
- cur="$word"
+ cur="${word%;}"
break
esac
done
@@ -1422,12 +1522,32 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad good skip reset visualize replay log run"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ __git_find_repo_path
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
+ if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
+
+ # We will complete any custom terms, but still always complete the
+ # more usual bad/new/good/old because git bisect gives a good error
+ # message if these are given when not in use, and that's better than
+ # silent refusal to complete if the user is confused.
+ #
+ # We want to recognize 'view' but not complete it, because it overlaps
+ # with 'visualize' too much and is just an alias for it.
+ #
+ local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
+ local all_subcommands="$completable_subcommands view"
+
+ local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
+
if [ -z "$subcommand" ]; then
__git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
- __gitcomp "$subcommands"
+ __gitcomp "$completable_subcommands"
else
__gitcomp "replay start"
fi
@@ -1435,7 +1555,26 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|good|reset|skip|start)
+ start)
+ case "$cur" in
+ --*)
+ __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
+ return
+ ;;
+ *)
+ __git_complete_refs
+ ;;
+ esac
+ ;;
+ terms)
+ __gitcomp "--term-good --term-old --term-bad --term-new"
+ return
+ ;;
+ visualize|view)
+ __git_complete_log_opts
+ return
+ ;;
+ bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
*)
@@ -1566,7 +1705,7 @@ _git_checkout ()
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--*)
__gitcomp_builtin checkout
@@ -1582,7 +1721,7 @@ _git_checkout ()
if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
__git_complete_refs --mode="refs"
- elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
__git_complete_refs --mode="remote-heads"
else
__git_complete_refs $dwim_opt --mode="refs"
@@ -1597,8 +1736,7 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
_git_cherry_pick ()
{
- __git_find_repo_path
- if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
+ if __git_pseudoref_exists CHERRY_PICK_HEAD; then
__gitcomp "$__git_cherry_pick_inprogress_options"
return
fi
@@ -1652,6 +1790,11 @@ _git_clone ()
__git_untracked_file_modes="all no normal"
+__git_trailer_tokens ()
+{
+ __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev
+}
+
_git_commit ()
{
case "$prev" in
@@ -1676,6 +1819,10 @@ _git_commit ()
__gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
return
;;
+ --trailer=*)
+ __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
+ return
+ ;;
--*)
__gitcomp_builtin commit
return
@@ -1708,31 +1855,44 @@ __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
__git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
ignore-all-space allow-indentation-change"
+__git_ws_error_highlight_opts="context old new all default"
+
+# Options for the diff machinery (diff, log, show, stash, range-diff, ...)
__git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
--color-moved --color-moved= --no-color-moved
--color-moved-ws= --no-color-moved-ws
--full-index --binary --abbrev --diff-filter=
+ --find-copies --find-object --find-renames
+ --no-relative --relative
--find-copies-harder --ignore-cr-at-eol
--text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --ignore-blank-lines --exit-code
- --quiet --ext-diff --no-ext-diff
+ --quiet --ext-diff --no-ext-diff --unified=
--no-prefix --src-prefix= --dst-prefix=
- --inter-hunk-context=
+ --inter-hunk-context= --function-context
--patience --histogram --minimal
--raw --word-diff --word-diff-regex=
--dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative
- --diff-algorithm=
+ --diff-algorithm= --default-prefix
--submodule --submodule= --ignore-submodules
--indent-heuristic --no-indent-heuristic
- --textconv --no-textconv
- --patch --no-patch
+ --textconv --no-textconv --break-rewrites
+ --patch --no-patch --cc --combined-all-paths
+ --anchored= --compact-summary --ignore-matching-lines=
+ --irreversible-delete --line-prefix --no-stat
+ --output= --output-indicator-context=
+ --output-indicator-new= --output-indicator-old=
+ --ws-error-highlight=
+ --pickaxe-all --pickaxe-regex --patch-with-raw
"
-__git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
- --base --ours --theirs --no-index --relative --merge-base
+# Options for diff/difftool
+__git_diff_difftool_options="--cached --staged
+ --base --ours --theirs --no-index --merge-base
+ --ita-invisible-in-index --ita-visible-in-index
$__git_diff_common_options"
_git_diff ()
@@ -1756,6 +1916,10 @@ _git_diff ()
__gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--*)
__gitcomp "$__git_diff_difftool_options"
return
@@ -1986,6 +2150,16 @@ __git_log_common_options="
--min-age= --until= --before=
--min-parents= --max-parents=
--no-min-parents --no-max-parents
+ --alternate-refs --ancestry-path
+ --author-date-order --basic-regexp
+ --bisect --boundary --exclude-first-parent-only
+ --exclude-hidden --extended-regexp
+ --fixed-strings --grep-reflog
+ --ignore-missing --left-only --perl-regexp
+ --reflog --regexp-ignore-case --remove-empty
+ --right-only --show-linear-break
+ --show-notes-by-default --show-pulls
+ --since-as-filter --single-worktree
"
# Options that go well for log and gitk (not shortlog)
__git_log_gitk_options="
@@ -1998,17 +2172,26 @@ __git_log_shortlog_options="
--author= --committer= --grep=
--all-match --invert-grep
"
+# Options accepted by log and show
+__git_log_show_options="
+ --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff
+ --encoding=
+"
+
+__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
-__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
+__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
-_git_log ()
+# Complete porcelain (i.e. not git-rev-list) options and at least some
+# option arguments accepted by git-log. Note that this same set of options
+# are also accepted by some other git commands besides git-log.
+__git_complete_log_opts ()
{
- __git_has_doubledash && return
- __git_find_repo_path
+ COMPREPLY=()
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$prev,$cur" in
@@ -2046,15 +2229,24 @@ _git_log ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--no-walk=*)
__gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
return
;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "
$__git_log_common_options
$__git_log_shortlog_options
$__git_log_gitk_options
+ $__git_log_show_options
--root --topo-order --date-order --reverse
--follow --full-diff
--abbrev-commit --no-abbrev-commit --abbrev=
@@ -2069,9 +2261,10 @@ _git_log ()
--no-walk --no-walk= --do-walk
--parents --children
--expand-tabs --expand-tabs= --no-expand-tabs
+ --clear-decorations --decorate-refs=
+ --decorate-refs-exclude=
$merge
$__git_diff_common_options
- --pickaxe-all --pickaxe-regex
"
return
;;
@@ -2091,6 +2284,16 @@ _git_log ()
return
;;
esac
+}
+
+_git_log ()
+{
+ __git_has_doubledash && return
+ __git_find_repo_path
+
+ __git_complete_log_opts
+ [ ${#COMPREPLY[@]} -eq 0 ] || return
+
__git_complete_revlist
}
@@ -2307,13 +2510,30 @@ _git_rebase ()
_git_reflog ()
{
- local subcommands="show delete expire"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ local subcommands subcommand
- if [ -z "$subcommand" ]; then
- __gitcomp "$subcommands"
- else
- __git_complete_refs
+ __git_resolve_builtins "reflog"
+
+ subcommands="$___git_resolved_builtins"
+ subcommand="$(__git_find_subcommand "$subcommands" "show")"
+
+ case "$subcommand,$cur" in
+ show,--*)
+ __gitcomp "
+ $__git_log_common_options
+ "
+ return
+ ;;
+ $subcommand,--*)
+ __gitcomp_builtin "reflog_$subcommand"
+ return
+ ;;
+ esac
+
+ __git_complete_refs
+
+ if [ $((cword - __git_cmd_idx)) -eq 1 ]; then
+ __gitcompappend "$subcommands" "" "$cur" " "
fi
}
@@ -2358,16 +2578,7 @@ _git_send_email ()
return
;;
--*)
- __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
- --compose --confirm= --dry-run --envelope-sender
- --from --identity
- --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
- --no-suppress-from --no-thread --quiet --reply-to
- --signed-off-by-cc --smtp-pass --smtp-server
- --smtp-server-port --smtp-encryption= --smtp-user
- --subject --suppress-cc= --suppress-from --thread --to
- --validate --no-validate
- $__git_format_patch_extra_options"
+ __gitcomp_builtin send-email "$__git_format_patch_extra_options"
return
;;
esac
@@ -2445,7 +2656,7 @@ _git_switch ()
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--*)
__gitcomp_builtin switch
@@ -2467,7 +2678,7 @@ _git_switch ()
if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
__git_complete_refs --mode="refs"
- elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
__git_complete_refs --mode="remote-heads"
else
__git_complete_refs $dwim_opt --mode="heads"
@@ -2502,7 +2713,41 @@ __git_config_vars=
__git_compute_config_vars ()
{
test -n "$__git_config_vars" ||
- __git_config_vars="$(git help --config-for-completion | sort -u)"
+ __git_config_vars="$(git help --config-for-completion)"
+}
+
+__git_config_vars_all=
+__git_compute_config_vars_all ()
+{
+ test -n "$__git_config_vars_all" ||
+ __git_config_vars_all="$(git --no-pager help --config)"
+}
+
+__git_compute_first_level_config_vars_for_section ()
+{
+ local section="$1"
+ __git_compute_config_vars
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ test -n "${!this_section}" ||
+ printf -v "__git_first_level_config_vars_for_section_${section}" %s \
+ "$(echo "$__git_config_vars" | awk -F. "/^${section}\.[a-z]/ { print \$2 }")"
+}
+
+__git_compute_second_level_config_vars_for_section ()
+{
+ local section="$1"
+ __git_compute_config_vars_all
+ local this_section="__git_second_level_config_vars_for_section_${section}"
+ test -n "${!this_section}" ||
+ printf -v "__git_second_level_config_vars_for_section_${section}" %s \
+ "$(echo "$__git_config_vars_all" | awk -F. "/^${section}\.</ { print \$3 }")"
+}
+
+__git_config_sections=
+__git_compute_config_sections ()
+{
+ test -n "$__git_config_sections" ||
+ __git_config_sections="$(git help --config-sections-for-completion)"
}
# Completes possible values of various configuration variables.
@@ -2542,7 +2787,7 @@ __git_complete_config_variable_value ()
return
;;
branch.*.rebase)
- __gitcomp "false true merges preserve interactive" "" "$cur_"
+ __gitcomp "false true merges interactive" "" "$cur_"
return
;;
remote.pushdefault)
@@ -2642,73 +2887,50 @@ __git_complete_config_variable_name ()
done
case "$cur_" in
- branch.*.*)
+ branch.*.*|guitool.*.*|difftool.*.*|man.*.*|mergetool.*.*|remote.*.*|submodule.*.*|url.*.*)
local pfx="${cur_%.*}."
cur_="${cur_##*.}"
- __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
+ local section="${pfx%.*.}"
+ __git_compute_second_level_config_vars_for_section "${section}"
+ local this_section="__git_second_level_config_vars_for_section_${section}"
+ __gitcomp "${!this_section}" "$pfx" "$cur_" "$sfx"
return
;;
branch.*)
- local pfx="${cur%.*}."
- cur_="${cur#*.}"
- __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
- __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
- return
- ;;
- guitool.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "
- argPrompt cmd confirm needsFile noConsole noRescan
- prompt revPrompt revUnmerged title
- " "$pfx" "$cur_" "$sfx"
- return
- ;;
- difftool.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
- return
- ;;
- man.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
- return
- ;;
- mergetool.*.*)
local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
+ cur_="${cur_#*.}"
+ local section="${pfx%.}"
+ __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
pager.*)
local pfx="${cur_%.*}."
cur_="${cur_#*.}"
__git_compute_all_commands
- __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
- return
- ;;
- remote.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "
- url proxy fetch push mirror skipDefaultUpdate
- receivepack uploadpack tagOpt pushurl
- " "$pfx" "$cur_" "$sfx"
+ __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }"
return
;;
remote.*)
local pfx="${cur_%.*}."
cur_="${cur_#*.}"
+ local section="${pfx%.}"
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
- __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
- url.*.*)
+ submodule.*)
local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
+ cur_="${cur_#*.}"
+ local section="${pfx%.}"
+ __gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "."
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
*.*)
@@ -2716,16 +2938,8 @@ __git_complete_config_variable_name ()
__gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
;;
*)
- __git_compute_config_vars
- __gitcomp "$(echo "$__git_config_vars" |
- awk -F . '{
- sections[$1] = 1
- }
- END {
- for (s in sections)
- print s "."
- }
- ')" "" "$cur_"
+ __git_compute_config_sections
+ __gitcomp "$__git_config_sections" "" "$cur_" "."
;;
esac
}
@@ -2886,7 +3100,7 @@ _git_restore ()
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--source=*)
__git_complete_refs --cur="${cur##--source=}"
@@ -2894,6 +3108,10 @@ _git_restore ()
--*)
__gitcomp_builtin restore
;;
+ *)
+ if __git_pseudoref_exists HEAD; then
+ __git_complete_index_file "--modified"
+ fi
esac
}
@@ -2901,8 +3119,7 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
_git_revert ()
{
- __git_find_repo_path
- if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
+ if __git_pseudoref_exists REVERT_HEAD; then
__gitcomp "$__git_revert_inprogress_options"
return
fi
@@ -2972,10 +3189,19 @@ _git_show ()
__gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
--oneline --show-signature
--expand-tabs --expand-tabs= --no-expand-tabs
+ $__git_log_show_options
$__git_diff_common_options
"
return
@@ -2995,24 +3221,169 @@ _git_show_branch ()
__git_complete_revlist
}
+__gitcomp_directories ()
+{
+ local _tmp_dir _tmp_completions _found=0
+
+ # Get the directory of the current token; this differs from dirname
+ # in that it keeps up to the final trailing slash. If no slash found
+ # that's fine too.
+ [[ "$cur" =~ .*/ ]]
+ _tmp_dir=$BASH_REMATCH
+
+ # Find possible directory completions, adding trailing '/' characters,
+ # de-quoting, and handling unusual characters.
+ while IFS= read -r -d $'\0' c ; do
+ # If there are directory completions, find ones that start
+ # with "$cur", the current token, and put those in COMPREPLY
+ if [[ $c == "$cur"* ]]; then
+ COMPREPLY+=("$c/")
+ _found=1
+ fi
+ done < <(__git ls-tree -z -d --name-only HEAD $_tmp_dir)
+
+ if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
+ # No possible further completions any deeper, so assume we're at
+ # a leaf directory and just consider it complete
+ __gitcomp_direct_append "$cur "
+ elif [[ $_found == 0 ]]; then
+ # No possible completions found. Avoid falling back to
+ # bash's default file and directory completion, because all
+ # valid completions have already been searched and the
+ # fallbacks can do nothing but mislead. In fact, they can
+ # mislead in three different ways:
+ # 1) Fallback file completion makes no sense when asking
+ # for directory completions, as this function does.
+ # 2) Fallback directory completion is bad because
+ # e.g. "/pro" is invalid and should NOT complete to
+ # "/proc".
+ # 3) Fallback file/directory completion only completes
+ # on paths that exist in the current working tree,
+ # i.e. which are *already* part of their
+ # sparse-checkout. Thus, normal file and directory
+ # completion is always useless for "git
+ # sparse-checkout add" and is also probelmatic for
+ # "git sparse-checkout set" unless using it to
+ # strictly narrow the checkout.
+ COMPREPLY=( "" )
+ fi
+}
+
+# In non-cone mode, the arguments to {set,add} are supposed to be
+# patterns, relative to the toplevel directory. These can be any kind
+# of general pattern, like 'subdir/*.c' and we can't complete on all
+# of those. However, if the user presses Tab to get tab completion, we
+# presume that they are trying to provide a pattern that names a specific
+# path.
+__gitcomp_slash_leading_paths ()
+{
+ local dequoted_word pfx="" cur_ toplevel
+
+ # Since we are dealing with a sparse-checkout, subdirectories may not
+ # exist in the local working copy. Therefore, we want to run all
+ # ls-files commands relative to the repository toplevel.
+ toplevel="$(git rev-parse --show-toplevel)/"
+
+ __git_dequote "$cur"
+
+ # If the paths provided by the user already start with '/', then
+ # they are considered relative to the toplevel of the repository
+ # already. If they do not start with /, then we need to adjust
+ # them to start with the appropriate prefix.
+ case "$cur" in
+ /*)
+ cur="${cur:1}"
+ ;;
+ *)
+ pfx="$(__git rev-parse --show-prefix)"
+ esac
+
+ # Since sparse-index is limited to cone-mode, in non-cone-mode the
+ # list of valid paths is precisely the cached files in the index.
+ #
+ # NEEDSWORK:
+ # 1) We probably need to take care of cases where ls-files
+ # responds with special quoting.
+ # 2) We probably need to take care of cases where ${cur} has
+ # some kind of special quoting.
+ # 3) On top of any quoting from 1 & 2, we have to provide an extra
+ # level of quoting for any paths that contain a '*', '?', '\',
+ # '[', ']', or leading '#' or '!' since those will be
+ # interpreted by sparse-checkout as something other than a
+ # literal path character.
+ # Since there are two types of quoting here, this might get really
+ # complex. For now, just punt on all of this...
+ completions="$(__git -C "${toplevel}" -c core.quotePath=false \
+ ls-files --cached -- "${pfx}${cur}*" \
+ | sed -e s%^%/% -e 's%$% %')"
+ # Note, above, though that we needed all of the completions to be
+ # prefixed with a '/', and we want to add a space so that bash
+ # completion will actually complete an entry and let us move on to
+ # the next one.
+
+ # Return what we've found.
+ if test -n "$completions"; then
+ # We found some completions; return them
+ local IFS=$'\n'
+ COMPREPLY=($completions)
+ else
+ # Do NOT fall back to bash-style all-local-files-and-dirs
+ # when we find no match. Such options are worse than
+ # useless:
+ # 1. "git sparse-checkout add" needs paths that are NOT
+ # currently in the working copy. "git
+ # sparse-checkout set" does as well, except in the
+ # special cases when users are only trying to narrow
+ # their sparse checkout to a subset of what they
+ # already have.
+ #
+ # 2. A path like '.config' is ambiguous as to whether
+ # the user wants all '.config' files throughout the
+ # tree, or just the one under the current directory.
+ # It would result in a warning from the
+ # sparse-checkout command due to this. As such, all
+ # completions of paths should be prefixed with a
+ # '/'.
+ #
+ # 3. We don't want paths prefixed with a '/' to
+ # complete files in the system root directory, we
+ # want it to complete on files relative to the
+ # repository root.
+ #
+ # As such, make sure that NO completions are offered rather
+ # than falling back to bash's default completions.
+ COMPREPLY=( "" )
+ fi
+}
+
_git_sparse_checkout ()
{
- local subcommands="list init set disable"
+ local subcommands="list init set disable add reapply"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ local using_cone=true
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand,$cur" in
- init,--*)
- __gitcomp "--cone"
- ;;
- set,--*)
- __gitcomp "--stdin"
- ;;
- *)
+ *,--*)
+ __gitcomp_builtin sparse-checkout_$subcommand "" "--"
;;
+ set,*|add,*)
+ if [[ "$(__git config core.sparseCheckout)" == "true" &&
+ "$(__git config core.sparseCheckoutCone)" == "false" &&
+ -z "$(__git_find_on_cmdline --cone)" ]]; then
+ using_cone=false
+ fi
+ if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then
+ using_cone=false
+ fi
+ if [[ "$using_cone" == "true" ]]; then
+ __gitcomp_directories
+ else
+ __gitcomp_slash_leading_paths
+ fi
esac
}
@@ -3258,7 +3629,7 @@ __git_complete_worktree_paths ()
# Generate completion reply from worktree list skipping the first
# entry: it's the path of the main worktree, which can't be moved,
# removed, locked, etc.
- __gitcomp_nl "$(git worktree list --porcelain |
+ __gitcomp_nl "$(__git worktree list --porcelain |
sed -n -e '2,$ s/^worktree //p')"
}
@@ -3464,7 +3835,13 @@ __git_main ()
then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else
- __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
+ local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
+
+ if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
+ then
+ list_cmds=builtins,$list_cmds
+ fi
+ __gitcomp "$(__git --list-cmds=$list_cmds)"
fi
;;
esac
@@ -3488,7 +3865,7 @@ __gitk_main ()
__git_find_repo_path
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$cur" in
@@ -3512,6 +3889,7 @@ fi
__git_func_wrap ()
{
local cur words cword prev
+ local __git_cmd_idx=0
_get_comp_words_by_ref -n =: cur words cword prev
$1
}
diff --git a/contrib/completion/git-completion.tcsh b/contrib/completion/git-completion.tcsh
index 4a790d8..ba797e5 100644
--- a/contrib/completion/git-completion.tcsh
+++ b/contrib/completion/git-completion.tcsh
@@ -80,8 +80,9 @@ else
COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
fi
-# Call _git() or _gitk() of the bash script, based on the first argument
-_\${1}
+# Call __git_wrap__git_main() or __git_wrap__gitk_main() of the bash script,
+# based on the first argument
+__git_wrap__\${1}_main
IFS=\$'\n'
if [ \${#COMPREPLY[*]} -eq 0 ]; then
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index db7c006..5330e76 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -66,6 +66,11 @@
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
+# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
+# find one, or @{upstream} otherwise. Once you have set
+# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
+# setting the bash.showUpstream config variable.
+#
# You can change the separator between the branch name and the above
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
# is SP.
@@ -79,10 +84,9 @@
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
# by setting GIT_PS1_OMITSPARSESTATE.
#
-# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
-# find one, or @{upstream} otherwise. Once you have set
-# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
-# setting the bash.showUpstream config variable.
+# 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
@@ -96,9 +100,7 @@
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
-# the colored output of "git status -sb" and are available only when
-# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
-# but always available in Zsh.
+# the colored output of "git status -sb".
#
# If you would like __git_ps1 to do nothing in the case when the current
# directory is set up to be ignored by git, then set
@@ -115,7 +117,7 @@ __git_ps1_show_upstream ()
{
local key value
local svn_remote svn_url_pattern count n
- local upstream=git legacy="" verbose="" name=""
+ local upstream_type=git legacy="" verbose="" name=""
svn_remote=()
# get some config options from git-config
@@ -132,25 +134,25 @@ __git_ps1_show_upstream ()
svn-remote.*.url)
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
svn_url_pattern="$svn_url_pattern\\|$value"
- upstream=svn+git # default upstream is SVN if available, else git
+ upstream_type=svn+git # default upstream type is SVN if available, else git
;;
esac
done <<< "$output"
# parse configuration values
local option
- for option in ${GIT_PS1_SHOWUPSTREAM}; do
+ for option in ${GIT_PS1_SHOWUPSTREAM-}; do
case "$option" in
- git|svn) upstream="$option" ;;
+ git|svn) upstream_type="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
name) name=1 ;;
esac
done
- # Find our upstream
- case "$upstream" in
- git) upstream="@{upstream}" ;;
+ # Find our upstream type
+ case "$upstream_type" in
+ git) upstream_type="@{upstream}" ;;
svn*)
# get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally)
@@ -167,12 +169,12 @@ __git_ps1_show_upstream ()
if [[ -z "$svn_upstream" ]]; then
# default branch name for checkouts with no layout:
- upstream=${GIT_SVN_ID:-git-svn}
+ upstream_type=${GIT_SVN_ID:-git-svn}
else
- upstream=${svn_upstream#/}
+ upstream_type=${svn_upstream#/}
fi
- elif [[ "svn+git" = "$upstream" ]]; then
- upstream="@{upstream}"
+ elif [[ "svn+git" = "$upstream_type" ]]; then
+ upstream_type="@{upstream}"
fi
;;
esac
@@ -180,11 +182,11 @@ __git_ps1_show_upstream ()
# Find how many commits we are ahead/behind our upstream
if [[ -z "$legacy" ]]; then
count="$(git rev-list --count --left-right \
- "$upstream"...HEAD 2>/dev/null)"
+ "$upstream_type"...HEAD 2>/dev/null)"
else
# produce equivalent output to --count for older versions of git
local commits
- if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
+ if commits="$(git rev-list --left-right "$upstream_type"...HEAD 2>/dev/null)"
then
local commit behind=0 ahead=0
for commit in $commits
@@ -214,26 +216,26 @@ __git_ps1_show_upstream ()
*) # diverged from upstream
p="<>" ;;
esac
- else
+ else # verbose, set upstream instead of p
case "$count" in
"") # no upstream
- p="" ;;
+ upstream="" ;;
"0 0") # equal to upstream
- p=" u=" ;;
+ upstream="|u=" ;;
"0 "*) # ahead of upstream
- p=" u+${count#0 }" ;;
+ upstream="|u+${count#0 }" ;;
*" 0") # behind upstream
- p=" u-${count% 0}" ;;
+ upstream="|u-${count% 0}" ;;
*) # diverged from upstream
- p=" u+${count#* }-${count% *}" ;;
+ upstream="|u+${count#* }-${count% *}" ;;
esac
if [[ -n "$count" && -n "$name" ]]; then
__git_ps1_upstream_name=$(git rev-parse \
- --abbrev-ref "$upstream" 2>/dev/null)
+ --abbrev-ref "$upstream_type" 2>/dev/null)
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
- p="$p \${__git_ps1_upstream_name}"
+ upstream="$upstream \${__git_ps1_upstream_name}"
else
- p="$p ${__git_ps1_upstream_name}"
+ upstream="$upstream ${__git_ps1_upstream_name}"
# not needed anymore; keep user's
# environment clean
unset __git_ps1_upstream_name
@@ -245,7 +247,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
@@ -254,12 +257,12 @@ __git_ps1_colorize_gitstring ()
local c_lblue='%F{blue}'
local c_clear='%f'
else
- # Using \[ and \] around colors is necessary to prevent
+ # Using \001 and \002 around colors is necessary to prevent
# issues with command line editing/browsing/completion!
- local c_red='\[\e[31m\]'
- local c_green='\[\e[32m\]'
- local c_lblue='\[\e[1;34m\]'
- local c_clear='\[\e[0m\]'
+ local c_red=$'\001\e[31m\002'
+ local c_green=$'\001\e[32m\002'
+ local c_lblue=$'\001\e[1;34m\002'
+ local c_clear=$'\001\e[0m\002'
fi
local bad_color=$c_red
local ok_color=$c_green
@@ -271,22 +274,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.
@@ -294,7 +298,7 @@ __git_ps1_colorize_gitstring ()
# variable, in that order.
__git_eread ()
{
- test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
+ test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
}
# see if a cherry-pick or revert is in progress, if the user has committed a
@@ -404,7 +408,7 @@ __git_ps1 ()
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
- --is-bare-repository --is-inside-work-tree \
+ --is-bare-repository --is-inside-work-tree --show-ref-format \
--short HEAD 2>/dev/null)"
rev_parse_exit_code="$?"
@@ -417,6 +421,8 @@ __git_ps1 ()
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
fi
+ local ref_format="${repo_info##*$'\n'}"
+ repo_info="${repo_info%$'\n'*}"
local inside_worktree="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local bare_repo="${repo_info##*$'\n'}"
@@ -475,12 +481,25 @@ __git_ps1 ()
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
- if ! __git_eread "$g/HEAD" head; then
- return $exit
- fi
- # is it a symbolic ref?
- b="${head#ref: }"
- if [ "$head" = "$b" ]; then
+
+ case "$ref_format" in
+ files)
+ if ! __git_eread "$g/HEAD" head; then
+ return $exit
+ fi
+
+ if [[ $head == "ref: "* ]]; then
+ head="${head#ref: }"
+ else
+ head=""
+ fi
+ ;;
+ *)
+ head="$(git symbolic-ref HEAD 2>/dev/null)"
+ ;;
+ esac
+
+ if test -z "$head"; then
detached=yes
b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
@@ -498,6 +517,8 @@ __git_ps1 ()
b="$short_sha..."
b="($b)"
+ else
+ b="$head"
fi
fi
fi
@@ -506,13 +527,20 @@ __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=""
local u=""
local h=""
local c=""
- local p=""
+ local p="" # short version of upstream state indicator
+ local upstream="" # verbose version of upstream state indicator
if [ "true" = "$inside_gitdir" ]; then
if [ "true" = "$bare_repo" ]; then
@@ -555,21 +583,18 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}"
- # 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
- __git_ps1_colorize_gitstring
- 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"
- local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
+ if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
+ __git_ps1_colorize_gitstring
+ fi
+
+ local f="$h$w$i$s$u$p"
+ 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/coverage-diff.sh b/contrib/coverage-diff.sh
index 4ec419f..6ce9603 100755
--- a/contrib/coverage-diff.sh
+++ b/contrib/coverage-diff.sh
@@ -74,8 +74,7 @@ do
sort >uncovered_lines.txt
comm -12 uncovered_lines.txt new_lines.txt |
- sed -e 's/$/\)/' |
- sed -e 's/^/ /' >uncovered_new_lines.txt
+ sed -e 's/$/\)/' -e 's/^/ /' >uncovered_new_lines.txt
grep -q '[^[:space:]]' <uncovered_new_lines.txt &&
echo $file >>coverage-data.txt &&
@@ -91,11 +90,7 @@ cat coverage-data.txt
echo "Commits introducing uncovered code:"
-commit_list=$(cat coverage-data.txt |
- grep -E '^[0-9a-f]{7,} ' |
- awk '{print $1;}' |
- sort |
- uniq)
+commit_list=$(awk '/^[0-9a-f]{7,}/ { print $1 }' coverage-data.txt | sort -u)
(
for commit in $commit_list
diff --git a/contrib/credential/gnome-keyring/.gitignore b/contrib/credential/gnome-keyring/.gitignore
deleted file mode 100644
index 88d8fcd..0000000
--- a/contrib/credential/gnome-keyring/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-git-credential-gnome-keyring
diff --git a/contrib/credential/gnome-keyring/Makefile b/contrib/credential/gnome-keyring/Makefile
deleted file mode 100644
index 22c19df..0000000
--- a/contrib/credential/gnome-keyring/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-MAIN:=git-credential-gnome-keyring
-all:: $(MAIN)
-
-CC = gcc
-RM = rm -f
-CFLAGS = -g -O2 -Wall
-PKG_CONFIG = pkg-config
-
--include ../../../config.mak.autogen
--include ../../../config.mak
-
-INCS:=$(shell $(PKG_CONFIG) --cflags gnome-keyring-1 glib-2.0)
-LIBS:=$(shell $(PKG_CONFIG) --libs gnome-keyring-1 glib-2.0)
-
-SRCS:=$(MAIN).c
-OBJS:=$(SRCS:.c=.o)
-
-%.o: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) $(INCS) -o $@ -c $<
-
-$(MAIN): $(OBJS)
- $(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
-
-clean:
- @$(RM) $(MAIN) $(OBJS)
diff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
deleted file mode 100644
index d389bfa..0000000
--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (C) 2011 John Szakmeister <john@szakmeister.net>
- * 2012 Philipp A. Hartmann <pah@qo.cx>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Credits:
- * - GNOME Keyring API handling originally written by John Szakmeister
- * - ported to credential helper API by Philipp A. Hartmann
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <gnome-keyring.h>
-
-#ifdef GNOME_KEYRING_DEFAULT
-
- /* Modern gnome-keyring */
-
-#include <gnome-keyring-memory.h>
-
-#else
-
- /*
- * Support ancient gnome-keyring, circ. RHEL 5.X.
- * GNOME_KEYRING_DEFAULT seems to have been introduced with Gnome 2.22,
- * and the other features roughly around Gnome 2.20, 6 months before.
- * Ubuntu 8.04 used Gnome 2.22 (I think). Not sure any distro used 2.20.
- * So the existence/non-existence of GNOME_KEYRING_DEFAULT seems like
- * a decent thing to use as an indicator.
- */
-
-#define GNOME_KEYRING_DEFAULT NULL
-
-/*
- * ancient gnome-keyring returns DENIED when an entry is not found.
- * Setting NO_MATCH to DENIED will prevent us from reporting DENIED
- * errors during get and erase operations, but we will still report
- * DENIED errors during a store.
- */
-#define GNOME_KEYRING_RESULT_NO_MATCH GNOME_KEYRING_RESULT_DENIED
-
-#define gnome_keyring_memory_alloc g_malloc
-#define gnome_keyring_memory_free gnome_keyring_free_password
-#define gnome_keyring_memory_strdup g_strdup
-
-static const char *gnome_keyring_result_to_message(GnomeKeyringResult result)
-{
- switch (result) {
- case GNOME_KEYRING_RESULT_OK:
- return "OK";
- case GNOME_KEYRING_RESULT_DENIED:
- return "Denied";
- case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
- return "No Keyring Daemon";
- case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
- return "Already UnLocked";
- case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
- return "No Such Keyring";
- case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
- return "Bad Arguments";
- case GNOME_KEYRING_RESULT_IO_ERROR:
- return "IO Error";
- case GNOME_KEYRING_RESULT_CANCELLED:
- return "Cancelled";
- case GNOME_KEYRING_RESULT_ALREADY_EXISTS:
- return "Already Exists";
- default:
- return "Unknown Error";
- }
-}
-
-/*
- * Support really ancient gnome-keyring, circ. RHEL 4.X.
- * Just a guess for the Glib version. Glib 2.8 was roughly Gnome 2.12 ?
- * Which was released with gnome-keyring 0.4.3 ??
- */
-#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 8
-
-static void gnome_keyring_done_cb(GnomeKeyringResult result, gpointer user_data)
-{
- gpointer *data = (gpointer *)user_data;
- int *done = (int *)data[0];
- GnomeKeyringResult *r = (GnomeKeyringResult *)data[1];
-
- *r = result;
- *done = 1;
-}
-
-static void wait_for_request_completion(int *done)
-{
- GMainContext *mc = g_main_context_default();
- while (!*done)
- g_main_context_iteration(mc, TRUE);
-}
-
-static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, guint32 id)
-{
- int done = 0;
- GnomeKeyringResult result;
- gpointer data[] = { &done, &result };
-
- gnome_keyring_item_delete(keyring, id, gnome_keyring_done_cb, data,
- NULL);
-
- wait_for_request_completion(&done);
-
- return result;
-}
-
-#endif
-#endif
-
-/*
- * This credential struct and API is simplified from git's credential.{h,c}
- */
-struct credential {
- char *protocol;
- char *host;
- unsigned short port;
- char *path;
- char *username;
- char *password;
-};
-
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
-
-typedef int (*credential_op_cb)(struct credential *);
-
-struct credential_operation {
- char *name;
- credential_op_cb op;
-};
-
-#define CREDENTIAL_OP_END { NULL, NULL }
-
-/* ----------------- GNOME Keyring functions ----------------- */
-
-/* create a special keyring option string, if path is given */
-static char *keyring_object(struct credential *c)
-{
- if (!c->path)
- return NULL;
-
- if (c->port)
- return g_strdup_printf("%s:%hd/%s", c->host, c->port, c->path);
-
- return g_strdup_printf("%s/%s", c->host, c->path);
-}
-
-static int keyring_get(struct credential *c)
-{
- char *object = NULL;
- GList *entries;
- GnomeKeyringNetworkPasswordData *password_data;
- GnomeKeyringResult result;
-
- if (!c->protocol || !(c->host || c->path))
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_find_network_password_sync(
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- &entries);
-
- g_free(object);
-
- if (result == GNOME_KEYRING_RESULT_NO_MATCH)
- return EXIT_SUCCESS;
-
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return EXIT_SUCCESS;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- /* pick the first one from the list */
- password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
-
- gnome_keyring_memory_free(c->password);
- c->password = gnome_keyring_memory_strdup(password_data->password);
-
- if (!c->username)
- c->username = g_strdup(password_data->user);
-
- gnome_keyring_network_password_list_free(entries);
-
- return EXIT_SUCCESS;
-}
-
-
-static int keyring_store(struct credential *c)
-{
- guint32 item_id;
- char *object = NULL;
- GnomeKeyringResult result;
-
- /*
- * Sanity check that what we are storing is actually sensible.
- * In particular, we can't make a URL without a protocol field.
- * Without either a host or pathname (depending on the scheme),
- * we have no primary key. And without a username and password,
- * we are not actually storing a credential.
- */
- if (!c->protocol || !(c->host || c->path) ||
- !c->username || !c->password)
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_set_network_password_sync(
- GNOME_KEYRING_DEFAULT,
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- c->password,
- &item_id);
-
- g_free(object);
-
- if (result != GNOME_KEYRING_RESULT_OK &&
- result != GNOME_KEYRING_RESULT_CANCELLED) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
-
-static int keyring_erase(struct credential *c)
-{
- char *object = NULL;
- GList *entries;
- GnomeKeyringNetworkPasswordData *password_data;
- GnomeKeyringResult result;
-
- /*
- * Sanity check that we actually have something to match
- * against. The input we get is a restrictive pattern,
- * so technically a blank credential means "erase everything".
- * But it is too easy to accidentally send this, since it is equivalent
- * to empty input. So explicitly disallow it, and require that the
- * pattern have some actual content to match.
- */
- if (!c->protocol && !c->host && !c->path && !c->username)
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_find_network_password_sync(
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- &entries);
-
- g_free(object);
-
- if (result == GNOME_KEYRING_RESULT_NO_MATCH)
- return EXIT_SUCCESS;
-
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return EXIT_SUCCESS;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- /* pick the first one from the list (delete all matches?) */
- password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
-
- result = gnome_keyring_item_delete_sync(
- password_data->keyring, password_data->item_id);
-
- gnome_keyring_network_password_list_free(entries);
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
-
-/*
- * Table with helper operation callbacks, used by generic
- * credential helper main function.
- */
-static struct credential_operation const credential_helper_ops[] = {
- { "get", keyring_get },
- { "store", keyring_store },
- { "erase", keyring_erase },
- CREDENTIAL_OP_END
-};
-
-/* ------------------ credential functions ------------------ */
-
-static void credential_init(struct credential *c)
-{
- memset(c, 0, sizeof(*c));
-}
-
-static void credential_clear(struct credential *c)
-{
- g_free(c->protocol);
- g_free(c->host);
- g_free(c->path);
- g_free(c->username);
- gnome_keyring_memory_free(c->password);
-
- credential_init(c);
-}
-
-static int credential_read(struct credential *c)
-{
- char *buf;
- size_t line_len;
- char *key;
- char *value;
-
- key = buf = gnome_keyring_memory_alloc(1024);
-
- while (fgets(buf, 1024, stdin)) {
- line_len = strlen(buf);
-
- if (line_len && buf[line_len-1] == '\n')
- buf[--line_len] = '\0';
-
- if (!line_len)
- break;
-
- value = strchr(buf, '=');
- if (!value) {
- g_warning("invalid credential line: %s", key);
- gnome_keyring_memory_free(buf);
- return -1;
- }
- *value++ = '\0';
-
- if (!strcmp(key, "protocol")) {
- g_free(c->protocol);
- c->protocol = g_strdup(value);
- } else if (!strcmp(key, "host")) {
- g_free(c->host);
- c->host = g_strdup(value);
- value = strrchr(c->host, ':');
- if (value) {
- *value++ = '\0';
- c->port = atoi(value);
- }
- } else if (!strcmp(key, "path")) {
- g_free(c->path);
- c->path = g_strdup(value);
- } else if (!strcmp(key, "username")) {
- g_free(c->username);
- c->username = g_strdup(value);
- } else if (!strcmp(key, "password")) {
- gnome_keyring_memory_free(c->password);
- c->password = gnome_keyring_memory_strdup(value);
- while (*value)
- *value++ = '\0';
- }
- /*
- * 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.
- */
- }
-
- gnome_keyring_memory_free(buf);
-
- return 0;
-}
-
-static void credential_write_item(FILE *fp, const char *key, const char *value)
-{
- if (!value)
- return;
- fprintf(fp, "%s=%s\n", key, value);
-}
-
-static void credential_write(const struct credential *c)
-{
- /* only write username/password, if set */
- credential_write_item(stdout, "username", c->username);
- credential_write_item(stdout, "password", c->password);
-}
-
-static void usage(const char *name)
-{
- struct credential_operation const *try_op = credential_helper_ops;
- const char *basename = strrchr(name, '/');
-
- basename = (basename) ? basename + 1 : name;
- fprintf(stderr, "usage: %s <", basename);
- while (try_op->name) {
- fprintf(stderr, "%s", (try_op++)->name);
- if (try_op->name)
- fprintf(stderr, "%s", "|");
- }
- fprintf(stderr, "%s", ">\n");
-}
-
-int main(int argc, char *argv[])
-{
- int ret = EXIT_SUCCESS;
-
- struct credential_operation const *try_op = credential_helper_ops;
- struct credential cred = CREDENTIAL_INIT;
-
- if (!argv[1]) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- g_set_application_name("Git Credential Helper");
-
- /* lookup operation callback */
- while (try_op->name && strcmp(argv[1], try_op->name))
- try_op++;
-
- /* unsupported operation given -- ignore silently */
- if (!try_op->name || !try_op->op)
- goto out;
-
- ret = credential_read(&cred);
- if (ret)
- goto out;
-
- /* perform credential operation */
- ret = (*try_op->op)(&cred);
-
- credential_write(&cred);
-
-out:
- credential_clear(&cred);
- return ret;
-}
diff --git a/contrib/credential/libsecret/.gitignore b/contrib/credential/libsecret/.gitignore
new file mode 100644
index 0000000..4fa2235
--- /dev/null
+++ b/contrib/credential/libsecret/.gitignore
@@ -0,0 +1 @@
+git-credential-libsecret
diff --git a/contrib/credential/libsecret/git-credential-libsecret.c b/contrib/credential/libsecret/git-credential-libsecret.c
index e6598b6..90034d0 100644
--- a/contrib/credential/libsecret/git-credential-libsecret.c
+++ b/contrib/credential/libsecret/git-credential-libsecret.c
@@ -39,9 +39,11 @@ struct credential {
char *path;
char *username;
char *password;
+ char *password_expiry_utc;
+ char *oauth_refresh_token;
};
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
+#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);
@@ -52,8 +54,29 @@ struct credential_operation {
#define CREDENTIAL_OP_END { NULL, NULL }
+static void credential_clear(struct credential *c);
+
/* ----------------- Secret Service functions ----------------- */
+static const SecretSchema schema = {
+ "org.git.Password",
+ /* Ignore schema name during search for backwards compatibility */
+ SECRET_SCHEMA_DONT_MATCH_NAME,
+ {
+ /*
+ * libsecret assumes attribute values are non-confidential and
+ * unchanging, so we can't include oauth_refresh_token or
+ * password_expiry_utc.
+ */
+ { "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "object", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
+ { "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { NULL, 0 },
+ }
+};
+
static char *make_label(struct credential *c)
{
if (c->port)
@@ -101,7 +124,7 @@ static int keyring_get(struct credential *c)
attributes = make_attr_list(c);
items = secret_service_search_sync(service,
- SECRET_SCHEMA_COMPAT_NETWORK,
+ &schema,
attributes,
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
NULL,
@@ -117,6 +140,7 @@ static int keyring_get(struct credential *c)
SecretItem *item;
SecretValue *secret;
const char *s;
+ gchar **parts;
item = items->data;
secret = secret_item_get_secret(item);
@@ -130,8 +154,30 @@ static int keyring_get(struct credential *c)
s = secret_value_get_text(secret);
if (s) {
- g_free(c->password);
- c->password = g_strdup(s);
+ /*
+ * Passwords and other attributes encoded in following format:
+ * hunter2
+ * password_expiry_utc=1684189401
+ * oauth_refresh_token=xyzzy
+ */
+ parts = g_strsplit(s, "\n", 0);
+ if (g_strv_length(parts) >= 1) {
+ g_free(c->password);
+ c->password = g_strdup(parts[0]);
+ } else {
+ g_free(c->password);
+ c->password = g_strdup("");
+ }
+ for (int i = 1; i < g_strv_length(parts); i++) {
+ if (g_str_has_prefix(parts[i], "password_expiry_utc=")) {
+ g_free(c->password_expiry_utc);
+ c->password_expiry_utc = g_strdup(&parts[i][20]);
+ } else if (g_str_has_prefix(parts[i], "oauth_refresh_token=")) {
+ g_free(c->oauth_refresh_token);
+ c->oauth_refresh_token = g_strdup(&parts[i][20]);
+ }
+ }
+ g_strfreev(parts);
}
g_hash_table_unref(attributes);
@@ -148,6 +194,7 @@ static int keyring_store(struct credential *c)
char *label = NULL;
GHashTable *attributes = NULL;
GError *error = NULL;
+ GString *secret = NULL;
/*
* Sanity check that what we are storing is actually sensible.
@@ -162,13 +209,23 @@ static int keyring_store(struct credential *c)
label = make_label(c);
attributes = make_attr_list(c);
- secret_password_storev_sync(SECRET_SCHEMA_COMPAT_NETWORK,
+ secret = g_string_new(c->password);
+ if (c->password_expiry_utc) {
+ g_string_append_printf(secret, "\npassword_expiry_utc=%s",
+ c->password_expiry_utc);
+ }
+ if (c->oauth_refresh_token) {
+ g_string_append_printf(secret, "\noauth_refresh_token=%s",
+ c->oauth_refresh_token);
+ }
+ secret_password_storev_sync(&schema,
attributes,
NULL,
label,
- c->password,
+ secret->str,
NULL,
&error);
+ g_string_free(secret, TRUE);
g_free(label);
g_hash_table_unref(attributes);
@@ -185,6 +242,7 @@ static int keyring_erase(struct credential *c)
{
GHashTable *attributes = NULL;
GError *error = NULL;
+ struct credential existing = CREDENTIAL_INIT;
/*
* Sanity check that we actually have something to match
@@ -197,8 +255,22 @@ static int keyring_erase(struct credential *c)
if (!c->protocol && !c->host && !c->path && !c->username)
return EXIT_FAILURE;
+ if (c->password) {
+ existing.host = g_strdup(c->host);
+ existing.path = g_strdup(c->path);
+ existing.port = c->port;
+ existing.protocol = g_strdup(c->protocol);
+ existing.username = g_strdup(c->username);
+ keyring_get(&existing);
+ if (existing.password && strcmp(c->password, existing.password)) {
+ credential_clear(&existing);
+ return EXIT_SUCCESS;
+ }
+ credential_clear(&existing);
+ }
+
attributes = make_attr_list(c);
- secret_password_clearv_sync(SECRET_SCHEMA_COMPAT_NETWORK,
+ secret_password_clearv_sync(&schema,
attributes,
NULL,
&error);
@@ -238,23 +310,24 @@ static void credential_clear(struct credential *c)
g_free(c->path);
g_free(c->username);
g_free(c->password);
+ g_free(c->password_expiry_utc);
+ g_free(c->oauth_refresh_token);
credential_init(c);
}
static int credential_read(struct credential *c)
{
- char *buf;
- size_t line_len;
+ char *buf = NULL;
+ size_t alloc;
+ ssize_t line_len;
char *key;
char *value;
- key = buf = g_malloc(1024);
-
- while (fgets(buf, 1024, stdin)) {
- line_len = strlen(buf);
+ while ((line_len = getline(&buf, &alloc, stdin)) > 0) {
+ key = buf;
- if (line_len && buf[line_len-1] == '\n')
+ if (buf[line_len-1] == '\n')
buf[--line_len] = '\0';
if (!line_len)
@@ -285,11 +358,19 @@ static int credential_read(struct credential *c)
} else if (!strcmp(key, "username")) {
g_free(c->username);
c->username = g_strdup(value);
+ } else if (!strcmp(key, "password_expiry_utc")) {
+ g_free(c->password_expiry_utc);
+ c->password_expiry_utc = g_strdup(value);
} else if (!strcmp(key, "password")) {
g_free(c->password);
c->password = g_strdup(value);
while (*value)
*value++ = '\0';
+ } else if (!strcmp(key, "oauth_refresh_token")) {
+ g_free(c->oauth_refresh_token);
+ c->oauth_refresh_token = g_strdup(value);
+ while (*value)
+ *value++ = '\0';
}
/*
* Ignore other lines; we don't know what they mean, but
@@ -298,7 +379,7 @@ static int credential_read(struct credential *c)
*/
}
- g_free(buf);
+ free(buf);
return 0;
}
@@ -315,6 +396,10 @@ static void credential_write(const struct credential *c)
/* only write username/password, if set */
credential_write_item(stdout, "username", c->username);
credential_write_item(stdout, "password", c->password);
+ credential_write_item(stdout, "password_expiry_utc",
+ c->password_expiry_utc);
+ credential_write_item(stdout, "oauth_refresh_token",
+ c->oauth_refresh_token);
}
static void usage(const char *name)
diff --git a/contrib/credential/netrc/git-credential-netrc.perl b/contrib/credential/netrc/git-credential-netrc.perl
index bc57cc6..9fb998a 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 07227d0..bf27773 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/Makefile b/contrib/credential/osxkeychain/Makefile
index 4b3a08a..238f5f8 100644
--- a/contrib/credential/osxkeychain/Makefile
+++ b/contrib/credential/osxkeychain/Makefile
@@ -8,7 +8,8 @@ CFLAGS = -g -O2 -Wall
-include ../../../config.mak
git-credential-osxkeychain: git-credential-osxkeychain.o
- $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -Wl,-framework -Wl,Security
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) \
+ -framework Security -framework CoreFoundation
git-credential-osxkeychain.o: git-credential-osxkeychain.c
$(CC) -c $(CFLAGS) $<
diff --git a/contrib/credential/osxkeychain/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
index bcd3f57..6a40917 100644
--- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c
+++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
@@ -3,13 +3,51 @@
#include <stdlib.h>
#include <Security/Security.h>
-static SecProtocolType protocol;
-static char *host;
-static char *path;
-static char *username;
-static char *password;
-static UInt16 port;
+#define ENCODING kCFStringEncodingUTF8
+static CFStringRef protocol; /* Stores constant strings - not memory managed */
+static CFStringRef host;
+static CFNumberRef port;
+static CFStringRef path;
+static CFStringRef username;
+static CFDataRef password;
+static CFDataRef password_expiry_utc;
+static CFDataRef oauth_refresh_token;
+static void clear_credential(void)
+{
+ if (host) {
+ CFRelease(host);
+ host = NULL;
+ }
+ if (port) {
+ CFRelease(port);
+ port = NULL;
+ }
+ if (path) {
+ CFRelease(path);
+ path = NULL;
+ }
+ if (username) {
+ CFRelease(username);
+ username = NULL;
+ }
+ if (password) {
+ CFRelease(password);
+ password = NULL;
+ }
+ if (password_expiry_utc) {
+ CFRelease(password_expiry_utc);
+ password_expiry_utc = NULL;
+ }
+ if (oauth_refresh_token) {
+ CFRelease(oauth_refresh_token);
+ oauth_refresh_token = NULL;
+ }
+}
+
+#define STRING_WITH_LENGTH(s) s, sizeof(s) - 1
+
+__attribute__((format (printf, 1, 2), __noreturn__))
static void die(const char *err, ...)
{
char msg[4096];
@@ -18,70 +56,199 @@ static void die(const char *err, ...)
vsnprintf(msg, sizeof(msg), err, params);
fprintf(stderr, "%s\n", msg);
va_end(params);
+ clear_credential();
exit(1);
}
-static void *xstrdup(const char *s1)
+static void *xmalloc(size_t len)
{
- void *ret = strdup(s1);
+ void *ret = malloc(len);
if (!ret)
die("Out of memory");
return ret;
}
-#define KEYCHAIN_ITEM(x) (x ? strlen(x) : 0), x
-#define KEYCHAIN_ARGS \
- NULL, /* default keychain */ \
- KEYCHAIN_ITEM(host), \
- 0, NULL, /* account domain */ \
- KEYCHAIN_ITEM(username), \
- KEYCHAIN_ITEM(path), \
- port, \
- protocol, \
- kSecAuthenticationTypeDefault
-
-static void write_item(const char *what, const char *buf, int len)
+static CFDictionaryRef create_dictionary(CFAllocatorRef allocator, ...)
+{
+ va_list args;
+ const void *key;
+ CFMutableDictionaryRef result;
+
+ result = CFDictionaryCreateMutable(allocator,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+
+ va_start(args, allocator);
+ while ((key = va_arg(args, const void *)) != NULL) {
+ const void *value;
+ value = va_arg(args, const void *);
+ if (value)
+ CFDictionarySetValue(result, key, value);
+ }
+ va_end(args);
+
+ return result;
+}
+
+#define CREATE_SEC_ATTRIBUTES(...) \
+ create_dictionary(kCFAllocatorDefault, \
+ kSecClass, kSecClassInternetPassword, \
+ kSecAttrServer, host, \
+ kSecAttrAccount, username, \
+ kSecAttrPath, path, \
+ kSecAttrPort, port, \
+ kSecAttrProtocol, protocol, \
+ kSecAttrAuthenticationType, \
+ kSecAttrAuthenticationTypeDefault, \
+ __VA_ARGS__);
+
+static void write_item(const char *what, const char *buf, size_t len)
{
printf("%s=", what);
fwrite(buf, 1, len, stdout);
putchar('\n');
}
-static void find_username_in_item(SecKeychainItemRef item)
+static void find_username_in_item(CFDictionaryRef item)
{
- SecKeychainAttributeList list;
- SecKeychainAttribute attr;
+ CFStringRef account_ref;
+ char *username_buf;
+ CFIndex buffer_len;
- list.count = 1;
- list.attr = &attr;
- attr.tag = kSecAccountItemAttr;
+ account_ref = CFDictionaryGetValue(item, kSecAttrAccount);
+ if (!account_ref)
+ {
+ write_item("username", "", 0);
+ return;
+ }
- if (SecKeychainItemCopyContent(item, NULL, &list, NULL, NULL))
+ username_buf = (char *)CFStringGetCStringPtr(account_ref, ENCODING);
+ if (username_buf)
+ {
+ write_item("username", username_buf, strlen(username_buf));
return;
+ }
- write_item("username", attr.data, attr.length);
- SecKeychainItemFreeContent(&list, NULL);
+ /* If we can't get a CString pointer then
+ * we need to allocate our own buffer */
+ buffer_len = CFStringGetMaximumSizeForEncoding(
+ CFStringGetLength(account_ref), ENCODING) + 1;
+ username_buf = xmalloc(buffer_len);
+ if (CFStringGetCString(account_ref,
+ username_buf,
+ buffer_len,
+ ENCODING)) {
+ write_item("username", username_buf, buffer_len - 1);
+ }
+ free(username_buf);
}
-static void find_internet_password(void)
+static OSStatus find_internet_password(void)
{
- void *buf;
- UInt32 len;
- SecKeychainItemRef item;
+ CFDictionaryRef attrs;
+ CFDictionaryRef item;
+ CFDataRef data;
+ OSStatus result;
- if (SecKeychainFindInternetPassword(KEYCHAIN_ARGS, &len, &buf, &item))
- return;
+ attrs = CREATE_SEC_ATTRIBUTES(kSecMatchLimit, kSecMatchLimitOne,
+ kSecReturnAttributes, kCFBooleanTrue,
+ kSecReturnData, kCFBooleanTrue,
+ NULL);
+ result = SecItemCopyMatching(attrs, (CFTypeRef *)&item);
+ if (result) {
+ goto out;
+ }
- write_item("password", buf, len);
+ data = CFDictionaryGetValue(item, kSecValueData);
+
+ write_item("password",
+ (const char *)CFDataGetBytePtr(data),
+ CFDataGetLength(data));
if (!username)
find_username_in_item(item);
- SecKeychainItemFreeContent(NULL, buf);
+ CFRelease(item);
+
+out:
+ CFRelease(attrs);
+
+ /* We consider not found to not be an error */
+ if (result == errSecItemNotFound)
+ result = errSecSuccess;
+
+ return result;
+}
+
+static OSStatus delete_ref(const void *itemRef)
+{
+ CFArrayRef item_ref_list;
+ CFDictionaryRef delete_query;
+ OSStatus result;
+
+ item_ref_list = CFArrayCreate(kCFAllocatorDefault,
+ &itemRef,
+ 1,
+ &kCFTypeArrayCallBacks);
+ delete_query = create_dictionary(kCFAllocatorDefault,
+ kSecClass, kSecClassInternetPassword,
+ kSecMatchItemList, item_ref_list,
+ NULL);
+
+ if (password) {
+ /* We only want to delete items with a matching password */
+ CFIndex capacity;
+ CFMutableDictionaryRef query;
+ CFDataRef data;
+
+ capacity = CFDictionaryGetCount(delete_query) + 1;
+ query = CFDictionaryCreateMutableCopy(kCFAllocatorDefault,
+ capacity,
+ delete_query);
+ CFDictionarySetValue(query, kSecReturnData, kCFBooleanTrue);
+ result = SecItemCopyMatching(query, (CFTypeRef *)&data);
+ if (!result) {
+ CFDataRef kc_password;
+ const UInt8 *raw_data;
+ const UInt8 *line;
+
+ /* Don't match appended metadata */
+ raw_data = CFDataGetBytePtr(data);
+ line = memchr(raw_data, '\n', CFDataGetLength(data));
+ if (line)
+ kc_password = CFDataCreateWithBytesNoCopy(
+ kCFAllocatorDefault,
+ raw_data,
+ line - raw_data,
+ kCFAllocatorNull);
+ else
+ kc_password = data;
+
+ if (CFEqual(kc_password, password))
+ result = SecItemDelete(delete_query);
+
+ if (line)
+ CFRelease(kc_password);
+ CFRelease(data);
+ }
+
+ CFRelease(query);
+ } else {
+ result = SecItemDelete(delete_query);
+ }
+
+ CFRelease(delete_query);
+ CFRelease(item_ref_list);
+
+ return result;
}
-static void delete_internet_password(void)
+static OSStatus delete_internet_password(void)
{
- SecKeychainItemRef item;
+ CFDictionaryRef attrs;
+ CFArrayRef refs;
+ OSStatus result;
/*
* Require at least a protocol and host for removal, which is what git
@@ -89,37 +256,83 @@ static void delete_internet_password(void)
* Keychain manager.
*/
if (!protocol || !host)
- return;
+ return -1;
- if (SecKeychainFindInternetPassword(KEYCHAIN_ARGS, 0, NULL, &item))
- return;
+ attrs = CREATE_SEC_ATTRIBUTES(kSecMatchLimit, kSecMatchLimitAll,
+ kSecReturnRef, kCFBooleanTrue,
+ NULL);
+ result = SecItemCopyMatching(attrs, (CFTypeRef *)&refs);
+ CFRelease(attrs);
+
+ if (!result) {
+ for (CFIndex i = 0; !result && i < CFArrayGetCount(refs); i++)
+ result = delete_ref(CFArrayGetValueAtIndex(refs, i));
+
+ CFRelease(refs);
+ }
+
+ /* We consider not found to not be an error */
+ if (result == errSecItemNotFound)
+ result = errSecSuccess;
- SecKeychainItemDelete(item);
+ return result;
}
-static void add_internet_password(void)
+static OSStatus add_internet_password(void)
{
+ CFMutableDataRef data;
+ CFDictionaryRef attrs;
+ OSStatus result;
+
/* Only store complete credentials */
if (!protocol || !host || !username || !password)
- return;
+ return -1;
- if (SecKeychainAddInternetPassword(
- KEYCHAIN_ARGS,
- KEYCHAIN_ITEM(password),
- NULL))
- return;
+ data = CFDataCreateMutableCopy(kCFAllocatorDefault, 0, password);
+ if (password_expiry_utc) {
+ CFDataAppendBytes(data,
+ (const UInt8 *)STRING_WITH_LENGTH("\npassword_expiry_utc="));
+ CFDataAppendBytes(data,
+ CFDataGetBytePtr(password_expiry_utc),
+ CFDataGetLength(password_expiry_utc));
+ }
+ if (oauth_refresh_token) {
+ CFDataAppendBytes(data,
+ (const UInt8 *)STRING_WITH_LENGTH("\noauth_refresh_token="));
+ CFDataAppendBytes(data,
+ CFDataGetBytePtr(oauth_refresh_token),
+ CFDataGetLength(oauth_refresh_token));
+ }
+
+ attrs = CREATE_SEC_ATTRIBUTES(kSecValueData, data,
+ NULL);
+
+ result = SecItemAdd(attrs, NULL);
+ if (result == errSecDuplicateItem) {
+ CFDictionaryRef query;
+ query = CREATE_SEC_ATTRIBUTES(NULL);
+ result = SecItemUpdate(query, attrs);
+ CFRelease(query);
+ }
+
+ CFRelease(data);
+ CFRelease(attrs);
+
+ return result;
}
static void read_credential(void)
{
- char buf[1024];
+ char *buf = NULL;
+ size_t alloc;
+ ssize_t line_len;
- while (fgets(buf, sizeof(buf), stdin)) {
+ while ((line_len = getline(&buf, &alloc, stdin)) > 0) {
char *v;
if (!strcmp(buf, "\n"))
break;
- buf[strlen(buf)-1] = '\0';
+ buf[line_len-1] = '\0';
v = strchr(buf, '=');
if (!v)
@@ -128,56 +341,93 @@ static void read_credential(void)
if (!strcmp(buf, "protocol")) {
if (!strcmp(v, "imap"))
- protocol = kSecProtocolTypeIMAP;
+ protocol = kSecAttrProtocolIMAP;
else if (!strcmp(v, "imaps"))
- protocol = kSecProtocolTypeIMAPS;
+ protocol = kSecAttrProtocolIMAPS;
else if (!strcmp(v, "ftp"))
- protocol = kSecProtocolTypeFTP;
+ protocol = kSecAttrProtocolFTP;
else if (!strcmp(v, "ftps"))
- protocol = kSecProtocolTypeFTPS;
+ protocol = kSecAttrProtocolFTPS;
else if (!strcmp(v, "https"))
- protocol = kSecProtocolTypeHTTPS;
+ protocol = kSecAttrProtocolHTTPS;
else if (!strcmp(v, "http"))
- protocol = kSecProtocolTypeHTTP;
+ protocol = kSecAttrProtocolHTTP;
else if (!strcmp(v, "smtp"))
- protocol = kSecProtocolTypeSMTP;
- else /* we don't yet handle other protocols */
+ protocol = kSecAttrProtocolSMTP;
+ else {
+ /* we don't yet handle other protocols */
+ clear_credential();
exit(0);
+ }
}
else if (!strcmp(buf, "host")) {
char *colon = strchr(v, ':');
if (colon) {
+ UInt16 port_i;
*colon++ = '\0';
- port = atoi(colon);
+ port_i = atoi(colon);
+ port = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberShortType,
+ &port_i);
}
- host = xstrdup(v);
+ host = CFStringCreateWithCString(kCFAllocatorDefault,
+ v,
+ ENCODING);
}
else if (!strcmp(buf, "path"))
- path = xstrdup(v);
+ path = CFStringCreateWithCString(kCFAllocatorDefault,
+ v,
+ ENCODING);
else if (!strcmp(buf, "username"))
- username = xstrdup(v);
+ username = CFStringCreateWithCString(
+ kCFAllocatorDefault,
+ v,
+ ENCODING);
else if (!strcmp(buf, "password"))
- password = xstrdup(v);
+ password = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(v));
+ else if (!strcmp(buf, "password_expiry_utc"))
+ password_expiry_utc = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(v));
+ else if (!strcmp(buf, "oauth_refresh_token"))
+ oauth_refresh_token = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(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.
+ */
}
+
+ free(buf);
}
int main(int argc, const char **argv)
{
+ OSStatus result = 0;
const char *usage =
"usage: git credential-osxkeychain <get|store|erase>";
if (!argv[1])
- die(usage);
+ die("%s", usage);
read_credential();
if (!strcmp(argv[1], "get"))
- find_internet_password();
+ result = find_internet_password();
else if (!strcmp(argv[1], "store"))
- add_internet_password();
+ result = add_internet_password();
else if (!strcmp(argv[1], "erase"))
- delete_internet_password();
+ result = delete_internet_password();
/* otherwise, ignore unknown action */
+ if (result)
+ die("failed to %s: %d", argv[1], (int)result);
+
+ clear_credential();
+
return 0;
}
diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c
index 5bdad41..4be0d58 100644
--- a/contrib/credential/wincred/git-credential-wincred.c
+++ b/contrib/credential/wincred/git-credential-wincred.c
@@ -6,11 +6,13 @@
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
+#include <wincred.h>
/* common helpers */
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+__attribute__((format (printf, 1, 2)))
static void die(const char *err, ...)
{
char msg[4096];
@@ -32,65 +34,8 @@ static void *xmalloc(size_t size)
return ret;
}
-/* MinGW doesn't have wincred.h, so we need to define stuff */
-
-typedef struct _CREDENTIAL_ATTRIBUTEW {
- LPWSTR Keyword;
- DWORD Flags;
- DWORD ValueSize;
- LPBYTE Value;
-} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;
-
-typedef struct _CREDENTIALW {
- DWORD Flags;
- DWORD Type;
- LPWSTR TargetName;
- LPWSTR Comment;
- FILETIME LastWritten;
- DWORD CredentialBlobSize;
- LPBYTE CredentialBlob;
- DWORD Persist;
- DWORD AttributeCount;
- PCREDENTIAL_ATTRIBUTEW Attributes;
- LPWSTR TargetAlias;
- LPWSTR UserName;
-} CREDENTIALW, *PCREDENTIALW;
-
-#define CRED_TYPE_GENERIC 1
-#define CRED_PERSIST_LOCAL_MACHINE 2
-#define CRED_MAX_ATTRIBUTES 64
-
-typedef BOOL (WINAPI *CredWriteWT)(PCREDENTIALW, DWORD);
-typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *,
- PCREDENTIALW **);
-typedef VOID (WINAPI *CredFreeT)(PVOID);
-typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD);
-
-static HMODULE advapi;
-static CredWriteWT CredWriteW;
-static CredEnumerateWT CredEnumerateW;
-static CredFreeT CredFree;
-static CredDeleteWT CredDeleteW;
-
-static void load_cred_funcs(void)
-{
- /* load DLLs */
- advapi = LoadLibraryExA("advapi32.dll", NULL,
- LOAD_LIBRARY_SEARCH_SYSTEM32);
- if (!advapi)
- die("failed to load advapi32.dll");
-
- /* get function pointers */
- CredWriteW = (CredWriteWT)GetProcAddress(advapi, "CredWriteW");
- CredEnumerateW = (CredEnumerateWT)GetProcAddress(advapi,
- "CredEnumerateW");
- CredFree = (CredFreeT)GetProcAddress(advapi, "CredFree");
- CredDeleteW = (CredDeleteWT)GetProcAddress(advapi, "CredDeleteW");
- if (!CredWriteW || !CredEnumerateW || !CredFree || !CredDeleteW)
- die("failed to load functions");
-}
-
-static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];
+static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
+ *password_expiry_utc, *oauth_refresh_token;
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
{
@@ -164,7 +109,18 @@ static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
return match_part_with_last(ptarget, want, delim, 1);
}
-static int match_cred(const CREDENTIALW *cred)
+static int match_cred_password(const CREDENTIALW *cred) {
+ int ret;
+ WCHAR *cred_password = xmalloc(cred->CredentialBlobSize);
+ wcsncpy_s(cred_password, cred->CredentialBlobSize,
+ (LPCWSTR)cred->CredentialBlob,
+ cred->CredentialBlobSize / sizeof(WCHAR));
+ ret = !wcscmp(cred_password, password);
+ free(cred_password);
+ return ret;
+}
+
+static int match_cred(const CREDENTIALW *cred, int match_password)
{
LPCWSTR target = cred->TargetName;
if (wusername && wcscmp(wusername, cred->UserName ? cred->UserName : L""))
@@ -174,7 +130,8 @@ static int match_cred(const CREDENTIALW *cred)
match_part(&target, protocol, L"://") &&
match_part_last(&target, wusername, L"@") &&
match_part(&target, host, L"/") &&
- match_part(&target, path, L"");
+ match_part(&target, path, L"") &&
+ (!match_password || match_cred_password(cred));
}
static void get_credential(void)
@@ -182,18 +139,47 @@ static void get_credential(void)
CREDENTIALW **creds;
DWORD num_creds;
int i;
+ CREDENTIAL_ATTRIBUTEW *attr;
+ WCHAR *secret;
+ WCHAR *line;
+ WCHAR *remaining_lines;
+ WCHAR *part;
+ WCHAR *remaining_parts;
if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
return;
/* search for the first credential that matches username */
for (i = 0; i < num_creds; ++i)
- if (match_cred(creds[i])) {
+ if (match_cred(creds[i], 0)) {
write_item("username", creds[i]->UserName,
creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
- write_item("password",
- (LPCWSTR)creds[i]->CredentialBlob,
- creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ if (creds[i]->CredentialBlobSize > 0) {
+ secret = xmalloc(creds[i]->CredentialBlobSize);
+ wcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ line = wcstok_s(secret, L"\r\n", &remaining_lines);
+ write_item("password", line, line ? wcslen(line) : 0);
+ while(line != NULL) {
+ part = wcstok_s(line, L"=", &remaining_parts);
+ if (!wcscmp(part, L"oauth_refresh_token")) {
+ write_item("oauth_refresh_token", remaining_parts, remaining_parts ? wcslen(remaining_parts) : 0);
+ }
+ line = wcstok_s(NULL, L"\r\n", &remaining_lines);
+ }
+ free(secret);
+ } else {
+ write_item("password",
+ (LPCWSTR)creds[i]->CredentialBlob,
+ creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ }
+ for (int j = 0; j < creds[i]->AttributeCount; j++) {
+ attr = creds[i]->Attributes + j;
+ if (!wcscmp(attr->Keyword, L"git_password_expiry_utc")) {
+ write_item("password_expiry_utc", (LPCWSTR)attr->Value,
+ attr->ValueSize / sizeof(WCHAR));
+ break;
+ }
+ }
break;
}
@@ -203,22 +189,43 @@ static void get_credential(void)
static void store_credential(void)
{
CREDENTIALW cred;
+ CREDENTIAL_ATTRIBUTEW expiry_attr;
+ WCHAR *secret;
+ int wlen;
if (!wusername || !password)
return;
+ if (oauth_refresh_token) {
+ wlen = _scwprintf(L"%s\r\noauth_refresh_token=%s", password, oauth_refresh_token);
+ secret = xmalloc(sizeof(WCHAR) * wlen);
+ _snwprintf_s(secret, sizeof(WCHAR) * wlen, wlen, L"%s\r\noauth_refresh_token=%s", password, oauth_refresh_token);
+ } else {
+ secret = _wcsdup(password);
+ }
+
cred.Flags = 0;
cred.Type = CRED_TYPE_GENERIC;
cred.TargetName = target;
cred.Comment = L"saved by git-credential-wincred";
- cred.CredentialBlobSize = (wcslen(password)) * sizeof(WCHAR);
- cred.CredentialBlob = (LPVOID)password;
+ cred.CredentialBlobSize = wcslen(secret) * sizeof(WCHAR);
+ cred.CredentialBlob = (LPVOID)_wcsdup(secret);
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
cred.AttributeCount = 0;
cred.Attributes = NULL;
+ if (password_expiry_utc != NULL) {
+ expiry_attr.Keyword = L"git_password_expiry_utc";
+ expiry_attr.Value = (LPVOID)password_expiry_utc;
+ expiry_attr.ValueSize = (wcslen(password_expiry_utc)) * sizeof(WCHAR);
+ expiry_attr.Flags = 0;
+ cred.Attributes = &expiry_attr;
+ cred.AttributeCount = 1;
+ }
cred.TargetAlias = NULL;
cred.UserName = wusername;
+ free(secret);
+
if (!CredWriteW(&cred, 0))
die("CredWrite failed");
}
@@ -233,7 +240,7 @@ static void erase_credential(void)
return;
for (i = 0; i < num_creds; ++i) {
- if (match_cred(creds[i]))
+ if (match_cred(creds[i], password != NULL))
CredDeleteW(creds[i]->TargetName, creds[i]->Type, 0);
}
@@ -248,17 +255,28 @@ static WCHAR *utf8_to_utf16_dup(const char *str)
return wstr;
}
+#define KB (1024)
+
static void read_credential(void)
{
- char buf[1024];
+ size_t alloc = 100 * KB;
+ char *buf = calloc(alloc, sizeof(*buf));
- while (fgets(buf, sizeof(buf), stdin)) {
+ while (fgets(buf, alloc, stdin)) {
char *v;
- int len = strlen(buf);
+ size_t len = strlen(buf);
+ int ends_in_newline = 0;
/* strip trailing CR / LF */
- while (len && strchr("\r\n", buf[len - 1]))
+ if (len && buf[len - 1] == '\n') {
+ buf[--len] = 0;
+ ends_in_newline = 1;
+ }
+ if (len && buf[len - 1] == '\r')
buf[--len] = 0;
+ if (!ends_in_newline)
+ die("bad input: %s", buf);
+
if (!*buf)
break;
@@ -277,9 +295,18 @@ 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");
+ else if (!strcmp(buf, "password_expiry_utc"))
+ password_expiry_utc = utf8_to_utf16_dup(v);
+ else if (!strcmp(buf, "oauth_refresh_token"))
+ oauth_refresh_token = utf8_to_utf16_dup(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.
+ */
}
+
+ free(buf);
}
int main(int argc, char *argv[])
@@ -288,7 +315,7 @@ int main(int argc, char *argv[])
"usage: git credential-wincred <get|store|erase>\n";
if (!argv[1])
- die(usage);
+ die("%s", usage);
/* git use binary pipes to avoid CRLF-issues */
_setmode(_fileno(stdin), _O_BINARY);
@@ -296,8 +323,6 @@ int main(int argc, char *argv[])
read_credential();
- load_cred_funcs();
-
if (!protocol || !(host || path))
return 0;
diff --git a/contrib/diff-highlight/DiffHighlight.pm b/contrib/diff-highlight/DiffHighlight.pm
index 376f577..636add6 100644
--- a/contrib/diff-highlight/DiffHighlight.pm
+++ b/contrib/diff-highlight/DiffHighlight.pm
@@ -1,6 +1,6 @@
package DiffHighlight;
-use 5.008;
+use 5.008001;
use warnings FATAL => 'all';
use strict;
diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 2f618a7..3211841 100644
--- a/contrib/git-jump/README
+++ b/contrib/git-jump/README
@@ -65,6 +65,9 @@ git jump diff --cached
# jump to merge conflicts
git jump merge
+# documentation conflicts are hard; skip past them for now
+git jump merge :^Documentation
+
# jump to all instances of foo_bar
git jump grep foo_bar
@@ -76,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
----------------
@@ -97,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 931b0fe..47e0c55 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -2,25 +2,43 @@
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:
diff: elements are diff hunks. Arguments are given to diff.
-merge: elements are merge conflicts. Arguments are ignored.
+merge: elements are merge conflicts. Arguments are given to ls-files -u.
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() {
@@ -39,7 +57,7 @@ mode_diff() {
}
mode_merge() {
- git ls-files -u |
+ git ls-files -u "$@" |
perl -pe 's/^.*?\t//' |
sort -u |
while IFS= read fn; do
@@ -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/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
deleted file mode 100755
index 7eb1b24..0000000
--- a/contrib/hg-to-git/hg-to-git.py
+++ /dev/null
@@ -1,254 +0,0 @@
-#!/usr/bin/env python
-
-""" hg-to-git.py - A Mercurial to GIT converter
-
- Copyright (C)2007 Stelian Pop <stelian@popies.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-"""
-
-import os, os.path, sys
-import tempfile, pickle, getopt
-import re
-
-if sys.hexversion < 0x02030000:
- # The behavior of the pickle module changed significantly in 2.3
- sys.stderr.write("hg-to-git.py: requires Python 2.3 or later.\n")
- sys.exit(1)
-
-# Maps hg version -> git version
-hgvers = {}
-# List of children for each hg revision
-hgchildren = {}
-# List of parents for each hg revision
-hgparents = {}
-# Current branch for each hg revision
-hgbranch = {}
-# Number of new changesets converted from hg
-hgnewcsets = 0
-
-#------------------------------------------------------------------------------
-
-def usage():
-
- print("""\
-%s: [OPTIONS] <hgprj>
-
-options:
- -s, --gitstate=FILE: name of the state to be saved/read
- for incrementals
- -n, --nrepack=INT: number of changesets that will trigger
- a repack (default=0, -1 to deactivate)
- -v, --verbose: be verbose
-
-required:
- hgprj: name of the HG project to import (directory)
-""" % sys.argv[0])
-
-#------------------------------------------------------------------------------
-
-def getgitenv(user, date):
- env = ''
- elems = re.compile('(.*?)\s+<(.*)>').match(user)
- if elems:
- env += 'export GIT_AUTHOR_NAME="%s" ;' % elems.group(1)
- env += 'export GIT_COMMITTER_NAME="%s" ;' % elems.group(1)
- env += 'export GIT_AUTHOR_EMAIL="%s" ;' % elems.group(2)
- env += 'export GIT_COMMITTER_EMAIL="%s" ;' % elems.group(2)
- else:
- env += 'export GIT_AUTHOR_NAME="%s" ;' % user
- env += 'export GIT_COMMITTER_NAME="%s" ;' % user
- env += 'export GIT_AUTHOR_EMAIL= ;'
- env += 'export GIT_COMMITTER_EMAIL= ;'
-
- env += 'export GIT_AUTHOR_DATE="%s" ;' % date
- env += 'export GIT_COMMITTER_DATE="%s" ;' % date
- return env
-
-#------------------------------------------------------------------------------
-
-state = ''
-opt_nrepack = 0
-verbose = False
-
-try:
- opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', ['gitstate=', 'tempdir=', 'nrepack=', 'verbose'])
- for o, a in opts:
- if o in ('-s', '--gitstate'):
- state = a
- state = os.path.abspath(state)
- if o in ('-n', '--nrepack'):
- opt_nrepack = int(a)
- if o in ('-v', '--verbose'):
- verbose = True
- if len(args) != 1:
- raise Exception('params')
-except:
- usage()
- sys.exit(1)
-
-hgprj = args[0]
-os.chdir(hgprj)
-
-if state:
- if os.path.exists(state):
- if verbose:
- print('State does exist, reading')
- f = open(state, 'r')
- hgvers = pickle.load(f)
- else:
- print('State does not exist, first run')
-
-sock = os.popen('hg tip --template "{rev}"')
-tip = sock.read()
-if sock.close():
- sys.exit(1)
-if verbose:
- print('tip is', tip)
-
-# Calculate the branches
-if verbose:
- print('analysing the branches...')
-hgchildren["0"] = ()
-hgparents["0"] = (None, None)
-hgbranch["0"] = "master"
-for cset in range(1, int(tip) + 1):
- hgchildren[str(cset)] = ()
- prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
- prnts = map(lambda x: x[:x.find(':')], prnts)
- if prnts[0] != '':
- parent = prnts[0].strip()
- else:
- parent = str(cset - 1)
- hgchildren[parent] += ( str(cset), )
- if len(prnts) > 1:
- mparent = prnts[1].strip()
- hgchildren[mparent] += ( str(cset), )
- else:
- mparent = None
-
- hgparents[str(cset)] = (parent, mparent)
-
- if mparent:
- # For merge changesets, take either one, preferably the 'master' branch
- if hgbranch[mparent] == 'master':
- hgbranch[str(cset)] = 'master'
- else:
- hgbranch[str(cset)] = hgbranch[parent]
- else:
- # Normal changesets
- # For first children, take the parent branch, for the others create a new branch
- if hgchildren[parent][0] == str(cset):
- hgbranch[str(cset)] = hgbranch[parent]
- else:
- hgbranch[str(cset)] = "branch-" + str(cset)
-
-if "0" not in hgvers:
- print('creating repository')
- os.system('git init')
-
-# loop through every hg changeset
-for cset in range(int(tip) + 1):
-
- # incremental, already seen
- if str(cset) in hgvers:
- continue
- hgnewcsets += 1
-
- # get info
- log_data = os.popen('hg log -r %d --template "{tags}\n{date|date}\n{author}\n"' % cset).readlines()
- tag = log_data[0].strip()
- date = log_data[1].strip()
- user = log_data[2].strip()
- parent = hgparents[str(cset)][0]
- mparent = hgparents[str(cset)][1]
-
- #get comment
- (fdcomment, filecomment) = tempfile.mkstemp()
- csetcomment = os.popen('hg log -r %d --template "{desc}"' % cset).read().strip()
- os.write(fdcomment, csetcomment)
- os.close(fdcomment)
-
- print('-----------------------------------------')
- print('cset:', cset)
- print('branch:', hgbranch[str(cset)])
- print('user:', user)
- print('date:', date)
- print('comment:', csetcomment)
- if parent:
- print('parent:', parent)
- if mparent:
- print('mparent:', mparent)
- if tag:
- print('tag:', tag)
- print('-----------------------------------------')
-
- # checkout the parent if necessary
- if cset != 0:
- if hgbranch[str(cset)] == "branch-" + str(cset):
- print('creating new branch', hgbranch[str(cset)])
- os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
- else:
- print('checking out branch', hgbranch[str(cset)])
- os.system('git checkout %s' % hgbranch[str(cset)])
-
- # merge
- if mparent:
- if hgbranch[parent] == hgbranch[str(cset)]:
- otherbranch = hgbranch[mparent]
- else:
- otherbranch = hgbranch[parent]
- print('merging', otherbranch, 'into', hgbranch[str(cset)])
- os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
-
- # remove everything except .git and .hg directories
- os.system('find . \( -path "./.hg" -o -path "./.git" \) -prune -o ! -name "." -print | xargs rm -rf')
-
- # repopulate with checkouted files
- os.system('hg update -C %d' % cset)
-
- # add new files
- os.system('git ls-files -x .hg --others | git update-index --add --stdin')
- # delete removed files
- os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')
-
- # commit
- os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)
- os.unlink(filecomment)
-
- # tag
- if tag and tag != 'tip':
- os.system(getgitenv(user, date) + 'git tag %s' % tag)
-
- # delete branch if not used anymore...
- if mparent and len(hgchildren[str(cset)]):
- print("Deleting unused branch:", otherbranch)
- os.system('git branch -d %s' % otherbranch)
-
- # retrieve and record the version
- vvv = os.popen('git show --quiet --pretty=format:%H').read()
- print('record', cset, '->', vvv)
- hgvers[str(cset)] = vvv
-
-if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
- os.system('git repack -a -d')
-
-# write the state for incrementals
-if state:
- if verbose:
- print('Writing state')
- f = open(state, 'w')
- pickle.dump(hgvers, f)
-
-# vim: et ts=8 sw=4 sts=4
diff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt
deleted file mode 100644
index 91f8fe6..0000000
--- a/contrib/hg-to-git/hg-to-git.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-hg-to-git.py is able to convert a Mercurial repository into a git one,
-and preserves the branches in the process (unlike tailor)
-
-hg-to-git.py can probably be greatly improved (it's a rather crude
-combination of shell and python) but it does already work quite well for
-me. Features:
- - supports incremental conversion
- (for keeping a git repo in sync with a hg one)
- - supports hg branches
- - converts hg tags
-
-Note that the git repository will be created 'in place' (at the same
-location as the source hg repo). You will have to manually remove the
-'.hg' directory after the conversion.
-
-Also note that the incremental conversion uses 'simple' hg changesets
-identifiers (ordinals, as opposed to SHA-1 ids), and since these ids
-are not stable across different repositories the hg-to-git.py state file
-is forever tied to one hg repository.
-
-Stelian Pop <stelian@popies.net>
diff --git a/contrib/hooks/multimail/CHANGES b/contrib/hooks/multimail/CHANGES
deleted file mode 100644
index 35791fd..0000000
--- a/contrib/hooks/multimail/CHANGES
+++ /dev/null
@@ -1,285 +0,0 @@
-Release 1.5.0
-=============
-
-Backward-incompatible change
-----------------------------
-
-The name of classes for environment was misnamed as `*Environement`.
-It is now `*Environment`.
-
-New features
-------------
-
-* A Thread-Index header is now added to each email sent (except for
- combined emails where it would not make sense), so that MS Outlook
- properly groups messages by threads even though they have a
- different subject line. Unfortunately, even adding this header the
- threading still seems to be unreliable, but it is unclear whether
- this is an issue on our side or on MS Outlook's side (see discussion
- here: https://github.com/git-multimail/git-multimail/pull/194).
-
-* A new variable multimailhook.ExcludeMergeRevisions was added to send
- notification emails only for non-merge commits.
-
-* For gitolite environment, it is now possible to specify the mail map
- in a separate file in addition to gitolite.conf, using the variable
- multimailhook.MailaddressMap.
-
-Internal changes
-----------------
-
-* The testsuite now uses GIT_PRINT_SHA1_ELLIPSIS where needed for
- compatibility with recent Git versions. Only tests are affected.
-
-* We don't try to install pyflakes in the continuous integration job
- for old Python versions where it's no longer available.
-
-* Stop using the deprecated cgi.escape in Python 3.
-
-* New flake8 warnings have been fixed.
-
-* Python 3.6 is now tested against on Travis-CI.
-
-* A bunch of lgtm.com warnings have been fixed.
-
-Bug fixes
----------
-
-* SMTPMailer logs in only once now. It used to re-login for each email
- sent which triggered errors for some SMTP servers.
-
-* migrate-mailhook-config was broken by internal refactoring, it
- should now work again.
-
-This version was tested with Python 2.6 to 3.7. It was tested with Git
-1.7.10.406.gdc801, 2.15.1 and 2.20.1.98.gecbdaf0.
-
-Release 1.4.0
-=============
-
-New features to troubleshoot a git-multimail installation
----------------------------------------------------------
-
-* One can now perform a basic check of git-multimail's setup by
- running the hook with the environment variable
- GIT_MULTIMAIL_CHECK_SETUP set to a non-empty string. See
- doc/troubleshooting.rst for details.
-
-* A new log files system was added. See the multimailhook.logFile,
- multimailhook.errorLogFile and multimailhook.debugLogFile variables.
-
-* git_multimail.py can now be made more verbose using
- multimailhook.verbose.
-
-* A new option --check-ref-filter is now available to help debugging
- the refFilter* options.
-
-Formatting emails
------------------
-
-* Formatting of emails was made slightly more compact, to reduce the
- odds of having long subject lines truncated or wrapped in short list
- of commits.
-
-* multimailhook.emailPrefix may now use the '%(repo_shortname)s'
- placeholder for the repository's short name.
-
-* A new option multimailhook.subjectMaxLength is available to truncate
- overly long subject lines.
-
-Bug fixes and minor changes
----------------------------
-
-* Options refFilterDoSendRegex and refFilterDontSendRegex were
- essentially broken. They should work now.
-
-* The behavior when both refFilter{Do,Dont}SendRegex and
- refFilter{Exclusion,Inclusion}Regex are set have been slightly
- changed. Exclusion/Inclusion is now strictly stronger than
- DoSend/DontSend.
-
-* The management of precedence when a setting can be computed in
- multiple ways has been considerably refactored and modified.
- multimailhook.from and multimailhook.reponame now have precedence
- over the environment-specific settings ($GL_REPO/$GL_USER for
- gitolite, --stash-user/repo for Stash, --submitter/--project for
- Gerrit).
-
-* The coverage of the testsuite has been considerably improved. All
- configuration variables now appear at least once in the testsuite.
-
-This version was tested with Python 2.6 to 3.5. It also mostly works
-with Python 2.4, but there is one known breakage in the testsuite
-related to non-ascii characters. It was tested with Git
-1.7.10.406.gdc801, 1.8.5.6, 2.1.4, and 2.10.0.rc0.1.g07c9292.
-
-Release 1.3.1 (bugfix-only release)
-===================================
-
-* Generate links to commits in combined emails (it was done only for
- commit emails in 1.3.0).
-
-* Fix broken links on PyPi.
-
-Release 1.3.0
-=============
-
-* New options multimailhook.htmlInIntro and multimailhook.htmlInFooter
- now allow using HTML in the introduction and footer of emails (e.g.
- for a more pleasant formatting or to insert a link to the commit on
- a web interface).
-
-* A new option multimailhook.commitBrowseURL gives a simpler (and less
- flexible) way to add a link to a web interface for commit emails
- than multimailhook.htmlInIntro and multimailhook.htmlInFooter.
-
-* A new public function config.add_config_parameters was added to
- allow custom hooks to set specific Git configuration variables
- without modifying the configuration files. See an example in
- post-receive.example.
-
-* Error handling for SMTP has been improved (we used to print Python
- backtraces for legitimate errors).
-
-* The SMTP mailer can now check TLS certificates when the newly added
- configuration variable multimailhook.smtpCACerts.
-
-* Python 3 portability has been improved.
-
-* The documentation's formatting has been improved.
-
-* The testsuite has been improved (we now use pyflakes to check for
- errors in the code).
-
-This version has been tested with Python 2.4 and 2.6 to 3.5, and Git
-v1.7.10-406-gdc801e7, 2.1.4 and 2.8.1.339.g3ad15fd.
-
-No change since 1.3 RC1.
-
-Release 1.2.0
-=============
-
-* It is now possible to exclude some refs (e.g. exclude some branches
- or tags). See refFilterDoSendRegex, refFilterDontSendRegex,
- refFilterInclusionRegex and refFilterExclusionRegex.
-
-* New commitEmailFormat option which can be set to "html" to generate
- simple colorized diffs using HTML for the commit emails.
-
-* git-multimail can now be ran as a Gerrit ref-updated hook, or from
- Atlassian BitBucket Server (formerly known as Atlassian Stash).
-
-* The From: field is now more customizeable. It can be set
- independently for refchange emails and commit emails (see
- fromCommit, fromRefChange). The special values pusher and author can
- be used in these configuration variable.
-
-* A new command-line option, --version, was added. The version is also
- available in the X-Git-Multimail-Version header of sent emails.
-
-* Set X-Git-NotificationType header to differentiate the various types
- of notifications. Current values are: diff, ref_changed_plus_diff,
- ref_changed.
-
-* Preliminary support for Python 3. The testsuite passes with Python 3,
- but it has not received as much testing as the Python 2 version yet.
-
-* Several encoding-related fixes. UTF-8 characters work in more
- situations (but non-ascii characters in email address are still not
- supported).
-
-* The testsuite and its documentation has been greatly improved.
-
-Plus all the bugfixes from version 1.1.1.
-
-This version has been tested with Python 2.4 and 2.6 to 3.5, and Git
-v1.7.10-406-gdc801e7, git-1.8.2.3 and 2.6.0. Git versions prior to
-v1.7.10-406-gdc801e7 probably work, but cannot run the testsuite
-properly.
-
-Release 1.1.1 (bugfix-only release)
-===================================
-
-* The SMTP mailer was not working with Python 2.4.
-
-Release 1.1.0
-=============
-
-* When a single commit is pushed, omit the reference changed email.
- Set multimailhook.combineWhenSingleCommit to false to disable this
- new feature.
-
-* In gitolite environments, the pusher's email address can be used as
- the From address by creating a specially formatted comment block in
- gitolite.conf (see multimailhook.from in README).
-
-* Support for SMTP authentication and SSL/TLS encryption was added,
- see smtpUser, smtpPass, smtpEncryption in README.
-
-* A new option scanCommitForCc was added to allow git-multimail to
- search the commit message for 'Cc: ...' lines, and add the
- corresponding emails in Cc.
-
-* If $USER is not set, use the variable $USERNAME. This is needed on
- Windows platform to recognize the pusher.
-
-* The emailPrefix variable can now be set to an empty string to remove
- the prefix.
-
-* A short tutorial was added in doc/gitolite.rst to set up
- git-multimail with gitolite.
-
-* The post-receive file was renamed to post-receive.example. It has
- always been an example (the standard way to call git-multimail is to
- call git_multimail.py), but it was unclear to many users.
-
-* A new refchangeShowGraph option was added to make it possible to
- include both a graph and a log in the summary emails. The options
- to control the graph formatting can be set via the new graphOpts
- option.
-
-* New option --force-send was added to disable new commit detection
- for update hook. One use-case is to run git_multimail.py after
- running "git fetch" to send emails about commits that have just been
- fetched (the detection of new commits was unreliable in this mode).
-
-* The testing infrastructure was considerably improved (continuous
- integration with travis-ci, automatic check of PEP8 and RST syntax,
- many improvements to the test scripts).
-
-This version has been tested with Python 2.4 to 2.7, and Git 1.7.1 to
-2.4.
-
-Release 1.0.0
-=============
-
-* Fix encoding of non-ASCII email addresses in email headers.
-
-* Fix backwards-compatibility bugs for older Python 2.x versions.
-
-* Fix a backwards-compatibility bug for Git 1.7.1.
-
-* Add an option commitDiffOpts to customize logs for revisions.
-
-* Pass "-oi" to sendmail by default to prevent premature termination
- on a line containing only ".".
-
-* Stagger email "Date:" values in an attempt to help mail clients
- thread the emails in the right order.
-
-* If a mailing list setting is missing, just skip sending the
- corresponding email (with a warning) instead of failing.
-
-* Add a X-Git-Host header that can be used for email filtering.
-
-* Allow the sender's fully-qualified domain name to be configured.
-
-* Minor documentation improvements.
-
-* Add this CHANGES file.
-
-
-Release 0.9.0
-=============
-
-* Initial release.
diff --git a/contrib/hooks/multimail/CONTRIBUTING.rst b/contrib/hooks/multimail/CONTRIBUTING.rst
deleted file mode 100644
index de20a54..0000000
--- a/contrib/hooks/multimail/CONTRIBUTING.rst
+++ /dev/null
@@ -1,60 +0,0 @@
-Contributing
-============
-
-git-multimail is an open-source project, built by volunteers. We would
-welcome your help!
-
-The current maintainers are `Matthieu Moy <http://matthieu-moy.fr>`__ and
-`Michael Haggerty <https://github.com/mhagger>`__.
-
-Please note that although a copy of git-multimail is distributed in
-the "contrib" section of the main Git project, development takes place
-in a separate `git-multimail repository on GitHub`_.
-
-Whenever enough changes to git-multimail have accumulated, a new
-code-drop of git-multimail will be submitted for inclusion in the Git
-project.
-
-We use the GitHub issue tracker to keep track of bugs and feature
-requests, and we use GitHub pull requests to exchange patches (though,
-if you prefer, you can send patches via the Git mailing list with CC
-to the maintainers). Please sign off your patches as per the `Git
-project practice
-<https://github.com/git/git/blob/master/Documentation/SubmittingPatches#L234>`__.
-
-Please vote for issues you would like to be addressed in priority
-(click "add your reaction" and then the "+1" thumbs-up button on the
-GitHub issue).
-
-General discussion of git-multimail can take place on the main `Git
-mailing list`_.
-
-Please CC emails regarding git-multimail to the maintainers so that we
-don't overlook them.
-
-Help needed: testers/maintainer for specific environments/OS
-------------------------------------------------------------
-
-The current maintainer uses and tests git-multimail on Linux with the
-Generic environment. More testers, or better contributors are needed
-to test git-multimail on other real-life setups:
-
-* Mac OS X, Windows: git-multimail is currently not supported on these
- platforms. But since we have no external dependencies and try to
- write code as portable as possible, it is possible that
- git-multimail already runs there and if not, it is likely that it
- could be ported easily.
-
- Patches to improve support for Windows and OS X are welcome.
- Ideally, there would be a sub-maintainer for each OS who would test
- at least once before each release (around twice a year).
-
-* Gerrit, Stash, Gitolite environments: although the testsuite
- contains tests for these environments, a tester/maintainer for each
- environment would be welcome to test and report failure (or success)
- on real-life environments periodically (here also, feedback before
- each release would be highly appreciated).
-
-
-.. _`git-multimail repository on GitHub`: https://github.com/git-multimail/git-multimail
-.. _`Git mailing list`: git@vger.kernel.org
diff --git a/contrib/hooks/multimail/README.Git b/contrib/hooks/multimail/README.Git
index 0444442..c427efc 100644
--- a/contrib/hooks/multimail/README.Git
+++ b/contrib/hooks/multimail/README.Git
@@ -1,15 +1,7 @@
-This copy of git-multimail is distributed as part of the "contrib"
-section of the Git project as a convenience to Git users.
git-multimail is developed as an independent project at the following
website:
https://github.com/git-multimail/git-multimail
-The version in this directory was obtained from the upstream project
-on January 07 2019 and consists of the "git-multimail" subdirectory from
-revision
-
- 04e80e6c40be465cc62b6c246f0fcb8fd2cfd454 refs/tags/1.5.0
-
-Please see the README file in this directory for information about how
-to report bugs or contribute to git-multimail.
+Please refer to that project page for information about how to report
+bugs or contribute to git-multimail.
diff --git a/contrib/hooks/multimail/README.migrate-from-post-receive-email b/contrib/hooks/multimail/README.migrate-from-post-receive-email
deleted file mode 100644
index 1e6a976..0000000
--- a/contrib/hooks/multimail/README.migrate-from-post-receive-email
+++ /dev/null
@@ -1,145 +0,0 @@
-git-multimail is close to, but not exactly, a plug-in replacement for
-the old Git project script contrib/hooks/post-receive-email. This
-document describes the differences and explains how to configure
-git-multimail to get behavior closest to that of post-receive-email.
-
-If you are in a hurry
-=====================
-
-A script called migrate-mailhook-config is included with
-git-multimail. If you run this script within a Git repository that is
-configured to use post-receive-email, it will convert the
-configuration settings into the approximate equivalent settings for
-git-multimail. For more information, run
-
- migrate-mailhook-config --help
-
-
-Configuration differences
-=========================
-
-* The names of the config options for git-multimail are in namespace
- "multimailhook.*" instead of "hooks.*". (Editorial comment:
- post-receive-email should never have used such a generic top-level
- namespace.)
-
-* In emails about new annotated tags, post-receive-email includes a
- shortlog of all changes since the previous annotated tag. To get
- this behavior with git-multimail, you need to set
- multimailhook.announceshortlog to true:
-
- git config multimailhook.announceshortlog true
-
-* multimailhook.commitlist -- This is a new configuration variable.
- Recipients listed here will receive a separate email for each new
- commit. However, if this variable is *not* set, it defaults to the
- value of multimailhook.mailinglist. Therefore, if you *don't* want
- the members of multimailhook.mailinglist to receive one email per
- commit, then set this value to the empty string:
-
- git config multimailhook.commitlist ''
-
-* multimailhook.emailprefix -- If this value is not set, then the
- subjects of generated emails are prefixed with the short name of the
- repository enclosed in square brackets; e.g., "[myrepo]".
- post-receive-email defaults to prefix "[SCM]" if this option is not
- set. So if you were using the old default and want to retain it
- (for example, to avoid having to change your email filters), set
- this variable explicitly to the old value:
-
- git config multimailhook.emailprefix "[SCM]"
-
-* The "multimailhook.showrev" configuration option is not supported.
- Its main use is obsoleted by the one-email-per-commit feature of
- git-multimail.
-
-
-Other differences
-=================
-
-This section describes other differences in the behavior of
-git-multimail vs. post-receive-email. For full details, please refer
-to the main README file:
-
-* One email per commit. For each reference change, the script first
- outputs one email summarizing the reference change (including
- one-line summaries of the new commits), then it outputs a separate
- email for each new commit that was introduced, including patches.
- These one-email-per-commit emails go to the addresses listed in
- multimailhook.commitlist. post-receive-email sends only one email
- for each *reference* that is changed, no matter how many commits
- were added to the reference.
-
-* Better algorithm for detecting new commits. post-receive-email
- processes one reference change at a time, which causes it to fail to
- describe new commits that were included in multiple branches. For
- example, if a single push adds the "*" commits in the diagram below,
- then post-receive-email would never include the details of the two
- commits that are common to "master" and "branch" in its
- notifications.
-
- o---o---o---*---*---* <-- master
- \
- *---* <-- branch
-
- git-multimail analyzes all reference modifications to determine
- which commits were not present before the change, therefore avoiding
- that error.
-
-* In reference change emails, git-multimail tells which commits have
- been added to the reference vs. are entirely new to the repository,
- and which commits that have been omitted from the reference
- vs. entirely discarded from the repository.
-
-* The environment in which Git is running can be configured via an
- "Environment" abstraction.
-
-* Built-in support for Gitolite-managed repositories.
-
-* Instead of using full SHA1 object names in emails, git-multimail
- mostly uses abbreviated SHA1s, plus one-line log message summaries
- where appropriate.
-
-* In the schematic diagrams that explain non-fast-forward commits,
- git-multimail shows the names of the branches involved.
-
-* The emails generated by git-multimail include the name of the Git
- repository that was modified; this is convenient for recipients who
- are monitoring multiple repositories.
-
-* git-multimail allows the email "From" addresses to be configured.
-
-* The recipients lists (multimailhook.mailinglist,
- multimailhook.refchangelist, multimailhook.announcelist, and
- multimailhook.commitlist) can be comma-separated values and/or
- multivalued settings in the config file; e.g.,
-
- [multimailhook]
- mailinglist = mr.brown@example.com, mr.black@example.com
- announcelist = Him <him@example.com>
- announcelist = Jim <jim@example.com>
- announcelist = pop@example.com
-
- This might make it easier to maintain short recipients lists without
- requiring full-fledged mailing list software.
-
-* By default, git-multimail sets email "Reply-To" headers to reply to
- the pusher (for reference updates) and to the author (for commit
- notifications). By default, the pusher's email address is
- constructed by appending "multimailhook.emaildomain" to the pusher's
- username.
-
-* The generated emails contain a configurable footer. By default, it
- lists the name of the administrator who should be contacted to
- unsubscribe from notification emails.
-
-* New option multimailhook.emailmaxlinelength to limit the length of
- lines in the main part of the email body. The default limit is 500
- characters.
-
-* New option multimailhook.emailstrictutf8 to ensure that the main
- part of the email body is valid UTF-8. Invalid characters are
- turned into the Unicode replacement character, U+FFFD. By default
- this option is turned on.
-
-* Written in Python. Easier to add new features.
diff --git a/contrib/hooks/multimail/README.rst b/contrib/hooks/multimail/README.rst
deleted file mode 100644
index 7c0fc4a..0000000
--- a/contrib/hooks/multimail/README.rst
+++ /dev/null
@@ -1,774 +0,0 @@
-git-multimail version 1.5.0
-===========================
-
-.. image:: https://travis-ci.org/git-multimail/git-multimail.svg?branch=master
- :target: https://travis-ci.org/git-multimail/git-multimail
-
-git-multimail is a tool for sending notification emails on pushes to a
-Git repository. It includes a Python module called ``git_multimail.py``,
-which can either be used as a hook script directly or can be imported
-as a Python module into another script.
-
-git-multimail is derived from the Git project's old
-contrib/hooks/post-receive-email, and is mostly compatible with that
-script. See README.migrate-from-post-receive-email for details about
-the differences and for how to migrate from post-receive-email to
-git-multimail.
-
-git-multimail, like the rest of the Git project, is licensed under
-GPLv2 (see the COPYING file for details).
-
-Please note: although, as a convenience, git-multimail may be
-distributed along with the main Git project, development of
-git-multimail takes place in its own, separate project. Please, read
-`<CONTRIBUTING.rst>`__ for more information.
-
-
-By default, for each push received by the repository, git-multimail:
-
-1. Outputs one email summarizing each reference that was changed.
- These "reference change" (called "refchange" below) emails describe
- the nature of the change (e.g., was the reference created, deleted,
- fast-forwarded, etc.) and include a one-line summary of each commit
- that was added to the reference.
-
-2. Outputs one email for each new commit that was introduced by the
- reference change. These "commit" emails include a list of the
- files changed by the commit, followed by the diffs of files
- modified by the commit. The commit emails are threaded to the
- corresponding reference change email via "In-Reply-To". This style
- (similar to the "git format-patch" style used on the Git mailing
- list) makes it easy to scan through the emails, jump to patches
- that need further attention, and write comments about specific
- commits. Commits are handled in reverse topological order (i.e.,
- parents shown before children). For example::
-
- [git] branch master updated
- + [git] 01/08: doc: fix xref link from api docs to manual pages
- + [git] 02/08: api-credentials.txt: show the big picture first
- + [git] 03/08: api-credentials.txt: mention credential.helper explicitly
- + [git] 04/08: api-credentials.txt: add "see also" section
- + [git] 05/08: t3510 (cherry-pick-sequence): add missing '&&'
- + [git] 06/08: Merge branch 'rr/maint-t3510-cascade-fix'
- + [git] 07/08: Merge branch 'mm/api-credentials-doc'
- + [git] 08/08: Git 1.7.11-rc2
-
- By default, each commit appears in exactly one commit email, the
- first time that it is pushed to the repository. If a commit is later
- merged into another branch, then a one-line summary of the commit
- is included in the reference change email (as usual), but no
- additional commit email is generated. See
- `multimailhook.refFilter(Inclusion|Exclusion|DoSend|DontSend)Regex`
- below to configure which branches and tags are watched by the hook.
-
- By default, reference change emails have their "Reply-To" field set
- to the person who pushed the change, and commit emails have their
- "Reply-To" field set to the author of the commit.
-
-3. Output one "announce" mail for each new annotated tag, including
- information about the tag and optionally a shortlog describing the
- changes since the previous tag. Such emails might be useful if you
- use annotated tags to mark releases of your project.
-
-
-Requirements
-------------
-
-* Python 2.x, version 2.4 or later. No non-standard Python modules
- are required. git-multimail has preliminary support for Python 3
- (but it has been better tested with Python 2).
-
-* The ``git`` command must be in your PATH. git-multimail is known to
- work with Git versions back to 1.7.1. (Earlier versions have not
- been tested; if you do so, please report your results.)
-
-* To send emails using the default configuration, a standard sendmail
- program must be located at '/usr/sbin/sendmail' or
- '/usr/lib/sendmail' and must be configured correctly to send emails.
- If this is not the case, set multimailhook.sendmailCommand, or see
- the multimailhook.mailer configuration variable below for how to
- configure git-multimail to send emails via an SMTP server.
-
-* git-multimail is currently tested only on Linux. It may or may not
- work on other platforms such as Windows and Mac OS. See
- `<CONTRIBUTING.rst>`__ to improve the situation.
-
-
-Invocation
-----------
-
-``git_multimail.py`` is designed to be used as a ``post-receive`` hook in a
-Git repository (see githooks(5)). Link or copy it to
-$GIT_DIR/hooks/post-receive within the repository for which email
-notifications are desired. Usually it should be installed on the
-central repository for a project, to which all commits are eventually
-pushed.
-
-For use on pre-v1.5.1 Git servers, ``git_multimail.py`` can also work as
-an ``update`` hook, taking its arguments on the command line. To use
-this script in this manner, link or copy it to $GIT_DIR/hooks/update.
-Please note that the script is not completely reliable in this mode
-[1]_.
-
-Alternatively, ``git_multimail.py`` can be imported as a Python module
-into your own Python post-receive script. This method is a bit more
-work, but allows the behavior of the hook to be customized using
-arbitrary Python code. For example, you can use a custom environment
-(perhaps inheriting from GenericEnvironment or GitoliteEnvironment) to
-
-* change how the user who did the push is determined
-
-* read users' email addresses from an LDAP server or from a database
-
-* decide which users should be notified about which commits based on
- the contents of the commits (e.g., for users who want to be notified
- only about changes affecting particular files or subdirectories)
-
-Or you can change how emails are sent by writing your own Mailer
-class. The ``post-receive`` script in this directory demonstrates how
-to use ``git_multimail.py`` as a Python module. (If you make interesting
-changes of this type, please consider sharing them with the
-community.)
-
-
-Troubleshooting/FAQ
--------------------
-
-Please read `<doc/troubleshooting.rst>`__ for frequently asked
-questions and common issues with git-multimail.
-
-
-Configuration
--------------
-
-By default, git-multimail mostly takes its configuration from the
-following ``git config`` settings:
-
-multimailhook.environment
- This describes the general environment of the repository. In most
- cases, you do not need to specify a value for this variable:
- `git-multimail` will autodetect which environment to use.
- Currently supported values:
-
- generic
- the username of the pusher is read from $USER or $USERNAME and
- the repository name is derived from the repository's path.
-
- gitolite
- Environment to use when ``git-multimail`` is ran as a gitolite_
- hook.
-
- The username of the pusher is read from $GL_USER, the repository
- name is read from $GL_REPO, and the From: header value is
- optionally read from gitolite.conf (see multimailhook.from).
-
- For more information about gitolite and git-multimail, read
- `<doc/gitolite.rst>`__
-
- stash
- Environment to use when ``git-multimail`` is ran as an Atlassian
- BitBucket Server (formerly known as Atlassian Stash) hook.
-
- **Warning:** this mode was provided by a third-party contributor
- and never tested by the git-multimail maintainers. It is
- provided as-is and may or may not work for you.
-
- This value is automatically assumed when the stash-specific
- flags (``--stash-user`` and ``--stash-repo``) are specified on
- the command line. When this environment is active, the username
- and repo come from these two command line flags, which must be
- specified.
-
- gerrit
- Environment to use when ``git-multimail`` is ran as a
- ``ref-updated`` Gerrit hook.
-
- This value is used when the gerrit-specific command line flags
- (``--oldrev``, ``--newrev``, ``--refname``, ``--project``) for
- gerrit's ref-updated hook are present. When this environment is
- active, the username of the pusher is taken from the
- ``--submitter`` argument if that command line option is passed,
- otherwise 'Gerrit' is used. The repository name is taken from
- the ``--project`` option on the command line, which must be passed.
-
- For more information about gerrit and git-multimail, read
- `<doc/gerrit.rst>`__
-
- If none of these environments is suitable for your setup, then you
- can implement a Python class that inherits from Environment and
- instantiate it via a script that looks like the example
- post-receive script.
-
- The environment value can be specified on the command line using
- the ``--environment`` option. If it is not specified on the
- command line or by ``multimailhook.environment``, the value is
- guessed as follows:
-
- * If stash-specific (respectively gerrit-specific) command flags
- are present on the command-line, then ``stash`` (respectively
- ``gerrit``) is used.
-
- * If the environment variables $GL_USER and $GL_REPO are set, then
- ``gitolite`` is used.
-
- * If none of the above apply, then ``generic`` is used.
-
-multimailhook.repoName
- A short name of this Git repository, to be used in various places
- in the notification email text. The default is to use $GL_REPO
- for gitolite repositories, or otherwise to derive this value from
- the repository path name.
-
-multimailhook.mailingList
- The list of email addresses to which notification emails should be
- sent, as RFC 2822 email addresses separated by commas. This
- configuration option can be multivalued. Leave it unset or set it
- to the empty string to not send emails by default. The next few
- settings can be used to configure specific address lists for
- specific types of notification email.
-
-multimailhook.refchangeList
- The list of email addresses to which summary emails about
- reference changes should be sent, as RFC 2822 email addresses
- separated by commas. This configuration option can be
- multivalued. The default is the value in
- multimailhook.mailingList. Set this value to "none" (or the empty
- string) to prevent reference change emails from being sent even if
- multimailhook.mailingList is set.
-
-multimailhook.announceList
- The list of email addresses to which emails about new annotated
- tags should be sent, as RFC 2822 email addresses separated by
- commas. This configuration option can be multivalued. The
- default is the value in multimailhook.refchangeList or
- multimailhook.mailingList. Set this value to "none" (or the empty
- string) to prevent annotated tag announcement emails from being sent
- even if one of the other values is set.
-
-multimailhook.commitList
- The list of email addresses to which emails about individual new
- commits should be sent, as RFC 2822 email addresses separated by
- commas. This configuration option can be multivalued. The
- default is the value in multimailhook.mailingList. Set this value
- to "none" (or the empty string) to prevent notification emails about
- individual commits from being sent even if
- multimailhook.mailingList is set.
-
-multimailhook.announceShortlog
- If this option is set to true, then emails about changes to
- annotated tags include a shortlog of changes since the previous
- tag. This can be useful if the annotated tags represent releases;
- then the shortlog will be a kind of rough summary of what has
- happened since the last release. But if your tagging policy is
- not so straightforward, then the shortlog might be confusing
- rather than useful. Default is false.
-
-multimailhook.commitEmailFormat
- The format of email messages for the individual commits, can be "text" or
- "html". In the latter case, the emails will include diffs using colorized
- HTML instead of plain text used by default. Note that this currently the
- ref change emails are always sent in plain text.
-
- Note that when using "html", the formatting is done by parsing the
- output of ``git log`` with ``-p``. When using
- ``multimailhook.commitLogOpts`` to specify a ``--format`` for
- ``git log``, one may get false positive (e.g. lines in the body of
- the message starting with ``+++`` or ``---`` colored in red or
- green).
-
- By default, all the message is HTML-escaped. See
- ``multimailhook.htmlInIntro`` to change this behavior.
-
-multimailhook.commitBrowseURL
- Used to generate a link to an online repository browser in commit
- emails. This variable must be a string. Format directives like
- ``%(<variable>)s`` will be expanded the same way as template
- strings. In particular, ``%(id)s`` will be replaced by the full
- Git commit identifier (40-chars hexadecimal).
-
- If the string does not contain any format directive, then
- ``%(id)s`` will be automatically added to the string. If you don't
- want ``%(id)s`` to be automatically added, use the empty format
- directive ``%()s`` anywhere in the string.
-
- For example, a suitable value for the git-multimail project itself
- would be
- ``https://github.com/git-multimail/git-multimail/commit/%(id)s``.
-
-multimailhook.htmlInIntro, multimailhook.htmlInFooter
- When generating an HTML message, git-multimail escapes any HTML
- sequence by default. This means that if a template contains HTML
- like ``<a href="foo">link</a>``, the reader will see the HTML
- source code and not a proper link.
-
- Set ``multimailhook.htmlInIntro`` to true to allow writing HTML
- formatting in introduction templates. Similarly, set
- ``multimailhook.htmlInFooter`` for HTML in the footer.
-
- Variables expanded in the template are still escaped. For example,
- if a repository's path contains a ``<``, it will be rendered as
- such in the message.
-
- Read `<doc/customizing-emails.rst>`__ for more details and
- examples.
-
-multimailhook.refchangeShowGraph
- If this option is set to true, then summary emails about reference
- changes will additionally include:
-
- * a graph of the added commits (if any)
-
- * a graph of the discarded commits (if any)
-
- The log is generated by running ``git log --graph`` with the options
- specified in graphOpts. The default is false.
-
-multimailhook.refchangeShowLog
- If this option is set to true, then summary emails about reference
- changes will include a detailed log of the added commits in
- addition to the one line summary. The log is generated by running
- ``git log`` with the options specified in multimailhook.logOpts.
- Default is false.
-
-multimailhook.mailer
- This option changes the way emails are sent. Accepted values are:
-
- * **sendmail (the default)**: use the command ``/usr/sbin/sendmail`` or
- ``/usr/lib/sendmail`` (or sendmailCommand, if configured). This
- mode can be further customized via the following options:
-
- multimailhook.sendmailCommand
- The command used by mailer ``sendmail`` to send emails. Shell
- quoting is allowed in the value of this setting, but remember that
- Git requires double-quotes to be escaped; e.g.::
-
- git config multimailhook.sendmailcommand '/usr/sbin/sendmail -oi -t -F \"Git Repo\"'
-
- Default is '/usr/sbin/sendmail -oi -t' or
- '/usr/lib/sendmail -oi -t' (depending on which file is
- present and executable).
-
- multimailhook.envelopeSender
- If set then pass this value to sendmail via the -f option to set
- the envelope sender address.
-
- * **smtp**: use Python's smtplib. This is useful when the sendmail
- command is not available on the system. This mode can be
- further customized via the following options:
-
- multimailhook.smtpServer
- The name of the SMTP server to connect to. The value can
- also include a colon and a port number; e.g.,
- ``mail.example.com:25``. Default is 'localhost' using port 25.
-
- multimailhook.smtpUser, multimailhook.smtpPass
- Server username and password. Required if smtpEncryption is 'ssl'.
- Note that the username and password currently need to be
- set cleartext in the configuration file, which is not
- recommended. If you need to use this option, be sure your
- configuration file is read-only.
-
- multimailhook.envelopeSender
- The sender address to be passed to the SMTP server. If
- unset, then the value of multimailhook.from is used.
-
- multimailhook.smtpServerTimeout
- Timeout in seconds. Default is 10.
-
- multimailhook.smtpEncryption
- Set the security type. Allowed values: ``none``, ``ssl``, ``tls`` (starttls).
- Default is ``none``.
-
- multimailhook.smtpCACerts
- Set the path to a list of trusted CA certificate to verify the
- server certificate, only supported when ``smtpEncryption`` is
- ``tls``. If unset or empty, the server certificate is not
- verified. If it targets a file containing a list of trusted CA
- certificates (PEM format) these CAs will be used to verify the
- server certificate. For debian, you can set
- ``/etc/ssl/certs/ca-certificates.crt`` for using the system
- trusted CAs. For self-signed server, you can add your server
- certificate to the system store::
-
- cd /usr/local/share/ca-certificates/
- openssl s_client -starttls smtp \
- -connect mail.example.net:587 -showcerts \
- </dev/null 2>/dev/null \
- | openssl x509 -outform PEM >mail.example.net.crt
- update-ca-certificates
-
- and used the updated ``/etc/ssl/certs/ca-certificates.crt``. Or
- directly use your ``/path/to/mail.example.net.crt``. Default is
- unset.
-
- multimailhook.smtpServerDebugLevel
- Integer number. Set to greater than 0 to activate debugging.
-
-multimailhook.from, multimailhook.fromCommit, multimailhook.fromRefchange
- If set, use this value in the From: field of generated emails.
- ``fromCommit`` is used for commit emails, ``fromRefchange`` is
- used for refchange emails, and ``from`` is used as fall-back in
- all cases.
-
- The value for these variables can be either:
-
- - An email address, which will be used directly.
-
- - The value ``pusher``, in which case the pusher's address (if
- available) will be used.
-
- - The value ``author`` (meaningful only for ``fromCommit``), in which
- case the commit author's address will be used.
-
- If config values are unset, the value of the From: header is
- determined as follows:
-
- 1. (gitolite environment only)
- 1.a) If ``multimailhook.MailaddressMap`` is set, and is a path
- to an existing file (if relative, it is considered relative to
- the place where ``gitolite.conf`` is located), then this file
- should contain lines like::
-
- username Firstname Lastname <email@example.com>
-
- git-multimail will then look for a line where ``$GL_USER``
- matches the ``username`` part, and use the rest of the line for
- the ``From:`` header.
-
- 1.b) Parse gitolite.conf, looking for a block of comments that
- looks like this::
-
- # BEGIN USER EMAILS
- # username Firstname Lastname <email@example.com>
- # END USER EMAILS
-
- If that block exists, and there is a line between the BEGIN
- USER EMAILS and END USER EMAILS lines where the first field
- matches the gitolite username ($GL_USER), use the rest of the
- line for the From: header.
-
- 2. If the user.email configuration setting is set, use its value
- (and the value of user.name, if set).
-
- 3. Use the value of multimailhook.envelopeSender.
-
-multimailhook.MailaddressMap
- (gitolite environment only)
- File to look for a ``From:`` address based on the user doing the
- push. Defaults to unset. See ``multimailhook.from`` for details.
-
-multimailhook.administrator
- The name and/or email address of the administrator of the Git
- repository; used in FOOTER_TEMPLATE. Default is
- multimailhook.envelopesender if it is set; otherwise a generic
- string is used.
-
-multimailhook.emailPrefix
- All emails have this string prepended to their subjects, to aid
- email filtering (though filtering based on the X-Git-* email
- headers is probably more robust). Default is the short name of
- the repository in square brackets; e.g., ``[myrepo]``. Set this
- value to the empty string to suppress the email prefix. You may
- use the placeholder ``%(repo_shortname)s`` for the short name of
- the repository.
-
-multimailhook.emailMaxLines
- The maximum number of lines that should be included in the body of
- a generated email. If not specified, there is no limit. Lines
- beyond the limit are suppressed and counted, and a final line is
- added indicating the number of suppressed lines.
-
-multimailhook.emailMaxLineLength
- The maximum length of a line in the email body. Lines longer than
- this limit are truncated to this length with a trailing ``[...]``
- added to indicate the missing text. The default is 500, because
- (a) diffs with longer lines are probably from binary files, for
- which a diff is useless, and (b) even if a text file has such long
- lines, the diffs are probably unreadable anyway. To disable line
- truncation, set this option to 0.
-
-multimailhook.subjectMaxLength
- The maximum length of the subject line (i.e. the ``oneline`` field
- in templates, not including the prefix). Lines longer than this
- limit are truncated to this length with a trailing ``[...]`` added
- to indicate the missing text. This option The default is to use
- ``multimailhook.emailMaxLineLength``. This option avoids sending
- emails with overly long subject lines, but should not be needed if
- the commit messages follow the Git convention (one short subject
- line, then a blank line, then the message body). To disable line
- truncation, set this option to 0.
-
-multimailhook.maxCommitEmails
- The maximum number of commit emails to send for a given change.
- When the number of patches is larger that this value, only the
- summary refchange email is sent. This can avoid accidental
- mailbombing, for example on an initial push. To disable commit
- emails limit, set this option to 0. The default is 500.
-
-multimailhook.excludeMergeRevisions
- When sending out revision emails, do not consider merge commits (the
- functional equivalent of `rev-list --no-merges`).
- The default is `false` (send merge commit emails).
-
-multimailhook.emailStrictUTF8
- If this boolean option is set to `true`, then the main part of the
- email body is forced to be valid UTF-8. Any characters that are
- not valid UTF-8 are converted to the Unicode replacement
- character, U+FFFD. The default is `true`.
-
- This option is ineffective with Python 3, where non-UTF-8
- characters are unconditionally replaced.
-
-multimailhook.diffOpts
- Options passed to ``git diff-tree`` when generating the summary
- information for ReferenceChange emails. Default is ``--stat
- --summary --find-copies-harder``. Add -p to those options to
- include a unified diff of changes in addition to the usual summary
- output. Shell quoting is allowed; see ``multimailhook.logOpts`` for
- details.
-
-multimailhook.graphOpts
- Options passed to ``git log --graph`` when generating graphs for the
- reference change summary emails (used only if refchangeShowGraph
- is true). The default is '--oneline --decorate'.
-
- Shell quoting is allowed; see logOpts for details.
-
-multimailhook.logOpts
- Options passed to ``git log`` to generate additional info for
- reference change emails (used only if refchangeShowLog is set).
- For example, adding -p will show each commit's complete diff. The
- default is empty.
-
- Shell quoting is allowed; for example, a log format that contains
- spaces can be specified using something like::
-
- git config multimailhook.logopts '--pretty=format:"%h %aN <%aE>%n%s%n%n%b%n"'
-
- If you want to set this by editing your configuration file
- directly, remember that Git requires double-quotes to be escaped
- (see git-config(1) for more information)::
-
- [multimailhook]
- logopts = --pretty=format:\"%h %aN <%aE>%n%s%n%n%b%n\"
-
-multimailhook.commitLogOpts
- Options passed to ``git log`` to generate additional info for
- revision change emails. For example, adding --ignore-all-spaces
- will suppress whitespace changes. The default options are ``-C
- --stat -p --cc``. Shell quoting is allowed; see
- multimailhook.logOpts for details.
-
-multimailhook.dateSubstitute
- String to use as a substitute for ``Date:`` in the output of ``git
- log`` while formatting commit messages. This is useful to avoid
- emitting a line that can be interpreted by mailers as the start of
- a cited message (Zimbra webmail in particular). Defaults to
- ``CommitDate:``. Set to an empty string or ``none`` to deactivate
- the behavior.
-
-multimailhook.emailDomain
- Domain name appended to the username of the person doing the push
- to convert it into an email address
- (via ``"%s@%s" % (username, emaildomain)``). More complicated
- schemes can be implemented by overriding Environment and
- overriding its get_pusher_email() method.
-
-multimailhook.replyTo, multimailhook.replyToCommit, multimailhook.replyToRefchange
- Addresses to use in the Reply-To: field for commit emails
- (replyToCommit) and refchange emails (replyToRefchange).
- multimailhook.replyTo is used as default when replyToCommit or
- replyToRefchange is not set. The shortcuts ``pusher`` and
- ``author`` are allowed with the same semantics as for
- ``multimailhook.from``. In addition, the value ``none`` can be
- used to omit the ``Reply-To:`` field.
-
- The default is ``pusher`` for refchange emails, and ``author`` for
- commit emails.
-
-multimailhook.quiet
- Do not output the list of email recipients from the hook
-
-multimailhook.stdout
- For debugging, send emails to stdout rather than to the
- mailer. Equivalent to the --stdout command line option
-
-multimailhook.scanCommitForCc
- If this option is set to true, than recipients from lines in commit body
- that starts with ``CC:`` will be added to CC list.
- Default: false
-
-multimailhook.combineWhenSingleCommit
- If this option is set to true and a single new commit is pushed to
- a branch, combine the summary and commit email messages into a
- single email.
- Default: true
-
-multimailhook.refFilterInclusionRegex, multimailhook.refFilterExclusionRegex, multimailhook.refFilterDoSendRegex, multimailhook.refFilterDontSendRegex
- **Warning:** these options are experimental. They should work, but
- the user-interface is not stable yet (in particular, the option
- names may change). If you want to participate in stabilizing the
- feature, please contact the maintainers and/or send pull-requests.
- If you are happy with the current shape of the feature, please
- report it too.
-
- Regular expressions that can be used to limit refs for which email
- updates will be sent. It is an error to specify both an inclusion
- and an exclusion regex. If a ``refFilterInclusionRegex`` is
- specified, emails will only be sent for refs which match this
- regex. If a ``refFilterExclusionRegex`` regex is specified,
- emails will be sent for all refs except those that match this
- regex (or that match a predefined regex specific to the
- environment, such as "^refs/notes" for most environments and
- "^refs/notes|^refs/changes" for the gerrit environment).
-
- The expressions are matched against the complete refname, and is
- considered to match if any substring matches. For example, to
- filter-out all tags, set ``refFilterExclusionRegex`` to
- ``^refs/tags/`` (note the leading ``^`` but no trailing ``$``). If
- you set ``refFilterExclusionRegex`` to ``master``, then any ref
- containing ``master`` will be excluded (the ``master`` branch, but
- also ``refs/tags/master`` or ``refs/heads/foo-master-bar``).
-
- ``refFilterDoSendRegex`` and ``refFilterDontSendRegex`` are
- analogous to ``refFilterInclusionRegex`` and
- ``refFilterExclusionRegex`` with one difference: with
- ``refFilterDoSendRegex`` and ``refFilterDontSendRegex``, commits
- introduced by one excluded ref will not be considered as new when
- they reach an included ref. Typically, if you add a branch ``foo``
- to ``refFilterDontSendRegex``, push commits to this branch, and
- later merge branch ``foo`` into ``master``, then the notification
- email for ``master`` will contain a commit email only for the
- merge commit. If you include ``foo`` in
- ``refFilterExclusionRegex``, then at the time of merge, you will
- receive one commit email per commit in the branch.
-
- These variables can be multi-valued, like::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/
- refFilterExclusionRegex = ^refs/heads/master$
-
- You can also provide a whitespace-separated list like::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/ ^refs/heads/master$
-
- Both examples exclude tags and the master branch, and are
- equivalent to::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/|^refs/heads/master$
-
- ``refFilterInclusionRegex`` and ``refFilterExclusionRegex`` are
- strictly stronger than ``refFilterDoSendRegex`` and
- ``refFilterDontSendRegex``. In other words, adding a ref to a
- DoSend/DontSend regex has no effect if it is already excluded by a
- Exclusion/Inclusion regex.
-
-multimailhook.logFile, multimailhook.errorLogFile, multimailhook.debugLogFile
-
- When set, these variable designate path to files where
- git-multimail will log some messages. Normal messages and error
- messages are sent to ``logFile``, and error messages are also sent
- to ``errorLogFile``. Debug messages and all other messages are
- sent to ``debugLogFile``. The recommended way is to set only one
- of these variables, but it is also possible to set several of them
- (part of the information is then duplicated in several log files,
- for example errors are duplicated to all log files).
-
- Relative path are relative to the Git repository where the push is
- done.
-
-multimailhook.verbose
-
- Verbosity level of git-multimail on its standard output. By
- default, show only error and info messages. If set to true, show
- also debug messages.
-
-Email filtering aids
---------------------
-
-All emails include extra headers to enable fine tuned filtering and
-give information for debugging. All emails include the headers
-``X-Git-Host``, ``X-Git-Repo``, ``X-Git-Refname``, and ``X-Git-Reftype``.
-ReferenceChange emails also include headers ``X-Git-Oldrev`` and ``X-Git-Newrev``;
-Revision emails also include header ``X-Git-Rev``.
-
-
-Customizing email contents
---------------------------
-
-git-multimail mostly generates emails by expanding templates. The
-templates can be customized. To avoid the need to edit
-``git_multimail.py`` directly, the preferred way to change the templates
-is to write a separate Python script that imports ``git_multimail.py`` as
-a module, then replaces the templates in place. See the provided
-post-receive script for an example of how this is done.
-
-
-Customizing git-multimail for your environment
-----------------------------------------------
-
-git-multimail is mostly customized via an "environment" that describes
-the local environment in which Git is running. Two types of
-environment are built in:
-
-GenericEnvironment
- a stand-alone Git repository.
-
-GitoliteEnvironment
- a Git repository that is managed by gitolite_. For such
- repositories, the identity of the pusher is read from
- environment variable $GL_USER, the name of the repository is read
- from $GL_REPO (if it is not overridden by multimailhook.reponame),
- and the From: header value is optionally read from gitolite.conf
- (see multimailhook.from).
-
-By default, git-multimail assumes GitoliteEnvironment if $GL_USER and
-$GL_REPO are set, and otherwise assumes GenericEnvironment.
-Alternatively, you can choose one of these two environments explicitly
-by setting a ``multimailhook.environment`` config setting (which can
-have the value `generic` or `gitolite`) or by passing an --environment
-option to the script.
-
-If you need to customize the script in ways that are not supported by
-the existing environments, you can define your own environment class
-class using arbitrary Python code. To do so, you need to import
-``git_multimail.py`` as a Python module, as demonstrated by the example
-post-receive script. Then implement your environment class; it should
-usually inherit from one of the existing Environment classes and
-possibly one or more of the EnvironmentMixin classes. Then set the
-``environment`` variable to an instance of your own environment class
-and pass it to ``run_as_post_receive_hook()``.
-
-The standard environment classes, GenericEnvironment and
-GitoliteEnvironment, are in fact themselves put together out of a
-number of mixin classes, each of which handles one aspect of the
-customization. For the finest control over your configuration, you
-can specify exactly which mixin classes your own environment class
-should inherit from, and override individual methods (or even add your
-own mixin classes) to implement entirely new behaviors. If you
-implement any mixins that might be useful to other people, please
-consider sharing them with the community!
-
-
-Getting involved
-----------------
-
-Please, read `<CONTRIBUTING.rst>`__ for instructions on how to
-contribute to git-multimail.
-
-
-Footnotes
----------
-
-.. [1] Because of the way information is passed to update hooks, the
- script's method of determining whether a commit has already
- been seen does not work when it is used as an ``update`` script.
- In particular, no notification email will be generated for a
- new commit that is added to multiple references in the same
- push. A workaround is to use --force-send to force sending the
- emails.
-
-.. _gitolite: https://github.com/sitaramc/gitolite
diff --git a/contrib/hooks/multimail/doc/customizing-emails.rst b/contrib/hooks/multimail/doc/customizing-emails.rst
deleted file mode 100644
index 3f5b67f..0000000
--- a/contrib/hooks/multimail/doc/customizing-emails.rst
+++ /dev/null
@@ -1,56 +0,0 @@
-Customizing the content and formatting of emails
-================================================
-
-Overloading template strings
-----------------------------
-
-The content of emails is generated based on template strings defined
-in ``git_multimail.py``. You can customize these template strings
-without changing the script itself, by defining a Python wrapper
-around it. The python wrapper should ``import git_multimail`` and then
-override the ``git_multimail.*`` strings like this::
-
- import sys # needed for sys.argv
-
- # Import and customize git_multimail:
- import git_multimail
- git_multimail.REVISION_INTRO_TEMPLATE = """..."""
- git_multimail.COMBINED_INTRO_TEMPLATE = git_multimail.REVISION_INTRO_TEMPLATE
-
- # start git_multimail itself:
- git_multimail.main(sys.argv[1:])
-
-The template strings can use any value already used in the existing
-templates (read the source code).
-
-Using HTML in template strings
-------------------------------
-
-If ``multimailhook.commitEmailFormat`` is set to HTML, then
-git-multimail will generate HTML emails for commit notifications. The
-log and diff will be formatted automatically by git-multimail. By
-default, any HTML special character in the templates will be escaped.
-
-To use HTML formatting in the introduction of the email, set
-``multimailhook.htmlInIntro`` to ``true``. Then, the template can
-contain any HTML tags, that will be sent as-is in the email. For
-example, to add some formatting and a link to the online commit, use
-a format like::
-
- git_multimail.REVISION_INTRO_TEMPLATE = """\
- <span style="color:#808080">This is an automated email from the git hooks/post-receive script.</span><br /><br />
-
- <strong>%(pusher)s</strong> pushed a commit to %(refname_type)s %(short_refname)s
- in repository %(repo_shortname)s.<br />
-
- <a href="https://github.com/git-multimail/git-multimail/commit/%(newrev)s">View on GitHub</a>.
- """
-
-Note that the values expanded from ``%(variable)s`` in the format
-strings will still be escaped.
-
-For a less flexible but easier to set up way to add a link to commit
-emails, see ``multimailhook.commitBrowseURL``.
-
-Similarly, one can set ``multimailhook.htmlInFooter`` and override any
-of the ``*_FOOTER*`` template strings.
diff --git a/contrib/hooks/multimail/doc/gerrit.rst b/contrib/hooks/multimail/doc/gerrit.rst
deleted file mode 100644
index 8011d05..0000000
--- a/contrib/hooks/multimail/doc/gerrit.rst
+++ /dev/null
@@ -1,56 +0,0 @@
-Setting up git-multimail on Gerrit
-==================================
-
-Gerrit has its own email-sending system, but you may prefer using
-``git-multimail`` instead. It supports Gerrit natively as a Gerrit
-``ref-updated`` hook (Warning: `Gerrit hooks
-<https://gerrit-review.googlesource.com/Documentation/config-hooks.html>`__
-are distinct from Git hooks). Setting up ``git-multimail`` on a Gerrit
-installation can be done following the instructions below.
-
-The explanations show an easy way to set up ``git-multimail``,
-but leave ``git-multimail`` installed and unconfigured for a while. If
-you run Gerrit on a production server, it is advised that you
-execute the step "Set up the hook" last to avoid confusing your users
-in the meantime.
-
-Set up the hook
----------------
-
-Create a directory ``$site_path/hooks/`` if it does not exist (if you
-don't know what ``$site_path`` is, run ``gerrit.sh status`` and look
-for a ``GERRIT_SITE`` line). Either copy ``git_multimail.py`` to
-``$site_path/hooks/ref-updated`` or create a wrapper script like
-this::
-
- #! /bin/sh
- exec /path/to/git_multimail.py "$@"
-
-In both cases, make sure the file is named exactly
-``$site_path/hooks/ref-updated`` and is executable.
-
-(Alternatively, you may configure the ``[hooks]`` section of
-gerrit.config)
-
-Configuration
--------------
-
-Log on the gerrit server and edit ``$site_path/git/$project/config``
-to configure ``git-multimail``.
-
-Troubleshooting
----------------
-
-Warning: this will disable ``git-multimail`` during the debug, and
-could confuse your users. Don't run on a production server.
-
-To debug configuration issues with ``git-multimail``, you can add the
-``--stdout`` option when calling ``git_multimail.py`` like this::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py \
- --stdout "$@" >> /tmp/log.txt
-
-and try pushing from a test repository. You should see the source of
-the email that would have been sent in the output of ``git push`` in
-the file ``/tmp/log.txt``.
diff --git a/contrib/hooks/multimail/doc/gitolite.rst b/contrib/hooks/multimail/doc/gitolite.rst
deleted file mode 100644
index 5054833..0000000
--- a/contrib/hooks/multimail/doc/gitolite.rst
+++ /dev/null
@@ -1,118 +0,0 @@
-Setting up git-multimail on gitolite
-====================================
-
-``git-multimail`` supports gitolite 3 natively.
-The explanations below show an easy way to set up ``git-multimail``,
-but leave ``git-multimail`` installed and unconfigured for a while. If
-you run gitolite on a production server, it is advised that you
-execute the step "Set up the hook" last to avoid confusing your users
-in the meantime.
-
-Set up the hook
----------------
-
-Log in as your gitolite user.
-
-Create a file ``.gitolite/hooks/common/post-receive`` on your gitolite
-account containing (adapt the path, obviously)::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py "$@"
-
-Make sure it's executable (``chmod +x``). Record the hook in
-gitolite::
-
- gitolite setup
-
-Configuration
--------------
-
-First, you have to allow the admin to set Git configuration variables.
-
-As gitolite user, edit the line containing ``GIT_CONFIG_KEYS`` in file
-``.gitolite.rc``, to make it look like::
-
- GIT_CONFIG_KEYS => 'multimailhook\..*',
-
-You can now log out and return to your normal user.
-
-In the ``gitolite-admin`` clone, edit the file ``conf/gitolite.conf``
-and add::
-
- repo @all
- # Not strictly needed as git_multimail.py will chose gitolite if
- # $GL_USER is set.
- config multimailhook.environment = gitolite
- config multimailhook.mailingList = # Where emails should be sent
- config multimailhook.from = # From address to use
-
-Note that by default, gitolite forbids ``<`` and ``>`` in variable
-values (for security/paranoia reasons, see
-`compensating for UNSAFE_PATT
-<http://gitolite.com/gitolite/git-config/index.html#compensating-for-unsafe95patt>`__
-in gitolite's documentation for explanations and a way to disable
-this). As a consequence, you will not be able to use ``First Last
-<First.Last@example.com>`` as recipient email, but specifying
-``First.Last@example.com`` alone works.
-
-Obviously, you can customize all parameters on a per-repository basis by
-adding these ``config multimailhook.*`` lines in the section
-corresponding to a repository or set of repositories.
-
-To activate ``git-multimail`` on a per-repository basis, do not set
-``multimailhook.mailingList`` in the ``@all`` section and set it only
-for repositories for which you want ``git-multimail``.
-
-Alternatively, you can set up the ``From:`` field on a per-user basis
-by adding a ``BEGIN USER EMAILS``/``END USER EMAILS`` section (see
-``../README``).
-
-Specificities of Gitolite for Configuration
--------------------------------------------
-
-Empty configuration variables
-.............................
-
-With gitolite, the syntax ``config multimailhook.commitList = ""``
-unsets the variable instead of setting it to an empty string (see
-`here
-<http://gitolite.com/gitolite/git-config.html#an-important-warning-about-deleting-a-config-line>`__).
-As a result, there is no way to set a variable to the empty string.
-In all most places where an empty value is required, git-multimail
-now allows to specify special ``"none"`` value (case-sensitive) to
-mean the same.
-
-Alternatively, one can use ``" "`` (a single space) instead of ``""``.
-In most cases (in particular ``multimailhook.*List`` variables), this
-will be equivalent to an empty string.
-
-If you have a use-case where ``"none"`` is not an acceptable value and
-you need ``" "`` or ``""`` instead, please report it as a bug to
-git-multimail.
-
-Allowing Regular Expressions in Configuration
-.............................................
-
-gitolite has a mechanism to prevent unsafe configuration variable
-values, which prevent characters like ``|`` commonly used in regular
-expressions. If you do not need the safety feature of gitolite and
-need to use regular expressions in your configuration (e.g. for
-``multimailhook.refFilter*`` variables), set
-`UNSAFE_PATT
-<http://gitolite.com/gitolite/git-config.html#unsafe-patt>`__ to a
-less restrictive value.
-
-Troubleshooting
----------------
-
-Warning: this will disable ``git-multimail`` during the debug, and
-could confuse your users. Don't run on a production server.
-
-To debug configuration issues with ``git-multimail``, you can add the
-``--stdout`` option when calling ``git_multimail.py`` like this::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py --stdout "$@"
-
-and try pushing from a test repository. You should see the source of
-the email that would have been sent in the output of ``git push``.
diff --git a/contrib/hooks/multimail/doc/troubleshooting.rst b/contrib/hooks/multimail/doc/troubleshooting.rst
deleted file mode 100644
index 651b509..0000000
--- a/contrib/hooks/multimail/doc/troubleshooting.rst
+++ /dev/null
@@ -1,78 +0,0 @@
-Troubleshooting issues with git-multimail: a FAQ
-================================================
-
-How to check that git-multimail is properly set up?
----------------------------------------------------
-
-Since version 1.4.0, git-multimail allows a simple self-checking of
-its configuration: run it with the environment variable
-``GIT_MULTIMAIL_CHECK_SETUP`` set to a non-empty string. You should
-get something like this::
-
- $ GIT_MULTIMAIL_CHECK_SETUP=true /home/moy/dev/git-multimail/git-multimail/git_multimail.py
- Environment values:
- administrator : 'the administrator of this repository'
- charset : 'utf-8'
- emailprefix : '[git-multimail] '
- fqdn : 'anie'
- projectdesc : 'UNNAMED PROJECT'
- pusher : 'moy'
- repo_path : '/home/moy/dev/git-multimail'
- repo_shortname : 'git-multimail'
-
- Now, checking that git-multimail's standard input is properly set ...
- Please type some text and then press Return
- foo
- You have just entered:
- foo
- git-multimail seems properly set up.
-
-If you forgot to set an important variable, you may get instead::
-
- $ GIT_MULTIMAIL_CHECK_SETUP=true /home/moy/dev/git-multimail/git-multimail/git_multimail.py
- No email recipients configured!
-
-Do not set ``$GIT_MULTIMAIL_CHECK_SETUP`` other than for testing your
-configuration: it would disable the hook completely.
-
-Git is not using the right address in the From/To/Reply-To field
-----------------------------------------------------------------
-
-First, make sure that git-multimail actually uses what you think it is
-using. A lot happens to your email (especially when posting to a
-mailing-list) between the time `git_multimail.py` sends it and the
-time it reaches your inbox.
-
-A simple test (to do on a test repository, do not use in production as
-it would disable email sending): change your post-receive hook to call
-`git_multimail.py` with the `--stdout` option, and try to push to the
-repository. You should see something like::
-
- Counting objects: 3, done.
- Writing objects: 100% (3/3), 263 bytes | 0 bytes/s, done.
- Total 3 (delta 0), reused 0 (delta 0)
- remote: Sending notification emails to: foo.bar@example.com
- remote: ===========================================================================
- remote: Date: Mon, 25 Apr 2016 18:39:59 +0200
- remote: To: foo.bar@example.com
- remote: Subject: [git] branch master updated: foo
- remote: MIME-Version: 1.0
- remote: Content-Type: text/plain; charset=utf-8
- remote: Content-Transfer-Encoding: 8bit
- remote: Message-ID: <20160425163959.2311.20498@anie>
- remote: From: Auth Or <Foo.Bar@example.com>
- remote: Reply-To: Auth Or <Foo.Bar@example.com>
- remote: X-Git-Host: example
- ...
- remote: --
- remote: To stop receiving notification emails like this one, please contact
- remote: the administrator of this repository.
- remote: ===========================================================================
- To /path/to/repo
- 6278f04..e173f20 master -> master
-
-Note: this does not include the sender (Return-Path: header), as it is
-not part of the message content but passed to the mailer. Some mailer
-show the ``Sender:`` field instead of the ``From:`` field (for
-example, Zimbra Webmail shows ``From: <sender-field> on behalf of
-<from-field>``).
diff --git a/contrib/hooks/multimail/git_multimail.py b/contrib/hooks/multimail/git_multimail.py
deleted file mode 100755
index f563be8..0000000
--- a/contrib/hooks/multimail/git_multimail.py
+++ /dev/null
@@ -1,4346 +0,0 @@
-#! /usr/bin/env python
-
-__version__ = '1.5.0'
-
-# Copyright (c) 2015-2016 Matthieu Moy and others
-# Copyright (c) 2012-2014 Michael Haggerty and others
-# Derived from contrib/hooks/post-receive-email, which is
-# Copyright (c) 2007 Andy Parkins
-# and also includes contributions by other authors.
-#
-# This file is part of git-multimail.
-#
-# git-multimail is free software: you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version
-# 2 as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
-
-"""Generate notification emails for pushes to a git repository.
-
-This hook sends emails describing changes introduced by pushes to a
-git repository. For each reference that was changed, it emits one
-ReferenceChange email summarizing how the reference was changed,
-followed by one Revision email for each new commit that was introduced
-by the reference change.
-
-Each commit is announced in exactly one Revision email. If the same
-commit is merged into another branch in the same or a later push, then
-the ReferenceChange email will list the commit's SHA1 and its one-line
-summary, but no new Revision email will be generated.
-
-This script is designed to be used as a "post-receive" hook in a git
-repository (see githooks(5)). It can also be used as an "update"
-script, but this usage is not completely reliable and is deprecated.
-
-To help with debugging, this script accepts a --stdout option, which
-causes the emails to be written to standard output rather than sent
-using sendmail.
-
-See the accompanying README file for the complete documentation.
-
-"""
-
-import sys
-import os
-import re
-import bisect
-import socket
-import subprocess
-import shlex
-import optparse
-import logging
-import smtplib
-try:
- import ssl
-except ImportError:
- # Python < 2.6 do not have ssl, but that's OK if we don't use it.
- pass
-import time
-
-import uuid
-import base64
-
-PYTHON3 = sys.version_info >= (3, 0)
-
-if sys.version_info <= (2, 5):
- def all(iterable):
- for element in iterable:
- if not element:
- return False
- return True
-
-
-def is_ascii(s):
- return all(ord(c) < 128 and ord(c) > 0 for c in s)
-
-
-if PYTHON3:
- def is_string(s):
- return isinstance(s, str)
-
- def str_to_bytes(s):
- return s.encode(ENCODING)
-
- def bytes_to_str(s, errors='strict'):
- return s.decode(ENCODING, errors)
-
- unicode = str
-
- def write_str(f, msg):
- # Try outputting with the default encoding. If it fails,
- # try UTF-8.
- try:
- f.buffer.write(msg.encode(sys.getdefaultencoding()))
- except UnicodeEncodeError:
- f.buffer.write(msg.encode(ENCODING))
-
- def read_line(f):
- # Try reading with the default encoding. If it fails,
- # try UTF-8.
- out = f.buffer.readline()
- try:
- return out.decode(sys.getdefaultencoding())
- except UnicodeEncodeError:
- return out.decode(ENCODING)
-
- import html
-
- def html_escape(s):
- return html.escape(s)
-
-else:
- def is_string(s):
- try:
- return isinstance(s, basestring)
- except NameError: # Silence Pyflakes warning
- raise
-
- def str_to_bytes(s):
- return s
-
- def bytes_to_str(s, errors='strict'):
- return s
-
- def write_str(f, msg):
- f.write(msg)
-
- def read_line(f):
- return f.readline()
-
- def next(it):
- return it.next()
-
- import cgi
-
- def html_escape(s):
- return cgi.escape(s, True)
-
-try:
- from email.charset import Charset
- from email.utils import make_msgid
- from email.utils import getaddresses
- from email.utils import formataddr
- from email.utils import formatdate
- from email.header import Header
-except ImportError:
- # Prior to Python 2.5, the email module used different names:
- from email.Charset import Charset
- from email.Utils import make_msgid
- from email.Utils import getaddresses
- from email.Utils import formataddr
- from email.Utils import formatdate
- from email.Header import Header
-
-
-DEBUG = False
-
-ZEROS = '0' * 40
-LOGBEGIN = '- Log -----------------------------------------------------------------\n'
-LOGEND = '-----------------------------------------------------------------------\n'
-
-ADDR_HEADERS = set(['from', 'to', 'cc', 'bcc', 'reply-to', 'sender'])
-
-# It is assumed in many places that the encoding is uniformly UTF-8,
-# so changing these constants is unsupported. But define them here
-# anyway, to make it easier to find (at least most of) the places
-# where the encoding is important.
-(ENCODING, CHARSET) = ('UTF-8', 'utf-8')
-
-
-REF_CREATED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s created'
- ' (now %(newrev_short)s)'
- )
-REF_UPDATED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s updated'
- ' (%(oldrev_short)s -> %(newrev_short)s)'
- )
-REF_DELETED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s deleted'
- ' (was %(oldrev_short)s)'
- )
-
-COMBINED_REFCHANGE_REVISION_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s updated: %(oneline)s'
- )
-
-REFCHANGE_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Subject: %(subject)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-Message-ID: %(msgid)s
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-Thread-Index: %(thread_index)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Oldrev: %(oldrev)s
-X-Git-Newrev: %(newrev)s
-X-Git-NotificationType: ref_changed
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-REFCHANGE_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a change to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-
-FOOTER_TEMPLATE = """\
-
--- \n\
-To stop receiving notification emails like this one, please contact
-%(administrator)s.
-"""
-
-
-REWIND_ONLY_TEMPLATE = """\
-This update removed existing revisions from the reference, leaving the
-reference pointing at a previous point in the repository history.
-
- * -- * -- N %(refname)s (%(newrev_short)s)
- \\
- O -- O -- O (%(oldrev_short)s)
-
-Any revisions marked "omit" are not gone; other references still
-refer to them. Any revisions marked "discard" are gone forever.
-"""
-
-
-NON_FF_TEMPLATE = """\
-This update added new revisions after undoing existing revisions.
-That is to say, some revisions that were in the old version of the
-%(refname_type)s are not in the new version. This situation occurs
-when a user --force pushes a change and generates a repository
-containing something like this:
-
- * -- * -- B -- O -- O -- O (%(oldrev_short)s)
- \\
- N -- N -- N %(refname)s (%(newrev_short)s)
-
-You should already have received notification emails for all of the O
-revisions, and so the following emails describe only the N revisions
-from the common base, B.
-
-Any revisions marked "omit" are not gone; other references still
-refer to them. Any revisions marked "discard" are gone forever.
-"""
-
-
-NO_NEW_REVISIONS_TEMPLATE = """\
-No new revisions were added by this update.
-"""
-
-
-DISCARDED_REVISIONS_TEMPLATE = """\
-This change permanently discards the following revisions:
-"""
-
-
-NO_DISCARDED_REVISIONS_TEMPLATE = """\
-The revisions that were on this %(refname_type)s are still contained in
-other references; therefore, this change does not discard any commits
-from the repository.
-"""
-
-
-NEW_REVISIONS_TEMPLATE = """\
-The %(tot)s revisions listed above as "new" are entirely new to this
-repository and will be described in separate emails. The revisions
-listed as "add" were already present in the repository and have only
-been added to this reference.
-
-"""
-
-
-TAG_CREATED_TEMPLATE = """\
- at %(newrev_short)-8s (%(newrev_type)s)
-"""
-
-
-TAG_UPDATED_TEMPLATE = """\
-*** WARNING: tag %(short_refname)s was modified! ***
-
- from %(oldrev_short)-8s (%(oldrev_type)s)
- to %(newrev_short)-8s (%(newrev_type)s)
-"""
-
-
-TAG_DELETED_TEMPLATE = """\
-*** WARNING: tag %(short_refname)s was deleted! ***
-
-"""
-
-
-# The template used in summary tables. It looks best if this uses the
-# same alignment as TAG_CREATED_TEMPLATE and TAG_UPDATED_TEMPLATE.
-BRIEF_SUMMARY_TEMPLATE = """\
-%(action)8s %(rev_short)-8s %(text)s
-"""
-
-
-NON_COMMIT_UPDATE_TEMPLATE = """\
-This is an unusual reference change because the reference did not
-refer to a commit either before or after the change. We do not know
-how to provide full information about this reference change.
-"""
-
-
-REVISION_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Cc: %(cc_recipients)s
-Subject: %(emailprefix)s%(num)02d/%(tot)02d: %(oneline)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-In-Reply-To: %(reply_to_msgid)s
-References: %(reply_to_msgid)s
-Thread-Index: %(thread_index)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Rev: %(rev)s
-X-Git-NotificationType: diff
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-REVISION_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a commit to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-LINK_TEXT_TEMPLATE = """\
-View the commit online:
-%(browse_url)s
-
-"""
-
-LINK_HTML_TEMPLATE = """\
-<p><a href="%(browse_url)s">View the commit online</a>.</p>
-"""
-
-
-REVISION_FOOTER_TEMPLATE = FOOTER_TEMPLATE
-
-
-# Combined, meaning refchange+revision email (for single-commit additions)
-COMBINED_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Subject: %(subject)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-Message-ID: %(msgid)s
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Oldrev: %(oldrev)s
-X-Git-Newrev: %(newrev)s
-X-Git-Rev: %(rev)s
-X-Git-NotificationType: ref_changed_plus_diff
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-COMBINED_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a commit to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-COMBINED_FOOTER_TEMPLATE = FOOTER_TEMPLATE
-
-
-class CommandError(Exception):
- def __init__(self, cmd, retcode):
- self.cmd = cmd
- self.retcode = retcode
- Exception.__init__(
- self,
- 'Command "%s" failed with retcode %s' % (' '.join(cmd), retcode,)
- )
-
-
-class ConfigurationException(Exception):
- pass
-
-
-# The "git" program (this could be changed to include a full path):
-GIT_EXECUTABLE = 'git'
-
-
-# How "git" should be invoked (including global arguments), as a list
-# of words. This variable is usually initialized automatically by
-# read_git_output() via choose_git_command(), but if a value is set
-# here then it will be used unconditionally.
-GIT_CMD = None
-
-
-def choose_git_command():
- """Decide how to invoke git, and record the choice in GIT_CMD."""
-
- global GIT_CMD
-
- if GIT_CMD is None:
- try:
- # Check to see whether the "-c" option is accepted (it was
- # only added in Git 1.7.2). We don't actually use the
- # output of "git --version", though if we needed more
- # specific version information this would be the place to
- # do it.
- cmd = [GIT_EXECUTABLE, '-c', 'foo.bar=baz', '--version']
- read_output(cmd)
- GIT_CMD = [GIT_EXECUTABLE, '-c', 'i18n.logoutputencoding=%s' % (ENCODING,)]
- except CommandError:
- GIT_CMD = [GIT_EXECUTABLE]
-
-
-def read_git_output(args, input=None, keepends=False, **kw):
- """Read the output of a Git command."""
-
- if GIT_CMD is None:
- choose_git_command()
-
- return read_output(GIT_CMD + args, input=input, keepends=keepends, **kw)
-
-
-def read_output(cmd, input=None, keepends=False, **kw):
- if input:
- stdin = subprocess.PIPE
- input = str_to_bytes(input)
- else:
- stdin = None
- errors = 'strict'
- if 'errors' in kw:
- errors = kw['errors']
- del kw['errors']
- p = subprocess.Popen(
- tuple(str_to_bytes(w) for w in cmd),
- stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kw
- )
- (out, err) = p.communicate(input)
- out = bytes_to_str(out, errors=errors)
- retcode = p.wait()
- if retcode:
- raise CommandError(cmd, retcode)
- if not keepends:
- out = out.rstrip('\n\r')
- return out
-
-
-def read_git_lines(args, keepends=False, **kw):
- """Return the lines output by Git command.
-
- Return as single lines, with newlines stripped off."""
-
- return read_git_output(args, keepends=True, **kw).splitlines(keepends)
-
-
-def git_rev_list_ish(cmd, spec, args=None, **kw):
- """Common functionality for invoking a 'git rev-list'-like command.
-
- Parameters:
- * cmd is the Git command to run, e.g., 'rev-list' or 'log'.
- * spec is a list of revision arguments to pass to the named
- command. If None, this function returns an empty list.
- * args is a list of extra arguments passed to the named command.
- * All other keyword arguments (if any) are passed to the
- underlying read_git_lines() function.
-
- Return the output of the Git command in the form of a list, one
- entry per output line.
- """
- if spec is None:
- return []
- if args is None:
- args = []
- args = [cmd, '--stdin'] + args
- spec_stdin = ''.join(s + '\n' for s in spec)
- return read_git_lines(args, input=spec_stdin, **kw)
-
-
-def git_rev_list(spec, **kw):
- """Run 'git rev-list' with the given list of revision arguments.
-
- See git_rev_list_ish() for parameter and return value
- documentation.
- """
- return git_rev_list_ish('rev-list', spec, **kw)
-
-
-def git_log(spec, **kw):
- """Run 'git log' with the given list of revision arguments.
-
- See git_rev_list_ish() for parameter and return value
- documentation.
- """
- return git_rev_list_ish('log', spec, **kw)
-
-
-def header_encode(text, header_name=None):
- """Encode and line-wrap the value of an email header field."""
-
- # Convert to unicode, if required.
- if not isinstance(text, unicode):
- text = unicode(text, 'utf-8')
-
- if is_ascii(text):
- charset = 'ascii'
- else:
- charset = 'utf-8'
-
- return Header(text, header_name=header_name, charset=Charset(charset)).encode()
-
-
-def addr_header_encode(text, header_name=None):
- """Encode and line-wrap the value of an email header field containing
- email addresses."""
-
- # Convert to unicode, if required.
- if not isinstance(text, unicode):
- text = unicode(text, 'utf-8')
-
- text = ', '.join(
- formataddr((header_encode(name), emailaddr))
- for name, emailaddr in getaddresses([text])
- )
-
- if is_ascii(text):
- charset = 'ascii'
- else:
- charset = 'utf-8'
-
- return Header(text, header_name=header_name, charset=Charset(charset)).encode()
-
-
-class Config(object):
- def __init__(self, section, git_config=None):
- """Represent a section of the git configuration.
-
- If git_config is specified, it is passed to "git config" in
- the GIT_CONFIG environment variable, meaning that "git config"
- will read the specified path rather than the Git default
- config paths."""
-
- self.section = section
- if git_config:
- self.env = os.environ.copy()
- self.env['GIT_CONFIG'] = git_config
- else:
- self.env = None
-
- @staticmethod
- def _split(s):
- """Split NUL-terminated values."""
-
- words = s.split('\0')
- assert words[-1] == ''
- return words[:-1]
-
- @staticmethod
- def add_config_parameters(c):
- """Add configuration parameters to Git.
-
- c is either an str or a list of str, each element being of the
- form 'var=val' or 'var', with the same syntax and meaning as
- the argument of 'git -c var=val'.
- """
- if isinstance(c, str):
- c = (c,)
- parameters = os.environ.get('GIT_CONFIG_PARAMETERS', '')
- if parameters:
- parameters += ' '
- # git expects GIT_CONFIG_PARAMETERS to be of the form
- # "'name1=value1' 'name2=value2' 'name3=value3'"
- # including everything inside the double quotes (but not the double
- # quotes themselves). Spacing is critical. Also, if a value contains
- # a literal single quote that quote must be represented using the
- # four character sequence: '\''
- parameters += ' '.join("'" + x.replace("'", "'\\''") + "'" for x in c)
- os.environ['GIT_CONFIG_PARAMETERS'] = parameters
-
- def get(self, name, default=None):
- try:
- values = self._split(read_git_output(
- ['config', '--get', '--null', '%s.%s' % (self.section, name)],
- env=self.env, keepends=True,
- ))
- assert len(values) == 1
- return values[0]
- except CommandError:
- return default
-
- def get_bool(self, name, default=None):
- try:
- value = read_git_output(
- ['config', '--get', '--bool', '%s.%s' % (self.section, name)],
- env=self.env,
- )
- except CommandError:
- return default
- return value == 'true'
-
- def get_all(self, name, default=None):
- """Read a (possibly multivalued) setting from the configuration.
-
- Return the result as a list of values, or default if the name
- is unset."""
-
- try:
- return self._split(read_git_output(
- ['config', '--get-all', '--null', '%s.%s' % (self.section, name)],
- env=self.env, keepends=True,
- ))
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 1:
- # "the section or key is invalid"; i.e., there is no
- # value for the specified key.
- return default
- else:
- raise
-
- def set(self, name, value):
- read_git_output(
- ['config', '%s.%s' % (self.section, name), value],
- env=self.env,
- )
-
- def add(self, name, value):
- read_git_output(
- ['config', '--add', '%s.%s' % (self.section, name), value],
- env=self.env,
- )
-
- def __contains__(self, name):
- return self.get_all(name, default=None) is not None
-
- # We don't use this method anymore internally, but keep it here in
- # case somebody is calling it from their own code:
- def has_key(self, name):
- return name in self
-
- def unset_all(self, name):
- try:
- read_git_output(
- ['config', '--unset-all', '%s.%s' % (self.section, name)],
- env=self.env,
- )
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 5:
- # The name doesn't exist, which is what we wanted anyway...
- pass
- else:
- raise
-
- def set_recipients(self, name, value):
- self.unset_all(name)
- for pair in getaddresses([value]):
- self.add(name, formataddr(pair))
-
-
-def generate_summaries(*log_args):
- """Generate a brief summary for each revision requested.
-
- log_args are strings that will be passed directly to "git log" as
- revision selectors. Iterate over (sha1_short, subject) for each
- commit specified by log_args (subject is the first line of the
- commit message as a string without EOLs)."""
-
- cmd = [
- 'log', '--abbrev', '--format=%h %s',
- ] + list(log_args) + ['--']
- for line in read_git_lines(cmd):
- yield tuple(line.split(' ', 1))
-
-
-def limit_lines(lines, max_lines):
- for (index, line) in enumerate(lines):
- if index < max_lines:
- yield line
-
- if index >= max_lines:
- yield '... %d lines suppressed ...\n' % (index + 1 - max_lines,)
-
-
-def limit_linelength(lines, max_linelength):
- for line in lines:
- # Don't forget that lines always include a trailing newline.
- if len(line) > max_linelength + 1:
- line = line[:max_linelength - 7] + ' [...]\n'
- yield line
-
-
-class CommitSet(object):
- """A (constant) set of object names.
-
- The set should be initialized with full SHA1 object names. The
- __contains__() method returns True iff its argument is an
- abbreviation of any the names in the set."""
-
- def __init__(self, names):
- self._names = sorted(names)
-
- def __len__(self):
- return len(self._names)
-
- def __contains__(self, sha1_abbrev):
- """Return True iff this set contains sha1_abbrev (which might be abbreviated)."""
-
- i = bisect.bisect_left(self._names, sha1_abbrev)
- return i < len(self) and self._names[i].startswith(sha1_abbrev)
-
-
-class GitObject(object):
- def __init__(self, sha1, type=None):
- if sha1 == ZEROS:
- self.sha1 = self.type = self.commit_sha1 = None
- else:
- self.sha1 = sha1
- self.type = type or read_git_output(['cat-file', '-t', self.sha1])
-
- if self.type == 'commit':
- self.commit_sha1 = self.sha1
- elif self.type == 'tag':
- try:
- self.commit_sha1 = read_git_output(
- ['rev-parse', '--verify', '%s^0' % (self.sha1,)]
- )
- except CommandError:
- # Cannot deref tag to determine commit_sha1
- self.commit_sha1 = None
- else:
- self.commit_sha1 = None
-
- self.short = read_git_output(['rev-parse', '--short', sha1])
-
- def get_summary(self):
- """Return (sha1_short, subject) for this commit."""
-
- if not self.sha1:
- raise ValueError('Empty commit has no summary')
-
- return next(iter(generate_summaries('--no-walk', self.sha1)))
-
- def __eq__(self, other):
- return isinstance(other, GitObject) and self.sha1 == other.sha1
-
- def __ne__(self, other):
- return not self == other
-
- def __hash__(self):
- return hash(self.sha1)
-
- def __nonzero__(self):
- return bool(self.sha1)
-
- def __bool__(self):
- """Python 2 backward compatibility"""
- return self.__nonzero__()
-
- def __str__(self):
- return self.sha1 or ZEROS
-
-
-class Change(object):
- """A Change that has been made to the Git repository.
-
- Abstract class from which both Revisions and ReferenceChanges are
- derived. A Change knows how to generate a notification email
- describing itself."""
-
- def __init__(self, environment):
- self.environment = environment
- self._values = None
- self._contains_html_diff = False
-
- def _contains_diff(self):
- # We do contain a diff, should it be rendered in HTML?
- if self.environment.commit_email_format == "html":
- self._contains_html_diff = True
-
- def _compute_values(self):
- """Return a dictionary {keyword: expansion} for this Change.
-
- Derived classes overload this method to add more entries to
- the return value. This method is used internally by
- get_values(). The return value should always be a new
- dictionary."""
-
- values = self.environment.get_values()
- fromaddr = self.environment.get_fromaddr(change=self)
- if fromaddr is not None:
- values['fromaddr'] = fromaddr
- values['multimail_version'] = get_version()
- return values
-
- # Aliases usable in template strings. Tuple of pairs (destination,
- # source).
- VALUES_ALIAS = (
- ("id", "newrev"),
- )
-
- def get_values(self, **extra_values):
- """Return a dictionary {keyword: expansion} for this Change.
-
- Return a dictionary mapping keywords to the values that they
- should be expanded to for this Change (used when interpolating
- template strings). If any keyword arguments are supplied, add
- those to the return value as well. The return value is always
- a new dictionary."""
-
- if self._values is None:
- self._values = self._compute_values()
-
- values = self._values.copy()
- if extra_values:
- values.update(extra_values)
-
- for alias, val in self.VALUES_ALIAS:
- values[alias] = values[val]
- return values
-
- def expand(self, template, **extra_values):
- """Expand template.
-
- Expand the template (which should be a string) using string
- interpolation of the values for this Change. If any keyword
- arguments are provided, also include those in the keywords
- available for interpolation."""
-
- return template % self.get_values(**extra_values)
-
- def expand_lines(self, template, html_escape_val=False, **extra_values):
- """Break template into lines and expand each line."""
-
- values = self.get_values(**extra_values)
- if html_escape_val:
- for k in values:
- if is_string(values[k]):
- values[k] = html_escape(values[k])
- for line in template.splitlines(True):
- yield line % values
-
- def expand_header_lines(self, template, **extra_values):
- """Break template into lines and expand each line as an RFC 2822 header.
-
- Encode values and split up lines that are too long. Silently
- skip lines that contain references to unknown variables."""
-
- values = self.get_values(**extra_values)
- if self._contains_html_diff:
- self._content_type = 'html'
- else:
- self._content_type = 'plain'
- values['contenttype'] = self._content_type
-
- for line in template.splitlines():
- (name, value) = line.split(': ', 1)
-
- try:
- value = value % values
- except KeyError:
- t, e, traceback = sys.exc_info()
- if DEBUG:
- self.environment.log_warning(
- 'Warning: unknown variable %r in the following line; line skipped:\n'
- ' %s\n'
- % (e.args[0], line,)
- )
- else:
- if name.lower() in ADDR_HEADERS:
- value = addr_header_encode(value, name)
- else:
- value = header_encode(value, name)
- for splitline in ('%s: %s\n' % (name, value)).splitlines(True):
- yield splitline
-
- def generate_email_header(self):
- """Generate the RFC 2822 email headers for this Change, a line at a time.
-
- The output should not include the trailing blank line."""
-
- raise NotImplementedError()
-
- def generate_browse_link(self, base_url):
- """Generate a link to an online repository browser."""
- return iter(())
-
- def generate_email_intro(self, html_escape_val=False):
- """Generate the email intro for this Change, a line at a time.
-
- The output will be used as the standard boilerplate at the top
- of the email body."""
-
- raise NotImplementedError()
-
- def generate_email_body(self, push):
- """Generate the main part of the email body, a line at a time.
-
- The text in the body might be truncated after a specified
- number of lines (see multimailhook.emailmaxlines)."""
-
- raise NotImplementedError()
-
- def generate_email_footer(self, html_escape_val):
- """Generate the footer of the email, a line at a time.
-
- The footer is always included, irrespective of
- multimailhook.emailmaxlines."""
-
- raise NotImplementedError()
-
- def _wrap_for_html(self, lines):
- """Wrap the lines in HTML <pre> tag when using HTML format.
-
- Escape special HTML characters and add <pre> and </pre> tags around
- the given lines if we should be generating HTML as indicated by
- self._contains_html_diff being set to true.
- """
- if self._contains_html_diff:
- yield "<pre style='margin:0'>\n"
-
- for line in lines:
- yield html_escape(line)
-
- yield '</pre>\n'
- else:
- for line in lines:
- yield line
-
- def generate_email(self, push, body_filter=None, extra_header_values={}):
- """Generate an email describing this change.
-
- Iterate over the lines (including the header lines) of an
- email describing this change. If body_filter is not None,
- then use it to filter the lines that are intended for the
- email body.
-
- The extra_header_values field is received as a dict and not as
- **kwargs, to allow passing other keyword arguments in the
- future (e.g. passing extra values to generate_email_intro()"""
-
- for line in self.generate_email_header(**extra_header_values):
- yield line
- yield '\n'
- html_escape_val = (self.environment.html_in_intro and
- self._contains_html_diff)
- intro = self.generate_email_intro(html_escape_val)
- if not self.environment.html_in_intro:
- intro = self._wrap_for_html(intro)
- for line in intro:
- yield line
-
- if self.environment.commitBrowseURL:
- for line in self.generate_browse_link(self.environment.commitBrowseURL):
- yield line
-
- body = self.generate_email_body(push)
- if body_filter is not None:
- body = body_filter(body)
-
- diff_started = False
- if self._contains_html_diff:
- # "white-space: pre" is the default, but we need to
- # specify it again in case the message is viewed in a
- # webmail which wraps it in an element setting white-space
- # to something else (Zimbra does this and sets
- # white-space: pre-line).
- yield '<pre style="white-space: pre; background: #F8F8F8">'
- for line in body:
- if self._contains_html_diff:
- # This is very, very naive. It would be much better to really
- # parse the diff, i.e. look at how many lines do we have in
- # the hunk headers instead of blindly highlighting everything
- # that looks like it might be part of a diff.
- bgcolor = ''
- fgcolor = ''
- if line.startswith('--- a/'):
- diff_started = True
- bgcolor = 'e0e0ff'
- elif line.startswith('diff ') or line.startswith('index '):
- diff_started = True
- fgcolor = '808080'
- elif diff_started:
- if line.startswith('+++ '):
- bgcolor = 'e0e0ff'
- elif line.startswith('@@'):
- bgcolor = 'e0e0e0'
- elif line.startswith('+'):
- bgcolor = 'e0ffe0'
- elif line.startswith('-'):
- bgcolor = 'ffe0e0'
- elif line.startswith('commit '):
- fgcolor = '808000'
- elif line.startswith(' '):
- fgcolor = '404040'
-
- # Chop the trailing LF, we don't want it inside <pre>.
- line = html_escape(line[:-1])
-
- if bgcolor or fgcolor:
- style = 'display:block; white-space:pre;'
- if bgcolor:
- style += 'background:#' + bgcolor + ';'
- if fgcolor:
- style += 'color:#' + fgcolor + ';'
- # Use a <span style='display:block> to color the
- # whole line. The newline must be inside the span
- # to display properly both in Firefox and in
- # text-based browser.
- line = "<span style='%s'>%s\n</span>" % (style, line)
- else:
- line = line + '\n'
-
- yield line
- if self._contains_html_diff:
- yield '</pre>'
- html_escape_val = (self.environment.html_in_footer and
- self._contains_html_diff)
- footer = self.generate_email_footer(html_escape_val)
- if not self.environment.html_in_footer:
- footer = self._wrap_for_html(footer)
- for line in footer:
- yield line
-
- def get_specific_fromaddr(self):
- """For kinds of Changes which specify it, return the kind-specific
- From address to use."""
- return None
-
-
-class Revision(Change):
- """A Change consisting of a single git commit."""
-
- CC_RE = re.compile(r'^\s*C[Cc]:\s*(?P<to>[^#]+@[^\s#]*)\s*(#.*)?$')
-
- def __init__(self, reference_change, rev, num, tot):
- Change.__init__(self, reference_change.environment)
- self.reference_change = reference_change
- self.rev = rev
- self.change_type = self.reference_change.change_type
- self.refname = self.reference_change.refname
- self.num = num
- self.tot = tot
- self.author = read_git_output(['log', '--no-walk', '--format=%aN <%aE>', self.rev.sha1])
- self.recipients = self.environment.get_revision_recipients(self)
-
- # -s is short for --no-patch, but -s works on older git's (e.g. 1.7)
- self.parents = read_git_lines(['show', '-s', '--format=%P',
- self.rev.sha1])[0].split()
-
- self.cc_recipients = ''
- if self.environment.get_scancommitforcc():
- self.cc_recipients = ', '.join(to.strip() for to in self._cc_recipients())
- if self.cc_recipients:
- self.environment.log_msg(
- 'Add %s to CC for %s' % (self.cc_recipients, self.rev.sha1))
-
- def _cc_recipients(self):
- cc_recipients = []
- message = read_git_output(['log', '--no-walk', '--format=%b', self.rev.sha1])
- lines = message.strip().split('\n')
- for line in lines:
- m = re.match(self.CC_RE, line)
- if m:
- cc_recipients.append(m.group('to'))
-
- return cc_recipients
-
- def _compute_values(self):
- values = Change._compute_values(self)
-
- oneline = read_git_output(
- ['log', '--format=%s', '--no-walk', self.rev.sha1]
- )
-
- max_subject_length = self.environment.get_max_subject_length()
- if max_subject_length > 0 and len(oneline) > max_subject_length:
- oneline = oneline[:max_subject_length - 6] + ' [...]'
-
- values['rev'] = self.rev.sha1
- values['parents'] = ' '.join(self.parents)
- values['rev_short'] = self.rev.short
- values['change_type'] = self.change_type
- values['refname'] = self.refname
- values['newrev'] = self.rev.sha1
- values['short_refname'] = self.reference_change.short_refname
- values['refname_type'] = self.reference_change.refname_type
- values['reply_to_msgid'] = self.reference_change.msgid
- values['thread_index'] = self.reference_change.thread_index
- values['num'] = self.num
- values['tot'] = self.tot
- values['recipients'] = self.recipients
- if self.cc_recipients:
- values['cc_recipients'] = self.cc_recipients
- values['oneline'] = oneline
- values['author'] = self.author
-
- reply_to = self.environment.get_reply_to_commit(self)
- if reply_to:
- values['reply_to'] = reply_to
-
- return values
-
- def generate_email_header(self, **extra_values):
- for line in self.expand_header_lines(
- REVISION_HEADER_TEMPLATE, **extra_values
- ):
- yield line
-
- def generate_browse_link(self, base_url):
- if '%(' not in base_url:
- base_url += '%(id)s'
- url = "".join(self.expand_lines(base_url))
- if self._content_type == 'html':
- for line in self.expand_lines(LINK_HTML_TEMPLATE,
- html_escape_val=True,
- browse_url=url):
- yield line
- elif self._content_type == 'plain':
- for line in self.expand_lines(LINK_TEXT_TEMPLATE,
- html_escape_val=False,
- browse_url=url):
- yield line
- else:
- raise NotImplementedError("Content-type %s unsupported. Please report it as a bug.")
-
- def generate_email_intro(self, html_escape_val=False):
- for line in self.expand_lines(REVISION_INTRO_TEMPLATE,
- html_escape_val=html_escape_val):
- yield line
-
- def generate_email_body(self, push):
- """Show this revision."""
-
- for line in read_git_lines(
- ['log'] + self.environment.commitlogopts + ['-1', self.rev.sha1],
- keepends=True,
- errors='replace'):
- if line.startswith('Date: ') and self.environment.date_substitute:
- yield self.environment.date_substitute + line[len('Date: '):]
- else:
- yield line
-
- def generate_email_footer(self, html_escape_val):
- return self.expand_lines(REVISION_FOOTER_TEMPLATE,
- html_escape_val=html_escape_val)
-
- def generate_email(self, push, body_filter=None, extra_header_values={}):
- self._contains_diff()
- return Change.generate_email(self, push, body_filter, extra_header_values)
-
- def get_specific_fromaddr(self):
- return self.environment.from_commit
-
-
-class ReferenceChange(Change):
- """A Change to a Git reference.
-
- An abstract class representing a create, update, or delete of a
- Git reference. Derived classes handle specific types of reference
- (e.g., tags vs. branches). These classes generate the main
- reference change email summarizing the reference change and
- whether it caused any any commits to be added or removed.
-
- ReferenceChange objects are usually created using the static
- create() method, which has the logic to decide which derived class
- to instantiate."""
-
- REF_RE = re.compile(r'^refs\/(?P<area>[^\/]+)\/(?P<shortname>.*)$')
-
- @staticmethod
- def create(environment, oldrev, newrev, refname):
- """Return a ReferenceChange object representing the change.
-
- Return an object that represents the type of change that is being
- made. oldrev and newrev should be SHA1s or ZEROS."""
-
- old = GitObject(oldrev)
- new = GitObject(newrev)
- rev = new or old
-
- # The revision type tells us what type the commit is, combined with
- # the location of the ref we can decide between
- # - working branch
- # - tracking branch
- # - unannotated tag
- # - annotated tag
- m = ReferenceChange.REF_RE.match(refname)
- if m:
- area = m.group('area')
- short_refname = m.group('shortname')
- else:
- area = ''
- short_refname = refname
-
- if rev.type == 'tag':
- # Annotated tag:
- klass = AnnotatedTagChange
- elif rev.type == 'commit':
- if area == 'tags':
- # Non-annotated tag:
- klass = NonAnnotatedTagChange
- elif area == 'heads':
- # Branch:
- klass = BranchChange
- elif area == 'remotes':
- # Tracking branch:
- environment.log_warning(
- '*** Push-update of tracking branch %r\n'
- '*** - incomplete email generated.'
- % (refname,)
- )
- klass = OtherReferenceChange
- else:
- # Some other reference namespace:
- environment.log_warning(
- '*** Push-update of strange reference %r\n'
- '*** - incomplete email generated.'
- % (refname,)
- )
- klass = OtherReferenceChange
- else:
- # Anything else (is there anything else?)
- environment.log_warning(
- '*** Unknown type of update to %r (%s)\n'
- '*** - incomplete email generated.'
- % (refname, rev.type,)
- )
- klass = OtherReferenceChange
-
- return klass(
- environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
-
- @staticmethod
- def make_thread_index():
- """Return a string appropriate for the Thread-Index header,
- needed by MS Outlook to get threading right.
-
- The format is (base64-encoded):
- - 1 byte must be 1
- - 5 bytes encode a date (hardcoded here)
- - 16 bytes for a globally unique identifier
-
- FIXME: Unfortunately, even with the Thread-Index field, MS
- Outlook doesn't seem to do the threading reliably (see
- https://github.com/git-multimail/git-multimail/pull/194).
- """
- thread_index = b'\x01\x00\x00\x12\x34\x56' + uuid.uuid4().bytes
- return base64.standard_b64encode(thread_index).decode('ascii')
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- Change.__init__(self, environment)
- self.change_type = {
- (False, True): 'create',
- (True, True): 'update',
- (True, False): 'delete',
- }[bool(old), bool(new)]
- self.refname = refname
- self.short_refname = short_refname
- self.old = old
- self.new = new
- self.rev = rev
- self.msgid = make_msgid()
- self.thread_index = self.make_thread_index()
- self.diffopts = environment.diffopts
- self.graphopts = environment.graphopts
- self.logopts = environment.logopts
- self.commitlogopts = environment.commitlogopts
- self.showgraph = environment.refchange_showgraph
- self.showlog = environment.refchange_showlog
-
- self.header_template = REFCHANGE_HEADER_TEMPLATE
- self.intro_template = REFCHANGE_INTRO_TEMPLATE
- self.footer_template = FOOTER_TEMPLATE
-
- def _compute_values(self):
- values = Change._compute_values(self)
-
- values['change_type'] = self.change_type
- values['refname_type'] = self.refname_type
- values['refname'] = self.refname
- values['short_refname'] = self.short_refname
- values['msgid'] = self.msgid
- values['thread_index'] = self.thread_index
- values['recipients'] = self.recipients
- values['oldrev'] = str(self.old)
- values['oldrev_short'] = self.old.short
- values['newrev'] = str(self.new)
- values['newrev_short'] = self.new.short
-
- if self.old:
- values['oldrev_type'] = self.old.type
- if self.new:
- values['newrev_type'] = self.new.type
-
- reply_to = self.environment.get_reply_to_refchange(self)
- if reply_to:
- values['reply_to'] = reply_to
-
- return values
-
- def send_single_combined_email(self, known_added_sha1s):
- """Determine if a combined refchange/revision email should be sent
-
- If there is only a single new (non-merge) commit added by a
- change, it is useful to combine the ReferenceChange and
- Revision emails into one. In such a case, return the single
- revision; otherwise, return None.
-
- This method is overridden in BranchChange."""
-
- return None
-
- def generate_combined_email(self, push, revision, body_filter=None, extra_header_values={}):
- """Generate an email describing this change AND specified revision.
-
- Iterate over the lines (including the header lines) of an
- email describing this change. If body_filter is not None,
- then use it to filter the lines that are intended for the
- email body.
-
- The extra_header_values field is received as a dict and not as
- **kwargs, to allow passing other keyword arguments in the
- future (e.g. passing extra values to generate_email_intro()
-
- This method is overridden in BranchChange."""
-
- raise NotImplementedError
-
- def get_subject(self):
- template = {
- 'create': REF_CREATED_SUBJECT_TEMPLATE,
- 'update': REF_UPDATED_SUBJECT_TEMPLATE,
- 'delete': REF_DELETED_SUBJECT_TEMPLATE,
- }[self.change_type]
- return self.expand(template)
-
- def generate_email_header(self, **extra_values):
- if 'subject' not in extra_values:
- extra_values['subject'] = self.get_subject()
-
- for line in self.expand_header_lines(
- self.header_template, **extra_values
- ):
- yield line
-
- def generate_email_intro(self, html_escape_val=False):
- for line in self.expand_lines(self.intro_template,
- html_escape_val=html_escape_val):
- yield line
-
- def generate_email_body(self, push):
- """Call the appropriate body-generation routine.
-
- Call one of generate_create_summary() /
- generate_update_summary() / generate_delete_summary()."""
-
- change_summary = {
- 'create': self.generate_create_summary,
- 'delete': self.generate_delete_summary,
- 'update': self.generate_update_summary,
- }[self.change_type](push)
- for line in change_summary:
- yield line
-
- for line in self.generate_revision_change_summary(push):
- yield line
-
- def generate_email_footer(self, html_escape_val):
- return self.expand_lines(self.footer_template,
- html_escape_val=html_escape_val)
-
- def generate_revision_change_graph(self, push):
- if self.showgraph:
- args = ['--graph'] + self.graphopts
- for newold in ('new', 'old'):
- has_newold = False
- spec = push.get_commits_spec(newold, self)
- for line in git_log(spec, args=args, keepends=True):
- if not has_newold:
- has_newold = True
- yield '\n'
- yield 'Graph of %s commits:\n\n' % (
- {'new': 'new', 'old': 'discarded'}[newold],)
- yield ' ' + line
- if has_newold:
- yield '\n'
-
- def generate_revision_change_log(self, new_commits_list):
- if self.showlog:
- yield '\n'
- yield 'Detailed log of new commits:\n\n'
- for line in read_git_lines(
- ['log', '--no-walk'] +
- self.logopts +
- new_commits_list +
- ['--'],
- keepends=True,
- ):
- yield line
-
- def generate_new_revision_summary(self, tot, new_commits_list, push):
- for line in self.expand_lines(NEW_REVISIONS_TEMPLATE, tot=tot):
- yield line
- for line in self.generate_revision_change_graph(push):
- yield line
- for line in self.generate_revision_change_log(new_commits_list):
- yield line
-
- def generate_revision_change_summary(self, push):
- """Generate a summary of the revisions added/removed by this change."""
-
- if self.new.commit_sha1 and not self.old.commit_sha1:
- # A new reference was created. List the new revisions
- # brought by the new reference (i.e., those revisions that
- # were not in the repository before this reference
- # change).
- sha1s = list(push.get_new_commits(self))
- sha1s.reverse()
- tot = len(sha1s)
- new_revisions = [
- Revision(self, GitObject(sha1), num=i + 1, tot=tot)
- for (i, sha1) in enumerate(sha1s)
- ]
-
- if new_revisions:
- yield self.expand('This %(refname_type)s includes the following new commits:\n')
- yield '\n'
- for r in new_revisions:
- (sha1, subject) = r.rev.get_summary()
- yield r.expand(
- BRIEF_SUMMARY_TEMPLATE, action='new', text=subject,
- )
- yield '\n'
- for line in self.generate_new_revision_summary(
- tot, [r.rev.sha1 for r in new_revisions], push):
- yield line
- else:
- for line in self.expand_lines(NO_NEW_REVISIONS_TEMPLATE):
- yield line
-
- elif self.new.commit_sha1 and self.old.commit_sha1:
- # A reference was changed to point at a different commit.
- # List the revisions that were removed and/or added *from
- # that reference* by this reference change, along with a
- # diff between the trees for its old and new values.
-
- # List of the revisions that were added to the branch by
- # this update. Note this list can include revisions that
- # have already had notification emails; we want such
- # revisions in the summary even though we will not send
- # new notification emails for them.
- adds = list(generate_summaries(
- '--topo-order', '--reverse', '%s..%s'
- % (self.old.commit_sha1, self.new.commit_sha1,)
- ))
-
- # List of the revisions that were removed from the branch
- # by this update. This will be empty except for
- # non-fast-forward updates.
- discards = list(generate_summaries(
- '%s..%s' % (self.new.commit_sha1, self.old.commit_sha1,)
- ))
-
- if adds:
- new_commits_list = push.get_new_commits(self)
- else:
- new_commits_list = []
- new_commits = CommitSet(new_commits_list)
-
- if discards:
- discarded_commits = CommitSet(push.get_discarded_commits(self))
- else:
- discarded_commits = CommitSet([])
-
- if discards and adds:
- for (sha1, subject) in discards:
- if sha1 in discarded_commits:
- action = 'discard'
- else:
- action = 'omit'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- for (sha1, subject) in adds:
- if sha1 in new_commits:
- action = 'new'
- else:
- action = 'add'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- yield '\n'
- for line in self.expand_lines(NON_FF_TEMPLATE):
- yield line
-
- elif discards:
- for (sha1, subject) in discards:
- if sha1 in discarded_commits:
- action = 'discard'
- else:
- action = 'omit'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- yield '\n'
- for line in self.expand_lines(REWIND_ONLY_TEMPLATE):
- yield line
-
- elif adds:
- (sha1, subject) = self.old.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='from',
- rev_short=sha1, text=subject,
- )
- for (sha1, subject) in adds:
- if sha1 in new_commits:
- action = 'new'
- else:
- action = 'add'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
-
- yield '\n'
-
- if new_commits:
- for line in self.generate_new_revision_summary(
- len(new_commits), new_commits_list, push):
- yield line
- else:
- for line in self.expand_lines(NO_NEW_REVISIONS_TEMPLATE):
- yield line
- for line in self.generate_revision_change_graph(push):
- yield line
-
- # The diffstat is shown from the old revision to the new
- # revision. This is to show the truth of what happened in
- # this change. There's no point showing the stat from the
- # base to the new revision because the base is effectively a
- # random revision at this point - the user will be interested
- # in what this revision changed - including the undoing of
- # previous revisions in the case of non-fast-forward updates.
- yield '\n'
- yield 'Summary of changes:\n'
- for line in read_git_lines(
- ['diff-tree'] +
- self.diffopts +
- ['%s..%s' % (self.old.commit_sha1, self.new.commit_sha1,)],
- keepends=True,
- ):
- yield line
-
- elif self.old.commit_sha1 and not self.new.commit_sha1:
- # A reference was deleted. List the revisions that were
- # removed from the repository by this reference change.
-
- sha1s = list(push.get_discarded_commits(self))
- tot = len(sha1s)
- discarded_revisions = [
- Revision(self, GitObject(sha1), num=i + 1, tot=tot)
- for (i, sha1) in enumerate(sha1s)
- ]
-
- if discarded_revisions:
- for line in self.expand_lines(DISCARDED_REVISIONS_TEMPLATE):
- yield line
- yield '\n'
- for r in discarded_revisions:
- (sha1, subject) = r.rev.get_summary()
- yield r.expand(
- BRIEF_SUMMARY_TEMPLATE, action='discard', text=subject,
- )
- for line in self.generate_revision_change_graph(push):
- yield line
- else:
- for line in self.expand_lines(NO_DISCARDED_REVISIONS_TEMPLATE):
- yield line
-
- elif not self.old.commit_sha1 and not self.new.commit_sha1:
- for line in self.expand_lines(NON_COMMIT_UPDATE_TEMPLATE):
- yield line
-
- def generate_create_summary(self, push):
- """Called for the creation of a reference."""
-
- # This is a new reference and so oldrev is not valid
- (sha1, subject) = self.new.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='at',
- rev_short=sha1, text=subject,
- )
- yield '\n'
-
- def generate_update_summary(self, push):
- """Called for the change of a pre-existing branch."""
-
- return iter([])
-
- def generate_delete_summary(self, push):
- """Called for the deletion of any type of reference."""
-
- (sha1, subject) = self.old.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='was',
- rev_short=sha1, text=subject,
- )
- yield '\n'
-
- def get_specific_fromaddr(self):
- return self.environment.from_refchange
-
-
-class BranchChange(ReferenceChange):
- refname_type = 'branch'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
- self._single_revision = None
-
- def send_single_combined_email(self, known_added_sha1s):
- if not self.environment.combine_when_single_commit:
- return None
-
- # In the sadly-all-too-frequent usecase of people pushing only
- # one of their commits at a time to a repository, users feel
- # the reference change summary emails are noise rather than
- # important signal. This is because, in this particular
- # usecase, there is a reference change summary email for each
- # new commit, and all these summaries do is point out that
- # there is one new commit (which can readily be inferred by
- # the existence of the individual revision email that is also
- # sent). In such cases, our users prefer there to be a combined
- # reference change summary/new revision email.
- #
- # So, if the change is an update and it doesn't discard any
- # commits, and it adds exactly one non-merge commit (gerrit
- # forces a workflow where every commit is individually merged
- # and the git-multimail hook fired off for just this one
- # change), then we send a combined refchange/revision email.
- try:
- # If this change is a reference update that doesn't discard
- # any commits...
- if self.change_type != 'update':
- return None
-
- if read_git_lines(
- ['merge-base', self.old.sha1, self.new.sha1]
- ) != [self.old.sha1]:
- return None
-
- # Check if this update introduced exactly one non-merge
- # commit:
-
- def split_line(line):
- """Split line into (sha1, [parent,...])."""
-
- words = line.split()
- return (words[0], words[1:])
-
- # Get the new commits introduced by the push as a list of
- # (sha1, [parent,...])
- new_commits = [
- split_line(line)
- for line in read_git_lines(
- [
- 'log', '-3', '--format=%H %P',
- '%s..%s' % (self.old.sha1, self.new.sha1),
- ]
- )
- ]
-
- if not new_commits:
- return None
-
- # If the newest commit is a merge, save it for a later check
- # but otherwise ignore it
- merge = None
- tot = len(new_commits)
- if len(new_commits[0][1]) > 1:
- merge = new_commits[0][0]
- del new_commits[0]
-
- # Our primary check: we can't combine if more than one commit
- # is introduced. We also currently only combine if the new
- # commit is a non-merge commit, though it may make sense to
- # combine if it is a merge as well.
- if not (
- len(new_commits) == 1 and
- len(new_commits[0][1]) == 1 and
- new_commits[0][0] in known_added_sha1s
- ):
- return None
-
- # We do not want to combine revision and refchange emails if
- # those go to separate locations.
- rev = Revision(self, GitObject(new_commits[0][0]), 1, tot)
- if rev.recipients != self.recipients:
- return None
-
- # We ignored the newest commit if it was just a merge of the one
- # commit being introduced. But we don't want to ignore that
- # merge commit it it involved conflict resolutions. Check that.
- if merge and merge != read_git_output(['diff-tree', '--cc', merge]):
- return None
-
- # We can combine the refchange and one new revision emails
- # into one. Return the Revision that a combined email should
- # be sent about.
- return rev
- except CommandError:
- # Cannot determine number of commits in old..new or new..old;
- # don't combine reference/revision emails:
- return None
-
- def generate_combined_email(self, push, revision, body_filter=None, extra_header_values={}):
- values = revision.get_values()
- if extra_header_values:
- values.update(extra_header_values)
- if 'subject' not in extra_header_values:
- values['subject'] = self.expand(COMBINED_REFCHANGE_REVISION_SUBJECT_TEMPLATE, **values)
-
- self._single_revision = revision
- self._contains_diff()
- self.header_template = COMBINED_HEADER_TEMPLATE
- self.intro_template = COMBINED_INTRO_TEMPLATE
- self.footer_template = COMBINED_FOOTER_TEMPLATE
-
- def revision_gen_link(base_url):
- # revision is used only to generate the body, and
- # _content_type is set while generating headers. Get it
- # from the BranchChange object.
- revision._content_type = self._content_type
- return revision.generate_browse_link(base_url)
- self.generate_browse_link = revision_gen_link
- for line in self.generate_email(push, body_filter, values):
- yield line
-
- def generate_email_body(self, push):
- '''Call the appropriate body generation routine.
-
- If this is a combined refchange/revision email, the special logic
- for handling this combined email comes from this function. For
- other cases, we just use the normal handling.'''
-
- # If self._single_revision isn't set; don't override
- if not self._single_revision:
- for line in super(BranchChange, self).generate_email_body(push):
- yield line
- return
-
- # This is a combined refchange/revision email; we first provide
- # some info from the refchange portion, and then call the revision
- # generate_email_body function to handle the revision portion.
- adds = list(generate_summaries(
- '--topo-order', '--reverse', '%s..%s'
- % (self.old.commit_sha1, self.new.commit_sha1,)
- ))
-
- yield self.expand("The following commit(s) were added to %(refname)s by this push:\n")
- for (sha1, subject) in adds:
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='new',
- rev_short=sha1, text=subject,
- )
-
- yield self._single_revision.rev.short + " is described below\n"
- yield '\n'
-
- for line in self._single_revision.generate_email_body(push):
- yield line
-
-
-class AnnotatedTagChange(ReferenceChange):
- refname_type = 'annotated tag'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_announce_recipients(self)
- self.show_shortlog = environment.announce_show_shortlog
-
- ANNOTATED_TAG_FORMAT = (
- '%(*objectname)\n'
- '%(*objecttype)\n'
- '%(taggername)\n'
- '%(taggerdate)'
- )
-
- def describe_tag(self, push):
- """Describe the new value of an annotated tag."""
-
- # Use git for-each-ref to pull out the individual fields from
- # the tag
- [tagobject, tagtype, tagger, tagged] = read_git_lines(
- ['for-each-ref', '--format=%s' % (self.ANNOTATED_TAG_FORMAT,), self.refname],
- )
-
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='tagging',
- rev_short=tagobject, text='(%s)' % (tagtype,),
- )
- if tagtype == 'commit':
- # If the tagged object is a commit, then we assume this is a
- # release, and so we calculate which tag this tag is
- # replacing
- try:
- prevtag = read_git_output(['describe', '--abbrev=0', '%s^' % (self.new,)])
- except CommandError:
- prevtag = None
- if prevtag:
- yield ' replaces %s\n' % (prevtag,)
- else:
- prevtag = None
- yield ' length %s bytes\n' % (read_git_output(['cat-file', '-s', tagobject]),)
-
- yield ' by %s\n' % (tagger,)
- yield ' on %s\n' % (tagged,)
- yield '\n'
-
- # Show the content of the tag message; this might contain a
- # change log or release notes so is worth displaying.
- yield LOGBEGIN
- contents = list(read_git_lines(['cat-file', 'tag', self.new.sha1], keepends=True))
- contents = contents[contents.index('\n') + 1:]
- if contents and contents[-1][-1:] != '\n':
- contents.append('\n')
- for line in contents:
- yield line
-
- if self.show_shortlog and tagtype == 'commit':
- # Only commit tags make sense to have rev-list operations
- # performed on them
- yield '\n'
- if prevtag:
- # Show changes since the previous release
- revlist = read_git_output(
- ['rev-list', '--pretty=short', '%s..%s' % (prevtag, self.new,)],
- keepends=True,
- )
- else:
- # No previous tag, show all the changes since time
- # began
- revlist = read_git_output(
- ['rev-list', '--pretty=short', '%s' % (self.new,)],
- keepends=True,
- )
- for line in read_git_lines(['shortlog'], input=revlist, keepends=True):
- yield line
-
- yield LOGEND
- yield '\n'
-
- def generate_create_summary(self, push):
- """Called for the creation of an annotated tag."""
-
- for line in self.expand_lines(TAG_CREATED_TEMPLATE):
- yield line
-
- for line in self.describe_tag(push):
- yield line
-
- def generate_update_summary(self, push):
- """Called for the update of an annotated tag.
-
- This is probably a rare event and may not even be allowed."""
-
- for line in self.expand_lines(TAG_UPDATED_TEMPLATE):
- yield line
-
- for line in self.describe_tag(push):
- yield line
-
- def generate_delete_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_DELETED_TEMPLATE):
- yield line
-
- yield self.expand(' tag was %(oldrev_short)s\n')
- yield '\n'
-
-
-class NonAnnotatedTagChange(ReferenceChange):
- refname_type = 'tag'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
-
- def generate_create_summary(self, push):
- """Called for the creation of an annotated tag."""
-
- for line in self.expand_lines(TAG_CREATED_TEMPLATE):
- yield line
-
- def generate_update_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_UPDATED_TEMPLATE):
- yield line
-
- def generate_delete_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_DELETED_TEMPLATE):
- yield line
-
- for line in ReferenceChange.generate_delete_summary(self, push):
- yield line
-
-
-class OtherReferenceChange(ReferenceChange):
- refname_type = 'reference'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- # We use the full refname as short_refname, because otherwise
- # the full name of the reference would not be obvious from the
- # text of the email.
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
-
-
-class Mailer(object):
- """An object that can send emails."""
-
- def __init__(self, environment):
- self.environment = environment
-
- def close(self):
- pass
-
- def send(self, lines, to_addrs):
- """Send an email consisting of lines.
-
- lines must be an iterable over the lines constituting the
- header and body of the email. to_addrs is a list of recipient
- addresses (can be needed even if lines already contains a
- "To:" field). It can be either a string (comma-separated list
- of email addresses) or a Python list of individual email
- addresses.
-
- """
-
- raise NotImplementedError()
-
-
-class SendMailer(Mailer):
- """Send emails using 'sendmail -oi -t'."""
-
- SENDMAIL_CANDIDATES = [
- '/usr/sbin/sendmail',
- '/usr/lib/sendmail',
- ]
-
- @staticmethod
- def find_sendmail():
- for path in SendMailer.SENDMAIL_CANDIDATES:
- if os.access(path, os.X_OK):
- return path
- else:
- raise ConfigurationException(
- 'No sendmail executable found. '
- 'Try setting multimailhook.sendmailCommand.'
- )
-
- def __init__(self, environment, command=None, envelopesender=None):
- """Construct a SendMailer instance.
-
- command should be the command and arguments used to invoke
- sendmail, as a list of strings. If an envelopesender is
- provided, it will also be passed to the command, via '-f
- envelopesender'."""
- super(SendMailer, self).__init__(environment)
- if command:
- self.command = command[:]
- else:
- self.command = [self.find_sendmail(), '-oi', '-t']
-
- if envelopesender:
- self.command.extend(['-f', envelopesender])
-
- def send(self, lines, to_addrs):
- try:
- p = subprocess.Popen(self.command, stdin=subprocess.PIPE)
- except OSError:
- self.environment.get_logger().error(
- '*** Cannot execute command: %s\n' % ' '.join(self.command) +
- '*** %s\n' % sys.exc_info()[1] +
- '*** Try setting multimailhook.mailer to "smtp"\n' +
- '*** to send emails without using the sendmail command.\n'
- )
- sys.exit(1)
- try:
- lines = (str_to_bytes(line) for line in lines)
- p.stdin.writelines(lines)
- except Exception:
- self.environment.get_logger().error(
- '*** Error while generating commit email\n'
- '*** - mail sending aborted.\n'
- )
- if hasattr(p, 'terminate'):
- # subprocess.terminate() is not available in Python 2.4
- p.terminate()
- else:
- import signal
- os.kill(p.pid, signal.SIGTERM)
- raise
- else:
- p.stdin.close()
- retcode = p.wait()
- if retcode:
- raise CommandError(self.command, retcode)
-
-
-class SMTPMailer(Mailer):
- """Send emails using Python's smtplib."""
-
- def __init__(self, environment,
- envelopesender, smtpserver,
- smtpservertimeout=10.0, smtpserverdebuglevel=0,
- smtpencryption='none',
- smtpuser='', smtppass='',
- smtpcacerts=''
- ):
- super(SMTPMailer, self).__init__(environment)
- if not envelopesender:
- self.environment.get_logger().error(
- 'fatal: git_multimail: cannot use SMTPMailer without a sender address.\n'
- 'please set either multimailhook.envelopeSender or user.email\n'
- )
- sys.exit(1)
- if smtpencryption == 'ssl' and not (smtpuser and smtppass):
- raise ConfigurationException(
- 'Cannot use SMTPMailer with security option ssl '
- 'without options username and password.'
- )
- self.envelopesender = envelopesender
- self.smtpserver = smtpserver
- self.smtpservertimeout = smtpservertimeout
- self.smtpserverdebuglevel = smtpserverdebuglevel
- self.security = smtpencryption
- self.username = smtpuser
- self.password = smtppass
- self.smtpcacerts = smtpcacerts
- self.loggedin = False
- try:
- def call(klass, server, timeout):
- try:
- return klass(server, timeout=timeout)
- except TypeError:
- # Old Python versions do not have timeout= argument.
- return klass(server)
- if self.security == 'none':
- self.smtp = call(smtplib.SMTP, self.smtpserver, timeout=self.smtpservertimeout)
- elif self.security == 'ssl':
- if self.smtpcacerts:
- raise smtplib.SMTPException(
- "Checking certificate is not supported for ssl, prefer starttls"
- )
- self.smtp = call(smtplib.SMTP_SSL, self.smtpserver, timeout=self.smtpservertimeout)
- elif self.security == 'tls':
- if 'ssl' not in sys.modules:
- self.environment.get_logger().error(
- '*** Your Python version does not have the ssl library installed\n'
- '*** smtpEncryption=tls is not available.\n'
- '*** Either upgrade Python to 2.6 or later\n'
- ' or use git_multimail.py version 1.2.\n')
- if ':' not in self.smtpserver:
- self.smtpserver += ':587' # default port for TLS
- self.smtp = call(smtplib.SMTP, self.smtpserver, timeout=self.smtpservertimeout)
- # start: ehlo + starttls
- # equivalent to
- # self.smtp.ehlo()
- # self.smtp.starttls()
- # with access to the ssl layer
- self.smtp.ehlo()
- if not self.smtp.has_extn("starttls"):
- raise smtplib.SMTPException("STARTTLS extension not supported by server")
- resp, reply = self.smtp.docmd("STARTTLS")
- if resp != 220:
- raise smtplib.SMTPException("Wrong answer to the STARTTLS command")
- if self.smtpcacerts:
- self.smtp.sock = ssl.wrap_socket(
- self.smtp.sock,
- ca_certs=self.smtpcacerts,
- cert_reqs=ssl.CERT_REQUIRED
- )
- else:
- self.smtp.sock = ssl.wrap_socket(
- self.smtp.sock,
- cert_reqs=ssl.CERT_NONE
- )
- self.environment.get_logger().error(
- '*** Warning, the server certificate is not verified (smtp) ***\n'
- '*** set the option smtpCACerts ***\n'
- )
- if not hasattr(self.smtp.sock, "read"):
- # using httplib.FakeSocket with Python 2.5.x or earlier
- self.smtp.sock.read = self.smtp.sock.recv
- self.smtp.file = smtplib.SSLFakeFile(self.smtp.sock)
- self.smtp.helo_resp = None
- self.smtp.ehlo_resp = None
- self.smtp.esmtp_features = {}
- self.smtp.does_esmtp = 0
- # end: ehlo + starttls
- self.smtp.ehlo()
- else:
- sys.stdout.write('*** Error: Control reached an invalid option. ***')
- sys.exit(1)
- if self.smtpserverdebuglevel > 0:
- sys.stdout.write(
- "*** Setting debug on for SMTP server connection (%s) ***\n"
- % self.smtpserverdebuglevel)
- self.smtp.set_debuglevel(self.smtpserverdebuglevel)
- except Exception:
- self.environment.get_logger().error(
- '*** Error establishing SMTP connection to %s ***\n'
- '*** %s\n'
- % (self.smtpserver, sys.exc_info()[1]))
- sys.exit(1)
-
- def close(self):
- if hasattr(self, 'smtp'):
- self.smtp.quit()
- del self.smtp
-
- def __del__(self):
- self.close()
-
- def send(self, lines, to_addrs):
- try:
- if self.username or self.password:
- if not self.loggedin:
- self.smtp.login(self.username, self.password)
- self.loggedin = True
- msg = ''.join(lines)
- # turn comma-separated list into Python list if needed.
- if is_string(to_addrs):
- to_addrs = [email for (name, email) in getaddresses([to_addrs])]
- self.smtp.sendmail(self.envelopesender, to_addrs, msg)
- except socket.timeout:
- self.environment.get_logger().error(
- '*** Error sending email ***\n'
- '*** SMTP server timed out (timeout is %s)\n'
- % self.smtpservertimeout)
- except smtplib.SMTPResponseException:
- err = sys.exc_info()[1]
- self.environment.get_logger().error(
- '*** Error sending email ***\n'
- '*** Error %d: %s\n'
- % (err.smtp_code, bytes_to_str(err.smtp_error)))
- try:
- smtp = self.smtp
- # delete the field before quit() so that in case of
- # error, self.smtp is deleted anyway.
- del self.smtp
- smtp.quit()
- except:
- self.environment.get_logger().error(
- '*** Error closing the SMTP connection ***\n'
- '*** Exiting anyway ... ***\n'
- '*** %s\n' % sys.exc_info()[1])
- sys.exit(1)
-
-
-class OutputMailer(Mailer):
- """Write emails to an output stream, bracketed by lines of '=' characters.
-
- This is intended for debugging purposes."""
-
- SEPARATOR = '=' * 75 + '\n'
-
- def __init__(self, f, environment=None):
- super(OutputMailer, self).__init__(environment=environment)
- self.f = f
-
- def send(self, lines, to_addrs):
- write_str(self.f, self.SEPARATOR)
- for line in lines:
- write_str(self.f, line)
- write_str(self.f, self.SEPARATOR)
-
-
-def get_git_dir():
- """Determine GIT_DIR.
-
- Determine GIT_DIR either from the GIT_DIR environment variable or
- from the working directory, using Git's usual rules."""
-
- try:
- return read_git_output(['rev-parse', '--git-dir'])
- except CommandError:
- sys.stderr.write('fatal: git_multimail: not in a git directory\n')
- sys.exit(1)
-
-
-class Environment(object):
- """Describes the environment in which the push is occurring.
-
- An Environment object encapsulates information about the local
- environment. For example, it knows how to determine:
-
- * the name of the repository to which the push occurred
-
- * what user did the push
-
- * what users want to be informed about various types of changes.
-
- An Environment object is expected to have the following methods:
-
- get_repo_shortname()
-
- Return a short name for the repository, for display
- purposes.
-
- get_repo_path()
-
- Return the absolute path to the Git repository.
-
- get_emailprefix()
-
- Return a string that will be prefixed to every email's
- subject.
-
- get_pusher()
-
- Return the username of the person who pushed the changes.
- This value is used in the email body to indicate who
- pushed the change.
-
- get_pusher_email() (may return None)
-
- Return the email address of the person who pushed the
- changes. The value should be a single RFC 2822 email
- address as a string; e.g., "Joe User <user@example.com>"
- if available, otherwise "user@example.com". If set, the
- value is used as the Reply-To address for refchange
- emails. If it is impossible to determine the pusher's
- email, this attribute should be set to None (in which case
- no Reply-To header will be output).
-
- get_sender()
-
- Return the address to be used as the 'From' email address
- in the email envelope.
-
- get_fromaddr(change=None)
-
- Return the 'From' email address used in the email 'From:'
- headers. If the change is known when this function is
- called, it is passed in as the 'change' parameter. (May
- be a full RFC 2822 email address like 'Joe User
- <user@example.com>'.)
-
- get_administrator()
-
- Return the name and/or email of the repository
- administrator. This value is used in the footer as the
- person to whom requests to be removed from the
- notification list should be sent. Ideally, it should
- include a valid email address.
-
- get_reply_to_refchange()
- get_reply_to_commit()
-
- Return the address to use in the email "Reply-To" header,
- as a string. These can be an RFC 2822 email address, or
- None to omit the "Reply-To" header.
- get_reply_to_refchange() is used for refchange emails;
- get_reply_to_commit() is used for individual commit
- emails.
-
- get_ref_filter_regex()
-
- Return a tuple -- a compiled regex, and a boolean indicating
- whether the regex picks refs to include (if False, the regex
- matches on refs to exclude).
-
- get_default_ref_ignore_regex()
-
- Return a regex that should be ignored for both what emails
- to send and when computing what commits are considered new
- to the repository. Default is "^refs/notes/".
-
- get_max_subject_length()
-
- Return an int giving the maximal length for the subject
- (git log --oneline).
-
- They should also define the following attributes:
-
- announce_show_shortlog (bool)
-
- True iff announce emails should include a shortlog.
-
- commit_email_format (string)
-
- If "html", generate commit emails in HTML instead of plain text
- used by default.
-
- html_in_intro (bool)
- html_in_footer (bool)
-
- When generating HTML emails, the introduction (respectively,
- the footer) will be HTML-escaped iff html_in_intro (respectively,
- the footer) is true. When false, only the values used to expand
- the template are escaped.
-
- refchange_showgraph (bool)
-
- True iff refchanges emails should include a detailed graph.
-
- refchange_showlog (bool)
-
- True iff refchanges emails should include a detailed log.
-
- diffopts (list of strings)
-
- The options that should be passed to 'git diff' for the
- summary email. The value should be a list of strings
- representing words to be passed to the command.
-
- graphopts (list of strings)
-
- Analogous to diffopts, but contains options passed to
- 'git log --graph' when generating the detailed graph for
- a set of commits (see refchange_showgraph)
-
- logopts (list of strings)
-
- Analogous to diffopts, but contains options passed to
- 'git log' when generating the detailed log for a set of
- commits (see refchange_showlog)
-
- commitlogopts (list of strings)
-
- The options that should be passed to 'git log' for each
- commit mail. The value should be a list of strings
- representing words to be passed to the command.
-
- date_substitute (string)
-
- String to be used in substitution for 'Date:' at start of
- line in the output of 'git log'.
-
- quiet (bool)
- On success do not write to stderr
-
- stdout (bool)
- Write email to stdout rather than emailing. Useful for debugging
-
- combine_when_single_commit (bool)
-
- True if a combined email should be produced when a single
- new commit is pushed to a branch, False otherwise.
-
- from_refchange, from_commit (strings)
-
- Addresses to use for the From: field for refchange emails
- and commit emails respectively. Set from
- multimailhook.fromRefchange and multimailhook.fromCommit
- by ConfigEnvironmentMixin.
-
- log_file, error_log_file, debug_log_file (string)
-
- Name of a file to which logs should be sent.
-
- verbose (int)
-
- How verbose the system should be.
- - 0 (default): show info, errors, ...
- - 1 : show basic debug info
- """
-
- REPO_NAME_RE = re.compile(r'^(?P<name>.+?)(?:\.git)$')
-
- def __init__(self, osenv=None):
- self.osenv = osenv or os.environ
- self.announce_show_shortlog = False
- self.commit_email_format = "text"
- self.html_in_intro = False
- self.html_in_footer = False
- self.commitBrowseURL = None
- self.maxcommitemails = 500
- self.excludemergerevisions = False
- self.diffopts = ['--stat', '--summary', '--find-copies-harder']
- self.graphopts = ['--oneline', '--decorate']
- self.logopts = []
- self.refchange_showgraph = False
- self.refchange_showlog = False
- self.commitlogopts = ['-C', '--stat', '-p', '--cc']
- self.date_substitute = 'AuthorDate: '
- self.quiet = False
- self.stdout = False
- self.combine_when_single_commit = True
- self.logger = None
-
- self.COMPUTED_KEYS = [
- 'administrator',
- 'charset',
- 'emailprefix',
- 'pusher',
- 'pusher_email',
- 'repo_path',
- 'repo_shortname',
- 'sender',
- ]
-
- self._values = None
-
- def get_logger(self):
- """Get (possibly creates) the logger associated to this environment."""
- if self.logger is None:
- self.logger = Logger(self)
- return self.logger
-
- def get_repo_shortname(self):
- """Use the last part of the repo path, with ".git" stripped off if present."""
-
- basename = os.path.basename(os.path.abspath(self.get_repo_path()))
- m = self.REPO_NAME_RE.match(basename)
- if m:
- return m.group('name')
- else:
- return basename
-
- def get_pusher(self):
- raise NotImplementedError()
-
- def get_pusher_email(self):
- return None
-
- def get_fromaddr(self, change=None):
- config = Config('user')
- fromname = config.get('name', default='')
- fromemail = config.get('email', default='')
- if fromemail:
- return formataddr([fromname, fromemail])
- return self.get_sender()
-
- def get_administrator(self):
- return 'the administrator of this repository'
-
- def get_emailprefix(self):
- return ''
-
- def get_repo_path(self):
- if read_git_output(['rev-parse', '--is-bare-repository']) == 'true':
- path = get_git_dir()
- else:
- path = read_git_output(['rev-parse', '--show-toplevel'])
- return os.path.abspath(path)
-
- def get_charset(self):
- return CHARSET
-
- def get_values(self):
- """Return a dictionary {keyword: expansion} for this Environment.
-
- This method is called by Change._compute_values(). The keys
- in the returned dictionary are available to be used in any of
- the templates. The dictionary is created by calling
- self.get_NAME() for each of the attributes named in
- COMPUTED_KEYS and recording those that do not return None.
- The return value is always a new dictionary."""
-
- if self._values is None:
- values = {'': ''} # %()s expands to the empty string.
-
- for key in self.COMPUTED_KEYS:
- value = getattr(self, 'get_%s' % (key,))()
- if value is not None:
- values[key] = value
-
- self._values = values
-
- return self._values.copy()
-
- def get_refchange_recipients(self, refchange):
- """Return the recipients for notifications about refchange.
-
- Return the list of email addresses to which notifications
- about the specified ReferenceChange should be sent."""
-
- raise NotImplementedError()
-
- def get_announce_recipients(self, annotated_tag_change):
- """Return the recipients for notifications about annotated_tag_change.
-
- Return the list of email addresses to which notifications
- about the specified AnnotatedTagChange should be sent."""
-
- raise NotImplementedError()
-
- def get_reply_to_refchange(self, refchange):
- return self.get_pusher_email()
-
- def get_revision_recipients(self, revision):
- """Return the recipients for messages about revision.
-
- Return the list of email addresses to which notifications
- about the specified Revision should be sent. This method
- could be overridden, for example, to take into account the
- contents of the revision when deciding whom to notify about
- it. For example, there could be a scheme for users to express
- interest in particular files or subdirectories, and only
- receive notification emails for revisions that affecting those
- files."""
-
- raise NotImplementedError()
-
- def get_reply_to_commit(self, revision):
- return revision.author
-
- def get_default_ref_ignore_regex(self):
- # The commit messages of git notes are essentially meaningless
- # and "filenames" in git notes commits are an implementational
- # detail that might surprise users at first. As such, we
- # would need a completely different method for handling emails
- # of git notes in order for them to be of benefit for users,
- # which we simply do not have right now.
- return "^refs/notes/"
-
- def get_max_subject_length(self):
- """Return the maximal subject line (git log --oneline) length.
- Longer subject lines will be truncated."""
- raise NotImplementedError()
-
- def filter_body(self, lines):
- """Filter the lines intended for an email body.
-
- lines is an iterable over the lines that would go into the
- email body. Filter it (e.g., limit the number of lines, the
- line length, character set, etc.), returning another iterable.
- See FilterLinesEnvironmentMixin and MaxlinesEnvironmentMixin
- for classes implementing this functionality."""
-
- return lines
-
- def log_msg(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().info(msg)
-
- def log_warning(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().warning(msg)
-
- def log_error(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().error(msg)
-
- def check(self):
- pass
-
-
-class ConfigEnvironmentMixin(Environment):
- """A mixin that sets self.config to its constructor's config argument.
-
- This class's constructor consumes the "config" argument.
-
- Mixins that need to inspect the config should inherit from this
- class (1) to make sure that "config" is still in the constructor
- arguments with its own constructor runs and/or (2) to be sure that
- self.config is set after construction."""
-
- def __init__(self, config, **kw):
- super(ConfigEnvironmentMixin, self).__init__(**kw)
- self.config = config
-
-
-class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin):
- """An Environment that reads most of its information from "git config"."""
-
- @staticmethod
- def forbid_field_values(name, value, forbidden):
- for forbidden_val in forbidden:
- if value is not None and value.lower() == forbidden:
- raise ConfigurationException(
- '"%s" is not an allowed setting for %s' % (value, name)
- )
-
- def __init__(self, config, **kw):
- super(ConfigOptionsEnvironmentMixin, self).__init__(
- config=config, **kw
- )
-
- for var, cfg in (
- ('announce_show_shortlog', 'announceshortlog'),
- ('refchange_showgraph', 'refchangeShowGraph'),
- ('refchange_showlog', 'refchangeshowlog'),
- ('quiet', 'quiet'),
- ('stdout', 'stdout'),
- ):
- val = config.get_bool(cfg)
- if val is not None:
- setattr(self, var, val)
-
- commit_email_format = config.get('commitEmailFormat')
- if commit_email_format is not None:
- if commit_email_format != "html" and commit_email_format != "text":
- self.log_warning(
- '*** Unknown value for multimailhook.commitEmailFormat: %s\n' %
- commit_email_format +
- '*** Expected either "text" or "html". Ignoring.\n'
- )
- else:
- self.commit_email_format = commit_email_format
-
- html_in_intro = config.get_bool('htmlInIntro')
- if html_in_intro is not None:
- self.html_in_intro = html_in_intro
-
- html_in_footer = config.get_bool('htmlInFooter')
- if html_in_footer is not None:
- self.html_in_footer = html_in_footer
-
- self.commitBrowseURL = config.get('commitBrowseURL')
-
- self.excludemergerevisions = config.get('excludeMergeRevisions')
-
- maxcommitemails = config.get('maxcommitemails')
- if maxcommitemails is not None:
- try:
- self.maxcommitemails = int(maxcommitemails)
- except ValueError:
- self.log_warning(
- '*** Malformed value for multimailhook.maxCommitEmails: %s\n'
- % maxcommitemails +
- '*** Expected a number. Ignoring.\n'
- )
-
- diffopts = config.get('diffopts')
- if diffopts is not None:
- self.diffopts = shlex.split(diffopts)
-
- graphopts = config.get('graphOpts')
- if graphopts is not None:
- self.graphopts = shlex.split(graphopts)
-
- logopts = config.get('logopts')
- if logopts is not None:
- self.logopts = shlex.split(logopts)
-
- commitlogopts = config.get('commitlogopts')
- if commitlogopts is not None:
- self.commitlogopts = shlex.split(commitlogopts)
-
- date_substitute = config.get('dateSubstitute')
- if date_substitute == 'none':
- self.date_substitute = None
- elif date_substitute is not None:
- self.date_substitute = date_substitute
-
- reply_to = config.get('replyTo')
- self.__reply_to_refchange = config.get('replyToRefchange', default=reply_to)
- self.forbid_field_values('replyToRefchange',
- self.__reply_to_refchange,
- ['author'])
- self.__reply_to_commit = config.get('replyToCommit', default=reply_to)
-
- self.from_refchange = config.get('fromRefchange')
- self.forbid_field_values('fromRefchange',
- self.from_refchange,
- ['author', 'none'])
- self.from_commit = config.get('fromCommit')
- self.forbid_field_values('fromCommit',
- self.from_commit,
- ['none'])
-
- combine = config.get_bool('combineWhenSingleCommit')
- if combine is not None:
- self.combine_when_single_commit = combine
-
- self.log_file = config.get('logFile', default=None)
- self.error_log_file = config.get('errorLogFile', default=None)
- self.debug_log_file = config.get('debugLogFile', default=None)
- if config.get_bool('Verbose', default=False):
- self.verbose = 1
- else:
- self.verbose = 0
-
- def get_administrator(self):
- return (
- self.config.get('administrator') or
- self.get_sender() or
- super(ConfigOptionsEnvironmentMixin, self).get_administrator()
- )
-
- def get_repo_shortname(self):
- return (
- self.config.get('reponame') or
- super(ConfigOptionsEnvironmentMixin, self).get_repo_shortname()
- )
-
- def get_emailprefix(self):
- emailprefix = self.config.get('emailprefix')
- if emailprefix is not None:
- emailprefix = emailprefix.strip()
- if emailprefix:
- emailprefix += ' '
- else:
- emailprefix = '[%(repo_shortname)s] '
- short_name = self.get_repo_shortname()
- try:
- return emailprefix % {'repo_shortname': short_name}
- except:
- self.get_logger().error(
- '*** Invalid multimailhook.emailPrefix: %s\n' % emailprefix +
- '*** %s\n' % sys.exc_info()[1] +
- "*** Only the '%(repo_shortname)s' placeholder is allowed\n"
- )
- raise ConfigurationException(
- '"%s" is not an allowed setting for emailPrefix' % emailprefix
- )
-
- def get_sender(self):
- return self.config.get('envelopesender')
-
- def process_addr(self, addr, change):
- if addr.lower() == 'author':
- if hasattr(change, 'author'):
- return change.author
- else:
- return None
- elif addr.lower() == 'pusher':
- return self.get_pusher_email()
- elif addr.lower() == 'none':
- return None
- else:
- return addr
-
- def get_fromaddr(self, change=None):
- fromaddr = self.config.get('from')
- if change:
- specific_fromaddr = change.get_specific_fromaddr()
- if specific_fromaddr:
- fromaddr = specific_fromaddr
- if fromaddr:
- fromaddr = self.process_addr(fromaddr, change)
- if fromaddr:
- return fromaddr
- return super(ConfigOptionsEnvironmentMixin, self).get_fromaddr(change)
-
- def get_reply_to_refchange(self, refchange):
- if self.__reply_to_refchange is None:
- return super(ConfigOptionsEnvironmentMixin, self).get_reply_to_refchange(refchange)
- else:
- return self.process_addr(self.__reply_to_refchange, refchange)
-
- def get_reply_to_commit(self, revision):
- if self.__reply_to_commit is None:
- return super(ConfigOptionsEnvironmentMixin, self).get_reply_to_commit(revision)
- else:
- return self.process_addr(self.__reply_to_commit, revision)
-
- def get_scancommitforcc(self):
- return self.config.get('scancommitforcc')
-
-
-class FilterLinesEnvironmentMixin(Environment):
- """Handle encoding and maximum line length of body lines.
-
- email_max_line_length (int or None)
-
- The maximum length of any single line in the email body.
- Longer lines are truncated at that length with ' [...]'
- appended.
-
- strict_utf8 (bool)
-
- If this field is set to True, then the email body text is
- expected to be UTF-8. Any invalid characters are
- converted to U+FFFD, the Unicode replacement character
- (encoded as UTF-8, of course).
-
- """
-
- def __init__(self, strict_utf8=True,
- email_max_line_length=500, max_subject_length=500,
- **kw):
- super(FilterLinesEnvironmentMixin, self).__init__(**kw)
- self.__strict_utf8 = strict_utf8
- self.__email_max_line_length = email_max_line_length
- self.__max_subject_length = max_subject_length
-
- def filter_body(self, lines):
- lines = super(FilterLinesEnvironmentMixin, self).filter_body(lines)
- if self.__strict_utf8:
- if not PYTHON3:
- lines = (line.decode(ENCODING, 'replace') for line in lines)
- # Limit the line length in Unicode-space to avoid
- # splitting characters:
- if self.__email_max_line_length > 0:
- lines = limit_linelength(lines, self.__email_max_line_length)
- if not PYTHON3:
- lines = (line.encode(ENCODING, 'replace') for line in lines)
- elif self.__email_max_line_length:
- lines = limit_linelength(lines, self.__email_max_line_length)
-
- return lines
-
- def get_max_subject_length(self):
- return self.__max_subject_length
-
-
-class ConfigFilterLinesEnvironmentMixin(
- ConfigEnvironmentMixin,
- FilterLinesEnvironmentMixin,
- ):
- """Handle encoding and maximum line length based on config."""
-
- def __init__(self, config, **kw):
- strict_utf8 = config.get_bool('emailstrictutf8', default=None)
- if strict_utf8 is not None:
- kw['strict_utf8'] = strict_utf8
-
- email_max_line_length = config.get('emailmaxlinelength')
- if email_max_line_length is not None:
- kw['email_max_line_length'] = int(email_max_line_length)
-
- max_subject_length = config.get('subjectMaxLength', default=email_max_line_length)
- if max_subject_length is not None:
- kw['max_subject_length'] = int(max_subject_length)
-
- super(ConfigFilterLinesEnvironmentMixin, self).__init__(
- config=config, **kw
- )
-
-
-class MaxlinesEnvironmentMixin(Environment):
- """Limit the email body to a specified number of lines."""
-
- def __init__(self, emailmaxlines, **kw):
- super(MaxlinesEnvironmentMixin, self).__init__(**kw)
- self.__emailmaxlines = emailmaxlines
-
- def filter_body(self, lines):
- lines = super(MaxlinesEnvironmentMixin, self).filter_body(lines)
- if self.__emailmaxlines > 0:
- lines = limit_lines(lines, self.__emailmaxlines)
- return lines
-
-
-class ConfigMaxlinesEnvironmentMixin(
- ConfigEnvironmentMixin,
- MaxlinesEnvironmentMixin,
- ):
- """Limit the email body to the number of lines specified in config."""
-
- def __init__(self, config, **kw):
- emailmaxlines = int(config.get('emailmaxlines', default='0'))
- super(ConfigMaxlinesEnvironmentMixin, self).__init__(
- config=config,
- emailmaxlines=emailmaxlines,
- **kw
- )
-
-
-class FQDNEnvironmentMixin(Environment):
- """A mixin that sets the host's FQDN to its constructor argument."""
-
- def __init__(self, fqdn, **kw):
- super(FQDNEnvironmentMixin, self).__init__(**kw)
- self.COMPUTED_KEYS += ['fqdn']
- self.__fqdn = fqdn
-
- def get_fqdn(self):
- """Return the fully-qualified domain name for this host.
-
- Return None if it is unavailable or unwanted."""
-
- return self.__fqdn
-
-
-class ConfigFQDNEnvironmentMixin(
- ConfigEnvironmentMixin,
- FQDNEnvironmentMixin,
- ):
- """Read the FQDN from the config."""
-
- def __init__(self, config, **kw):
- fqdn = config.get('fqdn')
- super(ConfigFQDNEnvironmentMixin, self).__init__(
- config=config,
- fqdn=fqdn,
- **kw
- )
-
-
-class ComputeFQDNEnvironmentMixin(FQDNEnvironmentMixin):
- """Get the FQDN by calling socket.getfqdn()."""
-
- def __init__(self, **kw):
- super(ComputeFQDNEnvironmentMixin, self).__init__(
- fqdn=socket.getfqdn(),
- **kw
- )
-
-
-class PusherDomainEnvironmentMixin(ConfigEnvironmentMixin):
- """Deduce pusher_email from pusher by appending an emaildomain."""
-
- def __init__(self, **kw):
- super(PusherDomainEnvironmentMixin, self).__init__(**kw)
- self.__emaildomain = self.config.get('emaildomain')
-
- def get_pusher_email(self):
- if self.__emaildomain:
- # Derive the pusher's full email address in the default way:
- return '%s@%s' % (self.get_pusher(), self.__emaildomain)
- else:
- return super(PusherDomainEnvironmentMixin, self).get_pusher_email()
-
-
-class StaticRecipientsEnvironmentMixin(Environment):
- """Set recipients statically based on constructor parameters."""
-
- def __init__(
- self,
- refchange_recipients, announce_recipients, revision_recipients, scancommitforcc,
- **kw
- ):
- super(StaticRecipientsEnvironmentMixin, self).__init__(**kw)
-
- # The recipients for various types of notification emails, as
- # RFC 2822 email addresses separated by commas (or the empty
- # string if no recipients are configured). Although there is
- # a mechanism to choose the recipient lists based on on the
- # actual *contents* of the change being reported, we only
- # choose based on the *type* of the change. Therefore we can
- # compute them once and for all:
- self.__refchange_recipients = refchange_recipients
- self.__announce_recipients = announce_recipients
- self.__revision_recipients = revision_recipients
-
- def check(self):
- if not (self.get_refchange_recipients(None) or
- self.get_announce_recipients(None) or
- self.get_revision_recipients(None) or
- self.get_scancommitforcc()):
- raise ConfigurationException('No email recipients configured!')
- super(StaticRecipientsEnvironmentMixin, self).check()
-
- def get_refchange_recipients(self, refchange):
- if self.__refchange_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(refchange)
- return self.__refchange_recipients
-
- def get_announce_recipients(self, annotated_tag_change):
- if self.__announce_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(annotated_tag_change)
- return self.__announce_recipients
-
- def get_revision_recipients(self, revision):
- if self.__revision_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(revision)
- return self.__revision_recipients
-
-
-class CLIRecipientsEnvironmentMixin(Environment):
- """Mixin storing recipients information coming from the
- command-line."""
-
- def __init__(self, cli_recipients=None, **kw):
- super(CLIRecipientsEnvironmentMixin, self).__init__(**kw)
- self.__cli_recipients = cli_recipients
-
- def get_refchange_recipients(self, refchange):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_refchange_recipients(refchange)
- return self.__cli_recipients
-
- def get_announce_recipients(self, annotated_tag_change):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_announce_recipients(annotated_tag_change)
- return self.__cli_recipients
-
- def get_revision_recipients(self, revision):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_revision_recipients(revision)
- return self.__cli_recipients
-
-
-class ConfigRecipientsEnvironmentMixin(
- ConfigEnvironmentMixin,
- StaticRecipientsEnvironmentMixin
- ):
- """Determine recipients statically based on config."""
-
- def __init__(self, config, **kw):
- super(ConfigRecipientsEnvironmentMixin, self).__init__(
- config=config,
- refchange_recipients=self._get_recipients(
- config, 'refchangelist', 'mailinglist',
- ),
- announce_recipients=self._get_recipients(
- config, 'announcelist', 'refchangelist', 'mailinglist',
- ),
- revision_recipients=self._get_recipients(
- config, 'commitlist', 'mailinglist',
- ),
- scancommitforcc=config.get('scancommitforcc'),
- **kw
- )
-
- def _get_recipients(self, config, *names):
- """Return the recipients for a particular type of message.
-
- Return the list of email addresses to which a particular type
- of notification email should be sent, by looking at the config
- value for "multimailhook.$name" for each of names. Use the
- value from the first name that is configured. The return
- value is a (possibly empty) string containing RFC 2822 email
- addresses separated by commas. If no configuration could be
- found, raise a ConfigurationException."""
-
- for name in names:
- lines = config.get_all(name)
- if lines is not None:
- lines = [line.strip() for line in lines]
- # Single "none" is a special value equivalen to empty string.
- if lines == ['none']:
- lines = ['']
- return ', '.join(lines)
- else:
- return ''
-
-
-class StaticRefFilterEnvironmentMixin(Environment):
- """Set branch filter statically based on constructor parameters."""
-
- def __init__(self, ref_filter_incl_regex, ref_filter_excl_regex,
- ref_filter_do_send_regex, ref_filter_dont_send_regex,
- **kw):
- super(StaticRefFilterEnvironmentMixin, self).__init__(**kw)
-
- if ref_filter_incl_regex and ref_filter_excl_regex:
- raise ConfigurationException(
- "Cannot specify both a ref inclusion and exclusion regex.")
- self.__is_inclusion_filter = bool(ref_filter_incl_regex)
- default_exclude = self.get_default_ref_ignore_regex()
- if ref_filter_incl_regex:
- ref_filter_regex = ref_filter_incl_regex
- elif ref_filter_excl_regex:
- ref_filter_regex = ref_filter_excl_regex + '|' + default_exclude
- else:
- ref_filter_regex = default_exclude
- try:
- self.__compiled_regex = re.compile(ref_filter_regex)
- except Exception:
- raise ConfigurationException(
- 'Invalid Ref Filter Regex "%s": %s' % (ref_filter_regex, sys.exc_info()[1]))
-
- if ref_filter_do_send_regex and ref_filter_dont_send_regex:
- raise ConfigurationException(
- "Cannot specify both a ref doSend and dontSend regex.")
- self.__is_do_send_filter = bool(ref_filter_do_send_regex)
- if ref_filter_do_send_regex:
- ref_filter_send_regex = ref_filter_do_send_regex
- elif ref_filter_dont_send_regex:
- ref_filter_send_regex = ref_filter_dont_send_regex
- else:
- ref_filter_send_regex = '.*'
- self.__is_do_send_filter = True
- try:
- self.__send_compiled_regex = re.compile(ref_filter_send_regex)
- except Exception:
- raise ConfigurationException(
- 'Invalid Ref Filter Regex "%s": %s' %
- (ref_filter_send_regex, sys.exc_info()[1]))
-
- def get_ref_filter_regex(self, send_filter=False):
- if send_filter:
- return self.__send_compiled_regex, self.__is_do_send_filter
- else:
- return self.__compiled_regex, self.__is_inclusion_filter
-
-
-class ConfigRefFilterEnvironmentMixin(
- ConfigEnvironmentMixin,
- StaticRefFilterEnvironmentMixin
- ):
- """Determine branch filtering statically based on config."""
-
- def _get_regex(self, config, key):
- """Get a list of whitespace-separated regex. The refFilter* config
- variables are multivalued (hence the use of get_all), and we
- allow each entry to be a whitespace-separated list (hence the
- split on each line). The whole thing is glued into a single regex."""
- values = config.get_all(key)
- if values is None:
- return values
- items = []
- for line in values:
- for i in line.split():
- items.append(i)
- if items == []:
- return None
- return '|'.join(items)
-
- def __init__(self, config, **kw):
- super(ConfigRefFilterEnvironmentMixin, self).__init__(
- config=config,
- ref_filter_incl_regex=self._get_regex(config, 'refFilterInclusionRegex'),
- ref_filter_excl_regex=self._get_regex(config, 'refFilterExclusionRegex'),
- ref_filter_do_send_regex=self._get_regex(config, 'refFilterDoSendRegex'),
- ref_filter_dont_send_regex=self._get_regex(config, 'refFilterDontSendRegex'),
- **kw
- )
-
-
-class ProjectdescEnvironmentMixin(Environment):
- """Make a "projectdesc" value available for templates.
-
- By default, it is set to the first line of $GIT_DIR/description
- (if that file is present and appears to be set meaningfully)."""
-
- def __init__(self, **kw):
- super(ProjectdescEnvironmentMixin, self).__init__(**kw)
- self.COMPUTED_KEYS += ['projectdesc']
-
- def get_projectdesc(self):
- """Return a one-line description of the project."""
-
- git_dir = get_git_dir()
- try:
- projectdesc = open(os.path.join(git_dir, 'description')).readline().strip()
- if projectdesc and not projectdesc.startswith('Unnamed repository'):
- return projectdesc
- except IOError:
- pass
-
- return 'UNNAMED PROJECT'
-
-
-class GenericEnvironmentMixin(Environment):
- def get_pusher(self):
- return self.osenv.get('USER', self.osenv.get('USERNAME', 'unknown user'))
-
-
-class GitoliteEnvironmentHighPrecMixin(Environment):
- def get_pusher(self):
- return self.osenv.get('GL_USER', 'unknown user')
-
-
-class GitoliteEnvironmentLowPrecMixin(
- ConfigEnvironmentMixin,
- Environment):
-
- def get_repo_shortname(self):
- # The gitolite environment variable $GL_REPO is a pretty good
- # repo_shortname (though it's probably not as good as a value
- # the user might have explicitly put in his config).
- return (
- self.osenv.get('GL_REPO', None) or
- super(GitoliteEnvironmentLowPrecMixin, self).get_repo_shortname()
- )
-
- @staticmethod
- def _compile_regex(re_template):
- return (
- re.compile(re_template % x)
- for x in (
- r'BEGIN\s+USER\s+EMAILS',
- r'([^\s]+)\s+(.*)',
- r'END\s+USER\s+EMAILS',
- ))
-
- def get_fromaddr(self, change=None):
- GL_USER = self.osenv.get('GL_USER')
- if GL_USER is not None:
- # Find the path to gitolite.conf. Note that gitolite v3
- # did away with the GL_ADMINDIR and GL_CONF environment
- # variables (they are now hard-coded).
- GL_ADMINDIR = self.osenv.get(
- 'GL_ADMINDIR',
- os.path.expanduser(os.path.join('~', '.gitolite')))
- GL_CONF = self.osenv.get(
- 'GL_CONF',
- os.path.join(GL_ADMINDIR, 'conf', 'gitolite.conf'))
-
- mailaddress_map = self.config.get('MailaddressMap')
- # If relative, consider relative to GL_CONF:
- if mailaddress_map:
- mailaddress_map = os.path.join(os.path.dirname(GL_CONF),
- mailaddress_map)
- if os.path.isfile(mailaddress_map):
- f = open(mailaddress_map, 'rU')
- try:
- # Leading '#' is optional
- re_begin, re_user, re_end = self._compile_regex(
- r'^(?:\s*#)?\s*%s\s*$')
- for l in f:
- l = l.rstrip('\n')
- if re_begin.match(l) or re_end.match(l):
- continue # Ignore these lines
- m = re_user.match(l)
- if m:
- if m.group(1) == GL_USER:
- return m.group(2)
- else:
- continue # Not this user, but not an error
- raise ConfigurationException(
- "Syntax error in mail address map.\n"
- "Check file {}.\n"
- "Line: {}".format(mailaddress_map, l))
-
- finally:
- f.close()
-
- if os.path.isfile(GL_CONF):
- f = open(GL_CONF, 'rU')
- try:
- in_user_emails_section = False
- re_begin, re_user, re_end = self._compile_regex(
- r'^\s*#\s*%s\s*$')
- for l in f:
- l = l.rstrip('\n')
- if not in_user_emails_section:
- if re_begin.match(l):
- in_user_emails_section = True
- continue
- if re_end.match(l):
- break
- m = re_user.match(l)
- if m and m.group(1) == GL_USER:
- return m.group(2)
- finally:
- f.close()
- return super(GitoliteEnvironmentLowPrecMixin, self).get_fromaddr(change)
-
-
-class IncrementalDateTime(object):
- """Simple wrapper to give incremental date/times.
-
- Each call will result in a date/time a second later than the
- previous call. This can be used to falsify email headers, to
- increase the likelihood that email clients sort the emails
- correctly."""
-
- def __init__(self):
- self.time = time.time()
- self.next = self.__next__ # Python 2 backward compatibility
-
- def __next__(self):
- formatted = formatdate(self.time, True)
- self.time += 1
- return formatted
-
-
-class StashEnvironmentHighPrecMixin(Environment):
- def __init__(self, user=None, repo=None, **kw):
- super(StashEnvironmentHighPrecMixin,
- self).__init__(user=user, repo=repo, **kw)
- self.__user = user
- self.__repo = repo
-
- def get_pusher(self):
- return re.match(r'(.*?)\s*<', self.__user).group(1)
-
- def get_pusher_email(self):
- return self.__user
-
-
-class StashEnvironmentLowPrecMixin(Environment):
- def __init__(self, user=None, repo=None, **kw):
- super(StashEnvironmentLowPrecMixin, self).__init__(**kw)
- self.__repo = repo
- self.__user = user
-
- def get_repo_shortname(self):
- return self.__repo
-
- def get_fromaddr(self, change=None):
- return self.__user
-
-
-class GerritEnvironmentHighPrecMixin(Environment):
- def __init__(self, project=None, submitter=None, update_method=None, **kw):
- super(GerritEnvironmentHighPrecMixin,
- self).__init__(submitter=submitter, project=project, **kw)
- self.__project = project
- self.__submitter = submitter
- self.__update_method = update_method
- "Make an 'update_method' value available for templates."
- self.COMPUTED_KEYS += ['update_method']
-
- def get_pusher(self):
- if self.__submitter:
- if self.__submitter.find('<') != -1:
- # Submitter has a configured email, we transformed
- # __submitter into an RFC 2822 string already.
- return re.match(r'(.*?)\s*<', self.__submitter).group(1)
- else:
- # Submitter has no configured email, it's just his name.
- return self.__submitter
- else:
- # If we arrive here, this means someone pushed "Submit" from
- # the gerrit web UI for the CR (or used one of the programmatic
- # APIs to do the same, such as gerrit review) and the
- # merge/push was done by the Gerrit user. It was technically
- # triggered by someone else, but sadly we have no way of
- # determining who that someone else is at this point.
- return 'Gerrit' # 'unknown user'?
-
- def get_pusher_email(self):
- if self.__submitter:
- return self.__submitter
- else:
- return super(GerritEnvironmentHighPrecMixin, self).get_pusher_email()
-
- def get_default_ref_ignore_regex(self):
- default = super(GerritEnvironmentHighPrecMixin, self).get_default_ref_ignore_regex()
- return default + '|^refs/changes/|^refs/cache-automerge/|^refs/meta/'
-
- def get_revision_recipients(self, revision):
- # Merge commits created by Gerrit when users hit "Submit this patchset"
- # in the Web UI (or do equivalently with REST APIs or the gerrit review
- # command) are not something users want to see an individual email for.
- # Filter them out.
- committer = read_git_output(['log', '--no-walk', '--format=%cN',
- revision.rev.sha1])
- if committer == 'Gerrit Code Review':
- return []
- else:
- return super(GerritEnvironmentHighPrecMixin, self).get_revision_recipients(revision)
-
- def get_update_method(self):
- return self.__update_method
-
-
-class GerritEnvironmentLowPrecMixin(Environment):
- def __init__(self, project=None, submitter=None, **kw):
- super(GerritEnvironmentLowPrecMixin, self).__init__(**kw)
- self.__project = project
- self.__submitter = submitter
-
- def get_repo_shortname(self):
- return self.__project
-
- def get_fromaddr(self, change=None):
- if self.__submitter and self.__submitter.find('<') != -1:
- return self.__submitter
- else:
- return super(GerritEnvironmentLowPrecMixin, self).get_fromaddr(change)
-
-
-class Push(object):
- """Represent an entire push (i.e., a group of ReferenceChanges).
-
- It is easy to figure out what commits were added to a *branch* by
- a Reference change:
-
- git rev-list change.old..change.new
-
- or removed from a *branch*:
-
- git rev-list change.new..change.old
-
- But it is not quite so trivial to determine which entirely new
- commits were added to the *repository* by a push and which old
- commits were discarded by a push. A big part of the job of this
- class is to figure out these things, and to make sure that new
- commits are only detailed once even if they were added to multiple
- references.
-
- The first step is to determine the "other" references--those
- unaffected by the current push. They are computed by listing all
- references then removing any affected by this push. The results
- are stored in Push._other_ref_sha1s.
-
- The commits contained in the repository before this push were
-
- git rev-list other1 other2 other3 ... change1.old change2.old ...
-
- Where "changeN.old" is the old value of one of the references
- affected by this push.
-
- The commits contained in the repository after this push are
-
- git rev-list other1 other2 other3 ... change1.new change2.new ...
-
- The commits added by this push are the difference between these
- two sets, which can be written
-
- git rev-list \
- ^other1 ^other2 ... \
- ^change1.old ^change2.old ... \
- change1.new change2.new ...
-
- The commits removed by this push can be computed by
-
- git rev-list \
- ^other1 ^other2 ... \
- ^change1.new ^change2.new ... \
- change1.old change2.old ...
-
- The last point is that it is possible that other pushes are
- occurring simultaneously to this one, so reference values can
- change at any time. It is impossible to eliminate all race
- conditions, but we reduce the window of time during which problems
- can occur by translating reference names to SHA1s as soon as
- possible and working with SHA1s thereafter (because SHA1s are
- immutable)."""
-
- # A map {(changeclass, changetype): integer} specifying the order
- # that reference changes will be processed if multiple reference
- # changes are included in a single push. The order is significant
- # mostly because new commit notifications are threaded together
- # with the first reference change that includes the commit. The
- # following order thus causes commits to be grouped with branch
- # changes (as opposed to tag changes) if possible.
- SORT_ORDER = dict(
- (value, i) for (i, value) in enumerate([
- (BranchChange, 'update'),
- (BranchChange, 'create'),
- (AnnotatedTagChange, 'update'),
- (AnnotatedTagChange, 'create'),
- (NonAnnotatedTagChange, 'update'),
- (NonAnnotatedTagChange, 'create'),
- (BranchChange, 'delete'),
- (AnnotatedTagChange, 'delete'),
- (NonAnnotatedTagChange, 'delete'),
- (OtherReferenceChange, 'update'),
- (OtherReferenceChange, 'create'),
- (OtherReferenceChange, 'delete'),
- ])
- )
-
- def __init__(self, environment, changes, ignore_other_refs=False):
- self.changes = sorted(changes, key=self._sort_key)
- self.__other_ref_sha1s = None
- self.__cached_commits_spec = {}
- self.environment = environment
-
- if ignore_other_refs:
- self.__other_ref_sha1s = set()
-
- @classmethod
- def _sort_key(klass, change):
- return (klass.SORT_ORDER[change.__class__, change.change_type], change.refname,)
-
- @property
- def _other_ref_sha1s(self):
- """The GitObjects referred to by references unaffected by this push.
- """
- if self.__other_ref_sha1s is None:
- # The refnames being changed by this push:
- updated_refs = set(
- change.refname
- for change in self.changes
- )
-
- # The SHA-1s of commits referred to by all references in this
- # repository *except* updated_refs:
- sha1s = set()
- fmt = (
- '%(objectname) %(objecttype) %(refname)\n'
- '%(*objectname) %(*objecttype) %(refname)'
- )
- ref_filter_regex, is_inclusion_filter = \
- self.environment.get_ref_filter_regex()
- for line in read_git_lines(
- ['for-each-ref', '--format=%s' % (fmt,)]):
- (sha1, type, name) = line.split(' ', 2)
- if (sha1 and type == 'commit' and
- name not in updated_refs and
- include_ref(name, ref_filter_regex, is_inclusion_filter)):
- sha1s.add(sha1)
-
- self.__other_ref_sha1s = sha1s
-
- return self.__other_ref_sha1s
-
- def _get_commits_spec_incl(self, new_or_old, reference_change=None):
- """Get new or old SHA-1 from one or each of the changed refs.
-
- Return a list of SHA-1 commit identifier strings suitable as
- arguments to 'git rev-list' (or 'git log' or ...). The
- returned identifiers are either the old or new values from one
- or all of the changed references, depending on the values of
- new_or_old and reference_change.
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the returned SHA-1 identifiers are the new values from
- each changed reference. If 'old', the SHA-1 identifiers are
- the old values from each changed reference.
-
- If reference_change is specified and not None, only the new or
- old reference from the specified reference is included in the
- return value.
-
- This function returns None if there are no matching revisions
- (e.g., because a branch was deleted and new_or_old is 'new').
- """
-
- if not reference_change:
- incl_spec = sorted(
- getattr(change, new_or_old).sha1
- for change in self.changes
- if getattr(change, new_or_old)
- )
- if not incl_spec:
- incl_spec = None
- elif not getattr(reference_change, new_or_old).commit_sha1:
- incl_spec = None
- else:
- incl_spec = [getattr(reference_change, new_or_old).commit_sha1]
- return incl_spec
-
- def _get_commits_spec_excl(self, new_or_old):
- """Get exclusion revisions for determining new or discarded commits.
-
- Return a list of strings suitable as arguments to 'git
- rev-list' (or 'git log' or ...) that will exclude all
- commits that, depending on the value of new_or_old, were
- either previously in the repository (useful for determining
- which commits are new to the repository) or currently in the
- repository (useful for determining which commits were
- discarded from the repository).
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the commits to be excluded are those that were in the
- repository before the push. If 'old', the commits to be
- excluded are those that are currently in the repository. """
-
- old_or_new = {'old': 'new', 'new': 'old'}[new_or_old]
- excl_revs = self._other_ref_sha1s.union(
- getattr(change, old_or_new).sha1
- for change in self.changes
- if getattr(change, old_or_new).type in ['commit', 'tag']
- )
- return ['^' + sha1 for sha1 in sorted(excl_revs)]
-
- def get_commits_spec(self, new_or_old, reference_change=None):
- """Get rev-list arguments for added or discarded commits.
-
- Return a list of strings suitable as arguments to 'git
- rev-list' (or 'git log' or ...) that select those commits
- that, depending on the value of new_or_old, are either new to
- the repository or were discarded from the repository.
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the returned list is used to select commits that are
- new to the repository. If 'old', the returned value is used
- to select the commits that have been discarded from the
- repository.
-
- If reference_change is specified and not None, the new or
- discarded commits are limited to those that are reachable from
- the new or old value of the specified reference.
-
- This function returns None if there are no added (or discarded)
- revisions.
- """
- key = (new_or_old, reference_change)
- if key not in self.__cached_commits_spec:
- ret = self._get_commits_spec_incl(new_or_old, reference_change)
- if ret is not None:
- ret.extend(self._get_commits_spec_excl(new_or_old))
- self.__cached_commits_spec[key] = ret
- return self.__cached_commits_spec[key]
-
- def get_new_commits(self, reference_change=None):
- """Return a list of commits added by this push.
-
- Return a list of the object names of commits that were added
- by the part of this push represented by reference_change. If
- reference_change is None, then return a list of *all* commits
- added by this push."""
-
- spec = self.get_commits_spec('new', reference_change)
- return git_rev_list(spec)
-
- def get_discarded_commits(self, reference_change):
- """Return a list of commits discarded by this push.
-
- Return a list of the object names of commits that were
- entirely discarded from the repository by the part of this
- push represented by reference_change."""
-
- spec = self.get_commits_spec('old', reference_change)
- return git_rev_list(spec)
-
- def send_emails(self, mailer, body_filter=None):
- """Use send all of the notification emails needed for this push.
-
- Use send all of the notification emails (including reference
- change emails and commit emails) needed for this push. Send
- the emails using mailer. If body_filter is not None, then use
- it to filter the lines that are intended for the email
- body."""
-
- # The sha1s of commits that were introduced by this push.
- # They will be removed from this set as they are processed, to
- # guarantee that one (and only one) email is generated for
- # each new commit.
- unhandled_sha1s = set(self.get_new_commits())
- send_date = IncrementalDateTime()
- for change in self.changes:
- sha1s = []
- for sha1 in reversed(list(self.get_new_commits(change))):
- if sha1 in unhandled_sha1s:
- sha1s.append(sha1)
- unhandled_sha1s.remove(sha1)
-
- # Check if we've got anyone to send to
- if not change.recipients:
- change.environment.log_warning(
- '*** no recipients configured so no email will be sent\n'
- '*** for %r update %s->%s'
- % (change.refname, change.old.sha1, change.new.sha1,)
- )
- else:
- if not change.environment.quiet:
- change.environment.log_msg(
- 'Sending notification emails to: %s' % (change.recipients,))
- extra_values = {'send_date': next(send_date)}
-
- rev = change.send_single_combined_email(sha1s)
- if rev:
- mailer.send(
- change.generate_combined_email(self, rev, body_filter, extra_values),
- rev.recipients,
- )
- # This change is now fully handled; no need to handle
- # individual revisions any further.
- continue
- else:
- mailer.send(
- change.generate_email(self, body_filter, extra_values),
- change.recipients,
- )
-
- max_emails = change.environment.maxcommitemails
- if max_emails and len(sha1s) > max_emails:
- change.environment.log_warning(
- '*** Too many new commits (%d), not sending commit emails.\n' % len(sha1s) +
- '*** Try setting multimailhook.maxCommitEmails to a greater value\n' +
- '*** Currently, multimailhook.maxCommitEmails=%d' % max_emails
- )
- return
-
- for (num, sha1) in enumerate(sha1s):
- rev = Revision(change, GitObject(sha1), num=num + 1, tot=len(sha1s))
- if len(rev.parents) > 1 and change.environment.excludemergerevisions:
- # skipping a merge commit
- continue
- if not rev.recipients and rev.cc_recipients:
- change.environment.log_msg('*** Replacing Cc: with To:')
- rev.recipients = rev.cc_recipients
- rev.cc_recipients = None
- if rev.recipients:
- extra_values = {'send_date': next(send_date)}
- mailer.send(
- rev.generate_email(self, body_filter, extra_values),
- rev.recipients,
- )
-
- # Consistency check:
- if unhandled_sha1s:
- change.environment.log_error(
- 'ERROR: No emails were sent for the following new commits:\n'
- ' %s'
- % ('\n '.join(sorted(unhandled_sha1s)),)
- )
-
-
-def include_ref(refname, ref_filter_regex, is_inclusion_filter):
- does_match = bool(ref_filter_regex.search(refname))
- if is_inclusion_filter:
- return does_match
- else: # exclusion filter -- we include the ref if the regex doesn't match
- return not does_match
-
-
-def run_as_post_receive_hook(environment, mailer):
- environment.check()
- send_filter_regex, send_is_inclusion_filter = environment.get_ref_filter_regex(True)
- ref_filter_regex, is_inclusion_filter = environment.get_ref_filter_regex(False)
- changes = []
- while True:
- line = read_line(sys.stdin)
- if line == '':
- break
- (oldrev, newrev, refname) = line.strip().split(' ', 2)
- environment.get_logger().debug(
- "run_as_post_receive_hook: oldrev=%s, newrev=%s, refname=%s" %
- (oldrev, newrev, refname))
-
- if not include_ref(refname, ref_filter_regex, is_inclusion_filter):
- continue
- if not include_ref(refname, send_filter_regex, send_is_inclusion_filter):
- continue
- changes.append(
- ReferenceChange.create(environment, oldrev, newrev, refname)
- )
- if not changes:
- mailer.close()
- return
- push = Push(environment, changes)
- try:
- push.send_emails(mailer, body_filter=environment.filter_body)
- finally:
- mailer.close()
-
-
-def run_as_update_hook(environment, mailer, refname, oldrev, newrev, force_send=False):
- environment.check()
- send_filter_regex, send_is_inclusion_filter = environment.get_ref_filter_regex(True)
- ref_filter_regex, is_inclusion_filter = environment.get_ref_filter_regex(False)
- if not include_ref(refname, ref_filter_regex, is_inclusion_filter):
- return
- if not include_ref(refname, send_filter_regex, send_is_inclusion_filter):
- return
- changes = [
- ReferenceChange.create(
- environment,
- read_git_output(['rev-parse', '--verify', oldrev]),
- read_git_output(['rev-parse', '--verify', newrev]),
- refname,
- ),
- ]
- if not changes:
- mailer.close()
- return
- push = Push(environment, changes, force_send)
- try:
- push.send_emails(mailer, body_filter=environment.filter_body)
- finally:
- mailer.close()
-
-
-def check_ref_filter(environment):
- send_filter_regex, send_is_inclusion = environment.get_ref_filter_regex(True)
- ref_filter_regex, ref_is_inclusion = environment.get_ref_filter_regex(False)
-
- def inc_exc_lusion(b):
- if b:
- return 'inclusion'
- else:
- return 'exclusion'
-
- if send_filter_regex:
- sys.stdout.write("DoSend/DontSend filter regex (" +
- (inc_exc_lusion(send_is_inclusion)) +
- '): ' + send_filter_regex.pattern +
- '\n')
- if send_filter_regex:
- sys.stdout.write("Include/Exclude filter regex (" +
- (inc_exc_lusion(ref_is_inclusion)) +
- '): ' + ref_filter_regex.pattern +
- '\n')
- sys.stdout.write(os.linesep)
-
- sys.stdout.write(
- "Refs marked as EXCLUDE are excluded by either refFilterInclusionRegex\n"
- "or refFilterExclusionRegex. No emails will be sent for commits included\n"
- "in these refs.\n"
- "Refs marked as DONT-SEND are excluded by either refFilterDoSendRegex or\n"
- "refFilterDontSendRegex, but not by either refFilterInclusionRegex or\n"
- "refFilterExclusionRegex. Emails will be sent for commits included in these\n"
- "refs only when the commit reaches a ref which isn't excluded.\n"
- "Refs marked as DO-SEND are not excluded by any filter. Emails will\n"
- "be sent normally for commits included in these refs.\n")
-
- sys.stdout.write(os.linesep)
-
- for refname in read_git_lines(['for-each-ref', '--format', '%(refname)']):
- sys.stdout.write(refname)
- if not include_ref(refname, ref_filter_regex, ref_is_inclusion):
- sys.stdout.write(' EXCLUDE')
- elif not include_ref(refname, send_filter_regex, send_is_inclusion):
- sys.stdout.write(' DONT-SEND')
- else:
- sys.stdout.write(' DO-SEND')
-
- sys.stdout.write(os.linesep)
-
-
-def show_env(environment, out):
- out.write('Environment values:\n')
- for (k, v) in sorted(environment.get_values().items()):
- if k: # Don't show the {'' : ''} pair.
- out.write(' %s : %r\n' % (k, v))
- out.write('\n')
- # Flush to avoid interleaving with further log output
- out.flush()
-
-
-def check_setup(environment):
- environment.check()
- show_env(environment, sys.stdout)
- sys.stdout.write("Now, checking that git-multimail's standard input "
- "is properly set ..." + os.linesep)
- sys.stdout.write("Please type some text and then press Return" + os.linesep)
- stdin = sys.stdin.readline()
- sys.stdout.write("You have just entered:" + os.linesep)
- sys.stdout.write(stdin)
- sys.stdout.write("git-multimail seems properly set up." + os.linesep)
-
-
-def choose_mailer(config, environment):
- mailer = config.get('mailer', default='sendmail')
-
- if mailer == 'smtp':
- smtpserver = config.get('smtpserver', default='localhost')
- smtpservertimeout = float(config.get('smtpservertimeout', default=10.0))
- smtpserverdebuglevel = int(config.get('smtpserverdebuglevel', default=0))
- smtpencryption = config.get('smtpencryption', default='none')
- smtpuser = config.get('smtpuser', default='')
- smtppass = config.get('smtppass', default='')
- smtpcacerts = config.get('smtpcacerts', default='')
- mailer = SMTPMailer(
- environment,
- envelopesender=(environment.get_sender() or environment.get_fromaddr()),
- smtpserver=smtpserver, smtpservertimeout=smtpservertimeout,
- smtpserverdebuglevel=smtpserverdebuglevel,
- smtpencryption=smtpencryption,
- smtpuser=smtpuser,
- smtppass=smtppass,
- smtpcacerts=smtpcacerts
- )
- elif mailer == 'sendmail':
- command = config.get('sendmailcommand')
- if command:
- command = shlex.split(command)
- mailer = SendMailer(environment,
- command=command, envelopesender=environment.get_sender())
- else:
- environment.log_error(
- 'fatal: multimailhook.mailer is set to an incorrect value: "%s"\n' % mailer +
- 'please use one of "smtp" or "sendmail".'
- )
- sys.exit(1)
- return mailer
-
-
-KNOWN_ENVIRONMENTS = {
- 'generic': {'highprec': GenericEnvironmentMixin},
- 'gitolite': {'highprec': GitoliteEnvironmentHighPrecMixin,
- 'lowprec': GitoliteEnvironmentLowPrecMixin},
- 'stash': {'highprec': StashEnvironmentHighPrecMixin,
- 'lowprec': StashEnvironmentLowPrecMixin},
- 'gerrit': {'highprec': GerritEnvironmentHighPrecMixin,
- 'lowprec': GerritEnvironmentLowPrecMixin},
- }
-
-
-def choose_environment(config, osenv=None, env=None, recipients=None,
- hook_info=None):
- env_name = choose_environment_name(config, env, osenv)
- environment_klass = build_environment_klass(env_name)
- env = build_environment(environment_klass, env_name, config,
- osenv, recipients, hook_info)
- return env
-
-
-def choose_environment_name(config, env, osenv):
- if not osenv:
- osenv = os.environ
-
- if not env:
- env = config.get('environment')
-
- if not env:
- if 'GL_USER' in osenv and 'GL_REPO' in osenv:
- env = 'gitolite'
- else:
- env = 'generic'
- return env
-
-
-COMMON_ENVIRONMENT_MIXINS = [
- ConfigRecipientsEnvironmentMixin,
- CLIRecipientsEnvironmentMixin,
- ConfigRefFilterEnvironmentMixin,
- ProjectdescEnvironmentMixin,
- ConfigMaxlinesEnvironmentMixin,
- ComputeFQDNEnvironmentMixin,
- ConfigFilterLinesEnvironmentMixin,
- PusherDomainEnvironmentMixin,
- ConfigOptionsEnvironmentMixin,
- ]
-
-
-def build_environment_klass(env_name):
- if 'class' in KNOWN_ENVIRONMENTS[env_name]:
- return KNOWN_ENVIRONMENTS[env_name]['class']
-
- environment_mixins = []
- known_env = KNOWN_ENVIRONMENTS[env_name]
- if 'highprec' in known_env:
- high_prec_mixin = known_env['highprec']
- environment_mixins.append(high_prec_mixin)
- environment_mixins = environment_mixins + COMMON_ENVIRONMENT_MIXINS
- if 'lowprec' in known_env:
- low_prec_mixin = known_env['lowprec']
- environment_mixins.append(low_prec_mixin)
- environment_mixins.append(Environment)
- klass_name = env_name.capitalize() + 'Environment'
- environment_klass = type(
- klass_name,
- tuple(environment_mixins),
- {},
- )
- KNOWN_ENVIRONMENTS[env_name]['class'] = environment_klass
- return environment_klass
-
-
-GerritEnvironment = build_environment_klass('gerrit')
-StashEnvironment = build_environment_klass('stash')
-GitoliteEnvironment = build_environment_klass('gitolite')
-GenericEnvironment = build_environment_klass('generic')
-
-
-def build_environment(environment_klass, env, config,
- osenv, recipients, hook_info):
- environment_kw = {
- 'osenv': osenv,
- 'config': config,
- }
-
- if env == 'stash':
- environment_kw['user'] = hook_info['stash_user']
- environment_kw['repo'] = hook_info['stash_repo']
- elif env == 'gerrit':
- environment_kw['project'] = hook_info['project']
- environment_kw['submitter'] = hook_info['submitter']
- environment_kw['update_method'] = hook_info['update_method']
-
- environment_kw['cli_recipients'] = recipients
-
- return environment_klass(**environment_kw)
-
-
-def get_version():
- oldcwd = os.getcwd()
- try:
- try:
- os.chdir(os.path.dirname(os.path.realpath(__file__)))
- git_version = read_git_output(['describe', '--tags', 'HEAD'])
- if git_version == __version__:
- return git_version
- else:
- return '%s (%s)' % (__version__, git_version)
- except:
- pass
- finally:
- os.chdir(oldcwd)
- return __version__
-
-
-def compute_gerrit_options(options, args, required_gerrit_options,
- raw_refname):
- if None in required_gerrit_options:
- raise SystemExit("Error: Specify all of --oldrev, --newrev, --refname, "
- "and --project; or none of them.")
-
- if options.environment not in (None, 'gerrit'):
- raise SystemExit("Non-gerrit environments incompatible with --oldrev, "
- "--newrev, --refname, and --project")
- options.environment = 'gerrit'
-
- if args:
- raise SystemExit("Error: Positional parameters not allowed with "
- "--oldrev, --newrev, and --refname.")
-
- # Gerrit oddly omits 'refs/heads/' in the refname when calling
- # ref-updated hook; put it back.
- git_dir = get_git_dir()
- if (not os.path.exists(os.path.join(git_dir, raw_refname)) and
- os.path.exists(os.path.join(git_dir, 'refs', 'heads',
- raw_refname))):
- options.refname = 'refs/heads/' + options.refname
-
- # New revisions can appear in a gerrit repository either due to someone
- # pushing directly (in which case options.submitter will be set), or they
- # can press "Submit this patchset" in the web UI for some CR (in which
- # case options.submitter will not be set and gerrit will not have provided
- # us the information about who pressed the button).
- #
- # Note for the nit-picky: I'm lumping in REST API calls and the ssh
- # gerrit review command in with "Submit this patchset" button, since they
- # have the same effect.
- if options.submitter:
- update_method = 'pushed'
- # The submitter argument is almost an RFC 2822 email address; change it
- # from 'User Name (email@domain)' to 'User Name <email@domain>' so it is
- options.submitter = options.submitter.replace('(', '<').replace(')', '>')
- else:
- update_method = 'submitted'
- # Gerrit knew who submitted this patchset, but threw that information
- # away when it invoked this hook. However, *IF* Gerrit created a
- # merge to bring the patchset in (project 'Submit Type' is either
- # "Always Merge", or is "Merge if Necessary" and happens to be
- # necessary for this particular CR), then it will have the committer
- # of that merge be 'Gerrit Code Review' and the author will be the
- # person who requested the submission of the CR. Since this is fairly
- # likely for most gerrit installations (of a reasonable size), it's
- # worth the extra effort to try to determine the actual submitter.
- rev_info = read_git_lines(['log', '--no-walk', '--merges',
- '--format=%cN%n%aN <%aE>', options.newrev])
- if rev_info and rev_info[0] == 'Gerrit Code Review':
- options.submitter = rev_info[1]
-
- # We pass back refname, oldrev, newrev as args because then the
- # gerrit ref-updated hook is much like the git update hook
- return (options,
- [options.refname, options.oldrev, options.newrev],
- {'project': options.project, 'submitter': options.submitter,
- 'update_method': update_method})
-
-
-def check_hook_specific_args(options, args):
- raw_refname = options.refname
- # Convert each string option unicode for Python3.
- if PYTHON3:
- opts = ['environment', 'recipients', 'oldrev', 'newrev', 'refname',
- 'project', 'submitter', 'stash_user', 'stash_repo']
- for opt in opts:
- if not hasattr(options, opt):
- continue
- obj = getattr(options, opt)
- if obj:
- enc = obj.encode('utf-8', 'surrogateescape')
- dec = enc.decode('utf-8', 'replace')
- setattr(options, opt, dec)
-
- # First check for stash arguments
- if (options.stash_user is None) != (options.stash_repo is None):
- raise SystemExit("Error: Specify both of --stash-user and "
- "--stash-repo or neither.")
- if options.stash_user:
- options.environment = 'stash'
- return options, args, {'stash_user': options.stash_user,
- 'stash_repo': options.stash_repo}
-
- # Finally, check for gerrit specific arguments
- required_gerrit_options = (options.oldrev, options.newrev, options.refname,
- options.project)
- if required_gerrit_options != (None,) * 4:
- return compute_gerrit_options(options, args, required_gerrit_options,
- raw_refname)
-
- # No special options in use, just return what we started with
- return options, args, {}
-
-
-class Logger(object):
- def parse_verbose(self, verbose):
- if verbose > 0:
- return logging.DEBUG
- else:
- return logging.INFO
-
- def create_log_file(self, environment, name, path, verbosity):
- log_file = logging.getLogger(name)
- file_handler = logging.FileHandler(path)
- log_fmt = logging.Formatter("%(asctime)s [%(levelname)-5.5s] %(message)s")
- file_handler.setFormatter(log_fmt)
- log_file.addHandler(file_handler)
- log_file.setLevel(verbosity)
- return log_file
-
- def __init__(self, environment):
- self.environment = environment
- self.loggers = []
- stderr_log = logging.getLogger('git_multimail.stderr')
-
- class EncodedStderr(object):
- def write(self, x):
- write_str(sys.stderr, x)
-
- def flush(self):
- sys.stderr.flush()
-
- stderr_handler = logging.StreamHandler(EncodedStderr())
- stderr_log.addHandler(stderr_handler)
- stderr_log.setLevel(self.parse_verbose(environment.verbose))
- self.loggers.append(stderr_log)
-
- if environment.debug_log_file is not None:
- debug_log_file = self.create_log_file(
- environment, 'git_multimail.debug', environment.debug_log_file, logging.DEBUG)
- self.loggers.append(debug_log_file)
-
- if environment.log_file is not None:
- log_file = self.create_log_file(
- environment, 'git_multimail.file', environment.log_file, logging.INFO)
- self.loggers.append(log_file)
-
- if environment.error_log_file is not None:
- error_log_file = self.create_log_file(
- environment, 'git_multimail.error', environment.error_log_file, logging.ERROR)
- self.loggers.append(error_log_file)
-
- def info(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.info(msg, *args, **kwargs)
-
- def debug(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.debug(msg, *args, **kwargs)
-
- def warning(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.warning(msg, *args, **kwargs)
-
- def error(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.error(msg, *args, **kwargs)
-
-
-def main(args):
- parser = optparse.OptionParser(
- description=__doc__,
- usage='%prog [OPTIONS]\n or: %prog [OPTIONS] REFNAME OLDREV NEWREV',
- )
-
- parser.add_option(
- '--environment', '--env', action='store', type='choice',
- choices=list(KNOWN_ENVIRONMENTS.keys()), default=None,
- help=(
- 'Choose type of environment is in use. Default is taken from '
- 'multimailhook.environment if set; otherwise "generic".'
- ),
- )
- parser.add_option(
- '--stdout', action='store_true', default=False,
- help='Output emails to stdout rather than sending them.',
- )
- parser.add_option(
- '--recipients', action='store', default=None,
- help='Set list of email recipients for all types of emails.',
- )
- parser.add_option(
- '--show-env', action='store_true', default=False,
- help=(
- 'Write to stderr the values determined for the environment '
- '(intended for debugging purposes), then proceed normally.'
- ),
- )
- parser.add_option(
- '--force-send', action='store_true', default=False,
- help=(
- 'Force sending refchange email when using as an update hook. '
- 'This is useful to work around the unreliable new commits '
- 'detection in this mode.'
- ),
- )
- parser.add_option(
- '-c', metavar="<name>=<value>", action='append',
- help=(
- 'Pass a configuration parameter through to git. The value given '
- 'will override values from configuration files. See the -c option '
- 'of git(1) for more details. (Only works with git >= 1.7.3)'
- ),
- )
- parser.add_option(
- '--version', '-v', action='store_true', default=False,
- help=(
- "Display git-multimail's version"
- ),
- )
-
- parser.add_option(
- '--python-version', action='store_true', default=False,
- help=(
- "Display the version of Python used by git-multimail"
- ),
- )
-
- parser.add_option(
- '--check-ref-filter', action='store_true', default=False,
- help=(
- 'List refs and show information on how git-multimail '
- 'will process them.'
- )
- )
-
- # The following options permit this script to be run as a gerrit
- # ref-updated hook. See e.g.
- # code.google.com/p/gerrit/source/browse/Documentation/config-hooks.txt
- # We suppress help for these items, since these are specific to gerrit,
- # and we don't want users directly using them any way other than how the
- # gerrit ref-updated hook is called.
- parser.add_option('--oldrev', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--newrev', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--refname', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--project', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--submitter', action='store', help=optparse.SUPPRESS_HELP)
-
- # The following allow this to be run as a stash asynchronous post-receive
- # hook (almost identical to a git post-receive hook but triggered also for
- # merges of pull requests from the UI). We suppress help for these items,
- # since these are specific to stash.
- parser.add_option('--stash-user', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--stash-repo', action='store', help=optparse.SUPPRESS_HELP)
-
- (options, args) = parser.parse_args(args)
- (options, args, hook_info) = check_hook_specific_args(options, args)
-
- if options.version:
- sys.stdout.write('git-multimail version ' + get_version() + '\n')
- return
-
- if options.python_version:
- sys.stdout.write('Python version ' + sys.version + '\n')
- return
-
- if options.c:
- Config.add_config_parameters(options.c)
-
- config = Config('multimailhook')
-
- environment = None
- try:
- environment = choose_environment(
- config, osenv=os.environ,
- env=options.environment,
- recipients=options.recipients,
- hook_info=hook_info,
- )
-
- if options.show_env:
- show_env(environment, sys.stderr)
-
- if options.stdout or environment.stdout:
- mailer = OutputMailer(sys.stdout, environment)
- else:
- mailer = choose_mailer(config, environment)
-
- must_check_setup = os.environ.get('GIT_MULTIMAIL_CHECK_SETUP')
- if must_check_setup == '':
- must_check_setup = False
- if options.check_ref_filter:
- check_ref_filter(environment)
- elif must_check_setup:
- check_setup(environment)
- # Dual mode: if arguments were specified on the command line, run
- # like an update hook; otherwise, run as a post-receive hook.
- elif args:
- if len(args) != 3:
- parser.error('Need zero or three non-option arguments')
- (refname, oldrev, newrev) = args
- environment.get_logger().debug(
- "run_as_update_hook: refname=%s, oldrev=%s, newrev=%s, force_send=%s" %
- (refname, oldrev, newrev, options.force_send))
- run_as_update_hook(environment, mailer, refname, oldrev, newrev, options.force_send)
- else:
- run_as_post_receive_hook(environment, mailer)
- except ConfigurationException:
- sys.exit(sys.exc_info()[1])
- except SystemExit:
- raise
- except Exception:
- t, e, tb = sys.exc_info()
- import traceback
- sys.stderr.write('\n') # Avoid mixing message with previous output
- msg = (
- 'Exception \'' + t.__name__ +
- '\' raised. Please report this as a bug to\n'
- 'https://github.com/git-multimail/git-multimail/issues\n'
- 'with the information below:\n\n'
- 'git-multimail version ' + get_version() + '\n'
- 'Python version ' + sys.version + '\n' +
- traceback.format_exc())
- try:
- environment.get_logger().error(msg)
- except:
- sys.stderr.write(msg)
- sys.exit(1)
-
-
-if __name__ == '__main__':
- main(sys.argv[1:])
diff --git a/contrib/hooks/multimail/migrate-mailhook-config b/contrib/hooks/multimail/migrate-mailhook-config
deleted file mode 100755
index 241ba22..0000000
--- a/contrib/hooks/multimail/migrate-mailhook-config
+++ /dev/null
@@ -1,274 +0,0 @@
-#! /usr/bin/env python
-
-"""Migrate a post-receive-email configuration to be usable with git_multimail.py.
-
-See README.migrate-from-post-receive-email for more information.
-
-"""
-
-import sys
-import optparse
-
-from git_multimail import CommandError
-from git_multimail import Config
-from git_multimail import read_output
-
-
-OLD_NAMES = [
- 'mailinglist',
- 'announcelist',
- 'envelopesender',
- 'emailprefix',
- 'showrev',
- 'emailmaxlines',
- 'diffopts',
- 'scancommitforcc',
- ]
-
-NEW_NAMES = [
- 'environment',
- 'reponame',
- 'mailinglist',
- 'refchangelist',
- 'commitlist',
- 'announcelist',
- 'announceshortlog',
- 'envelopesender',
- 'administrator',
- 'emailprefix',
- 'emailmaxlines',
- 'diffopts',
- 'emaildomain',
- 'scancommitforcc',
- ]
-
-
-INFO = """\
-
-SUCCESS!
-
-Your post-receive-email configuration has been converted to
-git-multimail format. Please see README and
-README.migrate-from-post-receive-email to learn about other
-git-multimail configuration possibilities.
-
-For example, git-multimail has the following new options with no
-equivalent in post-receive-email. You might want to read about them
-to see if they would be useful in your situation:
-
-"""
-
-
-def _check_old_config_exists(old):
- """Check that at least one old configuration value is set."""
-
- for name in OLD_NAMES:
- if name in old:
- return True
-
- return False
-
-
-def _check_new_config_clear(new):
- """Check that none of the new configuration names are set."""
-
- retval = True
- for name in NEW_NAMES:
- if name in new:
- if retval:
- sys.stderr.write('INFO: The following configuration values already exist:\n\n')
- sys.stderr.write(' "%s.%s"\n' % (new.section, name))
- retval = False
-
- return retval
-
-
-def erase_values(config, names):
- for name in names:
- if name in config:
- try:
- sys.stderr.write('...unsetting "%s.%s"\n' % (config.section, name))
- config.unset_all(name)
- except CommandError:
- sys.stderr.write(
- '\nWARNING: could not unset "%s.%s". '
- 'Perhaps it is not set at the --local level?\n\n'
- % (config.section, name)
- )
-
-
-def is_section_empty(section, local):
- """Return True iff the specified configuration section is empty.
-
- Iff local is True, use the --local option when invoking 'git
- config'."""
-
- if local:
- local_option = ['--local']
- else:
- local_option = []
-
- try:
- read_output(
- ['git', 'config'] +
- local_option +
- ['--get-regexp', '^%s\.' % (section,)]
- )
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 1:
- # This means that no settings were found.
- return True
- else:
- raise
- else:
- return False
-
-
-def remove_section_if_empty(section):
- """If the specified configuration section is empty, delete it."""
-
- try:
- empty = is_section_empty(section, local=True)
- except CommandError:
- # Older versions of git do not support the --local option, so
- # if the first attempt fails, try without --local.
- try:
- empty = is_section_empty(section, local=False)
- except CommandError:
- sys.stderr.write(
- '\nINFO: If configuration section "%s.*" is empty, you might want '
- 'to delete it.\n\n'
- % (section,)
- )
- return
-
- if empty:
- sys.stderr.write('...removing section "%s.*"\n' % (section,))
- read_output(['git', 'config', '--remove-section', section])
- else:
- sys.stderr.write(
- '\nINFO: Configuration section "%s.*" still has contents. '
- 'It will not be deleted.\n\n'
- % (section,)
- )
-
-
-def migrate_config(strict=False, retain=False, overwrite=False):
- old = Config('hooks')
- new = Config('multimailhook')
- if not _check_old_config_exists(old):
- sys.exit(
- 'Your repository has no post-receive-email configuration. '
- 'Nothing to do.'
- )
- if not _check_new_config_clear(new):
- if overwrite:
- sys.stderr.write('\nWARNING: Erasing the above values...\n\n')
- erase_values(new, NEW_NAMES)
- else:
- sys.exit(
- '\nERROR: Refusing to overwrite existing values. Use the --overwrite\n'
- 'option to continue anyway.'
- )
-
- name = 'showrev'
- if name in old:
- msg = 'git-multimail does not support "%s.%s"' % (old.section, name,)
- if strict:
- sys.exit(
- 'ERROR: %s.\n'
- 'Please unset that value then try again, or run without --strict.'
- % (msg,)
- )
- else:
- sys.stderr.write('\nWARNING: %s (ignoring).\n\n' % (msg,))
-
- for name in ['mailinglist', 'announcelist']:
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- old_recipients = old.get_all(name, default=None)
- old_recipients = ', '.join(o.strip() for o in old_recipients)
- new.set_recipients(name, old_recipients)
-
- if strict:
- sys.stderr.write(
- '...setting "%s.commitlist" to the empty string\n' % (new.section,)
- )
- new.set_recipients('commitlist', '')
- sys.stderr.write(
- '...setting "%s.announceshortlog" to "true"\n' % (new.section,)
- )
- new.set('announceshortlog', 'true')
-
- for name in ['envelopesender', 'emailmaxlines', 'diffopts', 'scancommitforcc']:
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- new.set(name, old.get(name))
-
- name = 'emailprefix'
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- new.set(name, old.get(name))
- elif strict:
- sys.stderr.write(
- '...setting "%s.%s" to "[SCM]" to preserve old subject lines\n'
- % (new.section, name)
- )
- new.set(name, '[SCM]')
-
- if not retain:
- erase_values(old, OLD_NAMES)
- remove_section_if_empty(old.section)
-
- sys.stderr.write(INFO)
- for name in NEW_NAMES:
- if name not in OLD_NAMES:
- sys.stderr.write(' "%s.%s"\n' % (new.section, name,))
- sys.stderr.write('\n')
-
-
-def main(args):
- parser = optparse.OptionParser(
- description=__doc__,
- usage='%prog [OPTIONS]',
- )
-
- parser.add_option(
- '--strict', action='store_true', default=False,
- help=(
- 'Slavishly configure git-multimail as closely as possible to '
- 'the post-receive-email configuration. Default is to turn '
- 'on some new features that have no equivalent in post-receive-email.'
- ),
- )
- parser.add_option(
- '--retain', action='store_true', default=False,
- help=(
- 'Retain the post-receive-email configuration values. '
- 'Default is to delete them after the new values are set.'
- ),
- )
- parser.add_option(
- '--overwrite', action='store_true', default=False,
- help=(
- 'Overwrite any existing git-multimail configuration settings. '
- 'Default is to abort if such settings already exist.'
- ),
- )
-
- (options, args) = parser.parse_args(args)
-
- if args:
- parser.error('Unexpected arguments: %s' % (' '.join(args),))
-
- migrate_config(strict=options.strict, retain=options.retain, overwrite=options.overwrite)
-
-
-main(sys.argv[1:])
diff --git a/contrib/hooks/multimail/post-receive.example b/contrib/hooks/multimail/post-receive.example
deleted file mode 100755
index 0f98c5a..0000000
--- a/contrib/hooks/multimail/post-receive.example
+++ /dev/null
@@ -1,101 +0,0 @@
-#! /usr/bin/env python
-
-"""Example post-receive hook based on git-multimail.
-
-The simplest way to use git-multimail is to use the script
-git_multimail.py directly as a post-receive hook, and to configure it
-using Git's configuration files and command-line parameters. You can
-also write your own Python wrapper for more advanced configurability,
-using git_multimail.py as a Python module.
-
-This script is a simple example of such a post-receive hook. It is
-intended to be customized before use; see the comments in the script
-to help you get started.
-
-Using git-multimail as a Python module as done here provides more
-flexibility. It has the following advantages:
-
-* The tool's behavior can be customized using arbitrary Python code,
- without having to edit git_multimail.py.
-
-* Configuration settings can be read from other sources; for example,
- user names and email addresses could be read from LDAP or from a
- database. Or the settings can even be hardcoded in the importing
- Python script, if this is preferred.
-
-This script is a very basic example of how to use git_multimail.py as
-a module. The comments below explain some of the points at which the
-script's behavior could be changed or customized.
-
-"""
-
-import sys
-
-# If necessary, add the path to the directory containing
-# git_multimail.py to the Python path as follows. (This is not
-# necessary if git_multimail.py is in the same directory as this
-# script):
-
-#LIBDIR = 'path/to/directory/containing/module'
-#sys.path.insert(0, LIBDIR)
-
-import git_multimail
-
-# It is possible to modify the output templates here; e.g.:
-
-#git_multimail.FOOTER_TEMPLATE = """\
-#
-#-- \n\
-#This email was generated by the wonderful git-multimail tool.
-#"""
-
-
-# Specify which "git config" section contains the configuration for
-# git-multimail:
-config = git_multimail.Config('multimailhook')
-
-# Set some Git configuration variables. Equivalent to passing var=val
-# to "git -c var=val" each time git is called, or to adding the
-# configuration in .git/config (must come before instantiating the
-# environment) :
-#git_multimail.Config.add_config_parameters('multimailhook.commitEmailFormat=html')
-#git_multimail.Config.add_config_parameters(('user.name=foo', 'user.email=foo@example.com'))
-
-# Select the type of environment:
-try:
- environment = git_multimail.GenericEnvironment(config=config)
- #environment = git_multimail.GitoliteEnvironment(config=config)
-except git_multimail.ConfigurationException:
- sys.stderr.write('*** %s\n' % sys.exc_info()[1])
- sys.exit(1)
-
-
-# Choose the method of sending emails based on the git config:
-mailer = git_multimail.choose_mailer(config, environment)
-
-# Alternatively, you may hardcode the mailer using code like one of
-# the following:
-
-# Use "/usr/sbin/sendmail -oi -t" to send emails. The envelopesender
-# argument is optional:
-#mailer = git_multimail.SendMailer(
-# command=['/usr/sbin/sendmail', '-oi', '-t'],
-# envelopesender='git-repo@example.com',
-# )
-
-# Use Python's smtplib to send emails. Both arguments are required.
-#mailer = git_multimail.SMTPMailer(
-# environment=environment,
-# envelopesender='git-repo@example.com',
-# # The smtpserver argument can also include a port number; e.g.,
-# # smtpserver='mail.example.com:25'
-# smtpserver='mail.example.com',
-# )
-
-# OutputMailer is intended only for testing; it writes the emails to
-# the specified file stream.
-#mailer = git_multimail.OutputMailer(sys.stdout)
-
-
-# Read changes from stdin and send notification emails:
-git_multimail.run_as_post_receive_hook(environment, mailer)
diff --git a/contrib/mw-to-git/Git/Mediawiki.pm b/contrib/mw-to-git/Git/Mediawiki.pm
index 917d9e2..ff78112 100644
--- a/contrib/mw-to-git/Git/Mediawiki.pm
+++ b/contrib/mw-to-git/Git/Mediawiki.pm
@@ -1,6 +1,6 @@
package Git::Mediawiki;
-use 5.008;
+use 5.008001;
use strict;
use POSIX;
use Git;
diff --git a/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh b/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
index 4c39bda..f08890d 100755
--- a/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
+++ b/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
@@ -86,7 +86,7 @@ test_expect_success 'Git clone works with page added' '
test_expect_success 'Git clone works with an edited page ' '
wiki_reset &&
wiki_editpage foo "this page will be edited" \
- false -s "first edition of page foo"&&
+ false -s "first edition of page foo" &&
wiki_editpage foo "this page has been edited and must be on the clone " true &&
git clone mediawiki::'"$WIKI_URL"' mw_dir_6 &&
test_path_is_file mw_dir_6/Foo.mw &&
diff --git a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
index 6b0dbda..526d928 100755
--- a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
+++ b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
@@ -287,7 +287,7 @@ test_expect_success 'git push with \' '
git add \\ko\\o.mw &&
git commit -m " \\ko\\o added" &&
git push
- )&&
+ ) &&
wiki_page_exist \\ko\\o &&
wiki_check_content mw_dir_18/\\ko\\o.mw \\ko\\o
@@ -311,7 +311,7 @@ test_expect_success 'git push with \ in format control' '
git add \\fo\\o.mw &&
git commit -m " \\fo\\o added" &&
git push
- )&&
+ ) &&
wiki_page_exist \\fo\\o &&
wiki_check_content mw_dir_20/\\fo\\o.mw \\fo\\o
diff --git a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
index 6187ec6..7139995 100755
--- a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
+++ b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
@@ -161,7 +161,7 @@ test_expect_success 'git push properly warns about insufficient permissions' '
git add foo.forbidden &&
git commit -m "add a file" &&
git push 2>actual &&
- test_i18ngrep "foo.forbidden is not a permitted file" actual
+ test_grep "foo.forbidden is not a permitted file" actual
)
'
diff --git a/contrib/mw-to-git/t/t9365-continuing-queries.sh b/contrib/mw-to-git/t/t9365-continuing-queries.sh
index 0164547..d3e7312 100755
--- a/contrib/mw-to-git/t/t9365-continuing-queries.sh
+++ b/contrib/mw-to-git/t/t9365-continuing-queries.sh
@@ -12,7 +12,7 @@ test_expect_success 'creating page w/ >500 revisions' '
for i in $(test_seq 501)
do
echo "creating revision $i" &&
- wiki_editpage foo "revision $i<br/>" true
+ wiki_editpage foo "revision $i<br/>" true || return 1
done
'
diff --git a/contrib/rerere-train.sh b/contrib/rerere-train.sh
index eeee45d..bd01e43 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
@@ -86,12 +86,12 @@ do
fi
if test -s "$GIT_DIR/MERGE_RR"
then
- git show -s --pretty=format:"Learning from %h %s" "$commit"
+ git --no-pager show -s --format="Learning from %h %s" "$commit"
git rerere
git checkout -q $commit -- .
git rerere
fi
- git reset -q --hard
+ git reset -q --hard # Might nuke untracked files...
done
if test -z "$branch"
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index b06782b..5dab3f5 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,8 +5,12 @@
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
#
-if test -z "$GIT_EXEC_PATH" || test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup"
+if test -z "$GIT_EXEC_PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" || {
+ test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" &&
+ test ! "$GIT_EXEC_PATH" -ef "${PATH%%:*}" 2>/dev/null
+}
then
+ basename=${0##*[/\\]}
echo >&2 'It looks like either your git installation or your'
echo >&2 'git-subtree installation is broken.'
echo >&2
@@ -14,10 +18,10 @@ then
echo >&2 " - If \`git --exec-path\` does not print the correct path to"
echo >&2 " your git install directory, then set the GIT_EXEC_PATH"
echo >&2 " environment variable to the correct directory."
- echo >&2 " - Make sure that your \`${0##*/}\` file is either in your"
+ echo >&2 " - Make sure that your \`$basename\` file is either in your"
echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)."
- echo >&2 " - You should run git-subtree as \`git ${0##*/git-}\`,"
- echo >&2 " not as \`${0##*/}\`." >&2
+ echo >&2 " - You should run git-subtree as \`git ${basename#git-}\`,"
+ echo >&2 " not as \`$basename\`." >&2
exit 126
fi
@@ -29,23 +33,31 @@ git subtree split --prefix=<prefix> [<commit>]
git subtree pull --prefix=<prefix> <repository> <ref>
git subtree push --prefix=<prefix> <repository> <refspec>
--
-h,help show the help
-q quiet
-d show debug messages
+h,help! show the help
+q,quiet! quiet
+d,debug! show debug messages
P,prefix= the name of the subdir to split out
options for 'split' (also: 'push')
annotate= add a prefix to commit message of new commits
-b,branch= create a new branch from the split subtree
+b,branch!= create a new branch from the split subtree
ignore-joins ignore prior --rejoin commits
onto= try connecting new tree to an existing one
rejoin merge the new branch back into HEAD
options for 'add' and 'merge' (also: 'pull', 'split --rejoin', and 'push --rejoin')
squash merge subtree changes as a single commit
-m,message= use the given message as the commit message for the merge commit
+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"
@@ -56,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
@@ -86,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
@@ -135,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=
@@ -157,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
;;
@@ -181,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
;;
@@ -189,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
@@ -231,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
@@ -261,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
}
@@ -292,10 +313,9 @@ cache_miss () {
done
}
-# Usage: check_parents PARENTS_EXPR
+# Usage: check_parents [REVS...]
check_parents () {
- assert test $# = 1
- missed=$(cache_miss "$1") || exit $?
+ missed=$(cache_miss "$@") || exit $?
local indent=$(($indent + 1))
for miss in $missed
do
@@ -322,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"
}
@@ -351,13 +371,49 @@ 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 $# -ge 2
+ assert test $# -le 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 $# -ge 1
+ assert test $# -le 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=
@@ -375,8 +431,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"
@@ -400,14 +455,20 @@ 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 $# -ge 2
+ assert test $# -le 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/*\$"
@@ -427,18 +488,17 @@ 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'"
- if test -z "$main" -a -n "$sub"
+ if test -z "$main" && test -n "$sub"
then
# squash commits refer to a subtree
debug " Squash: $sq from $sub"
cache_set "$sq" "$sub"
fi
- if test -n "$main" -a -n "$sub"
+ if test -n "$main" && test -n "$sub"
then
debug " Prior: $main -> $sub"
cache_set $main $sub
@@ -478,7 +538,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
@@ -581,10 +641,16 @@ subtree_for_commit () {
while read mode type tree name
do
assert test "$name" = "$dir"
- assert test "$type" = "tree" -o "$type" = "commit"
- test "$type" = "commit" && continue # ignore submodules
- echo $tree
- break
+
+ case "$type" in
+ commit)
+ continue;; # ignore submodules
+ tree)
+ echo $tree
+ break;;
+ *)
+ die "fatal: tree entry is of type ${type}, expected tree or commit";;
+ esac
done || exit $?
}
@@ -706,11 +772,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
}
@@ -718,7 +784,23 @@ 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: check if a commit from another subtree should be
+# ignored from processing for splits
+should_ignore_subtree_split_commit () {
+ assert test $# = 1
+ local rev="$1"
+ if test -n "$(git log -1 --grep="git-subtree-dir:" $rev)"
+ then
+ if test -z "$(git log -1 --grep="git-subtree-mainline:" $rev)" &&
+ test -z "$(git log -1 --grep="git-subtree-dir: $arg_prefix$" $rev)"
+ then
+ return 0
+ fi
+ fi
+ return 1
}
# Usage: process_split_commit REV PARENTS
@@ -749,7 +831,7 @@ process_split_commit () {
fi
createcount=$(($createcount + 1))
debug "parents: $parents"
- check_parents "$parents"
+ check_parents $parents
newparents=$(cache_get $parents) || exit $?
debug "newparents: $newparents"
@@ -784,7 +866,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 "$@"
@@ -799,7 +881,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
}
@@ -831,7 +913,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"
@@ -854,17 +936,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 || test $# -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"
@@ -888,7 +975,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.
@@ -901,13 +988,25 @@ cmd_split () {
eval "$grl" |
while read rev parents
do
- process_split_commit "$rev" "$parents"
+ if should_ignore_subtree_split_commit "$rev"
+ then
+ continue
+ fi
+ parsedparents=''
+ for parent in $parents
+ do
+ if ! should_ignore_subtree_split_commit "$parent"
+ then
+ parsedparents="$parsedparents$parent "
+ fi
+ done
+ process_split_commit "$rev" "$parsedparents"
done || exit $?
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"
@@ -928,7 +1027,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
@@ -942,20 +1041,28 @@ 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: '$*'"
+ if test $# -lt 1 || test $# -gt 2
+ then
+ die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
+ fi
+
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
@@ -972,10 +1079,10 @@ cmd_merge () {
if test -n "$arg_addmerge_message"
then
- git merge -Xsubtree="$arg_prefix" \
+ git merge --no-ff -Xsubtree="$arg_prefix" \
--message="$arg_addmerge_message" "$rev"
else
- git merge -Xsubtree="$arg_prefix" $rev
+ git merge --no-ff -Xsubtree="$arg_prefix" $rev
fi
}
@@ -983,19 +1090,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
@@ -1010,13 +1119,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 9cddfa2..004abf4 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 276898e..093399c 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
@@ -73,9 +74,7 @@ aggregate-results-and-cleanup: $(T)
$(MAKE) clean
aggregate-results:
- for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
- echo "$$f"; \
- done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
+ @'$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)'
valgrind:
$(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 4153b65..c3bd2a5 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -43,11 +43,35 @@ 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=$(sed -e "s/$commit/$tag/" msg | 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 &&
grep -e "^ *or: git subtree pull" out &&
- grep -e --annotate out
+ grep -F -e "--[no-]annotate" out
'
#
@@ -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" &&
@@ -354,6 +385,46 @@ test_expect_success 'split sub dir/ with --rejoin' '
)
'
+# Tests that commits from other subtrees are not processed as
+# part of a split.
+#
+# This test performs the following:
+# - Creates Repo with subtrees 'subA' and 'subB'
+# - Creates commits in the repo including changes to subtrees
+# - Runs the following 'split' and commit' commands in order:
+# - Perform 'split' on subtree A
+# - Perform 'split' on subtree B
+# - Create new commits with changes to subtree A and B
+# - Perform split on subtree A
+# - Check that the commits in subtree B are not processed
+# as part of the subtree A split
+test_expect_success 'split with multiple subtrees' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/subA" &&
+ subtree_test_create_repo "$test_count/subB" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/subA" subA1 &&
+ test_create_commit "$test_count/subA" subA2 &&
+ test_create_commit "$test_count/subA" subA3 &&
+ test_create_commit "$test_count/subB" subB1 &&
+ git -C "$test_count" fetch ./subA HEAD &&
+ git -C "$test_count" subtree add --prefix=subADir FETCH_HEAD &&
+ git -C "$test_count" fetch ./subB HEAD &&
+ git -C "$test_count" subtree add --prefix=subBDir FETCH_HEAD &&
+ test_create_commit "$test_count" subADir/main-subA1 &&
+ test_create_commit "$test_count" subBDir/main-subB1 &&
+ git -C "$test_count" subtree split --prefix=subADir \
+ --squash --rejoin -m "Sub A Split 1" &&
+ git -C "$test_count" subtree split --prefix=subBDir \
+ --squash --rejoin -m "Sub B Split 1" &&
+ test_create_commit "$test_count" subADir/main-subA2 &&
+ test_create_commit "$test_count" subBDir/main-subB2 &&
+ git -C "$test_count" subtree split --prefix=subADir \
+ --squash --rejoin -m "Sub A Split 2" &&
+ test "$(git -C "$test_count" subtree split --prefix=subBDir \
+ --squash --rejoin -d -m "Sub B Split 1" 2>&1 | grep -w "\[1\]")" = ""
+'
+
test_expect_success 'split sub dir/ with --rejoin from scratch' '
subtree_test_create_repo "$test_count" &&
test_create_commit "$test_count" main1 &&
@@ -551,6 +622,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 +647,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 +661,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 +707,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 +725,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 +744,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 +1035,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
#
@@ -1445,7 +1533,7 @@ test_expect_success 'subtree descendant check' '
) &&
test_create_commit "$test_count" folder_subtree/0 &&
test_create_commit "$test_count" folder_subtree/b &&
- cherry=$(cd "$test_count"; git rev-parse HEAD) &&
+ cherry=$(cd "$test_count" && git rev-parse HEAD) &&
(
cd "$test_count" &&
git checkout branch
diff --git a/contrib/vscode/README.md b/contrib/vscode/README.md
index 8202d62..f383c95 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 27de949..f2d61bb 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": {
@@ -88,7 +92,6 @@ cat >.vscode/settings.json.new <<\EOF ||
"isexe",
"iskeychar",
"kompare",
- "mksnpath",
"mktag",
"mktree",
"mmblob",
@@ -271,7 +274,6 @@ cat >.vscode/launch.json.new <<EOF ||
"stopAtEntry": false,
"cwd": "\${workspaceFolder}",
"environment": [],
- "externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "$GDBPATH",
"setupCommands": [
diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
index 888c34a..989197a 100755
--- a/contrib/workdir/git-new-workdir
+++ b/contrib/workdir/git-new-workdir
@@ -79,7 +79,7 @@ trap cleanup $siglist
# create the links to the original repo. explicitly exclude index, HEAD and
# logs/HEAD from the list since they are purely related to the current working
# directory, and should not be shared.
-for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
+for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn reftable
do
# create a containing directory if needed
case $x in