]> git.99rst.org Git - git.git/log
git.git
2 years agolog: do not set up extra_headers for non-email formats
Jeff King [Wed, 20 Mar 2024 00:31:39 +0000 (20:31 -0400)]
log: do not set up extra_headers for non-email formats

The commit pretty-printer code has an "after_subject" parameter which it
uses to insert extra headers into the email format. In show_log() we set
this by calling log_write_email_headers() if we are using an email
format, but otherwise default the variable to the rev_info.extra_headers
variable.

Since the pretty-printer code will ignore after_subject unless we are
using an email format, this default is pointless. We can just set
after_subject directly, eliminating an extra variable.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agopretty: drop print_email_subject flag
Jeff King [Wed, 20 Mar 2024 00:30:44 +0000 (20:30 -0400)]
pretty: drop print_email_subject flag

With one exception, the print_email_subject flag is set if and only if
the commit format is email based:

  - in make_cover_letter() we set it along with CMIT_FMT_EMAIL
    explicitly

  - in show_log(), we set it if cmit_fmt_is_mail() is true. That covers
    format-patch as well as "git log --format=email" (or mboxrd).

The one exception is "rev-list --format=email", which somewhat
nonsensically prints the author and date as email headers, but no
subject, like:

  $ git rev-list --format=email HEAD
  commit 64fc4c2cdd4db2645eaabb47aa4bac820b03cdba
  From: Jeff King <redacted>
  Date: Tue, 19 Mar 2024 19:39:26 -0400

  this is the subject

  this is the body

It's doubtful that this is a useful format at all (the "commit" lines
replace the "From" lines that would make it work as an actual mbox).
But I think that printing the subject as a header (like this patch does)
is the least surprising thing to do.

So let's drop this field, making the code a little simpler and easier to
reason about. Note that we do need to set the "rev" field of the
pretty_print_context in rev-list, since that is used to check for
subject_prefix, etc. It's not possible to set those fields via rev-list,
so we'll always just print "Subject: ". But unless we pass in our
rev_info, fmt_output_email_subject() would segfault trying to figure it
out.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agopretty: split oneline and email subject printing
Jeff King [Wed, 20 Mar 2024 00:28:51 +0000 (20:28 -0400)]
pretty: split oneline and email subject printing

The pp_title_line() function is used for two formats: the oneline format
and the subject line of the email format. But most of the logic in the
function does not make any sense for oneline; it is about special
formatting of email headers.

Lumping the two formats together made sense long ago in 4234a76167
(Extend --pretty=oneline to cover the first paragraph, 2007-06-11), when
there was a lot of manual logic to paste lines together. But later,
88c44735ab (pretty: factor out format_subject(), 2008-12-27) pulled that
logic into its own function.

We can implement the oneline format by just calling that one function.
This makes the intention of the code much more clear, as we know we only
need to worry about those extra email options when dealing with actual
email.

While the intent here is cleanup, it is possible to trigger these cases
in practice by running format-patch with an explicit --oneline option.
But if you did, the results are basically nonsense. For example, with
the preserve_subject flag:

  $ printf "%s\n" one two three | git commit --allow-empty -F -
  $ git format-patch -1 --stdout -k | grep ^Subject
  Subject: =?UTF-8?q?one=0Atwo=0Athree?=
  $ git format-patch -1 --stdout -k --oneline --no-signature
  2af7fbe one
  two
  three

Or with extra headers:

  $ git format-patch -1 --stdout --cc=me --oneline --no-signature
  2af7fbe one two three
Cc: me
So I'd actually consider this to be an improvement, though you are
probably crazy to use other formats with format-patch in the first place
(arguably it should forbid non-email formats entirely, but that's a
bigger change).

As a bonus, it eliminates some pointless extra allocations for the
oneline output. The email code, since it has to deal with wrapping,
formats into an extra auxiliary buffer. The speedup is tiny, though like
"rev-list --no-abbrev --format=oneline" seems to improve by a consistent
1-2% for me.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoshortlog: stop setting pp.print_email_subject
Jeff King [Wed, 20 Mar 2024 00:27:16 +0000 (20:27 -0400)]
shortlog: stop setting pp.print_email_subject

When shortlog processes a commit using its internal traversal, it may
pretty-print the subject line for the summary view. When we do so, we
set the "print_email_subject" flag in the pretty-print context. But this
flag does nothing! Since we are using CMIT_FMT_USERFORMAT, we skip most
of the usual formatting code entirely.

This flag is there due to commit 6d167fd7cc (pretty: use
fmt_output_email_subject(), 2017-03-01). But that just switched us away
from setting an empty "subject" header field, which was similarly
useless. That was added by dd2e794a21 (Refactor pretty_print_commit
arguments into a struct, 2009-10-19). Before using the struct, we had to
pass _something_ as the argument, so we passed the empty string (a NULL
would have worked equally well).

So this setting has never done anything, and we can drop the line. That
shortens the code, but more importantly, makes it easier to reason about
and refactor the other users of this flag.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoapply: parse names out of "diff --git" more carefully
Junio C Hamano [Tue, 19 Mar 2024 22:56:44 +0000 (15:56 -0700)]
apply: parse names out of "diff --git" more carefully

"git apply" uses the pathname parsed out of the "diff --git" header
to decide which path is being patched, but this is used only when
there is no other names available in the patch.  When there is any
content change (like we can see in this patch, that modifies the
contents of "apply.c") or rename (which comes with "rename from" and
"rename to" extended diff headers), the names are available without
having to parse this header.

When we do need to parse this header, a special care needs to be
taken, as the name of a directory or a file can have a SP in it so
it is not like "find a space, and take everything before the space
and that is the preimage filename, everything after the space is the
postimage filename".  We have a loop that stops at every SP on the
"diff --git a/dir/file b/dir/foo" line and see if that SP is the
right place that separates such a pair of names.

Unfortunately, this loop can terminate prematurely when a crafted
directory name ended with a SP.  The next pathname component after
that SP (i.e. the beginning of the possible postimage filename) will
be a slash, and instead of rejecting that position as the valid
separation point between pre- and post-image filenames and keep
looping, we stopped processing right there.

The fix is simple.  Instead of stopping and giving up, keep going on
when we see such a condition.

Reported-by: Han Young <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoMerge branch 'ps/reftable-stack-tempfile' into ps/pack-refs-auto
Junio C Hamano [Mon, 18 Mar 2024 20:24:32 +0000 (13:24 -0700)]
Merge branch 'ps/reftable-stack-tempfile' into ps/pack-refs-auto

* ps/reftable-stack-tempfile:
  reftable/stack: register compacted tables as tempfiles
  reftable/stack: register lockfiles during compaction
  reftable/stack: register new tables as tempfiles
  lockfile: report when rollback fails

2 years agoThe ninth batch
Junio C Hamano [Mon, 18 Mar 2024 20:02:12 +0000 (13:02 -0700)]
The ninth batch

Signed-off-by: Junio C Hamano <redacted>
2 years agoMerge branch 'jk/doc-remote-helpers-markup-fix'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)]
Merge branch 'jk/doc-remote-helpers-markup-fix'

Doc mark-up fix.

* jk/doc-remote-helpers-markup-fix:
  doc/gitremote-helpers: fix missing single-quote

2 years agoMerge branch 'jh/trace2-missing-def-param-fix'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)]
Merge branch 'jh/trace2-missing-def-param-fix'

