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