threads / patch / 8599

patchmake guilt use standard POSIX shell

Subject: [PATCH guilt] make guilt use standard POSIX shell

## tl;dr

22 messages between Jun 14, 2007 and Jun 15, 2007. Diffs are folded; open one to read it.

replies: 21people: 4as markdown or json

Pierre Habouzit· Jun 14, 2007, 12:50 UTC · lore
This patch series makes guilt be able to work with a standard posix shell.
This has been tested with bash, zsh, dash and posh acting as /bin/sh.

This uses awk and sed a bit more than before, but POSIX awk and sed should be enough. Though GNU find and GNU /bin/echo from the coreutils needs to be there.

Here is the shortlog:
	Pierre Habouzit (7):
		  Regression test suite needs bash, that's OK.
		  guilt(1): Obvious bashisms fixed.
		  guilt(1): simplifications...
		  guilt(1): reimplement push_patch, using a subshell to avoid locals.
		  Easy commands, without bashisms.
		  guilt-status(1): Remove bashisms.
		  Remove last bashisms from remaining commands.
and the diffstat:
	 guilt                       |  448 +++++++++++++++++++------------------------
	 guilt-add                   |    7 +-
	 guilt-applied               |    4 +-
	 guilt-delete                |    4 +-
	 guilt-export                |    6 +-
	 guilt-files                 |    6 +-
	 guilt-fold                  |    4 +-
	 guilt-fork                  |    6 +-
	 guilt-graph                 |   13 +-
	 guilt-header                |    4 +-
	 guilt-help                  |    6 +-
	 guilt-import                |    6 +-
	 guilt-import-commit         |    6 +-
	 guilt-init                  |    4 +-
	 guilt-new                   |   15 +-
	 guilt-next                  |    6 +-
	 guilt-patchbomb             |   10 +-
	 guilt-pop                   |    4 +-
	 guilt-prev                  |    4 +-
	 guilt-push                  |   16 +-
	 guilt-rebase                |    4 +-
	 guilt-refresh               |    4 +-
	 guilt-rm                    |    4 +-
	 guilt-series                |    6 +-
	 guilt-status                |   58 +++---
	 guilt-top                   |    4 +-
	 guilt-unapplied             |   12 +-
	 regression/010-init.sh      |    1 +
	 regression/011-no-repo.sh   |    1 +
	 regression/020-push.sh      |    1 +
	 regression/021-pop.sh       |    1 +
	 regression/022-applied.sh   |    1 +
	 regression/023-top.sh       |    1 +
	 regression/024-unapplied.sh |    1 +
	 regression/025-new.sh       |    1 +
	 regression/026-delete.sh    |    1 +
	 regression/027-refresh.sh   |    1 +
	 regression/050-series.sh    |    1 +
	 regression/060-files.sh     |    1 +
	 regression/Makefile         |    2 +-
	 uninstall                   |    7 +-
	 41 files changed, 317 insertions(+), 375 deletions(-)
Pierre Habouzit· Jun 14, 2007, 12:50 UTC · re: Pierre Habouzit · lore

[PATCH] Regression test suite needs bash, that's OK.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 regression/010-init.sh      |    1 +
 regression/011-no-repo.sh   |    1 +
 regression/020-push.sh      |    1 +
 regression/021-pop.sh       |    1 +
 regression/022-applied.sh   |    1 +
 regression/023-top.sh       |    1 +
 regression/024-unapplied.sh |    1 +
 regression/025-new.sh       |    1 +
 regression/026-delete.sh    |    1 +
 regression/027-refresh.sh   |    1 +
 regression/050-series.sh    |    1 +
 regression/060-files.sh     |    1 +
 regression/Makefile         |    2 +-
 13 files changed, 13 insertions(+), 1 deletions(-)
Show changes to 13 files +13 −1

regression/010-init.sh, regression/011-no-repo.sh, regression/020-push.sh, regression/021-pop.sh, regression/022-applied.sh, regression/023-top.sh, regression/024-unapplied.sh, regression/025-new.sh, regression/026-delete.sh, regression/027-refresh.sh, regression/050-series.sh, regression/060-files.sh, regression/Makefile

diff --git a/regression/010-init.sh b/regression/010-init.sh
index 17c1c16..1553d0c 100755
--- a/regression/010-init.sh
+++ b/regression/010-init.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the init code
 #
diff --git a/regression/011-no-repo.sh b/regression/011-no-repo.sh
index b37a548..fd4f6a5 100755
--- a/regression/011-no-repo.sh
+++ b/regression/011-no-repo.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test that all commands that should fail do indeed fail if the branch was
 # not guilt-init'ed
diff --git a/regression/020-push.sh b/regression/020-push.sh
index 0d49a7e..6242529 100755
--- a/regression/020-push.sh
+++ b/regression/020-push.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the push code
 #
diff --git a/regression/021-pop.sh b/regression/021-pop.sh
index 418a054..e1af856 100755
--- a/regression/021-pop.sh
+++ b/regression/021-pop.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the pop code
 #
diff --git a/regression/022-applied.sh b/regression/022-applied.sh
index 78d00d9..f259bf4 100755
--- a/regression/022-applied.sh
+++ b/regression/022-applied.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the applied code
 #
diff --git a/regression/023-top.sh b/regression/023-top.sh
index d490f14..c486448 100755
--- a/regression/023-top.sh
+++ b/regression/023-top.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the top code
 #
diff --git a/regression/024-unapplied.sh b/regression/024-unapplied.sh
index 368b3cc..ecb0298 100755
--- a/regression/024-unapplied.sh
+++ b/regression/024-unapplied.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the unapplied code
 #
diff --git a/regression/025-new.sh b/regression/025-new.sh
index f17f20e..680f6da 100755
--- a/regression/025-new.sh
+++ b/regression/025-new.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the new code
 #
diff --git a/regression/026-delete.sh b/regression/026-delete.sh
index 7c16b38..07c969a 100755
--- a/regression/026-delete.sh
+++ b/regression/026-delete.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the delete code
 #
diff --git a/regression/027-refresh.sh b/regression/027-refresh.sh
index 4a3270e..704d0b5 100755
--- a/regression/027-refresh.sh
+++ b/regression/027-refresh.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the refresh code
 #
diff --git a/regression/050-series.sh b/regression/050-series.sh
index 437cd2f..eb23540 100755
--- a/regression/050-series.sh
+++ b/regression/050-series.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the series parsing code
 #
diff --git a/regression/060-files.sh b/regression/060-files.sh
index 875f991..915c73a 100755
--- a/regression/060-files.sh
+++ b/regression/060-files.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Test the series parsing code
 #
diff --git a/regression/Makefile b/regression/Makefile
index c538029..3dd9d0e 100644
--- a/regression/Makefile
+++ b/regression/Makefile
@@ -1,3 +1,3 @@
 .PHONY: all
 all:
-	(for x in *.sh ; do sh $$x || exit $?; done)
+	set -e; $(foreach x,$(wildcard *.sh),./$x;)
-- 
1.5.2.1
Pierre Habouzit· Jun 14, 2007, 12:50 UTC · re: Pierre Habouzit · lore

[PATCH] guilt(1): Obvious bashisms fixed.

  + function foo { } -> foo() { }
  + add wrapper for echo -e
  + couple of '[' bashisms
  + get rid of easy local variables to remove
  + avoid cd - (using subshells)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt |  185 ++++++++++++++++++++++++++++++++---------------------------------
 1 files changed, 91 insertions(+), 94 deletions(-)
Show changes to guilt +91 −94
diff --git a/guilt b/guilt
index 2ae76f8..80f3faf 100755
--- a/guilt
+++ b/guilt
@@ -20,7 +20,29 @@ SUBDIRECTORY_OK=1
 
 . git-sh-setup
 
-function guilt_commands
+#
+# Shell library
+#
+
+# echo -e is a bashism, fallback to /bin/echo if the builtin does not supports it
+echo()
+{
+	/bin/echo "$@"
+}
+
+noerr()
+{
+    "$@" 2>/dev/null
+}
+
+silent()
+{
+    "$@" >/dev/null 2>/dev/null
+}
+
+########
+
+guilt_commands()
 {
 	local command
 	for command in $0-*
@@ -32,7 +54,7 @@ function guilt_commands
 	done
 }
 
-if [ `basename $0` = "guilt" ]; then
+if [ "`basename $0`" = "guilt" ]; then
 	# being run as standalone
 
 	# by default, we shouldn't fail
@@ -58,7 +80,7 @@ if [ `basename $0` = "guilt" ]; then
 				esac
 			done
 		fi
-		if [ $cmd ]; then
+		if [ -n "$cmd" ]; then
 			shift
 			exec "$dir/guilt-$cmd" "$@"
 
@@ -96,68 +118,55 @@ fi
 #
 
 # usage: valid_patchname <patchname>
-function valid_patchname
+valid_patchname()
 {
-	[ `echo "$1" | grep -e '^/' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '^\./' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '^\.\./' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '/\./' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '/\.\./' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '/\.$' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '/\.\.$' | wc -l` -gt 0 ] && return 1
-	[ `echo "$1" | grep -e '/$' | wc -l` -gt 0 ] && return 1
-	return 0
+	case "$1" in
+		/*|./*|../*|*/./*|*/../*|*/.|*/..|*/)
+			return 1;;
+		*)
+			return 0;;
+	esac
 }
 
-function get_branch
+get_branch()
 {
 	git-symbolic-ref HEAD | sed -e 's,^refs/heads/,,'
 }
 
