summaryrefslogtreecommitdiff
path: root/src/ident.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-09-11 22:00:36 -0700
committerRussell Belfer <rb@github.com>2013-09-17 09:31:45 -0700
commita9f51e430fef49b3299ec33c11a4e6623e3f58cc (patch)
treea3162a8bcf71628f0750d5560923e7783be38eca /src/ident.c
parent4b11f25a4fbb6952284e037a70e2d61fde841ab6 (diff)
downloadlibgit2-a9f51e430fef49b3299ec33c11a4e6623e3f58cc.tar.gz
Merge git_buf and git_buffer
This makes the git_buf struct that was used internally into an externally available structure and eliminates the git_buffer. As part of that, some of the special cases that arose with the externally used git_buffer were blended into the git_buf, such as being careful about git_buf objects that may have a NULL ptr and allowing for bufs with a valid ptr and size but zero asize as a way of referring to externally owned data.
Diffstat (limited to 'src/ident.c')
-rw-r--r--src/ident.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/ident.c b/src/ident.c
index aedb973f9..3ea949859 100644
--- a/src/ident.c
+++ b/src/ident.c
@@ -9,7 +9,7 @@
#include "filter.h"
#include "buffer.h"
-int ident_find_id(
+static int ident_find_id(
const char **id_start, const char **id_end, const char *start, size_t len)
{
const char *found;
@@ -36,12 +36,11 @@ int ident_find_id(
}
static int ident_insert_id(
- git_buffer *to, const git_buffer *from, const git_filter_source *src)
+ git_buf *to, const git_buf *from, const git_filter_source *src)
{
char oid[GIT_OID_HEXSZ+1];
const char *id_start, *id_end, *from_end = from->ptr + from->size;
size_t need_size;
- git_buf to_buf = GIT_BUF_FROM_BUFFER(to);
/* replace $Id$ with blob id */
@@ -57,28 +56,23 @@ static int ident_insert_id(
5 /* "$Id: " */ + GIT_OID_HEXSZ + 1 /* "$" */ +
(size_t)(from_end - id_end);
- if (git_buf_grow(&to_buf, need_size) < 0)
+ if (git_buf_grow(to, need_size) < 0)
return -1;
- git_buf_set(&to_buf, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(&to_buf, "$Id: ", 5);
- git_buf_put(&to_buf, oid, GIT_OID_HEXSZ);
- git_buf_putc(&to_buf, '$');
- git_buf_put(&to_buf, id_end, (size_t)(from_end - id_end));
+ git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_buf_put(to, "$Id: ", 5);
+ git_buf_put(to, oid, GIT_OID_HEXSZ);
+ git_buf_putc(to, '$');
+ git_buf_put(to, id_end, (size_t)(from_end - id_end));
- if (git_buf_oom(&to_buf))
- return -1;
-
- git_buffer_from_buf(to, &to_buf);
- return 0;
+ return git_buf_oom(to) ? -1 : 0;
}
static int ident_remove_id(
- git_buffer *to, const git_buffer *from)
+ git_buf *to, const git_buf *from)
{
const char *id_start, *id_end, *from_end = from->ptr + from->size;
size_t need_size;
- git_buf to_buf = GIT_BUF_FROM_BUFFER(to);
if (ident_find_id(&id_start, &id_end, from->ptr, from->size) < 0)
return GIT_ENOTFOUND;
@@ -86,25 +80,21 @@ static int ident_remove_id(
need_size = (size_t)(id_start - from->ptr) +
4 /* "$Id$" */ + (size_t)(from_end - id_end);
- if (git_buf_grow(&to_buf, need_size) < 0)
+ if (git_buf_grow(to, need_size) < 0)
return -1;
- git_buf_set(&to_buf, from->ptr, (size_t)(id_start - from->ptr));
- git_buf_put(&to_buf, "$Id$", 4);
- git_buf_put(&to_buf, id_end, (size_t)(from_end - id_end));
+ git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
+ git_buf_put(to, "$Id$", 4);
+ git_buf_put(to, id_end, (size_t)(from_end - id_end));
- if (git_buf_oom(&to_buf))
- return -1;
-
- git_buffer_from_buf(to, &to_buf);
- return 0;
+ return git_buf_oom(to) ? -1 : 0;
}
static int ident_apply(
- git_filter *self,
- void **payload,
- git_buffer *to,
- const git_buffer *from,
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
const git_filter_source *src)
{
GIT_UNUSED(self); GIT_UNUSED(payload);