Skip to content

Commit

Permalink
Merge pull request #6455 from libgit2/ethomson/sysdir
Browse files Browse the repository at this point in the history
Support the notion of a home directory separately from global configuration directory
  • Loading branch information
ethomson committed Feb 14, 2023
2 parents 1119326 + e0220e6 commit f7963f2
Show file tree
Hide file tree
Showing 27 changed files with 772 additions and 455 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/main.yml
Expand Up @@ -133,19 +133,25 @@ jobs:
- name: "Windows (amd64, Visual Studio)"
id: windows-amd64-vs
os: windows-2019
setup-script: win32
env:
ARCH: amd64
CMAKE_GENERATOR: Visual Studio 16 2019
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2
BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin
BUILD_TEMP: D:\Temp
SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true
- name: "Windows (x86, Visual Studio)"
id: windows-x86-vs
os: windows-2019
setup-script: win32
env:
ARCH: x86
CMAKE_GENERATOR: Visual Studio 16 2019
CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2
BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin
BUILD_TEMP: D:\Temp
SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true
- name: "Windows (amd64, mingw)"
Expand Down Expand Up @@ -283,6 +289,10 @@ jobs:
- name: Build and test
run: |
export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
export GITTEST_GITHUB_SSH_KEY="${{ secrets.GITTEST_GITHUB_SSH_KEY }}"
export GITTEST_GITHUB_SSH_PUBKEY="${{ secrets.GITTEST_GITHUB_SSH_PUBKEY }}"
export GITTEST_GITHUB_SSH_PASSPHRASE="${{ secrets.GITTEST_GITHUB_SSH_PASSPHRASE }}"
export GITTEST_GITHUB_SSH_REMOTE_HOSTKEY="${{ secrets.GITTEST_GITHUB_SSH_REMOTE_HOSTKEY }}"
if [ -n "${{ matrix.platform.container.name }}" ]; then
mkdir build
Expand Down
20 changes: 17 additions & 3 deletions ci/build.sh
Expand Up @@ -13,16 +13,30 @@ BUILD_PATH=${BUILD_PATH:=$PATH}
CMAKE=$(which cmake)
CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}

indent() { sed "s/^/ /"; }

cygfullpath() {
result=$(echo "${1}" | tr \; \\n | while read -r element; do
if [ "${last}" != "" ]; then echo -n ":"; fi
echo -n $(cygpath "${element}")
last="${element}"
done)
if [ "${result}" = "" ]; then exit 1; fi
echo "${result}"
}
if [[ "$(uname -s)" == MINGW* ]]; then
BUILD_PATH=$(cygpath "$BUILD_PATH")
BUILD_PATH=$(cygfullpath "${BUILD_PATH}")
fi
indent() { sed "s/^/ /"; }
echo "Source directory: ${SOURCE_DIR}"
echo "Build directory: ${BUILD_DIR}"
echo ""
echo "Platform:"
uname -s | indent
if [ "$(uname -s)" = "Darwin" ]; then
echo "macOS version:"
sw_vers | indent
Expand All @@ -40,7 +54,7 @@ echo "Kernel version:"
uname -a 2>&1 | indent
echo "CMake version:"
env PATH="${BUILD_PATH}" "${CMAKE}" --version 2>&1 | indent
env PATH="${BUILD_PATH}" "${CMAKE}" --version | head -1 2>&1 | indent
if test -n "${CC}"; then
echo "Compiler version:"
Expand Down
4 changes: 2 additions & 2 deletions ci/setup-mingw-build.sh
Expand Up @@ -11,9 +11,9 @@ BUILD_TEMP=$(cygpath $BUILD_TEMP)

case "$ARCH" in
amd64)
MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-01-23/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
x86)
MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-01-23/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
esac

if [ -z "$MINGW_URI" ]; then
Expand Down
27 changes: 27 additions & 0 deletions ci/setup-win32-build.sh
@@ -0,0 +1,27 @@
#!/bin/sh

set -ex

echo "##############################################################################"
echo "## Downloading libssh2"
echo "##############################################################################"

BUILD_TEMP=${BUILD_TEMP:=$TEMP}
BUILD_TEMP=$(cygpath $BUILD_TEMP)

case "$ARCH" in
amd64)
LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01/libssh2-20230201-amd64.zip";;
x86)
LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01-v2/libssh2-20230201-x86.zip";;
esac

if [ -z "$LIBSSH2_URI" ]; then
echo "No URL"
exit 1
fi

mkdir -p "$BUILD_TEMP"

curl -s -L "$LIBSSH2_URI" -o "$BUILD_TEMP"/libssh2-"$ARCH".zip
unzip -q "$BUILD_TEMP"/libssh2-"$ARCH".zip -d "$BUILD_TEMP"
36 changes: 33 additions & 3 deletions ci/test.sh
Expand Up @@ -13,9 +13,14 @@ fi

SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
BUILD_DIR=$(pwd)
BUILD_PATH=${BUILD_PATH:=$PATH}
CTEST=$(which ctest)
TMPDIR=${TMPDIR:-/tmp}
USER=${USER:-$(whoami)}

HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
export CLAR_HOMEDIR=${HOME}

SUCCESS=1
CONTINUE_ON_FAILURE=0

Expand Down Expand Up @@ -72,7 +77,11 @@ run_test() {

RETURN_CODE=0

CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
(
export PATH="${BUILD_PATH}"
export CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml"
"${CTEST}" -V -R "^${1}$"
) || RETURN_CODE=$? && true

if [ "$RETURN_CODE" -eq 0 ]; then
FAILED=0
Expand All @@ -93,9 +102,31 @@ run_test() {
fi
}

indent() { sed "s/^/ /"; }

cygfullpath() {
result=$(echo "${1}" | tr \; \\n | while read -r element; do
if [ "${last}" != "" ]; then echo -n ":"; fi
echo -n $(cygpath "${element}")
last="${element}"
done)
if [ "${result}" = "" ]; then exit 1; fi
echo "${result}"
}
if [[ "$(uname -s)" == MINGW* ]]; then
BUILD_PATH=$(cygfullpath "$BUILD_PATH")
fi
# Configure the test environment; run them early so that we're certain
# that they're started by the time we need them.
echo "CTest version:"
env PATH="${BUILD_PATH}" "${CTEST}" --version | head -1 2>&1 | indent
echo ""
echo "##############################################################################"
echo "## Configuring test environment"
echo "##############################################################################"
Expand Down Expand Up @@ -140,7 +171,6 @@ fi
if [ -z "$SKIP_SSH_TESTS" ]; then
echo "Starting SSH server..."
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
git init --bare "${SSHD_DIR}/test.git" >/dev/null
cat >"${SSHD_DIR}/sshd_config" <<-EOF
Expand Down Expand Up @@ -384,7 +414,7 @@ if [ -z "$SKIP_FUZZERS" ]; then
echo "## Running fuzzers"
echo "##############################################################################"
ctest -V -R 'fuzzer'
env PATH="${BUILD_PATH}" "${CTEST}" -V -R 'fuzzer'
fi
cleanup
Expand Down
14 changes: 13 additions & 1 deletion include/git2/common.h
Expand Up @@ -222,7 +222,9 @@ typedef enum {
GIT_OPT_GET_EXTENSIONS,
GIT_OPT_SET_EXTENSIONS,
GIT_OPT_GET_OWNER_VALIDATION,
GIT_OPT_SET_OWNER_VALIDATION
GIT_OPT_SET_OWNER_VALIDATION,
GIT_OPT_GET_HOMEDIR,
GIT_OPT_SET_HOMEDIR
} git_libgit2_opt_t;

/**
Expand Down Expand Up @@ -468,6 +470,16 @@ typedef enum {
* > Set that repository directories should be owned by the current
* > user. The default is to validate ownership.
*
* opts(GIT_OPT_GET_HOMEDIR, git_buf *out)
* > Gets the current user's home directory, as it will be used
* > for file lookups. The path is written to the `out` buffer.
*
* opts(GIT_OPT_SET_HOMEDIR, const char *path)
* > Sets the directory used as the current user's home directory,
* > for file lookups.
* >
* > - `path` directory of home directory.
*
* @param option Option key
* @param ... value to set the option
* @return 0 on success, <0 on failure
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/attrcache.c
Expand Up @@ -300,7 +300,7 @@ static int attr_cache__lookup_path(

/* expand leading ~/ as needed */
if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
if (! (error = git_sysdir_expand_homedir_file(&buf, &cfgval[2])))
*out = git_str_detach(&buf);
} else if (cfgval) {
*out = git__strdup(cfgval);
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/config.c
Expand Up @@ -860,7 +860,7 @@ static int git_config__parse_path(git_str *out, const char *value)
return -1;
}

return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
return git_sysdir_expand_homedir_file(out, value[1] ? &value[2] : NULL);
}

return git_str_sets(out, value);
Expand Down
4 changes: 2 additions & 2 deletions src/libgit2/config_file.c
Expand Up @@ -528,7 +528,7 @@ static int included_path(git_str *out, const char *dir, const char *path)
{
/* From the user's home */
if (path[0] == '~' && path[1] == '/')
return git_sysdir_expand_global_file(out, &path[1]);
return git_sysdir_expand_homedir_file(out, &path[1]);

return git_fs_path_join_unrooted(out, path, dir, NULL);
}
Expand Down Expand Up @@ -616,7 +616,7 @@ static int do_match_gitdir(
git_fs_path_dirname_r(&pattern, cfg_file);
git_str_joinpath(&pattern, pattern.ptr, condition + 2);
} else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1]))
git_sysdir_expand_global_file(&pattern, condition + 1);
git_sysdir_expand_homedir_file(&pattern, condition + 1);
else if (!git_fs_path_is_absolute(condition))
git_str_joinpath(&pattern, "**", condition);
else
Expand Down
19 changes: 19 additions & 0 deletions src/libgit2/libgit2.c
Expand Up @@ -414,6 +414,25 @@ int git_libgit2_opts(int key, ...)
git_repository__validate_ownership = (va_arg(ap, int) != 0);
break;

case GIT_OPT_GET_HOMEDIR:
{
git_buf *out = va_arg(ap, git_buf *);
git_str str = GIT_STR_INIT;
const git_str *tmp;

if ((error = git_buf_tostr(&str, out)) < 0 ||
(error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 ||
(error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
break;

error = git_buf_fromstr(out, &str);
}
break;

case GIT_OPT_SET_HOMEDIR:
error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *));
break;

default:
git_error_set(GIT_ERROR_INVALID, "invalid option key");
error = -1;
Expand Down

0 comments on commit f7963f2

Please sign in to comment.