Some trace2 events that lacked def_param have learned to show it,
enriching the output.

Reviewed-by: Josh Steadmon <redacted>
cf. <redacted>

* jh/trace2-missing-def-param-fix:
  trace2: emit 'def_param' set with 'cmd_name' event
  trace2: avoid emitting 'def_param' set more than once
  t0211: demonstrate missing 'def_param' events for certain commands

2 years agoMerge branch 'pw/rebase-i-ignore-cherry-pick-help-environment'
Junio C Hamano [Mon, 18 Mar 2024 20:04:25 +0000 (13:04 -0700)]
Merge branch 'pw/rebase-i-ignore-cherry-pick-help-environment'

Code simplification by getting rid of code that sets an environment
variable that is no longer used.

* pw/rebase-i-ignore-cherry-pick-help-environment:
  rebase -i: stop setting GIT_CHERRY_PICK_HELP

2 years agodocs: adjust trailer `separator` and `key_value_separator` language
Brian Lyles [Mon, 18 Mar 2024 05:38:02 +0000 (00:38 -0500)]
docs: adjust trailer `separator` and `key_value_separator` language

The language describing the trailer separator and key-value separator
default value is overly complicated.

Indicate the default with simpler "Defaults to ..." language.

Suggested-by: Linus Arver <redacted>
Signed-off-by: Brian Lyles <redacted>
Acked-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodocs: correct trailer `key_value_separator` description
Brian Lyles [Mon, 18 Mar 2024 05:38:01 +0000 (00:38 -0500)]
docs: correct trailer `key_value_separator` description

The description for `key_value_separator` incorrectly states that this
separator is inserted between trailer lines, which appears likely to
have been incorrectly copied from `separator` when this option was
added.

Update the description to correctly indicate that it is a separator that
appears between the key and the value of each trailer.

Signed-off-by: Brian Lyles <redacted>
Acked-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agobuiltin/am: allow disabling conflict advice
Philippe Blain [Sat, 16 Mar 2024 21:16:30 +0000 (21:16 +0000)]
builtin/am: allow disabling conflict advice

When 'git am' or 'git rebase --apply' encounter a conflict, they show a
message instructing the user how to continue the operation. This message
can't be disabled.

Use ADVICE_MERGE_CONFLICT introduced in the previous commit to allow
disabling it. Update the tests accordingly, as the advice output is now
on stderr instead of stdout. In t4150, redirect stdout to 'out' and
stderr to 'err', since this is less confusing. In t4254, as we are
testing a specific failure mode of 'git am', simply disable the advice.
Note that we are not testing that this advice is shown in 'git rebase'
for the apply backend since 2ac0d6273f (rebase: change the default
backend from "am" to "merge", 2020-02-15).

Helped-by: Phillip Wood <redacted>
Helped-by: Junio C Hamano <redacted>
Signed-off-by: Philippe Blain <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agosequencer: allow disabling conflict advice
Philippe Blain [Sat, 16 Mar 2024 21:16:29 +0000 (21:16 +0000)]
sequencer: allow disabling conflict advice

Allow disabling the advice shown when a squencer operation results in a
merge conflict through a new config 'advice.mergeConflict', which is
named generically such that it can be used by other commands eventually.

Remove that final '\n' in the first hunk in sequencer.c to avoid an
otherwise empty 'hint: ' line before the line 'hint: Disable this
message with "git config advice.mergeConflict false"' which is
automatically added by 'advise_if_enabled'.

Note that we use 'advise_if_enabled' for each message in the second hunk
in sequencer.c, instead of using 'if (show_hints &&
advice_enabled(...)', because the former instructs the user how to
disable the advice, which is more user-friendly.

Update the tests accordingly. Note that the body of the second test in
t3507-cherry-pick-conflict.sh is enclosed in double quotes, so we must
escape them in the added line. Note that t5520-pull.sh, which checks
that we display the advice for 'git rebase' (via 'git pull --rebase')
does not have to be updated because it only greps for a specific line in
the advice message.

Signed-off-by: Philippe Blain <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot-prio-queue: check result array bounds
René Scharfe [Sat, 16 Mar 2024 21:09:47 +0000 (22:09 +0100)]
t-prio-queue: check result array bounds

Avoid reading past the end of the "result" array, which could otherwise
happen if the prio-queue were to yield more items than were put into it
due to an implementation bug, or if the array has not enough entries due
to a test bug.

Also check at the end whether all "result" entries were consumed, which
would not be the case if the prio-queue forgot some entries or the test
definition contained too many.

Signed-off-by: René Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot-prio-queue: shorten array index message
René Scharfe [Sat, 16 Mar 2024 20:45:51 +0000 (21:45 +0100)]
t-prio-queue: shorten array index message

If we get an unexpected result, the prio-queue unit test reports it like
this:

 # check "result[j++] == show(get)" failed at t/unit-tests/t-prio-queue.c:43
 #    left: 5
 #   right: 1
 # failed at result[] index 0

That last line repeats "failed" and "result" from the first line.
Shorten it to resemble a similar one in t-ctype and also remove the
incrementation from the first line to avoid possible distractions from
the message of which comparison went wrong where:

 # check "result[j] == show(get)" failed at t/unit-tests/t-prio-queue.c:43
 #    left: 5
 #   right: 1
 #       j: 0

Signed-off-by: René Scharfe <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodiff.*Prefix: use camelCase in the doc and test titles
Junio C Hamano [Sat, 16 Mar 2024 05:57:22 +0000 (22:57 -0700)]
diff.*Prefix: use camelCase in the doc and test titles

We added documentation for diff.srcPrefix and diff.dstPrefix with
their names properly camelCased, but the diff.noPrefix is listed
there in all lowercase.  Also these configuration variables, both
existing ones and the {src,dst}Prefix we recently added, were
spelled in all lowercase in the tests in t4013.

Now we are done with the main change, clean these up.

Signed-off-by: Junio C Hamano <redacted>
Reviewed-by: Peter Hutterer <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agogit-quiltimport: avoid an unnecessary subshell
Beat Bolli [Fri, 15 Mar 2024 19:46:19 +0000 (20:46 +0100)]
git-quiltimport: avoid an unnecessary subshell

Use braces for the compound command.

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agocontrib/coverage-diff: avoid redundant pipelines
Beat Bolli [Fri, 15 Mar 2024 19:46:18 +0000 (20:46 +0100)]
contrib/coverage-diff: avoid redundant pipelines

