Merge branch 'jn/do-not-drop-username-when-reading-from-etc-mailname' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 4 Feb 2013 18:04:26 +0000 (10:04 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 4 Feb 2013 18:04:26 +0000 (10:04 -0800)
We used to stuff "user@" and then append what we read from
/etc/mailname to come up with a default e-mail ident, but a bug lost
the "user@" part.

* jn/do-not-drop-username-when-reading-from-etc-mailname:
ident: do not drop username when reading from /etc/mailname

1  2 
ident.c
diff --combined ident.c
index ac9672f607909111167559e3aa58e1585f05d0d8,fb4cc722a3aa7859cbf170e0376ac16b445e6cba..1c123e685fbfbfcd5289958adc54a6cd48351628
+++ b/ident.c
  static struct strbuf git_default_name = STRBUF_INIT;
  static struct strbuf git_default_email = STRBUF_INIT;
  static char git_default_date[50];
 -int user_ident_explicitly_given;
 +
 +#define IDENT_NAME_GIVEN 01
 +#define IDENT_MAIL_GIVEN 02
 +#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
 +static int committer_ident_explicitly_given;
 +static int author_ident_explicitly_given;
  
  #ifdef NO_GECOS_IN_PWENT
  #define get_gecos(ignored) "&"
@@@ -46,6 -41,7 +46,7 @@@ static void copy_gecos(const struct pas
  static int add_mailname_host(struct strbuf *buf)
  {
        FILE *mailname;
+       struct strbuf mailnamebuf = STRBUF_INIT;
  
        mailname = fopen("/etc/mailname", "r");
        if (!mailname) {
                                strerror(errno));
                return -1;
        }
-       if (strbuf_getline(buf, mailname, '\n') == EOF) {
+       if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
                if (ferror(mailname))
                        warning("cannot read /etc/mailname: %s",
                                strerror(errno));
+               strbuf_release(&mailnamebuf);
                fclose(mailname);
                return -1;
        }
        /* success! */
+       strbuf_addbuf(buf, &mailnamebuf);
+       strbuf_release(&mailnamebuf);
        fclose(mailname);
        return 0;
  }
@@@ -98,7 -97,7 +102,7 @@@ static void copy_email(const struct pas
        add_domainname(email);
  }
  
 -const char *ident_default_name(void)
 +static const char *ident_default_name(void)
  {
        if (!git_default_name.len) {
                copy_gecos(xgetpwuid_self(), &git_default_name);
@@@ -114,8 -113,7 +118,8 @@@ const char *ident_default_email(void
  
                if (email && email[0]) {
                        strbuf_addstr(&git_default_email, email);
 -                      user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
 +                      committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
 +                      author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                } else
                        copy_email(xgetpwuid_self(), &git_default_email);
                strbuf_trim(&git_default_email);
        return git_default_email.buf;
  }
  
 -const char *ident_default_date(void)
 +static const char *ident_default_date(void)
  {
        if (!git_default_date[0])
                datestamp(git_default_date, sizeof(git_default_date));
@@@ -333,10 -331,6 +337,10 @@@ const char *fmt_name(const char *name, 
  
  const char *git_author_info(int flag)
  {
 +      if (getenv("GIT_AUTHOR_NAME"))
 +              author_ident_explicitly_given |= IDENT_NAME_GIVEN;
 +      if (getenv("GIT_AUTHOR_EMAIL"))
 +              author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
        return fmt_ident(getenv("GIT_AUTHOR_NAME"),
                         getenv("GIT_AUTHOR_EMAIL"),
                         getenv("GIT_AUTHOR_DATE"),
  const char *git_committer_info(int flag)
  {
        if (getenv("GIT_COMMITTER_NAME"))
 -              user_ident_explicitly_given |= IDENT_NAME_GIVEN;
 +              committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
        if (getenv("GIT_COMMITTER_EMAIL"))
 -              user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
 +              committer_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)
 +static int ident_is_sufficient(int user_ident_explicitly_given)
  {
  #ifndef WINDOWS
        return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
  #endif
  }
  
 +int committer_ident_sufficiently_given(void)
 +{
 +      return ident_is_sufficient(committer_ident_explicitly_given);
 +}
 +
 +int author_ident_sufficiently_given(void)
 +{
 +      return ident_is_sufficient(author_ident_explicitly_given);
 +}
 +
  int git_ident_config(const char *var, const char *value, void *data)
  {
        if (!strcmp(var, "user.name")) {
                        return config_error_nonbool(var);
                strbuf_reset(&git_default_name);
                strbuf_addstr(&git_default_name, value);
 -              user_ident_explicitly_given |= IDENT_NAME_GIVEN;
 +              committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
 +              author_ident_explicitly_given |= IDENT_NAME_GIVEN;
                return 0;
        }
  
                        return config_error_nonbool(var);
                strbuf_reset(&git_default_email);
                strbuf_addstr(&git_default_email, value);
 -              user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
 +              committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
 +              author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                return 0;
        }