@@ -691,16 +691,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
691
691
struct strbuf committer_ident = STRBUF_INIT ;
692
692
int committable ;
693
693
struct strbuf sb = STRBUF_INIT ;
694
- const char * hook_arg1 = NULL ;
695
- const char * hook_arg2 = NULL ;
694
+ struct strvec hook_args = STRVEC_INIT ;
696
695
int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE );
697
696
int old_display_comment_prefix ;
698
697
int merge_contains_scissors = 0 ;
699
698
700
699
/* This checks and barfs if author is badly specified */
701
700
determine_author_info (author_ident );
702
701
703
- if (!no_verify && run_commit_hook (use_editor , index_file , "pre-commit" , NULL ))
702
+ if (!no_verify && run_commit_hook (use_editor , index_file , "pre-commit" ,
703
+ & hook_args ))
704
704
return 0 ;
705
705
706
706
if (squash_message ) {
@@ -722,27 +722,28 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
722
722
}
723
723
}
724
724
725
+ strvec_push (& hook_args , git_path_commit_editmsg ());
726
+
725
727
if (have_option_m && !fixup_message ) {
726
728
strbuf_addbuf (& sb , & message );
727
- hook_arg1 = "message" ;
729
+ strvec_push ( & hook_args , "message" ) ;
728
730
} else if (logfile && !strcmp (logfile , "-" )) {
729
731
if (isatty (0 ))
730
732
fprintf (stderr , _ ("(reading log message from standard input)\n" ));
731
733
if (strbuf_read (& sb , 0 , 0 ) < 0 )
732
734
die_errno (_ ("could not read log from standard input" ));
733
- hook_arg1 = "message" ;
735
+ strvec_push ( & hook_args , "message" ) ;
734
736
} else if (logfile ) {
735
737
if (strbuf_read_file (& sb , logfile , 0 ) < 0 )
736
738
die_errno (_ ("could not read log file '%s'" ),
737
739
logfile );
738
- hook_arg1 = "message" ;
740
+ strvec_push ( & hook_args , "message" ) ;
739
741
} else if (use_message ) {
740
742
char * buffer ;
741
743
buffer = strstr (use_message_buffer , "\n\n" );
742
744
if (buffer )
743
745
strbuf_addstr (& sb , skip_blank_lines (buffer + 2 ));
744
- hook_arg1 = "commit" ;
745
- hook_arg2 = use_message ;
746
+ strvec_pushl (& hook_args , "commit" , use_message , NULL );
746
747
} else if (fixup_message ) {
747
748
struct pretty_print_context ctx = {0 };
748
749
struct commit * commit ;
@@ -754,7 +755,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
754
755
& sb , & ctx );
755
756
if (have_option_m )
756
757
strbuf_addbuf (& sb , & message );
757
- hook_arg1 = "message" ;
758
+ strvec_push ( & hook_args , "message" ) ;
758
759
} else if (!stat (git_path_merge_msg (the_repository ), & statbuf )) {
759
760
size_t merge_msg_start ;
760
761
@@ -765,9 +766,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
765
766
if (!stat (git_path_squash_msg (the_repository ), & statbuf )) {
766
767
if (strbuf_read_file (& sb , git_path_squash_msg (the_repository ), 0 ) < 0 )
767
768
die_errno (_ ("could not read SQUASH_MSG" ));
768
- hook_arg1 = "squash" ;
769
+ strvec_push ( & hook_args , "squash" ) ;
769
770
} else
770
- hook_arg1 = "merge" ;
771
+ strvec_push ( & hook_args , "merge" ) ;
771
772
772
773
merge_msg_start = sb .len ;
773
774
if (strbuf_read_file (& sb , git_path_merge_msg (the_repository ), 0 ) < 0 )
@@ -781,11 +782,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
781
782
} else if (!stat (git_path_squash_msg (the_repository ), & statbuf )) {
782
783
if (strbuf_read_file (& sb , git_path_squash_msg (the_repository ), 0 ) < 0 )
783
784
die_errno (_ ("could not read SQUASH_MSG" ));
784
- hook_arg1 = "squash" ;
785
+ strvec_push ( & hook_args , "squash" ) ;
785
786
} else if (template_file ) {
786
787
if (strbuf_read_file (& sb , template_file , 0 ) < 0 )
787
788
die_errno (_ ("could not read '%s'" ), template_file );
788
- hook_arg1 = "template" ;
789
+ strvec_push ( & hook_args , "template" ) ;
789
790
clean_message_contents = 0 ;
790
791
}
791
792
@@ -794,20 +795,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
794
795
* just set the argument(s) to the prepare-commit-msg hook.
795
796
*/
796
797
else if (whence == FROM_MERGE )
797
- hook_arg1 = "merge" ;
798
- else if (is_from_cherry_pick (whence ) || whence == FROM_REBASE_PICK ) {
799
- hook_arg1 = "commit" ;
800
- hook_arg2 = "CHERRY_PICK_HEAD" ;
801
- }
798
+ strvec_push (& hook_args , "merge" );
799
+ else if (is_from_cherry_pick (whence ) || whence == FROM_REBASE_PICK )
800
+ strvec_pushl (& hook_args , "commit" , "CHERRY_PICK_HEAD" , NULL );
802
801
803
802
if (squash_message ) {
804
803
/*
805
804
* If squash_commit was used for the commit subject,
806
805
* then we're possibly hijacking other commit log options.
807
806
* Reset the hook args to tell the real story.
808
807
*/
809
- hook_arg1 = "message" ;
810
- hook_arg2 = "" ;
808
+ strvec_clear ( & hook_args ) ;
809
+ strvec_pushl ( & hook_args , git_path_commit_editmsg (), "message" , NULL ) ;
811
810
}
812
811
813
812
s -> fp = fopen_for_writing (git_path_commit_editmsg ());
@@ -999,8 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
999
998
return 0 ;
1000
999
}
1001
1000
1002
- if (run_commit_hook (use_editor , index_file , "prepare-commit-msg" ,
1003
- git_path_commit_editmsg (), hook_arg1 , hook_arg2 , NULL ))
1001
+ if (run_commit_hook (use_editor , index_file , "prepare-commit-msg" , & hook_args ))
1004
1002
return 0 ;
1005
1003
1006
1004
if (use_editor ) {
@@ -1015,8 +1013,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1015
1013
strvec_clear (& env );
1016
1014
}
1017
1015
1016
+ strvec_clear (& hook_args );
1017
+ strvec_push (& hook_args , git_path_commit_editmsg ());
1018
1018
if (!no_verify &&
1019
- run_commit_hook (use_editor , index_file , "commit-msg" , git_path_commit_editmsg (), NULL )) {
1019
+ run_commit_hook (use_editor , index_file , "commit-msg" , & hook_args )) {
1020
1020
return 0 ;
1021
1021
}
1022
1022
0 commit comments