From d05d84c5f507e8b973982e9cf3a27a07cd94fcb8 Mon Sep 17 00:00:00 2001 From: Mirko Faina Date: Mon, 16 Mar 2026 01:51:16 +0100 Subject: [PATCH 01/21] apply.c: fix -p argument parsing "git apply" has an option -p that takes an integer as its argument. Unfortunately the function apply_option_parse_p() in charge of parsing this argument uses atoi() to convert from string to integer, which allows a non-digit after the number (e.g. "1q") to be silently ignored. As a consequence, an argument that does not begin with a digit silently becomes a zero. Despite this command working fine when a non-positive argument is passed, it might be useful for the end user to know that their input contains non-digits that might've been unintended. Replace atoi() with strtol_i() to catch malformed inputs. Signed-off-by: Mirko Faina Signed-off-by: Junio C Hamano --- apply.c | 3 ++- t/t4120-apply-popt.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/apply.c b/apply.c index 3de4aa4d2eaac5..faf75b544977ad 100644 --- a/apply.c +++ b/apply.c @@ -4961,7 +4961,8 @@ static int apply_option_parse_p(const struct option *opt, BUG_ON_OPT_NEG(unset); - state->p_value = atoi(arg); + if (strtol_i(arg, 10, &state->p_value) < 0 || state->p_value < 0) + die(_("option -p expects a non-negative integer, got '%s'"), arg); state->p_value_known = 1; return 0; } diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh index 697e86c0ff4560..c960fdf622512f 100755 --- a/t/t4120-apply-popt.sh +++ b/t/t4120-apply-popt.sh @@ -23,6 +23,47 @@ test_expect_success setup ' rmdir süb ' +test_expect_success 'git apply -p 1 patch' ' + cat >patch <<-\EOF && + From 90ad11d5b2d437e82d4d992f72fb44c2227798b5 Mon Sep 17 00:00:00 2001 + From: Mroik + Date: Mon, 9 Mar 2026 23:25:00 +0100 + Subject: [PATCH] Test + + --- + t/test/test | 0 + 1 file changed, 0 insertions(+), 0 deletions(-) + create mode 100644 t/test/test + + diff --git a/t/test/test b/t/test/test + new file mode 100644 + index 0000000000..e69de29bb2 + -- + 2.53.0.851.ga537e3e6e9 + EOF + test_when_finished "rm -rf t" && + git apply -p 1 patch && + test_path_is_dir t +' + +test_expect_success 'apply fails due to non-num -p' ' + test_when_finished "rm -rf t test err" && + test_must_fail git apply -p malformed patch 2>err && + test_grep "option -p expects a non-negative integer" err +' + +test_expect_success 'apply fails due to trailing non-digit in -p' ' + test_when_finished "rm -rf t test err" && + test_must_fail git apply -p 2q patch 2>err && + test_grep "option -p expects a non-negative integer" err +' + +test_expect_success 'apply fails due to negative number in -p' ' + test_when_finished "rm -rf t test err patch" && + test_must_fail git apply -p -1 patch 2> err && + test_grep "option -p expects a non-negative integer" err +' + test_expect_success 'apply git diff with -p2' ' cp file1.saved file1 && git apply -p2 patch.file From daa91c693eb1fef0cd04aed8c6b37ee79d5897e0 Mon Sep 17 00:00:00 2001 From: Kristoffer Haugsbakk Date: Mon, 16 Mar 2026 22:48:24 +0100 Subject: [PATCH 02/21] doc: interpret-trailers: convert to synopsis style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See e.g. 0ae23ab5 (doc: convert git worktree to synopsis style, 2025-10-05) for the markup rules for this style. There aren’t many subtleties to the transformation of this doc since it doesn’t use any advanced constructs. The only thing is that "`:`{nbsp}" is used instead of `': '` to refer to effective inline-verbatim with a space (␠).[1] I also use (_) for emphasis although (') gives the same result. Also prefer linking to Git commands instead of saying e.g. `git format-patch`. But for this command we can type out git-interpret- trailers(1) to avoid a self-reference. Also replace camel case `` with kebab case ``. And while doing that make sure to replace `trailer.*` with `trailer.`. † 1: Similar to "`tag:`{nbsp}" in `Documentation/pretty-formats.adoc` Signed-off-by: Kristoffer Haugsbakk Signed-off-by: Junio C Hamano --- Documentation/git-interpret-trailers.adoc | 145 +++++++++++----------- 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/Documentation/git-interpret-trailers.adoc b/Documentation/git-interpret-trailers.adoc index fd335fe772ab99..ea47f2f7ae5f63 100644 --- a/Documentation/git-interpret-trailers.adoc +++ b/Documentation/git-interpret-trailers.adoc @@ -7,14 +7,14 @@ git-interpret-trailers - Add or parse structured information in commit messages SYNOPSIS -------- -[verse] -'git interpret-trailers' [--in-place] [--trim-empty] +[synopsis] +git interpret-trailers [--in-place] [--trim-empty] [(--trailer (|)[(=|:)])...] [--parse] [...] DESCRIPTION ----------- -Add or parse 'trailer' lines that look similar to RFC 822 e-mail +Add or parse _trailer_ lines that look similar to RFC 822 e-mail headers, at the end of the otherwise free-form part of a commit message. For example, in the following commit message @@ -27,23 +27,24 @@ Signed-off-by: Alice Signed-off-by: Bob ------------------------------------------------ -the last two lines starting with "Signed-off-by" are trailers. +the last two lines starting with `Signed-off-by` are trailers. This command reads commit messages from either the - arguments or the standard input if no is specified. +__ arguments or the standard input if no __ is specified. If `--parse` is specified, the output consists of the parsed trailers coming from the input, without influencing them with any command line options or configuration variables. -Otherwise, this command applies `trailer.*` configuration variables -(which could potentially add new trailers, as well as reposition them), -as well as any command line arguments that can override configuration -variables (such as `--trailer=...` which could also add new trailers), -to each input file. The result is emitted on the standard output. +Otherwise, this command applies `trailer.` configuration +variables (which could potentially add new trailers, as well as +reposition them), as well as any command line arguments that can +override configuration variables (such as `--trailer=...` which could +also add new trailers), to each input file. The result is emitted on the +standard output. This command can also operate on the output of linkgit:git-format-patch[1], which is more elaborate than a plain commit message. Namely, such output -includes a commit message (as above), a "---" divider line, and a patch part. +includes a commit message (as above), a `---` divider line, and a patch part. For these inputs, the divider and patch parts are not modified by this command and are emitted as is on the output, unless `--no-divider` is specified. @@ -53,24 +54,24 @@ are applied to each input and the way any existing trailer in the input is changed. They also make it possible to automatically add some trailers. -By default, a '=' or ':' argument given +By default, a `=` or `:` argument given using `--trailer` will be appended after the existing trailers only if -the last trailer has a different (, ) pair (or if there -is no existing trailer). The and parts will be trimmed +the last trailer has a different (__, __) pair (or if there +is no existing trailer). The __ and __ parts will be trimmed to remove starting and trailing whitespace, and the resulting trimmed - and will appear in the output like this: +__ and __ will appear in the output like this: ------------------------------------------------ key: value ------------------------------------------------ -This means that the trimmed and will be separated by -`': '` (one colon followed by one space). +This means that the trimmed __ and __ will be separated by +"`:`{nbsp}" (one colon followed by one space). -For convenience, a can be configured to make using `--trailer` +For convenience, a __ can be configured to make using `--trailer` shorter to type on the command line. This can be configured using the -'trailer..key' configuration variable. The must be a prefix -of the full string, although case sensitivity does not matter. For +`trailer..key` configuration variable. The __ must be a prefix +of the full __ string, although case sensitivity does not matter. For example, if you have ------------------------------------------------ @@ -91,13 +92,13 @@ least one Git-generated or user-configured trailer and consists of at least 25% trailers. The group must be preceded by one or more empty (or whitespace-only) lines. The group must either be at the end of the input or be the last -non-whitespace lines before a line that starts with '---' (followed by a +non-whitespace lines before a line that starts with `---` (followed by a space or the end of the line). When reading trailers, there can be no whitespace before or inside the -, but any number of regular space and tab characters are allowed -between the and the separator. There can be whitespaces before, -inside or after the . The may be split over multiple lines +__, but any number of regular space and tab characters are allowed +between the __ and the separator. There can be whitespaces before, +inside or after the __. The __ may be split over multiple lines with each subsequent line starting with at least one whitespace, like the "folding" in RFC 822. Example: @@ -111,77 +112,77 @@ rules for RFC 822 headers. For example they do not follow the encoding rule. OPTIONS ------- ---in-place:: +`--in-place`:: Edit the files in place. ---trim-empty:: - If the part of any trailer contains only whitespace, +`--trim-empty`:: + If the __ part of any trailer contains only whitespace, the whole trailer will be removed from the output. This applies to existing trailers as well as new trailers. ---trailer [(=|:)]:: - Specify a (, ) pair that should be applied as a +`--trailer [(=|:)]`:: + Specify a (__, __) pair that should be applied as a trailer to the inputs. See the description of this command. ---where :: ---no-where:: +`--where `:: +`--no-where`:: Specify where all new trailers will be added. A setting - provided with '--where' overrides the `trailer.where` and any - applicable `trailer..where` configuration variables - and applies to all '--trailer' options until the next occurrence of - '--where' or '--no-where'. Upon encountering '--no-where', clear the - effect of any previous use of '--where', such that the relevant configuration + provided with `--where` overrides the `trailer.where` and any + applicable `trailer..where` configuration variables + and applies to all `--trailer` options until the next occurrence of + `--where` or `--no-where`. Upon encountering `--no-where`, clear the + effect of any previous use of `--where`, such that the relevant configuration variables are no longer overridden. Possible placements are `after`, `before`, `end` or `start`. ---if-exists :: ---no-if-exists:: +`--if-exists `:: +`--no-if-exists`:: Specify what action will be performed when there is already at - least one trailer with the same in the input. A setting - provided with '--if-exists' overrides the `trailer.ifExists` and any - applicable `trailer..ifExists` configuration variables - and applies to all '--trailer' options until the next occurrence of - '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists', clear the - effect of any previous use of '--if-exists', such that the relevant configuration + least one trailer with the same __ in the input. A setting + provided with `--if-exists` overrides the `trailer.ifExists` and any + applicable `trailer..ifExists` configuration variables + and applies to all `--trailer` options until the next occurrence of + `--if-exists` or `--no-if-exists`. Upon encountering `--no-if-exists`, clear the + effect of any previous use of `--if-exists`, such that the relevant configuration variables are no longer overridden. Possible actions are `addIfDifferent`, `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`. ---if-missing :: ---no-if-missing:: +`--if-missing `:: +`--no-if-missing`:: Specify what action will be performed when there is no other - trailer with the same in the input. A setting - provided with '--if-missing' overrides the `trailer.ifMissing` and any - applicable `trailer..ifMissing` configuration variables - and applies to all '--trailer' options until the next occurrence of - '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing', - clear the effect of any previous use of '--if-missing', such that the relevant + trailer with the same __ in the input. A setting + provided with `--if-missing` overrides the `trailer.ifMissing` and any + applicable `trailer..ifMissing` configuration variables + and applies to all `--trailer` options until the next occurrence of + `--if-missing` or `--no-if-missing`. Upon encountering `--no-if-missing`, + clear the effect of any previous use of `--if-missing`, such that the relevant configuration variables are no longer overridden. Possible actions are `doNothing` or `add`. ---only-trailers:: +`--only-trailers`:: Output only the trailers, not any other parts of the input. ---only-input:: +`--only-input`:: Output only trailers that exist in the input; do not add any - from the command-line or by applying `trailer.*` configuration + from the command-line or by applying `trailer.` configuration variables. ---unfold:: +`--unfold`:: If a trailer has a value that runs over multiple lines (aka "folded"), reformat the value into a single line. ---parse:: +`--parse`:: A convenience alias for `--only-trailers --only-input --unfold`. This makes it easier to only see the trailers coming from the input without influencing them with any command line options or configuration variables, while also making the output machine-friendly with - --unfold. + `--unfold`. ---no-divider:: +`--no-divider`:: Do not treat `---` as the end of the commit message. Use this when you know your input contains just the commit message itself - (and not an email or the output of `git format-patch`). + (and not an email or the output of linkgit:git-format-patch[1]). CONFIGURATION VARIABLES ----------------------- @@ -193,7 +194,7 @@ include::config/trailer.adoc[] EXAMPLES -------- -* Configure a 'sign' trailer with a 'Signed-off-by' key, and then +* Configure a `sign` trailer with a `Signed-off-by` key, and then add two of these trailers to a commit message file: + ------------ @@ -230,8 +231,8 @@ Signed-off-by: Bob Acked-by: Alice ------------ -* Extract the last commit as a patch, and add a 'Cc' and a - 'Reviewed-by' trailer to it: +* Extract the last commit as a patch, and add a `Cc` and a + `Reviewed-by` trailer to it: + ------------ $ git format-patch -1 @@ -239,9 +240,9 @@ $ git format-patch -1 $ git interpret-trailers --trailer 'Cc: Alice ' --trailer 'Reviewed-by: Bob ' 0001-foo.patch >0001-bar.patch ------------ -* Configure a 'sign' trailer with a command to automatically add a - 'Signed-off-by: ' with the author information only if there is no - 'Signed-off-by: ' already, and show how it works: +* Configure a `sign` trailer with a command to automatically add a + "`Signed-off-by:`{nbsp}" with the author information only if there is no + "`Signed-off-by:`{nbsp}" already, and show how it works: + ------------ $ cat msg1.txt @@ -272,7 +273,7 @@ body text Signed-off-by: Alice ------------ -* Configure a 'fix' trailer with a key that contains a '#' and no +* Configure a `fix` trailer with a key that contains a `#` and no space after this character, and show how it works: + ------------ @@ -284,7 +285,7 @@ subject Fix #42 ------------ -* Configure a 'help' trailer with a cmd use a script `glog-find-author` +* Configure a `help` trailer with a cmd use a script `glog-find-author` which search specified author identity from git log in git repository and show how it works: + @@ -308,7 +309,7 @@ Helped-by: Junio C Hamano Helped-by: Christian Couder ------------ -* Configure a 'ref' trailer with a cmd use a script `glog-grep` +* Configure a `ref` trailer with a cmd use a script `glog-grep` to grep last relevant commit from git log in the git repository and show how it works: + @@ -331,7 +332,7 @@ body text Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07) ------------ -* Configure a 'see' trailer with a command to show the subject of a +* Configure a `see` trailer with a command to show the subject of a commit that is related, and show how it works: + ------------ @@ -359,8 +360,8 @@ See-also: fe3187489d69c4 (subject of related commit) * Configure a commit template with some trailers with empty values (using sed to show and keep the trailing spaces at the end of the trailers), then configure a commit-msg hook that uses - 'git interpret-trailers' to remove trailers with empty values and - to add a 'git-version' trailer: + git-interpret-trailers(1) to remove trailers with empty values and to + add a `git-version` trailer: + ------------ $ cat temp.txt From bec94f79e4b7473adf70c7b0623057883c549d16 Mon Sep 17 00:00:00 2001 From: Kristoffer Haugsbakk Date: Mon, 16 Mar 2026 22:48:25 +0100 Subject: [PATCH 03/21] doc: interpret-trailers: normalize and fill out options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some negated options are missing according to `git interpret-trailers -h`. Also normalize to the “stuck form” (see gitcli(7)) like what was done in 806337c7 (doc: notes: use stuck form throughout, 2025-05-27).[1] Also normalize the order of the regular and negated options according to the current convention.[2] Also note that `--no-trailer` will reset the list. † 1: See also https://lore.kernel.org/git/6f7d027e-088a-4d66-92af-b8d1c32d730c@app.fastmail.com/ † 2: https://lore.kernel.org/git/xmqqcyct1mtq.fsf@gitster.g/ Signed-off-by: Kristoffer Haugsbakk Signed-off-by: Junio C Hamano --- Documentation/git-interpret-trailers.adoc | 66 +++++++++++++++-------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/Documentation/git-interpret-trailers.adoc b/Documentation/git-interpret-trailers.adoc index ea47f2f7ae5f63..77b4f63b05cf5b 100644 --- a/Documentation/git-interpret-trailers.adoc +++ b/Documentation/git-interpret-trailers.adoc @@ -113,64 +113,80 @@ rules for RFC 822 headers. For example they do not follow the encoding rule. OPTIONS ------- `--in-place`:: - Edit the files in place. +`--no-in-place`:: + Edit the files in place. The default is `--no-in-place`. `--trim-empty`:: +`--no-trim-empty`:: If the __ part of any trailer contains only whitespace, the whole trailer will be removed from the output. This applies to existing trailers as well as new trailers. ++ +The default is `--no-trim-empty`. -`--trailer [(=|:)]`:: +`--trailer=[(=|:)]`:: +`--no-trailer`:: Specify a (__, __) pair that should be applied as a - trailer to the inputs. See the description of this - command. + trailer to the inputs. See the description of this command. Can + be given multiple times. ++ +Use `--no-trailer` to reset the list. -`--where `:: +`--where=`:: `--no-where`:: Specify where all new trailers will be added. A setting provided with `--where` overrides the `trailer.where` and any applicable `trailer..where` configuration variables and applies to all `--trailer` options until the next occurrence of - `--where` or `--no-where`. Upon encountering `--no-where`, clear the - effect of any previous use of `--where`, such that the relevant configuration - variables are no longer overridden. Possible placements are `after`, + `--where` or `--no-where`. Possible placements are `after`, `before`, `end` or `start`. ++ +Use `--no-where` to clear the effect of any previous use of `--where`, +such that the relevant configuration variables are no longer overridden. -`--if-exists `:: +`--if-exists=`:: `--no-if-exists`:: Specify what action will be performed when there is already at least one trailer with the same __ in the input. A setting provided with `--if-exists` overrides the `trailer.ifExists` and any applicable `trailer..ifExists` configuration variables and applies to all `--trailer` options until the next occurrence of - `--if-exists` or `--no-if-exists`. Upon encountering `--no-if-exists`, clear the - effect of any previous use of `--if-exists`, such that the relevant configuration - variables are no longer overridden. Possible actions are `addIfDifferent`, + `--if-exists` or `--no-if-exists`. Possible actions are `addIfDifferent`, `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`. ++ +Use `--no-if-exists` to clear the effect of any previous use of +`--if-exists`, such that the relevant configuration variables are no +longer overridden. -`--if-missing `:: +`--if-missing=`:: `--no-if-missing`:: Specify what action will be performed when there is no other trailer with the same __ in the input. A setting provided with `--if-missing` overrides the `trailer.ifMissing` and any applicable `trailer..ifMissing` configuration variables and applies to all `--trailer` options until the next occurrence of - `--if-missing` or `--no-if-missing`. Upon encountering `--no-if-missing`, - clear the effect of any previous use of `--if-missing`, such that the relevant - configuration variables are no longer overridden. Possible actions are `doNothing` - or `add`. + `--if-missing` or `--no-if-missing`. Possible actions are + `doNothing` or `add`. ++ +Use `--no-if-missing` to clear the effect of any previous use of +`--if-missing`, such that the relevant configuration variables are no +longer overridden. `--only-trailers`:: - Output only the trailers, not any other parts of the input. +`--no-only-trailers`:: + Output only the trailers, not any other parts of the + input. The default is `--no-only-trailers`. `--only-input`:: +`--no-only-input`:: Output only trailers that exist in the input; do not add any from the command-line or by applying `trailer.` configuration - variables. + variables. The default is `--no-only-input`. `--unfold`:: +`--no-unfold`:: If a trailer has a value that runs over multiple lines (aka "folded"), - reformat the value into a single line. + reformat the value into a single line. The default is `--no-unfold`. `--parse`:: A convenience alias for `--only-trailers --only-input @@ -178,11 +194,15 @@ OPTIONS input without influencing them with any command line options or configuration variables, while also making the output machine-friendly with `--unfold`. ++ +There is no convenience alias to negate this alias. +`--divider`:: `--no-divider`:: - Do not treat `---` as the end of the commit message. Use this - when you know your input contains just the commit message itself - (and not an email or the output of linkgit:git-format-patch[1]). + Treat `---` as the end of the commit message. This is the default. + Use `--no-divider` when you know your input contains just the + commit message itself (and not an email or the output of + linkgit:git-format-patch[1]). CONFIGURATION VARIABLES ----------------------- From 95bd86772eae65917fe5723ed89ee86c76907ef9 Mon Sep 17 00:00:00 2001 From: Kristoffer Haugsbakk Date: Mon, 16 Mar 2026 22:48:26 +0100 Subject: [PATCH 04/21] doc: config: convert trailers section to synopsis style Convert this part of the configuration documentation to synopsis style so that all of git-interpret-trailers(1) is consistent. See the commit message from two commits ago. Signed-off-by: Kristoffer Haugsbakk Signed-off-by: Junio C Hamano --- Documentation/config/trailer.adoc | 121 +++++++++++++++--------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/Documentation/config/trailer.adoc b/Documentation/config/trailer.adoc index 60bc221c88b801..1bc70192d3a547 100644 --- a/Documentation/config/trailer.adoc +++ b/Documentation/config/trailer.adoc @@ -1,21 +1,21 @@ -trailer.separators:: +`trailer.separators`:: This option tells which characters are recognized as trailer - separators. By default only ':' is recognized as a trailer - separator, except that '=' is always accepted on the command + separators. By default only `:` is recognized as a trailer + separator, except that `=` is always accepted on the command line for compatibility with other git commands. + The first character given by this option will be the default character used when another separator is not specified in the config for this trailer. + -For example, if the value for this option is "%=$", then only lines -using the format '' with containing '%', '=' -or '$' and then spaces will be considered trailers. And '%' will be +For example, if the value for this option is `%=$`, then only lines +using the format __ with __ containing `%`, `=` +or `$` and then spaces will be considered trailers. And `%` will be the default separator used, so by default trailers will appear like: -'% ' (one percent sign and one space will appear between +`% ` (one percent sign and one space will appear between the key and the value). -trailer.where:: +`trailer.where`:: This option tells where a new trailer will be added. + This can be `end`, which is the default, `start`, `after` or `before`. @@ -27,41 +27,41 @@ If it is `start`, then each new trailer will appear at the start, instead of the end, of the existing trailers. + If it is `after`, then each new trailer will appear just after the -last trailer with the same . +last trailer with the same __. + If it is `before`, then each new trailer will appear just before the -first trailer with the same . +first trailer with the same __. -trailer.ifexists:: +`trailer.ifexists`:: This option makes it possible to choose what action will be performed when there is already at least one trailer with the - same in the input. + same __ in the input. + The valid values for this option are: `addIfDifferentNeighbor` (this is the default), `addIfDifferent`, `add`, `replace` or `doNothing`. + With `addIfDifferentNeighbor`, a new trailer will be added only if no -trailer with the same (, ) pair is above or below the line +trailer with the same (__, __) pair is above or below the line where the new trailer will be added. + With `addIfDifferent`, a new trailer will be added only if no trailer -with the same (, ) pair is already in the input. +with the same (__, __) pair is already in the input. + With `add`, a new trailer will be added, even if some trailers with -the same (, ) pair are already in the input. +the same (__, __) pair are already in the input. + -With `replace`, an existing trailer with the same will be +With `replace`, an existing trailer with the same __ will be deleted and the new trailer will be added. The deleted trailer will be -the closest one (with the same ) to the place where the new one +the closest one (with the same __) to the place where the new one will be added. + With `doNothing`, nothing will be done; that is no new trailer will be -added if there is already one with the same in the input. +added if there is already one with the same __ in the input. -trailer.ifmissing:: +`trailer.ifmissing`:: This option makes it possible to choose what action will be performed when there is not yet any trailer with the same - in the input. + __ in the input. + The valid values for this option are: `add` (this is the default) and `doNothing`. @@ -70,67 +70,68 @@ With `add`, a new trailer will be added. + With `doNothing`, nothing will be done. -trailer..key:: - Defines a for the . The must be a - prefix (case does not matter) of the . For example, in `git - config trailer.ack.key "Acked-by"` the "Acked-by" is the and - the "ack" is the . This configuration allows the shorter +`trailer..key`:: + Defines a __ for the __. The __ must be a + prefix (case does not matter) of the __. For example, in `git + config trailer.ack.key "Acked-by"` the `Acked-by` is the __ and + the `ack` is the __. This configuration allows the shorter `--trailer "ack:..."` invocation on the command line using the "ack" - instead of the longer `--trailer "Acked-by:..."`. + `` instead of the longer `--trailer "Acked-by:..."`. + -At the end of the , a separator can appear and then some -space characters. By default the only valid separator is ':', +At the end of the __, a separator can appear and then some +space characters. By default the only valid separator is `:`, but this can be changed using the `trailer.separators` config variable. + If there is a separator in the key, then it overrides the default separator when adding the trailer. -trailer..where:: - This option takes the same values as the 'trailer.where' +`trailer..where`:: + This option takes the same values as the `trailer.where` configuration variable and it overrides what is specified by - that option for trailers with the specified . + that option for trailers with the specified __. -trailer..ifexists:: - This option takes the same values as the 'trailer.ifexists' +`trailer..ifexists`:: + This option takes the same values as the `trailer.ifexists` configuration variable and it overrides what is specified by - that option for trailers with the specified . + that option for trailers with the specified __. -trailer..ifmissing:: - This option takes the same values as the 'trailer.ifmissing' +`trailer..ifmissing`:: + This option takes the same values as the `trailer.ifmissing` configuration variable and it overrides what is specified by - that option for trailers with the specified . + that option for trailers with the specified __. -trailer..command:: - Deprecated in favor of 'trailer..cmd'. - This option behaves in the same way as 'trailer..cmd', except +`trailer..command`:: + Deprecated in favor of `trailer..cmd`. + This option behaves in the same way as `trailer..cmd`, except that it doesn't pass anything as argument to the specified command. - Instead the first occurrence of substring $ARG is replaced by the - that would be passed as argument. + Instead the first occurrence of substring `$ARG` is replaced by the + __ that would be passed as argument. + -Note that $ARG in the user's command is -only replaced once and that the original way of replacing $ARG is not safe. +Note that `$ARG` in the user's command is +only replaced once and that the original way of replacing `$ARG` is not safe. + -When both 'trailer..cmd' and 'trailer..command' are given -for the same , 'trailer..cmd' is used and -'trailer..command' is ignored. +When both `trailer..cmd` and `trailer..command` are given +for the same __, `trailer..cmd` is used and +`trailer..command` is ignored. -trailer..cmd:: +`trailer..cmd`:: This option can be used to specify a shell command that will be called - once to automatically add a trailer with the specified , and then - called each time a '--trailer =' argument is specified to - modify the of the trailer that this option would produce. + once to automatically add a trailer with the specified __, and then + called each time a `--trailer =` argument is specified to + modify the __ of the trailer that this option would produce. + When the specified command is first called to add a trailer -with the specified , the behavior is as if a special -'--trailer =' argument was added at the beginning -of the "git interpret-trailers" command, where -is taken to be the standard output of the command with any -leading and trailing whitespace trimmed off. +with the specified __, the behavior is as if a special +`--trailer =` argument was added at the beginning +of linkgit:git-interpret-trailers[1], where __ is taken to be the +standard output of the command with any leading and trailing whitespace +trimmed off. + -If some '--trailer =' arguments are also passed +If some `--trailer =` arguments are also passed on the command line, the command is called again once for each -of these arguments with the same . And the part +of these arguments with the same __. And the __ part of these arguments, if any, will be passed to the command as its -first argument. This way the command can produce a computed -from the passed in the '--trailer =' argument. +first argument. This way the command can produce a __ computed +from the __ passed in the `--trailer =` +argument. From 37182267a051906d7c625fd134c041297e757b3e Mon Sep 17 00:00:00 2001 From: Kristoffer Haugsbakk Date: Mon, 16 Mar 2026 22:48:27 +0100 Subject: [PATCH 05/21] interpret-trailers: use placeholder instead of * Use `` instead of `*` in order to be consistent with the documentation. Signed-off-by: Kristoffer Haugsbakk Signed-off-by: Junio C Hamano --- builtin/interpret-trailers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 41b0750e5af324..4b617c3ecb0c55 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -211,7 +211,7 @@ int cmd_interpret_trailers(int argc, N_("action if trailer is missing"), option_parse_if_missing), OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")), - OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply trailer.* configuration variables")), + OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply trailer. configuration variables")), OPT_BOOL(0, "unfold", &opts.unfold, N_("reformat multiline trailer values as single-line values")), OPT_CALLBACK_F(0, "parse", &opts, NULL, N_("alias for --only-trailers --only-input --unfold"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_parse), From 60d8c1e97d62c27ef60db0bc3d5deadd6dfdb98d Mon Sep 17 00:00:00 2001 From: Eric Ju Date: Mon, 16 Mar 2026 22:36:24 -0400 Subject: [PATCH 06/21] refs: add 'preparing' phase to the reference-transaction hook The "reference-transaction" hook is invoked multiple times during a ref transaction. Each invocation corresponds to a different phase: - The "prepared" phase indicates that references have been locked. - The "committed" phase indicates that all updates have been written to disk. - The "aborted" phase indicates that the transaction has been aborted and that all changes have been rolled back. This hook can be used to learn about the updates that Git wants to perform. For example, forges use it to coordinate reference updates across multiple nodes. However, the phases are insufficient for some specific use cases. The earliest observable phase in the "reference-transaction" hook is "prepared", at which point Git has already taken exclusive locks on every affected reference. This makes it suitable for last-chance validation, but not for serialization. So by the time a hook sees the "prepared" phase, it has no way to defer locking, and thus it cannot rearrange multiple concurrent ref transactions relative to one another. Introduce a new "preparing" phase that runs before the "prepared" phase, that is before Git acquires any reference lock on disk. This gives callers a well-defined window to perform validation, enable higher-level ordering of concurrent transactions, or reject the transaction entirely, all without interfering with the locking state. This change is strictly speaking not backwards compatible. Existing hook scripts that do not know how to handle unknown phases may treat 'preparing' as an error and return non-zero. But the hook is considered to expose internal implementation details of how Git works, and as such we have been a bit more lenient with changing its exact semantics, like for example in a8ae923f85 (refs: support symrefs in 'reference-transaction' hook, 2024-05-07). An alternative would be to introduce a "reference-transaction-v2" hook that knows about the new phase. This feels like a rather heavy-weight option though, and was thus discarded. Helped-by: Patrick Steinhardt Helped-by: Justin Tobler Helped-by: Karthik Nayak Signed-off-by: Eric Ju Signed-off-by: Junio C Hamano --- Documentation/githooks.adoc | 19 ++++++++++++------- refs.c | 12 +++++++++++- t/t1416-ref-transaction-hooks.sh | 30 ++++++++++++++++++++++++++---- t/t5510-fetch.sh | 7 ++++++- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Documentation/githooks.adoc b/Documentation/githooks.adoc index 056553788d4f43..ed045940d18ba5 100644 --- a/Documentation/githooks.adoc +++ b/Documentation/githooks.adoc @@ -484,13 +484,16 @@ reference-transaction ~~~~~~~~~~~~~~~~~~~~~ This hook is invoked by any Git command that performs reference -updates. It executes whenever a reference transaction is prepared, -committed or aborted and may thus get called multiple times. The hook -also supports symbolic reference updates. +updates. It executes whenever a reference transaction is preparing, +prepared, committed or aborted and may thus get called multiple times. +The hook also supports symbolic reference updates. The hook takes exactly one argument, which is the current state the given reference transaction is in: + - "preparing": All reference updates have been queued to the + transaction but references are not yet locked on disk. + - "prepared": All reference updates have been queued to the transaction and references were locked on disk. @@ -511,16 +514,18 @@ ref and `` is the full name of the ref. When force updating the reference regardless of its current value or when the reference is to be created anew, `` is the all-zeroes object name. To distinguish these cases, you can inspect the current value of -`` via `git rev-parse`. +`` via `git rev-parse`. During the "preparing" state, symbolic +references are not resolved: `` will reflect the symbolic reference +itself rather than the object it points to. For symbolic reference updates the `` and `` fields could denote references instead of objects. A reference will be denoted with a 'ref:' prefix, like `ref:`. The exit status of the hook is ignored for any state except for the -"prepared" state. In the "prepared" state, a non-zero exit status will -cause the transaction to be aborted. The hook will not be called with -"aborted" state in that case. +"preparing" and "prepared" states. In these states, a non-zero exit +status will cause the transaction to be aborted. The hook will not be +called with "aborted" state in that case. push-to-checkout ~~~~~~~~~~~~~~~~ diff --git a/refs.c b/refs.c index 6fb8f9d10c9800..e66cf4861d7ec5 100644 --- a/refs.c +++ b/refs.c @@ -64,6 +64,9 @@ const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_forma return be->name; } +static const char *abort_by_ref_transaction_hook = + N_("in '%s' phase, update aborted by the reference-transaction hook"); + /* * How to handle various characters in refnames: * 0: An acceptable character for refs @@ -2655,6 +2658,13 @@ int ref_transaction_prepare(struct ref_transaction *transaction, if (ref_update_reject_duplicates(&transaction->refnames, err)) return REF_TRANSACTION_ERROR_GENERIC; + /* Preparing checks before locking references */ + ret = run_transaction_hook(transaction, "preparing"); + if (ret) { + ref_transaction_abort(transaction, err); + die(_(abort_by_ref_transaction_hook), "preparing"); + } + ret = refs->be->transaction_prepare(refs, transaction, err); if (ret) return ret; @@ -2662,7 +2672,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction, ret = run_transaction_hook(transaction, "prepared"); if (ret) { ref_transaction_abort(transaction, err); - die(_("ref updates aborted by hook")); + die(_(abort_by_ref_transaction_hook), "prepared"); } return 0; diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index d91dd3a3b55e46..4fe9d9b23465ab 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -20,6 +20,7 @@ test_expect_success 'hook allows updating ref if successful' ' echo "$*" >>actual EOF cat >expect <<-EOF && + preparing prepared committed EOF @@ -27,6 +28,18 @@ test_expect_success 'hook allows updating ref if successful' ' test_cmp expect actual ' +test_expect_success 'hook aborts updating ref in preparing state' ' + git reset --hard PRE && + test_hook reference-transaction <<-\EOF && + if test "$1" = preparing + then + exit 1 + fi + EOF + test_must_fail git update-ref HEAD POST 2>err && + test_grep "in '\''preparing'\'' phase, update aborted by the reference-transaction hook" err +' + test_expect_success 'hook aborts updating ref in prepared state' ' git reset --hard PRE && test_hook reference-transaction <<-\EOF && @@ -36,7 +49,7 @@ test_expect_success 'hook aborts updating ref in prepared state' ' fi EOF test_must_fail git update-ref HEAD POST 2>err && - test_grep "ref updates aborted by hook" err + test_grep "in '\''prepared'\'' phase, update aborted by the reference-transaction hook" err ' test_expect_success 'hook gets all queued updates in prepared state' ' @@ -121,6 +134,7 @@ test_expect_success 'interleaving hook calls succeed' ' cat >expect <<-EOF && hooks/update refs/tags/PRE $ZERO_OID $PRE_OID hooks/update refs/tags/POST $ZERO_OID $POST_OID + hooks/reference-transaction preparing hooks/reference-transaction prepared hooks/reference-transaction committed EOF @@ -143,6 +157,8 @@ test_expect_success 'hook captures git-symbolic-ref updates' ' git symbolic-ref refs/heads/symref refs/heads/main && cat >expect <<-EOF && + preparing + $ZERO_OID ref:refs/heads/main refs/heads/symref prepared $ZERO_OID ref:refs/heads/main refs/heads/symref committed @@ -171,14 +187,20 @@ test_expect_success 'hook gets all queued symref updates' ' # In the files backend, "delete" also triggers an additional transaction # update on the packed-refs backend, which constitutes additional reflog # entries. + cat >expect <<-EOF && + preparing + ref:refs/heads/main $ZERO_OID refs/heads/symref + ref:refs/heads/main $ZERO_OID refs/heads/symrefd + $ZERO_OID ref:refs/heads/main refs/heads/symrefc + ref:refs/heads/main ref:refs/heads/branch refs/heads/symrefu + EOF + if test_have_prereq REFFILES then - cat >expect <<-EOF + cat >>expect <<-EOF aborted $ZERO_OID $ZERO_OID refs/heads/symrefd EOF - else - >expect fi && cat >>expect <<-EOF && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 5dcb4b51a47d88..6fe21e2b3a6b1b 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -469,12 +469,17 @@ test_expect_success 'fetch --atomic executes a single reference transaction only head_oid=$(git rev-parse HEAD) && cat >expected <<-EOF && + preparing + $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1 + $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2 prepared $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2 committed $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2 + preparing + $ZERO_OID ref:refs/remotes/origin/main refs/remotes/origin/HEAD EOF rm -f atomic/actual && @@ -497,7 +502,7 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' head_oid=$(git rev-parse HEAD) && cat >expected <<-EOF && - prepared + preparing $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3 From 1ae7a359ae53e98f153b8fb0dea532d2007a0093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 17 Mar 2026 22:40:07 +0100 Subject: [PATCH 07/21] use commit_stack instead of prio_queue in LIFO mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A prio_queue with a NULL compare function acts as a stack -- the last element in is the first one out (LIFO). Use an actual commit_stack instead where possible, as it documents the behavior better, provides type safety and saves some memory because prio_queue stores an additional tie-breaking counter per element. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- builtin/name-rev.c | 16 +++++++--------- negotiator/default.c | 10 +++++----- negotiator/skipping.c | 10 +++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 6188cf98ce0157..d6594ada53f49d 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -12,7 +12,6 @@ #include "object-name.h" #include "pager.h" #include "parse-options.h" -#include "prio-queue.h" #include "hash-lookup.h" #include "commit-slab.h" #include "commit-graph.h" @@ -178,7 +177,7 @@ static void name_rev(struct commit *start_commit, const char *tip_name, timestamp_t taggerdate, int from_tag, int deref, struct mem_pool *string_pool) { - struct prio_queue queue; + struct commit_stack stack = COMMIT_STACK_INIT; struct commit *commit; struct commit_stack parents_to_queue = COMMIT_STACK_INIT; struct rev_name *start_name; @@ -197,10 +196,9 @@ static void name_rev(struct commit *start_commit, else start_name->tip_name = mem_pool_strdup(string_pool, tip_name); - memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */ - prio_queue_put(&queue, start_commit); + commit_stack_push(&stack, start_commit); - while ((commit = prio_queue_get(&queue))) { + while ((commit = commit_stack_pop(&stack))) { struct rev_name *name = get_commit_rev_name(commit); struct commit_list *parents; int parent_number = 1; @@ -241,13 +239,13 @@ static void name_rev(struct commit *start_commit, } } - /* The first parent must come out first from the prio_queue */ + /* The first parent must come out first from the stack */ while (parents_to_queue.nr) - prio_queue_put(&queue, - commit_stack_pop(&parents_to_queue)); + commit_stack_push(&stack, + commit_stack_pop(&parents_to_queue)); } - clear_prio_queue(&queue); + commit_stack_clear(&stack); commit_stack_clear(&parents_to_queue); } diff --git a/negotiator/default.c b/negotiator/default.c index 116dedcf83035d..3cac0476a7bc2e 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -57,19 +57,19 @@ static int clear_marks(const struct reference *ref, void *cb_data UNUSED) static void mark_common(struct negotiation_state *ns, struct commit *commit, int ancestors_only, int dont_parse) { - struct prio_queue queue = { NULL }; + struct commit_stack stack = COMMIT_STACK_INIT; if (!commit || (commit->object.flags & COMMON)) return; - prio_queue_put(&queue, commit); + commit_stack_push(&stack, commit); if (!ancestors_only) { commit->object.flags |= COMMON; if ((commit->object.flags & SEEN) && !(commit->object.flags & POPPED)) ns->non_common_revs--; } - while ((commit = prio_queue_get(&queue))) { + while ((commit = commit_stack_pop(&stack))) { struct object *o = (struct object *)commit; if (!(o->flags & SEEN)) @@ -94,12 +94,12 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit, if ((p->object.flags & SEEN) && !(p->object.flags & POPPED)) ns->non_common_revs--; - prio_queue_put(&queue, parents->item); + commit_stack_push(&stack, parents->item); } } } - clear_prio_queue(&queue); + commit_stack_clear(&stack); } /* diff --git a/negotiator/skipping.c b/negotiator/skipping.c index 0a272130fb1b6d..fe4126ca4d2aaa 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -91,15 +91,15 @@ static int clear_marks(const struct reference *ref, void *cb_data UNUSED) */ static void mark_common(struct data *data, struct commit *seen_commit) { - struct prio_queue queue = { NULL }; + struct commit_stack stack = COMMIT_STACK_INIT; struct commit *c; if (seen_commit->object.flags & COMMON) return; - prio_queue_put(&queue, seen_commit); + commit_stack_push(&stack, seen_commit); seen_commit->object.flags |= COMMON; - while ((c = prio_queue_get(&queue))) { + while ((c = commit_stack_pop(&stack))) { struct commit_list *p; if (!(c->object.flags & POPPED)) @@ -113,11 +113,11 @@ static void mark_common(struct data *data, struct commit *seen_commit) continue; p->item->object.flags |= COMMON; - prio_queue_put(&queue, p->item); + commit_stack_push(&stack, p->item); } } - clear_prio_queue(&queue); + commit_stack_clear(&stack); } /* From 57246b7c626c18bad5f7a36b9479dea58b73242d Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Wed, 11 Mar 2026 06:44:06 +0000 Subject: [PATCH 08/21] merge-file: fix BUG when --object-id is used in a worktree The `--object-id` option was added in commit e1068f0ad4 (merge-file: add an option to process object IDs, 2023-11-01) together with a call to setup_git_directory() to avoid crashing when run outside a repository. However, the call to setup_git_directory() is redundant when run inside a repository, as merge-file runs with RUN_SETUP_GENTLY, so the repository has already been set up. The redundant call is harmless when linked worktrees are not used, but in a linked worktree, the repo_set_gitdir() function ends up being called twice. Calling repo_set_gitdir() used to be silently accepted, but commit 2816b748e5 (odb: handle changing a repository's commondir, 2025-11-19) changed this to a BUG in repository.c with the error message: "cannot reinitialize an already-initialized object directory". Guard the redundant call to setup_git_directory() behind a repo pointer check, to ensure that we continue to give the correct "not a git repo" error whilst avoiding the BUG when running in a linked worktree. Signed-off-by: Mathias Rav Signed-off-by: Junio C Hamano --- builtin/merge-file.c | 5 +++-- t/t6403-merge-file.sh | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 46775d0c79f454..cc8fda3b5b7c15 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -60,7 +60,7 @@ static int diff_algorithm_cb(const struct option *opt, int cmd_merge_file(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { const char *names[3] = { 0 }; mmfile_t mmfs[3] = { 0 }; @@ -110,7 +110,8 @@ int cmd_merge_file(int argc, return error_errno("failed to redirect stderr to /dev/null"); } - if (object_id) + if (!repo && object_id) + /* emit the correct "not a git repo" error in this case */ setup_git_directory(); for (i = 0; i < 3; i++) { diff --git a/t/t6403-merge-file.sh b/t/t6403-merge-file.sh index 06ab4d7aede081..ed7eec8f93cd02 100755 --- a/t/t6403-merge-file.sh +++ b/t/t6403-merge-file.sh @@ -506,6 +506,15 @@ test_expect_success '--object-id fails without repository' ' grep "not a git repository" err ' +test_expect_success 'run in a linked worktree with --object-id' ' + empty="$(test_oid empty_blob)" && + git worktree add work && + git -C work merge-file --object-id $empty $empty $empty >actual && + git worktree remove work && + git merge-file --object-id $empty $empty $empty >expected && + test_cmp actual expected +' + test_expect_success 'merging C files with "myers" diff algorithm creates some spurious conflicts' ' cat >expect.c <<-\EOF && int g(size_t u) From fc8a4f15e76ba986707dd0257ed0cc84c009f267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20=E2=80=9Cgabldotink=E2=80=9D?= Date: Wed, 18 Mar 2026 15:00:19 -0600 Subject: [PATCH 09/21] doc: add missing space on git-config page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel “gabldotink” Signed-off-by: Junio C Hamano --- Documentation/git-config.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-config.adoc b/Documentation/git-config.adoc index 936e0c5130fe7d..7bb28b60ec8d6a 100644 --- a/Documentation/git-config.adoc +++ b/Documentation/git-config.adoc @@ -213,7 +213,7 @@ See also <>. + Valid ``'s include: + -- 'bool': canonicalize values `true`, `yes`,`on`, and positive +- 'bool': canonicalize values `true`, `yes`, `on`, and positive numbers as "true", and values `false`, `no`, `off` and `0` as "false". - 'int': canonicalize values as simple decimal numbers. An optional suffix of From 8872941fd21e2afe37032e7d9beec87b69aca9c9 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:20 +0100 Subject: [PATCH 10/21] Introduce new "tools/" directory According to its readme, the "contrib/" directory's main intent is to collect stuff that is not an official part of Git, either because it is too specialized or because it is still considered experimental. The reality tells a bit of a different story though: while it _does_ contain such things, it also contains other things: - Our credential helpers, which are being distributed by many packagers nowadays and which can be considered "stable". - A bunch of tooling that relates to our build and test infrastructure. Especially the second category is somewhat of a sore spot. You really wouldn't expect build-related tooling to be considered an optional part of Git. Quite the opposite. Create a new top-level "tools/" directory to fix this discrepancy. This directory will contain all kind of tools that are related to our build infrastructure and that Git developers are likely to use day to day. For now, this directory doesn't contain anything yet except for a readme and a Meson skeleton. This will change in subsequent commits. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- Makefile | 2 ++ meson.build | 1 + tools/README.md | 7 +++++++ tools/meson.build | 0 4 files changed, 10 insertions(+) create mode 100644 tools/README.md create mode 100644 tools/meson.build diff --git a/Makefile b/Makefile index f3264d0a37cc50..c7cedbcd7cc31c 100644 --- a/Makefile +++ b/Makefile @@ -1066,11 +1066,13 @@ SOURCES_CMD = ( \ '*.sh' \ ':!*[tp][0-9][0-9][0-9][0-9]*' \ ':!contrib' \ + ':!tools' \ 2>/dev/null || \ $(FIND) . \ \( -name .git -type d -prune \) \ -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \ -o \( -name contrib -type d -prune \) \ + -o \( -name tools -type d -prune \) \ -o \( -name build -type d -prune \) \ -o \( -name .build -type d -prune \) \ -o \( -name 'trash*' -type d -prune \) \ diff --git a/meson.build b/meson.build index 4b536e012481ca..1d66b5181e97b6 100644 --- a/meson.build +++ b/meson.build @@ -2149,6 +2149,7 @@ else endif subdir('contrib') +subdir('tools') # Note that the target is intentionally configured after including the # 'contrib' directory, as some tool there also have their own manpages. diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 00000000000000..d7329971365cb3 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,7 @@ +Developer Tooling +----------------- + +This directory is expected to contain all sorts of tooling that +relates to our build infrastructure. This includes scripts and +inputs required by our build systems, but also scripts that +developers are expected to run manually. diff --git a/tools/meson.build b/tools/meson.build new file mode 100644 index 00000000000000..e69de29bb2d1d6 From 8ca1b4472ce97ae1d120608f9f02a86fa33d4187 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:21 +0100 Subject: [PATCH 11/21] contrib: move "coccinelle/" directory into "tools/" The Coccinelle tool is an ingrained part of our build infrastructure. It is executed by our CI to detect antipatterns and is used to detect misuses of certain interfaces. It's presence in "contrib/" is thus rather misleading. Promote the configuration into the new "tools/" directory. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- Makefile | 40 +++++++++---------- ci/run-static-analysis.sh | 2 +- contrib/meson.build | 1 - {contrib => tools}/coccinelle/.gitignore | 0 {contrib => tools}/coccinelle/README | 2 +- {contrib => tools}/coccinelle/array.cocci | 0 {contrib => tools}/coccinelle/commit.cocci | 0 .../coccinelle/config_fn_ctx.pending.cocci | 0 .../coccinelle/equals-null.cocci | 0 .../coccinelle/flex_alloc.cocci | 0 {contrib => tools}/coccinelle/free.cocci | 0 .../coccinelle/git_config_number.cocci | 0 {contrib => tools}/coccinelle/hashmap.cocci | 0 .../coccinelle/index-compatibility.cocci | 0 {contrib => tools}/coccinelle/meson.build | 0 {contrib => tools}/coccinelle/object_id.cocci | 0 {contrib => tools}/coccinelle/preincr.cocci | 0 {contrib => tools}/coccinelle/qsort.cocci | 0 {contrib => tools}/coccinelle/refs.cocci | 0 {contrib => tools}/coccinelle/spatchcache | 6 +-- {contrib => tools}/coccinelle/strbuf.cocci | 0 {contrib => tools}/coccinelle/swap.cocci | 0 {contrib => tools}/coccinelle/tests/free.c | 0 {contrib => tools}/coccinelle/tests/free.res | 0 .../coccinelle/the_repository.cocci | 0 {contrib => tools}/coccinelle/xcalloc.cocci | 0 {contrib => tools}/coccinelle/xopen.cocci | 0 .../coccinelle/xstrdup_or_null.cocci | 0 {contrib => tools}/coccinelle/xstrncmpz.cocci | 0 tools/meson.build | 1 + 30 files changed, 26 insertions(+), 26 deletions(-) rename {contrib => tools}/coccinelle/.gitignore (100%) rename {contrib => tools}/coccinelle/README (98%) rename {contrib => tools}/coccinelle/array.cocci (100%) rename {contrib => tools}/coccinelle/commit.cocci (100%) rename {contrib => tools}/coccinelle/config_fn_ctx.pending.cocci (100%) rename {contrib => tools}/coccinelle/equals-null.cocci (100%) rename {contrib => tools}/coccinelle/flex_alloc.cocci (100%) rename {contrib => tools}/coccinelle/free.cocci (100%) rename {contrib => tools}/coccinelle/git_config_number.cocci (100%) rename {contrib => tools}/coccinelle/hashmap.cocci (100%) rename {contrib => tools}/coccinelle/index-compatibility.cocci (100%) rename {contrib => tools}/coccinelle/meson.build (100%) rename {contrib => tools}/coccinelle/object_id.cocci (100%) rename {contrib => tools}/coccinelle/preincr.cocci (100%) rename {contrib => tools}/coccinelle/qsort.cocci (100%) rename {contrib => tools}/coccinelle/refs.cocci (100%) rename {contrib => tools}/coccinelle/spatchcache (97%) rename {contrib => tools}/coccinelle/strbuf.cocci (100%) rename {contrib => tools}/coccinelle/swap.cocci (100%) rename {contrib => tools}/coccinelle/tests/free.c (100%) rename {contrib => tools}/coccinelle/tests/free.res (100%) rename {contrib => tools}/coccinelle/the_repository.cocci (100%) rename {contrib => tools}/coccinelle/xcalloc.cocci (100%) rename {contrib => tools}/coccinelle/xopen.cocci (100%) rename {contrib => tools}/coccinelle/xstrdup_or_null.cocci (100%) rename {contrib => tools}/coccinelle/xstrncmpz.cocci (100%) diff --git a/Makefile b/Makefile index c7cedbcd7cc31c..8564b1be369cae 100644 --- a/Makefile +++ b/Makefile @@ -1005,8 +1005,8 @@ SPATCH_TEST_FLAGS = # COMPUTE_HEADER_DEPENDENCIES=no this will be unset too. SPATCH_USE_O_DEPENDENCIES = YesPlease -# Set SPATCH_CONCAT_COCCI to concatenate the contrib/cocci/*.cocci -# files into a single contrib/cocci/ALL.cocci before running +# Set SPATCH_CONCAT_COCCI to concatenate the tools/coccinelle/*.cocci +# files into a single tools/coccinelle/ALL.cocci before running # "coccicheck". # # Pros: @@ -1025,7 +1025,7 @@ SPATCH_USE_O_DEPENDENCIES = YesPlease # generate a specific patch, e.g. this will always use strbuf.cocci, # not ALL.cocci: # -# make contrib/coccinelle/strbuf.cocci.patch +# make tools/coccinelle/strbuf.cocci.patch SPATCH_CONCAT_COCCI = YesPlease # Rebuild 'coccicheck' if $(SPATCH), its flags etc. change @@ -3457,15 +3457,15 @@ check: exit 1; \ fi -COCCI_GEN_ALL = .build/contrib/coccinelle/ALL.cocci -COCCI_GLOB = $(wildcard contrib/coccinelle/*.cocci) +COCCI_GEN_ALL = .build/tools/coccinelle/ALL.cocci +COCCI_GLOB = $(wildcard tools/coccinelle/*.cocci) COCCI_RULES_TRACKED = $(COCCI_GLOB:%=.build/%) COCCI_RULES_TRACKED_NO_PENDING = $(filter-out %.pending.cocci,$(COCCI_RULES_TRACKED)) COCCI_RULES = COCCI_RULES += $(COCCI_GEN_ALL) COCCI_RULES += $(COCCI_RULES_TRACKED) COCCI_NAMES = -COCCI_NAMES += $(COCCI_RULES:.build/contrib/coccinelle/%.cocci=%) +COCCI_NAMES += $(COCCI_RULES:.build/tools/coccinelle/%.cocci=%) COCCICHECK_PENDING = $(filter %.pending.cocci,$(COCCI_RULES)) COCCICHECK = $(filter-out $(COCCICHECK_PENDING),$(COCCI_RULES)) @@ -3480,20 +3480,20 @@ COCCICHECK_PATCHES_PENDING_INTREE = $(COCCICHECK_PATCHES_PENDING:.build/%=%) # on $(MAKECMDGOALS) that match these $(COCCI_RULES) COCCI_RULES_GLOB = COCCI_RULES_GLOB += cocci% -COCCI_RULES_GLOB += .build/contrib/coccinelle/% +COCCI_RULES_GLOB += .build/tools/coccinelle/% COCCI_RULES_GLOB += $(COCCICHECK_PATCHES) COCCI_RULES_GLOB += $(COCCICHEC_PATCHES_PENDING) COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_INTREE) COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_PENDING_INTREE) COCCI_GOALS = $(filter $(COCCI_RULES_GLOB),$(MAKECMDGOALS)) -COCCI_TEST_RES = $(wildcard contrib/coccinelle/tests/*.res) +COCCI_TEST_RES = $(wildcard tools/coccinelle/tests/*.res) $(COCCI_RULES_TRACKED): .build/% : % $(call mkdir_p_parent_template) $(QUIET_CP)cp $< $@ -.build/contrib/coccinelle/FOUND_H_SOURCES: $(FOUND_H_SOURCES) +.build/tools/coccinelle/FOUND_H_SOURCES: $(FOUND_H_SOURCES) $(call mkdir_p_parent_template) $(QUIET_GEN) >$@ @@ -3507,12 +3507,12 @@ endif define cocci-rule ## Rule for .build/$(1).patch/$(2); Params: -# $(1) = e.g. ".build/contrib/coccinelle/free.cocci" +# $(1) = e.g. ".build/tools/coccinelle/free.cocci" # $(2) = e.g. "grep.c" # $(3) = e.g. "grep.o" -COCCI_$(1:.build/contrib/coccinelle/%.cocci=%) += $(1).d/$(2).patch +COCCI_$(1:.build/tools/coccinelle/%.cocci=%) += $(1).d/$(2).patch $(1).d/$(2).patch: GIT-SPATCH-DEFINES -$(1).d/$(2).patch: $(if $(and $(SPATCH_USE_O_DEPENDENCIES),$(wildcard $(3))),$(3),.build/contrib/coccinelle/FOUND_H_SOURCES) +$(1).d/$(2).patch: $(if $(and $(SPATCH_USE_O_DEPENDENCIES),$(wildcard $(3))),$(3),.build/tools/coccinelle/FOUND_H_SOURCES) $(1).d/$(2).patch: $(1) $(1).d/$(2).patch: $(1).d/%.patch : % $$(call mkdir_p_parent_template) @@ -3538,13 +3538,13 @@ endif define spatch-rule -.build/contrib/coccinelle/$(1).cocci.patch: $$(COCCI_$(1)) +.build/tools/coccinelle/$(1).cocci.patch: $$(COCCI_$(1)) $$(QUIET_SPATCH_CAT)cat $$^ >$$@ && \ if test -s $$@; \ then \ echo ' ' SPATCH result: $$@; \ fi -contrib/coccinelle/$(1).cocci.patch: .build/contrib/coccinelle/$(1).cocci.patch +tools/coccinelle/$(1).cocci.patch: .build/tools/coccinelle/$(1).cocci.patch $$(QUIET_CP)cp $$< $$@ endef @@ -3558,9 +3558,9 @@ $(COCCI_TEST_RES_GEN): GIT-SPATCH-DEFINES $(COCCI_TEST_RES_GEN): .build/%.res : %.c $(COCCI_TEST_RES_GEN): .build/%.res : %.res ifdef SPATCH_CONCAT_COCCI -$(COCCI_TEST_RES_GEN): .build/contrib/coccinelle/tests/%.res : $(COCCI_GEN_ALL) +$(COCCI_TEST_RES_GEN): .build/tools/coccinelle/tests/%.res : $(COCCI_GEN_ALL) else -$(COCCI_TEST_RES_GEN): .build/contrib/coccinelle/tests/%.res : contrib/coccinelle/%.cocci +$(COCCI_TEST_RES_GEN): .build/tools/coccinelle/tests/%.res : tools/coccinelle/%.cocci endif $(call mkdir_p_parent_template) $(QUIET_SPATCH_TEST)$(SPATCH) $(SPATCH_TEST_FLAGS) \ @@ -3576,14 +3576,14 @@ coccicheck-test: $(COCCI_TEST_RES_GEN) coccicheck: coccicheck-test ifdef SPATCH_CONCAT_COCCI -COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = contrib/coccinelle/ALL.cocci.patch +COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = tools/coccinelle/ALL.cocci.patch else COCCICHECK_PATCH_MUST_BE_EMPTY_FILES = $(COCCICHECK_PATCHES_INTREE) endif coccicheck: $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES) ! grep ^ $(COCCICHECK_PATCH_MUST_BE_EMPTY_FILES) /dev/null -# See contrib/coccinelle/README +# See tools/coccinelle/README coccicheck-pending: coccicheck-test coccicheck-pending: $(COCCICHECK_PATCHES_PENDING_INTREE) @@ -3857,8 +3857,8 @@ profile-clean: cocciclean: $(RM) GIT-SPATCH-DEFINES - $(RM) -r .build/contrib/coccinelle - $(RM) contrib/coccinelle/*.cocci.patch + $(RM) -r .build/tools/coccinelle + $(RM) tools/coccinelle/*.cocci.patch clean: profile-clean coverage-clean cocciclean $(RM) -r .build $(UNIT_TEST_BIN) diff --git a/ci/run-static-analysis.sh b/ci/run-static-analysis.sh index 9e9c72681d5715..ba67e80b4db2d5 100755 --- a/ci/run-static-analysis.sh +++ b/ci/run-static-analysis.sh @@ -10,7 +10,7 @@ make coccicheck set +x fail= -for cocci_patch in contrib/coccinelle/*.patch +for cocci_patch in tools/coccinelle/*.patch do if test -s "$cocci_patch" then diff --git a/contrib/meson.build b/contrib/meson.build index a88c5dfe09ed62..569c23ee768bb8 100644 --- a/contrib/meson.build +++ b/contrib/meson.build @@ -2,5 +2,4 @@ foreach feature : get_option('contrib') subdir(feature) endforeach -subdir('coccinelle') subdir('credential') diff --git a/contrib/coccinelle/.gitignore b/tools/coccinelle/.gitignore similarity index 100% rename from contrib/coccinelle/.gitignore rename to tools/coccinelle/.gitignore diff --git a/contrib/coccinelle/README b/tools/coccinelle/README similarity index 98% rename from contrib/coccinelle/README rename to tools/coccinelle/README index 055ad0e06a70e2..fd0a543cc27f9e 100644 --- a/contrib/coccinelle/README +++ b/tools/coccinelle/README @@ -38,7 +38,7 @@ that might be useful to developers. So to aid these large scale refactorings, semantic patches can be used. However we do not want to store them in the same place as the checks for bad patterns, as then automated builds would fail. - That is why semantic patches 'contrib/coccinelle/*.pending.cocci' + That is why semantic patches 'tools/coccinelle/*.pending.cocci' are ignored for checks, and can be applied using 'make coccicheck-pending'. This allows to expose plans of pending large scale refactorings without diff --git a/contrib/coccinelle/array.cocci b/tools/coccinelle/array.cocci similarity index 100% rename from contrib/coccinelle/array.cocci rename to tools/coccinelle/array.cocci diff --git a/contrib/coccinelle/commit.cocci b/tools/coccinelle/commit.cocci similarity index 100% rename from contrib/coccinelle/commit.cocci rename to tools/coccinelle/commit.cocci diff --git a/contrib/coccinelle/config_fn_ctx.pending.cocci b/tools/coccinelle/config_fn_ctx.pending.cocci similarity index 100% rename from contrib/coccinelle/config_fn_ctx.pending.cocci rename to tools/coccinelle/config_fn_ctx.pending.cocci diff --git a/contrib/coccinelle/equals-null.cocci b/tools/coccinelle/equals-null.cocci similarity index 100% rename from contrib/coccinelle/equals-null.cocci rename to tools/coccinelle/equals-null.cocci diff --git a/contrib/coccinelle/flex_alloc.cocci b/tools/coccinelle/flex_alloc.cocci similarity index 100% rename from contrib/coccinelle/flex_alloc.cocci rename to tools/coccinelle/flex_alloc.cocci diff --git a/contrib/coccinelle/free.cocci b/tools/coccinelle/free.cocci similarity index 100% rename from contrib/coccinelle/free.cocci rename to tools/coccinelle/free.cocci diff --git a/contrib/coccinelle/git_config_number.cocci b/tools/coccinelle/git_config_number.cocci similarity index 100% rename from contrib/coccinelle/git_config_number.cocci rename to tools/coccinelle/git_config_number.cocci diff --git a/contrib/coccinelle/hashmap.cocci b/tools/coccinelle/hashmap.cocci similarity index 100% rename from contrib/coccinelle/hashmap.cocci rename to tools/coccinelle/hashmap.cocci diff --git a/contrib/coccinelle/index-compatibility.cocci b/tools/coccinelle/index-compatibility.cocci similarity index 100% rename from contrib/coccinelle/index-compatibility.cocci rename to tools/coccinelle/index-compatibility.cocci diff --git a/contrib/coccinelle/meson.build b/tools/coccinelle/meson.build similarity index 100% rename from contrib/coccinelle/meson.build rename to tools/coccinelle/meson.build diff --git a/contrib/coccinelle/object_id.cocci b/tools/coccinelle/object_id.cocci similarity index 100% rename from contrib/coccinelle/object_id.cocci rename to tools/coccinelle/object_id.cocci diff --git a/contrib/coccinelle/preincr.cocci b/tools/coccinelle/preincr.cocci similarity index 100% rename from contrib/coccinelle/preincr.cocci rename to tools/coccinelle/preincr.cocci diff --git a/contrib/coccinelle/qsort.cocci b/tools/coccinelle/qsort.cocci similarity index 100% rename from contrib/coccinelle/qsort.cocci rename to tools/coccinelle/qsort.cocci diff --git a/contrib/coccinelle/refs.cocci b/tools/coccinelle/refs.cocci similarity index 100% rename from contrib/coccinelle/refs.cocci rename to tools/coccinelle/refs.cocci diff --git a/contrib/coccinelle/spatchcache b/tools/coccinelle/spatchcache similarity index 97% rename from contrib/coccinelle/spatchcache rename to tools/coccinelle/spatchcache index 29e9352d8a278a..efbcbc3827115b 100755 --- a/contrib/coccinelle/spatchcache +++ b/tools/coccinelle/spatchcache @@ -30,7 +30,7 @@ # out of control. # # This along with the general incremental "make" support for -# "contrib/coccinelle" makes it viable to (re-)run coccicheck +# "tools/coccinelle" makes it viable to (re-)run coccicheck # e.g. when merging integration branches. # # Note that the "--very-quiet" flag is currently critical. The cache @@ -42,7 +42,7 @@ # to change, so just supply "--very-quiet" for now. # # To use this, simply set SPATCH to -# contrib/coccinelle/spatchcache. Then optionally set: +# tools/coccinelle/spatchcache. Then optionally set: # # [spatchCache] # # Optional: path to a custom spatch @@ -65,7 +65,7 @@ # # redis-cli FLUSHALL # -# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/contrib/coccinelle | sort | uniq -c +# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/tools/coccinelle | sort | uniq -c # 600 CANTCACHE # 7365 MISS # 7365 SET diff --git a/contrib/coccinelle/strbuf.cocci b/tools/coccinelle/strbuf.cocci similarity index 100% rename from contrib/coccinelle/strbuf.cocci rename to tools/coccinelle/strbuf.cocci diff --git a/contrib/coccinelle/swap.cocci b/tools/coccinelle/swap.cocci similarity index 100% rename from contrib/coccinelle/swap.cocci rename to tools/coccinelle/swap.cocci diff --git a/contrib/coccinelle/tests/free.c b/tools/coccinelle/tests/free.c similarity index 100% rename from contrib/coccinelle/tests/free.c rename to tools/coccinelle/tests/free.c diff --git a/contrib/coccinelle/tests/free.res b/tools/coccinelle/tests/free.res similarity index 100% rename from contrib/coccinelle/tests/free.res rename to tools/coccinelle/tests/free.res diff --git a/contrib/coccinelle/the_repository.cocci b/tools/coccinelle/the_repository.cocci similarity index 100% rename from contrib/coccinelle/the_repository.cocci rename to tools/coccinelle/the_repository.cocci diff --git a/contrib/coccinelle/xcalloc.cocci b/tools/coccinelle/xcalloc.cocci similarity index 100% rename from contrib/coccinelle/xcalloc.cocci rename to tools/coccinelle/xcalloc.cocci diff --git a/contrib/coccinelle/xopen.cocci b/tools/coccinelle/xopen.cocci similarity index 100% rename from contrib/coccinelle/xopen.cocci rename to tools/coccinelle/xopen.cocci diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/tools/coccinelle/xstrdup_or_null.cocci similarity index 100% rename from contrib/coccinelle/xstrdup_or_null.cocci rename to tools/coccinelle/xstrdup_or_null.cocci diff --git a/contrib/coccinelle/xstrncmpz.cocci b/tools/coccinelle/xstrncmpz.cocci similarity index 100% rename from contrib/coccinelle/xstrncmpz.cocci rename to tools/coccinelle/xstrncmpz.cocci diff --git a/tools/meson.build b/tools/meson.build index e69de29bb2d1d6..f731f74312f613 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -0,0 +1 @@ +subdir('coccinelle') From fe309664ea804d17812bab22927756dc35e5e955 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:22 +0100 Subject: [PATCH 12/21] contrib: move "coverage-diff.sh" script into "tools/" The "coverage-diff.sh" script can be used to get information about test coverage fro the Git codebase. It is thus rather specific to our build and test infrastructure and part of the developer-facing tooling. The fact that this script is part of "contrib/" is thus rather misleading and a historic wart. Promote the tool into the new "tools/" directory. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- {contrib => tools}/coverage-diff.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {contrib => tools}/coverage-diff.sh (100%) diff --git a/contrib/coverage-diff.sh b/tools/coverage-diff.sh similarity index 100% rename from contrib/coverage-diff.sh rename to tools/coverage-diff.sh From 405c98a6a0e017f41f5de9c649a8f6f1b3fc4314 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:23 +0100 Subject: [PATCH 13/21] contrib: move "update-unicode.sh" script into "tools/" The "update-unicode.sh" script is used to update the unicode data compiled into Git whenever a new version of the Unicode standard has been released. As such, it is a natural part of our developer-facing tooling, and its presence in "contrib/" is misleading. Promote the script into the new "tools/" directory. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- {contrib => tools}/update-unicode/.gitignore | 0 {contrib => tools}/update-unicode/README | 0 {contrib => tools}/update-unicode/update_unicode.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {contrib => tools}/update-unicode/.gitignore (100%) rename {contrib => tools}/update-unicode/README (100%) rename {contrib => tools}/update-unicode/update_unicode.sh (100%) diff --git a/contrib/update-unicode/.gitignore b/tools/update-unicode/.gitignore similarity index 100% rename from contrib/update-unicode/.gitignore rename to tools/update-unicode/.gitignore diff --git a/contrib/update-unicode/README b/tools/update-unicode/README similarity index 100% rename from contrib/update-unicode/README rename to tools/update-unicode/README diff --git a/contrib/update-unicode/update_unicode.sh b/tools/update-unicode/update_unicode.sh similarity index 100% rename from contrib/update-unicode/update_unicode.sh rename to tools/update-unicode/update_unicode.sh From a767f2fd6c5a6104ff32a35a27f0c15aec546957 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:24 +0100 Subject: [PATCH 14/21] builds: move build scripts into "tools/" We have a bunch of scripts used by our different build systems that are all located in the top-level directory. Now that we have introduced the new "tools/" directory though we have a better home for them. Move the scripts into the "tools/" directory. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- Makefile | 34 +++++++++---------- config.mak.dev | 2 +- contrib/buildsystems/CMakeLists.txt | 18 +++++----- contrib/subtree/meson.build | 2 +- meson.build | 14 ++++---- check-builtins.sh => tools/check-builtins.sh | 0 detect-compiler => tools/detect-compiler | 0 .../generate-cmdlist.sh | 0 .../generate-configlist.sh | 0 .../generate-hooklist.sh | 0 generate-perl.sh => tools/generate-perl.sh | 0 .../generate-python.sh | 0 .../generate-script.sh | 0 13 files changed, 35 insertions(+), 35 deletions(-) rename check-builtins.sh => tools/check-builtins.sh (100%) rename detect-compiler => tools/detect-compiler (100%) rename generate-cmdlist.sh => tools/generate-cmdlist.sh (100%) rename generate-configlist.sh => tools/generate-configlist.sh (100%) rename generate-hooklist.sh => tools/generate-hooklist.sh (100%) rename generate-perl.sh => tools/generate-perl.sh (100%) rename generate-python.sh => tools/generate-python.sh (100%) rename generate-script.sh => tools/generate-script.sh (100%) diff --git a/Makefile b/Makefile index 8564b1be369cae..322f5940e3077d 100644 --- a/Makefile +++ b/Makefile @@ -2689,21 +2689,21 @@ $(BUILT_INS): git$X ln -s $< $@ 2>/dev/null || \ cp $< $@ -config-list.h: generate-configlist.sh +config-list.h: tools/generate-configlist.sh @mkdir -p .depend - $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh . $@ .depend/config-list.h.d + $(QUIET_GEN)$(SHELL_PATH) ./tools/generate-configlist.sh . $@ .depend/config-list.h.d -include .depend/config-list.h.d -command-list.h: generate-cmdlist.sh command-list.txt +command-list.h: tools/generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.adoc) - $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh \ + $(QUIET_GEN)$(SHELL_PATH) ./tools/generate-cmdlist.sh \ $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ . $@ -hook-list.h: generate-hooklist.sh Documentation/githooks.adoc - $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh . $@ +hook-list.h: tools/generate-hooklist.sh Documentation/githooks.adoc + $(QUIET_GEN)$(SHELL_PATH) ./tools/generate-hooklist.sh . $@ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):\ $(localedir_SQ):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ @@ -2716,8 +2716,8 @@ GIT-SCRIPT-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi -$(SCRIPT_SH_GEN) $(SCRIPT_LIB) : % : %.sh generate-script.sh GIT-BUILD-OPTIONS GIT-SCRIPT-DEFINES - $(QUIET_GEN)./generate-script.sh "$<" "$@+" ./GIT-BUILD-OPTIONS && \ +$(SCRIPT_SH_GEN) $(SCRIPT_LIB) : % : %.sh tools/generate-script.sh GIT-BUILD-OPTIONS GIT-SCRIPT-DEFINES + $(QUIET_GEN)./tools/generate-script.sh "$<" "$@+" ./GIT-BUILD-OPTIONS && \ mv $@+ $@ git.rc: git.rc.in GIT-VERSION-GEN GIT-VERSION-FILE @@ -2757,8 +2757,8 @@ endif PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir) -$(SCRIPT_PERL_GEN): % : %.perl generate-perl.sh GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE - $(QUIET_GEN)$(SHELL_PATH) generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@+" && \ +$(SCRIPT_PERL_GEN): % : %.perl tools/generate-perl.sh GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE + $(QUIET_GEN)$(SHELL_PATH) tools/generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@+" && \ mv $@+ $@ PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES)) @@ -2786,8 +2786,8 @@ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile perllibdir: @echo '$(perllibdir_SQ)' -git-instaweb: git-instaweb.sh generate-script.sh GIT-BUILD-OPTIONS GIT-SCRIPT-DEFINES - $(QUIET_GEN)./generate-script.sh "$<" "$@+" ./GIT-BUILD-OPTIONS && \ +git-instaweb: git-instaweb.sh tools/generate-script.sh GIT-BUILD-OPTIONS GIT-SCRIPT-DEFINES + $(QUIET_GEN)./tools/generate-script.sh "$<" "$@+" ./GIT-BUILD-OPTIONS && \ chmod +x $@+ && \ mv $@+ $@ else # NO_PERL @@ -2804,9 +2804,9 @@ endif # NO_PERL $(SCRIPT_PYTHON_GEN): GIT-BUILD-OPTIONS ifndef NO_PYTHON -$(SCRIPT_PYTHON_GEN): generate-python.sh +$(SCRIPT_PYTHON_GEN): tools/generate-python.sh $(SCRIPT_PYTHON_GEN): % : %.py - $(QUIET_GEN)$(SHELL_PATH) generate-python.sh ./GIT-BUILD-OPTIONS "$<" "$@" + $(QUIET_GEN)$(SHELL_PATH) tools/generate-python.sh ./GIT-BUILD-OPTIONS "$<" "$@" else # NO_PYTHON $(SCRIPT_PYTHON_GEN): % : unimplemented.sh $(QUIET_GEN) \ @@ -3226,9 +3226,9 @@ endif NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS)) endif -perl/build/lib/%.pm: perl/%.pm generate-perl.sh GIT-BUILD-OPTIONS GIT-VERSION-FILE GIT-PERL-DEFINES +perl/build/lib/%.pm: perl/%.pm tools/generate-perl.sh GIT-BUILD-OPTIONS GIT-VERSION-FILE GIT-PERL-DEFINES $(call mkdir_p_parent_template) - $(QUIET_GEN)$(SHELL_PATH) generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@" + $(QUIET_GEN)$(SHELL_PATH) tools/generate-perl.sh ./GIT-BUILD-OPTIONS ./GIT-VERSION-FILE GIT-PERL-HEADER "$<" "$@" perl/build/man/man3/Git.3pm: perl/Git.pm $(call mkdir_p_parent_template) @@ -3936,7 +3936,7 @@ check-docs:: ### Make sure built-ins do not have dups and listed in git.c # check-builtins:: - ./check-builtins.sh + ./tools/check-builtins.sh ### Test suite coverage testing # diff --git a/config.mak.dev b/config.mak.dev index e86b6e1b34a2d7..c8dcf78779e60b 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -1,5 +1,5 @@ ifndef COMPILER_FEATURES -COMPILER_FEATURES := $(shell ./detect-compiler $(CC)) +COMPILER_FEATURES := $(shell ./tools/detect-compiler $(CC)) endif ifeq ($(filter no-error,$(DEVOPTS)),) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index c6cfb874efbb17..81b4306e72046c 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -636,7 +636,7 @@ set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" F if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS) list(REMOVE_ITEM EXCLUSION_PROGS empty) message("Generating command-list.h") - execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-cmdlist.sh" + execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-cmdlist.sh" ${EXCLUSION_PROGS} "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/command-list.h") @@ -644,14 +644,14 @@ endif() if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) message("Generating config-list.h") - execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-configlist.sh" + execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-configlist.sh" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/config-list.h") endif() if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h) message("Generating hook-list.h") - execute_process(COMMAND "${SH_EXE}" ${CMAKE_SOURCE_DIR}/generate-hooklist.sh + execute_process(COMMAND "${SH_EXE}" ${CMAKE_SOURCE_DIR}/tools/generate-hooklist.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/hook-list.h") endif() @@ -832,11 +832,11 @@ foreach(script ${git_shell_scripts}) endif() add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${shell_gen_path}" - COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-script.sh" + COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-script.sh" "${CMAKE_SOURCE_DIR}/${script}.sh" "${CMAKE_BINARY_DIR}/${shell_gen_path}" "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" - DEPENDS "${CMAKE_SOURCE_DIR}/generate-script.sh" + DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-script.sh" "${CMAKE_SOURCE_DIR}/${script}.sh" VERBATIM) list(APPEND shell_gen ${CMAKE_BINARY_DIR}/${shell_gen_path}) @@ -875,13 +875,13 @@ foreach(script ${git_perl_scripts} ${perl_modules}) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${perl_gen_dir}") add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${perl_gen_path}" - COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-perl.sh" + COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-perl.sh" "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE" "${CMAKE_BINARY_DIR}/GIT-PERL-HEADER" "${CMAKE_SOURCE_DIR}/${script}" "${CMAKE_BINARY_DIR}/${perl_gen_path}" - DEPENDS "${CMAKE_SOURCE_DIR}/generate-perl.sh" + DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-perl.sh" "${CMAKE_SOURCE_DIR}/${script}" "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE" @@ -892,11 +892,11 @@ add_custom_target(perl-gen ALL DEPENDS ${perl_gen}) # Python script add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/git-p4" - COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-python.sh" + COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-python.sh" "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" "${CMAKE_SOURCE_DIR}/git-p4.py" "${CMAKE_BINARY_DIR}/git-p4" - DEPENDS "${CMAKE_SOURCE_DIR}/generate-python.sh" + DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-python.sh" "${CMAKE_SOURCE_DIR}/git-p4.py" "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS" VERBATIM) diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build index 161435abebd476..804c3158944779 100644 --- a/contrib/subtree/meson.build +++ b/contrib/subtree/meson.build @@ -3,7 +3,7 @@ git_subtree = custom_target( output: 'git-subtree', command: [ shell, - meson.project_source_root() / 'generate-script.sh', + meson.project_source_root() / 'tools/generate-script.sh', '@INPUT@', '@OUTPUT@', meson.project_build_root() / 'GIT-BUILD-OPTIONS', diff --git a/meson.build b/meson.build index 1d66b5181e97b6..604fe89d2d1a0f 100644 --- a/meson.build +++ b/meson.build @@ -554,7 +554,7 @@ libgit_sources = [ libgit_sources += custom_target( input: 'command-list.txt', output: 'command-list.h', - command: [shell, meson.current_source_dir() + '/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'], + command: [shell, meson.current_source_dir() + '/tools/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'], env: script_environment, ) @@ -723,10 +723,10 @@ endif builtin_sources += custom_target( output: 'config-list.h', depfile: 'config-list.h.d', - depend_files: [ 'generate-configlist.sh' ], + depend_files: [ 'tools/generate-configlist.sh' ], command: [ shell, - meson.current_source_dir() / 'generate-configlist.sh', + meson.current_source_dir() / 'tools/generate-configlist.sh', meson.current_source_dir(), '@OUTPUT@', '@DEPFILE@', @@ -739,7 +739,7 @@ builtin_sources += custom_target( output: 'hook-list.h', command: [ shell, - meson.current_source_dir() + '/generate-hooklist.sh', + meson.current_source_dir() + '/tools/generate-hooklist.sh', meson.current_source_dir(), '@OUTPUT@', ], @@ -1959,7 +1959,7 @@ foreach script : scripts_sh output: fs.stem(script), command: [ shell, - meson.project_source_root() / 'generate-script.sh', + meson.project_source_root() / 'tools/generate-script.sh', '@INPUT@', '@OUTPUT@', meson.project_build_root() / 'GIT-BUILD-OPTIONS', @@ -2008,7 +2008,7 @@ if perl_features_enabled generate_perl_command = [ shell, - meson.project_source_root() / 'generate-perl.sh', + meson.project_source_root() / 'tools/generate-perl.sh', meson.project_build_root() / 'GIT-BUILD-OPTIONS', git_version_file.full_path(), perl_header, @@ -2057,7 +2057,7 @@ if target_python.found() output: fs.stem(script), command: [ shell, - meson.project_source_root() / 'generate-python.sh', + meson.project_source_root() / 'tools/generate-python.sh', meson.project_build_root() / 'GIT-BUILD-OPTIONS', '@INPUT@', '@OUTPUT@', diff --git a/check-builtins.sh b/tools/check-builtins.sh similarity index 100% rename from check-builtins.sh rename to tools/check-builtins.sh diff --git a/detect-compiler b/tools/detect-compiler similarity index 100% rename from detect-compiler rename to tools/detect-compiler diff --git a/generate-cmdlist.sh b/tools/generate-cmdlist.sh similarity index 100% rename from generate-cmdlist.sh rename to tools/generate-cmdlist.sh diff --git a/generate-configlist.sh b/tools/generate-configlist.sh similarity index 100% rename from generate-configlist.sh rename to tools/generate-configlist.sh diff --git a/generate-hooklist.sh b/tools/generate-hooklist.sh similarity index 100% rename from generate-hooklist.sh rename to tools/generate-hooklist.sh diff --git a/generate-perl.sh b/tools/generate-perl.sh similarity index 100% rename from generate-perl.sh rename to tools/generate-perl.sh diff --git a/generate-python.sh b/tools/generate-python.sh similarity index 100% rename from generate-python.sh rename to tools/generate-python.sh diff --git a/generate-script.sh b/tools/generate-script.sh similarity index 100% rename from generate-script.sh rename to tools/generate-script.sh From baa61e46da8f501e3b2d1900486255a546d3535b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:25 +0100 Subject: [PATCH 15/21] git-compat-util.h: move warning infra to prepare for PCHs The "git-compat-util.h" header is supposed to be the first header included by every code compilation unit. As such, a subsequent commit will start to precompile this header to speed up compilation of Git. This will cause an issue though with the way that we have set up the "-Wsign-compare" warnings. It is expected that any compilation unit that fails with that compiler warning sets `DISABLE_SIGN_COMPARE_WARNINGS` before including "git-compat-util.h". If so, we'll disable the warning right away via a compiler pragma. But with precompiled headers we do not know ahead of time whether the code unit wants to disable those warnings, and thus we'll have to precompile the header without defining `DISABLE_SIGN_COMPARE_WARNINGS`. But as the pragma statement is wrapped by our include guards, the second include of that file will not have the desired effect of disabling the warnings anymore. We could fix this issue by declaring a new macro that compilation units are expected to invoke after having included the file. In retrospect, that would have been the better way to handle this as it allows for more flexibility: we could for example toggle the warning for specific code blocks, only. But changing this now would require a bunch of changes, and the churn feels excessive for what we gain. Instead, prepare for the precompiled headers by moving the code outside of the include guards. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- git-compat-util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index bebcf9f698cd39..4b4ea2498f13ef 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -34,10 +34,6 @@ struct strbuf; # define DISABLE_WARNING(warning) #endif -#ifdef DISABLE_SIGN_COMPARE_WARNINGS -DISABLE_WARNING(-Wsign-compare) -#endif - #undef FLEX_ARRAY #define FLEX_ARRAY /* empty - weather balloon to require C99 FAM */ @@ -1099,3 +1095,7 @@ extern int not_supposed_to_survive; #endif /* CHECK_ASSERTION_SIDE_EFFECTS */ #endif + +#ifdef DISABLE_SIGN_COMPARE_WARNINGS +DISABLE_WARNING(-Wsign-compare) +#endif From daa56fb7897ce8819e5a64f4ec7800b3eef03031 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:26 +0100 Subject: [PATCH 16/21] meson: compile compatibility sources separately In the next commit we're about to introduce a precompiled header for "git-compat-util.h". The consequence of this change is that we'll implicitly include that header for every compilation unit that uses the precompiled headers. This is okay for our "normal" library sources and our builtins. But some of our compatibility sources do not include the header on purpose, and doing so would cause compilation errors. Prepare for this change by splitting out compatibility sources into their static library. Like this, we can selectively enable precompiled headers for the library sources. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- meson.build | 79 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/meson.build b/meson.build index 604fe89d2d1a0f..cd00be1c23f996 100644 --- a/meson.build +++ b/meson.build @@ -271,6 +271,13 @@ version_gen_environment.set('GIT_VERSION', get_option('version')) compiler = meson.get_compiler('c') +compat_sources = [ + 'compat/nonblock.c', + 'compat/obstack.c', + 'compat/open.c', + 'compat/terminal.c', +] + libgit_sources = [ 'abspath.c', 'add-interactive.c', @@ -304,10 +311,6 @@ libgit_sources = [ 'commit.c', 'common-exit.c', 'common-init.c', - 'compat/nonblock.c', - 'compat/obstack.c', - 'compat/open.c', - 'compat/terminal.c', 'compiler-tricks/not-constant.c', 'config.c', 'connect.c', @@ -1163,7 +1166,7 @@ endif if not has_poll_h and not has_sys_poll_h libgit_c_args += '-DNO_POLL' - libgit_sources += 'compat/poll/poll.c' + compat_sources += 'compat/poll/poll.c' libgit_include_directories += 'compat/poll' endif @@ -1179,7 +1182,7 @@ endif # implementation to threat things like drive prefixes specially. if host_machine.system() == 'windows' or not compiler.has_header('libgen.h') libgit_c_args += '-DNO_LIBGEN_H' - libgit_sources += 'compat/basename.c' + compat_sources += 'compat/basename.c' endif if compiler.has_header('paths.h') @@ -1209,7 +1212,7 @@ if host_machine.system() != 'windows' foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror'] if not compiler.has_function(symbol, dependencies: networking_dependencies) libgit_c_args += '-DNO_' + symbol.to_upper() - libgit_sources += 'compat/' + symbol + '.c' + compat_sources += 'compat/' + symbol + '.c' endif endforeach endif @@ -1251,18 +1254,18 @@ else endif if host_machine.system() == 'darwin' - libgit_sources += 'compat/precompose_utf8.c' + compat_sources += 'compat/precompose_utf8.c' libgit_c_args += '-DPRECOMPOSE_UNICODE' libgit_c_args += '-DPROTECT_HFS_DEFAULT' endif # Configure general compatibility wrappers. if host_machine.system() == 'cygwin' - libgit_sources += [ + compat_sources += [ 'compat/win32/path-utils.c', ] elif host_machine.system() == 'windows' - libgit_sources += [ + compat_sources += [ 'compat/winansi.c', 'compat/win32/dirent.c', 'compat/win32/flush.c', @@ -1289,20 +1292,20 @@ elif host_machine.system() == 'windows' libgit_include_directories += 'compat/win32' if compiler.get_id() == 'msvc' libgit_include_directories += 'compat/vcbuild/include' - libgit_sources += 'compat/msvc.c' + compat_sources += 'compat/msvc.c' else - libgit_sources += 'compat/mingw.c' + compat_sources += 'compat/mingw.c' endif endif if host_machine.system() == 'linux' - libgit_sources += 'compat/linux/procinfo.c' + compat_sources += 'compat/linux/procinfo.c' elif host_machine.system() == 'windows' - libgit_sources += 'compat/win32/trace2_win32_process_info.c' + compat_sources += 'compat/win32/trace2_win32_process_info.c' elif host_machine.system() == 'darwin' - libgit_sources += 'compat/darwin/procinfo.c' + compat_sources += 'compat/darwin/procinfo.c' else - libgit_sources += 'compat/stub/procinfo.c' + compat_sources += 'compat/stub/procinfo.c' endif if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' @@ -1315,13 +1318,13 @@ endif # Configure the simple-ipc subsystem required fro the fsmonitor. if host_machine.system() == 'windows' - libgit_sources += [ + compat_sources += [ 'compat/simple-ipc/ipc-shared.c', 'compat/simple-ipc/ipc-win32.c', ] libgit_c_args += '-DSUPPORTS_SIMPLE_IPC' else - libgit_sources += [ + compat_sources += [ 'compat/simple-ipc/ipc-shared.c', 'compat/simple-ipc/ipc-unix-socket.c', ] @@ -1339,7 +1342,7 @@ if fsmonitor_backend != '' libgit_c_args += '-DHAVE_FSMONITOR_DAEMON_BACKEND' libgit_c_args += '-DHAVE_FSMONITOR_OS_SETTINGS' - libgit_sources += [ + compat_sources += [ 'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c', 'compat/fsmonitor/fsm-ipc-' + fsmonitor_backend + '.c', 'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c', @@ -1355,7 +1358,7 @@ if not get_option('b_sanitize').contains('address') and get_option('regex').allo if compiler.get_define('REG_ENHANCED', prefix: '#include ') != '' libgit_c_args += '-DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS' - libgit_sources += 'compat/regcomp_enhanced.c' + compat_sources += 'compat/regcomp_enhanced.c' endif elif not get_option('regex').enabled() libgit_c_args += [ @@ -1364,7 +1367,7 @@ elif not get_option('regex').enabled() '-DNO_MBSUPPORT', ] build_options_config.set('NO_REGEX', '1') - libgit_sources += 'compat/regex/regex.c' + compat_sources += 'compat/regex/regex.c' libgit_include_directories += 'compat/regex' else error('Native regex support requested but not found') @@ -1428,7 +1431,7 @@ else if get_option('b_sanitize').contains('address') libgit_c_args += '-DNO_MMAP' - libgit_sources += 'compat/mmap.c' + compat_sources += 'compat/mmap.c' else checkfuncs += { 'mmap': ['mmap.c'] } endif @@ -1438,7 +1441,7 @@ foreach func, impls : checkfuncs if not compiler.has_function(func) libgit_c_args += '-DNO_' + func.to_upper() foreach impl : impls - libgit_sources += 'compat/' + impl + compat_sources += 'compat/' + impl endforeach endif endforeach @@ -1449,13 +1452,13 @@ endif if not compiler.has_function('strdup') libgit_c_args += '-DOVERRIDE_STRDUP' - libgit_sources += 'compat/strdup.c' + compat_sources += 'compat/strdup.c' endif if not compiler.has_function('qsort') libgit_c_args += '-DINTERNAL_QSORT' endif -libgit_sources += 'compat/qsort_s.c' +compat_sources += 'compat/qsort_s.c' if compiler.has_function('getdelim') libgit_c_args += '-DHAVE_GETDELIM' @@ -1511,7 +1514,7 @@ if meson.can_run_host_binaries() and compiler.run(''' } ''', name: 'fread reads directories').returncode() == 0 libgit_c_args += '-DFREAD_READS_DIRECTORIES' - libgit_sources += 'compat/fopen.c' + compat_sources += 'compat/fopen.c' endif if not meson.is_cross_build() and fs.exists('/dev/tty') @@ -1745,14 +1748,22 @@ else endif libgit = declare_dependency( - link_with: static_library('git', - sources: libgit_sources, - c_args: libgit_c_args + [ - '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', - ], - dependencies: libgit_dependencies, - include_directories: libgit_include_directories, - ), + link_with: [ + static_library('compat', + sources: compat_sources, + c_args: libgit_c_args, + dependencies: libgit_dependencies, + include_directories: libgit_include_directories, + ), + static_library('git', + sources: libgit_sources, + c_args: libgit_c_args + [ + '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', + ], + dependencies: libgit_dependencies, + include_directories: libgit_include_directories, + ), + ], compile_args: libgit_c_args, dependencies: libgit_dependencies, include_directories: libgit_include_directories, From 671df48df895fdf259b48a7f90b70b7c75fc4059 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2026 06:33:27 +0100 Subject: [PATCH 17/21] meson: precompile "git-compat-util.h" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every compilation unit in Git is expected to include "git-compat-util.h" first, either directly or indirectly via "builtin.h". This header papers over differences between platforms so that we can expect the typical POSIX functions to exist. Furthermore, it provides functionality that we end up using everywhere. This header is thus quite heavy as a consequence. Preprocessing it as a standalone unit via `clang -E git-compat-util.h` yields over 23,000 lines of code overall. Naturally, it takes quite some time to compile all of this. Luckily, this is exactly the kind of use case that precompiled headers aim to solve: instead of recompiling it every single time, we compile it once and then link the result into the executable. If include guards are set up properly it means that the file won't need to be reprocessed. Set up such a precompiled header for "git-compat-util.h" and wire it up via Meson. This causes Meson to implicitly include the precompiled header in all compilation units. With GCC and Clang for example this is done via the "-include" statement [1]. This leads to a significant speedup when performing full builds: Benchmark 1: ninja (rev = HEAD~) Time (mean ± σ): 14.467 s ± 0.126 s [User: 248.133 s, System: 31.298 s] Range (min … max): 14.195 s … 14.633 s 10 runs Benchmark 2: ninja (rev = HEAD) Time (mean ± σ): 10.307 s ± 0.111 s [User: 173.290 s, System: 23.998 s] Range (min … max): 10.030 s … 10.433 s 10 runs Summary ninja (rev = HEAD) ran 1.40 ± 0.02 times faster than ninja (rev = HEAD~) [1]: https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- meson.build | 2 ++ tools/precompiled.h | 1 + 2 files changed, 3 insertions(+) create mode 100644 tools/precompiled.h diff --git a/meson.build b/meson.build index cd00be1c23f996..2002f4795eb2ab 100644 --- a/meson.build +++ b/meson.build @@ -1760,6 +1760,7 @@ libgit = declare_dependency( c_args: libgit_c_args + [ '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', ], + c_pch: 'tools/precompiled.h', dependencies: libgit_dependencies, include_directories: libgit_include_directories, ), @@ -1820,6 +1821,7 @@ test_dependencies = [ ] git_builtin = executable('git', sources: builtin_sources + 'git.c', + c_pch: 'tools/precompiled.h', dependencies: [libgit_commonmain], install: true, install_dir: git_exec_path, diff --git a/tools/precompiled.h b/tools/precompiled.h new file mode 100644 index 00000000000000..b2bec0d2b4fa25 --- /dev/null +++ b/tools/precompiled.h @@ -0,0 +1 @@ +#include "git-compat-util.h" From 753c8101b027f34359a921a8acb3abe7f10058c5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 19 Mar 2026 00:15:59 -0700 Subject: [PATCH 18/21] rerere: update to modern representation of empty strbufs Back when b4833a2c (rerere: Fix use of an empty strbuf.buf, 2007-09-26) was written, a freshly initialized empty strbuf had NULL in its .buf member, with .len set to 0. The code this patch touches in rerere.c was written to _fix_ the original code that assumed that the .buf member is always pointing at a NUL-terminated string, even for an empty string, which did not hold back then. That changed in b315c5c0 (strbuf change: be sure ->buf is never ever NULL., 2007-09-27), and it has again become safe to assume that .buf is never NULL, and .buf[0] has '\0' for an empty string (i.e., a strbuf with its .len member set to 0). A funny thing is, this piece of code has been moved around from builtin-rerere.c to rerere.c and also adjusted for updates to the hash function API over the years, but nobody bothered to question if this special casing for an empty strbuf was still necessary: b4833a2c62 (rerere: Fix use of an empty strbuf.buf, 2007-09-26) 5b2fd95606 (rerere: Separate libgit and builtin functions, 2008-07-09) 9126f0091f (fix openssl headers conflicting with custom SHA1 implementations, 2008-10-01) c0f16f8e14 (rerere: factor out handle_conflict function, 2018-08-05) 0d7c419a94 (rerere: convert to use the_hash_algo, 2018-10-15) 0578f1e66a (global: adapt callers to use generic hash context helpers, 2025-01-31) Finally get rid of the special casing that was unnecessary for the last 19 years. Signed-off-by: Junio C Hamano --- rerere.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rerere.c b/rerere.c index 3cd37c5f0ae70c..6e0c2183326f3b 100644 --- a/rerere.c +++ b/rerere.c @@ -402,12 +402,8 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, strbuf_addbuf(out, &two); rerere_strbuf_putconflict(out, '>', marker_size); if (ctx) { - git_hash_update(ctx, one.buf ? - one.buf : "", - one.len + 1); - git_hash_update(ctx, two.buf ? - two.buf : "", - two.len + 1); + git_hash_update(ctx, one.buf, one.len + 1); + git_hash_update(ctx, two.buf, two.len + 1); } break; } else if (hunk == RR_SIDE_1) From f64c50e76827f39c843102bc603817648a38a48c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 19 Mar 2026 15:39:02 -0700 Subject: [PATCH 19/21] cocci: strbuf.buf is never NULL We recently noticed one old code from 19 years ago protecting against an ancient strbuf convention that the .buf member can be NULL for an empty strbuf. As that is no longer the case in the modern codebase, let's catch such a construct. Signed-off-by: Junio C Hamano --- contrib/coccinelle/strbuf.cocci | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 5f06105df6db7b..13f0ad267902f5 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -60,3 +60,10 @@ expression E1, E2; @@ - strbuf_addstr(E1, real_path(E2)); + strbuf_add_real_path(E1, E2); + +// In modern codebase, .buf member of an empty strbuf is not NULL. +@@ +struct strbuf SB; +@@ +- SB.buf ? SB.buf : "" ++ SB.buf From 598f40c4b3de30d8f7c0666823a9d90884b78bee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 17 Mar 2026 19:02:23 -0400 Subject: [PATCH 20/21] contrib/diff-highlight: do not highlight identical pairs We pair lines for highlighting based on their position in the hunk. So we should never see two identical lines paired, like: -one -two +one +something else which would pair -one/+one, because that implies that the diff could easily be shrunk by turning line "one" into context. But there is (at least) one exception: removing a newline at the end of a file will produce a diff like: -foo +foo \No newline at end of file And we will pair those two lines. As a result, we end up marking the whole line, including the newline, as the shared prefix. And there's an empty suffix. The most obvious bug here is that when we try to print the highlighted lines, we remove the trailing newline from the suffix, but do not bother with the prefix (under the assumption that there had to be a difference _somewhere_ in the line, and thus the prefix would not eat all the way up to the newline). And so you get an extra line like: -foo +foo \No newline at end of file This is obviously ugly, but also causes interactive.diffFilter to (rightly) complain that the input and output do not match their lines 1-to-1. This could easily be fixed by chomping the prefix, too, but I think the problem is deeper. For one, I suspect some of the other logic gets confused by forming an array with zero-indexed element "3" in a 3-element array. But more importantly, we try not to highlight whole lines, as there's nothing interesting to show there. So let's catch this early in is_pair_interesting() and bail to our usual passthrough strategy. Reported-by: Scott Baker Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/diff-highlight/DiffHighlight.pm | 12 ++++++++++++ contrib/diff-highlight/t/t9400-diff-highlight.sh | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/contrib/diff-highlight/DiffHighlight.pm b/contrib/diff-highlight/DiffHighlight.pm index 3d061bc0b7da35..f0607a4b687cf4 100644 --- a/contrib/diff-highlight/DiffHighlight.pm +++ b/contrib/diff-highlight/DiffHighlight.pm @@ -273,6 +273,18 @@ sub highlight_line { # or suffix (disregarding boring bits like whitespace and colorization). sub is_pair_interesting { my ($a, $pa, $sa, $b, $pb, $sb) = @_; + + # We hit this case if the prefix consumed the entire line, meaning + # that two lines are identical. This generally shouldn't happen, + # since it implies the diff isn't minimal (you could shrink the hunk by + # making this a context line). But you can see it when the line + # content is the same, but the trailing newline is dropped, like: + # + # -foo + # +foo + # \No newline at end of file + return 0 if $pa == @$a || $pb == @$b; + my $prefix_a = join('', @$a[0..($pa-1)]); my $prefix_b = join('', @$b[0..($pb-1)]); my $suffix_a = join('', @$a[($sa+1)..$#$a]); diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh index dee296739cd383..2a9b68cf3bb8cd 100755 --- a/contrib/diff-highlight/t/t9400-diff-highlight.sh +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh @@ -340,4 +340,15 @@ test_expect_success 'diff-highlight handles --graph with leading dash' ' test_cmp expect actual ' +test_expect_success 'highlight diff that removes final newline' ' + printf "content\n" >a && + printf "content" >b && + dh_test a b <<-\EOF + @@ -1 +1 @@ + -content + +content + \ No newline at end of file + EOF +' + test_done From 5361983c075154725be47b65cca9a2421789e410 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Mar 2026 10:59:34 -0700 Subject: [PATCH 21/21] The 22nd batch Signed-off-by: Junio C Hamano --- Documentation/RelNotes/2.54.0.adoc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Documentation/RelNotes/2.54.0.adoc b/Documentation/RelNotes/2.54.0.adoc index 25affd6a981d61..4a3e0d3dfb0126 100644 --- a/Documentation/RelNotes/2.54.0.adoc +++ b/Documentation/RelNotes/2.54.0.adoc @@ -97,6 +97,9 @@ UI, Workflows & Features * "git history" learned the "split" subcommand. + * The reference-transaction hook was taught to be triggered before + taking locks on references in the "preparing" phase. + Performance, Internal Implementation, Development Support etc. -------------------------------------------------------------- @@ -231,6 +234,11 @@ Performance, Internal Implementation, Development Support etc. * The logic to count objects has been cleaned up. + * Tweak the build infrastructure by moving tools around. + + * Uses of prio_queue as a LIFO stack of commits have been written + with commit_stack. + Fixes since v2.53 ----------------- @@ -388,6 +396,16 @@ Fixes since v2.53 took an empty string as a valid . (merge 4f6a803aba ty/doc-diff-u-wo-number later to maint). + * The handling of the incomplete lines at the end by "git + diff-highlight" has been fixed. + + * merge-file --object-id used to trigger a BUG when run in a linked + worktree, which has been fixed. + (merge 57246b7c62 mr/merge-file-object-id-worktree-fix later to maint). + + * "git apply -p" parses more carefully now. + (merge d05d84c5f5 mf/apply-p-no-atoi later to maint). + * Other code cleanup, docfix, build fix, etc. (merge d79fff4a11 jk/remote-tracking-ref-leakfix later to maint). (merge 7a747f972d dd/t5403-modernise later to maint). @@ -435,3 +453,6 @@ Fixes since v2.53 (merge 2f05039717 rj/pack-refs-tests-path-is-helpers later to maint). (merge 2594747ad1 jk/transport-color-leakfix later to maint). (merge 48430e44ac mf/t0008-cleanup later to maint). + (merge fc8a4f15e7 gi/doc-boolean-config-typofix later to maint). + (merge 37182267a0 kh/doc-interpret-trailers-1 later to maint). + (merge f64c50e768 jc/rerere-modern-strbuf-handling later to maint).