]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
2 months agoMerge branch 'ps/reftable-block-search-fix'
Junio C Hamano [Thu, 21 Mar 2024 21:55:12 +0000 (14:55 -0700)] 
Merge branch 'ps/reftable-block-search-fix'

The reftable code has its own custom binary search function whose
comparison callback has an unusual interface, which caused the
binary search to degenerate into a linear search, which has been
corrected.

* ps/reftable-block-search-fix:
  reftable/block: fix binary search over restart counter
  reftable/record: fix memory leak when decoding object records

2 months agoMerge branch 'ps/reftable-stack-tempfile'
Junio C Hamano [Thu, 21 Mar 2024 21:55:12 +0000 (14:55 -0700)] 
Merge branch 'ps/reftable-stack-tempfile'

The code in reftable backend that creates new table files works
better with the tempfile framework to avoid leaving cruft after a
failure.

* ps/reftable-stack-tempfile:
  reftable/stack: register compacted tables as tempfiles
  reftable/stack: register lockfiles during compaction
  reftable/stack: register new tables as tempfiles
  lockfile: report when rollback fails

2 months agoMerge branch 'rs/opt-parse-long-fixups'
Junio C Hamano [Thu, 21 Mar 2024 21:55:12 +0000 (14:55 -0700)] 
Merge branch 'rs/opt-parse-long-fixups'

The parse-options code that deals with abbreviated long option
names have been cleaned up.

Reviewed-by: Josh Steadmon <steadmon@google.com>
cf. <ZfDM5Or3EKw7Q9SA@google.com>

* rs/opt-parse-long-fixups:
  parse-options: rearrange long_name matching code
  parse-options: normalize arg and long_name before comparison
  parse-options: detect ambiguous self-negation
  parse-options: factor out register_abbrev() and struct parsed_option
  parse-options: set arg of abbreviated option lazily
  parse-options: recognize abbreviated negated option with arg

2 months agoThe ninth batch
Junio C Hamano [Mon, 18 Mar 2024 20:02:12 +0000 (13:02 -0700)] 
The ninth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'jk/doc-remote-helpers-markup-fix'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)] 
Merge branch 'jk/doc-remote-helpers-markup-fix'

Doc mark-up fix.

* jk/doc-remote-helpers-markup-fix:
  doc/gitremote-helpers: fix missing single-quote

2 months agoMerge branch 'jh/trace2-missing-def-param-fix'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)] 
Merge branch 'jh/trace2-missing-def-param-fix'

Some trace2 events that lacked def_param have learned to show it,
enriching the output.

Reviewed-by: Josh Steadmon <steadmon@google.com>
cf. <ZejkVOVQBZhLVfHW@google.com>

* jh/trace2-missing-def-param-fix:
  trace2: emit 'def_param' set with 'cmd_name' event
  trace2: avoid emitting 'def_param' set more than once
  t0211: demonstrate missing 'def_param' events for certain commands

2 months agoMerge branch 'pw/rebase-i-ignore-cherry-pick-help-environment'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)] 
Merge branch 'pw/rebase-i-ignore-cherry-pick-help-environment'

Code simplification by getting rid of code that sets an environment
variable that is no longer used.

* pw/rebase-i-ignore-cherry-pick-help-environment:
  rebase -i: stop setting GIT_CHERRY_PICK_HELP

2 months agoThe eighth batch
Junio C Hamano [Fri, 15 Mar 2024 22:20:53 +0000 (15:20 -0700)] 
The eighth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'hd/config-mak-os390'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)] 
Merge branch 'hd/config-mak-os390'

Platform specific tweaks for OS/390 has been added to
config.mak.uname.

* hd/config-mak-os390:
  build: support z/OS (OS/390).

2 months agoMerge branch 'vm/t7301-use-test-path-helpers'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)] 
Merge branch 'vm/t7301-use-test-path-helpers'

GSoC practice to replace "test -f" with "test_path_is_file".

* vm/t7301-use-test-path-helpers:
  t7301: use test_path_is_(missing|file)

2 months agoMerge branch 'jc/xwrite-cleanup'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)] 
Merge branch 'jc/xwrite-cleanup'

Uses of xwrite() helper have been audited and updated for better
error checking and simpler code.

* jc/xwrite-cleanup:
  repack: check error writing to pack-objects subprocess
  sideband: avoid short write(2)
  unpack: replace xwrite() loop with write_in_full()

2 months agoMerge branch 'ag/t0010-modernize'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)] 
Merge branch 'ag/t0010-modernize'

GSoC practice to modernize a test script.

* ag/t0010-modernize:
  tests: modernize the test script t0010-racy-git.sh

2 months agoMerge branch 'as/option-names-in-messages'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)] 
Merge branch 'as/option-names-in-messages'

Error message updates.

* as/option-names-in-messages:
  revision.c: trivial fix to message
  builtin/clone.c: trivial fix of message
  builtin/remote.c: trivial fix of error message
  transport-helper.c: trivial fix of error message

2 months agoMerge branch 'kh/branch-ref-syntax-advice'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)] 
Merge branch 'kh/branch-ref-syntax-advice'

When git refuses to create a branch because the proposed branch
name is not a valid refname, an advice message is given to refer
the user to exact naming rules.

* kh/branch-ref-syntax-advice:
  branch: advise about ref syntax rules
  advice: use double quotes for regular quoting
  advice: use backticks for verbatim
  advice: make all entries stylistically consistent
  t3200: improve test style

2 months agoThe seventh batch
Junio C Hamano [Thu, 14 Mar 2024 21:03:22 +0000 (14:03 -0700)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'rj/complete-worktree-paths-fix'
Junio C Hamano [Thu, 14 Mar 2024 21:05:25 +0000 (14:05 -0700)] 
Merge branch 'rj/complete-worktree-paths-fix'

The logic to complete the command line arguments to "git worktree"
subcommand (in contrib/) has been updated to correctly honor things
like "git -C dir" etc.

* rj/complete-worktree-paths-fix:
  completion: fix __git_complete_worktree_paths

2 months agoMerge branch 'rj/complete-reflog'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)] 
Merge branch 'rj/complete-reflog'

The command line completion script (in contrib/) learned to
complete "git reflog" better.

* rj/complete-reflog:
  completion: reflog subcommands and options
  completion: factor out __git_resolve_builtins
  completion: introduce __git_find_subcommand
  completion: reflog show <log-options>
  completion: reflog with implicit "show"

2 months agoMerge branch 'jc/test-i18ngrep'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)] 
Merge branch 'jc/test-i18ngrep'

With release 2.44 we got rid of all uses of test_i18ngrep and there
is no in-flight topic that adds a new use of it.  Make a call to
test_i18ngrep a hard failure, so that we can remove it at the end
of this release cycle.

* jc/test-i18ngrep:
  test_i18ngrep: hard deprecate and forbid its use

2 months agoMerge branch 'gt/core-bare-in-templates'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)] 
Merge branch 'gt/core-bare-in-templates'

Code simplification.

* gt/core-bare-in-templates:
  setup: remove unnecessary variable

2 months agoMerge branch 'la/trailer-api'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)] 
Merge branch 'la/trailer-api'

Trailer API updates.

Acked-by: Christian Couder <christian.couder@gmail.com>
cf. <CAP8UFD1Zd+9q0z1JmfOf60S2vn5-sD3SafDvAJUzRFwHJKcb8A@mail.gmail.com>

