{"thread":{"id":"5851","subject":"[RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.","startedAt":"2006-10-07T21:04:29Z","lastAt":"2006-10-08T05:43:54Z","messageCount":4,"participants":["Martin Waitz","Jakub Narebski","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"28390","messageId":"20061007210429.GA2871@admingilde.org","threadId":"5851","inReplyTo":null,"subject":"[RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-10-07T21:04:29Z","receivedAt":"2006-10-07T21:04:29Z","isPatch":false,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"They don't really have anything to do with refs.\n\nSigned-off-by: Martin Waitz <tali@admingilde.org>\n---\n Makefile              |    1 +\n builtin-show-prefix.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++\n builtin.h             |    3 +++\n git.c                 |    3 +++\n 4 files changed, 57 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 2c7c338..c072162 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -298,6 +298,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-rm.o \\\n \tbuiltin-runstatus.o \\\n \tbuiltin-show-branch.o \\\n+\tbuiltin-show-prefix.o \\\n \tbuiltin-stripspace.o \\\n \tbuiltin-symbolic-ref.o \\\n \tbuiltin-tar-tree.o \\\ndiff --git a/builtin-show-prefix.c b/builtin-show-prefix.c\nnew file mode 100644\nindex 0000000..ed46434\n--- /dev/null\n+++ b/builtin-show-prefix.c\n@@ -0,0 +1,50 @@\n+/*\n+ * Show some information about the GIT repository\n+ */\n+\n+#include \"builtin.h\"\n+#include \"cache.h\"\n+\n+int cmd_show_prefix(int argc, const char **argv, const char *prefix)\n+{\n+\tif (prefix)\n+\t\tputs(prefix);\n+\n+\treturn 0;\n+}\n+\n+int cmd_show_cdup(int argc, const char **argv, const char *prefix)\n+{\n+\tconst char *pfx = prefix;\n+\n+\twhile (pfx) {\n+\t\tpfx = strchr(pfx, '/');\n+\t\tif (pfx) {\n+\t\t\tpfx++;\n+\t\t\tprintf(\"../\");\n+\t\t}\n+\t}\n+\tputchar('\\n');\n+\t\n+\treturn 0;\n+}\n+\n+int cmd_show_git_dir(int argc, const char **argv, const char *prefix)\n+{\n+\tconst char *gitdir = getenv(GIT_DIR_ENVIRONMENT);\n+\tstatic char cwd[PATH_MAX];\n+\n+\tif (gitdir) {\n+\t\tputs(gitdir);\n+\t\treturn 0;\n+\t}\n+\tif (!prefix) {\n+\t\tputs(\".git\");\n+\t\treturn 0;\n+\t}\n+\tif (!getcwd(cwd, PATH_MAX))\n+\t\tdie(\"unable to get current working directory\");\n+\tprintf(\"%s/.git\\n\", cwd);\n+\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex f9fa9ff..fb313d8 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -49,6 +49,9 @@ extern int cmd_rev_parse(int argc, const\n extern int cmd_rm(int argc, const char **argv, const char *prefix);\n extern int cmd_runstatus(int argc, const char **argv, const char *prefix);\n extern int cmd_show_branch(int argc, const char **argv, const char *prefix);\n+extern int cmd_show_cdup(int argc, const char **argv, const char *prefix);\n+extern int cmd_show_git_dir(int argc, const char **argv, const char *prefix);\n+extern int cmd_show_prefix(int argc, const char **argv, const char *prefix);\n extern int cmd_show(int argc, const char **argv, const char *prefix);\n extern int cmd_stripspace(int argc, const char **argv, const char *prefix);\n extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex b8e8622..3f2eada 100644\n--- a/git.c\n+++ b/git.c\n@@ -255,6 +255,9 @@ static void handle_internal_command(int \n \t\t{ \"rm\", cmd_rm, RUN_SETUP },\n \t\t{ \"runstatus\", cmd_runstatus, RUN_SETUP },\n \t\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n+\t\t{ \"show-cdup\", cmd_show_cdup, RUN_SETUP },\n+\t\t{ \"show-git-dir\", cmd_show_git_dir, RUN_SETUP },\n+\t\t{ \"show-prefix\", cmd_show_prefix, RUN_SETUP },\n \t\t{ \"show\", cmd_show, RUN_SETUP | USE_PAGER },\n \t\t{ \"stripspace\", cmd_stripspace },\n \t\t{ \"symbolic-ref\", cmd_symbolic_ref, RUN_SETUP },\n-- \n1.4.2.3\n\n-- \nMartin Waitz\n"},{"id":"28391","messageId":"eg95a6$2v7$1@sea.gmane.org","threadId":"5851","inReplyTo":"20061007210429.GA2871@admingilde.org","subject":"Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-10-07T21:14:34Z","receivedAt":"2006-10-07T21:14:34Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Martin Waitz wrote:\n\n> They don't really have anything to do with refs.\n\nBut is it a good idea to add yet another command? We have too many of them\nalready...\n\nI'd rather add one command, git-admin/git-config, or just move the options\nto the \"git\" command. So we would have \"git --show-git-dir\" in addition to\n\"git --git-dir=<directory>\".\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"28395","messageId":"20061007213603.GB2871@admingilde.org","threadId":"5851","inReplyTo":"eg95a6$2v7$1@sea.gmane.org","subject":"Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-10-07T21:36:03Z","receivedAt":"2006-10-07T21:36:03Z","isPatch":false,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"On Sat, Oct 07, 2006 at 11:14:34PM +0200, Jakub Narebski wrote:\n> Martin Waitz wrote:\n> > They don't really have anything to do with refs.\n> \n> But is it a good idea to add yet another command? We have too many of them\n> already...\n\ntrue\n\n> I'd rather add one command, git-admin/git-config, or just move the options\n> to the \"git\" command. So we would have \"git --show-git-dir\" in addition to\n> \"git --git-dir=<directory>\".\n\nI thought doing the same for these commands as for --help and --version\nbut wanted to hear some opinions first...\n\nAfter all, the comment in front of --version talked about legacy,\nso I was afraid to add more legacy ;-)\n\n-- \nMartin Waitz\n"},{"id":"28406","messageId":"7vvemvmkf9.fsf@assigned-by-dhcp.cox.net","threadId":"5851","inReplyTo":"20061007213603.GB2871@admingilde.org","subject":"Re: [RFC] move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-08T05:43:54Z","receivedAt":"2006-10-08T05:43:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Waitz <tali@admingilde.org> writes:\n\n> I thought doing the same for these commands as for --help and --version\n> but wanted to hear some opinions first...\n>\n> After all, the comment in front of --version talked about legacy,\n> so I was afraid to add more legacy ;-)\n\nNothing to fear; legacy is about \"version\" vs \"--version\".\n\nBy the way, rev-parse is not about \"refs\" at all.  It is about\n\"revs\".\n\nA possibly useless comment for people unfamiliar with history I\nshould add is that git-rev-parse serves two completely different\npurposes.  One is to separate command line parameters into four\ncategory and output only specified kind.  Four categories come\nfrom flags vs non-flags and arguments related to revision\ntraversal vs other arguments.  The \"parse\" in rev-parse actually\nstands for this feature.  Many git Porcelainish were implemented\nas shell scripts that pipes rev-list output into diff-tree, and\nrev-parse was originally invented as a helper for them.\n\nWe made many \"rev-list | diff-tree --stdin\" pattern into\nbuilt-in commands, by introducing revision.c, so this first\nfeature of rev-parse has become less useful.\n\nBut as a side-feature, when showing \"non-flag, revision\ntraversal argument\", it is told how to show the object name, and\nalso it acquired --verify option to make sure \"extended sha1\nexpression\" (refname, refname followed by ^n, ~n etc.) are\nvalid.\n\nThese days, the command is used primarily to get the object name\nfrom an extended sha1 expression.  But some commands (most\nnotably, bisect) still rely on the \"parse\" aspect of the\ncommand.\n\nHowever, in its history it has also become a kitchen sink\ncommand.  I think it may make sense to move these kitchen-sink\nfeatures such as --show-cdup etc. out of it and give it the\ndirect options to git wrapper these days.  When these features\nwere added, git wrapper did not even exist.\n"}]}