]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
10 months agobuiltin/fetch: fix leaking transaction with `--atomic`
Patrick Steinhardt [Thu, 22 Aug 2024 09:18:06 +0000 (11:18 +0200)] 
builtin/fetch: fix leaking transaction with `--atomic`

With the `--atomic` flag, we use a single ref transaction to commit all
ref updates in git-fetch(1). The lifetime of transactions is somewhat
weird: while `ref_transaction_abort()` will free the transaction, a call
to `ref_transaction_commit()` won't. We thus have to manually free the
transaction in the successful case.

Adapt the code to free the transaction in the exit path to plug the
resulting memory leak. As `ref_transaction_abort()` already freed the
transaction for us, we have to unset the transaction when we hit that
code path to not cause a double free.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoremote: fix leaking peer ref when expanding refmap
Patrick Steinhardt [Thu, 22 Aug 2024 09:18:00 +0000 (11:18 +0200)] 
remote: fix leaking peer ref when expanding refmap

When expanding remote refs via the refspec in `get_expanded_map()`, we
first copy the remote ref and then override its peer ref with the
expanded name. This may cause a memory leak though in case the peer ref
is already set, as this field is being copied by `copy_ref()`, as well.

Fix the leak by freeing the peer ref before we re-assign the field.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoremote: fix leaks when matching refspecs
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:58 +0000 (11:17 +0200)] 
remote: fix leaks when matching refspecs

In `match_explicit()`, we try to match a source ref with a destination
ref according to a refspec item. This matching sometimes requires us to
allocate a new source spec so that it looks like we expect. And while we
in some end up assigning this allocated ref as `peer_ref`, which hands
over ownership of it to the caller, in other cases we don't. We neither
free it though, causing a memory leak.

Fix the leak by creating a common exit path where we can easily free the
source ref in case it is allocated and hasn't been handed over to the
caller.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoremote: fix leaking config strings
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:55 +0000 (11:17 +0200)] 
remote: fix leaking config strings

We're leaking several config strings when assembling remotes, either
because we do not free preceding values in case a config was set
multiple times, or because we do not free them when releasing the remote
state. This includes config strings for "branch" sections, "insteadOf",
"pushInsteadOf", and "pushDefault".

Plug those leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/fetch-pack: fix leaking refs
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:52 +0000 (11:17 +0200)] 
builtin/fetch-pack: fix leaking refs

We build several ref lists in git-fetch-pack(1), but never free them.
Fix those leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agosideband: fix leaks when configuring sideband colors
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:49 +0000 (11:17 +0200)] 
sideband: fix leaks when configuring sideband colors

We read a bunch of configs in `use_sideband_colors()` to configure the
colors that Git should use. We never free the strings read from the
config though, causing memory leaks.

Refactor the code to use `git_config_get_string_tmp()` instead, which
does not allocate memory. As we throw the strings away after parsing
them anyway there is no need to use allocated strings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/send-pack: fix leaking refspecs
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:46 +0000 (11:17 +0200)] 
builtin/send-pack: fix leaking refspecs

We never free data associated with the assembled refspec in
git-send-pack(1), causing a memory leak. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agotransport: fix leaking OID arrays in git:// transport data
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:41 +0000 (11:17 +0200)] 
transport: fix leaking OID arrays in git:// transport data

The transport data for the "git://" protocol contains two OID arrays
that we never free, creating a memory leak. Plug them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot/helper: fix leaking multi-pack-indices in "read-midx"
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:38 +0000 (11:17 +0200)] 
t/helper: fix leaking multi-pack-indices in "read-midx"

Several of the subcommands of `test-helper read-midx` do not close the
MIDX that they have opened, leading to memory leaks. Fix those.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/repack: fix leaks when computing packs to repack
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:36 +0000 (11:17 +0200)] 
builtin/repack: fix leaks when computing packs to repack

When writing an MIDX in git-repack(1) we first collect all the pack
names that we want to add to it in a string list. This list is marked as
`NODUP`, which indicates that it will neither duplicate nor own strings
added to it. In `write_midx_included_packs()` we then `insert()` strings
via `xstrdup()` or `strbuf_detach()`, but the resulting strings will not
be owned by anything and thus leak.

Fix this issue by marking the list as `DUP` and using a local buffer to
compute the pack names.

This leak is hit in t5319, but plugging it is not sufficient to make the
whole test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agomidx-write: fix leaking hashfile on error cases
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:33 +0000 (11:17 +0200)] 
midx-write: fix leaking hashfile on error cases

When writing the MIDX file we first create the `struct hashfile` used to
write the trailer hash, and then afterwards we verify whether we can
actually write the MIDX in the first place. When we decide that we
can't, this leads to a memory leak because we never free the hash file
contents.

We could fix this by freeing the hashfile on the exit path. There is a
better option though: we can simply move the checks for the error
condition earlier. As there is no early exit between creating the
hashfile and finalizing it anymore this is sufficient to fix the memory
leak.

While at it, also move around the block checking for `ctx.entries_nr`.
This change is not required to fix the memory leak, but it feels natural
to move together all massaging of parameters before we go with them and
execute the actual logic.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/archive: fix leaking `OPT_FILENAME()` value
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:30 +0000 (11:17 +0200)] 
builtin/archive: fix leaking `OPT_FILENAME()` value

The "--output" switch is an `OPT_FILENAME()` option, which allocates
memory when specified by the user. But while we free the string when
executed without the "--remote" switch, we don't otherwise because we
return via a separate exit path that doesn't know to free it.

Fix this by creating a common exit path.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/upload-archive: fix leaking args passed to `write_archive()`
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:27 +0000 (11:17 +0200)] 
builtin/upload-archive: fix leaking args passed to `write_archive()`

In git-upload-archive(1), we pass an array of arguments to
`write_archive()` to tell it what exactly to do. We don't ever clear the
vector though, causing a memory leak. Furthermore though, the call to
`write_archive()` may cause contents of the array to be modified, which
would cause us to leak memory to allocated strings held by it.

