GitRepo.hashFile

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 use the global hashFile function. 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.

Parameters:

path: Path to file on disk whose contents should be hashed. This can be a relative path.

type: The object type to hash the file as (e.g. GitType.blob)

asPath: 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.

struct GitRepo
hashFile
(
in char[] path
,,
in char[] asPath = null
)

Examples

1 auto repo = initRepo(_userRepo, OpenBare.yes);
2 scope(exit) rmdirRecurse(_userRepo);
3 
4 string objPath = buildPath(repo.path, "test.d");
5 string text = "import std.stdio;";
6 std.file.write(objPath, text);
7 
8 auto oid = repo.hashFile(objPath, GitType.blob);

Meta