@@ -950,9 +950,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
950
950
{
951
951
int ret = 0 ;
952
952
struct strbuf untracked_msg = STRBUF_INIT ;
953
- struct strbuf out = STRBUF_INIT ;
954
953
struct child_process cp_upd_index = CHILD_PROCESS_INIT ;
955
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
954
+ struct index_state istate = { NULL } ;
956
955
957
956
cp_upd_index .git_cmd = 1 ;
958
957
argv_array_pushl (& cp_upd_index .args , "update-index" , "-z" , "--add" ,
@@ -967,15 +966,11 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
967
966
goto done ;
968
967
}
969
968
970
- cp_write_tree .git_cmd = 1 ;
971
- argv_array_push (& cp_write_tree .args , "write-tree" );
972
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
973
- stash_index_path .buf );
974
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
969
+ if (write_index_as_tree (& info -> u_tree , & istate , stash_index_path .buf , 0 ,
970
+ NULL )) {
975
971
ret = -1 ;
976
972
goto done ;
977
973
}
978
- get_oid_hex (out .buf , & info -> u_tree );
979
974
980
975
if (commit_tree (untracked_msg .buf , untracked_msg .len ,
981
976
& info -> u_tree , NULL , & info -> u_commit , NULL , NULL )) {
@@ -984,8 +979,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
984
979
}
985
980
986
981
done :
982
+ discard_index (& istate );
987
983
strbuf_release (& untracked_msg );
988
- strbuf_release (& out );
989
984
remove_path (stash_index_path .buf );
990
985
return ret ;
991
986
}
@@ -994,11 +989,10 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
994
989
struct strbuf * out_patch , int quiet )
995
990
{
996
991
int ret = 0 ;
997
- struct strbuf out = STRBUF_INIT ;
998
992
struct child_process cp_read_tree = CHILD_PROCESS_INIT ;
999
993
struct child_process cp_add_i = CHILD_PROCESS_INIT ;
1000
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
1001
994
struct child_process cp_diff_tree = CHILD_PROCESS_INIT ;
995
+ struct index_state istate = { NULL };
1002
996
1003
997
remove_path (stash_index_path .buf );
1004
998
@@ -1024,17 +1018,12 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1024
1018
}
1025
1019
1026
1020
/* State of the working tree. */
1027
- cp_write_tree .git_cmd = 1 ;
1028
- argv_array_push (& cp_write_tree .args , "write-tree" );
1029
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
1030
- stash_index_path .buf );
1031
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
1021
+ if (write_index_as_tree (& info -> w_tree , & istate , stash_index_path .buf , 0 ,
1022
+ NULL )) {
1032
1023
ret = -1 ;
1033
1024
goto done ;
1034
1025
}
1035
1026
1036
- get_oid_hex (out .buf , & info -> w_tree );
1037
-
1038
1027
cp_diff_tree .git_cmd = 1 ;
1039
1028
argv_array_pushl (& cp_diff_tree .args , "diff-tree" , "-p" , "HEAD" ,
1040
1029
oid_to_hex (& info -> w_tree ), "--" , NULL );
@@ -1050,7 +1039,7 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1050
1039
}
1051
1040
1052
1041
done :
1053
- strbuf_release ( & out );
1042
+ discard_index ( & istate );
1054
1043
remove_path (stash_index_path .buf );
1055
1044
return ret ;
1056
1045
}
@@ -1060,9 +1049,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1060
1049
int ret = 0 ;
1061
1050
struct rev_info rev ;
1062
1051
struct child_process cp_upd_index = CHILD_PROCESS_INIT ;
1063
- struct child_process cp_write_tree = CHILD_PROCESS_INIT ;
1064
- struct strbuf out = STRBUF_INIT ;
1065
1052
struct strbuf diff_output = STRBUF_INIT ;
1053
+ struct index_state istate = { NULL };
1066
1054
1067
1055
set_alternate_index_output (stash_index_path .buf );
1068
1056
if (reset_tree (& info -> i_tree , 0 , 0 )) {
@@ -1101,20 +1089,15 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1101
1089
goto done ;
1102
1090
}
1103
1091
1104
- cp_write_tree .git_cmd = 1 ;
1105
- argv_array_push (& cp_write_tree .args , "write-tree" );
1106
- argv_array_pushf (& cp_write_tree .env_array , "GIT_INDEX_FILE=%s" ,
1107
- stash_index_path .buf );
1108
- if (pipe_command (& cp_write_tree , NULL , 0 , & out , 0 ,NULL , 0 )) {
1092
+ if (write_index_as_tree (& info -> w_tree , & istate , stash_index_path .buf , 0 ,
1093
+ NULL )) {
1109
1094
ret = -1 ;
1110
1095
goto done ;
1111
1096
}
1112
1097
1113
- get_oid_hex (out .buf , & info -> w_tree );
1114
-
1115
1098
done :
1099
+ discard_index (& istate );
1116
1100
UNLEAK (rev );
1117
- strbuf_release (& out );
1118
1101
object_array_clear (& rev .pending );
1119
1102
strbuf_release (& diff_output );
1120
1103
remove_path (stash_index_path .buf );
0 commit comments