Fix the issue by having `write_archive()` create a shallow copy of
`argv` before parsing the arguments. Like this, we won't modify the
caller's array and can easily `strvec_clear()` it to plug these memory
leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/merge-tree: fix leaking `-X` strategy options
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:21 +0000 (11:17 +0200)] 
builtin/merge-tree: fix leaking `-X` strategy options

The `-X` switch for git-merge-tree(1) will push each option into a local
`xopts` vector that we then end up parsing. The vector never gets freed
though, causing a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopretty: fix leaking key/value separator buffer
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:18 +0000 (11:17 +0200)] 
pretty: fix leaking key/value separator buffer

The `format_set_trailers_options()` function is responsible for parsing
a custom pretty format for trailers. It puts the parsed options into a
`struct process_trailer_options` structure, while the allocated memory
required for this will be put into separate caller-provided arguments.
It is thus the caller's responsibility to free the memory not via the
options structure, but via the other parameters.

While we do this alright for the separator and filter keys, we do not
free the memory associated with the key/value separator. Fix this to
plug this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopretty: fix memory leaks when parsing pretty formats
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:16 +0000 (11:17 +0200)] 
pretty: fix memory leaks when parsing pretty formats

When parsing pretty formats from the config we leak the name and user
format whenever these are set multiple times. This is because we do not
free any already-set value in case there is one.

Plugging this leak for the name is trivial. For the user format we need
to be a bit more careful, because we may end up assigning a pointer into
the allocated region when the string is prefixed with either "format" or
"tformat:". In order to make it safe to unconditionally free the user
format we thus strdup the stripped string into the field instead of a
pointer into the string.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoconvert: fix leaks when resetting attributes
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:13 +0000 (11:17 +0200)] 
convert: fix leaks when resetting attributes

When resetting parsed gitattributes, we free the list of convert drivers
parsed from the config. We only free some of the drivers' fields though
and thus have memory leaks.

Fix this by freeing all allocated convert driver fields to plug these
memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agomailinfo: fix leaking header data
Patrick Steinhardt [Thu, 22 Aug 2024 09:17:11 +0000 (11:17 +0200)] 
mailinfo: fix leaking header data

We populate the `mailinfo` arrays `p_hdr_data` and `s_hdr_data` with
data parsed from the mail headers. These arrays may end up being only
partially populated with gaps in case some of the headers do not parse
properly. This causes memory leaks because `strbuf_list_free()` will
stop iterating once it hits the first `NULL` pointer in the backing
array.

Fix this by open-coding a variant of `strbuf_list_free()` that knows to
iterate through all headers.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'ps/leakfixes-part-4' into ps/leakfixes-part-5
Junio C Hamano [Tue, 20 Aug 2024 17:15:27 +0000 (10:15 -0700)] 
Merge branch 'ps/leakfixes-part-4' into ps/leakfixes-part-5

* ps/leakfixes-part-4: (22 commits)
  builtin/diff: free symmetric diff members
  diff: free state populated via options
  builtin/log: fix leak when showing converted blob contents
  userdiff: fix leaking memory for configured diff drivers
  builtin/format-patch: fix various trivial memory leaks
  diff: fix leak when parsing invalid ignore regex option
  unpack-trees: clear index when not propagating it
  sequencer: release todo list on error paths
  merge-ort: unconditionally release attributes index
  builtin/fast-export: plug leaking tag names
  builtin/fast-export: fix leaking diff options
  builtin/fast-import: plug trivial memory leaks
  builtin/notes: fix leaking `struct notes_tree` when merging notes
  builtin/rebase: fix leaking `commit.gpgsign` value
  config: fix leaking comment character config
  submodule-config: fix leaking name entry when traversing submodules
  read-cache: fix leaking hashfile when writing index fails
  bulk-checkin: fix leaking state TODO
  object-name: fix leaking symlink paths in object context
  object-file: fix memory leak when reading corrupted headers
  ...

10 months agoThe sixth batch
Junio C Hamano [Mon, 19 Aug 2024 17:44:04 +0000 (10:44 -0700)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'ps/transport-leakfix-test-updates'
Junio C Hamano [Mon, 19 Aug 2024 18:07:38 +0000 (11:07 -0700)] 
Merge branch 'ps/transport-leakfix-test-updates'

Test updates.

* ps/transport-leakfix-test-updates:
  transport: mark more tests leak-free

10 months agoMerge branch 'tb/incremental-midx-part-1'
Junio C Hamano [Mon, 19 Aug 2024 18:07:37 +0000 (11:07 -0700)] 
Merge branch 'tb/incremental-midx-part-1'

Incremental updates of multi-pack index files.

* tb/incremental-midx-part-1:
  midx: implement support for writing incremental MIDX chains
  t/t5313-pack-bounds-checks.sh: prepare for sub-directories
  t: retire 'GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP'
  midx: implement verification support for incremental MIDXs
  midx: support reading incremental MIDX chains
  midx: teach `midx_fanout_add_midx_fanout()` about incremental MIDXs
  midx: teach `midx_preferred_pack()` about incremental MIDXs
  midx: teach `midx_contains_pack()` about incremental MIDXs
  midx: remove unused `midx_locate_pack()`
  midx: teach `fill_midx_entry()` about incremental MIDXs
  midx: teach `nth_midxed_offset()` about incremental MIDXs
  midx: teach `bsearch_midx()` about incremental MIDXs
  midx: introduce `bsearch_one_midx()`
  midx: teach `nth_bitmapped_pack()` about incremental MIDXs
  midx: teach `nth_midxed_object_oid()` about incremental MIDXs
  midx: teach `prepare_midx_pack()` about incremental MIDXs
  midx: teach `nth_midxed_pack_int_id()` about incremental MIDXs
  midx: add new fields for incremental MIDX chains
  Documentation: describe incremental MIDX format

10 months agoMerge branch 'jc/tests-no-useless-tee'
Junio C Hamano [Mon, 19 Aug 2024 18:07:37 +0000 (11:07 -0700)] 
Merge branch 'jc/tests-no-useless-tee'

Test fixes.

* jc/tests-no-useless-tee:
  tests: drop use of 'tee' that hides exit status

10 months agoMerge branch 'rs/unit-tests-test-run'
Junio C Hamano [Mon, 19 Aug 2024 18:07:36 +0000 (11:07 -0700)] 
Merge branch 'rs/unit-tests-test-run'

Unit-test framework has learned a simple control structure to allow
embedding test statements in-line instead of having to create a new
function to contain them.

* rs/unit-tests-test-run:
  t-strvec: use if_test
  t-reftable-basics: use if_test
  t-ctype: use if_test
  unit-tests: add if_test
  unit-tests: show location of checks outside of tests
  t0080: use here-doc test body

10 months agoSync with 'maint'
Junio C Hamano [Fri, 16 Aug 2024 19:53:18 +0000 (12:53 -0700)] 
Sync with 'maint'

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoPrepare for 2.46.1
Junio C Hamano [Wed, 14 Aug 2024 22:02:29 +0000 (15:02 -0700)] 
Prepare for 2.46.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'sj/ref-fsck'
Junio C Hamano [Fri, 16 Aug 2024 19:51:51 +0000 (12:51 -0700)] 
Merge branch 'sj/ref-fsck'

"git fsck" infrastructure has been taught to also check the sanity
of the ref database, in addition to the object database.

* sj/ref-fsck:
  fsck: add ref name check for files backend
  files-backend: add unified interface for refs scanning
  builtin/refs: add verify subcommand
  refs: set up ref consistency check infrastructure
  fsck: add refs report function
  fsck: add a unified interface for reporting fsck messages
  fsck: make "fsck_error" callback generic
  fsck: rename objects-related fsck error functions
  fsck: rename "skiplist" to "skip_oids"

10 months agoMerge branch 'ps/p4-tests-updates' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:56 +0000 (12:50 -0700)] 
Merge branch 'ps/p4-tests-updates' into maint-2.46

Perforce tests have been updated.
cf. <na5mwletzpnacietbc7pzqcgb622mvrwgrkjgjosysz3gvjcso@gzxxi7d7icr7>

* ps/p4-tests-updates:
  t98xx: mark Perforce tests as memory-leak free
  ci: update Perforce version to r23.2
  t98xx: fix Perforce tests with p4d r23 and newer

10 months agoMerge branch 'ks/unit-test-comment-typofix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:56 +0000 (12:50 -0700)] 
Merge branch 'ks/unit-test-comment-typofix' into maint-2.46

Typofix.

* ks/unit-test-comment-typofix:
  unit-tests/test-lib: fix typo in check_pointer_eq() description

10 months agoMerge branch 'dh/encoding-trace-optim' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:55 +0000 (12:50 -0700)] 
Merge branch 'dh/encoding-trace-optim' into maint-2.46

An expensive operation to prepare tracing was done in re-encoding
code path even when the tracing was not requested, which has been
corrected.

* dh/encoding-trace-optim:
  convert: return early when not tracing

10 months agoMerge branch 'dd/notes-empty-no-edit-by-default' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:55 +0000 (12:50 -0700)] 
Merge branch 'dd/notes-empty-no-edit-by-default' into maint-2.46

"git notes add -m '' --allow-empty" and friends that take prepared
data to create notes should not invoke an editor, but it started
doing so since Git 2.42, which has been corrected.

* dd/notes-empty-no-edit-by-default:
  notes: do not trigger editor when adding an empty note

10 months agoMerge branch 'jc/doc-rebase-fuzz-vs-offset-fix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:54 +0000 (12:50 -0700)] 
Merge branch 'jc/doc-rebase-fuzz-vs-offset-fix' into maint-2.46

"git rebase --help" referred to "offset" (the difference between
the location a change was taken from and the change gets replaced)
incorrectly and called it "fuzz", which has been corrected.

* jc/doc-rebase-fuzz-vs-offset-fix:
  doc: difference in location to apply is "offset", not "fuzz"

10 months agoMerge branch 'tn/doc-commit-fix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:54 +0000 (12:50 -0700)] 
Merge branch 'tn/doc-commit-fix' into maint-2.46

Docfix.

* tn/doc-commit-fix:
  doc: remove dangling closing parenthesis

10 months agoMerge branch 'pw/add-patch-with-suppress-blank-empty' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:53 +0000 (12:50 -0700)] 
Merge branch 'pw/add-patch-with-suppress-blank-empty' into maint-2.46

"git add -p" by users with diff.suppressBlankEmpty set to true
failed to parse the patch that represents an unmodified empty line
with an empty line (not a line with a single space on it), which
has been corrected.

* pw/add-patch-with-suppress-blank-empty:
  add-patch: use normalize_marker() when recounting edited hunk
  add-patch: handle splitting hunks with diff.suppressBlankEmpty

10 months agoMerge branch 'jt/doc-post-receive-hook-update' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:53 +0000 (12:50 -0700)] 
Merge branch 'jt/doc-post-receive-hook-update' into maint-2.46

Doc update.

* jt/doc-post-receive-hook-update:
  doc: clarify post-receive hook behavior

10 months agoMerge branch 'jc/how-to-maintain-updates' (early part) into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:52 +0000 (12:50 -0700)] 
Merge branch 'jc/how-to-maintain-updates' (early part) into maint-2.46

* 'jc/how-to-maintain-updates' (early part):
  howto-maintain: update daily tasks
  howto-maintain: cover a whole development cycle

10 months agoMerge branch 'jc/doc-one-shot-export-with-shell-func' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:51 +0000 (12:50 -0700)] 
Merge branch 'jc/doc-one-shot-export-with-shell-func' into maint-2.46

It has been documented that we avoid "VAR=VAL shell_func" and why.

* jc/doc-one-shot-export-with-shell-func:
  CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func"

10 months agoMerge branch 'jc/checkout-no-op-switch-errors' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:51 +0000 (12:50 -0700)] 
Merge branch 'jc/checkout-no-op-switch-errors' into maint-2.46

"git checkout --ours" (no other arguments) complained that the
option is incompatible with branch switching, which is technically
correct, but found confusing by some users.  It now says that the
user needs to give pathspec to specify what paths to checkout.

* jc/checkout-no-op-switch-errors:
  checkout: special case error messages during noop switching

10 months agoThe fifth batch
Junio C Hamano [Thu, 15 Aug 2024 20:21:43 +0000 (13:21 -0700)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'xx/diff-tree-remerge-diff-fix'
Junio C Hamano [Thu, 15 Aug 2024 20:22:16 +0000 (13:22 -0700)] 
Merge branch 'xx/diff-tree-remerge-diff-fix'

"git rev-list ... | git diff-tree -p --remerge-diff --stdin" should
behave more or less like "git log -p --remerge-diff" but instead it
crashed, forgetting to prepare a temporary object store needed.

* xx/diff-tree-remerge-diff-fix:
  diff-tree: fix crash when used with --remerge-diff

10 months agoMerge branch 'jc/refs-symref-referent'
Junio C Hamano [Thu, 15 Aug 2024 20:22:15 +0000 (13:22 -0700)] 
Merge branch 'jc/refs-symref-referent'

The refs API has been taught to give symref target information to
the users of ref iterators, allowing for-each-ref and friends to
avoid an extra ref_resolve_* API call per a symbolic ref.

* jc/refs-symref-referent:
  ref-filter: populate symref from iterator
  refs: add referent to each_ref_fn
  refs: keep track of unresolved reference value in iterators

10 months agoMerge branch 'ps/submodule-ref-format'
Junio C Hamano [Thu, 15 Aug 2024 20:22:14 +0000 (13:22 -0700)] 
Merge branch 'ps/submodule-ref-format'

Support to specify ref backend for submodules has been enhanced.

* ps/submodule-ref-format:
  object: fix leaking packfiles when closing object store
  submodule: fix leaking seen submodule names
  submodule: fix leaking fetch tasks
  builtin/submodule: allow "add" to use different ref storage format
  refs: fix ref storage format for submodule ref stores
  builtin/clone: propagate ref storage format to submodules
  builtin/submodule: allow cloning with different ref storage format
  git-submodule.sh: break overly long command lines

10 months agoMerge branch 'ag/t7004-modernize'
Junio C Hamano [Thu, 15 Aug 2024 20:22:13 +0000 (13:22 -0700)] 
Merge branch 'ag/t7004-modernize'

Coding style fixes to a test script.

* ag/t7004-modernize:
  t7004: make use of write_script
  t7004: use single quotes instead of double quotes
  t7004: begin the test body on the same line as test_expect_success
  t7004: description on the same line as test_expect_success
  t7004: do not prepare things outside test_expect_success
  t7004: use indented here-doc
  t7004: one command per line
  t7004: remove space after redirect operators

10 months agoMerge branch 'ps/reftable-stack-compaction'
Junio C Hamano [Thu, 15 Aug 2024 20:22:13 +0000 (13:22 -0700)] 
Merge branch 'ps/reftable-stack-compaction'

The code paths to compact multiple reftable files have been updated
to correctly deal with multiple compaction triggering at the same
time.

* ps/reftable-stack-compaction:
  reftable/stack: handle locked tables during auto-compaction
  reftable/stack: fix corruption on concurrent compaction
  reftable/stack: use lock_file when adding table to "tables.list"
  reftable/stack: do not die when fsyncing lock file files
  reftable/stack: simplify tracking of table locks
  reftable/stack: update stats on failed full compaction
  reftable/stack: test compaction with already-locked tables
  reftable/stack: extract function to setup stack with N tables
  reftable/stack: refactor function to gather table sizes

10 months agoMerge branch 'es/doc-platform-support-policy'
Junio C Hamano [Thu, 15 Aug 2024 20:22:12 +0000 (13:22 -0700)] 
Merge branch 'es/doc-platform-support-policy'

A policy document that describes platform support levels and
expectation on platform stakeholders has been introduced.

* es/doc-platform-support-policy:
  Documentation: add platform support policy

10 months agoMerge branch 'gt/unit-test-hashmap'
Junio C Hamano [Thu, 15 Aug 2024 20:22:12 +0000 (13:22 -0700)] 
Merge branch 'gt/unit-test-hashmap'

An existing test of hashmap API has been rewritten with the
unit-test framework.

* gt/unit-test-hashmap:
  t: port helper/test-hashmap.c to unit-tests/t-hashmap.c

10 months agoMerge branch 'jc/t3206-test-when-finished-fix'
Junio C Hamano [Thu, 15 Aug 2024 20:22:11 +0000 (13:22 -0700)] 
Merge branch 'jc/t3206-test-when-finished-fix'

Test clean-up.

* jc/t3206-test-when-finished-fix:
  t3206: test_when_finished before dirtying operations, not after

10 months agoMerge branch 'rs/t-example-simplify'
Junio C Hamano [Thu, 15 Aug 2024 20:22:11 +0000 (13:22 -0700)] 
Merge branch 'rs/t-example-simplify'

Unit test simplification.

* rs/t-example-simplify:
  t-example-decorate: remove test messages

10 months agoMerge branch 'jc/safe-directory'
Junio C Hamano [Thu, 15 Aug 2024 20:22:10 +0000 (13:22 -0700)] 
Merge branch 'jc/safe-directory'

Follow-up on 2.45.1 regression fix.

* jc/safe-directory:
  safe.directory: setting safe.directory="." allows the "current" directory
  safe.directory: normalize the configured path
  safe.directory: normalize the checked path
  safe.directory: preliminary clean-up

10 months agoThe fourth batch
Junio C Hamano [Wed, 14 Aug 2024 21:17:22 +0000 (14:17 -0700)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'tb/t7704-deflake'
Junio C Hamano [Wed, 14 Aug 2024 21:54:58 +0000 (14:54 -0700)] 
Merge branch 'tb/t7704-deflake'

A test that fails on an unusually slow machine was found, and made
less likely to cause trouble by lengthening the expiry value it
uses.

* tb/t7704-deflake:
  t/t7704-repack-cruft.sh: avoid failures during long-running tests

10 months agoMerge branch 'jc/document-use-of-local'
Junio C Hamano [Wed, 14 Aug 2024 21:54:58 +0000 (14:54 -0700)] 
Merge branch 'jc/document-use-of-local'

Doc update.

* jc/document-use-of-local:
  doc: note that AT&T ksh does not work with our test suite

10 months agoMerge branch 'rs/use-decimal-width'
Junio C Hamano [Wed, 14 Aug 2024 21:54:57 +0000 (14:54 -0700)] 
Merge branch 'rs/use-decimal-width'

Code clean-up.

* rs/use-decimal-width:
  log-tree: use decimal_width()

10 months agoMerge branch 'ss/packed-ref-store-leakfix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:56 +0000 (14:54 -0700)] 
Merge branch 'ss/packed-ref-store-leakfix'

Leakfix.

* ss/packed-ref-store-leakfix:
  refs/files: prevent memory leak by freeing packed_ref_store

10 months agoMerge branch 'cp/unit-test-reftable-tree'
Junio C Hamano [Wed, 14 Aug 2024 21:54:56 +0000 (14:54 -0700)] 
Merge branch 'cp/unit-test-reftable-tree'

A test in reftable library has been rewritten using the unit test
framework.

* cp/unit-test-reftable-tree:
  t-reftable-tree: improve the test for infix_walk()
  t-reftable-tree: add test for non-existent key
  t-reftable-tree: split test_tree() into two sub-test functions
  t: move reftable/tree_test.c to the unit testing framework
  reftable: remove unnecessary curly braces in reftable/tree.c

10 months agoMerge branch 'kl/test-fixes'
Junio C Hamano [Wed, 14 Aug 2024 21:54:55 +0000 (14:54 -0700)] 
Merge branch 'kl/test-fixes'

A flakey test and incorrect calls to strtoX() functions have been
fixed.

* kl/test-fixes:
  t6421: fix test to work when repo dir contains d0
  set errno=0 before strtoX calls

10 months agoMerge branch 'jc/reflog-expire-lookup-commit-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:55 +0000 (14:54 -0700)] 
Merge branch 'jc/reflog-expire-lookup-commit-fix'

"git reflog expire" failed to honor annotated tags when computing
reachable commits.

* jc/reflog-expire-lookup-commit-fix:
  Revert "reflog expire: don't use lookup_commit_reference_gently()"

10 months agoMerge branch 'jr/ls-files-expand-literal-doc'
Junio C Hamano [Wed, 14 Aug 2024 21:54:54 +0000 (14:54 -0700)] 
Merge branch 'jr/ls-files-expand-literal-doc'

Docfix.

* jr/ls-files-expand-literal-doc:
  doc: fix hex code escapes in git-ls-files

10 months agoMerge branch 'jc/leakfix-mailmap'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-mailmap'

Leakfix.

* jc/leakfix-mailmap:
  mailmap: plug memory leak in read_mailmap_blob()

10 months agoMerge branch 'jc/leakfix-hashfile'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-hashfile'

Leakfix.

* jc/leakfix-hashfile:
  csum-file: introduce discard_hashfile()

10 months agoMerge branch 'jc/patch-id'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/patch-id'

The patch parser in "git patch-id" has been tightened to avoid
getting confused by lines that look like a patch header in the log
message.

* jc/patch-id:
  patch-id: tighten code to detect the patch header
  patch-id: rewrite code that detects the beginning of a patch
  patch-id: make get_one_patchid() more extensible
  patch-id: call flush_current_id() only when needed
  t4204: patch-id supports various input format

10 months agoMerge branch 'ps/refs-wo-the-repository'
Junio C Hamano [Wed, 14 Aug 2024 21:54:52 +0000 (14:54 -0700)] 
Merge branch 'ps/refs-wo-the-repository'

In the refs subsystem, implicit reliance of the_repository has been
eliminated; the repository associated with the ref store object is
used instead.

* ps/refs-wo-the-repository:
  refs/reftable: stop using `the_repository`
  refs/packed: stop using `the_repository`
  refs/files: stop using `the_repository`
  refs/files: stop using `the_repository` in `parse_loose_ref_contents()`
  refs: stop using `the_repository`

10 months agoMerge branch 'jc/jl-git-no-advice-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'jc/jl-git-no-advice-fix'

Remove leftover debugging cruft from a test script.

* jc/jl-git-no-advice-fix:
  t0018: remove leftover debugging cruft

10 months agoMerge branch 'tb/config-fixed-value-with-valueless-true'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'tb/config-fixed-value-with-valueless-true'

"git config --value=foo --fixed-value section.key newvalue" barfed
when the existing value in the configuration file used the
valueless true syntax, which has been corrected.

* tb/config-fixed-value-with-valueless-true:
  config.c: avoid segfault with --fixed-value and valueless config

10 months agoMerge branch 'jk/apply-patch-mode-check-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'jk/apply-patch-mode-check-fix'

The patch parser in 'git apply' has been a bit more lenient against
unexpected mode bits, like 100664, recorded on extended header lines.

* jk/apply-patch-mode-check-fix:
  apply: canonicalize modes read from patches

10 months agoMerge branch 'ps/ref-api-cleanup'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'ps/ref-api-cleanup'

Code clean-up.

* ps/ref-api-cleanup:
  refs: drop `ref_store`-less functions

10 months agoMerge branch 'ps/ls-remote-out-of-repo-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'ps/ls-remote-out-of-repo-fix'

A recent update broke "git ls-remote" used outside a repository,
which has been corrected.

* ps/ls-remote-out-of-repo-fix:
  builtin/ls-remote: fall back to SHA1 outside of a repo

10 months agoMerge branch 'jc/transport-leakfix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'jc/transport-leakfix'

Leakfix.

* jc/transport-leakfix:
  transport: fix leak with transport helper URLs

10 months agoMerge branch 'rh/http-proxy-path'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'rh/http-proxy-path'

The value of http.proxy can have "path" at the end for a socks
proxy that listens to a unix-domain socket, but we started to
discard it when we taught proxy auth code path to use the
credential helpers, which has been corrected.

* rh/http-proxy-path:
  http: do not ignore proxy path

10 months agoMerge branch 'cp/unit-test-reftable-pq'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'cp/unit-test-reftable-pq'

The tests for "pq" part of reftable library got rewritten to use
the unit test framework.

* cp/unit-test-reftable-pq:
  t-reftable-pq: add tests for merged_iter_pqueue_top()
  t-reftable-pq: add test for index based comparison
  t-reftable-pq: make merged_iter_pqueue_check() callable by reference
  t-reftable-pq: make merged_iter_pqueue_check() static
  t: move reftable/pq_test.c to the unit testing framework
  reftable: change the type of array indices to 'size_t' in reftable/pq.c
  reftable: remove unnecessary curly braces in reftable/pq.c

10 months agoMerge branch 'jk/osxkeychain-username-is-nul-terminated'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'jk/osxkeychain-username-is-nul-terminated'

The credential helper to talk to OSX keychain sometimes sent
garbage bytes after the username, which has been corrected.

* jk/osxkeychain-username-is-nul-terminated:
  credential/osxkeychain: respect NUL terminator in username

10 months agoMerge branch 'ps/leakfixes-part-3'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'ps/leakfixes-part-3'

More leakfixes.

* ps/leakfixes-part-3: (24 commits)
  commit-reach: fix trivial memory leak when computing reachability
  convert: fix leaking config strings
  entry: fix leaking pathnames during delayed checkout
  object-name: fix leaking commit list items
  t/test-repository: fix leaking repository
  builtin/credential-cache: fix trivial leaks
  builtin/worktree: fix leaking derived branch names
  builtin/shortlog: fix various trivial memory leaks
  builtin/rerere: fix various trivial memory leaks
  builtin/credential-store: fix leaking credential
  builtin/show-branch: fix several memory leaks
  builtin/rev-parse: fix memory leak with `--parseopt`
  builtin/stash: fix various trivial memory leaks
  builtin/remote: fix various trivial memory leaks
  builtin/remote: fix leaking strings in `branch_list`
  builtin/ls-remote: fix leaking `pattern` strings
  builtin/submodule--helper: fix leaking buffer in `is_tip_reachable`
  builtin/submodule--helper: fix leaking clone depth parameter
  builtin/name-rev: fix various trivial memory leaks
  builtin/describe: fix trivial memory leak when describing blob
  ...

10 months agobuiltin/diff: free symmetric diff members
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:58 +0000 (08:52 +0200)] 
builtin/diff: free symmetric diff members

We populate a `struct symdiff` in case the user has requested a
symmetric diff. Part of this is to populate a `skip` bitmap that
indicates which commits shall be ignored in the diff. But while this
bitmap is dynamically allocated, we never free it.

Fix this by introducing and calling a new `symdiff_release()` function
that does this for us.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff: free state populated via options
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:55 +0000 (08:52 +0200)] 
diff: free state populated via options

