{"thread":{"id":"32336","subject":"[PATCH] git.c: add --index-file command-line option.","startedAt":"2012-12-14T11:23:39Z","lastAt":"2012-12-16T08:20:59Z","messageCount":7,"participants":["Manlio Perillo","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"204866","messageId":"1355484219-7517-1-git-send-email-manlio.perillo@gmail.com","threadId":"32336","inReplyTo":null,"subject":"[PATCH] git.c: add --index-file command-line option.","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-14T11:23:39Z","receivedAt":"2012-12-14T11:23:39Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"Unlike other environment variables (e.g. GIT_WORK_TREE,\nGIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE\nenvironment variable using the command line.\n\nAdd a new --index-file command-line option.\n\nUpdate the t7500-commit test to include --index-file option coverage.\nThe tests have been adapted from the existing\n'using alternate GIT_INDEX_FILE (1)' and\n'using alternate GIT_INDEX_FILE (2)' tests.\n\nSigned-off-by: Manlio Perillo <manlio.perillo@gmail.com>\n---\n Documentation/git.txt | 10 +++++++++-\n git.c                 | 17 ++++++++++++++++-\n t/t7500-commit.sh     | 29 +++++++++++++++++++++++++++++\n 3 files changed, 54 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex e643683..5a582dd 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -12,7 +12,8 @@ SYNOPSIS\n 'git' [--version] [--help] [-c <name>=<value>]\n     [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n     [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n-    [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n+    [--git-dir=<path>] [--work-tree=<path>] [--index-file=<path>]\n+    [--namespace=<name>]\n     <command> [<args>]\n \n DESCRIPTION\n@@ -408,6 +409,12 @@ help ...`.\n \tvariable (see core.worktree in linkgit:git-config[1] for a\n \tmore detailed discussion).\n \n+--index-file=<path>::\n+\tSet the path to the index file. It can be an absolute path\n+\tor a path relative to the current working directory.\n+\tThis can also be controlled by setting the GIT_INDEX_FILE\n+\tenvironment variable.\n+\n --namespace=<path>::\n \tSet the git namespace.  See linkgit:gitnamespaces[7] for more\n \tdetails.  Equivalent to setting the `GIT_NAMESPACE` environment\n@@ -632,6 +639,7 @@ git so take care if using Cogito etc.\n \tThis environment allows the specification of an alternate\n \tindex file. If not specified, the default of `$GIT_DIR/index`\n \tis used.\n+\tThe '--index-file command-line option also sets this value.\n \n 'GIT_OBJECT_DIRECTORY'::\n \tIf the object storage directory is specified via this\ndiff --git a/git.c b/git.c\nindex d33f9b3..b0f473d 100644\n--- a/git.c\n+++ b/git.c\n@@ -8,7 +8,8 @@\n const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\\n\"\n \t\"           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\\n\"\n-\t\"           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\\n\"\n+\t\"           [--git-dir=<path>] [--work-tree=<path>] [--index-file=<path>]\\n\"\n+\t\"           [--namespace=<name>]\\n\"\n \t\"           [-c name=value] [--help]\\n\"\n \t\"           <command> [<args>]\";\n \n@@ -121,6 +122,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\tsetenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"--index-file\")) {\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"No path given for --index-file.\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t}\n+\t\t\tsetenv(INDEX_ENVIRONMENT, (*argv)[1], 1);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n+\t\t\t(*argv)++;\n+\t\t\t(*argc)--;\n+\t\t} else if (!prefixcmp(cmd, \"--index-file=\")) {\n+\t\t\tsetenv(INDEX_ENVIRONMENT, cmd + 13, 1);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--bare\")) {\n \t\t\tstatic char git_dir[PATH_MAX+1];\n \t\t\tis_bare_repository_cfg = 1;\ndiff --git a/t/t7500-commit.sh b/t/t7500-commit.sh\nindex 1c908f4..c405a78 100755\n--- a/t/t7500-commit.sh\n+++ b/t/t7500-commit.sh\n@@ -168,6 +168,35 @@ test_expect_success 'using alternate GIT_INDEX_FILE (2)' '\n \tcmp .git/index saved-index >/dev/null\n '\n \n+test_expect_success 'using alternate --index-file (1)' '\n+\n+\tcp .git/index saved-index &&\n+\t(\n+\t\techo some new content >file &&\n+\t\tindex_file=.git/another_index &&\n+\t\tgit --index-file=$index_file add file &&\n+\t\tgit --index-file=$index_file commit -m \"commit using another index\" &&\n+\t\tgit --index-file=$index_file diff-index --exit-code HEAD &&\n+\t\tgit --index-file=$index_file diff-files --exit-code\n+\t) &&\n+\tcmp .git/index saved-index >/dev/null\n+\n+'\n+\n+test_expect_success 'using alternate --index-file (2)' '\n+\n+\tcp .git/index saved-index &&\n+\t(\n+\t\trm -f .git/no-such-index &&\n+\t\tindex_file=.git/no-such-index &&\n+\t\tgit --index-file=$index_file commit -m \"commit using nonexistent index\" &&\n+\t\ttest -z \"$(git --index-file=$index_file ls-files)\" &&\n+\t\ttest -z \"$(git --index-file=$index_file ls-tree HEAD)\"\n+\n+\t) &&\n+\tcmp .git/index saved-index >/dev/null\n+'\n+\n cat > expect << EOF\n zort\n \n-- \n1.8.1.rc1.17.g75ed918.dirty\n"},{"id":"204917","messageId":"7vpq2btcqp.fsf@alter.siamese.dyndns.org","threadId":"32336","inReplyTo":"1355484219-7517-1-git-send-email-manlio.perillo@gmail.com","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-15T18:02:38Z","receivedAt":"2012-12-15T18:02:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Manlio Perillo <manlio.perillo@gmail.com> writes:\n\n> Unlike other environment variables (e.g. GIT_WORK_TREE,\n> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE\n> environment variable using the command line.\n\nIs this necessary?  I'd prefer to see a better reason than \"just\nbecause others have it\".\n"},{"id":"204934","messageId":"50CCC73B.3070802@gmail.com","threadId":"32336","inReplyTo":"7vpq2btcqp.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-15T18:53:47Z","receivedAt":"2012-12-15T18:53:47Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 15/12/2012 19:02, Junio C Hamano ha scritto:\n> Manlio Perillo <manlio.perillo@gmail.com> writes:\n> \n>> Unlike other environment variables (e.g. GIT_WORK_TREE,\n>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE\n>> environment variable using the command line.\n> \n> Is this necessary?  I'd prefer to see a better reason than \"just\n> because others have it\".\n\nA long running program will be able to tell git to use an alternate\nindex file, without having to modify its own environment, or having to\nuse execvpe (I assume this is the reason why it is possible to specify\nGIT_WORK_TREE from command line).\n\n\n\nRegards  Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEUEARECAAYFAlDMxzsACgkQscQJ24LbaUSzEQCYymkZa6JrT42OzigRfDgc5Hss\ngwCgjIzs1b0hEyu1WAgDgCir9XalDN8=\n=GtMF\n-----END PGP SIGNATURE-----\n"},{"id":"204942","messageId":"7vliczrttq.fsf@alter.siamese.dyndns.org","threadId":"32336","inReplyTo":"50CCC73B.3070802@gmail.com","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-15T19:36:33Z","receivedAt":"2012-12-15T19:36:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Manlio Perillo <manlio.perillo@gmail.com> writes:\n\n> Il 15/12/2012 19:02, Junio C Hamano ha scritto:\n>> Manlio Perillo <manlio.perillo@gmail.com> writes:\n>> \n>>> Unlike other environment variables (e.g. GIT_WORK_TREE,\n>>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE\n>>> environment variable using the command line.\n>> \n>> Is this necessary?  I'd prefer to see a better reason than \"just\n>> because others have it\".\n>\n> A long running program will be able to tell git to use an alternate\n> index file, without having to modify its own environment,...\n\nHrm, isn't that the single-shot environment export syntax\n\n\tGIT_INDEX_FILE=foo git blah\n\nis for?  Is there a real-world need for this?\n"},{"id":"204948","messageId":"50CCF324.5060802@gmail.com","threadId":"32336","inReplyTo":"7vliczrttq.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-15T22:01:08Z","receivedAt":"2012-12-15T22:01:08Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 15/12/2012 20:36, Junio C Hamano ha scritto:\n> [...]\n>>>> Unlike other environment variables (e.g. GIT_WORK_TREE,\n>>>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE\n>>>> environment variable using the command line.\n>>>\n>>> Is this necessary?  I'd prefer to see a better reason than \"just\n>>> because others have it\".\n>>\n>> A long running program will be able to tell git to use an alternate\n>> index file, without having to modify its own environment,...\n> \n> Hrm, isn't that the single-shot environment export syntax\n> \n> \tGIT_INDEX_FILE=foo git blah\n> \n> is for?  Is there a real-world need for this?\n> \n\nThis works with a shell.\nI'm using Python to write a custom git command.\n\n\n\n\nRegards  Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlDM8yQACgkQscQJ24LbaUTftQCbBC7D9P7Sqlr9GzWuCIcIHPf2\naQcAn13+d4trLZS4izGvZtoaopMav4nV\n=vfb6\n-----END PGP SIGNATURE-----\n"},{"id":"204956","messageId":"7vvcc2r0z8.fsf@alter.siamese.dyndns.org","threadId":"32336","inReplyTo":"50CCF324.5060802@gmail.com","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-16T05:59:39Z","receivedAt":"2012-12-16T05:59:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I\nManlio Perillo <manlio.perillo@gmail.com> writes:\n\n> This works with a shell.\n> I'm using Python to write a custom git command.\n\nI would be very surprised if Python lacked a way to spawn a\nsubprocess with an environment modified from the current process.\n"},{"id":"204959","messageId":"50CD846B.2040604@gmail.com","threadId":"32336","inReplyTo":"7vvcc2r0z8.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git.c: add --index-file command-line option.","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-16T08:20:59Z","receivedAt":"2012-12-16T08:20:59Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 16/12/2012 06:59, Junio C Hamano ha scritto:\n> I\n> Manlio Perillo <manlio.perillo@gmail.com> writes:\n> \n>> This works with a shell.\n>> I'm using Python to write a custom git command.\n> \n> I would be very surprised if Python lacked a way to spawn a\n> subprocess with an environment modified from the current process.\n\nOf course it is possible, but a command-line option is more convenient,\nIMHO.\n\n\n\nRegards  Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlDNhGsACgkQscQJ24LbaUQ0dQCglUAw8zwRKNeDUGznfrm1xFKf\nGQsAnA/ucztku4v9LnIr0Lv/gyl5ULiT\n=j/1w\n-----END PGP SIGNATURE-----\n"}]}