* la/trailer-api:
  format_trailers_from_commit(): indirectly call trailer_info_get()
  format_trailer_info(): move "fast path" to caller
  format_trailers(): use strbuf instead of FILE
  trailer_info_get(): reorder parameters
  trailer: move interpret_trailers() to interpret-trailers.c
  trailer: reorder format_trailers_from_commit() parameters
  trailer: rename functions to use 'trailer'
  shortlog: add test for de-duplicating folded trailers
  trailer: free trailer_info _after_ all related usage

2 months agoMerge branch 'kh/doc-commentchar-is-a-byte'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)] 
Merge branch 'kh/doc-commentchar-is-a-byte'

The "core.commentChar" configuration variable only allows an ASCII
character, which was not clearly documented, which has been
corrected.

* kh/doc-commentchar-is-a-byte:
  config: document `core.commentChar` as ASCII-only

2 months agoMerge branch 'jh/fsmonitor-icase-corner-case-fix'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)] 
Merge branch 'jh/fsmonitor-icase-corner-case-fix'

FSMonitor client code was confused when FSEvents were given in a
different case on a case-insensitive filesystem, which has been
corrected.

Acked-by: Patrick Steinhardt <ps@pks.im>
cf. <ZehofMaSZyUq8S1N@tanuki>

* jh/fsmonitor-icase-corner-case-fix:
  fsmonitor: support case-insensitive events
  fsmonitor: refactor bit invalidation in refresh callback
  fsmonitor: trace the new invalidated cache-entry count
  fsmonitor: return invalidated cache-entry count on non-directory event
  fsmonitor: remove custom loop from non-directory path handler
  fsmonitor: return invalidated cache-entry count on directory event
  fsmonitor: move untracked-cache invalidation into helper functions
  fsmonitor: refactor untracked-cache invalidation
  dir: create untracked_cache_invalidate_trimmed_path()
  fsmonitor: refactor refresh callback for non-directory events
  fsmonitor: clarify handling of directory events in callback helper
  fsmonitor: refactor refresh callback on directory events
  t7527: add case-insensitve test for FSMonitor
  name-hash: add index_dir_find()

2 months agoMerge branch 'ps/reftable-iteration-perf-part2'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)] 
Merge branch 'ps/reftable-iteration-perf-part2'

The code to iterate over refs with the reftable backend has seen
some optimization.

* ps/reftable-iteration-perf-part2:
  refs/reftable: precompute prefix length
  reftable: allow inlining of a few functions
  reftable/record: decode keys in place
  reftable/record: reuse refname when copying
  reftable/record: reuse refname when decoding
  reftable/merged: avoid duplicate pqueue emptiness check
  reftable/merged: circumvent pqueue with single subiter
  reftable/merged: handle subiter cleanup on close only
  reftable/merged: remove unnecessary null check for subiters
  reftable/merged: make subiters own their records
  reftable/merged: advance subiter on subsequent iteration
  reftable/merged: make `merged_iter` structure private
  reftable/pq: use `size_t` to track iterator index

2 months agoMerge branch 'so/clean-dry-run-without-force'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)] 
Merge branch 'so/clean-dry-run-without-force'

The implementation in "git clean" that makes "-n" and "-i" ignore
clean.requireForce has been simplified, together with the
documentation.

* so/clean-dry-run-without-force:
  clean: further clean-up of implementation around "--force"
  clean: improve -n and -f implementation and documentation

2 months agoThe sixth batch
Junio C Hamano [Mon, 11 Mar 2024 21:11:28 +0000 (14:11 -0700)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'sj/t9117-path-is-file'
Junio C Hamano [Mon, 11 Mar 2024 21:12:31 +0000 (14:12 -0700)] 
Merge branch 'sj/t9117-path-is-file'

GSoC practice to replace "test -f" with "test_path_is_file".

* sj/t9117-path-is-file:
  t9117: prefer test_path_* helper functions

2 months agoMerge branch 'kh/doc-dashed-commands-have-not-worked-for-a-long-time'
Junio C Hamano [Mon, 11 Mar 2024 21:12:31 +0000 (14:12 -0700)] 
Merge branch 'kh/doc-dashed-commands-have-not-worked-for-a-long-time'

Doc update.

* kh/doc-dashed-commands-have-not-worked-for-a-long-time:
  gitcli: drop mention of “non-dashed form”

2 months agoMerge branch 'rs/t-ctype-simplify'
Junio C Hamano [Mon, 11 Mar 2024 21:12:30 +0000 (14:12 -0700)] 
Merge branch 'rs/t-ctype-simplify'

Code simplification to one unit-test program.

* rs/t-ctype-simplify:
  t-ctype: avoid duplicating class names
  t-ctype: align output of i
  t-ctype: simplify EOF check
  t-ctype: allow NUL anywhere in the specification string

2 months agoMerge branch 'es/config-doc-sort-sections'
Junio C Hamano [Mon, 11 Mar 2024 21:12:30 +0000 (14:12 -0700)] 
Merge branch 'es/config-doc-sort-sections'

Doc updates.

* es/config-doc-sort-sections:
  docs: sort configuration variable groupings alphabetically

2 months agoMerge branch 'js/merge-base-with-missing-commit'
Junio C Hamano [Mon, 11 Mar 2024 21:12:30 +0000 (14:12 -0700)] 
Merge branch 'js/merge-base-with-missing-commit'

Make sure failure return from merge_bases_many() is properly caught.

* js/merge-base-with-missing-commit:
  merge-ort/merge-recursive: do report errors in `merge_submodule()`
  merge-recursive: prepare for `merge_submodule()` to report errors
  commit-reach(repo_get_merge_bases_many_dirty): pass on errors
  commit-reach(repo_get_merge_bases_many): pass on "missing commits" errors
  commit-reach(get_octopus_merge_bases): pass on "missing commits" errors
  commit-reach(repo_get_merge_bases): pass on "missing commits" errors
  commit-reach(get_merge_bases_many_0): pass on "missing commits" errors
  commit-reach(merge_bases_many): pass on "missing commits" errors
  commit-reach(paint_down_to_common): start reporting errors
  commit-reach(paint_down_to_common): prepare for handling shallow commits
  commit-reach(repo_in_merge_bases_many): report missing commits
  commit-reach(repo_in_merge_bases_many): optionally expect missing commits
  commit-reach(paint_down_to_common): plug two memory leaks

2 months agomerge-ort/merge-recursive: do report errors in `merge_submodule()`
Johannes Schindelin [Sat, 9 Mar 2024 14:09:57 +0000 (14:09 +0000)] 
merge-ort/merge-recursive: do report errors in `merge_submodule()`

In 24876ebf68b (commit-reach(repo_in_merge_bases_many): report missing
commits, 2024-02-28), I taught `merge_submodule()` to handle errors
reported by `repo_in_merge_bases_many()`.

However, those errors were not passed through to the callers. That was
unintentional, and this commit remedies that.

Note that `find_first_merges()` can now also return -1 (because it
passes through that return value from `repo_in_merge_bases()`), and this
commit also adds the forgotten handling for that scenario.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agomerge-recursive: prepare for `merge_submodule()` to report errors
Johannes Schindelin [Sat, 9 Mar 2024 14:09:56 +0000 (14:09 +0000)] 
merge-recursive: prepare for `merge_submodule()` to report errors

The `merge_submodule()` function returns an integer that indicates
whether the merge was clean (returning 1) or unclean (returning 0).

Like the version in `merge-ort.c`, the version in `merge-recursive.c`
does not report any errors (such as repository corruption) by returning
-1 as of time of writing, even if the callers in `merge-ort.c` are
prepared for exactly such errors.

However, we want to teach (both variants of) the `merge_submodule()`
function that trick: to report errors by returning -1. Therefore,
prepare the caller in `merge-recursive.c` to handle that scenario.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoThe fifth batch
Junio C Hamano [Thu, 7 Mar 2024 23:20:17 +0000 (15:20 -0800)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'jk/upload-pack-v2-capability-cleanup'
Junio C Hamano [Thu, 7 Mar 2024 23:59:42 +0000 (15:59 -0800)] 
Merge branch 'jk/upload-pack-v2-capability-cleanup'

The upload-pack program, when talking over v2, accepted the
packfile-uris protocol extension from the client, even if it did
not advertise the capability, which has been corrected.

* jk/upload-pack-v2-capability-cleanup:
  upload-pack: only accept packfile-uris if we advertised it
  upload-pack: use existing config mechanism for advertisement
  upload-pack: centralize setup of sideband-all config
  upload-pack: use repository struct to get config

2 months agoMerge branch 'jk/upload-pack-bounded-resources'
Junio C Hamano [Thu, 7 Mar 2024 23:59:42 +0000 (15:59 -0800)] 
Merge branch 'jk/upload-pack-bounded-resources'

Various parts of upload-pack has been updated to bound the resource
consumption relative to the size of the repository to protect from
abusive clients.

* jk/upload-pack-bounded-resources:
  upload-pack: free tree buffers after parsing
  upload-pack: use PARSE_OBJECT_SKIP_HASH_CHECK in more places
  upload-pack: always turn off save_commit_buffer
  upload-pack: disallow object-info capability by default
  upload-pack: accept only a single packfile-uri line
  upload-pack: use a strmap for want-ref lines
  upload-pack: use oidset for deepen_not list
  upload-pack: switch deepen-not list to an oid_array
  upload-pack: drop separate v2 "haves" array

2 months agoMerge branch 'ps/reftable-repo-init-fix'
Junio C Hamano [Thu, 7 Mar 2024 23:59:42 +0000 (15:59 -0800)] 
Merge branch 'ps/reftable-repo-init-fix'

Clear the fallout from a fix for 2.44 regression.

* ps/reftable-repo-init-fix:
  t0610: remove unused variable assignment
  refs/reftable: don't fail empty transactions in repo without HEAD

2 months agoMerge branch 'ps/remote-helper-repo-initialization-fix'
Junio C Hamano [Thu, 7 Mar 2024 23:59:42 +0000 (15:59 -0800)] 
Merge branch 'ps/remote-helper-repo-initialization-fix'

A custom remote helper no longer cannot access the newly created
repository during "git clone", which is a regression in Git 2.44.
This has been corrected.

* ps/remote-helper-repo-initialization-fix:
  builtin/clone: allow remote helpers to detect repo

2 months agoMerge branch 'ml/log-merge-with-cherry-pick-and-other-pseudo-heads'
Junio C Hamano [Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)] 
Merge branch 'ml/log-merge-with-cherry-pick-and-other-pseudo-heads'

"git log --merge" learned to pay attention to CHERRY_PICK_HEAD and
other kinds of *_HEAD pseudorefs.

* ml/log-merge-with-cherry-pick-and-other-pseudo-heads:
  revision: implement `git log --merge` also for rebase/cherry-pick/revert
  revision: ensure MERGE_HEAD is a ref in prepare_show_merge

2 months agoMerge branch 'eg/add-uflags'
Junio C Hamano [Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)] 
Merge branch 'eg/add-uflags'

Code clean-up practice.

* eg/add-uflags:
  add: use unsigned type for collection of bits

2 months agoMerge branch 'jt/commit-redundant-scissors-fix'
Junio C Hamano [Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)] 
Merge branch 'jt/commit-redundant-scissors-fix'

"git commit -v --cleanup=scissors" used to add the scissors line
twice in the log message buffer, which has been corrected.

* jt/commit-redundant-scissors-fix:
  commit: unify logic to avoid multiple scissors lines when merging
  commit: avoid redundant scissor line with --cleanup=scissors -v

2 months agoMerge branch 'js/merge-tree-3-trees'
Junio C Hamano [Thu, 7 Mar 2024 23:59:41 +0000 (15:59 -0800)] 
Merge branch 'js/merge-tree-3-trees'

"git merge-tree" has learned that the three trees involved in the
3-way merge only need to be trees, not necessarily commits.

* js/merge-tree-3-trees:
  fill_tree_descriptor(): mark error message for translation
  cache-tree: avoid an unnecessary check
  Always check `parse_tree*()`'s return value
  t4301: verify that merge-tree fails on missing blob objects
  merge-ort: do check `parse_tree()`'s return value
  merge-tree: fail with a non-zero exit code on missing tree objects
  merge-tree: accept 3 trees as arguments

2 months agoMerge branch 'cc/rev-list-allow-missing-tips'
Junio C Hamano [Thu, 7 Mar 2024 23:59:40 +0000 (15:59 -0800)] 
Merge branch 'cc/rev-list-allow-missing-tips'

"git rev-list --missing=print" has learned to optionally take
"--allow-missing-tips", which allows the objects at the starting
points to be missing.

* cc/rev-list-allow-missing-tips:
  revision: fix --missing=[print|allow*] for annotated tags
  rev-list: allow missing tips with --missing=[print|allow*]
  t6022: fix 'test' style and 'even though' typo
  oidset: refactor oidset_insert_from_set()
  revision: clarify a 'return NULL' in get_reference()

2 months agoMerge branch 'jc/no-lazy-fetch'
Junio C Hamano [Thu, 7 Mar 2024 23:59:40 +0000 (15:59 -0800)] 
Merge branch 'jc/no-lazy-fetch'

"git --no-lazy-fetch cmd" allows to run "cmd" while disabling lazy
fetching of objects from the promisor remote, which may be handy
for debugging.

* jc/no-lazy-fetch:
  git: extend --no-lazy-fetch to work across subprocesses
  git: document GIT_NO_REPLACE_OBJECTS environment variable
  git: --no-lazy-fetch option

2 months agoreftable/block: fix binary search over restart counter
Patrick Steinhardt [Thu, 7 Mar 2024 20:36:02 +0000 (21:36 +0100)] 
reftable/block: fix binary search over restart counter

Records store their keys prefix-compressed. As many records will share a
common prefix (e.g. "refs/heads/"), this can end up saving quite a bit
of disk space. The downside of this is that it is not possible to just
seek into the middle of a block and consume the corresponding record
because it may depend on prefixes read from preceding records.

To help with this usecase, the reftable format writes every n'th record
without using prefix compression, which is called a "restart". The list
of restarts is stored at the end of each block so that a reader can
figure out entry points at which to read a full record without having to
read all preceding records.

This allows us to do a binary search over the records in a block when
searching for a particular key by iterating through the restarts until
we have found the section in which our record must be located. From
thereon we perform a linear search to locate the desired record.

This mechanism is broken though. In `block_reader_seek()` we call
`binsearch()` over the count of restarts in the current block. The
function we pass to compare records with each other computes the key at
the current index and then compares it to our search key by calling
`strbuf_cmp()`, returning its result directly. But `binsearch()` expects
us to return a truish value that indicates whether the current index is
smaller than the searched-for key. And unless our key exactly matches
the value at the restart counter we always end up returning a truish
value.

