MCPcopy Index your code
hub / github.com/git/git / read_author_script

Function read_author_script

sequencer.c:962–1019  ·  view source on GitHub ↗

* Reads and parses the state directory's "author-script" file, and sets name, * email and date accordingly. * Returns 0 on success, -1 if the file could not be parsed. * * The author script is of the format: * * GIT_AUTHOR_NAME='$author_name' * GIT_AUTHOR_EMAIL='$author_email' * GIT_AUTHOR_DATE='$author_date' * * where $author_name, $author_email and $author_date are quoted. We are stric

Source from the content-addressed store, hash-verified

960 * something that the user does not expect.
961 */
962int read_author_script(const char *path, char **name, char **email, char **date,
963 int allow_missing)
964{
965 struct strbuf buf = STRBUF_INIT;
966 struct string_list kv = STRING_LIST_INIT_DUP;
967 int retval = -1; /* assume failure */
968 int i, name_i = -2, email_i = -2, date_i = -2, err = 0;
969
970 if (strbuf_read_file(&buf, path, 256) <= 0) {
971 strbuf_release(&buf);
972 if (errno == ENOENT && allow_missing)
973 return 0;
974 else
975 return error_errno(_("could not open '%s' for reading"),
976 path);
977 }
978
979 if (parse_key_value_squoted(buf.buf, &kv))
980 goto finish;
981
982 for (i = 0; i < kv.nr; i++) {
983 if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) {
984 if (name_i != -2)
985 name_i = error(_("'GIT_AUTHOR_NAME' already given"));
986 else
987 name_i = i;
988 } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) {
989 if (email_i != -2)
990 email_i = error(_("'GIT_AUTHOR_EMAIL' already given"));
991 else
992 email_i = i;
993 } else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) {
994 if (date_i != -2)
995 date_i = error(_("'GIT_AUTHOR_DATE' already given"));
996 else
997 date_i = i;
998 } else {
999 err = error(_("unknown variable '%s'"),
1000 kv.items[i].string);
1001 }
1002 }
1003 if (name_i == -2)
1004 error(_("missing 'GIT_AUTHOR_NAME'"));
1005 if (email_i == -2)
1006 error(_("missing 'GIT_AUTHOR_EMAIL'"));
1007 if (date_i == -2)
1008 error(_("missing 'GIT_AUTHOR_DATE'"));
1009 if (name_i < 0 || email_i < 0 || date_i < 0 || err)
1010 goto finish;
1011 *name = kv.items[name_i].util;
1012 *email = kv.items[email_i].util;
1013 *date = kv.items[date_i].util;
1014 retval = 0;
1015finish:
1016 string_list_clear(&kv, !!retval);
1017 strbuf_release(&buf);
1018 return retval;
1019}

Callers 2

read_env_scriptFunction · 0.85
read_am_author_scriptFunction · 0.85

Calls 6

strbuf_read_fileFunction · 0.85
strbuf_releaseFunction · 0.85
error_errnoFunction · 0.85
parse_key_value_squotedFunction · 0.85
errorFunction · 0.85
string_list_clearFunction · 0.85

Tested by

no test coverage detected