@@ -620,6 +620,36 @@ static int author_date_is_interesting(void)
620620 return author_message || force_date ;
621621}
622622
623+ static void adjust_comment_line_char (const struct strbuf * sb )
624+ {
625+ char candidates [] = "#;@!$%^&|:" ;
626+ char * candidate ;
627+ const char * p ;
628+
629+ comment_line_char = candidates [0 ];
630+ if (!memchr (sb -> buf , comment_line_char , sb -> len ))
631+ return ;
632+
633+ p = sb -> buf ;
634+ candidate = strchr (candidates , * p );
635+ if (candidate )
636+ * candidate = ' ' ;
637+ for (p = sb -> buf ; * p ; p ++ ) {
638+ if ((p [0 ] == '\n' || p [0 ] == '\r' ) && p [1 ]) {
639+ candidate = strchr (candidates , p [1 ]);
640+ if (candidate )
641+ * candidate = ' ' ;
642+ }
643+ }
644+
645+ for (p = candidates ; * p == ' ' ; p ++ )
646+ ;
647+ if (!* p )
648+ die (_ ("unable to select a comment character that is not used\n"
649+ "in the current commit message" ));
650+ comment_line_char = * p ;
651+ }
652+
623653static int prepare_to_commit (const char * index_file , const char * prefix ,
624654 struct commit * current_head ,
625655 struct wt_status * s ,
@@ -773,6 +803,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
773803 if (fwrite (sb .buf , 1 , sb .len , s -> fp ) < sb .len )
774804 die_errno (_ ("could not write commit template" ));
775805
806+ if (auto_comment_line_char )
807+ adjust_comment_line_char (& sb );
776808 strbuf_release (& sb );
777809
778810 /* This checks if committer ident is explicitly given */
0 commit comments