]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
2 years agogrep: refactor next_match() and match_one_pattern() for external use
Hamza Mahfooz [Wed, 29 Sep 2021 11:57:15 +0000 (07:57 -0400)] 
grep: refactor next_match() and match_one_pattern() for external use

These changes are made in preparation of, the colorization support for the
"git log" subcommands that, rely on regex functionality (i.e. "--author",
"--committer" and "--grep"). These changes are necessary primarily because
match_one_pattern() expects header lines to be prefixed, however, in
pretty, the prefixes are stripped from the lines because the name-email
pairs need to go through additional parsing, before they can be printed and
because next_match() doesn't handle the case of
"ctx == GREP_CONTEXT_HEAD" at all. So, teach next_match() how to handle the
new case and move match_one_pattern()'s core logic to
headerless_match_one_pattern() while preserving match_one_pattern()'s uses
that depend on the additional processing.

Signed-off-by: Hamza Mahfooz <someguy@effective-light.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jk/grep-haystack-is-read-only' into hm/paint-hits-in-log-grep
Junio C Hamano [Thu, 23 Sep 2021 16:47:05 +0000 (09:47 -0700)] 
Merge branch 'jk/grep-haystack-is-read-only' into hm/paint-hits-in-log-grep

* jk/grep-haystack-is-read-only:
  grep: store grep_source buffer as const
  grep: mark "haystack" buffers as const
  grep: stop modifying buffer in grep_source_1()
  grep: stop modifying buffer in show_line()
  grep: stop modifying buffer in strip_timestamp

2 years agogrep: store grep_source buffer as const
Jeff King [Tue, 21 Sep 2021 03:51:28 +0000 (23:51 -0400)] 
grep: store grep_source buffer as const

Our grep_buffer() function takes a non-const buffer, which is confusing:
we don't take ownership of nor write to the buffer.

This mostly comes from the fact that the underlying grep_source struct
in which we store the buffer uses non-const pointer. The memory pointed
to by the struct is sometimes owned by us (for FILE or OID sources), and
sometimes not (for BUF sources).

Let's store it as const, which lets us err on the side of caution (i.e.,
the compiler will warn us if any of our code writes to or tries to free
it).

As a result, we must annotate the one place where we do free it by
casting away the constness. But that's a small price to pay for the
extra safety and clarity elsewhere (and indeed, it already had a comment
explaining why GREP_SOURCE_BUF _didn't_ free it).

And then we can mark grep_buffer() as taking a const buffer.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogrep: mark "haystack" buffers as const
Jeff King [Tue, 21 Sep 2021 03:49:49 +0000 (23:49 -0400)] 
grep: mark "haystack" buffers as const

When we're grepping in a buffer, we don't need to modify it. So we can
take "const char *" buffers, rather than "char *". This can avoid some
awkward casts in our callers, and make our expectations more clear (we
will not take ownership of the memory, nor will we ever write to it).

These spots don't all necessarily have to be converted at the same time,
but some of them are dependent on others, because we pass
pointers-to-pointers in a few cases. And none of this should change any
behavior, since we're just adding "const" qualifiers (and likewise, the
compiler will let us know if we missed any spots). So it's relatively
low-risk to just do this all at once.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogrep: stop modifying buffer in grep_source_1()
Jeff King [Tue, 21 Sep 2021 03:48:44 +0000 (23:48 -0400)] 
grep: stop modifying buffer in grep_source_1()

We find the end of each matching line of a buffer, and then temporarily
write a NUL to turn it into a regular C string. But we don't need to do
so, because the only thing we do in the interim is pass the line and its
length (via an "eol" pointer) to match_line(). And that function should
only look at the bytes we passed it, whether it has a terminating NUL or
not.

We can drop this temporary write in order to simplify the code and make
it easier to use const buffers in more of grep.c.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogrep: stop modifying buffer in show_line()
Jeff King [Tue, 21 Sep 2021 03:48:09 +0000 (23:48 -0400)] 
grep: stop modifying buffer in show_line()

When showing lines via grep (or looking for funcnames), we call
show_line() on a multi-line buffer. It finds the end of line and marks
it with a NUL. However, we don't need to do so, as the resulting line is
only used along with its "eol" marker:

 - we pass both to next_match(), which takes care to look at only the
   bytes we specified

 - we pass the line to output_color() without its matching eol marker.
   However, we do use the "match" struct we got from next_match() to
   tell it how many bytes to look at (which can never exceed the string
   we passed it).

So we can stop setting and restoring this NUL marker. That makes the
code simpler, and will allow us to take a const buffer in a future
patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agogrep: stop modifying buffer in strip_timestamp
Jeff King [Tue, 21 Sep 2021 03:46:56 +0000 (23:46 -0400)] 
grep: stop modifying buffer in strip_timestamp

When grepping for headers in commit objects, we receive individual
lines (e.g., "author Name <email> 1234 -0000"), and then strip off the
timestamp to do our match. We do so by writing a NUL byte over the
whitespace separator, and then remembering to restore it later.

We had to do it this way when this was added back in a4d7d2c6db (log
--author/--committer: really match only with name part, 2008-09-04),
because we fed the result directly to regexec(), which expects a
NUL-terminated string. But since b7d36ffca0 (regex: use regexec_buf(),
2016-09-21), we have a function which can match part of a buffer.

