# Patchwork [2,of,7] ancestors: remove unnecessary handling of 'left'

Submitter Mads Kiilerich Feb. 24, 2014, 10:19 p.m. mbox | patch /patch/3744/ Accepted 4add43865a9be3fe8493901ce6c43507e4539c14 show

Mads Kiilerich - Feb. 24, 2014, 10:19 p.m.
```# HG changeset patch
# Date 1393278133 -3600
#      Mon Feb 24 22:42:13 2014 +0100
# Node ID b4a5e8ed29c32284842d7786dfbb039712fbe24f
# Parent  9f00c23a26e019f70f90b0501b2b8fa587c85292
ancestors: remove unnecessary handling of 'left'

If one of the initial nodes also is an ancestor then that most be the only
ancestor. There is no need for additional bookkeeping.
```

## Patch

```diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -31,7 +31,7 @@
poison = 1 << (i + 1)

gca = set()
-        interesting = left = len(nodes)
+        interesting = len(nodes)
nv = len(seen) - 1
while nv >= 0 and interesting:
v = nv
@@ -45,10 +45,8 @@
sv |= poison
if v in nodes:
-                        left -= 1
-                        if left <= 1:
-                            # history is linear
-                            return set([v])
+                        # history is linear
+                        return set([v])
if sv < poison:
for p in pfunc(v):
sp = seen[p]
diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1208,7 +1208,7 @@
const bitmask allseen = (1ull << revcount) - 1;
const bitmask poison = 1ull << revcount;
PyObject *gca = PyList_New(0);
-	int i, v, interesting, left;
+	int i, v, interesting;
int maxrev = -1;
long sp;
@@ -1230,7 +1230,7 @@
for (i = 0; i < revcount; i++)
seen[revs[i]] = 1ull << i;

-	interesting = left = revcount;
+	interesting = revcount;

for (v = maxrev; v >= 0 && interesting; v--) {
long sv = seen[v];
@@ -1251,11 +1251,8 @@
}
sv |= poison;
for (i = 0; i < revcount; i++) {
-					if (revs[i] == v) {
-						if (--left <= 1)
-							goto done;
-						break;
-					}
+					if (revs[i] == v)
+						goto done;
}
}
}

```