Merge multiple sed and "grep | awk" invocations, finally use "sort -u"
instead of "sort | uniq".

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t9*: merge "grep | sed" pipelines
Beat Bolli [Fri, 15 Mar 2024 19:46:17 +0000 (20:46 +0100)]
t/t9*: merge "grep | sed" pipelines

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t8*: merge "grep | sed" pipelines
Beat Bolli [Fri, 15 Mar 2024 19:46:16 +0000 (20:46 +0100)]
t/t8*: merge "grep | sed" pipelines

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t5*: merge a "grep | sed" pipeline
Beat Bolli [Fri, 15 Mar 2024 19:46:15 +0000 (20:46 +0100)]
t/t5*: merge a "grep | sed" pipeline

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t4*: merge a "grep | sed" pipeline
Beat Bolli [Fri, 15 Mar 2024 19:46:14 +0000 (20:46 +0100)]
t/t4*: merge a "grep | sed" pipeline

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t3*: merge a "grep | awk" pipeline
Beat Bolli [Fri, 15 Mar 2024 19:46:13 +0000 (20:46 +0100)]
t/t3*: merge a "grep | awk" pipeline

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t1*: merge a "grep | sed" pipeline
Beat Bolli [Fri, 15 Mar 2024 19:46:12 +0000 (20:46 +0100)]
t/t1*: merge a "grep | sed" pipeline

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t9*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:11 +0000 (20:46 +0100)]
t/t9*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t8*: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:10 +0000 (20:46 +0100)]
t/t8*: avoid redundant use of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t7*: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:09 +0000 (20:46 +0100)]
t/t7*: avoid redundant use of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t6*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:08 +0000 (20:46 +0100)]
t/t6*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t5*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:07 +0000 (20:46 +0100)]
t/t5*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t4*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:06 +0000 (20:46 +0100)]
t/t4*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t3*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:05 +0000 (20:46 +0100)]
t/t3*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t1*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:04 +0000 (20:46 +0100)]
t/t1*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/t0*: avoid redundant uses of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:03 +0000 (20:46 +0100)]
t/t0*: avoid redundant uses of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/perf: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:02 +0000 (20:46 +0100)]
t/perf: avoid redundant use of cat

Take care to redirect stdin, otherwise the output of wc would also contain
the file name.

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/annotate-tests.sh: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:01 +0000 (20:46 +0100)]
t/annotate-tests.sh: avoid redundant use of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot/lib-cvs.sh: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:46:00 +0000 (20:46 +0100)]
t/lib-cvs.sh: avoid redundant use of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agocontrib/subtree/t: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:45:59 +0000 (20:45 +0100)]
contrib/subtree/t: avoid redundant use of cat

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodoc: avoid redundant use of cat
Beat Bolli [Fri, 15 Mar 2024 19:45:58 +0000 (20:45 +0100)]
doc: avoid redundant use of cat

The update-hook-example.txt script uses this anti-pattern twice. Call grep
with the input file name directy. While at it, merge the two consecutive
grep calls.

Signed-off-by: Beat Bolli <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoMerge branch 'la/format-trailer-info' into la/hide-trailer-info
Junio C Hamano [Sat, 16 Mar 2024 17:07:39 +0000 (10:07 -0700)]
Merge branch 'la/format-trailer-info' into la/hide-trailer-info

* la/format-trailer-info:
  trailer: finish formatting unification
  trailer: begin formatting unification
  format_trailer_info(): append newline for non-trailer lines
  format_trailer_info(): drop redundant unfold_value()
  format_trailer_info(): use trailer_item objects

2 years agodoc: fix some placeholders formating
Jean-Noël Avila [Sat, 16 Mar 2024 15:21:41 +0000 (15:21 +0000)]
doc: fix some placeholders formating

Signed-off-by: Jean-Noël Avila <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodoc: format alternatives in synopsis
Jean-Noël Avila [Sat, 16 Mar 2024 15:21:40 +0000 (15:21 +0000)]
doc: format alternatives in synopsis

This is a list of various fixes on malformed alternative in commands
and option syntax.

Signed-off-by: Jean-Noël Avila <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodocs: fix typo in git-config `--default`
Brian Lyles [Sat, 16 Mar 2024 05:01:25 +0000 (00:01 -0500)]
docs: fix typo in git-config `--default`

Signed-off-by: Brian Lyles <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodocs: clarify file options in git-config `--edit`
Brian Lyles [Sat, 16 Mar 2024 05:01:24 +0000 (00:01 -0500)]
docs: clarify file options in git-config `--edit`

The description for the `-e`/`--edit` option references scopes
inconsistently: system and global are referenced by their option name
(`--system`/`--global`), but repository (`--local` is not. Additionally,
neither `--worktree` nor `--file` are referenced at all, despite also
being a valid options.

Update the description to mention all four available scopes as well as
`--file`, referencing each consistently by their option name.

Signed-off-by: Brian Lyles <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agobugreport.c: fix a crash in `git bugreport` with `--no-suffix` option
Jiamu Sun [Thu, 14 Mar 2024 04:00:16 +0000 (04:00 +0000)]
bugreport.c: fix a crash in `git bugreport` with `--no-suffix` option

`git bugreport` does not complain when `--no-suffix` is given, but
it leads to a segmentation fault as the it is not prepared to see a
NULL assigned to the option_suffix variable.

Signed-off-by: Jiamu Sun <redacted>
Acked-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoconfig: allow tweaking whitespace between value and comment
Junio C Hamano [Fri, 15 Mar 2024 22:26:40 +0000 (15:26 -0700)]
config: allow tweaking whitespace between value and comment

Extending the previous step, this allows the whitespace placed after
the value before the "# comment message" to be tweaked by tweaking
the preprocessing rule to:

 * If the given comment string begins with one or more whitespace
   characters followed by '#', it is passed intact.

 * If the given comment string begins with '#', a Space is
   prepended.

 * Otherwise, " # " (Space, '#', Space) is prefixed.

 * A string with LF in it cannot be used as a comment string.

Unlike the previous step, which unconditionally added a space after
the value before writing the "# comment string", because the above
preprocessing already gives a whitespace before the '#', the
resulting string is written immediately after copying the value.

And the sanity checking rule becomes

 * comment string after the above massaging that comes into
   git_config_set_multivar_in_file_gently() must

   - begin with zero or more whitespace characters followed by '#'.
   - not have a LF in it.

I personally think this is over-engineered, but since I thought
things through anyway, here it is in the patch form.  The logic to
tweak end-user supplied comment string is encapsulated in a new
helper function, git_config_prepare_comment_string(), so if new
front-end callers would want to use the same massaging rules, it is
easily reused.

Unfortunately I do not think of a way to tweak the preprocessing
rules further to optionally allow having no blank after the value,
i.e. to produce

[section]
variable = value#comment

(which is a valid way to say section.variable=value, by the way)
without sacrificing the ergonomics for the more usual case, so this
time I really stop here.

Signed-off-by: Junio C Hamano <redacted>
2 years agoconfig: fix --comment formatting
Junio C Hamano [Fri, 15 Mar 2024 19:43:58 +0000 (12:43 -0700)]
config: fix --comment formatting

When git adds comments itself (like "rebase -i" todo list and
"commit -e" log message editor), it always gives a comment
introducer "#" followed by a Space before the message, except for
the recently introduced "git config --comment", where the users are
forced to say " this is my comment" if they want to add their
comment in this usual format; otherwise their comment string will
end up without a space after the "#".

Make it more ergonomic, while keeping it possible to also use this
unusual style, by massaging the comment string at the UI layer with
a set of simple rules:

 * If the given comment string begins with '#', it is passed intact.
 * Otherwise, "# " is prefixed.
 * A string with LF in it cannot be used as a comment string.

Right now there is only one "front-end" that accepts end-user
comment string and calls the underlying machinery to add or modify
configuration file with comments, but to make sure that the future
callers perform similar massaging as they see fit, add a sanity
check logic in git_config_set_multivar_in_file_gently(), which is
the single choke point in the codepaths that consumes the comment
string.

Signed-off-by: Junio C Hamano <redacted>
2 years agoThe eighth batch
Junio C Hamano [Fri, 15 Mar 2024 22:20:53 +0000 (15:20 -0700)]
The eighth batch

Signed-off-by: Junio C Hamano <redacted>
2 years agoMerge branch 'hd/config-mak-os390'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)]
Merge branch 'hd/config-mak-os390'

