diff options
Diffstat (limited to 'refs')
-rw-r--r-- | refs/debug.c | 54 | ||||
-rw-r--r-- | refs/files-backend.c | 24 | ||||
-rw-r--r-- | refs/iterator.c | 2 | ||||
-rw-r--r-- | refs/packed-backend.c | 4 | ||||
-rw-r--r-- | refs/ref-cache.c | 2 |
5 files changed, 65 insertions, 21 deletions
diff --git a/refs/debug.c b/refs/debug.c index 922e64fa6a..7db4abccc3 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -243,7 +243,8 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; int res = 0; - oidcpy(oid, &null_oid); + oidcpy(oid, null_oid()); + errno = 0; res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent, type); @@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n", refname, oid_to_hex(oid), referent->buf, *type, res); } else { - trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res); + trace_printf_key(&trace_refs, + "read_raw_ref: %s: %d (errno %d)\n", refname, + res, errno); } return res; } @@ -353,6 +356,40 @@ static int debug_delete_reflog(struct ref_store *ref_store, const char *refname) return res; } +struct debug_reflog_expiry_should_prune { + reflog_expiry_prepare_fn *prepare; + reflog_expiry_should_prune_fn *should_prune; + reflog_expiry_cleanup_fn *cleanup; + void *cb_data; +}; + +static void debug_reflog_expiry_prepare(const char *refname, + const struct object_id *oid, + void *cb_data) +{ + struct debug_reflog_expiry_should_prune *prune = cb_data; + trace_printf_key(&trace_refs, "reflog_expire_prepare: %s\n", refname); + prune->prepare(refname, oid, prune->cb_data); +} + +static int debug_reflog_expiry_should_prune_fn(struct object_id *ooid, + struct object_id *noid, + const char *email, + timestamp_t timestamp, int tz, + const char *message, void *cb_data) { + struct debug_reflog_expiry_should_prune *prune = cb_data; + + int result = prune->should_prune(ooid, noid, email, timestamp, tz, message, prune->cb_data); + trace_printf_key(&trace_refs, "reflog_expire_should_prune: %s %ld: %d\n", message, (long int) timestamp, result); + return result; +} + +static void debug_reflog_expiry_cleanup(void *cb_data) +{ + struct debug_reflog_expiry_should_prune *prune = cb_data; + prune->cleanup(prune->cb_data); +} + static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, const struct object_id *oid, unsigned int flags, reflog_expiry_prepare_fn prepare_fn, @@ -361,10 +398,17 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, void *policy_cb_data) { struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; + struct debug_reflog_expiry_should_prune prune = { + .prepare = prepare_fn, + .cleanup = cleanup_fn, + .should_prune = should_prune_fn, + .cb_data = policy_cb_data, + }; int res = drefs->refs->be->reflog_expire(drefs->refs, refname, oid, - flags, prepare_fn, - should_prune_fn, cleanup_fn, - policy_cb_data); + flags, &debug_reflog_expiry_prepare, + &debug_reflog_expiry_should_prune_fn, + &debug_reflog_expiry_cleanup, + &prune); trace_printf_key(&trace_refs, "reflog_expire: %s: %d\n", refname, res); return res; } diff --git a/refs/files-backend.c b/refs/files-backend.c index 4fdc68810b..677b7e4cdd 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -45,10 +45,10 @@ #define REF_UPDATE_VIA_HEAD (1 << 8) /* - * Used as a flag in ref_update::flags when the loose reference has - * been deleted. + * Used as a flag in ref_update::flags when a reference has been + * deleted and the ref's parent directories may need cleanup. */ -#define REF_DELETED_LOOSE (1 << 9) +#define REF_DELETED_RMDIR (1 << 9) struct ref_lock { char *ref_name; @@ -549,7 +549,7 @@ static int lock_raw_ref(struct files_ref_store *refs, /* First lock the file so it can't change out from under us. */ - *lock_p = lock = xcalloc(1, sizeof(*lock)); + *lock_p = CALLOC_ARRAY(lock, 1); lock->ref_name = xstrdup(refname); files_ref_path(refs, &ref_file, refname); @@ -843,7 +843,7 @@ static struct ref_iterator *files_ref_iterator_begin( overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter); - iter = xcalloc(1, sizeof(*iter)); + CALLOC_ARRAY(iter, 1); ref_iterator = &iter->base; base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable, overlay_iter->ordered); @@ -930,7 +930,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, files_assert_main_repository(refs, "lock_ref_oid_basic"); assert(err); - lock = xcalloc(1, sizeof(struct ref_lock)); + CALLOC_ARRAY(lock, 1); if (mustexist) resolve_flags |= RESOLVE_REF_READING; @@ -1084,7 +1084,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r) ref_transaction_add_update( transaction, r->name, REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING, - &null_oid, &r->oid, NULL); + null_oid(), &r->oid, NULL); if (ref_transaction_commit(transaction, &err)) goto cleanup; @@ -2152,7 +2152,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store, return empty_ref_iterator_begin(); } - iter = xcalloc(1, sizeof(*iter)); + CALLOC_ARRAY(iter, 1); ref_iterator = &iter->base; base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0); @@ -2597,7 +2597,7 @@ static int files_transaction_prepare(struct ref_store *ref_store, if (!transaction->nr) goto cleanup; - backend_data = xcalloc(1, sizeof(*backend_data)); + CALLOC_ARRAY(backend_data, 1); transaction->backend_data = backend_data; /* @@ -2852,6 +2852,7 @@ static int files_transaction_finish(struct ref_store *ref_store, if (update->flags & REF_DELETING && !(update->flags & REF_LOG_ONLY)) { + update->flags |= REF_DELETED_RMDIR; if (!(update->type & REF_ISPACKED) || update->type & REF_ISSYMREF) { /* It is a loose reference. */ @@ -2861,7 +2862,6 @@ static int files_transaction_finish(struct ref_store *ref_store, ret = TRANSACTION_GENERIC_ERROR; goto cleanup; } - update->flags |= REF_DELETED_LOOSE; } } } @@ -2874,9 +2874,9 @@ cleanup: for (i = 0; i < transaction->nr; i++) { struct ref_update *update = transaction->updates[i]; - if (update->flags & REF_DELETED_LOOSE) { + if (update->flags & REF_DELETED_RMDIR) { /* - * The loose reference was deleted. Delete any + * The reference was deleted. Delete any * empty parent directories. (Note that this * can only work because we have already * removed the lockfile.) diff --git a/refs/iterator.c b/refs/iterator.c index 629e00a122..a89d132d4f 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -393,7 +393,7 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0, if (!*prefix && !trim) return iter0; /* optimization: no need to wrap iterator */ - iter = xcalloc(1, sizeof(*iter)); + CALLOC_ARRAY(iter, 1); ref_iterator = &iter->base; base_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable, iter0->ordered); diff --git a/refs/packed-backend.c b/refs/packed-backend.c index b912f2505f..dfecdbc1db 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -941,7 +941,7 @@ static struct ref_iterator *packed_ref_iterator_begin( if (start == snapshot->eof) return empty_ref_iterator_begin(); - iter = xcalloc(1, sizeof(*iter)); + CALLOC_ARRAY(iter, 1); ref_iterator = &iter->base; base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1); @@ -1424,7 +1424,7 @@ static int packed_transaction_prepare(struct ref_store *ref_store, * do so itself. */ - data = xcalloc(1, sizeof(*data)); + CALLOC_ARRAY(data, 1); string_list_init(&data->updates, 0); transaction->backend_data = data; diff --git a/refs/ref-cache.c b/refs/ref-cache.c index b7052f72e2..46f1e54284 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -530,7 +530,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache, if (prime_dir) prime_ref_dir(dir, prefix); - iter = xcalloc(1, sizeof(*iter)); + CALLOC_ARRAY(iter, 1); ref_iterator = &iter->base; base_ref_iterator_init(ref_iterator, &cache_ref_iterator_vtable, 1); ALLOC_GROW(iter->levels, 10, iter->levels_alloc); |