10000 Merge pull request #6455 from libgit2/ethomson/sysdir · libgit2/libgit2@f7963f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7963f2

Browse files
authored
Merge pull request #6455 from libgit2/ethomson/sysdir
Support the notion of a home directory separately from global configuration directory
2 parents 1119326 + e0220e6 commit f7963f2

27 files changed

+772
-455
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,25 @@ jobs:
133133
- name: "Windows (amd64, Visual Studio)"
134134
id: windows-amd64-vs
135135
os: windows-2019
136+
setup-script: win32
136137
env:
137138
ARCH: amd64
138139
CMAKE_GENERATOR: Visual Studio 16 2019
139-
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
140+
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2
141+
BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin
142+
BUILD_TEMP: D:\Temp
140143
SKIP_SSH_TESTS: true
141144
SKIP_NEGOTIATE_TESTS: true
142145
- name: "Windows (x86, Visual Studio)"
143146
id: windows-x86-vs
144147
os: windows-2019
148+
setup-script: win32
145149
env:
146150
ARCH: x86
147151
CMAKE_GENERATOR: Visual Studio 16 2019
148-
CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
152+
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
153+
BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin
154+
BUILD_TEMP: D:\Temp
149155
SKIP_SSH_TESTS: true
150156
SKIP_NEGOTIATE_TESTS: true
151157
- name: "Windows (amd64, mingw)"
@@ -283,6 +289,10 @@ jobs:
283289
- name: Build and test
284290
run: |
285291
export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
292+
export GITTEST_GITHUB_SSH_KEY="${{ secrets.GITTEST_GITHUB_SSH_KEY }}"
293+
export GITTEST_GITHUB_SSH_PUBKEY="${{ secrets.GITTEST_GITHUB_SSH_PUBKEY }}"
294+
export GITTEST_GITHUB_SSH_PASSPHRASE="${{ secrets.GITTEST_GITHUB_SSH_PASSPHRASE }}"
295+
export GITTEST_GITHUB_SSH_REMOTE_HOSTKEY="${{ secrets.GITTEST_GITHUB_SSH_REMOTE_HOSTKEY }}"
286296
287297
if [ -n "${{ matrix.platform.container.name }}" ]; then
288298
mkdir build

ci/build.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,30 @@ BUILD_PATH=${BUILD_PATH:=$PATH}
1313
CMAKE=$(which cmake)
1414
CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
1515

16+
indent() { sed "s/^/ /"; }
17+
18+
cygfullpath() {
19+
result=$(echo "${1}" | tr \; \\n | while read -r element; do
20+
if [ "${last}" != "" ]; then echo -n ":"; fi
21+
echo -n $(cygpath "${element}")
22+
last="${element}"
23+
done)
24+
if [ "${result}" = "" ]; then exit 1; fi
25+
echo "${result}"
26+
}
27+
1628
if [[ "$(uname -s)" == MINGW* ]]; then
17-
BUILD_PATH=$(cygpath "$BUILD_PATH")
29+
BUILD_PATH=$(cygfullpath "${BUILD_PATH}")
1830
fi
1931
20-
indent() { sed "s/^/ /"; }
2132
2233
echo "Source directory: ${SOURCE_DIR}"
2334
echo "Build directory: ${BUILD_DIR}"
2435
echo ""
2536
37+
echo "Platform:"
38+
uname -s | indent
39+
2640
if [ "$(uname -s)" = "Darwin" ]; then
2741
echo "macOS version:"
2842
sw_vers | indent
@@ -40,7 +54,7 @@ echo "Kernel version:"
4054
uname -a 2>&1 | indent
4155
4256
echo "CMake version:"
43-
env PATH="${BUILD_PATH}" "${CMAKE}" --version 2>&1 | indent
57+
env PATH="${BUILD_PATH}" "${CMAKE}" --version | head -1 2>&1 | indent
4458
4559
if test -n "${CC}"; then
4660
echo "Compiler version:"

ci/setup-mingw-build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ BUILD_TEMP=$(cygpath $BUILD_TEMP)
1111

1212
case "$ARCH" in
1313
amd64)
14-
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";;
14+
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";;
1515
x86)
16-
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";;
16+
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";;
1717
esac
1818

1919
if [ -z "$MINGW_URI" ]; then

ci/setup-win32-build.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
echo "##############################################################################"
6+
echo "## Downloading libssh2"
7+
echo "##############################################################################"
8+
9+
BUILD_TEMP=${BUILD_TEMP:=$TEMP}
10+
BUILD_TEMP=$(cygpath $BUILD_TEMP)
11+
12+
case "$ARCH" in
13+
amd64)
14+
LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01/libssh2-20230201-amd64.zip";;
15+
x86)
16+
LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01-v2/libssh2-20230201-x86.zip";;
17+
esac
18+
19+
if [ -z "$LIBSSH2_URI" ]; then
20+
echo "No URL"
21+
exit 1
22+
fi
23+
24+
mkdir -p "$BUILD_TEMP"
25+
26+
curl -s -L "$LIBSSH2_URI" -o "$BUILD_TEMP"/libssh2-"$ARCH".zip
27+
unzip -q "$BUILD_TEMP"/libssh2-"$ARCH".zip -d "$BUILD_TEMP"

ci/test.sh

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ fi
1313

1414
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
1515
BUILD_DIR=$(pwd)
16+
BUILD_PATH=${BUILD_PATH:=$PATH}
17+
CTEST=$(which ctest)
1618
TMPDIR=${TMPDIR:-/tmp}
1719
USER=${USER:-$(whoami)}
1820

21+
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
22+
export CLAR_HOMEDIR=${HOME}
23+
1924
SUCCESS=1
2025
CONTINUE_ON_FAILURE=0
2126

@@ -72,7 +77,11 @@ run_test() {
7277

7378
RETURN_CODE=0
7479

75-
CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
80+
(
81+
export PATH="${BUILD_PATH}"
82+
export CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml"
83+
"${CTEST}" -V -R "^${1}$"
84+
) || RETURN_CODE=$? && true
7685

7786
if [ "$RETURN_CODE" -eq 0 ]; then
7887
FAILED=0
@@ -93,9 +102,31 @@ run_test() {
93102
fi
94103
}
95104

105+
indent() { sed "s/^/ /"; }
106+
107+
cygfullpath() {
108+
result=$(echo "${1}" | tr \; \\n | while read -r element; do
109+
if [ "${last}" != "" ]; then echo -n ":"; fi
110+
echo -n $(cygpath "${element}")
111+
last="${element}"
112+
done)
113+
if [ "${result}" = "" ]; then exit 1; fi
114+
echo "${result}"
115+
}
116+
117+
if [[ "$(uname -s)" == MINGW* ]]; then
118+
BUILD_PATH=$(cygfullpath "$BUILD_PATH")
119+
fi
120+
121+
96122
# Configure the test environment; run them early so that we're certain
97123
# that they're started by the time we need them.
98124
125+
echo "CTest version:"
126+
env PATH="${BUILD_PATH}" "${CTEST}" --version | head -1 2>&1 | indent
127+
128+
echo ""
129+
99130
echo "##############################################################################"
100131
echo "## Configuring test environment"
101132
echo "##############################################################################"
@@ -140,7 +171,6 @@ fi
140171
141172
if [ -z "$SKIP_SSH_TESTS" ]; then
142173
echo "Starting SSH server..."
143-
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
144174
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
145175
git init --bare "${SSHD_DIR}/test.git" >/dev/null
146176
cat >"${SSHD_DIR}/sshd_config" <<-EOF
@@ -384,7 +414,7 @@ if [ -z "$SKIP_FUZZERS" ]; then
384414
echo "## Running fuzzers"
385415
echo "##############################################################################"
386416
387-
ctest -V -R 'fuzzer'
417+
env PATH="${BUILD_PATH}" "${CTEST}" -V -R 'fuzzer'
388418
fi
389419
390420
cleanup

include/git2/common.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ typedef enum {
222222
GIT_OPT_GET_EXTENSIONS,
223223
GIT_OPT_SET_EXTENSIONS,
224224
GIT_OPT_GET_OWNER_VALIDATION,
225-
GIT_OPT_SET_OWNER_VALIDATION
225+
GIT_OPT_SET_OWNER_VALIDATION,
226+
GIT_OPT_GET_HOMEDIR,
227+
GIT_OPT_SET_HOMEDIR
226228
} git_libgit2_opt_t;
227229

228230
/**
@@ -468,6 +470,16 @@ typedef enum {
468470
* > Set that repository directories should be owned by the current
469471
* > user. The default is to validate ownership.
470472
*
473+
* opts(GIT_OPT_GET_HOMEDIR, git_buf *out)
474+
* > Gets the current user's home directory, as it will be used
475+
* > for file lookups. The path is written to the `out` buffer.
476+
*
477+
* opts(GIT_OPT_SET_HOMEDIR, const char *path)
478+
* > Sets the directory used as the current user's home directory,
479+
* > for file lookups.
480+
* >
481+
* > - `path` directory of home directory.
482+
*
471483
* @param option Option key
472484
* @param ... value to set the option
473485
* @return 0 on success, <0 on failure

src/libgit2/attrcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int attr_cache__lookup_path(
300300

301301
/* expand leading ~/ as needed */
302302
if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
303-
if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
303+
if (! (error = git_sysdir_expand_homedir_file(&buf, &cfgval[2])))
304304
*out = git_str_detach(&buf);
305305
} else if (cfgval) {
306306
*out = git__strdup(cfgval);

src/libgit2/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static int git_config__parse_path(git_str *out, const char *value)
860860
return -1;
861861
}
862862

