* Add "--git-dir" flag to git-rev-parse
@ 2005-09-18 18:18 Linus Torvalds
2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2005-09-18 18:18 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List
Especially when you're deep inside the git repository, it's not all that
trivial for scripts to figure out where GIT_DIR is if it isn't set.
So add a flag to git-rev-parse to show where it is, since it will have
figured it out anyway.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/rev-parse.c b/rev-parse.c
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -191,6 +191,22 @@ int main(int argc, char **argv)
puts(prefix);
continue;
}
+ if (!strcmp(arg, "--git-dir")) {
+ const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
+ static char cwd[PATH_MAX];
+ if (gitdir) {
+ puts(gitdir);
+ continue;
+ }
+ if (!prefix) {
+ puts(".git");
+ continue;
+ }
+ if (!getcwd(cwd, PATH_MAX))
+ die("unable to get current working directory");
+ printf("%s/.git\n", cwd);
+ continue;
+ }
if (verify)
die("Needed a single revision");
show_flag(arg);
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH] Added -d and -e options to the "git" script.
2005-09-18 18:18 Add "--git-dir" flag to git-rev-parse Linus Torvalds
@ 2005-09-19 10:19 ` David Kågedal
2005-09-19 14:14 ` A Large Angry SCM
2005-09-19 14:42 ` Matthias Urlichs
0 siblings, 2 replies; 7+ messages in thread
From: David Kågedal @ 2005-09-19 10:19 UTC (permalink / raw)
To: git
These flags override the GIT_DIR and EDITOR environment variables.
---
This is more generic way to specify GIT_DIR than Linus' suggestion,
although it is only targeted at more porcelainish usage of the git
driver script.
I needed this for the Emacs commands I've been hacking on, since it's
hard to set environment variables for single commands without
involving /bin/env or a shell.
git.sh | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
b9a38ed5a16289f86b353c0bb541e607d35180a9
diff --git a/git.sh b/git.sh
--- a/git.sh
+++ b/git.sh
@@ -2,19 +2,32 @@
cmd=
path=$(dirname $0)
-case "$#" in
-0) ;;
-*) cmd="$1"
- shift
- case "$cmd" in
- -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
- echo "git version @@GIT_VERSION@@"
- exit 0 ;;
- esac
- test -x $path/git-$cmd && exec $path/git-$cmd "$@" ;;
-esac
-echo "Usage: git COMMAND [OPTIONS] [TARGET]"
+while test "$#" -gt 0
+do
+ case "$1" in
+ -d) export GIT_DIR
+ GIT_DIR=$2
+ shift
+ ;;
+ -e) export EDITOR
+ EDITOR=$2
+ shift
+ ;;
+ *) cmd="$1"
+ shift
+ case "$cmd" in
+ -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+ echo "git version @@GIT_VERSION@@"
+ exit 0 ;;
+ esac
+ test -x $path/git-$cmd && exec $path/git-$cmd "$@"
+ ;;
+ esac
+ shift
+done
+
+echo "Usage: git [GLOBAL OPTIONS] COMMAND [COMMAND OPTIONS]"
if [ -n "$cmd" ]; then
echo " git command '$cmd' not found: commands are:"
else
--
David Kågedal
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] Added -d and -e options to the "git" script.
2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
@ 2005-09-19 14:14 ` A Large Angry SCM
2005-09-19 14:24 ` David Kågedal
2005-09-19 14:42 ` Matthias Urlichs
1 sibling, 1 reply; 7+ messages in thread
From: A Large Angry SCM @ 2005-09-19 14:14 UTC (permalink / raw)
To: David Kågedal; +Cc: git
David Kågedal wrote:
> These flags override the GIT_DIR and EDITOR environment variables.
>
[Patch snipped]
An option for GIT_DIR maybe since it's a Git environment variable but a
command line option to change the EDITOR _environment_ variable is NOT
appropriate for git.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Added -d and -e options to the "git" script.
2005-09-19 14:14 ` A Large Angry SCM
@ 2005-09-19 14:24 ` David Kågedal
2005-09-19 14:42 ` A Large Angry SCM
0 siblings, 1 reply; 7+ messages in thread
From: David Kågedal @ 2005-09-19 14:24 UTC (permalink / raw)
To: git
A Large Angry SCM <gitzilla@gmail.com> writes:
> David Kågedal wrote:
>> These flags override the GIT_DIR and EDITOR environment variables.
>>
> [Patch snipped]
>
> An option for GIT_DIR maybe since it's a Git environment variable but a
> command line option to change the EDITOR _environment_ variable is NOT
> appropriate for git.
Yeah, I should have separated those two so that the GIT_DIR option
could be accepted on its own. And it should maybe have a --git-dir=
log form as well.
The reason I did -e too was simply that I needed it for the same
reason I needed -d. I wanted to run git with specific values for
GIT_DIR and EDITOR without having to setenv them in emacs. But the
EDITOR trick I'm using is a hack and should be replaced anyway. (I use
EDITOR=cat to get access to the default commit message with comments
from 'git commit').
So please disregard the -e part of my patch for now. You are free to
disregard the -d part as well, but I think that makes some kind of
sense.
And If we go down this path, maybe flags for other GIT_* environment
variables should be settable with git command line flags too?
--
David Kågedal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Added -d and -e options to the "git" script.
2005-09-19 14:24 ` David Kågedal
@ 2005-09-19 14:42 ` A Large Angry SCM
2005-09-19 15:08 ` David Kågedal
0 siblings, 1 reply; 7+ messages in thread
From: A Large Angry SCM @ 2005-09-19 14:42 UTC (permalink / raw)
To: David Kågedal; +Cc: git
David Kågedal wrote:
> A Large Angry SCM <gitzilla@gmail.com> writes:
>
>>David Kågedal wrote:
>>>These flags override the GIT_DIR and EDITOR environment variables.
>>>
>>[Patch snipped]
>>
[...]
>
> So please disregard the -e part of my patch for now. You are free to
> disregard the -d part as well, but I think that makes some kind of
> sense.
>
> And If we go down this path, maybe flags for other GIT_* environment
> variables should be settable with git command line flags too?
>
Please no!
There are better methods of setting environment variables than an
endless set of command options. Use the env command or you own
(personal) command wrapper instead.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Added -d and -e options to the "git" script.
2005-09-19 14:42 ` A Large Angry SCM
@ 2005-09-19 15:08 ` David Kågedal
0 siblings, 0 replies; 7+ messages in thread
From: David Kågedal @ 2005-09-19 15:08 UTC (permalink / raw)
To: git
A Large Angry SCM <gitzilla@gmail.com> writes:
> There are better methods of setting environment variables than an
> endless set of command options. Use the env command or you own
> (personal) command wrapper instead.
Remember that, to the user, this isn't about setting environment
variables, It's about providing git parameters.
Currently, the only of doing this is by setting environment variables;
what I'm suggesting is an *alternative* to that.
The fact that the implementation of these flags would actually use
environment variables to propagate these parameters to subprocesses
doesn't necessary mean that it is the only sane way to specify it
originally.
Anyway, there are other options, such as
$ git GIT_DIR=/foo/bar status
and today we already have
$ env GIT_DIR=/foo/bar status
The advantage of these forms is of course that they don't limit the
parameters that can be set, so I could keep setting EDITOR if I want
to. But if setting GIT_DIR is common enough it might make sense to
provide a short flag for that.
The summary of my ramblings are probably that I think the -d flag is a
good idea, but no way of specifying other parameters is needed.
--
David Kågedal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Added -d and -e options to the "git" script.
2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
2005-09-19 14:14 ` A Large Angry SCM
@ 2005-09-19 14:42 ` Matthias Urlichs
1 sibling, 0 replies; 7+ messages in thread
From: Matthias Urlichs @ 2005-09-19 14:42 UTC (permalink / raw)
To: git
Hi, David Kågedal wrote:
> + case "$1" in
> + -e) [...]
> + *) cmd="$1"
> + shift
> + case "$cmd" in
> + -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
Umm, can we please not have two case statements nested like that?
Better written as:
> + case "$1" in
> + -e) [...]
> + -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
> + [print and die]
> + *) cmd="$1"
> + shift
> + test -x $path/git-$cmd && exec $path/git-$cmd "$@"
Thanks.
--
Matthias Urlichs | {M:U} IT Design @ m-u-it.de | smurf@smurf.noris.de
Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de
- -
It is a sad commentary on today's society that this fortune has to be
classified as "offensive" simply because it contains the word "fuck".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-09-19 15:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-18 18:18 Add "--git-dir" flag to git-rev-parse Linus Torvalds
2005-09-19 10:19 ` [PATCH] Added -d and -e options to the "git" script David Kågedal
2005-09-19 14:14 ` A Large Angry SCM
2005-09-19 14:24 ` David Kågedal
2005-09-19 14:42 ` A Large Angry SCM
2005-09-19 15:08 ` David Kågedal
2005-09-19 14:42 ` Matthias Urlichs
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).