reflog: use parse_config_key in config callback
[gitweb.git] / mailmap.c
index 2f9c69157d7fbdd5f2b578fe72c2422712d36800..b16542febec14ed86fd7ef21ba19899d08c95a64 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -168,10 +168,19 @@ static int read_mailmap_file(struct string_list *map, const char *filename,
                             char **repo_abbrev)
 {
        char buffer[1024];
-       FILE *f = (filename == NULL ? NULL : fopen(filename, "r"));
+       FILE *f;
+
+       if (!filename)
+               return 0;
+
+       f = fopen(filename, "r");
+       if (!f) {
+               if (errno == ENOENT)
+                       return 0;
+               return error("unable to open mailmap at %s: %s",
+                            filename, strerror(errno));
+       }
 
-       if (f == NULL)
-               return 1;
        while (fgets(buffer, sizeof(buffer), f) != NULL)
                read_mailmap_line(map, buffer, repo_abbrev);
        fclose(f);
@@ -205,15 +214,15 @@ static int read_mailmap_blob(struct string_list *map,
        enum object_type type;
 
        if (!name)
-               return 1;
+               return 0;
        if (get_sha1(name, sha1) < 0)
-               return 1;
+               return 0;
 
        buf = read_sha1_file(sha1, &type, &size);
        if (!buf)
-               return 1;
+               return error("unable to read mailmap object at %s", name);
        if (type != OBJ_BLOB)
-               return 1;
+               return error("mailmap is not a blob: %s", name);
 
        read_mailmap_buf(map, buf, size, repo_abbrev);
 
@@ -223,11 +232,17 @@ static int read_mailmap_blob(struct string_list *map,
 
 int read_mailmap(struct string_list *map, char **repo_abbrev)
 {
+       int err = 0;
+
        map->strdup_strings = 1;
-       /* each failure returns 1, so >2 means all calls failed */
-       return read_mailmap_file(map, ".mailmap", repo_abbrev) +
-              read_mailmap_blob(map, git_mailmap_blob, repo_abbrev) +
-              read_mailmap_file(map, git_mailmap_file, repo_abbrev) > 2;
+
+       if (!git_mailmap_blob && is_bare_repository())
+               git_mailmap_blob = "HEAD:.mailmap";
+
+       err |= read_mailmap_file(map, ".mailmap", repo_abbrev);
+       err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev);
+       err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev);
+       return err;
 }
 
 void clear_mailmap(struct string_list *map)