]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
2 years agoMerge branch 'vd/stash-silence-reset'
Junio C Hamano [Thu, 31 Mar 2022 01:01:10 +0000 (18:01 -0700)] 
Merge branch 'vd/stash-silence-reset'

"git stash" does not allow subcommands it internally runs as its
implementation detail, except for "git reset", to emit messages;
now "git reset" part has also been squelched.

* vd/stash-silence-reset:
  reset: show --no-refresh in the short-help
  reset: remove 'reset.refresh' config option
  reset: remove 'reset.quiet' config option
  reset: do not make '--quiet' disable index refresh
  stash: make internal resets quiet and refresh index
  reset: suppress '--no-refresh' advice if logging is silenced
  reset: replace '--quiet' with '--no-refresh' in performance advice
  reset: introduce --[no-]refresh option to --mixed
  reset: revise index refresh advice

2 years agoMerge branch 'ab/racy-hooks'
Junio C Hamano [Thu, 31 Mar 2022 01:01:10 +0000 (18:01 -0700)] 
Merge branch 'ab/racy-hooks'

Regression fix.

* ab/racy-hooks:
  hooks: fix "invoked hook" regression in a8cc5943338

2 years agoThe 16th batch
Junio C Hamano [Tue, 29 Mar 2022 19:14:56 +0000 (12:14 -0700)] 
The 16th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jc/rebase-detach-fix'
Junio C Hamano [Tue, 29 Mar 2022 19:22:03 +0000 (12:22 -0700)] 
Merge branch 'jc/rebase-detach-fix'

"git rebase $base $non_branch_commit", when $base is an ancestor or
the $non_branch_commit, modified the current branch, which has been
corrected.

* jc/rebase-detach-fix:
  rebase: set REF_HEAD_DETACH in checkout_up_to_date()
  rebase: use test_commit helper in setup

2 years agoMerge branch 'jt/reset-grafts-when-resetting-shallow'
Junio C Hamano [Tue, 29 Mar 2022 19:22:03 +0000 (12:22 -0700)] 
Merge branch 'jt/reset-grafts-when-resetting-shallow'

When "shallow" information is updated, we forgot to update the
in-core equivalent, which has been corrected.

* jt/reset-grafts-when-resetting-shallow:
  shallow: reset commit grafts when shallow is reset

2 years agoMerge branch 'vd/cache-bottom-fix'
Junio C Hamano [Tue, 29 Mar 2022 19:22:02 +0000 (12:22 -0700)] 
Merge branch 'vd/cache-bottom-fix'

Correct a bug in unpack-trees introduced earlier.

* vd/cache-bottom-fix:
  Revert "unpack-trees: improve performance of next_cache_entry"
  unpack-trees: increment cache_bottom for sparse directories
  t1092: add sparse directory before cone in test repo

2 years agoMerge branch 'ab/refs-various-fixes'
Junio C Hamano [Tue, 29 Mar 2022 19:22:02 +0000 (12:22 -0700)] 
Merge branch 'ab/refs-various-fixes'

Code clean-up.

* ab/refs-various-fixes:
  refs debug: add a wrapper for "read_symbolic_ref"
  packed-backend: remove stub BUG(...) functions
  misc *.c: use designated initializers for struct assignments
  refs: use designated initializers for "struct ref_iterator_vtable"
  refs: use designated initializers for "struct ref_storage_be"

2 years agoThe 15th batch
Junio C Hamano [Fri, 25 Mar 2022 23:35:36 +0000 (16:35 -0700)] 
The 15th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'gc/recursive-fetch-with-unused-submodules'
Junio C Hamano [Fri, 25 Mar 2022 23:38:25 +0000 (16:38 -0700)] 
Merge branch 'gc/recursive-fetch-with-unused-submodules'

When "git fetch --recurse-submodules" grabbed submodule commits
that would be needed to recursively check out newly fetched commits
in the superproject, it only paid attention to submodules that are
in the current checkout of the superproject.  We now do so for all
submodules that have been run "git submodule init" on.

* gc/recursive-fetch-with-unused-submodules:
  submodule: fix latent check_has_commit() bug
  fetch: fetch unpopulated, changed submodules
  submodule: move logic into fetch_task_create()
  submodule: extract get_fetch_task()
  submodule: store new submodule commits oid_array in a struct
  submodule: inline submodule_commits() into caller
  submodule: make static functions read submodules from commits
  t5526: create superproject commits with test helper
  t5526: stop asserting on stderr literally
  t5526: introduce test helper to assert on fetches

2 years agoMerge branch 'ps/fsync-refs'
Junio C Hamano [Fri, 25 Mar 2022 23:38:24 +0000 (16:38 -0700)] 
Merge branch 'ps/fsync-refs'

Updates to refs traditionally weren't fsync'ed, but we can
configure using core.fsync variable to do so.

* ps/fsync-refs:
  core.fsync: new option to harden references

2 years agoMerge branch 'ns/core-fsyncmethod'
Junio C Hamano [Fri, 25 Mar 2022 23:38:24 +0000 (16:38 -0700)] 
Merge branch 'ns/core-fsyncmethod'

Replace core.fsyncObjectFiles with two new configuration variables,
core.fsync and core.fsyncMethod.

* ns/core-fsyncmethod:
  core.fsync: documentation and user-friendly aggregate options
  core.fsync: new option to harden the index
  core.fsync: add configuration parsing
  core.fsync: introduce granular fsync control infrastructure
  core.fsyncmethod: add writeout-only mode
  wrapper: make inclusion of Windows csprng header tightly scoped

2 years agoreset: show --no-refresh in the short-help
Junio C Hamano [Thu, 24 Mar 2022 17:33:10 +0000 (10:33 -0700)] 
reset: show --no-refresh in the short-help

In the short help output from "git reset -h", the recently added
"--[no-]refresh" option is shown like so:

        --refresh             skip refreshing the index after reset

which explains what happens when the option is given in the negative
form, i.e. "--no-refresh".  We could rephrase the explanation to
read "refresh the index after reset (default)" to hint that the user
can say "--no-refresh" to override the default, but listing the
"--no-refresh" form in the list of options would be more helpful.

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Acked-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: remove 'reset.refresh' config option
Victoria Dye [Wed, 23 Mar 2022 18:18:00 +0000 (18:18 +0000)] 
reset: remove 'reset.refresh' config option

Remove the 'reset.refresh' option, requiring that users explicitly specify
'--no-refresh' if they want to skip refreshing the index.

The 'reset.refresh' option was introduced in 101cee42dd (reset: introduce
--[no-]refresh option to --mixed, 2022-03-11) as a replacement for the
refresh-skipping behavior originally controlled by 'reset.quiet'.

Although 'reset.refresh=false' functionally served the same purpose as
'reset.quiet=true', it exposed [1] the fact that the existence of a global
"skip refresh" option could potentially cause problems for users. Allowing a
global config option to avoid refreshing the index forces scripts using 'git
reset --mixed' to defensively use '--refresh' if index refresh is expected;
if that option is missing, behavior of a script could vary from user-to-user
without explanation.

Furthermore, globally disabling index refresh in 'reset --mixed' was
initially devised as a passive performance improvement; since the
introduction of the option, other changes have been made to Git (e.g., the
sparse index) with a greater potential performance impact without
sacrificing index correctness. Therefore, we can more aggressively err on
the side of correctness and limit the cases of skipping index refresh to
only when a user specifies the '--no-refresh' option.

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

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: remove 'reset.quiet' config option
Victoria Dye [Wed, 23 Mar 2022 18:17:59 +0000 (18:17 +0000)] 
reset: remove 'reset.quiet' config option

