Skip to content

Commit 2fb9040

Browse files
ttaylorrgitster
authored andcommitted
reachable: add options to add_unseen_recent_objects_to_traversal
This function behaves very similarly to what we will need in pack-objects in order to implement cruft packs with expiration. But it is lacking a couple of things. Namely, it needs: - a mechanism to communicate the timestamps of individual recent objects to some external caller - and, in the case of packed objects, our future caller will also want to know the originating pack, as well as the offset within that pack at which the object can be found - finally, it needs a way to skip over packs which are marked as kept in-core. To address the first two, add a callback interface in this patch which reports the time of each recent object, as well as a (packed_git, off_t) pair for packed objects. Likewise, add a new option to the packed object iterators to skip over packs which are marked as kept in core. This option will become implicitly tested in a future patch. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b757353 commit 2fb9040

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
39573957
if (unpack_unreachable_expiration) {
39583958
revs->ignore_missing_links = 1;
39593959
if (add_unseen_recent_objects_to_traversal(revs,
3960-
unpack_unreachable_expiration))
3960+
unpack_unreachable_expiration, NULL, 0))
39613961
die(_("unable to add recent objects"));
39623962
if (prepare_revision_walk(revs))
39633963
die(_("revision walk setup failed"));

reachable.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ static void mark_commit(struct commit *c, void *data)
6060
struct recent_data {
6161
struct rev_info *revs;
6262
timestamp_t timestamp;
63+
report_recent_object_fn *cb;
64+
int ignore_in_core_kept_packs;
6365
};
6466

6567
static void add_recent_object(const struct object_id *oid,
68+
struct packed_git *pack,
69+
off_t offset,
6670
timestamp_t mtime,
6771
struct recent_data *data)
6872
{
@@ -103,13 +107,29 @@ static void add_recent_object(const struct object_id *oid,
103107
die("unable to lookup %s", oid_to_hex(oid));
104108

105109
add_pending_object(data->revs, obj, "");
110+
if (data->cb)
111+
data->cb(obj, pack, offset, mtime);
112+
}
113+
114+
static int want_recent_object(struct recent_data *data,
115+
const struct object_id *oid)
116+
{
117+
if (data->ignore_in_core_kept_packs &&
118+
has_object_kept_pack(oid, IN_CORE_KEEP_PACKS))
119+
return 0;
120+
return 1;
106121
}
107122

108123
static int add_recent_loose(const struct object_id *oid,
109124
const char *path, void *data)
110125
{
111126
struct stat st;
112-
struct object *obj = lookup_object(the_repository, oid);
127+
struct object *obj;
128+
129+
if (!want_recent_object(data, oid))
130+
return 0;
131+
132+
obj = lookup_object(the_repository, oid);
113133

114134
if (obj && obj->flags & SEEN)
115135
return 0;
@@ -126,37 +146,51 @@ static int add_recent_loose(const struct object_id *oid,
126146
return error_errno("unable to stat %s", oid_to_hex(oid));
127147
}
128148

129-
add_recent_object(oid, st.st_mtime, data);
149+
add_recent_object(oid, NULL, 0, st.st_mtime, data);
130150
return 0;
131151
}
132152

133153
static int add_recent_packed(const struct object_id *oid,
134154
struct packed_git *p, uint32_t pos,
135155
void *data)
136156
{
137-
struct object *obj = lookup_object(the_repository, oid);
157+
struct object *obj;
158+
159+
if (!want_recent_object(data, oid))
160+
return 0;
161+
162+
obj = lookup_object(the_repository, oid);
138163

139164
if (obj && obj->flags & SEEN)
140165
return 0;
141-
add_recent_object(oid, p->mtime, data);
166+
add_recent_object(oid, p, nth_packed_object_offset(p, pos), p->mtime, data);
142167
return 0;
143168
}
144169

145170
int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
146-
timestamp_t timestamp)
171+
timestamp_t timestamp,
172+
report_recent_object_fn *cb,
173+
int ignore_in_core_kept_packs)
147174
{
148175
struct recent_data data;
176+
enum for_each_object_flags flags;
149177
int r;
150178

151179
data.revs = revs;
152180
data.timestamp = timestamp;
181+
data.cb = cb;
182+
data.ignore_in_core_kept_packs = ignore_in_core_kept_packs;
153183

154184
r = for_each_loose_object(add_recent_loose, &data,
155185
FOR_EACH_OBJECT_LOCAL_ONLY);
156186
if (r)
157187
return r;
158-
return for_each_packed_object(add_recent_packed, &data,
159-
FOR_EACH_OBJECT_LOCAL_ONLY);
188+
189+
flags = FOR_EACH_OBJECT_LOCAL_ONLY | FOR_EACH_OBJECT_PACK_ORDER;
190+
if (ignore_in_core_kept_packs)
191+
flags |= FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS;
192+
193+
return for_each_packed_object(add_recent_packed, &data, flags);
160194
}
161195

162196
static int mark_object_seen(const struct object_id *oid,
@@ -217,7 +251,8 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
217251

218252
if (mark_recent) {
219253
revs->ignore_missing_links = 1;
220-
if (add_unseen_recent_objects_to_traversal(revs, mark_recent))
254+
if (add_unseen_recent_objects_to_traversal(revs, mark_recent,
255+
NULL, 0))
221256
die("unable to mark recent objects");
222257
if (prepare_revision_walk(revs))
223258
die("revision walk setup failed");

reachable.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#ifndef REACHEABLE_H
22
#define REACHEABLE_H
33

4+
#include "object.h"
5+
46
struct progress;
57
struct rev_info;
68

9+
typedef void report_recent_object_fn(const struct object *, struct packed_git *,
10+
off_t, time_t);
11+
712
int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
8-
timestamp_t timestamp);
13+
timestamp_t timestamp,
14+
report_recent_object_fn cb,
15+
int ignore_in_core_kept_packs);
916
void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
1017
timestamp_t mark_recent, struct progress *);
1118

0 commit comments

Comments
 (0)