]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
10 months agoMerge branch 'pw/diff-no-index-from-named-pipes'
Junio C Hamano [Mon, 17 Jul 2023 18:30:41 +0000 (11:30 -0700)] 
Merge branch 'pw/diff-no-index-from-named-pipes'

"git diff --no-index" learned to read from named pipes as if they
were regular files, to allow "git diff <(process) <(substitution)"
some shells support.

* pw/diff-no-index-from-named-pipes:
  diff --no-index: support reading from named pipes
  t4054: test diff --no-index with stdin
  diff --no-index: die on error reading stdin
  diff --no-index: refuse to compare stdin to a directory

10 months agoThe tenth batch
Junio C Hamano [Fri, 14 Jul 2023 17:45:39 +0000 (10:45 -0700)] 
The tenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'jk/imap-send-unused-variable-cleanup'
Junio C Hamano [Fri, 14 Jul 2023 17:46:07 +0000 (10:46 -0700)] 
Merge branch 'jk/imap-send-unused-variable-cleanup'

"imap-send" codepaths got cleaned up to get rid of unused
parameters.

* jk/imap-send-unused-variable-cleanup:
  imap-send: drop unused fields from imap_cmd_cb
  imap-send: drop unused parameter from imap_cmd_cb callback
  imap-send: use server conf argument in setup_curl()

10 months agoMerge branch 'ma/t0091-fixup'
Junio C Hamano [Fri, 14 Jul 2023 17:46:07 +0000 (10:46 -0700)] 
Merge branch 'ma/t0091-fixup'

"git bugreport" tests did not test what it wanted to test, which
has been corrected.

* ma/t0091-fixup:
  t0091-bugreport.sh: actually verify some content of report

10 months agoMerge branch 'ks/ref-filter-signature'
Junio C Hamano [Fri, 14 Jul 2023 17:46:07 +0000 (10:46 -0700)] 
Merge branch 'ks/ref-filter-signature'

The "git for-each-ref" family of commands learned placeholders
related to GPG signature verification.

* ks/ref-filter-signature:
  ref-filter: add new "signature" atom
  t/lib-gpg: introduce new prereq GPG2

10 months agoThe ninth batch
Junio C Hamano [Sat, 8 Jul 2023 16:13:16 +0000 (09:13 -0700)] 
The ninth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'jk/fsck-indices-in-worktrees'
Junio C Hamano [Sat, 8 Jul 2023 18:23:08 +0000 (11:23 -0700)] 
Merge branch 'jk/fsck-indices-in-worktrees'

Code clarification.

* jk/fsck-indices-in-worktrees:
  fsck: avoid misleading variable name

10 months agoMerge branch 'js/empty-index-fixes'
Junio C Hamano [Sat, 8 Jul 2023 18:23:07 +0000 (11:23 -0700)] 
Merge branch 'js/empty-index-fixes'

A few places failed to differenciate the case where the index is
truly empty (nothing added) and we haven't yet read from the
on-disk index file, which have been corrected.

* js/empty-index-fixes:
  commit -a -m: allow the top-level tree to become empty again
  split-index: accept that a base index can be empty
  do_read_index(): always mark index as initialized unless erroring out

10 months agoMerge branch 'ks/t4205-test-describe-with-abbrev-fix'
Junio C Hamano [Sat, 8 Jul 2023 18:23:07 +0000 (11:23 -0700)] 
Merge branch 'ks/t4205-test-describe-with-abbrev-fix'

Test update.

* ks/t4205-test-describe-with-abbrev-fix:
  t4205: correctly test %(describe:abbrev=...)

10 months agoThe eighth batch
Junio C Hamano [Thu, 6 Jul 2023 18:00:38 +0000 (11:00 -0700)] 
The eighth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'gc/config-context'
Junio C Hamano [Thu, 6 Jul 2023 18:54:48 +0000 (11:54 -0700)] 
Merge branch 'gc/config-context'

Reduce reliance on a global state in the config reading API.

* gc/config-context:
  config: pass source to config_parser_event_fn_t
  config: add kvi.path, use it to evaluate includes
  config.c: remove config_reader from configsets
  config: pass kvi to die_bad_number()
  trace2: plumb config kvi
  config.c: pass ctx with CLI config
  config: pass ctx with config files
  config.c: pass ctx in configsets
  config: add ctx arg to config_fn_t
  urlmatch.h: use config_fn_t type
  config: inline git_color_default_config

10 months agoMerge branch 'jc/doc-hash-object-types'
Junio C Hamano [Thu, 6 Jul 2023 18:54:47 +0000 (11:54 -0700)] 
Merge branch 'jc/doc-hash-object-types'

Doc update.

* jc/doc-hash-object-types:
  docs: add git hash-object -t option's possible values

10 months agoMerge branch 'jk/cherry-pick-revert-status'
Junio C Hamano [Thu, 6 Jul 2023 18:54:47 +0000 (11:54 -0700)] 
Merge branch 'jk/cherry-pick-revert-status'

During a cherry-pick or revert session that works on multiple
commits, "git status" did not give correct information, which has
been corrected.

* jk/cherry-pick-revert-status:
  fix cherry-pick/revert status when doing multiple commits

10 months agoMerge branch 'pw/apply-too-large'
Junio C Hamano [Thu, 6 Jul 2023 18:54:47 +0000 (11:54 -0700)] 
Merge branch 'pw/apply-too-large'

"git apply" punts when it is fed too large a patch input; the error
message it gives when it happens has been clarified.

* pw/apply-too-large:
  apply: improve error messages when reading patch

10 months agoMerge branch 'tl/notes-separator'
Junio C Hamano [Thu, 6 Jul 2023 18:54:47 +0000 (11:54 -0700)] 
Merge branch 'tl/notes-separator'

'git notes append' was taught '--separator' to specify string to insert
between paragraphs.

* tl/notes-separator:
  notes: introduce "--no-separator" option
  notes.c: introduce "--[no-]stripspace" option
  notes.c: append separator instead of insert by pos
  notes.c: introduce '--separator=<paragraph-break>' option
  t3321: add test cases about the notes stripspace behavior
  notes.c: use designated initializers for clarity
  notes.c: cleanup 'strbuf_grow' call in 'append_edit'

10 months agoMerge branch 'gc/config-partial-submodule-kvi-fix'
Junio C Hamano [Thu, 6 Jul 2023 18:54:46 +0000 (11:54 -0700)] 
Merge branch 'gc/config-partial-submodule-kvi-fix'

Partially revert a sanity check that the rest of the config code
was not ready, to avoid triggering it in a corner case.

* gc/config-partial-submodule-kvi-fix:
  config: don't BUG when both kvi and source are set

10 months agoMerge branch 'pb/complete-diff-options'
Junio C Hamano [Thu, 6 Jul 2023 18:54:46 +0000 (11:54 -0700)] 
Merge branch 'pb/complete-diff-options'

Completion updates.

* pb/complete-diff-options: (24 commits)
  diff.c: mention completion above add_diff_options
  completion: complete --remerge-diff
  completion: complete --diff-merges, its options and --no-diff-merges
  completion: move --pickaxe-{all,regex} to __git_diff_common_options
  completion: complete --ws-error-highlight
  completion: complete --unified
  completion: complete --output-indicator-{context,new,old}
  completion: complete --output
  completion: complete --no-stat
  completion: complete --no-relative
  completion: complete --line-prefix
  completion: complete --ita-invisible-in-index and --ita-visible-in-index
  completion: complete --irreversible-delete
  completion: complete --ignore-matching-lines
  completion: complete --function-context
  completion: complete --find-renames
  completion: complete --find-object
  completion: complete --find-copies
  completion: complete --default-prefix
  completion: complete --compact-summary
  ...

