]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
4 months agot2400: avoid losing exit status to pipes
Achu Luma [Sat, 20 Jan 2024 02:15:47 +0000 (03:15 +0100)] 
t2400: avoid losing exit status to pipes

The exit code of the preceding command in a pipe is disregarded. So
if that preceding command is a Git command that fails, the test would
not fail. Instead, by saving the output of that Git command to a file,
and removing the pipe, we make sure the test will fail if that Git
command fails.

Signed-off-by: Achu Luma <ach.lumap@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoThe ninth batch
Junio C Hamano [Fri, 19 Jan 2024 22:57:34 +0000 (14:57 -0800)] 
The ninth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ps/p4-use-ref-api'
Junio C Hamano [Fri, 19 Jan 2024 23:04:46 +0000 (15:04 -0800)] 
Merge branch 'ps/p4-use-ref-api'

"git p4" update to prepare for reftable

* ps/p4-use-ref-api:
  git-p4: stop reaching into the refdb

4 months agoMerge branch 'cp/t4129-pipefix'
Junio C Hamano [Fri, 19 Jan 2024 23:04:46 +0000 (15:04 -0800)] 
Merge branch 'cp/t4129-pipefix'

Test update.

* cp/t4129-pipefix:
  t4129: prevent loss of exit code due to the use of pipes

4 months agoMerge branch 'sk/mingw-owner-check-error-message-improvement'
Junio C Hamano [Fri, 19 Jan 2024 23:04:46 +0000 (15:04 -0800)] 
Merge branch 'sk/mingw-owner-check-error-message-improvement'

In addition to (rather cryptic) Security Identifiers, show username
and domain in the error message when we barf on mismatch between
the Git directory and the current user on Windows.

* sk/mingw-owner-check-error-message-improvement:
  mingw: give more details about unsafe directory's ownership

4 months agoMerge branch 'bk/bisect-doc-fix'
Junio C Hamano [Fri, 19 Jan 2024 23:04:46 +0000 (15:04 -0800)] 
Merge branch 'bk/bisect-doc-fix'

Synopsis fix.

* bk/bisect-doc-fix:
  doc: refer to pathspec instead of path
  doc: use singular form of repeatable path arg

4 months agoMerge branch 'tb/fetch-all-configuration'
Junio C Hamano [Fri, 19 Jan 2024 23:04:45 +0000 (15:04 -0800)] 
Merge branch 'tb/fetch-all-configuration'

"git fetch" learned to pay attention to "fetch.all" configuration
variable, which pretends as if "--all" was passed from the command
line when no remote parameter was given.

* tb/fetch-all-configuration:
  fetch: add new config option fetch.all

4 months agoMerge branch 'rj/clarify-branch-doc-m'
Junio C Hamano [Fri, 19 Jan 2024 23:04:45 +0000 (15:04 -0800)] 
Merge branch 'rj/clarify-branch-doc-m'

Doc update.

* rj/clarify-branch-doc-m:
  branch: clarify <oldbranch> term

4 months agoMerge branch 'ps/gitlab-ci-static-analysis'
Junio C Hamano [Fri, 19 Jan 2024 23:04:45 +0000 (15:04 -0800)] 
Merge branch 'ps/gitlab-ci-static-analysis'

GitLab CI update.

* ps/gitlab-ci-static-analysis:
  ci: add job performing static analysis on GitLab CI

4 months agoMerge branch 'ps/prompt-parse-HEAD-futureproof'
Junio C Hamano [Fri, 19 Jan 2024 23:04:45 +0000 (15:04 -0800)] 
Merge branch 'ps/prompt-parse-HEAD-futureproof'

Futureproof command line prompt support (in contrib/).

* ps/prompt-parse-HEAD-futureproof:
  git-prompt: stop manually parsing HEAD with unknown ref formats

4 months agoThe eighth batch
Junio C Hamano [Tue, 16 Jan 2024 18:11:37 +0000 (10:11 -0800)] 
The eighth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ib/rebase-reschedule-doc'
Junio C Hamano [Tue, 16 Jan 2024 18:11:58 +0000 (10:11 -0800)] 
Merge branch 'ib/rebase-reschedule-doc'

Doc update.

* ib/rebase-reschedule-doc:
  rebase: clarify --reschedule-failed-exec default

4 months agoMerge branch 'jk/commit-graph-slab-clear-fix'
Junio C Hamano [Tue, 16 Jan 2024 18:11:58 +0000 (10:11 -0800)] 
Merge branch 'jk/commit-graph-slab-clear-fix'

