@@ -199,16 +199,16 @@ static int stash_update_index_from_paths(
199199 const git_strarray * paths )
200200{
201201 unsigned int status_flags ;
202- size_t i , error = 0 ;
202+ size_t i ;
203+ int error = 0 ;
203204
204- for (i = 0 ; i < paths -> count ; i ++ ) {
205+ for (i = 0 ; i < paths -> count ; i ++ ) {
205206 git_status_file (& status_flags , repo , paths -> strings [i ]);
206207
207208 if (status_flags & (GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_DELETED )) {
208209 if ((error = git_index_remove (index , paths -> strings [i ], 0 )) < 0 )
209210 return error ;
210- }
211- else {
211+ } else {
212212 if ((error = stash_to_index (repo , index , paths -> strings [i ])) < 0 )
213213 return error ;
214214 }
@@ -453,7 +453,7 @@ static int build_stash_commit_from_index(
453453{
454454 git_tree * tree ;
455455 int error ;
456-
456+
457457 if ((error = build_tree_from_index (& tree , repo , index )) < 0 )
458458 goto cleanup ;
459459
@@ -465,8 +465,7 @@ static int build_stash_commit_from_index(
465465 i_commit ,
466466 b_commit ,
467467 u_commit ,
468- tree
469- );
468+ tree );
470469
471470cleanup :
472471 git_tree_free (tree );
@@ -599,7 +598,11 @@ static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flag
599598 return error ;
600599}
601600
602- static int has_changes_cb (const char * path , unsigned int status , void * payload ) {
601+ static int has_changes_cb (
602+ const char * path ,
603+ unsigned int status ,
604+ void * payload )
605+ {
603606 GIT_UNUSED (path );
604607 GIT_UNUSED (status );
605608 GIT_UNUSED (payload );
@@ -619,9 +622,9 @@ static int ensure_there_are_changes_to_stash_paths(
619622 git_status_options opts = GIT_STATUS_OPTIONS_INIT ;
620623
621624 opts .show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR ;
622- opts .flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES
623- | GIT_STATUS_OPT_INCLUDE_UNMODIFIED
624- | GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH ;
625+ opts .flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES |
626+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
627+ GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH ;
625628
626629 if (flags & GIT_STASH_INCLUDE_UNTRACKED )
627630 opts .flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
@@ -630,7 +633,7 @@ static int ensure_there_are_changes_to_stash_paths(
630633 if (flags & GIT_STASH_INCLUDE_IGNORED )
631634 opts .flags |= GIT_STATUS_OPT_INCLUDE_IGNORED |
632635 GIT_STATUS_OPT_RECURSE_IGNORED_DIRS ;
633-
636+
634637 git_strarray_copy (& opts .pathspec , paths );
635638
636639 error = git_status_foreach_ext (repo , & opts , has_changes_cb , NULL );
@@ -664,17 +667,20 @@ int git_stash_save(
664667 uint32_t flags )
665668{
666669 git_stash_save_options opts = GIT_STASH_SAVE_OPTIONS_INIT ;
667-
670+
668671 GIT_ASSERT_ARG (stasher );
669-
672+
670673 opts .stasher = stasher ;
671674 opts .message = message ;
672675 opts .flags = flags ;
676+
673677 return git_stash_save_with_opts (out , repo , & opts );
674678}
675679
676680int git_stash_save_with_opts (
677- git_oid * out , git_repository * repo , const git_stash_save_options * opts )
681+ git_oid * out ,
682+ git_repository * repo ,
683+ const git_stash_save_options * opts )
678684{
679685 git_index * index = NULL , * paths_index = NULL ;
680686 git_commit * b_commit = NULL , * i_commit = NULL , * u_commit = NULL ;
@@ -725,22 +731,12 @@ int git_stash_save_with_opts(
725731 i_commit , b_commit , u_commit )) < 0 )
726732 goto cleanup ;
727733 } else {
728- if ((error = git_index_new (& paths_index )) < 0 )
729- goto cleanup ;
730-
731- if ((error = retrieve_head (& head , repo )) < 0 )
732- goto cleanup ;
733-
734- if ((error = git_reference_peel ((git_object * * )& tree , head , GIT_OBJECT_TREE )) < 0 )
735- goto cleanup ;
736-
737- if ((error = git_index_read_tree (paths_index , tree )) < 0 )
738- goto cleanup ;
739-
740- if ((error = stash_update_index_from_paths (repo , paths_index , & opts -> paths )) < 0 )
741- goto cleanup ;
742-
743- if ((error = build_stash_commit_from_index (out , repo , opts -> stasher , git_str_cstr (& msg ),
734+ if ((error = git_index_new (& paths_index )) < 0 ||
735+ (error = retrieve_head (& head , repo )) < 0 ||
736+ (error = git_reference_peel ((git_object * * )& tree , head , GIT_OBJECT_TREE )) < 0 ||
737+ (error = git_index_read_tree (paths_index , tree )) < 0 ||
738+ (error = stash_update_index_from_paths (repo , paths_index , & opts -> paths )) < 0 ||
739+ (error = build_stash_commit_from_index (out , repo , opts -> stasher , git_str_cstr (& msg ),
744740 i_commit , b_commit , u_commit , paths_index )) < 0 )
745741 goto cleanup ;
746742 }
@@ -750,23 +746,20 @@ int git_stash_save_with_opts(
750746 if ((error = update_reflog (out , repo , git_str_cstr (& msg ))) < 0 )
751747 goto cleanup ;
752748
753- if (!(opts -> flags & GIT_STASH_KEEP_ALL ) && (error = reset_index_and_workdir (repo ,
754- (opts -> flags & GIT_STASH_KEEP_INDEX ) ? i_commit : b_commit , opts -> flags )) < 0 )
749+ if (!(opts -> flags & GIT_STASH_KEEP_ALL ) &&
750+ (error = reset_index_and_workdir (repo ,
751+ (opts -> flags & GIT_STASH_KEEP_INDEX ) ? i_commit : b_commit ,opts -> flags )) < 0 )
755752 goto cleanup ;
756753
757754cleanup :
758-
759755 git_str_dispose (& msg );
760756 git_commit_free (i_commit );
761757 git_commit_free (b_commit );
762758 git_commit_free (u_commit );
763759 git_tree_free (tree );
764-
765- if (has_paths ) {
766- git_reference_free (head );
767- git_index_free (index );
768- git_index_free (paths_index );
769- }
760+ git_reference_free (head );
761+ git_index_free (index );
762+ git_index_free (paths_index );
770763
771764 return error ;
772765}
0 commit comments