Skip to content

Commit 10746a3

Browse files
martinvonzgitster
authored andcommitted
reset $pathspec: no need to discard index
Since 34110cd (Make 'unpack_trees()' have a separate source and destination index, 2008-03-06), the index no longer gets clobbered by do_diff_cache() and we can remove the code for discarding and re-reading it. There are two paths to update_index_refresh() from cmd_reset(), but on both paths, either read_cache() or read_cache_unmerged() will have been called, so the call to read_cache() in this method is redundant (although practically free). This speeds up "git reset -- ." a little on the linux-2.6 repo (best of five, warm cache): Before After real 0m0.093s 0m0.080s user 0m0.040s 0m0.020s sys 0m0.050s 0m0.050s Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44fe835 commit 10746a3

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

builtin/reset.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ static int update_index_refresh(int fd, struct lock_file *index_lock, int flags)
126126
fd = hold_locked_index(index_lock, 1);
127127
}
128128

129-
if (read_cache() < 0)
130-
return error(_("Could not read index"));
131-
132129
result = refresh_index(&the_index, (flags), NULL, NULL,
133130
_("Unstaged changes after reset:")) ? 1 : 0;
134131
if (write_cache(fd, active_cache, active_nr) ||
@@ -141,12 +138,6 @@ static void update_index_from_diff(struct diff_queue_struct *q,
141138
struct diff_options *opt, void *data)
142139
{
143140
int i;
144-
int *discard_flag = data;
145-
146-
/* do_diff_cache() mangled the index */
147-
discard_cache();
148-
*discard_flag = 1;
149-
read_cache();
150141

151142
for (i = 0; i < q->nr; i++) {
152143
struct diff_filespec *one = q->queue[i]->one;
@@ -179,27 +170,22 @@ static int read_from_tree(const char *prefix, const char **argv,
179170
unsigned char *tree_sha1, int refresh_flags)
180171
{
181172
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
182-
int index_fd, index_was_discarded = 0;
173+
int index_fd;
183174
struct diff_options opt;
184175

185176
memset(&opt, 0, sizeof(opt));
186177
diff_tree_setup_paths(get_pathspec(prefix, (const char **)argv), &opt);
187178
opt.output_format = DIFF_FORMAT_CALLBACK;
188179
opt.format_callback = update_index_from_diff;
189-
opt.format_callback_data = &index_was_discarded;
190180

191181
index_fd = hold_locked_index(lock, 1);
192-
index_was_discarded = 0;
193182
read_cache();
194183
if (do_diff_cache(tree_sha1, &opt))
195184
return 1;
196185
diffcore_std(&opt);
197186
diff_flush(&opt);
198187
diff_tree_release_paths(&opt);
199188

200-
if (!index_was_discarded)
201-
/* The index is still clobbered from do_diff_cache() */
202-
discard_cache();
203189
return update_index_refresh(index_fd, lock, refresh_flags);
204190
}
205191

0 commit comments

Comments
 (0)