Skip to contentSkip to conversation

move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.

RFC In review Martin Waitz 3 participants 4 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC 1/1 move --show-cdup, --show-prefix, and --show-git-dir out of git-rev-parse.

They don't really have anything to do with refs.

---
 Makefile              |    1 +
 builtin-show-prefix.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h             |    3 +++
 git.c                 |    3 +++
 4 files changed, 57 insertions(+), 0 deletions(-)
Makefile +1 -0
index 2c7c338..c072162 100644
@@ -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 \
builtin-show-prefix.c new file +50 -0

50 lines not on this page · raw message

builtin.h +3 -0
index f9fa9ff..fb313d8 100644
@@ -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);
git.c +3 -0
index b8e8622..3f2eada 100644
@@ -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 },
Signature · 4 lines
1.4.2.3

-- 
Martin Waitz
#1 lore raw
Quoted 1 line · Martin Waitz

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>".

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#2 lore raw
Quoted 5 lines · Jakub Narebski
Quoted 1 line · Martin Waitz

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

Quoted 3 lines

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 ;-)

Signature · 1 line
Martin Waitz
#3 lore raw
Quoted 5 lines · Martin Waitz

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.