]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
10 months agounit-tests: ignore unused argc/argv
Jeff King [Sat, 17 Aug 2024 08:23:09 +0000 (04:23 -0400)] 
unit-tests: ignore unused argc/argv

All of the unit test programs have their own cmd_main() function, but
none of them actually look at the argc/argv that is passed in.

In the long run we may want them to handle options for the test harness.
But we'd probably do that with a shared harness cmd_main(), dispatching
to the individual tests. In the meantime, let's annotate the unused
parameters to avoid triggering -Wunused-parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot/helper: mark more unused argv/argc arguments
Jeff King [Sat, 17 Aug 2024 08:22:52 +0000 (04:22 -0400)] 
t/helper: mark more unused argv/argc arguments

This is a continuation of 126e3b3d2a (t/helper: mark unused argv/argc
arguments, 2023-03-28) to cover a few new cases:

 - test-example-tap was added since that commit

 - test-hashmap used to accept the "ignorecase" argument on the command
   line. But since most of its logic was moved to a unit-test in
   3469a23659 (t: port helper/test-hashmap.c to unit-tests/t-hashmap.c,
   2024-08-03), it now ignores its argv entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agooss-fuzz: mark unused argv/argc argument
Jeff King [Sat, 17 Aug 2024 08:22:38 +0000 (04:22 -0400)] 
oss-fuzz: mark unused argv/argc argument

The dummy fuzz cmd_main() does not look at its argc/argv parameters
(since it should never even be run), but has to match the usual
cmd_main() declaration.

Mark them to silence -Wunused-parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: mark unused parameters in do_for_each_reflog_helper()
Jeff King [Sat, 17 Aug 2024 08:22:22 +0000 (04:22 -0400)] 
refs: mark unused parameters in do_for_each_reflog_helper()

This is an each_ref_fn callback, so it has to match that interface. We
marked most of these in 63e14ee2d6 (refs: mark unused each_ref_fn
parameters, 2022-08-19), but in this case:

  - this function was created in 31f898397b (refs: drop unused params
    from the reflog iterator callback, 2024-02-21), and most of the
    arguments were correctly mark as UNUSED, but "flags" was missed.

  - commit e8207717f1 (refs: add referent to each_ref_fn, 2024-08-09)
    added a new argument to the each_ref_fn callback. In most callbacks
    it added an UNUSED annotation, but it missed one case.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: mark unused parameters in ref_store fsck callbacks
Jeff King [Sat, 17 Aug 2024 08:22:05 +0000 (04:22 -0400)] 
refs: mark unused parameters in ref_store fsck callbacks

Commit ab6f79d8df (refs: set up ref consistency check infrastructure,
2024-08-08) added virtual functions to the ref store for doing fsck
checks. But the packed and reftable backends do not yet do anything.

Let's annotate them to silence -Wunused-parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoupdate-ref: mark more unused parameters in parser callbacks
Jeff King [Sat, 17 Aug 2024 08:21:57 +0000 (04:21 -0400)] 
update-ref: mark more unused parameters in parser callbacks

This is a continuation of 44ad082968 (update-ref: mark unused parameter
in parser callbacks, 2023-08-29), as we've grown a few more virtual
functions since then.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoimap-send: mark unused parameter in ssl_socket_connect() fallback
Jeff King [Sat, 17 Aug 2024 08:21:27 +0000 (04:21 -0400)] 
imap-send: mark unused parameter in ssl_socket_connect() fallback

Commit cea1ff7f1f (imap-send: drop global `imap_server_conf` variable,
2024-06-07) added an imap_server_conf parameter to several functions.
But when compiled with NO_OPENSSL, the ssl_socket_connect() fallback
just returns immediately, so its parameters all need to be annotated to
avoid triggering -Wunused-parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoSync with 'maint'
Junio C Hamano [Fri, 16 Aug 2024 19:53:18 +0000 (12:53 -0700)] 
Sync with 'maint'

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoPrepare for 2.46.1
Junio C Hamano [Wed, 14 Aug 2024 22:02:29 +0000 (15:02 -0700)] 
Prepare for 2.46.1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'sj/ref-fsck'
Junio C Hamano [Fri, 16 Aug 2024 19:51:51 +0000 (12:51 -0700)] 
Merge branch 'sj/ref-fsck'

"git fsck" infrastructure has been taught to also check the sanity
of the ref database, in addition to the object database.

* sj/ref-fsck:
  fsck: add ref name check for files backend
  files-backend: add unified interface for refs scanning
  builtin/refs: add verify subcommand
  refs: set up ref consistency check infrastructure
  fsck: add refs report function
  fsck: add a unified interface for reporting fsck messages
  fsck: make "fsck_error" callback generic
  fsck: rename objects-related fsck error functions
  fsck: rename "skiplist" to "skip_oids"

10 months agoMerge branch 'ps/p4-tests-updates' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:56 +0000 (12:50 -0700)] 
Merge branch 'ps/p4-tests-updates' into maint-2.46

Perforce tests have been updated.
cf. <na5mwletzpnacietbc7pzqcgb622mvrwgrkjgjosysz3gvjcso@gzxxi7d7icr7>

* ps/p4-tests-updates:
  t98xx: mark Perforce tests as memory-leak free
  ci: update Perforce version to r23.2
  t98xx: fix Perforce tests with p4d r23 and newer

10 months agoMerge branch 'ks/unit-test-comment-typofix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:56 +0000 (12:50 -0700)] 
Merge branch 'ks/unit-test-comment-typofix' into maint-2.46

Typofix.

* ks/unit-test-comment-typofix:
  unit-tests/test-lib: fix typo in check_pointer_eq() description

10 months agoMerge branch 'dh/encoding-trace-optim' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:55 +0000 (12:50 -0700)] 
Merge branch 'dh/encoding-trace-optim' into maint-2.46

An expensive operation to prepare tracing was done in re-encoding
code path even when the tracing was not requested, which has been
corrected.

* dh/encoding-trace-optim:
  convert: return early when not tracing

10 months agoMerge branch 'dd/notes-empty-no-edit-by-default' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:55 +0000 (12:50 -0700)] 
Merge branch 'dd/notes-empty-no-edit-by-default' into maint-2.46

