Message ID | 6b427b4b1e82b1f01640f1f49fe8d1c2fd02111e.1691210737.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Fixes to trailer test script, help text, and documentation | expand |
"Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes: > @@ -114,8 +114,10 @@ OPTIONS > Specify where all new trailers will be added. A setting > provided with '--where' overrides all configuration variables Obviously this is not a new issue, but "all configuration variables" is misleading (the same comment applies to the description of the "--[no-]if-exists" and the "--[no-]if-missing" options). If I am reading the code correctly, --where=value overrides the trailer.where variable and nothing else, and --no-where stops the overriding of the trailer.where variable. Ditto for the other two with their relevant configuration variables.
Junio C Hamano <gitster@pobox.com> writes: > "Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes: > >> @@ -114,8 +114,10 @@ OPTIONS >> Specify where all new trailers will be added. A setting >> provided with '--where' overrides all configuration variables > > Obviously this is not a new issue, but "all configuration variables" > is misleading (the same comment applies to the description of the > "--[no-]if-exists" and the "--[no-]if-missing" options). Agreed. > If I am reading the code correctly, --where=value overrides the > trailer.where variable and nothing else, and --no-where stops the > overriding of the trailer.where variable. Ditto for the other two > with their relevant configuration variables. That is also my understanding. Will update to remove the "all" wording. On a separate note, I've realized there are more fixes to be done in this area (as I get more familiar with the codebase). For example, we have the following language in builtin/interpret-trailers.c inside cmd_interpret_trailers(): OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply config rules")), which should be fixed in similar style to what you suggested above, probably with: OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply trailer.* configuration variables")), When I reroll, I will include these additional fixes so expect the patch series to grow (probably ~12 patches instead of the ~5). One more thing. I think the documentation (Documentation/git-interpret-trailers.txt) uses the word "<token>" in two different ways. For example, if we have in the input subject line body text Acked-by: Foo the docs treat the word "Acked-by:" as the <token>. However, it defines the relevant configuration section like this: trailer.<token>.key:: This `key` will be used instead of <token> in the trailer. At the end of this key, 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, then the key will be used instead of both the <token> and the default separator when adding the trailer. So if I configure this like git config trailer.ack.key "Acked-by" && the <token> is both the longer-form "Acked-by:" (per the meaning so far in the doc) but also the shorter string "ack" per the "trailer.<token>.key" configuration section syntax. This secondary meaning is repeated again in the very start of the doc when we define the --trailer option syntax as SYNOPSIS -------- [verse] 'git interpret-trailers' [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [--parse] [<file>...] because the <token> here could be (using the example above) either "Acked-by" (as in "--trailer=Acked-by:...") if we did not configure "trailer.ack.key", or just "ack" (as in "--trailer=ack:...") if we did configure it. These two scenarios would give identical "Acked-by: ..." output. This is confusing and I don't like how we overload this "token" word (not to mention we already have the word "key" which we don't really use much in the docs). I am inclined to replace most uses of the word "<token>" with "<key>" while leaving the "trailer.<token>.key" configuration syntax intact. This will result in a large diff but I think the removal of the double meaning is worth it, and will include this fix also in the next reroll. The main reason I bring this up is because this means also having to update our funciton names like "token_len_without_separator" in trailer.c, to be "key_len_without_separator" if we want the nomenclature in the trailer.c internals to be consistent with the (updated) user-facing docs. I am not sure whether we want to do this as part of the same reroll, or if we should leave it as #leftoverbits for a future series.
Linus Arver <linusa@google.com> writes: > So if I configure this like > > git config trailer.ack.key "Acked-by" && > Oops, I meant just git config trailer.ack.key "Acked-by" without the trailing "&&".
Linus Arver <linusa@google.com> writes: > Junio C Hamano <gitster@pobox.com> writes: > >> "Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes: >> >>> @@ -114,8 +114,10 @@ OPTIONS >>> Specify where all new trailers will be added. A setting >>> provided with '--where' overrides all configuration variables >> >> Obviously this is not a new issue, but "all configuration variables" >> is misleading (the same comment applies to the description of the >> "--[no-]if-exists" and the "--[no-]if-missing" options). > > Agreed. > >> If I am reading the code correctly, --where=value overrides the >> trailer.where variable and nothing else, and --no-where stops the >> overriding of the trailer.where variable. Ditto for the other two >> with their relevant configuration variables. > > That is also my understanding. Will update to remove the "all" wording. Hmph, actually it also overrides any applicable "trailer.<token>.where" configurations (these <token>-specific configurations override the "trailer.where" configuration where applicable). Still, the "all configuration variables" wording should be updated, probably like this: › Specify where all new trailers will be added. A setting › provided with '--where' overrides the `trailer.where` and any › applicable `trailer.<token>.where` configuration variables › and applies to all '--trailer' options until the next occurrence of › '--where' or '--no-where'.
Linus Arver <linusa@google.com> writes: >>> If I am reading the code correctly, --where=value overrides the >>> trailer.where variable and nothing else, and --no-where stops the >>> overriding of the trailer.where variable. Ditto for the other two >>> with their relevant configuration variables. >> >> That is also my understanding. Will update to remove the "all" wording. > > Hmph, actually it also overrides any applicable "trailer.<token>.where" > configurations (these <token>-specific configurations override the > "trailer.where" configuration where applicable). Still, the "all > configuration variables" wording should be updated, probably like this: > > › Specify where all new trailers will be added. A setting > › provided with '--where' overrides the `trailer.where` and any > › applicable `trailer.<token>.where` configuration variables > › and applies to all '--trailer' options until the next occurrence of > › '--where' or '--no-where'. Yup, that was what I meant. I found it troubling that the "all" phrasing felt like it meant all trailer.* configurations, not just the "where" thing. Your new description looks good. Thanks.
diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt index 55d89614661..91a4dbc9a72 100644 --- a/Documentation/git-interpret-trailers.txt +++ b/Documentation/git-interpret-trailers.txt @@ -114,8 +114,10 @@ OPTIONS Specify where all new trailers will be added. A setting provided with '--where' overrides all configuration variables and applies to all '--trailer' options until the next occurrence of - '--where' or '--no-where'. Possible values are `after`, `before`, - `end` or `start`. + '--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 values are `after`, + `before`, `end` or `start`. --if-exists <action>:: --no-if-exists:: @@ -123,7 +125,9 @@ OPTIONS least one trailer with the same <token> in the input. A setting provided with '--if-exists' overrides all configuration variables and applies to all '--trailer' options until the next occurrence of - '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`, + '--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 <action>:: @@ -132,7 +136,9 @@ OPTIONS trailer with the same <token> in the input. A setting provided with '--if-missing' overrides all configuration variables and applies to all '--trailer' options until the next occurrence of - '--if-missing' or '--no-if-missing'. Possible actions are `doNothing` + '--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:: diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index ed0fc04bd95..832aff06167 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -812,6 +812,53 @@ test_expect_success 'using "--where after" with "--no-where"' ' test_cmp expected actual ' +# Check whether using "--no-where" clears out only the "--where after", such +# that we still use the configuration in trailer.where (which is different from +# the hardcoded default (in WHERE_END) assuming the absence of .gitconfig). +# Here, the "start" setting of trailer.where is respected, so the new "Acked-by" +# and "Bug" trailers are placed at the beginning, and not at the end which is +# the harcoded default. +test_expect_success 'using "--where after" with "--no-where" defaults to configuration' ' + test_config trailer.ack.key "Acked-by= " && + test_config trailer.bug.key "Bug #" && + test_config trailer.separators ":=#" && + test_config trailer.where "start" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Acked-by= Peff + Fixes: Z + Acked-by= Z + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers --where after --no-where --trailer "ack: Peff" \ + --trailer "bug: 42" complex_message >actual && + test_cmp expected actual +' + +# The "--where after" will only get respected for the trailer that came +# immediately after it. For the next trailer (Bug #42), we default to using the +# hardcoded WHERE_END because we don't have any "trailer.where" or +# "trailer.bug.where" configured. +test_expect_success 'using "--no-where" defaults to harcoded default if nothing configured' ' + test_config trailer.ack.key "Acked-by= " && + test_config trailer.bug.key "Bug #" && + test_config trailer.separators ":=#" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Acked-by= Peff + Reviewed-by: Z + Signed-off-by: Z + Bug #42 + EOF + git interpret-trailers --where after --trailer "ack: Peff" --no-where \ + --trailer "bug: 42" complex_message >actual && + test_cmp expected actual +' + test_expect_success 'using "where = after"' ' test_config trailer.ack.key "Acked-by= " && test_config trailer.ack.where "after" && @@ -1176,6 +1223,56 @@ test_expect_success 'overriding configuration with "--if-exists replace"' ' test_cmp expected actual ' +# "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults +# to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added. +test_expect_success 'using "--if-exists replace" with "--no-if-exists" defaults to configuration' ' + test_config trailer.ifexists "doNothing" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \ + <complex_message >actual && + test_cmp expected actual +' + +# No "ifexists" configuration is set, so using "--no-if-exists" makes it default +# to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53" +# (because it got added by overriding with "--if-exists replace" earlier in the +# arguments list), we add "Signed-off-by: addme". +test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured' ' + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + Fixes: 53 + Signed-off-by: addme + EOF + git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \ + --trailer "Signed-off-by: addme" <complex_message >actual && + test_cmp expected actual +' + +# The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here +# makes us default to addIfDifferentNeighbor, and we already added the "Fixes: +# 53" trailer earlier in the argument list. +test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' ' + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + Fixes: 53 + EOF + git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \ + --trailer "Fixes: 53" <complex_message >actual && + test_cmp expected actual +' + test_expect_success 'using "ifExists = replace"' ' test_config trailer.fix.key "Fixes: " && test_config trailer.fix.ifExists "replace" && @@ -1425,6 +1522,39 @@ test_expect_success 'using "ifMissing = doNothing"' ' test_cmp expected actual ' +# Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also +# ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to +# "doNothing" in configuration. +test_expect_success 'using "--no-if-missing" defaults to configuration' ' + test_config trailer.ifMissing "doNothing" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \ + --trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual && + test_cmp expected actual +' + +# Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing +# doNothing" from earlier in the argument list. +test_expect_success 'using "--no-if-missing" defaults to hardcoded default if nothing configured' ' + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + AddedTrailer: addme + EOF + git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \ + --trailer "AddedTrailer: addme" <complex_message >actual && + test_cmp expected actual +' + test_expect_success 'default "where" is now "after"' ' git config trailer.where "after" && test_config trailer.ack.ifExists "add" &&