16323 Commits

Author SHA1 Message Date
Edward Thomson
873ab30fe4 hashmap: correctly sized MAX 2026-05-22 11:21:37 +01:00
Daniel Scherzer
1b4eaa3309 commit.h: remove stray * in git_commit_amend() docs 2026-05-16 18:29:53 -07:00
Edward Thomson
5787752448 Merge pull request #7150 from ambv/rebase-example
feat: Add an example for the rebase API
2026-05-16 20:50:41 +01:00
Edward Thomson
b8e67d6664 Merge pull request #7263 from libgit2/ethomson/build
cmake: separate generated headers from translated headers
2026-05-16 20:48:06 +01:00
Yelninei
84806965a0 tests: Remove GITTEST_FLAKY_STAT environment variable.
This was caused by the tests being compiled with -D_FILE_OFFSET_BITS=64
which causes incompatibilities if libgit2 itself is not.

As this has been resolved the environment variable is no longer
necessary and can be removed.
2026-05-16 12:34:36 +00:00
Yelninei
4ae8367b4e tests: Fix stat tests on 32bit systems.
On 32bit systems the git_fs_path_lstat from libgit2 by default uses 32bit stat
structs while the tests are being compiled with struct stat64 via
_FILE_OFFSET_BITS=64.

This discrepancy causes the "flaky" stat failures in tests.

The solution is to use the same _FILE_OFFSET_BITS as the library by
setting _FILE_OFFSET_BITS globally

Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-05-16 12:34:03 +00:00
Edward Thomson
b1b421fe4b cmake: separate generated headers from translated headers
Make a distinction between generated headers and "translated" headers.
This is important to support build-time dependencies when headers are
updated.

Generated headers are those which contain build-time feature
specifications, like `git2_features.h` that are internal to the build
and `experimental.h` that contain API information.

Translated headers are the headers that are in `include/git2`, but may
be translated to have a unique prefix like `incklude/git2-experimental`.

This distinction is important so that the CMakeFiles.txt depend on the
in-tree include files (`src/include`) and the generated header files
_but not_ the translated header files. Otherwise there are two `pack.h`
and it's unclear whether the in-tree build is targeting the one in
`src/include` or the one in the build tree.

Without this, updating an in-tree header file like `pack.h` would not
cause a rebuild of its dependencies.
2026-05-16 13:01:55 +01:00
Edward Thomson
bc1ab28d5d Merge pull request #7266 from weihanglo/fix 2026-05-16 10:48:34 +01:00
Weihang Lo
455e513120 fix(sha256): thread-safety bug in builtin SHA-256
The implementation here seems to be sort of a copy
from the reference impl in RFC 6234 [2].
When multiple threads hash concurrently,
they race on this shared static variable.
It then corrupts the length-overflow detection,
and produces incorrect SHA-256 digests.

Here we replace it with a `static` function with a local variable.

The bug only affects the `GIT_SHA256_BUILTIN` backend.
The SHA-1 code path uses `sha1dc` which does not have this issue.

Reproducer:

```c
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <git2.h>

#define NUM_THREADS 8
#define ITERATIONS 100000

static volatile int found_bug = 0;

void *hash_thread(void *arg) {
    int id = *(int *)arg;
    const char *data = "hello world\n";
    size_t len = strlen(data);

    git_object_id_options opts = GIT_OBJECT_ID_OPTIONS_INIT;
    opts.object_type = GIT_OBJECT_BLOB;
    opts.oid_type = GIT_OID_SHA256;

    git_oid reference, result;
    git_object_id_from_buffer(&reference, data, len, &opts);

    for (int i = 0; i < ITERATIONS && !found_bug; i++) {
        git_object_id_from_buffer(&result, data, len, &opts);
        if (!git_oid_equal(&reference, &result)) {
            found_bug = 1;
            printf("BUG: thread %d, iteration %d\n", id, i);
            break;
        }
    }
    return NULL;
}

int main(void) {
    git_libgit2_init();
    pthread_t threads[NUM_THREADS];
    int ids[NUM_THREADS];
    for (int i = 0; i < NUM_THREADS; i++) {
        ids[i] = i;
        pthread_create(&threads[i], NULL, hash_thread, &ids[i]);
    }
    for (int i = 0; i < NUM_THREADS; i++)
        pthread_join(threads[i], NULL);
    if (!found_bug)
        printf("No bug triggered\n");
    git_libgit2_shutdown();
    return found_bug ? 1 : 0;
}
```