Remove the 'reset.quiet' config option, remove '--no-quiet' documentation in
'Documentation/git-reset.txt'. In 4c3abd0551 (reset: add new reset.quiet
config setting, 2018-10-23), 'reset.quiet' was introduced as a way to
globally change the default behavior of 'git reset --mixed' to skip index
refresh.

However, now that '--quiet' does not affect index refresh, 'reset.quiet'
would only serve to globally silence logging. This was not the original
intention of the config setting, and there's no precedent for such a setting
in other commands with a '--quiet' option, so it appears to be obsolete.

In addition to the options & its documentation, remove 'reset.quiet' from
the recommended config for 'scalar'.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: do not make '--quiet' disable index refresh
Victoria Dye [Wed, 23 Mar 2022 18:17:58 +0000 (18:17 +0000)] 
reset: do not make '--quiet' disable index refresh

Update '--quiet' to no longer implicitly skip refreshing the index in a
mixed reset. Users now have the ability to explicitly disable refreshing the
index with the '--no-refresh' option, so they no longer need to use
'--quiet' to do so. Moreover, we explicitly remove the refresh-skipping
behavior from '--quiet' because it is completely unrelated to the stated
purpose of the option: "Be quiet, only report errors."

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe 14th batch
Junio C Hamano [Wed, 23 Mar 2022 21:04:45 +0000 (14:04 -0700)] 
The 14th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/plug-random-leaks'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'ab/plug-random-leaks'

Double-free fix for a recently merged topic.

* ab/plug-random-leaks:
  diff.c: fix a double-free regression in a18d66cefb
  tests: demonstrate "show --word-diff --color-moved" regression

2 years agoMerge branch 'dc/complete-restore'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'dc/complete-restore'

The command line completion support (in contrib/) learns to give
modified paths to the "git restore" command.

* dc/complete-restore:
  completion: tab completion of filenames for 'git restore'

2 years agoMerge branch 'jc/cat-file-batch-default-format-optim'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'jc/cat-file-batch-default-format-optim'

Optimize away strbuf_expand() call with a hardcoded formatting logic
specific for the default format in the --batch and --batch-check
options of "git cat-file".

* jc/cat-file-batch-default-format-optim:
  cat-file: skip expanding default format

2 years agoMerge branch 'js/in-place-reverse-in-sequencer'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'js/in-place-reverse-in-sequencer'

Code clean-up.

* js/in-place-reverse-in-sequencer:
  sequencer: use reverse_commit_list() helper

2 years agoMerge branch 'ac/test-lazy-fetch'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ac/test-lazy-fetch'

A new test to ensure a lazy fetching is not triggered when it
should not be.

* ac/test-lazy-fetch:
  partial-clone: add a partial-clone test case

2 years agoMerge branch 'ps/repack-with-server-info'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ps/repack-with-server-info'

"git repack" learned a new configuration to disable triggering of
age-old "update-server-info" command, which is rarely useful these
days.

* ps/repack-with-server-info:
  repack: add config to skip updating server info
  repack: refactor to avoid double-negation of update-server-info

2 years agoMerge branch 'ds/doc-maintenance-synopsis-fix'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ds/doc-maintenance-synopsis-fix'

Doc update.

* ds/doc-maintenance-synopsis-fix:
  maintenance: fix synopsis in documentation

2 years agoMerge branch 'ab/reflog-prep-fix'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ab/reflog-prep-fix'

Regression fix.

* ab/reflog-prep-fix:
  reflog: don't be noisy on empty reflogs

2 years agoMerge branch 'ep/remove-duplicated-includes'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ep/remove-duplicated-includes'

Code clean-up.

* ep/remove-duplicated-includes:
  attr.h: remove duplicate struct definition
  t/helper/test-run-command.c: delete duplicate include
  builtin/stash.c: delete duplicate include
  builtin/sparse-checkout.c: delete duplicate include
  builtin/gc.c: delete duplicate include
  attr.c: delete duplicate include

2 years agoMerge branch 'ep/t6423-modernize'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'ep/t6423-modernize'

Code clean-up.

* ep/t6423-modernize:
  t6423-merge-rename-directories.sh: use the $(...) construct

2 years agoMerge branch 'jk/name-rev-w-genno'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'jk/name-rev-w-genno'

"git name-rev" learned to use the generation numbers when setting
the lower bound of searching commits used to explain the revision,
when available, instead of committer time.

* jk/name-rev-w-genno:
  name-rev: use generation numbers if available

2 years agoMerge branch 'jd/userdiff-kotlin'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'jd/userdiff-kotlin'

A new built-in userdiff driver for kotlin.

* jd/userdiff-kotlin:
  userdiff: add builtin diff driver for kotlin language.

2 years agoMerge branch 'bc/block-sha1-without-gcc-asm-extension'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'bc/block-sha1-without-gcc-asm-extension'

Get rid of one use of __asm__() GCC extension that does not help us
much these days, which has an added advantage of not having to
worry about -pedantic complaining.

* bc/block-sha1-without-gcc-asm-extension:
  block-sha1: remove use of obsolete x86 assembly

2 years agoMerge branch 'gc/submodule-update-part1'
Junio C Hamano [Wed, 23 Mar 2022 21:09:28 +0000 (14:09 -0700)] 
Merge branch 'gc/submodule-update-part1'

Rewrite of "git submodule update" in C (early part).

* gc/submodule-update-part1:
  submodule--helper update-clone: check for --filter and --init
  submodule update: add tests for --filter
  submodule--helper: remove ensure-core-worktree
  submodule--helper update-clone: learn --init
  submodule--helper: allow setting superprefix for init_submodule()
  submodule--helper: refactor get_submodule_displaypath()
  submodule--helper run-update-procedure: learn --remote
  submodule--helper: don't use bitfield indirection for parse_options()
  submodule--helper: get remote names from any repository
  submodule--helper run-update-procedure: remove --suboid
  submodule--helper: reorganize code for sh to C conversion
  submodule--helper: remove update-module-mode
  submodule tests: test for init and update failure output

2 years agohooks: fix "invoked hook" regression in a8cc5943338
Ævar Arnfjörð Bjarmason [Mon, 21 Mar 2022 23:15:13 +0000 (00:15 +0100)] 
hooks: fix "invoked hook" regression in a8cc5943338

