refs: teach arbitrary repo support to iterators
Note that should_pack_ref() is called when writing refs, which is only supported for the_repository, hence the_repository is hardcoded there. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
34224e14d6
commit
9bc45a2802
3
refs.c
3
refs.c
|
@ -255,12 +255,13 @@ int refname_is_safe(const char *refname)
|
||||||
* does not exist, emit a warning and return false.
|
* does not exist, emit a warning and return false.
|
||||||
*/
|
*/
|
||||||
int ref_resolves_to_object(const char *refname,
|
int ref_resolves_to_object(const char *refname,
|
||||||
|
struct repository *repo,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
if (flags & REF_ISBROKEN)
|
if (flags & REF_ISBROKEN)
|
||||||
return 0;
|
return 0;
|
||||||
if (!has_object_file(oid)) {
|
if (!repo_has_object_file(repo, oid)) {
|
||||||
error(_("%s does not point to a valid object!"), refname);
|
error(_("%s does not point to a valid object!"), refname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,6 +732,7 @@ struct files_ref_iterator {
|
||||||
struct ref_iterator base;
|
struct ref_iterator base;
|
||||||
|
|
||||||
struct ref_iterator *iter0;
|
struct ref_iterator *iter0;
|
||||||
|
struct repository *repo;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -753,6 +754,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
|
||||||
|
|
||||||
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
|
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
|
||||||
!ref_resolves_to_object(iter->iter0->refname,
|
!ref_resolves_to_object(iter->iter0->refname,
|
||||||
|
iter->repo,
|
||||||
iter->iter0->oid,
|
iter->iter0->oid,
|
||||||
iter->iter0->flags))
|
iter->iter0->flags))
|
||||||
continue;
|
continue;
|
||||||
|
@ -855,6 +857,7 @@ static struct ref_iterator *files_ref_iterator_begin(
|
||||||
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
|
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
|
||||||
overlay_iter->ordered);
|
overlay_iter->ordered);
|
||||||
iter->iter0 = overlay_iter;
|
iter->iter0 = overlay_iter;
|
||||||
|
iter->repo = ref_store->repo;
|
||||||
iter->flags = flags;
|
iter->flags = flags;
|
||||||
|
|
||||||
return ref_iterator;
|
return ref_iterator;
|
||||||
|
@ -1139,7 +1142,7 @@ static int should_pack_ref(const char *refname,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Do not pack broken refs: */
|
/* Do not pack broken refs: */
|
||||||
if (!ref_resolves_to_object(refname, oid, ref_flags))
|
if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -778,6 +778,7 @@ struct packed_ref_iterator {
|
||||||
struct object_id oid, peeled;
|
struct object_id oid, peeled;
|
||||||
struct strbuf refname_buf;
|
struct strbuf refname_buf;
|
||||||
|
|
||||||
|
struct repository *repo;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -866,8 +867,8 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
|
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
|
||||||
!ref_resolves_to_object(iter->base.refname, &iter->oid,
|
!ref_resolves_to_object(iter->base.refname, iter->repo,
|
||||||
iter->flags))
|
&iter->oid, iter->flags))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return ITER_OK;
|
return ITER_OK;
|
||||||
|
@ -956,6 +957,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
|
||||||
|
|
||||||
iter->base.oid = &iter->oid;
|
iter->base.oid = &iter->oid;
|
||||||
|
|
||||||
|
iter->repo = ref_store->repo;
|
||||||
iter->flags = flags;
|
iter->flags = flags;
|
||||||
|
|
||||||
if (prefix && *prefix)
|
if (prefix && *prefix)
|
||||||
|
|
|
@ -66,6 +66,7 @@ int refname_is_safe(const char *refname);
|
||||||
* referred-to object does not exist, emit a warning and return false.
|
* referred-to object does not exist, emit a warning and return false.
|
||||||
*/
|
*/
|
||||||
int ref_resolves_to_object(const char *refname,
|
int ref_resolves_to_object(const char *refname,
|
||||||
|
struct repository *repo,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue