summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-03-28 13:59:48 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-03-28 13:59:48 +0200
commit7b4a16e2c8869ba18264d0c44996880c8f9bb095 (patch)
treee3012c9af02032f8121dfeaa4e9b7242633d8bdf /src
parentc15e0db5a9f259e782cf49e50dd1109548bab1fa (diff)
downloadlibgit2-7b4a16e2c8869ba18264d0c44996880c8f9bb095.tar.gz
Add git_tag_create_frombuffer API
Expose the tag parsing capabilities already present in the library. Exporting this function makes it possible to implement the mktag command without duplicating this functionality. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src')
-rw-r--r--src/tag.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/tag.c b/src/tag.c
index d90e2de82..a68857763 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -241,6 +241,43 @@ int git_tag_create(
return error;
}
+int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *buffer)
+{
+ 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;
+
+ error = git_object_lookup(&obj, repo, &tag.target, tag.type);
+ if(error < 0)
+ goto exit_freetag;
+
+ error = git_tag_create_o(oid, repo, tag.tag_name, obj,
+ tag.tagger, tag.message);
+
+ git_object_close(obj);
+
+ exit_freetag:
+ 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)
{