MCPcopy Create free account
hub / github.com/git/git / determine_author_info

Function determine_author_info

builtin/commit.c:634–692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632}
633
634static void determine_author_info(struct strbuf *author_ident)
635{
636 char *name, *email, *date;
637 struct ident_split author;
638
639 name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME"));
640 email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL"));
641 date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE"));
642
643 if (author_message) {
644 struct ident_split ident;
645 size_t len;
646 const char *a;
647
648 a = find_commit_header(author_message_buffer, "author", &len);
649 if (!a)
650 die(_("commit '%s' lacks author header"), author_message);
651 if (split_ident_line(&ident, a, len) < 0)
652 die(_("commit '%s' has malformed author line"), author_message);
653
654 set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
655 set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
656
657 if (ident.date_begin) {
658 struct strbuf date_buf = STRBUF_INIT;
659 strbuf_addch(&date_buf, '@');
660 strbuf_add(&date_buf, ident.date_begin, ident.date_end - ident.date_begin);
661 strbuf_addch(&date_buf, ' ');
662 strbuf_add(&date_buf, ident.tz_begin, ident.tz_end - ident.tz_begin);
663 set_ident_var(&date, strbuf_detach(&date_buf, NULL));
664 }
665 }
666
667 if (force_author) {
668 struct ident_split ident;
669
670 if (split_ident_line(&ident, force_author, strlen(force_author)) < 0)
671 die(_("malformed --author parameter"));
672 set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
673 set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
674 }
675
676 if (force_date) {
677 struct strbuf date_buf = STRBUF_INIT;
678 if (parse_force_date(force_date, &date_buf))
679 die(_("invalid date format: %s"), force_date);
680 set_ident_var(&date, strbuf_detach(&date_buf, NULL));
681 }
682
683 strbuf_addstr(author_ident, fmt_ident(name, email, WANT_AUTHOR_IDENT, date,
684 IDENT_STRICT));
685 assert_split_ident(&author, author_ident);
686 export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
687 export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
688 export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
689 free(name);
690 free(email);
691 free(date);

Callers 1

prepare_to_commitFunction · 0.85

Calls 14

xstrdup_or_nullFunction · 0.85
find_commit_headerFunction · 0.85
split_ident_lineFunction · 0.85
set_ident_varFunction · 0.85
xmemdupzFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_addFunction · 0.85
strbuf_detachFunction · 0.85
parse_force_dateFunction · 0.85
strbuf_addstrFunction · 0.85
fmt_identFunction · 0.85
assert_split_identFunction · 0.85

Tested by

no test coverage detected