Skip to content

Commit 261ec7d

Browse files
committed
Merge branch 'jk/ident-gecos-strbuf'
Fixes quite a lot of brokenness when ident information needs to be taken from the system and cleans up the code. By Jeff King * jk/ident-gecos-strbuf: (22 commits) format-patch: do not use bogus email addresses in message ids ident: reject bogus email addresses with IDENT_STRICT ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICT format-patch: use GIT_COMMITTER_EMAIL in message ids ident: let callers omit name with fmt_indent ident: refactor NO_DATE flag in fmt_ident ident: reword empty ident error message format-patch: refactor get_patch_filename ident: trim whitespace from default name/email ident: use a dynamic strbuf in fmt_ident ident: use full dns names to generate email addresses ident: report passwd errors with a more friendly message drop length limitations on gecos-derived names and emails ident: don't write fallback username into git_default_name fmt_ident: drop IDENT_WARN_ON_NO_NAME code format-patch: use default email for generating message ids ident: trim trailing newline from /etc/mailname move git_default_* variables to ident.c move identity config parsing to ident.c fmt-merge-msg: don't use static buffer in record_person ...
2 parents 12d7d15 + 59f9b8a commit 261ec7d

19 files changed

+176
-238
lines changed

Documentation/git-commit-tree.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ for one to be entered and terminated with ^D.
8888

8989
include::date-formats.txt[]
9090

91-
Diagnostics
92-
-----------
93-
You don't exist. Go away!::
94-
The passwd(5) gecos field couldn't be read
95-
Your parents must have hated you!::
96-
The passwd(5) gecos field is longer than a giant static buffer.
97-
Your sysadmin must hate you!::
98-
The passwd(5) name field is longer than a giant static buffer.
99-
10091
Discussion
10192
----------
10293

Documentation/git-var.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ ifdef::git-default-pager[]
5959
The build you are using chose '{git-default-pager}' as the default.
6060
endif::git-default-pager[]
6161

62-
Diagnostics
63-
-----------
64-
You don't exist. Go away!::
65-
The passwd(5) gecos field couldn't be read
66-
Your parents must have hated you!::
67-
The passwd(5) gecos field is longer than a giant static buffer.
68-
Your sysadmin must hate you!::
69-
The passwd(5) name field is longer than a giant static buffer.
70-
7162
SEE ALSO
7263
--------
7364
linkgit:git-commit-tree[1]

builtin/commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ static void determine_author_info(struct strbuf *author_ident)
526526

527527
if (force_date)
528528
date = force_date;
529-
strbuf_addstr(author_ident, fmt_ident(name, email, date,
530-
IDENT_ERROR_ON_NO_NAME));
529+
strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
531530
if (!split_ident_line(&author, author_ident->buf, author_ident->len)) {
532531
export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
533532
export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);

builtin/fmt-merge-msg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)
230230
static void record_person(int which, struct string_list *people,
231231
struct commit *commit)
232232
{
233-
char name_buf[MAX_GITNAME], *name, *name_end;
233+
char *name_buf, *name, *name_end;
234234
struct string_list_item *elem;
235235
const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";
236236

@@ -243,17 +243,17 @@ static void record_person(int which, struct string_list *people,
243243
name_end--;
244244
while (isspace(*name_end) && name <= name_end)
245245
name_end--;
246-
if (name_end < name || name + MAX_GITNAME <= name_end)
246+
if (name_end < name)
247247
return;
248-
memcpy(name_buf, name, name_end - name + 1);
249-
name_buf[name_end - name + 1] = '\0';
248+
name_buf = xmemdupz(name, name_end - name + 1);
250249

251250
elem = string_list_lookup(people, name_buf);
252251
if (!elem) {
253252
elem = string_list_insert(people, name_buf);
254253
elem->util = (void *)0;
255254
}
256255
elem->util = (void*)(util_as_integral(elem) + 1);
256+
free(name_buf);
257257
}
258258

259259
static int cmp_string_list_util_as_integral(const void *a_, const void *b_)

builtin/log.c

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ static FILE *realstdout = NULL;
663663
static const char *output_directory = NULL;
664664
static int outdir_offset;
665665

666-
static int reopen_stdout(struct commit *commit, struct rev_info *rev, int quiet)
666+
static int reopen_stdout(struct commit *commit, const char *subject,
667+
struct rev_info *rev, int quiet)
667668
{
668669
struct strbuf filename = STRBUF_INIT;
669670
int suffix_len = strlen(fmt_patch_suffix) + 1;
@@ -677,7 +678,7 @@ static int reopen_stdout(struct commit *commit, struct rev_info *rev, int quiet)
677678
strbuf_addch(&filename, '/');
678679
}
679680

680-
get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);
681+
get_patch_filename(commit, subject, rev->nr, fmt_patch_suffix, &filename);
681682

