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.
This commit is contained in:
Russell Belfer
2012-09-11 15:01:09 -07:00
parent 412293dcc9
commit 47bfa0be6d
4 changed files with 148 additions and 2 deletions
+25
View File
@@ -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