Just put it all in buffer.
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
diff --git a/include/git2.h b/include/git2.h
index 2a2ad93..f749760 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -13,7 +13,6 @@
#include "git2/blame.h"
#include "git2/branch.h"
#include "git2/buffer.h"
-#include "git2/buf_text.h"
#include "git2/checkout.h"
#include "git2/cherrypick.h"
#include "git2/clone.h"
diff --git a/include/git2/buf_text.h b/include/git2/buf_text.h
deleted file mode 100644
index 29bfca8..0000000
--- a/include/git2/buf_text.h
+++ /dev/null
@@ -1,42 +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_git_buf_text_h__
-#define INCLUDE_git_buf_text_h__
-
-#include "common.h"
-#include "buffer.h"
-
-/**
- * @file git2/buf_text.h
- * @brief Buffer text export structure
- *
- * @ingroup Git
- * @{
- */
-GIT_BEGIN_DECL
-
-/**
- * Check quickly if buffer looks like it contains binary data
- *
- * @param buf Buffer to check
- * @return 1 if buffer looks like non-text data
- */
-GIT_EXTERN(int) git_buf_text_is_binary(const git_buf *buf);
-
-/**
- * Check quickly if buffer contains a NUL byte
- *
- * @param buf Buffer to check
- * @return 1 if buffer contains a NUL byte
- */
-GIT_EXTERN(int) git_buf_text_contains_nul(const git_buf *buf);
-
-GIT_END_DECL
-
-/** @} */
-
-#endif
diff --git a/include/git2/buffer.h b/include/git2/buffer.h
index 36a61e6..1c216bf 100644
--- a/include/git2/buffer.h
+++ b/include/git2/buffer.h
@@ -105,6 +105,22 @@ GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
GIT_EXTERN(int) git_buf_set(
git_buf *buffer, const void *data, size_t datalen);
+/**
+* Check quickly if buffer looks like it contains binary data
+*
+* @param buf Buffer to check
+* @return 1 if buffer looks like non-text data
+*/
+GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
+
+/**
+* Check quickly if buffer contains a NUL byte
+*
+* @param buf Buffer to check
+* @return 1 if buffer contains a NUL byte
+*/
+GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
+
GIT_END_DECL
/** @} */
diff --git a/src/buf_text.c b/src/buf_text.c
index 0e93696..8d2b141 100644
--- a/src/buf_text.c
+++ b/src/buf_text.c
@@ -176,7 +176,7 @@ int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strings)
return 0;
}
-int git_buf_text_is_binary(const git_buf *buf)
+bool git_buf_text_is_binary(const git_buf *buf)
{
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
git_bom_t bom;
@@ -201,7 +201,7 @@ int git_buf_text_is_binary(const git_buf *buf)
return ((printable >> 7) < nonprintable);
}
-int git_buf_text_contains_nul(const git_buf *buf)
+bool git_buf_text_contains_nul(const git_buf *buf)
{
return (memchr(buf->ptr, '\0', buf->size) != NULL);
}
diff --git a/src/buf_text.h b/src/buf_text.h
index 3415ac0..e753a02 100644
--- a/src/buf_text.h
+++ b/src/buf_text.h
@@ -7,7 +7,6 @@
#ifndef INCLUDE_buf_text_h__
#define INCLUDE_buf_text_h__
-#include "git2/buf_text.h"
#include "buffer.h"
typedef enum {
@@ -79,6 +78,22 @@ extern int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src);
extern int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strs);
/**
+ * Check quickly if buffer looks like it contains binary data
+ *
+ * @param buf Buffer to check
+ * @return true if buffer looks like non-text data
+ */
+extern bool git_buf_text_is_binary(const git_buf *buf);
+
+/**
+ * Check quickly if buffer contains a NUL byte
+ *
+ * @param buf Buffer to check
+ * @return true if buffer contains a NUL byte
+ */
+extern bool git_buf_text_contains_nul(const git_buf *buf);
+
+/**
* Check if a buffer begins with a UTF BOM
*
* @param bom Set to the type of BOM detected or GIT_BOM_NONE
diff --git a/src/buffer.c b/src/buffer.c
index b8f8660..1bee9d7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -7,6 +7,7 @@
#include "buffer.h"
#include "posix.h"
#include "git2/buffer.h"
+#include "buf_text.h"
#include <ctype.h>
/* Used as default value for git_buf->ptr so that people can always
@@ -141,6 +142,16 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
return 0;
}
+int git_buf_is_binary(const git_buf *buf)
+{
+ return git_buf_text_is_binary(buf);
+}
+
+int git_buf_contains_nul(const git_buf *buf)
+{
+ return git_buf_text_contains_nul(buf);
+}
+
int git_buf_sets(git_buf *buf, const char *string)
{
return git_buf_set(buf, string, string ? strlen(string) : 0);