Platform specific tweaks for OS/390 has been added to
config.mak.uname.

* hd/config-mak-os390:
  build: support z/OS (OS/390).

2 years agoMerge branch 'vm/t7301-use-test-path-helpers'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)]
Merge branch 'vm/t7301-use-test-path-helpers'

GSoC practice to replace "test -f" with "test_path_is_file".

* vm/t7301-use-test-path-helpers:
  t7301: use test_path_is_(missing|file)

2 years agoMerge branch 'jc/xwrite-cleanup'
Junio C Hamano [Fri, 15 Mar 2024 23:06:00 +0000 (16:06 -0700)]
Merge branch 'jc/xwrite-cleanup'

Uses of xwrite() helper have been audited and updated for better
error checking and simpler code.

* jc/xwrite-cleanup:
  repack: check error writing to pack-objects subprocess
  sideband: avoid short write(2)
  unpack: replace xwrite() loop with write_in_full()

2 years agoMerge branch 'ag/t0010-modernize'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)]
Merge branch 'ag/t0010-modernize'

GSoC practice to modernize a test script.

* ag/t0010-modernize:
  tests: modernize the test script t0010-racy-git.sh

2 years agoMerge branch 'as/option-names-in-messages'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)]
Merge branch 'as/option-names-in-messages'

Error message updates.

* as/option-names-in-messages:
  revision.c: trivial fix to message
  builtin/clone.c: trivial fix of message
  builtin/remote.c: trivial fix of error message
  transport-helper.c: trivial fix of error message

2 years agoMerge branch 'kh/branch-ref-syntax-advice'
Junio C Hamano [Fri, 15 Mar 2024 23:05:59 +0000 (16:05 -0700)]
Merge branch 'kh/branch-ref-syntax-advice'

When git refuses to create a branch because the proposed branch
name is not a valid refname, an advice message is given to refer
the user to exact naming rules.

* kh/branch-ref-syntax-advice:
  branch: advise about ref syntax rules
  advice: use double quotes for regular quoting
  advice: use backticks for verbatim
  advice: make all entries stylistically consistent
  t3200: improve test style

2 years agoconfig: add --comment option to add a comment
Ralph Seichter [Tue, 12 Mar 2024 21:47:00 +0000 (21:47 +0000)]
config: add --comment option to add a comment

Introduce the ability to append comments to modifications
made using git-config. Example usage:

  git config --comment "changed via script" \
    --add safe.directory /home/alice/repo.git

based on the proposed patch, the output produced is:

  [safe]
    directory = /home/alice/repo.git #changed via script

Users need to be able to distinguish between config entries made
using automation and entries made by a human. Automation can add
comments containing a URL pointing to explanations for the change
made, avoiding questions from users as to why their config file
was changed by a third party.

The implementation ensures that a # character is unconditionally
prepended to the provided comment string, and that the comment
text is appended as a suffix to the changed key-value-pair in the
same line of text. Multi-line comments (i.e. comments containing
linefeed) are rejected as errors, causing Git to exit without
making changes.

Comments are aimed at humans who inspect or change their Git
config using a pager or editor. Comments are not meant to be
read or displayed by git-config at a later time.

Signed-off-by: Ralph Seichter <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agofuzz: add fuzzer for config parsing
Brian C Tracy [Fri, 15 Mar 2024 05:47:31 +0000 (05:47 +0000)]
fuzz: add fuzzer for config parsing

Add a new fuzz target that exercises the parsing of git configs.
The existing git_config_from_mem function is a perfect entry point
for fuzzing as it exercises the same code paths as the rest of the
config parsing functions and offers an easily fuzzable interface.

Config parsing is a useful thing to fuzz because it operates on user
controlled data and is a central component of many git operations.

Signed-off-by: Brian C Tracy <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agotrailer: finish formatting unification
Linus Arver [Fri, 15 Mar 2024 06:55:05 +0000 (06:55 +0000)]
trailer: finish formatting unification

Rename format_trailer_info() to format_trailers(). Finally, both
interpret-trailers and format_trailers_from_commit() can call
"format_trailers()"!

Update the comment in <trailer.h> to remove the (now obsolete) caveats
about format_trailers_from_commit(). Those caveats come from
a388b10fc1 (pretty: move trailer formatting to trailer.c, 2017-08-15)
where it says:

    pretty: move trailer formatting to trailer.c

    The next commit will add many features to the %(trailer)
    placeholder in pretty.c. We'll need to access some internal
    functions of trailer.c for that, so our options are either:

      1. expose those functions publicly

    or

      2. make an entry point into trailer.c to do the formatting

    Doing (2) ends up exposing less surface area, though do note
    that caveats in the docstring of the new function.

which suggests format_trailers_from_commit() started out from pretty.c
and did not have access to all of the trailer implementation internals,
and was never intended to replace (unify) the formatting machinery in
trailer.c. The refactors leading up to this commit (as well as
additional refactors that will follow) expose additional functions
publicly, and is therefore choosing option (1) as described in
a388b10fc1.

Signed-off-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agotrailer: begin formatting unification
Linus Arver [Fri, 15 Mar 2024 06:55:04 +0000 (06:55 +0000)]
trailer: begin formatting unification

Now that the preparatory refactors are over, we can replace the call to
format_trailers() in interpret-trailers with format_trailer_info(). This
unifies the trailer formatting machinery

In order to avoid breakages in t7502 and t7513, we have to steal the
features present in format_trailers(). Namely, we have to teach
format_trailer_info() as follows:

  (1) make it aware of opts->trim_empty, and

  (2) make it avoid hardcoding ": " as the separator and space (which
  can result in double-printing these characters).

For (2), make it only print the separator and space if we cannot find
any recognized separator somewhere in the key (yes, keys may have a
trailing separator in it --- we will eventually fix this design but not
now). Do so by copying the code out of print_tok_val(), and deleting the
same function.

Helped-by: Junio C Hamano <redacted>
Helped-by: Christian Couder <redacted>
Signed-off-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoformat_trailer_info(): append newline for non-trailer lines
Linus Arver [Fri, 15 Mar 2024 06:55:03 +0000 (06:55 +0000)]
format_trailer_info(): append newline for non-trailer lines

This wraps up the preparatory refactors to unify the trailer formatters.

Two patches ago we made format_trailer_info() use trailer_item objects
instead of the "trailers" string array. The strings in the array
include trailing newlines, because the string array is split up with

    trailer_lines = strbuf_split_buf(str + trailer_block_start,
                                     end_of_log_message - trailer_block_start,
                                     '\n',
                                     0);

in trailer_info_get() and strbuf_split_buf() includes the terminator (in
this case the newline character '\n') for each split-up substring.

And before we made the transition to use trailer_item objects for it,
format_trailer_info() called parse_trailer() (which trims newlines) for
trailer lines but did _not_ call parse_trailer() for non-trailer lines.
So for trailer lines it had to add back the trimmed newline like this

    if (!opts->separator)
        strbuf_addch(out, '\n');

But for non-trailer lines it didn't have to add back the newline because
it could just reuse same string in the "trailers" string array (which
again, already included the trailing newline).

Now that format_trailer_info() uses trailer_item objects for all cases,
it can't rely on "trailers" string array anymore.  And so it must be
taught to add a newline back when printing non-trailer lines, just like
it already does for trailer lines. Do so now.

