|
33 | 33 | #include "pack.h" |
34 | 34 | #include "pack-objects.h" |
35 | 35 | #include "path.h" |
| 36 | +#include "reflog.h" |
36 | 37 | #include "blob.h" |
37 | 38 | #include "tree.h" |
38 | 39 | #include "promisor-remote.h" |
@@ -285,6 +286,49 @@ static int maintenance_task_pack_refs(struct maintenance_run_opts *opts, |
285 | 286 | return run_command(&cmd); |
286 | 287 | } |
287 | 288 |
|
| 289 | +struct count_reflog_entries_data { |
| 290 | + struct expire_reflog_policy_cb policy; |
| 291 | + size_t count; |
| 292 | + size_t limit; |
| 293 | +}; |
| 294 | + |
| 295 | +static int count_reflog_entries(struct object_id *old_oid, struct object_id *new_oid, |
| 296 | + const char *committer, timestamp_t timestamp, |
| 297 | + int tz, const char *msg, void *cb_data) |
| 298 | +{ |
| 299 | + struct count_reflog_entries_data *data = cb_data; |
| 300 | + if (should_expire_reflog_ent(old_oid, new_oid, committer, timestamp, tz, msg, &data->policy)) |
| 301 | + data->count++; |
| 302 | + return data->count >= data->limit; |
| 303 | +} |
| 304 | + |
| 305 | +static int reflog_expire_condition(struct gc_config *cfg UNUSED) |
| 306 | +{ |
| 307 | + timestamp_t now = time(NULL); |
| 308 | + struct count_reflog_entries_data data = { |
| 309 | + .policy = { |
| 310 | + .opts = REFLOG_EXPIRE_OPTIONS_INIT(now), |
| 311 | + }, |
| 312 | + }; |
| 313 | + int limit = 100; |
| 314 | + |
| 315 | + git_config_get_int("maintenance.reflog-expire.auto", &limit); |
| 316 | + if (!limit) |
| 317 | + return 0; |
| 318 | + if (limit < 0) |
| 319 | + return 1; |
| 320 | + data.limit = limit; |
| 321 | + |
| 322 | + repo_config(the_repository, reflog_expire_config, &data.policy.opts); |
| 323 | + |
| 324 | + reflog_expire_options_set_refname(&data.policy.opts, "HEAD"); |
| 325 | + refs_for_each_reflog_ent(get_main_ref_store(the_repository), "HEAD", |
| 326 | + count_reflog_entries, &data); |
| 327 | + |
| 328 | + reflog_expiry_cleanup(&data.policy); |
| 329 | + return data.count >= data.limit; |
| 330 | +} |
| 331 | + |
288 | 332 | static int maintenance_task_reflog_expire(struct maintenance_run_opts *opts UNUSED, |
289 | 333 | struct gc_config *cfg UNUSED) |
290 | 334 | { |
@@ -1383,6 +1427,7 @@ enum maintenance_task_label { |
1383 | 1427 | TASK_GC, |
1384 | 1428 | TASK_COMMIT_GRAPH, |
1385 | 1429 | TASK_PACK_REFS, |
| 1430 | + TASK_REFLOG_EXPIRE, |
1386 | 1431 |
|
1387 | 1432 | /* Leave as final value */ |
1388 | 1433 | TASK__COUNT |
@@ -1419,6 +1464,11 @@ static struct maintenance_task tasks[] = { |
1419 | 1464 | maintenance_task_pack_refs, |
1420 | 1465 | pack_refs_condition, |
1421 | 1466 | }, |
| 1467 | + [TASK_REFLOG_EXPIRE] = { |
| 1468 | + "reflog-expire", |
| 1469 | + maintenance_task_reflog_expire, |
| 1470 | + reflog_expire_condition, |
| 1471 | + }, |
1422 | 1472 | }; |
1423 | 1473 |
|
1424 | 1474 | static int compare_tasks_by_selection(const void *a_, const void *b_) |
|
0 commit comments