* [RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run".
@ 2007-05-01 9:31 Christian Couder
2007-05-01 9:44 ` Uwe Kleine-König
0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2007-05-01 9:31 UTC (permalink / raw)
To: Junio Hamano; +Cc: git
Something like:
$ git bisect run ! grep string my_file
does not work right now, probably because '!' is a shell keyword.
(This simple script shows the problem:
$ echo "#"\!"/bin/sh" > ./simple_test.sh
$ echo "echo \"running:\" \"\$@\"" >> ./simple_test.sh
$ echo "\"\$@\"" >> ./simple_test.sh
$ chmod +x ./simple_test.sh
$ ./simple_test.sh ! grep foo bar.txt
running: ! grep foo bar.txt
./simple_test.sh: line 3: !: command not found
)
This patch tries to work around this problem by counting how
many bangs are passed at the beginning of the "bisect run"
argument list and adding them back when evaluating "$@".
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
git-bisect.sh | 25 +++++++++++++++++++++++--
t/t6030-bisect-porcelain.sh | 9 +++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/git-bisect.sh b/git-bisect.sh
index 1cd4561..f4ce199 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -307,10 +307,31 @@ bisect_replay () {
bisect_run () {
bisect_next_check fail
+ # Count '!' because they need special code.
+ bang_count=0
+ while [ "$1" == '!' ]
+ do
+ bang_count=$(expr $bang_count + 1)
+ shift
+ done
+ test $bang_count -gt 0 && bang_modulo=$(expr $bang_count % 2)
+
+ # Bisect loop.
while true
do
- echo "running $@"
- "$@"
+ # Run the command/script passed as argument.
+ if [ $bang_count -eq 0 ]; then
+ echo "running $@"
+ "$@"
+ else
+ if [ $bang_modulo -eq 0 ]; then
+ echo "running ! ( ! $@ )"
+ ! ( ! "$@" )
+ else
+ echo "running ! $@"
+ ! "$@"
+ fi
+ fi
res=$?
# Check for really bad run error.
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 30f6ade..56fd645 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -99,6 +99,15 @@ test_expect_success \
grep "$HASH4 is first bad commit" my_bisect_log.txt &&
git bisect reset'
+# We again want to automatically find the commit that
+# introduced "Ciao" into hello.
+test_expect_success \
+ '"git bisect run" with bang in argument' \
+ 'git bisect start $HASH4 $HASH1 &&
+ git bisect run ! grep Ciao hello > my_bisect_log.txt &&
+ grep "$HASH4 is first bad commit" my_bisect_log.txt &&
+ git bisect reset'
+
#
#
test_done
--
1.5.2.rc0.71.g4342-dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run".
2007-05-01 9:31 [RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run" Christian Couder
@ 2007-05-01 9:44 ` Uwe Kleine-König
0 siblings, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2007-05-01 9:44 UTC (permalink / raw)
To: Christian Couder; +Cc: Junio Hamano, git
Hallo Christian,
> Something like:
>
> $ git bisect run ! grep string my_file
>
> does not work right now, probably because '!' is a shell keyword.
I didn't check you patch in deep, but you should consider that the
special meaning of "!" isn't implemented in the original Bourne
Shell[1].
IIRC this or something similar was brought up some time ago and the
result was, that your script has to do the negation if needed.
Best regards
Uwe
[1] login@~ > uname -a
SunOS login 5.10 Generic_118833-36 sun4u sparc
login@~ > /bin/sh -c "! true"
/bin/sh: !: not found
--
Uwe Kleine-König
cal 9 1752 | grep 10
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run".
@ 2007-05-01 12:17 Christian Couder
0 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2007-05-01 12:17 UTC (permalink / raw)
To: Uwe Kleine-König, Junio Hamano; +Cc: git
Something like:
$ git bisect run ! grep string my_file
does not work right now probably because '!' is a shell keyword.
(This simple script shows the problem:
$ echo "#"\!"/bin/sh" > ./simple_test.sh
$ echo "echo \"running:\" \"\$@\"" >> ./simple_test.sh
$ echo "\"\$@\"" >> ./simple_test.sh
$ chmod +x ./simple_test.sh
$ ./simple_test.sh ! grep foo bar.txt
running: ! grep foo bar.txt
./simple_test.sh: line 3: !: command not found
)
This patch tries to work around this problem by counting how
many bangs are passed at the beginning of the "bisect run"
argument list and changing the exit code accordingly.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Hallo Uwe,
Le mardi 1 mai 2007 11:44, Uwe Kleine-König a écrit :
> Hallo Christian,
>
> I didn't check you patch in deep, but you should consider that the
> special meaning of "!" isn't implemented in the original Bourne
> Shell[1].
You are right.
> IIRC this or something similar was brought up some time ago and the
> result was, that your script has to do the negation if needed.
You mean something like this ?
Thanks,
Christian.
git-bisect.sh | 19 +++++++++++++++++++
t/t6030-bisect-porcelain.sh | 9 +++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/git-bisect.sh b/git-bisect.sh
index 1cd4561..0c40fc9 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -307,12 +307,31 @@ bisect_replay () {
bisect_run () {
bisect_next_check fail
+ # Count '!' because they need special code.
+ bang_count=0
+ while [ "$1" == '!' ]
+ do
+ bang_count=$(expr $bang_count + 1)
+ shift
+ done
+ test $bang_count -gt 0 && bang_modulo=$(expr $bang_count % 2)
+
+ # Bisect loop.
while true
do
echo "running $@"
"$@"
res=$?
+ # Change res depending on bang count.
+ if [ $bang_count -gt 0 ]; then
+ if [ $bang_modulo -eq 0 ]; then
+ test $res -gt 0 && res=1
+ else
+ test $res -eq 0 && res=1 || res=0
+ fi
+ fi
+
# Check for really bad run error.
if [ $res -lt 0 -o $res -ge 128 ]; then
echo >&2 "bisect run failed:"
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 30f6ade..56fd645 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -99,6 +99,15 @@ test_expect_success \
grep "$HASH4 is first bad commit" my_bisect_log.txt &&
git bisect reset'
+# We again want to automatically find the commit that
+# introduced "Ciao" into hello.
+test_expect_success \
+ '"git bisect run" with bang in argument' \
+ 'git bisect start $HASH4 $HASH1 &&
+ git bisect run ! grep Ciao hello > my_bisect_log.txt &&
+ grep "$HASH4 is first bad commit" my_bisect_log.txt &&
+ git bisect reset'
+
#
#
test_done
--
1.5.2.rc0.71.g4342-dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-05-01 12:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 9:31 [RFC/PATCH] Bisect: add special treatment for bangs passed to "bisect run" Christian Couder
2007-05-01 9:44 ` Uwe Kleine-König
-- strict thread matches above, loose matches on Subject: below --
2007-05-01 12:17 Christian Couder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).