Build and run (from libgit2 repo root):

```sh
mkdir build && cd build
cmake .. -DEXPERIMENTAL_SHA256=ON -DUSE_SHA256=Builtin \
  -DUSE_HTTPS=OFF -DUSE_SSH=OFF -DUSE_NTLMCLIENT=OFF \
  -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug
make libgit2package
cd ..
cc -O0 -pthread -DGIT_EXPERIMENTAL_SHA256=1 \
  -I include -o repro repro.c \
  build/libgit2-experimental.a -lz -lpcre2-8
./repro
```

See <https://github.com/rust-lang/git2-rs/issues/1255> for more.

[1]: https://github.com/libgit2/libgit2/blob/1affb8b19/src/util/hash/rfc6234/sha224-256.c#L86-L91
[2]: https://www.rfc-editor.org/rfc/rfc6234#section-8.2.2
2026-05-16 10:50:32 +02:00
Sven Strickroth
c90dc5284e Add support for "/*" wildcard in safe.directory
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2026-05-16 09:22:01 +02:00
Edward Thomson
d23f18fd88 Merge pull request #7254 from cwill747/fix/relative-worktrees-extension
fix: Recognize relative worktrees extension
2026-05-12 09:38:10 +01:00
Edward Thomson
a7c02c9f45 Merge pull request #7258 from libgit2/ethomson/build
Avoid uninitialized variable warnings in gcc
2026-05-11 21:21:53 +01:00
Edward Thomson
83f6d0edc4 cli: avoid uninitialized variable warnings 2026-05-11 20:06:40 +01:00
Edward Thomson
8ae1cf5932 Merge pull request #7257 from libgit2/ethomson/build-2
cmake: correct private/public include split
2026-05-11 20:04:42 +01:00
Edward Thomson
1ef0088b71 midx: avoid uninitialized variable 2026-05-11 15:11:56 +01:00
Edward Thomson
42661d7745 index: initialize best_len unnecessarily
gcc thinks this could be used uninitialized; cope with this.
2026-05-11 09:51:40 +01:00
Edward Thomson
2fd627d2d3 runtime: avoid uninitialized variable
`init_common` could return an uninitialized variable when there are no
subsystems; simply return `0` in this case.
2026-05-11 09:50:33 +01:00
Edward Thomson
2fe5b9eee6 hashmap: initialize the variable
gcc thinks this could be used uninitialized; cope with this.
2026-05-11 09:32:56 +01:00
Edward Thomson
8555cc4402 cmake: correct private/public include split
PR #7202 (`1ab42f3`) accidentally dropped the `PUBLIC` in the includes;
this meant that local build was accidentally looking at the in-build
include files instead of the in-source include files, and updates to
source include files would not trigger a rebuild.
2026-05-11 09:28:11 +01:00
Edward Thomson
034fb30783 runtime: initialize the variable
gcc thinks this could be uninitialized; make it so.
2026-05-10 21:07:23 +01:00
Edward Thomson
6a4f3ea48e Merge pull request #7256 from libgit2/ethomson/ci
ci updates
2026-05-09 23:23:36 +01:00
Edward Thomson
fbad63cc82 cmake: build RelWithDebInfo by default
RelWithDebInfo is now the default; this is what most _consumers_ of the
library probably want, even though the developers likely want Debug
builds.
2026-05-09 22:29:22 +01:00
Edward Thomson
b9ff26de1a ci: move more flags to global flags 2026-05-09 22:29:22 +01:00
Cameron Will
3d1e45895e fix: Recognize relative worktrees extension
Git supports relative worktrees since Git v2.48 - cf6f63ea6b/Documentation/RelNotes/2.48.0.adoc (L57)

