]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
14 months agowt-status: don't show divergence advice when committing
Alex Henrie [Thu, 13 Jul 2023 04:41:13 +0000 (22:41 -0600)] 
wt-status: don't show divergence advice when committing

When the user is in the middle of making a commit, they are not yet at
the point where they are ready to think about integrating their local
branch with the corresponding remote branch or force-pushing over the
remote branch. Don't include advice on how to deal with divergent
branches in the commit template, to avoid giving the impression that the
divergence needs to be dealt with immediately. Similar advice will be
printed when it is most relevant, that is, if the user does try to push
without first reconciling the two branches.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 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>
14 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

14 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()`

14 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>
14 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

14 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

14 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
  ...

14 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

15 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>
15 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>
15 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>
15 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>
15 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>
15 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>
15 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>
15 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>
15 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>
15 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

15 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

15 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>
15 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

15 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

15 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>
15 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>
15 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

15 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

15 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

15 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()`

15 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

15 months agoMerge branch 'sl/worktree-sparse'
Junio C Hamano [Fri, 23 Jun 2023 18:21:16 +0000 (11:21 -0700)] 
Merge branch 'sl/worktree-sparse'

"git worktree" learned to work better with sparse index feature.

* sl/worktree-sparse:
  worktree: integrate with sparse-index

15 months agoMerge branch 'rs/run-command-exec-error-on-noent'
Junio C Hamano [Fri, 23 Jun 2023 18:21:16 +0000 (11:21 -0700)] 
Merge branch 'rs/run-command-exec-error-on-noent'

Simplify error message when run-command fails to start a command.

* rs/run-command-exec-error-on-noent:
  run-command: report exec error even on ENOENT
  t1800: loosen matching of error message for bad shebang

15 months agoMerge branch 'mh/credential-erase-improvements'
Junio C Hamano [Fri, 23 Jun 2023 18:21:16 +0000 (11:21 -0700)] 
Merge branch 'mh/credential-erase-improvements'

* mh/credential-erase-improvements:
  credential: erase all matching credentials
  credential: avoid erasing distinct password

15 months agoMerge branch 'gc/discover-not-setup'
Junio C Hamano [Fri, 23 Jun 2023 18:21:16 +0000 (11:21 -0700)] 
Merge branch 'gc/discover-not-setup'

discover_git_directory() no longer touches the_repository.

* gc/discover-not-setup:
  setup.c: don't setup in discover_git_directory()

15 months agoll-merge: killing the external merge driver aborts the merge
Junio C Hamano [Fri, 23 Jun 2023 00:33:01 +0000 (17:33 -0700)] 
ll-merge: killing the external merge driver aborts the merge

When an external merge driver dies with a signal, we should not
expect that the result left on the filesystem is in any useful
state.  However, because the current code uses the return value from
run_command() and declares any positive value as a sign that the
driver successfully left conflicts in the result, and because the
return value from run_command() for a subprocess that died upon a
signal is positive, we end up treating whatever garbage left on the
filesystem as the result the merge driver wanted to leave us.

