]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
8 months agoreftable/merged: handle allocation failures in `merged_table_init_iter()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:54 +0000 (12:55 +0200)] 
reftable/merged: handle allocation failures in `merged_table_init_iter()`

Handle allocation failures in `merged_table_init_iter()`. While at it,
merge `merged_iter_init()` into the function. It only has a single
caller and merging them makes it easier to handle allocation failures
consistently.

This change also requires us to adapt `reftable_stack_init_*_iterator()`
to bubble up the new error codes of `merged_table_iter_init()`. Adapt
callsites accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/writer: handle allocation failures in `reftable_new_writer()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:48 +0000 (12:55 +0200)] 
reftable/writer: handle allocation failures in `reftable_new_writer()`

Handle allocation failures in `reftable_new_writer()`. Adapt the
function to return an error code to return such failures. While at it,
rename it to match our code style as we have to touch up every callsite
anyway.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/writer: handle allocation failures in `writer_index_hash()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:45 +0000 (12:55 +0200)] 
reftable/writer: handle allocation failures in `writer_index_hash()`

Handle allocation errors in `writer_index_hash()`. Adjust its only
caller in `reftable_writer_add_ref()` accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/record: handle allocation failures when decoding records
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:43 +0000 (12:55 +0200)] 
reftable/record: handle allocation failures when decoding records

Handle allocation failures when decoding records. While at it, fix some
error codes to be `REFTABLE_FORMAT_ERROR`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/record: handle allocation failures on copy
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:40 +0000 (12:55 +0200)] 
reftable/record: handle allocation failures on copy

Handle allocation failures when copying records. While at it, convert
from `xstrdup()` to `reftable_strdup()`. Adapt callsites to check for
error codes.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/basics: handle allocation failures in `parse_names()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:38 +0000 (12:55 +0200)] 
reftable/basics: handle allocation failures in `parse_names()`

