Show More
@@ -1676,108 +1676,6 b' bail:' | |||||
1676 | } |
|
1676 | } | |
1677 |
|
1677 | |||
1678 | /* |
|
1678 | /* | |
1679 | * Given a (possibly overlapping) set of revs, return the greatest |
|
|||
1680 | * common ancestors: those with the longest path to the root. |
|
|||
1681 | */ |
|
|||
1682 | static PyObject *index_ancestors(indexObject *self, PyObject *args) |
|
|||
1683 | { |
|
|||
1684 | PyObject *ret = NULL, *gca = NULL; |
|
|||
1685 | Py_ssize_t argcount, i, len; |
|
|||
1686 | bitmask repeat = 0; |
|
|||
1687 | int revcount = 0; |
|
|||
1688 | int *revs; |
|
|||
1689 |
|
||||
1690 | argcount = PySequence_Length(args); |
|
|||
1691 | revs = malloc(argcount * sizeof(*revs)); |
|
|||
1692 | if (argcount > 0 && revs == NULL) |
|
|||
1693 | return PyErr_NoMemory(); |
|
|||
1694 | len = index_length(self) - 1; |
|
|||
1695 |
|
||||
1696 | for (i = 0; i < argcount; i++) { |
|
|||
1697 | static const int capacity = 24; |
|
|||
1698 | PyObject *obj = PySequence_GetItem(args, i); |
|
|||
1699 | bitmask x; |
|
|||
1700 | long val; |
|
|||
1701 |
|
||||
1702 | if (!PyInt_Check(obj)) { |
|
|||
1703 | PyErr_SetString(PyExc_TypeError, |
|
|||
1704 | "arguments must all be ints"); |
|
|||
1705 | Py_DECREF(obj); |
|
|||
1706 | goto bail; |
|
|||
1707 | } |
|
|||
1708 | val = PyInt_AsLong(obj); |
|
|||
1709 | Py_DECREF(obj); |
|
|||
1710 | if (val == -1) { |
|
|||
1711 | ret = PyList_New(0); |
|
|||
1712 | goto done; |
|
|||
1713 | } |
|
|||
1714 | if (val < 0 || val >= len) { |
|
|||
1715 | PyErr_SetString(PyExc_IndexError, |
|
|||
1716 | "index out of range"); |
|
|||
1717 | goto bail; |
|
|||
1718 | } |
|
|||
1719 | /* this cheesy bloom filter lets us avoid some more |
|
|||
1720 | * expensive duplicate checks in the common set-is-disjoint |
|
|||
1721 | * case */ |
|
|||
1722 | x = 1ull << (val & 0x3f); |
|
|||
1723 | if (repeat & x) { |
|
|||
1724 | int k; |
|
|||
1725 | for (k = 0; k < revcount; k++) { |
|
|||
1726 | if (val == revs[k]) |
|
|||
1727 | goto duplicate; |
|
|||
1728 | } |
|
|||
1729 | } |
|
|||
1730 | else repeat |= x; |
|
|||
1731 | if (revcount >= capacity) { |
|
|||
1732 | PyErr_Format(PyExc_OverflowError, |
|
|||
1733 | "bitset size (%d) > capacity (%d)", |
|
|||
1734 | revcount, capacity); |
|
|||
1735 | goto bail; |
|
|||
1736 | } |
|
|||
1737 | revs[revcount++] = (int)val; |
|
|||
1738 | duplicate:; |
|
|||
1739 | } |
|
|||
1740 |
|
||||
1741 | if (revcount == 0) { |
|
|||
1742 | ret = PyList_New(0); |
|
|||
1743 | goto done; |
|
|||
1744 | } |
|
|||
1745 | if (revcount == 1) { |
|
|||
1746 | PyObject *obj; |
|
|||
1747 | ret = PyList_New(1); |
|
|||
1748 | if (ret == NULL) |
|
|||
1749 | goto bail; |
|
|||
1750 | obj = PyInt_FromLong(revs[0]); |
|
|||
1751 | if (obj == NULL) |
|
|||
1752 | goto bail; |
|
|||
1753 | PyList_SET_ITEM(ret, 0, obj); |
|
|||
1754 | goto done; |
|
|||
1755 | } |
|
|||
1756 |
|
||||
1757 | gca = find_gca_candidates(self, revs, revcount); |
|
|||
1758 | if (gca == NULL) |
|
|||
1759 | goto bail; |
|
|||
1760 |
|
||||
1761 | if (PyList_GET_SIZE(gca) <= 1) { |
|
|||
1762 | ret = gca; |
|
|||
1763 | Py_INCREF(gca); |
|
|||
1764 | } |
|
|||
1765 | else ret = find_deepest(self, gca); |
|
|||
1766 |
|
||||
1767 | done: |
|
|||
1768 | free(revs); |
|
|||
1769 | Py_XDECREF(gca); |
|
|||
1770 |
|
||||
1771 | return ret; |
|
|||
1772 |
|
||||
1773 | bail: |
|
|||
1774 | free(revs); |
|
|||
1775 | Py_XDECREF(gca); |
|
|||
1776 | Py_XDECREF(ret); |
|
|||
1777 | return NULL; |
|
|||
1778 | } |
|
|||
1779 |
|
||||
1780 | /* |
|
|||
1781 | * Given a (possibly overlapping) set of revs, return all the |
|
1679 | * Given a (possibly overlapping) set of revs, return all the | |
1782 | * common ancestors heads: heads(::args[0] and ::a[1] and ...) |
|
1680 | * common ancestors heads: heads(::args[0] and ::a[1] and ...) | |
1783 | */ |
|
1681 | */ | |
@@ -1871,6 +1769,24 b' bail:' | |||||
1871 | } |
|
1769 | } | |
1872 |
|
1770 | |||
1873 | /* |
|
1771 | /* | |
|
1772 | * Given a (possibly overlapping) set of revs, return the greatest | |||
|
1773 | * common ancestors: those with the longest path to the root. | |||
|
1774 | */ | |||
|
1775 | static PyObject *index_ancestors(indexObject *self, PyObject *args) | |||
|
1776 | { | |||
|
1777 | PyObject *gca = index_commonancestorsheads(self, args); | |||
|
1778 | if (gca == NULL) | |||
|
1779 | return NULL; | |||
|
1780 | ||||
|
1781 | if (PyList_GET_SIZE(gca) <= 1) { | |||
|
1782 | Py_INCREF(gca); | |||
|
1783 | return gca; | |||
|
1784 | } | |||
|
1785 | ||||
|
1786 | return find_deepest(self, gca); | |||
|
1787 | } | |||
|
1788 | ||||
|
1789 | /* | |||
1874 | * Invalidate any trie entries introduced by added revs. |
|
1790 | * Invalidate any trie entries introduced by added revs. | |
1875 | */ |
|
1791 | */ | |
1876 | static void nt_invalidate_added(indexObject *self, Py_ssize_t start) |
|
1792 | static void nt_invalidate_added(indexObject *self, Py_ssize_t start) |
General Comments 0
You need to be logged in to leave comments.
Login now