| 454 | } |
| 455 | |
| 456 | const char *fmt_ident(const char *name, const char *email, |
| 457 | enum want_ident whose_ident, const char *date_str, int flag) |
| 458 | { |
| 459 | static int index; |
| 460 | static struct strbuf ident_pool[2] = { STRBUF_INIT, STRBUF_INIT }; |
| 461 | int strict = (flag & IDENT_STRICT); |
| 462 | int want_date = !(flag & IDENT_NO_DATE); |
| 463 | int want_name = !(flag & IDENT_NO_NAME); |
| 464 | |
| 465 | struct strbuf *ident = &ident_pool[index]; |
| 466 | index = (index + 1) % ARRAY_SIZE(ident_pool); |
| 467 | |
| 468 | if (!email) { |
| 469 | if (whose_ident == WANT_AUTHOR_IDENT && git_author_email.len) |
| 470 | email = git_author_email.buf; |
| 471 | else if (whose_ident == WANT_COMMITTER_IDENT && git_committer_email.len) |
| 472 | email = git_committer_email.buf; |
| 473 | } |
| 474 | if (!email) { |
| 475 | if (strict && ident_use_config_only |
| 476 | && !(ident_config_given & IDENT_MAIL_GIVEN)) { |
| 477 | ident_env_hint(whose_ident); |
| 478 | die(_("no email was given and auto-detection is disabled")); |
| 479 | } |
| 480 | email = ident_default_email(); |
| 481 | if (strict && default_email_is_bogus) { |
| 482 | ident_env_hint(whose_ident); |
| 483 | die(_("unable to auto-detect email address (got '%s')"), email); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | if (want_name) { |
| 488 | int using_default = 0; |
| 489 | if (!name) { |
| 490 | if (whose_ident == WANT_AUTHOR_IDENT && git_author_name.len) |
| 491 | name = git_author_name.buf; |
| 492 | else if (whose_ident == WANT_COMMITTER_IDENT && |
| 493 | git_committer_name.len) |
| 494 | name = git_committer_name.buf; |
| 495 | } |
| 496 | if (!name) { |
| 497 | if (strict && ident_use_config_only |
| 498 | && !(ident_config_given & IDENT_NAME_GIVEN)) { |
| 499 | ident_env_hint(whose_ident); |
| 500 | die(_("no name was given and auto-detection is disabled")); |
| 501 | } |
| 502 | name = ident_default_name(); |
| 503 | using_default = 1; |
| 504 | if (strict && default_name_is_bogus) { |
| 505 | ident_env_hint(whose_ident); |
| 506 | die(_("unable to auto-detect name (got '%s')"), name); |
| 507 | } |
| 508 | } |
| 509 | if (!*name) { |
| 510 | struct passwd *pw; |
| 511 | if (strict) { |
| 512 | if (using_default) |
| 513 | ident_env_hint(whose_ident); |
no test coverage detected