The test suite can pass again without the need to hide failures
with *_failure, so flip the affected test cases back to *_success. Now,
format_trailer_info() is in better shape to supersede format_trailers(),
which we'll do in the next commit.

Signed-off-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoformat_trailer_info(): drop redundant unfold_value()
Linus Arver [Fri, 15 Mar 2024 06:55:02 +0000 (06:55 +0000)]
format_trailer_info(): drop redundant unfold_value()

This is another preparatory refactor to unify the trailer formatters.

In the last patch we made format_trailer_info() use trailer_item objects
instead of the "trailers" string array. This means that the call to
unfold_value() here is redundant because the trailer_item objects are
already unfolded in parse_trailers() which is a dependency of our
caller, format_trailers_from_commit().

Remove the redundant call.

Signed-off-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoformat_trailer_info(): use trailer_item objects
Linus Arver [Fri, 15 Mar 2024 06:55:01 +0000 (06:55 +0000)]
format_trailer_info(): use trailer_item objects

This is another preparatory refactor to unify the trailer formatters.

Make format_trailer_info() operate on trailer_item objects, not the raw
string array.

We will continue to make improvements, culminating in the renaming of
format_trailer_info() to format_trailers(), at which point the
unification of these formatters will be complete.

In order to avoid breaking t4205 and t6300, flip *_success to *_failure
in the affected test cases. Add a temporary
"test_trailer_option_expect_failure" wrapper which we will use along
with "test_expect_failure" in the next commit to avoid breaking tests.
When the dust settles with the refactors a few more commits later, we
will drop the use of *_failure to make the tests truly pass again.

When the preparatory refactors are complete,
we'll be able to drop the use of *_failure that we introduce here.

Signed-off-by: Linus Arver <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot5300: fix test_with_bad_commit()
John Cai [Fri, 15 Mar 2024 04:57:26 +0000 (04:57 +0000)]
t5300: fix test_with_bad_commit()

0f8edf7317 (index-pack: --fsck-objects to take an optional argument for
fsck msgs, 2024-02-01) added a test function test_with_bad_commit() that
contained two bugs. test_expect_fail was used instead of test_must_fail,
and a && was not included at the end of the line.

Fix these two issues in the test.

Signed-off-by: John Cai <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agodiff: add diff.srcPrefix and diff.dstPrefix configuration variables
Peter Hutterer [Fri, 15 Mar 2024 01:03:10 +0000 (11:03 +1000)]
diff: add diff.srcPrefix and diff.dstPrefix configuration variables

Allow the default prefixes "a/" and "b/" to be tweaked by the
diff.srcPrefix and diff.dstPrefix configuration variables.

Signed-off-by: Peter Hutterer <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoThe seventh batch
Junio C Hamano [Thu, 14 Mar 2024 21:03:22 +0000 (14:03 -0700)]
The seventh batch

Signed-off-by: Junio C Hamano <redacted>
2 years agoMerge branch 'rj/complete-worktree-paths-fix'
Junio C Hamano [Thu, 14 Mar 2024 21:05:25 +0000 (14:05 -0700)]
Merge branch 'rj/complete-worktree-paths-fix'

The logic to complete the command line arguments to "git worktree"
subcommand (in contrib/) has been updated to correctly honor things
like "git -C dir" etc.

* rj/complete-worktree-paths-fix:
  completion: fix __git_complete_worktree_paths

2 years agoMerge branch 'rj/complete-reflog'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)]
Merge branch 'rj/complete-reflog'

The command line completion script (in contrib/) learned to
complete "git reflog" better.

* rj/complete-reflog:
  completion: reflog subcommands and options
  completion: factor out __git_resolve_builtins
  completion: introduce __git_find_subcommand
  completion: reflog show <log-options>
  completion: reflog with implicit "show"

2 years agoMerge branch 'jc/test-i18ngrep'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)]
Merge branch 'jc/test-i18ngrep'

With release 2.44 we got rid of all uses of test_i18ngrep and there
is no in-flight topic that adds a new use of it.  Make a call to
test_i18ngrep a hard failure, so that we can remove it at the end
of this release cycle.

* jc/test-i18ngrep:
  test_i18ngrep: hard deprecate and forbid its use

2 years agoMerge branch 'gt/core-bare-in-templates'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)]
Merge branch 'gt/core-bare-in-templates'

Code simplification.

* gt/core-bare-in-templates:
  setup: remove unnecessary variable

2 years agoMerge branch 'la/trailer-api'
Junio C Hamano [Thu, 14 Mar 2024 21:05:24 +0000 (14:05 -0700)]
Merge branch 'la/trailer-api'

Trailer API updates.

Acked-by: Christian Couder <redacted>
cf. <redacted>

* la/trailer-api:
  format_trailers_from_commit(): indirectly call trailer_info_get()
  format_trailer_info(): move "fast path" to caller
  format_trailers(): use strbuf instead of FILE
  trailer_info_get(): reorder parameters
  trailer: move interpret_trailers() to interpret-trailers.c
  trailer: reorder format_trailers_from_commit() parameters
  trailer: rename functions to use 'trailer'
  shortlog: add test for de-duplicating folded trailers
  trailer: free trailer_info _after_ all related usage

2 years agoMerge branch 'kh/doc-commentchar-is-a-byte'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)]
Merge branch 'kh/doc-commentchar-is-a-byte'

The "core.commentChar" configuration variable only allows an ASCII
character, which was not clearly documented, which has been
corrected.

* kh/doc-commentchar-is-a-byte:
  config: document `core.commentChar` as ASCII-only

2 years agoMerge branch 'jh/fsmonitor-icase-corner-case-fix'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)]
Merge branch 'jh/fsmonitor-icase-corner-case-fix'

FSMonitor client code was confused when FSEvents were given in a
different case on a case-insensitive filesystem, which has been
corrected.

Acked-by: Patrick Steinhardt <redacted>
cf. <redacted>

* jh/fsmonitor-icase-corner-case-fix:
  fsmonitor: support case-insensitive events
  fsmonitor: refactor bit invalidation in refresh callback
  fsmonitor: trace the new invalidated cache-entry count
  fsmonitor: return invalidated cache-entry count on non-directory event
  fsmonitor: remove custom loop from non-directory path handler
  fsmonitor: return invalidated cache-entry count on directory event
  fsmonitor: move untracked-cache invalidation into helper functions
  fsmonitor: refactor untracked-cache invalidation
  dir: create untracked_cache_invalidate_trimmed_path()
  fsmonitor: refactor refresh callback for non-directory events
  fsmonitor: clarify handling of directory events in callback helper
  fsmonitor: refactor refresh callback on directory events
  t7527: add case-insensitve test for FSMonitor
  name-hash: add index_dir_find()

2 years agoMerge branch 'ps/reftable-iteration-perf-part2'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)]
Merge branch 'ps/reftable-iteration-perf-part2'

The code to iterate over refs with the reftable backend has seen
some optimization.

* ps/reftable-iteration-perf-part2:
  refs/reftable: precompute prefix length
  reftable: allow inlining of a few functions
  reftable/record: decode keys in place
  reftable/record: reuse refname when copying
  reftable/record: reuse refname when decoding
  reftable/merged: avoid duplicate pqueue emptiness check
  reftable/merged: circumvent pqueue with single subiter
  reftable/merged: handle subiter cleanup on close only
  reftable/merged: remove unnecessary null check for subiters
  reftable/merged: make subiters own their records
  reftable/merged: advance subiter on subsequent iteration
  reftable/merged: make `merged_iter` structure private
  reftable/pq: use `size_t` to track iterator index

