Skip to content

Commit 6286a08

Browse files
committed
checkout: consolidate reset_{to_new,clean_to_new}()
These two were very similar functions with only tiny bit of difference. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 84a5750 commit 6286a08

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

builtin-checkout.c

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -151,39 +151,29 @@ static void describe_detached_head(char *msg, struct commit *commit)
151151
strbuf_release(&sb);
152152
}
153153

154-
static int reset_to_new(struct tree *tree, int quiet)
155-
{
156-
struct unpack_trees_options opts;
157-
struct tree_desc tree_desc;
154+
struct checkout_opts {
155+
int quiet;
156+
int merge;
157+
int force;
158158

159-
memset(&opts, 0, sizeof(opts));
160-
opts.head_idx = -1;
161-
opts.update = 1;
162-
opts.reset = 1;
163-
opts.merge = 1;
164-
opts.fn = oneway_merge;
165-
opts.verbose_update = !quiet;
166-
opts.src_index = &the_index;
167-
opts.dst_index = &the_index;
168-
parse_tree(tree);
169-
init_tree_desc(&tree_desc, tree->buffer, tree->size);
170-
if (unpack_trees(1, &tree_desc, &opts))
171-
return 128;
172-
return 0;
173-
}
159+
char *new_branch;
160+
int new_branch_log;
161+
enum branch_track track;
162+
};
174163

175-
static int reset_clean_to_new(struct tree *tree, int quiet)
164+
static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
176165
{
177166
struct unpack_trees_options opts;
178167
struct tree_desc tree_desc;
179168

180169
memset(&opts, 0, sizeof(opts));
181170
opts.head_idx = -1;
182-
opts.skip_unmerged = 1;
171+
opts.update = worktree;
172+
opts.skip_unmerged = !worktree;
183173
opts.reset = 1;
184174
opts.merge = 1;
185175
opts.fn = oneway_merge;
186-
opts.verbose_update = !quiet;
176+
opts.verbose_update = !o->quiet;
187177
opts.src_index = &the_index;
188178
opts.dst_index = &the_index;
189179
parse_tree(tree);
@@ -193,16 +183,6 @@ static int reset_clean_to_new(struct tree *tree, int quiet)
193183
return 0;
194184
}
195185

196-
struct checkout_opts {
197-
int quiet;
198-
int merge;
199-
int force;
200-
201-
char *new_branch;
202-
int new_branch_log;
203-
enum branch_track track;
204-
};
205-
206186
struct branch_info {
207187
const char *name; /* The short name used */
208188
const char *path; /* The full name of a real branch */
@@ -227,7 +207,7 @@ static int merge_working_tree(struct checkout_opts *opts,
227207
read_cache();
228208

229209
if (opts->force) {
230-
ret = reset_to_new(new->commit->tree, opts->quiet);
210+
ret = reset_tree(new->commit->tree, opts, 1);
231211
if (ret)
232212
return ret;
233213
} else {
@@ -291,12 +271,12 @@ static int merge_working_tree(struct checkout_opts *opts,
291271
add_files_to_cache(NULL, NULL, 0);
292272
work = write_tree_from_memory();
293273

294-
ret = reset_to_new(new->commit->tree, opts->quiet);
274+
ret = reset_tree(new->commit->tree, opts, 1);
295275
if (ret)
296276
return ret;
297277
merge_trees(new->commit->tree, work, old->commit->tree,
298278
new->name, "local", &result);
299-
ret = reset_clean_to_new(new->commit->tree, opts->quiet);
279+
ret = reset_tree(new->commit->tree, opts, 0);
300280
if (ret)
301281
return ret;
302282
}

0 commit comments

Comments
 (0)