Skip to content

Commit d0ea882

Browse files
vdyedscho
authored andcommitted
Merge pull request microsoft#428 from vdye/sparse-index/stash
Sparse index: integrate with `git stash`
2 parents 554f95f + b535ff0 commit d0ea882

File tree

8 files changed

+33
-7
lines changed

8 files changed

+33
-7
lines changed

builtin/am.c

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

1616-
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
1616+
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, merge_recursive, &result)) {
16171617
repo_rerere(the_repository, state->allow_rerere_autoupdate);
16181618
free(their_tree_name);
16191619
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

@@ -1786,6 +1787,9 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
17861787
argc = parse_options(argc, argv, prefix, options, git_stash_usage,
17871788
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
17881789

1790+
prepare_repo_settings(the_repository);
1791+
the_repository->settings.command_requires_full_index = 0;
1792+
17891793
index_file = get_index_file();
17901794
strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
17911795
(uintmax_t)pid);

merge-ort.c

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

46864686
/* We set the ancestor label based on the merge_bases */
4687-
assert(opt->ancestor == NULL);
4687+
assert(opt->ancestor == NULL ||
4688+
!strcmp(opt->ancestor, "constructed merge base"));
46884689

46894690
trace2_region_enter("merge", "merge_start", opt->repo);
46904691
merge_start(opt, result);

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,6 +3799,7 @@ int merge_recursive_generic(struct merge_options *opt,
37993799
const struct object_id *merge,
38003800
int num_merge_bases,
38013801
const struct object_id **merge_bases,
3802+
recursive_merge_fn_t merge_fn,
38023803
struct commit **result)
38033804
{
38043805
int clean;
@@ -3822,8 +3823,7 @@ int merge_recursive_generic(struct merge_options *opt,
38223823
}
38233824

38243825
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
3825-
clean = merge_recursive(opt, head_commit, next_commit, ca,
3826-
result);
3826+
clean = merge_fn(opt, head_commit, next_commit, ca, result);
38273827
if (clean < 0) {
38283828
rollback_lock_file(&lock);
38293829
return clean;

merge-recursive.h

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

54+
typedef int (*recursive_merge_fn_t)(struct merge_options *opt,
55+
struct commit *h1,
56+
struct commit *h2,
57+
struct commit_list *merge_bases,
58+
struct commit **result);
59+
5460
void init_merge_options(struct merge_options *opt, struct repository *repo);
5561

5662
/* parse the option in s and update the relevant field of opt */
@@ -103,7 +109,7 @@ int merge_recursive(struct merge_options *opt,
103109

104110
/*
105111
* merge_recursive_generic can operate on trees instead of commits, by
106-
* wrapping the trees into virtual commits, and calling merge_recursive().
112+
* wrapping the trees into virtual commits, and calling the provided merge_fn.
107113
* It also writes out the in-memory index to disk if the merge is successful.
108114
*
109115
* Outputs:
@@ -118,6 +124,7 @@ int merge_recursive_generic(struct merge_options *opt,
118124
const struct object_id *merge,
119125
int num_merge_bases,
120126
const struct object_id **merge_bases,
127+
recursive_merge_fn_t merge_fn,
121128
struct commit **result);
122129

123130
#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
@@ -1258,6 +1258,19 @@ test_expect_success 'sparse-index is not expanded' '
12581258
echo >>sparse-index/untracked.txt &&
12591259
ensure_not_expanded add . &&
12601260
1261+
echo >>sparse-index/a &&
1262+
ensure_not_expanded stash &&
1263+
ensure_not_expanded stash list &&
1264+
ensure_not_expanded stash show stash@{0} &&
1265+
ensure_not_expanded stash apply stash@{0} &&
1266+
ensure_not_expanded stash drop stash@{0} &&
1267+
1268+
ensure_not_expanded stash create &&
1269+
oid=$(git -C sparse-index stash create) &&
1270+
ensure_not_expanded stash store -m "test" $oid &&
1271+
ensure_not_expanded reset --hard &&
1272+
ensure_not_expanded stash pop &&
1273+
12611274
ensure_not_expanded checkout-index -f a &&
12621275
ensure_not_expanded checkout-index -f --all &&
12631276
for ref in update-deep update-folder1 update-folder2 update-deep

0 commit comments

Comments
 (0)