[PATCH 1 of 7] reachableroots: reduce nesting level by jumping to next iteration by continue

Yuya Nishihara yuya at tcha.org
Tue Aug 18 14:42:53 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1439629427 -32400
#      Sat Aug 15 18:03:47 2015 +0900
# Node ID ec875f53f7bdd78b215d1a312e3b958545b6368b
# Parent  a75d24539aba3d8d94dda1d9cf5c24081768ed02
reachableroots: reduce nesting level by jumping to next iteration by continue

This can eliminate lines over 80 columns. No code change except for the
outermost "if" condition.

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1197,16 +1197,16 @@ static PyObject *reachableroots(indexObj
 		Py_DECREF(val);
 
 		/* Add its parents to the list of nodes to visit */
-		if (revnum != -1) {
-			r = index_get_parents(self, revnum, parents, (int)len - 1);
-			if (r < 0)
-				goto bail;
-
-			for (i = 0; i < 2; i++) {
-				if (seen[parents[i] + 1] == 0 && parents[i] >= minroot) {
-					tovisit[lentovisit++] = parents[i];
-					seen[parents[i] + 1] = 1;
-				}
+		if (revnum == -1)
+			continue;
+		r = index_get_parents(self, revnum, parents, (int)len - 1);
+		if (r < 0)
+			goto bail;
+		for (i = 0; i < 2; i++) {
+			if (seen[parents[i] + 1] == 0
+			    && parents[i] >= minroot) {
+				tovisit[lentovisit++] = parents[i];
+				seen[parents[i] + 1] = 1;
 			}
 		}
 	}
@@ -1218,24 +1218,25 @@ static PyObject *reachableroots(indexObj
 		if (minidx < 0)
 			minidx = 0;
 		for (i = minidx; i < len; i++) {
-			if (seen[i + 1] == 1) {
-				r = index_get_parents(self, i, parents, (int)len - 1);
-				/* Corrupted index file, error is set from index_get_parents */
-				if (r < 0)
+			if (seen[i + 1] != 1)
+				continue;
+			r = index_get_parents(self, i, parents, (int)len - 1);
+			/* Corrupted index file, error is set from
+			 * index_get_parents */
+			if (r < 0)
+				goto bail;
+			for (k = 0; k < 2; k++) {
+				PyObject *p = PyInt_FromLong(parents[k]);
+				if (p == NULL)
 					goto bail;
-				for (k = 0; k < 2; k++) {
-					PyObject *p = PyInt_FromLong(parents[k]);
-					if (p == NULL)
+				if (PySet_Contains(reachable, p) == 1) {
+					val = PyInt_FromLong(i);
+					if (val == NULL)
 						goto bail;
-					if (PySet_Contains(reachable, p) == 1) {
-						val = PyInt_FromLong(i);
-						if (val == NULL)
-							goto bail;
-						PySet_Add(reachable, val);
-						Py_DECREF(val);
-					}
-					Py_DECREF(p);
+					PySet_Add(reachable, val);
+					Py_DECREF(val);
 				}
+				Py_DECREF(p);
 			}
 		}
 	}


More information about the Mercurial-devel mailing list