Skip to content

Commit 9bc45a2

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34224e1 commit 9bc45a2

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,13 @@ int refname_is_safe(const char *refname)
255255
* does not exist, emit a warning and return false.
256256
*/
257257
int ref_resolves_to_object(const char *refname,
258+
struct repository *repo,
258259
const struct object_id *oid,
259260
unsigned int flags)
260261
{
261262
if (flags & REF_ISBROKEN)
262263
return 0;
263-
if (!has_object_file(oid)) {
264+
if (!repo_has_object_file(repo, oid)) {
264265
error(_("%s does not point to a valid object!"), refname);
265266
return 0;
266267
}

refs/files-backend.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ struct files_ref_iterator {
732732
struct ref_iterator base;
733733

734734
struct ref_iterator *iter0;
735+
struct repository *repo;
735736
unsigned int flags;
736737
};
737738

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

754755
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
755756
!ref_resolves_to_object(iter->iter0->refname,
757+
iter->repo,
756758
iter->iter0->oid,
757759
iter->iter0->flags))
758760
continue;
@@ -855,6 +857,7 @@ static struct ref_iterator *files_ref_iterator_begin(
855857
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
856858
overlay_iter->ordered);
857859
iter->iter0 = overlay_iter;
860+
iter->repo = ref_store->repo;
858861
iter->flags = flags;
859862

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

11411144
/* Do not pack broken refs: */
1142-
if (!ref_resolves_to_object(refname, oid, ref_flags))
1145+
if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
11431146
return 0;
11441147

11451148
return 1;

refs/packed-backend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ struct packed_ref_iterator {
778778
struct object_id oid, peeled;
779779
struct strbuf refname_buf;
780780

781+
struct repository *repo;
781782
unsigned int flags;
782783
};
783784

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

868869
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
869-
!ref_resolves_to_object(iter->base.refname, &iter->oid,
870-
iter->flags))
870+
!ref_resolves_to_object(iter->base.refname, iter->repo,
871+
&iter->oid, iter->flags))
871872
continue;
872873

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

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

960+
iter->repo = ref_store->repo;
959961
iter->flags = flags;
960962

961963
if (prefix && *prefix)

refs/refs-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int refname_is_safe(const char *refname);
6666
* referred-to object does not exist, emit a warning and return false.
6767
*/
6868
int ref_resolves_to_object(const char *refname,
69+
struct repository *repo,
6970
const struct object_id *oid,
7071
unsigned int flags);
7172

0 commit comments

Comments
 (0)