Commit 13224ea4 by Vicent Martí

buffer: Unify `git_fbuffer` and `git_buf`

This makes so much sense that I can't believe it hasn't been done
before. Kill the old `git_fbuffer` and read files straight into
`git_buf` objects.

Also: In order to fully support 4GB files in 32-bit systems, the
`git_buf` implementation has been changed from using `ssize_t` for
storage and storing negative values on allocation failure, to using
`size_t` and changing the buffer pointer to a magical pointer on
allocation failure.

Hopefully this won't break anything.
parent e07c2d22
...@@ -111,7 +111,7 @@ int git_attr_file__from_file( ...@@ -111,7 +111,7 @@ int git_attr_file__from_file(
git_repository *repo, const char *path, git_attr_file *file) git_repository *repo, const char *path, git_attr_file *file)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
git_fbuffer fbuf = GIT_FBUFFER_INIT; git_buf fbuf = GIT_BUF_INIT;
assert(path && file); assert(path && file);
...@@ -120,9 +120,9 @@ int git_attr_file__from_file( ...@@ -120,9 +120,9 @@ int git_attr_file__from_file(
if (error == GIT_SUCCESS && if (error == GIT_SUCCESS &&
(error = git_futils_readbuffer(&fbuf, path)) == GIT_SUCCESS) (error = git_futils_readbuffer(&fbuf, path)) == GIT_SUCCESS)
error = git_attr_file__from_buffer(repo, fbuf.data, file); error = git_attr_file__from_buffer(repo, fbuf.ptr, file);
git_futils_freebuffer(&fbuf); git_buf_free(&fbuf);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS)
git__rethrow(error, "Could not open attribute file '%s'", path); git__rethrow(error, "Could not open attribute file '%s'", path);
......
...@@ -7,14 +7,17 @@ ...@@ -7,14 +7,17 @@
#include "buffer.h" #include "buffer.h"
#include "posix.h" #include "posix.h"
#include <stdarg.h> #include <stdarg.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
* assume ptr is non-NULL and zero terminated even for new git_bufs. * assume ptr is non-NULL and zero terminated even for new git_bufs.
*/ */
char git_buf_initbuf[1]; char git_buf_initbuf[1];
static char git_buf__oom;
#define ENSURE_SIZE(b, d) \ #define ENSURE_SIZE(b, d) \
if ((ssize_t)(d) > buf->asize && git_buf_grow(b, (d)) < GIT_SUCCESS)\ if ((d) > buf->asize && git_buf_grow(b, (d)) < GIT_SUCCESS)\
return GIT_ENOMEM; return GIT_ENOMEM;
...@@ -31,8 +34,10 @@ void git_buf_init(git_buf *buf, size_t initial_size) ...@@ -31,8 +34,10 @@ void git_buf_init(git_buf *buf, size_t initial_size)
int git_buf_grow(git_buf *buf, size_t target_size) int git_buf_grow(git_buf *buf, size_t target_size)
{ {
int error = git_buf_try_grow(buf, target_size); int error = git_buf_try_grow(buf, target_size);
if (error != GIT_SUCCESS) if (error != GIT_SUCCESS) {
buf->asize = -1; buf->ptr = &git_buf__oom;
}
return error; return error;
} }
...@@ -41,17 +46,17 @@ int git_buf_try_grow(git_buf *buf, size_t target_size) ...@@ -41,17 +46,17 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
char *new_ptr; char *new_ptr;
size_t new_size; size_t new_size;
if (buf->asize < 0) if (buf->ptr == &git_buf__oom)
return GIT_ENOMEM; return GIT_ENOMEM;
if (target_size <= (size_t)buf->asize) if (target_size <= buf->asize)
return GIT_SUCCESS; return GIT_SUCCESS;
if (buf->asize == 0) { if (buf->asize == 0) {
new_size = target_size; new_size = target_size;
new_ptr = NULL; new_ptr = NULL;
} else { } else {
new_size = (size_t)buf->asize; new_size = buf->asize;
new_ptr = buf->ptr; new_ptr = buf->ptr;
} }
...@@ -64,7 +69,6 @@ int git_buf_try_grow(git_buf *buf, size_t target_size) ...@@ -64,7 +69,6 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
new_size = (new_size + 7) & ~7; new_size = (new_size + 7) & ~7;
new_ptr = git__realloc(new_ptr, new_size); new_ptr = git__realloc(new_ptr, new_size);
/* if realloc fails, return without modifying the git_buf */
if (!new_ptr) if (!new_ptr)
return GIT_ENOMEM; return GIT_ENOMEM;
...@@ -83,7 +87,7 @@ void git_buf_free(git_buf *buf) ...@@ -83,7 +87,7 @@ void git_buf_free(git_buf *buf)
{ {
if (!buf) return; if (!buf) return;
if (buf->ptr != git_buf_initbuf) if (buf->ptr != git_buf_initbuf && buf->ptr != &git_buf__oom)
git__free(buf->ptr); git__free(buf->ptr);
git_buf_init(buf, 0); git_buf_init(buf, 0);
...@@ -98,12 +102,12 @@ void git_buf_clear(git_buf *buf) ...@@ -98,12 +102,12 @@ void git_buf_clear(git_buf *buf)
int git_buf_oom(const git_buf *buf) int git_buf_oom(const git_buf *buf)
{ {
return (buf->asize < 0); return (buf->ptr == &git_buf__oom);
} }
int git_buf_lasterror(const git_buf *buf) int git_buf_lasterror(const git_buf *buf)
{ {
return (buf->asize < 0) ? GIT_ENOMEM : GIT_SUCCESS; return (buf->ptr == &git_buf__oom) ? GIT_ENOMEM : GIT_SUCCESS;
} }
int git_buf_set(git_buf *buf, const char *data, size_t len) int git_buf_set(git_buf *buf, const char *data, size_t len)
...@@ -162,11 +166,12 @@ int git_buf_printf(git_buf *buf, const char *format, ...) ...@@ -162,11 +166,12 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
va_end(arglist); va_end(arglist);
if (len < 0) { if (len < 0) {
buf->asize = -1; free(buf->ptr);
buf->ptr = &git_buf__oom;
return GIT_ENOMEM; return GIT_ENOMEM;
} }
if (len + 1 <= buf->asize - buf->size) { if ((size_t)len + 1 <= buf->asize - buf->size) {
buf->size += len; buf->size += len;
break; break;
} }
...@@ -205,9 +210,9 @@ void git_buf_consume(git_buf *buf, const char *end) ...@@ -205,9 +210,9 @@ void git_buf_consume(git_buf *buf, const char *end)
} }
} }
void git_buf_truncate(git_buf *buf, ssize_t len) void git_buf_truncate(git_buf *buf, size_t len)
{ {
if (len >= 0 && len < buf->size) { if (len < buf->size) {
buf->size = len; buf->size = len;
buf->ptr[buf->size] = '\0'; buf->ptr[buf->size] = '\0';
} }
...@@ -238,7 +243,7 @@ char *git_buf_detach(git_buf *buf) ...@@ -238,7 +243,7 @@ char *git_buf_detach(git_buf *buf)
return data; return data;
} }
void git_buf_attach(git_buf *buf, char *ptr, ssize_t asize) void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
{ {
git_buf_free(buf); git_buf_free(buf);
...@@ -372,3 +377,13 @@ int git_buf_join( ...@@ -372,3 +377,13 @@ int git_buf_join(
return error; return error;
} }
void git_buf_rtrim(git_buf *buf)
{
while (buf->size > 0) {
if (!isspace(buf->ptr[buf->size - 1]))
break;
buf->size--;
}
}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
typedef struct { typedef struct {
char *ptr; char *ptr;
ssize_t asize, size; size_t asize, size;
} git_buf; } git_buf;
extern char git_buf_initbuf[]; extern char git_buf_initbuf[];
...@@ -47,7 +47,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size); ...@@ -47,7 +47,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size);
void git_buf_free(git_buf *buf); void git_buf_free(git_buf *buf);
void git_buf_swap(git_buf *buf_a, git_buf *buf_b); void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
char *git_buf_detach(git_buf *buf); char *git_buf_detach(git_buf *buf);
void git_buf_attach(git_buf *buf, char *ptr, ssize_t asize); void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
/** /**
* Test if there have been any reallocation failures with this git_buf. * Test if there have been any reallocation failures with this git_buf.
...@@ -83,7 +83,7 @@ int git_buf_puts(git_buf *buf, const char *string); ...@@ -83,7 +83,7 @@ int git_buf_puts(git_buf *buf, const char *string);
int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); int git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
void git_buf_clear(git_buf *buf); void git_buf_clear(git_buf *buf);
void git_buf_consume(git_buf *buf, const char *end); void git_buf_consume(git_buf *buf, const char *end);
void git_buf_truncate(git_buf *buf, ssize_t len); void git_buf_truncate(git_buf *buf, size_t len);
void git_buf_rtruncate_at_char(git_buf *path, char separator); void git_buf_rtruncate_at_char(git_buf *path, char separator);
int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...); int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...);
...@@ -115,4 +115,7 @@ GIT_INLINE(int) git_buf_rfind_next(git_buf *buf, char ch) ...@@ -115,4 +115,7 @@ GIT_INLINE(int) git_buf_rfind_next(git_buf *buf, char ch)
return idx; return idx;
} }
/* Remove whitespace from the end of the buffer */
void git_buf_rtrim(git_buf *buf);
#endif #endif
...@@ -73,7 +73,7 @@ typedef struct { ...@@ -73,7 +73,7 @@ typedef struct {
git_hashtable *values; git_hashtable *values;
struct { struct {
git_fbuffer buffer; git_buf buffer;
char *read_ptr; char *read_ptr;
int line_number; int line_number;
int eof; int eof;
...@@ -151,6 +151,7 @@ static int config_open(git_config_file *cfg) ...@@ -151,6 +151,7 @@ static int config_open(git_config_file *cfg)
if (b->values == NULL) if (b->values == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
git_buf_init(&b->reader.buffer, 0);
error = git_futils_readbuffer(&b->reader.buffer, b->file_path); error = git_futils_readbuffer(&b->reader.buffer, b->file_path);
/* It's fine if the file doesn't exist */ /* It's fine if the file doesn't exist */
...@@ -164,14 +165,14 @@ static int config_open(git_config_file *cfg) ...@@ -164,14 +165,14 @@ static int config_open(git_config_file *cfg)
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
git_futils_freebuffer(&b->reader.buffer); git_buf_free(&b->reader.buffer);
return GIT_SUCCESS; return GIT_SUCCESS;
cleanup: cleanup:
free_vars(b->values); free_vars(b->values);
b->values = NULL; b->values = NULL;
git_futils_freebuffer(&b->reader.buffer); git_buf_free(&b->reader.buffer);
return git__rethrow(error, "Failed to open config"); return git__rethrow(error, "Failed to open config");
} }
...@@ -765,7 +766,7 @@ static int skip_bom(diskfile_backend *cfg) ...@@ -765,7 +766,7 @@ static int skip_bom(diskfile_backend *cfg)
{ {
static const char utf8_bom[] = "\xef\xbb\xbf"; static const char utf8_bom[] = "\xef\xbb\xbf";
if (cfg->reader.buffer.len < sizeof(utf8_bom)) if (cfg->reader.buffer.size < sizeof(utf8_bom))
return GIT_SUCCESS; return GIT_SUCCESS;
if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0) if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0)
...@@ -847,7 +848,7 @@ static int config_parse(diskfile_backend *cfg_file) ...@@ -847,7 +848,7 @@ static int config_parse(diskfile_backend *cfg_file)
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
/* Initialize the reading position */ /* Initialize the reading position */
cfg_file->reader.read_ptr = cfg_file->reader.buffer.data; cfg_file->reader.read_ptr = cfg_file->reader.buffer.ptr;
cfg_file->reader.eof = 0; cfg_file->reader.eof = 0;
/* If the file is empty, there's nothing for us to do */ /* If the file is empty, there's nothing for us to do */
...@@ -976,10 +977,9 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p ...@@ -976,10 +977,9 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
cfg->reader.read_ptr = NULL; cfg->reader.read_ptr = NULL;
cfg->reader.eof = 1; cfg->reader.eof = 1;
data_start = NULL; data_start = NULL;
cfg->reader.buffer.len = 0; git_buf_clear(&cfg->reader.buffer);
cfg->reader.buffer.data = NULL;
} else { } else {
cfg->reader.read_ptr = cfg->reader.buffer.data; cfg->reader.read_ptr = cfg->reader.buffer.ptr;
cfg->reader.eof = 0; cfg->reader.eof = 0;
data_start = cfg->reader.read_ptr; data_start = cfg->reader.read_ptr;
} }
...@@ -1093,7 +1093,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p ...@@ -1093,7 +1093,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
/* And then the write out rest of the file */ /* And then the write out rest of the file */
error = git_filebuf_write(&file, post_start, error = git_filebuf_write(&file, post_start,
cfg->reader.buffer.len - (post_start - data_start)); cfg->reader.buffer.size - (post_start - data_start));
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to write the rest of the file"); git__rethrow(error, "Failed to write the rest of the file");
...@@ -1128,7 +1128,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p ...@@ -1128,7 +1128,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
goto cleanup; goto cleanup;
} }
error = git_filebuf_write(&file, cfg->reader.buffer.data, cfg->reader.buffer.len); error = git_filebuf_write(&file, cfg->reader.buffer.ptr, cfg->reader.buffer.size);
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to write original config content"); git__rethrow(error, "Failed to write original config content");
goto cleanup; goto cleanup;
...@@ -1155,7 +1155,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p ...@@ -1155,7 +1155,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
else else
error = git_filebuf_commit(&file, GIT_CONFIG_FILE_MODE); error = git_filebuf_commit(&file, GIT_CONFIG_FILE_MODE);
git_futils_freebuffer(&cfg->reader.buffer); git_buf_free(&cfg->reader.buffer);
return error; return error;
} }
......
...@@ -97,87 +97,77 @@ mode_t git_futils_canonical_mode(mode_t raw_mode) ...@@ -97,87 +97,77 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
return 0; return 0;
} }
int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated) int git_futils_readbuffer_updated(git_buf *buf, const char *path, time_t *mtime, int *updated)
{ {
git_file fd; git_file fd;
size_t len; size_t len;
struct stat st; struct stat st;
unsigned char *buff;
assert(obj && path && *path); assert(buf && path && *path);
if (updated != NULL) if (updated != NULL)
*updated = 0; *updated = 0;
if (p_stat(path, &st) < 0) if ((fd = p_open(path, O_RDONLY)) < 0) {
return git__throw(GIT_ENOTFOUND, "Failed to stat file %s", path); return git__throw(GIT_ENOTFOUND, "Failed to read file '%s': %s", path, strerror(errno));
}
if (S_ISDIR(st.st_mode)) if (p_fstat(fd, &st) < 0 || S_ISDIR(st.st_mode) || !git__is_sizet(st.st_size+1)) {
return git__throw(GIT_ERROR, "Can't read a dir into a buffer"); close(fd);
return git__throw(GIT_EOSERR, "Failed to stat file '%s'", path);
}
/* /*
* If we were given a time, we only want to read the file if it * If we were given a time, we only want to read the file if it
* has been modified. * has been modified.
*/ */
if (mtime != NULL && *mtime >= st.st_mtime) if (mtime != NULL && *mtime >= st.st_mtime) {
return GIT_SUCCESS; close(fd);
return 0;
}
if (mtime != NULL) if (mtime != NULL)
*mtime = st.st_mtime; *mtime = st.st_mtime;
if (!git__is_sizet(st.st_size+1))
return git__throw(GIT_ERROR, "Failed to read file `%s`. An error occured while calculating its size", path);
len = (size_t) st.st_size; len = (size_t) st.st_size;
if ((fd = p_open(path, O_RDONLY)) < 0) git_buf_clear(buf);
return git__throw(GIT_EOSERR, "Failed to open %s for reading", path);
if ((buff = git__malloc(len + 1)) == NULL) { if (git_buf_grow(buf, len + 1) < 0) {
p_close(fd); close(fd);
return GIT_ENOMEM; return GIT_ENOMEM;
} }
if (p_read(fd, buff, len) < 0) { buf->ptr[len] = '\0';
p_close(fd);
git__free(buff); while (len > 0) {
return git__throw(GIT_ERROR, "Failed to read file `%s`", path); ssize_t read_size = p_read(fd, buf->ptr, len);
if (read_size < 0) {
close(fd);
return git__throw(GIT_EOSERR, "Failed to read from FD");
}
len -= read_size;
buf->size += read_size;
} }
buff[len] = '\0';
p_close(fd); p_close(fd);
if (mtime != NULL) if (mtime != NULL)
*mtime = st.st_mtime; *mtime = st.st_mtime;
if (updated != NULL) if (updated != NULL)
*updated = 1; *updated = 1;
obj->data = buff; return 0;
obj->len = len;
return GIT_SUCCESS;
}
int git_futils_readbuffer(git_fbuffer *obj, const char *path)
{
return git_futils_readbuffer_updated(obj, path, NULL, NULL);
}
void git_futils_fbuffer_rtrim(git_fbuffer *obj)
{
unsigned char *buff = obj->data;
while (obj->len > 0 && isspace(buff[obj->len - 1]))
obj->len--;
buff[obj->len] = '\0';
} }
void git_futils_freebuffer(git_fbuffer *obj) int git_futils_readbuffer(git_buf *buf, const char *path)
{ {
assert(obj); return git_futils_readbuffer_updated(buf, path, NULL, NULL);
git__free(obj->data);
obj->data = NULL;
} }
int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode) int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
{ {
if (git_futils_mkpath2file(to, dirmode) < GIT_SUCCESS) if (git_futils_mkpath2file(to, dirmode) < GIT_SUCCESS)
......
...@@ -17,17 +17,8 @@ ...@@ -17,17 +17,8 @@
* *
* Read whole files into an in-memory buffer for processing * Read whole files into an in-memory buffer for processing
*/ */
#define GIT_FBUFFER_INIT {NULL, 0} extern int git_futils_readbuffer(git_buf *obj, const char *path);
extern int git_futils_readbuffer_updated(git_buf *obj, const char *path, time_t *mtime, int *updated);
typedef struct { /* file io buffer */
void *data; /* data bytes */
size_t len; /* data length */
} git_fbuffer;
extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
extern int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated);
extern void git_futils_freebuffer(git_fbuffer *obj);
extern void git_futils_fbuffer_rtrim(git_fbuffer *obj);
/** /**
* File utils * File utils
......
...@@ -11,7 +11,7 @@ static int load_ignore_file( ...@@ -11,7 +11,7 @@ static int load_ignore_file(
git_repository *repo, const char *path, git_attr_file *ignores) git_repository *repo, const char *path, git_attr_file *ignores)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
git_fbuffer fbuf = GIT_FBUFFER_INIT; git_buf fbuf = GIT_BUF_INIT;
git_attr_fnmatch *match = NULL; git_attr_fnmatch *match = NULL;
const char *scan = NULL; const char *scan = NULL;
char *context = NULL; char *context = NULL;
...@@ -28,7 +28,7 @@ static int load_ignore_file( ...@@ -28,7 +28,7 @@ static int load_ignore_file(
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
error = git_futils_readbuffer(&fbuf, path); error = git_futils_readbuffer(&fbuf, path);
scan = fbuf.data; scan = fbuf.ptr;
while (error == GIT_SUCCESS && *scan) { while (error == GIT_SUCCESS && *scan) {
if (!match && !(match = git__calloc(1, sizeof(git_attr_fnmatch)))) { if (!match && !(match = git__calloc(1, sizeof(git_attr_fnmatch)))) {
...@@ -53,7 +53,7 @@ static int load_ignore_file( ...@@ -53,7 +53,7 @@ static int load_ignore_file(
} }
} }
git_futils_freebuffer(&fbuf); git_buf_free(&fbuf);
git__free(match); git__free(match);
git__free(context); git__free(context);
......
...@@ -216,7 +216,7 @@ void git_index_clear(git_index *index) ...@@ -216,7 +216,7 @@ void git_index_clear(git_index *index)
int git_index_read(git_index *index) int git_index_read(git_index *index)
{ {
int error = GIT_SUCCESS, updated; int error = GIT_SUCCESS, updated;
git_fbuffer buffer = GIT_FBUFFER_INIT; git_buf buffer = GIT_BUF_INIT;
time_t mtime; time_t mtime;
assert(index->index_file_path); assert(index->index_file_path);
...@@ -235,12 +235,12 @@ int git_index_read(git_index *index) ...@@ -235,12 +235,12 @@ int git_index_read(git_index *index)
if (updated) { if (updated) {
git_index_clear(index); git_index_clear(index);
error = parse_index(index, buffer.data, buffer.len); error = parse_index(index, buffer.ptr, buffer.size);
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
index->last_modified = mtime; index->last_modified = mtime;
git_futils_freebuffer(&buffer); git_buf_free(&buffer);
} }
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
......
...@@ -393,8 +393,8 @@ static int add_default_backends(git_odb *db, const char *objects_dir, int as_alt ...@@ -393,8 +393,8 @@ static int add_default_backends(git_odb *db, const char *objects_dir, int as_alt
static int load_alternates(git_odb *odb, const char *objects_dir) static int load_alternates(git_odb *odb, const char *objects_dir)
{ {
git_buf alternates_path = GIT_BUF_INIT; git_buf alternates_path = GIT_BUF_INIT;
git_buf alternates_buf = GIT_BUF_INIT;
char *buffer; char *buffer;
git_fbuffer alternates_buf = GIT_FBUFFER_INIT;
const char *alternate; const char *alternate;
int error; int error;
...@@ -412,7 +412,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir) ...@@ -412,7 +412,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates"); return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates");
} }
buffer = (char *)alternates_buf.data; buffer = (char *)alternates_buf.ptr;
error = GIT_SUCCESS; error = GIT_SUCCESS;
/* add each alternate as a new backend; one alternate per line */ /* add each alternate as a new backend; one alternate per line */
...@@ -433,7 +433,8 @@ static int load_alternates(git_odb *odb, const char *objects_dir) ...@@ -433,7 +433,8 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
} }
git_buf_free(&alternates_path); git_buf_free(&alternates_path);
git_futils_freebuffer(&alternates_buf); git_buf_free(&alternates_buf);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to load alternates"); return git__rethrow(error, "Failed to load alternates");
return error; return error;
......
...@@ -75,13 +75,13 @@ static int object_file_name(git_buf *name, const char *dir, const git_oid *id) ...@@ -75,13 +75,13 @@ static int object_file_name(git_buf *name, const char *dir, const git_oid *id)
} }
static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj) static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
{ {
unsigned char c; unsigned char c;
unsigned char *data = obj->data; unsigned char *data = (unsigned char *)obj->ptr;
size_t shift, size, used = 0; size_t shift, size, used = 0;
if (obj->len == 0) if (obj->size == 0)
return 0; return 0;
c = data[used++]; c = data[used++];
...@@ -90,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj) ...@@ -90,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
size = c & 15; size = c & 15;
shift = 4; shift = 4;
while (c & 0x80) { while (c & 0x80) {
if (obj->len <= used) if (obj->size <= used)
return 0; return 0;
if (sizeof(size_t) * 8 <= shift) if (sizeof(size_t) * 8 <= shift)
return 0; return 0;
...@@ -177,12 +177,12 @@ static void set_stream_output(z_stream *s, void *out, size_t len) ...@@ -177,12 +177,12 @@ static void set_stream_output(z_stream *s, void *out, size_t len)
} }
static int start_inflate(z_stream *s, git_fbuffer *obj, void *out, size_t len) static int start_inflate(z_stream *s, git_buf *obj, void *out, size_t len)
{ {
int status; int status;
init_stream(s, out, len); init_stream(s, out, len);
set_stream_input(s, obj->data, obj->len); set_stream_input(s, obj->ptr, obj->size);
if ((status = inflateInit(s)) < Z_OK) if ((status = inflateInit(s)) < Z_OK)
return status; return status;
...@@ -287,7 +287,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr) ...@@ -287,7 +287,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
* of loose object data into packs. This format is no longer used, but * of loose object data into packs. This format is no longer used, but
* we must still read it. * we must still read it.
*/ */
static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_buf *obj)
{ {
unsigned char *in, *buf; unsigned char *in, *buf;
obj_hdr hdr; obj_hdr hdr;
...@@ -310,8 +310,8 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -310,8 +310,8 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
if (!buf) if (!buf)
return GIT_ENOMEM; return GIT_ENOMEM;
in = ((unsigned char *)obj->data) + used; in = ((unsigned char *)obj->ptr) + used;
len = obj->len - used; len = obj->size - used;
if (inflate_buffer(in, len, buf, hdr.size)) { if (inflate_buffer(in, len, buf, hdr.size)) {
git__free(buf); git__free(buf);
return git__throw(GIT_ERROR, "Failed to inflate loose object. Could not inflate buffer"); return git__throw(GIT_ERROR, "Failed to inflate loose object. Could not inflate buffer");
...@@ -325,7 +325,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -325,7 +325,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) static int inflate_disk_obj(git_rawobj *out, git_buf *obj)
{ {
unsigned char head[64], *buf; unsigned char head[64], *buf;
z_stream zs; z_stream zs;
...@@ -335,7 +335,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -335,7 +335,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
/* /*
* check for a pack-like loose object * check for a pack-like loose object
*/ */
if (!is_zlib_compressed_data(obj->data)) if (!is_zlib_compressed_data((unsigned char *)obj->ptr))
return inflate_packlike_loose_disk_obj(out, obj); return inflate_packlike_loose_disk_obj(out, obj);
/* /*
...@@ -383,7 +383,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -383,7 +383,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
static int read_loose(git_rawobj *out, git_buf *loc) static int read_loose(git_rawobj *out, git_buf *loc)
{ {
int error; int error;
git_fbuffer obj = GIT_FBUFFER_INIT; git_buf obj = GIT_BUF_INIT;
assert(out && loc); assert(out && loc);
...@@ -398,7 +398,7 @@ static int read_loose(git_rawobj *out, git_buf *loc) ...@@ -398,7 +398,7 @@ static int read_loose(git_rawobj *out, git_buf *loc)
return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found"); return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found");
error = inflate_disk_obj(out, &obj); error = inflate_disk_obj(out, &obj);
git_futils_freebuffer(&obj); git_buf_free(&obj);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object"); return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object");
} }
......
...@@ -183,7 +183,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) ...@@ -183,7 +183,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
{ {
int error; int error;
git_buf log_path = GIT_BUF_INIT; git_buf log_path = GIT_BUF_INIT;
git_fbuffer log_file = GIT_FBUFFER_INIT; git_buf log_file = GIT_BUF_INIT;
git_reflog *log = NULL; git_reflog *log = NULL;
*reflog = NULL; *reflog = NULL;
...@@ -201,7 +201,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) ...@@ -201,7 +201,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
goto cleanup; goto cleanup;
} }
if ((error = reflog_parse(log, log_file.data, log_file.len)) < GIT_SUCCESS) if ((error = reflog_parse(log, log_file.ptr, log_file.size)) < GIT_SUCCESS)
git__rethrow(error, "Failed to read reflog"); git__rethrow(error, "Failed to read reflog");
else else
*reflog = log; *reflog = log;
...@@ -209,7 +209,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) ...@@ -209,7 +209,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
cleanup: cleanup:
if (error != GIT_SUCCESS && log != NULL) if (error != GIT_SUCCESS && log != NULL)
git_reflog_free(log); git_reflog_free(log);
git_futils_freebuffer(&log_file); git_buf_free(&log_file);
git_buf_free(&log_path); git_buf_free(&log_path);
return error; return error;
......
...@@ -32,15 +32,15 @@ struct packref { ...@@ -32,15 +32,15 @@ struct packref {
static const int default_table_size = 32; static const int default_table_size = 32;
static int reference_read( static int reference_read(
git_fbuffer *file_content, git_buf *file_content,
time_t *mtime, time_t *mtime,
const char *repo_path, const char *repo_path,
const char *ref_name, const char *ref_name,
int *updated); int *updated);
/* loose refs */ /* loose refs */
static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content); static int loose_parse_symbolic(git_reference *ref, git_buf *file_content);
static int loose_parse_oid(git_oid *ref, git_fbuffer *file_content); static int loose_parse_oid(git_oid *ref, git_buf *file_content);
static int loose_lookup(git_reference *ref); static int loose_lookup(git_reference *ref);
static int loose_lookup_to_packfile(struct packref **ref_out, static int loose_lookup_to_packfile(struct packref **ref_out,
git_repository *repo, const char *name); git_repository *repo, const char *name);
...@@ -113,7 +113,7 @@ static int reference_alloc( ...@@ -113,7 +113,7 @@ static int reference_alloc(
return GIT_SUCCESS; return GIT_SUCCESS;
} }
static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *repo_path, const char *ref_name, int *updated) static int reference_read(git_buf *file_content, time_t *mtime, const char *repo_path, const char *ref_name, int *updated)
{ {
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
...@@ -129,15 +129,15 @@ static int reference_read(git_fbuffer *file_content, time_t *mtime, const char * ...@@ -129,15 +129,15 @@ static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *
return error; return error;
} }
static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content) static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
{ {
const unsigned int header_len = strlen(GIT_SYMREF); const unsigned int header_len = strlen(GIT_SYMREF);
const char *refname_start; const char *refname_start;
char *eol; char *eol;
refname_start = (const char *)file_content->data; refname_start = (const char *)file_content->ptr;
if (file_content->len < (header_len + 1)) if (file_content->size < (header_len + 1))
return git__throw(GIT_EOBJCORRUPTED, return git__throw(GIT_EOBJCORRUPTED,
"Failed to parse loose reference. Object too short"); "Failed to parse loose reference. Object too short");
...@@ -165,15 +165,15 @@ static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content) ...@@ -165,15 +165,15 @@ static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
static int loose_parse_oid(git_oid *oid, git_fbuffer *file_content) static int loose_parse_oid(git_oid *oid, git_buf *file_content)
{ {
int error; int error;
char *buffer; char *buffer;
buffer = (char *)file_content->data; buffer = (char *)file_content->ptr;
/* File format: 40 chars (OID) + newline */ /* File format: 40 chars (OID) + newline */
if (file_content->len < GIT_OID_HEXSZ + 1) if (file_content->size < GIT_OID_HEXSZ + 1)
return git__throw(GIT_EOBJCORRUPTED, return git__throw(GIT_EOBJCORRUPTED,
"Failed to parse loose reference. Reference too short"); "Failed to parse loose reference. Reference too short");
...@@ -193,26 +193,26 @@ static int loose_parse_oid(git_oid *oid, git_fbuffer *file_content) ...@@ -193,26 +193,26 @@ static int loose_parse_oid(git_oid *oid, git_fbuffer *file_content)
static git_rtype loose_guess_rtype(const git_buf *full_path) static git_rtype loose_guess_rtype(const git_buf *full_path)
{ {
git_fbuffer ref_file = GIT_FBUFFER_INIT; git_buf ref_file = GIT_BUF_INIT;
git_rtype type; git_rtype type;
type = GIT_REF_INVALID; type = GIT_REF_INVALID;
if (git_futils_readbuffer(&ref_file, full_path->ptr) == GIT_SUCCESS) { if (git_futils_readbuffer(&ref_file, full_path->ptr) == GIT_SUCCESS) {
if (git__prefixcmp((const char *)(ref_file.data), GIT_SYMREF) == 0) if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0)
type = GIT_REF_SYMBOLIC; type = GIT_REF_SYMBOLIC;
else else
type = GIT_REF_OID; type = GIT_REF_OID;
} }
git_futils_freebuffer(&ref_file); git_buf_free(&ref_file);
return type; return type;
} }
static int loose_lookup(git_reference *ref) static int loose_lookup(git_reference *ref)
{ {
int error = GIT_SUCCESS, updated; int error = GIT_SUCCESS, updated;
git_fbuffer ref_file = GIT_FBUFFER_INIT; git_buf ref_file = GIT_BUF_INIT;
if (reference_read(&ref_file, &ref->mtime, if (reference_read(&ref_file, &ref->mtime,
ref->owner->path_repository, ref->name, &updated) < GIT_SUCCESS) ref->owner->path_repository, ref->name, &updated) < GIT_SUCCESS)
...@@ -228,7 +228,7 @@ static int loose_lookup(git_reference *ref) ...@@ -228,7 +228,7 @@ static int loose_lookup(git_reference *ref)
ref->flags = 0; ref->flags = 0;
if (git__prefixcmp((const char *)(ref_file.data), GIT_SYMREF) == 0) { if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0) {
ref->flags |= GIT_REF_SYMBOLIC; ref->flags |= GIT_REF_SYMBOLIC;
error = loose_parse_symbolic(ref, &ref_file); error = loose_parse_symbolic(ref, &ref_file);
} else { } else {
...@@ -236,7 +236,7 @@ static int loose_lookup(git_reference *ref) ...@@ -236,7 +236,7 @@ static int loose_lookup(git_reference *ref)
error = loose_parse_oid(&ref->target.oid, &ref_file); error = loose_parse_oid(&ref->target.oid, &ref_file);
} }
git_futils_freebuffer(&ref_file); git_buf_free(&ref_file);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to lookup loose reference"); return git__rethrow(error, "Failed to lookup loose reference");
...@@ -250,7 +250,7 @@ static int loose_lookup_to_packfile( ...@@ -250,7 +250,7 @@ static int loose_lookup_to_packfile(
const char *name) const char *name)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
git_fbuffer ref_file = GIT_FBUFFER_INIT; git_buf ref_file = GIT_BUF_INIT;
struct packref *ref = NULL; struct packref *ref = NULL;
size_t name_len; size_t name_len;
...@@ -273,11 +273,11 @@ static int loose_lookup_to_packfile( ...@@ -273,11 +273,11 @@ static int loose_lookup_to_packfile(
ref->flags = GIT_PACKREF_WAS_LOOSE; ref->flags = GIT_PACKREF_WAS_LOOSE;
*ref_out = ref; *ref_out = ref;
git_futils_freebuffer(&ref_file); git_buf_free(&ref_file);
return GIT_SUCCESS; return GIT_SUCCESS;
cleanup: cleanup:
git_futils_freebuffer(&ref_file); git_buf_free(&ref_file);
free(ref); free(ref);
return git__rethrow(error, "Failed to lookup loose reference"); return git__rethrow(error, "Failed to lookup loose reference");
} }
...@@ -427,7 +427,7 @@ cleanup: ...@@ -427,7 +427,7 @@ cleanup:
static int packed_load(git_repository *repo) static int packed_load(git_repository *repo)
{ {
int error = GIT_SUCCESS, updated; int error = GIT_SUCCESS, updated;
git_fbuffer packfile = GIT_FBUFFER_INIT; git_buf packfile = GIT_BUF_INIT;
const char *buffer_start, *buffer_end; const char *buffer_start, *buffer_end;
git_refcache *ref_cache = &repo->references; git_refcache *ref_cache = &repo->references;
...@@ -468,8 +468,8 @@ static int packed_load(git_repository *repo) ...@@ -468,8 +468,8 @@ static int packed_load(git_repository *repo)
git_hashtable_clear(ref_cache->packfile); git_hashtable_clear(ref_cache->packfile);
buffer_start = (const char *)packfile.data; buffer_start = (const char *)packfile.ptr;
buffer_end = (const char *)(buffer_start) + packfile.len; buffer_end = (const char *)(buffer_start) + packfile.size;
while (buffer_start < buffer_end && buffer_start[0] == '#') { while (buffer_start < buffer_end && buffer_start[0] == '#') {
buffer_start = strchr(buffer_start, '\n'); buffer_start = strchr(buffer_start, '\n');
...@@ -500,13 +500,13 @@ static int packed_load(git_repository *repo) ...@@ -500,13 +500,13 @@ static int packed_load(git_repository *repo)
} }
} }
git_futils_freebuffer(&packfile); git_buf_free(&packfile);
return GIT_SUCCESS; return GIT_SUCCESS;
cleanup: cleanup:
git_hashtable_free(ref_cache->packfile); git_hashtable_free(ref_cache->packfile);
ref_cache->packfile = NULL; ref_cache->packfile = NULL;
git_futils_freebuffer(&packfile); git_buf_free(&packfile);
return git__rethrow(error, "Failed to load packed references"); return git__rethrow(error, "Failed to load packed references");
} }
......
...@@ -467,7 +467,7 @@ static int retrieve_ceiling_directories_offset( ...@@ -467,7 +467,7 @@ static int retrieve_ceiling_directories_offset(
*/ */
static int read_gitfile(git_buf *path_out, const char *file_path, const char *base_path) static int read_gitfile(git_buf *path_out, const char *file_path, const char *base_path)
{ {
git_fbuffer file; git_buf file = GIT_BUF_INIT;
int error; int error;
assert(path_out && file_path); assert(path_out && file_path);
...@@ -476,22 +476,22 @@ static int read_gitfile(git_buf *path_out, const char *file_path, const char *ba ...@@ -476,22 +476,22 @@ static int read_gitfile(git_buf *path_out, const char *file_path, const char *ba
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
if (git__prefixcmp((char *)file.data, GIT_FILE_CONTENT_PREFIX)) { if (git__prefixcmp((char *)file.ptr, GIT_FILE_CONTENT_PREFIX)) {
git_futils_freebuffer(&file); git_buf_free(&file);
return git__throw(GIT_ENOTFOUND, "Invalid gitfile format `%s`", file_path); return git__throw(GIT_ENOTFOUND, "Invalid gitfile format `%s`", file_path);
} }
git_futils_fbuffer_rtrim(&file); git_buf_rtrim(&file);
if (strlen(GIT_FILE_CONTENT_PREFIX) == file.len) { if (strlen(GIT_FILE_CONTENT_PREFIX) == file.size) {
git_futils_freebuffer(&file); git_buf_free(&file);
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path); return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
} }
error = git_path_prettify_dir(path_out, error = git_path_prettify_dir(path_out,
((char *)file.data) + strlen(GIT_FILE_CONTENT_PREFIX), base_path); ((char *)file.ptr) + strlen(GIT_FILE_CONTENT_PREFIX), base_path);
git_futils_freebuffer(&file); git_buf_free(&file);
if (error == GIT_SUCCESS && git_path_exists(path_out->ptr) == 0) if (error == GIT_SUCCESS && git_path_exists(path_out->ptr) == 0)
return GIT_SUCCESS; return GIT_SUCCESS;
......
...@@ -218,8 +218,8 @@ check_buf_append( ...@@ -218,8 +218,8 @@ check_buf_append(
const char* data_a, const char* data_a,
const char* data_b, const char* data_b,
const char* expected_data, const char* expected_data,
ssize_t expected_size, size_t expected_size,
ssize_t expected_asize) size_t expected_asize)
{ {
git_buf tgt = GIT_BUF_INIT; git_buf tgt = GIT_BUF_INIT;
...@@ -371,8 +371,8 @@ void test_core_buffer__7(void) ...@@ -371,8 +371,8 @@ void test_core_buffer__7(void)
git_buf_attach(&a, b, 0); git_buf_attach(&a, b, 0);
cl_assert_strequal(fun, a.ptr); cl_assert_strequal(fun, a.ptr);
cl_assert(a.size == (ssize_t)strlen(fun)); cl_assert(a.size == strlen(fun));
cl_assert(a.asize == (ssize_t)strlen(fun) + 1); cl_assert(a.asize == strlen(fun) + 1);
git_buf_free(&a); git_buf_free(&a);
...@@ -380,8 +380,8 @@ void test_core_buffer__7(void) ...@@ -380,8 +380,8 @@ void test_core_buffer__7(void)
git_buf_attach(&a, b, strlen(fun) + 1); git_buf_attach(&a, b, strlen(fun) + 1);
cl_assert_strequal(fun, a.ptr); cl_assert_strequal(fun, a.ptr);
cl_assert(a.size == (ssize_t)strlen(fun)); cl_assert(a.size == strlen(fun));
cl_assert(a.asize == (ssize_t)strlen(fun) + 1); cl_assert(a.asize == strlen(fun) + 1);
git_buf_free(&a); git_buf_free(&a);
} }
......
...@@ -243,7 +243,7 @@ void test_core_path__07_path_to_dir(void) ...@@ -243,7 +243,7 @@ void test_core_path__07_path_to_dir(void)
void test_core_path__08_self_join(void) void test_core_path__08_self_join(void)
{ {
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
ssize_t asize = 0; size_t asize = 0;
asize = path.asize; asize = path.asize;
cl_git_pass(git_buf_sets(&path, "/foo")); cl_git_pass(git_buf_sets(&path, "/foo"));
......
...@@ -182,7 +182,7 @@ int cmp_objects(git_rawobj *o, object_data *d) ...@@ -182,7 +182,7 @@ int cmp_objects(git_rawobj *o, object_data *d)
int copy_file(const char *src, const char *dst) int copy_file(const char *src, const char *dst)
{ {
git_fbuffer source_buf; git_buf source_buf = GIT_BUF_INIT;
git_file dst_fd; git_file dst_fd;
int error = GIT_ERROR; int error = GIT_ERROR;
...@@ -193,10 +193,10 @@ int copy_file(const char *src, const char *dst) ...@@ -193,10 +193,10 @@ int copy_file(const char *src, const char *dst)
if (dst_fd < 0) if (dst_fd < 0)
goto cleanup; goto cleanup;
error = p_write(dst_fd, source_buf.data, source_buf.len); error = p_write(dst_fd, source_buf.ptr, source_buf.size);
cleanup: cleanup:
git_futils_freebuffer(&source_buf); git_buf_free(&source_buf);
p_close(dst_fd); p_close(dst_fd);
return error; return error;
...@@ -204,22 +204,23 @@ cleanup: ...@@ -204,22 +204,23 @@ cleanup:
int cmp_files(const char *a, const char *b) int cmp_files(const char *a, const char *b)
{ {
git_fbuffer buf_a, buf_b; git_buf buf_a = GIT_BUF_INIT;
git_buf buf_b = GIT_BUF_INIT;
int error = GIT_ERROR; int error = GIT_ERROR;
if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS) if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) { if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) {
git_futils_freebuffer(&buf_a); git_buf_free(&buf_a);
return GIT_ERROR; return GIT_ERROR;
} }
if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len)) if (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size))
error = GIT_SUCCESS; error = GIT_SUCCESS;
git_futils_freebuffer(&buf_a); git_buf_free(&buf_a);
git_futils_freebuffer(&buf_b); git_buf_free(&buf_b);
return error; return error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment