[PATCH] Enable bisect --command to run shell scripts
Jonathan Watt
jwatt at jwatt.org
Fri Feb 13 22:24:47 CST 2009
# HG changeset patch
# User Jonathan Watt <jwatt at jwatt.org>
# Date 1234585428 -46800
# Node ID b7c73fc4fdf8198c908594d9df570f192cba8e39
# Parent 9f73bddb9d0bf1531523f4b328e8ae0de1247f09
Enable bisect --command to run shell scripts. Issue1512.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -7,16 +7,20 @@
from node import hex, nullid, nullrev, short
from i18n import _, gettext
import os, re, sys
import hg, util, revlog, bundlerepo, extensions, copies, context, error
import difflib, patch, time, help, mdiff, tempfile, url
import archival, changegroup, cmdutil, hgweb.server, sshserver, hbisect
import merge as merge_
+try:
+ import subprocess
+except ImportError:
+ pass
# Commands start here, listed alphabetically
def add(ui, repo, *pats, **opts):
"""add the specified files on the next commit
Schedule files to be version controlled and added to the repository.
@@ -326,17 +330,21 @@ def bisect(ui, repo, rev=None, extra=Non
state = hbisect.load_state(repo)
if command:
commandpath = util.find_exe(command)
changesets = 1
try:
while changesets:
# update state
- status = os.spawnl(os.P_WAIT, commandpath)
+ if 'subprocess' in globals(): # false for python 2.3
+ status = subprocess.call(commandpath)
+ else:
+ # this doesn't run shell scripts well
+ status = os.spawnl(os.P_WAIT, commandpath)
if status == 125:
transition = "skip"
elif status == 0:
transition = "good"
# status < 0 means process was killed
elif status == 127:
raise util.Abort(_("failed to execute %s") % command)
elif status < 0:
diff --git a/setup.py b/setup.py
old mode 100644
new mode 100755
diff --git a/tests/test-bisect3 b/tests/test-bisect3
new file mode 100755
--- /dev/null
+++ b/tests/test-bisect3
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# This test tests the -c option of the bisect command
+
+set -e
+
+echo % init
+hg init
+
+echo % committing changes
+count=0
+echo > a
+while test $count -lt 7 ; do
+ echo 'a' >> a
+ test $count -eq 0 && hg add
+ test $count -eq 4 && echo 'b' >> a
+ hg ci -m "msg $count" -d "$count 0"
+ echo % committed changeset $count
+ count=`expr $count + 1`
+done
+
+echo % log
+hg log
+
+echo % hg up -C
+hg up -C
+
+echo % create shell script for bisect\'s -c argument
+echo '#!/bin/sh
+if [ "`grep b a`" != "" ]; then
+ exit 1
+fi
+exit 0
+'> test.sh
+chmod +x test.sh
+
+echo % bisect test
+hg bisect -r
+hg bisect -g 0
+hg bisect -b 4
+hg bisect -c ./test.sh
diff --git a/tests/test-bisect3.out b/tests/test-bisect3.out
new file mode 100644
--- /dev/null
+++ b/tests/test-bisect3.out
@@ -0,0 +1,59 @@
+% init
+% committing changes
+adding a
+% committed changeset 0
+% committed changeset 1
+% committed changeset 2
+% committed changeset 3
+% committed changeset 4
+% committed changeset 5
+% committed changeset 6
+% log
+changeset: 6:91c1d25b4c96
+tag: tip
+user: test
+date: Thu Jan 01 00:00:06 1970 +0000
+summary: msg 6
+
+changeset: 5:ca9609849f9a
+user: test
+date: Thu Jan 01 00:00:05 1970 +0000
+summary: msg 5
+
+changeset: 4:959d92ae435d
+user: test
+date: Thu Jan 01 00:00:04 1970 +0000
+summary: msg 4
+
+changeset: 3:b53bea5e2fcb
+user: test
+date: Thu Jan 01 00:00:03 1970 +0000
+summary: msg 3
+
+changeset: 2:db07c04beaca
+user: test
+date: Thu Jan 01 00:00:02 1970 +0000
+summary: msg 2
+
+changeset: 1:5cd978ea5149
+user: test
+date: Thu Jan 01 00:00:01 1970 +0000
+summary: msg 1
+
+changeset: 0:b99c7b9c8e11
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: msg 0
+
+% hg up -C
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% create shell script for bisect's -c argument
+% bisect test
+Testing changeset 2:db07c04beaca (4 changesets remaining, ~2 tests)
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+The first good revision is:
+changeset: 4:959d92ae435d
+user: test
+date: Thu Jan 01 00:00:04 1970 +0000
+summary: msg 4
+
More information about the Mercurial-devel
mailing list