-function verify_branch
+verify_branch()
 {
-	local b=$branch
-
 	[ ! -d "$GIT_DIR/patches" ] &&
 		echo "Patches directory doesn't exist, try guilt-init" >&2 &&
 		return 1
-	[ ! -d "$GIT_DIR/patches/$b" ] &&
-		echo "Branch $b is not initialized, try guilt-init" >&2 &&
+	[ ! -d "$GIT_DIR/patches/$branch" ] &&
+		echo "Branch $branch is not initialized, try guilt-init" >&2 &&
 		return 1
-	[ ! -f "$GIT_DIR/patches/$b/series" ] &&
-		echo "Branch $b does not have a series file" >&2 &&
+	[ ! -f "$GIT_DIR/patches/$branch/series" ] &&
+		echo "Branch $branch does not have a series file" >&2 &&
 		return 1
-	[ ! -f "$GIT_DIR/patches/$b/status" ] &&
-		echo "Branch $b does not have a status file" >&2 &&
+	[ ! -f "$GIT_DIR/patches/$branch/status" ] &&
+		echo "Branch $branch does not have a status file" >&2 &&
 		return 1
-	[ -f "$GIT_DIR/patches/$b/applied" ] &&
-		echo "Warning: Branch $b has 'applied' file - guilt is not compatible with stgit" >&2 &&
+	[ -f "$GIT_DIR/patches/$branch/applied" ] &&
+		echo "Warning: Branch $branch has 'applied' file - guilt is not compatible with stgit" >&2 &&
 		return 1
 
 	return 0
 }
 
-function get_top
+get_top()
 {
 	tail -1 "$GUILT_DIR/$branch/status" | cut -d: -f 2-
 }
 
-function get_prev
+get_prev()
 {
-	local n=`wc -l < "$GUILT_DIR/$branch/status"`
-	local n=`expr $n - 1`
-
-	local idx=0
-	cat "$GUILT_DIR/$branch/status" | while read p; do
-		idx=`expr $idx + 1`
-		[ $idx -lt $n ] && continue
-		[ $idx -gt $n ] && break
-
-		echo "$p"
-	done
+	if [ `wc -l < "$GUILT_DIR/$branch/status"` -gt 1 ]; then
+		tail -n 2 "$GUILT_DIR/$branch/status" | head -n 1
+	fi
 }
 
-function get_series
+get_series()
 {
 	# ignore all lines matching:
 	#	- empty lines
@@ -168,7 +177,7 @@ function get_series
 }
 
 # usage: do_make_header <hash>
-function do_make_header
+do_make_header()
 {
 	# which revision do we want to work with?
 	local rev="$1"
@@ -195,7 +204,7 @@ BEGIN{ok=0}
 }
 
 # usage: do_get_header patchfile
-function do_get_header
+do_get_header()
 {
 	# The complexity arises from the fact that we want to ignore the
 	# From line and the empty line after it if it exists
@@ -212,7 +221,7 @@ END{}
 }
 
 # usage: do_get_full_header patchfile
-function do_get_full_header
+do_get_full_header()
 {
 	# 2nd line checks for the begining of a patch
 	# 3rd line outputs the line if it didn't get pruned by the above rules
@@ -225,37 +234,31 @@ END{}
 }
 
 # usage: assert_head_check
-function assert_head_check
+assert_head_check()
 {
-	local eh=`tail -1 < "$applied" | cut -d: -f 1`
-
-	if ! head_check "$eh"; then
+	if ! head_check "`tail -1 < "$applied" | cut -d: -f 1`"; then
 		die "aborting..."
 	fi
-
-	return 0
 }
 
 # usage: head_check <expected hash>
-function head_check
+head_check()
 {
 	# make sure we're not doing funky things to commits that don't
 	# belong to us
-	local ch=`cat "$GIT_DIR/refs/heads/$branch"`
-
 	# if the expected hash is empty, just return
 	[ -z "$1" ] && return 0
 
-	if [ "$ch" != "$1" ]; then
+	if [ "`cat "$GIT_DIR/refs/heads/$branch"`" != "$1" ]; then
 		echo "Expected HEAD commit $1" >&2
-		echo "                 got $ch" >&2
+		echo "                 got `cat "$GIT_DIR/refs/heads/$branch"`" >&2
 		return 1
 	fi
 	return 0
 }
 
 # usage: series_insert_patch <patchname>
-function series_insert_patch
+series_insert_patch()
 {
 	local top=`get_top | sed -e 's,/,\\\\/,g'`
 	local new=`echo "$1" | sed -e 's,/,\\\\/,g'` 
@@ -271,14 +274,14 @@ function series_insert_patch
 }
 
 # usage: series_remove_patch <patchname>
-function series_remove_patch
+series_remove_patch()
 {
 	grep -v "^$1\$" < "$series" > "$series.tmp"
 	mv "$series.tmp" "$series"
 }
 
 # usage: series_rename_patch <oldname> <newname>
-function series_rename_patch
+series_rename_patch()
 {
 	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
 	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
@@ -290,7 +293,7 @@ function series_rename_patch
 # file directly
 #
 # usage: applied_rename_patch <oldname> <newname>
-function applied_rename_patch
+applied_rename_patch()
 {
 	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
 	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
@@ -299,33 +302,32 @@ function applied_rename_patch
 }
 
 # usage: pop_many_patches <commitish> <number of patches>
-function pop_many_patches
+pop_many_patches()
 {
 	assert_head_check
 
+	(
 	cd "$TOP_DIR"
 
 	git-reset --hard "$1" > /dev/null
 	head -n "-$2" < "$applied" > "$applied.tmp"
 	mv "$applied.tmp" "$applied"
-
-	cd - 2>&1 >/dev/null
+	)
 
 	# update references to top, bottom, and base
 	update_stack_tags
 }
 
 # usage: pop_all_patches
-function pop_all_patches
+pop_all_patches()
 {
-	local x=`head -1 "$applied" | cut -d: -f1`
-	local n=`wc -l < "$applied"`
-
-	pop_many_patches $x^ $n
+	pop_many_patches \
+		`head -1 "$applied" | cut -d: -f1`^ \
+		`wc -l < "$applied"`
 }
 
 # usage: update_stack_tags
-function update_stack_tags
+update_stack_tags()
 {
 	# bail if autotagging is not enabled
 	if [ $autotag -eq 0 ]; then
@@ -336,13 +338,9 @@ function update_stack_tags
 		# there are patches applied, therefore we must get the top,
 		# bottom and base hashes, and update the tags
 
-		local top_hash=`git-rev-parse HEAD`
-		local bottom_hash=`head -1 < $applied | cut -d: -f1`
-		local base_hash=`git-rev-parse $bottom_hash^`
-
-		echo $top_hash > "$GIT_DIR/refs/tags/${branch}_top"
-		echo $bottom_hash > "$GIT_DIR/refs/tags/${branch}_bottom"
-		echo $base_hash > "$GIT_DIR/refs/tags/${branch}_base"
+                git-rev-parse HEAD > "$GIT_DIR/refs/tags/${branch}_top"
+                head -1 < $applied | cut -d: -f1 > "$GIT_DIR/refs/tags/${branch}_bottom"
+		git-rev-parse $(head -1 < $applied | cut -d: -f1)^ > "$GIT_DIR/refs/tags/${branch}_base"
 	else
 		# there are no patches applied, therefore we must remove the
 		# tags to old top, bottom, and base
@@ -354,7 +352,7 @@ function update_stack_tags
 }
 
 # usage: push_patch patchname [bail_action]
-function push_patch
+push_patch()
 {
 	local p="$GUILT_DIR/$branch/$1"
 	local pname="$1"
@@ -459,54 +457,53 @@ function push_patch
 }
 
 # usage: must_commit_first
-function must_commit_first
+must_commit_first()
 {
 	[ `git-diff-files | wc -l` -eq 0 ]
 	return $?
 }
 
 # usage: fold_patch patchname
-function fold_patch
+fold_patch()
 {
-	local top_patch=`get_top`
+	set -- "$1" "`get_top`"
 
 	assert_head_check
 
 	push_patch "$1"
 
-	__refresh_patch "$top_patch" HEAD^^ 2
+	__refresh_patch "$2" HEAD^^ 2
 
 	series_remove_patch "$1"
 }
 
 # usage: refresh_patch patchname
-function refresh_patch
+refresh_patch()
 {
 	__refresh_patch "$1" HEAD^ 1
 }
 
 # usage: __refresh_patch patchname commitish number_of_commits
-function __refresh_patch
+__refresh_patch()
 {
-	local p="$GUILT_DIR/$branch/$1"
-
 	assert_head_check
 
-	cd "$TOP_DIR"
-
-	git-diff-files --name-only | (while read n; do git-update-index "$n" ; done)
+	(
+		cd "$TOP_DIR"
+			p="$GUILT_DIR/$branch/$1"
 
-	# get the patch header
-	do_get_full_header "$p" > /tmp/guilt.diff.$$
+		git-diff-files --name-only | (while read n; do git-update-index "$n" ; done)
 
-	# get the new patch
-	git-diff "$2" >> /tmp/guilt.diff.$$
+		# get the patch header
+		do_get_full_header "$p" > /tmp/guilt.diff.$$
 
-	# move the new patch in
-	mv "$p" "$p~"
-	mv /tmp/guilt.diff.$$ $p
+		# get the new patch
+		git-diff "$2" >> /tmp/guilt.diff.$$
 
-	cd - 2>&1 >/dev/null
+		# move the new patch in
+		mv "$p" "$p~"
+		mv /tmp/guilt.diff.$$ $p
+	)
 
 	# drop the currently applied patch, pop_many_patches does it's own
 	# cd $TOP_DIR
@@ -525,7 +522,7 @@ function __refresh_patch
 #	<hash1>..<hash2>	- from hash to hash (inclusive)
 #
 # The output of this function is suitable to be passed to git-rev-list
-function munge_hash_range
+munge_hash_range()
 {
 	[ -z "$1" ] && return 1
 
-- 
1.5.2.1
Josef Sipek· Jun 14, 2007, 15:15 UTC · re: Pierre Habouzit · lore

Re: [PATCH] guilt(1): Obvious bashisms fixed.

On Thu, Jun 14, 2007 at 02:50:57PM +0200, Pierre Habouzit wrote:
Show 5 quoted lines
>   + function foo { } -> foo() { }
>   + add wrapper for echo -e
>   + couple of '[' bashisms
>   + get rid of easy local variables to remove
>   + avoid cd - (using subshells)
... 
Just a small nit-pick :)
Show 5 quoted lines
> diff --git a/guilt b/guilt
> index 2ae76f8..80f3faf 100755
> --- a/guilt
> +++ b/guilt
> @@ -20,7 +20,29 @@ SUBDIRECTORY_OK=1
...
Show 10 quoted lines
> +guilt_commands()
>  {
>  	local command
>  	for command in $0-*
> @@ -32,7 +54,7 @@ function guilt_commands
>  	done
>  }
>  
> -if [ `basename $0` = "guilt" ]; then
> +if [ "`basename $0`" = "guilt" ]; then
You added quotes here - that's ok....
>  	# being run as standalone
>  
>  	# by default, we shouldn't fail
> @@ -58,7 +80,7 @@ if [ `basename $0` = "guilt" ]; then
But did not add them here.... :)
Josef "Jeff" Sipek.
-- 
A CRAY is the only computer that runs an endless loop in just 4 hours...
Pierre Habouzit· Jun 14, 2007, 15:18 UTC · re: Josef Sipek · lore

Re: [PATCH] guilt(1): Obvious bashisms fixed.

On Thu, Jun 14, 2007 at 11:15:12AM -0400, Josef Sipek wrote:
Show 35 quoted lines
> On Thu, Jun 14, 2007 at 02:50:57PM +0200, Pierre Habouzit wrote:
> >   + function foo { } -> foo() { }
> >   + add wrapper for echo -e
> >   + couple of '[' bashisms
> >   + get rid of easy local variables to remove
> >   + avoid cd - (using subshells)
> .... 
> 
> Just a small nit-pick :)
> 
> > diff --git a/guilt b/guilt
> > index 2ae76f8..80f3faf 100755
> > --- a/guilt
> > +++ b/guilt
> > @@ -20,7 +20,29 @@ SUBDIRECTORY_OK=1
> ....
> > +guilt_commands()
> >  {
> >  	local command
> >  	for command in $0-*
> > @@ -32,7 +54,7 @@ function guilt_commands
> >  	done
> >  }
> >  
> > -if [ `basename $0` = "guilt" ]; then
> > +if [ "`basename $0`" = "guilt" ]; then
> 
> You added quotes here - that's ok....
> 
> >  	# being run as standalone
> >  
> >  	# by default, we shouldn't fail
> > @@ -58,7 +80,7 @@ if [ `basename $0` = "guilt" ]; then
> 
> But did not add them here.... :)
  heh, I tried my best, I've no automated tool for that, only my eyes