The `objfind` and `anchors` members of `struct diff_options` are
populated via option parsing, but are never freed in `diff_free()`. Fix
this to plug those memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/log: fix leak when showing converted blob contents
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:53 +0000 (08:52 +0200)] 
builtin/log: fix leak when showing converted blob contents

In `show_blob_object()`, we proactively call `textconv_object()`. In
case we have a textconv driver for this blob we will end up showing the
converted contents, otherwise we'll show the un-converted contents of it
instead.

When the object has been converted we never free the buffer containing
the converted contents. Fix this to plug this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agouserdiff: fix leaking memory for configured diff drivers
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:50 +0000 (08:52 +0200)] 
userdiff: fix leaking memory for configured diff drivers

The userdiff structures may be initialized either statically on the
stack or dynamically via configuration keys. In the latter case we end
up leaking memory because we didn't have any infrastructure to discern
those strings which have been allocated statically and those which have
been allocated dynamically.

Refactor the code such that we have two pointers for each of these
strings: one that holds the value as accessed by other subsystems, and
one that points to the same string in case it has been allocated. Like
this, we can safely free the second pointer and thus plug those memory
leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/format-patch: fix various trivial memory leaks
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:44 +0000 (08:52 +0200)] 
builtin/format-patch: fix various trivial memory leaks

