Patchwork [v2] bisect: --command without --noupdate should flag the parent rev it tested

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 12, 2014, 6:58 p.m.
Message ID <18a05dd444ccd13af0d8.1389553135@localhost.localdomain>
Download mbox | patch
Permalink /patch/3306/
State Accepted
Commit 0d32dd60016c58dfaf5bd38a975c0d9beb571b16
Headers show

Comments

Mads Kiilerich - Jan. 12, 2014, 6:58 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1384634789 18000
#      Sat Nov 16 15:46:29 2013 -0500
# Node ID 18a05dd444ccd13af0d85d7d64bbf108098043b4
# Parent  9b268bdad001f60131032e5a287aabffcd57699e
bisect: --command without --noupdate should flag the parent rev it tested

14913fcb30c6 not only introduced the 'bisect(current)' revset predicate, it
also changed how the 'current' revision is used in combination with --command.
The new behaviour might be ok for --noupdate where the working directory and
its revision shouldn't be used, but it also did that when --command is used to
run a command on the currently checked out revision then it could register the
test result on the wrong revision.

An example:

Before, bisect with --command could use the wrong revision when recording the
test result:

  $ hg up -qr 0
  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
  changeset 31:58c80a7c8a40: bad
  abort: inconsistent state, 31:58c80a7c8a40 is good and bad

Now it works as before and as expected and uses the working directory revision
for the --command result:

  $ hg up -qr 0
  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
  changeset 0:b99c7b9c8e11: bad
  ...
Pierre-Yves David - Jan. 13, 2014, 6:55 a.m.
Looks good to me.

(The generated diff is a bit confusing, most of it is just reindent.)

