MCPcopy Create free account
hub / github.com/git/git / compact_treesame

Function compact_treesame

revision.c:871–916  ·  view source on GitHub ↗

* Must be called immediately after removing the nth_parent from a commit's * parent list, if we are maintaining the per-parent treesame[] decoration. * This does not recalculate the master TREESAME flag - update_treesame() * should be called to update it after a sequence of treesame[] modifications * that may have affected it. */

Source from the content-addressed store, hash-verified

869 * that may have affected it.
870 */
871static int compact_treesame(struct rev_info *revs, struct commit *commit, unsigned nth_parent)
872{
873 struct treesame_state *st;
874 int old_same;
875
876 if (!commit->parents) {
877 /*
878 * Have just removed the only parent from a non-merge.
879 * Different handling, as we lack decoration.
880 */
881 if (nth_parent != 0)
882 die("compact_treesame %u", nth_parent);
883 old_same = !!(commit->object.flags & TREESAME);
884 if (rev_same_tree_as_empty(revs, commit, nth_parent))
885 commit->object.flags |= TREESAME;
886 else
887 commit->object.flags &= ~TREESAME;
888 return old_same;
889 }
890
891 st = lookup_decoration(&revs->treesame, &commit->object);
892 if (!st || nth_parent >= st->nparents)
893 die("compact_treesame %u", nth_parent);
894
895 old_same = st->treesame[nth_parent];
896 memmove(st->treesame + nth_parent,
897 st->treesame + nth_parent + 1,
898 st->nparents - nth_parent - 1);
899
900 /*
901 * If we've just become a non-merge commit, update TREESAME
902 * immediately, and remove the no-longer-needed decoration.
903 * If still a merge, defer update until update_treesame().
904 */
905 if (--st->nparents == 1) {
906 if (commit->parents->next)
907 die("compact_treesame parents mismatch");
908 if (st->treesame[0] && revs->dense)
909 commit->object.flags |= TREESAME;
910 else
911 commit->object.flags &= ~TREESAME;
912 free(add_decoration(&revs->treesame, &commit->object, NULL));
913 }
914
915 return old_same;
916}
917
918static unsigned update_treesame(struct rev_info *revs, struct commit *commit)
919{

Callers 2

remove_duplicate_parentsFunction · 0.85
remove_marked_parentsFunction · 0.85

Calls 4

rev_same_tree_as_emptyFunction · 0.85
lookup_decorationFunction · 0.85
add_decorationFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected