Browse Source

Merge branch 'ab/refs-various-fixes'

Code clean-up.

* ab/refs-various-fixes:
  refs debug: add a wrapper for "read_symbolic_ref"
  packed-backend: remove stub BUG(...) functions
  misc *.c: use designated initializers for struct assignments
  refs: use designated initializers for "struct ref_iterator_vtable"
  refs: use designated initializers for "struct ref_storage_be"
pull/1230/head
Junio C Hamano 4 months ago
parent
commit
3d8046a820
  1. 2
      attr.c
  2. 1
      notes-merge.c
  3. 9
      object-file.c
  4. 13
      refs.c
  5. 82
      refs/debug.c
  6. 64
      refs/files-backend.c
  7. 18
      refs/iterator.c
  8. 128
      refs/packed-backend.c
  9. 6
      refs/ref-cache.c

2
attr.c

@ -79,7 +79,7 @@ static int attr_hash_entry_cmp(const void *unused_cmp_data,
* Access to this dictionary must be surrounded with a mutex.
*/
static struct attr_hashmap g_attr_hashmap = {
HASHMAP_INIT(attr_hash_entry_cmp, NULL)
.map = HASHMAP_INIT(attr_hash_entry_cmp, NULL),
};
/*

1
notes-merge.c

@ -113,6 +113,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
}
static struct object_id uninitialized = {
.hash =
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" \
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
};

9
object-file.c

@ -274,10 +274,11 @@ static struct cached_object {
static int cached_object_nr, cached_object_alloc;
static struct cached_object empty_tree = {
{ EMPTY_TREE_SHA1_BIN_LITERAL },
OBJ_TREE,
"",
0
.oid = {
.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
},
.type = OBJ_TREE,
.buf = "",
};
static struct cached_object *find_cached_object(const struct object_id *oid)

13
refs.c

@ -1676,18 +1676,7 @@ int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
struct strbuf *referent)
{
struct object_id oid;
int ret, failure_errno = 0;
unsigned int type = 0;
if (ref_store->be->read_symbolic_ref)
return ref_store->be->read_symbolic_ref(ref_store, refname, referent);
ret = refs_read_raw_ref(ref_store, refname, &oid, referent, &type, &failure_errno);
if (ret || !(type & REF_ISSYMREF))
return -1;
return 0;
return ref_store->be->read_symbolic_ref(ref_store, refname, referent);
}
const char *refs_resolve_ref_unsafe(struct ref_store *refs,

82
refs/debug.c

@ -220,8 +220,9 @@ static int debug_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable debug_ref_iterator_vtable = {
debug_ref_iterator_advance, debug_ref_iterator_peel,
debug_ref_iterator_abort
.advance = debug_ref_iterator_advance,
.peel = debug_ref_iterator_peel,
.abort = debug_ref_iterator_abort,
};
static struct ref_iterator *
@ -261,6 +262,24 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
return res;
}
static int debug_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
struct strbuf *referent)
{
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
struct ref_store *refs = drefs->refs;
int res;
res = refs->be->read_symbolic_ref(refs, refname, referent);
if (!res)
trace_printf_key(&trace_refs, "read_symbolic_ref: %s: (%s)\n",
refname, referent->buf);
else
trace_printf_key(&trace_refs,
"read_symbolic_ref: %s: %d\n", refname, res);
return res;
}
static struct ref_iterator *
debug_reflog_iterator_begin(struct ref_store *ref_store)
{
@ -418,30 +437,37 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname,
}
struct ref_storage_be refs_be_debug = {
NULL,
"debug",
NULL,
debug_init_db,
debug_transaction_prepare,
debug_transaction_finish,
debug_transaction_abort,
debug_initial_transaction_commit,
debug_pack_refs,
debug_create_symref,
debug_delete_refs,
debug_rename_ref,
debug_copy_ref,
debug_ref_iterator_begin,
debug_read_raw_ref,
NULL,
debug_reflog_iterator_begin,
debug_for_each_reflog_ent,
debug_for_each_reflog_ent_reverse,
debug_reflog_exists,
debug_create_reflog,
debug_delete_reflog,
debug_reflog_expire,
.next = NULL,
.name = "debug",
.init = NULL,
.init_db = debug_init_db,
/*
* None of these should be NULL. If the "files" backend (in
* "struct ref_storage_be refs_be_files" in files-backend.c)
* has a function we should also have a wrapper for it here.
* Test the output with "GIT_TRACE_REFS=1".
*/
.transaction_prepare = debug_transaction_prepare,
.transaction_finish = debug_transaction_finish,
.transaction_abort = debug_transaction_abort,
.initial_transaction_commit = debug_initial_transaction_commit,
.pack_refs = debug_pack_refs,
.create_symref = debug_create_symref,
.delete_refs = debug_delete_refs,
.rename_ref = debug_rename_ref,
.copy_ref = debug_copy_ref,
.iterator_begin = debug_ref_iterator_begin,
.read_raw_ref = debug_read_raw_ref,
.read_symbolic_ref = debug_read_symbolic_ref,
.reflog_iterator_begin = debug_reflog_iterator_begin,
.for_each_reflog_ent = debug_for_each_reflog_ent,
.for_each_reflog_ent_reverse = debug_for_each_reflog_ent_reverse,
.reflog_exists = debug_reflog_exists,
.create_reflog = debug_create_reflog,
.delete_reflog = debug_delete_reflog,
.reflog_expire = debug_reflog_expire,
};

64
refs/files-backend.c

@ -822,9 +822,9 @@ static int files_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable files_ref_iterator_vtable = {
files_ref_iterator_advance,
files_ref_iterator_peel,
files_ref_iterator_abort
.advance = files_ref_iterator_advance,
.peel = files_ref_iterator_peel,
.abort = files_ref_iterator_abort,
};
static struct ref_iterator *files_ref_iterator_begin(
@ -2232,9 +2232,9 @@ static int files_reflog_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable files_reflog_iterator_vtable = {
files_reflog_iterator_advance,
files_reflog_iterator_peel,
files_reflog_iterator_abort
.advance = files_reflog_iterator_advance,
.peel = files_reflog_iterator_peel,
.abort = files_reflog_iterator_abort,
};
static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
@ -3292,30 +3292,30 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
}
struct ref_storage_be refs_be_files = {
NULL,
"files",
files_ref_store_create,
files_init_db,
files_transaction_prepare,
files_transaction_finish,
files_transaction_abort,
files_initial_transaction_commit,
files_pack_refs,
files_create_symref,
files_delete_refs,
files_rename_ref,
files_copy_ref,
files_ref_iterator_begin,
files_read_raw_ref,
files_read_symbolic_ref,
files_reflog_iterator_begin,
files_for_each_reflog_ent,
files_for_each_reflog_ent_reverse,
files_reflog_exists,
files_create_reflog,
files_delete_reflog,
files_reflog_expire
.next = NULL,
.name = "files",
.init = files_ref_store_create,
.init_db = files_init_db,
.transaction_prepare = files_transaction_prepare,
.transaction_finish = files_transaction_finish,
.transaction_abort = files_transaction_abort,
.initial_transaction_commit = files_initial_transaction_commit,
.pack_refs = files_pack_refs,
.create_symref = files_create_symref,
.delete_refs = files_delete_refs,
.rename_ref = files_rename_ref,
.copy_ref = files_copy_ref,
.iterator_begin = files_ref_iterator_begin,
.read_raw_ref = files_read_raw_ref,
.read_symbolic_ref = files_read_symbolic_ref,
.reflog_iterator_begin = files_reflog_iterator_begin,
.for_each_reflog_ent = files_for_each_reflog_ent,
.for_each_reflog_ent_reverse = files_for_each_reflog_ent_reverse,
.reflog_exists = files_reflog_exists,
.create_reflog = files_create_reflog,
.delete_reflog = files_delete_reflog,
.reflog_expire = files_reflog_expire
};

18
refs/iterator.c

