Patchwork bisect: improve option validation message

login
register
mail settings
Submitter Brandon McCaig
Date June 14, 2017, 5:51 a.m.
Message ID <20170614055146.GD18212@test-chamber-1.castopulence.org>
Download mbox | patch
Permalink /patch/21368/
State Accepted
Headers show

Comments

Brandon McCaig - June 14, 2017, 5:51 a.m.
On Sun, Jun 11, 2017 at 02:14:28PM +0900, Yuya Nishihara wrote:
> > I’m about to wander away from my laptop for supper, so if
> > you’d rather I push the two patches as one folded-together
> > patch let me know. If I don’t hear anything in the next few
> > hours I’ll just push as-is with two commits.
> 
> Folded them as fbe9c4dcc8a0 "bisect: improve option validation
> message".

I saw that. Thank you!

> Perhaps we can filter out False elements first and just take
> the first two?

That does seem much simpler, and probably more efficient... Feel
free to submit your own patch, but this is I think what you were
suggesting:

# HG changeset patch
# User Brandon McCaig <bamccaig@gmail.com>
# Date 1497419027 14400
#      Wed Jun 14 01:43:47 2017 -0400
# Node ID 630766ecca6c0df1256d25868778722f5e312353
# Parent  e65ff29dbeb02ce08e4a64f381ccd37949354dcf
bisect: Simpler approach for option validation message.

Yuya Nishihara gave this suggestion on the mailing list after the
previous patch was queued, and honestly this seems much simpler and
looks more efficient (I'm not too sure how best to wrap the
format string parameters so I took a guess).


Regards,

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -9,7 +9,6 @@ 
 
 import difflib
 import errno
-import itertools
 import os
 import re
 import sys
@@ -781,9 +780,11 @@ 
         '--skip': skip,
     }
 
-    for left, right in itertools.combinations(sorted(incompatibles), 2):
-        if incompatibles[left] and incompatibles[right]:
-            raise error.Abort(_('%s and %s are incompatible') % (left, right))
+    enabled = [x for x in incompatibles if incompatibles[x]]
+
+    if len(enabled) > 1:
+        raise error.Abort(_('%s and %s are incompatible') %
+                            tuple(sorted(enabled)[0:2]))
 
     if reset:
         hbisect.resetstate(repo)