]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
16 months agoMerge branch 'ob/sequencer-i18n-fix'
Junio C Hamano [Tue, 9 May 2023 23:45:46 +0000 (16:45 -0700)] 
Merge branch 'ob/sequencer-i18n-fix'

Message update.

* ob/sequencer-i18n-fix:
  sequencer: actually translate report in do_exec()

16 months agoMerge branch 'en/header-split-cache-h-part-2'
Junio C Hamano [Tue, 9 May 2023 23:45:45 +0000 (16:45 -0700)] 
Merge branch 'en/header-split-cache-h-part-2'

More header clean-up.

* en/header-split-cache-h-part-2: (22 commits)
  reftable: ensure git-compat-util.h is the first (indirect) include
  diff.h: reduce unnecessary includes
  object-store.h: reduce unnecessary includes
  commit.h: reduce unnecessary includes
  fsmonitor: reduce includes of cache.h
  cache.h: remove unnecessary headers
  treewide: remove cache.h inclusion due to previous changes
  cache,tree: move basic name compare functions from read-cache to tree
  cache,tree: move cmp_cache_name_compare from tree.[ch] to read-cache.c
  hash-ll.h: split out of hash.h to remove dependency on repository.h
  tree-diff.c: move S_DIFFTREE_IFXMIN_NEQ define from cache.h
  dir.h: move DTYPE defines from cache.h
  versioncmp.h: move declarations for versioncmp.c functions from cache.h
  ws.h: move declarations for ws.c functions from cache.h
  match-trees.h: move declarations for match-trees.c functions from cache.h
  pkt-line.h: move declarations for pkt-line.c functions from cache.h
  base85.h: move declarations for base85.c functions from cache.h
  copy.h: move declarations for copy.c functions from cache.h
  server-info.h: move declarations for server-info.c functions from cache.h
  packfile.h: move pack_window and pack_entry from cache.h
  ...

16 months agoMerge branch 'mh/fix-detect-compilers-with-nondigit-versions'
Junio C Hamano [Tue, 9 May 2023 23:45:45 +0000 (16:45 -0700)] 
Merge branch 'mh/fix-detect-compilers-with-nondigit-versions'

The detect-compilers script to help auto-tweaking the build system
had trouble working with compilers whose version number has extra
suffixes.  The script has been taught that certain suffixes (like
"-win32" in "gcc 10-win32") can be safely stripped as they share
the same features and bugs with the version without the suffix.

* mh/fix-detect-compilers-with-nondigit-versions:
  Handle some compiler versions containing a dash

16 months agoMerge branch 'jk/parse-commit-with-malformed-ident'
Junio C Hamano [Tue, 9 May 2023 23:45:44 +0000 (16:45 -0700)] 
Merge branch 'jk/parse-commit-with-malformed-ident'

The commit object parser has been taught to be a bit more lenient
to parse timestamps on the author/committer line with a malformed
author/committer ident.

* jk/parse-commit-with-malformed-ident:
  parse_commit(): describe more date-parsing failure modes
  parse_commit(): handle broken whitespace-only timestamp
  parse_commit(): parse timestamp from end of line
  t4212: avoid putting git on left-hand side of pipe

16 months agoThe sixteenth batch
Junio C Hamano [Tue, 2 May 2023 17:13:50 +0000 (10:13 -0700)] 
The sixteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoMerge branch 'tb/ban-strtok'
Junio C Hamano [Tue, 2 May 2023 17:13:35 +0000 (10:13 -0700)] 
Merge branch 'tb/ban-strtok'

Mark strtok() and strtok_r() to be banned.

* tb/ban-strtok:
  banned.h: mark `strtok()` and `strtok_r()` as banned
  t/helper/test-json-writer.c: avoid using `strtok()`
  t/helper/test-oidmap.c: avoid using `strtok()`
  t/helper/test-hashmap.c: avoid using `strtok()`
  string-list: introduce `string_list_setlen()`
  string-list: multi-delimiter `string_list_split_in_place()`

16 months agoMerge branch 'jk/blame-fake-commit-label'
Junio C Hamano [Tue, 2 May 2023 17:13:34 +0000 (10:13 -0700)] 
Merge branch 'jk/blame-fake-commit-label'

The output given by "git blame" that attributes a line to contents
taken from the file specified by the "--contents" option shows it
differently from a line attributed to the working tree file.

* jk/blame-fake-commit-label:
  blame: use different author name for fake commit generated by --contents

16 months agoMerge branch 'jk/misc-null-check-fixes'
Junio C Hamano [Tue, 2 May 2023 17:13:34 +0000 (10:13 -0700)] 
Merge branch 'jk/misc-null-check-fixes'

Code clean-up.

* jk/misc-null-check-fixes:
  fetch_bundle_uri(): drop pointless NULL check
  notes: clean up confusing NULL checks in init_notes()

16 months agoMerge branch 'en/ort-finalize-after-0-merges-fix'
Junio C Hamano [Tue, 2 May 2023 17:13:34 +0000 (10:13 -0700)] 
Merge branch 'en/ort-finalize-after-0-merges-fix'

A small API fix to the ort merge strategy backend.

* en/ort-finalize-after-0-merges-fix:
  merge-ort: fix calling merge_finalize() with no intermediate merge

16 months agoMerge branch 'ek/completion-use-read-r-to-read-literally'
Junio C Hamano [Tue, 2 May 2023 17:13:34 +0000 (10:13 -0700)] 
Merge branch 'ek/completion-use-read-r-to-read-literally'

The completion script used to use bare "read" without the "-r"
option to read the contents of various state files, which risked
getting confused with backslashes in them.  This has been
corrected.

* ek/completion-use-read-r-to-read-literally:
  completion: suppress unwanted unescaping of `read`

16 months agoThe fifteenth batch
Junio C Hamano [Fri, 28 Apr 2023 22:22:24 +0000 (15:22 -0700)] 
The fifteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoMerge branch 'jk/gpg-trust-level-fix'
Junio C Hamano [Fri, 28 Apr 2023 23:03:03 +0000 (16:03 -0700)] 
Merge branch 'jk/gpg-trust-level-fix'

The "%GT" placeholder for the "--format" option of "git log" and
friends caused BUG() to trigger on a commit signed with an unknown
key, which has been corrected.

* jk/gpg-trust-level-fix:
  gpg-interface: set trust level of missing key to "undefined"

16 months agoMerge branch 'tb/enable-cruft-packs-by-default'
Junio C Hamano [Fri, 28 Apr 2023 23:03:03 +0000 (16:03 -0700)] 
Merge branch 'tb/enable-cruft-packs-by-default'

When "gc" needs to retain unreachable objects, packing them into
cruft packs (instead of exploding them into loose object files) has
been offered as a more efficient option for some time.  Now the use
of cruft packs has been made the default and no longer considered
an experimental feature.

* tb/enable-cruft-packs-by-default:
  repository.h: drop unused `gc_cruft_packs`
  builtin/gc.c: make `gc.cruftPacks` enabled by default
  t/t9300-fast-import.sh: prepare for `gc --cruft` by default
  t/t6500-gc.sh: add additional test cases
  t/t6500-gc.sh: refactor cruft pack tests
  t/t6501-freshen-objects.sh: prepare for `gc --cruft` by default
  t/t5304-prune.sh: prepare for `gc --cruft` by default
  builtin/gc.c: ignore cruft packs with `--keep-largest-pack`
  builtin/repack.c: fix incorrect reference to '-C'
  pack-write.c: plug a leak in stage_tmp_packfiles()