The consequence is that `binsearch()` essentially always returns 0,
indicacting to us that we must start searching right at the beginning of
the block. This works by chance because we now always do a linear scan
from the start of the block, and thus we would still end up finding the
desired record. But needless to say, this makes the optimization quite
useless.

Fix this bug by returning whether the current key is smaller than the
searched key. As the current behaviour was correct it is not possible to
write a test. Furthermore it is also not really possible to demonstrate
in a benchmark that this fix speeds up seeking records.

This may cause the reader to question whether this binary search makes
sense in the first place if it doesn't even help with performance. But
it would end up helping if we were to read a reftable with a much larger
block size. Blocks can be up to 16MB in size, in which case it will
become much more important to avoid the linear scan. We are not yet
ready to read or write such larger blocks though, so we have to live
without a benchmark demonstrating this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoreftable/record: fix memory leak when decoding object records
Patrick Steinhardt [Thu, 7 Mar 2024 20:35:58 +0000 (21:35 +0100)] 
reftable/record: fix memory leak when decoding object records

When decoding records it is customary to reuse a `struct
reftable_ref_record` across calls. Thus, it may happen that the record
already holds some allocated memory. When decoding ref and log records
we handle this by releasing or reallocating held memory. But we fail to
do this for object records, which causes us to leak memory.

Fix this memory leak by releasing object records before we decode into
them. We may eventually want to reuse memory instead to avoid needless
reallocations. But for now, let's just plug the leak and be done.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoreftable/stack: register compacted tables as tempfiles
Patrick Steinhardt [Thu, 7 Mar 2024 13:10:43 +0000 (14:10 +0100)] 
reftable/stack: register compacted tables as tempfiles

We do not register tables resulting from stack compaction with the
tempfile API. Those tables will thus not be deleted in case Git gets
killed.

Refactor the code to register compacted tables as tempfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoreftable/stack: register lockfiles during compaction
Patrick Steinhardt [Thu, 7 Mar 2024 13:10:39 +0000 (14:10 +0100)] 
reftable/stack: register lockfiles during compaction

We do not register any of the locks we acquire when compacting the
reftable stack via our lockfiles interfaces. These locks will thus not
be released when Git gets killed.

Refactor the code to register locks as lockfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoreftable/stack: register new tables as tempfiles
Patrick Steinhardt [Thu, 7 Mar 2024 13:10:35 +0000 (14:10 +0100)] 
reftable/stack: register new tables as tempfiles

We do not register new tables which we're about to add to the stack with
the tempfile API. Those tables will thus not be deleted in case Git gets
killed.

Refactor the code to register tables as tempfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agolockfile: report when rollback fails
Patrick Steinhardt [Thu, 7 Mar 2024 13:10:31 +0000 (14:10 +0100)] 
lockfile: report when rollback fails

We do not report to the caller when rolling back a lockfile fails, which
will be needed by the reftable compaction logic in a subsequent commit.
It also cannot really report on all errors because the function calls
`delete_tempfile()`, which doesn't return an error either.

Refactor the code so that both `delete_tempfile()` and
`rollback_lock_file()` return an error code.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agodoc/gitremote-helpers: fix missing single-quote
Jeff King [Thu, 7 Mar 2024 08:43:13 +0000 (03:43 -0500)] 
doc/gitremote-helpers: fix missing single-quote

The formatting around "option push-option" was missing its closing
quote, leading to the output having a stray opening quote, rather than
rendering the item in italics (as we do for all of the other options in
the list).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agotrace2: emit 'def_param' set with 'cmd_name' event
Jeff Hostetler [Thu, 7 Mar 2024 15:22:29 +0000 (15:22 +0000)] 
trace2: emit 'def_param' set with 'cmd_name' event

Some commands do not cause a set of 'def_param' events to be emitted.
This includes "git-remote-https", "git-http-fetch", and various
"query" commands, like "git --man-path".

Since all of these commands do emit a 'cmd_name' event, add code to
the "trace2_cmd_name()" function to generate the set of 'def_param'
events.

Remove explicit calls to "trace2_cmd_list_config()" and
"trace2_cmd_list_env_vars()" in git.c since they are no longer needed.

Reviewed-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agotrace2: avoid emitting 'def_param' set more than once
Jeff Hostetler [Thu, 7 Mar 2024 15:22:28 +0000 (15:22 +0000)] 
trace2: avoid emitting 'def_param' set more than once

During nested alias expansion it is possible for
"trace2_cmd_list_config()" and "trace2_cmd_list_env_vars()"
to be called more than once.  This causes a full set of
'def_param' events to be emitted each time.  Let's avoid
that.

Add code to those two functions to only emit them once.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agot0211: demonstrate missing 'def_param' events for certain commands
Jeff Hostetler [Thu, 7 Mar 2024 15:22:27 +0000 (15:22 +0000)] 
t0211: demonstrate missing 'def_param' events for certain commands

Some Git commands fail to emit 'def_param' events for interesting
config and environment variable settings.

Add unit tests to demonstrate this.

Most commands are considered "builtin" and are based upon git.c.
These typically do emit 'def_param' events.  Exceptions are some of
the "query" commands, the "run-dashed" mechanism, and alias handling.

Commands built from remote-curl.c (instead of git.c), such as
"git-remote-https", do not emit 'def_param' events.

Likewise, "git-http-fetch" is built http-fetch.c and does not emit
them.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agot7301: use test_path_is_(missing|file)
Vincenzo Mezzela [Mon, 4 Mar 2024 17:17:32 +0000 (18:17 +0100)] 
t7301: use test_path_is_(missing|file)

Replace "test -f" and friends to use the test_path_is_file helper
function and friends from test-lib-functions.sh. These functions
perform identical operations while enhancing debugging capabilities
in case of test failures.

The original used 'test ! -f' to check if the file has been
correctly cleaned, so 'test ! -e' would have been a better choice.
Replace them with 'test_path_is_missing'.

Signed-off-by: Vincenzo Mezzela <vincenzo.mezzela@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agofsmonitor: support case-insensitive events
Jeff Hostetler [Mon, 26 Feb 2024 21:39:25 +0000 (21:39 +0000)] 
fsmonitor: support case-insensitive events

Teach fsmonitor_refresh_callback() to handle case-insensitive
lookups if case-sensitive lookups fail on case-insensitive systems.
This can cause 'git status' to report stale status for files if there
are case issues/errors in the worktree.

The FSMonitor daemon sends FSEvents using the observed spelling
of each pathname.  On case-insensitive file systems this may be
different than the expected case spelling.

The existing code uses index_name_pos() to find the cache-entry for
the pathname in the FSEvent and clear the CE_FSMONITOR_VALID bit so
that the worktree scan/index refresh will revisit and revalidate the
path.

On a case-insensitive file system, the exact match lookup may fail
to find the associated cache-entry. This causes status to think that
the cached CE flags are correct and skip over the file.

Update event handling to optionally use the name-hash and dir-name-hash
if necessary.

Also update t7527 to convert the "test_expect_failure" to "_success"
now that we have fixed the bug.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agofsmonitor: refactor bit invalidation in refresh callback
Jeff Hostetler [Mon, 26 Feb 2024 21:39:24 +0000 (21:39 +0000)] 
fsmonitor: refactor bit invalidation in refresh callback

