get_ref_dir(): return early if directory cannot be read
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5e69491bf2
commit
d5fdae6737
85
refs.c
85
refs.c
@ -754,6 +754,9 @@ static void get_ref_dir(struct ref_cache *refs, const char *base,
|
|||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
const char *path;
|
const char *path;
|
||||||
|
struct dirent *de;
|
||||||
|
int baselen;
|
||||||
|
char *refname;
|
||||||
|
|
||||||
if (*refs->name)
|
if (*refs->name)
|
||||||
path = git_path_submodule(refs->name, "%s", base);
|
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);
|
path = git_path("%s", base);
|
||||||
|
|
||||||
d = opendir(path);
|
d = opendir(path);
|
||||||
if (d) {
|
if (!d)
|
||||||
struct dirent *de;
|
return;
|
||||||
int baselen = strlen(base);
|
|
||||||
char *refname = xmalloc(baselen + 257);
|
|
||||||
|
|
||||||
memcpy(refname, base, baselen);
|
baselen = strlen(base);
|
||||||
if (baselen && base[baselen-1] != '/')
|
refname = xmalloc(baselen + 257);
|
||||||
refname[baselen++] = '/';
|
|
||||||
|
|
||||||
while ((de = readdir(d)) != NULL) {
|
memcpy(refname, base, baselen);
|
||||||
unsigned char sha1[20];
|
if (baselen && base[baselen-1] != '/')
|
||||||
struct stat st;
|
refname[baselen++] = '/';
|
||||||
int flag;
|
|
||||||
int namelen;
|
|
||||||
const char *refdir;
|
|
||||||
|
|
||||||
if (de->d_name[0] == '.')
|
while ((de = readdir(d)) != NULL) {
|
||||||
continue;
|
unsigned char sha1[20];
|
||||||
namelen = strlen(de->d_name);
|
struct stat st;
|
||||||
if (namelen > 255)
|
int flag;
|
||||||
continue;
|
int namelen;
|
||||||
if (has_extension(de->d_name, ".lock"))
|
const char *refdir;
|
||||||
continue;
|
|
||||||
memcpy(refname + baselen, de->d_name, namelen+1);
|
if (de->d_name[0] == '.')
|
||||||
refdir = *refs->name
|
continue;
|
||||||
? git_path_submodule(refs->name, "%s", refname)
|
namelen = strlen(de->d_name);
|
||||||
: git_path("%s", refname);
|
if (namelen > 255)
|
||||||
if (stat(refdir, &st) < 0)
|
continue;
|
||||||
continue;
|
if (has_extension(de->d_name, ".lock"))
|
||||||
if (S_ISDIR(st.st_mode)) {
|
continue;
|
||||||
get_ref_dir(refs, refname, dir);
|
memcpy(refname + baselen, de->d_name, namelen+1);
|
||||||
continue;
|
refdir = *refs->name
|
||||||
}
|
? git_path_submodule(refs->name, "%s", refname)
|
||||||
if (*refs->name) {
|
: git_path("%s", refname);
|
||||||
hashclr(sha1);
|
if (stat(refdir, &st) < 0)
|
||||||
flag = 0;
|
continue;
|
||||||
if (resolve_gitlink_ref(refs->name, refname, sha1) < 0) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
hashclr(sha1);
|
get_ref_dir(refs, refname, dir);
|
||||||
flag |= REF_ISBROKEN;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (read_ref_full(refname, sha1, 1, &flag)) {
|
if (*refs->name) {
|
||||||
|
hashclr(sha1);
|
||||||
|
flag = 0;
|
||||||
|
if (resolve_gitlink_ref(refs->name, refname, sha1) < 0) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
flag |= REF_ISBROKEN;
|
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);
|
add_ref(dir, create_ref_entry(refname, sha1, flag, 1));
|
||||||
closedir(d);
|
|
||||||
}
|
}
|
||||||
|
free(refname);
|
||||||
|
closedir(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
|
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
|
||||||
|
Loading…
Reference in New Issue
Block a user