@@ -828,11 +828,11 @@ static int store_stash(int argc, const char **argv, const char *prefix)
828
828
}
829
829
830
830
static void add_pathspecs (struct argv_array * args ,
831
- struct pathspec ps ) {
831
+ const struct pathspec * ps ) {
832
832
int i ;
833
833
834
- for (i = 0 ; i < ps . nr ; i ++ )
835
- argv_array_push (args , ps . items [i ].match );
834
+ for (i = 0 ; i < ps -> nr ; i ++ )
835
+ argv_array_push (args , ps -> items [i ].original );
836
836
}
837
837
838
838
/*
@@ -842,7 +842,7 @@ static void add_pathspecs(struct argv_array *args,
842
842
* = 0 if there are not any untracked files
843
843
* > 0 if there are untracked files
844
844
*/
845
- static int get_untracked_files (struct pathspec ps , int include_untracked ,
845
+ static int get_untracked_files (const struct pathspec * ps , int include_untracked ,
846
846
struct strbuf * untracked_files )
847
847
{
848
848
int i ;
@@ -855,12 +855,12 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
855
855
if (include_untracked != INCLUDE_ALL_FILES )
856
856
setup_standard_excludes (& dir );
857
857
858
- seen = xcalloc (ps . nr , 1 );
858
+ seen = xcalloc (ps -> nr , 1 );
859
859
860
- max_len = fill_directory (& dir , the_repository -> index , & ps );
860
+ max_len = fill_directory (& dir , the_repository -> index , ps );
861
861
for (i = 0 ; i < dir .nr ; i ++ ) {
862
862
struct dir_entry * ent = dir .entries [i ];
863
- if (dir_path_match (& the_index , ent , & ps , max_len , seen )) {
863
+ if (dir_path_match (& the_index , ent , ps , max_len , seen )) {
864
864
found ++ ;
865
865
strbuf_addstr (untracked_files , ent -> name );
866
866
/* NUL-terminate: will be fed to update-index -z */
@@ -883,11 +883,12 @@ static int get_untracked_files(struct pathspec ps, int include_untracked,
883
883
* = 0 if there are no changes.
884
884
* > 0 if there are changes.
885
885
*/
886
- static int check_changes_tracked_files (struct pathspec ps )
886
+ static int check_changes_tracked_files (const struct pathspec * ps )
887
887
{
888
888
int result ;
889
889
struct rev_info rev ;
890
890
struct object_id dummy ;
891
+ int ret = 0 ;
891
892
892
893
/* No initial commit. */
893
894
if (get_oid ("HEAD" , & dummy ))
@@ -897,7 +898,7 @@ static int check_changes_tracked_files(struct pathspec ps)
897
898
return -1 ;
898
899
899
900
init_revisions (& rev , NULL );
900
- rev .prune_data = ps ;
901
+ copy_pathspec ( & rev .prune_data , ps ) ;
901
902
902
903
rev .diffopt .flags .quick = 1 ;
903
904
rev .diffopt .flags .ignore_submodules = 1 ;
@@ -907,22 +908,28 @@ static int check_changes_tracked_files(struct pathspec ps)
907
908
diff_setup_done (& rev .diffopt );
908
909
909
910
result = run_diff_index (& rev , 1 );
910
- if (diff_result_code (& rev .diffopt , result ))
911
- return 1 ;
911
+ if (diff_result_code (& rev .diffopt , result )) {
912
+ ret = 1 ;
913
+ goto done ;
914
+ }
912
915
913
916
object_array_clear (& rev .pending );
914
917
result = run_diff_files (& rev , 0 );
915
- if (diff_result_code (& rev .diffopt , result ))
916
- return 1 ;
918
+ if (diff_result_code (& rev .diffopt , result )) {
919
+ ret = 1 ;
920
+ goto done ;
921
+ }
917
922
918
- return 0 ;
923
+ done :
924
+ clear_pathspec (& rev .prune_data );
925
+ return ret ;
919
926
}
920
927
921
928
/*
922
929
* The function will fill `untracked_files` with the names of untracked files
923
930
* It will return 1 if there were any changes and 0 if there were not.
924
931
*/
925
- static int check_changes (struct pathspec ps , int include_untracked ,
932
+ static int check_changes (const struct pathspec * ps , int include_untracked ,
926
933
struct strbuf * untracked_files )
927
934
{
928
935
int ret = 0 ;
@@ -976,7 +983,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
976
983
return ret ;
977
984
}
978
985
979
- static int stash_patch (struct stash_info * info , struct pathspec ps ,
986
+ static int stash_patch (struct stash_info * info , const struct pathspec * ps ,
980
987
struct strbuf * out_patch , int quiet )
981
988
{
982
989
int ret = 0 ;
@@ -1035,7 +1042,7 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
1035
1042
return ret ;
1036
1043
}
1037
1044
1038
- static int stash_working_tree (struct stash_info * info , struct pathspec ps )
1045
+ static int stash_working_tree (struct stash_info * info , const struct pathspec * ps )
1039
1046
{
1040
1047
int ret = 0 ;
1041
1048
struct rev_info rev ;
@@ -1044,6 +1051,7 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1044
1051
struct index_state istate = { NULL };
1045
1052
1046
1053
init_revisions (& rev , NULL );
1054
+ copy_pathspec (& rev .prune_data , ps );
1047
1055
1048
1056
set_alternate_index_output (stash_index_path .buf );
1049
1057
if (reset_tree (& info -> i_tree , 0 , 0 )) {
@@ -1052,7 +1060,6 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1052
1060
}
1053
1061
set_alternate_index_output (NULL );
1054
1062
1055
- rev .prune_data = ps ;
1056
1063
rev .diffopt .output_format = DIFF_FORMAT_CALLBACK ;
1057
1064
rev .diffopt .format_callback = add_diff_to_buf ;
1058
1065
rev .diffopt .format_callback_data = & diff_output ;
@@ -1091,12 +1098,13 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
1091
1098
discard_index (& istate );
1092
1099
UNLEAK (rev );
1093
1100
object_array_clear (& rev .pending );
1101
+ clear_pathspec (& rev .prune_data );
1094
1102
strbuf_release (& diff_output );
1095
1103
remove_path (stash_index_path .buf );
1096
1104
return ret ;
1097
1105
}
1098
1106
1099
- static int do_create_stash (struct pathspec ps , struct strbuf * stash_msg_buf ,
1107
+ static int do_create_stash (const struct pathspec * ps , struct strbuf * stash_msg_buf ,
1100
1108
int include_untracked , int patch_mode ,
1101
1109
struct stash_info * info , struct strbuf * patch ,
1102
1110
int quiet )
@@ -1228,10 +1236,10 @@ static int create_stash(int argc, const char **argv, const char *prefix)
1228
1236
strbuf_join_argv (& stash_msg_buf , argc - 1 , ++ argv , ' ' );
1229
1237
1230
1238
memset (& ps , 0 , sizeof (ps ));
1231
- if (!check_changes_tracked_files (ps ))
1239
+ if (!check_changes_tracked_files (& ps ))
1232
1240
return 0 ;
1233
1241
1234
- ret = do_create_stash (ps , & stash_msg_buf , 0 , 0 , & info ,
1242
+ ret = do_create_stash (& ps , & stash_msg_buf , 0 , 0 , & info ,
1235
1243
NULL , 0 );
1236
1244
if (!ret )
1237
1245
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
@@ -1240,7 +1248,7 @@ static int create_stash(int argc, const char **argv, const char *prefix)
1240
1248
return ret ;
1241
1249
}
1242
1250
1243
- static int do_push_stash (struct pathspec ps , const char * stash_msg , int quiet ,
1251
+ static int do_push_stash (const struct pathspec * ps , const char * stash_msg , int quiet ,
1244
1252
int keep_index , int patch_mode , int include_untracked )
1245
1253
{
1246
1254
int ret = 0 ;
@@ -1260,15 +1268,15 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1260
1268
}
1261
1269
1262
1270
read_cache_preload (NULL );
1263
- if (!include_untracked && ps . nr ) {
1271
+ if (!include_untracked && ps -> nr ) {
1264
1272
int i ;
1265
- char * ps_matched = xcalloc (ps . nr , 1 );
1273
+ char * ps_matched = xcalloc (ps -> nr , 1 );
1266
1274
1267
1275
for (i = 0 ; i < active_nr ; i ++ )
1268
- ce_path_match (& the_index , active_cache [i ], & ps ,
1276
+ ce_path_match (& the_index , active_cache [i ], ps ,
1269
1277
ps_matched );
1270
1278
1271
- if (report_path_error (ps_matched , & ps , NULL )) {
1279
+ if (report_path_error (ps_matched , ps , NULL )) {
1272
1280
fprintf_ln (stderr , _ ("Did you forget to 'git add'?" ));
1273
1281
ret = -1 ;
1274
1282
free (ps_matched );
@@ -1315,7 +1323,7 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1315
1323
stash_msg_buf .buf );
1316
1324
1317
1325
if (!patch_mode ) {
1318
- if (include_untracked && !ps . nr ) {
1326
+ if (include_untracked && !ps -> nr ) {
1319
1327
struct child_process cp = CHILD_PROCESS_INIT ;
1320
1328
1321
1329
cp .git_cmd = 1 ;
@@ -1329,7 +1337,7 @@ static int do_push_stash(struct pathspec ps, const char *stash_msg, int quiet,
1329
1337
}
1330
1338
}
1331
1339
discard_cache ();
1332
- if (ps . nr ) {
1340
+ if (ps -> nr ) {
1333
1341
struct child_process cp_add = CHILD_PROCESS_INIT ;
1334
1342
struct child_process cp_diff = CHILD_PROCESS_INIT ;
1335
1343
struct child_process cp_apply = CHILD_PROCESS_INIT ;
@@ -1468,8 +1476,9 @@ static int push_stash(int argc, const char **argv, const char *prefix)
1468
1476
git_stash_push_usage ,
1469
1477
0 );
1470
1478
1471
- parse_pathspec (& ps , 0 , PATHSPEC_PREFER_FULL , prefix , argv );
1472
- return do_push_stash (ps , stash_msg , quiet , keep_index , patch_mode ,
1479
+ parse_pathspec (& ps , 0 , PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN ,
1480
+ prefix , argv );
1481
+ return do_push_stash (& ps , stash_msg , quiet , keep_index , patch_mode ,
1473
1482
include_untracked );
1474
1483
}
1475
1484
@@ -1506,7 +1515,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1506
1515
stash_msg = strbuf_join_argv (& stash_msg_buf , argc , argv , ' ' );
1507
1516
1508
1517
memset (& ps , 0 , sizeof (ps ));
1509
- ret = do_push_stash (ps , stash_msg , quiet , keep_index ,
1518
+ ret = do_push_stash (& ps , stash_msg , quiet , keep_index ,
1510
1519
patch_mode , include_untracked );
1511
1520
1512
1521
strbuf_release (& stash_msg_buf );
0 commit comments