Clearing in-core repository (happens during e.g., "git fetch
--recurse-submodules" with commit graph enabled) made in-core
commit object in an inconsistent state by discarding the necessary
data from commit-graph too early, which has been corrected.

* jk/commit-graph-slab-clear-fix:
  commit-graph: retain commit slab when closing NULL commit_graph

4 months agoMerge branch 'jk/index-pack-lsan-false-positive-fix'
Junio C Hamano [Tue, 16 Jan 2024 18:11:58 +0000 (10:11 -0800)] 
Merge branch 'jk/index-pack-lsan-false-positive-fix'

Fix false positive reported by leak sanitizer.

* jk/index-pack-lsan-false-positive-fix:
  index-pack: spawn threads atomically

4 months agoMerge branch 'cp/sideband-array-index-comment-fix'
Junio C Hamano [Tue, 16 Jan 2024 18:11:57 +0000 (10:11 -0800)] 
Merge branch 'cp/sideband-array-index-comment-fix'

In-code comment fix.

* cp/sideband-array-index-comment-fix:
  sideband.c: remove redundant 'NEEDSWORK' tag

4 months agoMerge branch 'ps/refstorage-extension'
Junio C Hamano [Tue, 16 Jan 2024 18:11:57 +0000 (10:11 -0800)] 
Merge branch 'ps/refstorage-extension'

Introduce a new extension "refstorage" so that we can mark a
repository that uses a non-default ref backend, like reftable.

* ps/refstorage-extension:
  t9500: write "extensions.refstorage" into config
  builtin/clone: introduce `--ref-format=` value flag
  builtin/init: introduce `--ref-format=` value flag
  builtin/rev-parse: introduce `--show-ref-format` flag
  t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar
  setup: introduce GIT_DEFAULT_REF_FORMAT envvar
  setup: introduce "extensions.refStorage" extension
  setup: set repository's formats on init
  setup: start tracking ref storage format
  refs: refactor logic to look up storage backends
  worktree: skip reading HEAD when repairing worktrees
  t: introduce DEFAULT_REPO_FORMAT prereq

4 months agoMerge branch 'ps/reftable-fixes-and-optims'
Junio C Hamano [Tue, 16 Jan 2024 18:11:56 +0000 (10:11 -0800)] 
Merge branch 'ps/reftable-fixes-and-optims'

More fixes and optimizations to the reftable backend.

* ps/reftable-fixes-and-optims:
  reftable/merged: transfer ownership of records when iterating
  reftable/merged: really reuse buffers to compute record keys
  reftable/record: store "val2" hashes as static arrays
  reftable/record: store "val1" hashes as static arrays
  reftable/record: constify some parts of the interface
  reftable/writer: fix index corruption when writing multiple indices
  reftable/stack: do not auto-compact twice in `reftable_stack_add()`
  reftable/stack: do not overwrite errors when compacting

4 months agoThe seventh batch
Junio C Hamano [Fri, 12 Jan 2024 23:58:36 +0000 (15:58 -0800)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'cp/git-flush-is-an-env-bool'
Junio C Hamano [Sat, 13 Jan 2024 00:09:57 +0000 (16:09 -0800)] 
Merge branch 'cp/git-flush-is-an-env-bool'

Unlike other environment variables that took the usual
true/false/yes/no as well as 0/1, GIT_FLUSH only understood 0/1,
which has been corrected.

* cp/git-flush-is-an-env-bool:
  write-or-die: make GIT_FLUSH a Boolean environment variable

4 months agoMerge branch 'ms/rebase-insnformat-doc-fix'
Junio C Hamano [Sat, 13 Jan 2024 00:09:56 +0000 (16:09 -0800)] 
Merge branch 'ms/rebase-insnformat-doc-fix'

Docfix.

* ms/rebase-insnformat-doc-fix:
  Documentation: fix statement about rebase.instructionFormat

4 months agoMerge branch 'jx/sideband-chomp-newline-fix'
Junio C Hamano [Sat, 13 Jan 2024 00:09:56 +0000 (16:09 -0800)] 
Merge branch 'jx/sideband-chomp-newline-fix'

Sideband demultiplexer fixes.

* jx/sideband-chomp-newline-fix:
  pkt-line: do not chomp newlines for sideband messages
  pkt-line: memorize sideband fragment in reader
  test-pkt-line: add option parser for unpack-sideband

4 months agoMerge branch 'tb/multi-pack-verbatim-reuse'
Junio C Hamano [Sat, 13 Jan 2024 00:09:56 +0000 (16:09 -0800)] 
Merge branch 'tb/multi-pack-verbatim-reuse'

Streaming spans of packfile data used to be done only from a
single, primary, pack in a repository with multiple packfiles.  It
has been extended to allow reuse from other packfiles, too.

* tb/multi-pack-verbatim-reuse: (26 commits)
  t/perf: add performance tests for multi-pack reuse
  pack-bitmap: enable reuse from all bitmapped packs
  pack-objects: allow setting `pack.allowPackReuse` to "single"
  t/test-lib-functions.sh: implement `test_trace2_data` helper
  pack-objects: add tracing for various packfile metrics
  pack-bitmap: prepare to mark objects from multiple packs for reuse
  pack-revindex: implement `midx_pair_to_pack_pos()`
  pack-revindex: factor out `midx_key_to_pack_pos()` helper
  midx: implement `midx_preferred_pack()`
  git-compat-util.h: implement checked size_t to uint32_t conversion
  pack-objects: include number of packs reused in output
  pack-objects: prepare `write_reused_pack_verbatim()` for multi-pack reuse
  pack-objects: prepare `write_reused_pack()` for multi-pack reuse
  pack-objects: pass `bitmapped_pack`'s to pack-reuse functions
  pack-objects: keep track of `pack_start` for each reuse pack
  pack-objects: parameterize pack-reuse routines over a single pack
  pack-bitmap: return multiple packs via `reuse_partial_packfile_from_bitmap()`
  pack-bitmap: simplify `reuse_partial_packfile_from_bitmap()` signature
  ewah: implement `bitmap_is_empty()`
  pack-bitmap: pass `bitmapped_pack` struct to pack-reuse functions
  ...

4 months agoMerge branch 'jk/t1006-cat-file-objectsize-disk'
Junio C Hamano [Sat, 13 Jan 2024 00:09:56 +0000 (16:09 -0800)] 
Merge branch 'jk/t1006-cat-file-objectsize-disk'

Test update.

* jk/t1006-cat-file-objectsize-disk:
  t1006: prefer shell loop to awk for packed object sizes
  t1006: add tests for %(objectsize:disk)

4 months agoMerge branch 'jw/builtin-objectmode-attr'
Junio C Hamano [Sat, 13 Jan 2024 00:09:55 +0000 (16:09 -0800)] 
Merge branch 'jw/builtin-objectmode-attr'

The builtin_objectmode attribute is populated for each path
without adding anything in .gitattributes files, which would be
useful in magic pathspec, e.g., ":(attr:builtin_objectmode=100755)"
to limit to executables.

* jw/builtin-objectmode-attr:
  attr: add builtin objectmode values support

4 months agoMerge branch 'js/contributor-docs-updates'
Junio C Hamano [Sat, 13 Jan 2024 00:09:55 +0000 (16:09 -0800)] 
Merge branch 'js/contributor-docs-updates'

Doc update.

* js/contributor-docs-updates:
  SubmittingPatches: hyphenate non-ASCII
  SubmittingPatches: clarify GitHub artifact format
  SubmittingPatches: clarify GitHub visual
  SubmittingPatches: provide tag naming advice
  SubmittingPatches: update extra tags list
  SubmittingPatches: discourage new trailers
  SubmittingPatches: drop ref to "What's in git.git"
  CodingGuidelines: write punctuation marks
  CodingGuidelines: move period inside parentheses

4 months agogit-p4: stop reaching into the refdb
Patrick Steinhardt [Thu, 11 Jan 2024 13:47:27 +0000 (14:47 +0100)] 
git-p4: stop reaching into the refdb

The git-p4 tool creates a bunch of temporary branches that share a
common prefix "refs/git-p4-tmp/". These branches get cleaned up via
git-update-ref(1) after the import has finished. Once done, we try to
manually remove the now supposedly-empty ".git/refs/git-p4-tmp/"
directory.

This last step can fail in case there still are any temporary branches
around that we failed to delete because `os.rmdir()` refuses to delete a
non-empty directory. It can thus be seen as kind of a sanity check to
verify that we really did delete all temporary branches. Another failure
mode though is when the directory didn't exist in the first place, which
can be the case when using an alternate ref backend like the upcoming
"reftable" backend.

Convert the code to instead use git-for-each-ref(1) to verify that there
are no more temporary branches around. This works alright with alternate
ref backends while retaining the sanity check that we really did prune
all temporary branches.

This is a modification in behaviour for the "files" backend because the
empty directory does not get deleted anymore. But arguably we should not
care about such implementation details of the ref backend anyway, and
this should not cause any user-visible change in behaviour.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agodoc: refer to pathspec instead of path
Britton Leo Kerin [Wed, 3 Jan 2024 04:02:07 +0000 (19:02 -0900)] 
doc: refer to pathspec instead of path

Signed-off-by: Britton Leo Kerin <britton.kerin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agodoc: use singular form of repeatable path arg
Britton Leo Kerin [Wed, 3 Jan 2024 04:02:06 +0000 (19:02 -0900)] 
doc: use singular form of repeatable path arg

This is more correct because the <path>... doc syntax already indicates
that the arg is "array-type".  It's how other tools do it.  Finally, the
later document text mentions 'path' arguments, while it doesn't mention
'paths'.

Signed-off-by: Britton Leo Kerin <britton.kergin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot4129: prevent loss of exit code due to the use of pipes
Chandra Pratap [Wed, 10 Jan 2024 12:54:17 +0000 (12:54 +0000)] 
t4129: prevent loss of exit code due to the use of pipes

Piping the output of git commands like git-ls-files to another
command (grep in this case) hides the exit code returned by
these commands. Prevent this by storing the output of git-ls-files
to a temporary file and then "grep-ping" from that file. Replace
grep with test_grep as the latter is more verbose when it fails.

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agomingw: give more details about unsafe directory's ownership
Sören Krecker [Mon, 8 Jan 2024 17:38:37 +0000 (18:38 +0100)] 
mingw: give more details about unsafe directory's ownership

Add domain/username in error message, if owner sid of repository and
user sid are not equal on windows systems.

Old error message:
'''
fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git'
'C:/Users/test/source/repos/git' is owned by:
'S-1-5-21-571067702-4104414259-3379520149-500'
but the current user is:
'S-1-5-21-571067702-4104414259-3379520149-1001'
To add an exception for this directory, call:

git config --global --add safe.directory C:/Users/test/source/repos/git
'''

New error message:
'''
fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git'
'C:/Users/test/source/repos/git' is owned by:
        DESKTOP-L78JVA6/Administrator (S-1-5-21-571067702-4104414259-3379520149-500)
but the current user is:
        DESKTOP-L78JVA6/test (S-1-5-21-571067702-4104414259-3379520149-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory C:/Users/test/source/repos/git
'''

Signed-off-by: Sören Krecker <soekkle@freenet.de>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoThe sixth batch
Junio C Hamano [Mon, 8 Jan 2024 22:05:24 +0000 (14:05 -0800)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'rs/mem-pool-improvements'
Junio C Hamano [Mon, 8 Jan 2024 22:05:16 +0000 (14:05 -0800)] 
Merge branch 'rs/mem-pool-improvements'

MemPool allocator fixes.

* rs/mem-pool-improvements:
  mem-pool: simplify alignment calculation
  mem-pool: fix big allocations

4 months agoMerge branch 'rs/fast-import-simplify-mempool-allocation'
Junio C Hamano [Mon, 8 Jan 2024 22:05:16 +0000 (14:05 -0800)] 
Merge branch 'rs/fast-import-simplify-mempool-allocation'

Code simplification.

* rs/fast-import-simplify-mempool-allocation:
  fast-import: use mem_pool_calloc()

4 months agoMerge branch 'en/sparse-checkout-eoo'
Junio C Hamano [Mon, 8 Jan 2024 22:05:16 +0000 (14:05 -0800)] 
Merge branch 'en/sparse-checkout-eoo'

"git sparse-checkout (add|set) --[no-]cone --end-of-options" did
not handle "--end-of-options" correctly after a recent update.

* en/sparse-checkout-eoo:
  sparse-checkout: be consistent with end of options markers

4 months agoMerge branch 'jc/sparse-checkout-set-default-fix'
Junio C Hamano [Mon, 8 Jan 2024 22:05:16 +0000 (14:05 -0800)] 
Merge branch 'jc/sparse-checkout-set-default-fix'

"git sparse-checkout set" added default patterns even when the
patterns are being fed from the standard input, which has been
corrected.

* jc/sparse-checkout-set-default-fix:
  sparse-checkout: use default patterns for 'set' only !stdin

4 months agoMerge branch 'en/header-cleanup'
Junio C Hamano [Mon, 8 Jan 2024 22:05:15 +0000 (14:05 -0800)] 
Merge branch 'en/header-cleanup'

Remove unused header "#include".

* en/header-cleanup:
  treewide: remove unnecessary includes in source files
  treewide: add direct includes currently only pulled in transitively
  trace2/tr2_tls.h: remove unnecessary include
  submodule-config.h: remove unnecessary include
  pkt-line.h: remove unnecessary include
  line-log.h: remove unnecessary include
  http.h: remove unnecessary include
  fsmonitor--daemon.h: remove unnecessary includes
  blame.h: remove unnecessary includes
  archive.h: remove unnecessary include
  treewide: remove unnecessary includes in source files
  treewide: remove unnecessary includes from header files

4 months agoMerge branch 'ml/doc-merge-updates'
Junio C Hamano [Mon, 8 Jan 2024 22:05:15 +0000 (14:05 -0800)] 
Merge branch 'ml/doc-merge-updates'

Doc update.

* ml/doc-merge-updates:
  Documentation/git-merge.txt: use backticks for command wrapping
  Documentation/git-merge.txt: fix reference to synopsis

4 months agoMerge branch 'jc/archive-list-with-extra-args'
Junio C Hamano [Mon, 8 Jan 2024 22:05:14 +0000 (14:05 -0800)] 
Merge branch 'jc/archive-list-with-extra-args'

"git archive --list extra garbage" silently ignored excess command
line parameters, which has been corrected.

* jc/archive-list-with-extra-args:
  archive: "--list" does not take further options

4 months agofetch: add new config option fetch.all
Tamino Bauknecht [Mon, 8 Jan 2024 21:13:55 +0000 (22:13 +0100)] 
fetch: add new config option fetch.all

Introduce a boolean configuration option fetch.all which allows to
fetch all available remotes by default. The config option can be
overridden by explicitly specifying a remote or by using --no-all.
The behavior for --all is unchanged and calling git-fetch with --all
and a remote will still result in an error.

Additionally, describe the configuration variable in the config
documentation and implement new tests to cover the expected behavior.
Also add --no-all to the command-line documentation of git-fetch.

Signed-off-by: Tamino Bauknecht <dev@tb6.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoci: add job performing static analysis on GitLab CI
Patrick Steinhardt [Thu, 28 Dec 2023 11:02:50 +0000 (12:02 +0100)] 
ci: add job performing static analysis on GitLab CI

Our GitHub Workflows definitions have a static analysis job that
runs the following tasks:

  - Coccinelle to check for suggested refactorings.

  - `make hdr-check` to check for missing includes or forward
    declarations in our header files.

  - `make check-pot` to check our translations for issues.

  - `./ci/check-directional-formatting.bash` to check whether our
    sources contain any Unicode directional formatting code points.

Add an equivalent job to our GitLab CI definitions.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agogit-prompt: stop manually parsing HEAD with unknown ref formats
Patrick Steinhardt [Thu, 4 Jan 2024 08:21:53 +0000 (09:21 +0100)] 
git-prompt: stop manually parsing HEAD with unknown ref formats

We're manually parsing the HEAD reference in git-prompt to figure out
whether it is a symbolic or direct reference. This makes it intimately
tied to the on-disk format we use to store references and will stop
working once we gain additional reference backends in the Git project.

Ideally, we would refactor the code to exclusively use plumbing tools to
read refs such that we do not have to care about the on-disk format at
all. Unfortunately though, spawning processes can be quite expensive on
some systems like Windows. As the Git prompt logic may be executed quite
frequently we try very hard to spawn as few processes as possible. This
refactoring is thus out of question for now.

Instead, condition the logic on the repository's ref format: if the repo
uses the the "files" backend we can continue to use the old logic and
read the respective files from disk directly. If it's anything else,
then we use git-symbolic-ref(1) to read the value of HEAD.

This change makes the Git prompt compatible with the upcoming "reftable"
format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ps/refstorage-extension' into ps/prompt-parse-HEAD-futureproof
Junio C Hamano [Mon, 8 Jan 2024 19:21:18 +0000 (11:21 -0800)] 
Merge branch 'ps/refstorage-extension' into ps/prompt-parse-HEAD-futureproof

* ps/refstorage-extension:
  t9500: write "extensions.refstorage" into config
  builtin/clone: introduce `--ref-format=` value flag
  builtin/init: introduce `--ref-format=` value flag
  builtin/rev-parse: introduce `--show-ref-format` flag
  t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar
  setup: introduce GIT_DEFAULT_REF_FORMAT envvar
  setup: introduce "extensions.refStorage" extension
  setup: set repository's formats on init
  setup: start tracking ref storage format
  refs: refactor logic to look up storage backends
  worktree: skip reading HEAD when repairing worktrees
  t: introduce DEFAULT_REPO_FORMAT prereq

4 months agobranch: clarify <oldbranch> term
Rubén Justo [Sat, 6 Jan 2024 14:38:37 +0000 (15:38 +0100)] 
branch: clarify <oldbranch> term

Since 52d59cc645 (branch: add a --copy (-c) option to go with --move
(-m), 2017-06-18) <oldbranch> is used in more operations than just -m.

Let's also clarify what we do if <oldbranch> is omitted.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agorebase: clarify --reschedule-failed-exec default
Illia Bobyr [Fri, 5 Jan 2024 01:14:26 +0000 (17:14 -0800)] 
rebase: clarify --reschedule-failed-exec default

Documentation should mention the default behavior.

It is better to explain the persistent nature of the
--reschedule-failed-exec flag from the user standpoint, rather than from
the implementation standpoint.

Signed-off-by: Illia Bobyr <illia.bobyr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoindex-pack: spawn threads atomically
Jeff King [Fri, 5 Jan 2024 08:50:34 +0000 (03:50 -0500)] 
index-pack: spawn threads atomically

The t5309 script triggers a racy false positive with SANITIZE=leak on a
multi-core system. Running with "--stress --run=6" usually fails within
10 seconds or so for me, complaining with something like:

    + git index-pack --fix-thin --stdin
    fatal: REF_DELTA at offset 46 already resolved (duplicate base 01d7713666f4de822776c7622c10f1b07de280dc?)

    =================================================================
    ==3904583==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 32 byte(s) in 1 object(s) allocated from:
        #0 0x7fa790d01986 in __interceptor_realloc ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:98
        #1 0x7fa790add769 in __pthread_getattr_np nptl/pthread_getattr_np.c:180
        #2 0x7fa790d117c5 in __sanitizer::GetThreadStackTopAndBottom(bool, unsigned long*, unsigned long*) ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp:150
        #3 0x7fa790d11957 in __sanitizer::GetThreadStackAndTls(bool, unsigned long*, unsigned long*, unsigned long*, unsigned long*) ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp:598
        #4 0x7fa790d03fe8 in __lsan::ThreadStart(unsigned int, unsigned long long, __sanitizer::ThreadType) ../../../../src/libsanitizer/lsan/lsan_posix.cpp:51
        #5 0x7fa790d013fd in __lsan_thread_start_func ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:440
        #6 0x7fa790adc3eb in start_thread nptl/pthread_create.c:444
        #7 0x7fa790b5ca5b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

    SUMMARY: LeakSanitizer: 32 byte(s) leaked in 1 allocation(s).
    Aborted

What happens is this:

  0. We construct a bogus pack with a duplicate object in it and trigger
     index-pack.

  1. We spawn a bunch of worker threads to resolve deltas (on my system
     it is 16 threads).

  2. One of the threads sees the duplicate object and bails by calling
     exit(), taking down all of the threads. This is expected and is the
     point of the test.

  3. At the time exit() is called, we may still be spawning threads from
     the main process via pthread_create(). LSan hooks thread creation
     to update its book-keeping; it has to know where each thread's
     stack is (so it can find entry points for reachable memory). So it
     calls pthread_getattr_np() to get information about the new thread.
     That may allocate memory that must be freed with a matching call to
     pthread_attr_destroy(). Probably LSan does that immediately, but
     if you're unlucky enough, the exit() will happen while it's between
     those two calls, and the allocated pthread_attr_t appears as a
     leak.

This isn't a real leak. It's not even in our code, but rather in the
LSan instrumentation code. So we could just ignore it. But the false
positive can cause people to waste time tracking it down.

It's possibly something that LSan could protect against (e.g., cover the
getattr/destroy pair with a mutex, and then in the final post-exit()
check for leaks try to take the same mutex). But I don't know enough
about LSan to say if that's a reasonable approach or not (or if my
analysis is even completely correct).

In the meantime, it's pretty easy to avoid the race by making creation
of the worker threads "atomic". That is, we'll spawn all of them before
letting any of them start to work. That's easy to do because we already
have a work_lock() mutex for handing out that work. If the main process
takes it, then all of the threads will immediately block until we've
finished spawning and released it.

This shouldn't make any practical difference for non-LSan runs. The
thread spawning is quick, and could happen before any worker thread gets
scheduled anyway.

Probably other spots that use threads are subject to the same issues.
But since we have to manually insert locking (and since this really is
kind of a hack), let's not bother with them unless somebody experiences
a similar racy false-positive in practice.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agocommit-graph: retain commit slab when closing NULL commit_graph
Jeff King [Fri, 5 Jan 2024 05:41:42 +0000 (00:41 -0500)] 
commit-graph: retain commit slab when closing NULL commit_graph

This fixes a regression introduced in ac6d45d11f (commit-graph: move
slab-clearing to close_commit_graph(), 2023-10-03), in which running:

  git -c fetch.writeCommitGraph=true fetch --recurse-submodules

multiple times in a freshly cloned repository causes a segfault. What
happens in the second (and subsequent) runs is this:

  1. We make a "struct commit" for any ref tips which we're storing
     (even if we already have them, they still go into FETCH_HEAD).

     Because the first run will have created a commit graph, we'll find
     those commits in the graph.

     The commit struct is therefore created with a NULL "maybe_tree"
     entry, because we can load its oid from the graph later. But to do
     that we need to remember that we got the commit from the graph,
     which is recorded in a global commit_graph_data_slab object.

  2. Because we're using --recurse-submodules, we'll try to fetch each
     of the possible submodules. That implies creating a separate
     "struct repository" in-process for each submodule, which will
     require a later call to repo_clear().

     The call to repo_clear() calls raw_object_store_clear(), which in
     turn calls close_object_store(), which in turn calls
     close_commit_graph(). And the latter frees the commit graph data
     slab.

  3. Later, when trying to write out a new commit graph, we'll ask for
     their tree oid via get_commit_tree_oid(), which will see that the
     object is parsed but with a NULL maybe_tree field. We'd then
     usually pull it from the graph file, but because the slab was
     cleared, we don't realize that we can do so! We end up returning
     NULL and segfaulting.

     (It seems questionable that we'd write a graph entry for such a
     commit anyway, since we know we already have one. I didn't
     double-check, but that may simply be another side effect of having
     cleared the slab).

The bug is in step (2) above. We should not be clearing the slab when
cleaning up the submodule repository structs. Prior to ac6d45d11f, we
did not do so because it was done inside a helper function that returned
early when it saw NULL. So the behavior change from that commit is that
we'll now _always_ clear the slab via repo_clear(), even if the
repository being closed did not have a commit graph (and thus would have
a NULL commit_graph struct).

The most immediate fix is to add in a NULL check in close_commit_graph(),
making it a true noop when passed in an object_store with a NULL
commit_graph (it's OK to just return early, since the rest of its code
is already a noop when passed NULL). That restores the pre-ac6d45d11f
behavior. And that's what this patch does, along with a test that
exercises it (we already have a test that uses submodules along with
fetch.writeCommitGraph, but the bug only triggers when there is a
subsequent fetch and when that fetch uses --recurse-submodules).

So that fixes the regression in the least-risky way possible.

I do think there's some fragility here that we might want to follow up
on. We have a global commit_graph_data_slab that contains graph
positions, and our global commit structs depend on the that slab
remaining valid. But close_commit_graph() is just about closing _one_
object store's graph. So it's dangerous to call that function and clear
the slab without also throwing away any "struct commit" we might have
parsed that depends on it.

Which at first glance seems like a bug we could already trigger. In the
situation described here, there is no commit graph in the submodule
repository, so our commit graph is NULL (in fact, in our test script
there is no submodule repo at all, so we immediately return from
repo_init() and call repo_clear() only to free up memory). But what
would happen if there was one? Wouldn't we see a non-NULL commit_graph
entry, and then clear the global slab anyway?

The answer is "no", but for very bizarre reasons. Remember that
repo_clear() calls raw_object_store_clear(), which then calls
close_object_store() and thus close_commit_graph(). But before it does
so, raw_object_store_clear() does something else: it frees the commit
graph and sets it to NULL! So by this code path we'll _never_ see a
non-NULL commit_graph struct, and thus never clear the slab.

So it happens to work out. But it still seems questionable to me that we
would clear a global slab (which might still be in use) when closing the
commit graph. This clearing comes from 957ba814bf (commit-graph: when
closing the graph, also release the slab, 2021-09-08), and was fixing a
case where we really did need it to be closed (and in that case we
presumably call close_object_store() more directly).

So I suspect there may still be a bug waiting to happen there, as any
object loaded before the call to close_object_store() may be stranded
with a bogus maybe_tree entry (and thus looking at it after the call
might cause an error). But I'm not sure how to trigger it, nor what the
fix should look like (you probably would need to "unparse" any objects
pulled from the graph). And so this patch punts on that for now in favor
of fixing the recent regression in the most direct way, which should not
have any other fallouts.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agowrite-or-die: make GIT_FLUSH a Boolean environment variable
Chandra Pratap [Thu, 4 Jan 2024 10:20:17 +0000 (10:20 +0000)] 
write-or-die: make GIT_FLUSH a Boolean environment variable

Among Git's environment variables, the ones marked as "Boolean"
accept values in a way similar to Boolean configuration variables,
i.e. values like 'yes', 'on', 'true' and positive numbers are
taken as "on" and values like 'no', 'off', 'false' are taken as
"off".

GIT_FLUSH can be used to force Git to use non-buffered I/O when
writing to stdout. It can only accept two values, '1' which causes
Git to flush more often and '0' which makes all output buffered.
Make GIT_FLUSH accept more values besides '0' and '1' by turning it
into a Boolean environment variable, modifying the required logic.
Update the related documentation.

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoDocumentation: fix statement about rebase.instructionFormat
Maarten van der Schrieck [Wed, 3 Jan 2024 18:14:23 +0000 (18:14 +0000)] 
Documentation: fix statement about rebase.instructionFormat

Since commit 62db5247 (rebase -i: generate the script via
rebase--helper, 2017-07-14), the short hash is given in
rebase-todo. Specifying rebase.instructionFormat does not alter this
behavior, contrary to what the documentation implies.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/merged: transfer ownership of records when iterating
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:43 +0000 (07:22 +0100)] 
reftable/merged: transfer ownership of records when iterating

