1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 module libgit2_d.sys.hashsig;
8 
9 
10 extern (C):
11 nothrow @nogc:
12 package(libgit2_d):
13 
14 /**
15  * Similarity signature of arbitrary text content based on line hashes
16  */
17 struct git_hashsig;
18 
19 /**
20  * Options for hashsig computation
21  *
22  * The options GIT_HASHSIG_NORMAL, GIT_HASHSIG_IGNORE_WHITESPACE,
23  * GIT_HASHSIG_SMART_WHITESPACE are exclusive and should not be combined.
24  */
25 enum git_hashsig_option_t
26 {
27 	/**
28 	 * Use all data
29 	 */
30 	GIT_HASHSIG_NORMAL = 0,
31 
32 	/**
33 	 * Ignore whitespace
34 	 */
35 	GIT_HASHSIG_IGNORE_WHITESPACE = 1 << 0,
36 
37 	/**
38 	 * Ignore \r and all space after \n
39 	 */
40 	GIT_HASHSIG_SMART_WHITESPACE = 1 << 1,
41 
42 	/**
43 	 * Allow hashing of small files
44 	 */
45 	GIT_HASHSIG_ALLOW_SMALL_FILES = 1 << 2,
46 }
47 
48 /**
49  * Compute a similarity signature for a text buffer
50  *
51  * If you have passed the option git_hashsig_option_t.GIT_HASHSIG_IGNORE_WHITESPACE, then the
52  * whitespace will be removed from the buffer while it is being processed,
53  * modifying the buffer in place. Sorry about that!
54  *
55  * @param out_ The computed similarity signature.
56  * @param buf The input buffer.
57  * @param buflen The input buffer size.
58  * @param opts The signature computation options (see above).
59  * @return 0 on success, git_error_code.GIT_EBUFS if the buffer doesn't contain enough data to
60  * compute a valid signature (unless git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES is set), or
61  * error code.
62  */
63 //GIT_EXTERN
64 int git_hashsig_create(.git_hashsig** out_, const (char)* buf, size_t buflen, .git_hashsig_option_t opts);
65 
66 /**
67  * Compute a similarity signature for a text file
68  *
69  * This walks through the file, only loading a maximum of 4K of file data at
70  * a time. Otherwise, it acts just like `git_hashsig_create`.
71  *
72  * @param out_ The computed similarity signature.
73  * @param path The path to the input file.
74  * @param opts The signature computation options (see above).
75  * @return 0 on success, git_error_code.GIT_EBUFS if the buffer doesn't contain enough data to
76  * compute a valid signature (unless git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES is set), or
77  * error code.
78  */
79 //GIT_EXTERN
80 int git_hashsig_create_fromfile(.git_hashsig** out_, const (char)* path, .git_hashsig_option_t opts);
81 
82 /**
83  * Release memory for a content similarity signature
84  *
85  * @param sig The similarity signature to free.
86  */
87 //GIT_EXTERN
88 void git_hashsig_free(.git_hashsig* sig);
89 
90 /**
91  * Measure similarity score between two similarity signatures
92  *
93  * @param a The first similarity signature to compare.
94  * @param b The second similarity signature to compare.
95  * @return [0 to 100] on success as the similarity score, or error code.
96  */
97 //GIT_EXTERN
98 int git_hashsig_compare(const (.git_hashsig)* a, const (.git_hashsig)* b);