Merge pull request #2594 from libgit2/vmg/hashsig hashsig: Export as a `sys` header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
diff --git a/include/git2/sys/hashsig.h b/include/git2/sys/hashsig.h
new file mode 100644
index 0000000..cd735e1
--- /dev/null
+++ b/include/git2/sys/hashsig.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_sys_hashsig_h__
+#define INCLUDE_sys_hashsig_h__
+
+#include "git2/common.h"
+
+GIT_BEGIN_DECL
+
+/**
+ * Similarity signature of line hashes for a buffer
+ */
+typedef struct git_hashsig git_hashsig;
+
+typedef enum {
+ GIT_HASHSIG_NORMAL = 0, /* use all data */
+ GIT_HASHSIG_IGNORE_WHITESPACE = 1, /* ignore whitespace */
+ GIT_HASHSIG_SMART_WHITESPACE = 2, /* ignore \r and all space after \n */
+} git_hashsig_option_t;
+
+/**
+ * Build a similarity signature for a buffer
+ *
+ * If you have passed a whitespace-ignoring buffer, then the whitespace
+ * will be removed from the buffer while it is being processed, modifying
+ * the buffer in place. Sorry about that!
+ *
+ * This will return an error if the buffer doesn't contain enough data to
+ * compute a valid signature.
+ *
+ * @param out The array of hashed runs representing the file content
+ * @param buf The contents of the file to hash
+ * @param buflen The length of the data at `buf`
+ * @param generate_pairwise_hashes Should pairwise runs be hashed
+ */
+GIT_EXTERN(int) git_hashsig_create(
+ git_hashsig **out,
+ const char *buf,
+ size_t buflen,
+ git_hashsig_option_t opts);
+
+/**
+ * Build a similarity signature from a file
+ *
+ * This walks through the file, only loading a maximum of 4K of file data at
+ * a time. Otherwise, it acts just like `git_hashsig_create`.
+ *
+ * This will return an error if the file doesn't contain enough data to
+ * compute a valid signature.
+ */
+GIT_EXTERN(int) git_hashsig_create_fromfile(
+ git_hashsig **out,
+ const char *path,
+ git_hashsig_option_t opts);
+
+/**
+ * Release memory for a content similarity signature
+ */
+GIT_EXTERN(void) git_hashsig_free(git_hashsig *sig);
+
+/**
+ * Measure similarity between two files
+ *
+ * @return <0 for error, [0 to 100] as similarity score
+ */
+GIT_EXTERN(int) git_hashsig_compare(
+ const git_hashsig *a,
+ const git_hashsig *b);
+
+GIT_END_DECL
+
+#endif
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 423a0ca..9ebce06 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -8,9 +8,9 @@
#include "git2/config.h"
#include "git2/blob.h"
+#include "git2/sys/hashsig.h"
#include "diff.h"
-#include "hashsig.h"
#include "path.h"
#include "fileops.h"
#include "config.h"
diff --git a/src/hashsig.c b/src/hashsig.c
index 109f966..a6d5f20 100644
--- a/src/hashsig.c
+++ b/src/hashsig.c
@@ -4,7 +4,7 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "hashsig.h"
+#include "git2/sys/hashsig.h"
#include "fileops.h"
#include "util.h"
diff --git a/src/hashsig.h b/src/hashsig.h
deleted file mode 100644
index 8c920cb..0000000
--- a/src/hashsig.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_hashsig_h__
-#define INCLUDE_hashsig_h__
-
-#include "common.h"
-
-/**
- * Similarity signature of line hashes for a buffer
- */
-typedef struct git_hashsig git_hashsig;
-
-typedef enum {
- GIT_HASHSIG_NORMAL = 0, /* use all data */
- GIT_HASHSIG_IGNORE_WHITESPACE = 1, /* ignore whitespace */
- GIT_HASHSIG_SMART_WHITESPACE = 2, /* ignore \r and all space after \n */
-} git_hashsig_option_t;
-
-/**
- * Build a similarity signature for a buffer
- *
- * If you have passed a whitespace-ignoring buffer, then the whitespace
- * will be removed from the buffer while it is being processed, modifying
- * the buffer in place. Sorry about that!
- *
- * This will return an error if the buffer doesn't contain enough data to
- * compute a valid signature.
- *
- * @param out The array of hashed runs representing the file content
- * @param buf The contents of the file to hash
- * @param buflen The length of the data at `buf`
- * @param generate_pairwise_hashes Should pairwise runs be hashed
- */
-extern int git_hashsig_create(
- git_hashsig **out,
- const char *buf,
- size_t buflen,
- git_hashsig_option_t opts);
-
-/**
- * Build a similarity signature from a file
- *
- * This walks through the file, only loading a maximum of 4K of file data at
- * a time. Otherwise, it acts just like `git_hashsig_create`.
- *
- * This will return an error if the file doesn't contain enough data to
- * compute a valid signature.
- */
-extern int git_hashsig_create_fromfile(
- git_hashsig **out,
- const char *path,
- git_hashsig_option_t opts);
-
-/**
- * Release memory for a content similarity signature
- */
-extern void git_hashsig_free(git_hashsig *sig);
-
-/**
- * Measure similarity between two files
- *
- * @return <0 for error, [0 to 100] as similarity score
- */
-extern int git_hashsig_compare(
- const git_hashsig *a,
- const git_hashsig *b);
-
-#endif
diff --git a/src/merge.c b/src/merge.c
index ddeea87..1e72520 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -22,7 +22,6 @@
#include "tree.h"
#include "merge_file.h"
#include "blob.h"
-#include "hashsig.h"
#include "oid.h"
#include "index.h"
#include "filebuf.h"
@@ -42,6 +41,7 @@
#include "git2/tree.h"
#include "git2/oidarray.h"
#include "git2/sys/index.h"
+#include "git2/sys/hashsig.h"
#define GIT_MERGE_INDEX_ENTRY_EXISTS(X) ((X).mode != 0)
#define GIT_MERGE_INDEX_ENTRY_ISFILE(X) S_ISREG((X).mode)
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index 7482dad..641fed6 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -1,7 +1,7 @@
#include "clar_libgit2.h"
#include "buffer.h"
#include "buf_text.h"
-#include "hashsig.h"
+#include "git2/sys/hashsig.h"
#include "fileops.h"
#define TESTSTR "Have you seen that? Have you seeeen that??"
diff --git a/tests/merge/trees/treediff.c b/tests/merge/trees/treediff.c
index 2298a30..8b47f7d 100644
--- a/tests/merge/trees/treediff.c
+++ b/tests/merge/trees/treediff.c
@@ -3,7 +3,7 @@
#include "merge.h"
#include "../merge_helpers.h"
#include "diff.h"
-#include "hashsig.h"
+#include "git2/sys/hashsig.h"
static git_repository *repo;