Skip to content

Commit

Permalink
Just put it all in buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Jul 16, 2014
1 parent df4cba0 commit b3af2d8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
1 change: 0 additions & 1 deletion include/git2.h
Expand Up @@ -13,7 +13,6 @@
#include "git2/blame.h" #include "git2/blame.h"
#include "git2/branch.h" #include "git2/branch.h"
#include "git2/buffer.h" #include "git2/buffer.h"
#include "git2/buf_text.h"
#include "git2/checkout.h" #include "git2/checkout.h"
#include "git2/cherrypick.h" #include "git2/cherrypick.h"
#include "git2/clone.h" #include "git2/clone.h"
Expand Down
42 changes: 0 additions & 42 deletions include/git2/buf_text.h

This file was deleted.

16 changes: 16 additions & 0 deletions include/git2/buffer.h
Expand Up @@ -105,6 +105,22 @@ GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
GIT_EXTERN(int) git_buf_set( GIT_EXTERN(int) git_buf_set(
git_buf *buffer, const void *data, size_t datalen); 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 GIT_END_DECL


/** @} */ /** @} */
Expand Down
4 changes: 2 additions & 2 deletions src/buf_text.c
Expand Up @@ -176,7 +176,7 @@ int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strings)
return 0; 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; const char *scan = buf->ptr, *end = buf->ptr + buf->size;
git_bom_t bom; git_bom_t bom;
Expand All @@ -201,7 +201,7 @@ int git_buf_text_is_binary(const git_buf *buf)
return ((printable >> 7) < nonprintable); 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); return (memchr(buf->ptr, '\0', buf->size) != NULL);
} }
Expand Down
17 changes: 16 additions & 1 deletion src/buf_text.h
Expand Up @@ -7,7 +7,6 @@
#ifndef INCLUDE_buf_text_h__ #ifndef INCLUDE_buf_text_h__
#define INCLUDE_buf_text_h__ #define INCLUDE_buf_text_h__


#include "git2/buf_text.h"
#include "buffer.h" #include "buffer.h"


typedef enum { typedef enum {
Expand Down Expand Up @@ -78,6 +77,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); 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 * Check if a buffer begins with a UTF BOM
* *
Expand Down
11 changes: 11 additions & 0 deletions src/buffer.c
Expand Up @@ -7,6 +7,7 @@
#include "buffer.h" #include "buffer.h"
#include "posix.h" #include "posix.h"
#include "git2/buffer.h" #include "git2/buffer.h"
#include "buf_text.h"
#include <ctype.h> #include <ctype.h>


/* Used as default value for git_buf->ptr so that people can always /* Used as default value for git_buf->ptr so that people can always
Expand Down Expand Up @@ -141,6 +142,16 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
return 0; 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) int git_buf_sets(git_buf *buf, const char *string)
{ {
return git_buf_set(buf, string, string ? strlen(string) : 0); return git_buf_set(buf, string, string ? strlen(string) : 0);
Expand Down

0 comments on commit b3af2d8

Please sign in to comment.