@matheusbsbs / matheus-bagliano / commits / 589e4f93c7
Fork 0

Delay "empty ident" errors until they really matter.

Previous one warned people upfront to encourage fixing their environment early, but some people just use repositories and git tools read-only without making any changes, and in such a case there is not much point insisting on them having a usable ident. This round attempts to move the error until either "git-var" asks for the ident explicitly or "commit-tree" wants to use it. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 18, 2006 at 20:31 UTC 589e4f93c7fc31d73da3d0764c71d939c9332442
4 files changed +32 -29
cache.h
+2 -2
@@ -246,8 +246,8 @@ void datestamp(char *buf, int bufsize);
246 unsigned long approxidate(const char *);
247
248 extern int setup_ident(void);
249 -extern const char *git_author_info(void);
250 -extern const char *git_committer_info(void);
249 +extern const char *git_author_info(int);
250 +extern const char *git_committer_info(int);
251
252 struct checkout {
253 const char *base_dir;
commit-tree.c
+2 -2
@@ -118,8 +118,8 @@ int main(int argc, char **argv)
118 add_buffer(&buffer, &size, "parent %s\n", sha1_to_hex(parent_sha1[i]));
119
120 /* Person/date information */
121 - add_buffer(&buffer, &size, "author %s\n", git_author_info());
122 - add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info());
121 + add_buffer(&buffer, &size, "author %s\n", git_author_info(1));
122 + add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info(1));
123
124 /* And add the comment */
125 while (fgets(comment, sizeof(comment), stdin) != NULL)
ident.c
+25 -22
@@ -46,15 +46,6 @@ static void copy_gecos(struct passwd *w, char *name, int sz)
46
47 }
48
49 -static const char au_env[] = "GIT_AUTHOR_NAME";
50 -static const char co_env[] = "GIT_COMMITTER_NAME";
51 -static const char env_hint[] =
52 -"\n*** Environment problem:\n"
53 -"*** Your name cannot be determined from your system services (gecos).\n"
54 -"*** You would need to set %s and %s\n"
55 -"*** environment variables; otherwise you won't be able to perform\n"
56 -"*** certain operations because of \"empty ident\" errors.\n\n";
57 -
49 int setup_ident(void)
50 {
51 int len;
@@ -66,11 +57,6 @@ int setup_ident(void)
57 /* Get the name ("gecos") */
58 copy_gecos(pw, git_default_name, sizeof(git_default_name));
59
69 - if (!*git_default_name) {
70 - if (!getenv(au_env) || !getenv(co_env))
71 - fprintf(stderr, env_hint, au_env, co_env);
72 - }
73 -
60 /* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
61 len = strlen(pw->pw_name);
62 if (len > sizeof(git_default_email)/2)
@@ -170,8 +156,18 @@ static int copy(char *buf, int size, int offset, const char *src)
156 return offset;
157 }
158
159 +static const char au_env[] = "GIT_AUTHOR_NAME";
160 +static const char co_env[] = "GIT_COMMITTER_NAME";
161 +static const char *env_hint =
162 +"\n*** Environment problem:\n"
163 +"*** Your name cannot be determined from your system services (gecos).\n"
164 +"*** You would need to set %s and %s\n"
165 +"*** environment variables; otherwise you won't be able to perform\n"
166 +"*** certain operations because of \"empty ident\" errors.\n"
167 +"*** Alternatively, you can use user.name configuration variable.\n\n";
168 +
169 static const char *get_ident(const char *name, const char *email,
174 - const char *date_str)
170 + const char *date_str, int error_on_no_name)
171 {
172 static char buffer[1000];
173 char date[50];
@@ -182,9 +178,14 @@ static const char *get_ident(const char *name, const char *email,
178 if (!email)
179 email = git_default_email;
180
185 - if (!*name || !*email)
186 - die("empty ident %s <%s> not allowed",
187 - name, email);
181 + if (!*name) {
182 + if (name == git_default_name && env_hint) {
183 + fprintf(stderr, env_hint, au_env, co_env);
184 + env_hint = NULL; /* warn only once, for "git-var -l" */
185 + }
186 + if (error_on_no_name)
187 + die("empty ident %s <%s> not allowed", name, email);
188 + }
189
190 strcpy(date, git_default_date);
191 if (date_str)
@@ -201,16 +202,18 @@ static const char *get_ident(const char *name, const char *email,
202 return buffer;
203 }
204
204 -const char *git_author_info(void)
205 +const char *git_author_info(int error_on_no_name)
206 {
207 return get_ident(getenv("GIT_AUTHOR_NAME"),
208 getenv("GIT_AUTHOR_EMAIL"),
208 - getenv("GIT_AUTHOR_DATE"));
209 + getenv("GIT_AUTHOR_DATE"),
210 + error_on_no_name);
211 }
212
211 -const char *git_committer_info(void)
213 +const char *git_committer_info(int error_on_no_name)
214 {
215 return get_ident(getenv("GIT_COMMITTER_NAME"),
216 getenv("GIT_COMMITTER_EMAIL"),
215 - getenv("GIT_COMMITTER_DATE"));
217 + getenv("GIT_COMMITTER_DATE"),
218 + error_on_no_name);
219 }
var.c
+3 -3
@@ -12,7 +12,7 @@ static const char var_usage[] = "git-var [-l | <variable>]";
12
13 struct git_var {
14 const char *name;
15 - const char *(*read)(void);
15 + const char *(*read)(int);
16 };
17 static struct git_var git_vars[] = {
18 { "GIT_COMMITTER_IDENT", git_committer_info },
@@ -24,7 +24,7 @@ static void list_vars(void)
24 {
25 struct git_var *ptr;
26 for(ptr = git_vars; ptr->read; ptr++) {
27 - printf("%s=%s\n", ptr->name, ptr->read());
27 + printf("%s=%s\n", ptr->name, ptr->read(0));
28 }
29 }
30
@@ -35,7 +35,7 @@ static const char *read_var(const char *var)
35 val = NULL;
36 for(ptr = git_vars; ptr->read; ptr++) {
37 if (strcmp(var, ptr->name) == 0) {
38 - val = ptr->read();
38 + val = ptr->read(1);
39 break;
40 }
41 }