refs: extract out loose_fill_ref_dir_regular_file()
Extract out the code for adding a single file to the loose ref dir as `loose_fill_ref_dir_regular_file()` from `loose_fill_ref_dir()` in `refs/files-backend.c`. This allows us to use this function independently in the following commits where we add code to also add pseudorefs to the ref dir. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1eba2240f8
commit
f768296cf1
@ -229,6 +229,38 @@ static void add_per_worktree_entries_to_dir(struct ref_dir *dir, const char *dir
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
|
||||||
|
const char *refname,
|
||||||
|
struct ref_dir *dir)
|
||||||
|
{
|
||||||
|
struct object_id oid;
|
||||||
|
int flag;
|
||||||
|
|
||||||
|
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
|
||||||
|
&oid, &flag)) {
|
||||||
|
oidclr(&oid);
|
||||||
|
flag |= REF_ISBROKEN;
|
||||||
|
} else if (is_null_oid(&oid)) {
|
||||||
|
/*
|
||||||
|
* It is so astronomically unlikely
|
||||||
|
* that null_oid is the OID of an
|
||||||
|
* actual object that we consider its
|
||||||
|
* appearance in a loose reference
|
||||||
|
* file to be repo corruption
|
||||||
|
* (probably due to a software bug).
|
||||||
|
*/
|
||||||
|
flag |= REF_ISBROKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
||||||
|
if (!refname_is_safe(refname))
|
||||||
|
die("loose refname is dangerous: %s", refname);
|
||||||
|
oidclr(&oid);
|
||||||
|
flag |= REF_BAD_NAME | REF_ISBROKEN;
|
||||||
|
}
|
||||||
|
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the loose references from the namespace dirname into dir
|
* Read the loose references from the namespace dirname into dir
|
||||||
* (without recursing). dirname must end with '/'. dir must be the
|
* (without recursing). dirname must end with '/'. dir must be the
|
||||||
@ -257,8 +289,6 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
|
|||||||
strbuf_add(&refname, dirname, dirnamelen);
|
strbuf_add(&refname, dirname, dirnamelen);
|
||||||
|
|
||||||
while ((de = readdir(d)) != NULL) {
|
while ((de = readdir(d)) != NULL) {
|
||||||
struct object_id oid;
|
|
||||||
int flag;
|
|
||||||
unsigned char dtype;
|
unsigned char dtype;
|
||||||
|
|
||||||
if (de->d_name[0] == '.')
|
if (de->d_name[0] == '.')
|
||||||
@ -274,33 +304,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
|
|||||||
create_dir_entry(dir->cache, refname.buf,
|
create_dir_entry(dir->cache, refname.buf,
|
||||||
refname.len));
|
refname.len));
|
||||||
} else if (dtype == DT_REG) {
|
} else if (dtype == DT_REG) {
|
||||||
if (!refs_resolve_ref_unsafe(&refs->base,
|
loose_fill_ref_dir_regular_file(refs, refname.buf, dir);
|
||||||
refname.buf,
|
|
||||||
RESOLVE_REF_READING,
|
|
||||||
&oid, &flag)) {
|
|
||||||
oidclr(&oid);
|
|
||||||
flag |= REF_ISBROKEN;
|
|
||||||
} else if (is_null_oid(&oid)) {
|
|
||||||
/*
|
|
||||||
* It is so astronomically unlikely
|
|
||||||
* that null_oid is the OID of an
|
|
||||||
* actual object that we consider its
|
|
||||||
* appearance in a loose reference
|
|
||||||
* file to be repo corruption
|
|
||||||
* (probably due to a software bug).
|
|
||||||
*/
|
|
||||||
flag |= REF_ISBROKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (check_refname_format(refname.buf,
|
|
||||||
REFNAME_ALLOW_ONELEVEL)) {
|
|
||||||
if (!refname_is_safe(refname.buf))
|
|
||||||
die("loose refname is dangerous: %s", refname.buf);
|
|
||||||
oidclr(&oid);
|
|
||||||
flag |= REF_BAD_NAME | REF_ISBROKEN;
|
|
||||||
}
|
|
||||||
add_entry_to_dir(dir,
|
|
||||||
create_ref_entry(refname.buf, &oid, flag));
|
|
||||||
}
|
}
|
||||||
strbuf_setlen(&refname, dirnamelen);
|
strbuf_setlen(&refname, dirnamelen);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user