@@ -1624,144 +1624,6 @@ static int get_ref_atom_value(struct ref_array_item *ref, int atom,
1624
1624
return 0 ;
1625
1625
}
1626
1626
1627
- /*
1628
- * Unknown has to be "0" here, because that's the default value for
1629
- * contains_cache slab entries that have not yet been assigned.
1630
- */
1631
- enum contains_result {
1632
- CONTAINS_UNKNOWN = 0 ,
1633
- CONTAINS_NO ,
1634
- CONTAINS_YES
1635
- };
1636
-
1637
- define_commit_slab (contains_cache , enum contains_result );
1638
-
1639
- struct ref_filter_cbdata {
1640
- struct ref_array * array ;
1641
- struct ref_filter * filter ;
1642
- struct contains_cache contains_cache ;
1643
- struct contains_cache no_contains_cache ;
1644
- };
1645
-
1646
- /*
1647
- * Mimicking the real stack, this stack lives on the heap, avoiding stack
1648
- * overflows.
1649
- *
1650
- * At each recursion step, the stack items points to the commits whose
1651
- * ancestors are to be inspected.
1652
- */
1653
- struct contains_stack {
1654
- int nr , alloc ;
1655
- struct contains_stack_entry {
1656
- struct commit * commit ;
1657
- struct commit_list * parents ;
1658
- } * contains_stack ;
1659
- };
1660
-
1661
- static int in_commit_list (const struct commit_list * want , struct commit * c )
1662
- {
1663
- for (; want ; want = want -> next )
1664
- if (!oidcmp (& want -> item -> object .oid , & c -> object .oid ))
1665
- return 1 ;
1666
- return 0 ;
1667
- }
1668
-
1669
- /*
1670
- * Test whether the candidate is contained in the list.
1671
- * Do not recurse to find out, though, but return -1 if inconclusive.
1672
- */
1673
- static enum contains_result contains_test (struct commit * candidate ,
1674
- const struct commit_list * want ,
1675
- struct contains_cache * cache ,
1676
- uint32_t cutoff )
1677
- {
1678
- enum contains_result * cached = contains_cache_at (cache , candidate );
1679
-
1680
- /* If we already have the answer cached, return that. */
1681
- if (* cached )
1682
- return * cached ;
1683
-
1684
- /* or are we it? */
1685
- if (in_commit_list (want , candidate )) {
1686
- * cached = CONTAINS_YES ;
1687
- return CONTAINS_YES ;
1688
- }
1689
-
1690
- /* Otherwise, we don't know; prepare to recurse */
1691
- parse_commit_or_die (candidate );
1692
-
1693
- if (candidate -> generation < cutoff )
1694
- return CONTAINS_NO ;
1695
-
1696
- return CONTAINS_UNKNOWN ;
1697
- }
1698
-
1699
- static void push_to_contains_stack (struct commit * candidate , struct contains_stack * contains_stack )
1700
- {
1701
- ALLOC_GROW (contains_stack -> contains_stack , contains_stack -> nr + 1 , contains_stack -> alloc );
1702
- contains_stack -> contains_stack [contains_stack -> nr ].commit = candidate ;
1703
- contains_stack -> contains_stack [contains_stack -> nr ++ ].parents = candidate -> parents ;
1704
- }
1705
-
1706
- static enum contains_result contains_tag_algo (struct commit * candidate ,
1707
- const struct commit_list * want ,
1708
- struct contains_cache * cache )
1709
- {
1710
- struct contains_stack contains_stack = { 0 , 0 , NULL };
1711
- enum contains_result result ;
1712
- uint32_t cutoff = GENERATION_NUMBER_INFINITY ;
1713
- const struct commit_list * p ;
1714
-
1715
- for (p = want ; p ; p = p -> next ) {
1716
- struct commit * c = p -> item ;
1717
- load_commit_graph_info (the_repository , c );
1718
- if (c -> generation < cutoff )
1719
- cutoff = c -> generation ;
1720
- }
1721
-
1722
- result = contains_test (candidate , want , cache , cutoff );
1723
- if (result != CONTAINS_UNKNOWN )
1724
- return result ;
1725
-
1726
- push_to_contains_stack (candidate , & contains_stack );
1727
- while (contains_stack .nr ) {
1728
- struct contains_stack_entry * entry = & contains_stack .contains_stack [contains_stack .nr - 1 ];
1729
- struct commit * commit = entry -> commit ;
1730
- struct commit_list * parents = entry -> parents ;
1731
-
1732
- if (!parents ) {
1733
- * contains_cache_at (cache , commit ) = CONTAINS_NO ;
1734
- contains_stack .nr -- ;
1735
- }
1736
- /*
1737
- * If we just popped the stack, parents->item has been marked,
1738
- * therefore contains_test will return a meaningful yes/no.
1739
- */
1740
- else switch (contains_test (parents -> item , want , cache , cutoff )) {
1741
- case CONTAINS_YES :
1742
- * contains_cache_at (cache , commit ) = CONTAINS_YES ;
1743
- contains_stack .nr -- ;
1744
- break ;
1745
- case CONTAINS_NO :
1746
- entry -> parents = parents -> next ;
1747
- break ;
1748
- case CONTAINS_UNKNOWN :
1749
- push_to_contains_stack (parents -> item , & contains_stack );
1750
- break ;
1751
- }
1752
- }
1753
- free (contains_stack .contains_stack );
1754
- return contains_test (candidate , want , cache , cutoff );
1755
- }
1756
-
1757
- static int commit_contains (struct ref_filter * filter , struct commit * commit ,
1758
- struct commit_list * list , struct contains_cache * cache )
1759
- {
1760
- if (filter -> with_commit_tag_algo )
1761
- return contains_tag_algo (commit , list , cache ) == CONTAINS_YES ;
1762
- return is_descendant_of (commit , list );
1763
- }
1764
-
1765
1627
/*
1766
1628
* Return 1 if the refname matches one of the patterns, otherwise 0.
1767
1629
* A pattern can be a literal prefix (e.g. a refname "refs/heads/master"
@@ -1988,6 +1850,13 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
1988
1850
return ref_kind_from_refname (refname );
1989
1851
}
1990
1852
1853
+ struct ref_filter_cbdata {
1854
+ struct ref_array * array ;
1855
+ struct ref_filter * filter ;
1856
+ struct contains_cache contains_cache ;
1857
+ struct contains_cache no_contains_cache ;
1858
+ };
1859
+
1991
1860
/*
1992
1861
* A call-back given to for_each_ref(). Filter refs and keep them for
1993
1862
* later object processing.
0 commit comments