Refactor code in the fsmonitor_refresh_callback() call chain dealing
with invalidating the CE_FSMONITOR_VALID bit and add a trace message.

During the refresh, we clear the CE_FSMONITOR_VALID bit in response to
data from the FSMonitor daemon (so that a later phase will lstat() and
verify the true state of the file).

Create a new function to clear the bit and add some unique tracing for
it to help debug edge cases.

This is similar to the existing `mark_fsmonitor_invalid()` function,
but it also does untracked-cache invalidation and we've already
handled that in the refresh-callback handlers, so but we don't need
to repeat that.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agofsmonitor: trace the new invalidated cache-entry count
Jeff Hostetler [Mon, 26 Feb 2024 21:39:23 +0000 (21:39 +0000)] 
fsmonitor: trace the new invalidated cache-entry count

Consolidate the directory/non-directory calls to the refresh handler
code.  Log the resulting count of invalidated cache-entries.

The nr_in_cone value will be used in a later commit to decide if
we also need to try to do case-insensitive lookups.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agofsmonitor: return invalidated cache-entry count on non-directory event
Jeff Hostetler [Mon, 26 Feb 2024 21:39:22 +0000 (21:39 +0000)] 
fsmonitor: return invalidated cache-entry count on non-directory event

Teach the refresh callback helper function for unqualified FSEvents
(pathnames without a trailing slash) to return the number of
cache-entries that were invalided in response to the event.

This will be used in a later commit to help determine if the observed
pathname was (possibly) case-incorrect when (on a case-insensitive
file system).

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agot0610: remove unused variable assignment
Patrick Steinhardt [Wed, 6 Mar 2024 11:17:27 +0000 (12:17 +0100)] 
t0610: remove unused variable assignment

In b0f6b6b523 (refs/reftable: don't fail empty transactions in repo
without HEAD, 2024-02-27), we have added a new test to t0610. This test
contains a useless assignment to a variable that is never actually used.
Remove it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agobuild: support z/OS (OS/390).
Haritha D [Wed, 6 Mar 2024 05:44:17 +0000 (05:44 +0000)] 
build: support z/OS (OS/390).

Introduced z/OS (OS/390) as a platform in config.mak.uname

Signed-off-by: Haritha D <harithamma.d@ibm.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agotests: modernize the test script t0010-racy-git.sh
Aryan Gupta [Tue, 5 Mar 2024 22:09:17 +0000 (22:09 +0000)] 
tests: modernize the test script t0010-racy-git.sh

Modernize the formatting of the test script to align with current
standards and improve its overall readability.

Signed-off-by: Aryan Gupta <garyan447@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agorevision.c: trivial fix to message
Alexander Shopov [Fri, 16 Feb 2024 10:15:37 +0000 (11:15 +0100)] 
revision.c: trivial fix to message

ancestry-path is an option, not a command - mark it as such.
This brings it in sync with the rest of usages in the file

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agobuiltin/clone.c: trivial fix of message
Alexander Shopov [Fri, 16 Feb 2024 10:15:36 +0000 (11:15 +0100)] 
builtin/clone.c: trivial fix of message

bare in that context is an option, not purely an adjective
Mark it properly

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agobuiltin/remote.c: trivial fix of error message
Alexander Shopov [Fri, 16 Feb 2024 10:15:35 +0000 (11:15 +0100)] 
builtin/remote.c: trivial fix of error message

Mark --mirror as option rather than command

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agotransport-helper.c: trivial fix of error message
Alexander Shopov [Fri, 16 Feb 2024 10:15:34 +0000 (11:15 +0100)] 
transport-helper.c: trivial fix of error message

Mark --force as option rather than variable names

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agobranch: advise about ref syntax rules
Kristoffer Haugsbakk [Tue, 5 Mar 2024 20:29:43 +0000 (21:29 +0100)] 
branch: advise about ref syntax rules

git-branch(1) will error out if you give it a bad ref name. But the user
might not understand why or what part of the name is illegal.

The user might know that there are some limitations based on the *loose
ref* format (filenames), but there are also further rules for
easier integration with shell-based tools, pathname expansion, and
playing well with reference name expressions.

The man page for git-check-ref-format(1) contains these rules. Let’s
advise about it since that is not a command that you just happen
upon. Also make this advise configurable since you might not want to be
reminded every time you make a little typo.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoadvice: use double quotes for regular quoting
Kristoffer Haugsbakk [Tue, 5 Mar 2024 20:29:42 +0000 (21:29 +0100)] 
advice: use double quotes for regular quoting

Use double quotes like we use for “die” in this document.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoadvice: use backticks for verbatim
Kristoffer Haugsbakk [Tue, 5 Mar 2024 20:29:41 +0000 (21:29 +0100)] 
advice: use backticks for verbatim

Use backticks for inline-verbatim rather than single quotes. Also quote
the unquoted ref globs.

Also replace “the add command” with “`git add`”.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoadvice: make all entries stylistically consistent
Kristoffer Haugsbakk [Tue, 5 Mar 2024 20:29:40 +0000 (21:29 +0100)] 
advice: make all entries stylistically consistent

In general, rewrite entries to the following form:

1. Clause or sentence describing when the advice is shown
2. Optional “to <verb>” clause which says what the advice is
   about (e.g. for resetNoRefresh: tell the user that they can use
   `--no-refresh`)

Concretely:

1. Use “shown” instead of “advice shown”
   • “advice” is implied and a bit repetitive
2. Use “when” instead of “if”
3. Lead with “Shown when” and end the entry with the effect it has,
   where applicable
4. Use “the user” instead of “a user” or “you”
5. implicitIdentity: rewrite description in order to lead with *when*
   the advice is shown (see point (3))
6. Prefer the present tense (with the exception of pushNonFFMatching)
7. waitingForEditor: give example of relevance in this new context
8. pushUpdateRejected: exception to the above principles

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agot3200: improve test style
Kristoffer Haugsbakk [Tue, 5 Mar 2024 20:29:39 +0000 (21:29 +0100)] 
t3200: improve test style

Some tests use a preliminary heredoc for `expect` or have setup and
teardown commands before and after, respectively. It is however
preferred to keep all the logic in the test itself. Let’s move these
into the tests.

Also:

• Remove a now-irrelevant comment about test placement and switch back
  to `main` post-test
• Prefer indented literal heredocs (`-\EOF`) except for a block which
  says that this is intentional

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoconfig: document `core.commentChar` as ASCII-only
Kristoffer Haugsbakk [Tue, 5 Mar 2024 16:51:08 +0000 (17:51 +0100)] 
config: document `core.commentChar` as ASCII-only

d3b3419f8f2 (config: tell the user that we expect an ASCII character,
2023-03-27) updated an error message to make clear that this option
specifically wants an ASCII character but neglected to consider the
config documentation.

Reported-by: Manlio Perillo <manlio.perillo@gmail.com>
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoThe fourth batch
Junio C Hamano [Tue, 5 Mar 2024 17:31:41 +0000 (09:31 -0800)] 
The fourth batch

Also update the DEF_VER in GIT-VERSION-GEN, which I forgot to do
earlier (it should have been done when we started the new cycle).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoMerge branch 'ak/rebase-autosquash'
Junio C Hamano [Tue, 5 Mar 2024 17:44:44 +0000 (09:44 -0800)] 
Merge branch 'ak/rebase-autosquash'

Typofix.

* ak/rebase-autosquash:
  rebase: fix typo in autosquash documentation