and thise code will break iff `basename $0` has spaces in it, which is
rather crazy anyways. But you're welcome to add the missing ones *sigh*
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Jun 14, 2007, 12:50 UTC · re: Pierre Habouzit · lore

[PATCH] guilt(1): simplifications...

  + using awk to avoid local variables
  + more clever with sed
  + reimplement munge_hash_range with case
  and some whitespace problems.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt |  132 ++++++++++++++++++++++++++++-------------------------------------
 1 files changed, 57 insertions(+), 75 deletions(-)
Show changes to guilt +57 −75
diff --git a/guilt b/guilt
index 80f3faf..44273f3 100755
--- a/guilt
+++ b/guilt
@@ -44,14 +44,7 @@ silent()
 
 guilt_commands()
 {
-	local command
-	for command in $0-*
-	do
-		if [ -f "$command" -a -x "$command" ]
-		then
-			echo ${command##$0-}
-		fi
-	done
+	find "`dirname $0`" -maxdepth 1 -name "guilt-*" -type f -perm /111 | sed -e "s/.*\\/`basename $0`-//"
 }
 
 if [ "`basename $0`" = "guilt" ]; then
@@ -97,9 +90,7 @@ if [ "`basename $0`" = "guilt" ]; then
 	echo "Guilt v$GUILT_VERSION"
 	echo ""
 	echo "Pick a command:"
-	for x in `dirname $0`/guilt-*; do
-		[ -x $x ] && echo -e ${x##$0-}
-	done | sort | column | column -t | sed -e $'s/^/\t/'
+	guilt_commands | sort | column | column -t | sed -e 's/^/\t/'
 
 	echo ""
 	echo "Example:"
@@ -173,34 +164,29 @@ get_series()
 	#	- whitespace only
 	#	- optional whitespace followed by '#' followed by more
 	#	  optional whitespace
-	grep -ve '^[[:space:]]*\(#.*\)*$' < "$series"
+	grep -ve '^[[:space:]]*\(#.*\)*$' "$series"
 }
 
 # usage: do_make_header <hash>
 do_make_header()
 {
-	# which revision do we want to work with?
-	local rev="$1"
-
 	# we should try to work with commit objects only
-	if [ `git-cat-file -t "$rev"` != "commit" ]; then
-		echo "Hash $rev is not a commit object" >&2
+	if [ `git-cat-file -t "$1"` != "commit" ]; then
+		echo "Hash $1 is not a commit object" >&2
 		echo "Aborting..." >&2
 		exit 2
 	fi
 
-	# get the author line from the commit object
-	local author=`git-cat-file -p "$rev" | grep -e '^author ' | head -1`
-
-	# strip the timestamp & '^author ' string
-	author=`echo "$author" | sed -e 's/^author //' -e 's/ [0-9]* [+-]*[0-9][0-9]*$//'`
-
-	git-cat-file -p "$rev" | awk "
-BEGIN{ok=0}
-(ok==1){print \$0; print \"\nFrom: $author\"; ok=2; next}
-(ok==2){print \$0}
-/^\$/ && (ok==0){ok=1}
-"
+	git-cat-file -p "$1" | sed -e \
+		'1,/^$/ {
+			/^author/ {
+				s/^author /From: /
+				s/ [0-9]* [+-]*[0-9][0-9]*$//
+				p
+			}
+			/^$/p
+			d
+		}'
 }
 
 # usage: do_get_header patchfile
@@ -260,17 +246,12 @@ head_check()
 # usage: series_insert_patch <patchname>
 series_insert_patch()
 {
-	local top=`get_top | sed -e 's,/,\\\\/,g'`
-	local new=`echo "$1" | sed -e 's,/,\\\\/,g'` 
-
-	if [ ! -z "$top" ]; then
-		sed -i -e "s/^$top\$/$top\n$new/" "$series"
-	else
-		# don't use $new here as it would only complicate things
-		echo "$1" > "$series.tmp"
-		cat "$series" >> "$series.tmp"
-		mv "$series.tmp" "$series"
-	fi
+	awk -v top="`get_top`" -v new="$1" '{
+			if (top == "" && NR == 1) print new;
+			print $0;
+			if (top != "" && top == $0) print new;
+		}' "$series" > "$series.tmp"
+	mv "$series.tmp" "$series"
 }
 
 # usage: series_remove_patch <patchname>
@@ -283,10 +264,11 @@ series_remove_patch()
 # usage: series_rename_patch <oldname> <newname>
 series_rename_patch()
 {
-	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
-	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
+	awk -v old="$1" -v new="$2" \
+		'{ if ($0 == old) print new; else print $0 }' \
+		"$series.tmp" > "$series"
 
-	sed -i -e "s/^$old\$/$new/" "$series"
+	mv "$series.tmp" "$series"
 }
 
 # Beware! This is one of the few (only?) places where we modify the applied
@@ -295,10 +277,15 @@ series_rename_patch()
 # usage: applied_rename_patch <oldname> <newname>
 applied_rename_patch()
 {
-	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
-	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
+	awk -v old="$1" -v new="$2" \
+			'BEGIN{FS=":"}
+			{ if ($1 ~ /^[0-9a-f]*$/ && length($1) == 40 && substr($0, 42) == old)
+				print substr($0, 0, 41) new;
+			else
+				print;
+			}' "$applied" > "$applied.new"
 
-	sed -i -e "s/^\\([0-9a-f]\\{40\\}\\):$old\$/\\1:$new/" "$applied"
+	mv "$applied.tmp" "$applied"
 }
 
 # usage: pop_many_patches <commitish> <number of patches>
@@ -307,11 +294,11 @@ pop_many_patches()
 	assert_head_check
 
 	(
-	cd "$TOP_DIR"
+		cd "$TOP_DIR"
 
-	git-reset --hard "$1" > /dev/null
-	head -n "-$2" < "$applied" > "$applied.tmp"
-	mv "$applied.tmp" "$applied"
+		git-reset --hard "$1" > /dev/null
+		head -n "-$2" < "$applied" > "$applied.tmp"
+		mv "$applied.tmp" "$applied"
 	)
 
 	# update references to top, bottom, and base
