Skip to content

Build fails with libgit2 1.9.2: -Wmissing-field-initializers error in pass_githistory.c #104

@jsyrjala

Description

@jsyrjala

Problem

Build fails on clang with -Werror enabled when using libgit2 1.9.2:

  src/pipeline/pass_githistory.c:171:42: error: missing field 'interhunk_lines' initializer
      [-Werror,-Wmissing-field-initializers]
      git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
                                                        ^

The GIT_DIFF_OPTIONS_INIT macro does not initialize all struct fields, which clang treats as an error under -Werror,-Wmissing-field-initializers.

Fix

Replace the compile-time macro with the runtime API:

  // Before (fails):
  git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
  // After (works):
  git_diff_options diff_opts;
  git_diff_options_init(&diff_opts, GIT_DIFF_OPTIONS_VERSION);

git_diff_options_init() has been available since libgit2 0.28.

Affected file

src/pipeline/pass_githistory.c:171

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions