From 47bfa0be6d509b60eda92705b57d3f7ba89c1c6b Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 7 Sep 2012 13:27:49 -0700 Subject: Add git_repository_hashfile to hash with filters The existing `git_odb_hashfile` does not apply text filtering rules because it doesn't have a repository context to evaluate the correct rules to apply. This adds a new hashfile function that will apply repository-specific filters (based on config, attributes, and filename) before calculating the hash. --- include/git2/repository.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include/git2/repository.h') diff --git a/include/git2/repository.h b/include/git2/repository.h index f520d5433..ebea3b0d4 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -481,6 +481,31 @@ GIT_EXTERN(int) git_repository_message(char *buffer, size_t len, git_repository */ GIT_EXTERN(int) git_repository_message_remove(git_repository *repo); +/** + * Calculate hash of file using repository filtering rules. + * + * If you simply want to calculate the hash of a file on disk with no filters, + * you can just use the `git_odb_hashfile()` API. However, if you want to + * hash a file in the repository and you want to apply filtering rules (e.g. + * crlf filters) before generating the SHA, then use this function. + * + * @param out Output value of calculated SHA + * @param repo Repository pointer. NULL is allowed to just use global and + * system attributes for choosing filters. + * @param path Path to file on disk whose contents should be hashed. If the + * repository is not NULL, this can be a relative path. + * @param type The object type to hash as (e.g. GIT_OBJ_BLOB) + * @param as_path The path to use to look up filtering rules. If this is + * NULL, then the `path` parameter will be used instead. If + * this is passed as the empty string, then no filters will be + * applied when calculating the hash. + */ +GIT_EXTERN(int) git_repository_hashfile( + git_oid *out, + git_repository *repo, + const char *path, + git_otype type, + const char *as_path); /** @} */ GIT_END_DECL -- cgit v1.2.1