summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-02-27 04:28:31 +0100
committerVicent Martí <tanoku@gmail.com>2012-02-27 05:30:07 +0100
commit13224ea4aad9a1b3c9cc4c992ceaea9af623e047 (patch)
treeb5c3a503d1ef7ba6269bf4291530c4e8e5936bdb /src
parente07c2d225deec42e592133df49ad8c564d4d66c7 (diff)
downloadlibgit2-13224ea4aad9a1b3c9cc4c992ceaea9af623e047.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/attr_file.c6
-rw-r--r--src/buffer.c45
-rw-r--r--src/buffer.h9
-rw-r--r--src/config_file.c22
-rw-r--r--src/fileops.c74
-rw-r--r--src/fileops.h13
-rw-r--r--src/ignore.c6
-rw-r--r--src/index.c6
-rw-r--r--src/odb.c7
-rw-r--r--src/odb_loose.c26
-rw-r--r--src/reflog.c6
-rw-r--r--src/refs.c48
-rw-r--r--src/repository.c16
13 files changed, 142 insertions, 142 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 7911381ea..a1b69a5bb 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -111,7 +111,7 @@ int git_attr_file__from_file(
git_repository *repo, const char *path, git_attr_file *file)
{
int error = GIT_SUCCESS;
- git_fbuffer fbuf = GIT_FBUFFER_INIT;
+ git_buf fbuf = GIT_BUF_INIT;
assert(path && file);
@@ -120,9 +120,9 @@ int git_attr_file__from_file(
if (error == 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)
git__rethrow(error, "Could not open attribute file '%s'", path);
diff --git a/src/buffer.c b/src/buffer.c
index 183da7c5f..b9f62cc30 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -7,14 +7,17 @@
#include "buffer.h"
#include "posix.h"
#include <stdarg.h>
+#include <ctype.h>
/* 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.
*/
char git_buf_initbuf[1];
+static char git_buf__oom;
+
#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;
@@ -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 error = git_buf_try_grow(buf, target_size);
- if (error != GIT_SUCCESS)
- buf->asize = -1;
+ if (error != GIT_SUCCESS) {
+ buf->ptr = &git_buf__oom;
+ }
+
return error;
}
@@ -41,17 +46,17 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
char *new_ptr;
size_t new_size;
- if (buf->asize < 0)
+ if (buf->ptr == &git_buf__oom)
return GIT_ENOMEM;
- if (target_size <= (size_t)buf->asize)
+ if (target_size <= buf->asize)
return GIT_SUCCESS;
if (buf->asize == 0) {
new_size = target_size;
new_ptr = NULL;
} else {
- new_size = (size_t)buf->asize;
+ new_size = buf->asize;
new_ptr = buf->ptr;
}
@@ -64,7 +69,6 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
new_size = (new_size + 7) & ~7;
new_ptr = git__realloc(new_ptr, new_size);
- /* if realloc fails, return without modifying the git_buf */
if (!new_ptr)
return GIT_ENOMEM;
@@ -83,7 +87,7 @@ void git_buf_free(git_buf *buf)
{
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_buf_init(buf, 0);
@@ -98,12 +102,12 @@ void git_buf_clear(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)
{
- 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)
@@ -162,11 +166,12 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
va_end(arglist);
if (len < 0) {
- buf->asize = -1;
+ free(buf->ptr);
+ buf->ptr = &git_buf__oom;
return GIT_ENOMEM;
}
- if (len + 1 <= buf->asize - buf->size) {
+ if ((size_t)len + 1 <= buf->asize - buf->size) {
buf->size += len;
break;
}
@@ -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->ptr[buf->size] = '\0';
}
@@ -238,7 +243,7 @@ char *git_buf_detach(git_buf *buf)
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);
@@ -372,3 +377,13 @@ int git_buf_join(
return error;
}
+
+void git_buf_rtrim(git_buf *buf)
+{
+ while (buf->size > 0) {
+ if (!isspace(buf->ptr[buf->size - 1]))
+ break;
+
+ buf->size--;
+ }
+}
diff --git a/src/buffer.h b/src/buffer.h
index 3969f461e..3e9cb1713 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -11,7 +11,7 @@
typedef struct {
char *ptr;
- ssize_t asize, size;
+ size_t asize, size;
} git_buf;
extern char git_buf_initbuf[];
@@ -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_swap(git_buf *buf_a, git_buf *buf_b);
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.
@@ -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);
void git_buf_clear(git_buf *buf);
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);
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)
return idx;
}
+/* Remove whitespace from the end of the buffer */
+void git_buf_rtrim(git_buf *buf);
+
#endif
diff --git a/src/config_file.c b/src/config_file.c
index c9c7d11eb..ce76493c7 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -73,7 +73,7 @@ typedef struct {
git_hashtable *values;
struct {
- git_fbuffer buffer;
+ git_buf buffer;
char *read_ptr;
int line_number;
int eof;
@@ -151,6 +151,7 @@ static int config_open(git_config_file *cfg)
if (b->values == NULL)
return GIT_ENOMEM;
+ git_buf_init(&b->reader.buffer, 0);
error = git_futils_readbuffer(&b->reader.buffer, b->file_path);
/* It's fine if the file doesn't exist */
@@ -164,14 +165,14 @@ static int config_open(git_config_file *cfg)
if (error < GIT_SUCCESS)
goto cleanup;
- git_futils_freebuffer(&b->reader.buffer);
+ git_buf_free(&b->reader.buffer);
return GIT_SUCCESS;
cleanup:
free_vars(b->values);
b->values = NULL;
- git_futils_freebuffer(&b->reader.buffer);
+ git_buf_free(&b->reader.buffer);
return git__rethrow(error, "Failed to open config");
}
@@ -765,7 +766,7 @@ static int skip_bom(diskfile_backend *cfg)
{
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;
if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0)
@@ -847,7 +848,7 @@ static int config_parse(diskfile_backend *cfg_file)
git_buf buf = GIT_BUF_INIT;
/* 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;
/* 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
cfg->reader.read_ptr = NULL;
cfg->reader.eof = 1;
data_start = NULL;
- cfg->reader.buffer.len = 0;
- cfg->reader.buffer.data = NULL;
+ git_buf_clear(&cfg->reader.buffer);
} else {
- cfg->reader.read_ptr = cfg->reader.buffer.data;
+ cfg->reader.read_ptr = cfg->reader.buffer.ptr;
cfg->reader.eof = 0;
data_start = cfg->reader.read_ptr;
}
@@ -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 */
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) {
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
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) {
git__rethrow(error, "Failed to write original config content");
goto cleanup;
@@ -1155,7 +1155,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
else
error = git_filebuf_commit(&file, GIT_CONFIG_FILE_MODE);
- git_futils_freebuffer(&cfg->reader.buffer);
+ git_buf_free(&cfg->reader.buffer);
return error;
}
diff --git a/src/fileops.c b/src/fileops.c
index 3241c68b1..d2b4af51e 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -97,87 +97,77 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
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;
size_t len;
struct stat st;
- unsigned char *buff;
- assert(obj && path && *path);
+ assert(buf && path && *path);
if (updated != NULL)
*updated = 0;
- if (p_stat(path, &st) < 0)
- return git__throw(GIT_ENOTFOUND, "Failed to stat file %s", path);
+ if ((fd = p_open(path, O_RDONLY)) < 0) {
+ return git__throw(GIT_ENOTFOUND, "Failed to read file '%s': %s", path, strerror(errno));
+ }
- if (S_ISDIR(st.st_mode))
- return git__throw(GIT_ERROR, "Can't read a dir into a buffer");
+ if (p_fstat(fd, &st) < 0 || S_ISDIR(st.st_mode) || !git__is_sizet(st.st_size+1)) {
+ 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
* has been modified.
*/
- if (mtime != NULL && *mtime >= st.st_mtime)
- return GIT_SUCCESS;
+ if (mtime != NULL && *mtime >= st.st_mtime) {
+ close(fd);
+ return 0;
+ }
if (mtime != NULL)
*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;
- if ((fd = p_open(path, O_RDONLY)) < 0)
- return git__throw(GIT_EOSERR, "Failed to open %s for reading", path);
+ git_buf_clear(buf);
- if ((buff = git__malloc(len + 1)) == NULL) {
- p_close(fd);
+ if (git_buf_grow(buf, len + 1) < 0) {
+ close(fd);
return GIT_ENOMEM;
}
- if (p_read(fd, buff, len) < 0) {
- p_close(fd);
- git__free(buff);
- return git__throw(GIT_ERROR, "Failed to read file `%s`", path);
+ buf->ptr[len] = '\0';
+
+ while (len > 0) {
+ 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);
if (mtime != NULL)
*mtime = st.st_mtime;
+
if (updated != NULL)
*updated = 1;
- obj->data = buff;
- 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);
+ return 0;
}
-void git_futils_fbuffer_rtrim(git_fbuffer *obj)
+int git_futils_readbuffer(git_buf *buf, const char *path)
{
- unsigned char *buff = obj->data;
- while (obj->len > 0 && isspace(buff[obj->len - 1]))
- obj->len--;
- buff[obj->len] = '\0';
+ return git_futils_readbuffer_updated(buf, path, NULL, NULL);
}
-void git_futils_freebuffer(git_fbuffer *obj)
-{
- assert(obj);
- git__free(obj->data);
- obj->data = NULL;
-}
-
-
int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
{
if (git_futils_mkpath2file(to, dirmode) < GIT_SUCCESS)
diff --git a/src/fileops.h b/src/fileops.h
index 4c114026b..43ef21521 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -17,17 +17,8 @@
*
* Read whole files into an in-memory buffer for processing
*/
-#define GIT_FBUFFER_INIT {NULL, 0}
-
-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);
+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);
/**
* File utils
diff --git a/src/ignore.c b/src/ignore.c
index 30f86b822..a3bf0a282 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -11,7 +11,7 @@ static int load_ignore_file(
git_repository *repo, const char *path, git_attr_file *ignores)
{
int error = GIT_SUCCESS;
- git_fbuffer fbuf = GIT_FBUFFER_INIT;
+ git_buf fbuf = GIT_BUF_INIT;
git_attr_fnmatch *match = NULL;
const char *scan = NULL;
char *context = NULL;
@@ -28,7 +28,7 @@ static int load_ignore_file(
if (error == GIT_SUCCESS)
error = git_futils_readbuffer(&fbuf, path);
- scan = fbuf.data;
+ scan = fbuf.ptr;
while (error == GIT_SUCCESS && *scan) {
if (!match && !(match = git__calloc(1, sizeof(git_attr_fnmatch)))) {
@@ -53,7 +53,7 @@ static int load_ignore_file(
}
}
- git_futils_freebuffer(&fbuf);
+ git_buf_free(&fbuf);
git__free(match);
git__free(context);
diff --git a/src/index.c b/src/index.c
index 4dccad527..5ac99de3e 100644
--- a/src/index.c
+++ b/src/index.c
@@ -216,7 +216,7 @@ void git_index_clear(git_index *index)
int git_index_read(git_index *index)
{
int error = GIT_SUCCESS, updated;
- git_fbuffer buffer = GIT_FBUFFER_INIT;
+ git_buf buffer = GIT_BUF_INIT;
time_t mtime;
assert(index->index_file_path);
@@ -235,12 +235,12 @@ int git_index_read(git_index *index)
if (updated) {
git_index_clear(index);
- error = parse_index(index, buffer.data, buffer.len);
+ error = parse_index(index, buffer.ptr, buffer.size);
if (error == GIT_SUCCESS)
index->last_modified = mtime;
- git_futils_freebuffer(&buffer);
+ git_buf_free(&buffer);
}
if (error < GIT_SUCCESS)
diff --git a/src/odb.c b/src/odb.c
index 4eaf289e7..81fc82ba8 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -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)
{
git_buf alternates_path = GIT_BUF_INIT;
+ git_buf alternates_buf = GIT_BUF_INIT;
char *buffer;
- git_fbuffer alternates_buf = GIT_FBUFFER_INIT;
const char *alternate;
int error;
@@ -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");
}
- buffer = (char *)alternates_buf.data;
+ buffer = (char *)alternates_buf.ptr;
error = GIT_SUCCESS;
/* 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)
}
git_buf_free(&alternates_path);
- git_futils_freebuffer(&alternates_buf);
+ git_buf_free(&alternates_buf);
+
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to load alternates");
return error;
diff --git a/src/odb_loose.c b/src/odb_loose.c
index bb2b7b5f5..f5f6e35ac 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -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 *data = obj->data;
+ unsigned char *data = (unsigned char *)obj->ptr;
size_t shift, size, used = 0;
- if (obj->len == 0)
+ if (obj->size == 0)
return 0;
c = data[used++];
@@ -90,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
size = c & 15;
shift = 4;
while (c & 0x80) {
- if (obj->len <= used)
+ if (obj->size <= used)
return 0;
if (sizeof(size_t) * 8 <= shift)
return 0;
@@ -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;
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)
return status;
@@ -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
* 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;
obj_hdr hdr;
@@ -310,8 +310,8 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
if (!buf)
return GIT_ENOMEM;
- in = ((unsigned char *)obj->data) + used;
- len = obj->len - used;
+ in = ((unsigned char *)obj->ptr) + used;
+ len = obj->size - used;
if (inflate_buffer(in, len, buf, hdr.size)) {
git__free(buf);
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)
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;
z_stream zs;
@@ -335,7 +335,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
/*
* 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);
/*
@@ -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)
{
int error;
- git_fbuffer obj = GIT_FBUFFER_INIT;
+ git_buf obj = GIT_BUF_INIT;
assert(out && 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");
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");
}
diff --git a/src/reflog.c b/src/reflog.c
index 9f5ccd322..6ca9418cf 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -183,7 +183,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
{
int error;
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;
*reflog = NULL;
@@ -201,7 +201,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
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");
else
*reflog = log;
@@ -209,7 +209,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
cleanup:
if (error != GIT_SUCCESS && log != NULL)
git_reflog_free(log);
- git_futils_freebuffer(&log_file);
+ git_buf_free(&log_file);
git_buf_free(&log_path);
return error;
diff --git a/src/refs.c b/src/refs.c
index 8e911c1ae..2e1d92da2 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -32,15 +32,15 @@ struct packref {
static const int default_table_size = 32;
static int reference_read(
- git_fbuffer *file_content,
+ git_buf *file_content,
time_t *mtime,
const char *repo_path,
const char *ref_name,
int *updated);
/* loose refs */
-static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content);
-static int loose_parse_oid(git_oid *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_buf *file_content);
static int loose_lookup(git_reference *ref);
static int loose_lookup_to_packfile(struct packref **ref_out,
git_repository *repo, const char *name);
@@ -113,7 +113,7 @@ static int reference_alloc(
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;
int error = GIT_SUCCESS;
@@ -129,15 +129,15 @@ static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *
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 char *refname_start;
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,
"Failed to parse loose reference. Object too short");
@@ -165,15 +165,15 @@ static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content)
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;
char *buffer;
- buffer = (char *)file_content->data;
+ buffer = (char *)file_content->ptr;
/* 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,
"Failed to parse loose reference. Reference too short");
@@ -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)
{
- git_fbuffer ref_file = GIT_FBUFFER_INIT;
+ git_buf ref_file = GIT_BUF_INIT;
git_rtype type;
type = GIT_REF_INVALID;
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;
else
type = GIT_REF_OID;
}
- git_futils_freebuffer(&ref_file);
+ git_buf_free(&ref_file);
return type;
}
static int loose_lookup(git_reference *ref)
{
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,
ref->owner->path_repository, ref->name, &updated) < GIT_SUCCESS)
@@ -228,7 +228,7 @@ static int loose_lookup(git_reference *ref)
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;
error = loose_parse_symbolic(ref, &ref_file);
} else {
@@ -236,7 +236,7 @@ static int loose_lookup(git_reference *ref)
error = loose_parse_oid(&ref->target.oid, &ref_file);
}
- git_futils_freebuffer(&ref_file);
+ git_buf_free(&ref_file);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to lookup loose reference");
@@ -250,7 +250,7 @@ static int loose_lookup_to_packfile(
const char *name)
{
int error = GIT_SUCCESS;
- git_fbuffer ref_file = GIT_FBUFFER_INIT;
+ git_buf ref_file = GIT_BUF_INIT;
struct packref *ref = NULL;
size_t name_len;
@@ -273,11 +273,11 @@ static int loose_lookup_to_packfile(
ref->flags = GIT_PACKREF_WAS_LOOSE;
*ref_out = ref;
- git_futils_freebuffer(&ref_file);
+ git_buf_free(&ref_file);
return GIT_SUCCESS;
cleanup:
- git_futils_freebuffer(&ref_file);
+ git_buf_free(&ref_file);
free(ref);
return git__rethrow(error, "Failed to lookup loose reference");
}
@@ -427,7 +427,7 @@ cleanup:
static int packed_load(git_repository *repo)
{
int error = GIT_SUCCESS, updated;
- git_fbuffer packfile = GIT_FBUFFER_INIT;
+ git_buf packfile = GIT_BUF_INIT;
const char *buffer_start, *buffer_end;
git_refcache *ref_cache = &repo->references;
@@ -468,8 +468,8 @@ static int packed_load(git_repository *repo)
git_hashtable_clear(ref_cache->packfile);
- buffer_start = (const char *)packfile.data;
- buffer_end = (const char *)(buffer_start) + packfile.len;
+ buffer_start = (const char *)packfile.ptr;
+ buffer_end = (const char *)(buffer_start) + packfile.size;
while (buffer_start < buffer_end && buffer_start[0] == '#') {
buffer_start = strchr(buffer_start, '\n');
@@ -500,13 +500,13 @@ static int packed_load(git_repository *repo)
}
}
- git_futils_freebuffer(&packfile);
+ git_buf_free(&packfile);
return GIT_SUCCESS;
cleanup:
git_hashtable_free(ref_cache->packfile);
ref_cache->packfile = NULL;
- git_futils_freebuffer(&packfile);
+ git_buf_free(&packfile);
return git__rethrow(error, "Failed to load packed references");
}
diff --git a/src/repository.c b/src/repository.c
index f394d06fe..c46dd9df9 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -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)
{
- git_fbuffer file;
+ git_buf file = GIT_BUF_INIT;
int error;
assert(path_out && file_path);
@@ -476,22 +476,22 @@ static int read_gitfile(git_buf *path_out, const char *file_path, const char *ba
if (error < GIT_SUCCESS)
return error;
- if (git__prefixcmp((char *)file.data, GIT_FILE_CONTENT_PREFIX)) {
- git_futils_freebuffer(&file);
+ if (git__prefixcmp((char *)file.ptr, GIT_FILE_CONTENT_PREFIX)) {
+ git_buf_free(&file);
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) {
- git_futils_freebuffer(&file);
+ if (strlen(GIT_FILE_CONTENT_PREFIX) == file.size) {
+ git_buf_free(&file);
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
}
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)
return GIT_SUCCESS;