@@ -490,7 +477,7 @@ __refresh_patch()
 
 	(
 		cd "$TOP_DIR"
-			p="$GUILT_DIR/$branch/$1"
+		p="$GUILT_DIR/$branch/$1"
 
 		git-diff-files --name-only | (while read n; do git-update-index "$n" ; done)
 
@@ -524,30 +511,25 @@ __refresh_patch()
 # The output of this function is suitable to be passed to git-rev-list
 munge_hash_range()
 {
-	[ -z "$1" ] && return 1
-
-	local l=`echo "$1" | sed -e 's/\.\./ /'`
-
-	local h1=`echo "$l" | cut -s -d' ' -f 1`
-	local h2=`echo "$l" | cut -s -d' ' -f 2`
-
-	if [ -z "$h1" -a -z "$h2" ]; then
-		# e.g., "v0.19"
-		echo "$l^..$l"
-	elif [ -z "$h1" ]; then
-		# e.g., "..v0.10"
-		echo "$h2"
-	elif [ -z "$h2" ]; then
-		# e.g., "v0.19.."
-		echo "$h1..HEAD"
-	elif [ ! -z "$h1" -a ! -z "$h2" ]; then
-		# e.g., "v0.19-rc1..v0.19"
-		echo "$h1..$h2"
-	else
-		# unknown hash range format
-		return 1
-	fi
-
+	case "$1" in
+		*..*..*|*\ *)
+			# double .. or space is illegal
+			return 1;;
+		..*)
+			# e.g., "..v0.10"
+			echo ${1#..};;
+		*..)
+			# e.g., "v0.19.."
+			echo ${1%..}..HEAD;;
+		*..*)
+			# e.g., "v0.19-rc1..v0.19"
+			echo ${1%%..*}..${1#*..};;
+		?*)
+			# e.g., "v0.19"
+			echo $1^..$1;;
+		*)  # empty
+			return 1;;
+	esac
 	return 0
 }
 
-- 
1.5.2.1
Josef Sipek· Jun 14, 2007, 14:58 UTC · re: Pierre Habouzit · lore

Re: [PATCH] guilt(1): simplifications...

