Patchwork cvsps: add two more tiebreakers in cscmp

login
register
mail settings
Submitter Augie Fackler
Date Aug. 21, 2014, 5:39 p.m.
Message ID <66c426d3330ce065ecac.1408642755@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/5547/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 21, 2014, 5:39 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1408630050 14400
#      Thu Aug 21 10:07:30 2014 -0400
# Node ID 66c426d3330ce065ecacd697218e456c5ebe6a92
# Parent  32a2b293f4920c2c72aa30caa63232717e1439c7
cvsps: add two more tiebreakers in cscmp

test-convert-cvs.t has been a little flaky for a while now. Add an
extra tiebreaker in cscmp so that all the cases in the test will sort
reliably.

Without this patch, test-convert-cvs.t failed after 346 runs. With
this patch, I stopped trying to get it to fail after 615 runs. While
not conclusive, that makes me pretty optimistic that this is a working
fix.
Pierre-Yves David - Aug. 21, 2014, 7:33 p.m.
On 08/21/2014 10:39 AM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1408630050 14400
> #      Thu Aug 21 10:07:30 2014 -0400
> # Node ID 66c426d3330ce065ecacd697218e456c5ebe6a92
> # Parent  32a2b293f4920c2c72aa30caa63232717e1439c7
> cvsps: add two more tiebreakers in cscmp

excellent! Pushed to the clowncopter after some documentation update 
(from Augie)

Patch

diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -631,7 +631,13 @@ 
                     odd.add((l, r))
                 d = -1
                 break
-
+        # recommended replacement for cmp from
+        # https://docs.python.org/3.0/whatsnew/3.0.html
+        c = lambda x, y: (x > y) - (x < y)
+        if not d:
+            d = c(len(l.entries), len(r.entries))
+        if not d:
+            d = c(len(l.branchpoints), len(r.branchpoints))
         return d
 
     changesets.sort(cscmp)