682683
if (!quiet)
683684
fprintf(realstdout, "%s\n", filename.buf + outdir_offset);
@@ -737,15 +738,10 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
737738

738739
static void gen_message_id(struct rev_info *info, char *base)
739740
{
740-
const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
741-
const char *email_start = strrchr(committer, '<');
742-
const char *email_end = strrchr(committer, '>');
743741
struct strbuf buf = STRBUF_INIT;
744-
if (!email_start || !email_end || email_start > email_end - 1)
745-
die(_("Could not extract email from committer identity."));
746-
strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
742+
strbuf_addf(&buf, "%s.%lu.git.%s", base,
747743
(unsigned long) time(NULL),
748-
(int)(email_end - email_start - 1), email_start + 1);
744+
git_committer_info(IDENT_NO_NAME|IDENT_NO_DATE|IDENT_STRICT));
749745
info->message_id = strbuf_detach(&buf, NULL);
750746
}
751747

@@ -784,39 +780,17 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
784780
const char *encoding = "UTF-8";
785781
struct diff_options opts;
786782
int need_8bit_cte = 0;
787-
struct commit *commit = NULL;
788783
struct pretty_print_context pp = {0};
789784

790785
if (rev->commit_format != CMIT_FMT_EMAIL)
791786
die(_("Cover letter needs email format"));
792787

793788
committer = git_committer_info(0);
794789

795-
if (!numbered_files) {
796-
/*
797-
* We fake a commit for the cover letter so we get the filename
798-
* desired.
799-
*/
800-
commit = xcalloc(1, sizeof(*commit));
801-
commit->buffer = xmalloc(400);
802-
snprintf(commit->buffer, 400,
803-
"tree 0000000000000000000000000000000000000000\n"
804-
"parent %s\n"
805-
"author %s\n"
806-
"committer %s\n\n"
807-
"cover letter\n",
808-
sha1_to_hex(head->object.sha1), committer, committer);
809-
}
810-
811-
if (!use_stdout && reopen_stdout(commit, rev, quiet))
790+
if (!use_stdout &&
791+
reopen_stdout(NULL, numbered_files ? NULL : "cover-letter", rev, quiet))
812792
return;
813793

814-
if (commit) {
815-
816-
free(commit->buffer);
817-
free(commit);
818-
}
819-
820794
log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
821795
&need_8bit_cte);
822796

@@ -1173,7 +1147,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11731147
if (do_signoff) {
11741148
const char *committer;
11751149
const char *endpos;
1176-
committer = git_committer_info(IDENT_ERROR_ON_NO_NAME);
1150+
committer = git_committer_info(IDENT_STRICT);
11771151
endpos = strchr(committer, '>');
11781152
if (!endpos)
11791153
die(_("bogus committer info %s"), committer);
@@ -1411,8 +1385,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
14111385
gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
14121386
}
14131387

