]> git.ipfire.org Git - thirdparty/git.git/commit - ref-filter.c
ref-filter.c: filter & format refs in the same callback
authorVictoria Dye <vdye@github.com>
Tue, 14 Nov 2023 19:53:55 +0000 (19:53 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Nov 2023 05:03:00 +0000 (14:03 +0900)
commitbd98f9774e10808276c13f8438aa3c71093bc6a4
treebfb967ae17de37af5431ecc58a32faea161b61b1
parent613d9915499ed9d1fd21d743002d17ef972e9e57
ref-filter.c: filter & format refs in the same callback

Update 'filter_and_format_refs()' to try to perform ref filtering &
formatting in a single ref iteration, without an intermediate 'struct
ref_array'. This can only be done if no operations need to be performed on a
pre-filtered array; specifically, if the refs are

- filtered on reachability,
- sorted, or
- formatted with ahead-behind information

they cannot be filtered & formatted in the same iteration. In that case,
fall back on the current filter-then-sort-then-format flow.

This optimization substantially improves memory usage due to no longer
storing a ref array in memory. In some cases, it also dramatically reduces
runtime (e.g. 'git for-each-ref --no-sort --count=1', which no longer loads
all refs into a 'struct ref_array' to printing only the first ref).

Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ref-filter.c