"git notes add -m '' --allow-empty" and friends that take prepared
data to create notes should not invoke an editor, but it started
doing so since Git 2.42, which has been corrected.

* dd/notes-empty-no-edit-by-default:
  notes: do not trigger editor when adding an empty note

10 months agoMerge branch 'jc/doc-rebase-fuzz-vs-offset-fix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:54 +0000 (12:50 -0700)] 
Merge branch 'jc/doc-rebase-fuzz-vs-offset-fix' into maint-2.46

"git rebase --help" referred to "offset" (the difference between
the location a change was taken from and the change gets replaced)
incorrectly and called it "fuzz", which has been corrected.

* jc/doc-rebase-fuzz-vs-offset-fix:
  doc: difference in location to apply is "offset", not "fuzz"

10 months agoMerge branch 'tn/doc-commit-fix' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:54 +0000 (12:50 -0700)] 
Merge branch 'tn/doc-commit-fix' into maint-2.46

Docfix.

* tn/doc-commit-fix:
  doc: remove dangling closing parenthesis

10 months agoMerge branch 'pw/add-patch-with-suppress-blank-empty' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:53 +0000 (12:50 -0700)] 
Merge branch 'pw/add-patch-with-suppress-blank-empty' into maint-2.46

"git add -p" by users with diff.suppressBlankEmpty set to true
failed to parse the patch that represents an unmodified empty line
with an empty line (not a line with a single space on it), which
has been corrected.

* pw/add-patch-with-suppress-blank-empty:
  add-patch: use normalize_marker() when recounting edited hunk
  add-patch: handle splitting hunks with diff.suppressBlankEmpty

10 months agoMerge branch 'jt/doc-post-receive-hook-update' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:53 +0000 (12:50 -0700)] 
Merge branch 'jt/doc-post-receive-hook-update' into maint-2.46

Doc update.

* jt/doc-post-receive-hook-update:
  doc: clarify post-receive hook behavior

10 months agoMerge branch 'jc/how-to-maintain-updates' (early part) into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:52 +0000 (12:50 -0700)] 
Merge branch 'jc/how-to-maintain-updates' (early part) into maint-2.46

* 'jc/how-to-maintain-updates' (early part):
  howto-maintain: update daily tasks
  howto-maintain: cover a whole development cycle

10 months agoMerge branch 'jc/doc-one-shot-export-with-shell-func' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:51 +0000 (12:50 -0700)] 
Merge branch 'jc/doc-one-shot-export-with-shell-func' into maint-2.46

It has been documented that we avoid "VAR=VAL shell_func" and why.

* jc/doc-one-shot-export-with-shell-func:
  CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func"

10 months agoMerge branch 'jc/checkout-no-op-switch-errors' into maint-2.46
Junio C Hamano [Fri, 16 Aug 2024 19:50:51 +0000 (12:50 -0700)] 
Merge branch 'jc/checkout-no-op-switch-errors' into maint-2.46

"git checkout --ours" (no other arguments) complained that the
option is incompatible with branch switching, which is technically
correct, but found confusing by some users.  It now says that the
user needs to give pathspec to specify what paths to checkout.

* jc/checkout-no-op-switch-errors:
  checkout: special case error messages during noop switching

