summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2009-05-17 15:36:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-05-18 06:19:32 (GMT)
commit836a3fd5b0c439642268fd1299cd16729f15e614 (patch)
tree7ab2043a0070ddb232f11f40298a81c5e28a3851 /commit.c
parenta22347c6c866c94e9e941b1b39d57ea43218af96 (diff)
downloadgit-836a3fd5b0c439642268fd1299cd16729f15e614.zip
git-836a3fd5b0c439642268fd1299cd16729f15e614.tar.gz
git-836a3fd5b0c439642268fd1299cd16729f15e614.tar.bz2
commit: add function to unparse a commit and its parents
This patch adds the "unparse_commit" function that returns a commit into an unparsed state by freeing its data and resetting its fields to 0. Its parents are recursively unparsed too, because they might have been changed. But its tree is not unparsed as it should not have been modifed. Note that as the "flags" and "used" fields may be used even if the object is not parsed, we have to reset them anyway. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/commit.c b/commit.c
index aa3b35b..8f6b703 100644
--- a/commit.c
+++ b/commit.c
@@ -316,6 +316,26 @@ int parse_commit(struct commit *item)
return ret;
}
+static void unparse_commit_list(struct commit_list *list)
+{
+ for (; list; list = list->next)
+ unparse_commit(list->item);
+}
+
+void unparse_commit(struct commit *item)
+{
+ item->object.flags = 0;
+ item->object.used = 0;
+ if (item->object.parsed) {
+ item->object.parsed = 0;
+ if (item->parents) {
+ unparse_commit_list(item->parents);
+ free_commit_list(item->parents);
+ item->parents = NULL;
+ }
+ }
+}
+
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
{
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));