]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
8 months agobuiltin/maintenance: fix leak in `get_schedule_cmd()`
Patrick Steinhardt [Thu, 26 Sep 2024 11:47:02 +0000 (13:47 +0200)] 
builtin/maintenance: fix leak in `get_schedule_cmd()`

The `get_schedule_cmd()` function allows us to override the schedule
command with a specific test command such that we can verify the
underlying logic in a platform-independent way. Its memory management is
somewhat wild though, because it basically gives up and assigns an
allocated string to the string constant output pointer. While this part
is marked with `UNLEAK()` to mask this, we also leak the local string
lists.

Rework the function such that it has a separate out parameter. If set,
we will assign it the final allocated command. Plug the other memory
leaks and create a common exit path.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/maintenance: fix leaking config string
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:59 +0000 (13:46 +0200)] 
builtin/maintenance: fix leaking config string

When parsing the maintenance strategy from config we allocate a config
string, but do not free it after parsing it. Plug this leak by instead
using `git_config_get_string_tmp()`, which does not allocate any memory.

This leak is exposed by t7900, but plugging it alone does not make the
test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agopromisor-remote: fix leaking partial clone filter
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:57 +0000 (13:46 +0200)] 
promisor-remote: fix leaking partial clone filter

The partial clone filter of a promisor remote is never free'd, causing
memory leaks. Furthermore, in case multiple partial clone filters are
defined for the same remote, we'd overwrite previous values without
freeing them.

Fix these leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agogrep: fix leaking grep pattern
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:54 +0000 (13:46 +0200)] 
grep: fix leaking grep pattern

When creating a pattern via `create_grep_pat()` we allocate the pattern
member of the structure regardless of the token type. But later, when we
try to free the structure, we free the pattern member conditionally on
the token type and thus leak memory.

Plug this leak. The leak is exposed by t7814, but plugging it alone does
not make the whole test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agosubmodule: fix leaking submodule ODB paths
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:48 +0000 (13:46 +0200)] 
submodule: fix leaking submodule ODB paths

In `add_submodule_odb_by_path()` we add a path into a global string
list. The list is initialized with `NODUP`, which means that we do not
pass ownership of strings to the list. But we use `xstrdup()` when we
insert a path, with the consequence that the string will never get
free'd.

Plug the leak by marking the list as `DUP`. There is only a single
callsite where we insert paths anyway, and as explained above that
callsite was mishandling the allocation.

This leak is exposed by t7814, but plugging it does not make the whole
test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agotrace2: destroy context stored in thread-local storage
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:45 +0000 (13:46 +0200)] 
trace2: destroy context stored in thread-local storage

Each thread may have a specific context in the trace2 subsystem that we
set up via thread-local storage. We do not set up a destructor for this
data though, which means that the context data will leak.

Plug this leak by installing a destructor. This leak is exposed by
t7814, but plugging it alone does not make the whole test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/difftool: plug several trivial memory leaks
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:43 +0000 (13:46 +0200)] 
builtin/difftool: plug several trivial memory leaks

There are several leaking data structures in git-difftool(1). Plug them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/repack: fix leaking configuration
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:40 +0000 (13:46 +0200)] 
builtin/repack: fix leaking configuration

When repacking, we assemble git-pack-objects(1) arguments both for the
"normal" pack and for the cruft pack. This configuration gets populated
with a bunch of `OPT_PASSTHRU` options that we end up passing to the
child process. These options are allocated, but never free'd.

Create a new `pack_objects_args_release()` function that releases the
memory for us and call it for both sets of options.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agodiffcore-order: fix leaking buffer when parsing orderfiles
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:37 +0000 (13:46 +0200)] 
diffcore-order: fix leaking buffer when parsing orderfiles

In `prepare_order()` we parse an orderfile and assign it to a global
array. In order to save on some allocations, we replace newlines with
NUL characters and then assign pointers into the allocated buffer to
that array. This can cause the buffer to be completely unreferenced
though in some cases, e.g. because the order file is empty or because we
had to use `xmemdupz()` to copy the lines instead of NUL-terminating
them.

Refactor the code to always `xmemdupz()` the strings. This is a bit
simpler, and it is rather unlikely that saving a handful of allocations
really matters. This allows us to release the string buffer and thus
plug the memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoparse-options: free previous value of `OPTION_FILENAME`
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:32 +0000 (13:46 +0200)] 
parse-options: free previous value of `OPTION_FILENAME`

The `OPTION_FILENAME` option always assigns either an allocated string
or `NULL` to the value. In case it is passed multiple times it does not
know to free the previous value though, which causes a memory leak.

Refactor the function to always free the previous value. None of the
sites where this option is used pass a string constant, so this change
is safe.

While at it, fix the argument of `fix_filename()` to be a string
constant. The only reason why it's not is because we use it as an
in-out-parameter, where the input is a constant and the output is not.
This is weird and unnecessary, as we can just return the result instead
of using the parameter for this.

This leak is being hit in t7621, but plugging it alone does not make the
test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agodiff: fix leaking orderfile option
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:29 +0000 (13:46 +0200)] 
diff: fix leaking orderfile option

The `orderfile` diff option is being assigned via `OPT_FILENAME()`,
which assigns an allocated string to the variable. We never free it
though, causing a memory leak.

Change the type of the string to `char *` and free it to plug the leak.
This also requires us to use `xstrdup()` to assign the global config to
it in case it is set.

This leak is being hit in t7621, but plugging it alone does not make the
test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/pull: fix leaking "ff" option
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:26 +0000 (13:46 +0200)] 
builtin/pull: fix leaking "ff" option

The `opt_ff` field gets populated either via `OPT_PASSTHRU` via
`config_get_ff()` or when `--rebase` is passed. So we sometimes end up
overriding the value in `opt_ff` with another value, but we do not free
the old value, causing a memory leak.

Adapt the type of the variable to be `char *` and consistently assign
allocated strings to it such that we can easily free it when it is being
overridden.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agodir: fix off by one errors for ignored and untracked entries
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:24 +0000 (13:46 +0200)] 
dir: fix off by one errors for ignored and untracked entries