16 months agosequencer: actually translate report in do_exec()
Oswald Buddenhagen [Fri, 28 Apr 2023 12:56:48 +0000 (14:56 +0200)] 
sequencer: actually translate report in do_exec()

N_() is meant to be used on strings that are subsequently _()'d, which
isn't the case here.

The affected construct is a bit questionable from an i18n perspective,
as it pieces together a sentence from separate strings. However, it
doesn't appear to be that bad, as the "assembly instructions" are in a
translatable message as well. Lacking specific complaints from
translators, it doesn't seem worth changing this.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoThe fourteenth batch
Junio C Hamano [Thu, 27 Apr 2023 23:00:32 +0000 (16:00 -0700)] 
The fourteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoMerge branch 'fc/doc-checkout-markup-updates'
Junio C Hamano [Thu, 27 Apr 2023 23:00:59 +0000 (16:00 -0700)] 
Merge branch 'fc/doc-checkout-markup-updates'

Doc mark-up update.

* fc/doc-checkout-markup-updates:
  doc: git-checkout: reorganize examples
  doc: git-checkout: trivial callout cleanup

16 months agoMerge branch 'fc/doc-use-datestamp-in-commit'
Junio C Hamano [Thu, 27 Apr 2023 23:00:59 +0000 (16:00 -0700)] 
Merge branch 'fc/doc-use-datestamp-in-commit'

Instead of the time the formatter was run, show the timestamp
recorded in the commit in the documentation.

* fc/doc-use-datestamp-in-commit:
  doc: set actual revdate for manpages

16 months agoMerge branch 'ds/fsck-pack-revindex'
Junio C Hamano [Thu, 27 Apr 2023 23:00:59 +0000 (16:00 -0700)] 
Merge branch 'ds/fsck-pack-revindex'

"git fsck" learned to validate the on-disk pack reverse index files.

* ds/fsck-pack-revindex:
  fsck: validate .rev file header
  fsck: check rev-index position values
  fsck: check rev-index checksums
  fsck: create scaffolding for rev-index checks

16 months agoMerge branch 'tb/pack-revindex-on-disk'
Junio C Hamano [Thu, 27 Apr 2023 23:00:59 +0000 (16:00 -0700)] 
Merge branch 'tb/pack-revindex-on-disk'

The on-disk reverse index that allows mapping from the pack offset
to the object name for the object stored at the offset has been
enabled by default.

* tb/pack-revindex-on-disk:
  t: invert `GIT_TEST_WRITE_REV_INDEX`
  config: enable `pack.writeReverseIndex` by default
  pack-revindex: introduce `pack.readReverseIndex`
  pack-revindex: introduce GIT_TEST_REV_INDEX_DIE_ON_DISK
  pack-revindex: make `load_pack_revindex` take a repository
  t5325: mark as leak-free
  pack-write.c: plug a leak in stage_tmp_packfiles()

16 months agoparse_commit(): describe more date-parsing failure modes
Jeff King [Thu, 27 Apr 2023 08:17:24 +0000 (04:17 -0400)] 
parse_commit(): describe more date-parsing failure modes

The previous few commits improved the parsing of dates in malformed
commit objects. But there's one big case left implicit: we may still
feed garbage to parse_timestamp(). This is preferable to trying to be
more strict, but let's document the thinking in a comment.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoparse_commit(): handle broken whitespace-only timestamp
Jeff King [Thu, 27 Apr 2023 08:17:15 +0000 (04:17 -0400)] 
parse_commit(): handle broken whitespace-only timestamp

The comment in parse_commit_date() claims that parse_timestamp() will
not walk past the end of the buffer we've been given, since it will hit
the newline at "eol" and stop. This is usually true, when dateptr
contains actual numbers to parse. But with a line like:

   committer name <email>   \n

with just whitespace, and no numbers, parse_timestamp() will consume
that newline as part of the leading whitespace, and we may walk past our
"tail" pointer (which itself is set from the "size" parameter passed in
to parse_commit_buffer()).

In practice this can't cause us to walk off the end of an array, because
we always add an extra NUL byte to the end of objects we load from disk
(as a defense against exactly this kind of bug). However, you can see
the behavior in action when "committer" is the final header (which it
usually is, unless there's an encoding) and the subject line can be
parsed as an integer. We walk right past the newline on the committer
line, as well as the "\n\n" separator, and mistake the subject for the
timestamp.

We can solve this by trimming the whitespace ourselves, making sure that
it has some non-whitespace to parse. Note that we need to be a bit
careful about the definition of "whitespace" here, as our isspace()
doesn't match exotic characters like vertical tab or formfeed. We can
work around that by checking for an actual number (see the in-code
comment). This is slightly more restrictive than the current code, but
in practice the results are either the same (we reject "foo" as "0", but
so would parse_timestamp()) or extremely unlikely even for broken
commits (parse_timestamp() would allow "\v123" as "123", but we'll now
make it "0").

I did also allow "-" here, which may be controversial, as we don't
currently support negative timestamps. My reasoning was two-fold. One,
the design of parse_timestamp() is such that we should be able to easily
switch it to handling signed values, and this otherwise creates a
hard-to-find gotcha that anybody doing that work would get tripped up
on. And two, the status quo is that we currently parse them, though the
result of course ends up as a very large unsigned value (which is likely
to just get clamped to "0" for display anyway, since our date routines
can't handle it).

The new test checks the commit parser (via "--until") for both vanilla
spaces and the vertical-tab case. I also added a test to check these
against the pretty-print formatter, which uses split_ident_line().  It's
not subject to the same bug, because it already insists that there be
one or more digits in the timestamp.

Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoparse_commit(): parse timestamp from end of line
Jeff King [Thu, 27 Apr 2023 08:14:09 +0000 (04:14 -0400)] 
parse_commit(): parse timestamp from end of line

To find the committer timestamp, we parse left-to-right looking for the
closing ">" of the email, and then expect the timestamp right after
that. But we've seen some broken cases in the wild where this fails, but
we _could_ find the timestamp with a little extra work. E.g.:

  Name <Name<email>> 123456789 -0500

This means that features that rely on the committer timestamp, like
--since or --until, will treat the commit as happening at time 0 (i.e.,
1970).

This is doubly confusing because the pretty-print parser learned to
handle these in 03818a4a94 (split_ident: parse timestamp from end of
line, 2013-10-14). So printing them via "git show", etc, makes
everything look normal, but --until, etc are still broken (despite the
fact that that commit explicitly mentioned --until!).

So let's use the same trick as 03818a4a94: find the end of the line, and
parse back to the final ">". In theory we could use split_ident_line()
here, but it's actually a bit more strict. In particular, it requires a
valid time-zone token, too. That should be present, of course, but we
wouldn't want to break --until for cases that are working currently.

We might want to teach split_ident_line() to become more lenient there,
but it would require checking its many callers (since right now they can
assume that if date_start is non-NULL, so is tz_start).

So for now we'll just reimplement the same trick in the commit parser.

The test is in t4212, which already covers similar cases, courtesy of
03818a4a94. We'll just adjust the broken commit to munge both the author
and committer timestamps. Note that we could match (author|committer)
here, but alternation can't be used portably in sed. Since we wouldn't
expect to see ">" except as part of an ident line, we can just match
that character on any line.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agot4212: avoid putting git on left-hand side of pipe
Jeff King [Thu, 27 Apr 2023 08:14:06 +0000 (04:14 -0400)] 
t4212: avoid putting git on left-hand side of pipe

We wouldn't expect cat-file to fail here, but it's good practice to
avoid putting git on the upstream of a pipe, as we otherwise ignore its
exit code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agobanned.h: mark `strtok()` and `strtok_r()` as banned
Taylor Blau [Mon, 24 Apr 2023 22:20:26 +0000 (18:20 -0400)] 
banned.h: mark `strtok()` and `strtok_r()` as banned

`strtok()` has a couple of drawbacks that make it undesirable to have
any new instances. In addition to being thread-unsafe, it also
encourages confusing data flows, where `strtok()` may be called from
multiple functions with its first argument as NULL, making it unclear
from the immediate context which string is being tokenized.

Now that we have removed all instances of `strtok()` from the tree,
let's ban `strtok()` to avoid introducing new ones in the future. If new
callers should arise, they are encouraged to use
`string_list_split_in_place()` (and `string_list_remove_empty_items()`,
if applicable).

string_list_split_in_place() is not a perfect drop-in replacement
for `strtok_r()`, particularly if the caller is processing a string with
an arbitrary number of tokens, and wants to process each token one at a
time.

But there are no instances of this in Git's tree which are more
well-suited to `strtok_r()` than the friendlier
`string_list_split_in_place()`, so ban `strtok_r()`, too.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoHandle some compiler versions containing a dash
Mike Hommey [Wed, 26 Apr 2023 00:48:43 +0000 (09:48 +0900)] 
Handle some compiler versions containing a dash

The version reported by e.g. x86_64-w64-mingw32-gcc on Debian bullseye
looks like:
  gcc version 10-win32 20210110 (GCC)

This ends up with detect-compiler failing with:
  ./detect-compiler: 30: test: Illegal number: 10-win32

This change removes the two known suffixes known to exist in GCC versions
in Debian: -win32 and -posix.

Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoThe thirteenth batch
Junio C Hamano [Tue, 25 Apr 2023 20:17:56 +0000 (13:17 -0700)] 
The thirteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoMerge branch 'ps/fix-geom-repack-with-alternates'
Junio C Hamano [Tue, 25 Apr 2023 20:56:20 +0000 (13:56 -0700)] 
Merge branch 'ps/fix-geom-repack-with-alternates'

Geometric repacking ("git repack --geometric=<n>") in a repository
that borrows from an alternate object database had various corner
case bugs, which have been corrected.

* ps/fix-geom-repack-with-alternates:
  repack: disable writing bitmaps when doing a local repack
  repack: honor `-l` when calculating pack geometry
  t/helper: allow chmtime to print verbosely without modifying mtime
  pack-objects: extend test coverage of `--stdin-packs` with alternates
  pack-objects: fix error when same packfile is included and excluded
  pack-objects: fix error when packing same pack twice
  pack-objects: split out `--stdin-packs` tests into separate file
  repack: fix generating multi-pack-index with only non-local packs
  repack: fix trying to use preferred pack in alternates
  midx: fix segfault with no packs and invalid preferred pack

16 months agoMerge branch 'rj/send-email-validate-hook-count-messages'
Junio C Hamano [Tue, 25 Apr 2023 20:56:20 +0000 (13:56 -0700)] 
Merge branch 'rj/send-email-validate-hook-count-messages'

The sendemail-validate validate hook learned to pass the total
number of input files and where in the sequence each invocation is
via environment variables.

* rj/send-email-validate-hook-count-messages:
  send-email: export patch counters in validate environment

16 months agoMerge branch 'jk/protocol-cap-parse-fix'
Junio C Hamano [Tue, 25 Apr 2023 20:56:20 +0000 (13:56 -0700)] 
Merge branch 'jk/protocol-cap-parse-fix'

The code to parse capability list for v0 on-wire protocol fell into
an infinite loop when a capability appears multiple times, which
has been corrected.

* jk/protocol-cap-parse-fix:
  v0 protocol: use size_t for capability length/offset
  t5512: test "ls-remote --heads --symref" filtering with v0 and v2
  t5512: allow any protocol version for filtered symref test
  t5512: add v2 support for "ls-remote --symref" test
  v0 protocol: fix sha1/sha256 confusion for capabilities^{}
  t5512: stop referring to "v1" protocol
  v0 protocol: fix infinite loop when parsing multi-valued capabilities

16 months agoMerge branch 'en/header-split-cache-h'
Junio C Hamano [Tue, 25 Apr 2023 20:56:19 +0000 (13:56 -0700)] 
Merge branch 'en/header-split-cache-h'

Header clean-up.

* en/header-split-cache-h: (24 commits)
  protocol.h: move definition of DEFAULT_GIT_PORT from cache.h
  mailmap, quote: move declarations of global vars to correct unit
  treewide: reduce includes of cache.h in other headers
  treewide: remove double forward declaration of read_in_full
  cache.h: remove unnecessary includes
  treewide: remove cache.h inclusion due to pager.h changes
  pager.h: move declarations for pager.c functions from cache.h
  treewide: remove cache.h inclusion due to editor.h changes
  editor: move editor-related functions and declarations into common file
  treewide: remove cache.h inclusion due to object.h changes
  object.h: move some inline functions and defines from cache.h
  treewide: remove cache.h inclusion due to object-file.h changes
  object-file.h: move declarations for object-file.c functions from cache.h
  treewide: remove cache.h inclusion due to git-zlib changes
  git-zlib: move declarations for git-zlib functions from cache.h
  treewide: remove cache.h inclusion due to object-name.h changes
  object-name.h: move declarations for object-name.c functions from cache.h
  treewide: remove unnecessary cache.h inclusion
  treewide: be explicit about dependence on mem-pool.h
  treewide: be explicit about dependence on oid-array.h
  ...

16 months agoSync with Git 2.40.1
Junio C Hamano [Tue, 25 Apr 2023 05:31:32 +0000 (22:31 -0700)] 
Sync with Git 2.40.1

17 months agot/helper/test-json-writer.c: avoid using `strtok()`
Taylor Blau [Mon, 24 Apr 2023 22:20:23 +0000 (18:20 -0400)] 
t/helper/test-json-writer.c: avoid using `strtok()`

Apply similar treatment as in the previous commit to remove usage of
`strtok()` from the "oidmap" test helper.

Each of the different commands that the "json-writer" helper accepts
pops the next space-delimited token from the current line and interprets
it as a string, integer, or double (with the exception of the very first
token, which is the command itself).

To accommodate this, split the line in place by the space character, and
pass the corresponding string_list to each of the specialized `get_s()`,
`get_i()`, and `get_d()` functions.

`get_i()` and `get_d()` are thin wrappers around `get_s()` that convert
their result into the appropriate type by either calling `strtol()` or
`strtod()`, respectively. In `get_s()`, we mark the token as "consumed"
by incrementing the `consumed_nr` counter, indicating how many tokens we
have read up to that point.

Because each of these functions needs the string-list parts, the number
of tokens consumed, and the line number, these three are wrapped up in
to a struct representing the line state.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/helper/test-oidmap.c: avoid using `strtok()`
Taylor Blau [Mon, 24 Apr 2023 22:20:20 +0000 (18:20 -0400)] 
t/helper/test-oidmap.c: avoid using `strtok()`

Apply similar treatment as in the previous commit to remove usage of
`strtok()` from the "oidmap" test helper.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/helper/test-hashmap.c: avoid using `strtok()`
Taylor Blau [Mon, 24 Apr 2023 22:20:17 +0000 (18:20 -0400)] 
t/helper/test-hashmap.c: avoid using `strtok()`

Avoid using the non-reentrant `strtok()` to separate the parts of each
incoming command. Instead of replacing it with `strtok_r()`, let's
instead use the more friendly pair of `string_list_split_in_place()` and
`string_list_remove_empty_items()`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agostring-list: introduce `string_list_setlen()`
Taylor Blau [Mon, 24 Apr 2023 22:20:14 +0000 (18:20 -0400)] 
string-list: introduce `string_list_setlen()`

It is sometimes useful to reduce the size of a `string_list`'s list of
items without having to re-allocate them. For example, doing the
following:

    struct strbuf buf = STRBUF_INIT;
    struct string_list parts = STRING_LIST_INIT_NO_DUP;
    while (strbuf_getline(&buf, stdin) != EOF) {
      parts.nr = 0;
      string_list_split_in_place(&parts, buf.buf, ":", -1);
      /* ... */
    }
    string_list_clear(&parts, 0);

is preferable over calling `string_list_clear()` on every iteration of
the loop. This is because `string_list_clear()` causes us free our
existing `items` array. This means that every time we call
`string_list_split_in_place()`, the string-list internals re-allocate
the same size array.

Since in the above example we do not care about the individual parts
after processing each line, it is much more efficient to pretend that
there aren't any elements in the `string_list` by setting `list->nr` to
0 while leaving the list of elements allocated as-is.

This allows `string_list_split_in_place()` to overwrite any existing
entries without needing to free and re-allocate them.

However, setting `list->nr` manually is not safe in all instances. There
are a couple of cases worth worrying about:

  - If the `string_list` is initialized with `strdup_strings`,
    truncating the list can lead to overwriting strings which are
    allocated elsewhere. If there aren't any other pointers to those
    strings other than the ones inside of the `items` array, they will
    become unreachable and leak.

    (We could ourselves free the truncated items between
    string_list->items[nr] and `list->nr`, but no present or future
    callers would benefit from this additional complexity).

  - If the given `nr` is larger than the current value of `list->nr`,
    we'll trick the `string_list` into a state where it thinks there are
    more items allocated than there actually are, which can lead to
    undefined behavior if we try to read or write those entries.

Guard against both of these by introducing a helper function which
guards assignment of `list->nr` against each of the above conditions.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agostring-list: multi-delimiter `string_list_split_in_place()`
Taylor Blau [Mon, 24 Apr 2023 22:20:10 +0000 (18:20 -0400)] 
string-list: multi-delimiter `string_list_split_in_place()`

Enhance `string_list_split_in_place()` to accept multiple characters as
delimiters instead of a single character.

Instead of using `strchr(2)` to locate the first occurrence of the given
delimiter character, `string_list_split_in_place_multi()` uses
`strcspn(2)` to move past the initial segment of characters comprised of
any characters in the delimiting set.

When only a single delimiting character is provided, `strpbrk(2)` (which
is implemented with `strcspn(2)`) has equivalent performance to
`strchr(2)`. Modern `strcspn(2)` implementations treat an empty
delimiter or the singleton delimiter as a special case and fall back to
calling strchrnul(). Both glibc[1] and musl[2] implement `strcspn(2)`
this way.

This change is one step to removing `strtok(2)` from the tree. Note that
`string_list_split_in_place()` is not a strict replacement for
`strtok()`, since it will happily turn sequential delimiter characters
into empty entries in the resulting string_list. For example:

    string_list_split_in_place(&xs, "foo:;:bar:;:baz", ":;", -1)

would yield a string list of:

    ["foo", "", "", "bar", "", "", "baz"]

Callers that wish to emulate the behavior of strtok(2) more directly
should call `string_list_remove_empty_items()` after splitting.

To avoid regressions for the new multi-character delimter cases, update
t0063 in this patch as well.

[1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcspn.c;hb=glibc-2.37#l35
[2]: https://git.musl-libc.org/cgit/musl/tree/src/string/strcspn.c?h=v1.2.3#n11

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoblame: use different author name for fake commit generated by --contents
Jacob Keller [Mon, 24 Apr 2023 19:35:08 +0000 (12:35 -0700)] 
blame: use different author name for fake commit generated by --contents

When the --contents option is used with git blame, and the contents of
the file have lines which can't be annotated by the history being
blamed, the user will see an author of "Not Committed Yet". This is
similar to the way blame handles working tree contents when blaming
without a revision.

This is slightly confusing since this data isn't the working copy and
while it is technically "not committed yet", its also coming from an
external file. Replace this author name with "External file
(--contents)" to better differentiate such lines from actual working
copy lines.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Glen Choo <chooglen@google.com>
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agomerge-ort: fix calling merge_finalize() with no intermediate merge
Elijah Newren [Sat, 22 Apr 2023 20:22:10 +0000 (20:22 +0000)] 
merge-ort: fix calling merge_finalize() with no intermediate merge

If some code sets up the data structures for a merge, but then never
actually performs one before calling merge_finalize(), then
merge_finalize() wouldn't notice that result->priv was NULL and
return early, resulting in following that NULL pointer and getting
a segfault.  There is currently no code in the git codebase that does
this, but this issue was found during testing of some proposed patches
that had the following structure:

    struct merge_options merge_opt;
    struct merge_result result;

    init_merge_options(&merge_opt, the_repository);
    memset(&result, 0, sizeof(result));

    <do N merges, for some value of N>

    merge_finalize(&merge_opt, &result);

where some flags could cause the code to have N=0, i.e. doing no merges.
Add a check for result->priv being NULL and return early to avoid a
segfault in these kinds of cases.

While at it, ensure the FREE_AND_NULL() in the function does something
useful with the nulling aspect, namely sets result->priv to NULL rather
than a mere temporary.

Reported-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoreftable: ensure git-compat-util.h is the first (indirect) include
Elijah Newren [Sat, 22 Apr 2023 20:17:29 +0000 (20:17 +0000)] 
reftable: ensure git-compat-util.h is the first (indirect) include

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodiff.h: reduce unnecessary includes
Elijah Newren [Sat, 22 Apr 2023 20:17:28 +0000 (20:17 +0000)] 
diff.h: reduce unnecessary includes

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoobject-store.h: reduce unnecessary includes
Elijah Newren [Sat, 22 Apr 2023 20:17:27 +0000 (20:17 +0000)] 
object-store.h: reduce unnecessary includes

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agocommit.h: reduce unnecessary includes
Elijah Newren [Sat, 22 Apr 2023 20:17:26 +0000 (20:17 +0000)] 
commit.h: reduce unnecessary includes

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agofsmonitor: reduce includes of cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:25 +0000 (20:17 +0000)] 
fsmonitor: reduce includes of cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agocache.h: remove unnecessary headers
Elijah Newren [Sat, 22 Apr 2023 20:17:24 +0000 (20:17 +0000)] 
cache.h: remove unnecessary headers

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agotreewide: remove cache.h inclusion due to previous changes
Elijah Newren [Sat, 22 Apr 2023 20:17:23 +0000 (20:17 +0000)] 
treewide: remove cache.h inclusion due to previous changes

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agocache,tree: move basic name compare functions from read-cache to tree
Elijah Newren [Sat, 22 Apr 2023 20:17:22 +0000 (20:17 +0000)] 
cache,tree: move basic name compare functions from read-cache to tree

None of base_name_compare(), df_name_compare(), or name_compare()
depended upon a cache_entry or index_state in any way.  By moving these
functions to tree.h, half a dozen other files can stop depending upon
cache.h (though that change will be made in a later commit).

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agocache,tree: move cmp_cache_name_compare from tree.[ch] to read-cache.c
Elijah Newren [Sat, 22 Apr 2023 20:17:21 +0000 (20:17 +0000)] 
cache,tree: move cmp_cache_name_compare from tree.[ch] to read-cache.c

Since cmp_cache_name_compare() was comparing cache_entry structs, it
was associated with the cache rather than with trees.  Move the
function.  As a side effect, we can make cache_name_stage_compare()
static as well.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agohash-ll.h: split out of hash.h to remove dependency on repository.h
Elijah Newren [Sat, 22 Apr 2023 20:17:20 +0000 (20:17 +0000)] 
hash-ll.h: split out of hash.h to remove dependency on repository.h

hash.h depends upon and includes repository.h, due to the definition and
use of the_hash_algo (defined as the_repository->hash_algo).  However,
most headers trying to include hash.h are only interested in the layout
of the structs like object_id.  Move the parts of hash.h that do not
depend upon repository.h into a new file hash-ll.h (the "low level"
parts of hash.h), and adjust other files to use this new header where
the convenience inline functions aren't needed.

This allows hash.h and object.h to be fairly small, minimal headers.  It
also exposes a lot of hidden dependencies on both path.h (which was
brought in by repository.h) and repository.h (which was previously
implicitly brought in by object.h), so also adjust other files to be
more explicit about what they depend upon.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agotree-diff.c: move S_DIFFTREE_IFXMIN_NEQ define from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:19 +0000 (20:17 +0000)] 
tree-diff.c: move S_DIFFTREE_IFXMIN_NEQ define from cache.h

S_DIFFTREE_IFXMIN_NEQ is *only* used in tree-diff.c, so there is no
point exposing it in cache.h.  Move it to tree-diff.c.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodir.h: move DTYPE defines from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:18 +0000 (20:17 +0000)] 
dir.h: move DTYPE defines from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoversioncmp.h: move declarations for versioncmp.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:17 +0000 (20:17 +0000)] 
versioncmp.h: move declarations for versioncmp.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agows.h: move declarations for ws.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:16 +0000 (20:17 +0000)] 
ws.h: move declarations for ws.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agomatch-trees.h: move declarations for match-trees.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:15 +0000 (20:17 +0000)] 
match-trees.h: move declarations for match-trees.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agopkt-line.h: move declarations for pkt-line.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:14 +0000 (20:17 +0000)] 
pkt-line.h: move declarations for pkt-line.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobase85.h: move declarations for base85.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:13 +0000 (20:17 +0000)] 
base85.h: move declarations for base85.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agocopy.h: move declarations for copy.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:12 +0000 (20:17 +0000)] 
copy.h: move declarations for copy.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoserver-info.h: move declarations for server-info.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:11 +0000 (20:17 +0000)] 
server-info.h: move declarations for server-info.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agopackfile.h: move pack_window and pack_entry from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:10 +0000 (20:17 +0000)] 
packfile.h: move pack_window and pack_entry from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agosymlinks.h: move declarations for symlinks.c functions from cache.h
Elijah Newren [Sat, 22 Apr 2023 20:17:09 +0000 (20:17 +0000)] 
symlinks.h: move declarations for symlinks.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agotreewide: be explicit about dependence on strbuf.h
Elijah Newren [Sat, 22 Apr 2023 20:17:08 +0000 (20:17 +0000)] 
treewide: be explicit about dependence on strbuf.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agofetch_bundle_uri(): drop pointless NULL check
Jeff King [Sat, 22 Apr 2023 13:56:46 +0000 (09:56 -0400)] 
fetch_bundle_uri(): drop pointless NULL check

