Skip to content

Commit 2582846

Browse files
pks-tgitster
authored andcommitted
pack-write: stop depending on the_repository and the_hash_algo
There are a couple of functions in "pack-write.c" that implicitly depend on `the_repository` or `the_hash_algo`. Remove this dependency by injecting the repository via a parameter and adapt callers accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74d414c commit 2582846

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

builtin/fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static const char *create_index(void)
798798
if (c != last)
799799
die("internal consistency error creating the index");
800800

801-
tmpfile = write_idx_file(the_hash_algo, NULL, idx, object_count,
801+
tmpfile = write_idx_file(the_repository, NULL, idx, object_count,
802802
&pack_idx_opts, pack_data->hash);
803803
free(idx);
804804
return tmpfile;

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,10 +2088,10 @@ int cmd_index_pack(int argc,
20882088
ALLOC_ARRAY(idx_objects, nr_objects);
20892089
for (i = 0; i < nr_objects; i++)
20902090
idx_objects[i] = &objects[i].idx;
2091-
curr_index = write_idx_file(the_hash_algo, index_name, idx_objects,
2091+
curr_index = write_idx_file(the_repository, index_name, idx_objects,
20922092
nr_objects, &opts, pack_hash);
20932093
if (rev_index)
2094-
curr_rev_index = write_rev_file(the_hash_algo, rev_index_name,
2094+
curr_rev_index = write_rev_file(the_repository, rev_index_name,
20952095
idx_objects, nr_objects,
20962096
pack_hash, opts.flags);
20972097
free(idx_objects);

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ static void write_pack_file(void)
13141314
f = hashfd_throughput(the_repository->hash_algo, 1,
13151315
"<stdout>", progress_state);
13161316
else
1317-
f = create_tmp_packfile(&pack_tmp_name);
1317+
f = create_tmp_packfile(the_repository, &pack_tmp_name);
13181318

13191319
offset = write_pack_header(f, nr_remaining);
13201320

@@ -1407,7 +1407,7 @@ static void write_pack_file(void)
14071407
if (cruft)
14081408
pack_idx_opts.flags |= WRITE_MTIMES;
14091409

1410-
stage_tmp_packfiles(the_hash_algo, &tmpname,
1410+
stage_tmp_packfiles(the_repository, &tmpname,
14111411
pack_tmp_name, written_list,
14121412
nr_written, &to_pack,
14131413
&pack_idx_opts, hash,

bulk-checkin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void finish_tmp_packfile(struct strbuf *basename,
4444
{
4545
char *idx_tmp_name = NULL;
4646

47-
stage_tmp_packfiles(the_hash_algo, basename, pack_tmp_name,
47+
stage_tmp_packfiles(the_repository, basename, pack_tmp_name,
4848
written_list, nr_written, NULL, pack_idx_opts, hash,
4949
&idx_tmp_name);
5050
rename_tmp_packfile_idx(basename, &idx_tmp_name);
@@ -244,7 +244,7 @@ static void prepare_to_stream(struct bulk_checkin_packfile *state,
244244
if (!(flags & HASH_WRITE_OBJECT) || state->f)
245245
return;
246246

247-
state->f = create_tmp_packfile(&state->pack_tmp_name);
247+
state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name);
248248
reset_pack_idx_option(&state->pack_idx_opts);
249249

250250
/* Pretend we are going to write only one object */

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
658658
strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash,
659659
ctx->repo->hash_algo));
660660

661-
tmp_file = write_rev_file_order(ctx->repo->hash_algo, NULL, ctx->pack_order,
661+
tmp_file = write_rev_file_order(ctx->repo, NULL, ctx->pack_order,
662662
ctx->entries_nr, midx_hash, WRITE_REV);
663663

664664
if (finalize_object_file(tmp_file, buf.buf))

pack-write.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "environment.h"
53
#include "gettext.h"
@@ -56,7 +54,7 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
5654
* The *sha1 contains the pack content SHA1 hash.
5755
* The objects array passed in will be sorted by SHA1 on exit.
5856
*/
59-
const char *write_idx_file(const struct git_hash_algo *hash_algo,
57+
const char *write_idx_file(struct repository *repo,
6058
const char *index_name, struct pack_idx_entry **objects,
6159
int nr_objects, const struct pack_idx_option *opts,
6260
const unsigned char *sha1)
@@ -82,7 +80,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
8280

8381
if (opts->flags & WRITE_IDX_VERIFY) {
8482
assert(index_name);
85-
f = hashfd_check(the_repository->hash_algo, index_name);
83+
f = hashfd_check(repo->hash_algo, index_name);
8684
} else {
8785
if (!index_name) {
8886
struct strbuf tmp_file = STRBUF_INIT;
@@ -92,7 +90,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
9290
unlink(index_name);
9391
fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
9492
}
95-
f = hashfd(the_repository->hash_algo, fd, index_name);
93+
f = hashfd(repo->hash_algo, fd, index_name);
9694
}
9795

9896
/* 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,
131129
struct pack_idx_entry *obj = *list++;
132130
if (index_version < 2)
133131
hashwrite_be32(f, obj->offset);
134-
hashwrite(f, obj->oid.hash, hash_algo->rawsz);
132+
hashwrite(f, obj->oid.hash, repo->hash_algo->rawsz);
135133
if ((opts->flags & WRITE_IDX_STRICT) &&
136134
(i && oideq(&list[-2]->oid, &obj->oid)))
137135
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,
173171
}
174172
}
175173

176-
hashwrite(f, sha1, hash_algo->rawsz);
174+
hashwrite(f, sha1, repo->hash_algo->rawsz);
177175
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
178176
CSUM_HASH_IN_STREAM | CSUM_CLOSE |
179177
((opts->flags & WRITE_IDX_VERIFY) ? 0 : CSUM_FSYNC));
@@ -217,7 +215,7 @@ static void write_rev_trailer(const struct git_hash_algo *hash_algo,
217215
hashwrite(f, hash, hash_algo->rawsz);
218216
}
219217

220-
char *write_rev_file(const struct git_hash_algo *hash_algo,
218+
char *write_rev_file(struct repository *repo,
221219
const char *rev_name,
222220
struct pack_idx_entry **objects,
223221
uint32_t nr_objects,
@@ -236,15 +234,15 @@ char *write_rev_file(const struct git_hash_algo *hash_algo,
236234
pack_order[i] = i;
237235
QSORT_S(pack_order, nr_objects, pack_order_cmp, objects);
238236

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,
240238
hash, flags);
241239

242240
free(pack_order);
243241

244242
return ret;
245243
}
246244

247-
char *write_rev_file_order(const struct git_hash_algo *hash_algo,
245+
char *write_rev_file_order(struct repository *repo,
248246
const char *rev_name,
249247
uint32_t *pack_order,
250248
uint32_t nr_objects,
@@ -268,7 +266,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
268266
fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
269267
path = xstrdup(rev_name);
270268
}
271-
f = hashfd(the_repository->hash_algo, fd, path);
269+
f = hashfd(repo->hash_algo, fd, path);
272270
} else if (flags & WRITE_REV_VERIFY) {
273271
struct stat statbuf;
274272
if (stat(rev_name, &statbuf)) {
@@ -278,18 +276,18 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
278276
} else
279277
die_errno(_("could not stat: %s"), rev_name);
280278
}
281-
f = hashfd_check(the_repository->hash_algo, rev_name);
279+
f = hashfd_check(repo->hash_algo, rev_name);
282280
path = xstrdup(rev_name);
283281
} else {
284282
return NULL;
285283
}
286284

287-
write_rev_header(hash_algo, f);
285+
write_rev_header(repo->hash_algo, f);
288286

289287
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);
291289

292-
if (adjust_shared_perm(the_repository, path) < 0)
290+
if (adjust_shared_perm(repo, path) < 0)
293291
die(_("failed to make %s readable"), path);
294292

295293
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -330,7 +328,7 @@ static void write_mtimes_trailer(const struct git_hash_algo *hash_algo,
330328
hashwrite(f, hash, hash_algo->rawsz);
331329
}
332330

333-
static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
331+
static char *write_mtimes_file(struct repository *repo,
334332
struct packing_data *to_pack,
335333
struct pack_idx_entry **objects,
336334
uint32_t nr_objects,
@@ -346,13 +344,13 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
346344

347345
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
348346
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);
350348

351-
write_mtimes_header(hash_algo, f);
349+
write_mtimes_header(repo->hash_algo, f);
352350
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);
354352

355-
if (adjust_shared_perm(the_repository, mtimes_name) < 0)
353+
if (adjust_shared_perm(repo, mtimes_name) < 0)
356354
die(_("failed to make %s readable"), mtimes_name);
357355

358356
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -527,14 +525,15 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
527525
return n;
528526
}
529527

530-
struct hashfile *create_tmp_packfile(char **pack_tmp_name)
528+
struct hashfile *create_tmp_packfile(struct repository *repo,
529+
char **pack_tmp_name)
531530
{
532531
struct strbuf tmpname = STRBUF_INIT;
533532
int fd;
534533

535534
fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
536535
*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);
538537
}
539538

540539
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,
555554
rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
556555
}
557556

558-
void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
557+
void stage_tmp_packfiles(struct repository *repo,
559558
struct strbuf *name_buffer,
560559
const char *pack_tmp_name,
561560
struct pack_idx_entry **written_list,
@@ -568,19 +567,19 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
568567
char *rev_tmp_name = NULL;
569568
char *mtimes_tmp_name = NULL;
570569

571-
if (adjust_shared_perm(the_repository, pack_tmp_name))
570+
if (adjust_shared_perm(repo, pack_tmp_name))
572571
die_errno("unable to make temporary pack file readable");
573572

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,
575574
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))
577576
die_errno("unable to make temporary index file readable");
578577

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,
580579
hash, pack_idx_opts->flags);
581580

582581
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,
584583
written_list, nr_written,
585584
hash);
586585
}

pack.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct progress;
8787
/* Note, the data argument could be NULL if object type is blob */
8888
typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*);
8989

90-
const char *write_idx_file(const struct git_hash_algo *hash_algo,
90+
const char *write_idx_file(struct repository *repo,
9191
const char *index_name,
9292
struct pack_idx_entry **objects,
9393
int nr_objects,
@@ -106,13 +106,13 @@ struct ref;
106106

107107
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought);
108108

109-
char *write_rev_file(const struct git_hash_algo *hash_algo,
109+
char *write_rev_file(struct repository *repo,
110110
const char *rev_name,
111111
struct pack_idx_entry **objects,
112112
uint32_t nr_objects,
113113
const unsigned char *hash,
114114
unsigned flags);
115-
char *write_rev_file_order(const struct git_hash_algo *hash_algo,
115+
char *write_rev_file_order(struct repository *repo,
116116
const char *rev_name,
117117
uint32_t *pack_order,
118118
uint32_t nr_objects,
@@ -134,8 +134,9 @@ int read_pack_header(int fd, struct pack_header *);
134134

135135
struct packing_data;
136136

137-
struct hashfile *create_tmp_packfile(char **pack_tmp_name);
138-
void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
137+
struct hashfile *create_tmp_packfile(struct repository *repo,
138+
char **pack_tmp_name);
139+
void stage_tmp_packfiles(struct repository *repo,
139140
struct strbuf *name_buffer,
140141
const char *pack_tmp_name,
141142
struct pack_idx_entry **written_list,

0 commit comments

Comments
 (0)