Commit Graph

16172 Commits

Author SHA1 Message Date
Edward Thomson
249b9d6aad Merge pull request #7234 from libgit2/ethomson/cmake
cmake: don't recreate git2.h unnecessarily
2026-04-29 21:33:08 +01:00
Edward Thomson
d5241a2c04 cmake: don't recreate git2.h unnecessarily
Instead of regenerating `git2.h` on every cmake invocation, use
`configure_file` to avoid rewriting it. This keeps timestamps inline and
avoids unnecessarily rebuilding the library.
2026-04-29 20:56:29 +01:00
Edward Thomson
56883f9e9d Merge pull request #7232 from kcsaul/fix/config-memory-backend
Config Memory Backend Corruption Fix
2026-04-29 20:34:40 +01:00
Edward Thomson
445193c4f8 Merge pull request #7118 from oliverchang/fix
Fixed a heap-buffer-overflow in the smart_pkt.c:set_data function.
2026-04-29 20:15:04 +01:00
Edward Thomson
81706d1b35 Merge pull request #7231 from libgit2/ethomson/worktree_fi
repository: fix operators in `foreach_worktree`
2026-04-29 15:25:34 +01:00
Kevin Saul
d30a69c63d config: fix crash after memory backend entry freed 2026-04-29 22:24:33 +12:00
Kevin Saul
3b5ecb0d42 config: update memory backend test to reproduce crash 2026-04-29 22:11:28 +12:00
Edward Thomson
c0a4ef05f4 repository: fix operators in foreach_worktree
Fix a simple operator precedence bug in
`git_repository_foreach_worktree`.
2026-04-29 09:44:05 +01:00
Edward Thomson
c16683f5fb Merge pull request #7230 from libgit2/ethomson/clar-2
clar: update with const correct iterator
2026-04-28 21:14:38 +01:00
Edward Thomson
124a1a801b clar: update with const correct iterator 2026-04-28 15:25:58 +01:00
Edward Thomson
1e7d7c07d0 Merge pull request #7195 from weihanglo/insteadof
fix: apply insteadOf from global config for detached remotes
2026-04-24 11:19:47 +01:00
Edward Thomson
8a1f012861 Merge pull request #7229 from weihanglo/fix
fix(transport): get oid_type on local transport
2026-04-24 11:14:02 +01:00
Weihang Lo
e047e80074 fix(transport): get oid_type on local transport
Cache `oid_type` in `transport_local` struct during `connect()`
so `git_remote_oid_type()` keeps working after disconnect.

This matches the smart transport behavior.
2026-04-23 23:17:57 -04:00
Weihang Lo
6753d535c8 test(transport): get oid_type on local transport
Exercise git_remote_oid_type on a SHA256 local transport.

The after-disconnect assertion is commented out because
local_oid_type dereferences `t->repo`, which local_close
has already freed (SIGSEGV).

I ran these commands to test btw:

```
cmake .. -DGIT_EXPERIMENTAL_SHA256=ON -DBUILD_TESTS=ON
cmake --build .
./libgit2_tests -snetwork::remote::local::sha256_oid_type
```
2026-04-23 23:14:01 -04:00
Weihang Lo
d375ab70c1 fix(remote): apply insteadOf from global config for detached remotes
Detached remotes already read global/system config for http proxy
settings, but did not apply url.*.insteadOf or url.*.pushInsteadOf
rules. This inconsistency meant that `git_remote_create_detached`
behaved differently from git's `ls-remote`, which was the primary
use case for detached remotes.

This fixes it by loading the default config when no repository is
provided and apply insteadOf rules consistently.

While this is a behavior change, it still respects
`GIT_REMOTE_CREATE_SKIP_INSTEADOF`, meaning that user can restore
the previous behavior with minimal effort

Fixes https://github.com/libgit2/libgit2/issues/5469
2026-04-23 18:32:11 -04:00
Weihang Lo
aa5d9886d1 test(remote): show buggy detached remote insteadOf behavior
`git_remote_create_detached` does not apply
`url.*.insteadOf` or url.*.pushInsteadOf from global config.

These tests currently pass, asserting the buggy behavior
and serving as a minimal reproduction.

The assertions will be updated when the fix is applied.

See <https://github.com/libgit2/libgit2/issues/5469>
2026-04-23 18:32:11 -04:00
Edward Thomson
d35f378794 Merge pull request #7226 from weihanglo/local-object-format
fix(clone): propagate object format in local clone
2026-04-23 22:11:06 +01:00
Edward Thomson
08d91d0fbf Merge pull request #7228 from DanielEScherzer/patch-1
`GIT_REMOTE_DOWNLOAD_TAGS_ALL`: remove stray "the" in docs
2026-04-23 21:37:16 +01:00
Edward Thomson
9fd0be8525 Merge pull request #7227 from weihanglo/pseudoref
fix(refs): attach refdb owner to loose pseudorefs
2026-04-23 21:36:50 +01:00
Edward Thomson
b7e3a7df51 Merge pull request #7225 from csware/nullptr-deref
repo: Fix possible null pointer dereference
2026-04-23 21:31:09 +01:00
Edward Thomson
87c03c1aaa Apply suggestions from code review
Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-04-23 21:30:21 +01:00
Daniel Scherzer
9e78ec20bb GIT_REMOTE_DOWNLOAD_TAGS_ALL: remove stray "the" in docs 2026-04-22 16:27:54 -07:00
Weihang Lo
7a9b284302 fix(refdb): check loose ref allocation failures
The loose ref lookup helper was exposed by 7f35dc581
and then used by b17ecb23e directly for pseudoref lookup.

