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

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 18, 2015, 2:42 p.m.
Message ID <ec875f53f7bdd78b215d.1439908973@mimosa>
Download mbox | patch
Permalink /patch/10223/
State Accepted
Delegated to: Augie Fackler
Headers show

Comments

Yuya Nishihara - Aug. 18, 2015, 2:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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);
 			}
 		}
 	}