1
- #define USE_THE_REPOSITORY_VARIABLE
2
-
3
1
#include "git-compat-util.h"
4
2
#include "environment.h"
5
3
#include "gettext.h"
@@ -56,7 +54,7 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
56
54
* The *sha1 contains the pack content SHA1 hash.
57
55
* The objects array passed in will be sorted by SHA1 on exit.
58
56
*/
59
- const char * write_idx_file (const struct git_hash_algo * hash_algo ,
57
+ const char * write_idx_file (struct repository * repo ,
60
58
const char * index_name , struct pack_idx_entry * * objects ,
61
59
int nr_objects , const struct pack_idx_option * opts ,
62
60
const unsigned char * sha1 )
@@ -82,7 +80,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
82
80
83
81
if (opts -> flags & WRITE_IDX_VERIFY ) {
84
82
assert (index_name );
85
- f = hashfd_check (the_repository -> hash_algo , index_name );
83
+ f = hashfd_check (repo -> hash_algo , index_name );
86
84
} else {
87
85
if (!index_name ) {
88
86
struct strbuf tmp_file = STRBUF_INIT ;
@@ -92,7 +90,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
92
90
unlink (index_name );
93
91
fd = xopen (index_name , O_CREAT |O_EXCL |O_WRONLY , 0600 );
94
92
}
95
- f = hashfd (the_repository -> hash_algo , fd , index_name );
93
+ f = hashfd (repo -> hash_algo , fd , index_name );
96
94
}
97
95
98
96
/* if last object's offset is >= 2^31 we should use index V2 */
@@ -131,7 +129,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
131
129
struct pack_idx_entry * obj = * list ++ ;
132
130
if (index_version < 2 )
133
131
hashwrite_be32 (f , obj -> offset );
134
- hashwrite (f , obj -> oid .hash , hash_algo -> rawsz );
132
+ hashwrite (f , obj -> oid .hash , repo -> hash_algo -> rawsz );
135
133
if ((opts -> flags & WRITE_IDX_STRICT ) &&
136
134
(i && oideq (& list [-2 ]-> oid , & obj -> oid )))
137
135
die ("The same object %s appears twice in the pack" ,
@@ -173,7 +171,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
173
171
}
174
172
}
175
173
176
- hashwrite (f , sha1 , hash_algo -> rawsz );
174
+ hashwrite (f , sha1 , repo -> hash_algo -> rawsz );
177
175
finalize_hashfile (f , NULL , FSYNC_COMPONENT_PACK_METADATA ,
178
176
CSUM_HASH_IN_STREAM | CSUM_CLOSE |
179
177
((opts -> flags & WRITE_IDX_VERIFY ) ? 0 : CSUM_FSYNC ));
@@ -217,7 +215,7 @@ static void write_rev_trailer(const struct git_hash_algo *hash_algo,
217
215
hashwrite (f , hash , hash_algo -> rawsz );
218
216
}
219
217
220
- char * write_rev_file (const struct git_hash_algo * hash_algo ,
218
+ char * write_rev_file (struct repository * repo ,
221
219
const char * rev_name ,
222
220
struct pack_idx_entry * * objects ,
223
221
uint32_t nr_objects ,
@@ -236,15 +234,15 @@ char *write_rev_file(const struct git_hash_algo *hash_algo,
236
234
pack_order [i ] = i ;
237
235
QSORT_S (pack_order , nr_objects , pack_order_cmp , objects );
238
236
239
- ret = write_rev_file_order (hash_algo , rev_name , pack_order , nr_objects ,
237
+ ret = write_rev_file_order (repo , rev_name , pack_order , nr_objects ,
240
238
hash , flags );
241
239
242
240
free (pack_order );
243
241
244
242
return ret ;
245
243
}
246
244
247
- char * write_rev_file_order (const struct git_hash_algo * hash_algo ,
245
+ char * write_rev_file_order (struct repository * repo ,
248
246
const char * rev_name ,
249
247
uint32_t * pack_order ,
250
248
uint32_t nr_objects ,
@@ -268,7 +266,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
268
266
fd = xopen (rev_name , O_CREAT |O_EXCL |O_WRONLY , 0600 );
269
267
path = xstrdup (rev_name );
270
268
}
271
- f = hashfd (the_repository -> hash_algo , fd , path );
269
+ f = hashfd (repo -> hash_algo , fd , path );
272
270
} else if (flags & WRITE_REV_VERIFY ) {
273
271
struct stat statbuf ;
274
272
if (stat (rev_name , & statbuf )) {
@@ -278,18 +276,18 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
278
276
} else
279
277
die_errno (_ ("could not stat: %s" ), rev_name );
280
278
}
281
- f = hashfd_check (the_repository -> hash_algo , rev_name );
279
+ f = hashfd_check (repo -> hash_algo , rev_name );
282
280
path = xstrdup (rev_name );
283
281
} else {
284
282
return NULL ;
285
283
}
286
284
287
- write_rev_header (hash_algo , f );
285
+ write_rev_header (repo -> hash_algo , f );
288
286
289
287
write_rev_index_positions (f , pack_order , nr_objects );
290
- write_rev_trailer (hash_algo , f , hash );
288
+ write_rev_trailer (repo -> hash_algo , f , hash );
291
289
292
- if (adjust_shared_perm (the_repository , path ) < 0 )
290
+ if (adjust_shared_perm (repo , path ) < 0 )
293
291
die (_ ("failed to make %s readable" ), path );
294
292
295
293
finalize_hashfile (f , NULL , FSYNC_COMPONENT_PACK_METADATA ,
@@ -330,7 +328,7 @@ static void write_mtimes_trailer(const struct git_hash_algo *hash_algo,
330
328
hashwrite (f , hash , hash_algo -> rawsz );
331
329
}
332
330
333
- static char * write_mtimes_file (const struct git_hash_algo * hash_algo ,
331
+ static char * write_mtimes_file (struct repository * repo ,
334
332
struct packing_data * to_pack ,
335
333
struct pack_idx_entry * * objects ,
336
334
uint32_t nr_objects ,
@@ -346,13 +344,13 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
346
344
347
345
fd = odb_mkstemp (& tmp_file , "pack/tmp_mtimes_XXXXXX" );
348
346
mtimes_name = strbuf_detach (& tmp_file , NULL );
349
- f = hashfd (the_repository -> hash_algo , fd , mtimes_name );
347
+ f = hashfd (repo -> hash_algo , fd , mtimes_name );
350
348
351
- write_mtimes_header (hash_algo , f );
349
+ write_mtimes_header (repo -> hash_algo , f );
352
350
write_mtimes_objects (f , to_pack , objects , nr_objects );
353
- write_mtimes_trailer (hash_algo , f , hash );
351
+ write_mtimes_trailer (repo -> hash_algo , f , hash );
354
352
355
- if (adjust_shared_perm (the_repository , mtimes_name ) < 0 )
353
+ if (adjust_shared_perm (repo , mtimes_name ) < 0 )
356
354
die (_ ("failed to make %s readable" ), mtimes_name );
357
355
358
356
finalize_hashfile (f , NULL , FSYNC_COMPONENT_PACK_METADATA ,
@@ -527,14 +525,15 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
527
525
return n ;
528
526
}
529
527
530
- struct hashfile * create_tmp_packfile (char * * pack_tmp_name )
528
+ struct hashfile * create_tmp_packfile (struct repository * repo ,
529
+ char * * pack_tmp_name )
531
530
{
532
531
struct strbuf tmpname = STRBUF_INIT ;
533
532
int fd ;
534
533
535
534
fd = odb_mkstemp (& tmpname , "pack/tmp_pack_XXXXXX" );
536
535
* pack_tmp_name = strbuf_detach (& tmpname , NULL );
537
- return hashfd (the_repository -> hash_algo , fd , * pack_tmp_name );
536
+ return hashfd (repo -> hash_algo , fd , * pack_tmp_name );
538
537
}
539
538
540
539
static void rename_tmp_packfile (struct strbuf * name_prefix , const char * source ,
@@ -555,7 +554,7 @@ void rename_tmp_packfile_idx(struct strbuf *name_buffer,
555
554
rename_tmp_packfile (name_buffer , * idx_tmp_name , "idx" );
556
555
}
557
556
558
- void stage_tmp_packfiles (const struct git_hash_algo * hash_algo ,
557
+ void stage_tmp_packfiles (struct repository * repo ,
559
558
struct strbuf * name_buffer ,
560
559
const char * pack_tmp_name ,
561
560
struct pack_idx_entry * * written_list ,
@@ -568,19 +567,19 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
568
567
char * rev_tmp_name = NULL ;
569
568
char * mtimes_tmp_name = NULL ;
570
569
571
- if (adjust_shared_perm (the_repository , pack_tmp_name ))
570
+ if (adjust_shared_perm (repo , pack_tmp_name ))
572
571
die_errno ("unable to make temporary pack file readable" );
573
572
574
- * idx_tmp_name = (char * )write_idx_file (hash_algo , NULL , written_list ,
573
+ * idx_tmp_name = (char * )write_idx_file (repo , NULL , written_list ,
575
574
nr_written , pack_idx_opts , hash );
576
- if (adjust_shared_perm (the_repository , * idx_tmp_name ))
575
+ if (adjust_shared_perm (repo , * idx_tmp_name ))
577
576
die_errno ("unable to make temporary index file readable" );
578
577
579
- rev_tmp_name = write_rev_file (hash_algo , NULL , written_list , nr_written ,
578
+ rev_tmp_name = write_rev_file (repo , NULL , written_list , nr_written ,
580
579
hash , pack_idx_opts -> flags );
581
580
582
581
if (pack_idx_opts -> flags & WRITE_MTIMES ) {
583
- mtimes_tmp_name = write_mtimes_file (hash_algo , to_pack ,
582
+ mtimes_tmp_name = write_mtimes_file (repo , to_pack ,
584
583
written_list , nr_written ,
585
584
hash );
586
585
}
0 commit comments