On Sun, Jan 12, 2014 at 07:58:55PM +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1384634789 18000
> #      Sat Nov 16 15:46:29 2013 -0500
> # Node ID 18a05dd444ccd13af0d85d7d64bbf108098043b4
> # Parent  9b268bdad001f60131032e5a287aabffcd57699e
> bisect: --command without --noupdate should flag the parent rev it tested
> 
> 14913fcb30c6 not only introduced the 'bisect(current)' revset predicate, it
> also changed how the 'current' revision is used in combination with --command.
> The new behaviour might be ok for --noupdate where the working directory and
> its revision shouldn't be used, but it also did that when --command is used to
> run a command on the currently checked out revision then it could register the
> test result on the wrong revision.
> 
> An example:
> 
> Before, bisect with --command could use the wrong revision when recording the
> test result:
> 
>   $ hg up -qr 0
>   $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
>   changeset 31:58c80a7c8a40: bad
>   abort: inconsistent state, 31:58c80a7c8a40 is good and bad
> 
> Now it works as before and as expected and uses the working directory revision
> for the --command result:
> 
>   $ hg up -qr 0
>   $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
>   changeset 0:b99c7b9c8e11: bad
>   ...
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -667,12 +667,13 @@ def bisect(ui, repo, rev=None, extra=Non
>  
>      if command:
>          changesets = 1
> -        try:
> -            node = state['current'][0]
> -        except LookupError:
> -            if noupdate:
> +        if noupdate:
> +            try:
> +                node = state['current'][0]
> +            except LookupError:
>                  raise util.Abort(_('current bisect revision is unknown - '
>                                     'start a new bisect to fix'))
> +        else:
>              node, p2 = repo.dirstate.parents()
>              if p2 != nullid:
>                  raise util.Abort(_('current bisect revision is a merge'))
> diff --git a/tests/test-bisect.t b/tests/test-bisect.t
> --- a/tests/test-bisect.t
> +++ b/tests/test-bisect.t
> @@ -461,11 +461,14 @@ test bisecting command
>    > EOF
>    $ chmod +x script.py
>    $ hg bisect -r
> -  $ hg bisect --good tip
> -  $ hg bisect --bad 0
> -  Testing changeset 15:e7fa0811edb0 (31 changesets remaining, ~4 tests)
> -  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ hg up -qr tip
>    $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
> +  changeset 31:58c80a7c8a40: good
> +  abort: cannot bisect (no known bad revisions)
> +  [255]
> +  $ hg up -qr 0
> +  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
> +  changeset 0:b99c7b9c8e11: bad
>    changeset 15:e7fa0811edb0: good
>    changeset 7:03750880c6b5: good
>    changeset 3:b53bea5e2fcb: bad
> @@ -516,6 +519,39 @@ ensure that we still don't have a workin
>    $ hg parents
>  
>  
> +test the same case, this time with updating
> +
> +  $ cat > script.sh <<'EOF'
> +  > #!/bin/sh
> +  > test -n "$HG_NODE" || (echo HG_NODE missing; exit 127)
> +  > current="`hg log -r \"bisect(current)\" --template {node}`"
> +  > test "$current" = "$HG_NODE" || (echo current is bad: $current; exit 127)
> +  > rev="`hg log -r . --template {rev}`"
> +  > test "$rev" -ge 6
> +  > EOF
> +  $ chmod +x script.sh
> +  $ hg bisect -r
> +  $ hg up -qr tip
> +  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
> +  changeset 31:58c80a7c8a40: good
> +  abort: cannot bisect (no known bad revisions)
> +  [255]
> +  $ hg up -qr 0
> +  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
> +  changeset 0:b99c7b9c8e11: bad
> +  changeset 15:e7fa0811edb0: good
> +  changeset 7:03750880c6b5: good
> +  changeset 3:b53bea5e2fcb: bad
> +  changeset 5:7874a09ea728: bad
> +  changeset 6:a3d5c6fdf0d3: good
> +  The first good revision is:
> +  changeset:   6:a3d5c6fdf0d3
> +  user:        test
> +  date:        Thu Jan 01 00:00:06 1970 +0000
> +  summary:     msg 6
> +  
> +
> +
>  Check that bisect does not break on obsolete changesets
>  =========================================================
>  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -667,12 +667,13 @@  def bisect(ui, repo, rev=None, extra=Non
 
     if command:
         changesets = 1
-        try:
-            node = state['current'][0]
-        except LookupError:
-            if noupdate:
+        if noupdate:
+            try:
+                node = state['current'][0]
+            except LookupError:
                 raise util.Abort(_('current bisect revision is unknown - '
                                    'start a new bisect to fix'))
+        else:
             node, p2 = repo.dirstate.parents()
             if p2 != nullid:
                 raise util.Abort(_('current bisect revision is a merge'))
diff --git a/tests/test-bisect.t b/tests/test-bisect.t
--- a/tests/test-bisect.t
+++ b/tests/test-bisect.t
@@ -461,11 +461,14 @@  test bisecting command
   > EOF
   $ chmod +x script.py
   $ hg bisect -r
-  $ hg bisect --good tip
-  $ hg bisect --bad 0
-  Testing changeset 15:e7fa0811edb0 (31 changesets remaining, ~4 tests)
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg up -qr tip
   $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
+  changeset 31:58c80a7c8a40: good
+  abort: cannot bisect (no known bad revisions)
+  [255]
+  $ hg up -qr 0
+  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
+  changeset 0:b99c7b9c8e11: bad
   changeset 15:e7fa0811edb0: good
   changeset 7:03750880c6b5: good
   changeset 3:b53bea5e2fcb: bad
@@ -516,6 +519,39 @@  ensure that we still don't have a workin
   $ hg parents
 
 
+test the same case, this time with updating
+
+  $ cat > script.sh <<'EOF'
+  > #!/bin/sh
+  > test -n "$HG_NODE" || (echo HG_NODE missing; exit 127)
+  > current="`hg log -r \"bisect(current)\" --template {node}`"
+  > test "$current" = "$HG_NODE" || (echo current is bad: $current; exit 127)
+  > rev="`hg log -r . --template {rev}`"
+  > test "$rev" -ge 6
+  > EOF
+  $ chmod +x script.sh
+  $ hg bisect -r
+  $ hg up -qr tip
+  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
+  changeset 31:58c80a7c8a40: good
+  abort: cannot bisect (no known bad revisions)
+  [255]
+  $ hg up -qr 0
+  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
+  changeset 0:b99c7b9c8e11: bad
+  changeset 15:e7fa0811edb0: good
+  changeset 7:03750880c6b5: good
+  changeset 3:b53bea5e2fcb: bad
+  changeset 5:7874a09ea728: bad
+  changeset 6:a3d5c6fdf0d3: good
+  The first good revision is:
+  changeset:   6:a3d5c6fdf0d3
+  user:        test
+  date:        Thu Jan 01 00:00:06 1970 +0000
+  summary:     msg 6
+  
+
+
 Check that bisect does not break on obsolete changesets
 =========================================================