]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
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 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>
2 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>
2 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

2 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()`

2 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

2 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

2 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

2 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

2 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()

2 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()

2 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"

2 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>

2 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

2 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

2 months agoThe third batch
Junio C Hamano [Fri, 1 Mar 2024 17:23:17 +0000 (09:23 -0800)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'tb/multi-pack-verbatim-reuse' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:56 +0000 (14:38 -0800)] 
Merge branch 'tb/multi-pack-verbatim-reuse' into HEAD

Docfix.

* tb/multi-pack-verbatim-reuse:
  Documentation/config/pack.txt: fix broken AsciiDoc mark-up

2 months agoMerge branch 'hs/rebase-not-in-progress' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:56 +0000 (14:38 -0800)] 
Merge branch 'hs/rebase-not-in-progress' into HEAD

Error message update.

* hs/rebase-not-in-progress:
  rebase: make warning less passive aggressive

2 months agoMerge branch 'jw/remote-doc-typofix' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:56 +0000 (14:38 -0800)] 
Merge branch 'jw/remote-doc-typofix' into HEAD

Docfix.

* jw/remote-doc-typofix:
  git-remote.txt: fix typo

2 months agoMerge branch 'jc/doc-add-placeholder-fix' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:55 +0000 (14:38 -0800)] 
Merge branch 'jc/doc-add-placeholder-fix' into HEAD

Practice the new mark-up rule for <placeholders> with "git add"
documentation page.

* jc/doc-add-placeholder-fix:
  doc: apply the new placeholder rules to git-add documentation

2 months agoMerge branch 'ja/doc-placeholders-markup-rules' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:55 +0000 (14:38 -0800)] 
Merge branch 'ja/doc-placeholders-markup-rules' into HEAD

The way placeholders are to be marked-up in documentation have been
specified; use "_<placeholder>_" to typeset the word inside a pair
of <angle-brakets> emphasized.

* ja/doc-placeholders-markup-rules:
  doc: clarify the format of placeholders

2 months agoMerge branch 'ps/reflog-list' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:55 +0000 (14:38 -0800)] 
Merge branch 'ps/reflog-list' into HEAD

"git reflog" learned a "list" subcommand that enumerates known reflogs.

* ps/reflog-list:
  builtin/reflog: introduce subcommand to list reflogs
  refs: stop resolving ref corresponding to reflogs
  refs: drop unused params from the reflog iterator callback
  refs: always treat iterators as ordered
  refs/files: sort merged worktree and common reflogs
  refs/files: sort reflogs returned by the reflog iterator
  dir-iterator: support iteration in sorted order
  dir-iterator: pass name to `prepare_next_entry_data()` directly

2 months agoMerge branch 'ds/doc-send-email-capitalization' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:54 +0000 (14:38 -0800)] 
Merge branch 'ds/doc-send-email-capitalization' into HEAD

Doc update.

* ds/doc-send-email-capitalization:
  documentation: send-email: use camel case consistently

2 months agoMerge branch 'ja/docfixes' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:54 +0000 (14:38 -0800)] 
Merge branch 'ja/docfixes' into HEAD

Doc update.

* ja/docfixes:
  doc: end sentences with full-stop
  doc: close unclosed angle-bracket of a placeholder in git-clone doc
  doc: git-rev-parse: enforce command-line description syntax

2 months agoMerge branch 'cp/t9146-use-test-path-helpers' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:54 +0000 (14:38 -0800)] 
Merge branch 'cp/t9146-use-test-path-helpers' into HEAD

Test script clean-up.

* cp/t9146-use-test-path-helpers:
  t9146: replace test -d/-e/-f with appropriate test_path_is_* function

2 months agoMerge branch 'ps/difftool-dir-diff-exit-code' into HEAD
Junio C Hamano [Fri, 1 Mar 2024 22:38:54 +0000 (14:38 -0800)] 
Merge branch 'ps/difftool-dir-diff-exit-code' into HEAD

"git difftool --dir-diff" learned to honor the "--trust-exit-code"
option; it used to always exit with 0 and signalled success.

* ps/difftool-dir-diff-exit-code:
  git-difftool--helper: honor `--trust-exit-code` with `--dir-diff`

2 months agoadd: use unsigned type for collection of bits
Eugenio Gigante [Thu, 29 Feb 2024 19:44:44 +0000 (20:44 +0100)] 
add: use unsigned type for collection of bits

The 'refresh' function in 'builtin/add.c' declares 'flags' as
signed, and passes it as an argument to the 'refresh_index'
function, which though expects an unsigned value.

Since in this case 'flags' represents a bag of bits, whose MSB is
not used in special ways, change the type of 'flags' to unsigned.

Signed-off-by: Eugenio Gigante <giganteeugenio2@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: only accept packfile-uris if we advertised it
Jeff King [Wed, 28 Feb 2024 22:50:50 +0000 (17:50 -0500)] 
upload-pack: only accept packfile-uris if we advertised it

Clients are only supposed to request particular capabilities or features
if the server advertised them. For the "packfile-uris" feature, we only
advertise it if uploadpack.blobpacfileuri is set, but we always accept a
request from the client regardless.

In practice this doesn't really hurt anything, as we'd pass the client's
protocol list on to pack-objects, which ends up ignoring it. But we
should try to follow the protocol spec, and tightening this up may catch
buggy or misbehaving clients more easily.

Thanks to recent refactoring, we can hoist the config check from
upload_pack_advertise() into upload_pack_config(). Note the subtle
handling of a value-less bool (which does not count for triggering an
advertisement).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: use existing config mechanism for advertisement
Jeff King [Wed, 28 Feb 2024 22:48:18 +0000 (17:48 -0500)] 
upload-pack: use existing config mechanism for advertisement

When serving a v2 capabilities request, we call upload_pack_advertise()
to tell us the set of features we can advertise to the client. That
involves looking at various config options, all of which need to be kept
in sync with the rules we use in upload_pack_config to set flags like
allow_filter, allow_sideband_all, and so on. If these two pieces of code
get out of sync then we may refuse to respect a capability we
advertised, or vice versa accept one that we should not.

Instead, let's call the same config helper that we'll use for processing
the actual client request, and then just pick the values out of the
resulting struct. This is only a little bit shorter than the current
code, but we don't repeat any policy logic (e.g., we don't have to worry
about the magic sideband-all environment variable here anymore).

And this reveals a gap in the existing code: there is no struct flag for
the packfile-uris capability (we accept it even if it is not advertised,
which we should not). We'll leave the advertisement code for now and
deal with it in the next patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: centralize setup of sideband-all config
Jeff King [Wed, 28 Feb 2024 22:47:18 +0000 (17:47 -0500)] 
upload-pack: centralize setup of sideband-all config

We read uploadpack.allowsidebandall to set a matching flag in our
upload_pack_data struct. But for our tests, we also respect
GIT_TEST_SIDEBAND_ALL from the environment, and anybody looking at the
flag in the struct needs to remember to check both. There's only one
such piece of code now, but we're about to add another.

So let's have the config step actually fold the environment value into
the struct, letting the rest of the code use the flag in the obvious
way.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: use repository struct to get config
Jeff King [Wed, 28 Feb 2024 22:46:47 +0000 (17:46 -0500)] 
upload-pack: use repository struct to get config

Our upload_pack_v2() function gets a repository struct, but we ignore it
totally.  In practice this doesn't cause any problems, as it will never
differ from the_repository. But in the spirit of taking a small step
towards getting rid of the_repository, let's at least starting using it
to grab config. There are probably other spots that could benefit, but
it's a start.

Note that we don't need to pass the repo for protected_config(); the
whole point there is that we are not looking at repo config, so there is
no repo-specific version of the function.

For the v0 version of the protocol, we're not passed a repository
struct, so we'll continue to use the_repository there.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: free tree buffers after parsing
Jeff King [Wed, 28 Feb 2024 22:39:07 +0000 (17:39 -0500)] 
upload-pack: free tree buffers after parsing

When a client sends us a "want" or "have" line, we call parse_object()
to get an object struct. If the object is a tree, then the parsed state
means that tree->buffer points to the uncompressed contents of the tree.
But we don't really care about it. We only really need to parse commits
and tags; for trees and blobs, the important output is just a "struct
object" with the correct type.

But much worse, we do not ever free that tree buffer. It's not leaked in
the traditional sense, in that we still have a pointer to it from the
global object hash. But if the client requests many trees, we'll hold
all of their contents in memory at the same time.

Nobody really noticed because it's rare for clients to directly request
a tree. It might happen for a lightweight tag pointing straight at a
tree, or it might happen for a "tree:depth" partial clone filling in
missing trees.

But it's also possible for a malicious client to request a lot of trees,
causing upload-pack's memory to balloon. For example, without this
patch, requesting every tree in git.git like:

  pktline() {
    local msg="$*"
    printf "%04x%s\n" $((1+4+${#msg})) "$msg"
  }

  want_trees() {
    pktline command=fetch
    printf 0001
    git cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype)' |
      while read oid type; do
        test "$type" = "tree" || continue
        pktline want $oid
      done
      pktline done
      printf 0000
  }

  want_trees | GIT_PROTOCOL=version=2 valgrind --tool=massif ./git upload-pack . >/dev/null

shows a peak heap usage of ~3.7GB. Which is just about the sum of the
sizes of all of the uncompressed trees. For linux.git, it's closer to
17GB.

So the obvious thing to do is to call free_tree_buffer() after we
realize that we've parsed a tree. We know that upload-pack won't need it
later. But let's push the logic into parse_object_with_flags(), telling
it to discard the tree buffer immediately. There are two reasons for
this. One, all of the relevant call-sites already call the with_options
variant to pass the SKIP_HASH flag. So it actually ends up as less code
than manually free-ing in each spot. And two, it enables an extra
optimization that I'll discuss below.

I've touched all of the sites that currently use SKIP_HASH in
upload-pack. That drops the peak heap of the upload-pack invocation
above from 3.7GB to ~24MB.

I've also modified the caller in get_reference(); a partial clone
benefits from its use in pack-objects for the reasons given in
0bc2557951 (upload-pack: skip parse-object re-hashing of "want" objects,
2022-09-06), where we were measuring blob requests. But note that the
results of get_reference() are used for traversing, as well; so we
really would _eventually_ use the tree contents. That makes this at
first glance a space/time tradeoff: we won't hold all of the trees in
memory at once, but we'll have to reload them each when it comes time to
traverse.

And here's where our extra optimization comes in. If the caller is not
going to immediately look at the tree contents, and it doesn't care
about checking the hash, then parse_object() can simply skip loading the
tree entirely, just like we do for blobs! And now it's not a space/time
tradeoff in get_reference() anymore. It's just a lazy-load: we're
delaying reading the tree contents until it's time to actually traverse
them one by one.

And of course for upload-pack, this optimization means we never load the
trees at all, saving lots of CPU time. Timing the "every tree from
git.git" request above shows upload-pack dropping from 32 seconds of CPU
to 19 (the remainder is mostly due to pack-objects actually sending the
pack; timing just the upload-pack portion shows we go from 13s to
~0.28s).

These are all highly gamed numbers, of course. For real-world
partial-clone requests we're saving only a small bit of time in
practice. But it does help harden upload-pack against malicious
denial-of-service attacks.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: use PARSE_OBJECT_SKIP_HASH_CHECK in more places
Jeff King [Wed, 28 Feb 2024 22:39:03 +0000 (17:39 -0500)] 
upload-pack: use PARSE_OBJECT_SKIP_HASH_CHECK in more places

In commit 0bc2557951 (upload-pack: skip parse-object re-hashing of
"want" objects, 2022-09-06), we optimized the parse_object() calls for
v2 "want" lines from the client so that they avoided parsing blobs, and
so that they used the commit-graph rather than parsing commit objects
from scratch.

We should extend that to two other spots:

  1. We parse "have" objects in the got_oid() function. These won't
     generally be non-commits (unlike "want" lines from a partial
     clone). But we still benefit from the use of the commit-graph.

  2. For v0, the "want" lines are parsed in receive_needs(). These are
     also less likely to be non-commits because by default they have to
     be ref tips. There are config options you might set to allow
     non-tip objects, but you'd mostly do so to support partial clones,
     and clients recent enough to support partial clone will generally
     speak v2 anyway.

So I don't expect this change to improve performance much for day-to-day
operations. But both are possible denial-of-service vectors, where an
attacker can waste our time by sending over a large number of objects to
parse (of course we may waste even more time serving a pack to them, but
we try as much as possible to optimize that in pack-objects; we should
do what we can here in upload-pack, too).

With this patch, running p5600 with GIT_TEST_PROTOCOL_VERSION=0 shows
similar results to what we saw in 0bc2557951 (which ran with the v2
protocol by default). Here are the numbers for linux.git:

  Test                          HEAD^                 HEAD
  -----------------------------------------------------------------------------
  5600.3: checkout of result    50.91(87.95+2.93)     41.75(79.00+3.18) -18.0%

Or for a more extreme (and malicious) case, we can claim to "have" every
blob in git.git over the v0 protocol:

  $ {
      echo "0032want $(git rev-parse HEAD)"
      printf 0000
      git cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype)' |
      perl -alne 'print "0032have $F[0]" if $F[1] eq "blob"'
    } >input

  $ time ./git.old upload-pack . <input >/dev/null
  real 0m52.951s
  user 0m51.633s
  sys 0m1.304s

  $ time ./git.new upload-pack . <input >/dev/null
  real 0m0.261s
  user 0m0.156s
  sys 0m0.105s

(Note that these don't actually compute a pack because of the hacky
protocol usage, so those numbers are representing the raw blob-parsing
effort done by upload-pack).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: always turn off save_commit_buffer
Jeff King [Wed, 28 Feb 2024 22:39:00 +0000 (17:39 -0500)] 
upload-pack: always turn off save_commit_buffer

When the client sends us "want $oid" lines, we call parse_object($oid)
to get an object struct. It's important to parse the commits because we
need to traverse them in the negotiation phase. But of course we don't
need to hold on to the commit messages for each one.

We've turned off the save_commit_buffer flag in get_common_commits() for
a long time, since f0243f26f6 (git-upload-pack: More efficient usage of
the has_sha1 array, 2005-10-28). That helps with the commits we see
while actually traversing. But:

  1. That function is only used by the v0 protocol. I think the v2
     protocol's code path leaves the flag on (and thus pays the extra
     memory penalty), though I didn't measure it specifically.

  2. If the client sends us a bunch of "want" lines, that happens before
     the negotiation phase. So we'll hold on to all of those commit
     messages. Generally the number of "want" lines scales with the
     refs, not with the number of objects in the repo. But a malicious
     client could send a lot in order to waste memory.

As an example of (2), if I generate a request to fetch all commits in
git.git like this:

  pktline() {
    local msg="$*"
    printf "%04x%s\n" $((1+4+${#msg})) "$msg"
  }

  want_commits() {
    pktline command=fetch
    printf 0001
    git cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype)' |
      while read oid type; do
        test "$type" = "commit" || continue
        pktline want $oid
      done
      pktline done
      printf 0000
  }

  want_commits | GIT_PROTOCOL=version=2 valgrind --tool=massif git-upload-pack . >/dev/null

before this patch upload-pack peaks at ~125MB, and after at ~35MB. The
difference is not coincidentally about the same as the sum of all commit
object sizes as computed by:

  git cat-file --batch-all-objects --batch-check='%(objecttype) %(objectsize)' |
  perl -alne '$v += $F[1] if $F[0] eq "commit"; END { print $v }'

In a larger repository like linux.git, that number is ~1GB.

In a repository with a full commit-graph file this will have no impact
(and the commit graph would save us from parsing at all, so is a much
better solution!). But it's easy to do, might help a little in
real-world cases (where even if you have a commit graph it might not be
fully up to date), and helps a lot for a worst-case malicious request.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: disallow object-info capability by default
Taylor Blau [Wed, 28 Feb 2024 22:38:58 +0000 (17:38 -0500)] 
upload-pack: disallow object-info capability by default

We added an "object-info" capability to the v2 upload-pack protocol in
a2ba162cda (object-info: support for retrieving object info,
2021-04-20). In the almost 3 years since, we have not added any
client-side support, and it does not appear to exist in other
implementations either (JGit understands the verb on the server side,
but not on the client side).

Since this largely unused code is accessible over the network by
default, it increases the attack surface of upload-pack. I don't know of
any particularly severe problem, but one issue is that because of the
request/response nature of the v2 protocol, it will happily read an
unbounded number of packets, adding each one to a string list (without
regard to whether they are objects we know about, duplicates, etc).

This may be something we want to improve in the long run, but in the
short term it makes sense to disable the feature entirely. We'll add a
config option as an escape hatch for anybody who wants to develop the
feature further.

A more gentle option would be to add the config option to let people
disable it manually, but leave it enabled by default. But given that
there's no client side support, that seems like the wrong balance with
security.

Disabling by default will slow adoption a bit once client-side support
does become available (there were some patches[1] in 2022, but nothing
got merged and there's been nothing since). But clients have to deal
with older servers that do not understand the option anyway (and the
capability system handles that), so it will just be a matter of servers
flipping their config at that point (and hopefully once any unbounded
allocations have been addressed).

[jk: this is a patch that GitHub has been running for several years, but
     rebased forward and with a new commit message for upstream]

[1] https://lore.kernel.org/git/20220208231911.725273-1-calvinwan@google.com/

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: accept only a single packfile-uri line
Jeff King [Wed, 28 Feb 2024 22:38:46 +0000 (17:38 -0500)] 
upload-pack: accept only a single packfile-uri line

When we see a packfile-uri line from the client, we use
string_list_split() to split it on commas and store the result in a
string_list.  A single packfile-uri line is therefore limited to storing
~64kb, the size of a pkt-line.

But we'll happily accept multiple such lines, and each line appends to
the string list, growing without bound.

In theory this could be useful, making:

  0017packfile-uris http
  0018packfile-uris https

equivalent to:

  001dpackfile-uris http,https

But the protocol documentation doesn't indicate that this should work
(and indeed, refers to this in the singular as "the following argument
can be included in the client's request"). And the client-side
implementation in fetch-pack has always sent a single line (JGit appears
to understand the line on the server side but has no client-side
implementation, and libgit2 understands neither).

If we were worried about compatibility, we could instead just put a
limit on the maximum number of values we'd accept. The current client
implementation limits itself to only two values: "http" and "https", so
something like "256" would be more than enough. But accepting only a
single line seems more in line with the protocol documentation, and
matches other parts of the protocol (e.g., we will not accept a second
"filter" line).

We'll also make this more explicit in the protocol documentation; as
above, I think this was always the intent, but there's no harm in making
it clear.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: use a strmap for want-ref lines
Jeff King [Wed, 28 Feb 2024 22:38:40 +0000 (17:38 -0500)] 
upload-pack: use a strmap for want-ref lines

When the "ref-in-want" capability is advertised (which it is not by
default), then upload-pack processes a "want-ref" line from the client
by checking that the name is a valid ref and recording it in a
string-list.

In theory this list should grow no larger than the number of refs in the
server-side repository. But since we don't do any de-duplication, a
client which sends "want-ref refs/heads/foo" over and over will cause
the array to grow without bound.

We can fix this by switching to strmap, which efficiently detects
duplicates. There are two client-visible changes here:

  1. The "wanted-refs" response will now be in an apparently-random
     order (based on iterating the hashmap) rather than the order given
     by the client. The protocol documentation is quiet on ordering
     here. The current fetch-pack implementation is happy with any
     order, as it looks up each returned ref using a binary search in
     its local sorted list. JGit seems to implement want-ref on the
     server side, but has no client-side support. libgit2 doesn't
     support either side.

     It would obviously be possible to record the original order or to
     use the strmap as an auxiliary data structure. But if the client
     doesn't care, we may as well do the simplest thing.

  2. We'll now reject duplicates explicitly as a protocol error. The
     client should never send them (and our current implementation, even
     when asked to "git fetch master:one master:two" will de-dup on the
     client side).

     If we wanted to be more forgiving, we could perhaps just throw away
     the duplicates. But then our "wanted-refs" response back to the
     client would omit the duplicates, and it's hard to say what a
     client that accidentally sent a duplicate would do with that. So I
     think we're better off to complain loudly before anybody
     accidentally writes such a client.

Let's also add a note to the protocol documentation clarifying that
duplicates are forbidden. As discussed above, this was already the
intent, but it's not very explicit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: use oidset for deepen_not list
Jeff King [Wed, 28 Feb 2024 22:37:44 +0000 (17:37 -0500)] 
upload-pack: use oidset for deepen_not list

We record the oid of every deepen-not line the client sends to us. For a
well-behaved client, the resulting array should be bounded by the number
of unique refs we have. But because there's no de-duplication, a
malicious client can cause the array to grow unbounded by just sending
the same "refs/heads/foo" over and over (assuming such a ref exists).

Since the deepen-not list is just being fed to a "rev-list --not"
traversal, the order of items doesn't matter. So we can replace the
oid_array with an oidset which notices and skips duplicates.

That bounds the memory in malicious cases to be linear in the number of
unique refs. And even in non-malicious cases, there may be a slight
improvement in memory usage if multiple refs point to the same oid
(though in practice this list is probably pretty tiny anyway, as it
comes from the user specifying "--shallow-exclude" on the client fetch).

Note that in the trace2 output we'll now output the number of
de-duplicated objects, rather than the total number of "deepen-not"
lines we received. This is arguably a more useful value for tracing /
debugging anyway.

Reported-by: Benjamin Flesch <benjaminflesch@icloud.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: switch deepen-not list to an oid_array
Jeff King [Wed, 28 Feb 2024 22:37:20 +0000 (17:37 -0500)] 
upload-pack: switch deepen-not list to an oid_array

When we see a "deepen-not" line from the client, we verify that the
given name can be resolved as a ref, and then add it to a string list to
be passed later to an internal "rev-list --not" traversal. We record the
actual refname in the string list (so the traversal resolves it again
later), but we'd be better off recording the resolved oid:

  1. There's a tiny bit of wasted work in resolving it twice.

  2. There's a small race condition with simultaneous updates; the later
     traversal may resolve to a different value (or not at all). This
     shouldn't cause any bad behavior (we do not care about the value
     in this first resolution, so whatever value rev-list gets is OK)
     but it could mean a confusing error message (if upload-pack fails
     to resolve the ref it produces a useful message, but a failing
     traversal later results in just "revision walk setup failed").

  3. It makes it simpler to de-duplicate the results. We don't de-dup at
     all right now, but we will in the next patch.

>From the client's perspective the behavior should be the same.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: drop separate v2 "haves" array
Jeff King [Wed, 28 Feb 2024 22:37:13 +0000 (17:37 -0500)] 
upload-pack: drop separate v2 "haves" array

When upload-pack sees a "have" line in the v0 protocol, it immediately
calls got_oid() with its argument and potentially produces an ACK
response. In the v2 protocol, we simply record the argument in an
oid_array, and only later process all of the "have" objects by calling
the equivalent of got_oid() on the contents of the array.

This makes some sense, as v2 is a pure request/response protocol, as
opposed to v0's asynchronous negotiation phase. But there's a downside:
a client can send us an infinite number of garbage "have" lines, which
we'll happily slurp into the array, consuming memory. Whereas in v0,
they are limited by the number of objects in the repository (because
got_oid() only records objects we have ourselves, and we avoid
duplicates by setting a flag on the object struct).

We can make v2 behave more like v0 by also calling got_oid() directly
when v2 parses a "have" line. Calling it early like this is OK because
got_oid() itself does not interact with the client; it only confirms
that we have the object and sets a few flags. Note that unlike v0, v2
does not ever (before or after this patch) check the return code of
got_oid(), which lets the caller know whether we have the object. But
again, that makes sense; v0 is using it to asynchronously tell the
client to stop sending. In v2's synchronous protocol, we just discard
those entries (and decide how to ACK at the end of each round).

There is one slight tweak we need, though. In v2's state machine, we
reach the SEND_ACKS state if the other side sent us any "have" lines,
whether they were useful or not. Right now we do that by checking
whether the "have" array had any entries, but if we record only the
useful ones, that doesn't work. Instead, we can add a simple boolean
that tells us whether we saw any have line (even if it was useless).

This lets us drop the "haves" array entirely, as we're now placing
objects directly into the "have_obj" object array (which is where
got_oid() put them in the long run anyway). And as a bonus, we can drop
the secondary "common" array used in process_haves_and_send_acks(). It
was essentially a copy of "haves" minus the objects we do not have. But
now that we are using "have_obj" directly, we know everything in it is
useful. So in addition to protecting ourselves against malicious input,
we should slightly lower our memory usage for normal inputs.

Note that there is one user-visible effect. The trace2 output records
the number of "haves". Previously this was the total number of "have"
lines we saw, but now is the number of useful ones. We could retain the
original meaning by keeping a separate counter, but it doesn't seem
worth the effort; this trace info is for debugging and metrics, and
arguably the count of common oids is at least as useful as the total
count.

Reported-by: Benjamin Flesch <benjaminflesch@icloud.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorevision: implement `git log --merge` also for rebase/cherry-pick/revert
Michael Lohmann [Wed, 28 Feb 2024 13:54:54 +0000 (08:54 -0500)] 
revision: implement `git log --merge` also for rebase/cherry-pick/revert

'git log' learned in ae3e5e1ef2 (git log -p --merge [[--] paths...],
2006-07-03) to show commits touching conflicted files in the range
HEAD...MERGE_HEAD, an addition documented in d249b45547 (Document
rev-list's option --merge, 2006-08-04).

It can be useful to look at the commit history to understand what lead
to merge conflicts also for other mergy operations besides merges, like
cherry-pick, revert and rebase.

For rebases and cherry-picks, an interesting range to look at is
HEAD...{REBASE_HEAD,CHERRY_PICK_HEAD}, since even if all the commits
included in that range are not directly part of the 3-way merge,
conflicts encountered during these operations can indeed be caused by
changes introduced in preceding commits on both sides of the history.

For revert, as we are (most likely) reversing changes from a previous
commit, an appropriate range is REVERT_HEAD..HEAD, which is equivalent
to REVERT_HEAD...HEAD and to HEAD...REVERT_HEAD, if we keep HEAD and its
parents on the left side of the range.

As such, adjust the code in prepare_show_merge so it constructs the
range HEAD...$OTHER for OTHER={MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD
or REBASE_HEAD}. Note that we try these pseudorefs in order, so keep
REBASE_HEAD last since the three other operations can be performed
during a rebase. Note also that in the uncommon case where $OTHER and
HEAD do not share a common ancestor, this will show the complete
histories of both sides since their root commits, which is the same
behaviour as currently happens in that case for HEAD and MERGE_HEAD.

Adjust the documentation of this option accordingly.

Co-authored-by: Johannes Sixt <j6t@kdbg.org>
Co-authored-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Michael Lohmann <mi.al.lohmann@gmail.com>
[jc: tweaked in j6t's precedence fix that tries REBASE_HEAD last]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorevision: ensure MERGE_HEAD is a ref in prepare_show_merge
Michael Lohmann [Wed, 28 Feb 2024 13:54:53 +0000 (08:54 -0500)] 
revision: ensure MERGE_HEAD is a ref in prepare_show_merge

This is done to

 (1) ensure MERGE_HEAD is a ref,
 (2) obtain the oid without any prefixing by refs.c:repo_dwim_ref()
 (3) error out when MERGE_HEAD is a symref.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Lohmann <mi.al.lohmann@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorevision: fix --missing=[print|allow*] for annotated tags
Christian Couder [Wed, 28 Feb 2024 09:10:11 +0000 (10:10 +0100)] 
revision: fix --missing=[print|allow*] for annotated tags

In 9830926c7d (rev-list: add commit object support in `--missing`
option, 2023-10-27) we fixed the `--missing` option in `git rev-list`
so that it works with missing commits, not just blobs/trees.

Unfortunately, such a command was still failing with a "fatal: bad
object <oid>" if it was passed a missing commit, blob or tree as an
argument (before the rev walking even begins). This was fixed in a
recent commit.

That fix still doesn't work when an argument passed to the command is
an annotated tag pointing to a missing commit though. In that case
`git rev-list --missing=...` still errors out with a "fatal: bad
object <oid>" error where <oid> is the object ID of the missing
commit.

Let's fix this issue, and also, while at it, let's add tests not just
for annotated tags but also for regular tags and branches.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoThe second batch
Junio C Hamano [Wed, 28 Feb 2024 00:04:14 +0000 (16:04 -0800)] 
The second batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'jb/doc-interactive-singlekey-do-not-need-perl'
Junio C Hamano [Wed, 28 Feb 2024 00:04:33 +0000 (16:04 -0800)] 
Merge branch 'jb/doc-interactive-singlekey-do-not-need-perl'

Doc clean-up.

* jb/doc-interactive-singlekey-do-not-need-perl:
  doc: remove outdated information about interactive.singleKey

2 months agoMerge branch 'jk/t0303-clean'
Junio C Hamano [Wed, 28 Feb 2024 00:04:32 +0000 (16:04 -0800)] 
Merge branch 'jk/t0303-clean'

Test clean-up.

* jk/t0303-clean:
  t0303: check that helper_test_clean removes all credentials

2 months agoMerge branch 'mh/libsecret-empty-password-fix'
Junio C Hamano [Wed, 28 Feb 2024 00:04:32 +0000 (16:04 -0800)] 
Merge branch 'mh/libsecret-empty-password-fix'

Credential helper based on libsecret (in contrib/) has been updated
to handle an empty password correctly.

* mh/libsecret-empty-password-fix:
  libsecret: retrieve empty password

2 months agoMerge branch 'bb/completion-no-grep-into-awk'
Junio C Hamano [Wed, 28 Feb 2024 00:04:32 +0000 (16:04 -0800)] 
Merge branch 'bb/completion-no-grep-into-awk'

Some parts of command line completion script (in contrib/) have
been micro-optimized.

* bb/completion-no-grep-into-awk:
  completion: use awk for filtering the config entries

2 months agoMerge branch 'km/mergetool-vimdiff-layout-fallback'
Junio C Hamano [Wed, 28 Feb 2024 00:04:32 +0000 (16:04 -0800)] 
Merge branch 'km/mergetool-vimdiff-layout-fallback'

Variants of vimdiff learned to honor mergetool.<variant>.layout settings.

* km/mergetool-vimdiff-layout-fallback:
  mergetools: vimdiff: use correct tool's name when reading mergetool config

2 months agoMerge branch 'ba/credential-test-clean-fix'
Junio C Hamano [Wed, 28 Feb 2024 00:04:32 +0000 (16:04 -0800)] 
Merge branch 'ba/credential-test-clean-fix'

Test clean-up.

* ba/credential-test-clean-fix:
  t/lib-credential: clean additional credential

2 months agoMerge branch 'rj/tag-column-fix'
Junio C Hamano [Wed, 28 Feb 2024 00:04:31 +0000 (16:04 -0800)] 
Merge branch 'rj/tag-column-fix'

"git tag --column" failed to check the exit status of its "git
column" invocation, which has been corrected.

* rj/tag-column-fix:
  tag: error when git-column fails

2 months agoMerge branch 'jc/am-whitespace-doc'
Junio C Hamano [Wed, 28 Feb 2024 00:04:31 +0000 (16:04 -0800)] 
Merge branch 'jc/am-whitespace-doc'

"git am --help" now tells readers what actions are available in
"git am --whitespace=<action>", in addition to saying that the
option is passed through to the underlying "git apply".

* jc/am-whitespace-doc:
  doc: add shortcut to "am --whitespace=<action>"

2 months agorefs/reftable: don't fail empty transactions in repo without HEAD
Patrick Steinhardt [Tue, 27 Feb 2024 14:27:39 +0000 (15:27 +0100)] 
refs/reftable: don't fail empty transactions in repo without HEAD

Under normal circumstances, it shouldn't ever happen that a repository
has no HEAD reference. In fact, git-update-ref(1) would fail any request
to delete the HEAD reference, and a newly initialized repository always
pre-creates it, too.

We have however changed git-clone(1) to partially initialize the
refdb just up to the point where remote helpers can find the
repository. With that change, we are going to run into a situation
where repositories have no refs at all.

Now there is a very particular edge case in this situation: when
preparing an empty ref transacton, we end up returning whatever value
`read_ref_without_reload()` returned to the caller. Under normal
conditions this would be fine: "HEAD" should usually exist, and thus the
function would return `0`. But if "HEAD" doesn't exist, the function
returns a positive value which we end up returning to the caller.

Fix this bug by resetting the return code to `0` and add a test.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'ps/remote-helper-repo-initialization-fix' into ps/reftable-repo-init-fix
Junio C Hamano [Tue, 27 Feb 2024 21:53:22 +0000 (13:53 -0800)] 
Merge branch 'ps/remote-helper-repo-initialization-fix' into ps/reftable-repo-init-fix

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

2 months agobuiltin/clone: allow remote helpers to detect repo
Patrick Steinhardt [Tue, 27 Feb 2024 14:27:44 +0000 (15:27 +0100)] 
builtin/clone: allow remote helpers to detect repo

In 18c9cb7524 (builtin/clone: create the refdb with the correct object
format, 2023-12-12), we have changed git-clone(1) so that it delays
creation of the refdb until after it has learned about the remote's
object format. This change was required for the reftable backend, which
encodes the object format into the tables. So if we pre-initialized the
refdb with the default object format, but the remote uses a different
object format than that, then the resulting tables would have encoded
the wrong object format.

This change unfortunately breaks remote helpers which try to access the
repository that is about to be created. Because the refdb has not yet
been initialized at the point where we spawn the remote helper, we also
don't yet have "HEAD" or "refs/". Consequently, any Git commands ran by
the remote helper which try to access the repository would fail because
it cannot be discovered.

This is essentially a chicken-and-egg problem: we cannot initialize the
refdb because we don't know about the object format. But we cannot learn
about the object format because the remote helper may be unable to
access the partially-initialized repository.

Ideally, we would address this issue via capabilities. But the remote
helper protocol is not structured in a way that guarantees that the
capability announcement happens before the remote helper tries to access
the repository.

Instead, fix this issue by partially initializing the refdb up to the
point where it becomes discoverable by Git commands.

Reported-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agogit: extend --no-lazy-fetch to work across subprocesses
Junio C Hamano [Tue, 27 Feb 2024 16:48:29 +0000 (08:48 -0800)] 
git: extend --no-lazy-fetch to work across subprocesses

Modeling after how the `--no-replace-objects` option is made usable
across subprocess spawning (e.g., cURL based remote helpers are
spawned as a separate process while running "git fetch"), allow the
`--no-lazy-fetch` option to be passed across process boundaries.

Do not model how the value of GIT_NO_REPLACE_OBJECTS environment
variable is ignored, though.  Just use the usual git_env_bool() to
allow "export GIT_NO_LAZY_FETCH=0" and "unset GIT_NO_LAZY_FETCH"
to be equivalents.

Also do not model how the request is not propagated to subprocesses
we spawn (e.g. "git clone --local" that spawns a new process to work
in the origin repository, while the original one working in the
newly created one) by the "--no-replace-objects" option, as this "do
not lazily fetch from the promisor" is more about a per-request
debugging aid, not "this repository's promisor should not be relied
upon" property specific to a repository.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agocommit: unify logic to avoid multiple scissors lines when merging
Josh Triplett [Tue, 27 Feb 2024 09:17:36 +0000 (01:17 -0800)] 
commit: unify logic to avoid multiple scissors lines when merging

prepare_to_commit has some logic to figure out whether merge already
added a scissors line, and therefore it shouldn't add another. Now that
wt_status_add_cut_line has built-in state for whether it has
already added a previous line, just set that state instead, and then
remove that condition from subsequent calls to wt_status_add_cut_line.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agocommit: avoid redundant scissor line with --cleanup=scissors -v
Josh Triplett [Tue, 27 Feb 2024 09:16:09 +0000 (01:16 -0800)] 
commit: avoid redundant scissor line with --cleanup=scissors -v

`git commit --cleanup=scissors -v` prints two scissors lines:
one at the start of the comment lines, and the other right before the
diff. This is redundant, and pushes the diff further down in the user's
editor than it needs to be.

Make wt_status_add_cut_line() remember if it has added a cut line before,
and avoid adding a redundant one.

Add a test for this.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agodoc: clarify the wording on <git-compat-util.h> requirement
Junio C Hamano [Mon, 26 Feb 2024 23:28:16 +0000 (15:28 -0800)] 
doc: clarify the wording on <git-compat-util.h> requirement

The reason why we require the <git-compat-util.h> file to be the
first header file to be included is because it insulates other
header files and source files from platform differences, like which
system header files must be included in what order, and what C
preprocessor feature macros must be defined to trigger certain
features we want out of the system.

We tried to clarify the rule in the coding guidelines document, but
the wording was a bit fuzzy that can lead to misinterpretations like
you can include <xdiff/xinclude.h> only to avoid having to include
<git-compat-util.h> even if you have nothing to do with the xdiff
implementation, for example.  "You do not have to include more than
one of these" was also misleading and would have been puzzling if
you _needed_ to depend on more than one of these approved headers
(answer: you are allowed to include them all if you need the
declarations in them for reasons other than that you want to avoid
including compat-util yourself).

Instead of using the phrase "approved headers", enumerate them as
exceptions, each labeled with its intended audiences, to avoid such
misinterpretations.  The structure also makes it easier to add new
exceptions, so add the description of "t/unit-tests/test-lib.h"
being an exception only for the unit tests implementation as an
example.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Kyle Lippincott <spectral@google.com>
Acked-by: Elijah Newren <newren@gmail.com>
2 months agorebase: fix typo in autosquash documentation
Richard Macklin [Tue, 27 Feb 2024 06:32:58 +0000 (06:32 +0000)] 
rebase: fix typo in autosquash documentation

This is a minor follow-up to cb00f524df (rebase: rewrite
--(no-)autosquash documentation, 2023-11-14) to fix a typo introduced in
that commit.

Signed-off-by: Richard Macklin <code@rmacklin.dev>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agogit: document GIT_NO_REPLACE_OBJECTS environment variable
Junio C Hamano [Fri, 16 Feb 2024 17:22:20 +0000 (09:22 -0800)] 
git: document GIT_NO_REPLACE_OBJECTS environment variable

This variable is used as the primary way to disable the object
replacement mechanism, with the "--no-replace-objects" command line
option as an end-user visible way to set it, but has not been
documented.

The original reason why it was left undocumented might be because it
was meant as an internal implementation detail, but the thing is,
that our tests use the environment variable directly without the
command line option, and there certainly are folks who learned its
use from there, making it impossible to deprecate or change its
behaviour by now.

Add documentation and note that for this variable, unlike many
boolean-looking environment variables, only the presence matters,
not what value it is set to.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoStart the 2.45 cycle
Junio C Hamano [Tue, 27 Feb 2024 01:23:44 +0000 (17:23 -0800)] 
Start the 2.45 cycle

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoMerge branch 'ps/ref-tests-update-even-more'
Junio C Hamano [Tue, 27 Feb 2024 02:10:25 +0000 (18:10 -0800)] 
Merge branch 'ps/ref-tests-update-even-more'

More tests that are marked as "ref-files only" have been updated to
improve test coverage of reftable backend.

* ps/ref-tests-update-even-more:
  t7003: ensure filter-branch prunes reflogs with the reftable backend
  t2011: exercise D/F conflicts with HEAD with the reftable backend
  t1405: remove unneeded cleanup step
  t1404: make D/F conflict tests compatible with reftable backend
  t1400: exercise reflog with gaps with reftable backend
  t0410: convert tests to use DEFAULT_REPO_FORMAT prereq
  t: move tests exercising the "files" backend

2 months agoMerge branch 'gt/at-is-synonym-for-head-in-add-patch'
Junio C Hamano [Tue, 27 Feb 2024 02:10:25 +0000 (18:10 -0800)] 
Merge branch 'gt/at-is-synonym-for-head-in-add-patch'

Teach "git checkout -p" and friends that "@" is a synonym for
"HEAD".

* gt/at-is-synonym-for-head-in-add-patch:
  add -p tests: remove PERL prerequisites
  add-patch: classify '@' as a synonym for 'HEAD'

2 months agoMerge branch 'kh/column-reject-negative-padding'
Junio C Hamano [Tue, 27 Feb 2024 02:10:25 +0000 (18:10 -0800)] 
Merge branch 'kh/column-reject-negative-padding'

"git column" has been taught to reject negative padding value, as
it would lead to nonsense behaviour including division by zero.

* kh/column-reject-negative-padding:
  column: guard against negative padding
  column: disallow negative padding

2 months agoMerge branch 'jc/t9210-lazy-fix'
Junio C Hamano [Tue, 27 Feb 2024 02:10:24 +0000 (18:10 -0800)] 
Merge branch 'jc/t9210-lazy-fix'

Adjust use of "rev-list --missing" in an existing tests so that it
does not depend on a buggy failure mode.

* jc/t9210-lazy-fix:
  t9210: do not rely on lazy fetching to fail

2 months agoMerge branch 'ps/reftable-iteration-perf'
Junio C Hamano [Tue, 27 Feb 2024 02:10:24 +0000 (18:10 -0800)] 
Merge branch 'ps/reftable-iteration-perf'

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

* ps/reftable-iteration-perf:
  reftable/reader: add comments to `table_iter_next()`
  reftable/record: don't try to reallocate ref record name
  reftable/block: swap buffers instead of copying
  reftable/pq: allocation-less comparison of entry keys
  reftable/merged: skip comparison for records of the same subiter
  reftable/merged: allocation-less dropping of shadowed records
  reftable/record: introduce function to compare records by key

2 months agoMerge branch 'rs/use-xstrncmpz'
Junio C Hamano [Tue, 27 Feb 2024 02:10:24 +0000 (18:10 -0800)] 
Merge branch 'rs/use-xstrncmpz'

Code clean-up.

* rs/use-xstrncmpz:
  use xstrncmpz()

2 months agoMerge branch 'cp/apply-core-filemode'
Junio C Hamano [Tue, 27 Feb 2024 02:10:24 +0000 (18:10 -0800)] 
Merge branch 'cp/apply-core-filemode'

"git apply" on a filesystem without filemode support have learned
to take a hint from what is in the index for the path, even when
not working with the "--index" or "--cached" option, when checking
the executable bit match what is required by the preimage in the
patch.

* cp/apply-core-filemode:
  apply: code simplification
  apply: correctly reverse patch's pre- and post-image mode bits
  apply: ignore working tree filemode when !core.filemode

2 months agoMerge branch 'ps/reftable-backend'
Junio C Hamano [Tue, 27 Feb 2024 02:10:23 +0000 (18:10 -0800)] 
Merge branch 'ps/reftable-backend'

Integrate the reftable code into the refs framework as a backend.

* ps/reftable-backend:
  refs/reftable: fix leak when copying reflog fails
  ci: add jobs to test with the reftable backend
  refs: introduce reftable backend

2 months agoneue: remove a bogus empty file
Johannes Schindelin [Mon, 26 Feb 2024 14:36:23 +0000 (14:36 +0000)] 
neue: remove a bogus empty file

This file has been added as part of 2232a88ab6b (attr: add builtin
objectmode values support, 2023-11-16) and most likely serves no
relevant purpose.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agomerge-ort: turn submodule conflict suggestions into an advice
Philippe Blain [Mon, 26 Feb 2024 13:27:28 +0000 (13:27 +0000)] 
merge-ort: turn submodule conflict suggestions into an advice

Add a new advice type 'submoduleMergeConflict' for the error message
shown when a non-trivial submodule conflict is encountered, which
was added in 4057523a40 (submodule merge: update conflict error
message, 2022-08-04). That commit mentions making this message an
advice as possible future work.  The message can now be disabled
with the advice mechanism.

Update the tests as the expected message now appears on stderr instead
of stdout.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoread_ref_at(): special-case ref@{0} for an empty reflog
Jeff King [Mon, 26 Feb 2024 10:08:03 +0000 (05:08 -0500)] 
read_ref_at(): special-case ref@{0} for an empty reflog

The previous commit special-cased get_oid_basic()'s handling of ref@{n}
for a reflog with n entries. But its special case doesn't work for
ref@{0} in an empty reflog, because read_ref_at() dies when it notices
the empty reflog!

We can make this work by special-casing this in read_ref_at(). It's
somewhat gross, for two reasons:

  1. We have no reflog entry to describe in the "msg" out-parameter. So
     we have to leave it uninitialized or make something up.

  2. Likewise, we have no oid to put in the "oid" out-parameter. Leaving
     it untouched is actually the best thing here, as all of the callers
     will have initialized it with the current ref value via
     repo_dwim_log(). This is rather subtle, but it is how things worked
     in 6436a20284 (refs: allow @{n} to work with n-sized reflog,
     2021-01-07) before we reverted it.

The key difference from 6436a20284 here is that we'll return "1" to
indicate that we _didn't_ find the requested reflog entry. Coupled with
the special-casing in get_oid_basic() in the previous commit, that's
enough to make looking up ref@{0} work, and we can flip 6436a20284's
test back to expect_success.

It also means that the call in show-branch which segfaulted with
6436a20284 (and which is now tested in t3202) remains OK. The caller
notices that we could not find any reflog entry, and so it breaks out of
its loop, showing nothing. This is different from the current behavior
of producing an error, but it's just as reasonable (and is exactly what
we'd do if you asked it to walk starting at ref@{1} but there was only 1
entry).

Thus nobody should actually look at the reflog entry info we return. But
we'll still put in some fake values just to be on the safe side, since
this is such a subtle and confusing interface. Likewise, we'll document
what's going on in a comment above the function declaration. If this
were a function with a lot of callers, the footgun would probably not be
worth it. But it has only ever had two callers in its 18-year existence,
and it seems unlikely to grow more. So let's hold our noses and let
users enjoy the convenience of a simulated ref@{0}.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoget_oid_basic(): special-case ref@{n} for oldest reflog entry
Jeff King [Mon, 26 Feb 2024 10:04:07 +0000 (05:04 -0500)] 
get_oid_basic(): special-case ref@{n} for oldest reflog entry

The goal of 6436a20284 (refs: allow @{n} to work with n-sized reflog,
2021-01-07) was that if we have "n" entries in a reflog, we should still
be able to resolve ref@{n} by looking at the "old" value of the oldest
entry.

Commit 6436a20284 tried to put the logic into read_ref_at() by shifting
its idea of "n" by one. But we reverted that in the previous commit,
since it led to bugs in other callers which cared about the details of
the reflog entry we found. Instead, let's put the special case into the
caller that resolves @{n}, as it cares only about the oid.

read_ref_at() is even kind enough to return the "old" value from the
final reflog; it just returns "1" to signal to us that we ran off the
end of the reflog. But we can notice in the caller that we read just
enough records for that "old" value to be the one we're looking for, and
use it.

Note that read_ref_at() could notice this case, too, and just return 0.
But we don't want to do that, because the caller must be made aware that
we only found the oid, not an actual reflog entry (and the call sites in
show-branch do care about this).

There is one complication, though. When read_ref_at() hits a truncated
reflog, it will return the "old" value of the oldest entry only if it is
not the null oid. Otherwise, it actually returns the "new" value from
that entry! This bit of fudging is due to d1a4489a56 (avoid null SHA1 in
oldest reflog, 2008-07-08), where asking for "ref@{20.years.ago}" for a
ref created recently will produce the initial value as a convenience
(even though technically it did not exist 20 years ago).

But this convenience is only useful for time-based cutoffs. For
count-based cutoffs, get_oid_basic() has always simply complained about
going too far back:

  $ git rev-parse HEAD@{20}
  fatal: log for 'HEAD' only has 16 entries

and we should continue to do so, rather than returning a nonsense value
(there's even a test in t1508 already which covers this). So let's have
the d1a4489a56 code kick in only when doing timestamp-based cutoffs.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoRevert "refs: allow @{n} to work with n-sized reflog"
Jeff King [Mon, 26 Feb 2024 10:02:26 +0000 (05:02 -0500)] 
Revert "refs: allow @{n} to work with n-sized reflog"

This reverts commit 6436a20284f33d42103cac93bd82e65bebb31526.

The idea of that commit is that if read_ref_at() is counting back to the
Nth reflog but the reflog is short by one entry (e.g., because it was
pruned), we can find the oid of the missing entry by looking at the
"before" oid value of the entry that comes after it (whereas before, we
looked at the "after" value of each entry and complained that we
couldn't find the one from before the truncation).

This works fine for resolving the oid of ref@{n}, as it is used by
get_oid_basic(), which does not look at any other aspect of the reflog
we found (e.g., its timestamp or message). But there's another caller of
read_ref_at(): in show-branch we use it to walk over the reflog, and we
do care about the reflog entry. And so that commit broke "show-branch
--reflog"; it shows the reflog message for ref@{0} as ref@{1}, ref@{1}
as ref@{2}, and so on.

For example, in the new test in t3202 we produce:

  ! [branch@{0}] (0 seconds ago) commit: three
   ! [branch@{1}] (0 seconds ago) commit: three
    ! [branch@{2}] (60 seconds ago) commit: two
     ! [branch@{3}] (2 minutes ago) reset: moving to HEAD^

instead of the correct:

  ! [branch@{0}] (0 seconds ago) commit: three
   ! [branch@{1}] (60 seconds ago) commit: two
    ! [branch@{2}] (2 minutes ago) reset: moving to HEAD^
     ! [branch@{3}] (2 minutes ago) commit: one

But there's another bug, too: because it is looking at the "old" value
of the reflog after the one we're interested in, it has to special-case
ref@{0} (since there isn't anything after it). That's why it doesn't
show the offset bug in the output above. But this special-case code
fails to handle the situation where the reflog is empty or missing; it
returns success even though the reflog message out-parameter has been
left uninitialized. You can't trigger this through get_oid_basic(), but
"show-branch --reflog" will pretty reliably segfault as it tries to
access the garbage pointer.

Fixing the segfault would be pretty easy. But the off-by-one problem is
inherent in this approach. So let's start by reverting the commit to
give us a clean slate to work with.

This isn't a pure revert; all of the code changes are reverted, but for
the tests:

  1. We'll flip the cases in t1508 to expect_failure; making these work
     was the goal of 6436a2028, and we'll want to use them for our
     replacement approach.

  2. There's a test in t3202 for "show-branch --reflog", but it expects
     the broken output! It was added by f2463490c4 (show-branch: show
     reflog message, 2021-12-02) which was fixing another bug, and I
     think the author simply didn't notice that the second line showed
     the wrong reflog.

     Rather than fixing that test, let's replace it with one that is
     more thorough (while still covering the reflog message fix from
     that commit). We'll use a longer reflog, which lets us see more
     entries (thus making the "off by one" pattern much more clear). And
     we'll use a more recent timestamp for "now" so that our relative
     dates have more resolution. That lets us see that the reflog dates
     are correct (whereas when you are 4 years away, two entries that
     are 60 seconds apart will have the same "4 years ago" relative
     date). Because we're adjusting the repository state, I've moved
     this new test to the end of the script, leaving the other tests
     undisturbed.

     We'll also add a new test which covers the missing reflog case;
     previously it segfaulted, but now it reports the empty reflog).

Reported-by: Yasushi SHOJI <yasushi.shoji@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoupload-pack: don't send null character in abort message to the client
SZEDER Gábor [Sun, 25 Feb 2024 18:34:52 +0000 (19:34 +0100)] 
upload-pack: don't send null character in abort message to the client

Since 583b7ea31b (upload-pack/fetch-pack: support side-band
communication, 2006-06-21) the abort message sent by upload-pack in
case of possible repository corruption ends with a null character.
This can be seen in several test cases in 't5530-upload-pack-error.sh'
where 'grep <pattern> output.err' often reports "Binary file
output.err matches" because of that null character.

The reason for this is that the abort message is defined as a string
literal, and we pass its size to the send function as
sizeof(abort_msg), which also counts the terminating null character.

Use strlen() instead to avoid sending that terminating null character.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agosubmodule: use strvec_pushf() for --submodule-prefix
René Scharfe [Sun, 25 Feb 2024 18:24:39 +0000 (19:24 +0100)] 
submodule: use strvec_pushf() for --submodule-prefix

Add the option --submodule-prefix and its argument directly using
strvec_pushf() instead of via a detour through a strbuf.  This is
shorter, easier to read and doesn't require any explicit cleanup
afterwards.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agouserdiff: skip textconv caching when not in a repository
Jeff King [Mon, 26 Feb 2024 10:27:29 +0000 (05:27 -0500)] 
userdiff: skip textconv caching when not in a repository

The textconv caching system uses git-notes to store its cache entries.
But if you're using "diff --no-index" outside of a repository, then
obviously that isn't going to work.

Since caching is just an optimization, it's OK for us to skip it.
However, the current behavior is much worse: we call notes_cache_init()
which tries to look up the ref, and the low-level ref code hits a BUG(),
killing the program. Instead, we should notice before setting up the
cache that it there's no repository, and just silently skip it.

Reported-by: Paweł Dominiak <dominiak.pawel@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoname-rev: use mem_pool_strfmt()
René Scharfe [Sun, 25 Feb 2024 11:39:45 +0000 (12:39 +0100)] 
name-rev: use mem_pool_strfmt()

1c56fc2084 (name-rev: pre-size buffer in get_parent_name(), 2020-02-04)
got a big performance boost in an unusual repository by calculating the
name length in advance.  This is a bit awkward, as it references the
name components twice.

Use a memory pool to store the strings for the struct rev_name member
tip_name.  Using mem_pool_strfmt() allows efficient allocation without
explicit size calculation.  This simplifies the formatting part of the
code without giving up performance:

Benchmark 1: ./git_2.44.0 -C ../chromium/src name-rev --all
  Time (mean ± σ):      1.231 s ±  0.013 s    [User: 1.082 s, System: 0.136 s]
  Range (min … max):    1.214 s …  1.252 s    10 runs

Benchmark 2: ./git -C ../chromium/src name-rev --all
  Time (mean ± σ):      1.220 s ±  0.020 s    [User: 1.083 s, System: 0.130 s]
  Range (min … max):    1.197 s …  1.254 s    10 runs

Don't bother discarding the memory pool just before exiting.  The effort
for that would be very low, but actually measurable in the above
example, with no benefit to users.  At least UNLEAK it to calm down leak
checkers.  This addresses the leaks that 45a14f578e (Revert "name-rev:
release unused name strings", 2022-04-22) brought back.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agomem-pool: add mem_pool_strfmt()
René Scharfe [Sun, 25 Feb 2024 11:39:44 +0000 (12:39 +0100)] 
mem-pool: add mem_pool_strfmt()

Add a function for building a string, printf style, using a memory pool.
It uses the free space in the current block in the first attempt.  If
that suffices then the result can already be used without copying or
reformatting.

For strings that are significantly shorter on average than the block
size (ca. 1 MiB by default) this is the case most of the time, leading
to a better perfomance than a solution that doesn't access mem-pool
internals.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agofetch: convert strncmp() with strlen() to starts_with()
René Scharfe [Sat, 24 Feb 2024 21:47:06 +0000 (22:47 +0100)] 
fetch: convert strncmp() with strlen() to starts_with()

Using strncmp() and strlen() to check whether a string starts with
another one requires repeating the prefix candidate.  Use starts_with()
instead, which reduces repetition and is more readable.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agocompat: drop inclusion of <git-compat-util.h>
Junio C Hamano [Sat, 24 Feb 2024 20:32:51 +0000 (12:32 -0800)] 
compat: drop inclusion of <git-compat-util.h>

These two header files are included from ordinary source files that
already include <git-compat-util.h> as the first header file as they
should.  There is no need to include the compat-util in these
headers.

"make hdr-check" is not affected, as it is designed to assume that
what <git-compat-util.h> offers is available to everybody without
being included.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoDocumentation/config/pack.txt: fix broken AsciiDoc mark-up
Taylor Blau [Fri, 23 Feb 2024 20:30:58 +0000 (15:30 -0500)] 
Documentation/config/pack.txt: fix broken AsciiDoc mark-up

In af626ac0e0 (pack-bitmap: enable reuse from all bitmapped packs,
2023-12-14), the documentation for `pack.allowPackReuse` was amended to
include its effect when set to "multi".

This split the documentation into two paragraphs, but did not de-dent
the second paragraph on the right-hand side of a line-continuation
marker. This causes the rendered documentation to appear oddly, where
the second paragraph is treated as a <pre> block when rendered as HTML.

Fix this by correctly removing the indentation on the second paragraph.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agofor-each-ref: add new option to include root refs
Karthik Nayak [Fri, 23 Feb 2024 10:01:12 +0000 (11:01 +0100)] 
for-each-ref: add new option to include root refs

The git-for-each-ref(1) command doesn't provide a way to print root refs
i.e pseudorefs and HEAD with the regular "refs/" prefixed refs.

This commit adds a new option "--include-root-refs" to
git-for-each-ref(1). When used this would also print pseudorefs and HEAD
for the current worktree.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR'
Karthik Nayak [Fri, 23 Feb 2024 10:01:11 +0000 (11:01 +0100)] 
ref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR'

The flag 'FILTER_REFS_ALL' is a bit ambiguous, where ALL doesn't specify
if it means to contain refs from all worktrees or whether all types of
refs (regular, HEAD & pseudorefs) or all of the above.

Since here it is actually referring to all refs with the "refs/" prefix,
let's rename it to 'FILTER_REFS_REGULAR' to indicate that this is
specifically for regular refs.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorefs: introduce `refs_for_each_include_root_refs()`
Karthik Nayak [Fri, 23 Feb 2024 10:01:10 +0000 (11:01 +0100)] 
refs: introduce `refs_for_each_include_root_refs()`

Introduce a new ref iteration flag `DO_FOR_EACH_INCLUDE_ROOT_REFS`,
which will be used to iterate over regular refs plus pseudorefs and
HEAD.

Refs which fall outside the `refs/` and aren't either pseudorefs or HEAD
are more of a grey area. This is because we don't block the users from
creating such refs but they are not officially supported.

Introduce `refs_for_each_include_root_refs()` which calls
`do_for_each_ref()` with this newly introduced flag.

In `refs/files-backend.c`, introduce a new function
`add_pseudoref_and_head_entries()` to add pseudorefs and HEAD to the
`ref_dir`. We then finally call `add_pseudoref_and_head_entries()`
whenever the `DO_FOR_EACH_INCLUDE_ROOT_REFS` flag is set. Any new ref
backend will also have to implement similar changes on its end.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorefs: extract out `loose_fill_ref_dir_regular_file()`
Karthik Nayak [Fri, 23 Feb 2024 10:01:09 +0000 (11:01 +0100)] 
refs: extract out `loose_fill_ref_dir_regular_file()`

Extract out the code for adding a single file to the loose ref dir as
`loose_fill_ref_dir_regular_file()` from `loose_fill_ref_dir()` in
`refs/files-backend.c`.

This allows us to use this function independently in the following
commits where we add code to also add pseudorefs to the ref dir.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agorefs: introduce `is_pseudoref()` and `is_headref()`
Karthik Nayak [Fri, 23 Feb 2024 10:01:08 +0000 (11:01 +0100)] 
refs: introduce `is_pseudoref()` and `is_headref()`

Introduce two new functions `is_pseudoref()` and `is_headref()`. This
provides the necessary functionality for us to add pseudorefs and HEAD
to the loose ref cache in the files backend, allowing us to build
tooling to print these refs.

The `is_pseudoref()` function internally calls `is_pseudoref_syntax()`
but adds onto it by also checking to ensure that the pseudoref either
ends with a "_HEAD" suffix or matches a list of exceptions. After which
we also parse the contents of the pseudoref to ensure that it conforms
to the ref format.

We cannot directly add the new syntax checks to `is_pseudoref_syntax()`
because the function is also used by `is_current_worktree_ref()` and
making it stricter to match only known pseudorefs might have unintended
consequences due to files like 'BISECT_START' which isn't a pseudoref
but sometimes contains object ID.

Keeping this in mind, we leave `is_pseudoref_syntax()` as is and create
`is_pseudoref()` which is stricter. Ideally we'd want to move the new
syntax checks to `is_pseudoref_syntax()` but a prerequisite for this
would be to actually remove the exception list by converting those
pseudorefs to also contain a '_HEAD' suffix and perhaps move bisect
related files like 'BISECT_START' to a new directory similar to the
'rebase-merge' directory.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agofill_tree_descriptor(): mark error message for translation
Johannes Schindelin [Fri, 23 Feb 2024 08:34:25 +0000 (08:34 +0000)] 
fill_tree_descriptor(): mark error message for translation

There is an error message in that function to report a missing tree; In
contrast to three other, similar error messages, it is not marked for
translation yet.

Mark it for translation, and while at it, make the error message
consistent with the others by enclosing the SHA in parentheses.

This requires a change to t6030 which expects the previous format of the
commit message. Theoretically, this could present problems with existing
scripts that use `git bisect` and parse its output (because Git does not
provide other means for callers to discern between error conditions).
However, this is unlikely to matter in practice because the most common
course of action to deal with fatal corruptions is to report the error
message to the user and exit, rather than trying to do something with
the reported SHA of the missing tree.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agocache-tree: avoid an unnecessary check
Johannes Schindelin [Fri, 23 Feb 2024 08:34:24 +0000 (08:34 +0000)] 
cache-tree: avoid an unnecessary check

The first thing the `parse_tree()` function does is to return early if
the tree has already been parsed. Therefore we do not need to guard the
`parse_tree()` call behind a check of that flag.

As of time of writing, there are no other instances of this in Git's
code bases: whenever the `parsed` flag guards a `parse_tree()` call, it
guards more than just that call.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 months agoAlways check `parse_tree*()`'s return value
Johannes Schindelin [Fri, 23 Feb 2024 08:34:23 +0000 (08:34 +0000)] 
Always check `parse_tree*()`'s return value

Otherwise we may easily run into serious crashes: For example, if we run
`init_tree_desc()` directly after a failed `parse_tree()`, we are
accessing uninitialized data or trying to dereference `NULL`.

Note that the `parse_tree()` function already takes care of showing an
error message. The `parse_tree_indirectly()` and
`repo_get_commit_tree()` functions do not, therefore those latter call
sites need to show a useful error message while the former do not.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>