1414-
if (!use_stdout && reopen_stdout(numbered_files ? NULL : commit,
1415-
&rev, quiet))
1388+
if (!use_stdout &&
1389+
reopen_stdout(numbered_files ? NULL : commit, NULL, &rev, quiet))
14161390
die(_("Failed to create output files"));
14171391
shown = log_tree_commit(&rev, commit);
14181392
free(commit->buffer);

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14471447
refresh_cache(REFRESH_QUIET);
14481448
if (allow_trivial && !fast_forward_only) {
14491449
/* See if it is really trivial. */
1450-
git_committer_info(IDENT_ERROR_ON_NO_NAME);
1450+
git_committer_info(IDENT_STRICT);
14511451
printf(_("Trying really trivial in-index merge...\n"));
14521452
if (!read_tree_trivial(common->item->object.sha1,
14531453
head_commit->object.sha1,
@@ -1490,7 +1490,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14901490
die(_("Not possible to fast-forward, aborting."));
14911491

14921492
/* We are going to make a new commit. */
1493-
git_committer_info(IDENT_ERROR_ON_NO_NAME);
1493+
git_committer_info(IDENT_STRICT);
14941494

14951495
/*
14961496
* At this point, we need a real merge. No matter what strategy

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static void create_tag(const unsigned char *object, const char *tag,
332332
sha1_to_hex(object),
333333
typename(type),
334334
tag,
335-
git_committer_info(IDENT_ERROR_ON_NO_NAME));
335+
git_committer_info(IDENT_STRICT));
336336

337337
if (header_len > sizeof(header_buf) - 1)
338338
die(_("tag header too big."));

builtin/var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static const char *editor(int flag)
1111
{
1212
const char *pgm = git_editor();
1313

14-
if (!pgm && flag & IDENT_ERROR_ON_NO_NAME)
14+
if (!pgm && flag & IDENT_STRICT)
1515
die("Terminal is dumb, but EDITOR unset");
1616

1717
return pgm;
@@ -55,7 +55,7 @@ static const char *read_var(const char *var)
5555
val = NULL;
5656
for (ptr = git_vars; ptr->read; ptr++) {
5757
if (strcmp(var, ptr->name) == 0) {
58-
val = ptr->read(IDENT_ERROR_ON_NO_NAME);
58+
val = ptr->read(IDENT_STRICT);
5959
break;
6060
}
6161
}

cache.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,15 +887,19 @@ unsigned long approxidate_careful(const char *, int *);
887887
unsigned long approxidate_relative(const char *date, const struct timeval *now);
888888
enum date_mode parse_date_format(const char *format);
889889

890-
#define IDENT_WARN_ON_NO_NAME 1
891-
#define IDENT_ERROR_ON_NO_NAME 2
892-
#define IDENT_NO_DATE 4
890+
#define IDENT_STRICT 1
891+
#define IDENT_NO_DATE 2
892+
#define IDENT_NO_NAME 4
893893
extern const char *git_author_info(int);
894894
extern const char *git_committer_info(int);
895895
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
896896
extern const char *fmt_name(const char *name, const char *email);
897+
extern const char *ident_default_name(void);
898+
extern const char *ident_default_email(void);
899+
extern const char *ident_default_date(void);
897900
extern const char *git_editor(void);
898901
extern const char *git_pager(int stdout_is_tty);
902+
extern int git_ident_config(const char *, const char *, void *);
899903

900904
struct ident_split {
901905
const char *name_begin;
@@ -1139,9 +1143,6 @@ struct config_include_data {
11391143
#define CONFIG_INCLUDE_INIT { 0 }
11401144
extern int git_config_include(const char *name, const char *value, void *data);
11411145

1142-
#define MAX_GITNAME (1000)
1143-
extern char git_default_email[MAX_GITNAME];
1144-
extern char git_default_name[MAX_GITNAME];
11451146
#define IDENT_NAME_GIVEN 01
11461147
#define IDENT_MAIL_GIVEN 02
11471148
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)

commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,9 @@ int commit_tree_extended(const struct strbuf *msg, unsigned char *tree,
11541154

11551155
/* Person/date information */
11561156
if (!author)
1157-
author = git_author_info(IDENT_ERROR_ON_NO_NAME);
1157+
author = git_author_info(IDENT_STRICT);
11581158
strbuf_addf(&buffer, "author %s\n", author);
1159-
strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
1159+
strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_STRICT));
11601160
if (!encoding_is_utf8)
11611161
strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
11621162

0 commit comments

Comments
 (0)