Skip to content

Conversation

@lrm29
Copy link
Contributor

@lrm29 lrm29 commented Jan 15, 2020

Because this accessor is const, I can't do something like this in the git merge driver without casting away const:

int CustomApply(git_merge_driver* self,
                const char** path_out,
                uint32_t* mode_out,
                git_buf* merged_out,
                const char* filter_name,
                const git_merge_driver_source* src) {
    const git_repository* repo = git_merge_driver_source_repo(src);

    git_config* cfg;

    // ERROR! repo is const!
    int errorCode = git_repository_config(&cfg, repo);

    git_config_free(cfg);

    return 0;
}

The definition of git_merge_driver_source has git_repository as non-const:

struct git_merge_driver_source {
	git_repository *repo;
	const char *default_driver;
	const git_merge_file_options *file_opts;

	const git_index_entry *ancestor;
	const git_index_entry *ours;
	const git_index_entry *theirs;
};

@ethomson
Copy link
Member

Indeed. This seems like the right thing to do. @pks-t any comments?

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for this improvement!

@pks-t pks-t merged commit a76348e into libgit2:master Jan 17, 2020
@lrm29 lrm29 deleted the git_merge_driver_source_repo_non_const branch January 17, 2020 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants