MCPcopy Create free account
hub / github.com/git/git / prefix_ref_iterator_advance

Function prefix_ref_iterator_advance

refs/iterator.c:335–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335static int prefix_ref_iterator_advance(struct ref_iterator *ref_iterator)
336{
337 struct prefix_ref_iterator *iter =
338 (struct prefix_ref_iterator *)ref_iterator;
339 int ok;
340
341 while ((ok = ref_iterator_advance(iter->iter0)) == ITER_OK) {
342 int cmp = compare_prefix(iter->iter0->ref.name, iter->prefix);
343 if (cmp < 0)
344 continue;
345 /*
346 * As the source iterator is ordered, we
347 * can stop the iteration as soon as we see a
348 * refname that comes after the prefix:
349 */
350 if (cmp > 0)
351 return ITER_DONE;
352
353 iter->base.ref = iter->iter0->ref;
354
355 if (iter->trim) {
356 /*
357 * It is nonsense to trim off characters that
358 * you haven't already checked for via a
359 * prefix check, whether via this
360 * `prefix_ref_iterator` or upstream in
361 * `iter0`). So if there wouldn't be at least
362 * one character left in the refname after
363 * trimming, report it as a bug:
364 */
365 if (strlen(iter->base.ref.name) <= iter->trim)
366 BUG("attempt to trim too many characters");
367 iter->base.ref.name += iter->trim;
368 }
369
370 return ITER_OK;
371 }
372
373 return ok;
374}
375
376static int prefix_ref_iterator_seek(struct ref_iterator *ref_iterator,
377 const char *refname, unsigned int flags)

Callers

nothing calls this directly

Calls 2

ref_iterator_advanceFunction · 0.85
compare_prefixFunction · 0.85

Tested by

no test coverage detected