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 <junkio@cox.net>
Junio C Hamano committed
Mar 31, 2007 at 23:27 UTC
5e7f56ac33f7a5583f9fa4e0b6088709fea7a6f8
6 files changed
+30
-16
Documentation/git-read-tree.txt
+13
-1
@@ -8,7 +8,7 @@ git-read-tree - Reads tree information into the index
8
9
SYNOPSIS
10
--------
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>]])
12
13
14
DESCRIPTION
@@ -86,6 +86,18 @@ OPTIONS
86
file (usually '.gitignore') and allows such an untracked
87
but explicitly ignored file to be overwritten.
88
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
+
101
<tree-ish#>::
102
The id of the tree object(s) to be read/merged.
103
Documentation/git.txt
-8
@@ -315,14 +315,6 @@ git so take care if using Cogito etc.
315
index file. If not specified, the default of `$GIT_DIR/index`
316
is used.
317
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
-
318
'GIT_OBJECT_DIRECTORY'::
319
If the object storage directory is specified via this
320
environment variable then the sha1 directories are created
builtin-read-tree.c
+6
-1
@@ -84,7 +84,7 @@ static void prime_cache_tree(void)
84
85
}
86
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>]])";
88
89
static struct lock_file lock_file;
90
@@ -128,6 +128,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
128
continue;
129
}
130
131
+ if (!prefixcmp(arg, "--index-output=")) {
132
+ set_alternate_index_output(arg + 15);
133
+ continue;
134
+ }
135
+
136
/* "--prefix=<subdirectory>/" means keep the current index
137
* entries and put the entries from the tree under the
138
* given subdirectory.
cache.h
+1
-1
@@ -147,7 +147,6 @@ enum object_type {
147
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
148
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
149
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
150
-#define INDEX_OUTPUT_ENVIRONMENT "_GIT_INDEX_OUTPUT"
150
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
151
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
152
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
@@ -216,6 +215,7 @@ extern int commit_lock_file(struct lock_file *);
215
216
extern int hold_locked_index(struct lock_file *, int);
217
extern int commit_locked_index(struct lock_file *);
218
+extern void set_alternate_index_output(const char *);
219
220
extern void rollback_lock_file(struct lock_file *);
221
extern int delete_ref(const char *, unsigned char *sha1);
git-commit.sh
+2
-2
@@ -370,8 +370,8 @@ t,)
370
# the same way.
371
if test -z "$initial_commit"
372
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
375
else
376
rm -f "$TMP_INDEX"
377
fi || exit
lockfile.c
+8
-3
@@ -4,6 +4,7 @@
4
#include "cache.h"
5
6
static struct lock_file *lock_file_list;
7
+static const char *alternate_index_output;
8
9
static void remove_lock_file(void)
10
{
@@ -70,11 +71,15 @@ int hold_locked_index(struct lock_file *lk, int die_on_error)
71
return hold_lock_file_for_update(lk, get_index_file(), die_on_error);
72
}
73
74
+void set_alternate_index_output(const char *name)
75
+{
76
+ alternate_index_output = name;
77
+}
78
+
79
int commit_locked_index(struct lock_file *lk)
80
{
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);
83
lk->filename[0] = 0;
84
return result;
85
}