2 years agoMerge branch 'so/clean-dry-run-without-force'
Junio C Hamano [Thu, 14 Mar 2024 21:05:23 +0000 (14:05 -0700)]
Merge branch 'so/clean-dry-run-without-force'

The implementation in "git clean" that makes "-n" and "-i" ignore
clean.requireForce has been simplified, together with the
documentation.

* so/clean-dry-run-without-force:
  clean: further clean-up of implementation around "--force"
  clean: improve -n and -f implementation and documentation

2 years agocheckout: plug some leaks in git-restore
Rubén Justo [Thu, 14 Mar 2024 18:08:58 +0000 (19:08 +0100)]
checkout: plug some leaks in git-restore

In git-restore we need to free the pathspec and pathspec_from_file
values from the struct checkout_opts.

A simple fix could be to free them in cmd_restore, after the call to
checkout_main returns, like we are doing [1][2] in the sibling function
cmd_checkout.

However, we can do even better.

We have git-switch and git-restore, both of them spin-offs[3][4] of
git-checkout.  All three are implemented as thin wrappers around
checkout_main.  Considering this, it makes a lot of sense to do the
cleanup closer to checkout_main.

Move the cleanups, including the new_branch_info variable, to
checkout_main.

As a consequence, mark: t2070, t2071, t2072 and t6418 as leak-free.

 [1] 9081a421a6 (checkout: fix "branch info" memory leaks, 2021-11-16)

 [2] 7ce4088ab7 (parse-options: consistently allocate memory in
     fix_filename(), 2023-03-04)

 [3] d787d311db (checkout: split part of it to new command 'switch',
     2019-03-29)

 [4] 46e91b663b (checkout: split part of it to new command 'restore',
     2019-04-25)

Signed-off-by: Rubén Justo <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agocheckout: fix interaction between --conflict and --merge
Phillip Wood [Thu, 14 Mar 2024 17:05:07 +0000 (17:05 +0000)]
checkout: fix interaction between --conflict and --merge

When using "git checkout" to recreate merge conflicts or merge
uncommitted changes when switching branch "--conflict" sensibly implies
"--merge". Unfortunately the way this is implemented means that "git
checkout --conflict=diff3 --no-merge" implies "--merge" violating the
usual last-one-wins rule. Fix this by only overriding the value of
opts->merge if "--conflicts" comes after "--no-merge" or "-[-no]-merge"
is not given on the command line.

The behavior of "git checkout --merge --no-conflict" is unchanged and
will still merge on the basis that the "-[-no]-conflict" options are
primarily intended to affect the conflict style and so "--no-conflict"
should cancel a previous "--conflict" but not override "--merge".

Of the four new tests the second one tests the behavior change
introduced by this commit, the other three check that this commit does
not regress the existing behavior.

Signed-off-by: Phillip Wood <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agocheckout: cleanup --conflict=<style> parsing
Phillip Wood [Thu, 14 Mar 2024 17:05:06 +0000 (17:05 +0000)]
checkout: cleanup --conflict=<style> parsing

Passing an invalid conflict style name such as "--conflict=bad" gives
the error message

    error: unknown style 'bad' given for 'merge.conflictstyle'

which is unfortunate as it talks about a config setting rather than
the option given on the command line. This happens because the
implementation calls git_xmerge_config() to set the conflict style
using the value given on the command line. Use the newly added
parse_conflict_style_name() instead and pass the value down the call
chain to override the config setting. This also means we can avoid
setting up a struct config_context required for calling
git_xmerge_config().

The option is now parsed in a callback to avoid having to store the
option name. This is a change in behavior as now

    git checkout --conflict=bad --conflict=diff3

will error out when parsing "--conflict=bad" whereas before this change
it would succeed because it would only try to parse the value of the
last "--conflict" option given on the command line.

Signed-off-by: Phillip Wood <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agomerge options: add a conflict style member
Phillip Wood [Thu, 14 Mar 2024 17:05:05 +0000 (17:05 +0000)]
merge options: add a conflict style member

Add a conflict_style member to `struct merge_options` and `struct
ll_merge_options` to allow callers to override the default conflict
style. This will be used in the next commit.

Signed-off-by: Phillip Wood <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agomerge-ll: introduce LL_MERGE_OPTIONS_INIT
Phillip Wood [Thu, 14 Mar 2024 17:05:04 +0000 (17:05 +0000)]
merge-ll: introduce LL_MERGE_OPTIONS_INIT

Introduce a macro to initialize `struct ll_merge_options` in preparation
for the next commit that will add a new member that needs to be
initialized to a non-zero value.

Signed-off-by: Phillip Wood <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoxdiff-interface: refactor parsing of merge.conflictstyle
Phillip Wood [Thu, 14 Mar 2024 17:05:03 +0000 (17:05 +0000)]
xdiff-interface: refactor parsing of merge.conflictstyle

Factor out the code that parses of conflict style name so it can be
reused in a later commit that wants to parse the name given on the
command line.

Signed-off-by: Phillip Wood <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot0006: add more tests with a negative TZ offset
Beat Bolli [Thu, 14 Mar 2024 08:55:12 +0000 (09:55 +0100)]
t0006: add more tests with a negative TZ offset

This test doesn't systematically check a negative timezone offset. Add a
test for each format that outputs the offset to improve our test
coverage.

Signed-off-by: Beat Bolli <redacted>
2 years agodate: make "iso-strict" conforming for the UTC timezone
Beat Bolli [Wed, 13 Mar 2024 22:54:23 +0000 (23:54 +0100)]
date: make "iso-strict" conforming for the UTC timezone

ISO 8601-1:2020-12 specifies that a zero timezone offset must be denoted
with a "Z" suffix instead of the numeric "+00:00". Add the correponding
special case to show_date() and a new test.

Changing an established output format which might be depended on by
scripts is always problematic, but here we choose to adhere more closely
to the published standard.

Reported-by: Michael Osipov <redacted>
Signed-off-by: Beat Bolli <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostatus: allow --untracked=false and friends
Junio C Hamano [Wed, 13 Mar 2024 17:32:14 +0000 (10:32 -0700)]
status: allow --untracked=false and friends

It is natural to expect that the "--untracked" option and the
status.showuntrackedFiles configuration variable to take a Boolean
value ("do you want me to show untracked files?"), but the current
code takes nothing but "no" as "no, please do not show any".

Allow the usual Boolean values to be given, and treat 'true' as
"normal", and 'false' as "no".

Signed-off-by: Junio C Hamano <redacted>
2 years agostatus: unify parsing of --untracked= and status.showUntrackedFiles
Junio C Hamano [Wed, 13 Mar 2024 17:32:13 +0000 (10:32 -0700)]
status: unify parsing of --untracked= and status.showUntrackedFiles

There are two code paths that take a string and parse it to enum
untracked_status_type.  Introduce a helper function and use it.

As these two places handle an error differently, add an additional
invalid value to the enum, and have the caller of the helper handle
the error condition, instead of dying or emitting error message from
the helper.

Signed-off-by: Junio C Hamano <redacted>
2 years agodoc: status.showUntrackedFiles does not take "false"
Jonas Wunderlich [Tue, 12 Mar 2024 21:34:11 +0000 (21:34 +0000)]
doc: status.showUntrackedFiles does not take "false"