There are various memory leaks hit by git-format-patch(1). Basically all
of them are trivial, except that un-setting `diffopt.no_free` requires
us to unset the `diffopt.file` because we manually close it already.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff: fix leak when parsing invalid ignore regex option
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:42 +0000 (08:52 +0200)] 
diff: fix leak when parsing invalid ignore regex option

When parsing invalid ignore regexes passed via the `-I` option we don't
free already-allocated memory, leading to a memory leak. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agounpack-trees: clear index when not propagating it
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:39 +0000 (08:52 +0200)] 
unpack-trees: clear index when not propagating it

When provided a pointer to a destination index, then `unpack_trees()`
will end up copying its `o->internal.result` index into the provided
pointer. In those cases it is thus not necessary to free the index, as
we have transferred ownership of it.

There are cases though where we do not end up transferring ownership of
the memory, but `clear_unpack_trees_porcelain()` will never discard the
index in that case and thus cause a memory leak. And right now it cannot
do so in the first place because we have no indicator of whether we did
or didn't transfer ownership of the index.

Adapt the code to zero out the index in case we transfer its ownership.
Like this, we can now unconditionally discard the index when being asked
to clear the `unpack_trees_options`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agosequencer: release todo list on error paths
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:36 +0000 (08:52 +0200)] 
sequencer: release todo list on error paths