On Thu, Jun 14, 2007 at 02:50:58PM +0200, Pierre Habouzit wrote:
Show 5 quoted lines
>   + using awk to avoid local variables
>   + more clever with sed
>   + reimplement munge_hash_range with case
> 
>   and some whitespace problems.
Few tiny comments.
Thanks for the patches.
... 
Show 37 quoted lines
>  # usage: do_make_header <hash>
>  do_make_header()
>  {
> -	# which revision do we want to work with?
> -	local rev="$1"
> -
>  	# we should try to work with commit objects only
> -	if [ `git-cat-file -t "$rev"` != "commit" ]; then
> -		echo "Hash $rev is not a commit object" >&2
> +	if [ `git-cat-file -t "$1"` != "commit" ]; then
> +		echo "Hash $1 is not a commit object" >&2
>  		echo "Aborting..." >&2
>  		exit 2
>  	fi
>  
> -	# get the author line from the commit object
> -	local author=`git-cat-file -p "$rev" | grep -e '^author ' | head -1`
> -
> -	# strip the timestamp & '^author ' string
> -	author=`echo "$author" | sed -e 's/^author //' -e 's/ [0-9]* [+-]*[0-9][0-9]*$//'`
> -
> -	git-cat-file -p "$rev" | awk "
> -BEGIN{ok=0}
> -(ok==1){print \$0; print \"\nFrom: $author\"; ok=2; next}
> -(ok==2){print \$0}
> -/^\$/ && (ok==0){ok=1}
> -"
> +	git-cat-file -p "$1" | sed -e \
> +		'1,/^$/ {
> +			/^author/ {
> +				s/^author /From: /
> +				s/ [0-9]* [+-]*[0-9][0-9]*$//
> +				p
> +			}
> +			/^$/p
> +			d
> +		}'
You changed the output slightly. The original awk script outputed:
>>>>>
the first line of the commit message
From: foo@....

remainder of the commit message <<<<<

Yours outputs:
>>>>>
From: foo@....

the entire commit message <<<<<

I'd like to keep the previous format as it makes it easier to grab the first line of each patch file to get the "short summary" (assuming you follow the kernel/git/guilt commit message conventions). This doesn't make anything in guilt easier, it just makes the patch files more friendly to other tools one might use. (Especially if they grab the first line and use it as the subject in emails.)

Show 33 quoted lines
> @@ -260,17 +246,12 @@ head_check()
>  # usage: series_insert_patch <patchname>
>  series_insert_patch()
>  {
> -	local top=`get_top | sed -e 's,/,\\\\/,g'`
> -	local new=`echo "$1" | sed -e 's,/,\\\\/,g'` 
> -
> -	if [ ! -z "$top" ]; then
> -		sed -i -e "s/^$top\$/$top\n$new/" "$series"
> -	else
> -		# don't use $new here as it would only complicate things
> -		echo "$1" > "$series.tmp"
> -		cat "$series" >> "$series.tmp"
> -		mv "$series.tmp" "$series"
> -	fi
> +	awk -v top="`get_top`" -v new="$1" '{
> +			if (top == "" && NR == 1) print new;
> +			print $0;
> +			if (top != "" && top == $0) print new;
> +		}' "$series" > "$series.tmp"
> +	mv "$series.tmp" "$series"
>  }
>  
>  # usage: series_remove_patch <patchname>
> @@ -283,10 +264,11 @@ series_remove_patch()
>  # usage: series_rename_patch <oldname> <newname>
>  series_rename_patch()
>  {
> -	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
> -	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
> +	awk -v old="$1" -v new="$2" \
> +		'{ if ($0 == old) print new; else print $0 }' \
> +		"$series.tmp" > "$series"
 
Shouldn't that be '"$series" > "$series.tmp"' ?
Show 18 quoted lines
> -	sed -i -e "s/^$old\$/$new/" "$series"
> +	mv "$series.tmp" "$series"
>  }
>  
>  # Beware! This is one of the few (only?) places where we modify the applied
> @@ -295,10 +277,15 @@ series_rename_patch()
>  # usage: applied_rename_patch <oldname> <newname>
>  applied_rename_patch()
>  {
> -	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
> -	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
> +	awk -v old="$1" -v new="$2" \
> +			'BEGIN{FS=":"}
> +			{ if ($1 ~ /^[0-9a-f]*$/ && length($1) == 40 && substr($0, 42) == old)
> +				print substr($0, 0, 41) new;
> +			else
> +				print;
> +			}' "$applied" > "$applied.new"
                                                 ^^^^
> -	sed -i -e "s/^\\([0-9a-f]\\{40\\}\\):$old\$/\\1:$new/" "$applied"
> +	mv "$applied.tmp" "$applied"
                    ^^^^
.new or .tmp?
Josef "Jeff" Sipek.
-- 
The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.
		- George Bernard Shaw
Pierre Habouzit· Jun 14, 2007, 15:16 UTC · re: Josef Sipek · lore

Re: [PATCH] guilt(1): simplifications...

On Thu, Jun 14, 2007 at 10:58:45AM -0400, Josef Sipek wrote:
> On Thu, Jun 14, 2007 at 02:50:58PM +0200, Pierre Habouzit wrote:
Show 62 quoted lines
> >  # usage: do_make_header <hash>
> >  do_make_header()
> >  {
> > -	# which revision do we want to work with?
> > -	local rev="$1"
> > -
> >  	# we should try to work with commit objects only
> > -	if [ `git-cat-file -t "$rev"` != "commit" ]; then
> > -		echo "Hash $rev is not a commit object" >&2
> > +	if [ `git-cat-file -t "$1"` != "commit" ]; then
> > +		echo "Hash $1 is not a commit object" >&2
> >  		echo "Aborting..." >&2
> >  		exit 2
> >  	fi
> >  
> > -	# get the author line from the commit object
> > -	local author=`git-cat-file -p "$rev" | grep -e '^author ' | head -1`
> > -
> > -	# strip the timestamp & '^author ' string
> > -	author=`echo "$author" | sed -e 's/^author //' -e 's/ [0-9]* [+-]*[0-9][0-9]*$//'`
> > -
> > -	git-cat-file -p "$rev" | awk "
> > -BEGIN{ok=0}
> > -(ok==1){print \$0; print \"\nFrom: $author\"; ok=2; next}
> > -(ok==2){print \$0}
> > -/^\$/ && (ok==0){ok=1}
> > -"
> > +	git-cat-file -p "$1" | sed -e \
> > +		'1,/^$/ {
> > +			/^author/ {
> > +				s/^author /From: /
> > +				s/ [0-9]* [+-]*[0-9][0-9]*$//
> > +				p
> > +			}
> > +			/^$/p
> > +			d
> > +		}'
> 
> You changed the output slightly. The original awk script outputed:
> 
> >>>>>
> the first line of the commit message
> 
> From: foo@....
> 
> remainder of the commit message
> <<<<<
> 
> Yours outputs:
> 
> >>>>>
> From: foo@....
> 
> the entire commit message
> <<<<<
> 
> I'd like to keep the previous format as it makes it easier to grab the first
> line of each patch file to get the "short summary" (assuming you follow the
> kernel/git/guilt commit message conventions). This doesn't make anything in
> guilt easier, it just makes the patch files more friendly to other tools one
> might use. (Especially if they grab the first line and use it as the subject
> in emails.)
  damn, I thought I had checked that thouroughly, I'll see that in
details then. and will give you a new patch.
Show 37 quoted lines
> > @@ -283,10 +264,11 @@ series_remove_patch()
> >  # usage: series_rename_patch <oldname> <newname>
> >  series_rename_patch()
> >  {
> > -	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
> > -	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
> > +	awk -v old="$1" -v new="$2" \
> > +		'{ if ($0 == old) print new; else print $0 }' \
> > +		"$series.tmp" > "$series"
>  
> Shouldn't that be '"$series" > "$series.tmp"' ?
> 
> > -	sed -i -e "s/^$old\$/$new/" "$series"
> > +	mv "$series.tmp" "$series"
> >  }
> >  
> >  # Beware! This is one of the few (only?) places where we modify the applied
> > @@ -295,10 +277,15 @@ series_rename_patch()
> >  # usage: applied_rename_patch <oldname> <newname>
> >  applied_rename_patch()
> >  {
> > -	local old=`echo "$1" | sed -e 's,/,\\\\/,g'`
> > -	local new=`echo "$2" | sed -e 's,/,\\\\/,g'` 
> > +	awk -v old="$1" -v new="$2" \
> > +			'BEGIN{FS=":"}
> > +			{ if ($1 ~ /^[0-9a-f]*$/ && length($1) == 40 && substr($0, 42) == old)
> > +				print substr($0, 0, 41) new;
> > +			else
> > +				print;
> > +			}' "$applied" > "$applied.new"
>                                                  ^^^^
> 
> > -	sed -i -e "s/^\\([0-9a-f]\\{40\\}\\):$old\$/\\1:$new/" "$applied"
> > +	mv "$applied.tmp" "$applied"
>                     ^^^^
> 
> ..new or .tmp?
  Those are obvious blatant mistakes. THe fixes will be available in the
coming patch as well.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Jun 14, 2007, 12:50 UTC · re: Pierre Habouzit · lore

[PATCH] guilt(1): reimplement push_patch, using a subshell to avoid locals.

  this is a bit ugly, but makes the code really shorter, and more readable
anyway. We still need the old bail variable, named __push_patch_bail to
avoid spurious collisions (we are not recursing into ourselves, so it's
safe).
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt |  133 ++++++++++++++++++++++++-----------------------------------------
 1 files changed, 49 insertions(+), 84 deletions(-)
Show changes to guilt +49 −84
diff --git a/guilt b/guilt
index 44273f3..f77c050 100755
--- a/guilt
+++ b/guilt
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
@@ -341,106 +341,71 @@ update_stack_tags()
 # usage: push_patch patchname [bail_action]
 push_patch()
 {
-	local p="$GUILT_DIR/$branch/$1"
-	local pname="$1"
-	local bail_action="$2"
+	__push_patch_bail=0
 
-	local bail=0
-	local reject="--reject"
-
-	assert_head_check
-
-	cd "$TOP_DIR"
+	(
+		p="$GUILT_DIR/$branch/$1"
+		pname="$1"
+		bail_action="$2"
+		reject="--reject"
 
-	# apply the patch if and only if there is something to apply
-	if [ `git-apply --numstat "$p" | wc -l` -gt 0 ]; then
-		if [ "$bail_action" = abort ]; then
-		    reject=""
-		fi
-		git-apply -C$guilt_push_diff_context \
-			$reject "$p" > /dev/null 2> /tmp/guilt.log.$$
-		bail=$?
+		assert_head_check
+		cd "$TOP_DIR"
 
-		if [ $bail -ne 0 ]; then
-			cat /tmp/guilt.log.$$ >&2
+		# apply the patch if and only if there is something to apply
+		if [ `git-apply --numstat "$p" | wc -l` -gt 0 ]; then
 			if [ "$bail_action" = abort ]; then
-				return $bail
+				reject=""
+			fi
+			git-apply -C$guilt_push_diff_context \
+				$reject "$p" > /dev/null 2> /tmp/guilt.log.$$
+			__push_patch_bail=$?
+
+			if [ $__push_patch_bail -ne 0 ]; then
+				cat /tmp/guilt.log.$$ >&2
+				if [ "$bail_action" = "abort" ]; then
+					rm -f /tmp/guilt.log.$$ /tmp/guilt.msg.$$
+					return $__push_patch_bail
+				fi
 			fi
-		fi
-
-		# FIXME: Path munging is being done, we need to convince
-		# git-apply to just give us list of files with \0 as a
-		# delimiter, and pass -z to git-update-index
-		git-apply --numstat "$p" | cut -f 3- | git-update-index --add --remove --stdin
-	fi
 
-	# grab a commit message out of the patch
-	do_get_header "$p" > /tmp/guilt.msg.$$
+			# FIXME: Path munging is being done, we need to convince
+			# git-apply to just give us list of files with \0 as a
+			# delimiter, and pass -z to git-update-index
+			git-apply --numstat "$p" | cut -f 3- | git-update-index --add --remove --stdin
+		fi
 
-	# make a default commit message if patch doesn't contain one
-	[ ! -s /tmp/guilt.msg.$$ ] && echo "patch $pname" > /tmp/guilt.msg.$$
+		# grab a commit message out of the patch
+		do_get_header "$p" > /tmp/guilt.msg.$$
 
-	# extract a From line from the patch header, and set
-	# GIT_AUTHOR_{NAME,EMAIL}
-	local author_str=`cat "$p" | grep -e '^From: ' | sed -e 's/^From: //'`
-	if [ ! -z "$author_str" ]; then
-		local backup_author_name="$GIT_AUTHOR_NAME"
-		local backup_author_email="$GIT_AUTHOR_EMAIL"
-		GIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'`
-		GIT_AUTHOR_EMAIL=`echo $author_str | sed -e 's/[^<]*//'`
+		# make a default commit message if patch doesn't contain one
+		[ ! -s /tmp/guilt.msg.$$ ] && echo "patch $pname" > /tmp/guilt.msg.$$
 
-		if [ -z "$GIT_AUTHOR_NAME" ]; then
-			GIT_AUTHOR_NAME=" "
+		# extract a From line from the patch header, and set
+		# GIT_AUTHOR_{NAME,EMAIL}
+		author_str=`sed -n -e '/^From:/ { s/^From: //; p; q }' "$p"`
+		if [ ! -z "$author_str" ]; then
+			GIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'`
+			export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-" "}"
+                        export GIT_AUTHOR_EMAIL="`echo $author_str | sed -e 's/[^<]*//'`"
 		fi
+		export GIT_AUTHOR_DATE="`stat -c %y "$p"`"
+		export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
 
-		export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
-	fi
-	local backup_author_date="$GIT_AUTHOR_DATE"
-	local backup_committer_date="$GIT_COMMITTER_DATE"
-	export GIT_AUTHOR_DATE=`stat -c %y "$p"`
-	export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE
-
-	# commit
-	local treeish=`git-write-tree`
-	local commitish=`git-commit-tree $treeish -p HEAD < /tmp/guilt.msg.$$`
-	echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
+		# commit
+		treeish=`git-write-tree`
+		commitish=`git-commit-tree $treeish -p HEAD < /tmp/guilt.msg.$$`
+		echo $commitish > $GIT_DIR/`git-symbolic-ref HEAD`
 
-	# mark patch as applied
-	echo "$commitish:$pname" >> $applied
-
-	cd - 2>&1 >/dev/null
+		# mark patch as applied
+		echo "$commitish:$pname" >> $applied
+	)
 
 	# update references to top, bottom, and base of the stack
 	update_stack_tags
 
-	# restore original GIT_AUTHOR_{NAME,EMAIL}
-	if [ ! -z "$author_str" ]; then
-		if [ ! -z "$backup_author_name" ]; then
-			export GIT_AUTHOR_NAME="$backup_author_name"
-		else
-			unset GIT_AUTHOR_NAME
-		fi
-
-		if [ ! -z "$backup_author_name" ]; then
-			export GIT_AUTHOR_EMAIL="$backup_author_email"
-		else
-			unset GIT_AUTHOR_EMAIL
-		fi
-	fi
-	if [ ! -z "$backup_author_date" ]; then
-		export GIT_AUTHOR_DATE="$backup_author_date"
-	else
-		unset GIT_AUTHOR_DATE
-	fi
-		if [ ! -z "$backup_committer_date" ]; then
-		export GIT_COMMITTER_DATE="$backup_committer_date"
-	else
-		unset GIT_COMMITTER_DATE
-	fi
-
 	rm -f /tmp/guilt.msg.$$ /tmp/guilt.log.$$
-
-	return $bail
+	return $__push_patch_bail
 }
 
 # usage: must_commit_first
-- 
1.5.2.1
Pierre Habouzit· Jun 14, 2007, 12:51 UTC · re: Pierre Habouzit · lore

[PATCH] Easy commands, without bashisms.

  Just move to /bin/sh and use . `dirname $0`/guilt as posh fails else.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt-applied |    4 ++--
 guilt-delete  |    4 ++--
 guilt-fold    |    4 ++--
 guilt-header  |    4 ++--
 guilt-init    |    4 ++--
 guilt-pop     |    4 ++--
 guilt-prev    |    4 ++--
 guilt-rebase  |    4 ++--
 guilt-refresh |    4 ++--
 guilt-rm      |    4 ++--
 guilt-top     |    4 ++--
 11 files changed, 22 insertions(+), 22 deletions(-)
Show changes to 11 files +22 −22

guilt-applied, guilt-delete, guilt-fold, guilt-header, guilt-init, guilt-pop, guilt-prev, guilt-rebase, guilt-refresh, guilt-rm, guilt-top

diff --git a/guilt-applied b/guilt-applied
index 373e5f7..52f8470 100755
--- a/guilt-applied
+++ b/guilt-applied
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-c]"
-. guilt
+. `dirname $0`/guilt
 
 case $# in
 	0)
diff --git a/guilt-delete b/guilt-delete
index 8649875..1118b00 100755
--- a/guilt-delete
+++ b/guilt-delete
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-f] <patchname>"
-. guilt
+. `dirname $0`/guilt
 
 case $# in
 	1)
