git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] meson: Check whether git is new enough to support ls-files --deduplicate

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 1, 2025, 05:27 UTC
Message-ID
<aIxQWSrnMOuEmfHo@pks.im>
In-Reply-To
<20250731121533.178747-1-martin@martin.st>
On Thu, Jul 31, 2025 at 03:15:30PM +0300, Martin Storsjö wrote:
> This fixes Meson errors like this:

Our commit messages are described so that we first describe the error and then we describe how this is fixed, and typically they are written in such a way that they can be read without requiring you to also read the subject line.

So something like:
    When using the Meson build system with an old-enough Git version
    that does not yet know the `git ls-files --deduplicate` option one
    can observe the following error:
        ../meson.build:697:19: ERROR: Command `/usr/bin/git -C /home/martin/code/git ls-files --deduplicate '*.h' ':!contrib' ':!compat/inet_ntop.c' ':!compat/inet_pton.c' ':!compat/nedmalloc' ':!compat/obstack.*' ':!compat/poll' ':!compat/regex' ':!sha1collisiondetection' ':!sha1dc' ':!t/unit-tests/clar' ':!t/t[0-9][0-9][0-9][0-9]*' ':!xdiff'` failed with status 129.
    The failing command is used to find all header files in our code
    base, which is required for static analysis.
    Static analysis is an entirely optional feature that distributors
    typically don't care, and about we already know to skip running the
    command when we are not in a Git repository. But we do not handle
    the above failure gracefully, even though we could.
    Fix this by detecting whether the Git version is new enough to
    support the `--deduplicate` option. Unfortunately, Meson only
    supports the external_program.version() method since Meson 0.62. So
    with older versions of Meson, we have to just assume that it exists
    (or maybe assume that it doesn't).
Show 26 quoted lines
>     ../meson.build:697:19: ERROR: Command `/usr/bin/git -C /home/martin/code/git ls-files --deduplicate '*.h' ':!contrib' ':!compat/inet_ntop.c' ':!compat/inet_pton.c' ':!compat/nedmalloc' ':!compat/obstack.*' ':!compat/poll' ':!compat/regex' ':!sha1collisiondetection' ':!sha1dc' ':!t/unit-tests/clar' ':!t/t[0-9][0-9][0-9][0-9]*' ':!xdiff'` failed with status 129.
> 
> Unfortunately, Meson only supports the external_program.version()
> method since Meson 0.62. So with older versions of Meson, we have
> to just assume that it exists (or maybe assume that it doesn't).
> 
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
>  meson.build | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index 9bc1826cb6..717365baec 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -693,7 +693,14 @@ third_party_excludes = [
>  ]
>  
>  headers_to_check = []
> -if git.found() and fs.exists(meson.project_source_root() / '.git')
> +if meson.version().version_compare('>=0.62')
> +  new_enough_git = git.found() and git.version().version_compare('>=2.31')
> +else
> +  # On Meson 0.61, we can't check git.version(), so we just have to
> +  # assume that the found git is new enough.
> +  new_enough_git = git.found()

I'd rather call this `git_supports_file_deduplication`. It's a bit of a mouthful, but `new_enough_git` raises the question of what it is new enough for.

> +endif
> +if new_enough_git and fs.exists(meson.project_source_root() / '.git')
>    foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: true).stdout().split()

I wonder whether we could avoid the whole version check machinery and just change this command to `check: false`. If so we accept in case the command fails, which we can check by calling `.returncode()`.

Thanks!
Patrick
Previous: Martin StorsjöNext: Martin Storsjö
Message 2 of 13 in “meson: Check whether git is new enough to support ls-files --deduplicate”
  1. meson: Check whether git is new enough to support ls-files --deduplicateMartin Storsjö, Jul 31, 2025
  2. Patrick SteinhardtAug 1, 2025
  3. Martin StorsjöAug 1, 2025
  4. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 2025
  5. Patrick SteinhardtAug 1, 2025
  6. Martin StorsjöAug 1, 2025
  7. Patrick SteinhardtAug 1, 2025
  8. Martin StorsjöAug 1, 2025
  9. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 2025
  10. Patrick SteinhardtAug 1, 2025
  11. Junio C HamanoAug 1, 2025
  12. Martin StorsjöAug 1, 2025
  13. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.