Skip to content

Commit e2f6f76

Browse files
KarthikNayakgitster
authored andcommitted
pack-write: pass repository to index_pack_lockfile()
The `index_pack_lockfile()` function uses the global `the_repository` variable to access the repository. To avoid global variable usage, pass the repository from the layers above. Altough the layers above could have access to the repository internally, simply pass in `the_repository`. This avoids any compatibility issues and bubbles up global variable usage to upper layers which can be eventually resolved. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8244d01 commit e2f6f76

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
23042304
if (status)
23052305
return "index-pack fork failed";
23062306

2307-
lockfile = index_pack_lockfile(child.out, NULL);
2307+
lockfile = index_pack_lockfile(the_repository, child.out, NULL);
23082308
if (lockfile) {
23092309
pack_lockfile = register_tempfile(lockfile);
23102310
free(lockfile);

fetch-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ static int get_pack(struct fetch_pack_args *args,
10361036
die(_("fetch-pack: unable to fork off %s"), cmd_name);
10371037
if (do_keep && (pack_lockfiles || fsck_objects)) {
10381038
int is_well_formed;
1039-
char *pack_lockfile = index_pack_lockfile(cmd.out, &is_well_formed);
1039+
char *pack_lockfile = index_pack_lockfile(the_repository,
1040+
cmd.out,
1041+
&is_well_formed);
10401042

10411043
if (!is_well_formed)
10421044
die(_("fetch-pack: invalid index-pack output"));

pack-write.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo,
460460
fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name);
461461
}
462462

463-
char *index_pack_lockfile(int ip_out, int *is_well_formed)
463+
char *index_pack_lockfile(struct repository *r, int ip_out, int *is_well_formed)
464464
{
465465
char packname[GIT_MAX_HEXSZ + 6];
466-
const int len = the_hash_algo->hexsz + 6;
466+
const int len = r->hash_algo->hexsz + 6;
467467

468468
/*
469469
* The first thing we expect from index-pack's output
@@ -480,7 +480,7 @@ char *index_pack_lockfile(int ip_out, int *is_well_formed)
480480
packname[len-1] = 0;
481481
if (skip_prefix(packname, "keep\t", &name))
482482
return xstrfmt("%s/pack/pack-%s.keep",
483-
repo_get_object_directory(the_repository), name);
483+
repo_get_object_directory(r), name);
484484
return NULL;
485485
}
486486
if (is_well_formed)

pack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ off_t write_pack_header(struct hashfile *f, uint32_t);
9494
void fixup_pack_header_footer(const struct git_hash_algo *, int,
9595
unsigned char *, const char *, uint32_t,
9696
unsigned char *, off_t);
97-
char *index_pack_lockfile(int fd, int *is_well_formed);
97+
char *index_pack_lockfile(struct repository *r, int fd, int *is_well_formed);
9898

9999
struct ref;
100100

0 commit comments

Comments
 (0)