Mercurial > hg
comparison mercurial/cext/revlog.c @ 45180:a6fde9d789d9
phases: move short-lived PyObject pointers to local scope
It helps understand which object should be decrefed on goto release.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 18 Jul 2020 18:38:46 +0900 |
parents | ba5e4b11d085 |
children | 4404f129341e |
comparison
equal
deleted
inserted
replaced
45179:ba5e4b11d085 | 45180:a6fde9d789d9 |
---|---|
789 { | 789 { |
790 /* 0: public (untracked), 1: draft, 2: secret, 32: archive, | 790 /* 0: public (untracked), 1: draft, 2: secret, 32: archive, |
791 96: internal */ | 791 96: internal */ |
792 static const char trackedphases[] = {1, 2, 32, 96}; | 792 static const char trackedphases[] = {1, 2, 32, 96}; |
793 PyObject *roots = Py_None; | 793 PyObject *roots = Py_None; |
794 PyObject *pyphase = NULL; | |
795 PyObject *pyrev = NULL; | |
796 PyObject *phasesetsdict = NULL; | 794 PyObject *phasesetsdict = NULL; |
797 PyObject *phaseroots = NULL; | |
798 PyObject *phasesets[4] = {NULL, NULL, NULL, NULL}; | 795 PyObject *phasesets[4] = {NULL, NULL, NULL, NULL}; |
799 Py_ssize_t len = index_length(self); | 796 Py_ssize_t len = index_length(self); |
800 char *phases = NULL; | 797 char *phases = NULL; |
801 int minphaserev = -1, rev, i; | 798 int minphaserev = -1, rev, i; |
802 const int numphases = (int)(sizeof(phasesets) / sizeof(phasesets[0])); | 799 const int numphases = (int)(sizeof(phasesets) / sizeof(phasesets[0])); |
813 PyErr_NoMemory(); | 810 PyErr_NoMemory(); |
814 return NULL; | 811 return NULL; |
815 } | 812 } |
816 | 813 |
817 for (i = 0; i < numphases; ++i) { | 814 for (i = 0; i < numphases; ++i) { |
818 pyphase = PyInt_FromLong(trackedphases[i]); | 815 PyObject *pyphase = PyInt_FromLong(trackedphases[i]); |
816 PyObject *phaseroots = NULL; | |
819 if (pyphase == NULL) | 817 if (pyphase == NULL) |
820 goto release; | 818 goto release; |
821 phaseroots = PyDict_GetItem(roots, pyphase); | 819 phaseroots = PyDict_GetItem(roots, pyphase); |
822 Py_DECREF(pyphase); | 820 Py_DECREF(pyphase); |
823 if (phaseroots == NULL) | 821 if (phaseroots == NULL) |
824 continue; | 822 continue; |
825 rev = add_roots_get_min(self, phaseroots, phases, | 823 rev = add_roots_get_min(self, phaseroots, phases, |
826 trackedphases[i]); | 824 trackedphases[i]); |
827 phaseroots = NULL; | |
828 if (rev == -2) | 825 if (rev == -2) |
829 goto release; | 826 goto release; |
830 if (rev != -1 && (minphaserev == -1 || rev < minphaserev)) | 827 if (rev != -1 && (minphaserev == -1 || rev < minphaserev)) |
831 minphaserev = rev; | 828 minphaserev = rev; |
832 } | 829 } |
838 } | 835 } |
839 | 836 |
840 if (minphaserev == -1) | 837 if (minphaserev == -1) |
841 minphaserev = len; | 838 minphaserev = len; |
842 for (rev = minphaserev; rev < len; ++rev) { | 839 for (rev = minphaserev; rev < len; ++rev) { |
840 PyObject *pyphase = NULL; | |
841 PyObject *pyrev = NULL; | |
843 int parents[2]; | 842 int parents[2]; |
844 /* | 843 /* |
845 * The parent lookup could be skipped for phaseroots, but | 844 * The parent lookup could be skipped for phaseroots, but |
846 * phase --force would historically not recompute them | 845 * phase --force would historically not recompute them |
847 * correctly, leaving descendents with a lower phase around. | 846 * correctly, leaving descendents with a lower phase around. |
884 | 883 |
885 phasesetsdict = _dict_new_presized(numphases); | 884 phasesetsdict = _dict_new_presized(numphases); |
886 if (phasesetsdict == NULL) | 885 if (phasesetsdict == NULL) |
887 goto release; | 886 goto release; |
888 for (i = 0; i < numphases; ++i) { | 887 for (i = 0; i < numphases; ++i) { |
889 pyphase = PyInt_FromLong(trackedphases[i]); | 888 PyObject *pyphase = PyInt_FromLong(trackedphases[i]); |
890 if (pyphase == NULL) | 889 if (pyphase == NULL) |
891 goto release; | 890 goto release; |
892 if (PyDict_SetItem(phasesetsdict, pyphase, phasesets[i]) == | 891 if (PyDict_SetItem(phasesetsdict, pyphase, phasesets[i]) == |
893 -1) { | 892 -1) { |
894 Py_DECREF(pyphase); | 893 Py_DECREF(pyphase); |