Skip to content

Commit e121b9c

Browse files
mhaggergitster
authored andcommitted
refs_ref_iterator_begin(): new function
Extract a new function from `do_for_each_ref()`. It will be useful elsewhere. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 470be51 commit e121b9c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

refs.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,18 @@ int head_ref(each_ref_fn fn, void *cb_data)
12301230
return head_ref_submodule(NULL, fn, cb_data);
12311231
}
12321232

1233+
struct ref_iterator *refs_ref_iterator_begin(
1234+
struct ref_store *refs,
1235+
const char *prefix, int trim, int flags)
1236+
{
1237+
struct ref_iterator *iter;
1238+
1239+
iter = refs->be->iterator_begin(refs, prefix, flags);
1240+
iter = prefix_ref_iterator_begin(iter, prefix, trim);
1241+
1242+
return iter;
1243+
}
1244+
12331245
/*
12341246
* Call fn for each reference in the specified submodule for which the
12351247
* refname begins with prefix. If trim is non-zero, then trim that
@@ -1247,8 +1259,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
12471259
if (!refs)
12481260
return 0;
12491261

1250-
iter = refs->be->iterator_begin(refs, prefix, flags);
1251-
iter = prefix_ref_iterator_begin(iter, prefix, trim);
1262+
iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
12521263

12531264
return do_for_each_ref_iterator(iter, fn, cb_data);
12541265
}

refs/refs-internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ struct ref_iterator *empty_ref_iterator_begin(void);
335335
*/
336336
int is_empty_ref_iterator(struct ref_iterator *ref_iterator);
337337

338+
/*
339+
* Return an iterator that goes over each reference in `refs` for
340+
* which the refname begins with prefix. If trim is non-zero, then
341+
* trim that many characters off the beginning of each refname. flags
342+
* can be DO_FOR_EACH_INCLUDE_BROKEN to include broken references in
343+
* the iteration.
344+
*/
345+
struct ref_iterator *refs_ref_iterator_begin(
346+
struct ref_store *refs,
347+
const char *prefix, int trim, int flags);
348+
338349
/*
339350
* A callback function used to instruct merge_ref_iterator how to
340351
* interleave the entries from iter0 and iter1. The function should

0 commit comments

Comments
 (0)