@@ -943,9 +943,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
943
943
{
944
944
int ret = 0 ;
945
945
struct strbuf untracked_msg = STRBUF_INIT ;
946
- struct strbuf out = STRBUF_INIT ;
947
946
struct child_process cp_upd_index = CHILD_PROCESS_INIT ;
948
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
947
+ struct index_state istate = { NULL } ;
949
948
950
949
cp_upd_index .git_cmd = 1 ;
951
950
argv_array_pushl (& cp_upd_index .args , "update-index" , "-z" , "--add" ,
@@ -960,15 +959,11 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
960
959
goto done ;
961
960
}
962
961
963
- cp_write_tree .git_cmd = 1 ;
964
- argv_array_push (& cp_write_tree .args , "write-tree" );
965
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
966
- stash_index_path .buf );
967
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
962
+ if (write_index_as_tree (& info -> u_tree , & istate , stash_index_path .buf , 0 ,
963
+ NULL )) {
968
964
ret = -1 ;
969
965
goto done ;
970
966
}
971
- get_oid_hex (out .buf , & info -> u_tree );
972
967
973
968
if (commit_tree (untracked_msg .buf , untracked_msg .len ,
974
969
& info -> u_tree , NULL , & info -> u_commit , NULL , NULL )) {
@@ -977,8 +972,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
977
972
}
978
973
979
974
done :
975
+ discard_index (& istate );
980
976
strbuf_release (& untracked_msg );
981
- strbuf_release (& out );
982
977
remove_path (stash_index_path .buf );
983
978
return ret ;
984
979
}
@@ -987,11 +982,10 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
987
982
struct strbuf * out_patch , int quiet )
988
983
{
989
984
int ret = 0 ;
990
- struct strbuf out = STRBUF_INIT ;
991
985
struct child_process cp_read_tree = CHILD_PROCESS_INIT ;
992
986
struct child_process cp_add_i = CHILD_PROCESS_INIT ;
993
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
994
987
struct child_process cp_diff_tree = CHILD_PROCESS_INIT ;
988
+ struct index_state istate = { NULL };
995
989
996
990
remove_path (stash_index_path .buf );
997
991
@@ -1017,17 +1011,12 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1017
1011
}
1018
1012
1019
1013
/* State of the working tree. */
1020
- cp_write_tree .git_cmd = 1 ;
1021
- argv_array_push (& cp_write_tree .args , "write-tree" );
1022
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
1023
- stash_index_path .buf );
1024
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
1014
+ if (write_index_as_tree (& info -> w_tree , & istate , stash_index_path .buf , 0 ,
1015
+ NULL )) {
1025
1016
ret = -1 ;
1026
1017
goto done ;
1027
1018
}
1028
1019
1029
- get_oid_hex (out .buf , & info -> w_tree );
1030
-
1031
1020
cp_diff_tree .git_cmd = 1 ;
1032
1021
argv_array_pushl (& cp_diff_tree .args , "diff-tree" , "-p" , "HEAD" ,
1033
1022
oid_to_hex (& info -> w_tree ), "--" , NULL );
@@ -1043,7 +1032,7 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1043
1032
}
1044
1033
1045
1034
done :
1046
- strbuf_release ( & out );
1035
+ discard_index ( & istate );
1047
1036
remove_path (stash_index_path .buf );
1048
1037
return ret ;
1049
1038
}
@@ -1053,9 +1042,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1053
1042
int ret = 0 ;
1054
1043
struct rev_info rev ;
1055
1044
struct child_process cp_upd_index = CHILD_PROCESS_INIT ;
1056
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
1057
- struct strbuf out = STRBUF_INIT ;
1058
1045
struct strbuf diff_output = STRBUF_INIT ;
1046
+ struct index_state istate = { NULL };
1059
1047
1060
1048
init_revisions (& rev , NULL );
1061
1049
@@ -1095,20 +1083,15 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1095
1083
goto done ;
1096
1084
}
1097
1085
1098
- cp_write_tree .git_cmd = 1 ;
1099
- argv_array_push (& cp_write_tree .args , "write-tree" );
1100
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
1101
- stash_index_path .buf );
1102
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
1086
+ if (write_index_as_tree (& info -> w_tree , & istate , stash_index_path .buf , 0 ,
1087
+ NULL )) {
1103
1088
ret = -1 ;
1104
1089
goto done ;
1105
1090
}
1106
1091
1107
- get_oid_hex (out .buf , & info -> w_tree );
1108
-
1109
1092
done :
1093
+ discard_index (& istate );
1110
1094
UNLEAK (rev );
1111
- strbuf_release (& out );
1112
1095
object_array_clear (& rev .pending );
1113
1096
strbuf_release (& diff_output );
1114
1097
remove_path (stash_index_path .buf );
0 commit comments