Skip to content

Commit 2cf3fe6

Browse files
KarthikNayakgitster
authored andcommitted
packfile: add repository to struct packed_git
The struct `packed_git` holds information regarding a packed object file. Let's add the repository variable to this object, to represent the repository that this packfile belongs to. This helps remove dependency on the global `the_repository` object in `packfile.c` by simply using repository information now readily available in the struct. We do need to consider that a packfile could be part of the alternates of a repository, but considering that we only have one repository struct and also that we currently anyways use 'the_repository', we should be OK with this change. We also modify `alloc_packed_git` to ensure that the repository is added to newly created `packed_git` structs. This requires modifying the function and all its callee to pass the repository object down the levels. Helped-by: Taylor Blau <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f8d6ee commit 2cf3fe6

10 files changed

+30
-16
lines changed

builtin/fast-import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ static void start_packfile(void)
765765

766766
p->pack_fd = pack_fd;
767767
p->do_not_close = 1;
768+
p->repo = the_repository;
768769
pack_file = hashfd(pack_fd, p->pack_name);
769770

770771
pack_data = p;
@@ -888,7 +889,7 @@ static void end_packfile(void)
888889
idx_name = keep_pack(create_index());
889890

890891
/* Register the packfile with core git's machinery. */
891-
new_p = add_packed_git(idx_name, strlen(idx_name), 1);
892+
new_p = add_packed_git(pack_data->repo, idx_name, strlen(idx_name), 1);
892893
if (!new_p)
893894
die("core git rejected index %s", idx_name);
894895
all_packs[pack_id] = new_p;

builtin/index-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
15521552

15531553
if (do_fsck_object) {
15541554
struct packed_git *p;
1555-
p = add_packed_git(final_index_name, strlen(final_index_name), 0);
1555+
p = add_packed_git(the_repository, final_index_name,
1556+
strlen(final_index_name), 0);
15561557
if (p)
15571558
install_packed_git(the_repository, p);
15581559
}
@@ -1650,7 +1651,8 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
16501651

16511652
static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
16521653
{
1653-
struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);
1654+
struct packed_git *p = add_packed_git(the_repository, pack_name,
1655+
strlen(pack_name), 1);
16541656

16551657
if (!p)
16561658
die(_("Cannot open existing pack file '%s'"), pack_name);

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
19141914
struct packed_git *p;
19151915
strbuf_setlen(&packname, dirlen);
19161916
strbuf_addstr(&packname, pack_indexes->items[i].string);
1917-
p = add_packed_git(packname.buf, packname.len, 1);
1917+
p = add_packed_git(ctx->r, packname.buf, packname.len, 1);
19181918
if (!p) {
19191919
ret = error(_("error adding pack %s"), packname.buf);
19201920
goto cleanup;

connected.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
5454
strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,
5555
base_len);
5656
strbuf_addstr(&idx_file, ".idx");
57-
new_pack = add_packed_git(idx_file.buf, idx_file.len, 1);
57+
new_pack = add_packed_git(the_repository, idx_file.buf,
58+
idx_file.len, 1);
5859
strbuf_release(&idx_file);
5960
}
6061

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
24392439
if (!tmp_idx)
24402440
return -1;
24412441

