refs/debug: trace into reflog expiry too

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Apr 23, 2021 at 09:10 UTC 34c319970d1ccdeaa612fccdfa3e6a5f2847f1e7
1 file changed +44 -3
refs/debug.c
+44 -3
@@ -353,6 +353,40 @@ static int debug_delete_reflog(struct ref_store *ref_store, const char *refname)
353 return res;
354 }
355
356 +struct debug_reflog_expiry_should_prune {
357 + reflog_expiry_prepare_fn *prepare;
358 + reflog_expiry_should_prune_fn *should_prune;
359 + reflog_expiry_cleanup_fn *cleanup;
360 + void *cb_data;
361 +};
362 +
363 +static void debug_reflog_expiry_prepare(const char *refname,
364 + const struct object_id *oid,
365 + void *cb_data)
366 +{
367 + struct debug_reflog_expiry_should_prune *prune = cb_data;
368 + trace_printf_key(&trace_refs, "reflog_expire_prepare: %s\n", refname);
369 + prune->prepare(refname, oid, prune->cb_data);
370 +}
371 +
372 +static int debug_reflog_expiry_should_prune_fn(struct object_id *ooid,
373 + struct object_id *noid,
374 + const char *email,
375 + timestamp_t timestamp, int tz,
376 + const char *message, void *cb_data) {
377 + struct debug_reflog_expiry_should_prune *prune = cb_data;
378 +
379 + int result = prune->should_prune(ooid, noid, email, timestamp, tz, message, prune->cb_data);
380 + trace_printf_key(&trace_refs, "reflog_expire_should_prune: %s %ld: %d\n", message, (long int) timestamp, result);
381 + return result;
382 +}
383 +
384 +static void debug_reflog_expiry_cleanup(void *cb_data)
385 +{
386 + struct debug_reflog_expiry_should_prune *prune = cb_data;
387 + prune->cleanup(prune->cb_data);
388 +}
389 +
390 static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
391 const struct object_id *oid, unsigned int flags,
392 reflog_expiry_prepare_fn prepare_fn,
@@ -361,10 +395,17 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
395 void *policy_cb_data)
396 {
397 struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
398 + struct debug_reflog_expiry_should_prune prune = {
399 + .prepare = prepare_fn,
400 + .cleanup = cleanup_fn,
401 + .should_prune = should_prune_fn,
402 + .cb_data = policy_cb_data,
403 + };
404 int res = drefs->refs->be->reflog_expire(drefs->refs, refname, oid,
365 - flags, prepare_fn,
366 - should_prune_fn, cleanup_fn,
367 - policy_cb_data);
405 + flags, &debug_reflog_expiry_prepare,
406 + &debug_reflog_expiry_should_prune_fn,
407 + &debug_reflog_expiry_cleanup,
408 + &prune);
409 trace_printf_key(&trace_refs, "reflog_expire: %s: %d\n", refname, res);
410 return res;
411 }