run_command() returns larger than 128 (WTERMSIG(status) + 128, to be
exact) when it notices that the subprocess died with a signal, so
detect such a case and return LL_MERGE_ERROR from ll_ext_merge().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
15 months agoThe third batch
Junio C Hamano [Thu, 22 Jun 2023 23:28:50 +0000 (16:28 -0700)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoMerge branch 'jt/doc-use-octal-with-printf'
Junio C Hamano [Thu, 22 Jun 2023 23:29:07 +0000 (16:29 -0700)] 
Merge branch 'jt/doc-use-octal-with-printf'

Suggest to refrain from using hex literals that are non-portable
when writing printf(1) format strings.

* jt/doc-use-octal-with-printf:
  CodingGuidelines: use octal escapes, not hex

15 months agoMerge branch 'rs/doc-ls-tree-hex-literal'
Junio C Hamano [Thu, 22 Jun 2023 23:29:07 +0000 (16:29 -0700)] 
Merge branch 'rs/doc-ls-tree-hex-literal'

Doc update.

* rs/doc-ls-tree-hex-literal:
  ls-tree: fix documentation of %x format placeholder

15 months agoMerge branch 'la/docs-typofixes'
Junio C Hamano [Thu, 22 Jun 2023 23:29:06 +0000 (16:29 -0700)] 
Merge branch 'la/docs-typofixes'

Typofixes.

* la/docs-typofixes:
  docs: typofixes

15 months agoMerge branch 'as/dtype-compilation-fix'
Junio C Hamano [Thu, 22 Jun 2023 23:29:06 +0000 (16:29 -0700)] 
Merge branch 'as/dtype-compilation-fix'

Compilation fix for platforms without D_TYPE in struct dirent.

* as/dtype-compilation-fix:
  statinfo.h: move DTYPE defines from dir.h

15 months agoMerge branch 'ds/add-i-color-configuration-fix'
Junio C Hamano [Thu, 22 Jun 2023 23:29:06 +0000 (16:29 -0700)] 
Merge branch 'ds/add-i-color-configuration-fix'

The reimplemented "git add -i" did not honor color.ui configuration.

* ds/add-i-color-configuration-fix:
  add: test use of brackets when color is disabled
  add: check color.ui for interactive add

15 months agoMerge branch 'ps/cat-file-null-output'
Junio C Hamano [Thu, 22 Jun 2023 23:29:06 +0000 (16:29 -0700)] 
Merge branch 'ps/cat-file-null-output'

"git cat-file --batch" and friends learned "-Z" that uses NUL
delimiter for both input and output.

* ps/cat-file-null-output:
  cat-file: add option '-Z' that delimits input and output with NUL
  cat-file: simplify reading from standard input
  strbuf: provide CRLF-aware helper to read until a specified delimiter
  t1006: modernize test style to use `test_cmp`
  t1006: don't strip timestamps from expected results

15 months agoMerge branch 'ds/disable-replace-refs'
Junio C Hamano [Thu, 22 Jun 2023 23:29:05 +0000 (16:29 -0700)] 
Merge branch 'ds/disable-replace-refs'

Introduce a mechanism to disable replace refs globally and per
repository.

* ds/disable-replace-refs:
  repository: create read_replace_refs setting
  replace-objects: create wrapper around setting
  repository: create disable_replace_refs()

15 months agoMerge branch 'tb/pack-bitmap-traversal-with-boundary'
Junio C Hamano [Thu, 22 Jun 2023 23:29:05 +0000 (16:29 -0700)] 
Merge branch 'tb/pack-bitmap-traversal-with-boundary'

The object traversal using reachability bitmap done by
"pack-object" has been tweaked to take advantage of the fact that
using "boundary" commits as representative of all the uninteresting
ones can save quite a lot of object enumeration.

* tb/pack-bitmap-traversal-with-boundary:
  pack-bitmap.c: use commit boundary during bitmap traversal
  pack-bitmap.c: extract `fill_in_bitmap()`
  object: add object_array initializer helper function

15 months agoMerge branch 'ja/worktree-orphan'
Junio C Hamano [Thu, 22 Jun 2023 23:29:05 +0000 (16:29 -0700)] 
Merge branch 'ja/worktree-orphan'

'git worktree add' learned how to create a worktree based on an
orphaned branch with `--orphan`.

* ja/worktree-orphan:
  worktree add: emit warn when there is a bad HEAD
  worktree add: extend DWIM to infer --orphan
  worktree add: introduce "try --orphan" hint
  worktree add: add --orphan flag
  t2400: add tests to verify --quiet
  t2400: refactor "worktree add" opt exclusion tests
  t2400: cleanup created worktree in test
  worktree add: include -B in usage docs

15 months agofsmonitor-ll.h: split this header out of fsmonitor.h
Elijah Newren [Tue, 16 May 2023 06:34:08 +0000 (06:34 +0000)] 
fsmonitor-ll.h: split this header out of fsmonitor.h

This creates a new fsmonitor-ll.h with most of the functions from
fsmonitor.h, though it leaves three inline functions where they were.
Two-thirds of the files that previously included fsmonitor.h did not
need those three inline functions or the six extra includes those inline
functions required, so this allows them to only include the lower level
header.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agohash-ll, hashmap: move oidhash() to hash-ll
Elijah Newren [Tue, 16 May 2023 06:34:07 +0000 (06:34 +0000)] 
hash-ll, hashmap: move oidhash() to hash-ll

oidhash() was used by both hashmap and khash, which makes sense.
However, the location of this function in hashmap.[ch] meant that
khash.h had to depend upon hashmap.h, making people unfamiliar with
khash think that it was built upon hashmap.  (Or at least, I personally
was confused for a while about this in the past.)

Move this function to hash-ll, so that khash.h can stop depending upon
hashmap.h.

This has another benefit as well: it allows us to remove hashmap.h's
dependency on hash-ll.h.  While some callers of hashmap.h were making
use of oidhash, most were not, so this change provides another way to
reduce the number of includes.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoobject-store-ll.h: split this header out of object-store.h
Elijah Newren [Tue, 16 May 2023 06:34:06 +0000 (06:34 +0000)] 
object-store-ll.h: split this header out of object-store.h

The vast majority of files including object-store.h did not need dir.h
nor khash.h.  Split the header into two files, and let most just depend
upon object-store-ll.h, while letting the two callers that need it
depend on the full object-store.h.

After this patch:
    $ git grep -h include..object-store | sort | uniq -c
          2 #include "object-store.h"
        129 #include "object-store-ll.h"

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agokhash: name the structs that khash declares
Elijah Newren [Tue, 16 May 2023 06:34:05 +0000 (06:34 +0000)] 
khash: name the structs that khash declares

khash.h lets you instantiate custom hash types that map between two
types. These are defined as a struct, as you might expect, and khash
typedef's that to kh_foo_t. But it declares the struct anonymously,
which doesn't give a name to the struct type itself; there is no
"struct kh_foo". This has two small downsides:

  - when using khash, we declare "kh_foo_t *the_foo".  This is
    unlike our usual naming style, which is "struct kh_foo *the_foo".

  - you can't forward-declare a typedef of an unnamed struct type in
    C. So we might do something like this in a header file:

        struct kh_foo;
        struct bar {
                struct kh_foo *the_foo;
        };

    to avoid having to include the header that defines the real
    kh_foo. But that doesn't work with the typedef'd name. Without the
    "struct" keyword, the compiler doesn't know we mean that kh_foo is
    a type.

So let's always give khash structs the name that matches our
conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing
the typedef to retain compatibility with existing callers.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agomerge-ll: rename from ll-merge
Elijah Newren [Tue, 16 May 2023 06:34:04 +0000 (06:34 +0000)] 
merge-ll: rename from ll-merge

A long term (but rather minor) pet-peeve of mine was the name
ll-merge.[ch].  I thought it made it harder to realize what stuff was
related to merging when I was working on the merge machinery and trying
to improve it.

Further, back in d1cbe1e6d8a ("hash-ll.h: split out of hash.h to remove
dependency on repository.h", 2023-04-22), we have split the portions of
hash.h that do not depend upon repository.h into a "hash-ll.h" (due to
the recommendation to use "ll" for "low-level" in its name[1], but which
I used as a suffix precisely because of my distaste for "ll-merge").
When we discussed adding additional "*-ll.h" files, a request was made
that we use "ll" consistently as either a prefix or a suffix.  Since it
is already in use as both a prefix and a suffix, the only way to do so
is to rename some files.

Besides my distaste for the ll-merge.[ch] name, let me also note that
the files
  ll-fsmonitor.h, ll-hash.h, ll-merge.h, ll-object-store.h, ll-read-cache.h
would have essentially nothing to do with each other and make no sense
to group.  But giving them the common "ll-" prefix would group them.  Using
"-ll" as a suffix thus seems just much more logical to me.  Rename
ll-merge.[ch] to merge-ll.[ch] to achieve this consistency, and to
ensure we get a more logical grouping of files.

[1] https://lore.kernel.org/git/kl6lsfcu1g8w.fsf@chooglen-macbookpro.roam.corp.google.com/

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agogit-compat-util.h: remove unneccessary include of wildmatch.h
Elijah Newren [Tue, 16 May 2023 06:34:03 +0000 (06:34 +0000)] 
git-compat-util.h: remove unneccessary include of wildmatch.h

The include of wildmatch.h in git-compat-util.h was added in cebcab189aa
(Makefile: add USE_WILDMATCH to use wildmatch as fnmatch, 2013-01-01) as
a way to be able to compile-time force any calls to fnmatch() to instead
invoke wildmatch().  The defines and inline function were removed in
70a8fc999d9 (stop using fnmatch (either native or compat), 2014-02-15),
and this include in git-compat-util.h has been unnecessary ever since.

Remove the include from git-compat-util.h, but add it to the .c files
that had omitted the direct #include they needed.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agobuiltin.h: remove unneccessary includes
Elijah Newren [Tue, 16 May 2023 06:34:02 +0000 (06:34 +0000)] 
builtin.h: remove unneccessary includes

This also made it clear that a few .c files under builtin/ were
depending upon some headers but had forgotten to #include them.  Add the
missing direct includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agolist-objects-filter-options.h: remove unneccessary include
Elijah Newren [Tue, 16 May 2023 06:34:01 +0000 (06:34 +0000)] 
list-objects-filter-options.h: remove unneccessary include

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agodiff.h: remove unnecessary include of oidset.h
Elijah Newren [Tue, 16 May 2023 06:34:00 +0000 (06:34 +0000)] 
diff.h: remove unnecessary include of oidset.h

This also made it clear that several .c files depended upon various
things that oidset included, but had omitted the direct #include for
those headers.  Add those now.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agorepository: remove unnecessary include of path.h
Elijah Newren [Tue, 16 May 2023 06:33:59 +0000 (06:33 +0000)] 
repository: remove unnecessary include of path.h

This also made it clear that several .c files that depended upon path.h
were missing a #include for it; add the missing includes while at it.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agolog-tree: replace include of revision.h with simple forward declaration
Elijah Newren [Tue, 16 May 2023 06:33:58 +0000 (06:33 +0000)] 
log-tree: replace include of revision.h with simple forward declaration

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agocache.h: remove this no-longer-used header
Elijah Newren [Tue, 16 May 2023 06:33:57 +0000 (06:33 +0000)] 
cache.h: remove this no-longer-used header

Since this header showed up in some places besides just #include
statements, update/clean-up/remove those other places as well.

Note that compat/fsmonitor/fsm-path-utils-darwin.c previously got
away with violating the rule that all files must start with an include
of git-compat-util.h (or a short-list of alternate headers that happen
to include it first).  This change exposed the violation and caused it
to stop building correctly; fix it by having it include
git-compat-util.h first, as per policy.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoread-cache*.h: move declarations for read-cache.c functions from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:56 +0000 (06:33 +0000)] 
read-cache*.h: move declarations for read-cache.c functions from cache.h

For the functions defined in read-cache.c, move their declarations from
cache.h to a new header, read-cache-ll.h.  Also move some related inline
functions from cache.h to read-cache.h.  The purpose of the
read-cache-ll.h/read-cache.h split is that about 70% of the sites don't
need the inline functions and the extra headers they include.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agorepository.h: move declaration of the_index from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:55 +0000 (06:33 +0000)] 
repository.h: move declaration of the_index from cache.h

