Skip to content

Commit bf883f3

Browse files
martinvonzgitster
authored andcommitted
reset.c: move update_index_refresh() call out of read_from_tree()
The final part of cmd_reset() essentially looks like: if (pathspec) { ... read_from_tree(...); } else { ... reset_index(...); update_index_refresh(...); ... } where read_from_tree() internally also calls update_index_refresh(). Move the call to update_index_refresh() out of read_from_tree for symmetry with the 'else' block, making read_from_tree() and reset_index() closer in functionality. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b489097 commit bf883f3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

builtin/reset.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,23 @@ static void update_index_from_diff(struct diff_queue_struct *q,
145145
}
146146
}
147147

148-
static int read_from_tree(const char **pathspec, unsigned char *tree_sha1,
149-
int refresh_flags)
148+
static int read_from_tree(const char **pathspec, unsigned char *tree_sha1)
150149
{
151-
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
152-
int index_fd;
153150
struct diff_options opt;
154151

155152
memset(&opt, 0, sizeof(opt));
156153
diff_tree_setup_paths(pathspec, &opt);
157154
opt.output_format = DIFF_FORMAT_CALLBACK;
158155
opt.format_callback = update_index_from_diff;
159156

160-
index_fd = hold_locked_index(lock, 1);
161157
read_cache();
162158
if (do_diff_cache(tree_sha1, &opt))
163159
return 1;
164160
diffcore_std(&opt);
165161
diff_flush(&opt);
166162
diff_tree_release_paths(&opt);
167163

168-
return update_index_refresh(index_fd, lock, refresh_flags);
164+
return 0;
169165
}
170166

171167
static void set_reflog_message(struct strbuf *sb, const char *action,
@@ -322,9 +318,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
322318
die(_("%s reset is not allowed in a bare repository"),
323319
_(reset_type_names[reset_type]));
324320

325-
if (pathspec)
326-
return read_from_tree(pathspec, sha1,
327-
quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
321+
if (pathspec) {
322+
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
323+
int index_fd = hold_locked_index(lock, 1);
324+
return read_from_tree(pathspec, sha1) ||
325+
update_index_refresh(index_fd, lock,
326+
quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
327+
}
328328

329329
/* Soft reset does not touch the index file nor the working tree
330330
* at all, but requires them in a good order. Other resets reset

0 commit comments

Comments
 (0)