Fix a regression in a8cc5943338 (hooks: fix an obscure TOCTOU "did we
just run a hook?" race, 2022-03-07): The "invoked_hook" variable
passed to run_commit_hook() wasn't passed forward to run_hooks_opt(),
as push_to_checkout() in that commit correctly did.

Whether we ran the code contingent on having run the hook or not was
thus undefined, but in practice on most (all?) modern platforms we'd
have run it (almost?) all the time, since stack variables will get
initialized to some random value, which most of the time isn't "0".

This bug was revealed by running e.g. "t5537-fetch-shallow.sh" with
the --valgrind option. Unfortunately running the whole test suite with
--valgrind is really slow, so we didn't have a CI job that spotted
this. The --valgrind output was:

    ==31275== Conditional jump or move depends on uninitialised value(s)
    ==31275==    at 0x43C63F: prepare_to_commit (commit.c:1058)
    ==31275==    by 0x4396A5: cmd_commit (commit.c:1722)
    ==31275==    by 0x407C8A: run_builtin (git.c:465)
    ==31275==    by 0x406741: handle_builtin (git.c:718)
    ==31275==    by 0x407665: run_argv (git.c:785)
    ==31275==    by 0x406500: cmd_main (git.c:916)
    ==31275==    by 0x510839: main (common-main.c:56)
    ==31275==  Uninitialised value was created by a stack allocation
    ==31275==    at 0x43B344: prepare_to_commit (commit.c:719)

Reported-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe thirteenth batch
Junio C Hamano [Mon, 21 Mar 2022 21:18:51 +0000 (14:18 -0700)] 
The thirteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jy/gitweb-no-need-for-meta'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'jy/gitweb-no-need-for-meta'

Remove unneeded <meta http-equiv=content-type...> from gitweb
output.

* jy/gitweb-no-need-for-meta:
  gitweb: remove invalid http-equiv="content-type"
  comment: fix typo

2 years agoMerge branch 'pw/single-key-interactive'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'pw/single-key-interactive'

The single-key interactive operation used by "git add -p" has been
made more robust.

* pw/single-key-interactive:
  add -p: disable stdin buffering when interactive.singlekey is set
  terminal: set VMIN and VTIME in non-canonical mode
  terminal: pop signal handler when terminal is restored
  terminal: always reset terminal when reading without echo

2 years agoMerge branch 'ds/partial-bundles'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'ds/partial-bundles'

Bundle file format gets extended to allow a partial bundle,
filtered by similar criteria you would give when making a
partial/lazy clone.

* ds/partial-bundles:
  clone: fail gracefully when cloning filtered bundle
  bundle: unbundle promisor packs
  bundle: create filtered bundles
  rev-list: move --filter parsing into revision.c
  bundle: parse filter capability
  list-objects: handle NULL function pointers
  MyFirstObjectWalk: update recommended usage
  list-objects: consolidate traverse_commit_list[_filtered]
  pack-bitmap: drop filter in prepare_bitmap_walk()
  pack-objects: use rev.filter when possible
  revision: put object filter into struct rev_info
  list-objects-filter-options: create copy helper
  index-pack: document and test the --promisor option

2 years agoMerge branch 'ep/test-malloc-check-with-glibc-2.34'
Junio C Hamano [Mon, 21 Mar 2022 22:14:23 +0000 (15:14 -0700)] 
Merge branch 'ep/test-malloc-check-with-glibc-2.34'

The method to trigger malloc check used in our tests no longer work
with newer versions of glibc.

* ep/test-malloc-check-with-glibc-2.34:
  test-lib: declare local variables as local
  test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34

2 years agoMerge branch 'sm/no-git-in-upstream-of-pipe-in-tests'
Junio C Hamano [Mon, 21 Mar 2022 22:14:23 +0000 (15:14 -0700)] 
Merge branch 'sm/no-git-in-upstream-of-pipe-in-tests'

Test fixes.

* sm/no-git-in-upstream-of-pipe-in-tests:
  t0030-t0050: avoid pipes with Git on LHS
  t0001-t0028: avoid pipes with Git on LHS
  t0003: avoid pipes with Git on LHS

2 years agorebase: set REF_HEAD_DETACH in checkout_up_to_date()
John Cai [Fri, 18 Mar 2022 13:54:03 +0000 (13:54 +0000)] 
rebase: set REF_HEAD_DETACH in checkout_up_to_date()

"git rebase A B" where B is not a commit should behave as if the
HEAD got detached at B and then the detached HEAD got rebased on top
of A.  A bug however overwrites the current branch to point at B,
when B is a descendant of A (i.e. the rebase ends up being a
fast-forward).  See [1] for the original bug report.

The callstack from checkout_up_to_date() is the following:

cmd_rebase()
-> checkout_up_to_date()
   -> reset_head()
      -> update_refs()
         -> update_ref()

When B is not a valid branch but an oid, rebase sets the head_name
of rebase_options to NULL. This value gets passed down this call
chain through the branch member of reset_head_opts also getting set
to NULL all the way to update_refs().

Then update_refs() checks ropts.branch to decide whether or not to switch
branches. If ropts.branch is NULL, it calls update_ref() to update HEAD.
At this point however, from rebase's point of view, we want a detached
HEAD. But, since checkout_up_to_date() does not set the RESET_HEAD_DETACH
flag, the update_ref() call will deference HEAD and update the branch its
pointing to. We want the HEAD detached at B instead.

Fix this bug by adding the RESET_HEAD_DETACH flag in
checkout_up_to_date if B is not a valid branch, so that once
reset_head() calls update_refs(), it calls update_ref() with
REF_NO_DEREF which updates HEAD directly intead of deferencing it
and updating the branch that HEAD points to.

Also add a test to ensure the correct behavior.

[1] https://lore.kernel.org/git/YiokTm3GxIZQQUow@newk/

Reported-by: Michael McClimon <michael@mcclimon.org>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorebase: use test_commit helper in setup
John Cai [Fri, 18 Mar 2022 13:54:02 +0000 (13:54 +0000)] 
rebase: use test_commit helper in setup

To prepare for the next commit that will test rebase with oids instead
of branch names, update the rebase setup test to add a couple of tags we
can use. This uses the test_commit helper so we can replace some lines
that add a commit manually.

Setting logAllRefUpdates is not necessary because it's on by default for
repositories with a working tree.

Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoshallow: reset commit grafts when shallow is reset
Jonathan Tan [Thu, 17 Mar 2022 18:24:47 +0000 (11:24 -0700)] 
shallow: reset commit grafts when shallow is reset

When reset_repository_shallow() is called, Git clears its cache of
shallow information, so that if shallow information is re-requested, Git
will read fresh data from disk instead of reusing its stale cached data.
However, the cache of commit grafts is not likewise cleared, even though
there are commit grafts created from shallow information.

This means that if on-disk shallow information were to be updated and
then a commit-graft-using codepath were run (for example, a revision
walk), Git would be using stale commit graft information. This can be
seen from the test in this patch, in which Git performs a revision walk
(to check for changed submodules) after a fetch with --update-shallow.

Therefore, clear the cache of commit grafts whenever
reset_repository_shallow() is called.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorefs debug: add a wrapper for "read_symbolic_ref"
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 17:27:19 +0000 (18:27 +0100)] 
refs debug: add a wrapper for "read_symbolic_ref"

In cd475b3b038 (refs: add ability for backends to special-case reading
of symbolic refs, 2022-03-01) when the "read_symbolic_ref" callback
was added we'd fall back on "refs_read_raw_ref" if there wasn't any
backend implementation of "read_symbolic_ref".

As discussed in the preceding commit this would only happen if we were
running the "debug" backend, e.g. in the "setup for ref completion"
test in t9902-completion.sh with:

    GIT_TRACE_REFS=1 git fetch --no-tags other

Let's improve the trace output, but and also eliminate the
now-redundant refs_read_raw_ref() fallback case. As noted in the
preceding commit the "packed" backend will never call
refs_read_symbolic_ref() (nor is it ever going to). For any future
backend such as reftable it's OK to ask that they either implement
this (or a wrapper) themselves.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopacked-backend: remove stub BUG(...) functions
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 17:27:18 +0000 (18:27 +0100)] 
packed-backend: remove stub BUG(...) functions

Remove the stub BUG(...) functions previously used by the "struct
ref_storage_be refs_be_packed" backend.

We never call any functions in the packed backend by using it as a
"normal" primary ref store, instead we'll always initialize a "files"
backend ref-store.

It will then via the "packed_ref_store" member of "struct
files_ref_store" call selected functions in the "packed" backend, and
we'll in addition call others via wrappers in refs.c.

So while these would arguably give us *slightly* more meaningful error
messages we'll NULL the missing members in the initializer anyway, so
we'll reliably get a segfault if we're ever changing the backend and
having it call something it doesn't have.

So there's no need for this verbose boilerplate, and as shown in a
subsequent commit it might even lead to some confusion about the
packed backend being a "real" backend. Let's make it clear that it's
not.