the_index is a global variable defined in repository.c; as such, its
declaration feels better suited living in repository.h rather than
cache.h.  Move it.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agomerge.h: move declarations for merge.c from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:54 +0000 (06:33 +0000)] 
merge.h: move declarations for merge.c from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agodiff.h: move declaration for global in diff.c from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:53 +0000 (06:33 +0000)] 
diff.h: move declaration for global in diff.c from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agopreload-index.h: move declarations for preload-index.c from elsewhere
Elijah Newren [Tue, 16 May 2023 06:33:52 +0000 (06:33 +0000)] 
preload-index.h: move declarations for preload-index.c from elsewhere

We already have a preload-index.c file; move the declarations for the
functions in that file into a new preload-index.h.  These were
previously split between cache.h and repository.h.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agosparse-index.h: move declarations for sparse-index.c from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:51 +0000 (06:33 +0000)] 
sparse-index.h: move declarations for sparse-index.c from cache.h

Note in particular that this reverses the decision made in 118a2e8bde0
("cache: move ensure_full_index() to cache.h", 2021-04-01).

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoname-hash.h: move declarations for name-hash.c from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:50 +0000 (06:33 +0000)] 
name-hash.h: move declarations for name-hash.c from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agorun-command.h: move declarations for run-command.c from cache.h
Elijah Newren [Tue, 16 May 2023 06:33:49 +0000 (06:33 +0000)] 
run-command.h: move declarations for run-command.c from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agostatinfo: move stat_{data,validity} functions from cache/read-cache
Elijah Newren [Tue, 16 May 2023 06:33:48 +0000 (06:33 +0000)] 
statinfo: move stat_{data,validity} functions from cache/read-cache

These functions do not depend upon struct cache_entry or struct
index_state in any way, and it seems more logical to break them out into
this file, especially since statinfo.h already has the struct stat_data
declaration.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoread-cache: move shared add/checkout/commit code
Elijah Newren [Tue, 16 May 2023 06:33:47 +0000 (06:33 +0000)] 
read-cache: move shared add/checkout/commit code

The function add_files_to_cache(), plus associated helper functions,
were defined in builtin/add.c, but also shared with builtin/checkout.c
and builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoadd: modify add_files_to_cache() to avoid globals
Elijah Newren [Tue, 16 May 2023 06:33:46 +0000 (06:33 +0000)] 
add: modify add_files_to_cache() to avoid globals

The function add_files_to_cache() is used by all three of builtin/{add,
checkout, commit}.c.  That suggests this is common library code, and
should be moved somewhere else, like read-cache.c.  However, the
function and its helpers made use of two global variables that made
straight code movement difficult:
  * the_index
  * include_sparse
The latter was perhaps more problematic since it was only accessible in
builtin/add.c but was still affecting builtin/checkout.c and
builtin/commit.c without this fact being very clear from the code.  I'm
not sure if the other two callers would want to add a `--sparse` flag
similar to add.c to get non-default behavior, but exposing this
dependence will help if we ever decide we do want to add such a flag.

Modify add_files_to_cache() and its helpers to accept the necessary
arguments instead of relying on globals.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoread-cache: move shared commit and ls-files code
Elijah Newren [Tue, 16 May 2023 06:33:45 +0000 (06:33 +0000)] 
read-cache: move shared commit and ls-files code

The function overlay_tree_on_index(), plus associated helper functions,
were defined in builtin/ls-files.c, but also shared with
builtin/commit.c.  Move these shared functions to read-cache.c.

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agosetup: adopt shared init-db & clone code
Elijah Newren [Tue, 16 May 2023 06:33:44 +0000 (06:33 +0000)] 
setup: adopt shared init-db & clone code

The functions init_db() and initialize_repository_version() were shared
by builtin/init-db.c and builtin/clone.c, and declared in cache.h.

Move these functions, plus their several helpers only used by these
functions, to setup.[ch].

Diff best viewed with `--color-moved`.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoinit-db, clone: change unnecessary global into passed parameter
Elijah Newren [Tue, 16 May 2023 06:33:43 +0000 (06:33 +0000)] 
init-db, clone: change unnecessary global into passed parameter

Much like the parent commit, this commit was prompted by a desire to
move the functions which builtin/init-db.c and builtin/clone.c share out
of the former file and into setup.c.  A secondary issue that made it
difficult was the init_shared_repository global variable; replace it
with a simple parameter that is passed to the relevant functions.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoinit-db: remove unnecessary global variable
Elijah Newren [Tue, 16 May 2023 06:33:42 +0000 (06:33 +0000)] 
init-db: remove unnecessary global variable

This commit was prompted by a desire to move the functions which
builtin/init-db.c and builtin/clone.c share out of the former file and
into setup.c.  One issue that made it difficult was the
init_is_bare_repository global variable.

init_is_bare_repository's sole use in life it to cache a value in
init_db(), and then be used in create_default_files().  This is a bit
odd since init_db() directly calls create_default_files(), and is the
only caller of that function.  Convert the global to a simple function
parameter instead.

(Of course, this doesn't fix the fact that this value is then ignored by
create_default_files(), as noted in a big TODO comment in that function,
but it at least includes no behavioral change other than getting rid of
a very questionable global variable.)

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoinit-db: document existing bug with core.bare in template config
Elijah Newren [Tue, 16 May 2023 06:33:41 +0000 (06:33 +0000)] 
init-db: document existing bug with core.bare in template config

The comments in create_default_files() talks about reading config from
the config file in the specified `--templates` directory, which leads to
the question of whether core.bare could be set in such a config file and
thus whether the code is doing the right thing.  It turns out, that it
doesn't; it unconditionally ignores core.bare in the config file in any
--templates directory.  It is not clear to me that fixing it can be done
within this function; it seems to occur too late:
  * create_default_files() is called by init_db()
  * init_db() is called by both builtin/{clone.c,init-db.c}
  * both callers of init_db() call set_git_work_tree() before init_db()
and in order to actual affect whether a repository is bear, we'd need to
somewhere reset these values, not just the is_bare_repository_cfg
setting.

I do not want to open this can of worms at this time; I'm trying to
clean up some headers, for which I need to move some functions, for
which I need to clean up some globals, and that's far enough down the
rabbit hole.  So, simply document the issue with a careful TODO comment
and a few testcases.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoThe second batch for 2.42
Junio C Hamano [Tue, 20 Jun 2023 22:12:15 +0000 (15:12 -0700)] 
The second batch for 2.42

Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoMerge branch 'la/doc-interpret-trailers'
Junio C Hamano [Tue, 20 Jun 2023 22:53:13 +0000 (15:53 -0700)] 
Merge branch 'la/doc-interpret-trailers'

