Re: Cleaning up git user-interface warts

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Thursday, November 16, 2006 - 2:49 pm

Petr Baudis <pasky@suse.cz> writes:


I've been thinking about revamping the style of shell scripts in
git-core Porcelain-ish for some time, and I have a feeling that
now may be a good time to do so, after one feature release is
out and the list is discussing UI improvements.

But before mentioning the specifics, let me mention one tangent.
I recently installed an OpenBSD bochs (it was actually a qemu
image) without knowing much about the way of the land, and after
adjusting myself to necessary glitches (like "make" being called
"gmake" there), I saw git properly built and pass its selftest.
I was pleasantly surprised when I noticed there was no 'bash' on
the system after all that.

I would like to keep it that way.

I'll list things I would want to and not want to change.
Comments from the list are very appreciated.  You can say things
in two ways:

 * I guarantee that the _default_ shell on all sane platforms we
   care about handle this construct correctly, although it was
   not in the original Bourne.  There is no reason to stay away
   from it these days.

or

 * You've stayed away from this construct but now you say you
   feel it is Ok to use it.  Don't.  It would break with the
   shell on my platform (or "it is a bad practice because of
   such and such reasons").

I do not think many people can say the former with authority
unless you have a portability lab (the company I work for used
to be like that and it was an interesting experience to learn
all about irritating implementation differences).  And "POSIX
says shell should behave that way" is _not_ what I want to hear
about.

But the latter should be a lot easier to say, and would be
appreciated because it would help us avoid regressions.

Things I would want to change:

 - One indent level is one tab and the tab-width is eight
   columns.  Some of our scripts tend to use less than eight
   spaces for indentation to avoid line wrapping.

 - More use of shell functions are fine.   Especially if the
   above change makes lines too long, the logic should be
   refactored.

 - It is so 80-ish to follow certain portability and performance
   wisdom.  The following should go:

   . Use "case" when you do not have to use "if test".

   . Avoid ${parameter##word} and friends and use `expr` instead
     to pick a string apart.

   . Avoid "export name=word", write "name=word; export name"
     instead.

   . Avoid ${parameter:-word} and friends when ${parameter-word}
     would do.

Things I do not want to change:

 - The shell scripts should start with #!/bin/sh, not
   #!/bin/bash (nor even worse "#!/usr/bin/env sh").

 - Shell functions are written as "name () { ... }" without 
   "function" noiseword.

 - 'foo && bar || exit' exits with the error code of what
   failed; no need to say 'exit $?'.

 - String equality check for "test" is a single =, not ==. 

 - Do not use locals.

 - Do not use shell arrays.

 - In general, if something does not behave the same way in ksh,
   bash and dash, don't use it (that does not mean these three
   are special; it just means if something is not even portable
   across these three, it is a definite no-no).

I do not think I need to list other common-sense shell idioms in
the latter category (e.g. 'using "test z$name = zexpected" when
we do not know what $name contains' falls into that).

-
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
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Cleaning up git user-interface warts, Carl Worth, (Tue Nov 14, 12:22 pm)
Re: Cleaning up git user-interface warts, Shawn Pearce, (Tue Nov 14, 12:29 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Tue Nov 14, 12:47 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Tue Nov 14, 12:59 pm)
Re: Cleaning up git user-interface warts, Karl , (Tue Nov 14, 1:46 pm)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Tue Nov 14, 1:52 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Tue Nov 14, 1:56 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Tue Nov 14, 2:10 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 3:36 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 3:50 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 5:31 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Tue Nov 14, 9:08 pm)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Tue Nov 14, 9:32 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 9:33 pm)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Tue Nov 14, 9:46 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 10:35 pm)
Re: Cleaning up git user-interface warts, Shawn Pearce, (Tue Nov 14, 11:18 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Tue Nov 14, 11:30 pm)
Re: Cleaning up git user-interface warts, Andy Parkins, (Wed Nov 15, 2:17 am)
Re: Cleaning up git user-interface warts, Andreas Ericsson, (Wed Nov 15, 5:15 am)
Re: Cleaning up git user-interface warts, Johannes Schindelin, (Wed Nov 15, 7:01 am)
Re: Cleaning up git user-interface warts, Sean, (Wed Nov 15, 8:03 am)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Wed Nov 15, 8:10 am)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Wed Nov 15, 8:41 am)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Wed Nov 15, 10:55 am)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Wed Nov 15, 10:59 am)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Wed Nov 15, 11:11 am)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Wed Nov 15, 11:16 am)
Re: Cleaning up git user-interface warts, Andy Parkins, (Wed Nov 15, 12:02 pm)
Re: Cleaning up git user-interface warts, Andy Parkins, (Wed Nov 15, 12:14 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Wed Nov 15, 12:41 pm)
Re: Cleaning up git user-interface warts, Nicolas Pitre, (Wed Nov 15, 1:15 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Wed Nov 15, 1:19 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Wed Nov 15, 1:39 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Wed Nov 15, 1:51 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Wed Nov 15, 2:13 pm)
Re: Cleaning up git user-interface warts, Carl Worth, (Wed Nov 15, 3:36 pm)
Re: Cleaning up git user-interface warts, Han-Wen Nienhuys, (Wed Nov 15, 5:23 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Wed Nov 15, 8:21 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Wed Nov 15, 8:53 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Wed Nov 15, 10:12 pm)
Re: Cleaning up git user-interface warts, Robin Rosenberg, (Thu Nov 16, 3:09 am)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Thu Nov 16, 3:45 am)
Re: Cleaning up git user-interface warts, Karl , (Thu Nov 16, 6:21 am)
Re: Cleaning up git user-interface warts, Petr Baudis, (Thu Nov 16, 6:43 am)
Re: Cleaning up git user-interface warts, Petr Baudis, (Thu Nov 16, 6:46 am)
Re: Cleaning up git user-interface warts, Petr Baudis, (Thu Nov 16, 6:58 am)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Thu Nov 16, 2:49 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Thu Nov 16, 3:20 pm)
Re: Cleaning up git user-interface warts, Han-Wen Nienhuys, (Thu Nov 16, 5:11 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Thu Nov 16, 6:49 pm)
Re: Cleaning up git user-interface warts, Steven Grimm, (Fri Nov 17, 1:30 pm)
Re: Cleaning up git user-interface warts, Junio C Hamano, (Fri Nov 17, 2:35 pm)
Re: Cleaning up git user-interface warts, Petr Baudis, (Fri Nov 17, 3:07 pm)
Re: Cleaning up git user-interface warts, Alan Chandler, (Sat Nov 18, 12:59 am)
Re: Cleaning up git user-interface warts, Alan Chandler, (Sat Nov 18, 4:09 am)