We check if "uri" is NULL, but it cannot be since we'd have segfaulted
earlier in the function when we unconditionally called xstrdup() on it.

In theory we might want to soften that xstrdup() to handle this case,
but even before the code which added it via c23f592117 (bundle-uri:
fetch a list of bundles, 2022-10-12), we'd have fed NULL to
fetch_bundle_uri_internal(), which would also segfault.

The extra check isn't hurting anything, but it does cause Coverity to
complain, and it may mislead somebody reading the code into thinking
that a NULL uri is something we're prepared to handle.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agonotes: clean up confusing NULL checks in init_notes()
Jeff King [Sat, 22 Apr 2023 13:55:43 +0000 (09:55 -0400)] 
notes: clean up confusing NULL checks in init_notes()

Coverity complains that we check whether "notes_ref" is NULL, but it was
already implied to be non-NULL earlier in the function. And this is
true; since b9342b3fd63 (refs: add array of ref namespaces, 2022-08-05),
we call xstrdup(notes_ref) unconditionally, which would segfault if it
was NULL.

But that commit is actually doing the right thing. Even if NULL is
passed into the function, we'll use default_notes_ref() as a fallback,
which will never return NULL (it tries a few options, but its last
resort is a string literal). Ironically, the "!notes_ref" check was
added by the same commit that added the fallback: 709f79b0894 (Notes
API: init_notes(): Initialize the notes tree from the given notes ref,
2010-02-13). So this check never did anything.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoThe twelfth batch
Junio C Hamano [Fri, 21 Apr 2023 21:57:45 +0000 (14:57 -0700)] 
The twelfth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'ow/ref-filter-omit-empty'
Junio C Hamano [Fri, 21 Apr 2023 22:35:05 +0000 (15:35 -0700)] 
Merge branch 'ow/ref-filter-omit-empty'

