Fixups for cw/submodule-merge-messages
cover Fixups for cw/submodule-merge-messages
This series fixes a few issues I noted in cw/submodule-merge-messages (which merged to next a few days ago). Sorry for not responding before that topic merged to next; I caught Covid near the end of my vacation and it took me out for a while. So here are a few patches on top instead.
(Note that my first patch builds on Junio's patch-on-top, though it kind of obviates the need for his patch. Let me know if you want me to rebase directly on Calvin's patch and remove the need for your patch, Junio.)
Elijah Newren (3):
merge-ort: remove translator lego in new "submodule conflict
suggestion"
merge-ort: add comment to avoid surprise with new sub_flag variable
merge-ort: provide helpful submodule update message when possible
merge-ort.c | 106 +++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 72 deletions(-)
base-commit: 38e3c211f000ebde511099b62be2af104eb20c12
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1325%2Fnewren%2Fsubmodule-merge-messages-fixups-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1325/newren/submodule-merge-messages-fixups-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1325
Signature · 1 line
gitgitgadget
PATCH 1/3 merge-ort: remove translator lego in new "submodule conflict suggestion"
From: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), the new "submodule conflict suggestion" code was translating 6 different pieces of the new message and then used carefully crafted logic to allow stitching it back together with special formatting. Keep the components of the message together as much as possible, so that:
* we reduce the number of things translators have to translate
* translators have more control over the format of the output
* the code is much easier for developers to understand too
Also, reformat some comments running beyond the 80th column while at it.
--- merge-ort.c | 90 +++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 62 deletions(-)
merge-ort.c +28 -62
@@ -4481,36 +4481,6 @@ static int record_conflicted_index_entries(struct merge_options *opt)return errs; } -static void format_submodule_conflict_suggestion (struct strbuf *msg) { -struct strbuf tmp =STRBUF_INIT ; -struct string_list msg_list =STRING_LIST_INIT_DUP ; -int i; - -string_list_split (&msg_list, msg->buf,'\n' ,-1 ); -for (i =0 ; i < msg_list.nr; i++) { -if (!i) -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " - %s\n" -> "%s - \n" -*/ -strbuf_addf (&tmp,_ (" - %s\n" ), msg_list.items[i].string); -else -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " %s\n" -> "%s \n" -*/ -strbuf_addf (&tmp,_ (" %s\n" ), msg_list.items[i].string); - } -strbuf_reset (msg); -strbuf_add (msg, tmp.buf, tmp.len); -string_list_clear (&msg_list,0 ); -strbuf_release (&tmp); -} -static void print_submodule_conflict_suggestion (struct string_list *csub) {struct string_list_item *item;struct strbuf msg =STRBUF_INIT ;
@@ -4532,45 +4502,41 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {return ; } -printf (_ ("Recursive merging with submodules currently only supports " -"trivial cases.\nPlease manually handle the merging of each " -"conflicted submodule.\nThis can be accomplished with the following " -"steps:" )); -putchar ('\n' ); - +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* -* TRANSLATORS: This is a line of advice to resolve a merge conflict -* in a submodule. The second argument is the abbreviated id of the -* commit that needs to be merged. -* E.g. - go to submodule (sub), and either merge commit abc1234" +* TRANSLATORS: This is a line of advice to resolve a merge +* conflict in a submodule. The first argument is the submodule +* name, and the second argument is the abbreviated id of the +* commit that needs to be merged. For example: +* - go to submodule (mysubmodule), and either merge commit abc1234" */ -strbuf_addf (&tmp,_ ("go to submodule (%s), and either merge commit %s\n" -"or update to an existing commit which has merged those changes" ), - item->string, util->abbrev); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); +strbuf_addf (&tmp,_ (" - go to submodule (%s), and either merge commit %s\n" +" or update to an existing commit which has merged those changes\n" ), + item->string, util->abbrev); } -strbuf_add_separated_string_list (&subs," " , csub); -strbuf_addstr (&tmp,_ ("come back to superproject and run:" )); -strbuf_addf (&tmp,"\n\ngit add %s\n\n" , subs.buf); -strbuf_addstr (&tmp,_ ("to record the above merge or update" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("resolve any other conflicts in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("commit the resulting index in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); + +/* +* TRANSLATORS: This is a detailed message for resolving submodule +* conflicts. The first argument is string containing one step per +* submodule. The second is a space-separated list of submodule names. +*/ +strbuf_addf (&msg, +_ ("Recursive merging with submodules currently only supports trivial cases.\n" +"Please manually handle the merging of each conflicted submodule.\n" +"This can be accomplished with the following steps:\n" +"%s" +" - come back to superproject and run:\n\n" +" git add %s\n\n" +" to record the above merge or update\n" +" - resolve any other conflicts in the superproject\n" +" - commit the resulting index in the superproject\n" ), + tmp.buf, subs.buf);printf ("%s" , msg.buf); +strbuf_release (&subs);strbuf_release (&tmp);strbuf_release (&msg);
Signature · 1 line
gitgitgadget
PATCH 2/3 merge-ort: add comment to avoid surprise with new sub_flag variable
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
Commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04) added a sub_flag variable that is used to store a value from enum conflict_and_info_types, but initializes it with an invalid value of -1. The code may never set it to a valid value, and use the invalid one. This can be surprising when reading over the code at first, but it was intentional. Add a comment making it clear that it is okay to be using an invalid value, due to how it is used later.
--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-ort.c +1 -1
@@ -1886,7 +1886,7 @@ cleanup:const char *abbrev; util =xmalloc (sizeof (*util)); - util->flag = sub_flag; + util->flag = sub_flag;/* May still be -1 */ util->abbrev =NULL ;if (!sub_not_initialized) { abbrev =repo_find_unique_abbrev (&subrepo, b,DEFAULT_ABBREV );
Signature · 1 line
gitgitgadget
PATCH 3/3 merge-ort: provide helpful submodule update message when possible
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), a more detailed message was provided when submodules conflict, in order to help users know how to resolve those conflicts. There were a couple situations for which a different message would be more appropriate, but that commit left handling those for future work. Unfortunately, that commit would check if any submodules were of the type that it didn't know how to explain, and, if so, would avoid providing the more detailed explanation even for the submodules it did know how to explain.
Change this to have the code print the helpful messages for the subset of submodules it knows how to explain.
--- merge-ort.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
merge-ort.c +7 -11
@@ -4490,21 +4490,17 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {if (!csub->nr)return ; -/* -* NEEDSWORK: The steps to resolve these errors deserve a more -* detailed explanation than what is currently printed below. -*/ +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* +* NEEDSWORK: The steps to resolve these errors deserve a more +* detailed explanation than what is currently printed below. +*/ if (util->flag ==CONFLICT_SUBMODULE_NOT_INITIALIZED || - util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) -return ; - } - -strbuf_add_separated_string_list (&subs," " , csub); -for_each_string_list_item (item, csub) { -struct conflicted_submodule_item *util = item->util; + util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) +continue ;/* * TRANSLATORS: This is a line of advice to resolve a merge
Signature · 1 line
gitgitgadget
Quoted 3 lines · Elijah Newren via GitGitGadget
(Note that my first patch builds on Junio's patch-on-top, though it kind of obviates the need for his patch. Let me know if you want me to rebase directly on Calvin's patch and remove the need for your patch, Junio.)
It paid off that I didn't merge the leakfix to 'next' ;-) Please just tell me to drop the patch and build on top of what Calvin has in 'next' directly.
Thanks.
v2 cover Fixups for cw/submodule-merge-messages
In reply to Elijah Newren via GitGitGadgetThis series fixes a few issues I noted in cw/submodule-merge-messages (which merged to next a few days ago). Sorry for not responding before that topic merged to next; I caught Covid near the end of my vacation and it took me out for a while. So here are a few patches on top instead.
Changes since v1:
* rebased directly on top of Calvin's patch, allowing Junio's patch in cw/submodule-merge-messages to be dropped.
Elijah Newren (3):
merge-ort: remove translator lego in new "submodule conflict
suggestion"
merge-ort: add comment to avoid surprise with new sub_flag variable
merge-ort: provide helpful submodule update message when possible
merge-ort.c | 104 +++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 70 deletions(-)
base-commit: 4057523a4061092e9181220d54dca9eadcb75bdc
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1325%2Fnewren%2Fsubmodule-merge-messages-fixups-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1325/newren/submodule-merge-messages-fixups-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1325
Range-diff vs v1:
1: 46c9b48871b ! 1: 374278c6a1d merge-ort: remove translator lego in new "submodule conflict suggestion"
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *op
- }
- strbuf_reset(msg);
- strbuf_add(msg, tmp.buf, tmp.len);
-- string_list_clear(&msg_list, 0);
-- strbuf_release(&tmp);
-}
-
static void print_submodule_conflict_suggestion(struct string_list *csub) {
2: 269714da706 = 2: 340c0f46f74 merge-ort: add comment to avoid surprise with new sub_flag variable
3: 010cf4ff344 = 3: 80207d18334 merge-ort: provide helpful submodule update message when possibleSignature · 1 line
gitgitgadget
PATCH v2 1/3 merge-ort: remove translator lego in new "submodule conflict suggestion"
From: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), the new "submodule conflict suggestion" code was translating 6 different pieces of the new message and then used carefully crafted logic to allow stitching it back together with special formatting. Keep the components of the message together as much as possible, so that:
* we reduce the number of things translators have to translate
* translators have more control over the format of the output
* the code is much easier for developers to understand too
Also, reformat some comments running beyond the 80th column while at it.
--- merge-ort.c | 88 +++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 60 deletions(-)
merge-ort.c +28 -60
@@ -4481,34 +4481,6 @@ static int record_conflicted_index_entries(struct merge_options *opt)return errs; } -static void format_submodule_conflict_suggestion (struct strbuf *msg) { -struct strbuf tmp =STRBUF_INIT ; -struct string_list msg_list =STRING_LIST_INIT_DUP ; -int i; - -string_list_split (&msg_list, msg->buf,'\n' ,-1 ); -for (i =0 ; i < msg_list.nr; i++) { -if (!i) -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " - %s\n" -> "%s - \n" -*/ -strbuf_addf (&tmp,_ (" - %s\n" ), msg_list.items[i].string); -else -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " %s\n" -> "%s \n" -*/ -strbuf_addf (&tmp,_ (" %s\n" ), msg_list.items[i].string); - } -strbuf_reset (msg); -strbuf_add (msg, tmp.buf, tmp.len); -} -static void print_submodule_conflict_suggestion (struct string_list *csub) {struct string_list_item *item;struct strbuf msg =STRBUF_INIT ;
@@ -4530,45 +4502,41 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {return ; } -printf (_ ("Recursive merging with submodules currently only supports " -"trivial cases.\nPlease manually handle the merging of each " -"conflicted submodule.\nThis can be accomplished with the following " -"steps:" )); -putchar ('\n' ); - +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* -* TRANSLATORS: This is a line of advice to resolve a merge conflict -* in a submodule. The second argument is the abbreviated id of the -* commit that needs to be merged. -* E.g. - go to submodule (sub), and either merge commit abc1234" +* TRANSLATORS: This is a line of advice to resolve a merge +* conflict in a submodule. The first argument is the submodule +* name, and the second argument is the abbreviated id of the +* commit that needs to be merged. For example: +* - go to submodule (mysubmodule), and either merge commit abc1234" */ -strbuf_addf (&tmp,_ ("go to submodule (%s), and either merge commit %s\n" -"or update to an existing commit which has merged those changes" ), - item->string, util->abbrev); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); +strbuf_addf (&tmp,_ (" - go to submodule (%s), and either merge commit %s\n" +" or update to an existing commit which has merged those changes\n" ), + item->string, util->abbrev); } -strbuf_add_separated_string_list (&subs," " , csub); -strbuf_addstr (&tmp,_ ("come back to superproject and run:" )); -strbuf_addf (&tmp,"\n\ngit add %s\n\n" , subs.buf); -strbuf_addstr (&tmp,_ ("to record the above merge or update" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("resolve any other conflicts in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("commit the resulting index in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); + +/* +* TRANSLATORS: This is a detailed message for resolving submodule +* conflicts. The first argument is string containing one step per +* submodule. The second is a space-separated list of submodule names. +*/ +strbuf_addf (&msg, +_ ("Recursive merging with submodules currently only supports trivial cases.\n" +"Please manually handle the merging of each conflicted submodule.\n" +"This can be accomplished with the following steps:\n" +"%s" +" - come back to superproject and run:\n\n" +" git add %s\n\n" +" to record the above merge or update\n" +" - resolve any other conflicts in the superproject\n" +" - commit the resulting index in the superproject\n" ), + tmp.buf, subs.buf);printf ("%s" , msg.buf); +strbuf_release (&subs);strbuf_release (&tmp);strbuf_release (&msg);
Signature · 1 line
gitgitgadget
PATCH v2 2/3 merge-ort: add comment to avoid surprise with new sub_flag variable
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
Commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04) added a sub_flag variable that is used to store a value from enum conflict_and_info_types, but initializes it with an invalid value of -1. The code may never set it to a valid value, and use the invalid one. This can be surprising when reading over the code at first, but it was intentional. Add a comment making it clear that it is okay to be using an invalid value, due to how it is used later.
--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-ort.c +1 -1
@@ -1886,7 +1886,7 @@ cleanup:const char *abbrev; util =xmalloc (sizeof (*util)); - util->flag = sub_flag; + util->flag = sub_flag;/* May still be -1 */ util->abbrev =NULL ;if (!sub_not_initialized) { abbrev =repo_find_unique_abbrev (&subrepo, b,DEFAULT_ABBREV );
Signature · 1 line
gitgitgadget
Re: [PATCH v2 2/3] merge-ort: add comment to avoid surprise with new sub_flag variable
Quoted 9 lines · Elijah Newren via GitGitGadget
From: Elijah Newren <[email protected]>
Commit
4057523a40("submodule merge: update conflict error message", 2022-08-04) added asub_flagvariable that is used to store a value from enumconflict_and_info_types, but initializes it with an invalid value of -1. The code may never set it to a valid value, and use the invalid one. This can be surprising when reading over the code at first, but it was intentional. Add a comment making it clear that it is okay to be using an invalid value, due to how it is used later.
The current code uses -1 as the "suggest the default course of action", so -1 is very much a "valid value" from the viewpoint of the code that suggests how to resolve. It indeed is an invalid value from the viewpoint of those who maintain conflict_and_info_types enum.
Quoted 10 lines
Signed-off-by Elijah Newren <[email protected]>--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)merge-ort.c +0
-0
merge-ort.c cleanup: · line 1892
Quoted 8 lines
merge-ort.c +1
-1@@ -1886,7 +1886,7 @@ cleanup:const char *abbrev; util =xmalloc (sizeof (*util)); - util->flag = sub_flag; + util->flag = sub_flag;/* May still be -1 */ util->abbrev =NULL ;if (!sub_not_initialized) { abbrev =repo_find_unique_abbrev (&subrepo, b,DEFAULT_ABBREV );
This new comment may be a slight improvement, but a valid value of sub_flag is used only to signal the situation where the code does not know what to suggest, which feels backwards for longer-term code evolution. Presumably, we would use the util->flag field to store which of the known cases we know what to suggest as we know better.
I wonder if we should initialize the variable to the most generic CONFLICT_SUBMODULE_FAILED_TO_MERGE instead of -1. The value would mean "use the default suggestion", and the two known unworkable values (not-initialized and history-not-available) are currently handled according to what these two values mean. We may later add more specialization based on other CONFLICT_SUBMODULE_* values.
Thanks.
Re: [PATCH v2 2/3] merge-ort: add comment to avoid surprise with new sub_flag variable
Quoted 44 lines · Junio C Hamano
Quoted 9 lines · Elijah Newren via GitGitGadget
From: Elijah Newren <[email protected]>
Commit
4057523a40("submodule merge: update conflict error message", 2022-08-04) added asub_flagvariable that is used to store a value from enumconflict_and_info_types, but initializes it with an invalid value of -1. The code may never set it to a valid value, and use the invalid one. This can be surprising when reading over the code at first, but it was intentional. Add a comment making it clear that it is okay to be using an invalid value, due to how it is used later.The current code uses -1 as the "suggest the default course of action", so -1 is very much a "valid value" from the viewpoint of the code that suggests how to resolve. It indeed is an invalid value from the viewpoint of those who maintain
conflict_and_info_typesenum.Quoted 10 lines
Signed-off-by Elijah Newren <[email protected]>--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)merge-ort.c +0
-0merge-ort.c cleanup: · line 1892
Quoted 8 lines
merge-ort.c +1
-1@@ -1886,7 +1886,7 @@ cleanup:const char *abbrev; util =xmalloc (sizeof (*util)); - util->flag = sub_flag; + util->flag = sub_flag;/* May still be -1 */ util->abbrev =NULL ;if (!sub_not_initialized) { abbrev =repo_find_unique_abbrev (&subrepo, b,DEFAULT_ABBREV );This new comment may be a slight improvement, but a valid value of
sub_flagis used only to signal the situation where the code does not know what to suggest, which feels backwards for longer-term code evolution. Presumably, we would use theutil->flagfield to store which of the known cases we know what to suggest as we know better.
Quoted 6 lines
I wonder if we should initialize the variable to the most generic
CONFLICT_SUBMODULE_FAILED_TO_MERGEinstead of -1. The value would mean "use the default suggestion", and the two known unworkable values (not-initialized and history-not-available) are currently handled according to what these two values mean. We may later add more specialization based on other CONFLICT_SUBMODULE_* values.
I like that; I'll make the switch.
PATCH v2 3/3 merge-ort: provide helpful submodule update message when possible
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), a more detailed message was provided when submodules conflict, in order to help users know how to resolve those conflicts. There were a couple situations for which a different message would be more appropriate, but that commit left handling those for future work. Unfortunately, that commit would check if any submodules were of the type that it didn't know how to explain, and, if so, would avoid providing the more detailed explanation even for the submodules it did know how to explain.
Change this to have the code print the helpful messages for the subset of submodules it knows how to explain.
--- merge-ort.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
merge-ort.c +7 -11
@@ -4490,21 +4490,17 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {if (!csub->nr)return ; -/* -* NEEDSWORK: The steps to resolve these errors deserve a more -* detailed explanation than what is currently printed below. -*/ +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* +* NEEDSWORK: The steps to resolve these errors deserve a more +* detailed explanation than what is currently printed below. +*/ if (util->flag ==CONFLICT_SUBMODULE_NOT_INITIALIZED || - util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) -return ; - } - -strbuf_add_separated_string_list (&subs," " , csub); -for_each_string_list_item (item, csub) { -struct conflicted_submodule_item *util = item->util; + util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) +continue ;/* * TRANSLATORS: This is a line of advice to resolve a merge
Signature · 1 line
gitgitgadget
Quoted 5 lines · Elijah Newren via GitGitGadget
Elijah Newren (3):
merge-ort: remove translator lego in new "submodule conflict
suggestion"
merge-ort: add comment to avoid surprise with newsub_flagvariable
merge-ort: provide helpful submodule update message when possible
Thanks. The last step was especially the pleasant one.
v3 cover Fixups for cw/submodule-merge-messages
In reply to Elijah Newren via GitGitGadgetThis series fixes a few issues I noted in cw/submodule-merge-messages (which merged to next a few days ago). Sorry for not responding before that topic merged to next; I caught Covid near the end of my vacation and it took me out for a while. So here are a few patches on top instead.
Changes since v1:
* rebased directly on top of Calvin's patch, allowing Junio's patch in cw/submodule-merge-messages to be dropped.
Changes since v2:
* changed the second patch to instead initialize sub_flag to CONFLICT_SUBMODULE_FAILED_TO_MERGE, as suggested by Junio. (thanks!)
Elijah Newren (3):
merge-ort: remove translator lego in new "submodule conflict
suggestion"
merge-ort: avoid surprise with new sub_flag variable
merge-ort: provide helpful submodule update message when possible
merge-ort.c | 104 +++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 70 deletions(-)
base-commit: 4057523a4061092e9181220d54dca9eadcb75bdc
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1325%2Fnewren%2Fsubmodule-merge-messages-fixups-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1325/newren/submodule-merge-messages-fixups-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1325
Range-diff vs v2:
1: 374278c6a1d = 1: 374278c6a1d merge-ort: remove translator lego in new "submodule conflict suggestion" 2: 340c0f46f74 < -: ----------- merge-ort: add comment to avoid surprise with new sub_flag variable -: ----------- > 2: 48200773a1b merge-ort: avoid surprise with new sub_flag variable 3: 80207d18334 = 3: 4c4a8f028d4 merge-ort: provide helpful submodule update message when possible
Signature · 1 line
gitgitgadget
PATCH v3 1/3 merge-ort: remove translator lego in new "submodule conflict suggestion"
From: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), the new "submodule conflict suggestion" code was translating 6 different pieces of the new message and then used carefully crafted logic to allow stitching it back together with special formatting. Keep the components of the message together as much as possible, so that:
* we reduce the number of things translators have to translate
* translators have more control over the format of the output
* the code is much easier for developers to understand too
Also, reformat some comments running beyond the 80th column while at it.
--- merge-ort.c | 88 +++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 60 deletions(-)
merge-ort.c +28 -60
@@ -4481,34 +4481,6 @@ static int record_conflicted_index_entries(struct merge_options *opt)return errs; } -static void format_submodule_conflict_suggestion (struct strbuf *msg) { -struct strbuf tmp =STRBUF_INIT ; -struct string_list msg_list =STRING_LIST_INIT_DUP ; -int i; - -string_list_split (&msg_list, msg->buf,'\n' ,-1 ); -for (i =0 ; i < msg_list.nr; i++) { -if (!i) -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " - %s\n" -> "%s - \n" -*/ -strbuf_addf (&tmp,_ (" - %s\n" ), msg_list.items[i].string); -else -/* -* TRANSLATORS: This is line item of submodule conflict message -* from print_submodule_conflict_suggestion() below. For RTL -* languages, the following swap is suggested: -* " %s\n" -> "%s \n" -*/ -strbuf_addf (&tmp,_ (" %s\n" ), msg_list.items[i].string); - } -strbuf_reset (msg); -strbuf_add (msg, tmp.buf, tmp.len); -} -static void print_submodule_conflict_suggestion (struct string_list *csub) {struct string_list_item *item;struct strbuf msg =STRBUF_INIT ;
@@ -4530,45 +4502,41 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {return ; } -printf (_ ("Recursive merging with submodules currently only supports " -"trivial cases.\nPlease manually handle the merging of each " -"conflicted submodule.\nThis can be accomplished with the following " -"steps:" )); -putchar ('\n' ); - +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* -* TRANSLATORS: This is a line of advice to resolve a merge conflict -* in a submodule. The second argument is the abbreviated id of the -* commit that needs to be merged. -* E.g. - go to submodule (sub), and either merge commit abc1234" +* TRANSLATORS: This is a line of advice to resolve a merge +* conflict in a submodule. The first argument is the submodule +* name, and the second argument is the abbreviated id of the +* commit that needs to be merged. For example: +* - go to submodule (mysubmodule), and either merge commit abc1234" */ -strbuf_addf (&tmp,_ ("go to submodule (%s), and either merge commit %s\n" -"or update to an existing commit which has merged those changes" ), - item->string, util->abbrev); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); +strbuf_addf (&tmp,_ (" - go to submodule (%s), and either merge commit %s\n" +" or update to an existing commit which has merged those changes\n" ), + item->string, util->abbrev); } -strbuf_add_separated_string_list (&subs," " , csub); -strbuf_addstr (&tmp,_ ("come back to superproject and run:" )); -strbuf_addf (&tmp,"\n\ngit add %s\n\n" , subs.buf); -strbuf_addstr (&tmp,_ ("to record the above merge or update" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("resolve any other conflicts in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); -strbuf_reset (&tmp); - -strbuf_addstr (&tmp,_ ("commit the resulting index in the superproject" )); -format_submodule_conflict_suggestion (&tmp); -strbuf_add (&msg, tmp.buf, tmp.len); + +/* +* TRANSLATORS: This is a detailed message for resolving submodule +* conflicts. The first argument is string containing one step per +* submodule. The second is a space-separated list of submodule names. +*/ +strbuf_addf (&msg, +_ ("Recursive merging with submodules currently only supports trivial cases.\n" +"Please manually handle the merging of each conflicted submodule.\n" +"This can be accomplished with the following steps:\n" +"%s" +" - come back to superproject and run:\n\n" +" git add %s\n\n" +" to record the above merge or update\n" +" - resolve any other conflicts in the superproject\n" +" - commit the resulting index in the superproject\n" ), + tmp.buf, subs.buf);printf ("%s" , msg.buf); +strbuf_release (&subs);strbuf_release (&tmp);strbuf_release (&msg);
Signature · 1 line
gitgitgadget
PATCH v3 2/3 merge-ort: avoid surprise with new sub_flag variable
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
Commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04) added a sub_flag variable that is used to store a value from enum conflict_and_info_types, but initializes it with a value of -1 that does not correspond to any of the conflict_and_info_types. The code may never set it to a valid value and yet still use it, which can be surprising when reading over the code at first. Initialize it instead to the generic CONFLICT_SUBMODULE_FAILED_TO_MERGE value, which is still distinct from the two values we need to special case.
--- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-ort.c +1 -1
@@ -1767,7 +1767,7 @@ static int merge_submodule(struct merge_options *opt,int i;int search = !opt->priv->call_depth;int sub_not_initialized =1 ; -int sub_flag =-1 ; +int sub_flag =CONFLICT_SUBMODULE_FAILED_TO_MERGE ;/* store fallback answer in result in case we fail */ oidcpy (result, opt->priv->call_depth ? o : a);
Signature · 1 line
gitgitgadget
PATCH v3 3/3 merge-ort: provide helpful submodule update message when possible
In reply to Elijah Newren via GitGitGadgetFrom: Elijah Newren <[email protected]>
In commit 4057523a40 ("submodule merge: update conflict error message", 2022-08-04), a more detailed message was provided when submodules conflict, in order to help users know how to resolve those conflicts. There were a couple situations for which a different message would be more appropriate, but that commit left handling those for future work. Unfortunately, that commit would check if any submodules were of the type that it didn't know how to explain, and, if so, would avoid providing the more detailed explanation even for the submodules it did know how to explain.
Change this to have the code print the helpful messages for the subset of submodules it knows how to explain.
--- merge-ort.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
merge-ort.c +7 -11
@@ -4490,21 +4490,17 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {if (!csub->nr)return ; -/* -* NEEDSWORK: The steps to resolve these errors deserve a more -* detailed explanation than what is currently printed below. -*/ +strbuf_add_separated_string_list (&subs," " , csub);for_each_string_list_item (item, csub) {struct conflicted_submodule_item *util = item->util; +/* +* NEEDSWORK: The steps to resolve these errors deserve a more +* detailed explanation than what is currently printed below. +*/ if (util->flag ==CONFLICT_SUBMODULE_NOT_INITIALIZED || - util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) -return ; - } - -strbuf_add_separated_string_list (&subs," " , csub); -for_each_string_list_item (item, csub) { -struct conflicted_submodule_item *util = item->util; + util->flag ==CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ) +continue ;/* * TRANSLATORS: This is a line of advice to resolve a merge
Signature · 1 line
gitgitgadget