diff --git a/guilt-fold b/guilt-fold
index 0d0222b..92fac1a 100755
--- a/guilt-fold
+++ b/guilt-fold
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="<patchname>"
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 1 ]; then
 	usage
diff --git a/guilt-header b/guilt-header
index eb89cfd..d07e2be 100755
--- a/guilt-header
+++ b/guilt-header
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[<patchname>]"
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -gt 1 ]; then
 	usage
diff --git a/guilt-init b/guilt-init
index feacf95..ffe2434 100755
--- a/guilt-init
+++ b/guilt-init
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
@@ -6,7 +6,7 @@
 DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE="[-n]"
-. guilt
+. `dirname $0`/guilt
 
 autotag=1
 
diff --git a/guilt-pop b/guilt-pop
index 2b9c2ec..89ad021 100755
--- a/guilt-pop
+++ b/guilt-pop
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-f] [-a | --all | <patchname>]"
-. guilt
+. `dirname $0`/guilt
 
 while [ $# -gt 0 ]; do
 	case "$1" in
diff --git a/guilt-prev b/guilt-prev
index 5348f88..26e7a51 100755
--- a/guilt-prev
+++ b/guilt-prev
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE=""
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 0 ]; then
 	usage
diff --git a/guilt-rebase b/guilt-rebase
index 823384d..cc8dcf6 100755
--- a/guilt-rebase
+++ b/guilt-rebase
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
@@ -6,7 +6,7 @@
 #
 
 USAGE="<upstream>"
-. guilt
+. `dirname $0`/guilt
 
 case "$#" in
 	1) 
diff --git a/guilt-refresh b/guilt-refresh
index 957f23d..8541484 100755
--- a/guilt-refresh
+++ b/guilt-refresh
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE=""
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 0 ]; then
 	usage
diff --git a/guilt-rm b/guilt-rm
index f0025b4..0ec120d 100755
--- a/guilt-rm
+++ b/guilt-rm
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="<file>..."
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -lt 1 ]; then
 	usage
diff --git a/guilt-top b/guilt-top
index 3d407e8..8004f10 100755
--- a/guilt-top
+++ b/guilt-top
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE=""
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 0 ]; then
 	usage
-- 
1.5.2.1
Pierre Habouzit· Jun 14, 2007, 12:51 UTC · re: Pierre Habouzit · lore

[PATCH] guilt-status(1): Remove bashisms.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt-status |   58 ++++++++++++++++++++++++++++------------------------------
 1 files changed, 28 insertions(+), 30 deletions(-)
Show changes to guilt-status +28 −30
diff --git a/guilt-status b/guilt-status
index 934ea53..bc2f33e 100755
--- a/guilt-status
+++ b/guilt-status
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-a|-A] [-c|-C] [-d|-D] [-m|-M] [-r|-R] [-t|-T] [-u|-U] [-x|-X] [-n]"
-. guilt
+. `dirname $0`/guilt
 
 untracked=""
 DIFF_FILTER=""
@@ -53,7 +53,7 @@ fi
 
 git-rev-parse --verify HEAD >/dev/null 2>&1 || IS_INITIAL=t
 
-function print_status
+print_status()
 {
 	if [ -z "$no_prefix" ] ; then
 		Apfx="A "
@@ -81,34 +81,32 @@ function print_status
 	done
 }
 
-cd "$TOP_DIR"
-
 (
-# untracked; FIXME: there's got to be a better way
-if [ ! -z "$untracked" ]; then
-	if [ -f "$GIT_DIR/info/exclude" ]; then
-		git-ls-files -z --others \
-		--exclude-from="$GIT_DIR/info/exclude" \
-		--exclude-per-directory=.gitignore
-	else
-		git-ls-files -z --others --exclude-per-directory=.gitignore
-	fi | xargs -0 -L 1 echo | while read n; do
-		[ -z "$n" ] && continue
-		echo "$n" | sed -e "s/^/?\t/"
-	done
-fi
+	cd "$TOP_DIR"
+	# untracked; FIXME: there's got to be a better way
+	if [ ! -z "$untracked" ]; then
+		if [ -f "$GIT_DIR/info/exclude" ]; then
+			git-ls-files -z --others \
+			--exclude-from="$GIT_DIR/info/exclude" \
+			--exclude-per-directory=.gitignore
+		else
+			git-ls-files -z --others --exclude-per-directory=.gitignore
+		fi | xargs -0 -L 1 echo | while read n; do
+			[ -z "$n" ] && continue
+			echo "$n" | sed -e "s/^/?\t/"
+		done
+	fi
 
-# added
-if [ -z "$IS_INITIAL" ]; then
-	# non-initial commit
-	git-diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
-else
-	# initial commit
-	git-ls-files | sed -e "s/^/A\t/"
-fi | sed -e '
-	s/\\/\\\\/g
-	s/ /\\ /g
-'
+	# added
+	if [ -z "$IS_INITIAL" ]; then
+		# non-initial commit
+		git-diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
+	else
+		# initial commit
+		git-ls-files | sed -e "s/^/A\t/"
+	fi | sed -e '
+		s/\\/\\\\/g
+		s/ /\\ /g
+	'
 ) | print_status
 
-cd - 2>&1 >/dev/null
-- 
1.5.2.1
Pierre Habouzit· Jun 14, 2007, 12:51 UTC · re: Pierre Habouzit · lore

[PATCH] Remove last bashisms from remaining commands.

  Especially also simplify the (quite sloppy) loops to extract ranges of
lines, use sed -n -e '<min>,<max>p' for that.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt-add           |    7 +++----
 guilt-export        |    6 +++---
 guilt-files         |    6 +++---
 guilt-fork          |    6 +++---
 guilt-graph         |   13 +++++++------
 guilt-help          |    6 +++---
 guilt-import        |    6 +++---
 guilt-import-commit |    6 +++---
 guilt-new           |   15 ++++++++-------
 guilt-next          |    6 +++---
 guilt-patchbomb     |   10 +++++-----
 guilt-push          |   16 ++++++----------
 guilt-series        |    6 +++---
 guilt-unapplied     |   12 +++---------
 uninstall           |    7 ++-----
 15 files changed, 58 insertions(+), 70 deletions(-)
Show changes to 15 files +58 −70

guilt-add, guilt-export, guilt-files, guilt-fork, guilt-graph, guilt-help, guilt-import, guilt-import-commit, guilt-new, guilt-next, guilt-patchbomb, guilt-push, guilt-series, guilt-unapplied, uninstall

diff --git a/guilt-add b/guilt-add
index fd1e716..ebf41e4 100755
--- a/guilt-add
+++ b/guilt-add
@@ -1,14 +1,13 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="<file>..."
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -lt 1 ]; then
 	usage
 fi
 
-git-add -- "$@"
-
+exec git-add -- "$@"
diff --git a/guilt-export b/guilt-export
index 444ccdf..2c0a9fd 100755
--- a/guilt-export
+++ b/guilt-export
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Pierre Habouzit, 2007
 #
 
 USAGE="[<target_dir>]"
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -gt 1 ]; then
 	usage
@@ -19,7 +19,7 @@ trap "rm -rf \"$target_dir\"" 0
 mkdir -p "$target_dir"
 
 get_series | tee "$target_dir/series" | while read p; do
-	mkdir -p "`dirname $target_dir/$p`" 2> /dev/null || true
+	silent mkdir -p "`dirname $target_dir/$p`" || true
 	cp "$GUILT_DIR/$branch/$p" "$target_dir/$p"
 done
 
diff --git a/guilt-files b/guilt-files
index bc06f39..3428be4 100755
--- a/guilt-files
+++ b/guilt-files
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (C) 2007 Yasushi SHOJI <yashi@atmark-techno.com>
 #
 
 USAGE="[-v] [-a] [-l]"
-. guilt
+. `dirname $0`/guilt
 
 opt_verbose=
 opt_all=
@@ -26,7 +26,7 @@ do
 done
 
 IFS=:
-if [ $opt_all ]; then
+if [ -n "$opt_all" ]; then
 	cat $applied
 else
 	tail -1 $applied
diff --git a/guilt-fork b/guilt-fork
index 426a7e7..32b31dc 100755
--- a/guilt-fork
+++ b/guilt-fork
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
 
 USAGE="[<new_name>]"
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -gt 1 ]; then
 	usage
@@ -28,7 +28,7 @@ else
 		| sed -r -e 's:(\.diff?|\.patch)$::')
 	num=$(echo "$base" | sed -nre 's:.*-([0-9]+)$:\1:'p)
 	[ -n "$num" ] || num=1
-	newpatch="${base%-$num}-$((num+1))${patch#$base}"
+	newpatch="${base%-$num}-$(($num+1))${patch#$base}"
 fi
 
 if [ -e "$GUILT_DIR/$branch/$newpatch" ]; then
diff --git a/guilt-graph b/guilt-graph
index 5d67040..0c6b890 100755
--- a/guilt-graph
+++ b/guilt-graph
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
 
 USAGE="[<patchname>]"
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -gt 1 ]; then
 	usage
@@ -24,13 +24,14 @@ else
 	fi
 fi
 
-function getfiles
+getfiles()
 {
 	git-diff-tree -r "$1^" "$1" | tr '\t' ' ' | cut -d' ' -f6
 }
 
 cache="$GUILT_DIR/$branch/.graphcache.$$"
 mkdir "$cache"
+trap "rm -rf \"$cache\"" 0
 
 echo "digraph G {"
 
