Code

detect close failure on just-written file handles
[git.git] / ident.c
diff --git a/ident.c b/ident.c
index a6fc7b5e11e3f232a7becd62223cc23c5eb68ccc..3d49608e6f9afe22f24a2faf70f2d6cee50b8919 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -9,10 +9,10 @@
 
 static char git_default_date[50];
 
-static void copy_gecos(struct passwd *w, char *name, int sz)
+static void copy_gecos(const struct passwd *w, char *name, size_t sz)
 {
        char *src, *dst;
-       int len, nlen;
+       size_t len, nlen;
 
        nlen = strlen(w->pw_name);
 
@@ -43,13 +43,13 @@ static void copy_gecos(struct passwd *w, char *name, int sz)
 
 }
 
-static void copy_email(struct passwd *pw)
+static void copy_email(const struct passwd *pw)
 {
        /*
         * Make up a fake email address
         * (name + '@' + hostname [+ '.' + domainname])
         */
-       int len = strlen(pw->pw_name);
+       size_t len = strlen(pw->pw_name);
        if (len > sizeof(git_default_email)/2)
                die("Your sysadmin must hate you!");
        memcpy(git_default_email, pw->pw_name, len);
@@ -95,9 +95,9 @@ static void setup_ident(void)
                datestamp(git_default_date, sizeof(git_default_date));
 }
 
-static int add_raw(char *buf, int size, int offset, const char *str)
+static int add_raw(char *buf, size_t size, int offset, const char *str)
 {
-       int len = strlen(str);
+       size_t len = strlen(str);
        if (offset + len > size)
                return size;
        memcpy(buf + offset, str, len);
@@ -131,9 +131,9 @@ static int crud(unsigned char c)
  * Copy over a string to the destination, but avoid special
  * characters ('\n', '<' and '>') and remove crud at the end
  */
-static int copy(char *buf, int size, int offset, const char *src)
+static int copy(char *buf, size_t size, int offset, const char *src)
 {
-       int i, len;
+       size_t i, len;
        unsigned char c;
 
        /* Remove crud from the beginning.. */
@@ -185,8 +185,8 @@ static const char *env_hint =
 "Add --global to set your account\'s default\n"
 "\n";
 
-static const char *get_ident(const char *name, const char *email,
-                            const char *date_str, int error_on_no_name)
+const char *fmt_ident(const char *name, const char *email,
+                     const char *date_str, int error_on_no_name)
 {
        static char buffer[1000];
        char date[50];
@@ -197,6 +197,8 @@ static const char *get_ident(const char *name, const char *email,
                name = git_default_name;
        if (!email)
                email = git_default_email;
+       if (!email)
+               email = getenv("EMAIL");
 
        if (!*name) {
                struct passwd *pw;
@@ -233,7 +235,7 @@ static const char *get_ident(const char *name, const char *email,
 
 const char *git_author_info(int error_on_no_name)
 {
-       return get_ident(getenv("GIT_AUTHOR_NAME"),
+       return fmt_ident(getenv("GIT_AUTHOR_NAME"),
                         getenv("GIT_AUTHOR_EMAIL"),
                         getenv("GIT_AUTHOR_DATE"),
                         error_on_no_name);
@@ -241,7 +243,7 @@ const char *git_author_info(int error_on_no_name)
 
 const char *git_committer_info(int error_on_no_name)
 {
-       return get_ident(getenv("GIT_COMMITTER_NAME"),
+       return fmt_ident(getenv("GIT_COMMITTER_NAME"),
                         getenv("GIT_COMMITTER_EMAIL"),
                         getenv("GIT_COMMITTER_DATE"),
                         error_on_no_name);