In `treat_directory()` we perform some logic to handle ignored and
untracked entries. When populating a directory with entries we first
save the current number of ignored/untracked entries and then populate
new entries at the end of our arrays that keep track of those entries.
When we figure out that all entries have been ignored/are untracked we
then remove this tail of entries from those vectors again. But there is
an off by one error in both paths that causes us to not free the first
ignored and untracked entries, respectively.

Fix these off-by-one errors to plug the resulting leak. While at it,
massage the code a bit to match our modern code style.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/submodule--helper: fix leaking remote ref on errors
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:21 +0000 (13:46 +0200)] 
builtin/submodule--helper: fix leaking remote ref on errors

When `update_submodule()` fails we return with `die_message()`, which
only causes us to print the same message as `die()` would without
actually causing the process to die. We don't free memory in that case
and thus leak memory.

Fix the leak by freeing the remote ref.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agot/helper: fix leaking subrepo in nested submodule config helper
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:18 +0000 (13:46 +0200)] 
t/helper: fix leaking subrepo in nested submodule config helper

In the "submodule-nested-repo-config" helper we create a submodule
repository and print its configuration. We do not clear the repo,
causing a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/submodule--helper: fix leaking error buffer
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:14 +0000 (13:46 +0200)] 
builtin/submodule--helper: fix leaking error buffer

Fix leaking error buffer when `compute_alternate_path()` fails.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/submodule--helper: clear child process when not running it
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:11 +0000 (13:46 +0200)] 
builtin/submodule--helper: clear child process when not running it

In `runcommand_in_submodule_cb()` we may end up not executing the child
command when `argv` is empty. But we still populate the command with
environment variables and other things, which needs cleanup. This leads
to a memory leak because we do not call `finish_command()`.

Fix this by clearing the child process when we don't execute it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agosubmodule: fix leaking update strategy
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:08 +0000 (13:46 +0200)] 
submodule: fix leaking update strategy