10 months agoMerge branch 'cw/strbuf-cleanup'
Junio C Hamano [Thu, 6 Jul 2023 18:54:46 +0000 (11:54 -0700)] 
Merge branch 'cw/strbuf-cleanup'

Move functions that are not about pure string manipulation out of
strbuf.[ch]

* cw/strbuf-cleanup:
  strbuf: remove global variable
  path: move related function to path
  object-name: move related functions to object-name
  credential-store: move related functions to credential-store file
  abspath: move related functions to abspath
  strbuf: clarify dependency
  strbuf: clarify API boundary

10 months agoMerge branch 'rs/strbuf-expand-step'
Junio C Hamano [Thu, 6 Jul 2023 18:54:45 +0000 (11:54 -0700)] 
Merge branch 'rs/strbuf-expand-step'

Code clean-up around strbuf_expand() API.

* rs/strbuf-expand-step:
  strbuf: simplify strbuf_expand_literal_cb()
  replace strbuf_expand() with strbuf_expand_step()
  replace strbuf_expand_dict_cb() with strbuf_expand_step()
  strbuf: factor out strbuf_expand_step()
  pretty: factor out expand_separator()

10 months agodiff --no-index: support reading from named pipes
Phillip Wood [Wed, 5 Jul 2023 19:49:30 +0000 (20:49 +0100)] 
diff --no-index: support reading from named pipes

In some shells, such as bash and zsh, it's possible to use a command
substitution to provide the output of a command as a file argument to
another process, like so:

  diff -u <(printf "a\nb\n") <(printf "a\nc\n")

However, this syntax does not produce useful results with "git diff
--no-index". On macOS, the arguments to the command are named pipes
under /dev/fd, and git diff doesn't know how to handle a named pipe. On
Linux, the arguments are symlinks to pipes, so git diff "helpfully"
diffs these symlinks, comparing their targets like "pipe:[1234]" and
"pipe:[5678]".

To address this "diff --no-index" is changed so that if a path given on
the commandline is a named pipe or a symbolic link that resolves to a
named pipe then we read the data to diff from that pipe. This is
implemented by generalizing the code that already exists to handle
reading from stdin when the user passes the path "-".

If the user tries to compare a named pipe to a directory then we die as
we do when trying to compare stdin to a directory.

As process substitution is not support by POSIX this change is tested by
using a pipe and a symbolic link to a pipe.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot4054: test diff --no-index with stdin
Phillip Wood [Wed, 5 Jul 2023 19:49:29 +0000 (20:49 +0100)] 
t4054: test diff --no-index with stdin

"git diff --no-index" supports reading from stdin with the path "-".
There is no test coverage for this so add a regression test before
changing the code in the next commit.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff --no-index: die on error reading stdin
Phillip Wood [Wed, 5 Jul 2023 19:49:28 +0000 (20:49 +0100)] 
diff --no-index: die on error reading stdin

If there is an error when reading from stdin then "diff --no-index"
prints an error message but continues to try and diff a file named "-"
resulting in an error message that looks like

    error: error while reading from stdin: Invalid argument
    fatal: stat '-': No such file or directory

assuming that no file named "-" exists. If such a file exists it prints
the first error message and generates the diff from that file which is
not what the user wanted. Instead just die() straight away if we cannot
read from stdin.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agodiff --no-index: refuse to compare stdin to a directory
Phillip Wood [Wed, 5 Jul 2023 19:49:27 +0000 (20:49 +0100)] 
diff --no-index: refuse to compare stdin to a directory

When the user runs

    git diff --no-index file directory

we follow the behavior of POSIX diff and rewrite the arguments as

    git diff --no-index file directory/file

Doing that when "file" is "-" (which means "read from stdin") does not
make sense so we should error out if the user asks us to compare "-" to
a directory. This matches the behavior of GNU diff and diff on *BSD.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot0091-bugreport.sh: actually verify some content of report
Martin Ågren [Wed, 5 Jul 2023 18:35:27 +0000 (20:35 +0200)] 
t0091-bugreport.sh: actually verify some content of report

In the first test in this script, 'creates a report with content in the
right places', we generate a report and pipe it into our helper
`check_all_headers_populated()`. The idea of the helper is to find all
lines that look like headers ("[Some Header Here]") and to check that
the next line is non-empty. This is supposed to catch erroneous outputs
such as the following:

  [A Header]
  something
  more here

  [Another Header]

  [Too Early Header]
  contents

However, we provide the lines of the bug report as filenames to grep,
meaning we mostly end up spewing errors:

  grep: : No such file or directory
  grep: [System Info]: No such file or directory
  grep: git version:: No such file or directory
  grep: git version 2.41.0.2.gfb7d80edca: No such file or directory

This doesn't disturb the test, which tugs along and reports success, not
really having verified the contents of the report at all.

Note that after 788a776069 ("bugreport: collect list of populated
hooks", 2020-05-07), the bug report, which is created in our hook-less
test repo, contains an empty section with the enabled hooks. Thus, even
the intention of our helper is a bit misguided: there is nothing
inherently wrong with having an empty section in the bug report.

Let's instead split this test into three: first verify that we generate
a report at all, then check that the introductory blurb looks the way it
should, then verify that the "[System Info]" seems to contain the right
things. (The "[Enabled Hooks]" section is tested later in the script.)

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoimap-send: drop unused fields from imap_cmd_cb
Jeff King [Mon, 3 Jul 2023 06:34:28 +0000 (02:34 -0400)] 
imap-send: drop unused fields from imap_cmd_cb

The imap_cmd_cb struct has several fields which are totally unused.
Presumably they did useful things in the upstream isync code from which
this is derived, but they don't in our more limited program. This is
particularly confusing for the "done" callback, which (as of the
previous patch) no longer matches the signature of the adjacent "cont"
callback.

Since we're unlikely to share code with isync going forward, we should
feel free to simplify the code here. Note that "done" is examined but
never set, so we can also drop a little bit of code outside of the
struct definition.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoimap-send: drop unused parameter from imap_cmd_cb callback
Jeff King [Mon, 3 Jul 2023 06:34:02 +0000 (02:34 -0400)] 
imap-send: drop unused parameter from imap_cmd_cb callback

There's a generic callback mechanism for handling plus-continuation of
IMAP commands. It takes the imap_cmd struct itself as an argument. That
seems reasonable, and in a larger imap-using program it might be used.
But in imap-send, we have only one such callback (auth_cram_md5) and it
doesn't use this value, triggering -Wunused-parameter warnings.

We could just mark the parameter as UNUSED. But since this is the only
such function, and because we are not likely to share code with the
upstream isync anymore, we can just simplify the interface to remove
this parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoimap-send: use server conf argument in setup_curl()
Jeff King [Mon, 3 Jul 2023 06:33:30 +0000 (02:33 -0400)] 
imap-send: use server conf argument in setup_curl()

Our caller passes in an imap_server_conf struct, but we ignore it
totally, and instead read the config directly from the global "server"
variable. This works OK, since our sole caller will pass in that same
global variable. But the intent seems to have been to use the passed-in
variable, as otherwise it has no purpose (and many other functions use
the same pattern).

Let's use the passed-in value, which also silences a -Wunused-parameter
warning.

It would be nice if "server" was not a global here, as we could avoid
making similar mistakes. But changing that would be a larger refactor,
as it must be accessed as a global in a few spots (e.g., filling it in
with the config callback).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoThe seventh batch
Junio C Hamano [Tue, 4 Jul 2023 22:23:39 +0000 (15:23 -0700)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoMerge branch 'bc/more-git-var'
Junio C Hamano [Tue, 4 Jul 2023 23:08:18 +0000 (16:08 -0700)] 
Merge branch 'bc/more-git-var'

Add more "git var" for toolsmiths to learn various locations Git is
configured with either via the configuration or hardcoded defaults.

* bc/more-git-var:
  var: add config file locations
  var: add attributes files locations
  attr: expose and rename accessor functions
  var: adjust memory allocation for strings
  var: format variable structure with C99 initializers
  var: add support for listing the shell
  t: add a function to check executable bit
  var: mark unused parameters in git_var callbacks

11 months agoMerge branch 'ps/revision-stdin-with-options'
Junio C Hamano [Tue, 4 Jul 2023 23:08:18 +0000 (16:08 -0700)] 
Merge branch 'ps/revision-stdin-with-options'

The set-up code for the get_revision() API now allows feeding
options like --all and --not in the --stdin mode.

* ps/revision-stdin-with-options:
  revision: handle pseudo-opts in `--stdin` mode
  revision: small readability improvement for reading from stdin
  revision: reorder `read_revisions_from_stdin()`

11 months agoThe sixth batch
Junio C Hamano [Thu, 29 Jun 2023 22:57:26 +0000 (15:57 -0700)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoMerge branch 'tb/gc-recent-object-hook'
Junio C Hamano [Thu, 29 Jun 2023 23:43:21 +0000 (16:43 -0700)] 
Merge branch 'tb/gc-recent-object-hook'

Test update.

* tb/gc-recent-object-hook:
  t7701: make annotated tag unreachable

11 months agoMerge branch 'jc/abort-ll-merge-with-a-signal'
Junio C Hamano [Thu, 29 Jun 2023 23:43:21 +0000 (16:43 -0700)] 
Merge branch 'jc/abort-ll-merge-with-a-signal'

When the external merge driver is killed by a signal, its output
should not be trusted as a resolution with conflicts that is
proposed by the driver, but the code did.

* jc/abort-ll-merge-with-a-signal:
  t6406: skip "external merge driver getting killed by a signal" test on Windows
  ll-merge: killing the external merge driver aborts the merge

11 months agoMerge branch 'en/header-split-cache-h-part-3'
Junio C Hamano [Thu, 29 Jun 2023 23:43:20 +0000 (16:43 -0700)] 
Merge branch 'en/header-split-cache-h-part-3'

Header files cleanup.

* en/header-split-cache-h-part-3: (28 commits)
  fsmonitor-ll.h: split this header out of fsmonitor.h
  hash-ll, hashmap: move oidhash() to hash-ll
  object-store-ll.h: split this header out of object-store.h
  khash: name the structs that khash declares
  merge-ll: rename from ll-merge
  git-compat-util.h: remove unneccessary include of wildmatch.h
  builtin.h: remove unneccessary includes
  list-objects-filter-options.h: remove unneccessary include
  diff.h: remove unnecessary include of oidset.h
  repository: remove unnecessary include of path.h
  log-tree: replace include of revision.h with simple forward declaration
  cache.h: remove this no-longer-used header
  read-cache*.h: move declarations for read-cache.c functions from cache.h
  repository.h: move declaration of the_index from cache.h
  merge.h: move declarations for merge.c from cache.h
  diff.h: move declaration for global in diff.c from cache.h
  preload-index.h: move declarations for preload-index.c from elsewhere
  sparse-index.h: move declarations for sparse-index.c from cache.h
  name-hash.h: move declarations for name-hash.c from cache.h
  run-command.h: move declarations for run-command.c from cache.h
  ...

11 months agoMerge branch 'ds/remove-idx-before-pack'
Junio C Hamano [Thu, 29 Jun 2023 23:43:20 +0000 (16:43 -0700)] 
Merge branch 'ds/remove-idx-before-pack'

We create .pack and then .idx, we consider only packfiles that have
.idx usable (those with only .pack are not ready yet), so we should
remove .idx before removing .pack for consistency.

* ds/remove-idx-before-pack:
  packfile: delete .idx files before .pack files

11 months agofsck: avoid misleading variable name
Eric Sunshine [Thu, 29 Jun 2023 18:13:33 +0000 (14:13 -0400)] 
fsck: avoid misleading variable name

When reporting a problem, `git fsck` emits a message such as:

    missing blob 1234abcd (:file)

However, this can be ambiguous when the problem is detected in the index
of a worktree other than the one in which `git fsck` was invoked. To
address this shortcoming, 592ec63b38 (fsck: mention file path for index
errors, 2023-02-24) enhanced the output to mention the path of the index
when the problem is detected in some other worktree:

    missing blob 1234abcd (.git/worktrees/wt/index:file)

Unfortunately, the variable in fsck_index() which controls whether the
index path should be shown is misleadingly named "is_main_index" which
can be misunderstood as referring to the main worktree (i.e. the one
housing the .git/ repository) rather than to the current worktree (i.e.
the one in which `git fsck` was invoked). Avoid such potential confusion
by choosing a name more reflective of its actual purpose.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agot4205: correctly test %(describe:abbrev=...)
Kousik Sanagavarapu [Thu, 29 Jun 2023 13:18:08 +0000 (18:48 +0530)] 
t4205: correctly test %(describe:abbrev=...)

The pretty format %(describe:abbrev=<number>) tells describe to use
at least <number> digits of the oid to generate the human-readable
format of the commit-ish.

There are three things to test here:
  - Check that we can describe a commit that is not tagged (that is,
    for example our HEAD is at least one commit ahead of some reachable
    commit which is tagged) with at least <number> digits of the oid
    being used for describing it.

  - Check that when using such a commit-ish, we always use at least
    <number> digits of the oid to describe it.

  - Check that we can describe a tag. This just gives the name of the
    tag irrespective of abbrev (abbrev doesn't make sense here).

Do this, instead of the current test which only tests the last case.

Helped-by: Junio C Hamano <gitster@pobox.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocommit -a -m: allow the top-level tree to become empty again
Johannes Schindelin [Thu, 29 Jun 2023 13:23:10 +0000 (13:23 +0000)] 
commit -a -m: allow the top-level tree to become empty again

In 03267e8656c (commit: discard partial cache before (re-)reading it,
2022-11-08), a memory leak was plugged by discarding any partial index
before re-reading it.

The problem with this memory leak fix is that it was based on an
incomplete understanding of the logic introduced in 7168624c353 (Do not
generate full commit log message if it is not going to be used,
2007-11-28).

That logic was introduced to add a shortcut when committing without
editing the commit message interactively. A part of that logic was to
ensure that the index was read into memory:

if (!active_nr && read_cache() < 0)
die(...)

Translation to English: If the index has not yet been read, read it, and
if that fails, error out.

That logic was incorrect, though: It used `!active_nr` as an indicator
that the index was not yet read. Usually this is not a problem because
in the vast majority of instances, the index contains at least one
entry.

And it was natural to do it this way because at the time that condition
was introduced, the `index_state` structure had no explicit flag to
indicate that it was initialized: This flag was only introduced in
913e0e99b6a (unpack_trees(): protect the handcrafted in-core index from
read_cache(), 2008-08-23), but that commit did not adjust the code path
where no index file was found and a new, pristine index was initialized.

Now, when the index does not contain any entry (which is quite
common in Git's test suite because it starts quite a many repositories
from scratch), subsequent calls to `do_read_index()` will mistake the
index not to be initialized, and read it again unnecessarily.

This is a problem because after initializing the empty index e.g. the
`cache_tree` in that index could have been initialized before a
subsequent call to `do_read_index()` wants to ensure an initialized
index. And if that subsequent call mistakes the index not to have been
initialized, it would lead to leaked memory.

The correct fix for that memory leak is to adjust the condition so that
it does not mistake `active_nr == 0` to mean that the index has not yet
been read.

Using the `initialized` flag instead, we avoid that mistake, and as a
bonus we can fix a bug at the same time that was introduced by the
memory leak fix: When deleting all tracked files and then asking `git
commit -a -m ...` to commit the result, Git would internally update the
index, then discard and re-read the index undoing the update, and fail
to commit anything.

This fixes https://github.com/git-for-windows/git/issues/4462

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agosplit-index: accept that a base index can be empty
Johannes Schindelin [Thu, 29 Jun 2023 13:23:09 +0000 (13:23 +0000)] 
split-index: accept that a base index can be empty

We are about to fix an ancient bug where `do_read_index()` pretended
that the index was not initialized when there are no index entries.

Before the `index_state` structure gained the `initialized` flag in
913e0e99b6a (unpack_trees(): protect the handcrafted in-core index from
read_cache(), 2008-08-23), that was the best we could do (even if it was
incorrect: it is totally possible to read a Git index file that contains
no index entries).

This pattern was repeated also in 998330ac2e7 (read-cache: look for
shared index files next to the index, too, 2021-08-26), which we fix
here by _not_ mistaking an empty base index for a missing
`sharedindex.*` file.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agodo_read_index(): always mark index as initialized unless erroring out
Johannes Schindelin [Thu, 29 Jun 2023 13:23:08 +0000 (13:23 +0000)] 
do_read_index(): always mark index as initialized unless erroring out

In 913e0e99b6a (unpack_trees(): protect the handcrafted in-core index
from read_cache(), 2008-08-23) a flag was introduced into the
`index_state` structure to indicate whether it had been initialized (or
more correctly: read and parsed).

There was one code path that was not handled, though: when the index
file does not yet exist (but the `must_exist` parameter is set to 0 to
indicate that that's okay). In this instance, Git wants to go forward
with a new, pristine Git index, almost as if the file had existed and
contained no index entries or extensions.

Since Git wants to handle this situation the same as if an "empty" Git
index file existed, let's set the `initialized` flag also in that case.

This is necessary to prepare for fixing the bug where the condition
`cache_nr == 0` is incorrectly used as an indicator that the index was
already read, and the condition `initialized != 0` needs to be used
instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agodocs: add git hash-object -t option's possible values
John Cai [Thu, 29 Jun 2023 02:07:53 +0000 (02:07 +0000)] 
docs: add git hash-object -t option's possible values

The summary under the NAME section for git hash-object can mislead
readers to conclude that the command can only be used to create blobs,
whereas the description makes it clear that it can be used to create
objects, not just blobs. Let's clarify the one-line summary.

Further, the description for the option -t does not list out other types
that can be used when creating objects. Let's make this explicit by
listing out the different object types.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: pass source to config_parser_event_fn_t
Glen Choo [Wed, 28 Jun 2023 19:26:30 +0000 (19:26 +0000)] 
config: pass source to config_parser_event_fn_t

..so that the callback can use a "struct config_source" parameter
instead of "config_reader.source". "struct config_source" is internal to
config.c, so we are adding a pointer to a struct defined in config.c
into a public function signature defined in config.h, but this is okay
because this function has only ever been (and probably ever will be)
used internally by config.c.

As a result, the_reader isn't used anywhere, so "struct config_reader"
is obsolete (it was only intended to be used with the_reader). Remove
them.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: add kvi.path, use it to evaluate includes
Glen Choo [Wed, 28 Jun 2023 19:26:29 +0000 (19:26 +0000)] 
config: add kvi.path, use it to evaluate includes

Include directives are evaluated using the path of the config file. To
reduce the dependence on "config_reader.source", add a new
"key_value_info.path" member and use that instead of
"config_source.path". This allows us to remove a "struct config_reader
*" field from "struct config_include_data", which will subsequently
allow us to remove "struct config_reader" entirely.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig.c: remove config_reader from configsets
Glen Choo [Wed, 28 Jun 2023 19:26:28 +0000 (19:26 +0000)] 
config.c: remove config_reader from configsets

Remove the last usage of "struct config_reader" from configsets by
copying the "kvi" arg instead of recomputing "kvi" from
config_reader.source. Since we no longer need to pass both "struct
config_reader" and "struct config_set" in a single "void *cb", remove
"struct configset_add_data" too.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: pass kvi to die_bad_number()
Glen Choo [Wed, 28 Jun 2023 19:26:27 +0000 (19:26 +0000)] 
config: pass kvi to die_bad_number()

Plumb "struct key_value_info" through all code paths that end in
die_bad_number(), which lets us remove the helper functions that read
analogous values from "struct config_reader". As a result, nothing reads
config_reader.config_kvi any more, so remove that too.

In config.c, this requires changing the signature of
git_configset_get_value() to 'return' "kvi" in an out parameter so that
git_configset_get_<type>() can pass it to git_config_<type>(). Only
numeric types will use "kvi", so for non-numeric types (e.g.
git_configset_get_string()), pass NULL to indicate that the out
parameter isn't needed.

Outside of config.c, config callbacks now need to pass "ctx->kvi" to any
of the git_config_<type>() functions that parse a config string into a
number type. Included is a .cocci patch to make that refactor.

The only exceptional case is builtin/config.c, where git_config_<type>()
is called outside of a config callback (namely, on user-provided input),
so config source information has never been available. In this case,
die_bad_number() defaults to a generic, but perfectly descriptive
message. Let's provide a safe, non-NULL for "kvi" anyway, but make sure
not to change the message.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agotrace2: plumb config kvi
Glen Choo [Wed, 28 Jun 2023 19:26:26 +0000 (19:26 +0000)] 
trace2: plumb config kvi

There is a code path starting from trace2_def_param_fl() that eventually
calls current_config_scope(), and thus it needs to have "kvi" plumbed
through it. Additional plumbing is also needed to get "kvi" to
trace2_def_param_fl(), which gets called by two code paths:

- Through tr2_cfg_cb(), which is a config callback, so it trivially
  receives "kvi" via the "struct config_context ctx" parameter.

- Through tr2_list_env_vars_fl(), which is a high level function that
  lists environment variables for tracing. This has been secretly
  behaving like git_config_from_parameters() (in that it parses config
  from environment variables/the CLI), but does not set config source
  information.

  Teach tr2_list_env_vars_fl() to be well-behaved by using
  kvi_from_param(), which is used elsewhere for CLI/environment
  variable-based config.

As a result, current_config_scope() has no more callers, so remove it.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig.c: pass ctx with CLI config
Glen Choo [Wed, 28 Jun 2023 19:26:25 +0000 (19:26 +0000)] 
config.c: pass ctx with CLI config

Pass config_context when parsing CLI config. To provide the .kvi member,
refactor out kvi_from_param() from the logic that caches CLI config in
configsets. Now that config_context and config_context.kvi is always
present when config machinery calls config callbacks, plumb "kvi" so
that we can remove all calls of current_config_scope() except for
trace2/*.c (which will be handled in a later commit), and remove all
other current_config_*() (the functions themselves and their calls).
Note that this results in .kvi containing a different, more complete
set of information than the mocked up "struct config_source" in
git_config_from_parameters().

Plumbing "kvi" reveals a few places where we've been doing the wrong
thing:

* git_config_parse_parameter() hasn't been setting config source
  information, so plumb "kvi" there too.

* Several sites in builtin/config.c have been calling current_config_*()
  functions outside of config callbacks (indirectly, via the
  format_config() helper), which means they're reading state that isn't
  set correctly:

  * "git config --get-urlmatch --show-scope" iterates config to collect
    values, but then attempts to display the scope after config
    iteration, causing the "unknown" scope to be shown instead of the
    config file's scope. It's clear that this wasn't intended: we knew
    that "--get-urlmatch" couldn't show config source metadata, which is
    why "--show-origin" was marked incompatible with "--get-urlmatch"
    when it was introduced [1]. It was most likely a mistake that we
    allowed "--show-scope" to sneak through.

    Fix this by copying the "kvi" value in the collection phase so that
    it can be read back later. This means that we can now support "git
    config --get-urlmatch --show-origin", but that is left unchanged
    for now.

  * "git config --default" doesn't have config source metadata when
    displaying the default value, so "--show-scope" also results in
    "unknown", and "--show-origin" results in a BUG(). Fix this by
    treating the default value as if it came from the command line (e.g.
    like we do with "git -c" or "git config --file"), using
    kvi_from_param().

[1] https://lore.kernel.org/git/20160205112001.GA13397@sigill.intra.peff.net/

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: pass ctx with config files
Glen Choo [Wed, 28 Jun 2023 19:26:24 +0000 (19:26 +0000)] 
config: pass ctx with config files

Pass config_context to config_callbacks when parsing config files. To
provide the .kvi member, refactor out the configset logic that caches
"struct config_source" and "enum config_scope" as a "struct
key_value_info". Make the "enum config_scope" available to the config
file machinery by plumbing an additional arg through
git_config_from_file_with_options().

We do not exercise ctx yet because the remaining current_config_*()
callers may be used with config_with_options(), which may read config
from parameters, but parameters don't pass ctx yet.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig.c: pass ctx in configsets
Glen Choo [Wed, 28 Jun 2023 19:26:23 +0000 (19:26 +0000)] 
config.c: pass ctx in configsets

Pass config_context to config callbacks in configset_iter(), trivially
setting the .kvi member to the cached key_value_info. Then, in config
callbacks that are only used with configsets, use the .kvi member to
replace calls to current_config_*(), and delete current_config_line()
because it has no remaining callers.

This leaves builtin/config.c and config.c as the only remaining users of
current_config_*().

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: add ctx arg to config_fn_t
Glen Choo [Wed, 28 Jun 2023 19:26:22 +0000 (19:26 +0000)] 
config: add ctx arg to config_fn_t

Add a new "const struct config_context *ctx" arg to config_fn_t to hold
additional information about the config iteration operation.
config_context has a "struct key_value_info kvi" member that holds
metadata about the config source being read (e.g. what kind of config
source it is, the filename, etc). In this series, we're only interested
in .kvi, so we could have just used "struct key_value_info" as an arg,
but config_context makes it possible to add/adjust members in the future
without changing the config_fn_t signature. We could also consider other
ways of organizing the args (e.g. moving the config name and value into
config_context or key_value_info), but in my experiments, the
incremental benefit doesn't justify the added complexity (e.g. a
config_fn_t will sometimes invoke another config_fn_t but with a
different config value).

In subsequent commits, the .kvi member will replace the global "struct
config_reader" in config.c, making config iteration a global-free
operation. It requires much more work for the machinery to provide
meaningful values of .kvi, so for now, merely change the signature and
call sites, pass NULL as a placeholder value, and don't rely on the arg
in any meaningful way.

Most of the changes are performed by
contrib/coccinelle/config_fn_ctx.pending.cocci, which, for every
config_fn_t:

- Modifies the signature to accept "const struct config_context *ctx"
- Passes "ctx" to any inner config_fn_t, if needed
- Adds UNUSED attributes to "ctx", if needed

Most config_fn_t instances are easily identified by seeing if they are
called by the various config functions. Most of the remaining ones are
manually named in the .cocci patch. Manual cleanups are still needed,
but the majority of it is trivial; it's either adjusting config_fn_t
that the .cocci patch didn't catch, or adding forward declarations of
"struct config_context ctx" to make the signatures make sense.

The non-trivial changes are in cases where we are invoking a config_fn_t
outside of config machinery, and we now need to decide what value of
"ctx" to pass. These cases are:

- trace2/tr2_cfg.c:tr2_cfg_set_fl()

  This is indirectly called by git_config_set() so that the trace2
  machinery can notice the new config values and update its settings
  using the tr2 config parsing function, i.e. tr2_cfg_cb().

- builtin/checkout.c:checkout_main()

  This calls git_xmerge_config() as a shorthand for parsing a CLI arg.
  This might be worth refactoring away in the future, since
  git_xmerge_config() can call git_default_config(), which can do much
  more than just parsing.

Handle them by creating a KVI_INIT macro that initializes "struct
key_value_info" to a reasonable default, and use that to construct the
"ctx" arg.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agourlmatch.h: use config_fn_t type
Glen Choo [Wed, 28 Jun 2023 19:26:21 +0000 (19:26 +0000)] 
urlmatch.h: use config_fn_t type

These are actually used as config callbacks, so use the typedef-ed type
and make future refactors easier.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: inline git_color_default_config
Glen Choo [Wed, 28 Jun 2023 19:26:20 +0000 (19:26 +0000)] 
config: inline git_color_default_config

git_color_default_config() is a shorthand for calling two other config
callbacks. There are no other non-static functions that do this and it
will complicate our refactoring of config_fn_t so inline it instead.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agofix cherry-pick/revert status when doing multiple commits
Jacob Keller [Tue, 27 Jun 2023 22:41:50 +0000 (15:41 -0700)] 
fix cherry-pick/revert status when doing multiple commits

The status report for an in-progress cherry-pick does not show the
current commit if the cherry-pick happens as part of a series of
multiple commits:

 $ git cherry-pick <commit1> <commit2>
 < one of the cherry-picks fails to merge clean >
 Cherry-pick currently in progress.
  (run "git cherry-pick --continue" to continue)
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

 $ git status
 On branch <branch>
 Your branch is ahead of '<upstream>' by 1 commit.
   (use "git push" to publish your local commits)

 Cherry-pick currently in progress.
   (run "git cherry-pick --continue" to continue)
   (use "git cherry-pick --skip" to skip this patch)
   (use "git cherry-pick --abort" to cancel the cherry-pick operation)

The show_cherry_pick_in_progress() function prints "Cherry-pick
currently in progress". That function does have a more verbose print
based on whether the cherry_pick_head_oid is null or not. If it is not
null, then a more helpful message including which commit is actually
being picked is displayed.

The introduction of the "Cherry-pick currently in progress" message
comes from 4a72486de97b ("fix cherry-pick/revert status after commit",
2019-04-17). This commit modified wt_status_get_state() in order to
detect that a cherry-pick was in progress even if the user has used `git
commit` in the middle of the sequence.

The check used to detect this is the call to sequencer_get_last_command.
If the sequencer indicates that the lass command was a REPLAY_PICK, then
the state->cherry_pick_in_progress is set to 1 and the
cherry_pick_head_oid is initialized to the null_oid. Similar behavior is
done for the case of REPLAY_REVERT.

It happens that this call of sequencer_get_last_command will always
report the action even if the user hasn't interrupted anything. Thus,
during a range of cherry-picks or reverts, the cherry_pick_head_oid and
revert_head_oid will always be overwritten and initialized to the null
oid.

This results in status always displaying the terse message which does
not include commit information.

Fix this by adding an additional check so that we do not re-initialize
the cherry_pick_head_oid or revert_head_oid if we have already set the
cherry_pick_in_progress or revert_in_progress bits. This ensures that
git status will display the more helpful information when its available.
Add a test case covering this behavior.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: add config file locations
brian m. carlson [Tue, 27 Jun 2023 16:19:02 +0000 (16:19 +0000)] 
var: add config file locations

Much like with attributes files, sometimes programs would like to know
the location of configuration files at the global or system levels.
However, it isn't always clear where these may live, especially for the
system file, which may have been hard-coded at compile time or computed
dynamically based on the runtime prefix.

Since other parties cannot intuitively know how Git was compiled and
where it looks for these files, help them by providing variables that
can be queried.  Because we have multiple paths for global config
values, print them in order from highest to lowest priority, and be sure
to split on newlines so that "git var -l" produces two entries for the
global value.

However, be careful not to split all values on newlines, since our
editor values could well contain such characters, and we don't want to
split them in such a case.

Note in the documentation that some values may contain multiple paths
and that callers should be prepared for that fact.  This helps people
write code that will continue to work in the event we allow multiple
items elsewhere in the future.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: add attributes files locations
brian m. carlson [Tue, 27 Jun 2023 16:19:01 +0000 (16:19 +0000)] 
var: add attributes files locations

Currently, there are some programs which would like to read and parse
the gitattributes files at the global or system levels.  However, it's
not always obvious where these files live, especially for the system
file, which may have been hard-coded at compile time or computed
dynamically based on the runtime prefix.

It's not reasonable to expect all callers of Git to intuitively know
where the Git distributor or user has configured these locations to
be, so add some entries to allow us to determine their location.  Honor
the GIT_ATTR_NOSYSTEM environment variable if one is specified.  Expose
the accessor functions in a way that we can reuse them from within the
var code.

In order to make our paths consistent on Windows and also use the same
form as paths use in "git rev-parse", let's normalize the path before we
return it.  This results in Windows-style paths that use slashes, which
is convenient for making our tests function in a consistent way across
platforms.  Note that this requires that some of our values be freed, so
let's add a flag about whether the value needs to be freed and use it
accordingly.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoattr: expose and rename accessor functions
brian m. carlson [Tue, 27 Jun 2023 16:19:00 +0000 (16:19 +0000)] 
attr: expose and rename accessor functions

Right now, the functions which determine the current system and global
gitattributes files are not exposed.  We'd like to use them in a future
commit, but they're not ideally named.  Rename them to something more
suitable as a public interface, expose them, and document them.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: adjust memory allocation for strings
brian m. carlson [Tue, 27 Jun 2023 16:18:59 +0000 (16:18 +0000)] 
var: adjust memory allocation for strings

Right now, all of our values are constants whose allocation is managed
elsewhere.  However, in the future, we'll have some variables whose
memory we will need to free.  To keep things consistent, let's make each
of our functions allocate its own memory and make the caller responsible
for freeing it.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: format variable structure with C99 initializers
brian m. carlson [Tue, 27 Jun 2023 16:18:58 +0000 (16:18 +0000)] 
var: format variable structure with C99 initializers

Right now, we have only two items in our variable struct.  However, in
the future, we're going to add two more items.  To help keep our diffs
nice and tidy and make this structure easier to read, switch to use
C99-style initializers for our data.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: add support for listing the shell
brian m. carlson [Tue, 27 Jun 2023 16:18:57 +0000 (16:18 +0000)] 
var: add support for listing the shell

On most Unix systems, finding a suitable shell is easy: one simply uses
"sh" with an appropriate PATH value.  However, in many Windows
environments, the shell is shipped alongside Git, and it may or may not
be in PATH, even if Git is.

In such an environment, it can be very helpful to query Git for the
shell it's using, since other tools may want to use the same shell as
well.  To help them out, let's add a variable, GIT_SHELL_PATH, that
points to the location of the shell.

On Unix, we know our shell must be executable to be functional, so
assume that the distributor has correctly configured their environment,
and use that as a basic test.  On Git for Windows, we know that our
shell will be one of a few fixed values, all of which end in "sh" (such
as "bash").  This seems like it might be a nice test on Unix as well,
since it is customary for all shells to end in "sh", but there probably
exist such systems that don't have such a configuration, so be careful
here not to break them.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agot: add a function to check executable bit
brian m. carlson [Tue, 27 Jun 2023 16:18:56 +0000 (16:18 +0000)] 
t: add a function to check executable bit

In line with our other helper functions for paths, let's add a function
to check whether a path is executable, and if not, print a suitable
error message.  Document this function, and note that it must only be
used under the POSIXPERM prerequisite, since it doesn't otherwise work
on Windows.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agovar: mark unused parameters in git_var callbacks
Jeff King [Tue, 27 Jun 2023 16:18:55 +0000 (16:18 +0000)] 
var: mark unused parameters in git_var callbacks

We abstract the set of variables into a table, with a "read" callback to
provide the value of each. Each callback takes a "flag" argument, but
most callbacks don't make use of it.

This flag is a bit odd. It may be set to IDENT_STRICT, which make sense
for ident-based callbacks, but is just confusing for things like
GIT_EDITOR.

At first glance, it seems like this is just a hack to let us directly
stick the generic git_committer_info() and git_author_info() functions
into our table. And we'd be better off to wrap them with local functions
which pass IDENT_STRICT, and have our callbacks take no option at all.

But that doesn't quite work. We pass IDENT_STRICT when the caller asks
for a specific variable, but otherwise do not (so that "git var -l" does
not bail if the committer ident cannot be formed).

So we really do need to pass in the flag to each invocation, even if the
individual callback doesn't care about it. Let's mark the unused ones so
that -Wunused-parameter does not complain. And while we're here, let's
rename them so that it's clear that the flag values we get will be from
the IDENT_* set. That may prevent confusion for future readers of the
code.

Another option would be to define our own local "strict" flag for the
callbacks, and then have wrappers that translate that to IDENT_STRICT
where it matters. But that would be more boilerplate for little gain
(most functions would still ignore the "strict" flag anyway).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoconfig: don't BUG when both kvi and source are set
Glen Choo [Mon, 26 Jun 2023 17:41:37 +0000 (17:41 +0000)] 
config: don't BUG when both kvi and source are set

When iterating through config, we read config source metadata from
global values - either a "struct config_source + enum config_scope"
or a "struct key_value_info", using the current_config* functions. Prior
to the series starting from 0c60285147 (config.c: create config_reader
and the_reader, 2023-03-28), we weren't very picky about which values we
should read in which situation; we did note that both groups of values
generally shouldn't be set together, but if both were set,
current_config* preferentially reads key_value_info. When that series
added more structure, we enforced that either the former (when parsing a
config source) can be set, or the latter (when iterating a config set),
but *never* both at the same time. See 9828453ff0 (config.c: remove
current_config_kvi, 2023-03-28) and 5cdf18e7cd (config.c: remove
current_parsing_scope, 2023-03-28).

That was a good simplifying constraint that helped us reason about the
global state, but it turns out that there is at least one situation
where we need both to be set at the same time: in a blobless partial
clone where .gitmodules is missing. "git fetch" in such a repo will
start a config parse over .gitmodules (setting the config_source), and
Git will attempt to lazy-fetch it from the promisor remote. However,
when we try to read the promisor configuration, we start iterating a
config set (setting the key_value_info), and we BUG() out because that's
not allowed any more.

Teaching config_reader to gracefully handle this is somewhat
complicated, but fortunately, there are proposed changes to the config.c
machinery to get rid of this global state, and make the BUG() obsolete
[1]. We should rely on that as the eventual solution, and avoid doing
yet another refactor in the meantime.

Therefore, fix the bug by removing the BUG() check. We're reverting to
an older, less safe state, but that's generally okay since
key_value_info is always preferentially read, so we'd always read the
correct values when we iterate a config set in the middle of a config
parse (like we are here). The reverse would be wrong, but extremely
unlikely to happen since very few callers parse config without going
through a config set.

[1] https://lore.kernel.org/git/pull.1497.v3.git.git.1687290231.gitgitgadget@gmail.com

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agodiff.c: mention completion above add_diff_options
Philippe Blain [Mon, 26 Jun 2023 16:24:48 +0000 (16:24 +0000)] 
diff.c: mention completion above add_diff_options

Add a comment on top of add_diff_options, where common diff options are
listed, mentioning __git_diff_common_options in the completion script,
in the hope that contributors update it when they add new diff flags.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --remerge-diff
Philippe Blain [Mon, 26 Jun 2023 16:24:47 +0000 (16:24 +0000)] 
completion: complete --remerge-diff

--remerge-diff only makes sense for 'git log' and 'git show', so add it
to __git_log_show_options which is referenced in the completion for
these two commands.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --diff-merges, its options and --no-diff-merges
Philippe Blain [Mon, 26 Jun 2023 16:24:46 +0000 (16:24 +0000)] 
completion: complete --diff-merges, its options and --no-diff-merges

The flags --[no-]diff-merges only make sense for 'git log' and 'git
show', so add a new variable __git_log_show_options for options only
relevant to these two commands, and add them there. Also add
__git_diff_merges_opts and list the accepted values for --diff-merges,
and use it in _git_log and _git_show.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: move --pickaxe-{all,regex} to __git_diff_common_options
Philippe Blain [Mon, 26 Jun 2023 16:24:45 +0000 (16:24 +0000)] 
completion: move --pickaxe-{all,regex} to __git_diff_common_options

The options --pickaxe-all and --pickaxe-regex are listed in
__git_diff_difftool_options and repeated in _git_log. Move them to
__git_diff_common_options instead, which makes them available
automatically in the completion of other commands referencing this
variable.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --ws-error-highlight
Philippe Blain [Mon, 26 Jun 2023 16:24:44 +0000 (16:24 +0000)] 
completion: complete --ws-error-highlight

Add --ws-error-highlight= to the list in __git_diff_common_options, and
add the accepted values in a new list __git_ws_error_highlight_opts.

Use __git_ws_error_highlight_opts in _git_diff, _git_log and _git_show
to offer the accepted values.

As noted in fd0bc17557 (completion: add diff --color-moved[-ws],
2020-02-21), there is no easy way to offer completion for several
comma-separated values, so this is limited to completing a single
value.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --unified
Philippe Blain [Mon, 26 Jun 2023 16:24:43 +0000 (16:24 +0000)] 
completion: complete --unified

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --output-indicator-{context,new,old}
Philippe Blain [Mon, 26 Jun 2023 16:24:42 +0000 (16:24 +0000)] 
completion: complete --output-indicator-{context,new,old}

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --output
Philippe Blain [Mon, 26 Jun 2023 16:24:41 +0000 (16:24 +0000)] 
completion: complete --output

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --no-stat
Philippe Blain [Mon, 26 Jun 2023 16:24:40 +0000 (16:24 +0000)] 
completion: complete --no-stat

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --no-relative
Philippe Blain [Mon, 26 Jun 2023 16:24:39 +0000 (16:24 +0000)] 
completion: complete --no-relative

Add --no-relative to __git_diff_common_options in the completion script,
and move --relative from __git_diff_difftool_options to
__git_diff_common_options since it applies to more than just diff and
difftool.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --line-prefix
Philippe Blain [Mon, 26 Jun 2023 16:24:38 +0000 (16:24 +0000)] 
completion: complete --line-prefix

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --ita-invisible-in-index and --ita-visible-in-index
Philippe Blain [Mon, 26 Jun 2023 16:24:37 +0000 (16:24 +0000)] 
completion: complete --ita-invisible-in-index and --ita-visible-in-index

The options --ita-invisible-in-index and --ita-visible-in-index are
listed in diff-options.txt and so are included in the documentation of
commands which include this file (diff, diff-*, log, show, format-patch)
but they only make sense for diffs relating to the index. As such, add
them to '__git_diff_difftool_options' instead of
'__git_diff_common_options' since it makes more sense to add them there.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --irreversible-delete
Philippe Blain [Mon, 26 Jun 2023 16:24:36 +0000 (16:24 +0000)] 
completion: complete --irreversible-delete

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --ignore-matching-lines
Philippe Blain [Mon, 26 Jun 2023 16:24:35 +0000 (16:24 +0000)] 
completion: complete --ignore-matching-lines

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --function-context
Philippe Blain [Mon, 26 Jun 2023 16:24:34 +0000 (16:24 +0000)] 
completion: complete --function-context

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --find-renames
Philippe Blain [Mon, 26 Jun 2023 16:24:33 +0000 (16:24 +0000)] 
completion: complete --find-renames

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --find-object
Philippe Blain [Mon, 26 Jun 2023 16:24:32 +0000 (16:24 +0000)] 
completion: complete --find-object

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --find-copies
Philippe Blain [Mon, 26 Jun 2023 16:24:31 +0000 (16:24 +0000)] 
completion: complete --find-copies

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --default-prefix
Philippe Blain [Mon, 26 Jun 2023 16:24:30 +0000 (16:24 +0000)] 
completion: complete --default-prefix

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --compact-summary
Philippe Blain [Mon, 26 Jun 2023 16:24:29 +0000 (16:24 +0000)] 
completion: complete --compact-summary

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --combined-all-paths
Philippe Blain [Mon, 26 Jun 2023 16:24:28 +0000 (16:24 +0000)] 
completion: complete --combined-all-paths

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --cc
Philippe Blain [Mon, 26 Jun 2023 16:24:27 +0000 (16:24 +0000)] 
completion: complete --cc

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: complete --break-rewrites
Philippe Blain [Mon, 26 Jun 2023 16:24:26 +0000 (16:24 +0000)] 
completion: complete --break-rewrites

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agocompletion: add comments describing __git_diff_* globals
Philippe Blain [Mon, 26 Jun 2023 16:24:25 +0000 (16:24 +0000)] 
completion: add comments describing __git_diff_* globals

Add descriptive comments for '__git_diff_common_options' and
'__git_diff_difftool_options', so that it is clearer when looking at
these variables to know in which command's completion they are used.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoThe fifth batch
Junio C Hamano [Mon, 26 Jun 2023 16:29:17 +0000 (09:29 -0700)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoMerge branch 'tb/collect-pack-filenames-fix'
Junio C Hamano [Mon, 26 Jun 2023 16:29:49 +0000 (09:29 -0700)] 
Merge branch 'tb/collect-pack-filenames-fix'

Avoid breakage of "git pack-objects --cruft" due to inconsistency
between the way the code enumerates packfiles in the repository.

* tb/collect-pack-filenames-fix:
  builtin/repack.c: only collect fully-formed packs

11 months agoMerge branch 'jk/commit-use-no-divider-with-interpret-trailers'
Junio C Hamano [Mon, 26 Jun 2023 16:29:49 +0000 (09:29 -0700)] 
Merge branch 'jk/commit-use-no-divider-with-interpret-trailers'

When "git commit --trailer=..." invokes the interpret-trailers
machinery, it knows what it feeds to interpret-trailers is a full
log message without any patch, but failed to express that by
passing the "--no-divider" option, which has been corrected.

* jk/commit-use-no-divider-with-interpret-trailers:
  commit: pass --no-divider to interpret-trailers

11 months agoapply: improve error messages when reading patch
Phillip Wood [Mon, 26 Jun 2023 09:37:33 +0000 (09:37 +0000)] 
apply: improve error messages when reading patch

Commit f1c0e3946e (apply: reject patches larger than ~1 GiB, 2022-10-25)
added a limit on the size of patch that apply will process to avoid
integer overflows. The implementation re-used the existing error message
for when we are unable to read the patch. This is unfortunate because (a) it
does not signal to the user that the patch is being rejected because it
is too large and (b) it uses error_errno() without setting errno.

This patch adds a specific error message for the case when a patch is
too large. It also updates the existing message to make it clearer that
it is the patch that cannot be read rather than any other file and marks
both messages for translation. The "git apply" prefix is also dropped to
match most of the rest of the error messages in apply.c (there are still
a few error messages that prefixed with "git apply" and are not marked
for translation after this patch). The test added in f1c0e3946e is
updated accordingly.

Reported-by: Premek Vysoky <Premek.Vysoky@microsoft.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agot7701: make annotated tag unreachable
Taylor Blau [Sat, 24 Jun 2023 14:33:47 +0000 (10:33 -0400)] 
t7701: make annotated tag unreachable

In 4dc16e2cb0 (gc: introduce `gc.recentObjectsHook`, 2023-06-07), we
added tests to ensure that prune-able (i.e. unreachable and with mtime
older than the cutoff) objects which are marked as recent via the new
`gc.recentObjectsHook` configuration are unpacked as loose with
`--unpack-unreachable`.

In that test, we also ensure that objects which are reachable from other
unreachable objects which were *not* pruned are kept as well, regardless
of their mtimes. For this, we use an annotated tag pointing at a blob
($obj2) which would otherwise be pruned.

But after pruning, that object is kept around for two reasons. One, the
tag object's mtime wasn't adjusted to be beyond the 1-hour cutoff, so it
would be kept as due to its recency regardless. The other reason is
because the tag itself is reachable.

Use mktag to write the tag object directly without pointing a reference
at it, and adjust the mtime of the tag object to be older than the
cutoff to ensure that our `gc.recentObjectsHook` configuration is
working as intended.

Noticed-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoMerge branch 'maint'
Junio C Hamano [Sat, 24 Jun 2023 22:05:06 +0000 (15:05 -0700)] 
Merge branch 'maint'

* maint:
  http: handle both "h2" and "h2h3" in curl info lines

11 months agoMerge branch 'jk/redact-h2h3-headers-fix' into maint-2.41
Junio C Hamano [Sat, 24 Jun 2023 22:04:48 +0000 (15:04 -0700)] 
Merge branch 'jk/redact-h2h3-headers-fix' into maint-2.41

* jk/redact-h2h3-headers-fix:
  http: handle both "h2" and "h2h3" in curl info lines

11 months agot6406: skip "external merge driver getting killed by a signal" test on Windows
Junio C Hamano [Fri, 23 Jun 2023 23:34:40 +0000 (16:34 -0700)] 
t6406: skip "external merge driver getting killed by a signal" test on Windows

The run_command() on the platform does not seem to report death by
signal as the caller expects.  For now, skip the test on Windows.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoThe fourth batch
Junio C Hamano [Fri, 23 Jun 2023 18:21:28 +0000 (11:21 -0700)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
11 months agoMerge branch 'js/defeat-ignore-submodules-config-with-explicit-addition'
Junio C Hamano [Fri, 23 Jun 2023 18:21:17 +0000 (11:21 -0700)] 
Merge branch 'js/defeat-ignore-submodules-config-with-explicit-addition'

Even when diff.ignoreSubmodules tells us to ignore submodule
changes, "git commit" with an index that already records changes to
submodules should include the submodule changes in the resulting
commit, but it did not.

* js/defeat-ignore-submodules-config-with-explicit-addition:
  diff-lib: honor override_submodule_config flag bit

11 months agoMerge branch 'rj/leakfixes'
Junio C Hamano [Fri, 23 Jun 2023 18:21:17 +0000 (11:21 -0700)] 
Merge branch 'rj/leakfixes'

Leakfixes

* rj/leakfixes:
  tests: mark as passing with SANITIZE=leak
  config: fix a leak in git_config_copy_or_rename_section_in_file
  branch: fix a leak in cmd_branch
  branch: fix a leak in setup_tracking
  rev-parse: fix a leak with --abbrev-ref
  branch: fix a leak in setup_tracking
  branch: fix a leak in check_tracking_branch
  branch: fix a leak in inherit_tracking
  branch: fix a leak in dwim_and_setup_tracking
  remote: fix a leak in query_matches_negative_refspec
  config: fix a leak in git_config_copy_or_rename_section_in_file

11 months agoMerge branch 'tb/open-midx-bitmap-fallback'
Junio C Hamano [Fri, 23 Jun 2023 18:21:17 +0000 (11:21 -0700)] 
Merge branch 'tb/open-midx-bitmap-fallback'

Gracefully deal with a stale MIDX file that lists a packfile that
no longer exists.

* tb/open-midx-bitmap-fallback:
  pack-bitmap.c: gracefully degrade on failure to load MIDX'd pack

11 months agoMerge branch 'tb/gc-recent-object-hook'
Junio C Hamano [Fri, 23 Jun 2023 18:21:17 +0000 (11:21 -0700)] 
Merge branch 'tb/gc-recent-object-hook'

"git pack-objects" learned to invoke a new hook program that
enumerates extra objects to be used as anchoring points to keep
otherwise unreachable objects in cruft packs.

* tb/gc-recent-object-hook:
  gc: introduce `gc.recentObjectsHook`
  reachable.c: extract `obj_is_recent()`

11 months agoMerge branch 'tz/lib-gpg-prereq-fix'
Junio C Hamano [Fri, 23 Jun 2023 18:21:16 +0000 (11:21 -0700)] 
Merge branch 'tz/lib-gpg-prereq-fix'

Test update.

* tz/lib-gpg-prereq-fix:
  t/lib-gpg: require GPGSSH for GPGSSH_VERIFYTIME prereq