@matheusbsbs / matheus-bagliano / commits / 836a3fd5b0
Fork 0

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>

Christian Couder committed May 17, 2009 at 17:36 UTC 836a3fd5b0c439642268fd1299cd16729f15e614
2 files changed +22
commit.c
+20
@@ -316,6 +316,26 @@ int parse_commit(struct commit *item)
316 return ret;
317 }
318
319 +static void unparse_commit_list(struct commit_list *list)
320 +{
321 + for (; list; list = list->next)
322 + unparse_commit(list->item);
323 +}
324 +
325 +void unparse_commit(struct commit *item)
326 +{
327 + item->object.flags = 0;
328 + item->object.used = 0;
329 + if (item->object.parsed) {
330 + item->object.parsed = 0;
331 + if (item->parents) {
332 + unparse_commit_list(item->parents);
333 + free_commit_list(item->parents);
334 + item->parents = NULL;
335 + }
336 + }
337 +}
338 +
339 struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
340 {
341 struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
commit.h
+2
@@ -40,6 +40,8 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
40
41 int parse_commit(struct commit *item);
42
43 +void unparse_commit(struct commit *item);
44 +
45 struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
46 unsigned commit_list_count(const struct commit_list *l);
47 struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);