2442-
new_pack = parse_pack_index(sha1, tmp_idx);
2442+
new_pack = parse_pack_index(the_repository, sha1, tmp_idx);
24432443
if (!new_pack) {
24442444
unlink(tmp_idx);
24452445
free(tmp_idx);

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,
154154
return;
155155

156156
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
157-
p = add_packed_git(full_path, full_path_len, 0);
157+
p = add_packed_git(the_repository, full_path, full_path_len, 0);
158158
if (!p) {
159159
warning(_("failed to add packfile '%s'"),
160160
full_path);

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
464464
strhash(key.buf), key.buf,
465465
struct packed_git, packmap_ent);
466466
if (!p) {
467-
p = add_packed_git(pack_name.buf, pack_name.len, m->local);
467+
p = add_packed_git(r, pack_name.buf, pack_name.len, m->local);
468468
if (p) {
469469
install_packed_git(r, p);
470470
list_add_tail(&p->mru, &r->objects->packed_git_mru);

object-store-ll.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
struct oidmap;
1111
struct oidtree;
1212
struct strbuf;
13+
struct repository;
1314

1415
struct object_directory {
1516
struct object_directory *next;
@@ -135,6 +136,10 @@ struct packed_git {
135136
*/
136137
const uint32_t *mtimes_map;
137138
size_t mtimes_size;
139+
140+
/* repo denotes the repository this packfile belongs to */
141+
struct repository *repo;
142+
138143
/* something like ".git/objects/pack/xxxxx.pack" */
139144
char pack_name[FLEX_ARRAY]; /* more */
140145
};

packfile.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value)
217217
return ntohl(level1_ofs[value]);
218218
}
219219

220-
static struct packed_git *alloc_packed_git(int extra)
220+
static struct packed_git *alloc_packed_git(struct repository *r, int extra)
221221
{
222222
struct packed_git *p = xmalloc(st_add(sizeof(*p), extra));
223223
memset(p, 0, sizeof(*p));
224224
p->pack_fd = -1;
225+
p->repo = r;
225226
return p;
226227
}
227228

@@ -233,11 +234,12 @@ static char *pack_path_from_idx(const char *idx_path)
233234
return xstrfmt("%.*s.pack", (int)len, idx_path);
234235
}
235236

236-
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
237+
struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,
238+
const char *idx_path)
237239
{
238240
char *path = pack_path_from_idx(idx_path);
239241
size_t alloc = st_add(strlen(path), 1);
240-
struct packed_git *p = alloc_packed_git(alloc);
242+
struct packed_git *p = alloc_packed_git(r, alloc);
241243

242244
memcpy(p->pack_name, path, alloc); /* includes NUL */
243245
free(path);
@@ -703,7 +705,8 @@ void unuse_pack(struct pack_window **w_cursor)
703705
}
704706
}
705707

706-
struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
708+
struct packed_git *add_packed_git(struct repository *r, const char *path,
709+
size_t path_len, int local)
707710
{
708711
struct stat st;
709712
size_t alloc;
@@ -721,7 +724,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
721724
* the use xsnprintf double-checks that)
722725
*/
723726
alloc = st_add3(path_len, strlen(".promisor"), 1);
724-
p = alloc_packed_git(alloc);
727+
p = alloc_packed_git(r, alloc);
725728
memcpy(p->pack_name, path, path_len);
726729

727730
xsnprintf(p->pack_name + path_len, alloc - path_len, ".keep");
@@ -877,7 +880,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
877880

878881
/* Don't reopen a pack we already have. */
879882
if (!hashmap_get(&data->r->objects->pack_map, &hent, pack_name)) {
880-
p = add_packed_git(full_name, full_name_len, data->local);
883+
p = add_packed_git(data->r, full_name, full_name_len, data->local);
881884
if (p)
882885
install_packed_git(data->r, p);
883886
}

packfile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const char *pack_basename(struct packed_git *p);
4646
* and does not add the resulting packed_git struct to the internal list of
4747
* packs. You probably want add_packed_git() instead.
4848
*/
49-
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
49+
struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,
50+
const char *idx_path);
5051

5152
typedef void each_file_in_pack_dir_fn(const char *full_path, size_t full_path_len,
5253
const char *file_name, void *data);
@@ -113,7 +114,8 @@ void close_pack(struct packed_git *);
113114
void close_object_store(struct raw_object_store *o);
114115
void unuse_pack(struct pack_window **);
115116
void clear_delta_base_cache(void);
116-
struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
117+
struct packed_git *add_packed_git(struct repository *r, const char *path,
118+
size_t path_len, int local);
117119

118120
/*
119121
* Unlink the .pack and associated extension files.

0 commit comments

Comments
 (0)