We're not freeing the submodule update strategy command. Provide a
helper function that does this for us and call it in
`update_data_release()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agogit: fix leaking argv when handling builtins
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:06 +0000 (13:46 +0200)] 
git: fix leaking argv when handling builtins

In `handle_builtin()` we may end up creating an ad-hoc argv array in
case we see that the command line contains the "--help" parameter. In
this case we observe two memory leaks though:

  - We leak the `struct strvec` itself because we directly exit after
    calling `run_builtin()`, without bothering about any cleanups.

  - Even if we free'd that vector we'd end up leaking some of its
    strings because `run_builtin()` will modify the array.

Plug both of these leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/help: fix leaking `html_path` when reading config multiple times
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:03 +0000 (13:46 +0200)] 
builtin/help: fix leaking `html_path` when reading config multiple times

The `html_path` variable gets populated via `git_help_config()`, which
puts an allocated string into it if its value has been configured. We do
not clear the old value though, which causes a memory leak in case the
config exists multiple times.

Plug this leak. The leak is exposed by t0012, but plugging it alone is
not sufficient to make the test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobuiltin/help: fix dangling reference to `html_path`
Patrick Steinhardt [Thu, 26 Sep 2024 11:46:00 +0000 (13:46 +0200)] 
builtin/help: fix dangling reference to `html_path`

In `get_html_page_path()` we may end up assigning the return value of
`system_path()` to the global `html_path` variable. But as we also
assign the returned value to `to_free`, we will deallocate its memory
upon returning from the function. Consequently, `html_path` will now
point to deallocated memory.

Fix this issue by instead assigning the value to a separate local
variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'ps/leakfixes-part-6' into ps/leakfixes-part-7
Junio C Hamano [Mon, 16 Sep 2024 21:03:30 +0000 (14:03 -0700)] 
Merge branch 'ps/leakfixes-part-6' into ps/leakfixes-part-7

* ps/leakfixes-part-6: (22 commits)
  builtin/repack: fix leaking keep-pack list
  merge-ort: fix two leaks when handling directory rename modifications
  match-trees: fix leaking prefixes in `shift_tree()`
  builtin/fmt-merge-msg: fix leaking buffers
  builtin/grep: fix leaking object context
  builtin/pack-objects: plug leaking list of keep-packs
  builtin/repack: fix leaking line buffer when packing promisors
  negotiator/skipping: fix leaking commit entries
  shallow: fix leaking members of `struct shallow_info`
  shallow: free grafts when unregistering them
  object: clear grafts when clearing parsed object pool
  gpg-interface: fix misdesigned signing key interfaces
  send-pack: fix leaking push cert nonce
  remote: fix leak in reachability check of a remote-tracking ref
  remote: fix leaking tracking refs
  builtin/submodule--helper: fix leaking refs on push-check
  submodule: fix leaking fetch task data
  upload-pack: fix leaking child process data on reachability checks
  builtin/push: fix leaking refspec query result
  send-pack: fix leaking common object IDs
  ...

9 months agoSync with Git 2.46.1
Junio C Hamano [Fri, 13 Sep 2024 22:28:15 +0000 (15:28 -0700)] 
Sync with Git 2.46.1

9 months agoThe sixteenth batch
Junio C Hamano [Fri, 13 Sep 2024 21:48:30 +0000 (14:48 -0700)] 
The sixteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'bl/trailers-and-incomplete-last-line-fix'
Junio C Hamano [Fri, 13 Sep 2024 22:27:45 +0000 (15:27 -0700)] 
Merge branch 'bl/trailers-and-incomplete-last-line-fix'

The interpret-trailers command failed to recognise the end of the
message when the commit log ends in an incomplete line.

* bl/trailers-and-incomplete-last-line-fix:
  interpret-trailers: handle message without trailing newline

9 months agoMerge branch 'rj/cygwin-has-dev-tty'
Junio C Hamano [Fri, 13 Sep 2024 22:27:44 +0000 (15:27 -0700)] 
Merge branch 'rj/cygwin-has-dev-tty'

Cygwin does have /dev/tty support that is needed by things like
single-key input mode.

* rj/cygwin-has-dev-tty:
  config.mak.uname: add HAVE_DEV_TTY to cygwin config section

9 months agoMerge branch 'rs/diff-exit-code-fix'
Junio C Hamano [Fri, 13 Sep 2024 22:27:43 +0000 (15:27 -0700)] 
Merge branch 'rs/diff-exit-code-fix'

In a few corner cases "git diff --exit-code" failed to report
"changes" (e.g., renamed without any content change), which has
been corrected.

* rs/diff-exit-code-fix:
  diff: report dirty submodules as changes in builtin_diff()
  diff: report copies and renames as changes in run_diff_cmd()

9 months agoMerge branch 'jc/doc-skip-fetch-all-and-prefetch'
Junio C Hamano [Fri, 13 Sep 2024 22:27:43 +0000 (15:27 -0700)] 
Merge branch 'jc/doc-skip-fetch-all-and-prefetch'

Doc updates.

* jc/doc-skip-fetch-all-and-prefetch:
  doc: remote.*.skip{DefaultUpdate,FetchAll} stops prefetch

9 months agoMerge branch 'ds/doc-wholesale-disabling-advice-messages'
Junio C Hamano [Fri, 13 Sep 2024 22:27:43 +0000 (15:27 -0700)] 
Merge branch 'ds/doc-wholesale-disabling-advice-messages'

The environment GIT_ADVICE has been intentionally kept undocumented
to discourage its use by interactive users.  Add documentation to
help tool writers.

* ds/doc-wholesale-disabling-advice-messages:
  advice: recommend GIT_ADVICE=0 for tools

9 months agoMerge branch 'jk/sparse-fdleak-fix'
Junio C Hamano [Fri, 13 Sep 2024 22:27:42 +0000 (15:27 -0700)] 
Merge branch 'jk/sparse-fdleak-fix'

A file descriptor left open is now properly closed when "git
sparse-checkout" updates the sparse patterns.

* jk/sparse-fdleak-fix:
  sparse-checkout: use fdopen_lock_file() instead of xfdopen()
  sparse-checkout: check commit_lock_file when writing patterns
  sparse-checkout: consolidate cleanup when writing patterns

9 months agoMerge branch 'ds/scalar-no-tags'
Junio C Hamano [Fri, 13 Sep 2024 22:27:42 +0000 (15:27 -0700)] 
Merge branch 'ds/scalar-no-tags'

The "scalar clone" command learned the "--no-tags" option.

* ds/scalar-no-tags:
  scalar: add --no-tags option to 'scalar clone'

9 months agoGit 2.46.1 v2.46.1
Junio C Hamano [Fri, 13 Sep 2024 21:05:56 +0000 (14:05 -0700)] 
Git 2.46.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'rj/compat-terminal-unused-fix' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:52 +0000 (15:26 -0700)] 
Merge branch 'rj/compat-terminal-unused-fix' into maint-2.46

Build fix.

* rj/compat-terminal-unused-fix:
  compat/terminal: mark parameter of git_terminal_prompt() UNUSED

9 months agoMerge branch 'jc/config-doc-update' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:52 +0000 (15:26 -0700)] 
Merge branch 'jc/config-doc-update' into maint-2.46

Docfix.

* jc/config-doc-update:
  git-config.1: fix description of --regexp in synopsis
  git-config.1: --get-all description update

9 months agoMerge branch 'aa/cat-file-batch-output-doc' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:51 +0000 (15:26 -0700)] 
Merge branch 'aa/cat-file-batch-output-doc' into maint-2.46

Docfix.

* aa/cat-file-batch-output-doc:
  docs: explain the order of output in the batched mode of git-cat-file(1)

9 months agoMerge branch 'cl/config-regexp-docfix' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:51 +0000 (15:26 -0700)] 
Merge branch 'cl/config-regexp-docfix' into maint-2.46

Docfix.

* cl/config-regexp-docfix:
  doc: replace 3 dash with correct 2 dash in git-config(1)

9 months agoMerge branch 'jc/coding-style-c-operator-with-spaces' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:51 +0000 (15:26 -0700)] 
Merge branch 'jc/coding-style-c-operator-with-spaces' into maint-2.46

Write down whitespacing rules around C opeators.

* jc/coding-style-c-operator-with-spaces:
  CodingGuidelines: spaces around C operators

9 months agoMerge branch 'ps/stash-keep-untrack-empty-fix' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:50 +0000 (15:26 -0700)] 
Merge branch 'ps/stash-keep-untrack-empty-fix' into maint-2.46

A corner case bug in "git stash" was fixed.

* ps/stash-keep-untrack-empty-fix:
  builtin/stash: fix `--keep-index --include-untracked` with empty HEAD

9 months agoMerge branch 'ps/index-pack-outside-repo-fix' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:50 +0000 (15:26 -0700)] 
Merge branch 'ps/index-pack-outside-repo-fix' into maint-2.46

"git verify-pack" and "git index-pack" started dying outside a
repository, which has been corrected.

* ps/index-pack-outside-repo-fix:
  builtin/index-pack: fix segfaults when running outside of a repo

9 months agoMerge branch 'jk/free-commit-buffer-of-skipped-commits' into maint-2.46
Junio C Hamano [Fri, 13 Sep 2024 22:26:49 +0000 (15:26 -0700)] 
Merge branch 'jk/free-commit-buffer-of-skipped-commits' into maint-2.46

The code forgot to discard unnecessary in-core commit buffer data
for commits that "git log --skip=<number>" traversed but omitted
from the output, which has been corrected.

* jk/free-commit-buffer-of-skipped-commits:
  revision: free commit buffers for skipped commits

9 months agoSync with 'maint'
Junio C Hamano [Thu, 12 Sep 2024 18:48:46 +0000 (11:48 -0700)] 
Sync with 'maint'

9 months agoThe fifteenth batch
Junio C Hamano [Thu, 12 Sep 2024 17:36:55 +0000 (10:36 -0700)] 
The fifteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'kl/cat-file-on-sparse-index'
Junio C Hamano [Thu, 12 Sep 2024 18:47:23 +0000 (11:47 -0700)] 
Merge branch 'kl/cat-file-on-sparse-index'

"git cat-file" works well with the sparse-index, and gets marked as
such.

* kl/cat-file-on-sparse-index:
  builtin/cat-file: mark 'git cat-file' sparse-index compatible
  t1092: allow run_on_* functions to use standard input

9 months agoMerge branch 'jk/messages-with-excess-lf-fix'
Junio C Hamano [Thu, 12 Sep 2024 18:47:23 +0000 (11:47 -0700)] 
Merge branch 'jk/messages-with-excess-lf-fix'

One-line messages to "die" and other helper functions will get LF
added by these helper functions, but many existing messages had an
unnecessary LF at the end, which have been corrected.

* jk/messages-with-excess-lf-fix:
  drop trailing newline from warning/error/die messages

9 months agoMerge branch 'ps/pack-refs-auto-heuristics'
Junio C Hamano [Thu, 12 Sep 2024 18:47:23 +0000 (11:47 -0700)] 
Merge branch 'ps/pack-refs-auto-heuristics'

"git pack-refs --auto" for the files backend was too aggressive,
which has been a bit tamed.

* ps/pack-refs-auto-heuristics:
  refs/files: use heuristic to decide whether to repack with `--auto`
  t0601: merge tests for auto-packing of refs
  wrapper: introduce `log2u()`

9 months agoMerge branch 'tb/multi-pack-reuse-fix'
Junio C Hamano [Thu, 12 Sep 2024 18:47:23 +0000 (11:47 -0700)] 
Merge branch 'tb/multi-pack-reuse-fix'

A data corruption bug when multi-pack-index is used and the same
objects are stored in multiple packfiles has been corrected.

* tb/multi-pack-reuse-fix:
  builtin/pack-objects.c: do not open-code `MAX_PACK_OBJECT_HEADER`
  pack-bitmap.c: avoid repeated `pack_pos_to_offset()` during reuse
  builtin/pack-objects.c: translate bit positions during pack-reuse
  pack-bitmap: tag bitmapped packs with their corresponding MIDX
  t/t5332-multi-pack-reuse.sh: verify pack generation with --strict

9 months agoMerge branch 'gt/unit-test-oid-array'
Junio C Hamano [Thu, 12 Sep 2024 18:47:22 +0000 (11:47 -0700)] 
Merge branch 'gt/unit-test-oid-array'

Another unit-test.

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

9 months agoMerge branch 'ps/index-pack-outside-repo-fix'
Junio C Hamano [Thu, 12 Sep 2024 18:47:22 +0000 (11:47 -0700)] 
Merge branch 'ps/index-pack-outside-repo-fix'

"git verify-pack" and "git index-pack" started dying outside a
repository, which has been corrected.

* ps/index-pack-outside-repo-fix:
  builtin/index-pack: fix segfaults when running outside of a repo

9 months agoMerge branch 'jc/mailinfo-header-cleanup'
Junio C Hamano [Thu, 12 Sep 2024 18:47:22 +0000 (11:47 -0700)] 
Merge branch 'jc/mailinfo-header-cleanup'

Code clean-up.

* jc/mailinfo-header-cleanup:
  mailinfo: we parse fixed headers

9 months agoAnother batch of topics for 2.46.1
Junio C Hamano [Thu, 12 Sep 2024 18:09:46 +0000 (11:09 -0700)] 
Another batch of topics for 2.46.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'jc/grammo-fixes' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:19 +0000 (11:02 -0700)] 
Merge branch 'jc/grammo-fixes' into maint-2.46

Doc updates.

* jc/grammo-fixes:
  doc: grammofix in git-diff-tree
  tutorial: grammofix

9 months agoMerge branch 'jc/tests-no-useless-tee' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:18 +0000 (11:02 -0700)] 
Merge branch 'jc/tests-no-useless-tee' into maint-2.46

Test fixes.

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

9 months agoMerge branch 'jc/how-to-maintain-updates' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:17 +0000 (11:02 -0700)] 
Merge branch 'jc/how-to-maintain-updates' into maint-2.46

Doc updates.

* jc/how-to-maintain-updates:
  howto-maintain: mention preformatted docs

9 months agoMerge branch 'ps/bundle-outside-repo-fix' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:16 +0000 (11:02 -0700)] 
Merge branch 'ps/bundle-outside-repo-fix' into maint-2.46

"git bundle unbundle" outside a repository triggered a BUG()
unnecessarily, which has been corrected.

* ps/bundle-outside-repo-fix:
  bundle: default to SHA1 when reading bundle headers
  builtin/bundle: have unbundle check for repo before opening its bundle

9 months agoMerge branch 'jc/patch-id' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:16 +0000 (11:02 -0700)] 
Merge branch 'jc/patch-id' into maint-2.46

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.
cf. <Zqh2T_2RLt0SeKF7@tanuki>

* 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

9 months agoMerge branch 'jk/apply-patch-mode-check-fix' into maint-2.46
Junio C Hamano [Thu, 12 Sep 2024 18:02:15 +0000 (11:02 -0700)] 
Merge branch 'jk/apply-patch-mode-check-fix' into maint-2.46

Test fix.

* jk/apply-patch-mode-check-fix:
  t4129: fix racy index when calling chmod after git-add
  apply: canonicalize modes read from patches

9 months agoThe fourteenth batch
Junio C Hamano [Tue, 10 Sep 2024 19:06:06 +0000 (12:06 -0700)] 
The fourteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'sp/mailmap'
Junio C Hamano [Tue, 10 Sep 2024 20:16:43 +0000 (13:16 -0700)] 
Merge branch 'sp/mailmap'

Update to a mailmap entry.

* sp/mailmap:
  .mailmap document current address.

9 months agoMerge branch 'ps/declare-pack-redundamt-dead'
Junio C Hamano [Tue, 10 Sep 2024 20:16:43 +0000 (13:16 -0700)] 
Merge branch 'ps/declare-pack-redundamt-dead'

"git pack-redundant" has been marked for removal in Git 3.0.

* ps/declare-pack-redundamt-dead:
  Documentation/BreakingChanges: announce removal of git-pack-redundant(1)

9 months agoMerge branch 'ah/mergetols-vscode'
Junio C Hamano [Tue, 10 Sep 2024 20:16:42 +0000 (13:16 -0700)] 
Merge branch 'ah/mergetols-vscode'

"git mergetool" learned to use VSCode as a merge backend.

* ah/mergetols-vscode:
  mergetools: vscode: new tool

9 months agoMerge branch 'rj/compat-terminal-unused-fix'
Junio C Hamano [Tue, 10 Sep 2024 20:16:41 +0000 (13:16 -0700)] 
Merge branch 'rj/compat-terminal-unused-fix'

Build fix.

* rj/compat-terminal-unused-fix:
  compat/terminal: mark parameter of git_terminal_prompt() UNUSED

9 months agoMerge branch 'jk/free-commit-buffer-of-skipped-commits'
Junio C Hamano [Tue, 10 Sep 2024 20:16:41 +0000 (13:16 -0700)] 
Merge branch 'jk/free-commit-buffer-of-skipped-commits'

The code forgot to discard unnecessary in-core commit buffer data
for commits that "git log --skip=<number>" traversed but omitted
from the output, which has been corrected.

* jk/free-commit-buffer-of-skipped-commits:
  revision: free commit buffers for skipped commits

9 months agodoc: remote.*.skip{DefaultUpdate,FetchAll} stops prefetch
Junio C Hamano [Mon, 9 Sep 2024 15:53:11 +0000 (08:53 -0700)] 
doc: remote.*.skip{DefaultUpdate,FetchAll} stops prefetch

Back when 7cc91a2f (Add the configuration option skipFetchAll,
2009-11-09) added for the sole purpose of adding skipFetchAll as a
synonym to skipDefaultUpdate, there was no explanation about the
reason why it was needed., but these two configuration variables
mean exactly the same thing.

Also, when we taught the "prefetch" task to "git maintenance" later,
we did make it pay attention to the setting, but we forgot to
document it.

Document these variables as synonyms that collectively implements
the last-one-wins semantics, and also clarify that the prefetch task
is also controlled by this variable.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoconfig.mak.uname: add HAVE_DEV_TTY to cygwin config section
Ramsay Jones [Mon, 9 Sep 2024 01:23:48 +0000 (02:23 +0100)] 
config.mak.uname: add HAVE_DEV_TTY to cygwin config section

If neither HAVE_DEV_TTY nor GIT_WINDOWS_NATIVE is set, while compiling
the 'compat/terminal.c' code, then the fallback code calls the system
getpass() function. Unfortunately, this ignores the 'echo' parameter of
the git_terminal_prompt() function, since it has no way to implement that
functionality. This results in a less than optimal user experience on
cygwin, which does not define either of those build flags.

However, cygwin does have a functional '/dev/tty', so that it can build
with HAVE_DEV_TTY and benefit from the improved user experience.

The improved git_terminal_prompt() function that comes with HAVE_DEV_TTY
is used in the git_prompt() function, which in turn is used by the
'git credential', 'git bisect' and 'git help' commands. In addition to
git_terminal_prompt(), read_key_without_echo() is likewise improved and
used by the 'git add -p' command.

While using the 'git credential fill' command, for example:

  $ printf "%s\n" protocol=https host=example.com path=git | ./git credential fill
  Username for 'https://example.com': user
  Password for 'https://user@example.com':
  protocol=https
  host=example.com
  username=user
  password=pass
  $

The 'user' name is now echoed while typing (the password isn't), where this
wasn't the case before.

When using the auto-correct feature:

  $ ./git -c help.autocorrect=prompt fred
  WARNING: You called a Git command named 'fred', which does not exist.
  Run 'grep' instead [y/N]? n
  $ ./git -c help.autocorrect=prompt fred
  WARNING: You called a Git command named 'fred', which does not exist.
  Run 'grep' instead [y/N]? y
  fatal: no pattern given
  $

The user can actually see what they are typing at the prompt. Similar
comments apply to 'git bisect':

  $ ./git bisect bad master~1
  You need to start by "git bisect start"

  Do you want me to do it for you [Y/n]? y
  status: waiting for both good and bad commits
  status: waiting for good commit(s), bad commit known
  $ ./git bisect reset
  Already on 'master-tmp'
  $

  $ ./git bisect start
  status: waiting for both good and bad commits
  $ ./git bisect bad master~1
  status: waiting for good commit(s), bad commit known
  $ ./git bisect next
  warning: bisecting only with a bad commit
  Are you sure [Y/n]? n
  $ ./git bisect reset
  Already on 'master-tmp'
  $

The read_key_without_echo() function leads to a much improved 'git add -p'
command, when the 'interactive.singleKey' configuration is set:

  $ cd ..
  $ mkdir test-git
  $ cd test-git
  $ git init -q
  $ echo foo >file
  $ git add file
  $ echo bar >file
  $ ../git/git -c interactive.singleKey=true add -p
  diff --git a/file b/file
  index 257cc56..5716ca5 100644
  --- a/file
  +++ b/file
  @@ -1 +1 @@
  -foo
  +bar
  (1/1) Stage this hunk [y,n,q,a,d,e,p,?]? y

  $

Note that, not only is the user input echoed, but that it is immediately
accepted (without having to type <return>) and the program exits with the
hunk staged (in this case) or not.

In order to reap these benefits, set the HAVE_DEV_TTY build flag in the
cygwin configuration section of config.mak.uname.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodiff: report dirty submodules as changes in builtin_diff()
René Scharfe [Sun, 8 Sep 2024 07:08:35 +0000 (09:08 +0200)] 
diff: report dirty submodules as changes in builtin_diff()

The diff machinery has two ways to detect changes to set the exit code:
Just comparing hashes and comparing blob contents.  The latter is needed
if certain changes have to be ignored, e.g. with --ignore-space-change
or --ignore-matching-lines.  It's enabled by the diff_options flag
diff_from_contents.

The slower mode as never considered submodules (and subrepos) as changes
with --submodule=diff or --submodule=log, which is inconsistent with
--submodule=short (the default).  Fix it.

d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09) set diff_from_contents if external diff
programs are allowed.  This is the default e.g. for git diff, and so
that change exposed the inconsistency much more widely.

Reported-by: David Hull <david.hull@friendbuy.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodiff: report copies and renames as changes in run_diff_cmd()
René Scharfe [Sun, 8 Sep 2024 07:05:44 +0000 (09:05 +0200)] 
diff: report copies and renames as changes in run_diff_cmd()

The diff machinery has two ways to detect changes to set the exit code:
Just comparing hashes and comparing blob contents.  The latter is needed
if certain changes have to be ignored, e.g. with --ignore-space-change
or --ignore-matching-lines.  It's enabled by the diff_options flag
diff_from_contents.

The slower mode has never considered copies and renames to be changes,
which is inconsistent with the quicker one.  Fix it.  Even if we ignore
the file contents (because it's empty or contains only ignored lines),
there's still the meta data change of adding or changing a filename, so
we need to report it in the exit code.

d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09) set diff_from_contents if external diff
programs are allowed.  This is the default e.g. for git diff, and so
that change exposed the inconsistency much more widely.

Reported-by: Jorge Luis Martinez Gomez <jol@jol.dev>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoadvice: recommend GIT_ADVICE=0 for tools
Derrick Stolee [Fri, 6 Sep 2024 20:22:35 +0000 (20:22 +0000)] 
advice: recommend GIT_ADVICE=0 for tools

The GIT_ADVICE environment variable was added implicitly in b79deeb5544
(advice: add --no-advice global option, 2024-05-03) but was not
documented. Add documentation to show that it is an option for tools
that want to disable these messages. Make note that while the
--no-advice option exists, older Git versions will fail to parse that
option. The environment variable presents a way to change the behavior
of Git versions that understand it without disrupting older versions.

Co-authored-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoscalar: add --no-tags option to 'scalar clone'
Derrick Stolee [Fri, 6 Sep 2024 20:21:41 +0000 (20:21 +0000)] 
scalar: add --no-tags option to 'scalar clone'

Some large repositories use tags to track a huge list of release
versions. While this choice is costly on the ref advertisement, it is
further wasteful for clients who do not need those tags. Allow clients
to optionally skip the tag advertisement.

This behavior is similar to that of 'git clone --no-tags' implemented in
0dab2468ee5 (clone: add a --no-tags option to clone without tags,
2017-04-26), including the modification of the remote.origin.tagOpt
config value to include "--no-tags".

One thing that is opposite of the 'git clone' implementation is that
this allows '--tags' as an assumed option, which can be naturally negated
with '--no-tags'. The clone command does not accept '--tags' but allows
"--no-no-tags" as the negation of its '--no-tags' option.

While testing this option, combine the test with the previously untested
'--no-src' option introduced in 4527db8ff8c (scalar: add --[no-]src
option, 2023-08-28).

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoThe thirteenth batch
Junio C Hamano [Fri, 6 Sep 2024 17:22:39 +0000 (10:22 -0700)] 
The thirteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'jk/maybe-unused-cleanup'
Junio C Hamano [Fri, 6 Sep 2024 17:38:52 +0000 (10:38 -0700)] 
Merge branch 'jk/maybe-unused-cleanup'

Code clean-up.

* jk/maybe-unused-cleanup:
  grep: prefer UNUSED to MAYBE_UNUSED for pcre allocators
  gc: drop MAYBE_UNUSED annotation from used parameter

9 months agoMerge branch 'jc/unused-on-windows'
Junio C Hamano [Fri, 6 Sep 2024 17:38:51 +0000 (10:38 -0700)] 
Merge branch 'jc/unused-on-windows'

Fix more fallouts from -Werror=unused-parameter.

* jc/unused-on-windows:
  refs/files-backend: work around -Wunused-parameter

9 months agoMerge branch 'jc/maybe-unused'
Junio C Hamano [Fri, 6 Sep 2024 17:38:50 +0000 (10:38 -0700)] 
Merge branch 'jc/maybe-unused'

Developer doc updates.

* jc/maybe-unused:
  CodingGuidelines: also mention MAYBE_UNUSED

9 months agoMerge branch 'jk/unused-parameters'
Junio C Hamano [Fri, 6 Sep 2024 17:38:49 +0000 (10:38 -0700)] 
Merge branch 'jk/unused-parameters'

Make our codebase compilable with the -Werror=unused-parameter
option.

* jk/unused-parameters:
  CodingGuidelines: mention -Wunused-parameter and UNUSED
  config.mak.dev: enable -Wunused-parameter by default
  compat: mark unused parameters in win32/mingw functions
  compat: disable -Wunused-parameter in win32/headless.c
  compat: disable -Wunused-parameter in 3rd-party code
  t-reftable-readwrite: mark unused parameter in callback function
  gc: mark unused config parameter in virtual functions

9 months agoMerge branch 'jk/send-email-mailmap'
Junio C Hamano [Fri, 6 Sep 2024 17:38:49 +0000 (10:38 -0700)] 
Merge branch 'jk/send-email-mailmap'

"git send-email" learned "--mailmap" option to allow rewriting the
recipient addresses.

* jk/send-email-mailmap:
  send-email: add mailmap support via sendemail.mailmap and --mailmap
  check-mailmap: add options for additional mailmap sources
  check-mailmap: accept "user@host" contacts

9 months ago.mailmap document current address.
Stephen P. Smith [Fri, 6 Sep 2024 15:30:02 +0000 (08:30 -0700)] 
.mailmap document current address.

Cox Communications no longer supports email and transfered accounts to
yahoo. I closed the account at yahoo since I use gmail.com.

Signed-off-by: Stephen P. Smith <ishchis2@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agointerpret-trailers: handle message without trailing newline
Brian Lyles [Fri, 6 Sep 2024 14:50:08 +0000 (09:50 -0500)] 
interpret-trailers: handle message without trailing newline

When git-interpret-trailers is used to add a trailer to a message that
does not end in a trailing newline, the new trailer is added on the line
immediately following the message instead of as a trailer block
separated from the message by a blank line.

For example, if a message's text was exactly "The subject" with no
trailing newline present, `git interpret-trailers --trailer
my-trailer=true` will result in the following malformed commit message:

    The subject
    my-trailer: true

While it is generally expected that a commit message should end with a
newline character, git-interpret-trailers should not be returning an
invalid message in this case.

Use `strbuf_complete_line` to ensure that the message ends with a
newline character when reading the input.

Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosparse-checkout: use fdopen_lock_file() instead of xfdopen()
Jeff King [Fri, 6 Sep 2024 03:48:41 +0000 (23:48 -0400)] 
sparse-checkout: use fdopen_lock_file() instead of xfdopen()

When updating sparse patterns, we open a lock_file to write out the new
data. The lock_file struct holds the file descriptor, but we call
fdopen() to get a stdio handle to do the actual write.

After we finish writing, we fflush() so that all of the data is on disk,
and then call commit_lock_file() which closes the descriptor. But we
never fclose() the stdio handle, leaking it.

The obvious solution seems like it would be to just call fclose(). But
when? If we do it before commit_lock_file(), then the lock_file code is
left thinking it owns the now-closed file descriptor, and will do an
extra close() on the descriptor. But if we do it before, we have the
opposite problem: the lock_file code will close the descriptor, and
fclose() will do the extra close().

We can handle this correctly by using fdopen_lock_file(). That leaves
ownership of the stdio handle with the lock_file, which knows not to
double-close it.

We do have to adjust the code a bit:

  - we have to handle errors ourselves; we can just die(), since that's
    what xfdopen() would have done (and we can even provide a more
    specific error message).

  - we no longer need to call fflush(); committing the lock-file
    auto-closes it, which will now do the flush for us. As a bonus, this
    will actually check that the flush was successful before renaming
    the file into place.

  - we can get rid of the local "fd" variable, since we never look at it
    ourselves now

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosparse-checkout: check commit_lock_file when writing patterns
Jeff King [Fri, 6 Sep 2024 03:47:38 +0000 (23:47 -0400)] 
sparse-checkout: check commit_lock_file when writing patterns

When writing a new "sparse-checkout" file, we do the usual strategy of
writing to a lockfile and committing it into place. But we don't check
the outcome of commit_lock_file(). Failing there would prevent us from
writing a bogus file (good), but we would ignore the error and return a
successful exit code (bad).

Fix this by calling die(). Note that we need to keep the sparse_filename
variable valid for longer, since the filename stored in the lock_file
struct will be dropped when we run commit_lock_file().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosparse-checkout: consolidate cleanup when writing patterns
Jeff King [Fri, 6 Sep 2024 03:47:08 +0000 (23:47 -0400)] 
sparse-checkout: consolidate cleanup when writing patterns

In write_patterns_and_update(), we always need to free the pattern list
before exiting the function.  Rather than handling it manually when we
return early, we can jump to an "out" label where cleanup happens. This
let us drop one line, but also establishes a pattern we can use for
other cleanup.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodrop trailing newline from warning/error/die messages
Jeff King [Thu, 5 Sep 2024 08:51:49 +0000 (04:51 -0400)] 
drop trailing newline from warning/error/die messages

Our error reporting routines append a trailing newline, and the strings
we pass to them should not include them (otherwise we get an extra blank
line after the message).

These cases were all found by looking at the results of:

  git grep -P '[^_](error|error_errno|warning|die|die_errno)\(.*\\n"[,)]' '*.c'

Note that we _do_ sometimes include a newline in the middle of such
messages, to create multiline output (hence our grep matching "," or ")"
after we see the newline, so we know we're at the end of the string).

It's possible that one or more of these cases could intentionally be
including a blank line at the end, but having looked at them all
manually, I think these are all just mistakes.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/repack: fix leaking keep-pack list
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:41 +0000 (12:09 +0200)] 
builtin/repack: fix leaking keep-pack list

The list of packs to keep is populated via a command line option but
never free'd. Plug this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agomerge-ort: fix two leaks when handling directory rename modifications
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:39 +0000 (12:09 +0200)] 
merge-ort: fix two leaks when handling directory rename modifications

There are two leaks in `apply_directory_rename_modifications()`:

  - We do not release the `dirs_to_insert` string list.

  - We do not release some `conflict_info` we put into the
    `opt->priv->paths` string map.

The former is trivial to fix. The latter is a bit less straight forward:
the `util` pointer of the string map may sometimes point to data that
has been allocated via `CALLOC()`, while at other times it may point to
data that has been allocated via a `mem_pool`.

It very much seems like an oversight that we didn't also allocate the
conflict info in this code path via the memory pool, though. So let's
fix that, which will also plug the memory leak for us.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agomatch-trees: fix leaking prefixes in `shift_tree()`
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:36 +0000 (12:09 +0200)] 
match-trees: fix leaking prefixes in `shift_tree()`

In `shift_tree()` we allocate two empty strings that we end up
passing to `match_trees()`. If that function finds a better match it
will update these pointers to point to a newly allocated strings,
freeing the old strings. We never free the final results though, neither
the ones we have allocated ourselves, nor the one that `match_trees()`
might've returned to us.

Fix the resulting memory leaks by creating a common exit path where we
free them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/fmt-merge-msg: fix leaking buffers
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:34 +0000 (12:09 +0200)] 
builtin/fmt-merge-msg: fix leaking buffers

Fix leaking input and output buffers in git-fmt-merge-msg(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/grep: fix leaking object context
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:31 +0000 (12:09 +0200)] 
builtin/grep: fix leaking object context

Even when `get_oid_with_context()` fails it may have allocated some data
in the object context. But we do not release it in git-grep(1) when the
call fails, leading to a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/pack-objects: plug leaking list of keep-packs
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:26 +0000 (12:09 +0200)] 
builtin/pack-objects: plug leaking list of keep-packs

The `--keep-pack` option of git-pack-objects(1) populates the arguments
into a string list. And while the list is marked as `NODUP` and thus
won't duplicate the strings, the list entries themselves still need to
be free'd. We don't though, causing a leak.

Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/repack: fix leaking line buffer when packing promisors
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:23 +0000 (12:09 +0200)] 
builtin/repack: fix leaking line buffer when packing promisors

In `repack_promisor_objects()` we read output from git-pack-objects(1)
line by line, using `strbuf_getline_lf()`. We never free the line
buffer, causing a memory leak. Plug it.

This leak is being hit in t5616, but plugging it alone is not
sufficient to make the whole test suite leak free.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agonegotiator/skipping: fix leaking commit entries
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:20 +0000 (12:09 +0200)] 
negotiator/skipping: fix leaking commit entries

When releasing the skipping negotiator we free its priority queue, but
not the contained entries. Fix this to plug a memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoshallow: fix leaking members of `struct shallow_info`
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:17 +0000 (12:09 +0200)] 
shallow: fix leaking members of `struct shallow_info`

We do not free several struct members in `clear_shallow_info()`. Fix
this to plug the resulting leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoshallow: free grafts when unregistering them
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:15 +0000 (12:09 +0200)] 
shallow: free grafts when unregistering them

When removing a graft via `unregister_shallow()` we remove it from the
grafts array, but do not free the structure. Fix this to plug the leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoobject: clear grafts when clearing parsed object pool
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:12 +0000 (12:09 +0200)] 
object: clear grafts when clearing parsed object pool

We do not clear grafts part of the parsed object pool when clearing the
pool itself, which can lead to memory leaks when a repository is being
cleared.

Fix this by moving `reset_commit_grafts()` into "object.c" and making it
part of the `struct parsed_object_pool` interface such that we can call
it from `parsed_object_pool_clear()`. Adapt `parsed_object_pool_new()`
to take and store a reference to its owning repository, which is needed
by `unparse_commit()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agogpg-interface: fix misdesigned signing key interfaces
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:07 +0000 (12:09 +0200)] 
gpg-interface: fix misdesigned signing key interfaces

