Patchwork [2,of,3,stable,V2] ancestor.deepest: decrement ninteresting correctly (issue3984)

login
register
mail settings
Submitter Siddharth Agarwal
Date July 25, 2013, 10:50 p.m.
Message ID <e2b3ff5b507ac825fa64.1374792603@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1965/
State Superseded
Headers show

Comments

Siddharth Agarwal - July 25, 2013, 10:50 p.m.
# HG changeset patch
# User Wei, Elson <elson.wei@gmail.com>
# Date 1374744953 -28800
#      Thu Jul 25 17:35:53 2013 +0800
# Branch stable
# Node ID e2b3ff5b507ac825fa646e49c61696e8d3ca3bcc
# Parent  acd8063547ca3cb47f65140be7930b60fefd9cdc
ancestor.deepest: decrement ninteresting correctly (issue3984)

The invariant this code tries to hold is that ninteresting is the number of
non-zero elements in the interesting array. interesting[nsp] will be
incremented soon, so if it was previously 0, it shouldn't be decremented.
Siddharth Agarwal - July 25, 2013, 10:59 p.m.
On 07/25/2013 03:50 PM, Siddharth Agarwal wrote:

> interesting[nsp] will be
> incremented soon, so if it was previously 0, it shouldn't be decremented.

This can be a bit clearer --

"interesting[nsp] is incremented at the same time as interesting[sp] is 
decremented. So if interesting[nsp] was previously 0, ninteresting 
shouldn't be decremented".

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1362,10 +1362,10 @@ 
 				if (nsp == sp)
 					continue;
 				seen[p] = nsp;
+				interesting[sp] -= 1;
+				if (interesting[sp] == 0 && interesting[nsp] > 0)
+					ninteresting -= 1;
 				interesting[nsp] += 1;
-				interesting[sp] -= 1;
-				if (interesting[sp] == 0)
-					ninteresting -= 1;
 			}
 		}
 		interesting[sv] -= 1;