The `status.showUntrackedFiles` config option only accepts the
values "no", "normal" or "all", but not as this part of the man page
suggested "false".  While we are at it, camel-case the name of the
variable.

Signed-off-by: Jonas Wunderlich <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agot5601: exercise clones with "includeIf.*.onbranch"
Patrick Steinhardt [Tue, 12 Mar 2024 12:35:11 +0000 (13:35 +0100)]
t5601: exercise clones with "includeIf.*.onbranch"

It was reported that git-clone(1) started to fail in Git v2.44 when
cloning via HTTPS when the config contains an "includeIf.*.onbranch"
condition:

    $ git clone https://example.com/repo.git
    Cloning into 'repo'...
    BUG: refs.c:2083: reference backend is unknown
    error: git-remote-https died of signal 6

This regression was bisected to 0fcc285c5e (refs: refactor logic to look
up storage backends, 2023-12-29). This commit tightens the logic to look
up ref backends such that we now die when the backend has not yet been
detected by reading the gitconfig.

Now on its own, this commit wouldn't have caused the failure. But in
18c9cb7524 (builtin/clone: create the refdb with the correct object
format, 2023-12-12) we have also changed how git-clone(1) initializes
the refdb such that it happens after the remote helper is spawned, which
is required so that we can first learn about the object format used by
the remote repository before initializing the refdb. Starting with this
change, the remote helper will be unable to detect the repository right
from the start and thus have an unconfigured ref backend. Consequently,
when we try to resolve the "includeIf.*.onbranch" condition, we will now
fail to look up the refdb and die.

This regression has already been fixed via 199f44cb2e (builtin/clone:
allow remote helpers to detect repo, 2024-02-27), where we now
pre-initialize a partial refdb so that the remote helper can detect the
repository right from the start. But it's clear that we're lacking test
coverage of this functionality.

Add a test to avoid regressing in the future. Note that this test stops
short of defining the desired behaviour for the "onbranch" condition
during a clone. It's not quite clear how exactly it should behave, so
this is a leftover bit for the future.

Reported-by: Angelo Dureghello <redacted>
Signed-off-by: Patrick Steinhardt <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoDocumentation/user-manual.txt: example for generating object hashes
Dirk Gouders [Tue, 12 Mar 2024 10:41:56 +0000 (11:41 +0100)]
Documentation/user-manual.txt: example for generating object hashes

Add a simple example on how object hashes can be generated manually.

Further, because the document suggests to have a look at the initial
commit, clarify that some details changed since that time.

Signed-off-by: Dirk Gouders <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoconfig: allow multi-byte core.commentChar
Jeff King [Tue, 12 Mar 2024 09:17:50 +0000 (05:17 -0400)]
config: allow multi-byte core.commentChar

Now that all of the code handles multi-byte comment characters, it's
safe to allow users to set them.

There is one special case I kept: we still will not allow an empty
string for the commentChar. While it might make sense in some contexts
(e.g., output where you don't want any comment prefix), there are plenty
where it will behave badly (e.g., all of our starts_with() checks will
indicate that every line is a comment!). It might be reasonable to
assign some meaningful semantics, but it would probably involve checking
how each site behaves. In the interim let's forbid it and we can loosen
things later.

Likewise, the "commentChar cannot be a newline" rule is now extended to
"it cannot contain a newline" (for the same reason: it can confuse our
parsing loops).

Since comment_line_str is used in many parts of the code, it's hard to
cover all possibilities with tests. We can convert the existing
double-semicolon prefix test to show that "git status" works. And we'll
give it a more challenging case in t7507, where we confirm that
git-commit strips out the commit template along with any --verbose text
when reading the edited commit message back in. That covers the basics,
though it's possible there could be issues in more exotic spots (e.g.,
the sequencer todo list uses its own code).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoenvironment: drop comment_line_char compatibility macro
Jeff King [Tue, 12 Mar 2024 09:17:47 +0000 (05:17 -0400)]
environment: drop comment_line_char compatibility macro

There is no longer any code which references the single-byte
comment_line_char. Let's drop it, clearing the way for true multi-byte
entries in comment_line_str.

It's possible there are topics in flight that have added new references
to comment_line_char. But we would prefer to fail compilation (and then
fix it) upon merging with this, rather than have them quietly ignore the
bytes after the first.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agowt-status: drop custom comment-char stringification
Jeff King [Tue, 12 Mar 2024 09:17:45 +0000 (05:17 -0400)]
wt-status: drop custom comment-char stringification

In wt_longstatus_print_tracking() we may conditionally show a comment
prefix based on the wt_status->display_comment_prefix flag. We handle
that by creating a local "comment_line_string" that is either the empty
string or the comment character followed by a space.

For a single-byte comment, the maximum length of this string is 2 (plus
a NUL byte). But to handle multi-byte comment characters, it can be
arbitrarily large. One way to handle this is to just call
xstrfmt("%s ", comment_line_str), and then free it when we're done.

But we can simplify things further by just conditionally switching
between our prefix string and an empty string when formatting. We
couldn't just do that with the previous code, because the comment
character was a single byte. There's no way to have a "%c" format switch
between some character and "no character at all". Whereas with "%s" you
can switch between some string and the empty string. So now that we have
a comment string and not a comment char, we can just use it directly
when formatting. Do note that we have to also conditionally add the
trailing space at the same time.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agosequencer: handle multi-byte comment characters when writing todo list
Jeff King [Tue, 12 Mar 2024 09:17:42 +0000 (05:17 -0400)]
sequencer: handle multi-byte comment characters when writing todo list

We already match multi-byte comment characters in parse_insn_line(),
thanks to the previous commit, yielding a TODO_COMMENT entry. But in
todo_list_to_strbuf(), we may call command_to_char() to convert that
back into something we can output.

We can't just return comment_line_char anymore, since it may require
multiple bytes. Instead, we'll return "0" for this case, which is the
same thing we'd return for a command which does not have a single-letter
abbreviation (e.g., "revert" or "noop"). There is only a single caller
of command_to_char(), and upon seeing "0" it falls back to outputting
the full name via command_to_string(). So we can handle TODO_COMMENT
there, returning the full string.

Note that there are many other callers of command_to_string(), which
will now behave differently if they pass TODO_COMMENT. But we would not
expect that to happen; prior to this commit, the function just calls
die() in this case. And looking at those callers, that makes sense;
e.g., do_pick_commit() will only be called when servicing a pick
command, and should never be called for a comment in the first place.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agofind multi-byte comment chars in unterminated buffers
Jeff King [Tue, 12 Mar 2024 09:17:39 +0000 (05:17 -0400)]
find multi-byte comment chars in unterminated buffers

As with the previous patch, we need to swap out single-byte matching for
something like starts_with() to match all bytes of a multi-byte comment
character. But for cases where the buffer is not NUL-terminated (and we
instead have an explicit size or end pointer), it's not safe to use
starts_with(), as it might walk off the end of the buffer.

Let's introduce a new starts_with_mem() that does the same thing but
also accepts the length of the "haystack" str and makes sure not to walk
past it.

Note that in most cases the existing code did not need a length check at
all, since it was written in a way that knew we had at least one byte
available (and that was all we checked). So I had to read each one to
find the appropriate bounds. The one exception is sequencer.c's
add_commented_lines(), where we can actually get rid of the length
check. Just like starts_with(), our starts_with_mem() handles an empty
haystack variable by not matching (assuming a non-empty prefix).