When iterating over records with the merged iterator we put the records
into a priority queue before yielding them to the caller. This means
that we need to allocate the contents of these records before we can
pass them over to the caller.

The handover to the caller is quite inefficient though because we first
deallocate the record passed in by the caller and then copy over the new
record, which requires us to reallocate memory.

Refactor the code to instead transfer ownership of the new record to the
caller. So instead of reallocating all contents, we now release the old
record and then copy contents of the new record into place.

The following benchmark of `git show-ref --quiet` in a repository with
around 350k refs shows a clear improvement. Before:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 708,058 allocs, 707,865 frees, 36,783,255 bytes allocated

After:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 357,007 allocs, 356,814 frees, 24,193,602 bytes allocated

This shows that we now have roundabout a single allocation per record
that we're yielding from the iterator. Ideally, we'd also get rid of
this allocation so that the number of allocations doesn't scale with the
number of refs anymore. This would require some larger surgery though
because the memory is owned by the priority queue before transferring it
over to the caller.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/merged: really reuse buffers to compute record keys
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:39 +0000 (07:22 +0100)] 
reftable/merged: really reuse buffers to compute record keys

In 829231dc20 (reftable/merged: reuse buffer to compute record keys,
2023-12-11), we have refactored the merged iterator to reuse a pair of
long-living strbufs by relying on the fact that `reftable_record_key()`
tries to reuse already allocated strbufs by calling `strbuf_reset()`,
which should give us significantly fewer reallocations compared to the
old code that used on-stack strbufs that are allocated for each and
every iteration. Unfortunately, we called `strbuf_release()` on these
long-living strbufs that we meant to reuse on each iteration, defeating
the optimization.

Fix this performance issue by not releasing those buffers on iteration
anymore, where we instead rely on `merged_iter_close()` to release the
buffers for us.

Using `git show-ref --quiet` in a repository with ~350k refs this leads
to a significant drop in allocations. Before:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 1,410,148 allocs, 1,409,955 frees, 61,976,068 bytes allocated

After:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 708,058 allocs, 707,865 frees, 36,783,255 bytes allocated

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: store "val2" hashes as static arrays
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:34 +0000 (07:22 +0100)] 
reftable/record: store "val2" hashes as static arrays

Similar to the preceding commit, convert ref records of type "val2" to
store their object IDs in static arrays instead of allocating them for
every single record.

We're using the same benchmark as in the preceding commit, with `git
show-ref --quiet` in a repository with ~350k refs. This time around
though the effects aren't this huge. Before:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 1,419,040 allocs, 1,418,847 frees, 62,153,868 bytes allocated

After:

    HEAP SUMMARY:
        in use at exit: 21,163 bytes in 193 blocks
      total heap usage: 1,410,148 allocs, 1,409,955 frees, 61,976,068 bytes allocated

This is because "val2"-type records are typically only stored for peeled
tags, and the number of annotated tags in the benchmark repository is
rather low. Still, it can be seen that this change leads to a reduction
of allocations overall, even if only a small one.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: store "val1" hashes as static arrays
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:30 +0000 (07:22 +0100)] 
reftable/record: store "val1" hashes as static arrays

When reading ref records of type "val1", we store its object ID in an
allocated array. This results in an additional allocation for every
single ref record we read, which is rather inefficient especially when
iterating over refs.

Refactor the code to instead use an embedded array of `GIT_MAX_RAWSZ`
bytes. While this means that `struct ref_record` is bigger now, we
typically do not store all refs in an array anyway and instead only
handle a limited number of records at the same point in time.

Using `git show-ref --quiet` in a repository with ~350k refs this leads
to a significant drop in allocations. Before:

    HEAP SUMMARY:
        in use at exit: 21,098 bytes in 192 blocks
      total heap usage: 2,116,683 allocs, 2,116,491 frees, 76,098,060 bytes allocated

After:

    HEAP SUMMARY:
        in use at exit: 21,098 bytes in 192 blocks
      total heap usage: 1,419,031 allocs, 1,418,839 frees, 62,145,036 bytes allocated

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: constify some parts of the interface
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:26 +0000 (07:22 +0100)] 
reftable/record: constify some parts of the interface

We're about to convert reftable records to stop storing their object IDs
as allocated hashes. Prepare for this refactoring by constifying some
parts of the interface that will be impacted by this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/writer: fix index corruption when writing multiple indices
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:21 +0000 (07:22 +0100)] 
reftable/writer: fix index corruption when writing multiple indices

Each reftable may contain multiple types of blocks for refs, objects and
reflog records, where each of these may have an index that makes it more
efficient to find the records. It was observed that the index for log
records can become corrupted under certain circumstances, where the
first entry of the index points into the object index instead of to the
log records.

As it turns out, this corruption can occur whenever we write a log index
as well as at least one additional index. Writing records and their index
is basically a two-step process:

  1. We write all blocks for the corresponding record. Each block that
     gets written is added to a list of blocks to index.

  2. Once all blocks were written we finish the section. If at least two
     blocks have been added to the list of blocks to index then we will
     now write the index for those blocks and flush it, as well.

When we have a very large number of blocks then we may decide to write a
multi-level index, which is why we also keep track of the list of the
index blocks in the same way as we previously kept track of the blocks
to index.

Now when we have finished writing all index blocks we clear the index
and flush the last block to disk. This is done in the wrong order though
because flushing the block to disk will re-add it to the list of blocks
to be indexed. The result is that the next section we are about to write
will have an entry in the list of blocks to index that points to the
last block of the preceding section's index, which will corrupt the log
index.

Fix this corruption by clearing the index after having written the last
block.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/stack: do not auto-compact twice in `reftable_stack_add()`
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:17 +0000 (07:22 +0100)] 
reftable/stack: do not auto-compact twice in `reftable_stack_add()`

In 5c086453ff (reftable/stack: perform auto-compaction with
transactional interface, 2023-12-11), we fixed a bug where the
transactional interface to add changes to a reftable stack did not
perform auto-compaction by calling `reftable_stack_auto_compact()` in
`reftable_stack_addition_commit()`. While correct, this change may now
cause us to perform auto-compaction twice in the non-transactional
interface `reftable_stack_add()`:

  - It performs auto-compaction by itself.

  - It now transitively performs auto-compaction via the transactional
    interface.

Remove the first instance so that we only end up doing auto-compaction
once.

Reported-by: Han-Wen Nienhuys <hanwenn@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/stack: do not overwrite errors when compacting
Patrick Steinhardt [Wed, 3 Jan 2024 06:22:13 +0000 (07:22 +0100)] 
reftable/stack: do not overwrite errors when compacting

In order to compact multiple stacks we iterate through the merged ref
and log records. When there is any error either when reading the records
from the old merged table or when writing the records to the new table
then we break out of the respective loops. When breaking out of the loop
for the ref records though the error code will be overwritten, which may
cause us to inadvertently skip over bad ref records. In the worst case,
this can lead to a compacted stack that is missing records.

Fix the code by using `goto done` instead so that any potential error
codes are properly returned to the caller.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot1006: prefer shell loop to awk for packed object sizes
René Scharfe [Wed, 3 Jan 2024 09:01:52 +0000 (04:01 -0500)] 
t1006: prefer shell loop to awk for packed object sizes

To compute the expected on-disk size of packed objects, we sort the
output of show-index by pack offset and then compute the difference
between adjacent entries using awk. This works but has a few readability
problems:

  1. Reading the index in pack order means don't find out the size of an
     oid's entry until we see the _next_ entry. So we have to save it to
     print later.

     We can instead iterate in reverse order, so we compute each oid's
     size as we see it.

  2. Since the awk invocation is inside a text_expect block, we can't
     easily use single-quotes to hold the script. So we use
     double-quotes, but then have to escape the dollar signs in the awk
     script.

     We can swap this out for a shell loop instead (which is made much
     easier by the first change).

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoThe fifth batch
Junio C Hamano [Tue, 2 Jan 2024 21:50:46 +0000 (13:50 -0800)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoMerge branch 'ps/pseudo-refs'
Junio C Hamano [Tue, 2 Jan 2024 21:51:30 +0000 (13:51 -0800)] 
Merge branch 'ps/pseudo-refs'

Assorted changes around pseudoref handling.

* ps/pseudo-refs:
  bisect: consistently write BISECT_EXPECTED_REV via the refdb
  refs: complete list of special refs
  refs: propagate errno when reading special refs fails
  wt-status: read HEAD and ORIG_HEAD via the refdb

5 months agoMerge branch 'jc/orphan-unborn'
Junio C Hamano [Tue, 2 Jan 2024 21:51:30 +0000 (13:51 -0800)] 
Merge branch 'jc/orphan-unborn'

Doc updates to clarify what an "unborn branch" means.

* jc/orphan-unborn:
  orphan/unborn: fix use of 'orphan' in end-user facing messages
  orphan/unborn: add to the glossary and use them consistently

5 months agoMerge branch 'rj/status-bisect-while-rebase'
Junio C Hamano [Tue, 2 Jan 2024 21:51:29 +0000 (13:51 -0800)] 
Merge branch 'rj/status-bisect-while-rebase'

"git status" is taught to show both the branch being bisected and
being rebased when both are in effect at the same time.

* rj/status-bisect-while-rebase:
  status: fix branch shown when not only bisecting

5 months agoMerge branch 'la/trailer-cleanups'
Junio C Hamano [Tue, 2 Jan 2024 21:51:29 +0000 (13:51 -0800)] 
Merge branch 'la/trailer-cleanups'

Code clean-up.

* la/trailer-cleanups:
  trailer: use offsets for trailer_start/trailer_end
  trailer: find the end of the log message
  commit: ignore_non_trailer computes number of bytes to ignore

5 months agoMerge branch 'jc/retire-cas-opt-name-constant'
Junio C Hamano [Tue, 2 Jan 2024 21:51:29 +0000 (13:51 -0800)] 
Merge branch 'jc/retire-cas-opt-name-constant'

Code clean-up.

* jc/retire-cas-opt-name-constant:
  remote.h: retire CAS_OPT_NAME

5 months agoMerge branch 'rs/rebase-use-strvec-pushf'
Junio C Hamano [Tue, 2 Jan 2024 21:51:29 +0000 (13:51 -0800)] 
Merge branch 'rs/rebase-use-strvec-pushf'

Code clean-up.

* rs/rebase-use-strvec-pushf:
  rebase: use strvec_pushf() for format-patch revisions

5 months agoMerge branch 'sh/completion-with-reftable'
Junio C Hamano [Tue, 2 Jan 2024 21:51:28 +0000 (13:51 -0800)] 
Merge branch 'sh/completion-with-reftable'

Command line completion script (in contrib/) learned to work better
with the reftable backend.

* sh/completion-with-reftable:
  completion: support pseudoref existence checks for reftables
  completion: refactor existence checks for pseudorefs

5 months agot9500: write "extensions.refstorage" into config
Patrick Steinhardt [Fri, 29 Dec 2023 07:27:13 +0000 (08:27 +0100)] 
t9500: write "extensions.refstorage" into config

In t9500 we're writing a custom configuration that sets up gitweb. This
requires us to manually ensure that the repository format is configured
as required, including both the repository format version and
extensions. With the introduction of the "extensions.refStorage"
extension we need to update the test to also write this new one.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agobuiltin/clone: introduce `--ref-format=` value flag
Patrick Steinhardt [Fri, 29 Dec 2023 07:27:09 +0000 (08:27 +0100)] 
builtin/clone: introduce `--ref-format=` value flag

Introduce a new `--ref-format` value flag for git-clone(1) that allows
the user to specify the ref format that is to be used for a newly
initialized repository.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agobuiltin/init: introduce `--ref-format=` value flag
Patrick Steinhardt [Fri, 29 Dec 2023 07:27:04 +0000 (08:27 +0100)] 
builtin/init: introduce `--ref-format=` value flag

Introduce a new `--ref-format` value flag for git-init(1) that allows
the user to specify the ref format that is to be used for a newly
initialized repository.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agobuiltin/rev-parse: introduce `--show-ref-format` flag
Patrick Steinhardt [Fri, 29 Dec 2023 07:27:00 +0000 (08:27 +0100)] 
builtin/rev-parse: introduce `--show-ref-format` flag

Introduce a new `--show-ref-format` to git-rev-parse(1) that causes it
to print the ref format used by a repository.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agot: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:56 +0000 (08:26 +0100)] 
t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar

Introduce a new GIT_TEST_DEFAULT_REF_FORMAT environment variable that
lets developers run the test suite with a different default ref format
without impacting the ref format used by non-test Git invocations. This
is modeled after GIT_TEST_DEFAULT_OBJECT_FORMAT, which does the same
thing for the repository's object format.

Adapt the setup of the `REFFILES` test prerequisite to be conditionally
set based on the default ref format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agosetup: introduce GIT_DEFAULT_REF_FORMAT envvar
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:52 +0000 (08:26 +0100)] 
setup: introduce GIT_DEFAULT_REF_FORMAT envvar

Introduce a new GIT_DEFAULT_REF_FORMAT environment variable that lets
users control the default ref format used by both git-init(1) and
git-clone(1). This is modeled after GIT_DEFAULT_OBJECT_FORMAT, which
does the same thing for the repository's object format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agosetup: introduce "extensions.refStorage" extension
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:47 +0000 (08:26 +0100)] 
setup: introduce "extensions.refStorage" extension

Introduce a new "extensions.refStorage" extension that allows us to
specify the ref storage format used by a repository. For now, the only
supported format is the "files" format, but this list will likely soon
be extended to also support the upcoming "reftable" format.

There have been discussions on the Git mailing list in the past around
how exactly this extension should look like. One alternative [1] that
was discussed was whether it would make sense to model the extension in
such a way that backends are arbitrarily stackable. This would allow for
a combined value of e.g. "loose,packed-refs" or "loose,reftable", which
indicates that new refs would be written via "loose" files backend and
compressed into "packed-refs" or "reftable" backends, respectively.

It is arguable though whether this flexibility and the complexity that
it brings with it is really required for now. It is not foreseeable that
there will be a proliferation of backends in the near-term future, and
the current set of existing formats and formats which are on the horizon
can easily be configured with the much simpler proposal where we have a
single value, only.

Furthermore, if we ever see that we indeed want to gain the ability to
arbitrarily stack the ref formats, then we can adapt the current
extension rather easily. Given that Git clients will refuse any unknown
value for the "extensions.refStorage" extension they would also know to
ignore a stacked "loose,packed-refs" in the future.

So let's stick with the easy proposal for the time being and wire up the
extension.

[1]: <pull.1408.git.1667846164.gitgitgadget@gmail.com>

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agosetup: set repository's formats on init
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:43 +0000 (08:26 +0100)] 
setup: set repository's formats on init

The proper hash algorithm and ref storage format that will be used for a
newly initialized repository will be figured out in `init_db()` via
`validate_hash_algorithm()` and `validate_ref_storage_format()`. Until
now though, we never set up the hash algorithm or ref storage format of
`the_repository` accordingly.

There are only two callsites of `init_db()`, one in git-init(1) and one
in git-clone(1). The former function doesn't care for the formats to be
set up properly because it never access the repository after calling the
function in the first place.

For git-clone(1) it's a different story though, as we call `init_db()`
before listing remote refs. While we do indeed have the wrong hash
function in `the_repository` when `init_db()` sets up a non-default
object format for the repository, it never mattered because we adjust
the hash after learning about the remote's hash function via the listed
refs.

So the current state is correct for the hash algo, but it's not for the
ref storage format because git-clone(1) wouldn't know to set it up
properly. But instead of adjusting only the `ref_storage_format`, set
both the hash algo and the ref storage format so that `the_repository`
is in the correct state when `init_db()` exits. This is fine as we will
adjust the hash later on anyway and makes it easier to reason about the
end state of `the_repository`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agosetup: start tracking ref storage format
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:39 +0000 (08:26 +0100)] 
setup: start tracking ref storage format

In order to discern which ref storage format a repository is supposed to
use we need to start setting up and/or discovering the format. This
needs to happen in two separate code paths.

  - The first path is when we create a repository via `init_db()`. When
    we are re-initializing a preexisting repository we need to retain
    the previously used ref storage format -- if the user asked for a
    different format then this indicates an error and we error out.
    Otherwise we either initialize the repository with the format asked
    for by the user or the default format, which currently is the
    "files" backend.

  - The second path is when discovering repositories, where we need to
    read the config of that repository. There is not yet any way to
    configure something other than the "files" backend, so we can just
    blindly set the ref storage format to this backend.

Wire up this logic so that we have the ref storage format always readily
available when needed. As there is only a single backend and because it
is not configurable we cannot yet verify that this tracking works as
expected via tests, but tests will be added in subsequent commits. To
countermand this ommission now though, raise a BUG() in case the ref
storage format is not set up properly in `ref_store_init()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agorefs: refactor logic to look up storage backends
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:34 +0000 (08:26 +0100)] 
refs: refactor logic to look up storage backends