@@ -39,7 +40,7 @@ current="$top"
 while [ "$current" != "$base" ]; do
 	echo "# checking rev $current"
 
-	echo -n '' > "$cache/dep"
+	touch "$cache/dep"
 
 	getfiles $current | while read f; do
 		# hash the filename
@@ -51,7 +52,7 @@ while [ "$current" != "$base" ]; do
 		echo "$current" > "$cache/$fh"
 	done
 
-	cat "$cache/dep" | sort | uniq | while read h; do
+	sort -u "$cache/dep" | while read h; do
 		echo "	\"${h:0:8}\" -> \"${current:0:8}\"; // ?"
 	done
 
@@ -60,4 +61,4 @@ done
 
 echo "}"
 
-rm -rf "$cache"
+trap - 0
diff --git a/guilt-help b/guilt-help
index 5f867b4..274246b 100755
--- a/guilt-help
+++ b/guilt-help
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
@@ -6,7 +6,7 @@
 DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE="[<command> | <topic>]"
-. guilt
+. `dirname $0`/guilt
 
 case $# in
 	0)
@@ -24,4 +24,4 @@ case $# in
 		;;
 esac
 
-man "$page"
+exec man "$page"
diff --git a/guilt-import b/guilt-import
index 0e4e037..da3ece8 100755
--- a/guilt-import
+++ b/guilt-import
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
 
 USAGE="[-P <patch> ] <patch_file>"
-. guilt
+. `dirname $0`/guilt
 
 case "$1" in
 	-P)
@@ -17,7 +17,7 @@ case "$1" in
 		;;
 esac
 
-if [ $# -lt 1 -o $# -gt 3 -o -z "$newname" -o -z "$oldname" ]; then
+if [ $# -lt 1 ] || [ $# -gt 3 ] || [ -z "$newname" ] || [ -z "$oldname" ]; then
 	usage
 fi
 
diff --git a/guilt-import-commit b/guilt-import-commit
index 47f0dc0..6aa65e5 100755
--- a/guilt-import-commit
+++ b/guilt-import-commit
@@ -1,12 +1,12 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
 
 USAGE="[<hash> | <since>..[<until>] | ..<until>]"
-. guilt
+. `dirname $0`/guilt
 
-if [ $# -ne 1 -o -z "$1" ]; then
+if [ $# -ne 1 ] || [ -z "$1" ]; then
 	die "You must specify a range of commits"
 fi
 
diff --git a/guilt-new b/guilt-new
index 7a89b42..5c7eb39 100755
--- a/guilt-new
+++ b/guilt-new
@@ -1,12 +1,12 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-f] [-s] [-e|-m message] <patchname>"
-. guilt
+. `dirname $0`/guilt
 
-if [ $# -lt 1 -o $# -gt 4 ]; then
+if [ $# -lt 1 ] || [ $# -gt 4 ]; then
 	usage
 fi
 
@@ -80,10 +80,11 @@ mkdir_dir=`dirname "$GUILT_DIR/$branch/$patch"`
 [ "$edit" = "t" ] && $editor "$GUILT_DIR/$branch/$patch"
 
 if [ ! -z "$force" ]; then
-	cd "$TOP_DIR"
-	git-diff HEAD >> "$GUILT_DIR/$branch/$patch"
-	git-reset --hard HEAD > /dev/null
-	cd -
+	(
+		cd "$TOP_DIR"
+		git-diff HEAD >> "$GUILT_DIR/$branch/$patch"
+		git-reset --hard HEAD > /dev/null
+	)
 fi
 
 # insert the patch name into the series file
diff --git a/guilt-next b/guilt-next
index b25c761..f38f1cc 100755
--- a/guilt-next
+++ b/guilt-next
@@ -1,17 +1,17 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE=""
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 0 ]; then
 	usage
 fi
 
 n=`wc -l < $applied`
-n=`expr $n + 1`
+n=$(($n + 1))
 
 get_series | awk "{ if (NR == $n) print \$0}"
 
diff --git a/guilt-patchbomb b/guilt-patchbomb
index c1c3ea0..5001d47 100755
--- a/guilt-patchbomb
+++ b/guilt-patchbomb
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2007
 #
@@ -6,7 +6,7 @@
 DO_NOT_CHECK_BRANCH_EXISTENCE=1
 
 USAGE="[-n] [--in-reply-to <msgid>] [<hash> | <since>..[<until>] | ..<until>]"
-. guilt
+. `dirname $0`/guilt
 
 while [ $# -gt 0 ]; do
 	case "$1" in
@@ -34,7 +34,7 @@ git-log --pretty=oneline "$r" | cut -c 1-8,41- | $pager
 
 echo -n "Are these what you want to send? [Y/n] "
 read n
-if [ "$n" = "n" -o "$n" = "N" ]; then
+if [ "$n" = "n" ] || [ "$n" = "N" ]; then
 	die "Aborting..."
 fi
 
@@ -72,7 +72,7 @@ opts="$opts $to_opts"
 # last possible point to abort!
 echo -n "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
 read n
-if [ "$n" != "y" -a "$n" != "Y" ]; then
+if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
 	die "Aborting..."
 fi
 
@@ -93,5 +93,5 @@ fi
 echo -n "Delete temporary directory? [Y/n] "
 read n
 
-[ "$n" = "n" -o "$n" = "N" ] && exit 0
+[ "$n" = "n" ] || [ "$n" = "N" ] && exit 0
 rm -rf $dir
diff --git a/guilt-push b/guilt-push
index c7d8355..ad3616b 100755
--- a/guilt-push
+++ b/guilt-push
@@ -1,15 +1,15 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[ -f ] [-a | --all | <patchname>]"
-. guilt
+. `dirname $0`/guilt
 
 abort_flag="abort"
 
 
-if [ "$1" == "-f" ]; then
+if [ "$1" = "-f" ]; then
 	abort_flag=""
 	shift
 fi
@@ -20,7 +20,7 @@ fi
 
 patch="$1"
 
-if [ "$patch" = "--all" -o "$patch" = "-a" ]; then
+if [ "$patch" = "--all" ] || [ "$patch" = "-a" ]; then
 	# we are supposed to push all patches, get the last one out of
 	# series
 
@@ -52,12 +52,8 @@ fi
 sidx=`wc -l < $applied`
 sidx=`expr $sidx + 1`
 
-idx=0
-for p in `get_series`; do
-	idx=`expr $idx + 1`
-	[ $idx -lt $sidx ] && continue
-	[ $idx -gt $eidx ] && break
-
+get_series | sed -n -e "${sidx},${eidx}p" | while read p
+do
 	echo "Applying patch..$p"
 	if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
 		die "Patch $patch does not exist. Aborting."
diff --git a/guilt-series b/guilt-series
index af1c8f2..efb11c2 100755
--- a/guilt-series
+++ b/guilt-series
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE="[-v]"
-. guilt
+. `dirname $0`/guilt
 
 while case "$#" in 0) break ;; esac
 do
@@ -17,7 +17,7 @@ do
 	shift
 done
 
-if ! [ $verbose ]; then
+if ! [ -n "$verbose" ]; then
 	get_series
 else
 	prefix="+"
diff --git a/guilt-unapplied b/guilt-unapplied
index 5bbe4d8..192a7e5 100755
--- a/guilt-unapplied
+++ b/guilt-unapplied
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
 #
 
 USAGE=""
-. guilt
+. `dirname $0`/guilt
 
 if [ $# -ne 0 ]; then
 	usage
@@ -13,10 +13,4 @@ fi
 n=`wc -l < $applied`
 n=`expr $n + 1`
 
-idx=0
-for p in `get_series`; do
-	idx=`expr $idx + 1`
-	[ $idx -lt $n ] && continue
-
-	echo $p
-done
+get_series | sed -n -e "$n,\$p"
diff --git a/uninstall b/uninstall
index 54c6d26..9c8a3b7 100755
--- a/uninstall
+++ b/uninstall
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (c) 2007 Nur Hussein <hussein@cs.usm.my>
 #
@@ -12,7 +12,4 @@ PRE=$1
 
 shift
 
-for x in "$@"
-do
-	rm "$PRE/$x"
-done
+(cd $PRE; rm "$@")
-- 
1.5.2.1
Pierre Habouzit· Jun 14, 2007, 13:07 UTC · re: Pierre Habouzit · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 02:50:55PM +0200, Pierre Habouzit wrote:
> This patch series makes guilt be able to work with a standard posix shell.
> 
> This has been tested with bash, zsh, dash and posh acting as /bin/sh.
  By tested I mean that I carefully crafted the changes, and ran make
test with /bin/sh pointing to those shells, and the suite passed.
  Though, we could have /some/ regressions.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Jun 14, 2007, 13:20 UTC · re: Pierre Habouzit · lore

[PATCH] Small regresson when series file is empty.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
Show changes to guilt +3 −2
diff --git a/guilt b/guilt
index f77c050..58df606 100755
--- a/guilt
+++ b/guilt
@@ -246,8 +246,9 @@ head_check()
 # usage: series_insert_patch <patchname>
 series_insert_patch()
 {
-	awk -v top="`get_top`" -v new="$1" '{
-			if (top == "" && NR == 1) print new;
+	awk -v top="`get_top`" -v new="$1" \
+		'BEGIN{if (top == "") print new;}
+		{
 			print $0;
 			if (top != "" && top == $0) print new;
 		}' "$series" > "$series.tmp"
-- 
1.5.2.1
Josef Sipek· Jun 14, 2007, 15:27 UTC · re: Pierre Habouzit · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 02:50:55PM +0200, Pierre Habouzit wrote:
Show 18 quoted lines
> This patch series makes guilt be able to work with a standard posix shell.
> 
> This has been tested with bash, zsh, dash and posh acting as /bin/sh.
> 
> This uses awk and sed a bit more than before, but POSIX awk and sed should be
> enough. Though GNU find and GNU /bin/echo from the coreutils needs to be
> there.
> 
> Here is the shortlog:
> 
> 	Pierre Habouzit (7):
> 		  Regression test suite needs bash, that's OK.
> 		  guilt(1): Obvious bashisms fixed.
> 		  guilt(1): simplifications...
> 		  guilt(1): reimplement push_patch, using a subshell to avoid locals.
> 		  Easy commands, without bashisms.
> 		  guilt-status(1): Remove bashisms.
> 		  Remove last bashisms from remaining commands.
 
I went though the patches, and it's mostly good (see individual patch
replies for details). I noticed an indentation issue or two, but I can fix
that up easily, I can take care of the quoting of `basename $0`.

The regression suite is little lacking, so I am going to put your updated patches onto a special branch, and test it for a while - fixing up any potential bugs. (I don't want to be even remotely responsible for people's patches turning into empty files :) )

Thanks a lot!
Josef "Jeff" Sipek.
-- 
A CRAY is the only computer that runs an endless loop in just 4 hours...
Pierre Habouzit· Jun 14, 2007, 15:56 UTC · re: Josef Sipek · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 11:27:02AM -0400, Josef Sipek wrote:
Show 23 quoted lines
> On Thu, Jun 14, 2007 at 02:50:55PM +0200, Pierre Habouzit wrote:
> > This patch series makes guilt be able to work with a standard posix shell.
> > 
> > This has been tested with bash, zsh, dash and posh acting as /bin/sh.
> > 
> > This uses awk and sed a bit more than before, but POSIX awk and sed should be
> > enough. Though GNU find and GNU /bin/echo from the coreutils needs to be
> > there.
> > 
> > Here is the shortlog:
> > 
> > 	Pierre Habouzit (7):
> > 		  Regression test suite needs bash, that's OK.
> > 		  guilt(1): Obvious bashisms fixed.
> > 		  guilt(1): simplifications...
> > 		  guilt(1): reimplement push_patch, using a subshell to avoid locals.
> > 		  Easy commands, without bashisms.
> > 		  guilt-status(1): Remove bashisms.
> > 		  Remove last bashisms from remaining commands.
>  
> I went though the patches, and it's mostly good (see individual patch
> replies for details). I noticed an indentation issue or two, but I can fix
> that up easily, I can take care of the quoting of `basename $0`.
  Thanks.
> The regression suite is little lacking, so I am going to put your updated
> patches onto a special branch, and test it for a while - fixing up any
> potential bugs. (I don't want to be even remotely responsible for people's
> patches turning into empty files :) )
  That seems like a very good plan. I just sent the fixes. Hopefully
this should fix major issues right now.
  Interestingly enough, benchmarking for runs with different shells as
/bin/sh show:
  dash: 1.63s user 3.93s system 102% cpu 5.436 total
  posh: 2.02s user 4.29s system 100% cpu 6.260 total
  bash: 2.82s user 5.78s system 104% cpu 8.223 total
  zsh:  3.70s user 5.86s system  99% cpu 9.626 total
  (this is obviously completely not unreliable, but gives some rough
ideas though)
> Thanks a lot!
  Well, worry for the obvious mistakes.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Jun 14, 2007, 15:58 UTC · re: Pierre Habouzit · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 05:56:00PM +0200, Pierre Habouzit wrote:
> On Thu, Jun 14, 2007 at 11:27:02AM -0400, Josef Sipek wrote:
> > Thanks a lot!
> 
>   Well, worry for the obvious mistakes.
         *sorry
  Now, *that* was an interesting typo :P
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Josef Sipek· Jun 14, 2007, 16:39 UTC · re: Pierre Habouzit · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 05:58:26PM +0200, Pierre Habouzit wrote:
Show 8 quoted lines
> On Thu, Jun 14, 2007 at 05:56:00PM +0200, Pierre Habouzit wrote:
> > On Thu, Jun 14, 2007 at 11:27:02AM -0400, Josef Sipek wrote:
> > > Thanks a lot!
> > 
> >   Well, worry for the obvious mistakes.
>          *sorry
> 
>   Now, *that* was an interesting typo :P
:)

Ok, pushed to kernel.org. I folded the 2 regression fixing patches into the right places.

Thanks a lot!
Josef "Jeff" Sipek.
-- 
Linux, n.:
  Generous programmers from around the world all join forces to help
  you shoot yourself in the foot for free. 
Pierre Habouzit· Jun 14, 2007, 17:16 UTC · re: Josef Sipek · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 12:39:40PM -0400, Josef Sipek wrote:
Show 14 quoted lines
> On Thu, Jun 14, 2007 at 05:58:26PM +0200, Pierre Habouzit wrote:
> > On Thu, Jun 14, 2007 at 05:56:00PM +0200, Pierre Habouzit wrote:
> > > On Thu, Jun 14, 2007 at 11:27:02AM -0400, Josef Sipek wrote:
> > > > Thanks a lot!
> > > 
> > >   Well, worry for the obvious mistakes.
> >          *sorry
> > 
> >   Now, *that* was an interesting typo :P
> 
> :)
> 
> Ok, pushed to kernel.org. I folded the 2 regression fixing patches into the
> right places.
  Just a small remark: 87739d0e should be merged in the master branch,