The interfaces to retrieve signing keys and their IDs are misdesigned as
they return string constants even though they indeed allocate memory,
which leads to memory leaks. Refactor the code to instead always return
allocated strings and let the callers free them accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosend-pack: fix leaking push cert nonce
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:04 +0000 (12:09 +0200)] 
send-pack: fix leaking push cert nonce

When retrieving the push cert nonce from the server, we first store the
constant returned by `server_feature_value()` and then, if the nonce is
valid, we duplicate the nonce memory to a NUL-terminated string, so that
we can pass it to `generate_push_cert()`. We never free the latter and
thus cause a memory leak.

Fix this by storing the limited-lifetime nonce into a scope-local
variable such that the long-lived, allocated nonce can be easily freed
without having to cast away its constness.

This leak was exposed by t5534, but fixing it is not sufficient to make
the whole test suite leak free.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoremote: fix leak in reachability check of a remote-tracking ref
Patrick Steinhardt [Thu, 5 Sep 2024 10:09:01 +0000 (12:09 +0200)] 
remote: fix leak in reachability check of a remote-tracking ref

In `check_if_includes_upstream()` we retrieve the local ref
corresponding to a remote-tracking ref we want to check reachability
for. We never free that local ref and thus cause a memory leak. Fix
this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoremote: fix leaking tracking refs
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:59 +0000 (12:08 +0200)] 
remote: fix leaking tracking refs