"git branch --format=..." and "git format-patch --format=..."
learns "--omit-empty" to hide refs that whose formatting result
becomes an empty string from the output.

* ow/ref-filter-omit-empty:
  branch, for-each-ref, tag: add option to omit empty lines

17 months agoMerge branch 'ah/format-patch-thread-doc'
Junio C Hamano [Fri, 21 Apr 2023 22:35:04 +0000 (15:35 -0700)] 
Merge branch 'ah/format-patch-thread-doc'

Doc update.

* ah/format-patch-thread-doc:
  format-patch: correct documentation of --thread without an argument

17 months agoMerge branch 'rn/sparse-describe'
Junio C Hamano [Fri, 21 Apr 2023 22:35:04 +0000 (15:35 -0700)] 
Merge branch 'rn/sparse-describe'

"git describe --dirty" learns to work better with sparse-index.

* rn/sparse-describe:
  describe: enable sparse index for describe

17 months agoMerge branch 'rs/archive-from-subdirectory-fixes'
Junio C Hamano [Fri, 21 Apr 2023 22:35:04 +0000 (15:35 -0700)] 
Merge branch 'rs/archive-from-subdirectory-fixes'

"git archive" run from a subdirectory mishandled attributes and
paths outside the current directory.

* rs/archive-from-subdirectory-fixes:
  archive: improve support for running in subdirectory

17 months agoMerge branch 'fc/doc-stop-using-manversion'
Junio C Hamano [Fri, 21 Apr 2023 22:35:04 +0000 (15:35 -0700)] 
Merge branch 'fc/doc-stop-using-manversion'

Doc build simplification.

* fc/doc-stop-using-manversion:
  doc: simplify man version

