diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-03-22 22:00:22 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-03-22 22:00:22 +0100 |
commit | 204333b015a663a339c855c72b86034203b66a6a (patch) | |
tree | 04978dc454e8dbb85ab406e1149934ff9c99e158 /mailmap.c | |
parent | The first batch in 2.32 cycle (diff) | |
parent | mailmap: do not respect symlinks for in-tree .mailmap (diff) | |
download | git-204333b015a663a339c855c72b86034203b66a6a.tar.xz git-204333b015a663a339c855c72b86034203b66a6a.zip |
Merge branch 'jk/open-dotgitx-with-nofollow'
It does not make sense to make ".gitattributes", ".gitignore" and
".mailmap" symlinks, as they are supposed to be usable from the
object store (think: bare repositories where HEAD:.mailmap etc. are
used). When these files are symbolic links, we used to read the
contents of the files pointed by them by mistake, which has been
corrected.
* jk/open-dotgitx-with-nofollow:
mailmap: do not respect symlinks for in-tree .mailmap
exclude: do not respect symlinks for in-tree .gitignore
attr: do not respect symlinks for in-tree .gitattributes
exclude: add flags parameter to add_patterns()
attr: convert "macro_ok" into a flags field
add open_nofollow() helper
Diffstat (limited to 'mailmap.c')
-rw-r--r-- | mailmap.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -157,20 +157,30 @@ static void read_mailmap_line(struct string_list *map, char *buffer) add_mapping(map, name1, email1, name2, email2); } -static int read_mailmap_file(struct string_list *map, const char *filename) +/* Flags for read_mailmap_file() */ +#define MAILMAP_NOFOLLOW (1<<0) + +static int read_mailmap_file(struct string_list *map, const char *filename, + unsigned flags) { char buffer[1024]; FILE *f; + int fd; if (!filename) return 0; - f = fopen(filename, "r"); - if (!f) { + if (flags & MAILMAP_NOFOLLOW) + fd = open_nofollow(filename, O_RDONLY); + else + fd = open(filename, O_RDONLY); + + if (fd < 0) { if (errno == ENOENT) return 0; return error_errno("unable to open mailmap at %s", filename); } + f = xfdopen(fd, "r"); while (fgets(buffer, sizeof(buffer), f) != NULL) read_mailmap_line(map, buffer); @@ -226,10 +236,12 @@ int read_mailmap(struct string_list *map) git_mailmap_blob = "HEAD:.mailmap"; if (!startup_info->have_repository || !is_bare_repository()) - err |= read_mailmap_file(map, ".mailmap"); + err |= read_mailmap_file(map, ".mailmap", + startup_info->have_repository ? + MAILMAP_NOFOLLOW : 0); if (startup_info->have_repository) err |= read_mailmap_blob(map, git_mailmap_blob); - err |= read_mailmap_file(map, git_mailmap_file); + err |= read_mailmap_file(map, git_mailmap_file, 0); return err; } |