3 months agoMerge branch 'kn/for-all-refs'
Junio C Hamano [Tue, 5 Mar 2024 17:44:44 +0000 (09:44 -0800)] 
Merge branch 'kn/for-all-refs'

"git for-each-ref" learned "--include-root-refs" option to show
even the stuff outside the 'refs/' hierarchy.

* kn/for-all-refs:
  for-each-ref: add new option to include root refs
  ref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR'
  refs: introduce `refs_for_each_include_root_refs()`
  refs: extract out `loose_fill_ref_dir_regular_file()`
  refs: introduce `is_pseudoref()` and `is_headref()`

3 months agoMerge branch 'pb/ort-make-submodule-conflict-message-an-advice'
Junio C Hamano [Tue, 5 Mar 2024 17:44:43 +0000 (09:44 -0800)] 
Merge branch 'pb/ort-make-submodule-conflict-message-an-advice'

When a merge conflicted at a submodule, merge-ort backend used to
unconditionally give a lengthy message to suggest how to resolve
it.  Now the message can be squelched as an advice message.

* pb/ort-make-submodule-conflict-message-an-advice:
  merge-ort: turn submodule conflict suggestions into an advice

3 months agoMerge branch 'jc/doc-compat-util'
Junio C Hamano [Tue, 5 Mar 2024 17:44:43 +0000 (09:44 -0800)] 
Merge branch 'jc/doc-compat-util'

Clarify wording in the CodingGuidelines that requires <git-compat-util.h>
to be the first header file.

* jc/doc-compat-util:
  doc: clarify the wording on <git-compat-util.h> requirement

3 months agoMerge branch 'sg/upload-pack-error-message-fix'
Junio C Hamano [Tue, 5 Mar 2024 17:44:43 +0000 (09:44 -0800)] 
Merge branch 'sg/upload-pack-error-message-fix'

An error message from "git upload-pack", which responds to "git
fetch" requests, had a trialing NUL in it, which has been
corrected.

* sg/upload-pack-error-message-fix:
  upload-pack: don't send null character in abort message to the client

3 months agoMerge branch 'rs/submodule-prefix-simplify'
Junio C Hamano [Tue, 5 Mar 2024 17:44:43 +0000 (09:44 -0800)] 
Merge branch 'rs/submodule-prefix-simplify'

Code simplification.

* rs/submodule-prefix-simplify:
  submodule: use strvec_pushf() for --submodule-prefix

3 months agoMerge branch 'rs/name-rev-with-mempool'
Junio C Hamano [Tue, 5 Mar 2024 17:44:43 +0000 (09:44 -0800)] 
Merge branch 'rs/name-rev-with-mempool'

Many small allocations "git name-rev" makes have been updated to
allocate from a mem-pool.

* rs/name-rev-with-mempool:
  name-rev: use mem_pool_strfmt()
  mem-pool: add mem_pool_strfmt()

3 months agoMerge branch 'rs/fetch-simplify-with-starts-with'
Junio C Hamano [Tue, 5 Mar 2024 17:44:42 +0000 (09:44 -0800)] 
Merge branch 'rs/fetch-simplify-with-starts-with'

Code simplification.

* rs/fetch-simplify-with-starts-with:
  fetch: convert strncmp() with strlen() to starts_with()

3 months agoMerge branch 'jk/reflog-special-cases-fix'
Junio C Hamano [Tue, 5 Mar 2024 17:44:42 +0000 (09:44 -0800)] 
Merge branch 'jk/reflog-special-cases-fix'

The logic to access reflog entries by date and number had ugly
corner cases at the boundaries, which have been cleaned up.

* jk/reflog-special-cases-fix:
  read_ref_at(): special-case ref@{0} for an empty reflog
  get_oid_basic(): special-case ref@{n} for oldest reflog entry
  Revert "refs: allow @{n} to work with n-sized reflog"

3 months agoMerge branch 'jc/no-include-of-compat-util-from-headers'
Junio C Hamano [Tue, 5 Mar 2024 17:44:42 +0000 (09:44 -0800)] 
Merge branch 'jc/no-include-of-compat-util-from-headers'

Header file clean-up.

* jc/no-include-of-compat-util-from-headers:
  compat: drop inclusion of <git-compat-util.h>

3 months agoMerge branch 'js/remove-cruft-files'
Junio C Hamano [Tue, 5 Mar 2024 17:44:42 +0000 (09:44 -0800)] 
Merge branch 'js/remove-cruft-files'

Remove an empty file that shouldn't have been added in the first
place.

* js/remove-cruft-files:
  neue: remove a bogus empty file

3 months agoMerge branch 'jk/textconv-cache-outside-repo-fix'
Junio C Hamano [Tue, 5 Mar 2024 17:44:42 +0000 (09:44 -0800)] 
Merge branch 'jk/textconv-cache-outside-repo-fix'

The code incorrectly attempted to use textconv cache when asked,
even when we are not running in a repository, which has been
corrected.

* jk/textconv-cache-outside-repo-fix:
  userdiff: skip textconv caching when not in a repository

3 months agoclean: further clean-up of implementation around "--force"
Junio C Hamano [Sun, 3 Mar 2024 22:06:00 +0000 (14:06 -0800)] 
clean: further clean-up of implementation around "--force"

We clarified how "clean.requireForce" interacts with the "--dry-run"
option in the previous commit, both in the implementation and in the
documentation.  Even when "git clean" (without other options) is
required to be used with "--force" (i.e. either clean.requireForce
is unset, or explicitly set to true) to protect end-users from
casual invocation of the command by mistake, "--dry-run" does not
require "--force" to be used, because it is already its own
protection mechanism by being a no-op to the working tree files.

The previous commit, however, missed another clean-up opportunity
around the same area.  Just like in the "--dry-run" mode, the
command in the "--interactive" mode does not require "--force",
either.  This is because by going interactive and giving the end
user one more chance to confirm, the mode itself is serving as its
own protection mechanism.

Let's take things one step further, and unify the code that defines
interaction between "--force" and these two other options.  Just
like we added explanation for the reason why "--dry-run" does not
honor "clean.requireForce", give an explanation for the reason why
"--interactive" makes "clean.requireForce" to be ignored.

Finally, add some tests to show the interaction between "--force"
and "--interactive".  We already have tests that show interaction
between "--force" and "--dry-run", but didn't test "--interactive".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agorefs/reftable: precompute prefix length
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:40 +0000 (11:49 +0100)] 
refs/reftable: precompute prefix length

We're recomputing the prefix length on every iteration of the ref
iterator. Precompute it for another speedup when iterating over 1
million refs:

    Benchmark 1: show-ref: single matching ref (revision = HEAD~)
      Time (mean ± σ):     100.3 ms ±   3.7 ms    [User: 97.3 ms, System: 2.8 ms]
      Range (min … max):    97.5 ms … 139.7 ms    1000 runs

    Benchmark 2: show-ref: single matching ref (revision = HEAD)
      Time (mean ± σ):      95.8 ms ±   3.4 ms    [User: 92.9 ms, System: 2.8 ms]
      Range (min … max):    93.0 ms … 121.9 ms    1000 runs

    Summary
      show-ref: single matching ref (revision = HEAD) ran
        1.05 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable: allow inlining of a few functions
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:35 +0000 (11:49 +0100)] 
reftable: allow inlining of a few functions

