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 //Declaration name in C language
49 enum
50 {
51 	GIT_HASHSIG_NORMAL = .git_hashsig_option_t.GIT_HASHSIG_NORMAL,
52 	GIT_HASHSIG_IGNORE_WHITESPACE = .git_hashsig_option_t.GIT_HASHSIG_IGNORE_WHITESPACE,
53 	GIT_HASHSIG_SMART_WHITESPACE = .git_hashsig_option_t.GIT_HASHSIG_SMART_WHITESPACE,
54 	GIT_HASHSIG_ALLOW_SMALL_FILES = .git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES,
55 }
56 
57 /**
58  * Compute a similarity signature for a text buffer
59  *
60  * If you have passed the option git_hashsig_option_t.GIT_HASHSIG_IGNORE_WHITESPACE, then the
61  * whitespace will be removed from the buffer while it is being processed,
62  * modifying the buffer in place. Sorry about that!
63  *
64  * Params:
65  *      out_ = The computed similarity signature.
66  *      buf = The input buffer.
67  *      buflen = The input buffer size.
68  *      opts = The signature computation options (see above).
69  *
70  * Returns: 0 on success, git_error_code.GIT_EBUFS if the buffer doesn't contain enough data to compute a valid signature (unless git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES is set), or error code.
71  */
72 //GIT_EXTERN
73 int git_hashsig_create(.git_hashsig** out_, const (char)* buf, size_t buflen, .git_hashsig_option_t opts);
74 
75 /**
76  * Compute a similarity signature for a text file
77  *
78  * This walks through the file, only loading a maximum of 4K of file data at
79  * a time. Otherwise, it acts just like `git_hashsig_create`.
80  *
81  * Params:
82  *      out_ = The computed similarity signature.
83  *      path = The path to the input file.
84  *      opts = The signature computation options (see above).
85  *
86  * Returns: 0 on success, git_error_code.GIT_EBUFS if the buffer doesn't contain enough data to compute a valid signature (unless git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES is set), or error code.
87  */
88 //GIT_EXTERN
89 int git_hashsig_create_fromfile(.git_hashsig** out_, const (char)* path, .git_hashsig_option_t opts);
90 
91 /**
92  * Release memory for a content similarity signature
93  *
94  * Params:
95  *      sig = The similarity signature to free.
96  */
97 //GIT_EXTERN
98 void git_hashsig_free(.git_hashsig* sig);
99 
100 /**
101  * Measure similarity score between two similarity signatures
102  *
103  * Params:
104  *      a = The first similarity signature to compare.
105  *      b = The second similarity signature to compare.
106  *
107  * Returns: [0 to 100] on success as the similarity score, or error code.
108  */
109 //GIT_EXTERN
110 int git_hashsig_compare(const (.git_hashsig)* a, const (.git_hashsig)* b);