As an aside, this also fixes a warning emitted by SunCC in at least
versions 12.5 and 12.6 of Oracle Developer Studio:

    "refs/packed-backend.c", line 1599: warning: Function has no return statement : packed_create_symref
    "refs/packed-backend.c", line 1606: warning: Function has no return statement : packed_rename_ref)
    "refs/packed-backend.c", line 1613: warning: Function has no return statement : packed_copy_ref
    "refs/packed-backend.c", line 1648: warning: Function has no return statement : packed_create_reflog

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agomisc *.c: use designated initializers for struct assignments
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 17:27:17 +0000 (18:27 +0100)] 
misc *.c: use designated initializers for struct assignments

Change a few miscellaneous non-designated initializer assignments to
use designated initializers.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorefs: use designated initializers for "struct ref_iterator_vtable"
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 17:27:16 +0000 (18:27 +0100)] 
refs: use designated initializers for "struct ref_iterator_vtable"

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorefs: use designated initializers for "struct ref_storage_be"
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 17:27:15 +0000 (18:27 +0100)] 
refs: use designated initializers for "struct ref_storage_be"

Change the definition of the three refs backends we currently carry to
use designated initializers.

The "= NULL" assignments being retained here are redundant, and could
be removed, but let's keep them for clarity. All of these backends
define almost all fields, so we're not saving much in terms of line
count by omitting these, but e.g. for "refs_be_debug" it's immediately
apparent that we're omitting "init" when comparing its assignment to
the others.

This is a follow-up to similar work merged in bd4232fac33 (Merge
branch 'ab/struct-init', 2021-07-16), a4b9fb6a5cf (Merge branch
'ab/designated-initializers-more', 2021-10-18) and a30321b9eae (Merge
branch 'ab/designated-initializers' into
ab/designated-initializers-more, 2021-09-27).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoRevert "unpack-trees: improve performance of next_cache_entry"
Victoria Dye [Thu, 17 Mar 2022 15:55:36 +0000 (15:55 +0000)] 
Revert "unpack-trees: improve performance of next_cache_entry"

This reverts commit f2a454e0a5 (unpack-trees: improve performance of
next_cache_entry, 2021-11-29).

The "hint" value was originally needed to improve performance in 'git reset
-- <pathspec>' caused by 'cache_bottom' lagging behind its correct value
when using a sparse index. The 'cache_bottom' tracking has since been
corrected, removing the need for an additional "pseudo-cache_bottom"
tracking variable.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agounpack-trees: increment cache_bottom for sparse directories
Victoria Dye [Thu, 17 Mar 2022 15:55:35 +0000 (15:55 +0000)] 
unpack-trees: increment cache_bottom for sparse directories

Correct tracking of the 'cache_bottom' for cases where sparse directories
are present in the index.

BACKGROUND
----------
The 'unpack_trees_options.cache_bottom' is a variable that tracks the
in-progress "bottom" of the cache as 'unpack_trees()' iterates through the
contents of the index. Most importantly, this value informs the sequential
return values of 'next_cache_entry()' which, in the "diff cache" usage of
'unpack_callback()', are either unpacked as-is or are passed into the diff
machinery.

The 'cache_bottom' is intended to track the position of the first entry in
the index that has not yet been diffed or unpacked. It is advanced in two
main ways: either it is incremented when an index entry is marked as "used"
(in 'mark_ce_used()'), indicating that it was unpacked or diffed, or when a
directory is unpacked, in which case it is increased by an amount equaling
the number of index entries inside that tree.

In 17a1bb570b (unpack-trees: preserve cache_bottom, 2021-07-14), it was
identified that sparse directories posed a problem to the above
'cache_bottom' advancement logic - because a sparse directory was both an
index entry that could be "used" and a directory that can be unpacked, the
'cache_bottom' would be incremented too many times. To solve this problem,
the 'mark_ce_used()' advancement of 'cache_bottom' was skipped for sparse
directories.

INCORRECT CACHE_BOTTOM TRACKING
-------------------------------
Skipping the 'cache_bottom' advancement for sparse directories in
'mark_ce_used()' breaks down in two cases:

1. When the 'unpack_trees()' operation is *not* a "cache diff" (because the
   directory contents-based incrementing of 'cache_bottom' does not happen).
2. When a cache diff is performed with a pathspec (because
   'unpack_index_entry()' will unpack a sparse directory not matched by the
   pathspec without performing the directory contents-based increment).

The former luckily does not appear to affect 'git' behavior, likely because
'cache_bottom' is largely unused (non-"cache diff" 'unpack_trees()' uses
'find_index_entry()' - rather than 'next_cache_entry()' - to find the index
entries to unpack).

The latter, however, causes 'cache_bottom' to "lag behind" its intended
position by an amount equal to the number of sparse directories unpacked so
far with 'unpack_index_entry()'. If a repository is structured such that any
sparse directories are ordered lexicographically *after* any
pathspec-matching directories, though, this issue won't present any adverse
behavior.

This was the case with the 't1092-sparse-checkout-compatibility.sh' tests
before the addition of the 'before/' sparse directory (ordered *before* the
in-cone 'deep/' directory), therefore sidestepping the issue. Once the
'before/' directory was added, though, 'cache_bottom' began to lag behind
its intended position, causing 'next_cache_entry()' to return index entries
it had already processed and, ultimately, an incorrect diff.

CORRECTING CACHE_BOTTOM
-----------------------
The problems observed in 't1092' come from 'cache_bottom' lagging behind in
cases where the cache tree-based advancement doesn't occur. To solve this,
then, the fix in 17a1bb570b is "reversed"; rather than skipping
'cache_bottom' advancement in 'mark_ce_used()', we skip the directory
contents-based advancement for sparse directories. Now, every index entry
can be accounted for in 'cache_bottom':

* if you're working with a single index entry, 'cache_bottom' is incremented
  in 'mark_ce_used()'
* if you're working with a directory that contains index entries (but is not
  one itself), 'cache_bottom' is incremented by the number of entries in
  that directory.

Finally, change the 'test_expect_failure' tests in 't1092' failing due to
this bug back to 'test_expect_success'.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot1092: add sparse directory before cone in test repo
Victoria Dye [Thu, 17 Mar 2022 15:55:34 +0000 (15:55 +0000)] 
t1092: add sparse directory before cone in test repo

Add a sparse directory 'before/' containing files 'a' and 'b' to the test
repo used in 't/t1092-sparse-checkout-compatibility.sh'. This is meant to
ensure that no sparse index integrations rely on the in-cone path(s) being
lexicographically first in the repo.

Unfortunately, some existing tests do not handle this repo architecture
properly:

* 'add outside sparse cone'
* 'status/add: outside sparse cone'
* 'reset with pathspecs inside sparse definition'

All three of these are due to the incorrect handling of the
'unpack_trees_options.cache_bottom' when performing a cache diff via
'unpack_trees'. This will be corrected in a future patch; in the meantime,
mark the tests with 'test_expect_failure'.

Finally, update the 'ls-files' and 'root directory cannot be sparse' tests
to include the 'before/' directory in their expected index contents.

Co-authored-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agodiff.c: fix a double-free regression in a18d66cefb
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 14:55:35 +0000 (15:55 +0100)] 
diff.c: fix a double-free regression in a18d66cefb

My a18d66cefb9 (diff.c: free "buf" in diff_words_flush(), 2022-03-04)
has what it retrospect is a rather obvious bug (I don't know what I
was thinking, if it all): We use the "emitted_symbols" allocation in
append_emitted_diff_symbol() N times, but starting with a18d66cefb9
we'd free it after its first use!

The correct way to free this data would have been to add the free() to
the existing free_diff_words_data() function, so let's do that. The
"ecbdata->diff_words->opt->emitted_symbols" might be NULL, so let's
add a trivial free_emitted_diff_symbols() helper next to the function
that appends to it.

