Skip to content

Commit d6554d0

Browse files
stash: introduce build_stash_commit_from_index
we want to build a partial stash from an index in the future, so some functions have been reworked to allow for this
1 parent 4c98283 commit d6554d0

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

src/stash.c

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,80 @@ static int build_workdir_tree(
389389
return error;
390390
}
391391

392-
static int commit_worktree(
392+
static int build_stash_commit_from_tree(
393393
git_oid *w_commit_oid,
394394
git_repository *repo,
395395
const git_signature *stasher,
396396
const char *message,
397397
git_commit *i_commit,
398398
git_commit *b_commit,
399-
git_commit *u_commit)
399+
git_commit *u_commit,
400+
git_tree *tree)
400401
{
401402
const git_commit *parents[] = { NULL, NULL, NULL };
402-
git_index *i_index = NULL, *r_index = NULL;
403-
git_tree *w_tree = NULL;
404-
int error = 0, ignorecase;
405403

406404
parents[0] = b_commit;
407405
parents[1] = i_commit;
408406
parents[2] = u_commit;
409407

408+
return git_commit_create(
409+
w_commit_oid,
410+
repo,
411+
NULL,
412+
stasher,
413+
stasher,
414+
NULL,
415+
message,
416+
tree,
417+
u_commit ? 3 : 2,
418+
parents);
419+
}
420+
421+
static int build_stash_commit_from_index(
422+
git_oid *w_commit_oid,
423+
git_repository *repo,
424+
const git_signature *stasher,
425+
const char *message,
426+
git_commit *i_commit,
427+
git_commit *b_commit,
428+
git_commit *u_commit,
429+
git_index *index)
430+
{
431+
git_tree *tree;
432+
int error;
433+
434+
if ((error = build_tree_from_index(&tree, repo, index)) < 0)
435+
goto cleanup;
436+
437+
error = build_stash_commit_from_tree(
438+
w_commit_oid,
439+
repo,
440+
stasher,
441+
message,
442+
i_commit,
443+
b_commit,
444+
u_commit,
445+
tree
446+
);
447+
448+
cleanup:
449+
git_tree_free(tree);
450+
return error;
451+
}
452+
453+
static int commit_worktree(
454+
git_oid *w_commit_oid,
455+
git_repository *repo,
456+
const git_signature *stasher,
457+
const char *message,
458+
git_commit *i_commit,
459+
git_commit *b_commit,
460+
git_commit *u_commit)
461+
{
462+
git_index *i_index = NULL, *r_index = NULL;
463+
git_tree *w_tree = NULL;
464+
int error = 0, ignorecase;
465+
410466
if ((error = git_repository_index(&r_index, repo) < 0) ||
411467
(error = git_index_new(&i_index)) < 0 ||
412468
(error = git_index__fill(i_index, &r_index->entries) < 0) ||
@@ -418,17 +474,16 @@ static int commit_worktree(
418474
if ((error = build_workdir_tree(&w_tree, repo, i_index, b_commit)) < 0)
419475
goto cleanup;
420476

421-
error = git_commit_create(
477+
error = build_stash_commit_from_tree(
422478
w_commit_oid,
423479
repo,
424-
NULL,
425-
stasher,
426480
stasher,
427-
NULL,
428481
message,
429-
w_tree,
430-
u_commit ? 3 : 2,
431-
parents);
482+
i_commit,
483+
b_commit,
484+
u_commit,
485+
w_tree
486+
);
432487

433488
cleanup:
434489
git_tree_free(w_tree);

0 commit comments

Comments
 (0)