When computing the remote tracking ref we cause two memory leaks:

  - We leak when `remote_tracking()` fails.

  - We leak when the call to `remote_tracking()` succeeds and sets
    `ref->tracking_ref()`.

Fix both of these leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/submodule--helper: fix leaking refs on push-check
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:56 +0000 (12:08 +0200)] 
builtin/submodule--helper: fix leaking refs on push-check

In the push-check subcommand of the submodule helper we acquire a list
of local refs, but never free that list. Fix this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosubmodule: fix leaking fetch task data
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:53 +0000 (12:08 +0200)] 
submodule: fix leaking fetch task data

The `submodule_parallel_fetch` structure contains various data
structures that we use to set up parallel fetches of submodules. We do
not free some of its data though, causing memory leaks. Plug those.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoupload-pack: fix leaking child process data on reachability checks
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:48 +0000 (12:08 +0200)] 
upload-pack: fix leaking child process data on reachability checks

We spawn a git-rev-list(1) command to perform reachability checks in
"upload-pack.c". We do not release memory associated with the process
in error cases though, thus leaking memory.

Fix these by calling `child_process_clear()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/push: fix leaking refspec query result
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:46 +0000 (12:08 +0200)] 
builtin/push: fix leaking refspec query result

When appending a refspec via `refspec_append_mapped()` we leak the
result of `query_refspecs()`. The overall logic around refspec queries
is quite weird, as callers are expected to either set the `src` or `dst`
pointers, and then the (allocated) result will be in the respective
other struct member.

As we have the `src` member set, plugging the memory leak is thus as
easy as just freeing the `dst` member. While at it, use designated
initializers to initialize the structure.

This leak was exposed by t5516, but fixing it is not sufficient to make
the whole test suite leak free.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agosend-pack: fix leaking common object IDs
Patrick Steinhardt [Thu, 5 Sep 2024 10:08:43 +0000 (12:08 +0200)] 
send-pack: fix leaking common object IDs

We're leaking the array of common object IDs in `send_pack()`. Fix this
by creating a common exit path where we free the leaking data. While at
it, unify some other cleanups now that we have a central place to put
them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>