This fixes the "no effect on show from" leak tested for in the
preceding commit. Perhaps confusingly this change will skip that test
under SANITIZE=leak, but otherwise opt-in the
"t4015-diff-whitespace.sh" test.

The reason is that a18d66cefb9 "fixed" the leak in the preceding "no
effect on diff" test, but for the first call to diff_words_flush() the
"wol->buf" would be NULL, so we wouldn't double-free (and
SANITIZE=address would see nothing amiss). With this change we'll
still pass that test, showing that we've also fixed leaks on this
codepath.

We then have to skip the new "no effect on show" test because it
happens to trip over an unrelated memory leak (in revision.c). The
same goes for "move detection with submodules". Both of them pass with
SANITIZE=address though, which would error on the "no effect on show"
test before this change.

Reported-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agotests: demonstrate "show --word-diff --color-moved" regression
Michael J Gruber [Thu, 17 Mar 2022 14:55:34 +0000 (15:55 +0100)] 
tests: demonstrate "show --word-diff --color-moved" regression

Add a failing test which demonstrates a regression in
a18d66cefb ("diff.c: free "buf" in diff_words_flush()", 2022-03-04),
the regression is discussed in detail in the subsequent commit. With
it running `git show --word-diff --color-moved` with SANITIZE=address
would emit:

==31191==ERROR: AddressSanitizer: attempting double-free on 0x617000021100 in thread T0:
    #0 0x49f0a2 in free (git+0x49f0a2)
    #1 0x9b0e4d in diff_words_flush diff.c:2153:3
    #2 0x9aed5d in fn_out_consume diff.c:2354:3
    #3 0xe092ab in consume_one xdiff-interface.c:43:9
    #4 0xe072eb in xdiff_outf xdiff-interface.c:76:10
    #5 0xec7014 in xdl_emit_diffrec xdiff/xutils.c:53:6
    [...]

0x617000021100 is located 0 bytes inside of 768-byte region [0x617000021100,0x617000021400)
freed by thread T0 here:
    #0 0x49f0a2 in free (git+0x49f0a2)
    [...(same stacktrace)...]

previously allocated by thread T0 here:
    #0 0x49f603 in __interceptor_realloc (git+0x49f603)
    #1 0xde4da4 in xrealloc wrapper.c:126:8
    #2 0x995dc5 in append_emitted_diff_symbol diff.c:794:2
    #3 0x96c44a in emit_diff_symbol diff.c:1527:3
    [...]

This was not caught by the test suite because we test `diff
--word-diff --color-moved` only so far.

Therefore, add a test for `show`, too.

Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe twelfth batch
Junio C Hamano [Thu, 17 Mar 2022 00:45:59 +0000 (17:45 -0700)] 
The twelfth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/string-list-count-in-size-t'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/string-list-count-in-size-t'

Count string_list items in size_t, not "unsigned int".

* ab/string-list-count-in-size-t:
  string-list API: change "nr" and "alloc" to "size_t"
  gettext API users: don't explicitly cast ngettext()'s "n"

2 years agoMerge branch 'ab/racy-hooks'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/racy-hooks'

Code clean-up to allow callers of run_commit_hook() to learn if it
got "success" because the hook succeeded or because there wasn't
any hook.

* ab/racy-hooks:
  hooks: fix an obscure TOCTOU "did we just run a hook?" race
  merge: don't run post-hook logic on --no-verify

2 years agoMerge branch 'ab/keep-git-exit-codes-in-tests'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/keep-git-exit-codes-in-tests'

Updates tests around the use of "test $(git cmd) = constant".

* ab/keep-git-exit-codes-in-tests:
  rev-list simplify tests: don't ignore "git" exit code
  checkout tests: don't ignore "git <cmd>" exit code
  apply tests: don't ignore "git ls-files" exit code, drop sub-shell
  gettext tests: don't ignore "test-tool regex" exit code
  rev-list tests: don't hide abort() in "test_expect_failure"
  diff tests: don't ignore "git rev-list" exit code
  notes tests: don't ignore "git" exit code
  rev-parse tests: don't ignore "git reflog" exit code
  merge tests: use "test_must_fail" instead of ad-hoc pattern
  apply tests: use "test_must_fail" instead of ad-hoc pattern
  diff tests: don't ignore "git diff" exit code in "read" loop
  diff tests: don't ignore "git diff" exit code
  read-tree tests: check "diff-files" exit code on failure
  tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)"
  tests: change some 'test $(git) = "x"' to test_cmp

2 years agoMerge branch 'tk/t7063-chmtime-dirs-too'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'tk/t7063-chmtime-dirs-too'

Teach "test-chmtime" to work on a directory and use it to avoid
having to wait for a second in a few places in tests.

* tk/t7063-chmtime-dirs-too:
  t7063: mtime-mangling instead of delays in untracked cache testing
  t/helper/test-chmtime: update mingw to support chmtime on directories

2 years agoMerge branch 'ds/commit-graph-gen-v2-fixes'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ds/commit-graph-gen-v2-fixes'

Fixes to the way generation number v2 in the commit-graph files are
(not) handled.

* ds/commit-graph-gen-v2-fixes:
  commit-graph: declare bankruptcy on GDAT chunks
  commit-graph: fix generation number v2 overflow values
  commit-graph: start parsing generation v2 (again)
  commit-graph: fix ordering bug in generation numbers
  t5318: extract helpers to lib-commit-graph.sh
  test-read-graph: include extra post-parse info

2 years agoMerge branch 'jc/stash-drop'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'jc/stash-drop'

"git stash drop" is reimplemented as an internal call to
reflog_delete() function, instead of invoking "git reflog delete"
via run_command() API.

* jc/stash-drop:
  stash: call reflog_delete() in reflog.c
  reflog: libify delete reflog function and helpers
  stash: add tests to ensure reflog --rewrite --updatref behavior

2 years agoMerge branch 'tb/rename-remote-progress'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'tb/rename-remote-progress'

"git remote rename A B", depending on the number of remote-tracking
refs involved, takes long time renaming them.  The command has been
taught to show progress bar while making the user wait.

* tb/rename-remote-progress:
  builtin/remote.c: show progress when renaming remote references
  builtin/remote.c: parse options in 'rename'

2 years agoMerge branch 'vd/sparse-read-tree'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'vd/sparse-read-tree'

"git read-tree" has been made to be aware of the sparse-index
feature.

* vd/sparse-read-tree:
  read-tree: make three-way merge sparse-aware
  read-tree: make two-way merge sparse-aware
  read-tree: narrow scope of index expansion for '--prefix'
  read-tree: integrate with sparse index
  read-tree: expand sparse checkout test coverage
  read-tree: explicitly disallow prefixes with a leading '/'
  status: fix nested sparse directory diff in sparse index
  sparse-index: prevent repo root from becoming sparse

2 years agoMerge branch 'ab/object-file-api-updates'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'ab/object-file-api-updates'

Object-file API shuffling.

* ab/object-file-api-updates:
  object-file API: pass an enum to read_object_with_reference()
  object-file.c: add a literal version of write_object_file_prepare()
  object-file API: have hash_object_file() take "enum object_type"
  object API: rename hash_object_file_literally() to write_*()
  object-file API: split up and simplify check_object_signature()
  object API users + docs: check <0, not !0 with check_object_signature()
  object API docs: move check_object_signature() docs to cache.h
  object API: correct "buf" v.s. "map" mismatch in *.c and *.h
  object-file API: have write_object_file() take "enum object_type"
  object-file API: add a format_object_header() function
  object-file API: return "void", not "int" from hash_object_file()
  object-file.c: split up declaration of unrelated variables

