@@ -91,44 +91,6 @@ static int repack_config(const char *var, const char *value, void *cb)
91
91
return git_default_config (var , value , cb );
92
92
}
93
93
94
- /*
95
- * Remove temporary $GIT_OBJECT_DIRECTORY/pack/.tmp-$$-pack-* files.
96
- */
97
- static void remove_temporary_files (void )
98
- {
99
- struct strbuf buf = STRBUF_INIT ;
100
- size_t dirlen , prefixlen ;
101
- DIR * dir ;
102
- struct dirent * e ;
103
-
104
- dir = opendir (packdir );
105
- if (!dir )
106
- return ;
107
-
108
- /* Point at the slash at the end of ".../objects/pack/" */
109
- dirlen = strlen (packdir ) + 1 ;
110
- strbuf_addstr (& buf , packtmp );
111
- /* Hold the length of ".tmp-%d-pack-" */
112
- prefixlen = buf .len - dirlen ;
113
-
114
- while ((e = readdir (dir ))) {
115
- if (strncmp (e -> d_name , buf .buf + dirlen , prefixlen ))
116
- continue ;
117
- strbuf_setlen (& buf , dirlen );
118
- strbuf_addstr (& buf , e -> d_name );
119
- unlink (buf .buf );
120
- }
121
- closedir (dir );
122
- strbuf_release (& buf );
123
- }
124
-
125
- static void remove_pack_on_signal (int signo )
126
- {
127
- remove_temporary_files ();
128
- sigchain_pop (signo );
129
- raise (signo );
130
- }
131
-
132
94
/*
133
95
* Adds all packs hex strings to either fname_nonkept_list or
134
96
* fname_kept_list based on whether each pack has a corresponding
@@ -247,11 +209,15 @@ static struct {
247
209
{".idx" },
248
210
};
249
211
250
- static unsigned populate_pack_exts (char * name )
212
+ struct generated_pack_data {
213
+ struct tempfile * tempfiles [ARRAY_SIZE (exts )];
214
+ };
215
+
216
+ static struct generated_pack_data * populate_pack_exts (const char * name )
251
217
{
252
218
struct stat statbuf ;
253
219
struct strbuf path = STRBUF_INIT ;
254
- unsigned ret = 0 ;
220
+ struct generated_pack_data * data = xcalloc ( 1 , sizeof ( * data )) ;
255
221
int i ;
256
222
257
223
for (i = 0 ; i < ARRAY_SIZE (exts ); i ++ ) {
@@ -261,11 +227,11 @@ static unsigned populate_pack_exts(char *name)
261
227
if (stat (path .buf , & statbuf ))
262
228
continue ;
263
229
264
- ret |= ( 1 << i );
230
+ data -> tempfiles [ i ] = register_tempfile ( path . buf );
265
231
}
266
232
267
233
strbuf_release (& path );
268
- return ret ;
234
+ return data ;
269
235
}
270
236
271
237
static void repack_promisor_objects (const struct pack_objects_args * args ,
@@ -320,7 +286,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
320
286
line .buf );
321
287
write_promisor_file (promisor_name , NULL , 0 );
322
288
323
- item -> util = ( void * )( uintptr_t ) populate_pack_exts (item -> string );
289
+ item -> util = populate_pack_exts (item -> string );
324
290
325
291
free (promisor_name );
326
292
}
@@ -739,10 +705,14 @@ static int write_cruft_pack(const struct pack_objects_args *args,
739
705
740
706
out = xfdopen (cmd .out , "r" );
741
707
while (strbuf_getline_lf (& line , out ) != EOF ) {
708
+ struct string_list_item * item ;
709
+
742
710
if (line .len != the_hash_algo -> hexsz )
743
711
die (_ ("repack: Expecting full hex object ID lines only "
744
712
"from pack-objects." ));
745
- string_list_append (names , line .buf );
713
+
714
+ item = string_list_append (names , line .buf );
715
+ item -> util = populate_pack_exts (line .buf );
746
716
}
747
717
fclose (out );
748
718
@@ -888,8 +858,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
888
858
split_pack_geometry (geometry , geometric_factor );
889
859
}
890
860
891
- sigchain_push_common (remove_pack_on_signal );
892
-
893
861
prepare_pack_objects (& cmd , & po_args );
894
862
895
863
show_progress = !po_args .quiet && isatty (2 );
@@ -981,9 +949,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
981
949
982
950
out = xfdopen (cmd .out , "r" );
983
951
while (strbuf_getline_lf (& line , out ) != EOF ) {
952
+ struct string_list_item * item ;
953
+
984
954
if (line .len != the_hash_algo -> hexsz )
985
955
die (_ ("repack: Expecting full hex object ID lines only from pack-objects." ));
986
- string_list_append (& names , line .buf );
956
+ item = string_list_append (& names , line .buf );
957
+ item -> util = populate_pack_exts (item -> string );
987
958
}
988
959
fclose (out );
989
960
ret = finish_command (& cmd );
@@ -1022,40 +993,38 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1022
993
1023
994
string_list_sort (& names );
1024
995
1025
- for_each_string_list_item (item , & names ) {
1026
- item -> util = (void * )(uintptr_t )populate_pack_exts (item -> string );
1027
- }
1028
-
1029
996
close_object_store (the_repository -> objects );
1030
997
1031
998
/*
1032
999
* Ok we have prepared all new packfiles.
1033
1000
*/
1034
1001
for_each_string_list_item (item , & names ) {
1002
+ struct generated_pack_data * data = item -> util ;
1003
+
1035
1004
for (ext = 0 ; ext < ARRAY_SIZE (exts ); ext ++ ) {
1036
- char * fname , * fname_old ;
1005
+ char * fname ;
1037
1006
1038
1007
fname = mkpathdup ("%s/pack-%s%s" ,
1039
1008
packdir , item -> string , exts [ext ].name );
1040
- fname_old = mkpathdup ("%s-%s%s" ,
1041
- packtmp , item -> string , exts [ext ].name );
1042
1009
1043
- if (((uintptr_t )item -> util ) & ((uintptr_t )1 << ext )) {
1010
+ if (data -> tempfiles [ext ]) {
1011
+ const char * fname_old = get_tempfile_path (data -> tempfiles [ext ]);
1044
1012
struct stat statbuffer ;
1013
+
1045
1014
if (!stat (fname_old , & statbuffer )) {
1046
1015
statbuffer .st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH );
1047
1016
chmod (fname_old , statbuffer .st_mode );
1048
1017
}
1049
1018
1050
- if (rename ( fname_old , fname ))
1051
- die_errno (_ ("renaming '%s' failed" ), fname_old );
1019
+ if (rename_tempfile ( & data -> tempfiles [ ext ] , fname ))
1020
+ die_errno (_ ("renaming pack to '%s' failed" ), fname );
1052
1021
} else if (!exts [ext ].optional )
1053
- die (_ ("missing required file: %s" ), fname_old );
1022
+ die (_ ("pack-objects did not write a '%s' file for pack %s-%s" ),
1023
+ exts [ext ].name , packtmp , item -> string );
1054
1024
else if (unlink (fname ) < 0 && errno != ENOENT )
1055
1025
die_errno (_ ("could not unlink: %s" ), fname );
1056
1026
1057
1027
free (fname );
1058
- free (fname_old );
1059
1028
}
1060
1029
}
1061
1030
/* End of pack replacement. */
@@ -1143,7 +1112,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1143
1112
1144
1113
if (run_update_server_info )
1145
1114
update_server_info (0 );
1146
- remove_temporary_files ();
1147
1115
1148
1116
if (git_env_bool (GIT_TEST_MULTI_PACK_INDEX , 0 )) {
1149
1117
unsigned flags = 0 ;
@@ -1152,7 +1120,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1152
1120
write_midx_file (get_object_directory (), NULL , NULL , flags );
1153
1121
}
1154
1122
1155
- string_list_clear (& names , 0 );
1123
+ string_list_clear (& names , 1 );
1156
1124
string_list_clear (& existing_nonkept_packs , 0 );
1157
1125
string_list_clear (& existing_kept_packs , 0 );
1158
1126
clear_pack_geometry (geometry );
0 commit comments