Skip to content

Commit 5e7f56a

Browse files
author
Junio C Hamano
committed
git-read-tree --index-output=<file>
This corrects the interface mistake of the previous one, and gives a command line parameter to the only plumbing command that currently needs it: "git-read-tree". We can add the calls to set_alternate_index_output() to other plumbing commands that update the index if/when needed. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30ca07a commit 5e7f56a

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

Documentation/git-read-tree.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-read-tree - Reads tree information into the index
88

99
SYNOPSIS
1010
--------
11-
'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
11+
'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
1212

1313

1414
DESCRIPTION
@@ -86,6 +86,18 @@ OPTIONS
8686
file (usually '.gitignore') and allows such an untracked
8787
but explicitly ignored file to be overwritten.
8888

89+
--index-output=<file>::
90+
Instead of writing the results out to `$GIT_INDEX_FILE`,
91+
write the resulting index in the named file. While the
92+
command is operating, the original index file is locked
93+
with the same mechanism as usual. The file must allow
94+
to be rename(2)ed into from a temporary file that is
95+
created next to the usual index file; typically this
96+
means it needs to be on the same filesystem as the index
97+
file itself, and you need write permission to the
98+
directories the index file and index output file are
99+
located in.
100+
89101
<tree-ish#>::
90102
The id of the tree object(s) to be read/merged.
91103

Documentation/git.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,6 @@ git so take care if using Cogito etc.
315315
index file. If not specified, the default of `$GIT_DIR/index`
316316
is used.
317317

318-
'_GIT_INDEX_OUTPUT'::
319-
When this environment is defined, plumbing level
320-
commands that update the index writes the resulting
321-
index to this file, instead of `$GIT_INDEX_FILE` (or its
322-
default `$GIT_DIR/index`). This is solely meant to be
323-
used by Porcelain to drive low-level plumbing. Defining
324-
this in user's environment is always an error.
325-
326318
'GIT_OBJECT_DIRECTORY'::
327319
If the object storage directory is specified via this
328320
environment variable then the sha1 directories are created

builtin-read-tree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void prime_cache_tree(void)
8484

8585
}
8686

87-
static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] <sha1> [<sha2> [<sha3>]])";
87+
static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
8888

8989
static struct lock_file lock_file;
9090

@@ -128,6 +128,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
128128
continue;
129129
}
130130

131+
if (!prefixcmp(arg, "--index-output=")) {
132+
set_alternate_index_output(arg + 15);
133+
continue;
134+
}
135+
131136
/* "--prefix=<subdirectory>/" means keep the current index
132137
* entries and put the entries from the tree under the
133138
* given subdirectory.

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ enum object_type {
147147
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
148148
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
149149
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
150-
#define INDEX_OUTPUT_ENVIRONMENT "_GIT_INDEX_OUTPUT"
151150
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
152151
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
153152
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
@@ -216,6 +215,7 @@ extern int commit_lock_file(struct lock_file *);
216215

217216
extern int hold_locked_index(struct lock_file *, int);
218217
extern int commit_locked_index(struct lock_file *);
218+
extern void set_alternate_index_output(const char *);
219219

220220
extern void rollback_lock_file(struct lock_file *);
221221
extern int delete_ref(const char *, unsigned char *sha1);

git-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ t,)
370370
# the same way.
371371
if test -z "$initial_commit"
372372
then
373-
_GIT_INDEX_OUTPUT="$TMP_INDEX" \
374-
GIT_INDEX_FILE="$THIS_INDEX" git-read-tree -i -m HEAD
373+
GIT_INDEX_FILE="$THIS_INDEX" \
374+
git-read-tree --index-output="$TMP_INDEX" -i -m HEAD
375375
else
376376
rm -f "$TMP_INDEX"
377377
fi || exit

lockfile.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cache.h"
55

66
static struct lock_file *lock_file_list;
7+
static const char *alternate_index_output;
78

89
static void remove_lock_file(void)
910
{
@@ -70,11 +71,15 @@ int hold_locked_index(struct lock_file *lk, int die_on_error)
7071
return hold_lock_file_for_update(lk, get_index_file(), die_on_error);
7172
}
7273

74+
void set_alternate_index_output(const char *name)
75+
{
76+
alternate_index_output = name;
77+
}
78+
7379
int commit_locked_index(struct lock_file *lk)
7480
{
75-
char *output = getenv(INDEX_OUTPUT_ENVIRONMENT);
76-
if (output && *output) {
77-
int result = rename(lk->filename, output);
81+
if (alternate_index_output) {
82+
int result = rename(lk->filename, alternate_index_output);
7883
lk->filename[0] = 0;
7984
return result;
8085
}

0 commit comments

Comments
 (0)