From: Michael Haggerty Date: Tue, 24 Apr 2012 22:45:07 +0000 (+0200) Subject: get_ref_dir(): return early if directory cannot be read X-Git-Tag: v1.7.11-rc0~49^2~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d5fdae67379778502ca8b3b3186ce4692d912e30;p=git.git get_ref_dir(): return early if directory cannot be read Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- diff --git a/refs.c b/refs.c index 09322fede..d539241d9 100644 --- a/refs.c +++ b/refs.c @@ -754,6 +754,9 @@ static void get_ref_dir(struct ref_cache *refs, const char *base, { DIR *d; const char *path; + struct dirent *de; + int baselen; + char *refname; if (*refs->name) path = git_path_submodule(refs->name, "%s", base); @@ -761,55 +764,55 @@ static void get_ref_dir(struct ref_cache *refs, const char *base, path = git_path("%s", base); d = opendir(path); - if (d) { - struct dirent *de; - int baselen = strlen(base); - char *refname = xmalloc(baselen + 257); + if (!d) + return; - memcpy(refname, base, baselen); - if (baselen && base[baselen-1] != '/') - refname[baselen++] = '/'; + baselen = strlen(base); + refname = xmalloc(baselen + 257); - while ((de = readdir(d)) != NULL) { - unsigned char sha1[20]; - struct stat st; - int flag; - int namelen; - const char *refdir; + memcpy(refname, base, baselen); + if (baselen && base[baselen-1] != '/') + refname[baselen++] = '/'; - if (de->d_name[0] == '.') - continue; - namelen = strlen(de->d_name); - if (namelen > 255) - continue; - if (has_extension(de->d_name, ".lock")) - continue; - memcpy(refname + baselen, de->d_name, namelen+1); - refdir = *refs->name - ? git_path_submodule(refs->name, "%s", refname) - : git_path("%s", refname); - if (stat(refdir, &st) < 0) - continue; - if (S_ISDIR(st.st_mode)) { - get_ref_dir(refs, refname, dir); - continue; - } - if (*refs->name) { - hashclr(sha1); - flag = 0; - if (resolve_gitlink_ref(refs->name, refname, sha1) < 0) { - hashclr(sha1); - flag |= REF_ISBROKEN; - } - } else if (read_ref_full(refname, sha1, 1, &flag)) { + while ((de = readdir(d)) != NULL) { + unsigned char sha1[20]; + struct stat st; + int flag; + int namelen; + const char *refdir; + + if (de->d_name[0] == '.') + continue; + namelen = strlen(de->d_name); + if (namelen > 255) + continue; + if (has_extension(de->d_name, ".lock")) + continue; + memcpy(refname + baselen, de->d_name, namelen+1); + refdir = *refs->name + ? git_path_submodule(refs->name, "%s", refname) + : git_path("%s", refname); + if (stat(refdir, &st) < 0) + continue; + if (S_ISDIR(st.st_mode)) { + get_ref_dir(refs, refname, dir); + continue; + } + if (*refs->name) { + hashclr(sha1); + flag = 0; + if (resolve_gitlink_ref(refs->name, refname, sha1) < 0) { hashclr(sha1); flag |= REF_ISBROKEN; } - add_ref(dir, create_ref_entry(refname, sha1, flag, 1)); + } else if (read_ref_full(refname, sha1, 1, &flag)) { + hashclr(sha1); + flag |= REF_ISBROKEN; } - free(refname); - closedir(d); + add_ref(dir, create_ref_entry(refname, sha1, flag, 1)); } + free(refname); + closedir(d); } static struct ref_dir *get_loose_refs(struct ref_cache *refs)