# HG changeset patch # User Raphaël Gomès # Date 2024-02-21 10:53:30 # Node ID 3a7ef1398385898a5899e7a49ee73b311496ef98 # Parent 6603a1448f189bf98cb90ba968bb21271bf3f6f2 # Parent e0fc40b95f053bf291bd6238869aa173992b8a54 branching: merge stable into default diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -909,6 +909,19 @@ static inline void set_phase_from_parent phases[i] = phases[parent_2]; } +/* Take ownership of a given Python value and add it to a Python list. + Return -1 on failure (including if [elem] is NULL). */ +static int pylist_append_owned(PyObject *list, PyObject *elem) +{ + int res; + + if (elem == NULL) + return -1; + res = PyList_Append(list, elem); + Py_DECREF(elem); + return res; +} + static PyObject *reachableroots2(indexObject *self, PyObject *args) { @@ -921,7 +934,6 @@ static PyObject *reachableroots2(indexOb PyObject *roots = NULL; PyObject *reachable = NULL; - PyObject *val; Py_ssize_t len = index_length(self); long revnum; Py_ssize_t k; @@ -1002,11 +1014,8 @@ static PyObject *reachableroots2(indexOb revnum = tovisit[k++]; if (revstates[revnum + 1] & RS_ROOT) { revstates[revnum + 1] |= RS_REACHABLE; - val = PyLong_FromLong(revnum); - if (val == NULL) - goto bail; - r = PyList_Append(reachable, val); - Py_DECREF(val); + r = pylist_append_owned(reachable, + PyLong_FromLong(revnum)); if (r < 0) goto bail; if (includepath == 0) @@ -1047,11 +1056,8 @@ static PyObject *reachableroots2(indexOb RS_REACHABLE) && !(revstates[i + 1] & RS_REACHABLE)) { revstates[i + 1] |= RS_REACHABLE; - val = PyLong_FromSsize_t(i); - if (val == NULL) - goto bail; - r = PyList_Append(reachable, val); - Py_DECREF(val); + r = pylist_append_owned(reachable, + PyLong_FromSsize_t(i)); if (r < 0) goto bail; } @@ -1263,8 +1269,7 @@ static PyObject *index_headrevs(indexObj if (heads == NULL) goto bail; if (len == 0) { - PyObject *nullid = PyLong_FromLong(-1); - if (nullid == NULL || PyList_Append(heads, nullid) == -1) { + if (pylist_append_owned(heads, PyLong_FromLong(-1)) == -1) { Py_XDECREF(nullid); goto bail; } @@ -1308,13 +1313,9 @@ static PyObject *index_headrevs(indexObj } for (i = 0; i < len; i++) { - PyObject *head; - if (nothead[i]) continue; - head = PyLong_FromSsize_t(i); - if (head == NULL || PyList_Append(heads, head) == -1) { - Py_XDECREF(head); + if (pylist_append_owned(heads, PyLong_FromSsize_t(i)) == -1) { goto bail; } } @@ -1561,15 +1562,9 @@ static PyObject *index_deltachain(indexO iterrev = rev; while (iterrev != baserev && iterrev != stoprev) { - PyObject *value = PyLong_FromLong(iterrev); - if (value == NULL) { + if (pylist_append_owned(chain, PyLong_FromLong(iterrev))) { goto bail; } - if (PyList_Append(chain, value)) { - Py_DECREF(value); - goto bail; - } - Py_DECREF(value); if (generaldelta) { iterrev = baserev; @@ -1600,15 +1595,9 @@ static PyObject *index_deltachain(indexO if (iterrev == stoprev) { stopped = 1; } else { - PyObject *value = PyLong_FromLong(iterrev); - if (value == NULL) { + if (pylist_append_owned(chain, PyLong_FromLong(iterrev))) { goto bail; } - if (PyList_Append(chain, value)) { - Py_DECREF(value); - goto bail; - } - Py_DECREF(value); stopped = 0; } @@ -1727,7 +1716,6 @@ static PyObject *index_slicechunktodensi 0; /* total number of notable gap recorded so far */ Py_ssize_t *selected_indices = NULL; /* indices of gap skipped over */ Py_ssize_t num_selected = 0; /* number of gaps skipped */ - PyObject *chunk = NULL; /* individual slice */ PyObject *allchunks = NULL; /* all slices */ Py_ssize_t previdx; @@ -1872,15 +1860,11 @@ static PyObject *index_slicechunktodensi goto bail; } if (previdx < endidx) { - chunk = PyList_GetSlice(list_revs, previdx, endidx); - if (chunk == NULL) { + PyObject *chunk = + PyList_GetSlice(list_revs, previdx, endidx); + if (pylist_append_owned(allchunks, chunk) == -1) { goto bail; } - if (PyList_Append(allchunks, chunk) == -1) { - goto bail; - } - Py_DECREF(chunk); - chunk = NULL; } previdx = idx; } @@ -1889,7 +1873,6 @@ static PyObject *index_slicechunktodensi bail: Py_XDECREF(allchunks); - Py_XDECREF(chunk); done: free(revs); free(gaps); @@ -2534,11 +2517,8 @@ static PyObject *find_gca_candidates(ind if (sv < poison) { interesting -= 1; if (sv == allseen) { - PyObject *obj = PyLong_FromLong(v); - if (obj == NULL) - goto bail; - if (PyList_Append(gca, obj) == -1) { - Py_DECREF(obj); + if (pylist_append_owned( + gca, PyLong_FromLong(v)) == -1) { goto bail; } sv |= poison; diff --git a/mercurial/upgrade_utils/actions.py b/mercurial/upgrade_utils/actions.py --- a/mercurial/upgrade_utils/actions.py +++ b/mercurial/upgrade_utils/actions.py @@ -501,7 +501,7 @@ class compressionlevel(formatvariant): level = repo.ui.configint(b'storage', b'revlog.zstd.level') if level is None: return b'default' - return bytes(level) + return b"%d" % level @classmethod def fromconfig(cls, repo): @@ -513,7 +513,7 @@ class compressionlevel(formatvariant): level = repo.ui.configint(b'storage', b'revlog.zstd.level') if level is None: return b'default' - return bytes(level) + return b"%d" % level def find_format_upgrades(repo): diff --git a/tests/test-chg.t b/tests/test-chg.t --- a/tests/test-chg.t +++ b/tests/test-chg.t @@ -561,12 +561,12 @@ If CHGHG is not set, chg will set it bef $ hg --kill-chg-daemon $ HG=$CHGHG CHGHG= CHGDEBUG= hg debugshell -c \ > 'ui.write(b"CHGHG=%s\n" % ui.environ.get(b"CHGHG"))' 2>&1 \ - > | grep -E 'CHGHG|start' + > | grep -E 'CHGHG|start cmdserver' chg: debug: * start cmdserver at * (glob) CHGHG=/*/install/bin/hg (glob) Running the same command a second time shouldn't spawn a new command server. $ HG=$CHGHG CHGHG= CHGDEBUG= hg debugshell -c \ > 'ui.write(b"CHGHG=%s\n" % ui.environ.get(b"CHGHG"))' 2>&1 \ - > | grep -E 'CHGHG|start' + > | grep -E 'CHGHG|start cmdserver' CHGHG=/*/install/bin/hg (glob)