863-
return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
863+
return git_sysdir_expand_homedir_file(out, value[1] ? &value[2] : NULL);
864864
}
865865

866866
return git_str_sets(out, value);

src/libgit2/config_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ static int included_path(git_str *out, const char *dir, const char *path)
528528
{
529529
/* From the user's home */
530530
if (path[0] == '~' && path[1] == '/')
531-
return git_sysdir_expand_global_file(out, &path[1]);
531+
return git_sysdir_expand_homedir_file(out, &path[1]);
532532

533533
return git_fs_path_join_unrooted(out, path, dir, NULL);
534534
}
@@ -616,7 +616,7 @@ static int do_match_gitdir(
616616
git_fs_path_dirname_r(&pattern, cfg_file);
617617
git_str_joinpath(&pattern, pattern.ptr, condition + 2);
618618
} else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1]))
619-
git_sysdir_expand_global_file(&pattern, condition + 1);
619+
git_sysdir_expand_homedir_file(&pattern, condition + 1);
620620
else if (!git_fs_path_is_absolute(condition))
621621
git_str_joinpath(&pattern, "**", condition);
622622
else

src/libgit2/libgit2.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,25 @@ int git_libgit2_opts(int key, ...)
414414
git_repository__validate_ownership = (va_arg(ap, int) != 0);
415415
break;
416416

417+
case GIT_OPT_GET_HOMEDIR:
418+
{
419+
git_buf *out = va_arg(ap, git_buf *);
420+
git_str str = GIT_STR_INIT;
421+
const git_str *tmp;
422+
423+
if ((error = git_buf_tostr(&str, out)) < 0 ||
424+
(error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 ||
425+
(error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
426+
break;
427+
428+
error = git_buf_fromstr(out, &str);
429+
}
430+
break;
431+
432+
case GIT_OPT_SET_HOMEDIR:
433+
error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *));
434+
break;
435+
417436
default:
418437
git_error_set(GIT_ERROR_INVALID, "invalid option key");
419438
error = -1;

0 commit comments

Comments
 (0)
0