10 months agoThe fifth batch
Junio C Hamano [Thu, 15 Aug 2024 20:21:43 +0000 (13:21 -0700)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'xx/diff-tree-remerge-diff-fix'
Junio C Hamano [Thu, 15 Aug 2024 20:22:16 +0000 (13:22 -0700)] 
Merge branch 'xx/diff-tree-remerge-diff-fix'

"git rev-list ... | git diff-tree -p --remerge-diff --stdin" should
behave more or less like "git log -p --remerge-diff" but instead it
crashed, forgetting to prepare a temporary object store needed.

* xx/diff-tree-remerge-diff-fix:
  diff-tree: fix crash when used with --remerge-diff

10 months agoMerge branch 'jc/refs-symref-referent'
Junio C Hamano [Thu, 15 Aug 2024 20:22:15 +0000 (13:22 -0700)] 
Merge branch 'jc/refs-symref-referent'

The refs API has been taught to give symref target information to
the users of ref iterators, allowing for-each-ref and friends to
avoid an extra ref_resolve_* API call per a symbolic ref.

* jc/refs-symref-referent:
  ref-filter: populate symref from iterator
  refs: add referent to each_ref_fn
  refs: keep track of unresolved reference value in iterators

10 months agoMerge branch 'ps/submodule-ref-format'
Junio C Hamano [Thu, 15 Aug 2024 20:22:14 +0000 (13:22 -0700)] 
Merge branch 'ps/submodule-ref-format'

Support to specify ref backend for submodules has been enhanced.

* ps/submodule-ref-format:
  object: fix leaking packfiles when closing object store
  submodule: fix leaking seen submodule names
  submodule: fix leaking fetch tasks
  builtin/submodule: allow "add" to use different ref storage format
  refs: fix ref storage format for submodule ref stores
  builtin/clone: propagate ref storage format to submodules
  builtin/submodule: allow cloning with different ref storage format
  git-submodule.sh: break overly long command lines

10 months agoMerge branch 'ag/t7004-modernize'
Junio C Hamano [Thu, 15 Aug 2024 20:22:13 +0000 (13:22 -0700)] 
Merge branch 'ag/t7004-modernize'

Coding style fixes to a test script.

* ag/t7004-modernize:
  t7004: make use of write_script
  t7004: use single quotes instead of double quotes
  t7004: begin the test body on the same line as test_expect_success
  t7004: description on the same line as test_expect_success
  t7004: do not prepare things outside test_expect_success
  t7004: use indented here-doc
  t7004: one command per line
  t7004: remove space after redirect operators

10 months agoMerge branch 'ps/reftable-stack-compaction'
Junio C Hamano [Thu, 15 Aug 2024 20:22:13 +0000 (13:22 -0700)] 
Merge branch 'ps/reftable-stack-compaction'

The code paths to compact multiple reftable files have been updated
to correctly deal with multiple compaction triggering at the same
time.

* ps/reftable-stack-compaction:
  reftable/stack: handle locked tables during auto-compaction
  reftable/stack: fix corruption on concurrent compaction
  reftable/stack: use lock_file when adding table to "tables.list"
  reftable/stack: do not die when fsyncing lock file files
  reftable/stack: simplify tracking of table locks
  reftable/stack: update stats on failed full compaction
  reftable/stack: test compaction with already-locked tables
  reftable/stack: extract function to setup stack with N tables
  reftable/stack: refactor function to gather table sizes

10 months agoMerge branch 'es/doc-platform-support-policy'
Junio C Hamano [Thu, 15 Aug 2024 20:22:12 +0000 (13:22 -0700)] 
Merge branch 'es/doc-platform-support-policy'

A policy document that describes platform support levels and
expectation on platform stakeholders has been introduced.

* es/doc-platform-support-policy:
  Documentation: add platform support policy

10 months agoMerge branch 'gt/unit-test-hashmap'
Junio C Hamano [Thu, 15 Aug 2024 20:22:12 +0000 (13:22 -0700)] 
Merge branch 'gt/unit-test-hashmap'

An existing test of hashmap API has been rewritten with the
unit-test framework.

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

10 months agoMerge branch 'jc/t3206-test-when-finished-fix'
Junio C Hamano [Thu, 15 Aug 2024 20:22:11 +0000 (13:22 -0700)] 
Merge branch 'jc/t3206-test-when-finished-fix'

Test clean-up.

* jc/t3206-test-when-finished-fix:
  t3206: test_when_finished before dirtying operations, not after

10 months agoMerge branch 'rs/t-example-simplify'
Junio C Hamano [Thu, 15 Aug 2024 20:22:11 +0000 (13:22 -0700)] 
Merge branch 'rs/t-example-simplify'

Unit test simplification.

* rs/t-example-simplify:
  t-example-decorate: remove test messages

10 months agoMerge branch 'jc/safe-directory'
Junio C Hamano [Thu, 15 Aug 2024 20:22:10 +0000 (13:22 -0700)] 
Merge branch 'jc/safe-directory'

Follow-up on 2.45.1 regression fix.

* jc/safe-directory:
  safe.directory: setting safe.directory="." allows the "current" directory
  safe.directory: normalize the configured path
  safe.directory: normalize the checked path
  safe.directory: preliminary clean-up

10 months agoThe fourth batch
Junio C Hamano [Wed, 14 Aug 2024 21:17:22 +0000 (14:17 -0700)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'tb/t7704-deflake'
Junio C Hamano [Wed, 14 Aug 2024 21:54:58 +0000 (14:54 -0700)] 
Merge branch 'tb/t7704-deflake'

A test that fails on an unusually slow machine was found, and made
less likely to cause trouble by lengthening the expiry value it
uses.

* tb/t7704-deflake:
  t/t7704-repack-cruft.sh: avoid failures during long-running tests

10 months agoMerge branch 'jc/document-use-of-local'
Junio C Hamano [Wed, 14 Aug 2024 21:54:58 +0000 (14:54 -0700)] 
Merge branch 'jc/document-use-of-local'

Doc update.

* jc/document-use-of-local:
  doc: note that AT&T ksh does not work with our test suite

10 months agoMerge branch 'rs/use-decimal-width'
Junio C Hamano [Wed, 14 Aug 2024 21:54:57 +0000 (14:54 -0700)] 
Merge branch 'rs/use-decimal-width'

Code clean-up.

* rs/use-decimal-width:
  log-tree: use decimal_width()

10 months agoMerge branch 'ss/packed-ref-store-leakfix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:56 +0000 (14:54 -0700)] 
Merge branch 'ss/packed-ref-store-leakfix'

Leakfix.

* ss/packed-ref-store-leakfix:
  refs/files: prevent memory leak by freeing packed_ref_store

10 months agoMerge branch 'cp/unit-test-reftable-tree'
Junio C Hamano [Wed, 14 Aug 2024 21:54:56 +0000 (14:54 -0700)] 
Merge branch 'cp/unit-test-reftable-tree'

A test in reftable library has been rewritten using the unit test
framework.

* cp/unit-test-reftable-tree:
  t-reftable-tree: improve the test for infix_walk()
  t-reftable-tree: add test for non-existent key
  t-reftable-tree: split test_tree() into two sub-test functions
  t: move reftable/tree_test.c to the unit testing framework
  reftable: remove unnecessary curly braces in reftable/tree.c

10 months agoMerge branch 'kl/test-fixes'
Junio C Hamano [Wed, 14 Aug 2024 21:54:55 +0000 (14:54 -0700)] 
Merge branch 'kl/test-fixes'

A flakey test and incorrect calls to strtoX() functions have been
fixed.

* kl/test-fixes:
  t6421: fix test to work when repo dir contains d0
  set errno=0 before strtoX calls

10 months agoMerge branch 'jc/reflog-expire-lookup-commit-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:55 +0000 (14:54 -0700)] 
Merge branch 'jc/reflog-expire-lookup-commit-fix'

"git reflog expire" failed to honor annotated tags when computing
reachable commits.

* jc/reflog-expire-lookup-commit-fix:
  Revert "reflog expire: don't use lookup_commit_reference_gently()"

10 months agoMerge branch 'jr/ls-files-expand-literal-doc'
Junio C Hamano [Wed, 14 Aug 2024 21:54:54 +0000 (14:54 -0700)] 
Merge branch 'jr/ls-files-expand-literal-doc'

Docfix.

* jr/ls-files-expand-literal-doc:
  doc: fix hex code escapes in git-ls-files

10 months agoMerge branch 'jc/leakfix-mailmap'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-mailmap'

Leakfix.

* jc/leakfix-mailmap:
  mailmap: plug memory leak in read_mailmap_blob()

10 months agoMerge branch 'jc/leakfix-hashfile'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-hashfile'

Leakfix.

* jc/leakfix-hashfile:
  csum-file: introduce discard_hashfile()

10 months agoMerge branch 'jc/patch-id'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/patch-id'

The patch parser in "git patch-id" has been tightened to avoid
getting confused by lines that look like a patch header in the log
message.

* jc/patch-id:
  patch-id: tighten code to detect the patch header
  patch-id: rewrite code that detects the beginning of a patch
  patch-id: make get_one_patchid() more extensible
  patch-id: call flush_current_id() only when needed
  t4204: patch-id supports various input format

10 months agoMerge branch 'ps/refs-wo-the-repository'
Junio C Hamano [Wed, 14 Aug 2024 21:54:52 +0000 (14:54 -0700)] 
Merge branch 'ps/refs-wo-the-repository'

In the refs subsystem, implicit reliance of the_repository has been
eliminated; the repository associated with the ref store object is
used instead.

* ps/refs-wo-the-repository:
  refs/reftable: stop using `the_repository`
  refs/packed: stop using `the_repository`
  refs/files: stop using `the_repository`
  refs/files: stop using `the_repository` in `parse_loose_ref_contents()`
  refs: stop using `the_repository`

10 months agoMerge branch 'jc/jl-git-no-advice-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'jc/jl-git-no-advice-fix'

Remove leftover debugging cruft from a test script.

* jc/jl-git-no-advice-fix:
  t0018: remove leftover debugging cruft

10 months agoMerge branch 'tb/config-fixed-value-with-valueless-true'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'tb/config-fixed-value-with-valueless-true'

"git config --value=foo --fixed-value section.key newvalue" barfed
when the existing value in the configuration file used the
valueless true syntax, which has been corrected.

* tb/config-fixed-value-with-valueless-true:
  config.c: avoid segfault with --fixed-value and valueless config

10 months agoMerge branch 'jk/apply-patch-mode-check-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'jk/apply-patch-mode-check-fix'

The patch parser in 'git apply' has been a bit more lenient against
unexpected mode bits, like 100664, recorded on extended header lines.

* jk/apply-patch-mode-check-fix:
  apply: canonicalize modes read from patches

10 months agoMerge branch 'ps/ref-api-cleanup'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'ps/ref-api-cleanup'

Code clean-up.

* ps/ref-api-cleanup:
  refs: drop `ref_store`-less functions

10 months agoMerge branch 'ps/ls-remote-out-of-repo-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'ps/ls-remote-out-of-repo-fix'

A recent update broke "git ls-remote" used outside a repository,
which has been corrected.

* ps/ls-remote-out-of-repo-fix:
  builtin/ls-remote: fall back to SHA1 outside of a repo

10 months agoMerge branch 'jc/transport-leakfix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'jc/transport-leakfix'

Leakfix.

* jc/transport-leakfix:
  transport: fix leak with transport helper URLs

10 months agoMerge branch 'rh/http-proxy-path'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'rh/http-proxy-path'

The value of http.proxy can have "path" at the end for a socks
proxy that listens to a unix-domain socket, but we started to
discard it when we taught proxy auth code path to use the
credential helpers, which has been corrected.

* rh/http-proxy-path:
  http: do not ignore proxy path

10 months agoMerge branch 'cp/unit-test-reftable-pq'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'cp/unit-test-reftable-pq'

The tests for "pq" part of reftable library got rewritten to use
the unit test framework.

* cp/unit-test-reftable-pq:
  t-reftable-pq: add tests for merged_iter_pqueue_top()
  t-reftable-pq: add test for index based comparison
  t-reftable-pq: make merged_iter_pqueue_check() callable by reference
  t-reftable-pq: make merged_iter_pqueue_check() static
  t: move reftable/pq_test.c to the unit testing framework
  reftable: change the type of array indices to 'size_t' in reftable/pq.c
  reftable: remove unnecessary curly braces in reftable/pq.c

10 months agoMerge branch 'jk/osxkeychain-username-is-nul-terminated'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'jk/osxkeychain-username-is-nul-terminated'

The credential helper to talk to OSX keychain sometimes sent
garbage bytes after the username, which has been corrected.

* jk/osxkeychain-username-is-nul-terminated:
  credential/osxkeychain: respect NUL terminator in username

10 months agoMerge branch 'ps/leakfixes-part-3'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'ps/leakfixes-part-3'

More leakfixes.

* ps/leakfixes-part-3: (24 commits)
  commit-reach: fix trivial memory leak when computing reachability
  convert: fix leaking config strings
  entry: fix leaking pathnames during delayed checkout
  object-name: fix leaking commit list items
  t/test-repository: fix leaking repository
  builtin/credential-cache: fix trivial leaks
  builtin/worktree: fix leaking derived branch names
  builtin/shortlog: fix various trivial memory leaks
  builtin/rerere: fix various trivial memory leaks
  builtin/credential-store: fix leaking credential
  builtin/show-branch: fix several memory leaks
  builtin/rev-parse: fix memory leak with `--parseopt`
  builtin/stash: fix various trivial memory leaks
  builtin/remote: fix various trivial memory leaks
  builtin/remote: fix leaking strings in `branch_list`
  builtin/ls-remote: fix leaking `pattern` strings
  builtin/submodule--helper: fix leaking buffer in `is_tip_reachable`
  builtin/submodule--helper: fix leaking clone depth parameter
  builtin/name-rev: fix various trivial memory leaks
  builtin/describe: fix trivial memory leak when describing blob
  ...

10 months agoref-filter: populate symref from iterator
John Cai [Fri, 9 Aug 2024 15:37:51 +0000 (15:37 +0000)] 
ref-filter: populate symref from iterator

With a previous commit, the reference the symbolic ref points to is saved
in the ref iterator records. Instead of making a separate call to
resolve_refdup() each time, we can just populate the ref_array_item with
the value from the iterator.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: add referent to each_ref_fn
John Cai [Fri, 9 Aug 2024 15:37:50 +0000 (15:37 +0000)] 
refs: add referent to each_ref_fn

Add a parameter to each_ref_fn so that callers to the ref APIs
that use this function as a callback can have acess to the
unresolved value of a symbolic ref.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: keep track of unresolved reference value in iterators
John Cai [Fri, 9 Aug 2024 15:37:49 +0000 (15:37 +0000)] 
refs: keep track of unresolved reference value in iterators

Since ref iterators do not hold onto the direct value of a reference
without resolving it, the only way to get ahold of a direct value of a
symbolic ref is to make a separate call to refs_read_symbolic_ref.

To make accessing the direct value of a symbolic ref more efficient,
let's save the direct value of the ref in the iterators for both the
files backend and the reftable backend.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff-tree: fix crash when used with --remerge-diff
Xing Xin [Fri, 9 Aug 2024 07:24:52 +0000 (07:24 +0000)] 
diff-tree: fix crash when used with --remerge-diff

When using "git-diff-tree" to get the tree diff for merge commits with
the diff format set to `remerge`, a bug is triggered as shown below:

  $ git diff-tree -r --remerge-diff 363337e6eb
  363337e6eb812d0c0d785ed4261544f35559ff8b
  BUG: log-tree.c:1006: did a remerge diff without remerge_objdir?!?

This bug is reported by `log-tree.c:do_remerge_diff`, where a bug check
added in commit 7b90ab467a (log: clean unneeded objects during log
--remerge-diff, 2022-02-02) detects the absence of `remerge_objdir` when
attempting to clean up temporary objects generated during the remerge
process.

After some further digging, I find that the remerge-related diff options
were introduced in db757e8b8d (show, log: provide a --remerge-diff
capability, 2022-02-02), which also affect the setup of `rev_info` for
"git-diff-tree", but were not accounted for in the original
implementation (inferred from the commit message).

Elijah Newren, the author of the remerge diff feature, notes that other
callers of `log-tree.c:log_tree_commit` (the only caller of
`log-tree.c:do_remerge_diff`) also exist, but:

  `builtin/am.c`: manually sets all flags; remerge_diff is not among them
  `sequencer.c`: manually sets all flags; remerge_diff is not among them

so `builtin/diff-tree.c` really is the only caller that was overlooked
when remerge-diff functionality was added.

This commit resolves the crash by adding `remerge_objdir` setup logic to
`builtin/diff-tree.c`, mirroring `builtin/log.c:cmd_log_walk_no_free`.
It also includes the necessary cleanup for `remerge_objdir`.

Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoThe third batch
Junio C Hamano [Wed, 7 Aug 2024 16:46:53 +0000 (09:46 -0700)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'ps/p4-tests-updates'
Junio C Hamano [Thu, 8 Aug 2024 17:41:20 +0000 (10:41 -0700)] 
Merge branch 'ps/p4-tests-updates'

Perforce tests have been updated.

* ps/p4-tests-updates:
  t98xx: mark Perforce tests as memory-leak free
  ci: update Perforce version to r23.2
  t98xx: fix Perforce tests with p4d r23 and newer

10 months agoMerge branch 'dh/encoding-trace-optim'
Junio C Hamano [Thu, 8 Aug 2024 17:41:20 +0000 (10:41 -0700)] 
Merge branch 'dh/encoding-trace-optim'

An expensive operation to prepare tracing was done in re-encoding
code path even when the tracing was not requested, which has been
corrected.

* dh/encoding-trace-optim:
  convert: return early when not tracing

10 months agoMerge branch 'ps/doc-more-c-coding-guidelines'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'ps/doc-more-c-coding-guidelines'

Some project conventions have been added to CodingGuidelines.

* ps/doc-more-c-coding-guidelines:
  Documentation: consistently use spaces inside initializers
  Documentation: document idiomatic function names
  Documentation: document naming schema for structs and their functions
  Documentation: clarify indentation style for C preprocessor directives
  clang-format: fix indentation width for preprocessor directives

10 months agoMerge branch 'rs/grep-omit-blank-lines-after-function-at-eof'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'rs/grep-omit-blank-lines-after-function-at-eof'

"git grep -W" omits blank lines that follow the found function at
the end of the file, just like it omits blank lines before the next
function.

* rs/grep-omit-blank-lines-after-function-at-eof:
  grep: -W: skip trailing empty lines at EOF, too

10 months agoMerge branch 'dd/notes-empty-no-edit-by-default'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'dd/notes-empty-no-edit-by-default'

"git notes add -m '' --allow-empty" and friends that take prepared
data to create notes should not invoke an editor, but it started
doing so since Git 2.42, which has been corrected.

* dd/notes-empty-no-edit-by-default:
  notes: do not trigger editor when adding an empty note

10 months agoMerge branch 'es/shell-check-updates'
Junio C Hamano [Thu, 8 Aug 2024 17:41:18 +0000 (10:41 -0700)] 
Merge branch 'es/shell-check-updates'

Test script linter has been updated to catch an attempt to use
one-shot export construct "VAR=VAL func" for shell functions (which
does not work for some shells) better.

* es/shell-check-updates:
  check-non-portable-shell: improve `VAR=val shell-func` detection
  check-non-portable-shell: suggest alternative for `VAR=val shell-func`
  check-non-portable-shell: loosen one-shot assignment error message
  t4034: fix use of one-shot variable assignment with shell function
  t3430: drop unnecessary one-shot "VAR=val shell-func" invocation

10 months agoMerge branch 'rj/add-p-pager'
Junio C Hamano [Thu, 8 Aug 2024 17:41:18 +0000 (10:41 -0700)] 
Merge branch 'rj/add-p-pager'

A 'P' command to "git add -p" that passes the patch hunk to the
pager has been added.

* rj/add-p-pager:
  add-patch: render hunks through the pager
  pager: introduce wait_for_pager
  pager: do not close fd 2 unnecessarily
  add-patch: test for 'p' command

10 months agoMerge branch 'ks/unit-test-comment-typofix'
Junio C Hamano [Thu, 8 Aug 2024 17:41:17 +0000 (10:41 -0700)] 
Merge branch 'ks/unit-test-comment-typofix'

Typofix.

* ks/unit-test-comment-typofix:
  unit-tests/test-lib: fix typo in check_pointer_eq() description

10 months agot7004: make use of write_script
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:07 +0000 (19:32 +0300)] 
t7004: make use of write_script

Use write_script which takes care of emitting the `#!/bin/sh` line
and the `chmod +x`.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: use single quotes instead of double quotes
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:06 +0000 (19:32 +0300)] 
t7004: use single quotes instead of double quotes

Some test bodies and test description are surrounded with double
quotes instead of single quotes, violating our coding style.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: begin the test body on the same line as test_expect_success
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:05 +0000 (19:32 +0300)] 
t7004: begin the test body on the same line as test_expect_success

Test body should begin with a single quote right after the test
description instead of backslash followed by new line.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: description on the same line as test_expect_success
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:04 +0000 (19:32 +0300)] 
t7004: description on the same line as test_expect_success

There are several tests in t7004 where the test description that
follows `test_expect_success` is on a separate line, violating our
coding style. Adapt these to be on the same line.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: do not prepare things outside test_expect_success
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:02 +0000 (19:32 +0300)] 
t7004: do not prepare things outside test_expect_success

Do not prepare expect and other things outside test_expect_success.
If such code fails for some reason, we won't necessarily hear about
it in a timely fashion (or perhaps at all). By placing all code inside
`test_expect_success` it ensures that we know immediately if it fails.

Also add '\' before EOF to avoid shell interpolation and '-' to allow
indentation of the body.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: use indented here-doc
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:03 +0000 (19:32 +0300)] 
t7004: use indented here-doc

Use <<-\EOF instead of <<\EOF where the latter allows us to indent
the body of the here-doc.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: one command per line
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:01 +0000 (19:32 +0300)] 
t7004: one command per line

One of the tests in t7004 has multiple commands on a single line,
which is discouraged. Adapt these by splitting up these into one
line per command.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot7004: remove space after redirect operators
AbdAlRahman Gad [Thu, 8 Aug 2024 16:32:00 +0000 (19:32 +0300)] 
t7004: remove space after redirect operators

Modernize 't7004' by removing whitespace after redirect operators.

Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: handle locked tables during auto-compaction
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:58 +0000 (16:06 +0200)] 
reftable/stack: handle locked tables during auto-compaction

When compacting tables, it may happen that we want to compact a set of
tables which are already locked by a concurrent process that compacts
them. In the case where we wanted to perform a full compaction of all
tables it is sensible to bail out in this case, as we cannot fulfill the
requested action.

But when performing auto-compaction it isn't necessarily in our best
interest of us to abort the whole operation. For example, due to the
geometric compacting schema that we use, it may be that process A takes
a lot of time to compact the bulk of all tables whereas process B
appends a bunch of new tables to the stack. B would in this case also
notice that it has to compact the tables that process A is compacting
already and thus also try to compact the same range, probably including
the new tables it has appended. But because those tables are locked
already, it will fail and thus abort the complete auto-compaction. The
consequence is that the stack will grow longer and longer while A isn't
yet done with compaction, which will lead to a growing performance
impact.

Instead of aborting auto-compaction altogether, let's gracefully handle
this situation by instead compacting tables which aren't locked. To do
so, instead of locking from the beginning of the slice-to-be-compacted,
we start locking tables from the end of the slice. Once we hit the first
table that is locked already, we abort. If we succeeded to lock two or
more tables, then we simply reduce the slice of tables that we're about
to compact to those which we managed to lock.