We have a few functions which are basically just accessors to
structures. As those functions are executed inside the hot loop when
iterating through many refs, the fact that they cannot be inlined is
costing us some performance.

Move the function definitions into their respective headers so that they
can be inlined. This results in a performance improvement when iterating
over 1 million refs:

    Benchmark 1: show-ref: single matching ref (revision = HEAD~)
      Time (mean ± σ):     105.9 ms ±   3.6 ms    [User: 103.0 ms, System: 2.8 ms]
      Range (min … max):   103.1 ms … 133.4 ms    1000 runs

    Benchmark 2: show-ref: single matching ref (revision = HEAD)
      Time (mean ± σ):     100.7 ms ±   3.4 ms    [User: 97.8 ms, System: 2.8 ms]
      Range (min … max):    97.8 ms … 124.0 ms    1000 runs

    Summary
      show-ref: single matching ref (revision = HEAD) ran
        1.05 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/record: decode keys in place
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:31 +0000 (11:49 +0100)] 
reftable/record: decode keys in place

When reading a record from a block, we need to decode the record's key.
As reftable keys are prefix-compressed, meaning they reuse a prefix from
the preceding record's key, this is a bit more involved than just having
to copy the relevant bytes: we need to figure out the prefix and suffix
lengths, copy the prefix from the preceding record and finally copy the
suffix from the current record.

This is done by passing three buffers to `reftable_decode_key()`: one
buffer that holds the result, one buffer that holds the last key, and
one buffer that points to the current record. The final key is then
assembled by calling `strbuf_add()` twice to copy over the prefix and
suffix.

Performing two memory copies is inefficient though. And we can indeed do
better by decoding keys in place. Instead of providing two buffers, the
caller may only call a single buffer that is already pre-populated with
the last key. Like this, we only have to call `strbuf_setlen()` to trim
the record to its prefix and then `strbuf_add()` to add the suffix.

This refactoring leads to a noticeable performance bump when iterating
over 1 million refs:

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)
    Time (mean ± σ):     112.2 ms ±   3.9 ms    [User: 109.3 ms, System: 2.8 ms]
    Range (min … max):   109.2 ms … 149.6 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     106.0 ms ±   3.5 ms    [User: 103.2 ms, System: 2.7 ms]
    Range (min … max):   103.2 ms … 133.7 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.06 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/record: reuse refname when copying
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:26 +0000 (11:49 +0100)] 
reftable/record: reuse refname when copying

Do the same optimization as in the preceding commit, but this time for
`reftable_record_copy()`. While not as noticeable, it still results in a
small speedup when iterating over 1 million refs:

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)
    Time (mean ± σ):     114.0 ms ±   3.8 ms    [User: 111.1 ms, System: 2.7 ms]
    Range (min … max):   110.9 ms … 144.3 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     112.5 ms ±   3.7 ms    [User: 109.5 ms, System: 2.8 ms]
    Range (min … max):   109.2 ms … 140.7 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.01 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/record: reuse refname when decoding
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:22 +0000 (11:49 +0100)] 
reftable/record: reuse refname when decoding

When decoding a reftable record we will first release the user-provided
record and then decode the new record into it. This is quite inefficient
as we basically need to reallocate at least the refname every time.

Refactor the function to start tracking the refname capacity. Like this,
we can stow away the refname, release, restore and then grow the refname
to the required number of bytes via `REFTABLE_ALLOC_GROW()`.

This refactoring is safe to do because all functions that assigning to
the refname will first call `reftable_ref_record_release()`, which will
zero out the complete record after releasing memory.

This change results in a nice speedup when iterating over 1 million
refs:

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)

    Time (mean ± σ):     124.0 ms ±   3.9 ms    [User: 121.1 ms, System: 2.7 ms]
    Range (min … max):   120.4 ms … 152.7 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     114.4 ms ±   3.7 ms    [User: 111.5 ms, System: 2.7 ms]
    Range (min … max):   111.0 ms … 152.1 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.08 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Furthermore, with this change we now perform a mostly constant number of
allocations when iterating. Before this change:

  HEAP SUMMARY:
      in use at exit: 13,603 bytes in 125 blocks
    total heap usage: 1,006,620 allocs, 1,006,495 frees, 25,398,363 bytes allocated

After this change:

  HEAP SUMMARY:
      in use at exit: 13,603 bytes in 125 blocks
    total heap usage: 6,623 allocs, 6,498 frees, 509,592 bytes allocated

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: avoid duplicate pqueue emptiness check
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:18 +0000 (11:49 +0100)] 
reftable/merged: avoid duplicate pqueue emptiness check

When calling `merged_iter_next_void()` we first check whether the iter
has been exhausted already. We already perform this check two levels
down the stack in `merged_iter_next_entry()` though, which makes this
check redundant.

Now if this check was there to accelerate the common case it might have
made sense to keep it. But the iterator being exhausted is rather the
uncommon case because you can expect most reftable stacks to contain
more than two refs.

Simplify the code by removing the check. As `merged_iter_next_void()` is
basically empty except for calling `merged_iter_next()` now, merge these
two functions. This also results in a tiny speedup when iterating over
many refs:

    Benchmark 1: show-ref: single matching ref (revision = HEAD~)
      Time (mean ± σ):     125.6 ms ±   3.8 ms    [User: 122.7 ms, System: 2.8 ms]
      Range (min … max):   122.4 ms … 153.4 ms    1000 runs

    Benchmark 2: show-ref: single matching ref (revision = HEAD)
      Time (mean ± σ):     124.0 ms ±   3.9 ms    [User: 121.1 ms, System: 2.8 ms]
      Range (min … max):   120.1 ms … 156.4 ms    1000 runs

    Summary
      show-ref: single matching ref (revision = HEAD) ran
        1.01 ± 0.04 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: circumvent pqueue with single subiter
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:13 +0000 (11:49 +0100)] 
reftable/merged: circumvent pqueue with single subiter

The merged iterator uses a priority queue to order records so that we
can yielid them in the expected order. This priority queue of course
comes with some overhead as we need to add, compare and remove entries
in that priority queue.

In the general case, that overhead cannot really be avoided. But when we
have a single subiter left then there is no need to use the priority
queue anymore because the order is exactly the same as what that subiter
would return.

While having a single subiter may sound like an edge case, it happens
more frequently than one might think. In the most common scenario, you
can expect a repository to have a single large table that contains most
of the records and then a set of smaller tables which contain later
additions to the reftable stack. In this case it is quite likely that we
exhaust subiters of those smaller stacks before exhausting the large
table.

Special-case this and return records directly from the remaining
subiter. This results in a sizeable speedup when iterating over 1m refs
in a repository with a single table:

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)
    Time (mean ± σ):     135.4 ms ±   4.4 ms    [User: 132.5 ms, System: 2.8 ms]
    Range (min … max):   131.0 ms … 166.3 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     126.3 ms ±   3.9 ms    [User: 123.3 ms, System: 2.8 ms]
    Range (min … max):   122.7 ms … 157.0 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.07 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: handle subiter cleanup on close only
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:08 +0000 (11:49 +0100)] 
reftable/merged: handle subiter cleanup on close only

When advancing one of the subiters fails we immediately release
resources associated with that subiter. This is not necessary though as
we will release these resources when closing the merged iterator anyway.

Drop the logic and only release resources when the merged iterator is
done. This is a mere cleanup that should help reduce the cognitive load
when reading through the code.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: remove unnecessary null check for subiters
Patrick Steinhardt [Mon, 4 Mar 2024 10:49:03 +0000 (11:49 +0100)] 
reftable/merged: remove unnecessary null check for subiters