So instead of modifying the string, we can instead just move the "eol"
pointer, and the rest of the code will do the right thing. This will let
further patches mark more buffers as "const".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe seventh batch
Junio C Hamano [Mon, 20 Sep 2021 22:09:44 +0000 (15:09 -0700)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jk/t5562-racefix'
Junio C Hamano [Mon, 20 Sep 2021 22:20:46 +0000 (15:20 -0700)] 
Merge branch 'jk/t5562-racefix'

Test update.

* jk/t5562-racefix:
  t5562: use alarm() to interrupt timed child-wait

2 years agoMerge branch 'rs/no-mode-to-open-when-appending'
Junio C Hamano [Mon, 20 Sep 2021 22:20:45 +0000 (15:20 -0700)] 
Merge branch 'rs/no-mode-to-open-when-appending'

The "mode" word is useless in a call to open(2) that does not
create a new file.  Such a call in the files backend of the ref
subsystem has been cleaned up.

* rs/no-mode-to-open-when-appending:
  refs/files-backend: remove unused open mode parameter

2 years agoMerge branch 'rs/setup-use-xopen-and-xdup'
Junio C Hamano [Mon, 20 Sep 2021 22:20:45 +0000 (15:20 -0700)] 
Merge branch 'rs/setup-use-xopen-and-xdup'

Code clean-up.

* rs/setup-use-xopen-and-xdup:
  setup: use xopen and xdup in sanitize_stdfds

2 years agoMerge branch 'js/run-command-close-packs'
Junio C Hamano [Mon, 20 Sep 2021 22:20:45 +0000 (15:20 -0700)] 
Merge branch 'js/run-command-close-packs'

The run-command API has been updated so that the callers can easily
ask the file descriptors open for packfiles to be closed immediately
before spawning commands that may trigger auto-gc.

* js/run-command-close-packs:
  Close object store closer to spawning child processes
  run_auto_maintenance(): implicitly close the object store
  run-command: offer to close the object store before running
  run-command: prettify the `RUN_COMMAND_*` flags
  pull: release packs before fetching
  commit-graph: when closing the graph, also release the slab

2 years agoMerge branch 'ds/mergies-with-sparse-index'
Junio C Hamano [Mon, 20 Sep 2021 22:20:44 +0000 (15:20 -0700)] 
Merge branch 'ds/mergies-with-sparse-index'

Various mergy operations have been prepared to work efficiently
with the sparse index.

* ds/mergies-with-sparse-index:
  sparse-index: integrate with cherry-pick and rebase
  sequencer: ensure full index if not ORT strategy
  t1092: add cherry-pick, rebase tests
  merge-ort: expand only for out-of-cone conflicts
  merge: make sparse-aware with ORT
  diff: ignore sparse paths in diffstat

2 years agoMerge branch 'ds/sparse-index-ignored-files'
Junio C Hamano [Mon, 20 Sep 2021 22:20:44 +0000 (15:20 -0700)] 
Merge branch 'ds/sparse-index-ignored-files'

In cone mode, the sparse-index code path learned to remove ignored
files (like build artifacts) outside the sparse cone, allowing the
entire directory outside the sparse cone to be removed, which is
especially useful when the sparse patterns change.

* ds/sparse-index-ignored-files:
  sparse-checkout: clear tracked sparse dirs
  sparse-index: add SPARSE_INDEX_MEMORY_ONLY flag
  attr: be careful about sparse directories
  sparse-checkout: create helper methods
  sparse-index: use WRITE_TREE_MISSING_OK
  sparse-index: silently return when cache tree fails
  unpack-trees: fix nested sparse-dir search
  sparse-index: silently return when not using cone-mode patterns
  t7519: rewrite sparse index test

2 years agoMerge branch 'ar/submodule-run-update-procedure'
Junio C Hamano [Mon, 20 Sep 2021 22:20:44 +0000 (15:20 -0700)] 
Merge branch 'ar/submodule-run-update-procedure'

Reimplementation of parts of "git submodule" in C continues.

* ar/submodule-run-update-procedure:
  submodule--helper: run update procedures from C

2 years agoMerge branch 'ab/make-tags-cleanup'
Junio C Hamano [Mon, 20 Sep 2021 22:20:43 +0000 (15:20 -0700)] 
Merge branch 'ab/make-tags-cleanup'

Build clean-up for "make tags" and friends.

* ab/make-tags-cleanup:
  Makefile: normalize clobbering & xargs for tags targets
  Makefile: remove "cscope.out", not "cscope*" in cscope.out target
  Makefile: don't use "FORCE" for tags targets
  Makefile: add QUIET_GEN to "cscope" target
  Makefile: move ".PHONY: cscope" near its target

2 years agoMerge branch 'ab/serve-cleanup'
Junio C Hamano [Mon, 20 Sep 2021 22:20:43 +0000 (15:20 -0700)] 
Merge branch 'ab/serve-cleanup'

Code clean-up around "git serve".

* ab/serve-cleanup:
  upload-pack: document and rename --advertise-refs
  serve.[ch]: remove "serve_options", split up --advertise-refs code
  {upload,receive}-pack tests: add --advertise-refs tests
  serve.c: move version line to advertise_capabilities()
  serve: move transfer.advertiseSID check into session_id_advertise()
  serve.[ch]: don't pass "struct strvec *keys" to commands
  serve: use designated initializers
  transport: use designated initializers
  transport: rename "fetch" in transport_vtable to "fetch_refs"
  serve: mark has_capability() as static

2 years agoMerge branch 'ar/submodule-add-more'
Junio C Hamano [Mon, 20 Sep 2021 22:20:43 +0000 (15:20 -0700)] 
Merge branch 'ar/submodule-add-more'

More parts of "git submodule add" has been rewritten in C.

* ar/submodule-add-more:
  submodule--helper: rename compute_submodule_clone_url()
  submodule--helper: remove resolve-relative-url subcommand
  submodule--helper: remove add-config subcommand
  submodule--helper: remove add-clone subcommand
  submodule--helper: convert the bulk of cmd_add() to C
  dir: libify and export helper functions from clone.c
  submodule--helper: remove repeated code in sync_submodule()
  submodule--helper: refactor resolve_relative_url() helper
  submodule--helper: add options for compute_submodule_clone_url()

2 years agoMerge branch 'ar/submodule-add-config'
Junio C Hamano [Mon, 20 Sep 2021 22:20:42 +0000 (15:20 -0700)] 
Merge branch 'ar/submodule-add-config'

Large part of "git submodule add" gets rewritten in C.

* ar/submodule-add-config:
  submodule--helper: introduce add-config subcommand

2 years agoMerge branch 'ab/unbundle-progress'
Junio C Hamano [Mon, 20 Sep 2021 22:20:42 +0000 (15:20 -0700)] 
Merge branch 'ab/unbundle-progress'

Add progress display to "git bundle unbundle".

* ab/unbundle-progress:
  bundle: show progress on "unbundle"
  index-pack: add --progress-title option
  bundle API: change "flags" to be "extra_index_pack_args"
  bundle API: start writing API documentation

2 years agoMerge branch 'tb/pack-finalize-ordering'
Junio C Hamano [Mon, 20 Sep 2021 22:20:42 +0000 (15:20 -0700)] 
Merge branch 'tb/pack-finalize-ordering'

The order in which various files that make up a single (conceptual)
packfile has been reevaluated and straightened up.  This matters in
correctness, as an incomplete set of files must not be shown to a
running Git.

* tb/pack-finalize-ordering:
  pack-objects: rename .idx files into place after .bitmap files
  pack-write: split up finish_tmp_packfile() function
  builtin/index-pack.c: move `.idx` files into place last
  index-pack: refactor renaming in final()
  builtin/repack.c: move `.idx` files into place last
  pack-write.c: rename `.idx` files after `*.rev`
  pack-write: refactor renaming in finish_tmp_packfile()
  bulk-checkin.c: store checksum directly
  pack.h: line-wrap the definition of finish_tmp_packfile()

2 years agoMerge branch 'cb/pedantic-build-for-developers'
Junio C Hamano [Mon, 20 Sep 2021 22:20:41 +0000 (15:20 -0700)] 
Merge branch 'cb/pedantic-build-for-developers'

Update the build procedure to use the "-pedantic" build when
DEVELOPER makefile macro is in effect.

* cb/pedantic-build-for-developers:
  developer: enable pedantic by default
  win32: allow building with pedantic mode enabled
  gettext: remove optional non-standard parens in N_() definition

2 years agoMerge branch 'ab/progress-users-adjust-counters'
Junio C Hamano [Mon, 20 Sep 2021 22:20:41 +0000 (15:20 -0700)] 
Merge branch 'ab/progress-users-adjust-counters'

The code to show progress indicator in a few code paths did not
cover between 0-100%, which has been corrected.

* ab/progress-users-adjust-counters:
  entry: show finer-grained counter in "Filtering content" progress line
  commit-graph: fix bogus counter in "Scanning merged commits" progress line

2 years agoMerge branch 'dt/submodule-diff-fixes'
Junio C Hamano [Mon, 20 Sep 2021 22:20:41 +0000 (15:20 -0700)] 
Merge branch 'dt/submodule-diff-fixes'

"git diff --submodule=diff" showed failure from run_command() when
trying to run diff inside a submodule, when the user manually
removes the submodule directory.

* dt/submodule-diff-fixes:
  diff --submodule=diff: don't print failure message twice
  diff --submodule=diff: do not fail on ever-initialied deleted submodules
  t4060: remove unused variable

2 years agoMerge branch 'jv/pkt-line-batch'
Junio C Hamano [Mon, 20 Sep 2021 22:20:40 +0000 (15:20 -0700)] 
Merge branch 'jv/pkt-line-batch'

Reduce number of write(2) system calls while sending the
ref advertisement.

* jv/pkt-line-batch:
  upload-pack: use stdio in send_ref callbacks
  pkt-line: add stdio packet write functions

2 years agoMerge branch 'lh/systemd-timers'
Junio C Hamano [Mon, 20 Sep 2021 22:20:40 +0000 (15:20 -0700)] 
Merge branch 'lh/systemd-timers'

"git maintenance" scheduler learned to use systemd timers as a
possible backend.

* lh/systemd-timers:
  maintenance: add support for systemd timers on Linux
  maintenance: `git maintenance run` learned `--scheduler=<scheduler>`
  cache.h: Introduce a generic "xdg_config_home_for(…)" function

2 years agoMerge branch 'ab/tr2-leaks-and-fixes'
Junio C Hamano [Mon, 20 Sep 2021 22:20:40 +0000 (15:20 -0700)] 
Merge branch 'ab/tr2-leaks-and-fixes'

The tracing of process ancestry information has been enhanced.

* ab/tr2-leaks-and-fixes:
  tr2: log N parent process names on Linux
  tr2: do compiler enum check in trace2_collect_process_info()
  tr2: leave the parent list empty upon failure & don't leak memory
  tr2: stop leaking "thread_name" memory
  tr2: clarify TRACE2_PROCESS_INFO_EXIT comment under Linux
  tr2: remove NEEDSWORK comment for "non-procfs" implementations

2 years agoMerge branch 'jt/grep-wo-submodule-odb-as-alternate'
Junio C Hamano [Mon, 20 Sep 2021 22:20:39 +0000 (15:20 -0700)] 
Merge branch 'jt/grep-wo-submodule-odb-as-alternate'

The code to make "git grep" recurse into submodules has been
updated to migrate away from the "add submodule's object store as
an alternate object store" mechanism (which is suboptimal).

* jt/grep-wo-submodule-odb-as-alternate:
  t7814: show lack of alternate ODB-adding
  submodule-config: pass repo upon blob config read
  grep: add repository to OID grep sources
  grep: allocate subrepos on heap
  grep: read submodule entry with explicit repo
  grep: typesafe versions of grep_source_init
  grep: use submodule-ODB-as-alternate lazy-addition
  submodule: lazily add submodule ODBs as alternates

2 years agoMerge branch 'tb/multi-pack-bitmaps'
Junio C Hamano [Mon, 20 Sep 2021 22:20:39 +0000 (15:20 -0700)] 
Merge branch 'tb/multi-pack-bitmaps'

The reachability bitmap file used to be generated only for a single
pack, but now we've learned to generate bitmaps for history that
span across multiple packfiles.

* tb/multi-pack-bitmaps: (29 commits)
  pack-bitmap: drop bitmap_index argument from try_partial_reuse()
  pack-bitmap: drop repository argument from prepare_midx_bitmap_git()
  p5326: perf tests for MIDX bitmaps
  p5310: extract full and partial bitmap tests
  midx: respect 'GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP'
  t7700: update to work with MIDX bitmap test knob
  t5319: don't write MIDX bitmaps in t5319
  t5310: disable GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP
  t0410: disable GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP
  t5326: test multi-pack bitmap behavior
  t/helper/test-read-midx.c: add --checksum mode
  t5310: move some tests to lib-bitmap.sh
  pack-bitmap: write multi-pack bitmaps
  pack-bitmap: read multi-pack bitmaps
  pack-bitmap.c: avoid redundant calls to try_partial_reuse
  pack-bitmap.c: introduce 'bitmap_is_preferred_refname()'
  pack-bitmap.c: introduce 'nth_bitmap_object_oid()'
  pack-bitmap.c: introduce 'bitmap_num_objects()'
  midx: avoid opening multiple MIDXs when writing
  midx: close linked MIDXs, avoid leaking memory
  ...

2 years agoMerge branch 'ps/fetch-optim'
Junio C Hamano [Mon, 20 Sep 2021 22:20:39 +0000 (15:20 -0700)] 
Merge branch 'ps/fetch-optim'

Optimize code that handles large number of refs in the "git fetch"
code path.

* ps/fetch-optim:
  fetch: avoid second connectivity check if we already have all objects
  fetch: merge fetching and consuming refs
  fetch: refactor fetch refs to be more extendable
  fetch-pack: optimize loading of refs via commit graph
  connected: refactor iterator to return next object ID directly
  fetch: avoid unpacking headers in object existence check
  fetch: speed up lookup of want refs via commit-graph

2 years agoThe sixth batch
Junio C Hamano [Wed, 15 Sep 2021 20:15:09 +0000 (13:15 -0700)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jc/prefix-filename-allocates'
Junio C Hamano [Wed, 15 Sep 2021 20:15:28 +0000 (13:15 -0700)] 
Merge branch 'jc/prefix-filename-allocates'

Leakfix.

* jc/prefix-filename-allocates:
  hash-object: prefix_filename() returns allocated memory these days

2 years agoMerge branch 'rs/range-diff-avoid-segfault-with-I'
Junio C Hamano [Wed, 15 Sep 2021 20:15:27 +0000 (13:15 -0700)] 
Merge branch 'rs/range-diff-avoid-segfault-with-I'

"git range-diff -I... <range> <range>" segfaulted, which has been
corrected.

* rs/range-diff-avoid-segfault-with-I:
  range-diff: avoid segfault with -I

2 years agoMerge branch 'ab/reverse-midx-optim'
Junio C Hamano [Wed, 15 Sep 2021 20:15:27 +0000 (13:15 -0700)] 
Merge branch 'ab/reverse-midx-optim'

The code that optionally creates the *.rev reverse index file has
been optimized to avoid needless computation when it is not writing
the file out.

* ab/reverse-midx-optim:
  pack-write: skip *.rev work when not writing *.rev

2 years agoMerge branch 'bs/install-strip'
Junio C Hamano [Wed, 15 Sep 2021 20:15:26 +0000 (13:15 -0700)] 
Merge branch 'bs/install-strip'

"make INSTALL_STRIP=-s install" allows the installation step to use
"install -s" to strip the binaries as they get installed.

* bs/install-strip:
  make: add INSTALL_STRIP option variable

2 years agoMerge branch 'pb/test-use-user-env'
Junio C Hamano [Wed, 15 Sep 2021 20:15:26 +0000 (13:15 -0700)] 
Merge branch 'pb/test-use-user-env'

Teach "test_pause" and "debug" helpers to allow using the HOME and
TERM environment variables the user usually uses.

* pb/test-use-user-env:
  test-lib-functions: keep user's debugger config files and TERM in 'debug'
  test-lib-functions: optionally keep HOME, TERM and SHELL in 'test_pause'
  test-lib-functions: use 'TEST_SHELL_PATH' in 'test_pause'

2 years agoMerge branch 'jc/trivial-threeway-binary-merge'
Junio C Hamano [Wed, 15 Sep 2021 20:15:26 +0000 (13:15 -0700)] 
Merge branch 'jc/trivial-threeway-binary-merge'

The "git apply -3" code path learned not to bother the lower level
merge machinery when the three-way merge can be trivially resolved
without the content level merge.

* jc/trivial-threeway-binary-merge:
  apply: resolve trivial merge without hitting ll-merge with "--3way"

2 years agoMerge branch 'bs/doc-bugreport-outdir'
Junio C Hamano [Wed, 15 Sep 2021 20:15:25 +0000 (13:15 -0700)] 
Merge branch 'bs/doc-bugreport-outdir'

Docfix.

* bs/doc-bugreport-outdir:
  Documentation: fix default directory of git bugreport -o

2 years agoMerge branch 'ab/no-more-check-bindir'
Junio C Hamano [Wed, 15 Sep 2021 20:15:25 +0000 (13:15 -0700)] 
Merge branch 'ab/no-more-check-bindir'

Build simplification.

* ab/no-more-check-bindir:
  Makefile: remove the check_bindir script

2 years agoMerge branch 'ab/send-email-config-fix'
Junio C Hamano [Wed, 15 Sep 2021 20:15:24 +0000 (13:15 -0700)] 
Merge branch 'ab/send-email-config-fix'

Regression fix.

* ab/send-email-config-fix:
  send-email: fix a "first config key wins" regression in v2.33.0

2 years agoMerge branch 'so/diff-index-regression-fix'
Junio C Hamano [Wed, 15 Sep 2021 20:15:24 +0000 (13:15 -0700)] 
Merge branch 'so/diff-index-regression-fix'

Recent "diff -m" changes broke "gitk", which has been corrected.

* so/diff-index-regression-fix:
  diff-index: restore -c/--cc options handling

2 years agoThe fifth batch
Junio C Hamano [Fri, 10 Sep 2021 18:47:10 +0000 (11:47 -0700)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/help-autocorrect-prompt'
Junio C Hamano [Fri, 10 Sep 2021 18:46:33 +0000 (11:46 -0700)] 
Merge branch 'ab/help-autocorrect-prompt'

The logic for auto-correction of misspelt subcommands learned to go
interactive when the help.autocorrect configuration variable is set
to 'prompt'.

* ab/help-autocorrect-prompt:
  help.c: help.autocorrect=prompt waits for user action

2 years agoMerge branch 'cb/ci-build-pedantic'
Junio C Hamano [Fri, 10 Sep 2021 18:46:32 +0000 (11:46 -0700)] 
Merge branch 'cb/ci-build-pedantic'

CI update.

* cb/ci-build-pedantic:
  ci: run a pedantic build as part of the GitHub workflow

2 years agoMerge branch 'gh/gitweb-branch-sort'
Junio C Hamano [Fri, 10 Sep 2021 18:46:31 +0000 (11:46 -0700)] 
Merge branch 'gh/gitweb-branch-sort'

Tie-break branches that point at the same object in the list of
branches on GitWeb to show the one pointed at by HEAD early.

* gh/gitweb-branch-sort:
  gitweb: use HEAD as secondary sort key in git_get_heads_list()

2 years agoMerge branch 'rs/archive-use-object-id'
Junio C Hamano [Fri, 10 Sep 2021 18:46:31 +0000 (11:46 -0700)] 
Merge branch 'rs/archive-use-object-id'

Code cleanup.

* rs/archive-use-object-id:
  archive: convert queue_directory to struct object_id

2 years agoMerge branch 'rs/show-branch-simplify'
Junio C Hamano [Fri, 10 Sep 2021 18:46:30 +0000 (11:46 -0700)] 
Merge branch 'rs/show-branch-simplify'

Code cleanup.

* rs/show-branch-simplify:
  show-branch: simplify rev_is_head()

2 years agoMerge branch 'jk/log-warn-on-bogus-encoding'
Junio C Hamano [Fri, 10 Sep 2021 18:46:30 +0000 (11:46 -0700)] 
Merge branch 'jk/log-warn-on-bogus-encoding'

Doc update plus improved error reporting.

* jk/log-warn-on-bogus-encoding:
  docs: use "character encoding" to refer to commit-object encoding
  logmsg_reencode(): warn when iconv() fails

2 years agoMerge branch 'cb/remote-ndebug-fix'
Junio C Hamano [Fri, 10 Sep 2021 18:46:30 +0000 (11:46 -0700)] 
Merge branch 'cb/remote-ndebug-fix'

Build fix.

* cb/remote-ndebug-fix:
  remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG

2 years agoMerge branch 'ab/retire-advice-config'
Junio C Hamano [Fri, 10 Sep 2021 18:46:29 +0000 (11:46 -0700)] 
Merge branch 'ab/retire-advice-config'

Code clean up to migrate callers from older advice_config[] based
API to newer advice_if_enabled() and advice_enabled() API.

* ab/retire-advice-config:
  advice: move advice.graftFileDeprecated squashing to commit.[ch]
  advice: remove use of global advice_add_embedded_repo
  advice: remove read uses of most global `advice_` variables
  advice: add enum variants for missing advice variables

2 years agoMerge branch 'mk/clone-recurse-submodules'
Junio C Hamano [Fri, 10 Sep 2021 18:46:29 +0000 (11:46 -0700)] 
Merge branch 'mk/clone-recurse-submodules'

After "git clone --recurse-submodules", all submodules are cloned
but they are not by default recursed into by other commands.  With
submodule.stickyRecursiveClone configuration set, submodule.recurse
configuration is set to true in a repository created by "clone"
with "--recurse-submodules" option.

* mk/clone-recurse-submodules:
  clone: set submodule.recurse=true if submodule.stickyRecursiveClone enabled

2 years agoMerge branch 'ab/mailmap-leakfix'
Junio C Hamano [Fri, 10 Sep 2021 18:46:28 +0000 (11:46 -0700)] 
Merge branch 'ab/mailmap-leakfix'

Leakfix.

* ab/mailmap-leakfix:
  mailmap.c: fix a memory leak in free_mailap_{info,entry}()

2 years agoMerge branch 'ab/gc-log-rephrase'
Junio C Hamano [Fri, 10 Sep 2021 18:46:28 +0000 (11:46 -0700)] 
Merge branch 'ab/gc-log-rephrase'

A pathname in an advice message has been made cut-and-paste ready.

* ab/gc-log-rephrase:
  gc: remove trailing dot from "gc.log" line

2 years agoMerge branch 'uk/userdiff-php-enum'
Junio C Hamano [Fri, 10 Sep 2021 18:46:27 +0000 (11:46 -0700)] 
Merge branch 'uk/userdiff-php-enum'

Update the userdiff pattern for PHP.

* uk/userdiff-php-enum:
  userdiff: support enum keyword in PHP hunk header

2 years agoMerge branch 'tk/fast-export-anonymized-tag-fix'
Junio C Hamano [Fri, 10 Sep 2021 18:46:27 +0000 (11:46 -0700)] 
Merge branch 'tk/fast-export-anonymized-tag-fix'

The output from "git fast-export", when its anonymization feature
is in use, showed an annotated tag incorrectly.

* tk/fast-export-anonymized-tag-fix:
  fast-export: fix anonymized tag using original length

2 years agoMerge branch 'ba/object-info'
Junio C Hamano [Fri, 10 Sep 2021 18:46:26 +0000 (11:46 -0700)] 
Merge branch 'ba/object-info'

Leakfix.

* ba/object-info:
  protocol-caps.c: fix memory leak in send_info()

2 years agoMerge branch 'ab/commit-graph-usage'
Junio C Hamano [Fri, 10 Sep 2021 18:46:25 +0000 (11:46 -0700)] 
Merge branch 'ab/commit-graph-usage'

Fixes on usage message from "git commit-graph".

* ab/commit-graph-usage:
  commit-graph: show "unexpected subcommand" error
  commit-graph: show usage on "commit-graph [write|verify] garbage"
  commit-graph: early exit to "usage" on !argc
  multi-pack-index: refactor "goto usage" pattern
  commit-graph: use parse_options_concat()
  commit-graph: remove redundant handling of -h
  commit-graph: define common usage with a macro

2 years agoMerge branch 'mh/send-email-reset-in-reply-to'
Junio C Hamano [Fri, 10 Sep 2021 18:46:25 +0000 (11:46 -0700)] 
Merge branch 'mh/send-email-reset-in-reply-to'

Even when running "git send-email" without its own threaded
discussion support, a threading related header in one message is
carried over to the subsequent message to result in an unwanted
threading, which has been corrected.

* mh/send-email-reset-in-reply-to:
  send-email: avoid incorrect header propagation

2 years agoMerge branch 'rs/more-fspathcmp'
Junio C Hamano [Fri, 10 Sep 2021 18:46:24 +0000 (11:46 -0700)] 
Merge branch 'rs/more-fspathcmp'

Code simplification.

* rs/more-fspathcmp:
  merge-recursive: use fspathcmp() in path_hashmap_cmp()

2 years agoMerge branch 'sg/set-ceiling-during-tests'
Junio C Hamano [Fri, 10 Sep 2021 18:46:23 +0000 (11:46 -0700)] 
Merge branch 'sg/set-ceiling-during-tests'

Buggy tests could damage repositories outside the throw-away test
area we created.  We now by default export GIT_CEILING_DIRECTORIES
to limit the damage from such a stray test.

* sg/set-ceiling-during-tests:
  test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository

2 years agoMerge branch 'jh/sparse-index-resize-fix'
Junio C Hamano [Fri, 10 Sep 2021 18:46:23 +0000 (11:46 -0700)] 
Merge branch 'jh/sparse-index-resize-fix'

The sparse-index support can corrupt the index structure by storing
a stale and/or uninitialized data, which has been corrected.

* jh/sparse-index-resize-fix:
  sparse-index: copy dir_hash in ensure_full_index()

2 years agoMerge branch 'es/walken-tutorial-fix'
Junio C Hamano [Fri, 10 Sep 2021 18:46:23 +0000 (11:46 -0700)] 
Merge branch 'es/walken-tutorial-fix'

Typofix.

* es/walken-tutorial-fix:
  doc: fix syntax error and the format of printf

2 years agoMerge branch 'tb/add-objects-in-unpacked-packs-simplify'
Junio C Hamano [Fri, 10 Sep 2021 18:46:21 +0000 (11:46 -0700)] 
Merge branch 'tb/add-objects-in-unpacked-packs-simplify'

Code simplification with reduced memory usage.

* tb/add-objects-in-unpacked-packs-simplify:
  builtin/pack-objects.c: remove duplicate hash lookup
  builtin/pack-objects.c: simplify add_objects_in_unpacked_packs()
  object-store.h: teach for_each_packed_object to ignore kept packs

2 years agoMerge branch 'ps/fetch-omit-formatting-under-quiet'
Junio C Hamano [Fri, 10 Sep 2021 18:46:20 +0000 (11:46 -0700)] 
Merge branch 'ps/fetch-omit-formatting-under-quiet'

"git fetch --quiet" optimization to avoid useless computation of
info that will never be displayed.

* ps/fetch-omit-formatting-under-quiet:
  fetch: skip formatting updated refs with `--quiet`

2 years agoMerge branch 'ka/want-ref-in-namespace'
Junio C Hamano [Fri, 10 Sep 2021 18:46:20 +0000 (11:46 -0700)] 
Merge branch 'ka/want-ref-in-namespace'

"git upload-pack" which runs on the other side of "git fetch"
forgot to take the ref namespaces into account when handling
want-ref requests.

* ka/want-ref-in-namespace:
  docs: clarify the interaction of transfer.hideRefs and namespaces
  upload-pack.c: treat want-ref relative to namespace
  t5730: introduce fetch command helper

2 years agoMerge branch 'zh/cherry-pick-advice'
Junio C Hamano [Fri, 10 Sep 2021 18:46:19 +0000 (11:46 -0700)] 
Merge branch 'zh/cherry-pick-advice'

The advice message that "git cherry-pick" gives when it asks
conflicted replay of a commit to be resolved by the end user has
been updated.

* zh/cherry-pick-advice:
  cherry-pick: use better advice message

2 years agoMerge branch 'js/advise-when-skipping-cherry-picked'
Junio C Hamano [Fri, 10 Sep 2021 18:46:19 +0000 (11:46 -0700)] 
Merge branch 'js/advise-when-skipping-cherry-picked'

"git rebase" by default skips changes that are equivalent to
commits that are already in the history the branch is rebased onto;
give messages when this happens to let the users be aware of
skipped commits, and also teach them how to tell "rebase" to keep
duplicated changes.

* js/advise-when-skipping-cherry-picked:
  sequencer: advise if skipping cherry-picked commit

2 years agopack-objects: rename .idx files into place after .bitmap files
Ævar Arnfjörð Bjarmason [Thu, 9 Sep 2021 23:25:00 +0000 (19:25 -0400)] 
pack-objects: rename .idx files into place after .bitmap files

In preceding commits the race of renaming .idx files in place before
.rev files and other auxiliary files was fixed in pack-write.c's
finish_tmp_packfile(), builtin/repack.c's "struct exts", and
builtin/index-pack.c's final(). As noted in the change to pack-write.c
we left in place the issue of writing *.bitmap files after the *.idx,
let's fix that issue.

See 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21)
for commentary at the time when *.bitmap was implemented about how
those files are written out, nothing in that commit contradicts what's
being done here.

Note that this commit and preceding ones only close any race condition
with *.idx files being written before their auxiliary files if we're
optimistic about our lack of fsync()-ing in this are not tripping us
over. See the thread at [1] for a rabbit hole of various discussions
about filesystem races in the face of doing and not doing fsync() (and
if doing fsync(), not doing it properly).

We may want to fsync the containing directory once after renaming the
*.idx file into place, but that is outside the scope of this series.

1. https://lore.kernel.org/git/8735qgkvv1.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-write: split up finish_tmp_packfile() function
Ævar Arnfjörð Bjarmason [Thu, 9 Sep 2021 23:24:56 +0000 (19:24 -0400)] 
pack-write: split up finish_tmp_packfile() function

Split up the finish_tmp_packfile() function and use the split-up version
in pack-objects.c in preparation for moving the step of renaming the
*.idx file later as part of a function change.

Since the only other caller of finish_tmp_packfile() was in
bulk-checkin.c, and it won't be needing a change to its *.idx renaming,
provide a thin wrapper for the old function as a static function in that
file. If other callers end up needing the simpler version it could be
moved back to "pack-write.c" and "pack.h".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/index-pack.c: move `.idx` files into place last
Taylor Blau [Thu, 9 Sep 2021 23:24:53 +0000 (19:24 -0400)] 
builtin/index-pack.c: move `.idx` files into place last

In a similar spirit as preceding patches to `git repack` and `git
pack-objects`, fix the identical problem in `git index-pack`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoindex-pack: refactor renaming in final()
Ævar Arnfjörð Bjarmason [Thu, 9 Sep 2021 23:24:49 +0000 (19:24 -0400)] 
index-pack: refactor renaming in final()

Refactor the renaming in final() into a helper function, this is
similar in spirit to a preceding refactoring of finish_tmp_packfile()
in pack-write.c.

Before e37d0b8730b (builtin/index-pack.c: write reverse indexes,
2021-01-25) it probably wasn't worth it to have this sort of helper,
due to the differing "else if" case for "pack" files v.s. "idx" files.

But since we've got "rev" as well now, let's do the renaming via a
helper, this is both a net decrease in lines, and improves the
readability, since we can easily see at a glance that the logic for
writing these three types of files is exactly the same, aside from the
obviously differing cases of "*final_name" being NULL, and
"make_read_only_if_same" being different.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/repack.c: move `.idx` files into place last
Taylor Blau [Thu, 9 Sep 2021 23:24:44 +0000 (19:24 -0400)] 
builtin/repack.c: move `.idx` files into place last

In a similar spirit as the previous patch, fix the identical problem
from `git repack` (which invokes `pack-objects` with a temporary
location for output, and then moves the files into their final locations
itself).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-write.c: rename `.idx` files after `*.rev`
Taylor Blau [Thu, 9 Sep 2021 23:24:41 +0000 (19:24 -0400)] 
pack-write.c: rename `.idx` files after `*.rev`

We treat the presence of an `.idx` file as the indicator of whether or
not it's safe to use a packfile. But `finish_tmp_packfile()` (which is
responsible for writing the pack and moving the temporary versions of
all of its auxiliary files into place) is inconsistent about the write
order.

Specifically, it moves the `.rev` file into place after the `.idx`,
leaving open the possibility to open a pack which looks "ready" (because
the `.idx` file exists and is readable) but appears momentarily to not
have a `.rev` file. This causes Git to fall back to generating the
pack's reverse index in memory.

Though racy, this amounts to an unnecessary slow-down at worst, and
doesn't affect the correctness of the resulting reverse index.

Close this race by moving the .rev file into place before moving the
.idx file into place.

This still leaves the issue of `.idx` files being renamed into place
before the auxiliary `.bitmap` file is renamed when in pack-object.c's
write_pack_file() "write_bitmap_index" is true. That race will be
addressed in subsequent commits.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-write: refactor renaming in finish_tmp_packfile()
Ævar Arnfjörð Bjarmason [Thu, 9 Sep 2021 23:24:37 +0000 (19:24 -0400)] 
pack-write: refactor renaming in finish_tmp_packfile()

Refactor the renaming in finish_tmp_packfile() into a helper function.
The callers are now expected to pass a "name_buffer" ending in
"pack-OID." instead of the previous "pack-", we then append "pack",
"idx" or "rev" to it.

By doing the strbuf_setlen() in rename_tmp_packfile() we reuse the
buffer and avoid the repeated allocations we'd get if that function had
its own temporary "struct strbuf".

This approach of reusing the buffer does make the last user in
pack-object.c's write_pack_file() slightly awkward, since we needlessly
do a strbuf_setlen() before calling strbuf_release() for consistency. In
subsequent changes we'll move that bitmap writing code around, so let's
not skip the strbuf_setlen() now.

The previous strbuf_reset() idiom originated with 5889271114a
(finish_tmp_packfile():use strbuf for pathname construction,
2014-03-03), which in turn was a minimal adjustment of pre-strbuf code
added in 0e990530ae (finish_tmp_packfile(): a helper function,
2011-10-28).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobulk-checkin.c: store checksum directly
Taylor Blau [Thu, 9 Sep 2021 23:24:32 +0000 (19:24 -0400)] 
bulk-checkin.c: store checksum directly

finish_bulk_checkin() stores the checksum from finalize_hashfile() by
writing to the `hash` member of `struct object_id`, but that hash has
nothing to do with an object id (it's just a convenient location that
happens to be sized correctly).

Store the hash directly in an unsigned char array. This behaves the same
as writing to the `hash` member, but makes the intent clearer (and
avoids allocating an extra four bytes for the `algo` member of `struct
object_id`). It likewise prevents the possibility of a segfault when
reading `algo` (e.g., by calling `oid_to_hex()`) if it is uninitialized.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot5562: use alarm() to interrupt timed child-wait
Jeff King [Thu, 9 Sep 2021 22:57:57 +0000 (18:57 -0400)] 
t5562: use alarm() to interrupt timed child-wait

The t5562 script occasionally takes 60 extra seconds to complete due to
a race condition in the invoke-with-content-length.pl helper.

The way it's supposed to work is this:

  - we set up a SIGCLD handler

  - we kick off http-backend and write to it with a set content-length,
    but _don't_ close the pipe

  - we sleep for 60 seconds, assuming that SIGCLD from http-backend
    finishing will interrupt us

  - after the sleep finishes (whetherby 60 seconds or because it was
    interrupted by the signal), we check a flag to see if our SIGCLD
    handler was called. If not, then we complain.

This usually completes immediately, because the signal interrupts our
sleep. But very occasionally the child process dies _before_ we hit the
sleep, so we don't realize it. The test still completes successfully
(because our $exited flag is set), but it takes an extra 60 seconds.

There's no way to check the flag and sleep atomically. So the best we
can do with this approach is to sleep in smaller chunks (say, 1 second)
and check the flag incrementally. Then we waste a maximum of 1 second if
we lose the race. This was proposed in:

  https://lore.kernel.org/git/20190218205028.32486-1-max@max630.net/

and it does work. But we can do better.

Instead of blocking on sleep and waiting for the child signal to
interrupt us, we can block on the child exiting and set an alarm signal
to trigger the timeout.

This lets us exit the script immediately when the child behaves (with no
race possible), and wait a maximum of 60 seconds when it doesn't.

Note one small subtlety: perl is very willing to restart the waitpid()
call after the alarm is delivered, even if we've thrown an exception via
die. "perldoc -f alarm" claims you can get around this with an eval/die
combo (and even has some example code), but it doesn't seem to work for
me with waitpid(); instead, we continue waiting until the child exits.

So instead, we'll instruct the child process to exit in the alarm
handler itself. In the original code this was done by calling
close($out). That would continue to work, since our child is always
http-backend, which should exit when its stdin closes. But we can be
even more robust against a hung or confused child by sending a KILL
signal, which should terminate it immediately.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorefs/files-backend: remove unused open mode parameter
René Scharfe [Thu, 9 Sep 2021 21:45:51 +0000 (23:45 +0200)] 
refs/files-backend: remove unused open mode parameter

We only need to provide a mode if we are willing to let open(2) create
the file, which is not the case here, so drop the unnecessary parameter.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosetup: use xopen and xdup in sanitize_stdfds
René Scharfe [Thu, 9 Sep 2021 21:45:29 +0000 (23:45 +0200)] 
setup: use xopen and xdup in sanitize_stdfds

Replace the catch-all error message with specific ones for opening and
duplicating by calling the wrappers xopen and xdup.  The code becomes
easier to follow when error handling is reduced to two letters.

Remove the unnecessary mode parameter while at it -- we expect /dev/null
to already exist.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-bitmap: drop bitmap_index argument from try_partial_reuse()
Jeff King [Thu, 9 Sep 2021 19:57:21 +0000 (15:57 -0400)] 
pack-bitmap: drop bitmap_index argument from try_partial_reuse()

Starting in commit 0f533c7284 (pack-bitmap: read multi-pack bitmaps,
2021-08-31), we no longer look at the "struct bitmap_index" passed to
try_partial_reuse(). This is because we only handle verbatim reuse from
a single pack: either the pack whose bitmap we're looking at, or the
"preferred" pack of a midx bitmap. And thus the primary item we look at
is the "pack" parameter added by that same commit, and not the
bitmap_git->pack parameter (which would be NULL for a midx bitmap). It's
our caller, reuse_partial_packfile_from_bitmap(), which decides which
pack to use and passes it in to us.

Drop the unused parameter to prevent confusion.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-bitmap: drop repository argument from prepare_midx_bitmap_git()
Jeff King [Thu, 9 Sep 2021 19:56:58 +0000 (15:56 -0400)] 
pack-bitmap: drop repository argument from prepare_midx_bitmap_git()

We never look at the repository argument which is passed. This makes
sense, since the multi_pack_index struct already tells us everything we
need to access the files in its associated object directory.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosparse-index: integrate with cherry-pick and rebase
Derrick Stolee [Wed, 8 Sep 2021 11:24:01 +0000 (11:24 +0000)] 
sparse-index: integrate with cherry-pick and rebase

The hard work was already done with 'git merge' and the ORT strategy.
Just add extra tests to see that we get the expected results in the
non-conflict cases.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosequencer: ensure full index if not ORT strategy
Derrick Stolee [Wed, 8 Sep 2021 11:24:00 +0000 (11:24 +0000)] 
sequencer: ensure full index if not ORT strategy

The sequencer is used by 'cherry-pick' and 'rebase' to sequence a list
of operations that modify the index. Since we intend to remove the need
for 'command_requires_full_index', we need to ensure the sparse index is
expanded every time it is written to disk between these steps. That is,
unless the merge strategy is 'ort' where the index can remain sparse
throughout.

There are two main places to be extra careful about a full index:

1. Right before calling merge_trees(), ensure the index is full. This
   happens within an 'else' where the 'if' block checks if the 'ort'
   strategy is selected.

2. During read_and_refresh_cache(), the index might be written to disk
   and converted to sparse in the process. Ensure it expands back to
   full afterwards by checking if the strategy is _not_ 'ort'. This
   'if' statement is the logical negation of the 'if' in item (1).

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot1092: add cherry-pick, rebase tests
Derrick Stolee [Wed, 8 Sep 2021 11:23:59 +0000 (11:23 +0000)] 
t1092: add cherry-pick, rebase tests

Add tests to check that cherry-pick and rebase behave the same in the
sparse-index case as in the full index cases. These tests are agnostic
to GIT_TEST_MERGE_ALGORITHM, so a full CI test suite will check both the
'ort' and 'recursive' strategies on this test.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agomerge-ort: expand only for out-of-cone conflicts
Derrick Stolee [Wed, 8 Sep 2021 11:23:58 +0000 (11:23 +0000)] 
merge-ort: expand only for out-of-cone conflicts

Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.

Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.

Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agomerge: make sparse-aware with ORT
Derrick Stolee [Wed, 8 Sep 2021 11:23:57 +0000 (11:23 +0000)] 
merge: make sparse-aware with ORT

Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:

1. If the merge strategy is 'recursive', then we enable
   command_requires_full_index at the start of the merge_recursive()
   method. We expect sparse-index users to also have the 'ort' strategy
   enabled.

2. With the 'ort' strategy, if the merge results in a conflicted file,
   then we expand the index before updating the working tree. The loop
   that iterates over the worktree replaces index entries and tracks
   'origintal_cache_nr' which can become completely wrong if the index
   expands in the middle of the operation. This safety valve is
   important before that loop starts. A later change will focus this
   to only expand if we indeed have a conflict outside of the
   sparse-checkout cone.

3. Other merge strategies are executed as a 'git merge-X' subcommand,
   and those strategies are currently protected with the
   'command_requires_full_index' guard.

Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agodiff: ignore sparse paths in diffstat
Derrick Stolee [Wed, 8 Sep 2021 11:23:56 +0000 (11:23 +0000)] 
diff: ignore sparse paths in diffstat

The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete. In order to avoid expanding a sparse index,
the reuse_worktree_file() needs to be adapted to ignore files that are
outside of the sparse-checkout cone. The file names and OIDs used for
this check come from the merged tree in the case of the ORT strategy,
not the index, hence the ability to look into these paths without having
already expanded the index.

The work done by reuse_worktree_file() is only an optimization, and
requires the file being on disk for it to be of any value. Thus, it is
safe to exit the method early if we do not expect the file on disk.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoClose object store closer to spawning child processes
Johannes Schindelin [Thu, 9 Sep 2021 09:47:08 +0000 (09:47 +0000)] 
Close object store closer to spawning child processes

In many cases where we spawned child processes that _may_ trigger a
repack, we explicitly closed the object store first (so that the
`repack` process can delete the `.pack` files, which would otherwise not
be possible on Windows since files cannot be deleted as long as they as
still in use).

Wherever possible, we now use the new `close_object_store` bit of the
`run_command()` API, to delay closing the object store even further.
This makes the code easier to maintain because it is now more obvious
that we only release those file handles because of those child
processes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorun_auto_maintenance(): implicitly close the object store
Johannes Schindelin [Thu, 9 Sep 2021 09:47:07 +0000 (09:47 +0000)] 
run_auto_maintenance(): implicitly close the object store

Before spawning the auto maintenance, we need to make sure that we
release all open file handles to all the `.pack` files (and MIDX files
and commit-graph files and...) so that the maintenance process has the
freedom to delete those files.

So far, we did this manually every time before calling
`run_auto_maintenance()`. With the new `close_object_store` flag, we can
do that implicitly in that function, which is more robust because future
callers won't be able to forget to close the object store.

Note: this changes behavior slightly, as we previously _always_ closed
the object store, but now we only close the object store when actually
running the auto maintenance. In practice, this should not matter (if
anything, it might speed up operations where auto maintenance is
disabled).

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorun-command: offer to close the object store before running
Johannes Schindelin [Thu, 9 Sep 2021 09:47:06 +0000 (09:47 +0000)] 
run-command: offer to close the object store before running

Especially on Windows, where files cannot be deleted if _any_ process
holds an open file handle to them, it is important to close the object
store (releasing all handles to all `.pack` files) before running a
command that might spawn a garbage collection.

This scenario is so common that we frequently see the pattern of closing
the object store before running auto maintenance or another Git command.

Let's make this much more convenient by teaching the `run_command()`
machinery a new flag to release the object store before spawning the
process.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorun-command: prettify the `RUN_COMMAND_*` flags
Johannes Schindelin [Thu, 9 Sep 2021 09:47:05 +0000 (09:47 +0000)] 
run-command: prettify the `RUN_COMMAND_*` flags

The values were listed unaligned, and with powers of two spelled out in
decimal. The list is easier to parse for human readers if the numbers
are aligned and spelled out as powers of two (using the bit-shift
operator `<<`).

While at it, remove a code comment that was unclear at best, and
confusing at worst.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack.h: line-wrap the definition of finish_tmp_packfile()
Ævar Arnfjörð Bjarmason [Thu, 9 Sep 2021 03:24:47 +0000 (23:24 -0400)] 
pack.h: line-wrap the definition of finish_tmp_packfile()

Line-wrap the definition of finish_tmp_packfile() to make subsequent
changes easier to read. See 0e990530ae (finish_tmp_packfile(): a
helper function, 2011-10-28) for the commit that introduced this
overly long line.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoentry: show finer-grained counter in "Filtering content" progress line
SZEDER Gábor [Thu, 9 Sep 2021 01:10:12 +0000 (03:10 +0200)] 
entry: show finer-grained counter in "Filtering content" progress line

The "Filtering content" progress in entry.c:finish_delayed_checkout()
is unusual because of how it calculates the progress count and because
it shows the progress of a nested loop.  It works basically like this:

  start_delayed_progress(p, nr_of_paths_to_filter)
  for_each_filter {
      display_progress(p, nr_of_paths_to_filter - nr_of_paths_still_left_to_filter)
      for_each_path_handled_by_the_current_filter {
          checkout_entry()
      }
  }
  stop_progress(p)

There are two issues with this approach:

  - The work done by the last filter (or the only filter if there is
    only one) is never counted, so if the last filter still has some
    paths to process, then the counter shown in the "done" progress
    line will not match the expected total.

    The partially-RFC series to add a GIT_TEST_CHECK_PROGRESS=1
    mode[1] helps spot this issue. Under it the 'missing file in
    delayed checkout' and 'invalid file in delayed checkout' tests in
    't0021-conversion.sh' fail, because both use only one
    filter.  (The test 'delayed checkout in process filter' uses two
    filters but the first one does all the work, so that test already
    happens to succeed even with GIT_TEST_CHECK_PROGRESS=1.)

  - The progress counter is updated only once per filter, not once per
    processed path, so if a filter has a lot of paths to process, then
    the counter might stay unchanged for a long while and then make a
    big jump (though the user still gets a sense of progress, because
    we call display_throughput() after each processed path to show the
    amount of processed data).

Move the display_progress() call to the inner loop, right next to that
checkout_entry() call that does the hard work for each path, and use a
dedicated counter variable that is incremented upon processing each
path.

After this change the 'invalid file in delayed checkout' in
't0021-conversion.sh' would succeed with the GIT_TEST_CHECK_PROGRESS=1
assertion discussed above, but the 'missing file in delayed checkout'
test would still fail.

It'll fail because its purposefully buggy filter doesn't process any
paths, so we won't execute that inner loop at all, see [2] for how to
spot that issue without GIT_TEST_CHECK_PROGRESS=1. It's not
straightforward to fix it with the current progress.c library (see [3]
for an attempt), so let's leave it for now.

Let's also initialize the *progress to "NULL" while we're at it. Since
7a132c628e5 (checkout: make delayed checkout respect --quiet and
--no-progress, 2021-08-26) we have had progress conditional on
"show_progress", usually we use the idiom of a "NULL" initialization
of the "*progress", rather than the more verbose ternary added in
7a132c628e5.

1. https://lore.kernel.org/git/20210620200303.2328957-1-szeder.dev@gmail.com/
2. http://lore.kernel.org/git/20210802214827.GE23408@szeder.dev
3. https://lore.kernel.org/git/20210620200303.2328957-7-szeder.dev@gmail.com/

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocommit-graph: fix bogus counter in "Scanning merged commits" progress line
SZEDER Gábor [Thu, 9 Sep 2021 01:10:11 +0000 (03:10 +0200)] 
commit-graph: fix bogus counter in "Scanning merged commits" progress line

The final value of the counter of the "Scanning merged commits"
progress line is always one less than its expected total, e.g.:

  Scanning merged commits:  83% (5/6), done.

This happens because while iterating over an array the loop variable
is passed to display_progress() as-is, but while C arrays (and thus
the loop variable) start at 0 and end at N-1, the progress counter
must end at N. Fix this by passing 'i + 1' to display_progress(), like
most other callsites do.

There's an RFC series to add a GIT_TEST_CHECK_PROGRESS=1 mode[1] which
catches this issue in the 'fetch.writeCommitGraph' and
'fetch.writeCommitGraph with submodules' tests in
't5510-fetch.sh'. The GIT_TEST_CHECK_PROGRESS=1 mode is not part of
this series, but future changes to progress.c may add it or similar
assertions to catch this and similar bugs elsewhere.

1. https://lore.kernel.org/git/20210620200303.2328957-1-szeder.dev@gmail.com/

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe fourth batch
Junio C Hamano [Wed, 8 Sep 2021 00:47:04 +0000 (17:47 -0700)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'sg/column-nl'
Junio C Hamano [Wed, 8 Sep 2021 20:30:34 +0000 (13:30 -0700)] 
Merge branch 'sg/column-nl'

The parser for the "--nl" option of "git column" has been
corrected.

* sg/column-nl:
  column: fix parsing of the '--nl' option

2 years agoMerge branch 'cb/makefile-apple-clang'
Junio C Hamano [Wed, 8 Sep 2021 20:30:33 +0000 (13:30 -0700)] 
Merge branch 'cb/makefile-apple-clang'

Build update for Apple clang.

* cb/makefile-apple-clang:
  build: catch clang that identifies itself as "$VENDOR clang"
  build: clang version may not be followed by extra words
  build: update detect-compiler for newer Xcode version

2 years agoMerge branch 'ps/ls-refs-strbuf-optim'
Junio C Hamano [Wed, 8 Sep 2021 20:30:33 +0000 (13:30 -0700)] 
Merge branch 'ps/ls-refs-strbuf-optim'

Micro-optimization for the wire protocol driver.

* ps/ls-refs-strbuf-optim:
  ls-refs: reuse buffer when sending refs

2 years agoMerge branch 'rs/branch-allow-deleting-dangling'
Junio C Hamano [Wed, 8 Sep 2021 20:30:32 +0000 (13:30 -0700)] 
Merge branch 'rs/branch-allow-deleting-dangling'

"git branch -D <branch>" used to refuse to remove a broken branch
ref that points at a missing commit, which has been corrected.

* rs/branch-allow-deleting-dangling:
  branch: allow deleting dangling branches with --force

2 years agoMerge branch 'mt/quiet-with-delayed-checkout'
Junio C Hamano [Wed, 8 Sep 2021 20:30:32 +0000 (13:30 -0700)] 
Merge branch 'mt/quiet-with-delayed-checkout'

The delayed checkout code path in "git checkout" etc. were chatty
even when --quiet and/or --no-progress options were given.

* mt/quiet-with-delayed-checkout:
  checkout: make delayed checkout respect --quiet and --no-progress

2 years agoMerge branch 'rs/xopen-reports-open-failures'
Junio C Hamano [Wed, 8 Sep 2021 20:30:32 +0000 (13:30 -0700)] 
Merge branch 'rs/xopen-reports-open-failures'

Error diagnostics improvement.

* rs/xopen-reports-open-failures:
  use xopen() to handle fatal open(2) failures
  xopen: explicitly report creation failures