git/t/helper
Patrick Steinhardt cec2b6f55a refs/iterator: separate lifecycle from iteration
The ref and reflog iterators have their lifecycle attached to iteration:
once the iterator reaches its end, it is automatically released and the
caller doesn't have to care about that anymore. When the iterator should
be released before it has been exhausted, callers must explicitly abort
the iterator via `ref_iterator_abort()`.

This lifecycle is somewhat unusual in the Git codebase and creates two
problems:

  - Callsites need to be very careful about when exactly they call
    `ref_iterator_abort()`, as calling the function is only valid when
    the iterator itself still is. This leads to somewhat awkward calling
    patterns in some situations.

  - It is impossible to reuse iterators and re-seek them to a different
    prefix. This feature isn't supported by any iterator implementation
    except for the reftable iterators anyway, but if it was implemented
    it would allow us to optimize cases where we need to search for
    specific references repeatedly by reusing internal state.

Detangle the lifecycle from iteration so that we don't deallocate the
iterator anymore once it is exhausted. Instead, callers are now expected
to always call a newly introduce `ref_iterator_free()` function that
deallocates the iterator and its internal state.

Note that the `dir_iterator` is somewhat special because it does not
implement the `ref_iterator` interface, but is only used to implement
other iterators. Consequently, we have to provide `dir_iterator_free()`
instead of `dir_iterator_release()` as the allocated structure itself is
managed by the `dir_iterator` interfaces, as well, and not freed by
`ref_iterator_free()` like in all the other cases.

While at it, drop the return value of `ref_iterator_abort()`, which
wasn't really required by any of the iterator implementations anyway.
Furthermore, stop calling `base_ref_iterator_free()` in any of the
backends, but instead call it in `ref_iterator_free()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-03-12 11:31:18 -07:00
..
.gitignore
meson.build Merge branch 'ds/name-hash-tweaks' 2025-02-12 10:08:51 -08:00
test-advise.c global: prepare for hiding away repo-less config functions 2024-08-13 10:01:05 -07:00
test-bitmap.c Merge branch 'ps/use-the-repository' 2024-07-02 09:59:00 -07:00
test-bloom.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-bundle-uri.c
test-cache-tree.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-chmtime.c
test-config.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-crontab.c
test-csprng.c wrapper: allow generating insecure random bytes 2025-01-07 09:04:18 -08:00
test-date.c
test-delete-gpgsig.c
test-delta.c
test-dir-iterator.c refs/iterator: separate lifecycle from iteration 2025-03-12 11:31:18 -07:00
test-drop-caches.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-dump-cache-tree.c
test-dump-fsmonitor.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-dump-split-index.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-dump-untracked-cache.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-env-helper.c
test-example-tap.c Merge branch 'jk/mark-unused-parameters' 2024-08-26 11:32:23 -07:00
test-fake-ssh.c
test-find-pack.c packfile: use object_id in find_pack_entry_one() 2024-10-25 17:35:46 -04:00
test-fsmonitor-client.c
test-genrandom.c t/helper: don't depend on implicit wraparound 2024-12-06 20:20:05 +09:00
test-genzeros.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-getcwd.c
test-hash-speed.c global: adapt callers to use generic hash context helpers 2025-01-31 10:06:11 -08:00
test-hash.c global: adapt callers to use generic hash context helpers 2025-01-31 10:06:11 -08:00
test-hashmap.c t/helper: mark more unused argv/argc arguments 2024-08-17 09:46:11 -07:00
test-hexdump.c
test-json-writer.c set errno=0 before strtoX calls 2024-08-05 10:59:20 -07:00
test-lazy-init-name-hash.c
test-match-trees.c
test-mergesort.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-mktemp.c
test-name-hash.c test-tool: add helper for name-hash values 2025-01-27 13:21:43 -08:00
test-online-cpus.c
test-pack-mtimes.c
test-parse-options.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-parse-pathspec-file.c
test-partial-clone.c t/helper: fix leaking repository in partial-clone helper 2024-09-30 11:23:05 -07:00
test-path-utils.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-path-walk.c backfill: add --sparse option 2025-02-03 16:12:42 -08:00
test-pcre2-config.c
test-pkt-line.c
test-proc-receive.c t/helper: fix leaks in proc-receive helper 2024-09-30 11:23:08 -07:00
test-progress.c progress: stop using `the_repository` 2024-12-18 10:44:30 -08:00
test-reach.c commit-reach: use `size_t` to track indices when computing merge bases 2024-12-27 08:12:40 -08:00
test-read-cache.c t/helper: stop re-initialization of `the_repository` 2024-11-04 22:37:56 -08:00
test-read-graph.c t/helper: fix leaking commit graph in "read-graph" subcommand 2024-11-21 08:23:45 +09:00
test-read-midx.c midx: pass `repository` to `load_multi_pack_index` 2024-12-04 10:32:20 +09:00
test-ref-store.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
test-reftable.c reftable/system: stop depending on "hash.h" 2024-11-19 12:23:10 +09:00
test-regex.c
test-repository.c t/test-repository: fix leaking repository 2024-08-01 08:47:37 -07:00
test-revision-walking.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
test-rot13-filter.c t/helper: fix a typo 2024-10-10 13:31:13 -07:00
test-run-command.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-scrap-cache-tree.c
test-serve-v2.c serve: stop using `the_repository` 2024-12-18 10:44:30 -08:00
test-sha1.c t/helper/test-tool: implement sha1-unsafe helper 2025-01-23 10:28:16 -08:00
test-sha1.sh t/helper/test-tool: implement sha1-unsafe helper 2025-01-23 10:28:16 -08:00
test-sha256.c t/helper/test-tool: implement sha1-unsafe helper 2025-01-23 10:28:16 -08:00
test-sigchain.c
test-simple-ipc.c builtins: send usage_with_options() help text to standard output 2025-01-17 13:30:03 -08:00
test-string-list.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-submodule-config.c
test-submodule-nested-repo-config.c t/helper: fix leaking subrepo in nested submodule config helper 2024-09-27 08:25:35 -07:00
test-submodule.c
test-subprocess.c
test-tool-utils.h
test-tool.c Merge branch 'ds/name-hash-tweaks' 2025-02-12 10:08:51 -08:00
test-tool.h Merge branch 'ds/name-hash-tweaks' 2025-02-12 10:08:51 -08:00
test-trace2.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
test-truncate.c
test-userdiff.c global: prepare for hiding away repo-less config functions 2024-08-13 10:01:05 -07:00
test-wildmatch.c
test-windows-named-pipe.c
test-write-cache.c
test-xml-encode.c