Doc update.

* la/doc-interpret-trailers:
  doc: trailer: add more examples in DESCRIPTION
  doc: trailer: mention 'key' in DESCRIPTION
  doc: trailer.<token>.command: emphasize deprecation
  doc: trailer: use angle brackets for <token> and <value>
  doc: trailer: remove redundant phrasing
  doc: trailer: examples: avoid the word "message" by itself
  doc: trailer: drop "commit message part" phrasing
  doc: trailer: swap verb order
  doc: trailer: fix grammar

15 months agoMerge branch 'jk/log-follow-with-non-literal-pathspec'
Junio C Hamano [Tue, 20 Jun 2023 22:53:13 +0000 (15:53 -0700)] 
Merge branch 'jk/log-follow-with-non-literal-pathspec'

"git [-c log.follow=true] log [--follow] ':(glob)f**'" used to barf.

* jk/log-follow-with-non-literal-pathspec:
  diff: detect pathspec magic not supported by --follow
  diff: factor out --follow pathspec check
  pathspec: factor out magic-to-name function

15 months agoMerge branch 'vd/worktree-config-is-per-repository'
Junio C Hamano [Tue, 20 Jun 2023 22:53:13 +0000 (15:53 -0700)] 
Merge branch 'vd/worktree-config-is-per-repository'

The value of config.worktree is per-repository, but has been kept
in a singleton global variable per process. This has been OK as
most Git operations interacted with a single repository at a time,
but not right for operations like recursive "grep" that want to
access multiple repositories from a single process without forking.

The global variable has been eliminated and made into a member in
the per-repository data structure.

* vd/worktree-config-is-per-repository:
  repository: move 'repository_format_worktree_config' to repo scope
  config: pass 'repo' directly to 'config_with_options()'
  config: use gitdir to get worktree config

15 months agoMerge branch 'tb/submodule-null-deref-fix'
Junio C Hamano [Tue, 20 Jun 2023 22:53:12 +0000 (15:53 -0700)] 
Merge branch 'tb/submodule-null-deref-fix'

"git submodule" code trusted the data coming from the config (and
the in-tree .gitmodules file) too much without validating, leading
to NULL dereference if the user mucks with a repository (e.g.
submodule.<name>.url is removed).  This has been corrected.

* tb/submodule-null-deref-fix:
  builtin/submodule--helper.c: handle missing submodule URLs

15 months agoMerge branch 'jc/test-modernization-2'
Junio C Hamano [Tue, 20 Jun 2023 22:53:12 +0000 (15:53 -0700)] 
Merge branch 'jc/test-modernization-2'

Test style updates.

* jc/test-modernization-2:
  t9400-git-cvsserver-server: modernize test format
  t9200-git-cvsexportcommit: modernize test format
  t9104-git-svn-follow-parent: modernize test format
  t9100-git-svn-basic: modernize test format
  t7700-repack: modernize test format
  t7600-merge: modernize test format
  t7508-status: modernize test format
  t7201-co: modernize test format
  t7111-reset-table: modernize test format
  t7110-reset-merge: modernize test format

15 months agoMerge branch 'jc/test-modernization'
Junio C Hamano [Tue, 20 Jun 2023 22:53:12 +0000 (15:53 -0700)] 
Merge branch 'jc/test-modernization'

* jc/test-modernization:
  t7101-reset-empty-subdirs: modernize test format
  t6050-replace: modernize test format
  t5306-pack-nobase: modernize test format
  t5303-pack-corruption-resilience: modernize test format
  t5301-sliding-window: modernize test format
  t5300-pack-object: modernize test format
  t4206-log-follow-harder-copies: modernize test format
  t4202-log: modernize test format
  t4004-diff-rename-symlink: modernize test format
  t4003-diff-rename-1: modernize test format
  t4002-diff-basic: modernize test format
  t3903-stash: modernize test format
  t3700-add: modernize test format
  t3500-cherry: modernize test format
  t1006-cat-file: modernize test format
  t1002-read-tree-m-u-2way: modernize test format
  t1001-read-tree-m-2way: modernize test format
  t3210-pack-refs: modernize test format
  t0030-stripspace: modernize test format
  t0000-basic: modernize test format

15 months agoMerge branch 'kh/use-default-notes-doc'
Junio C Hamano [Tue, 20 Jun 2023 22:53:12 +0000 (15:53 -0700)] 
Merge branch 'kh/use-default-notes-doc'

Doc update.

* kh/use-default-notes-doc:
  notes: move the documentation to the struct
  notes: update documentation for `use_default_notes`

15 months agoMerge branch 'pb/complete-and-document-auto-merge-and-friends'
Junio C Hamano [Tue, 20 Jun 2023 22:53:11 +0000 (15:53 -0700)] 
Merge branch 'pb/complete-and-document-auto-merge-and-friends'

Document more pseudo-refs and teach the command line completion
machinery to complete AUTO_MERGE.

* pb/complete-and-document-auto-merge-and-friends:
  completion: complete AUTO_MERGE
  Documentation: document AUTO_MERGE
  git-merge.txt: modernize word choice in "True merge" section
  completion: complete REVERT_HEAD and BISECT_HEAD
  revisions.txt: document more special refs
  revisions.txt: use description list for special refs

