{"thread":{"id":"1850","subject":"Add \"--git-dir\" flag to git-rev-parse","startedAt":"2005-09-18T18:18:30Z","lastAt":"2005-09-19T15:08:23Z","messageCount":7,"participants":["Linus Torvalds","David Kågedal","A Large Angry SCM","Matthias Urlichs"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8797","messageId":"Pine.LNX.4.58.0509181114190.26803@g5.osdl.org","threadId":"1850","inReplyTo":null,"subject":"Add \"--git-dir\" flag to git-rev-parse","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-18T18:18:30Z","receivedAt":"2005-09-18T18:18:30Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nEspecially when you're deep inside the git repository, it's not all that\ntrivial for scripts to figure out where GIT_DIR is if it isn't set.\n\nSo add a flag to git-rev-parse to show where it is, since it will have \nfigured it out anyway.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/rev-parse.c b/rev-parse.c\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -191,6 +191,22 @@ int main(int argc, char **argv)\n \t\t\t\t\tputs(prefix);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--git-dir\")) {\n+\t\t\t\tconst char *gitdir = getenv(GIT_DIR_ENVIRONMENT);\n+\t\t\t\tstatic char cwd[PATH_MAX];\n+\t\t\t\tif (gitdir) {\n+\t\t\t\t\tputs(gitdir);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tif (!prefix) {\n+\t\t\t\t\tputs(\".git\");\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tif (!getcwd(cwd, PATH_MAX))\n+\t\t\t\t\tdie(\"unable to get current working directory\");\n+\t\t\t\tprintf(\"%s/.git\\n\", cwd);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (verify)\n \t\t\t\tdie(\"Needed a single revision\");\n \t\t\tshow_flag(arg);\n"},{"id":"8848","messageId":"u5tmzm9bbrb.fsf@lysator.liu.se","threadId":"1850","inReplyTo":"Pine.LNX.4.58.0509181114190.26803@g5.osdl.org","subject":"[PATCH] Added -d and -e options to the \"git\" script.","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2005-09-19T10:19:36Z","receivedAt":"2005-09-19T10:19:36Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"These flags override the GIT_DIR and EDITOR environment variables.\n\n---\nThis is more generic way to specify GIT_DIR than Linus' suggestion,\nalthough it is only targeted at more porcelainish usage of the git\ndriver script.\n\nI needed this for the Emacs commands I've been hacking on, since it's\nhard to set environment variables for single commands without\ninvolving /bin/env or a shell.\n\n git.sh |   37 +++++++++++++++++++++++++------------\n 1 files changed, 25 insertions(+), 12 deletions(-)\n\nb9a38ed5a16289f86b353c0bb541e607d35180a9\ndiff --git a/git.sh b/git.sh\n--- a/git.sh\n+++ b/git.sh\n@@ -2,19 +2,32 @@\n \n cmd=\n path=$(dirname $0)\n-case \"$#\" in\n-0)\t;;\n-*)\tcmd=\"$1\"\n-\tshift\n-\tcase \"$cmd\" in\n-\t-v|--v|--ve|--ver|--vers|--versi|--versio|--version)\n-\t\techo \"git version @@GIT_VERSION@@\"\n-\t\texit 0 ;;\n-\tesac\n-\ttest -x $path/git-$cmd && exec $path/git-$cmd \"$@\" ;;\n-esac\n \n-echo \"Usage: git COMMAND [OPTIONS] [TARGET]\"\n+while test \"$#\" -gt 0\n+do\n+        case \"$1\" in\n+        -d)\texport GIT_DIR\n+                GIT_DIR=$2\n+                shift\n+                ;;\n+        -e)\texport EDITOR\n+                EDITOR=$2\n+                shift\n+                ;;\n+        *)\tcmd=\"$1\"\n+                shift\n+                case \"$cmd\" in\n+                -v|--v|--ve|--ver|--vers|--versi|--versio|--version)\n+                        echo \"git version @@GIT_VERSION@@\"\n+                        exit 0 ;;\n+                esac\n+                test -x $path/git-$cmd && exec $path/git-$cmd \"$@\"\n+                ;;\n+        esac\n+        shift\n+done\n+\n+echo \"Usage: git [GLOBAL OPTIONS] COMMAND [COMMAND OPTIONS]\"\n if [ -n \"$cmd\" ]; then\n     echo \" git command '$cmd' not found: commands are:\"\n else\n\n-- \nDavid Kågedal\n"},{"id":"8858","messageId":"432EC7D6.6080105@gmail.com","threadId":"1850","inReplyTo":"u5tmzm9bbrb.fsf@lysator.liu.se","subject":"Re: [PATCH] Added -d and -e options to the \"git\" script.","fromName":"A Large Angry SCM","fromEmail":"gitzilla@gmail.com","sentAt":"2005-09-19T14:14:46Z","receivedAt":"2005-09-19T14:14:46Z","isPatch":true,"sender":{"key":"gitzilla@gmail.com","avatar":"https://gravatar.com/avatar/354625c442439908ff3dd99757dee330e29e9df7847472384faf7a00add247fb?d=mp&s=160"},"body":"David Kågedal wrote:\n> These flags override the GIT_DIR and EDITOR environment variables.\n> \n[Patch snipped]\n\nAn option for GIT_DIR maybe since it's a Git environment variable but a \ncommand line option to change the EDITOR _environment_ variable is NOT \nappropriate for git.\n"},{"id":"8859","messageId":"u5tvf0xb0fp.fsf@lysator.liu.se","threadId":"1850","inReplyTo":"432EC7D6.6080105@gmail.com","subject":"Re: [PATCH] Added -d and -e options to the \"git\" script.","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2005-09-19T14:24:10Z","receivedAt":"2005-09-19T14:24:10Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"A Large Angry SCM <gitzilla@gmail.com> writes:\n\n> David Kågedal wrote:\n>> These flags override the GIT_DIR and EDITOR environment variables.\n>>\n> [Patch snipped]\n>\n> An option for GIT_DIR maybe since it's a Git environment variable but a \n> command line option to change the EDITOR _environment_ variable is NOT \n> appropriate for git.\n\nYeah, I should have separated those two so that the GIT_DIR option\ncould be accepted on its own.  And it should maybe have a --git-dir=\nlog form as well.\n\nThe reason I did -e too was simply that I needed it for the same\nreason I needed -d.  I wanted to run git with specific values for\nGIT_DIR and EDITOR without having to setenv them in emacs.  But the\nEDITOR trick I'm using is a hack and should be replaced anyway. (I use\nEDITOR=cat to get access to the default commit message with comments\nfrom 'git commit').\n\nSo please disregard the -e part of my patch for now.  You are free to\ndisregard the -d part as well, but I think that makes some kind of\nsense.\n\nAnd If we go down this path, maybe flags for other GIT_* environment\nvariables should be settable with git command line flags too?\n\n-- \nDavid Kågedal\n"},{"id":"8864","messageId":"432ECE5A.7040703@gmail.com","threadId":"1850","inReplyTo":"u5tvf0xb0fp.fsf@lysator.liu.se","subject":"Re: [PATCH] Added -d and -e options to the \"git\" script.","fromName":"A Large Angry SCM","fromEmail":"gitzilla@gmail.com","sentAt":"2005-09-19T14:42:34Z","receivedAt":"2005-09-19T14:42:34Z","isPatch":true,"sender":{"key":"gitzilla@gmail.com","avatar":"https://gravatar.com/avatar/354625c442439908ff3dd99757dee330e29e9df7847472384faf7a00add247fb?d=mp&s=160"},"body":"David Kågedal wrote:\n> A Large Angry SCM <gitzilla@gmail.com> writes:\n> \n>>David Kågedal wrote:\n>>>These flags override the GIT_DIR and EDITOR environment variables.\n>>>\n>>[Patch snipped]\n>>\n[...]\n> \n> So please disregard the -e part of my patch for now.  You are free to\n> disregard the -d part as well, but I think that makes some kind of\n> sense.\n> \n> And If we go down this path, maybe flags for other GIT_* environment\n> variables should be settable with git command line flags too?\n> \n\nPlease no!\n\nThere are better methods of setting environment variables than an \nendless set of command options. Use the env command or you own \n(personal) command wrapper instead.\n"},{"id":"8868","messageId":"pan.2005.09.19.14.42.44.111271@smurf.noris.de","threadId":"1850","inReplyTo":"u5tmzm9bbrb.fsf@lysator.liu.se","subject":"Re: [PATCH] Added -d and -e options to the \"git\" script.","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-09-19T14:42:47Z","receivedAt":"2005-09-19T14:42:47Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Hi, David Kågedal wrote:\n> +        case \"$1\" in\n> +        -e)\t[...]\n> +        *)\tcmd=\"$1\"\n> +                shift\n> +                case \"$cmd\" in\n> +                -v|--v|--ve|--ver|--vers|--versi|--versio|--version)\n\nUmm, can we please not have two case statements nested like that?\n\nBetter written as:\n> +        case \"$1\" in\n> +        -e)\t[...]\n> +        -v|--v|--ve|--ver|--vers|--versi|--versio|--version)\n> +             [print and die]\n> +        *)\tcmd=\"$1\"\n> +             shift\n> +             test -x $path/git-$cmd && exec $path/git-$cmd \"$@\"\n\nThanks.\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nIt is a sad commentary on today's society that this fortune has to be\nclassified as \"offensive\" simply because it contains the word \"fuck\".\n"},{"id":"8871","messageId":"u5tpsr5aye0.fsf@lysator.liu.se","threadId":"1850","inReplyTo":"432ECE5A.7040703@gmail.com","subject":"Re: [PATCH] Added -d and -e options to the \"git\" script.","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2005-09-19T15:08:23Z","receivedAt":"2005-09-19T15:08:23Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"A Large Angry SCM <gitzilla@gmail.com> writes:\n\n> There are better methods of setting environment variables than an \n> endless set of command options. Use the env command or you own \n> (personal) command wrapper instead.\n\nRemember that, to the user, this isn't about setting environment\nvariables, It's about providing git parameters.\n\nCurrently, the only of doing this is by setting environment variables;\nwhat I'm suggesting is an *alternative* to that.\n\nThe fact that the implementation of these flags would actually use\nenvironment variables to propagate these parameters to subprocesses\ndoesn't necessary mean that it is the only sane way to specify it\noriginally.\n\nAnyway, there are other options, such as\n\n   $ git GIT_DIR=/foo/bar status\n\nand today we already have\n\n   $ env GIT_DIR=/foo/bar status\n\nThe advantage of these forms is of course that they don't limit the\nparameters that can be set, so I could keep setting EDITOR if I want\nto.  But if setting GIT_DIR is common enough it might make sense to\nprovide a short flag for that.\n\nThe summary of my ramblings are probably that I think the -d flag is a\ngood idea, but no way of specifying other parameters is needed.\n\n-- \nDavid Kågedal\n"}]}