]> git.proxmox.com Git - libgit2.git/commitdiff
Add git_tag_create_frombuffer API
authorCarlos Martín Nieto <cmn@elego.de>
Mon, 28 Mar 2011 11:59:48 +0000 (13:59 +0200)
committerCarlos Martín Nieto <cmn@elego.de>
Mon, 28 Mar 2011 11:59:48 +0000 (13:59 +0200)
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>
include/git2/tag.h
src/tag.c

index ee92cd5c23a6b2db9fd9eb32dc169597eeb3efd3..c47e3412c45765a7ec5c5327d8d4523370119f3b 100644 (file)
@@ -188,6 +188,20 @@ GIT_EXTERN(int) git_tag_create_o(
                const git_signature *tagger,
                const char *message);
 
+/**
+ * Create a new tag in the repository from a buffer
+ *
+ * @param oid Pointer where to store the OID of the newly created tag
+ *
+ * @param repo Repository where to store the tag
+ *
+ * @param buffer Raw tag data
+ */
+GIT_EXTERN(int) git_tag_create_frombuffer(
+               git_oid *oid,
+               git_repository *repo,
+               const char *buffer);
+
 /** @} */
 GIT_END_DECL
 #endif
index d90e2de82108d63339bdf3ad828e944ab836d2f5..a6885776310025d0e4e61a9f4f989a6d04c7955c 100644 (file)
--- 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)
 {