@@ -389,24 +389,80 @@ static int build_workdir_tree(
389
389
return error ;
390
390
}
391
391
392
- static int commit_worktree (
392
+ static int build_stash_commit_from_tree (
393
393
git_oid * w_commit_oid ,
394
394
git_repository * repo ,
395
395
const git_signature * stasher ,
396
396
const char * message ,
397
397
git_commit * i_commit ,
398
398
git_commit * b_commit ,
399
- git_commit * u_commit )
399
+ git_commit * u_commit ,
400
+ git_tree * tree )
400
401
{
401
402
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 ;
405
403
406
404
parents [0 ] = b_commit ;
407
405
parents [1 ] = i_commit ;
408
406
parents [2 ] = u_commit ;
409
407
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
+
410
466
if ((error = git_repository_index (& r_index , repo ) < 0 ) ||
411
467
(error = git_index_new (& i_index )) < 0 ||
412
468
(error = git_index__fill (i_index , & r_index -> entries ) < 0 ) ||
@@ -418,17 +474,16 @@ static int commit_worktree(
418
474
if ((error = build_workdir_tree (& w_tree , repo , i_index , b_commit )) < 0 )
419
475
goto cleanup ;
420
476
421
- error = git_commit_create (
477
+ error = build_stash_commit_from_tree (
422
478
w_commit_oid ,
423
479
repo ,
424
- NULL ,
425
- stasher ,
426
480
stasher ,
427
- NULL ,
428
481
message ,
429
- w_tree ,
430
- u_commit ? 3 : 2 ,
431
- parents );
482
+ i_commit ,
483
+ b_commit ,
484
+ u_commit ,
485
+ w_tree
486
+ );
432
487
433
488
cleanup :
434
489
git_tree_free (w_tree );
0 commit comments