summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commit.c4
-rw-r--r--src/oid.c4
-rw-r--r--src/repository.h2
-rw-r--r--src/signature.c8
-rw-r--r--src/signature.h2
-rw-r--r--src/tag.c42
-rw-r--r--src/tree.c4
7 files changed, 24 insertions, 42 deletions
diff --git a/src/commit.c b/src/commit.c
index 03b111da5..9fc3f0767 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -235,9 +235,9 @@ int git_commit_create(
return error;
}
-int commit_parse_buffer(git_commit *commit, void *data, size_t len)
+int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
{
- char *buffer = (char *)data;
+ const char *buffer = (char *)data;
const char *buffer_end = (char *)data + len;
git_oid parent_oid;
diff --git a/src/oid.c b/src/oid.c
index eb167a685..86c1e0039 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -118,13 +118,13 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
return out;
}
-int git__parse_oid(git_oid *oid, char **buffer_out,
+int git__parse_oid(git_oid *oid, const char **buffer_out,
const char *buffer_end, const char *header)
{
const size_t sha_len = GIT_OID_HEXSZ;
const size_t header_len = strlen(header);
- char *buffer = *buffer_out;
+ const char *buffer = *buffer_out;
if (buffer + (header_len + sha_len + 1) > buffer_end)
return GIT_EOBJCORRUPTED;
diff --git a/src/repository.h b/src/repository.h
index fef1c7da0..813cac942 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -43,7 +43,7 @@ struct git_repository {
* export */
void git_object__free(void *object);
-int git__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header);
+int git__parse_oid(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
int git__write_oid(git_odb_stream *src, const char *header, const git_oid *oid);
#endif
diff --git a/src/signature.c b/src/signature.c
index 412637600..0c99755d4 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -109,14 +109,14 @@ static int parse_timezone_offset(const char *buffer, int *offset_out)
}
-int git_signature__parse(git_signature *sig, char **buffer_out,
+int git_signature__parse(git_signature *sig, const char **buffer_out,
const char *buffer_end, const char *header)
{
const size_t header_len = strlen(header);
int name_length, email_length;
- char *buffer = *buffer_out;
- char *line_end, *name_end, *email_end;
+ const char *buffer = *buffer_out;
+ const char *line_end, *name_end, *email_end;
int offset = 0;
memset(sig, 0x0, sizeof(git_signature));
@@ -159,7 +159,7 @@ int git_signature__parse(git_signature *sig, char **buffer_out,
if (buffer >= line_end)
return GIT_EOBJCORRUPTED;
- sig->when.time = strtol(buffer, &buffer, 10);
+ sig->when.time = strtol(buffer, (char **)&buffer, 10);
if (sig->when.time == 0)
return GIT_EOBJCORRUPTED;
diff --git a/src/signature.h b/src/signature.h
index 3534cb21f..feba6578d 100644
--- a/src/signature.h
+++ b/src/signature.h
@@ -6,7 +6,7 @@
#include "repository.h"
#include <time.h>
-int git_signature__parse(git_signature *sig, char **buffer_out, const char *buffer_end, const char *header);
+int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header);
int git_signature__write(char **signature, const char *header, const git_signature *sig);
#endif
diff --git a/src/tag.c b/src/tag.c
index a68857763..5982a053b 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -79,7 +79,7 @@ const char *git_tag_message(git_tag *t)
return t->message;
}
-static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
+static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer_end)
{
static const char *tag_types[] = {
NULL, "commit\n", "tree\n", "blob\n", "tag\n"
@@ -130,9 +130,6 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
text_len = search - buffer;
- if (tag->tag_name != NULL)
- free(tag->tag_name);
-
tag->tag_name = git__malloc(text_len + 1);
memcpy(tag->tag_name, buffer, text_len);
tag->tag_name[text_len] = '\0';
@@ -141,8 +138,11 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
tag->tagger = git__malloc(sizeof(git_signature));
- if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0)
- goto cleanup;
+ if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0) {
+ free(tag->tag_name);
+ git_signature_free(tag->tagger);
+ return error;
+ }
text_len = buffer_end - ++buffer;
@@ -151,14 +151,6 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
tag->message[text_len] = '\0';
return GIT_SUCCESS;
-
- cleanup:
- if(tag->tag_name)
- free(tag->tag_name);
- if(tag->tagger)
- git_signature_free(tag->tagger);
-
- return error;
}
int git_tag_create_o(
@@ -194,7 +186,6 @@ int git_tag_create(
int type_str_len, tag_name_len, tagger_str_len, message_len;
int error;
-
type_str = git_object_type2string(target_type);
tagger_str_len = git_signature__write(&tagger_str, "tagger", tagger);
@@ -245,40 +236,31 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
{
git_tag tag;
int error;
- char *buf;
git_object *obj;
assert(oid && buffer);
memset(&tag, 0, sizeof(tag));
- buf = strdup(buffer);
- if(buf == NULL)
- return GIT_ENOMEM;
-
- if((error = parse_tag_buffer(&tag, buf, buf + strlen(buf))) < 0)
- goto exit_freebuf;
+ if ((error = parse_tag_buffer(&tag, buffer, buffer + strlen(buffer))) < GIT_SUCCESS)
+ return error;
error = git_object_lookup(&obj, repo, &tag.target, tag.type);
- if(error < 0)
- goto exit_freetag;
+ if (error < GIT_SUCCESS)
+ goto cleanup;
- error = git_tag_create_o(oid, repo, tag.tag_name, obj,
- tag.tagger, tag.message);
+ error = git_tag_create_o(oid, repo, tag.tag_name, obj, tag.tagger, tag.message);
git_object_close(obj);
- exit_freetag:
+cleanup:
git_signature_free(tag.tagger);
free(tag.tag_name);
free(tag.message);
- exit_freebuf:
- free(buf);
return error;
}
-
int git_tag__parse(git_tag *tag, git_odb_object *obj)
{
assert(tag);
diff --git a/src/tree.c b/src/tree.c
index 31b286e69..dea50463b 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -127,7 +127,7 @@ size_t git_tree_entrycount(git_tree *tree)
return tree->entries.length;
}
-static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end)
+static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buffer_end)
{
int error = GIT_SUCCESS;
@@ -146,7 +146,7 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end)
if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS)
return GIT_ENOMEM;
- entry->attr = strtol(buffer, &buffer, 8);
+ entry->attr = strtol(buffer, (char **)&buffer, 8);
if (*buffer++ != ' ') {
error = GIT_EOBJCORRUPTED;