Browse Source

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
Jonathan Tan 3 years ago committed by Junio C Hamano
parent
commit
9bc45a2802
  1. 3
      refs.c
  2. 5
      refs/files-backend.c
  3. 6
      refs/packed-backend.c
  4. 1
      refs/refs-internal.h

3
refs.c

@ -255,12 +255,13 @@ int refname_is_safe(const char *refname) @@ -255,12 +255,13 @@ int refname_is_safe(const char *refname)
* does not exist, emit a warning and return false.
*/
int ref_resolves_to_object(const char *refname,
struct repository *repo,
const struct object_id *oid,
unsigned int flags)
{
if (flags & REF_ISBROKEN)
return 0;
if (!has_object_file(oid)) {
if (!repo_has_object_file(repo, oid)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}

5
refs/files-backend.c

@ -732,6 +732,7 @@ struct files_ref_iterator { @@ -732,6 +732,7 @@ struct files_ref_iterator {
struct ref_iterator base;

struct ref_iterator *iter0;
struct repository *repo;
unsigned int flags;
};

@ -753,6 +754,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator) @@ -753,6 +754,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)

if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
!ref_resolves_to_object(iter->iter0->refname,
iter->repo,
iter->iter0->oid,
iter->iter0->flags))
continue;
@ -855,6 +857,7 @@ static struct ref_iterator *files_ref_iterator_begin( @@ -855,6 +857,7 @@ static struct ref_iterator *files_ref_iterator_begin(
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
overlay_iter->ordered);
iter->iter0 = overlay_iter;
iter->repo = ref_store->repo;
iter->flags = flags;

return ref_iterator;
@ -1139,7 +1142,7 @@ static int should_pack_ref(const char *refname, @@ -1139,7 +1142,7 @@ static int should_pack_ref(const char *refname,
return 0;

/* 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 1;

6
refs/packed-backend.c

@ -778,6 +778,7 @@ struct packed_ref_iterator { @@ -778,6 +778,7 @@ struct packed_ref_iterator {
struct object_id oid, peeled;
struct strbuf refname_buf;

struct repository *repo;
unsigned int flags;
};

@ -866,8 +867,8 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator) @@ -866,8 +867,8 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
continue;

if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
!ref_resolves_to_object(iter->base.refname, &iter->oid,
iter->flags))
!ref_resolves_to_object(iter->base.refname, iter->repo,
&iter->oid, iter->flags))
continue;

return ITER_OK;
@ -956,6 +957,7 @@ static struct ref_iterator *packed_ref_iterator_begin( @@ -956,6 +957,7 @@ static struct ref_iterator *packed_ref_iterator_begin(

iter->base.oid = &iter->oid;

iter->repo = ref_store->repo;
iter->flags = flags;

if (prefix && *prefix)

1
refs/refs-internal.h

@ -66,6 +66,7 @@ int refname_is_safe(const char *refname); @@ -66,6 +66,7 @@ int refname_is_safe(const char *refname);
* referred-to object does not exist, emit a warning and return false.
*/
int ref_resolves_to_object(const char *refname,
struct repository *repo,
const struct object_id *oid,
unsigned int flags);


Loading…
Cancel
Save