Commit Graph

16192 Commits

Author SHA1 Message Date
Edward Thomson
8bb32e5780 object: move internal use to git_object_id_from...
Using the `git_object_id_from` is an overall code simplification; switch
to it.
2026-05-02 14:17:21 +01:00
Edward Thomson
2dd70bc196 object: introduce git_object_id_from... APIs
Introduce APIs within the `git_object` namespace to calculate the IDs
of objects based on their raw content.
2026-05-02 14:17:21 +01:00
Edward Thomson
200aace53d Merge pull request #7165 from ambv/tcp-keepalive
fix: prevent SSH timeout infinite loop and enable TCP keepalive
2026-05-02 14:12:25 +01:00
Edward Thomson
16cb9c5ed8 Merge pull request #7239 from libgit2/ethomson/mergefix
merge_files: avoid UB in xdiff
2026-05-02 08:44:05 +01:00
Edward Thomson
a7b267c7a6 Merge pull request #7238 from kanru-contrib/null-terminate-pack-buffer
fix(pack): ensure pack_backend__read returns null terminated buffer
2026-05-02 08:33:47 +01:00
Edward Thomson
43b5707765 Merge pull request #7241 from kcsaul/fix/cmake-temp-header
cmake: write git.h.tmp to current binary directory
2026-05-02 08:27:13 +01:00
Edward Thomson
a25d9a18fa xdiff: don't try to malloc 0 bytes
For zero byte files, avoid allocation - this avoids undefined behavior
around malloc(0) and potentially memcpy(..., NULL, 0).
2026-05-02 08:24:18 +01:00
Edward Thomson
643b7e1038 merge_files: some simplification 2026-05-02 08:24:18 +01:00
Edward Thomson
8d4d980b10 merge_files: test with zero-byte file
Test handing a zero byte but extant file to merge_files.
2026-05-02 08:24:18 +01:00
Kevin Saul
5b59e4a180 cmake: write git.h.tmp to current binary directory 2026-05-02 13:56:47 +12:00
Kan-Ru Chen
22e80c6065 fix(pack): ensure pack_backend__read returns null terminated buffer
Depending on the zlib library used, the inflate() function may write
beyond the object size into the additional trailing buffer for aligned
memory copies. This may cause out-of-bounds memory read if the object
buffer is later used without checking the object size, as in
git_commit__extract_signature.

Link: https://github.com/zlib-ng/zlib-ng/issues/1767
Signed-off-by: Kan-Ru Chen <kanru@kanru.info>
2026-05-01 07:47:54 +09:00
Edward Thomson
cefc409a97 Merge pull request #7092 from eantoranz/git_merge_file_from_index-null_child
git_merge_file_from_index: handle cases when a child (ours or theirs) is null
2026-04-30 23:39:06 +01:00
Edward Thomson
70ff46d7fe Merge pull request #7236 from libgit2/ethomson/lengths
Check object lengths against headers in `read_loose`
2026-04-30 23:19:07 +01:00
Edward Thomson
a1c807c79e object: test looking up truncated objects
Add a test that looks up an invalid, truncated object, that is shorter
than the advertised length.
2026-04-30 22:59:20 +01:00
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