This was already handled programatically in libgit2, but was
not recognized as an extension, meaning downstream consumers
like Nix had issues with relative worktree-enabled repos.

Fixes #7210
2026-05-08 15:14:16 -04:00
Edward Thomson
de73c97d74 Merge pull request #7197 from libgit2/ethomson/ci_simplification
ci: local build options
2026-05-08 17:25:45 +01:00
Edward Thomson
83b56ab2db Merge branch 'pr/7202' 2026-05-08 14:49:01 +01:00
Edward Thomson
1ab42f3acb cmake: use configure_file for generated headers
Use `configure_file` to move the generated headers into place, to avoid
unnecessary updates (and unnecessary rebuilds). See #7241
2026-05-08 14:46:39 +01:00
Edward Thomson
45567bebb7 ssh: only allow not found (nonexistent) HOME
Only succeed if the HOME directory is not found. Otherwise, error.
2026-05-06 23:55:09 +01:00
Jonas Vautherin
0e95b72277 load_known_hosts: do not fail if homedir is invalid 2026-05-06 23:55:09 +01:00
Edward Thomson
160bb3d942 Merge pull request #7220 from libgit2/ethomson/faster_sha256_oids
oid: sha1s must now be zero-padded
2026-05-06 23:35:04 +01:00
Edward Thomson
0d3eefd4be Merge pull request #7193 from bakersdozen123/fix-revparse-leak
Fix memory leak in `git_revparse()`
2026-05-06 23:21:48 +01:00
Edward Thomson
3a244c6875 Merge pull request #7052 from QiuYitai/main
Fix the null reference vulnerability.
2026-05-06 23:05:55 +01:00
Edward Thomson
e279d645f1 oid: sha1s must now be zero-padded
Now that we have two types of object IDs, with different sizes, we
expect shorter object ID types (in other words, SHA1 object ids) to be
zero-padded at their suffix. This allows us to use faster comparison and
copy routines over the entirety of the structure, instead of trying to
examine the type and then do a comparison of the appropriately sized
structure.

For pure manipulation of object IDs, this produces parity with the
SHA1-only object ID code.

SHA1:
oid::cmp_sha1:  8.065 ms ± 703.9 μs / range: 7.875 ms … 14.88 ms  (201 runs)
oid::cmp_sha256:  skipped
oid::cpy_sha1:  5.340 ms ± 47.26 μs / range: 5.272 ms … 5.617 ms  (548 runs)
oid::cpy_sha256:  skipped
oid::zero_sha1:  5.327 ms ± 49.27 μs / range: 5.271 ms … 5.612 ms  (553 runs)
oid::zero_sha256:  skipped

SHA256 (before this change; testing the `type`):
oid::cmp_sha1:  10.82 ms ± 1.029 ms / range: 10.57 ms … 20.63 ms  (145 runs)
oid::cmp_sha256:  10.63 ms ± 103.9 μs / range: 10.50 ms … 11.48 ms  (279 runs)
oid::cpy_sha1:  26.13 ms ± 63.91 μs / range: 26.07 ms … 26.45 ms  (113 runs)
oid::cpy_sha256:  20.92 ms ± 58.32 μs / range: 20.86 ms … 21.25 ms  (141 runs)
oid::zero_sha1:  13.19 ms ± 129.1 μs / range: 13.11 ms … 13.72 ms  (224 runs)
oid::zero_sha256:  13.12 ms ± 30.06 μs / range: 13.10 ms … 13.30 ms  (225 runs)

