{"thread":{"id":"22149","subject":"[PATCH 1/2] Add 'git rev-parse --show-toplevel' option.","startedAt":"2010-01-10T07:19:13Z","lastAt":"2010-01-11T22:34:34Z","messageCount":3,"participants":["Steven Drake"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"131212","messageId":"alpine.LNX.2.00.1001102011420.2560@vqena.qenxr.bet.am","threadId":"22149","inReplyTo":null,"subject":"[PATCH 1/2] Add 'git rev-parse --show-toplevel' option.","fromName":"Steven Drake","fromEmail":"sdrake@xnet.co.nz","sentAt":"2010-01-10T07:19:13Z","receivedAt":"2010-01-10T07:19:13Z","isPatch":true,"sender":{"key":"sdrake@xnet.co.nz","avatar":null},"body":" Shows the absolute path of the top-level working directory.\n---\n Documentation/git-rev-parse.txt |    3 +++\n builtin-rev-parse.c             |    6 ++++++\n 2 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 82045a2..dc829b3 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -112,6 +112,9 @@ OPTIONS\n --remotes::\n \tShow tag refs found in `$GIT_DIR/refs/remotes`.\n \n+--show-toplevel::\n+\tShow the absolute path of the top-level directory.\n+\n --show-prefix::\n \tWhen the command is invoked from a subdirectory, show the\n \tpath of the current directory relative to the top-level\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 37d0233..96ab8bb 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tfor_each_remote_ref(show_reference, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--show-toplevel\")) {\n+\t\t\t\tconst char *work_tree = get_git_work_tree();\n+\t\t\t\tif (work_tree)\n+\t\t\t\t\tprintf(\"%s\\n\", work_tree);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-prefix\")) {\n \t\t\t\tif (prefix)\n \t\t\t\t\tputs(prefix);\n-- \n1.6.4\n"},{"id":"131325","messageId":"alpine.LNX.2.00.1001121133080.10158@vqena.qenxr.bet.am","threadId":"22149","inReplyTo":"alpine.LNX.2.00.1001102011420.2560@vqena.qenxr.bet.am","subject":"[PATCH 1/2] Add 'git rev-parse --show-toplevel' option.","fromName":"Steven Drake","fromEmail":"sdrake@xnet.co.nz","sentAt":"2010-01-11T22:33:48Z","receivedAt":"2010-01-11T22:33:48Z","isPatch":true,"sender":{"key":"sdrake@xnet.co.nz","avatar":null},"body":"Shows the absolute path of the top-level working directory.\n\nSigned-off-by: Steven Drake <sdrake@xnet.co.nz>\n---\n Documentation/git-rev-parse.txt |    3 +++\n builtin-rev-parse.c             |    6 ++++++\n 2 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 82045a2..dc829b3 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -112,6 +112,9 @@ OPTIONS\n --remotes::\n \tShow tag refs found in `$GIT_DIR/refs/remotes`.\n \n+--show-toplevel::\n+\tShow the absolute path of the top-level directory.\n+\n --show-prefix::\n \tWhen the command is invoked from a subdirectory, show the\n \tpath of the current directory relative to the top-level\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 37d0233..96ab8bb 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tfor_each_remote_ref(show_reference, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--show-toplevel\")) {\n+\t\t\t\tconst char *work_tree = get_git_work_tree();\n+\t\t\t\tif (work_tree)\n+\t\t\t\t\tprintf(\"%s\\n\", work_tree);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-prefix\")) {\n \t\t\t\tif (prefix)\n \t\t\t\t\tputs(prefix);\n-- \n1.6.4\n"},{"id":"131326","messageId":"alpine.LNX.2.00.1001121133520.10158@vqena.qenxr.bet.am","threadId":"22149","inReplyTo":"alpine.LNX.2.00.1001102011420.2560@vqena.qenxr.bet.am","subject":"[PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel().","fromName":"Steven Drake","fromEmail":"sdrake@xnet.co.nz","sentAt":"2010-01-11T22:34:34Z","receivedAt":"2010-01-11T22:34:34Z","isPatch":true,"sender":{"key":"sdrake@xnet.co.nz","avatar":null},"body":"rev-parse --show-toplevel gives the absolute (aka \"physical\") path of the \ntoplevel directory and is more portable as 'cd -P' is not supported by all \nshell implementations.\n\nThis is also closer to what setup_work_tree() does.\n\nSigned-off-by: Steven Drake <sdrake@xnet.co.nz>\n---\n git-sh-setup.sh |   19 +++++--------------\n 1 files changed, 5 insertions(+), 14 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex dfcb807..d56426d 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -120,20 +120,11 @@ is_bare_repository () {\n }\n \n cd_to_toplevel () {\n-\tcdup=$(git rev-parse --show-cdup)\n-\tif test ! -z \"$cdup\"\n-\tthen\n-\t\t# The \"-P\" option says to follow \"physical\" directory\n-\t\t# structure instead of following symbolic links.  When cdup is\n-\t\t# \"../\", this means following the \"..\" entry in the current\n-\t\t# directory instead textually removing a symlink path element\n-\t\t# from the PWD shell variable.  The \"-P\" behavior is more\n-\t\t# consistent with the C-style chdir used by most of Git.\n-\t\tcd -P \"$cdup\" || {\n-\t\t\techo >&2 \"Cannot chdir to $cdup, the toplevel of the working tree\"\n-\t\t\texit 1\n-\t\t}\n-\tfi\n+\tcdup=$(git rev-parse --show-toplevel) &&\n+\tcd \"$cdup\" || {\n+\t\techo >&2 \"Cannot chdir to $cdup, the toplevel of the working tree\"\n+\t\texit 1\n+\t}\n }\n \n require_work_tree () {\n-- \n1.6.4\n"}]}