git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Waitz <tali@admingilde.org>
To: git@vger.kernel.org
Subject: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.
Date: Sat, 7 Oct 2006 23:04:29 +0200	[thread overview]
Message-ID: <20061007210429.GA2871@admingilde.org> (raw)

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

             reply	other threads:[~2006-10-07 21:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-07 21:04 Martin Waitz [this message]
2006-10-07 21:14 ` [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse Jakub Narebski
2006-10-07 21:36   ` Martin Waitz
2006-10-08  5:43     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061007210429.GA2871@admingilde.org \
    --to=tali@admingilde.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).