meson: don't recompile git-remote-http(1) multiple times for tests

When running our tests, we expect git-remote-http(1) and a couple of
other binaries to be available to the test suite. In our Makefile, we
achieve this by simply hardlinking the file into place in our source
directory. We cannot easily do that in Meson though because there is no
available command to create such a hardlink.

We could of course create a custom target that uses a script for that,
but that feels quite awkward. Instead, we build the executable several
times, which is of course less efficient. Even worse though, similar as
in the preceding commit, we're building "remote-curl.c" once for each of
these targets, which makes this even more expensive.

Fix this by reusing the already-compiled objects from git-remote-http(1)
so that we only have to perform the linking step several times. This
leads to a mild speedup:

  Benchmark 1: meson compile (version = HEAD~)
    Time (mean ± σ):      6.250 s ±  0.040 s    [User: 90.881 s, System: 21.912 s]
    Range (min … max):    6.197 s …  6.344 s    10 runs

  Benchmark 2: meson compile (version = HEAD)
    Time (mean ± σ):      6.218 s ±  0.029 s    [User: 90.633 s, System: 22.022 s]
    Range (min … max):    6.166 s …  6.262 s    10 runs

  Summary
    meson compile (version = HEAD) ran
      1.01 ± 0.01 times faster than meson compile (version = HEAD~)

Honestly, a 1% speedup isn't really worth it. But the change makes sense
anyway, as we're doing the same when we build git-receive-pack(1) et al.
So while the speed improvement is negligible, it brings more consistency
into our build instructions.

For the record: I also had a look at using a custom target that
hardlinks the files into place. But the improvement it had on our build
times were not that mindblowing either, saving roundabout ~100ms in wall
time. So sticking with the status quo felt like the better solution as
it is native to Meson.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-09-24 16:09:11 +02:00 committed by Junio C Hamano
parent d8e1ba5c4d
commit cc839e97a3
1 changed files with 3 additions and 2 deletions

View File

@ -1935,12 +1935,13 @@ if curl.found()
dependencies: [libgit_commonmain, curl],
)

test_dependencies += executable('git-remote-http',
git_remote_http = executable('git-remote-http',
sources: 'remote-curl.c',
dependencies: [libgit_curl],
install: true,
install_dir: git_exec_path,
)
test_dependencies += git_remote_http

test_dependencies += executable('git-http-fetch',
sources: 'http-fetch.c',
@ -1960,7 +1961,7 @@ if curl.found()

foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ]
test_dependencies += executable(alias,
sources: 'remote-curl.c',
objects: git_remote_http.extract_all_objects(recursive: false),
dependencies: [libgit_curl],
)