17 months agocompletion: suppress unwanted unescaping of `read`
Edwin Kofler [Thu, 20 Apr 2023 22:38:00 +0000 (07:38 +0900)] 
completion: suppress unwanted unescaping of `read`

The function `__git_eread`, which reads the first line from the file,
calls the `read` builtin without passing the flag option `-r`.  When
the `read` builtin is called without the flag `-r`, it processes the
backslash escaping in the text that it reads.  For this reason, it is
generally considered the best practice to always use the `read`
builtin with flag `-r` unless one intensionally processes the
backslash escaping.  For the present case in git-prompt.sh, in fact,
all the occurrences of the calls of `__git_eread` intend to read the
literal content of the first lines.

To make it read the first line literally, pass the flag `-r` to the
`read` builtin in the function `__git_eread`.

Signed-off-by: Edwin Kofler <edwin@kofler.dev>
Signed-off-by: Koichi Murase <myoga.murase@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoThe eleventh batch
Junio C Hamano [Thu, 20 Apr 2023 20:41:15 +0000 (13:41 -0700)] 
The eleventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'gc/better-error-when-local-clone-fails-with-symlink'
Junio C Hamano [Thu, 20 Apr 2023 21:33:36 +0000 (14:33 -0700)] 
Merge branch 'gc/better-error-when-local-clone-fails-with-symlink'

"git clone --local" stops copying from an original repository that
has symbolic links inside its $GIT_DIR; an error message when that
happens has been updated.

* gc/better-error-when-local-clone-fails-with-symlink:
  clone: error specifically with --local and symlinked objects

17 months agoMerge branch 'ar/t2024-checkout-output-fix'
Junio C Hamano [Thu, 20 Apr 2023 21:33:36 +0000 (14:33 -0700)] 
Merge branch 'ar/t2024-checkout-output-fix'

Test fix.

* ar/t2024-checkout-output-fix:
  t2024: fix loose/strict local base branch DWIM test

17 months agoMerge branch 'rs/get-tar-commit-id-use-defined-const'
Junio C Hamano [Thu, 20 Apr 2023 21:33:36 +0000 (14:33 -0700)] 
Merge branch 'rs/get-tar-commit-id-use-defined-const'

Code clean-up to replace a hardcoded constant with a CPP macro.

* rs/get-tar-commit-id-use-defined-const:
  get-tar-commit-id: use TYPEFLAG_GLOBAL_HEADER instead of magic value

17 months agoMerge branch 'rs/remove-approxidate-relative'
Junio C Hamano [Thu, 20 Apr 2023 21:33:35 +0000 (14:33 -0700)] 
Merge branch 'rs/remove-approxidate-relative'

The approxidate() API has been simplified by losing an extra
function that did the same thing as another one.

* rs/remove-approxidate-relative:
  date: remove approxidate_relative()

17 months agoMerge branch 'rs/userdiff-multibyte-regex'
Junio C Hamano [Thu, 20 Apr 2023 21:33:35 +0000 (14:33 -0700)] 
Merge branch 'rs/userdiff-multibyte-regex'

The userdiff regexp patterns for various filetypes that are built
into the system have been updated to avoid triggering regexp errors
from UTF-8 aware regex engines.

* rs/userdiff-multibyte-regex:
  userdiff: support regexec(3) with multi-byte support

17 months agogpg-interface: set trust level of missing key to "undefined"
Jeff King [Wed, 19 Apr 2023 01:29:57 +0000 (21:29 -0400)] 
gpg-interface: set trust level of missing key to "undefined"

In check_signature(), we initialize the trust_level field to "-1", with
the idea that if gpg does not return a trust level at all (if there is
no signature, or if the signature is made by an unknown key), we'll
use that value. But this has two problems:

  1. Since the field is an enum, it's up to the compiler to decide what
     underlying storage to use, and it only has to fit the values we've
     declared. So we may not be able to store "-1" at all. And indeed,
     on my system (linux with gcc), the resulting enum is an unsigned
     32-bit value, and -1 becomes 4294967295.

     The difference may seem academic (and you even get "-1" if you pass
     it to printf("%d")), but it means that code like this:

       status |= sigc->trust_level < configured_min_trust_level;

     does not necessarily behave as expected. This turns out not to be a
     bug in practice, though, because we keep the "-1" only when gpg did
     not report a signature from a known key, in which case the line
     above:

       status |= sigc->result != 'G';

     would always set status to non-zero anyway. So only a 'G' signature
     with no parsed trust level would cause a problem, which doesn't
     seem likely to trigger (outside of unexpected gpg behavior).

  2. When using the "%GT" format placeholder, we pass the value to
     gpg_trust_level_to_str(), which complains that the value is out of
     range with a BUG(). This behavior was introduced by 803978da49
     (gpg-interface: add function for converting trust level to string,
     2022-07-11). Before that, we just did a switch() on the enum, and
     anything that wasn't matched would end up as the empty string.

     Curiously, solving this by naively doing:

       if (level < 0)
               return "";

     in that function isn't sufficient. Because of (1) above, the
     compiler can (and does in my case) actually remove that conditional
     as dead code!

We can solve both by representing this state as an enum value. We could
do this by adding a new "unknown" value. But this really seems to match
the existing "undefined" level well. GPG describes this as "Not enough
information for calculation".

We have tests in t7510 that trigger this case (verifying a signature
from a key that we don't have, and then checking various %G
placeholders), but they didn't notice the BUG() because we didn't look
at %GT for that case! Let's make sure we check all %G placeholders for
each case in the formatting tests.

The interesting ones here are "show unknown signature with custom
format" and "show lack of signature with custom format", both of which
would BUG() before, and now turn %GT into "undefined". Prior to
803978da49 they would have turned it into the empty string, but I think
saying "undefined" consistently is a reasonable outcome, and probably
makes life easier for anyone parsing the output (and any such parser had
to be ready to see "undefined" already).

The other modified tests produce the same output before and after this
patch, but now we're consistently checking both %G? and %GT in all of
them.

Signed-off-by: Jeff King <peff@peff.net>
Reported-by: Rolf Eike Beer <eb@emlix.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodoc: git-checkout: reorganize examples
Felipe Contreras [Tue, 18 Apr 2023 07:00:48 +0000 (01:00 -0600)] 
doc: git-checkout: reorganize examples

The examples are an ordered list, however, they are complex enough that
a callout is inside example 1, and that confuses the parsers as the list
continuation (`+`) is unclear (are we continuing the previous list item,
or the previous callout?).

We could use an open block as the asciidoctor documentation suggests,
but that has a tiny formatting issue (a newline is missing).

To simplify things for everyone (the reader, the writer, and the parser)
let's use subsections.

After this change, the HTML documentation generated with asciidoc has
the right indentation.

Cc: Jeff King <peff@peff.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodoc: git-checkout: trivial callout cleanup
Felipe Contreras [Tue, 18 Apr 2023 07:00:47 +0000 (01:00 -0600)] 
doc: git-checkout: trivial callout cleanup

The callouts are directly tied to the listing above, remove spaces to
make it clear they are one and the same.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agorepository.h: drop unused `gc_cruft_packs`
Taylor Blau [Tue, 18 Apr 2023 20:41:00 +0000 (16:41 -0400)] 
repository.h: drop unused `gc_cruft_packs`

As of the previous commit, all callers that need to read the value of
`gc.cruftPacks` do so outside without using the `repo_settings` struct,
making its `gc_cruft_packs` unused. Drop it accordingly.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobuiltin/gc.c: make `gc.cruftPacks` enabled by default
Taylor Blau [Tue, 18 Apr 2023 20:40:57 +0000 (16:40 -0400)] 
builtin/gc.c: make `gc.cruftPacks` enabled by default

