Show More
@@ -1050,6 +1050,67 b' static PyObject *index_issnapshot(indexO' | |||
|
1050 | 1050 | return PyBool_FromLong((long)issnap); |
|
1051 | 1051 | } |
|
1052 | 1052 | |
|
1053 | static PyObject *index_findsnapshots(indexObject *self, PyObject *args) | |
|
1054 | { | |
|
1055 | Py_ssize_t start_rev; | |
|
1056 | PyObject *cache; | |
|
1057 | Py_ssize_t base; | |
|
1058 | Py_ssize_t rev; | |
|
1059 | PyObject *key = NULL; | |
|
1060 | PyObject *value = NULL; | |
|
1061 | const Py_ssize_t length = index_length(self); | |
|
1062 | if (!PyArg_ParseTuple(args, "O!n", &PyDict_Type, &cache, &start_rev)) { | |
|
1063 | return NULL; | |
|
1064 | } | |
|
1065 | for (rev = start_rev; rev < length; rev++) { | |
|
1066 | int issnap; | |
|
1067 | PyObject *allvalues = NULL; | |
|
1068 | issnap = index_issnapshotrev(self, rev); | |
|
1069 | if (issnap < 0) { | |
|
1070 | goto bail; | |
|
1071 | } | |
|
1072 | if (issnap == 0) { | |
|
1073 | continue; | |
|
1074 | } | |
|
1075 | base = (Py_ssize_t)index_baserev(self, rev); | |
|
1076 | if (base == rev) { | |
|
1077 | base = -1; | |
|
1078 | } | |
|
1079 | if (base == -2) { | |
|
1080 | assert(PyErr_Occurred()); | |
|
1081 | goto bail; | |
|
1082 | } | |
|
1083 | key = PyInt_FromSsize_t(base); | |
|
1084 | allvalues = PyDict_GetItem(cache, key); | |
|
1085 | if (allvalues == NULL && PyErr_Occurred()) { | |
|
1086 | goto bail; | |
|
1087 | } | |
|
1088 | if (allvalues == NULL) { | |
|
1089 | int r; | |
|
1090 | allvalues = PyList_New(0); | |
|
1091 | if (!allvalues) { | |
|
1092 | goto bail; | |
|
1093 | } | |
|
1094 | r = PyDict_SetItem(cache, key, allvalues); | |
|
1095 | Py_DECREF(allvalues); | |
|
1096 | if (r < 0) { | |
|
1097 | goto bail; | |
|
1098 | } | |
|
1099 | } | |
|
1100 | value = PyInt_FromSsize_t(rev); | |
|
1101 | if (PyList_Append(allvalues, value)) { | |
|
1102 | goto bail; | |
|
1103 | } | |
|
1104 | Py_CLEAR(key); | |
|
1105 | Py_CLEAR(value); | |
|
1106 | } | |
|
1107 | Py_RETURN_NONE; | |
|
1108 | bail: | |
|
1109 | Py_XDECREF(key); | |
|
1110 | Py_XDECREF(value); | |
|
1111 | return NULL; | |
|
1112 | } | |
|
1113 | ||
|
1053 | 1114 | static PyObject *index_deltachain(indexObject *self, PyObject *args) |
|
1054 | 1115 | { |
|
1055 | 1116 | int rev, generaldelta; |
@@ -2664,6 +2725,8 b' static PyMethodDef index_methods[] = {' | |||
|
2664 | 2725 | "get filtered head revisions"}, /* Can always do filtering */ |
|
2665 | 2726 | {"issnapshot", (PyCFunction)index_issnapshot, METH_O, |
|
2666 | 2727 | "True if the object is a snapshot"}, |
|
2728 | {"findsnapshots", (PyCFunction)index_findsnapshots, METH_VARARGS, | |
|
2729 | "Gather snapshot data in a cache dict"}, | |
|
2667 | 2730 | {"deltachain", (PyCFunction)index_deltachain, METH_VARARGS, |
|
2668 | 2731 | "determine revisions with deltas to reconstruct fulltext"}, |
|
2669 | 2732 | {"slicechunktodensity", (PyCFunction)index_slicechunktodensity, |
@@ -30,6 +30,7 b' from ..thirdparty import (' | |||
|
30 | 30 | from .. import ( |
|
31 | 31 | error, |
|
32 | 32 | mdiff, |
|
33 | util, | |
|
33 | 34 | ) |
|
34 | 35 | |
|
35 | 36 | # maximum <delta-chain-data>/<revision-text-length> ratio |
@@ -688,11 +689,14 b' def _candidategroups(revlog, textlen, p1' | |||
|
688 | 689 | |
|
689 | 690 | def _findsnapshots(revlog, cache, start_rev): |
|
690 | 691 | """find snapshot from start_rev to tip""" |
|
691 | deltaparent = revlog.deltaparent | |
|
692 | issnapshot = revlog.issnapshot | |
|
693 | for rev in revlog.revs(start_rev): | |
|
694 | if issnapshot(rev): | |
|
695 | cache[deltaparent(rev)].append(rev) | |
|
692 | if util.safehasattr(revlog.index, 'findsnapshots'): | |
|
693 | revlog.index.findsnapshots(cache, start_rev) | |
|
694 | else: | |
|
695 | deltaparent = revlog.deltaparent | |
|
696 | issnapshot = revlog.issnapshot | |
|
697 | for rev in revlog.revs(start_rev): | |
|
698 | if issnapshot(rev): | |
|
699 | cache[deltaparent(rev)].append(rev) | |
|
696 | 700 | |
|
697 | 701 | def _refinedgroups(revlog, p1, p2, cachedelta): |
|
698 | 702 | good = None |
General Comments 0
You need to be logged in to leave comments.
Login now