In order to look up ref storage backends, we're currently using a linked
list of backends, where each backend is expected to set up its `next`
pointer to the next ref storage backend. This is kind of a weird setup
as backends need to be aware of other backends without much of a reason.

Refactor the code so that the array of backends is centrally defined in
"refs.c", where each backend is now identified by an integer constant.
Expose functions to translate from those integer constants to the name
and vice versa, which will be required by subsequent patches.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoworktree: skip reading HEAD when repairing worktrees
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:30 +0000 (08:26 +0100)] 
worktree: skip reading HEAD when repairing worktrees

When calling `git init --separate-git-dir=<new-path>` on a preexisting
repository, we move the Git directory of that repository to the new path
specified by the user. If there are worktrees present in the repository,
we need to repair the worktrees so that their gitlinks point to the new
location of the repository.

This repair logic will load repositories via `get_worktrees()`, which
will enumerate up and initialize all worktrees. Part of initialization
is logic that we resolve their respective worktree HEADs, even though
that information may not actually be needed in the end by all callers.

Although not a problem presently with the file-based reference backend,
it will become a problem with the upcoming reftable backend. In the
context of git-init(1) we do not have a fully-initialized repository set
up via `setup_git_directory()` or friends. Consequently, we do not know
about the repository format when `repair_worktrees()` is called, and
properly setting up all parts of the repositroy in `init_db()` before we
try to repair worktrees is not an easy task. With the introduction of
the reftable backend, we would ultimately try to look up the worktree
HEADs before we have figured out the reference format, which does not
work.

We do not require the worktree HEADs at all to repair worktrees. So
let's fix this issue by skipping over the step that reads them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agot: introduce DEFAULT_REPO_FORMAT prereq
Patrick Steinhardt [Fri, 29 Dec 2023 07:26:26 +0000 (08:26 +0100)] 
t: introduce DEFAULT_REPO_FORMAT prereq

A limited number of tests require repositories to have the default
repository format or otherwise they would fail to run, e.g. because they
fail to detect the correct hash function. While the hash function is the
only extension right now that creates problems like this, we are about
to add a second extension for the ref format.

Introduce a new DEFAULT_REPO_FORMAT prereq that can easily be amended
whenever we add new format extensions. Next to making any such changes
easier on us, the prerequisite's name should also help to clarify the
intent better.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoattr: add builtin objectmode values support
Joanna Wang [Thu, 16 Nov 2023 05:44:37 +0000 (05:44 +0000)] 
attr: add builtin objectmode values support

Gives all paths builtin objectmode values based on the paths' modes
(one of 100644, 100755, 120000, 040000, 160000). Users may use
this feature to filter by file types. For example a pathspec such as
':(attr:builtin_objectmode=160000)' could filter for submodules without
needing to have `builtin_objectmode=160000` to be set in .gitattributes
for every submodule path.