We're not releasing the `todo_list` in `sequencer_pick_revisions()` when
hitting an error path. Restructure the function to have a common exit
path such that we can easily clean up the list and thus plug this memory
leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agomerge-ort: unconditionally release attributes index
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:33 +0000 (08:52 +0200)] 
merge-ort: unconditionally release attributes index

We conditionally release the index used for reading gitattributes in
merge-ort based on whether or the index has been populated. This check
uses `cache_nr` as a condition. This isn't sufficient though, as the
variable may be zero even when some other parts of the index have been
populated. This leads to memory leaks when sparse checkouts are in use,
as we may not end up releasing the sparse checkout patterns.

Fix this issue by unconditionally releasing the index.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/fast-export: plug leaking tag names
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:31 +0000 (08:52 +0200)] 
builtin/fast-export: plug leaking tag names

When resolving revisions in `get_tags_and_duplicates()`, we only
partially manage the lifetime of `full_name`. In fact, managing its
lifetime properly is almost impossible because we put direct pointers to
that variable into multiple lists without duplicating the string. The
consequence is that these strings will ultimately leak.

Refactor the code to make the lists we put those names into duplicate
the memory. This allows us to properly free the string as required and
thus plugs the memory leak.

While this requires us to allocate more data overall, it shouldn't be
all that bad given that the number of allocations corresponds with the
number of command line parameters, which typically aren't all that many.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/fast-export: fix leaking diff options
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:26 +0000 (08:52 +0200)] 
builtin/fast-export: fix leaking diff options

Before calling `handle_commit()` in a loop, we set `diffopt.no_free`
such that its contents aren't getting freed inside of `handle_commit()`.
We never unset that flag though, which means that the structure's
allocated resources will ultimately leak.

