diff mbox series

[v3,3/7] sequencer: use rebase_path_message()

Message ID 8f6c0e4056742951ce84acbdb07b0518f7607b2a.1690903412.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit 9f67899b41e5a95ce31af38c6b6d600433546d9e
Headers show
Series rebase -i: impove handling of failed commands | expand

Commit Message

Phillip Wood Aug. 1, 2023, 3:23 p.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Rather than constructing the path in a struct strbuf use the ready
made function to get the path name instead. This was the last
remaining use of the strbuf so remove it as well.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Junio C Hamano Aug. 1, 2023, 5:23 p.m. UTC | #1
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Rather than constructing the path in a struct strbuf use the ready
> made function to get the path name instead. This was the last
> remaining use of the strbuf so remove it as well.

The same comment about "get_dir() vs hardcoded rebase-merge" applies
here, I think.  And the same (1) assertion to ensure that we are in
"rebase -i" when make_patch() is called should give us a sufficient
safety valve, or (2) instead of hardcoding rebase_path_message(),
call it sequencer_path_message() and switch at runtime behaving the
same way as get_dir(opts) based version, would also work.

Thanks.

> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  sequencer.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index 70b0a7023b0..dbddd19b2c2 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -3501,7 +3501,6 @@ static int make_patch(struct repository *r,
>  		      struct commit *commit,
>  		      struct replay_opts *opts)
>  {
> -	struct strbuf buf = STRBUF_INIT;
>  	struct rev_info log_tree_opt;
>  	const char *subject;
>  	char hex[GIT_MAX_HEXSZ + 1];
> @@ -3529,18 +3528,16 @@ static int make_patch(struct repository *r,
>  		fclose(log_tree_opt.diffopt.file);
>  	}
>  
> -	strbuf_addf(&buf, "%s/message", get_dir(opts));
> -	if (!file_exists(buf.buf)) {
> +	if (!file_exists(rebase_path_message())) {
>  		const char *encoding = get_commit_output_encoding();
>  		const char *commit_buffer = repo_logmsg_reencode(r,
>  								 commit, NULL,
>  								 encoding);
>  		find_commit_subject(commit_buffer, &subject);
> -		res |= write_message(subject, strlen(subject), buf.buf, 1);
> +		res |= write_message(subject, strlen(subject), rebase_path_message(), 1);
>  		repo_unuse_commit_buffer(r, commit,
>  					 commit_buffer);
>  	}
> -	strbuf_release(&buf);
>  	release_revisions(&log_tree_opt);
>  
>  	return res;
Phillip Wood Aug. 1, 2023, 6:49 p.m. UTC | #2
On 01/08/2023 18:23, Junio C Hamano wrote:
> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> Rather than constructing the path in a struct strbuf use the ready
>> made function to get the path name instead. This was the last
>> remaining use of the strbuf so remove it as well.
> 
> The same comment about "get_dir() vs hardcoded rebase-merge" applies
> here, I think.  And the same (1) assertion to ensure that we are in
> "rebase -i" when make_patch() is called should give us a sufficient
> safety valve,

Agreed

> or (2) instead of hardcoding rebase_path_message(),
> call it sequencer_path_message() and switch at runtime behaving the
> same way as get_dir(opts) based version, would also work.

I think that would me misleading because cherry-pick/revert do not 
create that file - they rely on "git commit" reading .git/MERGE_MSG

Best Wishes

Phillip

> Thanks.
> 
>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>> ---
>>   sequencer.c | 7 ++-----
>>   1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/sequencer.c b/sequencer.c
>> index 70b0a7023b0..dbddd19b2c2 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -3501,7 +3501,6 @@ static int make_patch(struct repository *r,
>>   		      struct commit *commit,
>>   		      struct replay_opts *opts)
>>   {
>> -	struct strbuf buf = STRBUF_INIT;
>>   	struct rev_info log_tree_opt;
>>   	const char *subject;
>>   	char hex[GIT_MAX_HEXSZ + 1];
>> @@ -3529,18 +3528,16 @@ static int make_patch(struct repository *r,
>>   		fclose(log_tree_opt.diffopt.file);
>>   	}
>>   
>> -	strbuf_addf(&buf, "%s/message", get_dir(opts));
>> -	if (!file_exists(buf.buf)) {
>> +	if (!file_exists(rebase_path_message())) {
>>   		const char *encoding = get_commit_output_encoding();
>>   		const char *commit_buffer = repo_logmsg_reencode(r,
>>   								 commit, NULL,
>>   								 encoding);
>>   		find_commit_subject(commit_buffer, &subject);
>> -		res |= write_message(subject, strlen(subject), buf.buf, 1);
>> +		res |= write_message(subject, strlen(subject), rebase_path_message(), 1);
>>   		repo_unuse_commit_buffer(r, commit,
>>   					 commit_buffer);
>>   	}
>> -	strbuf_release(&buf);
>>   	release_revisions(&log_tree_opt);
>>   
>>   	return res;
Junio C Hamano Aug. 2, 2023, 10:02 p.m. UTC | #3
Phillip Wood <phillip.wood123@gmail.com> writes:

> On 01/08/2023 18:23, Junio C Hamano wrote:
>> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
>> 
>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>
>>> Rather than constructing the path in a struct strbuf use the ready
>>> made function to get the path name instead. This was the last
>>> remaining use of the strbuf so remove it as well.
>> The same comment about "get_dir() vs hardcoded rebase-merge" applies
>> here, I think.  And the same (1) assertion to ensure that we are in
>> "rebase -i" when make_patch() is called should give us a sufficient
>> safety valve,
>
> Agreed
>
>> or (2) instead of hardcoding rebase_path_message(),
>> call it sequencer_path_message() and switch at runtime behaving the
>> same way as get_dir(opts) based version, would also work.
>
> I think that would me misleading because cherry-pick/revert do not
> create that file - they rely on "git commit" reading .git/MERGE_MSG

Fair enough.  

Abusing the MERGE_MSG this way probably came from the "if 'commit'
picks up whatever is left inside MERGE_MSG when it is run, reusing
it for this operation (even though it clearly is not a 'merge')
would be a way to do with the least effort, even if it does not make
sense for those who will be reading the code 3 years from now on"
kind of hackery.  The file probably outgrew its name and we might
want to rename it to a more appropriate name (it is "we gave control
back to the user to help us resolve a mess in the working tree, and
here is the message to be used when the user is done"; the "mess" no
longer is limited to conflicts created during a "merge").

But it would be a major headache if end-user tools are relying on
it, so it is not likely to happen anytime soon.

So, moving to hardcoded "rebase-merge", as long as we make sure
make_patch() will only callable by "rebase -i" (and not something
like "cherry-pick -i" people will wish to add in the future), I am
fine with such a design.

Thanks.
diff mbox series

Patch

diff --git a/sequencer.c b/sequencer.c
index 70b0a7023b0..dbddd19b2c2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3501,7 +3501,6 @@  static int make_patch(struct repository *r,
 		      struct commit *commit,
 		      struct replay_opts *opts)
 {
-	struct strbuf buf = STRBUF_INIT;
 	struct rev_info log_tree_opt;
 	const char *subject;
 	char hex[GIT_MAX_HEXSZ + 1];
@@ -3529,18 +3528,16 @@  static int make_patch(struct repository *r,
 		fclose(log_tree_opt.diffopt.file);
 	}
 
-	strbuf_addf(&buf, "%s/message", get_dir(opts));
-	if (!file_exists(buf.buf)) {
+	if (!file_exists(rebase_path_message())) {
 		const char *encoding = get_commit_output_encoding();
 		const char *commit_buffer = repo_logmsg_reencode(r,
 								 commit, NULL,
 								 encoding);
 		find_commit_subject(commit_buffer, &subject);
-		res |= write_message(subject, strlen(subject), buf.buf, 1);
+		res |= write_message(subject, strlen(subject), rebase_path_message(), 1);
 		repo_unuse_commit_buffer(r, commit,
 					 commit_buffer);
 	}
-	strbuf_release(&buf);
 	release_revisions(&log_tree_opt);
 
 	return res;