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 <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Jan 14, 2013 at 21:47 UTC bf883f3006f719ba1ade0180f1764f42cc20b529
1 file changed +9 -9
builtin/reset.c
+9 -9
@@ -145,11 +145,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,
145 }
146 }
147
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)
149 {
151 - struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
152 - int index_fd;
150 struct diff_options opt;
151
152 memset(&opt, 0, sizeof(opt));
@@ -157,7 +154,6 @@ static int read_from_tree(const char **pathspec, unsigned char *tree_sha1,
154 opt.output_format = DIFF_FORMAT_CALLBACK;
155 opt.format_callback = update_index_from_diff;
156
160 - index_fd = hold_locked_index(lock, 1);
157 read_cache();
158 if (do_diff_cache(tree_sha1, &opt))
159 return 1;
@@ -165,7 +161,7 @@ static int read_from_tree(const char **pathspec, unsigned char *tree_sha1,
161 diff_flush(&opt);
162 diff_tree_release_paths(&opt);
163
168 - return update_index_refresh(index_fd, lock, refresh_flags);
164 + return 0;
165 }
166
167 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)
318 die(_("%s reset is not allowed in a bare repository"),
319 _(reset_type_names[reset_type]));
320
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 + }
328
329 /* Soft reset does not touch the index file nor the working tree
330 * at all, but requires them in a good order. Other resets reset