Handle allocation failures in `parse_names()` by returning `NULL` in
case any allocation fails. While at it, refactor the function to return
the array directly instead of assigning it to an out-pointer.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/basics: handle allocation failures in `reftable_calloc()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:35 +0000 (12:55 +0200)] 
reftable/basics: handle allocation failures in `reftable_calloc()`

Handle allocation failures in `reftable_calloc()`.

While at it, remove our use of `st_mult()` that would cause us to die on
an overflow. From the caller's point of view there is not much of a
difference between arguments that are too large to be multiplied and a
request that is too big to handle by the allocator: in both cases the
allocation cannot be fulfilled. And in neither of these cases do we want
the reftable library to die.

While we could use `unsigned_mult_overflows()` to handle the overflow
gracefully, we instead open-code it to further our goal of converting
the reftable codebase to become a standalone library that can be reused
by external projects.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable: introduce `reftable_strdup()`
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:30 +0000 (12:55 +0200)] 
reftable: introduce `reftable_strdup()`

The reftable library provides the ability to swap out allocators. There
is a gap here though, because we continue to use `xstrdup()` even in the
case where all the other allocators have been swapped out.

Introduce `reftable_strdup()` that uses `reftable_malloc()` to do the
allocation.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/basics: merge "publicbasics" into "basics"
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:27 +0000 (12:55 +0200)] 
reftable/basics: merge "publicbasics" into "basics"

The split between "basics" and "publicbasics" is somewhat arbitrary and
not in line with how we typically structure code in the reftable
library. While we do indeed split up headers into a public and internal
part, we don't do that for the compilation unit itself. Furthermore, the
declarations for "publicbasics.c" are in "reftable-malloc.h", which
isn't in line with our naming schema, either.

Fix these inconsistencies by:

  - Merging "publicbasics.c" into "basics.c".

  - Renaming "reftable-malloc.h" to "reftable-basics.h" as the public
    header.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/error: introduce out-of-memory error code
Patrick Steinhardt [Wed, 2 Oct 2024 10:55:24 +0000 (12:55 +0200)] 
reftable/error: introduce out-of-memory error code

The reftable library does not use the same memory allocation functions
as the rest of the Git codebase. Instead, as the reftable library is
supposed to be usable as a standalone library without Git, it provides a
set of pluggable memory allocators.

Compared to `xmalloc()` and friends these allocators are _not_ expected
to die when an allocation fails. This design choice is concious, as a
library should leave it to its caller to handle any kind of error. While
it is very likely that the caller cannot really do much in the case of
an out-of-memory situation anyway, we are not the ones to make that
decision.

Curiously though, we never handle allocation errors even though memory
allocation functions are allowed to fail. And as we do not plug in Git's
memory allocator via `reftable_set_alloc()` either the consequence is
that we'd instead segfault as soon as we run out of memory.

While the easy fix would be to wire up `xmalloc()` and friends, it
would only fix the usage of the reftable library in Git itself. Other
users like libgit2, which is about to revive its efforts to land a
backend for reftables, wouldn't be able to benefit from this solution.

Instead, we are about to do it the hard way: adapt all allocation sites
to perform error checking. Introduce a new error code for out-of-memory
errors that we will wire up in subsequent steps.

This commit also serves as the motivator for all the remaining steps in
this series such that we do not have to repeat the same arguments in
every single subsequent commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'ps/reftable-exclude' into ps/reftable-alloc-failures
Junio C Hamano [Mon, 16 Sep 2024 21:06:31 +0000 (14:06 -0700)] 
Merge branch 'ps/reftable-exclude' into ps/reftable-alloc-failures

* ps/reftable-exclude:
  refs/reftable: wire up support for exclude patterns
  reftable/reader: make table iterator reseekable
  t/unit-tests: introduce reftable library
  Makefile: stop listing test library objects twice
  builtin/receive-pack: fix exclude patterns when announcing refs
  refs: properly apply exclude patterns to namespaced refs

9 months agoMerge branch 'cp/unit-test-reftable-stack' into ps/reftable-alloc-failures
Junio C Hamano [Mon, 16 Sep 2024 21:06:06 +0000 (14:06 -0700)] 
Merge branch 'cp/unit-test-reftable-stack' into ps/reftable-alloc-failures

* cp/unit-test-reftable-stack:
  t-reftable-stack: add test for stack iterators
  t-reftable-stack: add test for non-default compaction factor
  t-reftable-stack: use reftable_ref_record_equal() to compare ref records
  t-reftable-stack: use Git's tempfile API instead of mkstemp()
  t: harmonize t-reftable-stack.c with coding guidelines
  t: move reftable/stack_test.c to the unit testing framework

9 months agorefs/reftable: wire up support for exclude patterns
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:16 +0000 (10:50 +0200)] 
refs/reftable: wire up support for exclude patterns

Exclude patterns can be used by reference backends to skip over blocks
of references that are uninteresting to the caller. Reference backends
do not have to wire up support for them, and all callers are expected to
behave as if the backend didn't support them. In fact, the only backend
that supports exclude patterns right now is the "packed" backend.

Exclude patterns can be quite an important performance optimization in
repositories that have loads of references. The patterns are set up in
case "transfer.hideRefs" and friends are configured during a fetch, so
handling these patterns becomes important once there are lots of hidden
refs in a served repository.

Now that we have properly re-seekable reftable iterators we can also
wire up support for these patterns in the "reftable" backend. Doing so
is conceptually simple: once we hit a reference whose prefix matches the
current exclude pattern we re-seek the iterator to the first reference
that doesn't match the pattern anymore. This schema only works for
trivial patterns that do not have any globbing characters in them, but
this restriction also applies do the "packed" backend.

This makes t1419 work with the "reftable" backend with some slight
modifications. Of course it also speeds up listing of references with
hidden refs. The following benchmark prints one reference with 1 million
hidden references:

    Benchmark 1: HEAD~
      Time (mean ± σ):      93.3 ms ±   2.1 ms    [User: 90.3 ms, System: 2.5 ms]
      Range (min … max):    89.8 ms …  97.2 ms    33 runs

    Benchmark 2: HEAD
      Time (mean ± σ):       4.2 ms ±   0.6 ms    [User: 2.2 ms, System: 1.8 ms]
      Range (min … max):     3.1 ms …   8.1 ms    765 runs

    Summary
      HEAD ran
       22.15 ± 3.19 times faster than HEAD~

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoreftable/reader: make table iterator reseekable
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:14 +0000 (10:50 +0200)] 
reftable/reader: make table iterator reseekable

In 67ce50ba26 (Merge branch 'ps/reftable-reusable-iterator', 2024-05-30)
we have refactored the interface of reftable iterators such that they
can be reused in theory. This patch series only landed the required
changes on the interface level, but didn't yet implement the actual
logic to make iterators reusable.

As it turns out almost all of the infrastructure already does support
re-seeking. The only exception is the table iterator, which does not
reset its `is_finished` bit. Do so and add a couple of tests that verify
that we can re-seek iterators.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot/unit-tests: introduce reftable library
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:11 +0000 (10:50 +0200)] 
t/unit-tests: introduce reftable library

We have recently migrated all of the reftable unit tests that were part
of the reftable library into our own unit testing framework. As part of
that migration we have duplicated some of the functionality that was
part of the reftable test framework into each of the migrated test
suites. This was a sensible decision to not have all of the migrations
dependent on each other, but now that the migration is done it makes
sense to deduplicate the functionality again.

Introduce a new reftable test library that hosts some shared code and
adapt tests to use it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMakefile: stop listing test library objects twice
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:08 +0000 (10:50 +0200)] 
Makefile: stop listing test library objects twice

Whenever one adds another test library compilation unit one has to wire
it up twice in the Makefile: once to append it to `UNIT_TEST_OBJS`, and
once to append it to the `UNIT_TEST_PROGS` target. Ideally, we'd just
reuse the `UNIT_TEST_OBJS` variable in the target so that we can avoid
the duplication. But it also contains all the objects for our test
programs, each of which contains a `cmd_main()`, and thus we cannot link
them all into the target executable.

Refactor the code such that `UNIT_TEST_OBJS` does not contain the unit
test program objects anymore, which we can instead manually append to
the `OBJECTS` variable. Like this, the former variable now only contains
objects for test libraries and can thus be reused.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/receive-pack: fix exclude patterns when announcing refs
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:05 +0000 (10:50 +0200)] 
builtin/receive-pack: fix exclude patterns when announcing refs

In `write_head_info()` we announce references to the remote client. We
need to honor "transfer.hideRefs" here so that we do not announce any
references that the client shouldn't be able to learn about. This is
done via two separate mechanisms:

  - We hand over exclude patterns to the reference backend. We can only
    honor "plain" exclude patterns here that do not have prefixes with
    special meaning such as "^" or "!". Filtering down the references is
    handled by `hidden_refs_to_excludes()`.

  - In `show_ref_cb()` we perform a second check against hidden refs.
    For one this is done such that we can handle those special prefixes.
    And second, handling exclude patterns in ref backends is optional,
    so we also have to handle "normal" patterns.

The special-meaning "^" prefix alters whether a hidden ref applies to
the namespace-stripped reference name or the full name. So while we
would usually call `refs_for_each_namespaced_ref()` to only get those
references in the current namespace, we can't because we'd get the
already-rewritten reference names. Instead, we are forced to use
`refs_for_each_fullref_in()` and then manually strip away the namespace
prefix such that we have access to both names.

But this also means that we do not get namespace handling for exclude
patterns, which `refs_for_each_namespaced_ref()` brings for free. This
results in a bug because we potentially end up hiding away references
based on their namespaced name and not on the stripped name as we really
should be doing.

Fix this by manually rewriting the exclude patterns to their namespaced
variants.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agorefs: properly apply exclude patterns to namespaced refs
Patrick Steinhardt [Mon, 16 Sep 2024 08:50:03 +0000 (10:50 +0200)] 
refs: properly apply exclude patterns to namespaced refs

Reference namespaces allow commands like git-upload-pack(1) to serve
different sets of references to the client depending on which namespace
is enabled, which is for example useful in fork networks. Namespaced
refs are stored with a `refs/namespaces/$namespace` prefix, but all the
user will ultimately see is a stripped version where that prefix is
removed.

The way that this interacts with "transfer.hideRefs" is not immediately
obvious: the hidden refs can either apply to the stripped references, or
to the non-stripped ones that still have the namespace prefix. In fact,
the "transfer.hideRefs" machinery does the former and applies to the
stripped reference by default, but rules can have "^" prefixed to switch
this behaviour to instead match against the full reference name.

Namespaces are exclusively handled at the generic "refs" layer, the
respective backends have no clue that such a thing even exists. This
also has the consequence that they cannot handle hiding references as
soon as reference namespaces come into play because they neither know
whether a namespace is active, nor do they know how to strip references
if they are active.

Handling such exclude patterns in `refs_for_each_namespaced_ref()` and
`refs_for_each_fullref_in_prefixes()` is broken though, as both support
that the user passes both namespaces and exclude patterns. In the case
where both are set we will exclude references with unstripped names,
even though we really wanted to exclude references based on their
stripped names.

This only surfaces when:

  - A repository uses reference namespaces.

  - "transfer.hideRefs" is active.

  - The namespaced references are packed into the "packed-refs" file.

None of our tests exercise this scenario, and thus we haven't ever hit
it. While t5509 exercises both (1) and (2), it does not happen to hit
(3). It is trivial to demonstrate the bug though by explicitly packing
refs in the tests, and then we indeed surface the breakage.

Fix this bug by prefixing exclude patterns with the namespace in the
generic layer. The newly introduced function will be used outside of
"refs.c" in the next patch, so we add a declaration to "refs.h".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 agoMerge branch 'cp/unit-test-reftable-stack' into ps/reftable-exclude
Junio C Hamano [Mon, 9 Sep 2024 17:13:44 +0000 (10:13 -0700)] 
Merge branch 'cp/unit-test-reftable-stack' into ps/reftable-exclude

* cp/unit-test-reftable-stack:
  t-reftable-stack: add test for stack iterators
  t-reftable-stack: add test for non-default compaction factor
  t-reftable-stack: use reftable_ref_record_equal() to compare ref records
  t-reftable-stack: use Git's tempfile API instead of mkstemp()
  t: harmonize t-reftable-stack.c with coding guidelines
  t: move reftable/stack_test.c to the unit testing framework

9 months agot-reftable-stack: add test for stack iterators
Chandra Pratap [Sun, 8 Sep 2024 04:06:01 +0000 (09:36 +0530)] 
t-reftable-stack: add test for stack iterators

reftable_stack_init_ref_iterator and reftable_stack_init_log_iterator
as defined by reftable/stack.{c,h} initialize a stack iterator to
iterate over the ref and log records in a reftable stack respectively.
Since these functions are not exercised by any of the existing tests,
add a test for them.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot-reftable-stack: add test for non-default compaction factor
Chandra Pratap [Sun, 8 Sep 2024 04:06:00 +0000 (09:36 +0530)] 
t-reftable-stack: add test for non-default compaction factor

In a recent codebase update (commit ae8e378430, merge branch
'ps/reftable-write-options', 2024/05/13) the geometric factor used
in auto-compaction of reftable tables was made configurable. Add
a test to verify the functionality introduced by this update.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot-reftable-stack: use reftable_ref_record_equal() to compare ref records
Chandra Pratap [Sun, 8 Sep 2024 04:05:59 +0000 (09:35 +0530)] 
t-reftable-stack: use reftable_ref_record_equal() to compare ref records

In the current stack tests, ref records are compared for equality
by sometimes using the dedicated function for ref-record comparison,
reftable_ref_record_equal(), and sometimes by explicity comparing
contents of the ref records.

The latter method is undesired because there can exist unequal ref
records with some of the contents being equal. Replace the latter
instances of ref-record comparison with the former. This has the
added benefit of preserving uniformity throughout the test file.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 agot-reftable-stack: use Git's tempfile API instead of mkstemp()
Chandra Pratap [Sun, 8 Sep 2024 04:05:58 +0000 (09:35 +0530)] 
t-reftable-stack: use Git's tempfile API instead of mkstemp()

Git's tempfile API defined by $GIT_DIR/tempfile.{c,h} provides
a unified interface for tempfile operations. Since reftable/stack.c
uses this API for all its tempfile needs instead of raw functions
like mkstemp(), make the ported stack test strictly use Git's
tempfile API as well.

A bigger benefit is the fact that we know to clean up the tempfile
in case the test fails because it gets registered and pruned via a
signal handler.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot: harmonize t-reftable-stack.c with coding guidelines
Chandra Pratap [Sun, 8 Sep 2024 04:05:57 +0000 (09:35 +0530)] 
t: harmonize t-reftable-stack.c with coding guidelines

Harmonize the newly ported test unit-tests/t-reftable-stack.c
with the following guidelines:
- Single line 'for' statements must omit curly braces.
- Structs must be 0-initialized with '= { 0 }' instead of '= { NULL }'.
- Array sizes and indices should preferably be of type 'size_t' and
  not 'int'.
- Function pointers should be passed as 'func' and not '&func'.

While at it, remove initialization for those variables that are
re-used multiple times, like loop variables.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot: move reftable/stack_test.c to the unit testing framework
Chandra Pratap [Sun, 8 Sep 2024 04:05:56 +0000 (09:35 +0530)] 
t: move reftable/stack_test.c to the unit testing framework

reftable/stack_test.c exercises the functions defined in
reftable/stack.{c, h}. Migrate reftable/stack_test.c to the
unit testing framework. Migration involves refactoring the tests
to use the unit testing framework instead of reftable's test
framework and renaming the tests to be in-line with unit-tests'
standards.

Since some of the tests use set_test_hash() defined by
reftable/test_framework.{c, h} but these files are not
'#included' in the test file, copy this function in the
ported test file.

With the migration of stack test to the unit-tests framework,
"test-tool reftable" becomes a no-op. Hence, get rid of everything
that uses "test-tool reftable" alongside everything that is used
to implement it.

While at it, alphabetically sort the cmds[] list in
helper/test-tool.c by moving the entry for "dump-reftable".

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.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/cat-file: mark 'git cat-file' sparse-index compatible
Kevin Lyles [Tue, 3 Sep 2024 22:06:47 +0000 (22:06 +0000)] 
builtin/cat-file: mark 'git cat-file' sparse-index compatible

This change affects how 'git cat-file' works with the index when
specifying an object with the ":<path>" syntax (which will give file
contents from the index).

'git cat-file' expands a sparse index to a full index any time contents
are requested from the index by specifying an object with the ":<path>"
syntax. This is true even when the requested file is part of the sparse
index, and results in much slower 'git cat-file' operations when working
within the sparse index.

Mark 'git cat-file' as not needing a full index, so that you only pay
the cost of expanding the sparse index to a full index when you request
a file outside of the sparse index.

Add tests to ensure both that:
- 'git cat-file' returns the correct file contents whether or not the
  file is in the sparse index
- 'git cat-file' expands to the full index any time you request
  something outside of the sparse index

Signed-off-by: Kevin Lyles <klyles+github@epic.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot1092: allow run_on_* functions to use standard input
Kevin Lyles [Tue, 3 Sep 2024 22:06:46 +0000 (22:06 +0000)] 
t1092: allow run_on_* functions to use standard input

The 'run_on_sparse' and 'run_on_all' functions do not work correctly for
commands accepting standard input, because they run the same command
multiple times and the first instance consumes it. This also indirectly
affects 'test_all_match' and 'test_sparse_match'.

To allow these functions to work with commands accepting standard input,
first slurp standard input to a temporary file, and then run the command
with its standard input redirected from the temporary file. This ensures
that each command sees the same contents from its standard input.

Note that this does not impact commands that do not read from standard
input; they continue to ignore it. Additionally, existing uses of the
run_on_* functions do not need to do anything differently, as the
standard input of the test environment is already connected to
/dev/null.

We do not explicitly clean up the input files because they are cleaned
up with the rest of the test repositories and their contents may be
useful for figuring out which command failed when a test case fails.

Signed-off-by: Kevin Lyles <klyles@epic.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agorefs/files: use heuristic to decide whether to repack with `--auto`
Patrick Steinhardt [Wed, 4 Sep 2024 08:53:08 +0000 (10:53 +0200)] 
refs/files: use heuristic to decide whether to repack with `--auto`

The `--auto` flag for git-pack-refs(1) allows the ref backend to decide
whether or not a repack is in order. This switch has been introduced
mostly with the "reftable" backend in mind, which already knows to
auto-compact its tables during normal operations. When the flag is set,
then it will use the same auto-compaction mechanism and thus end up
doing nothing in most cases.

The "files" backend does not have any such heuristic yet and instead
packs any loose references unconditionally. So we rewrite the complete
"packed-refs" file even if there's only a single loose reference to be
packed.

Even worse, starting with 9f6714ab3e (builtin/gc: pack refs when using
`git maintenance run --auto`, 2024-03-25), `git pack-refs --auto` is
unconditionally executed via our auto maintenance, so we end up repacking
references every single time auto maintenance kicks in. And while that
commit already mentioned that the "files" backend unconditionally packs
refs now, the author obviously didn't quite think about the consequences
thereof. So while the idea was sound, we really should have added a
heuristic to the "files" backend before implementing it.

Introduce a heuristic that decides whether or not it is worth to pack
loose references. The important factors to decide here are the number of
loose references in comparison to the overall size of the "packed-refs"
file. The bigger the "packed-refs" file, the longer it takes to rewrite
it and thus we scale up the limit of allowed loose references before we
repack.

As is the nature of heuristics, this mechansim isn't obviously
"correct", but should rather be seen as a tradeoff between how much
resources we spend packing refs and how inefficient the ref store
becomes. For all I can say, we have successfully been using the exact
same heuristic in Gitaly for several years by now.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot0601: merge tests for auto-packing of refs
Patrick Steinhardt [Wed, 4 Sep 2024 08:53:03 +0000 (10:53 +0200)] 
t0601: merge tests for auto-packing of refs

We have two tests in t0601 which exercise the same underlying logic,
once via `git pack-refs --auto` and once via `git maintenance run
--auto`. Merge these two tests into one such that it becomes easier to
extend test coverage for both commands at the same time.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agowrapper: introduce `log2u()`
Patrick Steinhardt [Wed, 4 Sep 2024 08:53:00 +0000 (10:53 +0200)] 
wrapper: introduce `log2u()`

We have an implementation of a function that computes the log2 for an
integer. While we could instead use log2(3P), that involves floating
point numbers and is thus needlessly complex and inefficient.

We're about to add a second caller that wants to compute log2 for a
`size_t`. Let's thus move the function into "wrapper.h" such that it
becomes generally available.

While at it, tweak the implementation a bit:

  - The parameter is converted from `int` to `uintmax_t`. This
    conversion is safe to do in "bisect.c" because we already check that
    the argument is positive.

  - The return value is an `unsigned`. It cannot ever be negative, so it
    is pointless for it to be a signed integer.

  - Loop until `!n` instead of requiring that `n > 1` and then subtract
    1 from the result and add a special case for `!sz`. This helps
    compilers to generate more efficient code.

Compilers recognize the pattern of this function and optimize
accordingly. On GCC 14.2 x86_64:

    log2u(unsigned long):
            test    rdi, rdi
            je      .L3
            bsr     rax, rdi
            ret
    .L3:
            mov     eax, -1
            ret

Clang 18.1 does not yet recognize the pattern, but starts to do so on
Clang trunk x86_64. The code isn't quite as efficient as the one
generated by GCC, but still manages to optimize away the loop:

    log2u(unsigned long):
            test    rdi, rdi
            je      .LBB0_1
            shr     rdi
            bsr     rcx, rdi
            mov     eax, 127
            cmovne  rax, rcx
            xor     eax, -64
            add     eax, 65
            ret
    .LBB0_1:
            mov     eax, -1
            ret

The pattern is also recognized on other platforms like ARM64 GCC 14.2.0,
where we end up using `clz`:

    log2u(unsigned long):
            clz     x2, x0
            cmp     x0, 0
            mov     w1, 63
            sub     w0, w1, w2
            csinv   w0, w0, wzr, ne
            ret

Note that we have a similar function `fastlog2()` in the reftable code.
As that codebase is separate from the Git codebase we do not adapt it to
use the new function.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin/index-pack: fix segfaults when running outside of a repo
Patrick Steinhardt [Wed, 4 Sep 2024 06:26:24 +0000 (08:26 +0200)] 
builtin/index-pack: fix segfaults when running outside of a repo

It was reported that git-verify-pack(1) has started to crash with Git
v2.46.0 when run outside of a repository. This is another fallout from
c8aed5e8da (repository: stop setting SHA1 as the default object hash,
2024-05-07), where we have stopped setting the default hash algorithm
for `the_repository`. Consequently, code that relies on `the_hash_algo`
will now crash when it hasn't explicitly been initialized, which may be
the case when running outside of a Git repository.

The crash is not in git-verify-pack(1) but instead in git-index-pack(1),
which gets called by the former. Ideally, both of these programs should
be able to identify the hash algorithm used by the packfile and index
without having to rely on external information. But unfortunately, the
format for neither of them is completely self-describing, so it is not
possible to derive that information. This is a design issue that we
should address by introducing a new packfile version that encodes its
object hash.

For now though the more important fix is to not make either of these
programs crash anymore, which we do by falling back to SHA1 when the
object hash is unconfigured. This pessimizes reading packfiles which
use a different hash than SHA1, but restores previous behaviour.

Reported-by: Ilya K <me@0upti.me>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoDocumentation/BreakingChanges: announce removal of git-pack-redundant(1)
Patrick Steinhardt [Mon, 2 Sep 2024 08:13:00 +0000 (10:13 +0200)] 
Documentation/BreakingChanges: announce removal of git-pack-redundant(1)

The git-pack-redundant(1) command is already in the process of being
phased out and dies unless the user passes the `--i-still-use-this` flag
since 4406522b76 (pack-redundant: escalate deprecation warning to an
error, 2023-03-23). We haven't heard any complaints, so let's announce
the removal of this command in Git 3.0 in our breaking changes document.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoThe twelfth batch
Junio C Hamano [Tue, 3 Sep 2024 16:13:21 +0000 (09:13 -0700)] 
The twelfth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'jc/config-doc-update'
Junio C Hamano [Tue, 3 Sep 2024 16:15:04 +0000 (09:15 -0700)] 
Merge branch 'jc/config-doc-update'

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 'rs/remote-leakfix'
Junio C Hamano [Tue, 3 Sep 2024 16:15:03 +0000 (09:15 -0700)] 
Merge branch 'rs/remote-leakfix'

Leakfix.

* rs/remote-leakfix:
  remote: plug memory leaks at early returns

9 months agoMerge branch 'ps/reftable-concurrent-compaction'
Junio C Hamano [Tue, 3 Sep 2024 16:15:02 +0000 (09:15 -0700)] 
Merge branch 'ps/reftable-concurrent-compaction'

The code path for compacting reftable files saw some bugfixes
against concurrent operation.

* ps/reftable-concurrent-compaction:
  reftable/stack: fix segfault when reload with reused readers fails
  reftable/stack: reorder swapping in the reloaded stack contents
  reftable/reader: keep readers alive during iteration
  reftable/reader: introduce refcounting
  reftable/stack: fix broken refnames in `write_n_ref_tables()`
  reftable/reader: inline `reader_close()`
  reftable/reader: inline `init_reader()`
  reftable/reader: rename `reftable_new_reader()`
  reftable/stack: inline `stack_compact_range_stats()`
  reftable/blocksource: drop malloc block source

9 months agoMerge branch 'js/fetch-push-trace2-annotation'
Junio C Hamano [Tue, 3 Sep 2024 16:15:01 +0000 (09:15 -0700)] 
Merge branch 'js/fetch-push-trace2-annotation'

More trace2 events at key points on push and fetch code paths have
been added.

* js/fetch-push-trace2-annotation:
  send-pack: add new tracing regions for push
  fetch: add top-level trace2 regions
  trace2: implement trace2_printf() for event target

9 months agoMerge branch 'aa/cat-file-batch-output-doc'
Junio C Hamano [Tue, 3 Sep 2024 16:15:01 +0000 (09:15 -0700)] 
Merge branch 'aa/cat-file-batch-output-doc'

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 'dh/runtime-prefix-on-zos'
Junio C Hamano [Tue, 3 Sep 2024 16:15:00 +0000 (09:15 -0700)] 
Merge branch 'dh/runtime-prefix-on-zos'

Support for the RUNTIME_PREFIX feature has been added to z/OS port.

* dh/runtime-prefix-on-zos:
  exec_cmd: RUNTIME_PREFIX on z/OS systems

9 months agoMerge branch 'ps/leakfixes-part-5'
Junio C Hamano [Tue, 3 Sep 2024 16:14:59 +0000 (09:14 -0700)] 
Merge branch 'ps/leakfixes-part-5'

Even more leak fixes.

* ps/leakfixes-part-5:
  transport: fix leaking negotiation tips
  transport: fix leaking arguments when fetching from bundle
  builtin/fetch: fix leaking transaction with `--atomic`
  remote: fix leaking peer ref when expanding refmap
  remote: fix leaks when matching refspecs
  remote: fix leaking config strings
  builtin/fetch-pack: fix leaking refs
  sideband: fix leaks when configuring sideband colors
  builtin/send-pack: fix leaking refspecs
  transport: fix leaking OID arrays in git:// transport data
  t/helper: fix leaking multi-pack-indices in "read-midx"
  builtin/repack: fix leaks when computing packs to repack
  midx-write: fix leaking hashfile on error cases
  builtin/archive: fix leaking `OPT_FILENAME()` value
  builtin/upload-archive: fix leaking args passed to `write_archive()`
  builtin/merge-tree: fix leaking `-X` strategy options
  pretty: fix leaking key/value separator buffer
  pretty: fix memory leaks when parsing pretty formats
  convert: fix leaks when resetting attributes
  mailinfo: fix leaking header data

9 months agoMerge branch 'cl/config-regexp-docfix'
Junio C Hamano [Tue, 3 Sep 2024 16:14:59 +0000 (09:14 -0700)] 
Merge branch 'cl/config-regexp-docfix'

Docfix.

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

9 months agomergetools: vscode: new tool
Alex Henrie [Mon, 2 Sep 2024 02:59:14 +0000 (20:59 -0600)] 
mergetools: vscode: new tool

VSCode has supported three-way merges since 2022, see
<https://github.com/microsoft/vscode/issues/5770#issuecomment-1188658476>.

Although the program binary is located at /usr/bin/code, name the
mergetool "vscode" because the word "code" is too generic and would lead
to confusion. The name "vscode" also matches Git's existing
contrib/vscode directory.

On Windows, VSCode adds the directory that contains code.cmd to %PATH%,
so there is no need to invoke mergetool_find_win32_cmd to search for the
program.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>