Back in 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects
via loose, 2022-05-20), `git gc` learned the `--cruft` option and
`gc.cruftPacks` configuration to opt-in to writing cruft packs when
collecting or pruning unreachable objects.

Cruft packs were introduced with the merge in a50036da1a (Merge branch
'tb/cruft-packs', 2022-06-03). They address the problem of "loose object
explosions", where Git will write out many individual loose objects when
there is a large number of unreachable objects that have not yet aged
past `--prune=<date>`.

Instead of keeping track of those unreachable yet recent objects via
their loose object file's mtime, cruft packs collect all unreachable
objects into a single pack with a corresponding `*.mtimes` file that
acts as a table to store the mtimes of all unreachable objects. This
prevents the need to store unreachable objects as loose as they age out
of the repository, and avoids the problem of loose object explosions.

Beyond avoiding loose object explosions, cruft packs also act as a more
efficient mechanism to store unreachable objects as they age out of a
repository. This is because pairs of similar unreachable objects serve
as delta bases for one another.

In 5b92477f89, the feature was introduced as experimental. Since then,
GitHub has been running these patches in every repository generating
hundreds of millions of cruft packs along the way. The feature is
battle-tested, and avoids many pathological cases such as above. Users
who either run `git gc` manually, or via `git maintenance` can benefit
from having cruft packs.