While investigating the pseudoref owner regression,
I found that the helper also returns success
with a NULL output reference when `git_reference__alloc()`
or `git_reference__alloc_symbolic()` failed.

This fixes it by reporting allocation failures inside
`git_reference__lookup_loose`.
2026-04-22 17:51:25 -04:00
Weihang Lo
735bb2e2f5 fix(refs): attach refdb owner to loose pseudorefs
Pseudoref lookup now reads `FETCH_HEAD` directly as a loose ref,
but callers still expect looked-up references to know their owning
repository.

Attach the repo's refdb after the loose pseudoref is read so
owner-dependent ops such as peeling can safely resolve objects.
2026-04-22 17:50:23 -04:00
Weihang Lo
c0a5341635 test(refs): cover pseudoref owner regression from b17ecb23e
b17ecb23e changed pseudoref lookup to read loose refs directly,
bypassing refdb lookup.

This documents the resulting buggy behavior:
a looked-up `FETCH_HEAD` pseudoref has no owning refdb attached.
2026-04-22 17:50:14 -04:00
Weihang Lo
47fdc9c3f0 fix(clone): propagate object format in local clone
`clone_local_into()` copies objects from the source repository
but does not set the destination's object format.
This cause SHA256 repositories to be unreadable after a local clone
because the destination defaults to SHA1.

The remote clone path already handles this correctly
so local clone path follows suite.

See: <https://github.com/libgit2/libgit2/blob/1f34e2a57/src/libgit2/clone.c#L448-L450>
2026-04-19 11:34:50 -04:00
Weihang Lo
9fa192de95 test(clone): document SHA256 local clone failure
Local clone, both hardlink and copy paths, does not propagate
the source repository's object format to the destination.

A SHA256 repository cloned locally is initialized as SHA1
and caused object lookup failures.

These tests are added as reproducible examples,
and will be fixed in the next commit

* `sha256_via_no_local`
  * `file://` URL + `GIT_CLONE_NO_LOCAL` -> remote code path
* `sha256_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL` -> local code path with hardlinks
* `sha256_no_links_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL_NO_LINKS` -> local code path with copy
2026-04-19 11:34:44 -04:00
Sven Strickroth
0bbc49b9e3 repo: Fix possible null pointer dereference
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2026-04-16 19:42:46 +02:00
Edward Thomson
1f34e2a57a Merge pull request #7113 from pks-gitlab/pks-test-fixes-for-reftables
Test fixes to prepare for the reftable backend
2026-03-31 20:34:06 +01:00
Patrick Steinhardt
1888a166e4 tests/libgit2: conditional checks for the "files"-backend
We have a bunch of checks for properties of the "files" reference
backend:

  - Whether a specific reference has been packed or whether it still
    exists as a loose reference.

  - Whether empty ref directories get pruned.

  - Whether we properly fsync data to disk.

These checks continue to be sensible for that backend, but for any other
backend they plain don't work. Adapt the tests so that we only run them
in case the repository uses the "files" backend.
2026-03-30 07:54:12 +02:00
Patrick Steinhardt
1030b68f3d tests/libgit2: don't overwrite config when testing conditionals
When testing conditional includes we overwrite the repository's config
file with the relevant conditions. This causes us to fully overwrite all
repository configuration, including the repository format version and
any extensions. While the test repository used in this test does not
have any extensions, we will add a reftable-enabled repository that does
rely on the "refStorage" extension eventually.

Fix this by only modifying the relevant config keys.
2026-03-30 07:54:12 +02:00
Patrick Steinhardt
5c5db73e3e tests/libgit2: don't access refs via filesystem
There are a bunch of tests where we read or write references via the
filesystem directly. This only works with the "files" backend, but
naturally breaks if we supported any other reference format.

