]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
17 months agoMerge branch 'pw/wildmatch-fixes'
Junio C Hamano [Tue, 4 Apr 2023 21:28:27 +0000 (14:28 -0700)] 
Merge branch 'pw/wildmatch-fixes'

The wildmatch library code unlearns exponential behaviour it
acquired some time ago since it was borrowed from rsync.

* pw/wildmatch-fixes:
  t3070: make chain lint tester happy
  wildmatch: hide internal return values
  wildmatch: avoid undefined behavior
  wildmatch: fix exponential behavior

17 months agoThe sixth batch
Junio C Hamano [Sat, 1 Apr 2023 00:50:32 +0000 (17:50 -0700)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'ss/hashmap-typofix'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'ss/hashmap-typofix'

Typofix.

* ss/hashmap-typofix:
  hashmap.h: fix minor typo

17 months agoMerge branch 'ds/p2000-fix-grep-sparse'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'ds/p2000-fix-grep-sparse'

Fix perf test.

* ds/p2000-fix-grep-sparse:
  p2000: remove stray '--sparse' flag from test

17 months agoMerge branch 'kh/commentchar-config-error-message'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'kh/commentchar-config-error-message'

Doc update.

* kh/commentchar-config-error-message:
  config: tell the user that we expect an ASCII character

17 months agoMerge branch 'ab/retire-scripted-add-p'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'ab/retire-scripted-add-p'

Test fix.

* ab/retire-scripted-add-p:
  t3701: we don't need no Perl for `add -i` anymore

17 months agoMerge branch 'js/t5563-portability-fix'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'js/t5563-portability-fix'

Test portability fix.

* js/t5563-portability-fix:
  t5563: prevent "ambiguous redirect"

17 months agoMerge branch 'bb/unicode-width-table-15'
Junio C Hamano [Sat, 1 Apr 2023 00:50:23 +0000 (17:50 -0700)] 
Merge branch 'bb/unicode-width-table-15'

Update width table for the latest edition of Unicode.

* bb/unicode-width-table-15:
  unicode: update the width tables to Unicode 15

17 months agot5563: prevent "ambiguous redirect"
Johannes Schindelin [Fri, 31 Mar 2023 06:52:05 +0000 (06:52 +0000)] 
t5563: prevent "ambiguous redirect"

When I ran this test using `TEST_SHELL_PATH=/bin/bash` in my Ubuntu
setup (where Bash is at version 5.0.17(1)-release), I was greeted with
this error message:

./test-lib.sh: line 1072: $CHALLENGE: ambiguous redirect

This commit fixes that error by quoting the `CHALLENGE` variable (which
has as value a path containing spaces), and by avoiding to cuddle the
empty string parameter in the `printf` call with the redirect character
(in fact, the `printf ''>$CHALLENGE` is removed because the next line
overwrites the file anyway because it _also_ uses a single `>` to
redirect the output).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoThe fifth batch
Junio C Hamano [Thu, 30 Mar 2023 20:47:19 +0000 (13:47 -0700)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'mk/workaround-pcre-jit-ucp-bug'
Junio C Hamano [Thu, 30 Mar 2023 20:47:12 +0000 (13:47 -0700)] 
Merge branch 'mk/workaround-pcre-jit-ucp-bug'

A recent-ish change to allow unicode character classes to be used
with "grep -P" triggered a JIT bug in older pcre2 libraries.
The problematic change in Git built with these older libraries has
been disabled to work around the bug.

* mk/workaround-pcre-jit-ucp-bug:
  grep: work around UTF-8 related JIT bug in PCRE2 <= 10.34

17 months agoMerge branch 'jc/am-doc-refer-to-format-patch'
Junio C Hamano [Thu, 30 Mar 2023 20:47:12 +0000 (13:47 -0700)] 
Merge branch 'jc/am-doc-refer-to-format-patch'

Doc update.

* jc/am-doc-refer-to-format-patch:
  am: refer to format-patch in the documentation

17 months agoMerge branch 'sg/parse-options-h-initializers'
Junio C Hamano [Thu, 30 Mar 2023 20:47:11 +0000 (13:47 -0700)] 
Merge branch 'sg/parse-options-h-initializers'

Code clean-up to use designated initializers in parse-options API.

* sg/parse-options-h-initializers:
  parse-options.h: use designated initializers in OPT_* macros
  parse-options.h: rename _OPT_CONTAINS_OR_WITH()'s parameters
  parse-options.h: use consistent name for the callback parameters

17 months agoMerge branch 'sg/parse-options-h-users'
Junio C Hamano [Thu, 30 Mar 2023 20:47:11 +0000 (13:47 -0700)] 
Merge branch 'sg/parse-options-h-users'

Code clean-up to include and/or uninclude parse-options.h file as
needed.

* sg/parse-options-h-users:
  treewide: remove unnecessary inclusions of parse-options.h from headers
  treewide: include parse-options.h in source files

17 months agounicode: update the width tables to Unicode 15
Beat Bolli [Thu, 30 Mar 2023 19:15:17 +0000 (21:15 +0200)] 
unicode: update the width tables to Unicode 15

Unicode version 15 was released in September 2022 [1], and we have so
far neglected to update our width tables. Do this now.

[1] http://blog.unicode.org/2022/09/announcing-unicode-standard-version-150.html

Signed-off-by: Beat Bolli <dev+git@drbeat.li>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agohashmap.h: fix minor typo
Siddharth Singh [Thu, 30 Mar 2023 15:28:03 +0000 (15:28 +0000)] 
hashmap.h: fix minor typo

The word "no" should be "not".

Signed-off-by: Siddharth Singh <siddhartth@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agop2000: remove stray '--sparse' flag from test
Derrick Stolee [Tue, 28 Mar 2023 20:09:22 +0000 (20:09 +0000)] 
p2000: remove stray '--sparse' flag from test

This argument was added in 7cae7627c45 (builtin/grep.c: integrate with
sparse index, 2022-09-22), but it was a carry-over from an earlier
version where the --sparse flag was added to the 'git grep' builtin.
This argument does not exist, so currently the
p2000-sparse-operations.sh performance test script fails when reaching
this step.

With this fix, the script works with these numbers for my copy of the
Git source code repository:

Test                                         HEAD
------------------------------------------------------------
2000.30: git grep --cached ... (full-v3)     0.34(1.20+0.14)
2000.31: git grep --cached ... (full-v4)     0.31(1.15+0.13)
2000.32: git grep --cached ... (sparse-v3)   0.26(1.13+0.12)
2000.33: git grep --cached ... (sparse-v4)   0.27(1.13+0.12)

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoThe fourth batch
Junio C Hamano [Tue, 28 Mar 2023 17:49:52 +0000 (10:49 -0700)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoMerge branch 'fc/docbook-remove-groff-workaround'
Junio C Hamano [Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)] 
Merge branch 'fc/docbook-remove-groff-workaround'

Remove workaround for ancient versions of DocBook to make it work
correctly with groff, which has not been necessary since docbook
1.76 from 2010.

* fc/docbook-remove-groff-workaround:
  doc: remove GNU troff workaround

17 months agoMerge branch 'pe/time-use-gettimeofday'
Junio C Hamano [Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)] 
Merge branch 'pe/time-use-gettimeofday'

time(2) on glib 2.31+, especially on Linux, goes out of sync with
higher resolution timers used for gettimeofday(2) and by the
filesystem.  Replace all calls to it with a git_time() wrapper and
use gettimeofday(2) in its implementation.

* pe/time-use-gettimeofday:
  git-compat-util: use gettimeofday(2) for time(2)

17 months agoMerge branch 'jk/fix-proto-downgrade-to-v0'
Junio C Hamano [Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)] 
Merge branch 'jk/fix-proto-downgrade-to-v0'