These values are also reflected in `git check-attr` results.
If the git_attr_direction is set to GIT_ATTR_INDEX or GIT_ATTR_CHECKIN
and a path is not found in the index, the value will be unspecified.

This patch also reserves the builtin_* attribute namespace for objectmode
and any future builtin attributes. Any user defined attributes using this
reserved namespace will result in a warning. This is a breaking change for
any existing builtin_* attributes.
Pathspecs with some builtin_* attribute name (excluding builtin_objectmode)
will behave like any attribute where there are no user specified values.

Signed-off-by: Joanna Wang <jojwang@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agomem-pool: simplify alignment calculation
René Scharfe [Sun, 24 Dec 2023 17:02:04 +0000 (18:02 +0100)] 
mem-pool: simplify alignment calculation

Use DIV_ROUND_UP in mem_pool_alloc() to round the allocation length to
the next multiple of GIT_MAX_ALIGNMENT instead of twiddling bits
explicitly.  This is shorter and clearer, to the point that we no longer
need the comment that explains what's being calculated.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agomem-pool: fix big allocations
René Scharfe [Thu, 28 Dec 2023 19:19:06 +0000 (20:19 +0100)] 
mem-pool: fix big allocations

Memory pool allocations that require a new block and would fill at
least half of it are handled specially.  Before 158dfeff3d (mem-pool:
add life cycle management functions, 2018-07-02) they used to be
allocated outside of the pool.  This patch made mem_pool_alloc() create
a bespoke block instead, to allow releasing it when the pool gets
discarded.

Unfortunately mem_pool_alloc() returns a pointer to the start of such a
bespoke block, i.e. to the struct mp_block at its top.  When the caller
writes to it, the management information gets corrupted.  This affects
mem_pool_discard() and -- if there are no other blocks in the pool --
also mem_pool_alloc().

Return the payload pointer of bespoke blocks, just like for smaller
allocations, to protect the management struct.

Also update next_free to mark the block as full.  This is only strictly
necessary for the first allocated block, because subsequent ones are
inserted after the current block and never considered for further
allocations, but it's easier to just do it in all cases.

Add a basic unit test to demonstrate the issue by using
mem_pool_calloc() with a tiny block size, which forces the creation of a
bespoke block.

Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agosideband.c: remove redundant 'NEEDSWORK' tag
Chandra Pratap [Thu, 28 Dec 2023 08:01:00 +0000 (08:01 +0000)] 
sideband.c: remove redundant 'NEEDSWORK' tag

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: hyphenate non-ASCII
Josh Soref [Thu, 28 Dec 2023 04:55:24 +0000 (04:55 +0000)] 
SubmittingPatches: hyphenate non-ASCII

Git documentation does this with the exception of ancient release notes.

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: clarify GitHub artifact format
Josh Soref [Thu, 28 Dec 2023 04:55:23 +0000 (04:55 +0000)] 
SubmittingPatches: clarify GitHub artifact format

GitHub wraps artifacts generated by workflows in a .zip file.

Internally, workflows can package anything they like in them.

A recently generated failure artifact had the form:

