@@ -49,7 +49,7 @@ static const char * const builtin_commit_usage[] = {
4949 " [--dry-run] [(-c | -C | --squash) <commit> | --fixup [(amend|reword):]<commit>]\n"
5050 " [-F <file> | -m <msg>] [--reset-author] [--allow-empty]\n"
5151 " [--allow-empty-message] [--no-verify] [-e] [--author=<author>]\n"
52- " [--date=<date>] [--cleanup=<mode>] [--[no-]status]\n"
52+ " [--date=<date>] [--committer=<committer>] [-- cleanup=<mode>] [--[no-]status]\n"
5353 " [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n"
5454 " [(--trailer <token>[(=|:)<value>])...] [-S[<keyid>]]\n"
5555 " [--] [<pathspec>...]" ),
@@ -112,6 +112,7 @@ static enum {
112112} commit_style ;
113113
114114static const char * force_author ;
115+ static const char * force_committer ;
115116static char * logfile ;
116117static char * template_file ;
117118/*
@@ -690,6 +691,48 @@ static void determine_author_info(struct strbuf *author_ident)
690691 free (date );
691692}
692693
694+ static void determine_committer_info (struct strbuf * committer_ident )
695+ {
696+ char * name , * email , * date ;
697+ struct ident_split committer ;
698+
699+ name = xstrdup_or_null (getenv ("GIT_COMMITTER_NAME" ));
700+ email = xstrdup_or_null (getenv ("GIT_COMMITTER_EMAIL" ));
701+ date = xstrdup_or_null (getenv ("GIT_COMMITTER_DATE" ));
702+
703+ if (force_committer ) {
704+ struct ident_split ident ;
705+
706+ if (split_ident_line (& ident , force_committer , strlen (force_committer )) < 0 )
707+ die (_ ("malformed --committer parameter" ));
708+ set_ident_var (& name , xmemdupz (ident .name_begin , ident .name_end - ident .name_begin ));
709+ set_ident_var (& email , xmemdupz (ident .mail_begin , ident .mail_end - ident .mail_begin ));
710+
711+ if (ident .date_begin ) {
712+ struct strbuf date_buf = STRBUF_INIT ;
713+ strbuf_addch (& date_buf , '@' );
714+ strbuf_add (& date_buf , ident .date_begin , ident .date_end - ident .date_begin );
715+ strbuf_addch (& date_buf , ' ' );
716+ strbuf_add (& date_buf , ident .tz_begin , ident .tz_end - ident .tz_begin );
717+ set_ident_var (& date , strbuf_detach (& date_buf , NULL ));
718+ }
719+ }
720+
721+ if (force_date ) {
722+ struct strbuf date_buf = STRBUF_INIT ;
723+ if (parse_force_date (force_date , & date_buf ))
724+ die (_ ("invalid date format: %s" ), force_date );
725+ set_ident_var (& date , strbuf_detach (& date_buf , NULL ));
726+ }
727+
728+ strbuf_addstr (committer_ident , fmt_ident (name , email , WANT_COMMITTER_IDENT , date ,
729+ IDENT_STRICT ));
730+ assert_split_ident (& committer , committer_ident );
731+ free (name );
732+ free (email );
733+ free (date );
734+ }
735+
693736static int author_date_is_interesting (void )
694737{
695738 return author_message || force_date ;
@@ -1321,6 +1364,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
13211364 if (force_author && renew_authorship )
13221365 die (_ ("options '%s' and '%s' cannot be used together" ), "--reset-author" , "--author" );
13231366
1367+ if (force_committer && !strchr (force_committer , '>' ))
1368+ force_committer = find_author_by_nickname (force_committer );
1369+
13241370 if (logfile || have_option_m || use_message )
13251371 use_editor = 0 ;
13261372
@@ -1709,6 +1755,7 @@ int cmd_commit(int argc,
17091755 OPT_FILENAME ('F' , "file" , & logfile , N_ ("read message from file" )),
17101756 OPT_STRING (0 , "author" , & force_author , N_ ("author" ), N_ ("override author for commit" )),
17111757 OPT_STRING (0 , "date" , & force_date , N_ ("date" ), N_ ("override date for commit" )),
1758+ OPT_STRING (0 , "committer" , & force_committer , N_ ("committer" ), N_ ("override committer for commit" )),
17121759 OPT_CALLBACK ('m' , "message" , & message , N_ ("message" ), N_ ("commit message" ), opt_parse_m ),
17131760 OPT_STRING ('c' , "reedit-message" , & edit_message , N_ ("commit" ), N_ ("reuse and edit message from specified commit" )),
17141761 OPT_STRING ('C' , "reuse-message" , & use_message , N_ ("commit" ), N_ ("reuse message from specified commit" )),
@@ -1785,6 +1832,7 @@ int cmd_commit(int argc,
17851832
17861833 struct strbuf sb = STRBUF_INIT ;
17871834 struct strbuf author_ident = STRBUF_INIT ;
1835+ struct strbuf committer_ident = STRBUF_INIT ;
17881836 const char * index_file , * reflog_msg ;
17891837 struct object_id oid ;
17901838 struct commit_list * parents = NULL ;
@@ -1930,8 +1978,13 @@ int cmd_commit(int argc,
19301978 append_merge_tag_headers (parents , & tail );
19311979 }
19321980
1981+ if (force_committer ) {
1982+ determine_committer_info (& committer_ident );
1983+ }
1984+
19331985 if (commit_tree_extended (sb .buf , sb .len , & the_repository -> index -> cache_tree -> oid ,
1934- parents , & oid , author_ident .buf , NULL ,
1986+ parents , & oid , author_ident .buf ,
1987+ force_committer ? committer_ident .buf : NULL ,
19351988 sign_commit , extra )) {
19361989 rollback_index_files ();
19371990 die (_ ("failed to write commit object" ));
@@ -1980,6 +2033,7 @@ int cmd_commit(int argc,
19802033 free_commit_extra_headers (extra );
19812034 free_commit_list (parents );
19822035 strbuf_release (& author_ident );
2036+ strbuf_release (& committer_ident );
19832037 strbuf_release (& err );
19842038 strbuf_release (& sb );
19852039 free (logfile );
0 commit comments