Transports that do not support protocol v2 did not correctly fall
back to protocol v0 under certain conditions, which has been
corrected.

* jk/fix-proto-downgrade-to-v0:
  git_connect(): fix corner cases in downgrading v2 to v0

17 months agoMerge branch 'fc/oid-quietly-parse-upstream'
Junio C Hamano [Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)] 
Merge branch 'fc/oid-quietly-parse-upstream'

"git rev-parse --quiet foo@{u}", or anything that asks @{u} to be
parsed with GET_OID_QUIETLY option, did not quietly fail, which has
been corrected.

* fc/oid-quietly-parse-upstream:
  object-name: fix quiet @{u} parsing

17 months agoMerge branch 'fc/completion-colors-do-not-need-prompt-command'
Junio C Hamano [Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)] 
Merge branch 'fc/completion-colors-do-not-need-prompt-command'

Lift the limitation that colored prompts can only be used with
PROMPT_COMMAND mode.

* fc/completion-colors-do-not-need-prompt-command:
  completion: prompt: use generic colors

17 months agot3070: make chain lint tester happy
Michael J Gruber [Fri, 24 Mar 2023 22:17:11 +0000 (23:17 +0100)] 
t3070: make chain lint tester happy

1f2e05f0b7 ("wildmatch: fix exponential behavior", 2023-03-20)
introduced a new test with a background process. Backgrounding
necessarily gives a result of 0, so that a seemingly broken && chain is
not really broken.

Adjust t3070 slightly so that our chain lint test recognizes the
construct for what it is and does not raise a false positive.

Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoconfig: tell the user that we expect an ASCII character
Kristoffer Haugsbakk [Mon, 27 Mar 2023 19:43:44 +0000 (21:43 +0200)] 
config: tell the user that we expect an ASCII character

Commit 50b54fd72a (config: be strict on core.commentChar, 2014-05-17)
notes that “multi-byte character encoding could also be misinterpreted”,
and indeed a multi-byte codepoint (non-ASCII) is not accepted as a valid
`core.commentChar`.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agot3701: we don't need no Perl for `add -i` anymore
Johannes Schindelin [Mon, 27 Mar 2023 06:36:36 +0000 (06:36 +0000)] 
t3701: we don't need no Perl for `add -i` anymore

This should have been removed in `ab/retire-scripted-add-p` but wasn't.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agogrep: work around UTF-8 related JIT bug in PCRE2 <= 10.34
Mathias Krause [Thu, 23 Mar 2023 17:25:39 +0000 (18:25 +0100)] 
grep: work around UTF-8 related JIT bug in PCRE2 <= 10.34

Stephane is reporting[1] a regression introduced in git v2.40.0 that leads
to 'git grep' segfaulting in his CI pipeline. It turns out, he's using an
older version of libpcre2 that triggers a wild pointer dereference in
the generated JIT code that was fixed in PCRE2 10.35.

