summaryrefslogtreecommitdiff
path: root/src/refs.c
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/refs.c
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/refs.c')
-rw-r--r--src/refs.c48
1 files changed, 24 insertions, 24 deletions
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");
}