@ -64,9 +64,9 @@ static int empty_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable empty_ref_iterator_vtable = {
empty_ref_iterator_advance,
empty_ref_iterator_peel,
empty_ref_iterator_abort
.advance = empty_ref_iterator_advance,
.peel = empty_ref_iterator_peel,
.abort = empty_ref_iterator_abort,
};
struct ref_iterator *empty_ref_iterator_begin(void)
@ -201,9 +201,9 @@ static int merge_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable merge_ref_iterator_vtable = {
merge_ref_iterator_advance,
merge_ref_iterator_peel,
merge_ref_iterator_abort
.advance = merge_ref_iterator_advance,
.peel = merge_ref_iterator_peel,
.abort = merge_ref_iterator_abort,
};
struct ref_iterator *merge_ref_iterator_begin(
@ -378,9 +378,9 @@ static int prefix_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable prefix_ref_iterator_vtable = {
prefix_ref_iterator_advance,
prefix_ref_iterator_peel,
prefix_ref_iterator_abort
.advance = prefix_ref_iterator_advance,
.peel = prefix_ref_iterator_peel,
.abort = prefix_ref_iterator_abort,
};
struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,

128
refs/packed-backend.c

@ -911,9 +911,9 @@ static int packed_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable packed_ref_iterator_vtable = {
packed_ref_iterator_advance,
packed_ref_iterator_peel,
packed_ref_iterator_abort
.advance = packed_ref_iterator_advance,
.peel = packed_ref_iterator_peel,
.abort = packed_ref_iterator_abort
};
static struct ref_iterator *packed_ref_iterator_begin(
@ -1592,106 +1592,36 @@ static int packed_pack_refs(struct ref_store *ref_store, unsigned int flags)
return 0;
}
static int packed_create_symref(struct ref_store *ref_store,
const char *refname, const char *target,
const char *logmsg)
{
BUG("packed reference store does not support symrefs");
}
static int packed_rename_ref(struct ref_store *ref_store,
const char *oldrefname, const char *newrefname,
const char *logmsg)
{
BUG("packed reference store does not support renaming references");
}
static int packed_copy_ref(struct ref_store *ref_store,
const char *oldrefname, const char *newrefname,
const char *logmsg)
{
BUG("packed reference store does not support copying references");
}
static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_store)
{
return empty_ref_iterator_begin();
}
static int packed_for_each_reflog_ent(struct ref_store *ref_store,
const char *refname,
each_reflog_ent_fn fn, void *cb_data)
{
BUG("packed reference store does not support reflogs");
return 0;
}
static int packed_for_each_reflog_ent_reverse(struct ref_store *ref_store,
const char *refname,
each_reflog_ent_fn fn,
void *cb_data)
{
BUG("packed reference store does not support reflogs");
return 0;
}
static int packed_reflog_exists(struct ref_store *ref_store,
const char *refname)
{
BUG("packed reference store does not support reflogs");
return 0;
}
static int packed_create_reflog(struct ref_store *ref_store,
const char *refname, struct strbuf *err)
{
BUG("packed reference store does not support reflogs");
}
static int packed_delete_reflog(struct ref_store *ref_store,
const char *refname)
{
BUG("packed reference store does not support reflogs");
return 0;
}
static int packed_reflog_expire(struct ref_store *ref_store,
const char *refname,
unsigned int flags,
reflog_expiry_prepare_fn prepare_fn,
reflog_expiry_should_prune_fn should_prune_fn,
reflog_expiry_cleanup_fn cleanup_fn,
void *policy_cb_data)
{
BUG("packed reference store does not support reflogs");
return 0;
}
struct ref_storage_be refs_be_packed = {
NULL,
"packed",
packed_ref_store_create,
packed_init_db,
packed_transaction_prepare,
packed_transaction_finish,
packed_transaction_abort,
packed_initial_transaction_commit,
packed_pack_refs,
packed_create_symref,
packed_delete_refs,
packed_rename_ref,
packed_copy_ref,
packed_ref_iterator_begin,
packed_read_raw_ref,
NULL,
packed_reflog_iterator_begin,
packed_for_each_reflog_ent,
packed_for_each_reflog_ent_reverse,
packed_reflog_exists,
packed_create_reflog,
packed_delete_reflog,
packed_reflog_expire
.next = NULL,
.name = "packed",
.init = packed_ref_store_create,
.init_db = packed_init_db,
.transaction_prepare = packed_transaction_prepare,
.transaction_finish = packed_transaction_finish,
.transaction_abort = packed_transaction_abort,
.initial_transaction_commit = packed_initial_transaction_commit,
.pack_refs = packed_pack_refs,
.create_symref = NULL,
.delete_refs = packed_delete_refs,
.rename_ref = NULL,
.copy_ref = NULL,
.iterator_begin = packed_ref_iterator_begin,
.read_raw_ref = packed_read_raw_ref,
.read_symbolic_ref = NULL,
.reflog_iterator_begin = packed_reflog_iterator_begin,
.for_each_reflog_ent = NULL,
.for_each_reflog_ent_reverse = NULL,
.reflog_exists = NULL,
.create_reflog = NULL,
.delete_reflog = NULL,
.reflog_expire = NULL,
};

6
refs/ref-cache.c

@ -456,9 +456,9 @@ static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
}
static struct ref_iterator_vtable cache_ref_iterator_vtable = {
cache_ref_iterator_advance,
cache_ref_iterator_peel,
cache_ref_iterator_abort
.advance = cache_ref_iterator_advance,
.peel = cache_ref_iterator_peel,
.abort = cache_ref_iterator_abort
};
struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,

Loading…
Cancel
Save