Refactor these tests to instead use the refdb to access those.
2026-03-30 07:54:09 +02:00
Patrick Steinhardt
5e058b54ee tests/clar: introduce cl_repo_has_ref_format()
Introduce a function that reads the "refStorage" extension so that we
can easily figure out whether a specific repository uses the "files" or
any other reference format. While we don't support other formats yet, we
are about to add support for the "reftable" format.
2026-03-30 07:50:44 +02:00
Edward Thomson
079379ee96 Merge pull request #7111 from pks-gitlab/pks-refdb-pseudorefs
Fix handling of pseudorefs with different refdb backends
2026-03-29 14:00:44 +01:00
Edward Thomson
ffb0a2c47e Merge pull request #7218 from KoviRobi/main
revparse: Allow `HEAD` abbreviation `@`
2026-03-24 21:13:54 +00:00
Edward Thomson
7b33412006 Merge pull request #7211 from cehoffman/fix-o-fsync-undefined-behavior
futils: fix undefined behavior in O_FSYNC fallback definition
2026-03-24 20:57:58 +00:00
Chris Hoffman
46208be836 futils: fix undefined behavior in O_FSYNC fallback definition
The fallback definition of O_FSYNC uses `(1 << 31)`, which is undefined
behavior in C. The literal `1` is a signed int, and left-shifting into
the sign bit of a signed integer is undefined per the C standard.

This causes crashes on arm64 Linux with musl libc (which doesn't define
O_FSYNC), manifesting as:

    thread panic: left shift of 1 by 31 places cannot be represented
    in type 'int'

Fall back to O_SYNC when available, since it is the POSIX standard name
for the same flag. On platforms where neither is defined (e.g. Windows),
use (1 << 30) as a sentinel value that avoids the sign bit.
2026-03-17 20:05:42 -05:00
Edward Thomson
d78c1eb08f Merge pull request #7215 from carlosmn/cmn/ssh2-pc-requires
camke: include libssh2 in `Requires.private` in the PC file
2026-03-14 14:13:40 +00:00
Kovacsics Robert
828f60337c revparse: Allow HEAD abbreviation @
The `@` alone (without predeeding refname in `<refname>@`) is an
alias for HEAD, and can then be used with other modifiers for example
`HEAD^{/...}`
2026-03-01 21:03:26 +00:00
Carlos Martín Nieto
873bf4794a camke: include libssh2 in Requires.private in the PC file
We need this in order for `pkg-config` to be able to tell what you should link
against when building libgit2 statically. We do include libssh2 in
`Libs.private` but not in `Requires.private`. The difference is a bit subtle but
has become important.

You can call `pkg-config --libs --static ${build}/libgit2.pc` and it will give
you what is in the Libs line, and also what the packages from the Requires field
have in theirs. This is what e.g. `rugged` does and it has been working until
recently. An update to openssl to require zstd now means that using `--libs
--static` returns `-lzstd` as well as many others. This means that those who
want to link using that command now need to have the development packages for
zstd installed, which should not be necessary as libgit2 itself doesn't want to
use anything from it.

A better command to use here seems to be `pkg-config --libs --static --pure
${build}/libgit2.pc`. The manpage and help output are not very precise but what
this does is limit the list of dependencies to a single layer, which is what we
want as we would only want to link statically against libgit2 and not the rest
of the libraries.

But trying to do so breaks building with libssh2 as it's included in the Libs
field rather than the Requires, so that command excludes any linking to libssh2.

Put libssh2 in the `Requires.private` field so we correctly express we need to
link to it when linking statically.

This is unfortunately an imperfect fix as now, if we did not find libssh2 via
pkg-config but rather via CMake's `find_package`, the combination of `--static
--pure` does not take `Libs.private` into account. However we only support this
as an edge case and we expect `pkg-config` to be available for the rest of our
dependencies.
2026-02-20 23:36:18 +01:00
Edward Thomson
86c7738ca6 Merge pull request #7209 from libgit2/ethomson/ci 2026-01-31 14:40:08 +00:00
Edward Thomson
f4eee4fa9a Merge pull request #7208 from libgit2/ethomson/oidbench
ab tests: enable sha256
2026-01-31 14:07:26 +00:00
Edward Thomson
c84cf608f6 main: revert a/b test debugging changes 2026-01-31 14:06:48 +00:00
Edward Thomson
7ef512a828 ab tests: enable sha256 2026-01-31 13:58:52 +00:00
Edward Thomson
b1a826a7ff Merge pull request #7207 from libgit2/ethomson/oidbench
Benchmark the OID code
2026-01-26 23:41:43 +00:00
Edward Thomson
9935da4661 ci: optionally run benchmarks 2026-01-26 23:40:53 +00:00
Edward Thomson
c0f5c9bd80 ci: generate markdown results from benchmarks 2026-01-26 23:02:06 +00:00
Edward Thomson
928a81e872 microbenchmarks: benchmark the oid code
At present, the library's oid manipulation functions are slower when
built in SHA256 mode than when not. Add some microbenchmarks around the
oid compare and copy functions to understand this better.
2026-01-26 21:43:06 +00:00
Edward Thomson
d55ff3cd70 clar: fix remove unused 2026-01-26 21:43:06 +00:00
Edward Thomson
3ac6bf801c clar: avoid iterator clobbered by longjmp
If the iterator is moved to a register, it may be clobbered by the
longjmp. Avoid this by treating it as volatile.
2026-01-26 21:43:06 +00:00