As such, enable cruft pack generation to take place by default (by
making `gc.cruftPacks` have the default of "true" rather than "false).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/t9300-fast-import.sh: prepare for `gc --cruft` by default
Taylor Blau [Tue, 18 Apr 2023 20:40:52 +0000 (16:40 -0400)] 
t/t9300-fast-import.sh: prepare for `gc --cruft` by default

In a similar fashion as previous commits, adjust the fast-import tests
to prepare for "git gc" generating a cruft pack by default.

This adjustment is slightly different, however. Instead of relying on us
writing out the objects loose, and then calling `git prune` to remove
them, t9300 needs to be prepared to drop objects that would be moved
into cruft packs.

To do this, we can combine the `git gc` invocation with `git prune` into
one `git gc --prune`, which handles pruning both loose objects, and
objects that would otherwise be written to a cruft pack.

Likely this pattern of "git gc && git prune" started all the way back in
03db4525d3 (Support gitlinks in fast-import., 2008-07-19), which
happened after deprecating `git gc --prune` in 9e7d501990 (builtin-gc.c:
deprecate --prune, it now really has no effect, 2008-05-09).

After `--prune` was un-deprecated in 58e9d9d472 (gc: make --prune useful
again by accepting an optional parameter, 2009-02-14), this script got a
handful of new "git gc && git prune" instances via via 4cedb78cb5
(fast-import: add input format tests, 2011-08-11). These could have been
`git gc --prune`, but weren't (likely taking after 03db4525d3).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/t6500-gc.sh: add additional test cases
Taylor Blau [Tue, 18 Apr 2023 20:40:49 +0000 (16:40 -0400)] 
t/t6500-gc.sh: add additional test cases

In the last commit, we refactored some of the tests in t6500 to make
clearer when cruft packs will and won't be generated by `git gc`.

Add the remaining cases not covered by the previous patch into this one,
which enumerates all possible combinations of arguments that will
produce (or not produce) a cruft pack.

This prepares us for a future commit which will change the default value
of `gc.cruftPacks` by ensuring that we understand which invocations do
and do not change as a result.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/t6500-gc.sh: refactor cruft pack tests
Taylor Blau [Tue, 18 Apr 2023 20:40:46 +0000 (16:40 -0400)] 
t/t6500-gc.sh: refactor cruft pack tests

In 12253ab6d0 (gc: add tests for --cruft and friends, 2022-10-26), we
added a handful of tests to t6500 to ensure that `git gc` respected the
value of `--cruft` and `gc.cruftPacks`.

Then, in c695592850 (config: let feature.experimental imply
gc.cruftPacks=true, 2022-10-26), another set of similar tests was added
to ensure that `feature.experimental` correctly implied enabling cruft
pack generation (or not).

These tests are similar and could be consolidated. Do so in this patch
to prepare for expanding the set of command-line invocations that enable
or disable writing cruft packs. This makes it possible to easily test
more combinations of arguments without being overly repetitive.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/t6501-freshen-objects.sh: prepare for `gc --cruft` by default
Taylor Blau [Tue, 18 Apr 2023 20:40:43 +0000 (16:40 -0400)] 
t/t6501-freshen-objects.sh: prepare for `gc --cruft` by default

In a similar spirit as previous commits, prepare for `gc --cruft`
becoming the default by ensuring that the tests in t6501 explicitly
cover the case of freshening loose objects not using cruft packs.

We could run this test twice, once with `--cruft` and once with
`--no-cruft`, but doing so is unnecessary, since we already test object
rescuing, freshening, and dealing with corrupt parts of the unreachable
object graph extensively via t5329.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot/t5304-prune.sh: prepare for `gc --cruft` by default
Taylor Blau [Tue, 18 Apr 2023 20:40:41 +0000 (16:40 -0400)] 
t/t5304-prune.sh: prepare for `gc --cruft` by default

Many of the tests in t5304 run `git gc`, and rely on its behavior that
unreachable-but-recent objects are written out loose. This is sensible,
since t5304 deals specifically with this kind of pruning.

If left unattended, however, this test would break when the default
behavior of a bare "git gc" is adjusted to generate a cruft pack by
default.

Ensure that these tests continue to work as-is (and continue to provide
coverage of loose object pruning) by passing `--no-cruft` explicitly.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobuiltin/gc.c: ignore cruft packs with `--keep-largest-pack`
Taylor Blau [Tue, 18 Apr 2023 20:40:38 +0000 (16:40 -0400)] 
builtin/gc.c: ignore cruft packs with `--keep-largest-pack`

When cruft packs were implemented, we never adjusted the code for `git
gc`'s `--keep-largest-pack` and `gc.bigPackThreshold` to ignore cruft
packs. This option and configuration option share a common
implementation, but including cruft packs is wrong in both cases:

  - Running `git gc --keep-largest-pack` in a repository where the
    largest pack is the cruft pack itself will make it impossible for
    `git gc` to prune objects, since the cruft pack itself is kept.

  - The same is true for `gc.bigPackThreshold`, if the size of the cruft
    pack exceeds the limit set by the caller.

In the future, it is possible that `gc.bigPackThreshold` could be used
to write a separate cruft pack containing any new unreachable objects
that entered the repository since the last time a cruft pack was
written.

There are some complexities to doing so, mainly around handling
pruning objects that are in an existing cruft pack that is above the
threshold (which would either need to be rewritten, or else delay
pruning). Rewriting a substantially similar cruft pack isn't ideal, but
it is significantly better than the status-quo.

If users have large cruft packs that they don't want to rewrite, they
can mark them as `*.keep` packs. But in general, if a repository has a
cruft pack that is so large it is slowing down GC's, it should probably
be pruned anyway.

In the meantime, ignore cruft packs in the common implementation for
both of these options, and add a pair of tests to prevent any future
regressions here.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobuiltin/repack.c: fix incorrect reference to '-C'
Taylor Blau [Tue, 18 Apr 2023 20:40:35 +0000 (16:40 -0400)] 
builtin/repack.c: fix incorrect reference to '-C'

When cruft packs were originally being developed, `-C` was designated as
the short-form for `--cruft` (as in `git repack -C`).

This was dropped due to confusion with Git's top-level `-C` option
before submitting to the list. But the reference to it in
`--cruft-expiration`'s help text was never updated. Fix that dangling
reference in this patch.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agopack-write.c: plug a leak in stage_tmp_packfiles()
Taylor Blau [Tue, 18 Apr 2023 20:40:32 +0000 (16:40 -0400)] 
pack-write.c: plug a leak in stage_tmp_packfiles()

The function `stage_tmp_packfiles()` generates a filename to use for
staging the contents of what will become the pack's ".mtimes" file.

The name is generated in `write_mtimes_file()` and the result is
returned back to `stage_tmp_packfiles()` which uses it to rename the
temporary file into place via `rename_tmp_packfiles()`.

`write_mtimes_file()` returns a `const char *`, indicating that callers
are not expected to free its result (similar to, e.g., `oid_to_hex()`).
But callers are expected to free its result, so this return type is
incorrect.

Change the function's signature to return a non-const `char *`, and free
it at the end of `stage_tmp_packfiles()`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoprotocol.h: move definition of DEFAULT_GIT_PORT from cache.h
Elijah Newren [Sun, 16 Apr 2023 03:03:05 +0000 (03:03 +0000)] 
protocol.h: move definition of DEFAULT_GIT_PORT from cache.h

Michael J Gruber noticed that connection via the git:// protocol no
longer worked after a recent header clean-up.  This was caused by
funny interaction of few gotchas.  First, a necessary definition

#define DEFAULT_GIT_PORT 9418

was made invisible to a place where

const char *port = STR(DEFAULT_GIT_PORT);

was expecting to turn the integer into "9418" with a clever STR()
macro, and ended up stringifying it to

const char *port = "DEFAULT_GIT_PORT";

without giving any chance to compilers to notice such a mistake.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoThe tenth batch
Junio C Hamano [Mon, 17 Apr 2023 23:41:04 +0000 (16:41 -0700)] 
The tenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'pw/rebase-cleanup-merge-strategy-option-handling'
Junio C Hamano [Tue, 18 Apr 2023 01:05:13 +0000 (18:05 -0700)] 
Merge branch 'pw/rebase-cleanup-merge-strategy-option-handling'

Clean-up of the code path that deals with merge strategy option
handling in "git rebase".

* pw/rebase-cleanup-merge-strategy-option-handling:
  rebase: remove a couple of redundant strategy tests
  rebase -m: fix serialization of strategy options
  rebase -m: cleanup --strategy-option handling
  sequencer: use struct strvec to store merge strategy options
  rebase: stop reading and writing unnecessary strategy state

17 months agoMerge branch 'cm/branch-delete-error-message-update'
Junio C Hamano [Tue, 18 Apr 2023 01:05:12 +0000 (18:05 -0700)] 
Merge branch 'cm/branch-delete-error-message-update'

"git branch -d origin/master" would say "no such branch", but it is
likely a missed "-r" if refs/remotes/origin/master exists.  The
command has been taught to give such a hint in its error message.

* cm/branch-delete-error-message-update:
  branch: improve error log on branch not found by checking remotes refs

17 months agoMerge branch 'fc/remove-header-workarounds-for-asciidoc'
Junio C Hamano [Tue, 18 Apr 2023 01:05:12 +0000 (18:05 -0700)] 
Merge branch 'fc/remove-header-workarounds-for-asciidoc'

Doc toolchain update to remove old workaround for AsciiDoc.

* fc/remove-header-workarounds-for-asciidoc:
  doc: asciidoc: remove custom header macro

17 months agoMerge branch 'la/mfc-markup-fix'
Junio C Hamano [Tue, 18 Apr 2023 01:05:12 +0000 (18:05 -0700)] 
Merge branch 'la/mfc-markup-fix'

Documentation mark-up fix.

* la/mfc-markup-fix:
  MyFirstContribution: render literal *

17 months agoMerge branch 'tk/mergetool-gui-default-config'
Junio C Hamano [Tue, 18 Apr 2023 01:05:11 +0000 (18:05 -0700)] 
Merge branch 'tk/mergetool-gui-default-config'

"git mergetool" and "git difftool" learns a new configuration
guiDefault to optionally favor configured guitool over non-gui-tool
automatically when $DISPLAY is set.

* tk/mergetool-gui-default-config:
  mergetool: new config guiDefault supports auto-toggling gui by DISPLAY

17 months agoMerge branch 'sl/sparse-write-tree'
Junio C Hamano [Tue, 18 Apr 2023 01:05:11 +0000 (18:05 -0700)] 
Merge branch 'sl/sparse-write-tree'

"git write-tree" learns to work better with sparse-index.

* sl/sparse-write-tree:
  write-tree: integrate with sparse index

17 months agofsck: validate .rev file header
Derrick Stolee [Mon, 17 Apr 2023 16:21:41 +0000 (16:21 +0000)] 
fsck: validate .rev file header

While parsing a .rev file, we check the header information to be sure it
makes sense. This happens before doing any additional validation such as
a checksum or value check. In order to differentiate between a bad
header and a non-existent file, we need to update the API for loading a
reverse index.

Make load_pack_revindex_from_disk() non-static and specify that a
positive value means "the file does not exist" while other errors during
parsing are negative values. Since an invalid header prevents setting up
the structures we would use for further validations, we can stop at that
point.

The place where we can distinguish between a missing file and a corrupt
file is inside load_revindex_from_disk(), which is used both by pack
rev-indexes and multi-pack-index rev-indexes. Some tests in t5326
demonstrate that it is critical to take some conditions to allow
positive error signals.

Add tests that check the three header values.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agofsck: check rev-index position values
Derrick Stolee [Mon, 17 Apr 2023 16:21:40 +0000 (16:21 +0000)] 
fsck: check rev-index position values

When checking a rev-index file, it may be helpful to identify exactly
which positions are incorrect. Compare the rev-index to a
freshly-computed in-memory rev-index and report the comparison failures.

This additional check (on top of the checksum validation) can help find
files that were corrupt by a single bit flip on-disk or perhaps were
written incorrectly due to a bug in Git.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agofsck: check rev-index checksums
Derrick Stolee [Mon, 17 Apr 2023 16:21:39 +0000 (16:21 +0000)] 
fsck: check rev-index checksums

The previous change added calls to verify_pack_revindex() in
builtin/fsck.c, but the implementation of the method was left empty. Add
the first and most-obvious check to this method: checksum verification.

While here, create a helper method in the test script that makes it easy
to adjust the .rev file and check that 'git fsck' reports the correct
error message.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agofsck: create scaffolding for rev-index checks
Derrick Stolee [Mon, 17 Apr 2023 16:21:38 +0000 (16:21 +0000)] 
fsck: create scaffolding for rev-index checks

The 'fsck' builtin checks many of Git's on-disk data structures, but
does not currently validate the pack rev-index files (a .rev file to
pair with a .pack and .idx file).

Before doing a more-involved check process, create the scaffolding
within builtin/fsck.c to have a new error type and add that error type
when the API method verify_pack_revindex() returns an error. That method
does nothing currently, but we will add checks to it in later changes.

For now, check that 'git fsck' succeeds without any errors in the normal
case. Future checks will be paired with tests that corrupt the .rev file
appropriately.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>