2 years agoMerge branch 'mf/fix-type-in-config-h'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'mf/fix-type-in-config-h'

"git config -h" did not describe the "--type" option correctly.

* mf/fix-type-in-config-h:
  config: correct "--type" option in "git config -h" output

2 years agoMerge branch 'ps/fetch-mirror-optim'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'ps/fetch-mirror-optim'

Various optimization for "git fetch".

* ps/fetch-mirror-optim:
  refs/files-backend: optimize reading of symbolic refs
  remote: read symbolic refs via `refs_read_symbolic_ref()`
  refs: add ability for backends to special-case reading of symbolic refs
  fetch: avoid lookup of commits when not appending to FETCH_HEAD
  upload-pack: look up "want" lines via commit-graph

2 years agoMerge branch 'tk/empty-untracked-cache'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'tk/empty-untracked-cache'

The untracked cache newly computed weren't written back to the
on-disk index file when there is no other change to the index,
which has been corrected.

* tk/empty-untracked-cache:
  untracked-cache: write index when populating empty untracked cache
  t7519: populate untracked cache before test
  t7519: avoid file to index mtime race for untracked cache

2 years agoMerge branch 'ab/grep-patterntype'
Junio C Hamano [Thu, 17 Mar 2022 00:53:06 +0000 (17:53 -0700)] 
Merge branch 'ab/grep-patterntype'

Test fix-up for a topic already in master.

* ab/grep-patterntype:
  log tests: fix "abort tests early" regression in ff37a60c369

2 years agosubmodule: fix latent check_has_commit() bug
Glen Choo [Tue, 8 Mar 2022 00:14:33 +0000 (16:14 -0800)] 
submodule: fix latent check_has_commit() bug

When check_has_commit() is called on a missing submodule, initialization
of the struct repository fails, but it attempts to clear the struct
anyway (which is a fatal error). This bug is masked by its only caller,
submodule_has_commits(), first calling add_submodule_odb(). The latter
fails if the submodule does not exist, making submodule_has_commits()
exit early and not invoke check_has_commit().

Fix this bug, and because calling add_submodule_odb() is no longer
necessary as of 13a2f620b2 (submodule: pass repo to
check_has_commit(), 2021-10-08), remove that call too.

This is the last caller of add_submodule_odb(), so remove that
function. (Submodule ODBs are still added as alternates via
add_submodule_odb_by_path().)

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agofetch: fetch unpopulated, changed submodules
Glen Choo [Tue, 8 Mar 2022 00:14:32 +0000 (16:14 -0800)] 
fetch: fetch unpopulated, changed submodules

"git fetch --recurse-submodules" only considers populated
submodules (i.e. submodules that can be found by iterating the index),
which makes "git fetch" behave differently based on which commit is
checked out. As a result, even if the user has initialized all submodules
correctly, they may not fetch the necessary submodule commits, and
commands like "git checkout --recurse-submodules" might fail.

Teach "git fetch" to fetch cloned, changed submodules regardless of
whether they are populated. This is in addition to the current behavior
of fetching populated submodules (which is always attempted regardless
of what was fetched in the superproject, or even if nothing was fetched
in the superproject).

A submodule may be encountered multiple times (via the list of
populated submodules or via the list of changed submodules). When this
happens, "git fetch" only reads the 'populated copy' and ignores the
'changed copy'. Amend the verify_fetch_result() test helper so that we
can assert on which 'copy' is being read.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopartial-clone: add a partial-clone test case
Abhradeep Chakraborty [Wed, 16 Mar 2022 09:46:09 +0000 (09:46 +0000)] 
partial-clone: add a partial-clone test case

In a blobless-cloned repo, `git log --follow -- <path>` (`<path>` have
an exact OID rename) shouldn't download blob of the file from where the
new file is renamed.

Add a test case to verify it.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosequencer: use reverse_commit_list() helper
Jayati Shrivastava [Wed, 16 Mar 2022 11:20:23 +0000 (11:20 +0000)] 
sequencer: use reverse_commit_list() helper

Instead of creating a new allocation, reverse the original list
in-place by calling the reverse_commit_list() helper.

The original code discards the list "bases" after storing its
reverse copy in a newly created list "reversed".  If the code that
followed from here used both "bases" and "reversed", the
modification would not have worked, but since the original list
"bases" gets discarded, we can simply reverse "bases" in-place with
the reverse_commit_list() helper and reuse the same variable in the
code that follows.

builtin/merge.c has been left unmodified, since in its case, the
original list is needed separately from its reverse copy by the
code.

Signed-off-by: Jayati Shrivastava <gaurijove@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocompletion: tab completion of filenames for 'git restore'
David Cantrell [Tue, 15 Mar 2022 22:13:57 +0000 (22:13 +0000)] 
completion: tab completion of filenames for 'git restore'

If no --args are present after 'git restore', it assumes that you
want to tab-complete one of the files with unstaged uncommitted
changes.

If a file has been staged, we don't want to list it, as restoring those
requires a slightly more complex `git restore --staged`, so we only list
those files that are --modified. While --committable also looks like
a good candidate, that includes changes that have been staged.

Signed-off-by: David Cantrell <david@cantrell.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocore.fsync: new option to harden references
Patrick Steinhardt [Fri, 11 Mar 2022 09:58:59 +0000 (10:58 +0100)] 
core.fsync: new option to harden references

When writing both loose and packed references to disk we first create a
lockfile, write the updated values into that lockfile, and on commit we
rename the file into place. According to filesystem developers, this
behaviour is broken because applications should always sync data to disk
before doing the final rename to ensure data consistency [1][2][3]. If
applications fail to do this correctly, a hard crash of the machine can
easily result in corrupted on-disk data.

This kind of corruption can in fact be easily observed with Git when the
machine hard-resets shortly after writing references to disk. On
machines with ext4, this will likely lead to the "empty files" problem:
the file has been renamed, but its data has not been synced to disk. The
result is that the reference is corrupt, and in the worst case this can
lead to data loss.

Implement a new option to harden references so that users and admins can
avoid this scenario by syncing locked loose and packed references to
disk before we rename them into place.

[1]: https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
[2]: https://btrfs.wiki.kernel.org/index.php/FAQ (What are the crash guarantees of overwrite-by-rename)
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/ext4.rst (see auto_da_alloc)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ns/core-fsyncmethod' into ps/fsync-refs
Junio C Hamano [Tue, 15 Mar 2022 20:30:37 +0000 (13:30 -0700)] 
Merge branch 'ns/core-fsyncmethod' into ps/fsync-refs

* ns/core-fsyncmethod:
  core.fsync: documentation and user-friendly aggregate options
  core.fsync: new option to harden the index
  core.fsync: add configuration parsing
  core.fsync: introduce granular fsync control infrastructure
  core.fsyncmethod: add writeout-only mode
  wrapper: make inclusion of Windows csprng header tightly scoped

2 years agocore.fsync: documentation and user-friendly aggregate options
Neeraj Singh [Tue, 15 Mar 2022 19:12:45 +0000 (12:12 -0700)] 
core.fsync: documentation and user-friendly aggregate options

This commit adds aggregate options for the core.fsync setting that are
more user-friendly. These options are specified in terms of 'levels of
safety', indicating which Git operations are considered to be sync
points for durability.

The new documentation is also included here in its entirety for ease of
review.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agomaintenance: fix synopsis in documentation
Derrick Stolee [Tue, 15 Mar 2022 17:41:44 +0000 (17:41 +0000)] 
maintenance: fix synopsis in documentation

The synopsis for 'git maintenance' did not include the commands other
than the 'run' command. Update this to include the others. The 'start'
command is the only one of these that parses additional options, and
then only the --scheduler option.

Also move the 'register' command down after 'stop' and before
'unregister' for a logical grouping of the commands instead of an
alphabetical one. The diff makes it look as three other commands are
moved up.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocat-file: skip expanding default format
John Cai [Tue, 15 Mar 2022 02:40:36 +0000 (02:40 +0000)] 
cat-file: skip expanding default format

When format is passed into --batch, --batch-check, --batch-command,
the format gets expanded. When nothing is passed in, the default format
is set and the expand_format() gets called.

We can save on these cycles by hardcoding how to print the
information when nothing is passed as the format, or when the default
format is passed. There is no need for the fully expanded format with
the default. Since batch_object_write() happens on every object provided
in batch mode, we get a nice performance improvement.

git rev-list --all > /tmp/all-obj.txt

git cat-file --batch-check </tmp/all-obj.txt

with HEAD^:

Time (mean ± σ): 57.6 ms ± 1.7 ms [User: 51.5 ms, System: 6.2 ms]
Range (min … max): 54.6 ms … 64.7 ms 50 runs

with HEAD:

Time (mean ± σ): 49.8 ms ± 1.7 ms [User: 42.6 ms, System: 7.3 ms]
Range (min … max): 46.9 ms … 55.9 ms 56 runs

If nothing is provided as a format argument, or if the default format is
passed, skip expanding of the format and print the object info with a
default format.

See https://lore.kernel.org/git/87eecf8ork.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agostash: make internal resets quiet and refresh index
Victoria Dye [Tue, 15 Mar 2022 01:49:42 +0000 (01:49 +0000)] 
stash: make internal resets quiet and refresh index

Add the options '-q' and '--refresh' to the 'git reset' executed in
'reset_head()', and '--refresh' to the 'git reset -q' executed in
'do_push_stash(...)'.

'stash' is implemented such that git commands invoked  as part of it (e.g.,
'clean', 'read-tree', 'reset', etc.) have their informational output
silenced. However, the 'reset' in 'reset_head()' is *not* called with '-q',
leading to the potential for a misleading printout from 'git stash apply
--index' if the stash included a removed file:

Unstaged changes after reset: D      <deleted file>

Not only is this confusing in its own right (since, after the reset, 'git
stash' execution would stage the deletion in the index), it would be printed
even when the stash was applied with the '-q' option. As a result, the
messaging is removed entirely by calling 'git status' with '-q'.

Additionally, because the default behavior of 'git reset -q' is to skip
refreshing the index, but later operations in 'git stash' subcommands expect
a non-stale index, enable '--refresh' as well.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: suppress '--no-refresh' advice if logging is silenced
Victoria Dye [Tue, 15 Mar 2022 01:49:41 +0000 (01:49 +0000)] 
reset: suppress '--no-refresh' advice if logging is silenced

If using '--quiet' or 'reset.quiet=true', do not print the 'resetnoRefresh'
advice string. For applications that rely on '--quiet' disabling all
non-error logs, the advice message should be suppressed accordingly.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: replace '--quiet' with '--no-refresh' in performance advice
Victoria Dye [Tue, 15 Mar 2022 01:49:40 +0000 (01:49 +0000)] 
reset: replace '--quiet' with '--no-refresh' in performance advice

Replace references to '--quiet' with '--no-refresh' in the advice on how to
skip refreshing the index. When the advice was introduced, '--quiet' was the
only way to avoid the expensive 'refresh_index(...)' at the end of a mixed
reset. After introducing '--no-refresh', however, '--quiet' became only a
fallback option for determining refresh behavior, overridden by
'--[no-]refresh' or 'reset.refresh' if either is set. To ensure users are
advised to use the most reliable option for avoiding 'refresh_index(...)',
replace recommendation of '--quiet' with '--[no-]refresh'.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: introduce --[no-]refresh option to --mixed
Victoria Dye [Tue, 15 Mar 2022 01:49:39 +0000 (01:49 +0000)] 
reset: introduce --[no-]refresh option to --mixed

Add a new --[no-]refresh option that is intended to explicitly determine
whether a mixed reset should end in an index refresh.

Starting at 9ac8125d1a (reset: don't compute unstaged changes after reset
when --quiet, 2018-10-23), using the '--quiet' option results in skipping
the call to 'refresh_index(...)' at the end of a mixed reset with the goal
of improving performance. However, by coupling behavior that modifies the
index with the option that silences logs, there is no way for users to have
one without the other (i.e., silenced logs with a refreshed index) without
incurring the overhead of a separate call to 'git update-index --refresh'.
Furthermore, there is minimal user-facing documentation indicating that
--quiet skips the index refresh, potentially leading to unexpected issues
executing commands after 'git reset --quiet' that do not themselves refresh
the index (e.g., internals of 'git stash', 'git read-tree').

To mitigate these issues, '--[no-]refresh' and 'reset.refresh' are
introduced to provide a dedicated mechanism for refreshing the index. When
either is set, '--quiet' and 'reset.quiet' revert to controlling only
whether logs are silenced and do not affect index refresh.

Helped-by: Derrick Stolee <derrickstolee@github.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreset: revise index refresh advice
Victoria Dye [Tue, 15 Mar 2022 01:49:38 +0000 (01:49 +0000)] 
reset: revise index refresh advice

Update the advice describing index refresh from "enumerate unstaged changes"
to "refresh the index." Describing 'refresh_index(...)' as "enumerating
unstaged changes" is not fully representative of what an index refresh is
doing; more generally, it updates the properties of index entries that are
affected by outside-of-index state, e.g. CE_UPTODATE, which is affected by
the file contents on-disk. This distinction is relevant to operations that
read the index but do not refresh first - e.g., 'git read-tree' - where a
stale index may cause incorrect behavior.

In addition to changing the advice message, use the "advise" function to
print advice.

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorepack: add config to skip updating server info
Patrick Steinhardt [Mon, 14 Mar 2022 07:42:51 +0000 (08:42 +0100)] 
repack: add config to skip updating server info

By default, git-repack(1) will update server info that is required by
the dumb HTTP transport. This can be skipped by passing the `-n` flag,
but what we're noticably missing is a config option to permanently
disable updating this information.

Add a new option "repack.updateServerInfo" which can be used to disable
the logic. Most hosting providers have turned off the dumb HTTP protocol
anyway, and on the client-side it woudln't typically be useful either.
Giving a persistent way to disable this feature thus makes quite some
sense to avoid wasting compute cycles and storage.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorepack: refactor to avoid double-negation of update-server-info
Patrick Steinhardt [Mon, 14 Mar 2022 07:42:46 +0000 (08:42 +0100)] 
repack: refactor to avoid double-negation of update-server-info

By default, git-repack(1) runs `update_server_info()` to generate info
required for the dumb HTTP protocol. This can be disabled via the `-n`
flag, which then sets the `no_update_server_info` flag. Further down the
code this leads to some double-negation logic, which is about to become
more confusing as we're about to add a new config which allows the user
to permanently disable generation of the info.

Refactor the code to avoid the double-negation and add some tests which
verify that the flag continues to work as expected.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoattr.h: remove duplicate struct definition
Elia Pinto [Mon, 14 Mar 2022 00:23:27 +0000 (00:23 +0000)] 
attr.h: remove duplicate struct definition

struct index_state is declared more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe eleventh batch
Junio C Hamano [Sun, 13 Mar 2022 22:50:24 +0000 (22:50 +0000)] 
The eleventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/plug-random-leaks'
Junio C Hamano [Sun, 13 Mar 2022 22:56:18 +0000 (22:56 +0000)] 
Merge branch 'ab/plug-random-leaks'

Plug random memory leaks.

* ab/plug-random-leaks:
  repository.c: free the "path cache" in repo_clear()
  range-diff: plug memory leak in read_patches()
  range-diff: plug memory leak in common invocation
  lockfile API users: simplify and don't leak "path"
  commit-graph: stop fill_oids_from_packs() progress on error and free()
  commit-graph: fix memory leak in misused string_list API
  submodule--helper: fix trivial leak in module_add()
  transport: stop needlessly copying bundle header references
  bundle: call strvec_clear() on allocated strvec
  remote-curl.c: free memory in cmd_main()
  urlmatch.c: add and use a *_release() function
  diff.c: free "buf" in diff_words_flush()
  merge-base: free() allocated "struct commit **" list
  index-pack: fix memory leaks

2 years agoMerge branch 'nj/read-tree-doc-reffix'
Junio C Hamano [Sun, 13 Mar 2022 22:56:18 +0000 (22:56 +0000)] 
Merge branch 'nj/read-tree-doc-reffix'

Documentation mark-up fix.

* nj/read-tree-doc-reffix:
  Documentation: git-read-tree: separate links using commas

2 years agoMerge branch 'ps/fetch-atomic-fixup'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'ps/fetch-atomic-fixup'

Test simplification.

* ps/fetch-atomic-fixup:
  t5503: simplify setup of test which exercises failure of backfill

2 years agoMerge branch 'fs/gpgsm-update'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'fs/gpgsm-update'

Newer version of GPGSM changed its output in a backward
incompatible way to break our code that parses its output.  It also
added more processes our tests need to kill when cleaning up.
Adjustments have been made to accommodate these changes.

* fs/gpgsm-update:
  t/lib-gpg: kill all gpg components, not just gpg-agent
  t/lib-gpg: reload gpg components after updating trustlist
  gpg-interface/gpgsm: fix for v2.3

2 years agoMerge branch 'gc/parse-tree-indirect-errors'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'gc/parse-tree-indirect-errors'

Check the return value from parse_tree_indirect() to turn segfaults
into calls to die().

* gc/parse-tree-indirect-errors:
  checkout, clone: die if tree cannot be parsed

2 years agoMerge branch 'en/merge-ort-align-verbosity-with-recursive'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'en/merge-ort-align-verbosity-with-recursive'

Align the level of verbose output from the ort backend during inner
merge to that of the recursive backend.

* en/merge-ort-align-verbosity-with-recursive:
  merge-ort: exclude messages from inner merges by default

2 years agoMerge branch 'ab/make-optim-noop'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'ab/make-optim-noop'

Makefile refactoring with a bit of suffixes rule stripping to
optimize the runtime overhead.

* ab/make-optim-noop:
  Makefiles: add and use wildcard "mkdir -p" template
  Makefile: add "$(QUIET)" boilerplate to shared.mak
  Makefile: move $(comma), $(empty) and $(space) to shared.mak
  Makefile: move ".SUFFIXES" rule to shared.mak
  Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES)
  Makefile: disable GNU make built-in wildcard rules
  Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it
  scalar Makefile: use "The default target of..." pattern

