Skip to content

Commit ee9693e

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/index-output'
* jc/index-output: git-read-tree --index-output=<file> _GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file. Conflicts: builtin-apply.c
2 parents 3941544 + 5e7f56a commit ee9693e

13 files changed

+66
-25
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

builtin-add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
133133

134134
git_config(git_add_config);
135135

136-
newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
136+
newfd = hold_locked_index(&lock_file, 1);
137137

138138
for (i = 1; i < argc; i++) {
139139
const char *arg = argv[i];
@@ -209,7 +209,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
209209

210210
if (active_cache_changed) {
211211
if (write_cache(newfd, active_cache, active_nr) ||
212-
close(newfd) || commit_lock_file(&lock_file))
212+
close(newfd) || commit_locked_index(&lock_file))
213213
die("Unable to write new index file");
214214
}
215215

builtin-apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,8 +2664,8 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
26642664

26652665
update_index = check_index && apply;
26662666
if (update_index && newfd < 0)
2667-
newfd = hold_lock_file_for_update(&lock_file,
2668-
get_index_file(), 1);
2667+
newfd = hold_locked_index(&lock_file, 1);
2668+
26692669
if (check_index) {
26702670
if (read_cache() < 0)
26712671
die("unable to read index file");
@@ -2872,7 +2872,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
28722872

28732873
if (update_index) {
28742874
if (write_cache(newfd, active_cache, active_nr) ||
2875-
close(newfd) || commit_lock_file(&lock_file))
2875+
close(newfd) || commit_locked_index(&lock_file))
28762876
die("Unable to write new index file");
28772877
}
28782878

builtin-checkout-index.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
202202
if (!strcmp(arg, "-u") || !strcmp(arg, "--index")) {
203203
state.refresh_cache = 1;
204204
if (newfd < 0)
205-
newfd = hold_lock_file_for_update
206-
(&lock_file, get_index_file(), 1);
207-
if (newfd < 0)
208-
die("cannot open index.lock file.");
205+
newfd = hold_locked_index(&lock_file, 1);
209206
continue;
210207
}
211208
if (!strcmp(arg, "-z")) {
@@ -302,7 +299,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
302299

303300
if (0 <= newfd &&
304301
(write_cache(newfd, active_cache, active_nr) ||
305-
close(newfd) || commit_lock_file(&lock_file)))
302+
close(newfd) || commit_locked_index(&lock_file)))
306303
die("Unable to write new index file");
307304
return 0;
308305
}

builtin-mv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
7777

7878
git_config(git_default_config);
7979

80-
newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
80+
newfd = hold_locked_index(&lock_file, 1);
8181
if (read_cache() < 0)
8282
die("index file corrupt");
8383

@@ -285,7 +285,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
285285
if (active_cache_changed) {
286286
if (write_cache(newfd, active_cache, active_nr) ||
287287
close(newfd) ||
288-
commit_lock_file(&lock_file))
288+
commit_locked_index(&lock_file))
289289
die("Unable to write new index file");
290290
}
291291
}

builtin-read-tree.c

Lines changed: 8 additions & 3 deletions
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

@@ -100,7 +100,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
100100
setup_git_directory();
101101
git_config(git_default_config);
102102

103-
newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
103+
newfd = hold_locked_index(&lock_file, 1);
104104

105105
git_config(git_default_config);
106106

@@ -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.
@@ -267,7 +272,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
267272
}
268273

269274
if (write_cache(newfd, active_cache, active_nr) ||
270-
close(newfd) || commit_lock_file(&lock_file))
275+
close(newfd) || commit_locked_index(&lock_file))
271276
die("unable to write new index file");
272277
return 0;
273278
}

builtin-rm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
110110

111111
git_config(git_default_config);
112112

113-
newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
113+
newfd = hold_locked_index(&lock_file, 1);
114114

115115
if (read_cache() < 0)
116116
die("index file corrupt");
@@ -220,7 +220,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
220220

221221
if (active_cache_changed) {
222222
if (write_cache(newfd, active_cache, active_nr) ||
223-
close(newfd) || commit_lock_file(&lock_file))
223+
close(newfd) || commit_locked_index(&lock_file))
224224
die("Unable to write new index file");
225225
}
226226

builtin-update-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
495495
/* We can't free this memory, it becomes part of a linked list parsed atexit() */
496496
lock_file = xcalloc(1, sizeof(struct lock_file));
497497

498-
newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
498+
newfd = hold_locked_index(lock_file, 0);
499499
if (newfd < 0)
500500
lock_error = errno;
501501

@@ -661,7 +661,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
661661
get_index_file(), strerror(lock_error));
662662
}
663663
if (write_cache(newfd, active_cache, active_nr) ||
664-
close(newfd) || commit_lock_file(lock_file))
664+
close(newfd) || commit_locked_index(lock_file))
665665
die("Unable to write new index file");
666666
}
667667

builtin-write-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
1818
/* We can't free this memory, it becomes part of a linked list parsed atexit() */
1919
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
2020

21-
newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
21+
newfd = hold_locked_index(lock_file, 1);
2222

2323
entries = read_cache();
2424
if (entries < 0)

cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ struct lock_file {
211211
};
212212
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
213213
extern int commit_lock_file(struct lock_file *);
214+
215+
extern int hold_locked_index(struct lock_file *, int);
216+
extern int commit_locked_index(struct lock_file *);
217+
extern void set_alternate_index_output(const char *);
218+
214219
extern void rollback_lock_file(struct lock_file *);
215220
extern int delete_ref(const char *, unsigned char *sha1);
216221

0 commit comments

Comments
 (0)