git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git.c: add --index-file command-line option.
@ 2012-12-14 11:23 Manlio Perillo
  2012-12-15 18:02 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Manlio Perillo @ 2012-12-14 11:23 UTC (permalink / raw)
  To: git; +Cc: Manlio Perillo

Unlike other environment variables (e.g. GIT_WORK_TREE,
GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE
environment variable using the command line.

Add a new --index-file command-line option.

Update the t7500-commit test to include --index-file option coverage.
The tests have been adapted from the existing
'using alternate GIT_INDEX_FILE (1)' and
'using alternate GIT_INDEX_FILE (2)' tests.

Signed-off-by: Manlio Perillo <manlio.perillo@gmail.com>
---
 Documentation/git.txt | 10 +++++++++-
 git.c                 | 17 ++++++++++++++++-
 t/t7500-commit.sh     | 29 +++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index e643683..5a582dd 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -12,7 +12,8 @@ SYNOPSIS
 'git' [--version] [--help] [-c <name>=<value>]
     [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
     [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
-    [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
+    [--git-dir=<path>] [--work-tree=<path>] [--index-file=<path>]
+    [--namespace=<name>]
     <command> [<args>]
 
 DESCRIPTION
@@ -408,6 +409,12 @@ help ...`.
 	variable (see core.worktree in linkgit:git-config[1] for a
 	more detailed discussion).
 
+--index-file=<path>::
+	Set the path to the index file. It can be an absolute path
+	or a path relative to the current working directory.
+	This can also be controlled by setting the GIT_INDEX_FILE
+	environment variable.
+
 --namespace=<path>::
 	Set the git namespace.  See linkgit:gitnamespaces[7] for more
 	details.  Equivalent to setting the `GIT_NAMESPACE` environment
@@ -632,6 +639,7 @@ git so take care if using Cogito etc.
 	This environment allows the specification of an alternate
 	index file. If not specified, the default of `$GIT_DIR/index`
 	is used.
+	The '--index-file command-line option also sets this value.
 
 'GIT_OBJECT_DIRECTORY'::
 	If the object storage directory is specified via this
diff --git a/git.c b/git.c
index d33f9b3..b0f473d 100644
--- a/git.c
+++ b/git.c
@@ -8,7 +8,8 @@
 const char git_usage_string[] =
 	"git [--version] [--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"
 	"           [-c name=value] [--help]\n"
 	"           <command> [<args>]";
 
@@ -121,6 +122,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			setenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
 			if (envchanged)
 				*envchanged = 1;
+		} else if (!strcmp(cmd, "--index-file")) {
+			if (*argc < 2) {
+				fprintf(stderr, "No path given for --index-file.\n" );
+				usage(git_usage_string);
+			}
+			setenv(INDEX_ENVIRONMENT, (*argv)[1], 1);
+			if (envchanged)
+				*envchanged = 1;
+			(*argv)++;
+			(*argc)--;
+		} else if (!prefixcmp(cmd, "--index-file=")) {
+			setenv(INDEX_ENVIRONMENT, cmd + 13, 1);
+			if (envchanged)
+				*envchanged = 1;
 		} else if (!strcmp(cmd, "--bare")) {
 			static char git_dir[PATH_MAX+1];
 			is_bare_repository_cfg = 1;
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 1c908f4..c405a78 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -168,6 +168,35 @@ test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
 	cmp .git/index saved-index >/dev/null
 '
 
+test_expect_success 'using alternate --index-file (1)' '
+
+	cp .git/index saved-index &&
+	(
+		echo some new content >file &&
+		index_file=.git/another_index &&
+		git --index-file=$index_file add file &&
+		git --index-file=$index_file commit -m "commit using another index" &&
+		git --index-file=$index_file diff-index --exit-code HEAD &&
+		git --index-file=$index_file diff-files --exit-code
+	) &&
+	cmp .git/index saved-index >/dev/null
+
+'
+
+test_expect_success 'using alternate --index-file (2)' '
+
+	cp .git/index saved-index &&
+	(
+		rm -f .git/no-such-index &&
+		index_file=.git/no-such-index &&
+		git --index-file=$index_file commit -m "commit using nonexistent index" &&
+		test -z "$(git --index-file=$index_file ls-files)" &&
+		test -z "$(git --index-file=$index_file ls-tree HEAD)"
+
+	) &&
+	cmp .git/index saved-index >/dev/null
+'
+
 cat > expect << EOF
 zort
 
-- 
1.8.1.rc1.17.g75ed918.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-14 11:23 [PATCH] git.c: add --index-file command-line option Manlio Perillo
@ 2012-12-15 18:02 ` Junio C Hamano
  2012-12-15 18:53   ` Manlio Perillo
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-12-15 18:02 UTC (permalink / raw)
  To: Manlio Perillo; +Cc: git

Manlio Perillo <manlio.perillo@gmail.com> writes:

> Unlike other environment variables (e.g. GIT_WORK_TREE,
> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE
> environment variable using the command line.

Is this necessary?  I'd prefer to see a better reason than "just
because others have it".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-15 18:02 ` Junio C Hamano
@ 2012-12-15 18:53   ` Manlio Perillo
  2012-12-15 19:36     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Manlio Perillo @ 2012-12-15 18:53 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 15/12/2012 19:02, Junio C Hamano ha scritto:
> Manlio Perillo <manlio.perillo@gmail.com> writes:
> 
>> Unlike other environment variables (e.g. GIT_WORK_TREE,
>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE
>> environment variable using the command line.
> 
> Is this necessary?  I'd prefer to see a better reason than "just
> because others have it".

A long running program will be able to tell git to use an alternate
index file, without having to modify its own environment, or having to
use execvpe (I assume this is the reason why it is possible to specify
GIT_WORK_TREE from command line).



Regards  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEUEARECAAYFAlDMxzsACgkQscQJ24LbaUSzEQCYymkZa6JrT42OzigRfDgc5Hss
gwCgjIzs1b0hEyu1WAgDgCir9XalDN8=
=GtMF
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-15 18:53   ` Manlio Perillo
@ 2012-12-15 19:36     ` Junio C Hamano
  2012-12-15 22:01       ` Manlio Perillo
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-12-15 19:36 UTC (permalink / raw)
  To: Manlio Perillo; +Cc: git

Manlio Perillo <manlio.perillo@gmail.com> writes:

> Il 15/12/2012 19:02, Junio C Hamano ha scritto:
>> Manlio Perillo <manlio.perillo@gmail.com> writes:
>> 
>>> Unlike other environment variables (e.g. GIT_WORK_TREE,
>>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE
>>> environment variable using the command line.
>> 
>> Is this necessary?  I'd prefer to see a better reason than "just
>> because others have it".
>
> A long running program will be able to tell git to use an alternate
> index file, without having to modify its own environment,...

Hrm, isn't that the single-shot environment export syntax

	GIT_INDEX_FILE=foo git blah

is for?  Is there a real-world need for this?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-15 19:36     ` Junio C Hamano
@ 2012-12-15 22:01       ` Manlio Perillo
  2012-12-16  5:59         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Manlio Perillo @ 2012-12-15 22:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 15/12/2012 20:36, Junio C Hamano ha scritto:
> [...]
>>>> Unlike other environment variables (e.g. GIT_WORK_TREE,
>>>> GIT_NAMESPACE), it was not possible to set the GIT_INDEX_FILE
>>>> environment variable using the command line.
>>>
>>> Is this necessary?  I'd prefer to see a better reason than "just
>>> because others have it".
>>
>> A long running program will be able to tell git to use an alternate
>> index file, without having to modify its own environment,...
> 
> Hrm, isn't that the single-shot environment export syntax
> 
> 	GIT_INDEX_FILE=foo git blah
> 
> is for?  Is there a real-world need for this?
> 

This works with a shell.
I'm using Python to write a custom git command.




Regards  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlDM8yQACgkQscQJ24LbaUTftQCbBC7D9P7Sqlr9GzWuCIcIHPf2
aQcAn13+d4trLZS4izGvZtoaopMav4nV
=vfb6
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-15 22:01       ` Manlio Perillo
@ 2012-12-16  5:59         ` Junio C Hamano
  2012-12-16  8:20           ` Manlio Perillo
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-12-16  5:59 UTC (permalink / raw)
  To: Manlio Perillo; +Cc: git

I
Manlio Perillo <manlio.perillo@gmail.com> writes:

> This works with a shell.
> I'm using Python to write a custom git command.

I would be very surprised if Python lacked a way to spawn a
subprocess with an environment modified from the current process.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git.c: add --index-file command-line option.
  2012-12-16  5:59         ` Junio C Hamano
@ 2012-12-16  8:20           ` Manlio Perillo
  0 siblings, 0 replies; 7+ messages in thread
From: Manlio Perillo @ 2012-12-16  8:20 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 16/12/2012 06:59, Junio C Hamano ha scritto:
> I
> Manlio Perillo <manlio.perillo@gmail.com> writes:
> 
>> This works with a shell.
>> I'm using Python to write a custom git command.
> 
> I would be very surprised if Python lacked a way to spawn a
> subprocess with an environment modified from the current process.

Of course it is possible, but a command-line option is more convenient,
IMHO.



Regards  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlDNhGsACgkQscQJ24LbaUQ0dQCglUAw8zwRKNeDUGznfrm1xFKf
GQsAnA/ucztku4v9LnIr0Lv/gyl5ULiT
=j/1w
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-12-16  8:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-14 11:23 [PATCH] git.c: add --index-file command-line option Manlio Perillo
2012-12-15 18:02 ` Junio C Hamano
2012-12-15 18:53   ` Manlio Perillo
2012-12-15 19:36     ` Junio C Hamano
2012-12-15 22:01       ` Manlio Perillo
2012-12-16  5:59         ` Junio C Hamano
2012-12-16  8:20           ` Manlio Perillo

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).