windows-artifacts.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
 76001695  12-19-2023 01:35   artifacts.tar.gz
 11005650  12-19-2023 01:35   tracked.tar.gz
---------                     -------
 87007345                     2 files

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: clarify GitHub visual
Josh Soref [Thu, 28 Dec 2023 04:55:22 +0000 (04:55 +0000)] 
SubmittingPatches: clarify GitHub visual

GitHub has two general forms for its states, sometimes they're a simple
colored object (e.g. green check or red x), and sometimes there's also a
colored container (e.g. green box or red circle) which contains that
object (e.g. check or x).

That's a lot of words to try to describe things, but in general, the key
for a failure is that it's recognized as an `x` and that it's associated
with the color red -- the color of course is problematic for people who
are red-green color-blind, but that's why they are paired with distinct
shapes.

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: provide tag naming advice
Josh Soref [Thu, 28 Dec 2023 04:55:21 +0000 (04:55 +0000)] 
SubmittingPatches: provide tag naming advice

Current statistics show a strong preference to only capitalize the first
letter in a hyphenated tag, but that some guidance would be helpful:

git log |
  perl -ne 'next unless /^\s+(?:Signed-[oO]ff|Acked)-[bB]y:/;
    s/^\s+//;s/:.*/:/;print'|
  sort|uniq -c|sort -n
   2 Signed-off-By:
   4 Signed-Off-by:
  22 Acked-By:
  47 Signed-Off-By:
2202 Acked-by:
95315 Signed-off-by:

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: update extra tags list
Josh Soref [Thu, 28 Dec 2023 04:55:20 +0000 (04:55 +0000)] 
SubmittingPatches: update extra tags list

Add items with at least 100 uses in the past three years:
- Co-authored-by
- Helped-by
- Mentored-by
- Suggested-by

git log --since=3.years|
  perl -ne 'next unless /^\s+[A-Z][a-z]+-\S+:/;s/^\s+//;s/:.*/:/;print'|
  sort|uniq -c|sort -n|grep '[0-9][0-9] '
  14 Based-on-patch-by:
  14 Original-patch-by:
  17 Tested-by:
 100 Suggested-by:
 121 Co-authored-by:
 163 Mentored-by:
 274 Reported-by:
 290 Acked-by:
 450 Helped-by:
 602 Reviewed-by:
14111 Signed-off-by:

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: discourage new trailers
Josh Soref [Thu, 28 Dec 2023 04:55:19 +0000 (04:55 +0000)] 
SubmittingPatches: discourage new trailers

There seems to be consensus amongst the core Git community on a working
set of common trailers, and there are non-trivial costs to people
inventing new trailers (research to discover what they mean/how they
differ from existing trailers) such that inventing new ones is generally
unwarranted and not something to be recommended to new contributors.

Suggested-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoSubmittingPatches: drop ref to "What's in git.git"
Josh Soref [Thu, 28 Dec 2023 04:55:18 +0000 (04:55 +0000)] 
SubmittingPatches: drop ref to "What's in git.git"

"What's in git.git" was last seen in 2010:
  https://lore.kernel.org/git/?q=%22what%27s+in+git.git%22
  https://lore.kernel.org/git/7vaavikg72.fsf@alter.siamese.dyndns.org/

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoCodingGuidelines: write punctuation marks
Josh Soref [Thu, 28 Dec 2023 04:55:17 +0000 (04:55 +0000)] 
CodingGuidelines: write punctuation marks

- Match style in Release Notes

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoCodingGuidelines: move period inside parentheses
Josh Soref [Thu, 28 Dec 2023 04:55:16 +0000 (04:55 +0000)] 
CodingGuidelines: move period inside parentheses

The contents within parenthesis should be omittable without resulting
in broken text.

Eliding the parenthesis left a period to end a run without any content.

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoThe fourth batch
Junio C Hamano [Wed, 27 Dec 2023 22:51:46 +0000 (14:51 -0800)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
5 months agoMerge branch 'ps/clone-into-reftable-repository'
Junio C Hamano [Wed, 27 Dec 2023 22:52:28 +0000 (14:52 -0800)] 
Merge branch 'ps/clone-into-reftable-repository'

"git clone" has been prepared to allow cloning a repository with
non-default hash function into a repository that uses the reftable
backend.

* ps/clone-into-reftable-repository:
  builtin/clone: create the refdb with the correct object format
  builtin/clone: skip reading HEAD when retrieving remote
  builtin/clone: set up sparse checkout later
  builtin/clone: fix bundle URIs with mismatching object formats
  remote-curl: rediscover repository when fetching refs
  setup: allow skipping creation of the refdb
  setup: extract function to create the refdb

5 months agoMerge branch 'rs/t6300-compressed-size-fix'
Junio C Hamano [Wed, 27 Dec 2023 22:52:27 +0000 (14:52 -0800)] 
Merge branch 'rs/t6300-compressed-size-fix'

Test fix.

* rs/t6300-compressed-size-fix:
  t6300: avoid hard-coding object sizes

5 months agoMerge branch 'jx/fetch-atomic-error-message-fix'
Junio C Hamano [Wed, 27 Dec 2023 22:52:27 +0000 (14:52 -0800)] 
Merge branch 'jx/fetch-atomic-error-message-fix'

"git fetch --atomic" issued an unnecessary empty error message,
which has been corrected.

* jx/fetch-atomic-error-message-fix:
  fetch: no redundant error message for atomic fetch
  t5574: test porcelain output of atomic fetch

5 months agoMerge branch 'rs/c99-stdbool-test-balloon'
Junio C Hamano [Wed, 27 Dec 2023 22:52:27 +0000 (14:52 -0800)] 
Merge branch 'rs/c99-stdbool-test-balloon'

Test balloon to use C99 "bool" type from <stdbool.h>.

* rs/c99-stdbool-test-balloon:
  git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool

5 months agoMerge branch 'sp/test-i18ngrep'
Junio C Hamano [Wed, 27 Dec 2023 22:52:27 +0000 (14:52 -0800)] 
Merge branch 'sp/test-i18ngrep'

Error message fix in the test framework.

* sp/test-i18ngrep:
  test-lib-functions.sh: fix test_grep fail message wording

5 months agoMerge branch 'jc/doc-misspelt-refs-fix'
Junio C Hamano [Wed, 27 Dec 2023 22:52:26 +0000 (14:52 -0800)] 
Merge branch 'jc/doc-misspelt-refs-fix'

Doc update.

* jc/doc-misspelt-refs-fix:
  doc: format.notes specify a ref under refs/notes/ hierarchy

5 months agoMerge branch 'jc/doc-most-refs-are-not-that-special'
Junio C Hamano [Wed, 27 Dec 2023 22:52:26 +0000 (14:52 -0800)] 
Merge branch 'jc/doc-most-refs-are-not-that-special'

Doc updates.

* jc/doc-most-refs-are-not-that-special:
  docs: MERGE_AUTOSTASH is not that special
  docs: AUTO_MERGE is not that special
  refs.h: HEAD is not that special
  git-bisect.txt: BISECT_HEAD is not that special
  git.txt: HEAD is not that special

5 months agoMerge branch 'es/add-doc-list-short-form-of-all-in-synopsis'
Junio C Hamano [Wed, 27 Dec 2023 22:52:26 +0000 (14:52 -0800)] 
Merge branch 'es/add-doc-list-short-form-of-all-in-synopsis'

Doc update.

* es/add-doc-list-short-form-of-all-in-synopsis:
  git-add.txt: add missing short option -A to synopsis

5 months agoMerge branch 'jk/mailinfo-iterative-unquote-comment'
Junio C Hamano [Wed, 27 Dec 2023 22:52:26 +0000 (14:52 -0800)] 
Merge branch 'jk/mailinfo-iterative-unquote-comment'

The code to parse the From e-mail header has been updated to avoid
recursion.

* jk/mailinfo-iterative-unquote-comment:
  mailinfo: avoid recursion when unquoting From headers
  t5100: make rfc822 comment test more careful