Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Export git_buf_text_is_binary and git_buf_text_contains_nul. #2475

Merged
merged 2 commits into from

4 participants

@joshaber
Owner

So that users don’t need to implement binary detection themselves.

@joshaber joshaber Export git_buf_text_is_binary and git_buf_text_contains_nul.
So that users don’t need to implement binary detection themselves.
df4cba0
@arrbee
Owner

Hmm, I feel like if we're going to expose these functions that instead of adding another public header, it would be tempting to just add them as git_buffer_is_binary and git_buffer_contains_nul and either make 1-line wrappers with the new names or just rename the old functions. Of course, @vmg may disagree, but this doesn't feel like significant enough functionality the keep distinct from include/git2/buffer.h.

@joshaber
Owner

That's cool too! I was looking at buf_text.h and it seemed like there was other stuff in there that we might want to export in the future. But I'm happy to keep it all in buffer.h if that's what you guys would prefer.

@linquize

Have you notice the problem in #2436?

@vmg
Owner

Definitely agree with @arrbee let's put this in the buf namespace, at least with a thin wrapper.

@joshaber
Owner

:cool:

Moved it to buf.

@vmg vmg merged commit 091165c into from
@joshaber
Owner

:metal:

@joshaber joshaber deleted the branch
@linquize

Hi, does anyone notice the problem in #2436?
And you expose them before git_buf_text_is_binary() is corrected.

@joshaber
Owner

Well, to be fair we expose both. Users can decide if they want the simpler NUL check or the heuristic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 16, 2014
  1. @joshaber

    Export git_buf_text_is_binary and git_buf_text_contains_nul.

    joshaber authored
    So that users don’t need to implement binary detection themselves.
  2. @joshaber

    Just put it all in buffer.

    joshaber authored
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 0 deletions.
  1. +16 −0 include/git2/buffer.h
  2. +11 −0 src/buffer.c
View
16 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
/** @} */
View
11 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);
Something went wrong with that request. Please try again.