15 months agoMerge branch 'mh/commit-reach-get-reachable-plug-leak'
Junio C Hamano [Tue, 20 Jun 2023 22:53:11 +0000 (15:53 -0700)] 
Merge branch 'mh/commit-reach-get-reachable-plug-leak'

Plug memory leak.

* mh/commit-reach-get-reachable-plug-leak:
  commit-reach: fix memory leak in get_reachable_subset()

15 months agoMerge branch 'tz/test-fix-pthreads-prereq'
Junio C Hamano [Tue, 20 Jun 2023 22:53:11 +0000 (15:53 -0700)] 
Merge branch 'tz/test-fix-pthreads-prereq'

Test fix.

* tz/test-fix-pthreads-prereq:
  trace2 tests: fix PTHREADS prereq

15 months agoMerge branch 'tz/test-ssh-verifytime-fix'
Junio C Hamano [Tue, 20 Jun 2023 22:53:11 +0000 (15:53 -0700)] 
Merge branch 'tz/test-ssh-verifytime-fix'

Test fix.

* tz/test-ssh-verifytime-fix:
  t/lib-gpg: fix ssh-keygen -Y check-novalidate with openssh-9.0

15 months agoMerge branch 'jk/ci-use-clang-for-sanitizer-jobs'
Junio C Hamano [Tue, 20 Jun 2023 22:53:11 +0000 (15:53 -0700)] 
Merge branch 'jk/ci-use-clang-for-sanitizer-jobs'

Clang's sanitizer implementation seems to work better than GCC's.

* jk/ci-use-clang-for-sanitizer-jobs:
  ci: drop linux-clang job
  ci: run ASan/UBSan in a single job
  ci: use clang for ASan/UBSan checks

15 months agoMerge branch 'tl/quote-problematic-arg-for-clarity'
Junio C Hamano [Tue, 20 Jun 2023 22:53:10 +0000 (15:53 -0700)] 
Merge branch 'tl/quote-problematic-arg-for-clarity'

Error message fix.

* tl/quote-problematic-arg-for-clarity:
  surround %s with quotes when failed to lookup commit

15 months agoMerge branch 'ps/fetch-cleanups'
Junio C Hamano [Tue, 20 Jun 2023 22:53:10 +0000 (15:53 -0700)] 
Merge branch 'ps/fetch-cleanups'

Code clean-up.

* ps/fetch-cleanups:
  fetch: use `fetch_config` to store "submodule.fetchJobs" value
  fetch: use `fetch_config` to store "fetch.parallel" value
  fetch: use `fetch_config` to store "fetch.recurseSubmodules" value
  fetch: use `fetch_config` to store "fetch.showForcedUpdates" value
  fetch: use `fetch_config` to store "fetch.pruneTags" value
  fetch: use `fetch_config` to store "fetch.prune" value
  fetch: pass through `fetch_config` directly
  fetch: drop unneeded NULL-check for `remote_ref`
  fetch: drop unused DISPLAY_FORMAT_UNKNOWN enum value

15 months agopackfile: delete .idx files before .pack files
Derrick Stolee [Tue, 20 Jun 2023 19:01:15 +0000 (19:01 +0000)] 
packfile: delete .idx files before .pack files

When installing a packfile, we place the .pack file before the .idx
file. The intention is that Git scans for .idx files in the pack
directory and then loads the .pack files from that list.

However, when we delete packfiles, we do not do this in the reverse
order as we should. The unlink_pack_path() method deletes the .pack
followed by the .idx.

This creates a window where the process could be interrupted between
the .pack deletion and the .idx deletion, leaving the repository in a
state that looks strange, but isn't actually too problematic if we
assume the pack was safe to delete. The .idx without a .pack will cause
some overhead, but will not interrupt other Git processes.

This ordering was introduced into the 'git repack' builtin by
a1bbc6c0176 (repack: rewrite the shell script in C, 2013-09-15), though
we must be careful to track history through the code move in 8434e85d5f9
(repack: refactor pack deletion for future use, 2019-06-10) to see that.

This became more important after 73320e49add (builtin/repack.c: only
collect fully-formed packs, 2023-06-07) changed how 'git repack' scanned
for packfiles for use in the cruft pack process. It previously looked
for .pack files, but that was problematic due to the order that packs
are installed: repacks between the creation of a .pack and the creation
of its .idx would result in hard failures.

There is an independent proposal about what to do in the case of a .idx
without a .pack during this 'git repack' scenario, but this change is
focused on deleting .pack files more safely.

Modify the order to delete the .idx before the .pack. The rest of the
modifiers on the .pack should still come after the .pack so we know all
of the presumed properties of the packfile as long as it exists in the
filesystem, in case we wish to reinstate it by re-indexing the .pack
file.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agohttp: handle both "h2" and "h2h3" in curl info lines
Jeff King [Sat, 17 Jun 2023 05:15:59 +0000 (01:15 -0400)] 
http: handle both "h2" and "h2h3" in curl info lines

When redacting auth tokens in trace output from curl, we look for http/2
headers of the form "h2h3 [header: value]". This comes from b637a41ebe
(http: redact curl h2h3 headers in info, 2022-11-11).

But the "h2h3" prefix changed to just "h2" in curl's fc2f1e547 (http2:
support HTTP/2 to forward proxies, non-tunneling, 2023-04-14). That's in
released version curl 8.1.0; linking against that version means we'll
fail to correctly redact the trace. Our t5559.17 notices and fails.

We can fix this by matching either prefix, which should handle both old
and new versions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agotests: mark as passing with SANITIZE=leak
Rubén Justo [Sat, 17 Jun 2023 06:41:54 +0000 (08:41 +0200)] 
tests: mark as passing with SANITIZE=leak

