topgit icon indicating copy to clipboard operation
topgit copied to clipboard

non-POSIX usage

Open greenrd opened this issue 11 years ago • 4 comments

local is used, which works in bash and dash but apparently not in ksh, which is used in OpenBSD.

It's pretty silly not to have a way of declaring local variables (because POSIX hasn't standardised that feature) so I propose either moving to

#!/bin/bash

or rewriting TopGit in a better language. I haven't decided which option to take yet.

greenrd avatar Apr 07 '13 18:04 greenrd

On Sun, Apr 07, 2013 at 11:42:18AM -0700, Robin Green wrote:

local is used, which works in bash and dash but apparently not in ksh, which is used in OpenBSD.

It's pretty silly not to have a way of declaring local variables (because POSIX hasn't standardised that feature) so I propose either moving to

#!/bin/bash

or rewriting TopGit in a better language. I haven't decided which option to take yet.

Hi Robin,

Does typeset do what you want? The default aliases on OpenBSD include local=typeset, which indicates that it does. And here's a test:

$ cat ttypeset.sh #!/bin/ksh A=foo echo Outside the function A=$A thefunction () { typeset A A=bar echo Inside thefunction A=$A } thefunction2 () { A=baz echo Inside thefunction2 A=$A } thefunction echo Outside again, A=$A thefunction2 echo Outside again, A=$A

$ /bin/ksh ttypeset.sh Outside the function A=foo Inside thefunction A=bar Outside again, A=foo Inside thefunction2 A=baz Outside again, A=baz $

And OpenBSD's sed is different to GNU sed. Here is the first change I've had to make to get it going:

diff --git a/tg-info.sh b/tg-info.sh index 0ff82d1..fcf1dbf 100644 --- a/tg-info.sh +++ b/tg-info.sh @@ -20,7 +20,7 @@ while [ -n "$1" ]; do esac done

-[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/(heads|top-bases)/##')" +[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed -E 's#^refs/(heads|top-bases)/##')" base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" || die "not a TopGit-controlled branch"

OpenBSD's sed(1) refers to re_format(7), which says that for basic regular expressions

"|',+', and `?' are ordinary characters and there is no equivalent for their functionality."

So it seems there's no way to do `|' without extended RE syntax, hence the -E above.

There doesn't seem to be anything in topgit to detect OS types, eg by inspecting "uname -s". Is that something you'd consider adding, instead of changing the implementation language?

I note that if you did change to #!/bin/bash, OpenBSD would still need some customisation as its bash is at /usr/local/bin/bash.

Russell

Russell Steicke

-- Fortune says: Tact, n.: The unsaid part of what you're thinking.

russells avatar Apr 08 '13 14:04 russells

Personally I'd much rather spend my time programming in a cross-platform programming language, so that the platform issues get solved there once and for all.

And as you quite rightly point out, switching to bash isn't enough, because there are actually four languages used in this project: Shell, sed, awk and Makefile, all of which may have incompatibilities between OSs.

I think I will create a topgit2 project, which will be a rewrite in Scala. I know that will distance it from git, but I don't view getting TopGit merged in to git as an important goal.

greenrd avatar Apr 09 '13 20:04 greenrd

Scala is an interesting choice. Would you keep the current approach of topgit, parsing output from git commands, or use the jgit library?

Personally, I think that's a rather heavyweight way to maintain what is really a very thin layer on top of git.

russells avatar Apr 10 '13 11:04 russells

Pull request #34 contains fixes for these issues.

mackyle avatar Apr 11 '14 00:04 mackyle