Whenever we advance a subiter we first call `iterator_is_null()`. This
is not needed though because we only ever advance subiters which have
entries in the priority queue, and we do not end entries to the priority
queue when the subiter has been exhausted.

Drop the check as well as the now-unused function. This results in a
surprisingly big speedup:

    Benchmark 1: show-ref: single matching ref (revision = HEAD~)
      Time (mean ± σ):     138.1 ms ±   4.4 ms    [User: 135.1 ms, System: 2.8 ms]
      Range (min … max):   133.4 ms … 167.3 ms    1000 runs

    Benchmark 2: show-ref: single matching ref (revision = HEAD)
      Time (mean ± σ):     134.4 ms ±   4.2 ms    [User: 131.5 ms, System: 2.8 ms]
      Range (min … max):   130.0 ms … 164.0 ms    1000 runs

    Summary
      show-ref: single matching ref (revision = HEAD) ran
        1.03 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: make subiters own their records
Patrick Steinhardt [Mon, 4 Mar 2024 10:48:59 +0000 (11:48 +0100)] 
reftable/merged: make subiters own their records

For each subiterator, the merged table needs to track their current
record. This record is owned by the priority queue though instead of by
the merged iterator. This is not optimal performance-wise.

For one, we need to move around records whenever we add or remove a
record from the priority queue. Thus, the bigger the entries the more
bytes we need to copy around. And compared to pointers, a reftable
record is rather on the bigger side. The other issue is that this makes
it harder to reuse the records.

Refactor the code so that the merged iterator tracks ownership of the
records per-subiter. Instead of having records in the priority queue, we
can now use mere pointers to the per-subiter records. This also allows
us to swap records between the caller and the per-subiter record instead
of doing an actual copy via `reftable_record_copy_from()`, which removes
the need to release the caller-provided record.

This results in a noticeable speedup when iterating through many refs.
The following benchmark iterates through 1 million refs:

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)
    Time (mean ± σ):     145.5 ms ±   4.5 ms    [User: 142.5 ms, System: 2.8 ms]
    Range (min … max):   141.3 ms … 177.0 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     139.0 ms ±   4.7 ms    [User: 136.1 ms, System: 2.8 ms]
    Range (min … max):   134.2 ms … 182.2 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.05 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~)

This refactoring also allows a subsequent refactoring where we start
reusing memory allocated by the reftable records because we do not need
to release the caller-provided record anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: advance subiter on subsequent iteration
Patrick Steinhardt [Mon, 4 Mar 2024 10:48:55 +0000 (11:48 +0100)] 
reftable/merged: advance subiter on subsequent iteration

When advancing the merged iterator, we pop the topmost entry from its
priority queue and then advance the sub-iterator that the entry belongs
to, adding the result as a new entry. This is quite sensible in the case
where the merged iterator is used to actually iterate through records.
But the merged iterator is also used when we look up a single record,
only, so advancing the sub-iterator is wasted effort because we would
never even look at the result.

Instead of immediately advancing the sub-iterator, we can also defer
this to the next iteration of the merged iterator by storing the
intent-to-advance. This results in a small speedup when reading many
records. The following benchmark creates 10000 refs, which will also end
up with many ref lookups:

    Benchmark 1: update-ref: create many refs (revision = HEAD~)
      Time (mean ± σ):     337.2 ms ±   7.3 ms    [User: 200.1 ms, System: 136.9 ms]
      Range (min … max):   329.3 ms … 373.2 ms    100 runs

    Benchmark 2: update-ref: create many refs (revision = HEAD)
      Time (mean ± σ):     332.5 ms ±   5.9 ms    [User: 197.2 ms, System: 135.1 ms]
      Range (min … max):   327.6 ms … 359.8 ms    100 runs

    Summary
      update-ref: create many refs (revision = HEAD) ran
        1.01 ± 0.03 times faster than update-ref: create many refs (revision = HEAD~)

While this speedup alone isn't really worth it, this refactoring will
also allow two additional optimizations in subsequent patches. First, it
will allow us to special-case when there is only a single sub-iter left
to circumvent the priority queue altogether. And second, it makes it
easier to avoid copying records to the caller.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/merged: make `merged_iter` structure private
Patrick Steinhardt [Mon, 4 Mar 2024 10:48:51 +0000 (11:48 +0100)] 
reftable/merged: make `merged_iter` structure private

The `merged_iter` structure is not used anywhere outside of "merged.c",
but is declared in its header. Move it into the code file so that it is
clear that its implementation details are never exposed to anything.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agoreftable/pq: use `size_t` to track iterator index
Patrick Steinhardt [Mon, 4 Mar 2024 10:48:47 +0000 (11:48 +0100)] 
reftable/pq: use `size_t` to track iterator index

The reftable priority queue is used by the merged iterator to yield
records from its sub-iterators in the expected order. Each entry has a
record corresponding to such a sub-iterator as well as an index that
indicates which sub-iterator the record belongs to. But while the
sub-iterators are tracked with a `size_t`, we store the index as an
`int` in the entry.

Fix this and use `size_t` consistently.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agosetup: remove unnecessary variable
Ghanshyam Thakkar [Mon, 4 Mar 2024 15:18:11 +0000 (20:48 +0530)] 
setup: remove unnecessary variable

The TODO comment suggested to heed core.bare from template config file
if no command line override given. And the prev_bare_repository
variable seems to have been placed for this sole purpose as it is not
used anywhere else.

However, it was clarified by Junio [1] that such values (including
core.bare) are ignored intentionally and does not make sense to
propagate them from template config to repository config. Also, the
directories for the worktree and repository are already created, and
therefore the bare/non-bare decision has already been made, by the
point we reach the codepath where the TODO comment is placed.
Therefore, prev_bare_repository does not have a usecase with/without
supporting core.bare from template. And the removal of
prev_bare_repository is safe as proved by the later part of the
comment:

    "Unfortunately, the line above is equivalent to
        is_bare_repository_cfg = !work_tree;
    which ignores the config entirely even if no `--[no-]bare`
    command line option was present.

    To see why, note that before this function, there was this call:
        prev_bare_repository = is_bare_repository()
    expanding the right hand side:
        = is_bare_repository_cfg && !get_git_work_tree()
        = is_bare_repository_cfg && !work_tree
    note that the last simplification above is valid because nothing
    calls repo_init() or set_git_work_tree() between any of the
    relevant calls in the code, and thus the !get_git_work_tree()
    calls will return the same result each time.  So, what we are
    interested in computing is the right hand side of the line of
    code just above this comment:
        prev_bare_repository || !work_tree
        = is_bare_repository_cfg && !work_tree || !work_tree
        = !work_tree
    because "A && !B || !B == !B" for all boolean values of A & B."

Therefore, remove the TODO comment and remove prev_bare_repository
variable. Also, update relevant testcases and remove one redundant
testcase.

[1]: https://lore.kernel.org/git/xmqqjzonpy9l.fsf@gitster.g/

Helped-by: Elijah Newren <newren@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 months agot9117: prefer test_path_* helper functions
shejialuo [Mon, 4 Mar 2024 09:54:36 +0000 (17:54 +0800)] 
t9117: prefer test_path_* helper functions

test -(e|d) does not provide a nice error message when we hit test
failures, so use test_path_exists, test_path_is_dir instead.

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