2 years agoMerge branch 'ps/fetch-atomic'
Junio C Hamano [Sun, 13 Mar 2022 22:56:16 +0000 (22:56 +0000)] 
Merge branch 'ps/fetch-atomic'

"git fetch" can make two separate fetches, but ref updates coming
from them were in two separate ref transactions under "--atomic",
which has been corrected.

* ps/fetch-atomic:
  fetch: make `--atomic` flag cover pruning of refs
  fetch: make `--atomic` flag cover backfilling of tags
  refs: add interface to iterate over queued transactional updates
  fetch: report errors when backfilling tags fails
  fetch: control lifecycle of FETCH_HEAD in a single place
  fetch: backfill tags before setting upstream
  fetch: increase test coverage of fetches

2 years agot/helper/test-run-command.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:36 +0000 (19:55 +0000)] 
t/helper/test-run-command.c: delete duplicate include

parse-options.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/stash.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:35 +0000 (19:55 +0000)] 
builtin/stash.c: delete duplicate include

 entry.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/sparse-checkout.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:34 +0000 (19:55 +0000)] 
builtin/sparse-checkout.c: delete duplicate include

cache.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/gc.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:33 +0000 (19:55 +0000)] 
builtin/gc.c: delete duplicate include

object-store.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoattr.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:32 +0000 (19:55 +0000)] 
attr.c: delete duplicate include

dir.h is included more than once

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot6423-merge-rename-directories.sh: use the $(...) construct
Elia Pinto [Sun, 13 Mar 2022 17:28:29 +0000 (17:28 +0000)] 
t6423-merge-rename-directories.sh: use the $(...) construct

The Git CodingGuidelines prefer the $(...) construct for command
substitution instead of using the backquotes `...`.

The backquoted form is the traditional method for command
substitution, and is supported by POSIX.  However, all but the
simplest uses become complicated quickly.  In particular, embedded
command substitutions and/or the use of double quotes require
careful escaping with the backslash character.

The patch was generated by:

for _f in $(find . -name "*.sh")
do
shellcheck -i SC2006 -f diff ${_f} | ifne git apply -p2
done

and then carefully proof-read.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoname-rev: use generation numbers if available
Jacob Keller [Sat, 12 Mar 2022 00:00:15 +0000 (16:00 -0800)] 
name-rev: use generation numbers if available

If a commit in a sequence of linear history has a non-monotonically
increasing commit timestamp, git name-rev might not properly name the
commit.

This occurs because name-rev uses a heuristic of the commit date to
avoid searching down tags which lead to commits that are older than the
named commit. This is intended to avoid work on larger repositories.

This heuristic impacts git name-rev, and by extension git describe
--contains which is built on top of name-rev.

Further more, if --all or --annotate-stdin is used, the heuristic is not
enabled because the full history has to be analyzed anyways. This
results in some confusion if a user sees that --annotate-stdin works but
a normal name-rev does not.

If the repository has a commit graph, we can use the generation numbers
instead of using the commit dates. This is essentially the same check
except that generation numbers make it exact, where the commit date
heuristic could be incorrect due to clock errors.

Since we're extending the notion of cutoff to more than one variable,
create a series of functions for setting and checking the cutoff. This
avoids duplication and moves access of the global cutoff and
generation_cutoff to as few functions as possible.

Add several test cases including a test that covers the new commitGraph
behavior, as well as tests for --all and --annotate-stdin with and
without commitGraphs.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreflog: don't be noisy on empty reflogs
Ævar Arnfjörð Bjarmason [Thu, 10 Mar 2022 22:56:11 +0000 (23:56 +0100)] 
reflog: don't be noisy on empty reflogs

Fix a regression in my daf1d8285ee (reflog expire: don't use
lookup_commit_reference_gently(), 2021-12-22), in changing from
lookup_commit_reference_gently() to lookup_commit() we stopped trying
to call deref_tag() and parse_object() on the provided OID, but we
also started returning non-NULL for the null_oid().

As a result we'd emit an error() via mark_reachable() later in this
function as we tried to invoke parse_commit() on it.

Reported-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agouserdiff: add builtin diff driver for kotlin language.
Jaydeep P Das [Sat, 12 Mar 2022 04:48:32 +0000 (10:18 +0530)] 
userdiff: add builtin diff driver for kotlin language.

The xfuncname pattern finds func/class declarations
in diffs to display as a hunk header. The word_regex
pattern finds individual tokens in Kotlin code to generate
appropriate diffs.

This patch adds xfuncname regex and word_regex for Kotlin
language.

Signed-off-by: Jaydeep P Das <jaydeepjd.8914@gmail.com>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>