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 * Params: 56 * out_ = The computed similarity signature. 57 * buf = The input buffer. 58 * buflen = The input buffer size. 59 * opts = The signature computation options (see above). 60 * 61 * 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. 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 * Params: 73 * out_ = The computed similarity signature. 74 * path = The path to the input file. 75 * opts = The signature computation options (see above). 76 * 77 * 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. 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 * Params: 86 * sig = The similarity signature to free. 87 */ 88 //GIT_EXTERN 89 void git_hashsig_free(.git_hashsig* sig); 90 91 /** 92 * Measure similarity score between two similarity signatures 93 * 94 * Params: 95 * a = The first similarity signature to compare. 96 * b = The second similarity signature to compare. 97 * 98 * Returns: [0 to 100] on success as the similarity score, or error code. 99 */ 100 //GIT_EXTERN 101 int git_hashsig_compare(const (.git_hashsig)* a, const (.git_hashsig)* b);