mirror of
https://github.com/git/git.git
synced 2024-11-27 20:14:30 +08:00
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:
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
|
||||
* (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);
|
||||
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
struct object_id oid;
|
||||
int flag;
|
||||
unsigned char dtype;
|
||||
|
||||
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,
|
||||
refname.len));
|
||||
} else if (dtype == DT_REG) {
|
||||
if (!refs_resolve_ref_unsafe(&refs->base,
|
||||
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));
|
||||
loose_fill_ref_dir_regular_file(refs, refname.buf, dir);
|
||||
}
|
||||
strbuf_setlen(&refname, dirnamelen);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user