Skip to content

Commit 32213da

Browse files
vdyedscho
authored andcommitted
Merge pull request #428 from vdye/sparse-index/stash
Sparse index: integrate with `git stash`
2 parents 7d47378 + 9065355 commit 32213da

8 files changed

+33
-7
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16141614
if (state->quiet)
16151615
o.verbosity = 0;
16161616

1617-
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
1617+
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, merge_recursive, &result)) {
16181618
repo_rerere(the_repository, state->allow_rerere_autoupdate);
16191619
free(their_tree_name);
16201620
return error(_("Failed to merge in the changes."));

builtin/merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
8181
if (o.verbosity >= 3)
8282
printf(_("Merging %s with %s\n"), o.branch1, o.branch2);
8383

84-
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
84+
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, merge_recursive, &result);
8585

8686
free(better1);
8787
free(better2);

builtin/stash.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "cache-tree.h"
88
#include "unpack-trees.h"
99
#include "merge-recursive.h"
10+
#include "merge-ort-wrappers.h"
1011
#include "strvec.h"
1112
#include "run-command.h"
1213
#include "dir.h"
@@ -554,7 +555,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
554555
bases[0] = &info->b_tree;
555556

556557
ret = merge_recursive_generic(&o, &c_tree, &info->w_tree, 1, bases,
557-
&result);
558+
merge_ort_recursive, &result);
558559
if (ret) {
559560
rerere(0);
560561

@@ -1770,6 +1771,9 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
17701771
argc = parse_options(argc, argv, prefix, options, git_stash_usage,
17711772
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
17721773

1774+
prepare_repo_settings(the_repository);
1775+
the_repository->settings.command_requires_full_index = 0;
1776+
17731777
index_file = get_index_file();
17741778
strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
17751779
(uintmax_t)pid);

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4737,7 +4737,8 @@ void merge_incore_recursive(struct merge_options *opt,
47374737
trace2_region_enter("merge", "incore_recursive", opt->repo);
47384738

47394739
/* We set the ancestor label based on the merge_bases */
4740-
assert(opt->ancestor == NULL);
4740+
assert(opt->ancestor == NULL ||
4741+
!strcmp(opt->ancestor, "constructed merge base"));
47414742

47424743
trace2_region_enter("merge", "merge_start", opt->repo);
47434744
merge_start(opt, result);

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,6 +3806,7 @@ int merge_recursive_generic(struct merge_options *opt,
38063806
const struct object_id *merge,
38073807
int num_merge_bases,
38083808
const struct object_id **merge_bases,
3809+
recursive_merge_fn_t merge_fn,
38093810
struct commit **result)
38103811
{
38113812
int clean;
@@ -3829,8 +3830,7 @@ int merge_recursive_generic(struct merge_options *opt,
38293830
}
38303831

38313832
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
3832-
clean = merge_recursive(opt, head_commit, next_commit, ca,
3833-
result);
3833+
clean = merge_fn(opt, head_commit, next_commit, ca, result);
38343834
if (clean < 0) {
38353835
rollback_lock_file(&lock);
38363836
return clean;

merge-recursive.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct merge_options {
5353
struct merge_options_internal *priv;
5454
};
5555

56+
typedef int (*recursive_merge_fn_t)(struct merge_options *opt,
57+
struct commit *h1,
58+
struct commit *h2,
59+
struct commit_list *merge_bases,
60+
struct commit **result);
61+
5662
void init_merge_options(struct merge_options *opt, struct repository *repo);
5763

5864
/* parse the option in s and update the relevant field of opt */
@@ -105,7 +111,7 @@ int merge_recursive(struct merge_options *opt,
105111

106112
/*
107113
* merge_recursive_generic can operate on trees instead of commits, by
108-
* wrapping the trees into virtual commits, and calling merge_recursive().
114+
* wrapping the trees into virtual commits, and calling the provided merge_fn.
109115
* It also writes out the in-memory index to disk if the merge is successful.
110116
*
111117
* Outputs:
@@ -120,6 +126,7 @@ int merge_recursive_generic(struct merge_options *opt,
120126
const struct object_id *merge,
121127
int num_merge_bases,
122128
const struct object_id **merge_bases,
129+
recursive_merge_fn_t merge_fn,
123130
struct commit **result);
124131

125132
#endif

t/perf/p2000-sparse-operations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ test_perf_on_all () {
106106
}
107107

108108
test_perf_on_all git status
109+
test_perf_on_all 'git stash && git stash pop'
109110
test_perf_on_all git add -A
110111
test_perf_on_all git add .
111112
test_perf_on_all git commit -a -m A

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,19 @@ test_expect_success 'sparse-index is not expanded' '
13031303
echo >>sparse-index/untracked.txt &&
13041304
ensure_not_expanded add . &&
13051305
1306+
echo >>sparse-index/a &&
1307+
ensure_not_expanded stash &&
1308+
ensure_not_expanded stash list &&
1309+
ensure_not_expanded stash show stash@{0} &&
1310+
ensure_not_expanded stash apply stash@{0} &&
1311+
ensure_not_expanded stash drop stash@{0} &&
1312+
1313+
ensure_not_expanded stash create &&
1314+
oid=$(git -C sparse-index stash create) &&
1315+
ensure_not_expanded stash store -m "test" $oid &&
1316+
ensure_not_expanded reset --hard &&
1317+
ensure_not_expanded stash pop &&
1318+
13061319
ensure_not_expanded checkout-index -f a &&
13071320
ensure_not_expanded checkout-index -f --all &&
13081321
for ref in update-deep update-folder1 update-folder2 update-deep

0 commit comments

Comments
 (0)