A few notes on the implementation of starts_with_mem():

  - it would be equally correct to take an "end" pointer (and indeed,
    many of the callers have this and have to subtract to come up with
    the length). I think taking a ptr/size combo is a more usual
    interface for our codebase, though, and has the added benefit that
    the function signature makes it harder to mix up the three
    parameters.

  - we could obviously build starts_with() on top of this by passing
    strlen(str) as the length. But it's possible that starts_with() is a
    relatively hot code path, and it should not pay that penalty (it can
    generally return an answer proportional to the size of the prefix,
    not the whole string).

  - it naively feels like xstrncmpz() should be able to do the same
    thing, but that's not quite true. If you pass the length of the
    haystack buffer, then strncmp() finds that a shorter prefix string
    is "less than" than the haystack, even if the haystack starts with
    the prefix. If you pass the length of the prefix, then you risk
    reading past the end of the haystack if it is shorter than the
    prefix. So I think we really do need a new function.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agofind multi-byte comment chars in NUL-terminated strings
Jeff King [Tue, 12 Mar 2024 09:17:37 +0000 (05:17 -0400)]
find multi-byte comment chars in NUL-terminated strings

Several parts of the code need to identify lines that begin with the
comment character, and do so with a simple byte equality check. As part
of the transition to handling multi-byte characters, we need to match
all of the bytes. For cases where we are looking in a NUL-terminated
string, we can just use starts_with(), which checks all of the
characters in comment_line_str.

Note that we can drop the "line.len" check in wt-status.c's
read_rebase_todolist(). The starts_with() function handles the case of
an empty haystack buffer (it will always return false for a non-empty
prefix).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoprefer comment_line_str to comment_line_char for printing
Jeff King [Tue, 12 Mar 2024 09:17:34 +0000 (05:17 -0400)]
prefer comment_line_str to comment_line_char for printing

As part of our transition to multi-byte comment characters, we should
use the string variable rather than the historical character variable.
All of the sites adjusted here are just swapping out "%c" for "%s" in
format strings, or strbuf_addch() for strbuf_addstr(). The type system
and printf-attribute give the compiler enough information to make sure
our formats and variable changes all match (especially important for
cases where the format string is defined far away from its use, like
prepare_to_commit() in commit.c).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostrbuf: accept a comment string for strbuf_add_commented_lines()
Jeff King [Tue, 12 Mar 2024 09:17:32 +0000 (05:17 -0400)]
strbuf: accept a comment string for strbuf_add_commented_lines()

As part of our transition to multi-byte comment characters, let's take a
NUL-terminated string pointer for strbuf_add_commented_lines() rather
than a single character.

All of the callers have to be adjusted; most can just pass
comment_line_str rather than comment_line_char.

And now our "cheat" in strbuf_commented_addf() can go away, as we can
take the full string from it.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostrbuf: accept a comment string for strbuf_commented_addf()
Jeff King [Tue, 12 Mar 2024 09:17:29 +0000 (05:17 -0400)]
strbuf: accept a comment string for strbuf_commented_addf()

As part of our transition to multi-byte comment characters, let's take a
NUL-terminated string pointer for strbuf_commented_addf() rather than a
single character.

All of the callers have to be adjusted, but they can just pass
comment_line_str rather than comment_line_char.

Note that we rely on strbuf_add_commented_lines() under the hood, so
we'll cheat a bit to squeeze our string into a single character (for now
the two are equivalent, and we'll address this TODO in the next patch).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostrbuf: accept a comment string for strbuf_stripspace()
Jeff King [Tue, 12 Mar 2024 09:17:27 +0000 (05:17 -0400)]
strbuf: accept a comment string for strbuf_stripspace()

As part of our transition to multi-byte comment characters, let's take a
NUL-terminated string pointer for strbuf_stripspace(), rather than a
single character. We can continue to support its feature of ignoring
comments by accepting a NULL pointer (as opposed to the current behavior
of a NUL byte).

All of the callers have to be adjusted, but they can all just pass
comment_line_str (or NULL).

Inside the function we detect comments by comparing the first byte of a
line to the comment character. We'll adjust that to use starts_with(),
which will match multiple bytes (though for now, of course, we still
only allow a single byte, so it's academic).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agoenvironment: store comment_line_char as a string
Jeff King [Tue, 12 Mar 2024 09:17:24 +0000 (05:17 -0400)]
environment: store comment_line_char as a string

We'd like to eventually support multi-byte comment prefixes, but the
comment_line_char variable is referenced in many spots, making the
transition difficult.

Let's start by storing the character in a NUL-terminated string. That
will let us switch code over incrementally to the string format, and we
can easily support the existing code with a macro wrapper (since we'll
continue to allow only a single-byte prefix, this will behave
identically).

Once all references to the "char" variable have been converted, we can
drop it and enable longer strings.

We'll still have to touch all of the spots that create or set the
variable in this patch, but there are only a few (reading the config,
and the "auto" character selector).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostrbuf: avoid shadowing global comment_line_char name
Jeff King [Tue, 12 Mar 2024 09:17:22 +0000 (05:17 -0400)]
strbuf: avoid shadowing global comment_line_char name

Several comment-related strbuf functions take a comment_line_char
parameter. There's also a global comment_line_char variable, which is
closely related (most callers pass it in as this parameter). Let's avoid
shadowing the global name. This makes it more obvious that we're not
using the global value, and it will be especially helpful as we refactor
the global in future patches (in particular, any macro trickery wouldn't
work because the preprocessor doesn't respect scope).

We'll use "comment_prefix". That should be descriptive enough, and as a
bonus is more neutral with respect to the "char" type (since we'll
eventually swap it out for a string).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agocommit: refactor base-case of adjust_comment_line_char()
Jeff King [Tue, 12 Mar 2024 09:17:19 +0000 (05:17 -0400)]
commit: refactor base-case of adjust_comment_line_char()

When core.commentChar is set to "auto", we check a set of candidate
characters against the proposed buffer to see which if any can be used
without ambiguity. But before we do that, we optimize for the common
case that the default "#" is fine by just seeing if it is present in the
buffer at all.

The way we do this is a bit subtle, though: we assign the candidate
character to comment_line_char preemptively, then check if it works, and
return if it does. The subtle part is that sometimes setting
comment_line_char is important (after we return, the important outcome
is the fact that we have set the variable) and sometimes it is useless
(if our optimization fails, we go on to do the more careful checks and
eventually assign something else instead).

To make it more clear what is happening (and to make further refactoring
of comment_line_char easier), let's check our candidate character
directly, and then assign as part of returning if it worked out.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
2 years agostrbuf: avoid static variables in strbuf_add_commented_lines()
Jeff King [Tue, 12 Mar 2024 09:17:15 +0000 (05:17 -0400)]
strbuf: avoid static variables in strbuf_add_commented_lines()

In strbuf_add_commented_lines(), we have to convert the single-byte
comment_line_char into a string to pass to add_lines(). We cache the
created string using a static-local variable. But this makes the
function non-reentrant, and it's doubtful that this provides any real
performance benefit given that we know the string always contains a
single character.

So let's just create it from scratch each time, and to give the compiler
the maximal opportunity to make it fast we'll ditch the over-complicated
xsnprintf() and just assign directly into the array.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
git clone https://git.99rst.org/PROJECT