diff options
Diffstat (limited to 'ident.c')
-rw-r--r-- | ident.c | 51 |
1 files changed, 49 insertions, 2 deletions
@@ -46,6 +46,7 @@ static void copy_gecos(const struct passwd *w, struct strbuf *name) static int add_mailname_host(struct strbuf *buf) { FILE *mailname; + struct strbuf mailnamebuf = STRBUF_INIT; mailname = fopen("/etc/mailname", "r"); if (!mailname) { @@ -54,14 +55,17 @@ static int add_mailname_host(struct strbuf *buf) 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; } @@ -229,7 +233,21 @@ int split_ident_line(struct ident_split *split, const char *line, int len) if (!split->mail_end) return status; - for (cp = split->mail_end + 1; cp < line + len && isspace(*cp); cp++) + /* + * Look from the end-of-line to find the trailing ">" of the mail + * address, even though we should already know it as split->mail_end. + * This can help in cases of broken idents with an extra ">" somewhere + * in the email address. Note that we are assuming the timestamp will + * never have a ">" in it. + * + * Note that we will always find some ">" before going off the front of + * the string, because will always hit the split->mail_end closing + * bracket. + */ + for (cp = line + len - 1; *cp != '>'; cp--) + ; + + for (cp = cp + 1; cp < line + len && isspace(*cp); cp++) ; if (line + len <= cp) goto person_only; @@ -398,3 +416,32 @@ int git_ident_config(const char *var, const char *value, void *data) return 0; } + +static int buf_cmp(const char *a_begin, const char *a_end, + const char *b_begin, const char *b_end) +{ + int a_len = a_end - a_begin; + int b_len = b_end - b_begin; + int min = a_len < b_len ? a_len : b_len; + int cmp; + + cmp = memcmp(a_begin, b_begin, min); + if (cmp) + return cmp; + + return a_len - b_len; +} + +int ident_cmp(const struct ident_split *a, + const struct ident_split *b) +{ + int cmp; + + cmp = buf_cmp(a->mail_begin, a->mail_end, + b->mail_begin, b->mail_end); + if (cmp) + return cmp; + + return buf_cmp(a->name_begin, a->name_end, + b->name_begin, b->name_end); +} |