This ensures that we can at least make some progress for compaction in
said scenario. It also helps in other scenarios, like for example when a
process died and left a stale lockfile behind. In such a case we can at
least ensure some compaction on a best-effort basis.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: fix corruption on concurrent compaction
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:53 +0000 (16:06 +0200)] 
reftable/stack: fix corruption on concurrent compaction

The locking employed by compaction uses the following schema:

  1. Lock "tables.list" and verify that it matches the version we have
     loaded in core.

  2. Lock each of the tables in the user-supplied range of tables that
     we are supposed to compact. These locks prohibit any concurrent
     process to compact those tables while we are doing that.

  3. Unlock "tables.list". This enables concurrent processes to add new
     tables to the stack, but also allows them to compact tables outside
     of the range of tables that we have locked.

  4. Perform the compaction.

  5. Lock "tables.list" again.

  6. Move the compacted table into place.

  7. Write the new order of tables, including the compacted table, into
     the lockfile.

  8. Commit the lockfile into place.

Letting concurrent processes modify the "tables.list" file while we are
doing the compaction is very much part of the design and thus expected.
After all, it may take some time to compact tables in the case where we
are compacting a lot of very large tables.

But there is a bug in the code. Suppose we have two processes which are
compacting two slices of the table. Given that we lock each of the
tables before compacting them, we know that the slices must be disjunct
from each other. But regardless of that, compaction performed by one
process will always impact what the other process needs to write to the
"tables.list" file.

Right now, we do not check whether the "tables.list" has been changed
after we have locked it for the second time in (5). This has the
consequence that we will always commit the old, cached in-core tables to
disk without paying to respect what the other process has written. This
scenario would then lead to data loss and corruption.

This can even happen in the simpler case of one compacting process and
one writing process. The newly-appended table by the writing process
would get discarded by the compacting process because it never sees the
new table.

Fix this bug by re-checking whether our stack is still up to date after
locking for the second time. If it isn't, then we adjust the indices of
tables to replace in the updated stack.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: use lock_file when adding table to "tables.list"
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:49 +0000 (16:06 +0200)] 
reftable/stack: use lock_file when adding table to "tables.list"

When modifying "tables.list", we need to lock the list before updating
it to ensure that no concurrent writers modify the list at the same
point in time. While we do this via the `lock_file` subsystem when
compacting the stack, we manually handle the lock when adding a new
table to it. While not wrong, it is at least inconsistent.

Refactor the code to consistently lock "tables.list" via the `lock_file`
subsytem.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: do not die when fsyncing lock file files
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:44 +0000 (16:06 +0200)] 
reftable/stack: do not die when fsyncing lock file files

We use `fsync_component_or_die()` when committing an addition to the
"tables.list" lock file, which unsurprisingly dies in case the fsync
fails. Given that this is part of the reftable library, we should never
die and instead let callers handle the error.

Adapt accordingly and use `fsync_component()` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: simplify tracking of table locks
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:39 +0000 (16:06 +0200)] 
reftable/stack: simplify tracking of table locks

