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 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.sys.hashsig; 11 12 13 private import libgit2.common: GIT_EXTERN; 14 15 extern (C): 16 nothrow @nogc: 17 18 /** 19 * Similarity signature of arbitrary text content based on line hashes 20 */ 21 struct git_hashsig; 22 23 /** 24 * Options for hashsig computation 25 * 26 * The options GIT_HASHSIG_NORMAL, GIT_HASHSIG_IGNORE_WHITESPACE, 27 * GIT_HASHSIG_SMART_WHITESPACE are exclusive and should not be combined. 28 */ 29 enum git_hashsig_option_t 30 { 31 /** 32 * Use all data 33 */ 34 GIT_HASHSIG_NORMAL = 0, 35 36 /** 37 * Ignore whitespace 38 */ 39 GIT_HASHSIG_IGNORE_WHITESPACE = 1 << 0, 40 41 /** 42 * Ignore \r and all space after \n 43 */ 44 GIT_HASHSIG_SMART_WHITESPACE = 1 << 1, 45 46 /** 47 * Allow hashing of small files 48 */ 49 GIT_HASHSIG_ALLOW_SMALL_FILES = 1 << 2, 50 } 51 52 //Declaration name in C language 53 enum 54 { 55 GIT_HASHSIG_NORMAL = .git_hashsig_option_t.GIT_HASHSIG_NORMAL, 56 GIT_HASHSIG_IGNORE_WHITESPACE = .git_hashsig_option_t.GIT_HASHSIG_IGNORE_WHITESPACE, 57 GIT_HASHSIG_SMART_WHITESPACE = .git_hashsig_option_t.GIT_HASHSIG_SMART_WHITESPACE, 58 GIT_HASHSIG_ALLOW_SMALL_FILES = .git_hashsig_option_t.GIT_HASHSIG_ALLOW_SMALL_FILES, 59 } 60 61 /** 62 * Compute a similarity signature for a text buffer 63 * 64 * If you have passed the option git_hashsig_option_t.GIT_HASHSIG_IGNORE_WHITESPACE, then the 65 * whitespace will be removed from the buffer while it is being processed, 66 * modifying the buffer in place. Sorry about that! 67 * 68 * Params: 69 * out_ = The computed similarity signature. 70 * buf = The input buffer. 71 * buflen = The input buffer size. 72 * opts = The signature computation options (see above). 73 * 74 * 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. 75 */ 76 @GIT_EXTERN 77 int git_hashsig_create(.git_hashsig** out_, const (char)* buf, size_t buflen, .git_hashsig_option_t opts); 78 79 /** 80 * Compute a similarity signature for a text file 81 * 82 * This walks through the file, only loading a maximum of 4K of file data at 83 * a time. Otherwise, it acts just like `git_hashsig_create`. 84 * 85 * Params: 86 * out_ = The computed similarity signature. 87 * path = The path to the input file. 88 * opts = The signature computation options (see above). 89 * 90 * 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. 91 */ 92 @GIT_EXTERN 93 int git_hashsig_create_fromfile(.git_hashsig** out_, const (char)* path, .git_hashsig_option_t opts); 94 95 /** 96 * Release memory for a content similarity signature 97 * 98 * Params: 99 * sig = The similarity signature to free. 100 */ 101 @GIT_EXTERN 102 void git_hashsig_free(.git_hashsig* sig); 103 104 /** 105 * Measure similarity score between two similarity signatures 106 * 107 * Params: 108 * a = The first similarity signature to compare. 109 * b = The second similarity signature to compare. 110 * 111 * Returns: [0 to 100] on success as the similarity score, or error code. 112 */ 113 @GIT_EXTERN 114 int git_hashsig_compare(const (.git_hashsig)* a, const (.git_hashsig)* b);