object-store: move `struct packed_git` into "packfile.h"

The "object-store.h" header contains the definition of `struct packed_git`. As this structure hosts all kind of information about a specific packfile it is arguably a bit out of place in a generic place like "object-store.h". Move the structure as well as `pack_map_entry_cmp()` into "packfile.h". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 29, 2025 at 09:52 UTC ddb28da58fd657fa672f4605e50e140ce4c662f8
3 files changed +60 -59
object-store.h
+1 -58
@@ -92,65 +92,8 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
92 /* Empty the loose object cache for the specified object directory. */
93 void odb_clear_loose_cache(struct object_directory *odb);
94
95 -struct packed_git {
96 - struct hashmap_entry packmap_ent;
97 - struct packed_git *next;
98 - struct list_head mru;
99 - struct pack_window *windows;
100 - off_t pack_size;
101 - const void *index_data;
102 - size_t index_size;
103 - uint32_t num_objects;
104 - size_t crc_offset;
105 - struct oidset bad_objects;
106 - int index_version;
107 - time_t mtime;
108 - int pack_fd;
109 - int index; /* for builtin/pack-objects.c */
110 - unsigned pack_local:1,
111 - pack_keep:1,
112 - pack_keep_in_core:1,
113 - freshened:1,
114 - do_not_close:1,
115 - pack_promisor:1,
116 - multi_pack_index:1,
117 - is_cruft:1;
118 - unsigned char hash[GIT_MAX_RAWSZ];
119 - struct revindex_entry *revindex;
120 - const uint32_t *revindex_data;
121 - const uint32_t *revindex_map;
122 - size_t revindex_size;
123 - /*
124 - * mtimes_map points at the beginning of the memory mapped region of
125 - * this pack's corresponding .mtimes file, and mtimes_size is the size
126 - * of that .mtimes file
127 - */
128 - const uint32_t *mtimes_map;
129 - size_t mtimes_size;
130 -
131 - /* repo denotes the repository this packfile belongs to */
132 - struct repository *repo;
133 -
134 - /* something like ".git/objects/pack/xxxxx.pack" */
135 - char pack_name[FLEX_ARRAY]; /* more */
136 -};
137 -
95 +struct packed_git;
96 struct multi_pack_index;
139 -
140 -static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
141 - const struct hashmap_entry *entry,
142 - const struct hashmap_entry *entry2,
143 - const void *keydata)
144 -{
145 - const char *key = keydata;
146 - const struct packed_git *pg1, *pg2;
147 -
148 - pg1 = container_of(entry, const struct packed_git, packmap_ent);
149 - pg2 = container_of(entry2, const struct packed_git, packmap_ent);
150 -
151 - return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
152 -}
153 -
97 struct cached_object_entry;
98
99 struct raw_object_store {
pack-objects.h
+1
@@ -4,6 +4,7 @@
4 #include "object-store.h"
5 #include "thread-utils.h"
6 #include "pack.h"
7 +#include "packfile.h"
8
9 struct repository;
10
packfile.h
+58 -1
@@ -1,13 +1,70 @@
1 #ifndef PACKFILE_H
2 #define PACKFILE_H
3
4 +#include "list.h"
5 #include "object.h"
6 #include "oidset.h"
7
8 /* in object-store.h */
8 -struct packed_git;
9 struct object_info;
10
11 +struct packed_git {
12 + struct hashmap_entry packmap_ent;
13 + struct packed_git *next;
14 + struct list_head mru;
15 + struct pack_window *windows;
16 + off_t pack_size;
17 + const void *index_data;
18 + size_t index_size;
19 + uint32_t num_objects;
20 + size_t crc_offset;
21 + struct oidset bad_objects;
22 + int index_version;
23 + time_t mtime;
24 + int pack_fd;
25 + int index; /* for builtin/pack-objects.c */
26 + unsigned pack_local:1,
27 + pack_keep:1,
28 + pack_keep_in_core:1,
29 + freshened:1,
30 + do_not_close:1,
31 + pack_promisor:1,
32 + multi_pack_index:1,
33 + is_cruft:1;
34 + unsigned char hash[GIT_MAX_RAWSZ];
35 + struct revindex_entry *revindex;
36 + const uint32_t *revindex_data;
37 + const uint32_t *revindex_map;
38 + size_t revindex_size;
39 + /*
40 + * mtimes_map points at the beginning of the memory mapped region of
41 + * this pack's corresponding .mtimes file, and mtimes_size is the size
42 + * of that .mtimes file
43 + */
44 + const uint32_t *mtimes_map;
45 + size_t mtimes_size;
46 +
47 + /* repo denotes the repository this packfile belongs to */
48 + struct repository *repo;
49 +
50 + /* something like ".git/objects/pack/xxxxx.pack" */
51 + char pack_name[FLEX_ARRAY]; /* more */
52 +};
53 +
54 +static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
55 + const struct hashmap_entry *entry,
56 + const struct hashmap_entry *entry2,
57 + const void *keydata)
58 +{
59 + const char *key = keydata;
60 + const struct packed_git *pg1, *pg2;
61 +
62 + pg1 = container_of(entry, const struct packed_git, packmap_ent);
63 + pg2 = container_of(entry2, const struct packed_git, packmap_ent);
64 +
65 + return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
66 +}
67 +
68 struct pack_window {
69 struct pack_window *next;
70 unsigned char *base;