Code

commit: ignore intent-to-add entries instead of refusing
[git.git] / ident.c
diff --git a/ident.c b/ident.c
index 09cf0c95c9bfc24fa3e4a8f9e212ec42b8a55eba..35a6f264737e700ddd45714a0e966422a0d756c7 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -9,6 +9,12 @@
 
 static char git_default_date[50];
 
+#ifdef NO_GECOS_IN_PWENT
+#define get_gecos(ignored) "&"
+#else
+#define get_gecos(struct_passwd) ((struct_passwd)->pw_gecos)
+#endif
+
 static void copy_gecos(const struct passwd *w, char *name, size_t sz)
 {
        char *src, *dst;
@@ -20,7 +26,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
         * with commas.  Also & stands for capitalized form of the login name.
         */
 
-       for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {
+       for (len = 0, dst = name, src = get_gecos(w); len < sz; src++) {
                int ch = *src;
                if (ch != '&') {
                        *dst++ = ch;
@@ -34,6 +40,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
                        *dst++ = toupper(*w->pw_name);
                        memcpy(dst, w->pw_name + 1, nlen - 1);
                        dst += nlen - 1;
+                       len += nlen;
                }
        }
        if (len < sz)
@@ -85,10 +92,11 @@ static void setup_ident(void)
        if (!git_default_email[0]) {
                const char *email = getenv("EMAIL");
 
-               if (email && email[0])
+               if (email && email[0]) {
                        strlcpy(git_default_email, email,
                                sizeof(git_default_email));
-               else {
+                       user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+               } else {
                        if (!pw)
                                pw = getpwuid(getuid());
                        if (!pw)
@@ -121,6 +129,7 @@ static int crud(unsigned char c)
                c == '<' ||
                c == '>' ||
                c == '"' ||
+               c == '\\' ||
                c == '\'';
 }
 
@@ -167,8 +176,6 @@ static int copy(char *buf, size_t size, int offset, const char *src)
        return offset;
 }
 
-static const char au_env[] = "GIT_AUTHOR_NAME";
-static const char co_env[] = "GIT_COMMITTER_NAME";
 static const char *env_hint =
 "\n"
 "*** Please tell me who you are.\n"
@@ -203,8 +210,8 @@ const char *fmt_ident(const char *name, const char *email,
 
                if ((warn_on_no_name || error_on_no_name) &&
                    name == git_default_name && env_hint) {
-                       fprintf(stderr, env_hint, au_env, co_env);
-                       env_hint = NULL; /* warn only once, for "git var -l" */
+                       fputs(env_hint, stderr);
+                       env_hint = NULL; /* warn only once */
                }
                if (error_on_no_name)
                        die("empty ident %s <%s> not allowed", name, email);
@@ -217,8 +224,10 @@ const char *fmt_ident(const char *name, const char *email,
        }
 
        strcpy(date, git_default_date);
-       if (!name_addr_only && date_str)
-               parse_date(date_str, date, sizeof(date));
+       if (!name_addr_only && date_str && date_str[0]) {
+               if (parse_date(date_str, date, sizeof(date)) < 0)
+                       die("invalid date format: %s", date_str);
+       }
 
        i = copy(buffer, sizeof(buffer), 0, name);
        i = add_raw(buffer, sizeof(buffer), i, " <");
@@ -250,11 +259,21 @@ const char *git_author_info(int flag)
 
 const char *git_committer_info(int flag)
 {
-       if (getenv("GIT_COMMITTER_NAME") &&
-           getenv("GIT_COMMITTER_EMAIL"))
-               user_ident_explicitly_given = 1;
+       if (getenv("GIT_COMMITTER_NAME"))
+               user_ident_explicitly_given |= IDENT_NAME_GIVEN;
+       if (getenv("GIT_COMMITTER_EMAIL"))
+               user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
        return fmt_ident(getenv("GIT_COMMITTER_NAME"),
                         getenv("GIT_COMMITTER_EMAIL"),
                         getenv("GIT_COMMITTER_DATE"),
                         flag);
 }
+
+int user_ident_sufficiently_given(void)
+{
+#ifndef WINDOWS
+       return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
+#else
+       return (user_ident_explicitly_given == IDENT_ALL_GIVEN);
+#endif
+}