The tests listed below, since previous commits, no longer trigger any
leak.

   + t1507-rev-parse-upstream.sh
   + t1508-at-combinations.sh
   + t1514-rev-parse-push.sh
   + t2027-checkout-track.sh
   + t3200-branch.sh
   + t3204-branch-name-interpretation.sh
   + t5404-tracking-branches.sh
   + t5517-push-mirror.sh
   + t5525-fetch-tagopt.sh
   + t6040-tracking-info.sh
   + t7508-status.sh

Let's mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix
promptly any new leak that may be introduced and triggered by them in
the future.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoconfig: fix a leak in git_config_copy_or_rename_section_in_file
Rubén Justo [Sat, 17 Jun 2023 06:41:40 +0000 (08:41 +0200)] 
config: fix a leak in git_config_copy_or_rename_section_in_file

A branch can have its configuration spread over several configuration
sections.  This situation was already foreseen in 52d59cc645 (branch:
add a --copy (-c) option to go with --move (-m), 2017-06-18) when
"branch -c" was introduced.

Unfortunately, a leak was also introduced:

   $ git branch foo
   $ cat >> .git/config <<EOF
   [branch "foo"]
    some-key-a = a value
   [branch "foo"]
    some-key-b = b value
   [branch "foo"]
    some-key-c = c value
   EOF
   $ git branch -c foo bar

   Direct leak of 130 byte(s) in 2 object(s) allocated from:
       ... in xrealloc wrapper.c
       ... in strbuf_grow strbuf.c
       ... in strbuf_vaddf strbuf.c
       ... in strbuf_addf strbuf.c
       ... in store_create_section config.c
       ... in git_config_copy_or_rename_section_in_file config.c
       ... in git_config_copy_section_in_file config.c
       ... in git_config_copy_section config.c
       ... in copy_or_rename_branch builtin/branch.c
       ... in cmd_branch builtin/branch.c
       ... in run_builtin git.c

Let's fix it.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agobranch: fix a leak in cmd_branch
Rubén Justo [Sat, 17 Jun 2023 06:41:22 +0000 (08:41 +0200)] 
branch: fix a leak in cmd_branch

In 98e7ab6d42 (for-each-ref: delay parsing of --sort=<atom> options,
2021-10-20) a new string_list was introduced to accumulate any
"branch.sort" setting.

That string_list is cleared in ref_sorting_options(), which is only
called when processing the "--list" sub-command.  Therefore, with other
sub-command, while having any sort option set, a leak is produced, e.g.:

   $ git config branch.sort invalid_sort_option
   $ git branch --edit-description

   Direct leak of 384 byte(s) in 1 object(s) allocated from:
       ... in xrealloc wrapper.c
       ... in string_list_append_nodup string-list.c
       ... in string_list_append string-list.c
       ... in git_branch_config builtin/branch.c
       ... in configset_iter config.c
       ... in repo_config config.c
       ... in git_config config.c
       ... in cmd_branch builtin/branch.c
       ... in run_builtin git.c

   Indirect leak of 20 byte(s) in 1 object(s) allocated from:
       ... in xstrdup wrapper.c
       ... in string_list_append string-list.c
       ... in git_branch_config builtin/branch.c
       ... in configset_iter config.c
       ... in repo_config config.c
       ... in git_config config.c
       ... in cmd_branch builtin/branch.c
       ... in run_builtin git.c

We don't have a common clean-up section in cmd_branch().  To avoid
refactoring, keep the fix simple, and while we find a better solution
which hopefuly will avoid entirely that string_list, when no sort
options are needed; let's squelch the leak sanitizer using UNLEAK().

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agobranch: fix a leak in setup_tracking
Rubén Justo [Sat, 17 Jun 2023 06:41:08 +0000 (08:41 +0200)] 
branch: fix a leak in setup_tracking

In bdaf1dfae7 (branch: new autosetupmerge option "simple" for matching
branches, 2022-04-29) a new exit for setup_tracking() missed the
clean-up, producing a leak.

   $ git config branch.autoSetupMerge simple
   $ git remote add local .
   $ git update-ref refs/remotes/local/foo HEAD
   $ git branch bar local/foo

   Direct leak of 384 byte(s) in 1 object(s) allocated from:
       ... in xrealloc wrapper.c
       ... in string_list_append_nodup string-list.c
       ... in find_tracked_branch branch.c
       ... in for_each_remote remote.c
       ... in setup_tracking branch.c
       ... in create_branch branch.c
       ... in cmd_branch builtinbranch.c
       ... in run_builtin git.c

   Indirect leak of 24 byte(s) in 1 object(s) allocated from:
       ... in xrealloc wrapper.c
       ... in strbuf_grow strbuf.c
       ... in strbuf_add strbuf.c
       ... in match_name_with_pattern remote.c
       ... in query_refspecs remote.c
       ... in remote_find_tracking remote.c
       ... in find_tracked_branch branch.c
       ... in for_each_remote remote.c
       ... in setup_tracking branch.c
       ... in create_branch branch.c
       ... in cmd_branch builtinbranch.c
       ... in run_builtin git.c

The return introduced in bdaf1dfae7 was to avoid setting up the
tracking, but even in that case it is still necessary to do the
clean-up.  Let's do it.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agorev-parse: fix a leak with --abbrev-ref
Rubén Justo [Sat, 17 Jun 2023 06:40:43 +0000 (08:40 +0200)] 
rev-parse: fix a leak with --abbrev-ref