as the regression suite does not work atm if you are using a shell that
does not understands enough bashisms.
  The patch is safe (it only adds /bin/bash shebangs to tests, and
changes the way tests are called in the Makefile).
  For the rest, I agree the patches should continue to live in a
separate branch until better coverage of the testsuite can give us more
faith in those patches :)
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Jun 14, 2007, 15:50 UTC · re: Pierre Habouzit · lore

[PATCH] More regressions fixes.

  + use awk again to parse git-cat-file properly
  + fixes .new -> .tmp (always use the same suffix to avoid problems)
  + write in foo.tmp and move it, and not the reverse :)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 guilt |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
Show changes to guilt +17 −11
diff --git a/guilt b/guilt
index 58df606..7c78cc7 100755
--- a/guilt
+++ b/guilt
@@ -177,16 +177,22 @@ do_make_header()
 		exit 2
 	fi
 
-	git-cat-file -p "$1" | sed -e \
-		'1,/^$/ {
-			/^author/ {
-				s/^author /From: /
-				s/ [0-9]* [+-]*[0-9][0-9]*$//
-				p
+	git-cat-file -p "$1" | awk '
+		BEGIN{headers=1; firstline=1}
+		/^author / && headers {
+			sub(/^author +/, "");
+			sub(/ [0-9]* [+-]*[0-9][0-9]*$/, "");
+			author=$0
+		}
+		!headers {
+			print
+			if (firstline) {
+				firstline = 0;
+				print "\nFrom: " author;
 			}
-			/^$/p
-			d
-		}'
+		}
+		/^$/ && headers { headers = 0 }
+	'
 }
 
 # usage: do_get_header patchfile
@@ -267,7 +273,7 @@ series_rename_patch()
 {
 	awk -v old="$1" -v new="$2" \
 		'{ if ($0 == old) print new; else print $0 }' \
-		"$series.tmp" > "$series"
+		"$series" > "$series.tmp"
 
 	mv "$series.tmp" "$series"
 }
@@ -284,7 +290,7 @@ applied_rename_patch()
 				print substr($0, 0, 41) new;
 			else
 				print;
-			}' "$applied" > "$applied.new"
+			}' "$applied" > "$applied.tmp"
 
 	mv "$applied.tmp" "$applied"
 }
-- 
1.5.2.1
Derek Fawcus· Jun 15, 2007, 08:01 UTC · re: Pierre Habouzit · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On Thu, Jun 14, 2007 at 02:50:55PM +0200, Pierre Habouzit wrote:
> This patch series makes guilt be able to work with a standard posix shell.
> 
> This has been tested with bash, zsh, dash and posh acting as /bin/sh.

Well if you want to try with a 'real' bourne shell, there is always the heirloom sh or the v7 shell...

http://heirloom.sourceforge.net/sh.html http://www.collyer.net/who/geoff/v7sh.tar http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/sh/

DF
Benjamin Sergeant· Jun 15, 2007, 22:31 UTC · re: Derek Fawcus · lore

Re: [PATCH guilt] make guilt use standard POSIX shell

On 6/15/07, Derek Fawcus <dfawcus@cisco.com> wrote:
Show 9 quoted lines
> On Thu, Jun 14, 2007 at 02:50:55PM +0200, Pierre Habouzit wrote:
> > This patch series makes guilt be able to work with a standard posix shell.
> >
> > This has been tested with bash, zsh, dash and posh acting as /bin/sh.
>
> Well if you want to try with a 'real' bourne shell,  there is always the
> heirloom sh or the v7 shell...
>
> http://heirloom.sourceforge.net/sh.html
>From the main page

''' interactive use. The Bourne shell provides job control if it is invoked as jsh and runs on a terminal. Of course, it lacks fancy features such as a command history, command line completion, etc. But working with these features tends to distract the user's attention. After a familiarization phase, use of the Bourne shell can lead to a more even-tempered, concentrated working style. Give it a try. Seriously. '''

I love it. I acknowledge that you have to be fairly well concentrated if you want to type /usr/lib/python2.5/site-packages/spambayes/resources/ (as an example) without missing one char.

:) Benjamin.

Show 9 quoted lines
> http://www.collyer.net/who/geoff/v7sh.tar
> http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/sh/
>
> DF
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

← back to recent threads