| 651 | } |
| 652 | |
| 653 | struct commit_list *reduce_heads(struct commit_list *heads) |
| 654 | { |
| 655 | struct commit_list *p; |
| 656 | struct commit_list *result = NULL, **tail = &result; |
| 657 | struct commit **array; |
| 658 | size_t num_head, i; |
| 659 | int ret; |
| 660 | |
| 661 | if (!heads) |
| 662 | return NULL; |
| 663 | |
| 664 | /* Uniquify */ |
| 665 | for (p = heads; p; p = p->next) |
| 666 | p->item->object.flags &= ~STALE; |
| 667 | for (p = heads, num_head = 0; p; p = p->next) { |
| 668 | if (p->item->object.flags & STALE) |
| 669 | continue; |
| 670 | p->item->object.flags |= STALE; |
| 671 | num_head++; |
| 672 | } |
| 673 | CALLOC_ARRAY(array, num_head); |
| 674 | for (p = heads, i = 0; p; p = p->next) { |
| 675 | if (p->item->object.flags & STALE) { |
| 676 | array[i++] = p->item; |
| 677 | p->item->object.flags &= ~STALE; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | ret = remove_redundant(the_repository, array, num_head, &num_head); |
| 682 | if (ret < 0) { |
| 683 | free(array); |
| 684 | return NULL; |
| 685 | } |
| 686 | |
| 687 | for (i = 0; i < num_head; i++) |
| 688 | tail = &commit_list_insert(array[i], tail)->next; |
| 689 | free(array); |
| 690 | return result; |
| 691 | } |
| 692 | |
| 693 | void reduce_heads_replace(struct commit_list **heads) |
| 694 | { |