Commit Graph

16296 Commits

Author SHA1 Message Date
Edward Thomson
ca77af7a9a cli: update opt parsing to allow optional values 2026-06-01 22:15:47 +01:00
Edward Thomson
59abaf51e1 cli: add a CLI_ASSERT macro
`GIT_ASSERT` is not necessarily useful for the CLI; we need something
that prints to stderr and exits.
2026-06-01 22:15:47 +01:00
Edward Thomson
0239d68bb2 process: allow NULL options
The process options structure should be allowed to be `NULL`; treated as
if it's empty.
2026-06-01 22:15:47 +01:00
Edward Thomson
353e7059dc Merge pull request #7237 from libgit2/ethomson/commit
Introduce a new commit API
2026-06-01 22:14:48 +01:00
Edward Thomson
f8823e4e11 commit: add headers and signature to create_from
The `create_from` and `amend_from` APIs use a slightly different options
structure. They should both allow extra headers and signature callbacks.
2026-06-01 21:23:59 +01:00
Edward Thomson
05c4b5cf95 commit: introduce git_commit_amend_from_...
Similar to the `git_commit_create_from_...` APIs, a simple amend
function that uses smart defaults and amends HEAD from the staged
changes or a given tree.
2026-06-01 21:23:59 +01:00
Edward Thomson
16b12ff3c5 commit: introduce git_commit_create_from_tree
Similar to the `git_commit_create_from_stage` function, a batteries-
included commit creation function that uses smart defaults and commits a
given tree.
2026-06-01 21:23:59 +01:00
Edward Thomson
096cc6f76d commit: introduce a signing callback
Callers can now introduce a commit signing callback instead of needing
to call a specialized commit buffer creation function.
2026-06-01 21:23:59 +01:00
Edward Thomson
a7786fcd7e commit: support custom user-specified headers
Some clients (eg GitButler) are storing additional information in custom
user-specified commit headers. We should make this a first-class
concept.
2026-06-01 21:23:59 +01:00
Edward Thomson
cf02e92b54 commit: introduce commit creation options
Introduce `git_commit_create_ext` and an options structure for
extensibility. Non-default arguments (message encoding, reference
updates) are in the options structure.

This simplifies the complex self-service commit creation APIs and allows
for future sustainable improvements.
2026-06-01 21:23:59 +01:00
Edward Thomson
a7e1eb2638 Merge pull request #7245 from mrdimidium/main 2026-05-30 18:56:01 +01:00
Edward Thomson
8a94cd54ee Merge pull request #7277 from yonathan-ashebir/main 2026-05-30 18:53:25 +01:00
Edward Thomson
3c7234e3a0 Update filter.h 2026-05-30 18:52:36 +01:00
yoni_ash
3f1d5c1fa9 Fix a small documentation error 2026-05-29 14:52:16 +04:00
Edward Thomson
e490b18b70 Merge pull request #7157 from OlekRaymond/main
Update GIT_DIFF_OPTIONS_INIT macro
2026-05-25 22:01:06 +01:00
Edward Thomson
0808a4b650 Apply suggestion from @ethomson 2026-05-25 22:00:50 +01:00
Edward Thomson
ff7c86f87e Merge pull request #7276 from libgit2/ethomson/ci
ci: drop coverity, add sonarqube
2026-05-25 21:57:28 +01:00
Edward Thomson
43bbc31735 Merge branch 'pr/7170' 2026-05-25 21:50:30 +01:00
Edward Thomson
7723452680 build: only set _FILE_OFFSET_BITS on non-Windows
mingw is confused - https://github.com/msys2/MINGW-packages/issues/10591
2026-05-25 21:38:17 +01:00
Edward Thomson
d70e2f69ee ci: drop coverity, add sonarqube
Coverity has appeared to stop working with no status updates. Remove it.

Add SonarQube.
2026-05-25 17:55:21 +01:00
Edward Thomson
0609130af2 Merge pull request #7275 from libgit2/ethomson/regex
regex: don't test odd characters on macOS
2026-05-22 19:36:40 +01:00
Edward Thomson
9710edbd8b regex: apple's regcomp got weird with locales 2026-05-22 17:19:45 +01:00
Edward Thomson
678ba13ce7 Merge pull request #7269 from DanielEScherzer/git_commit_amend-docs
commit.h: remove stray `*` in `git_commit_amend()` docs
2026-05-22 16:28:54 +01:00
Edward Thomson
acb4abd32a Merge pull request #7274 from libgit2/ethomson/ci
examples: don't system() anything
2026-05-22 14:43:21 +01:00
Edward Thomson
766d62bc28 examples: don't system() anything 2026-05-22 14:16:15 +01:00
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
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