* [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.
@ 2006-10-07 21:04 Martin Waitz
2006-10-07 21:14 ` Jakub Narebski
0 siblings, 1 reply; 4+ messages in thread
From: Martin Waitz @ 2006-10-07 21:04 UTC (permalink / raw)
To: git
They don't really have anything to do with refs.
Signed-off-by: Martin Waitz <tali@admingilde.org>
---
Makefile | 1 +
builtin-show-prefix.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
builtin.h | 3 +++
git.c | 3 +++
4 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index 2c7c338..c072162 100644
--- a/Makefile
+++ b/Makefile
@@ -298,6 +298,7 @@ BUILTIN_OBJS = \
builtin-rm.o \
builtin-runstatus.o \
builtin-show-branch.o \
+ builtin-show-prefix.o \
builtin-stripspace.o \
builtin-symbolic-ref.o \
builtin-tar-tree.o \
diff --git a/builtin-show-prefix.c b/builtin-show-prefix.c
new file mode 100644
index 0000000..ed46434
--- /dev/null
+++ b/builtin-show-prefix.c
@@ -0,0 +1,50 @@
+/*
+ * Show some information about the GIT repository
+ */
+
+#include "builtin.h"
+#include "cache.h"
+
+int cmd_show_prefix(int argc, const char **argv, const char *prefix)
+{
+ if (prefix)
+ puts(prefix);
+
+ return 0;
+}
+
+int cmd_show_cdup(int argc, const char **argv, const char *prefix)
+{
+ const char *pfx = prefix;
+
+ while (pfx) {
+ pfx = strchr(pfx, '/');
+ if (pfx) {
+ pfx++;
+ printf("../");
+ }
+ }
+ putchar('\n');
+
+ return 0;
+}
+
+int cmd_show_git_dir(int argc, const char **argv, const char *prefix)
+{
+ const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
+ static char cwd[PATH_MAX];
+
+ if (gitdir) {
+ puts(gitdir);
+ return 0;
+ }
+ if (!prefix) {
+ puts(".git");
+ return 0;
+ }
+ if (!getcwd(cwd, PATH_MAX))
+ die("unable to get current working directory");
+ printf("%s/.git\n", cwd);
+
+ return 0;
+}
diff --git a/builtin.h b/builtin.h
index f9fa9ff..fb313d8 100644
--- a/builtin.h
+++ b/builtin.h
@@ -49,6 +49,9 @@ extern int cmd_rev_parse(int argc, const
extern int cmd_rm(int argc, const char **argv, const char *prefix);
extern int cmd_runstatus(int argc, const char **argv, const char *prefix);
extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
+extern int cmd_show_cdup(int argc, const char **argv, const char *prefix);
+extern int cmd_show_git_dir(int argc, const char **argv, const char *prefix);
+extern int cmd_show_prefix(int argc, const char **argv, const char *prefix);
extern int cmd_show(int argc, const char **argv, const char *prefix);
extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index b8e8622..3f2eada 100644
--- a/git.c
+++ b/git.c
@@ -255,6 +255,9 @@ static void handle_internal_command(int
{ "rm", cmd_rm, RUN_SETUP },
{ "runstatus", cmd_runstatus, RUN_SETUP },
{ "show-branch", cmd_show_branch, RUN_SETUP },
+ { "show-cdup", cmd_show_cdup, RUN_SETUP },
+ { "show-git-dir", cmd_show_git_dir, RUN_SETUP },
+ { "show-prefix", cmd_show_prefix, RUN_SETUP },
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
{ "stripspace", cmd_stripspace },
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
--
1.4.2.3
--
Martin Waitz
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.
2006-10-07 21:04 [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse Martin Waitz
@ 2006-10-07 21:14 ` Jakub Narebski
2006-10-07 21:36 ` Martin Waitz
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Narebski @ 2006-10-07 21:14 UTC (permalink / raw)
To: git
Martin Waitz wrote:
> They don't really have anything to do with refs.
But is it a good idea to add yet another command? We have too many of them
already...
I'd rather add one command, git-admin/git-config, or just move the options
to the "git" command. So we would have "git --show-git-dir" in addition to
"git --git-dir=<directory>".
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.
2006-10-07 21:14 ` Jakub Narebski
@ 2006-10-07 21:36 ` Martin Waitz
2006-10-08 5:43 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Martin Waitz @ 2006-10-07 21:36 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 684 bytes --]
On Sat, Oct 07, 2006 at 11:14:34PM +0200, Jakub Narebski wrote:
> Martin Waitz wrote:
> > They don't really have anything to do with refs.
>
> But is it a good idea to add yet another command? We have too many of them
> already...
true
> I'd rather add one command, git-admin/git-config, or just move the options
> to the "git" command. So we would have "git --show-git-dir" in addition to
> "git --git-dir=<directory>".
I thought doing the same for these commands as for --help and --version
but wanted to hear some opinions first...
After all, the comment in front of --version talked about legacy,
so I was afraid to add more legacy ;-)
--
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.
2006-10-07 21:36 ` Martin Waitz
@ 2006-10-08 5:43 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2006-10-08 5:43 UTC (permalink / raw)
To: Martin Waitz; +Cc: git
Martin Waitz <tali@admingilde.org> writes:
> I thought doing the same for these commands as for --help and --version
> but wanted to hear some opinions first...
>
> After all, the comment in front of --version talked about legacy,
> so I was afraid to add more legacy ;-)
Nothing to fear; legacy is about "version" vs "--version".
By the way, rev-parse is not about "refs" at all. It is about
"revs".
A possibly useless comment for people unfamiliar with history I
should add is that git-rev-parse serves two completely different
purposes. One is to separate command line parameters into four
category and output only specified kind. Four categories come
from flags vs non-flags and arguments related to revision
traversal vs other arguments. The "parse" in rev-parse actually
stands for this feature. Many git Porcelainish were implemented
as shell scripts that pipes rev-list output into diff-tree, and
rev-parse was originally invented as a helper for them.
We made many "rev-list | diff-tree --stdin" pattern into
built-in commands, by introducing revision.c, so this first
feature of rev-parse has become less useful.
But as a side-feature, when showing "non-flag, revision
traversal argument", it is told how to show the object name, and
also it acquired --verify option to make sure "extended sha1
expression" (refname, refname followed by ^n, ~n etc.) are
valid.
These days, the command is used primarily to get the object name
from an extended sha1 expression. But some commands (most
notably, bisect) still rely on the "parse" aspect of the
command.
However, in its history it has also become a kitchen sink
command. I think it may make sense to move these kitchen-sink
features such as --show-cdup etc. out of it and give it the
direct options to git wrapper these days. When these features
were added, git wrapper did not even exist.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-10-08 5:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-07 21:04 [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse Martin Waitz
2006-10-07 21:14 ` Jakub Narebski
2006-10-07 21:36 ` Martin Waitz
2006-10-08 5:43 ` Junio C Hamano
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).