When compacting tables, we store the locks of all tables we are about to
compact in the `table_locks` array. As we currently only ever compact
all tables in the user-provided range or none, we simply track those
locks via the indices of the respective tables in the merged stack.

This is about to change though, as we will introduce a mode where auto
compaction gracefully handles the case of already-locked files. In this
case, it may happen that we only compact a subset of the user-supplied
range of tables. In this case, the indices will not necessarily match
the lock indices anymore.

Refactor the code such that we track the number of locks via a separate
variable. The resulting code is expected to perform the same, but will
make it easier to perform the described change.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: update stats on failed full compaction
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:34 +0000 (16:06 +0200)] 
reftable/stack: update stats on failed full compaction

When auto-compaction fails due to a locking error, we update the
statistics to indicate this failure. We're not doing the same when
performing a full compaction.

Fix this inconsistency by using `stack_compact_range_stats()`, which
handles the stat update for us.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: test compaction with already-locked tables
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:29 +0000 (16:06 +0200)] 
reftable/stack: test compaction with already-locked tables

We're lacking test coverage for compacting tables when some of the
tables that we are about to compact are locked. Add two tests that
exercise this, one for auto-compaction and one for full compaction.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: extract function to setup stack with N tables
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:24 +0000 (16:06 +0200)] 
reftable/stack: extract function to setup stack with N tables

We're about to add two tests, and both of them will want to initialize
the reftable stack with a set of N tables. Introduce a new function that
handles this and refactor existing tests that use such a setup to use
it.

Note that this changes the exact records contained in the preexisting
tests. This is fine though as we only care about the shape of the stack
here, not the shape of each table.

Furthermore, with this change we now start to disable auto compaction
when writing the tables, as otherwise we might not end up with the
expected amount of new tables added. This also slightly changes the
behaviour of these tests, but the properties we care for remain intact.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable/stack: refactor function to gather table sizes
Patrick Steinhardt [Thu, 8 Aug 2024 14:06:19 +0000 (16:06 +0200)] 
reftable/stack: refactor function to gather table sizes

Refactor the function that gathers table sizes to be more idiomatic. For
one, use `REFTABLE_CALLOC_ARRAY()` instead of `reftable_calloc()`.
Second, avoid using an integer to iterate through the tables in the
reftable stack given that `stack_len` itself is using a `size_t`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: add ref name check for files backend
shejialuo [Thu, 8 Aug 2024 11:31:42 +0000 (19:31 +0800)] 
fsck: add ref name check for files backend

The git-fsck(1) only implicitly checks the reference, it does not fully
check refs with bad format name such as standalone "@".

However, a file ending with ".lock" should not be marked as having a bad
ref name. It is expected that concurrent writers may have such lock files.
We currently ignore this situation. But for bare ".lock" file, we will
report it as error.

In order to provide such checks, add a new fsck message id "badRefName"
with default ERROR type. Use existing "check_refname_format" to explicit
check the ref name. And add a new unit test to verify the functionality.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofiles-backend: add unified interface for refs scanning
shejialuo [Thu, 8 Aug 2024 11:31:31 +0000 (19:31 +0800)] 
files-backend: add unified interface for refs scanning

For refs and reflogs, we need to scan its corresponding directories to
check every regular file or symbolic link which shares the same pattern.
Introduce a unified interface for scanning directories for
files-backend.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/refs: add verify subcommand
shejialuo [Thu, 8 Aug 2024 11:27:28 +0000 (19:27 +0800)] 
builtin/refs: add verify subcommand

Introduce a new subcommand "verify" in git-refs(1) to allow the user to
check the reference database consistency and also this subcommand will
be used as the entry point of checking refs for "git-fsck(1)".

Add "verbose" field into "fsck_options" to indicate whether we should
print verbose messages when checking refs and objects consistency.

Remove bit-field for "strict" field, this is because we cannot take
address of a bit-field which makes it unhandy to set member variables
when parsing the command line options.

The "git-fsck(1)" declares "fsck_options" variable with "static"
identifier which avoids complaint by the leak-checker. However, in
"git-refs verify", we need to do memory clean manually. Thus add
"fsck_options_clear" function in "fsck.c" to provide memory clean
operation.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: set up ref consistency check infrastructure
shejialuo [Thu, 8 Aug 2024 11:27:17 +0000 (19:27 +0800)] 
refs: set up ref consistency check infrastructure

The "struct ref_store" is the base class which contains the "be" pointer
which provides backend-specific functions whose interfaces are defined
in the "ref_storage_be". We could reuse this polymorphism to define only
one interface. For every backend, we need to provide its own function
pointer.

The interfaces defined in the `ref_storage_be` are carefully structured
in semantic. It's organized as the five parts:

1. The name and the initialization interfaces.
2. The ref transaction interfaces.
3. The ref internal interfaces (pack, rename and copy).
4. The ref filesystem interfaces.
5. The reflog related interfaces.

To keep consistent with the git-fsck(1), add a new interface named
"fsck_refs_fn" to the end of "ref_storage_be". This semantic cannot be
grouped into any above five categories. Explicitly add blank line to
make it different from others.

Last, implement placeholder functions for each ref backends.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: add refs report function
shejialuo [Thu, 8 Aug 2024 11:27:08 +0000 (19:27 +0800)] 
fsck: add refs report function

Introduce a new struct "fsck_ref_report" to contain the information we
need when reporting refs-related messages.

With the new "fsck_vreport" function, add a new function
"fsck_report_ref" to report refs-related fsck error message. Unlike
"report" function uses the exact parameters, we simply pass "struct
fsck_ref_report *report" as the parameter. This is because at current we
don't know exactly how many fields we need. By passing this parameter,
we don't need to change this function prototype when we want to add more
information into "fsck_ref_report".

We have introduced "fsck_report_ref" function to report the error
message for refs. We still need to add the corresponding callback
function. Create refs-specific "error_func" callback
"fsck_refs_error_function".