Instead of completely disabling the JIT compiler for the buggy version,
just mask out the Unicode property handling as we used to do prior to
commit acabd2048ee0 ("grep: correctly identify utf-8 characters with
\{b,w} in -P").

[1] https://lore.kernel.org/git/7E83DAA1-F9A9-4151-8D07-D80EA6D59EEA@clumio.com/

Reported-by: Stephane Odul <stephane@clumio.com>
Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoThe third batch
Junio C Hamano [Tue, 21 Mar 2023 21:19:03 +0000 (14:19 -0700)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'fc/test-aggregation-clean-up'
Junio C Hamano [Tue, 21 Mar 2023 21:18:56 +0000 (14:18 -0700)] 
Merge branch 'fc/test-aggregation-clean-up'

Code clean-up for test framework.

* fc/test-aggregation-clean-up:
  test: don't print aggregate-results command
  test: simplify counts aggregation

18 months agoMerge branch 'ps/receive-pack-unlock-before-die'
Junio C Hamano [Tue, 21 Mar 2023 21:18:55 +0000 (14:18 -0700)] 
Merge branch 'ps/receive-pack-unlock-before-die'

"git receive-pack" that responds to "git push" requests failed to
clean a stale lockfile when killed in the middle, which has been
corrected.

* ps/receive-pack-unlock-before-die:
  receive-pack: fix stale packfile locks when dying

18 months agoMerge branch 'aj/ls-files-format-fix'
Junio C Hamano [Tue, 21 Mar 2023 21:18:55 +0000 (14:18 -0700)] 
Merge branch 'aj/ls-files-format-fix'

Fix for a "ls-files --format="%(path)" that produced nonsense
output, which was a bug in 2.38.

* aj/ls-files-format-fix:
  ls-files: fix "--format" output of relative paths

18 months agoMerge branch 'jk/format-patch-ignore-noprefix'
Junio C Hamano [Tue, 21 Mar 2023 21:18:55 +0000 (14:18 -0700)] 
Merge branch 'jk/format-patch-ignore-noprefix'

"git format-patch" honors the src/dst prefixes set to nonstandard
values with configuration variables like "diff.noprefix", causing
receiving end of the patch that expects the standard -p1 format to
break.  Teach "format-patch" to ignore end-user configuration and
always use the standard prefixes.

This is a backward compatibility breaking change.

* jk/format-patch-ignore-noprefix:
  rebase: prefer --default-prefix to --{src,dst}-prefix for format-patch
  format-patch: add format.noprefix option
  format-patch: do not respect diff.noprefix
  diff: add --default-prefix option
  t4013: add tests for diff prefix options
  diff: factor out src/dst prefix setup

18 months agoam: refer to format-patch in the documentation
Junio C Hamano [Tue, 21 Mar 2023 17:27:08 +0000 (10:27 -0700)] 
am: refer to format-patch in the documentation

There were two reasons we didn't do this.  As "git am" is designed
to grok e-mailed patches, not necessarily taken out of a Git
repostiory or even if it came from a Git repository not necessarily
produced with format-patch, we didn't want to single it out as the
"blessed" input producer to the command.  Also, in the original
workflow that "git am" was invented for, the user of "am" was
expected to be a different person than the users of "format-patch".

But this is a very safe change to make in 2023.  Thanks to the
effort by many contributors, Git ended up becoming a bit more
popular than we initially thought it would be, and "format-patch",
which took me a few weeks to pursuade Linus to take in 2005, seems
to have become the de-facto standard tool to produce patch e-mails.

Interestingly, the documentation for "git apply", which is listed in
SEE ALSO section of "git am" documentation, does mention "am" and
"format-patch" as two things that are related but different from
"apply" in an early part.

Suggested-by: Kai Grossjohann <kai.grossjohann@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agodoc: remove GNU troff workaround
Felipe Contreras [Mon, 20 Mar 2023 19:00:47 +0000 (13:00 -0600)] 
doc: remove GNU troff workaround

In 2007 the docbook project made the mistake of converting ' to \' for
man pages [1]. It's a problem because groff interprets \' as acute
accent which is rendered as ' in ASCII, but as ´ in utf-8.

This started a cascade of bug reports in git [2], debian [3], Arch Linux
[4], docbook itself [5], and probably many others.

A solution was to use the correct groff character: \(aq, which is always
rendered as ', but the problem is that such character doesn't work in
other troff programs.

A portable solution required the use of a conditional character that is
\(aq in groff, but ' in all others:

  .ie \n(.g .ds Aq \(aq
  .el .ds Aq '

The proper solution took time to be implemented in docbook, but in 2010
they did it [6]. So the docbook man page stylesheets were broken from
1.73 to 1.76.

Unfortunately by that point many workarounds already existed. In the
case of git, GNU_ROFF was introduced, and in the case of Arch Linux
a mapping from \' to ' was added to groff's man.local. Other
distributions might have done the same, or similar workarounds.

Since 2010 there is no need for this workaround, which is fixed
elsewhere, not just in docbook, but other layers as well.

Let's remove it.

[1] https://github.com/docbook/xslt10-stylesheets/commit/ea2a0bac56c56eec1892ac3d9254dca89f7c5746
[2] https://lore.kernel.org/git/20091012102926.GA3937@debian.b2j/
[3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=507673#65
[4] https://bugs.archlinux.org/task/9643
[5] https://sourceforge.net/p/docbook/bugs/1022/
[6] https://github.com/docbook/xslt10-stylesheets/commit/fb553434265906ed81edc6d5f533d0b08d200046

Inspired-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agogit-compat-util: use gettimeofday(2) for time(2)
Paul Eggert [Mon, 20 Mar 2023 23:05:07 +0000 (16:05 -0700)] 
git-compat-util: use gettimeofday(2) for time(2)

Use gettimeofday instead of time(NULL) to get current time.
This avoids clock skew on glibc 2.31+ on Linux, where in the
first 1 to 2.5 ms of every second, time(NULL) returns a
value that is one less than the tv_sec part of
higher-resolution timestamps such as those returned by
gettimeofday or timespec_get, or those in the file system.
There are similar clock skew problems on AIX and MS-Windows,
which have problems in the first 5 ms of every second.

Without this patch, users can observe Git issuing a
timestamp T+1 before it issues timestamp T, because Git
sometimes uses time(NULL) or time(&t) and sometimes uses
higher-res methods like gettimeofday.  Although strictly
speaking users should tolerate this behavior because a
superuser can always change the clock back, this is a
quality of implementation issue and users naturally expect
Git to issue timestamps in increasing order unless the
superuser has fiddled with the system clock.

This patch always uses gettimeofday(...) instead of time(...),
and I have verified that the resulting .o files never refer
to the name 'time'.  A trickier patch would change only
those calls for which timestamp monotonicity is user-visible.
Such a patch would require more expertise about Git internals,
though, and would be harder to maintain later.

Another possibility would be to change Git's documentation
to warn users that Git does not always issue timestamps in
increasing order.  However, Git users would likely be either
dismayed by this possibility, or confused by the level of
detail that any such documentation would require.

Yet another possibility would be to fix the Linux kernel so
that the time syscall is consistent with the other timestamp
syscalls.  I suppose this has not been done due to
performance implications.  (Git's use of timestamps is rare
enough that performance is not a significant consideration
for git.)  However, this wouldn't fix Git's problem on older
Linux kernels, or on AIX or MS-Windows.

Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoparse-options.h: use designated initializers in OPT_* macros
SZEDER Gábor [Sun, 19 Mar 2023 16:56:48 +0000 (17:56 +0100)] 
parse-options.h: use designated initializers in OPT_* macros

Use designated initializers in the expansions of the OPT_* macros to
make it more readable which one-letter macro parameter initializes
which field in the resulting 'struct option'.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoparse-options.h: rename _OPT_CONTAINS_OR_WITH()'s parameters
SZEDER Gábor [Sun, 19 Mar 2023 16:56:47 +0000 (17:56 +0100)] 
parse-options.h: rename _OPT_CONTAINS_OR_WITH()'s parameters

Rename the 'help' parameter as it matches one of the fields in 'struct
option', and, while at it, rename all other parameters to the usual
one-letter name used in similar macro definitions.

Furthermore, put all parameters in the replacement list between
parentheses, like all other OPT_* macros do.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoparse-options.h: use consistent name for the callback parameters
SZEDER Gábor [Sun, 19 Mar 2023 16:56:46 +0000 (17:56 +0100)] 
parse-options.h: use consistent name for the callback parameters

In the various OPT_* macros the 'f' parameter is usually used to
specify flags, while the 'cb' parameter is used to specify a callback
function.  OPT_CALLBACK and OPT_NUMBER_CALLBACKS, however, are
inconsistent with the rest, as they use 'f' to specify their callback
function.

Rename their callback macro parameters to 'cb' to avoid the
inconsistency.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agotreewide: remove unnecessary inclusions of parse-options.h from headers
SZEDER Gábor [Sun, 19 Mar 2023 16:27:12 +0000 (17:27 +0100)] 
treewide: remove unnecessary inclusions of parse-options.h from headers

The headers 'diagnose.h', 'list-objects-filter-options.h',
'ref-filter.h' and 'remote.h' declare option parsing callback
functions with a 'struct option*' parameter, and 'revision.h' declares
an option parsing helper function taking 'struct parse_opt_ctx_t*' and
'struct option*' parameters.  These headers all include
'parse-options.h', although they don't need any of the type
definitions from that header file.  Furthermore,
'list-objects-filter-options.h' and 'ref-filter.h' also define some
OPT_* macros to initialize a 'struct option', but these don't
necessitate the inclusion of parse-options.h in these headers either,
because these macros are only expanded in source files.

Remove these unnecessary inclusions of parse-options.h and use forward
declarations to declare the necessary types.

After this patch none of the header files include parse-options.h
anymore.

With these changes, the build time after modifying only
parse-options.h is reduced by about 30%, and the number of targets
built is almost 20% less:

  Before:

    $ touch parse-options.h && time make -j4 |wc -l
    353

    real    1m1.527s
    user    3m32.205s
    sys     0m15.903s

  After:

    289

    real    0m39.285s
    user    2m12.540s
    sys     0m11.164s

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agotreewide: include parse-options.h in source files
SZEDER Gábor [Sun, 19 Mar 2023 16:27:11 +0000 (17:27 +0100)] 
treewide: include parse-options.h in source files

The builtins 'ls-remote', 'pack-objects', 'receive-pack', 'reflog' and
'send-pack' use parse_options(), but their source files don't directly
include 'parse-options.h'.  Furthermore, the source files
'diagnose.c', 'list-objects-filter-options.c', 'remote.c' and
'send-pack.c' define option parsing callback functions, while
'revision.c' defines an option parsing helper function, and thus need
access to various fields in 'struct option' and 'struct
parse_opt_ctx_t', but they don't directly include 'parse-options.h'
either.  They all can still be built, of course, because they include
one of the header files that does include 'parse-options.h' (though
unnecessarily, see the next commit).

Add those missing includes to these files, as our general rule is that
"a C file must directly include the header files that declare the
functions and the types it uses".

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agowildmatch: hide internal return values
Phillip Wood [Mon, 20 Mar 2023 16:10:02 +0000 (16:10 +0000)] 
wildmatch: hide internal return values

WM_ABORT_ALL and WM_ABORT_TO_STARSTAR are used internally to limit
backtracking when a match fails, they are not of interest to the caller
and so should not be public.

Suggested-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agowildmatch: avoid undefined behavior
Phillip Wood [Mon, 20 Mar 2023 16:10:01 +0000 (16:10 +0000)] 
wildmatch: avoid undefined behavior

The code changed in this commit is designed to check if the pattern
starts with "**/" or contains "/**/" (see 3a078dec33 (wildmatch: fix
"**" special case, 2013-01-01)). Unfortunately when the pattern begins
with "**/" `prev_p = p - 2` is evaluated when `p` points to the second
"*" and so the subtraction is undefined according to section 6.5.6 of
the C standard because the result does not point within the same object
as `p`. Fix this by avoiding the subtraction unless it is well defined.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agowildmatch: fix exponential behavior
Phillip Wood [Mon, 20 Mar 2023 16:10:00 +0000 (16:10 +0000)] 
wildmatch: fix exponential behavior

When dowild() cannot match a '*' or '/**/' wildcard then it must return
WM_ABORT_TO_STARSTAR or WM_ABORT_ALL respectively. Failure to observe
this results in unnecessary backtracking and the time taken for a failed
match increases exponentially with the number of wildcards in the
pattern [1]. Unfortunately in some instances dowild() returns WM_NOMATCH
for a failed match resulting in long match times for patterns containing
multiple wildcards as can be seen in the following benchmark.
(Note that the timings in the Benchmark 1 are really measuring the time
to execute test-tool rather than the time to match the pattern)

Benchmark 1: t/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a"
  Time (mean ± σ):      22.8 ms ±   1.7 ms    [User: 12.1 ms, System: 10.6 ms]
  Range (min … max):    19.4 ms …  26.9 ms    113 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: t/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a*a*a*a*a*a*a*a*a"
  Time (mean ± σ):      5.244 s ±  0.228 s    [User: 5.229 s, System: 0.010 s]
  Range (min … max):    4.969 s …  5.707 s    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  't/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a"' ran
  230.37 ± 20.04 times faster than 't/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a*a*a*a*a*a*a*a*a"'

The security implications are limited as it only affects operations that
are potentially DoS vectors. For example by creating a blob containing
such a pattern a malicious user can exploit this behavior to use large
amounts of CPU time on a remote server by pushing the blob and then
creating a new clone with --filter=sparse:oid. However this filter type
is usually disabled as it is known to consume large amounts of CPU time
even without this bug.

The WM_MATCH changed in the first hunk of this patch comes from the
original implementation imported from rsync in 5230f605e1 (Import
wildmatch from rsync, 2012-10-15). Compared to the others converted here
it is fairly harmless as it only triggers at the end of the pattern and
so will only cause a single unnecessary backtrack. The others introduced
by 6f1a31f0aa (wildmatch: advance faster in <asterisk> + <literal>
patterns, 2013-01-01) and 46983441ae (wildmatch: make a special case for
"*/" with FNM_PATHNAME, 2013-01-01) are more pernicious and will cause
exponential behavior.

A new test is added to protect against future regressions.

[1] https://research.swtch.com/glob

Helped-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoThe second batch
Junio C Hamano [Sun, 19 Mar 2023 22:03:22 +0000 (15:03 -0700)] 
The second batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'jk/add-p-unmerged-fix'
Junio C Hamano [Sun, 19 Mar 2023 22:03:13 +0000 (15:03 -0700)] 
Merge branch 'jk/add-p-unmerged-fix'

"git add -p" while the index is unmerged sometimes failed to parse
the diff output it internally produces and died, which has been
corrected.

* jk/add-p-unmerged-fix:
  add-patch: handle "* Unmerged path" lines

18 months agoMerge branch 'ew/fetch-no-write-fetch-head-fix'
Junio C Hamano [Sun, 19 Mar 2023 22:03:13 +0000 (15:03 -0700)] 
Merge branch 'ew/fetch-no-write-fetch-head-fix'

* ew/fetch-no-write-fetch-head-fix:
  fetch: pass --no-write-fetch-head to subprocesses

18 months agoMerge branch 'fc/advice-diverged-history'
Junio C Hamano [Sun, 19 Mar 2023 22:03:12 +0000 (15:03 -0700)] 
Merge branch 'fc/advice-diverged-history'

After "git pull" that is configured with pull.rebase=false
merge.ff=only fails due to our end having our own development, give
advice messages to get out of the "Not possible to fast-forward"
state.

* fc/advice-diverged-history:
  advice: add diverging advice for novices

18 months agoMerge branch 'ab/fix-strategy-opts-parsing'
Junio C Hamano [Sun, 19 Mar 2023 22:03:12 +0000 (15:03 -0700)] 
Merge branch 'ab/fix-strategy-opts-parsing'

The code to parse "git rebase -X<opt>" was not prepared to see an
unparsable option string, which has been corrected.

* ab/fix-strategy-opts-parsing:
  sequencer.c: fix overflow & segfault in parse_strategy_opts()

18 months agoMerge branch 'ds/reprepare-alternates-when-repreparing-packfiles'
Junio C Hamano [Sun, 19 Mar 2023 22:03:12 +0000 (15:03 -0700)] 
Merge branch 'ds/reprepare-alternates-when-repreparing-packfiles'

Once we start running, we assumed that the list of alternate object
databases would never change.  Hook into the machinery used to
update the list of packfiles during runtime to update this list as
well.

* ds/reprepare-alternates-when-repreparing-packfiles:
  object-file: reprepare alternates when necessary

18 months agoMerge branch 'jk/format-patch-change-format-for-empty-commits'
Junio C Hamano [Sun, 19 Mar 2023 22:03:12 +0000 (15:03 -0700)] 
Merge branch 'jk/format-patch-change-format-for-empty-commits'

"git format-patch" learned to write a log-message only output file
for empty commits.

* jk/format-patch-change-format-for-empty-commits:
  format-patch: output header for empty commits

18 months agoMerge branch 'jk/bundle-use-dash-for-stdfiles'
Junio C Hamano [Sun, 19 Mar 2023 22:03:12 +0000 (15:03 -0700)] 
Merge branch 'jk/bundle-use-dash-for-stdfiles'

"git bundle" learned that "-" is a common way to say that the input
comes from the standard input and/or the output goes to the
standard output.  It used to work only for output and only from the
root level of the working tree.

* jk/bundle-use-dash-for-stdfiles:
  parse-options: use prefix_filename_except_for_dash() helper
  parse-options: consistently allocate memory in fix_filename()
  bundle: don't blindly apply prefix_filename() to "-"
  bundle: document handling of "-" as stdin
  bundle: let "-" mean stdin for reading operations

18 months agoMerge branch 'jk/bundle-progress'
Junio C Hamano [Sun, 19 Mar 2023 22:03:11 +0000 (15:03 -0700)] 
Merge branch 'jk/bundle-progress'

Simplify UI to control progress meter given by "git bundle" command.

* jk/bundle-progress:
  bundle: turn on --all-progress-implied by default

18 months agoMerge branch 'as/doc-markup-fix'
Junio C Hamano [Sun, 19 Mar 2023 22:03:11 +0000 (15:03 -0700)] 
Merge branch 'as/doc-markup-fix'

Fix for a mis-mark-up in doc made in Git 2.39 days.

* as/doc-markup-fix:
  git-merge-tree.txt: replace spurious HTML entity

18 months agoMerge branch 'rj/avoid-switching-to-already-used-branch'
Junio C Hamano [Sun, 19 Mar 2023 22:03:11 +0000 (15:03 -0700)] 
Merge branch 'rj/avoid-switching-to-already-used-branch'

A few subcommands have been taught to stop users from working on a
branch that is being used in another worktree linked to the same
repository.

* rj/avoid-switching-to-already-used-branch:
  switch: reject if the branch is already checked out elsewhere (test)
  rebase: refuse to switch to a branch already checked out elsewhere (test)
  branch: fix die_if_checked_out() when ignore_current_worktree
  worktree: introduce is_shared_symref()

18 months agoMerge branch 'rj/bisect-already-used-branch'
Junio C Hamano [Sun, 19 Mar 2023 22:03:11 +0000 (15:03 -0700)] 
Merge branch 'rj/bisect-already-used-branch'

Allow "git bisect reset" to check out the original branch when the
branch is already checked out in a different worktree linked to the
same repository.

* rj/bisect-already-used-branch:
  bisect: fix "reset" when branch is checked out elsewhere

18 months agoMerge branch 'zh/push-to-delete-onelevel-ref'
Junio C Hamano [Sun, 19 Mar 2023 22:03:10 +0000 (15:03 -0700)] 
Merge branch 'zh/push-to-delete-onelevel-ref'

"git push" has been taught to allow deletion of refs with one-level
names to help repairing a repository who acquired such a ref by
mistake.  In general, we don't encourage use of such a ref, and
creation or update to such a ref is rejected as before.

* zh/push-to-delete-onelevel-ref:
  push: allow delete single-level ref
  receive-pack: fix funny ref error messsage

18 months agoMerge branch 'ak/restore-both-incompatible-with-conflicts'
Junio C Hamano [Sun, 19 Mar 2023 22:03:10 +0000 (15:03 -0700)] 
Merge branch 'ak/restore-both-incompatible-with-conflicts'

"git restore" supports options like "--ours" that are only
meaningful during a conflicted merge, but these options are only
meaningful when updating the working tree files.  These options are
marked to be incompatible when both "--staged" and "--worktree" are
in effect.

* ak/restore-both-incompatible-with-conflicts:
  restore: fault --staged --worktree with merge opts

18 months agoMerge branch 'ew/commit-reach-clean-up-flags-fix'
Junio C Hamano [Sun, 19 Mar 2023 22:03:10 +0000 (15:03 -0700)] 
Merge branch 'ew/commit-reach-clean-up-flags-fix'

Fix a segfaulting loop.  The function and its caller may need
further clean-up.

* ew/commit-reach-clean-up-flags-fix:
  commit-reach: avoid NULL dereference

18 months agoMerge branch 'ab/avoid-losing-exit-codes-in-tests'
Junio C Hamano [Sun, 19 Mar 2023 22:03:10 +0000 (15:03 -0700)] 
Merge branch 'ab/avoid-losing-exit-codes-in-tests'

Test clean-up.

* ab/avoid-losing-exit-codes-in-tests:
  tests: don't lose misc "git" exit codes
  tests: don't lose exit status with "test <op> $(git ...)"
  tests: don't lose "git" exit codes in "! ( git ... | grep )"
  tests: don't lose exit status with "(cd ...; test <op> $(git ...))"
  t/lib-patch-mode.sh: fix ignored exit codes
  auto-crlf tests: don't lose exit code in loops and outside tests

18 months agogit_connect(): fix corner cases in downgrading v2 to v0
Jeff King [Fri, 17 Mar 2023 19:08:51 +0000 (15:08 -0400)] 
git_connect(): fix corner cases in downgrading v2 to v0

There's code in git_connect() that checks whether we are doing a push
with protocol_v2, and if so, drops us to protocol_v0 (since we know
how to do v2 only for fetches). But it misses some corner cases:

  1. it checks the "prog" variable, which is actually the path to
     receive-pack on the remote side. By default this is just
     "git-receive-pack", but it could be an arbitrary string (like
     "/path/to/git receive-pack", etc). We'd accidentally stay in v2
     mode in this case.

  2. besides "receive-pack" and "upload-pack", there's one other value
     we'd expect: "upload-archive" for handling "git archive --remote".
     Like receive-pack, this doesn't understand v2, and should use the
     v0 protocol.

In practice, neither of these causes bugs in the real world so far. We
do send a "we understand v2" probe to the server, but since no server
implements v2 for anything but upload-pack, it's simply ignored. But
this would eventually become a problem if we do implement v2 for those
endpoints, as older clients would falsely claim to understand it,
leading to a server response they can't parse.

We can fix (1) by passing in both the program path and the "name" of the
operation. I treat the name as a string here, because that's the pattern
set in transport_connect(), which is one of our callers (we were simply
throwing away the "name" value there before).

We can fix (2) by allowing only known-v2 protocols ("upload-pack"),
rather than blocking unknown ones ("receive-pack" and "upload-archive").
That will mean whoever eventually implements v2 push will have to adjust
this list, but that's reasonable. We'll do the safe, conservative thing
(sticking to v0) by default, and anybody working on v2 will quickly
realize this spot needs to be updated.

The new tests cover the receive-pack and upload-archive cases above, and
re-confirm that we allow v2 with an arbitrary "--upload-pack" path (that
already worked before this patch, of course, but it would be an easy
thing to break if we flipped the allow/block logic without also handling
"name" separately).

Here are a few miscellaneous implementation notes, since I had to do a
little head-scratching to understand who calls what:

  - transport_connect() is called only for git-upload-archive. For
    non-http git remotes, that resolves to the virtual connect_git()
    function (which then calls git_connect(); confused yet?). So
    plumbing through "name" in connect_git() covers that.

  - for regular fetches and pushes, callers use higher-level functions
    like transport_fetch_refs(). For non-http git remotes, that means
    calling git_connect() under the hood via connect_setup(). And that
    uses the "for_push" flag to decide which name to use.

  - likewise, plumbing like fetch-pack and send-pack may call
    git_connect() directly; they each know which name to use.

  - for remote helpers (including http), we already have separate
    parameters for "name" and "exec" (another name for "prog"). In
    process_connect_service(), we feed the "name" to the helper via
    "connect" or "stateless-connect" directives.

    There's also a "servpath" option, which can be used to tell the
    helper about the "exec" path. But no helpers we implement support
    it! For http it would be useless anyway (no reasonable server
    implementation will allow you to send a shell command to run the
    server). In theory it would be useful for more obscure helpers like
    remote-ext, but even there it is not implemented.

    It's tempting to get rid of it simply to reduce confusion, but we
    have publicly documented it since it was added in fa8c097cc9
    (Support remote helpers implementing smart transports, 2009-12-09),
    so it's possible some helper in the wild is using it.

  - So for v2, helpers (again, including http) are mainly used via
    stateless-connect, driven by the main program. But they do still
    need to decide whether to do a v2 probe. And so there's similar
    logic in remote-curl.c's discover_refs() that looks for
    "git-receive-pack". But it's not buggy in the same way. Since it
    doesn't support servpath, it is always dealing with a "service"
    string like "git-receive-pack". And since it doesn't support
    straight "connect", it can't be used for "upload-archive".

    So we could leave that spot alone. But I've updated it here to match
    the logic we're changing in connect_git(). That seems like the least
    confusing thing for somebody who has to touch both of these spots
    later (say, to add v2 push support). I didn't add a new test to make
    sure this doesn't break anything; we already have several tests (in
    t5551 and elsewhere) that make sure we are using v2 over http.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoStart the 2.41 cycle
Junio C Hamano [Fri, 17 Mar 2023 21:03:20 +0000 (14:03 -0700)] 
Start the 2.41 cycle

Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'fz/rebase-msg-update'
Junio C Hamano [Fri, 17 Mar 2023 21:03:10 +0000 (14:03 -0700)] 
Merge branch 'fz/rebase-msg-update'

Message update.

* fz/rebase-msg-update:
  rebase: fix capitalisation autoSquash in i18n string

18 months agoMerge branch 'ew/fetch-hiderefs'
Junio C Hamano [Fri, 17 Mar 2023 21:03:10 +0000 (14:03 -0700)] 
Merge branch 'ew/fetch-hiderefs'

A new "fetch.hideRefs" option can be used to exclude specified refs
from "rev-list --objects --stdin --not --all" traversal for
checking object connectivity, most useful when there are many
unrelated histories in a single repository.

* ew/fetch-hiderefs:
  fetch: support hideRefs to speed up connectivity checks

18 months agoMerge branch 'mc/credential-helper-www-authenticate'
Junio C Hamano [Fri, 17 Mar 2023 21:03:10 +0000 (14:03 -0700)] 
Merge branch 'mc/credential-helper-www-authenticate'

Allow information carried on the WWW-AUthenticate header to be
passed to the credential helpers.

* mc/credential-helper-www-authenticate:
  credential: add WWW-Authenticate header to cred requests
  http: read HTTP WWW-Authenticate response headers
  t5563: add tests for basic and anoymous HTTP access

18 months agoMerge branch 'jc/gpg-lazy-init'
Junio C Hamano [Fri, 17 Mar 2023 21:03:10 +0000 (14:03 -0700)] 
Merge branch 'jc/gpg-lazy-init'

Instead of forcing each command to choose to honor GPG related
configuration variables, make the subsystem lazily initialize
itself.

* jc/gpg-lazy-init:
  drop pure pass-through config callbacks
  gpg-interface: lazily initialize and read the configuration

18 months agoMerge branch 'jk/unused-post-2.39-part2'
Junio C Hamano [Fri, 17 Mar 2023 21:03:09 +0000 (14:03 -0700)] 
Merge branch 'jk/unused-post-2.39-part2'

More work towards -Wunused.

* jk/unused-post-2.39-part2: (21 commits)
  help: mark unused parameter in git_unknown_cmd_config()
  run_processes_parallel: mark unused callback parameters
  userformat_want_item(): mark unused parameter
  for_each_commit_graft(): mark unused callback parameter
  rewrite_parents(): mark unused callback parameter
  fetch-pack: mark unused parameter in callback function
  notes: mark unused callback parameters
  prio-queue: mark unused parameters in comparison functions
  for_each_object: mark unused callback parameters
  list-objects: mark unused callback parameters
  mark unused parameters in signal handlers
  run-command: mark error routine parameters as unused
  mark "pointless" data pointers in callbacks
  ref-filter: mark unused callback parameters
  http-backend: mark unused parameters in virtual functions
  http-backend: mark argc/argv unused
  object-name: mark unused parameters in disambiguate callbacks
  serve: mark unused parameters in virtual functions
  serve: use repository pointer to get config
  ls-refs: drop config caching
  ...

18 months agoMerge branch 'en/header-cleanup'
Junio C Hamano [Fri, 17 Mar 2023 21:03:08 +0000 (14:03 -0700)] 
Merge branch 'en/header-cleanup'

Code clean-up to clarify the rule that "git-compat-util.h" must be
the first to be included.

* en/header-cleanup:
  diff.h: remove unnecessary include of object.h
  Remove unnecessary includes of builtin.h
  treewide: replace cache.h with more direct headers, where possible
  replace-object.h: move read_replace_refs declaration from cache.h to here
  object-store.h: move struct object_info from cache.h
  dir.h: refactor to no longer need to include cache.h
  object.h: stop depending on cache.h; make cache.h depend on object.h
  ident.h: move ident-related declarations out of cache.h
  pretty.h: move has_non_ascii() declaration from commit.h
  cache.h: remove dependence on hex.h; make other files include it explicitly
  hex.h: move some hex-related declarations from cache.h
  hash.h: move some oid-related declarations from cache.h
  alloc.h: move ALLOC_GROW() functions from cache.h
  treewide: remove unnecessary cache.h includes in source files
  treewide: remove unnecessary cache.h includes
  treewide: remove unnecessary git-compat-util.h includes in headers
  treewide: ensure one of the appropriate headers is sourced first

18 months agoMerge branch 'en/dir-api-cleanup'
Junio C Hamano [Fri, 17 Mar 2023 21:03:08 +0000 (14:03 -0700)] 
Merge branch 'en/dir-api-cleanup'

Code clean-up to clarify directory traversal API.

* en/dir-api-cleanup:
  unpack-trees: add usage notices around df_conflict_entry
  unpack-trees: special case read-tree debugging as internal usage
  unpack-trees: rewrap a few overlong lines from previous patch
  unpack-trees: mark fields only used internally as internal
  unpack_trees: start splitting internal fields from public API
  sparse-checkout: avoid using internal API of unpack-trees, take 2
  sparse-checkout: avoid using internal API of unpack-trees
  unpack-trees: clean up some flow control
  dir: mark output only fields of dir_struct as such
  dir: add a usage note to exclude_per_dir
  dir: separate public from internal portion of dir_struct
  unpack-trees: heed requests to overwrite ignored files
  t2021: fix platform-specific leftover cruft

18 months agoMerge branch 'jk/fsck-indices-in-worktrees'
Junio C Hamano [Fri, 17 Mar 2023 21:03:08 +0000 (14:03 -0700)] 
Merge branch 'jk/fsck-indices-in-worktrees'

"git fsck" learned to check the index files in other worktrees,
just like "git gc" honors them as anchoring points.

* jk/fsck-indices-in-worktrees:
  fsck: check even zero-entry index files
  fsck: mention file path for index errors
  fsck: check index files in all worktrees
  fsck: factor out index fsck

18 months agocompletion: prompt: use generic colors
Felipe Contreras [Tue, 28 Feb 2023 14:59:34 +0000 (08:59 -0600)] 
completion: prompt: use generic colors

When the prompt command mode was introduced in 1bfc51ac81 (Allow
__git_ps1 to be used in PROMPT_COMMAND, 2012-10-10), the assumption was
that it was necessary in order to properly add colors to PS1 in bash,
but this wasn't true.

It's true that the \[ \] markers add the information needed to properly
calculate the width of the prompt, and they have to be added directly to
PS1, a function returning them doesn't work.

But that is because bash coverts the \[ \] markers in PS1 to \001 \002,
which is what readline ultimately needs in order to calculate the width.

We don't need bash to do this conversion, we can use \001 \002
ourselves, and then the prompt command mode is not necessary to display
colors.

This is what functions returning colors are supposed to do [1].

[1] http://mywiki.wooledge.org/BashFAQ/053

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Tested-by: Joakim Petersen <joak-pet@online.no>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoobject-name: fix quiet @{u} parsing
Felipe Contreras [Thu, 16 Mar 2023 17:15:14 +0000 (11:15 -0600)] 
object-name: fix quiet @{u} parsing

Currently `git rev-parse --quiet @{u}` is not actually quiet when
upstream isn't configured:

  fatal: no upstream configured for branch 'foo'

Make it so.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agorebase: prefer --default-prefix to --{src,dst}-prefix for format-patch
Jeff King [Mon, 13 Mar 2023 19:54:11 +0000 (15:54 -0400)] 
rebase: prefer --default-prefix to --{src,dst}-prefix for format-patch

When git-rebase invokes format-patch, it wants to make sure we use the
normal prefixes, and are not confused by diff.noprefix or similar. When
this was added in 5b220a6876f (Add --src/dst-prefix to git-formt-patch
in git-rebase.sh, 2010-09-09), we only had --src-prefix and --dst-prefix
to do so, which requires re-specifying the prefixes we expect to see.
These days we can say what we want more directly: just use the defaults.

This is a minor cleanup that should have no behavior change, but
hopefully the result expresses more clearly what the code is trying to
accomplish.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoGit 2.40 v2.40.0
Junio C Hamano [Sun, 12 Mar 2023 21:34:41 +0000 (14:34 -0700)] 
Git 2.40

Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge tag 'l10n-2.40.0-rnd1' of https://github.com/git-l10n/git-po
Junio C Hamano [Sun, 12 Mar 2023 21:33:14 +0000 (14:33 -0700)] 
Merge tag 'l10n-2.40.0-rnd1' of https://github.com/git-l10n/git-po

l10n-2.40.0-rnd1

* tag 'l10n-2.40.0-rnd1' of https://github.com/git-l10n/git-po:
  l10n: zh_CN v2.40.0 round 1
  l10n: update German translation
  l10n: tr: Update Turkish translations for v.2.40.0
  l10n: fr: v2.40.0 rnd 2
  l10n: fr: v2.40.0 rnd 1
  l10n: fr: fix some typos
  l10n: po-id for 2.40 (round 1)
  l10n: sv.po: Update Swedish translation (5490t0f0u)
  l10n: bg.po: Updated Bulgarian translation (5490t)
  l10n: Update Catalan translation

18 months agols-files: fix "--format" output of relative paths
Adam Johnson [Fri, 10 Mar 2023 13:04:33 +0000 (13:04 +0000)] 
ls-files: fix "--format" output of relative paths

Fix a bug introduced with the "--format" option in
ce74de93 (ls-files: introduce "--format" option, 2022-07-23),
where relative paths were computed using the output buffer,
which could lead to random garbage data in the output.

Signed-off-by: Adam Johnson <me@adamj.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoreceive-pack: fix stale packfile locks when dying
Patrick Steinhardt [Fri, 10 Mar 2023 06:52:10 +0000 (07:52 +0100)] 
receive-pack: fix stale packfile locks when dying

When accepting a packfile in git-receive-pack(1), we feed that packfile
into git-index-pack(1) to generate the packfile index. As the packfile
would often only contain unreachable objects until the references have
been updated, concurrently running garbage collection might be tempted
to delete the packfile right away and thus cause corruption. To fix
this, we ask git-index-pack(1) to create a `.keep` file before moving
the packfile into place, which is getting deleted again once all of the
reference updates have been processed.

Now in production systems we have observed that those `.keep` files are
sometimes not getting deleted as expected, where the result is that
repositories tend to grow packfiles that are never deleted over time.
This seems to be caused by a race when git-receive-pack(1) is killed
after we have migrated the kept packfile from the quarantine directory
into the main object database. While this race window is typically small
it can be extended for example by installing a `proc-receive` hook.

Fix this race by registering the lockfile as a tempfile so that it will
automatically be removed at exit or when receiving a signal.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'fz/po-zh_CN' of github.com:fangyi-zhou/git-po
Jiang Xin [Fri, 10 Mar 2023 14:50:14 +0000 (22:50 +0800)] 
Merge branch 'fz/po-zh_CN' of github.com:fangyi-zhou/git-po

* 'fz/po-zh_CN' of github.com:fangyi-zhou/git-po:
  l10n: zh_CN v2.40.0 round 1

18 months agotest: don't print aggregate-results command
Felipe Contreras [Thu, 9 Mar 2023 17:30:32 +0000 (11:30 -0600)] 
test: don't print aggregate-results command

There's no value in it.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agotest: simplify counts aggregation
Felipe Contreras [Thu, 9 Mar 2023 17:30:31 +0000 (11:30 -0600)] 
test: simplify counts aggregation

When the list of files as input was implemented in 6508eedf67
(t/aggregate-results: accomodate systems with small max argument list
length, 2010-06-01), a much simpler solution wasn't considered.

Let's just pass the directory as an argument.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoobject-file: reprepare alternates when necessary
Derrick Stolee [Wed, 8 Mar 2023 18:47:32 +0000 (18:47 +0000)] 
object-file: reprepare alternates when necessary

When an object is not found in a repository's object store, we sometimes
call reprepare_packed_git() to see if the object was temporarily moved
into a new pack-file (and its old pack-file or loose object was
deleted). This process does a scan of each pack directory within each
odb, but does not reevaluate if the odb list needs updating.

Extend reprepare_packed_git() to also reprepare the alternate odb list
by setting loaded_alternates to zero and calling prepare_alt_odb(). This
will add newly-discoverd odbs to the linked list, but will not duplicate
existing ones nor will it remove existing ones that are no longer listed
in the alternates file. Do this under the object read lock to avoid
readers from interacting with a potentially incomplete odb being added
to the odb list.

If the alternates file was edited to _remove_ some alternates during the
course of the Git process, Git will continue to see alternates that were
ever valid for that repository. ODBs are not removed from the list, the
same as the existing behavior before this change. Git already has
protections against an alternate directory disappearing from the
filesystem during the lifetime of a process, and those are still in
effect.

This change is specifically for concurrent changes to the repository, so
it is difficult to create a test that guarantees this behavior is
correct. I manually verified by introducing a reprepare_packed_git() call
into get_revision() and stepped into that call in a debugger with a
parent 'git log' process. Multiple runs of prepare_alt_odb() kept
the_repository->objects->odb as a single-item chain until I added a
.git/objects/info/alternates file in a different process. The next run
added the new odb to the chain and subsequent runs did not add to the
chain.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agofetch: pass --no-write-fetch-head to subprocesses
Eric Wong [Wed, 8 Mar 2023 22:22:05 +0000 (22:22 +0000)] 
fetch: pass --no-write-fetch-head to subprocesses

It seems a user would expect this option would work regardless
of whether it's fetching from a single remote, many remotes,
or recursing into submodules.

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoadd-patch: handle "* Unmerged path" lines
Jeff King [Thu, 9 Mar 2023 08:58:16 +0000 (03:58 -0500)] 
add-patch: handle "* Unmerged path" lines

When we generate a diff with --cached, unmerged entries have no oid for
their index entry:

  $ git diff-index --abbrev --cached HEAD
  :100644 000000 f719efd 0000000 U my-conflict

So when we are asked to produce a patch, since we only have one side, we
just emit a special message:

  $ git diff-index --cached -p HEAD
  * Unmerged path my-conflict

This confuses interactive-patch modes that look at cached diffs. For
example:

  $ git reset -p
  BUG: add-patch.c:498: diff starts with unexpected line:
  * Unmerged path my-conflict

Making things even more confusing, you'll get that error only if the
unmerged entry is alphabetically the first changed file. Otherwise, we
simply stick the unrecognized line to the end of the previous hunk.
There it's mostly harmless, as it eventually gets fed back to "git
apply", which happily ignores it. But it's still shown to the user
attached to the hunk, which is wrong.

So let's handle these lines as a noop. There's not really anything
useful to do with a conflicted merge in this case, and that's what we do
for other cases like "add -p". There we get a "diff --cc" line, which we
accept as starting a new file, but we refuse to use any of its hunks
(their headers start with "@@@" and not "@@ ", so we silently ignore
them).

It seems like simply recognizing the line and continuing in our parsing
loop would work. But we actually need to run the rest of the loop body
to handle matching up our colored/filtered output. But that code assumes
that we have some active file_diff we're working on. So instead, we'll
just insert a dummy entry into our array. This ends up the same as if we
saw a "diff --cc" line (a file with no hunks).

Reported-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoformat-patch: add format.noprefix option
Jeff King [Thu, 9 Mar 2023 06:12:37 +0000 (01:12 -0500)] 
format-patch: add format.noprefix option

The previous commit dropped support for diff.noprefix in format-patch.
While this will do the right thing in most cases (where sending patches
without a prefix was an accidental side effect of the sender preferring
to see their local patches without prefixes), it left no good option for
a project or workflow where you really do want to send patches without
prefixes. You'd be stuck using "--no-prefix" for every invocation.

So let's add a config option specific to format-patch that enables this
behavior. That gives people who have such a workflow a way to get what
they want, but makes it hard to accidentally trigger it.

A more backwards-compatible way of doing the transition would be to have
format.noprefix default to diff.noprefix when it's not set. But that
doesn't really help the "accidental" problem; people would have to
manually set format.noprefix=false. And it's unlikely that anybody
really wants format.noprefix=true in the first place. I'm adding it here
mostly as an escape hatch, not because anybody has expressed any
interest in it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoformat-patch: do not respect diff.noprefix
Jeff King [Thu, 9 Mar 2023 06:11:49 +0000 (01:11 -0500)] 
format-patch: do not respect diff.noprefix

The output of format-patch respects diff.noprefix, but this usually ends
up being a hassle for people receiving the patch, as they have to
manually specify "-p0" in order to apply it.

I don't think there was any specific intention for it to behave this
way. The noprefix option is handled by git_diff_ui_config(), and
format-patch exists in a gray area between plumbing and porcelain.
People do look at the output, and we'd expect it to colorize things,
respect their choice of algorithm, and so on. But this particular option
creates problems for the receiver (in theory so does diff.mnemonicprefix,
but since we are always formatting commits, the mnemonic prefixes will
always be "a/" and "b/").

So let's disable it. The slight downsides are:

  - people who have set diff.noprefix presumably like to see their
    patches without prefixes. If they use format-patch to review their
    series, they'll see prefixes. On the other hand, it is probably a
    good idea for them to look at what will actually get sent out.

    We could try to play games here with "is stdout a tty", as we do for
    color. But that's not a completely reliable signal, and it's
    probably not worth the trouble. If you want to see the patch with
    the usual bells and whistles, then you are better off using "git
    log" or "git show".

  - if a project really does have a workflow that likes prefix-less
    patches, and the receiver is prepared to use "-p0", then the sender
    now has to manually say "--no-prefix" for each format-patch
    invocation. That doesn't seem _too_ terrible given that the receiver
    has to manually say "-p0" for each git-am invocation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agodiff: add --default-prefix option
Jeff King [Thu, 9 Mar 2023 06:09:54 +0000 (01:09 -0500)] 
diff: add --default-prefix option

You can change the output of prefixes with diff.noprefix and
diff.mnemonicprefix, but there's no easy way to override them from the
command-line. We do have "--no-prefix", but there's no way to get back
to the default prefix. So let's add an option to do that.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agot4013: add tests for diff prefix options
Jeff King [Thu, 9 Mar 2023 06:07:45 +0000 (01:07 -0500)] 
t4013: add tests for diff prefix options

We don't have any specific test coverage of diff's various prefix
options. We do incidentally invoke them in a few places, but it's worth
having a more thorough set of tests that covers all of the effects we
expect to see, and that the options kick in at the appropriate times.

This will be especially useful as the next patch adds more options.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agodiff: factor out src/dst prefix setup
Jeff King [Thu, 9 Mar 2023 06:07:06 +0000 (01:07 -0500)] 
diff: factor out src/dst prefix setup

We directly manipulate diffopt's a_prefix and b_prefix to set up either
the default "a/foo" prefix or the "--no-prefix" variant. Although this
is only a few lines, it's worth pulling these into their own functions.
That lets us avoid one repetition already in this patch, but will also
give us a cleaner interface for callers which want to tweak this
setting.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agosequencer.c: fix overflow & segfault in parse_strategy_opts()
Ævar Arnfjörð Bjarmason [Tue, 7 Mar 2023 18:21:59 +0000 (19:21 +0100)] 
sequencer.c: fix overflow & segfault in parse_strategy_opts()

The split_cmdline() function introduced in [1] returns an "int". If
it's negative it signifies an error. The option parsing in [2] didn't
account for this, and assigned the value directly to the "size_t
xopts_nr". We'd then attempt to loop over all of these elements, and
access uninitialized memory.

There's a few things that use this for option parsing, but one way to
trigger it is with a bad value to "-X <strategy-option>", e.g:

git rebase -X"bad argument\""

In another context this might be a security issue, but in this case
someone who's already able to inject arguments directly to our
commands would be past other defenses, making this potential
escalation a moot point.

As the example above & test case shows the error reporting leaves
something to be desired. The function will loop over the
whitespace-split values, but when it encounters an error we'll only
report the first element, which is OK, not the second "argument\""
whose quote is unbalanced.

This is an inherent limitation of the current API, and the issue
affects other API users. Let's not attempt to fix that now. If and
when that happens these tests will need to be adjusted to assert the
new output.

1. 2b11e3170e9 (If you have a config containing something like this:,
   2006-06-05)
2. ca6c6b45dd9 (sequencer (rebase -i): respect strategy/strategy_opts
   settings, 2017-01-02)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoadvice: add diverging advice for novices
Felipe Contreras [Wed, 8 Mar 2023 02:48:33 +0000 (20:48 -0600)] 
advice: add diverging advice for novices

The user might not necessarily know why ff only was configured, maybe an
admin did it, or the installer (Git for Windows), or perhaps they just
followed some online advice.

This can happen not only on pull.ff=only, but merge.ff=only too.

Even worse if the user has configured pull.rebase=false and
merge.ff=only, because in those cases a diverging merge will constantly
keep failing. There's no trivial way to get out of this other than
`git merge --no-ff`.

Let's not assume our users are experts in git who completely understand
all their configurations.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'l10n-de-2.40' of github.com:ralfth/git
Jiang Xin [Wed, 8 Mar 2023 01:10:20 +0000 (09:10 +0800)] 
Merge branch 'l10n-de-2.40' of github.com:ralfth/git

* 'l10n-de-2.40' of github.com:ralfth/git:
  l10n: update German translation

18 months agoMerge branch 'po-id' of github.com:bagasme/git-po
Jiang Xin [Wed, 8 Mar 2023 00:28:02 +0000 (08:28 +0800)] 
Merge branch 'po-id' of github.com:bagasme/git-po

* 'po-id' of github.com:bagasme/git-po:
  l10n: po-id for 2.40 (round 1)

18 months agoMerge branch 'catalan' of github.com:Softcatala/git-po
Jiang Xin [Wed, 8 Mar 2023 00:27:07 +0000 (08:27 +0800)] 
Merge branch 'catalan' of github.com:Softcatala/git-po

* 'catalan' of github.com:Softcatala/git-po:
  l10n: Update Catalan translation

18 months agoMerge branch 'fr_2.40.0_rnd1' of github.com:jnavila/git
Jiang Xin [Wed, 8 Mar 2023 00:26:00 +0000 (08:26 +0800)] 
Merge branch 'fr_2.40.0_rnd1' of github.com:jnavila/git

* 'fr_2.40.0_rnd1' of github.com:jnavila/git:
  l10n: fr: v2.40.0 rnd 2
  l10n: fr: v2.40.0 rnd 1
  l10n: fr: fix some typos

18 months agoMerge branch 'master' of github.com:nafmo/git-l10n-sv
Jiang Xin [Wed, 8 Mar 2023 00:25:07 +0000 (08:25 +0800)] 
Merge branch 'master' of github.com:nafmo/git-l10n-sv

* 'master' of github.com:nafmo/git-l10n-sv:
  l10n: sv.po: Update Swedish translation (5490t0f0u)

18 months agoMerge branch 'master' of github.com:alshopov/git-po
Jiang Xin [Wed, 8 Mar 2023 00:23:16 +0000 (08:23 +0800)] 
Merge branch 'master' of github.com:alshopov/git-po

* 'master' of github.com:alshopov/git-po:
  l10n: bg.po: Updated Bulgarian translation (5490t)

18 months agoMerge branch 'turkish' of github.com:bitigchi/git-po
Jiang Xin [Wed, 8 Mar 2023 00:22:01 +0000 (08:22 +0800)] 
Merge branch 'turkish' of github.com:bitigchi/git-po

* 'turkish' of github.com:bitigchi/git-po:
  l10n: tr: Update Turkish translations for v.2.40.0

18 months agol10n: zh_CN v2.40.0 round 1
Fangyi Zhou [Tue, 7 Mar 2023 23:42:30 +0000 (23:42 +0000)] 
l10n: zh_CN v2.40.0 round 1

Reviewed-by: 依云 <lilydjwg@gmail.com>
Signed-off-by: Fangyi Zhou <me@fangyi.io>
18 months agoGit 2.40-rc2 v2.40.0-rc2
Junio C Hamano [Tue, 7 Mar 2023 05:53:11 +0000 (21:53 -0800)] 
Git 2.40-rc2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 months agoMerge branch 'gm/signature-format-doc'
Junio C Hamano [Tue, 7 Mar 2023 05:51:56 +0000 (21:51 -0800)] 
Merge branch 'gm/signature-format-doc'

Doc update.

* gm/signature-format-doc:
  signature-format.txt: note SSH and X.509 signature delimiters

18 months agoparse-options: use prefix_filename_except_for_dash() helper
Jeff King [Sat, 4 Mar 2023 10:31:47 +0000 (05:31 -0500)] 
parse-options: use prefix_filename_except_for_dash() helper

Since our fix_filename()'s only remaining special case is handling "-",
we can use the newly-minted helper function that handles this already.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>