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