summaryrefslogtreecommitdiff
path: root/src/git
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-09-20 21:39:11 +0300
committerVicent Marti <tanoku@gmail.com>2010-09-20 21:39:11 +0300
commitd45b4a9a1bcbb157a4f02cf5ed23fde5222db9c8 (patch)
tree554847491982e4256559938b1dab33730b2cffcb /src/git
parent0c3596f18a6f07d8a61f8d6e2fd730a276a51599 (diff)
downloadlibgit2-d45b4a9a1bcbb157a4f02cf5ed23fde5222db9c8.tar.gz
Add support for in-memory objects
All repository objects can now be created from scratch in memory using either the git_object_new() method, or the corresponding git_XXX_new() for each object. So far, only git_commits can be written back to disk once created in memory. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/git')
-rw-r--r--src/git/commit.h12
-rw-r--r--src/git/repository.h44
-rw-r--r--src/git/tag.h12
-rw-r--r--src/git/tree.h12
4 files changed, 80 insertions, 0 deletions
diff --git a/src/git/commit.h b/src/git/commit.h
index 4387925da..a584273a1 100644
--- a/src/git/commit.h
+++ b/src/git/commit.h
@@ -30,6 +30,18 @@ typedef struct git_commit git_commit;
*/
GIT_EXTERN(git_commit *) git_commit_lookup(git_repository *repo, const git_oid *id);
+/*
+ * Create a new in-memory git_commit.
+ *
+ * The commit object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param repo The repository where the object will reside
+ * @return the object if creation was posible; NULL otherwise
+ */
+GIT_EXTERN(git_commit *) git_commit_new(git_repository *repo);
+
/**
* Get the id of a commit.
* @param commit a previously loaded commit.
diff --git a/src/git/repository.h b/src/git/repository.h
index 33bb2fcef..9417d7b51 100644
--- a/src/git/repository.h
+++ b/src/git/repository.h
@@ -57,9 +57,53 @@ GIT_EXTERN(git_object *) git_repository_lookup(git_repository *repo, const git_o
*/
GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
+/*
+ * Create a new in-memory repository object with
+ * the given type.
+ *
+ * The object's attributes can be filled in using the
+ * correspondign setter methods.
+ *
+ * The object will be written back to given git_repository
+ * when the git_object_write() function is called; objects
+ * cannot be written to disk until all their main
+ * attributes have been properly filled.
+ *
+ * Objects are instantiated with no SHA1 id; their id
+ * will be automatically generated when writing to the
+ * repository.
+ *
+ * @parem repo Repository where the object belongs
+ * @param type Type of the object to be created
+ * @return the new object
+ */
+GIT_EXTERN(git_object *) git_object_new(git_repository *repo, git_otype type);
+
+/*
+ * Write back an object to disk.
+ *
+ * The object will be written to its corresponding
+ * repository.
+ *
+ * If the object has no changes since it was first
+ * read from the repository, no actions will take place.
+ *
+ * If the object has been modified since it was read from
+ * the repository, or it has been created from scratch
+ * in memory, it will be written to the repository and
+ * its SHA1 ID will be updated accordingly.
+ *
+ * @param object Git object to write back
+ * @return 0 on success; otherwise an error code
+ */
+int git_object_write(git_object *object);
+
/**
* Get the id (SHA1) of a repository object
*
+ * In-memory objects created by git_object_new() do not
+ * have a SHA1 ID until they are written on a repository.
+ *
* @param obj the repository object
* @return the SHA1 id
*/
diff --git a/src/git/tag.h b/src/git/tag.h
index a6efabb0e..33e3d6f26 100644
--- a/src/git/tag.h
+++ b/src/git/tag.h
@@ -29,6 +29,18 @@ typedef struct git_tag git_tag;
*/
GIT_EXTERN(git_tag *) git_tag_lookup(git_repository *repo, const git_oid *id);
+/*
+ * Create a new in-memory git_tag.
+ *
+ * The tag object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param repo The repository where the object will reside
+ * @return the object if creation was posible; NULL otherwise
+ */
+GIT_EXTERN(git_tag *) git_tag_new(git_repository *repo);
+
/**
* Get the id of a tag.
* @param tag a previously loaded tag.
diff --git a/src/git/tree.h b/src/git/tree.h
index 646c085bb..32fd6527a 100644
--- a/src/git/tree.h
+++ b/src/git/tree.h
@@ -32,6 +32,18 @@ typedef struct git_tree git_tree;
*/
GIT_EXTERN(git_tree *) git_tree_lookup(git_repository *repo, const git_oid *id);
+/*
+ * Create a new in-memory git_tree.
+ *
+ * The tree object must be manually filled using
+ * setter methods before it can be written to its
+ * repository.
+ *
+ * @param repo The repository where the object will reside
+ * @return the object if creation was posible; NULL otherwise
+ */
+GIT_EXTERN(git_tree *) git_tree_new(git_repository *repo);
+
/**
* Get the id of a tree.
* @param tree a previously loaded tree.