SHA256 (with this change):
oid::cmp_sha1:  7.985 ms ± 562.3 μs / range: 7.874 ms … 14.32 ms  (209 runs)
oid::cmp_sha256:  6.609 ms ± 30.77 μs / range: 6.584 ms … 6.870 ms  (443 runs)
oid::cpy_sha1:  5.282 ms ± 21.90 μs / range: 5.266 ms … 5.524 ms  (543 runs)
oid::cpy_sha256:  5.279 ms ± 17.57 μs / range: 5.263 ms … 5.415 ms  (554 runs)
oid::zero_sha1:  5.288 ms ± 22.92 μs / range: 5.268 ms … 5.508 ms  (544 runs)
oid::zero_sha256:  5.286 ms ± 21.29 μs / range: 5.271 ms … 5.527 ms  (542 runs)
2026-05-06 23:03:46 +01:00
Edward Thomson
4e7a7e090c Merge pull request #7139 from dyfer/fix-xcode-static-lib
cmake: fix creation of static lib in xcode
2026-05-06 22:05:49 +01:00
Edward Thomson
af1e2fa3d0 Merge pull request #7117 from pks-gitlab/pks/reftables-support
Reftables support
2026-05-06 22:02:32 +01:00
Edward Thomson
7a12070f5a Merge pull request #7121 from yonathan-ashebir/main
Adding missing includes in public header files
2026-05-06 22:01:18 +01:00
Edward Thomson
b6a9e9a994 Merge pull request #7051 from timonvo/diff-from-buffer-binary-roundtrip
diff: make `git_diff_from_buffer` diffs show binary data when printed.
2026-05-06 21:48:25 +01:00
bakersdozen123
93b16df1f1 Set revspec->from to NULL after freeing 2026-05-06 11:27:20 -07:00
Kevin Saul
3e5b7ed79b remote: don't create empty FETCH_HEAD file when update suppressed (#7244) 2026-05-06 17:37:41 +01:00
Edward Thomson
f687244dc2 Merge pull request #7252 from libgit2/ethomson/docs-update 2026-05-05 07:05:24 +01:00
Edward Thomson
95bacb75a1 docs: update README to remove Coverity Scan badge (#7251)
Removed Coverity Scan Status badge from Nightly builds section. Coverity apparently has ceased to be.
2026-05-04 23:26:22 +01:00
Edward Thomson
eb0f7a734e docs: proceed when version folder doesn't exist
A version folder may not exists (for example, when adding a new
version). Proceed!
2026-05-04 23:25:08 +01:00
Edward Thomson
cf028e7e9a Merge pull request #7246 from libgit2/ethomson/redirect
Handle redirects with `Content-Length: 0` correctly
2026-05-04 21:39:51 +01:00
Edward Thomson
07c737f235 Merge pull request #7249 from kcsaul/fix/missing-library-error
cmake: fix linker error when using ninja build generator
2026-05-04 21:29:15 +01:00
Kevin Saul
50fa757381 cmake: fix linker error when using ninja build generator 2026-05-05 07:40:20 +12:00
Edward Thomson
242d66e931 httpclient: stop if there's no content length
When we were done reading headers, we checked if we needed to read a
body, or if we were done. The body check was done by looking at the
transfer encoding type and the content type. If we were chunked, then we
know we have a body (it may be a zero byte body, but we would need to
read the chunk length to know this). But looking at the content _type_
was erroneous; we should have been looking at the content _length_.

The effect of this is that when a server sends a zero byte response
with a content _type_, we try to go read the body, which does not exist.
We will hang waiting for the body that the server will never send.

Correct this typo. Now we will try to read the body if there was a
content _length_ specified, or if the transfer encoding is chunked.
2026-05-04 19:52:45 +01:00
Edward Thomson
293aa39785 httpclient: update complete_response_body explanation 2026-05-04 19:52:45 +01:00
Edward Thomson
c6de625624 ci: use the new initial-redirect:none repo
poxygit now supports a "specification" within the URI that can provide
additional details about the mock/debugging connection. The `:none`
suffix on the redirect request indicates that the proxy should send a 0
byte response body.
2026-05-04 19:52:45 +01:00
Edward Thomson
4dc25c267b Merge pull request #7248 from libgit2/ethomson/poxygit
ci: use poxygit v0.8.1 in the tests
2026-05-04 19:48:40 +01:00
Edward Thomson
c9dd053d71 ci: use poxygit v0.8.1 in the tests
Update our CI to use poxygit v0.8.1, which has additional mocking and
debugging capabilities.

As part of this, the paths to the `speed` test routes changed - now they
are `speed:<n>` where `<n>` is the speed to emulate in bps.
2026-05-04 17:47:50 +01:00