Skip to content

Commit c8c6379

Browse files
authored
Merge pull request git-for-windows#428 from vdye/sparse-index/stash
Sparse index: integrate with `git stash`
2 parents 52ac048 + 613c955 commit c8c6379

9 files changed

+35
-9
lines changed

builtin/am.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15851585
if (state->quiet)
15861586
o.verbosity = 0;
15871587

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

builtin/merge-recursive.c

+1-1
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

+5-1
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"
@@ -541,7 +542,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
541542
bases[0] = &info->b_tree;
542543

543544
ret = merge_recursive_generic(&o, &c_tree, &info->w_tree, 1, bases,
544-
&result);
545+
merge_ort_recursive, &result);
545546
if (ret) {
546547
rerere(0);
547548

@@ -1703,6 +1704,9 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
17031704
argc = parse_options(argc, argv, prefix, options, git_stash_usage,
17041705
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
17051706

1707+
prepare_repo_settings(the_repository);
1708+
the_repository->settings.command_requires_full_index = 0;
1709+
17061710
index_file = get_index_file();
17071711
strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
17081712
(uintmax_t)pid);

merge-ort.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -4652,7 +4652,8 @@ void merge_incore_recursive(struct merge_options *opt,
46524652
trace2_region_enter("merge", "incore_recursive", opt->repo);
46534653

46544654
/* We set the ancestor label based on the merge_bases */
4655-
assert(opt->ancestor == NULL);
4655+
assert(opt->ancestor == NULL ||
4656+
!strcmp(opt->ancestor, "constructed merge base"));
46564657

46574658
trace2_region_enter("merge", "merge_start", opt->repo);
46584659
merge_start(opt, result);

merge-recursive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,7 @@ int merge_recursive_generic(struct merge_options *opt,
37853785
const struct object_id *merge,
37863786
int num_merge_bases,
37873787
const struct object_id **merge_bases,
3788+
recursive_merge_fn_t merge_fn,
37883789
struct commit **result)
37893790
{
37903791
int clean;
@@ -3808,8 +3809,7 @@ int merge_recursive_generic(struct merge_options *opt,
38083809
}
38093810

38103811
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
3811-
clean = merge_recursive(opt, head_commit, next_commit, ca,
3812-
result);
3812+
clean = merge_fn(opt, head_commit, next_commit, ca, result);
38133813
if (clean < 0) {
38143814
rollback_lock_file(&lock);
38153815
return clean;

merge-recursive.h

+8-1
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

+1
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/perf/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ set_git_test_installed () {
7474
mydir=$1
7575

7676
mydir_abs=$(cd $mydir && pwd)
77-
mydir_abs_wrappers="$mydir_abs_wrappers/bin-wrappers"
77+
mydir_abs_wrappers="$mydir_abs/bin-wrappers"
7878
if test -d "$mydir_abs_wrappers"
7979
then
8080
GIT_TEST_INSTALLED=$mydir_abs_wrappers

t/t1092-sparse-checkout-compatibility.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ test_expect_success 'reset with wildcard pathspec' '
621621
622622
test_all_match git checkout -b reset-test update-deep &&
623623
test_all_match git reset --hard update-folder1 &&
624-
test_all_match git reset base -- */a &&
624+
test_all_match git reset base -- \*/a &&
625625
test_all_match git status --porcelain=v2
626626
'
627627

@@ -1159,6 +1159,19 @@ test_expect_success 'sparse-index is not expanded' '
11591159
echo >>sparse-index/untracked.txt &&
11601160
ensure_not_expanded add . &&
11611161
1162+
echo >>sparse-index/a &&
1163+
ensure_not_expanded stash &&
1164+
ensure_not_expanded stash list &&
1165+
ensure_not_expanded stash show stash@{0} &&
1166+
ensure_not_expanded stash apply stash@{0} &&
1167+
ensure_not_expanded stash drop stash@{0} &&
1168+
1169+
ensure_not_expanded stash create &&
1170+
oid=$(git -C sparse-index stash create) &&
1171+
ensure_not_expanded stash store -m "test" $oid &&
1172+
ensure_not_expanded reset --hard &&
1173+
ensure_not_expanded stash pop &&
1174+
11621175
ensure_not_expanded checkout-index -f a &&
11631176
ensure_not_expanded checkout-index -f --all &&
11641177
for ref in update-deep update-folder1 update-folder2 update-deep

0 commit comments

Comments
 (0)