Last, add "FSCK_REFS_OPTIONS_DEFAULT" macro to create default options
when checking ref consistency.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: add a unified interface for reporting fsck messages
shejialuo [Thu, 8 Aug 2024 11:26:57 +0000 (19:26 +0800)] 
fsck: add a unified interface for reporting fsck messages

The static function "report" provided by "fsck.c" aims at checking error
type and calling the callback "error_func" to report the message. Both
refs and objects need to check the error type of the current fsck
message. In order to extract this common behavior, create a new function
"fsck_vreport". Instead of using "...", provide "va_list" to allow more
flexibility.

Instead of changing "report" prototype to be align with the
"fsck_vreport" function, we leave the "report" prototype unchanged due
to the reason that there are nearly 62 references about "report"
function. Simply change "report" function to use "fsck_vreport" to
report objects related messages.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: make "fsck_error" callback generic
shejialuo [Thu, 8 Aug 2024 11:26:47 +0000 (19:26 +0800)] 
fsck: make "fsck_error" callback generic

The "fsck_error" callback is designed to report the objects-related
error messages. It accepts two parameter "oid" and "object_type" which
is not generic. In order to provide a unified callback which can report
either objects or refs, remove the objects-related parameters and add
the generic parameter "void *fsck_report".

Create a new "fsck_object_report" structure which incorporates the
removed parameters "oid" and "object_type". Then change the
corresponding references to adapt to new "fsck_error" callback.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: rename objects-related fsck error functions
shejialuo [Thu, 8 Aug 2024 11:24:25 +0000 (19:24 +0800)] 
fsck: rename objects-related fsck error functions

The names of objects-related fsck error functions are generic. It's OK
when there is only object database check. However, we are going to
introduce refs database check report function. To avoid ambiguity,
rename object-related fsck error functions to explicitly indicate these
functions are used to report objects-related messages.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agofsck: rename "skiplist" to "skip_oids"
shejialuo [Thu, 8 Aug 2024 11:24:13 +0000 (19:24 +0800)] 
fsck: rename "skiplist" to "skip_oids"

The "skiplist" field in "fsck_options" is related to objects. Because we
are going to introduce ref consistency check, the "skiplist" name is too
general which will make the caller think "skiplist" is related to both
the refs and objects.

It may seem that for both refs and objects, we should provide a general
"skiplist" here. However, the type for "skiplist" is `struct oidset`
which is totally unsuitable for refs.

To avoid above ambiguity, rename "skiplist" to "skip_oids".

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoobject: fix leaking packfiles when closing object store
Patrick Steinhardt [Thu, 8 Aug 2024 07:36:00 +0000 (09:36 +0200)] 
object: fix leaking packfiles when closing object store

When calling `raw_object_store_clear()`, we close and free several
resources associated with the object store. Part of that is to close and
free all the packfiles, which is handled by `close_object_store()`.

That function really only ends up closing the packfiles though, but it
doesn't free them. And in fact it can't, as that function is being
called via `run_command()` when `close_object_store = 1`, which is done
e.g. when we execute git-maintenance(1). At that point, other structures
may still have references on those packfiles, and thus we cannot free
them here. So while it is in fact intentional that we really only close
them, the result is a memory leak because `raw_object_store_clear()`
does not free them, either.

Fix the leak by freeing the packfiles in `raw_object_store_clear()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agosubmodule: fix leaking seen submodule names
Patrick Steinhardt [Thu, 8 Aug 2024 07:35:56 +0000 (09:35 +0200)] 
submodule: fix leaking seen submodule names

We keep track of submodules we have already seen via a string map such
that we don't process the same submodule twice. We never free that map
though, causing a memory leak.

Fix this leak by clearing the map.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agosubmodule: fix leaking fetch tasks
Patrick Steinhardt [Thu, 8 Aug 2024 07:35:51 +0000 (09:35 +0200)] 
submodule: fix leaking fetch tasks

When done with a fetch task used for parallel fetches of submodules, we
need to both call `fetch_task_release()` to release the task's contents
and `free()` to release the task itself. Most sites do this already, but
some only call `fetch_task_release()` and thus leak memory.

While we could trivially fix this by adding the two missing calls to
free(3P), the result would be that we always call both functions. Let's
thus refactor the code such that `fetch_task_release()` also frees the
structure itself. Rename it to `fetch_task_free()` accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/submodule: allow "add" to use different ref storage format
Patrick Steinhardt [Thu, 8 Aug 2024 07:35:47 +0000 (09:35 +0200)] 
builtin/submodule: allow "add" to use different ref storage format

Same as with "clone", users may want to add a submodule to a repository
with a non-default ref storage format. Wire up a new `--ref-format=`
option that works the same as for `git submodule clone`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: fix ref storage format for submodule ref stores
Patrick Steinhardt [Thu, 8 Aug 2024 07:35:42 +0000 (09:35 +0200)] 
refs: fix ref storage format for submodule ref stores

When opening a submodule ref storage we accidentally use the ref storage
format of the owning repository, not of the submodule repository. As
submodules may have a different storage format than their parent repo
this can lead to bugs when trying to access the submodule ref storage
from the parent repository.

One such bug was reported when performing a recursive pull with mixed
ref stores, which fails with:

    $ git pull --recursive
    fatal: Unable to find current revision in submodule path 'path/to/sub'

The same issue occurs when adding a repository contained in the working
tree with a different ref storage format via `git submodule add`.

Fix the bug by using the submodule repository's ref storage format
instead and add some tests. Note that the test for `git submodule
status` was included as a precaution, only. The command worked alright
even without the bugfix.

Reported-by: Jeppe Øland <joland@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/clone: propagate ref storage format to submodules
Patrick Steinhardt [Thu, 8 Aug 2024 07:35:37 +0000 (09:35 +0200)] 
builtin/clone: propagate ref storage format to submodules

When recursively cloning a repository with a non-default ref storage
format, e.g. by passing the `--ref-format=` option, then only the
top-level repository will end up using that ref storage format, and
all recursively cloned submodules will instead use the default format.

While mixed-format constellations are expected to work alright, the
outcome still is somewhat surprising as we have essentially ignored
the user's request.

Fix this by propagating the requested ref format to cloned submodules.

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