Fix this by unsetting the flag after the loop such that we release its
resources via `release_revisions()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/fast-import: plug trivial memory leaks
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:23 +0000 (08:52 +0200)] 
builtin/fast-import: plug trivial memory leaks

Plug some trivial memory leaks in git-fast-import(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/notes: fix leaking `struct notes_tree` when merging notes
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:20 +0000 (08:52 +0200)] 
builtin/notes: fix leaking `struct notes_tree` when merging notes

We allocate a `struct notes_tree` in `merge_commit()` which we then
initialize via `init_notes()`. It's not really necessary to allocate the
structure though given that we never pass ownership to the caller.
Furthermore, the allocation leads to a memory leak because despite its
name, `free_notes()` doesn't free the `notes_tree` but only clears it.

Fix this issue by converting the code to use an on-stack variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/rebase: fix leaking `commit.gpgsign` value
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:17 +0000 (08:52 +0200)] 
builtin/rebase: fix leaking `commit.gpgsign` value

In `get_replay_opts()`, we override the `gpg_sign` field that already
got populated by `sequencer_init_config()` in case the user has
"commit.gpgsign" set in their config. This creates a memory leak because
we overwrite the previously assigned value, which may have already
pointed to an allocated string.

Let's plug the memory leak by freeing the value before we overwrite it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoconfig: fix leaking comment character config
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:14 +0000 (08:52 +0200)] 
config: fix leaking comment character config

When the comment line character has been specified multiple times in the
configuration, then `git_default_core_config()` will cause a memory leak
because it unconditionally copies the string into `comment_line_str`
without free'ing the previous value. In fact, it can't easily free the
value in the first place because it may contain a string constant.

Refactor the code such that we track allocated comment character strings
via a separate non-constant variable `comment_line_str_to_free`. Adapt
sites that set `comment_line_str` to set both and free the old value
that was stored in `comment_line_str_to_free`.

This memory leak is being hit in t3404. As there are still other memory
leaks in that file we cannot yet mark it as passing with leak checking
enabled.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agosubmodule-config: fix leaking name entry when traversing submodules
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:12 +0000 (08:52 +0200)] 
submodule-config: fix leaking name entry when traversing submodules

We traverse through submodules in the tree via `tree_entry()`, passing
to it a `struct name_entry` that it is supposed to populate with the
tree entry's contents. We unnecessarily allocate this variable instead
of passing a variable that is allocated on the stack, and the ultimately
don't even free that variable. This is unnecessary and leaks memory.

Convert the variable to instead be allocated on the stack to plug the
memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoread-cache: fix leaking hashfile when writing index fails
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:06 +0000 (08:52 +0200)] 
read-cache: fix leaking hashfile when writing index fails

In `do_write_index()`, we use a `struct hashfile` to write the index
with a trailer hash. In case the write fails though, we never clean up
the allocated `hashfile` state and thus leak memory.

Refactor the code to have a common exit path where we can free this and
other allocated memory. While at it, refactor our use of `strbuf`s such
that we reuse the same buffer to avoid some unneeded allocations.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobulk-checkin: fix leaking state TODO
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:03 +0000 (08:52 +0200)] 
bulk-checkin: fix leaking state TODO

When flushing a bulk-checking to disk we also reset the `struct
bulk_checkin_packfile` state. But while we free some of its members,
others aren't being free'd, leading to memory leaks:

  - The temporary packfile name is not getting freed.

  - The `struct hashfile` only gets freed in case we end up calling
    `finalize_hashfile()`. There are code paths though where that is not
    the case, namely when nothing has been written. For this, we need to
    make `free_hashfile()` public.

Fix those leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoobject-name: fix leaking symlink paths in object context
Patrick Steinhardt [Wed, 14 Aug 2024 06:52:00 +0000 (08:52 +0200)] 
object-name: fix leaking symlink paths in object context

The object context may be populated with symlink contents when reading a
symlink, but the associated strbuf doesn't ever get released when
releasing the object context, causing a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoobject-file: fix memory leak when reading corrupted headers
Patrick Steinhardt [Wed, 14 Aug 2024 06:51:58 +0000 (08:51 +0200)] 
object-file: fix memory leak when reading corrupted headers

When reading corrupt object headers in `read_loose_object()`, we bail
out immediately. This causes a memory leak though because we would have
already initialized the zstream in `unpack_loose_header()`, and it is
the callers responsibility to finish the zstream even on error. While
this feels weird, other callsites do it correctly already.

Fix this leak by ending the zstream even on errors. We may want to
revisit this interface in the future such that the callee handles this
for us already when there was an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agogit: fix leaking system paths
Patrick Steinhardt [Wed, 14 Aug 2024 06:51:55 +0000 (08:51 +0200)] 
git: fix leaking system paths

Git has some flags to make it output system paths as they have been
compiled into Git. This is done by calling `system_path()`, which
returns an allocated string. This string isn't ever free'd though,
creating a memory leak.

Plug those leaks. While they are surfaced by t0211, there are more
memory leaks looming exposed by that test suite and it thus does not yet
pass with the memory leak checker enabled.

Helped-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoremote: plug memory leak when aliasing URLs
Patrick Steinhardt [Wed, 14 Aug 2024 06:51:52 +0000 (08:51 +0200)] 
remote: plug memory leak when aliasing URLs

When we have a `url.*.insteadOf` configuration, then we end up aliasing
URLs when populating remotes. One place where this happens is in
`alias_all_urls()`, where we loop through all remotes and then alias
each of their URLs. The actual aliasing logic is then contained in
`alias_url()`, which returns an allocated string that contains the new
URL. This URL replaces the old URL that we have in the strvec that
contains all remote URLs.

We replace the remote URLs via `strvec_replace()`, which does not hand
over ownership of the new string to the vector. Still, we didn't free
the aliased URL and thus have a memory leak here. Fix it by freeing the
aliased string.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoref-filter: populate symref from iterator
John Cai [Fri, 9 Aug 2024 15:37:51 +0000 (15:37 +0000)] 
ref-filter: populate symref from iterator

With a previous commit, the reference the symbolic ref points to is saved
in the ref iterator records. Instead of making a separate call to
resolve_refdup() each time, we can just populate the ref_array_item with
the value from the iterator.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: add referent to each_ref_fn
John Cai [Fri, 9 Aug 2024 15:37:50 +0000 (15:37 +0000)] 
refs: add referent to each_ref_fn

Add a parameter to each_ref_fn so that callers to the ref APIs
that use this function as a callback can have acess to the
unresolved value of a symbolic ref.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: keep track of unresolved reference value in iterators
John Cai [Fri, 9 Aug 2024 15:37:49 +0000 (15:37 +0000)] 
refs: keep track of unresolved reference value in iterators

Since ref iterators do not hold onto the direct value of a reference
without resolving it, the only way to get ahold of a direct value of a
symbolic ref is to make a separate call to refs_read_symbolic_ref.

To make accessing the direct value of a symbolic ref more efficient,
let's save the direct value of the ref in the iterators for both the
files backend and the reftable backend.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff-tree: fix crash when used with --remerge-diff
Xing Xin [Fri, 9 Aug 2024 07:24:52 +0000 (07:24 +0000)] 
diff-tree: fix crash when used with --remerge-diff

When using "git-diff-tree" to get the tree diff for merge commits with
the diff format set to `remerge`, a bug is triggered as shown below:

  $ git diff-tree -r --remerge-diff 363337e6eb
  363337e6eb812d0c0d785ed4261544f35559ff8b
  BUG: log-tree.c:1006: did a remerge diff without remerge_objdir?!?

This bug is reported by `log-tree.c:do_remerge_diff`, where a bug check
added in commit 7b90ab467a (log: clean unneeded objects during log
--remerge-diff, 2022-02-02) detects the absence of `remerge_objdir` when
attempting to clean up temporary objects generated during the remerge
process.

After some further digging, I find that the remerge-related diff options
were introduced in db757e8b8d (show, log: provide a --remerge-diff
capability, 2022-02-02), which also affect the setup of `rev_info` for
"git-diff-tree", but were not accounted for in the original
implementation (inferred from the commit message).

Elijah Newren, the author of the remerge diff feature, notes that other
callers of `log-tree.c:log_tree_commit` (the only caller of
`log-tree.c:do_remerge_diff`) also exist, but:

  `builtin/am.c`: manually sets all flags; remerge_diff is not among them
  `sequencer.c`: manually sets all flags; remerge_diff is not among them

so `builtin/diff-tree.c` really is the only caller that was overlooked
when remerge-diff functionality was added.

This commit resolves the crash by adding `remerge_objdir` setup logic to
`builtin/diff-tree.c`, mirroring `builtin/log.c:cmd_log_walk_no_free`.
It also includes the necessary cleanup for `remerge_objdir`.

Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agotests: drop use of 'tee' that hides exit status
Junio C Hamano [Thu, 8 Aug 2024 21:19:25 +0000 (14:19 -0700)] 
tests: drop use of 'tee' that hides exit status

A few tests have "| tee output" downstream of a git command, and
then inspect the contents of the file.  The net effect is that we
use an extra process, and hide the exit status from the upstream git
command.

In any of these tests, I do not see a reason why we want to hide a
possible failure from these git commands.  Replace the use of tee
with a plain simple redirection.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoThe third batch
Junio C Hamano [Wed, 7 Aug 2024 16:46:53 +0000 (09:46 -0700)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>