Skip to content

Commit 836a3fd

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a22347c commit 836a3fd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

commit.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,26 @@ int parse_commit(struct commit *item)
316316
return ret;
317317
}
318318

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+
319339
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
320340
{
321341
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
4040

4141
int parse_commit(struct commit *item);
4242

43+
void unparse_commit(struct commit *item);
44+
4345
struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
4446
unsigned commit_list_count(const struct commit_list *l);
4547
struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);

0 commit comments

Comments
 (0)