To handle "--abbrev-ref" we use shorten_unambiguous_ref().  This
function takes a refname and returns a shortened refname, which is a
newly allocated string that needs to be freed.

Unfortunately, the refname variable is reused to receive the shortened
one.  Therefore, we lose the original refname, which needs to be freed
as well, producing a leak.

This leak can be reviewed with:

   $ for a in {1..10}; do git branch foo_${a}; done
   $ git rev-parse --abbrev-ref refs/heads/foo_{1..10}

   Direct leak of 171 byte(s) in 10 object(s) allocated from:
       ... in xstrdup wrapper.c
       ... in expand_ref refs.c
       ... in repo_dwim_ref refs.c
       ... in show_rev builtin/rev-parse.c
       ... in cmd_rev_parse builtin/rev-parse.c
       ... in run_builtin git.c

We have this leak since a45d34691e (rev-parse: --abbrev-ref option to
shorten ref name, 2009-04-13) when "--abbrev-ref" was introduced.

Let's fix it.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agocommit: pass --no-divider to interpret-trailers
Jeff King [Sat, 17 Jun 2023 04:26:24 +0000 (00:26 -0400)] 
commit: pass --no-divider to interpret-trailers

When git-commit sees any "--trailer" options, it passes the
COMMIT_EDITMSG file through git-interpret-trailers. But it does so
without passing --no-divider, which means that interpret-trailers will
look for a "---" divider to signal the end of the commit message.

That behavior doesn't make any sense in this context; we know we have a
complete and solitary commit message, not something we have to further
parse. And as a result, we'll do the wrong thing if the commit message
contains a "---" marker (which otherwise is not syntactically
significant), inserting any new trailers at the wrong spot.

We can fix this by passing --no-divider. This is the exact situation for
which it was added in 1688c9a489 (interpret-trailers: allow suppressing
"---" divider, 2018-08-22). As noted in the message for that commit, it
just adds the mechanism, and further patches were needed to trigger it
from various callers.  We did that back then in a few spots, like
ffce7f590f (sequencer: ignore "---" divider when parsing trailers,
2018-08-22), but obviously missed this one.

Reported-by: <eric.frederich@siemens.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agosetup.c: don't setup in discover_git_directory()
Glen Choo [Wed, 14 Jun 2023 19:35:58 +0000 (19:35 +0000)] 
setup.c: don't setup in discover_git_directory()

discover_git_directory() started modifying the_repository in ebaf3bcf1ae
(repository: move global r_f_p_c to repo struct, 2021-06-17), when, in
the repository setup process, we started copying members from the
"struct repository_format" we're inspecting to the appropriate "struct
repository". However, discover_git_directory() isn't actually used in
the setup process (its only caller in the Git binary is
read_early_config()), so it shouldn't be doing this setup at all!

As explained by 16ac8b8db6 (setup: introduce the
discover_git_directory() function, 2017-03-13) and the comment on its
declaration, discover_git_directory() is intended to be an entrypoint
into setup.c machinery that allows the Git directory to be discovered
without side effects, e.g. so that read_early_config() can read
".git/config" before the_repository has been set up.

Fortunately, we didn't start to rely on this unintended behavior between
then and now, so we let's just remove it. It isn't harming anyone, but
it's confusing.

Signed-off-by: Glen Choo <chooglen@google.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agocredential: erase all matching credentials
M Hickford [Thu, 15 Jun 2023 19:19:33 +0000 (19:19 +0000)] 
credential: erase all matching credentials

`credential reject` sends the erase action to each helper, but the
exact behaviour of erase isn't specified in documentation or tests.
Some helpers (such as credential-store and credential-libsecret) delete
all matching credentials, others (such as credential-cache) delete at
most one matching credential.

Test that helpers erase all matching credentials. This behaviour is
easiest to reason about. Users expect that `echo
"url=https://example.com" | git credential reject` or `echo
"url=https://example.com\nusername=tim" | git credential reject` erase
all matching credentials.

Fix credential-cache.

Signed-off-by: M Hickford <mirth.hickford@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agocredential: avoid erasing distinct password
M Hickford [Thu, 15 Jun 2023 19:19:32 +0000 (19:19 +0000)] 
credential: avoid erasing distinct password

Test that credential helpers do not erase a password distinct from the
input. Such calls can happen when multiple credential helpers are
configured.

Fixes for credential-cache and credential-store.

Signed-off-by: M Hickford <mirth.hickford@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agorevision: handle pseudo-opts in `--stdin` mode
Patrick Steinhardt [Thu, 15 Jun 2023 14:39:59 +0000 (16:39 +0200)] 
revision: handle pseudo-opts in `--stdin` mode

While both git-rev-list(1) and git-log(1) support `--stdin`, it only
accepts commits and files. Most notably, it is impossible to pass any of
the pseudo-opts like `--all`, `--glob=` or others via stdin.

This makes it hard to use this function in certain scripted scenarios,
like when one wants to support queries against specific revisions, but
also against reference patterns. While this is theoretically possible by
using arguments, this may run into issues once we hit platform limits
with sufficiently large queries. And because `--stdin` cannot handle
pseudo-opts, the only alternative would be to use a mixture of arguments
and standard input, which is cumbersome.

Implement support for handling pseudo-opts in both commands to support
this usecase better. One notable restriction here is that `--stdin` only
supports "stuck" arguments in the form of `--glob=foo`. This is because
"unstuck" arguments would also require us to read the next line, which
would add quite some complexity to the code. This restriction should be
fine for scripted usage though.

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