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

Function get_commit_info

builtin/am.c:1353–1393  ·  view source on GitHub ↗

* Sets state->msg, state->author_name, state->author_email, state->author_date * to the commit's respective info. */

Source from the content-addressed store, hash-verified

1351 * to the commit's respective info.
1352 */
1353static void get_commit_info(struct am_state *state, struct commit *commit)
1354{
1355 const char *buffer, *ident_line, *msg;
1356 size_t ident_len;
1357 struct ident_split id;
1358
1359 buffer = repo_logmsg_reencode(the_repository, commit, NULL,
1360 get_commit_output_encoding());
1361
1362 ident_line = find_commit_header(buffer, "author", &ident_len);
1363 if (!ident_line)
1364 die(_("missing author line in commit %s"),
1365 oid_to_hex(&commit->object.oid));
1366 if (split_ident_line(&id, ident_line, ident_len) < 0)
1367 die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
1368
1369 assert(!state->author_name);
1370 if (id.name_begin)
1371 state->author_name =
1372 xmemdupz(id.name_begin, id.name_end - id.name_begin);
1373 else
1374 state->author_name = xstrdup("");
1375
1376 assert(!state->author_email);
1377 if (id.mail_begin)
1378 state->author_email =
1379 xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
1380 else
1381 state->author_email = xstrdup("");
1382
1383 assert(!state->author_date);
1384 state->author_date = xstrdup(show_ident_date(&id, DATE_MODE(NORMAL)));
1385
1386 assert(!state->msg);
1387 msg = strstr(buffer, "\n\n");
1388 if (!msg)
1389 die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
1390 state->msg = xstrdup(msg + 2);
1391 state->msg_len = strlen(state->msg);
1392 repo_unuse_commit_buffer(the_repository, commit, buffer);
1393}
1394
1395/**
1396 * Writes `commit` as a patch to the state directory's "patch" file.

Callers 1

parse_mail_rebaseFunction · 0.70

Calls 10

repo_logmsg_reencodeFunction · 0.85
find_commit_headerFunction · 0.85
oid_to_hexFunction · 0.85
split_ident_lineFunction · 0.85
xmemdupzFunction · 0.85
xstrdupFunction · 0.85
show_ident_dateFunction · 0.85
repo_unuse_commit_bufferFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected