11
static struct strbuf git_default_name = STRBUF_INIT;
12
static struct strbuf git_default_email = STRBUF_INIT;
13
static struct strbuf git_default_date = STRBUF_INIT;
14
+static struct strbuf git_author_name = STRBUF_INIT;
15
+static struct strbuf git_author_email = STRBUF_INIT;
16
+static struct strbuf git_committer_name = STRBUF_INIT;
17
+static struct strbuf git_committer_email = STRBUF_INIT;
18
static int default_email_is_bogus;
19
static int default_name_is_bogus;
20
359
"\n");
360
361
const char *fmt_ident(const char *name, const char *email,
358
- const char *date_str, int flag)
362
+ enum want_ident whose_ident, const char *date_str, int flag)
363
{
364
static struct strbuf ident = STRBUF_INIT;
365
int strict = (flag & IDENT_STRICT);
366
int want_date = !(flag & IDENT_NO_DATE);
367
int want_name = !(flag & IDENT_NO_NAME);
368
369
+ if (!email) {
370
+ if (whose_ident == WANT_AUTHOR_IDENT && git_author_email.len)
371
+ email = git_author_email.buf;
372
+ else if (whose_ident == WANT_COMMITTER_IDENT && git_committer_email.len)
373
+ email = git_committer_email.buf;
374
+ }
375
if (!email) {
376
if (strict && ident_use_config_only
377
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
387
388
if (want_name) {
389
int using_default = 0;
390
+ if (!name) {
391
+ if (whose_ident == WANT_AUTHOR_IDENT && git_author_name.len)
392
+ name = git_author_name.buf;
393
+ else if (whose_ident == WANT_COMMITTER_IDENT &&
394
+ git_committer_name.len)
395
+ name = git_committer_name.buf;
396
+ }
397
if (!name) {
398
if (strict && ident_use_config_only
399
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
442
return ident.buf;
443
}
444
428
-const char *fmt_name(const char *name, const char *email)
445
+const char *fmt_name(enum want_ident whose_ident)
446
{
430
- return fmt_ident(name, email, NULL, IDENT_STRICT | IDENT_NO_DATE);
447
+ char *name = NULL;
448
+ char *email = NULL;
449
+
450
+ switch (whose_ident) {
451
+ case WANT_BLANK_IDENT:
452
+ break;
453
+ case WANT_AUTHOR_IDENT:
454
+ name = getenv("GIT_AUTHOR_NAME");
455
+ email = getenv("GIT_AUTHOR_EMAIL");
456
+ break;
457
+ case WANT_COMMITTER_IDENT:
458
+ name = getenv("GIT_COMMITTER_NAME");
459
+ email = getenv("GIT_COMMITTER_EMAIL");
460
+ break;
461
+ }
462
+ return fmt_ident(name, email, whose_ident, NULL,
463
+ IDENT_STRICT | IDENT_NO_DATE);
464
}
465
466
const char *git_author_info(int flag)
471
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
472
return fmt_ident(getenv("GIT_AUTHOR_NAME"),
473
getenv("GIT_AUTHOR_EMAIL"),
474
+ WANT_AUTHOR_IDENT,
475
getenv("GIT_AUTHOR_DATE"),
476
flag);
477
}
484
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
485
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
486
getenv("GIT_COMMITTER_EMAIL"),
487
+ WANT_COMMITTER_IDENT,
488
getenv("GIT_COMMITTER_DATE"),
489
flag);
490
}
508
return ident_is_sufficient(author_ident_explicitly_given);
509
}
510
476
-int git_ident_config(const char *var, const char *value, void *data)
511
+static int set_ident(const char *var, const char *value)
512
{
478
- if (!strcmp(var, "user.useconfigonly")) {
479
- ident_use_config_only = git_config_bool(var, value);
513
+ if (!strcmp(var, "author.name")) {
514
+ if (!value)
515
+ return config_error_nonbool(var);
516
+ strbuf_reset(&git_author_name);
517
+ strbuf_addstr(&git_author_name, value);
518
+ author_ident_explicitly_given |= IDENT_NAME_GIVEN;
519
+ ident_config_given |= IDENT_NAME_GIVEN;
520
+ return 0;
521
+ }
522
+
523
+ if (!strcmp(var, "author.email")) {
524
+ if (!value)
525
+ return config_error_nonbool(var);
526
+ strbuf_reset(&git_author_email);
527
+ strbuf_addstr(&git_author_email, value);
528
+ author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
529
+ ident_config_given |= IDENT_MAIL_GIVEN;
530
+ return 0;
531
+ }
532
+
533
+ if (!strcmp(var, "committer.name")) {
534
+ if (!value)
535
+ return config_error_nonbool(var);
536
+ strbuf_reset(&git_committer_name);
537
+ strbuf_addstr(&git_committer_name, value);
538
+ committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
539
+ ident_config_given |= IDENT_NAME_GIVEN;
540
+ return 0;
541
+ }
542
+
543
+ if (!strcmp(var, "committer.email")) {
544
+ if (!value)
545
+ return config_error_nonbool(var);
546
+ strbuf_reset(&git_committer_email);
547
+ strbuf_addstr(&git_committer_email, value);
548
+ committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
549
+ ident_config_given |= IDENT_MAIL_GIVEN;
550
return 0;
551
}
552
575
return 0;
576
}
577
578
+int git_ident_config(const char *var, const char *value, void *data)
579
+{
580
+ if (!strcmp(var, "user.useconfigonly")) {
581
+ ident_use_config_only = git_config_bool(var, value);
582
+ return 0;
583
+ }
584
+
585
+ return set_ident(var, value);
586
+}
587
+
588
static int buf_cmp(const char *a_begin, const char *a_end,
589
const char *b_begin, const char *b_end)
590
{