Commit 2988f736 by lhchavez

Review feedback

* Added the `PenaltyBreakAssignment: 1000` clang-format option to avoid
  breaking statements around the assignment operator.
* Avoided using the dot initializer syntax.
* Avoided casting allocations.
* Also avoided casting `void *`.
parent 83862c83
...@@ -69,8 +69,7 @@ static void packed_commit_free(struct packed_commit *p) ...@@ -69,8 +69,7 @@ static void packed_commit_free(struct packed_commit *p)
static struct packed_commit *packed_commit_new(git_commit *commit) static struct packed_commit *packed_commit_new(git_commit *commit)
{ {
unsigned int i, parentcount = git_commit_parentcount(commit); unsigned int i, parentcount = git_commit_parentcount(commit);
struct packed_commit *p struct packed_commit *p = git__calloc(1, sizeof(struct packed_commit));
= (struct packed_commit *)git__calloc(1, sizeof(struct packed_commit));
if (!p) if (!p)
goto cleanup; goto cleanup;
...@@ -436,8 +435,8 @@ static int git_commit_graph_entry_get_byindex( ...@@ -436,8 +435,8 @@ static int git_commit_graph_entry_get_byindex(
commit_data = file->commit_data + pos * (GIT_OID_RAWSZ + 4 * sizeof(uint32_t)); commit_data = file->commit_data + pos * (GIT_OID_RAWSZ + 4 * sizeof(uint32_t));
git_oid_cpy(&e->tree_oid, (const git_oid *)commit_data); git_oid_cpy(&e->tree_oid, (const git_oid *)commit_data);
e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ))); e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ)));
e->parent_indices[1] e->parent_indices[1] = ntohl(
= ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + sizeof(uint32_t)))); *((uint32_t *)(commit_data + GIT_OID_RAWSZ + sizeof(uint32_t))));
e->parent_count = (e->parent_indices[0] != GIT_COMMIT_GRAPH_MISSING_PARENT) e->parent_count = (e->parent_indices[0] != GIT_COMMIT_GRAPH_MISSING_PARENT)
+ (e->parent_indices[1] != GIT_COMMIT_GRAPH_MISSING_PARENT); + (e->parent_indices[1] != GIT_COMMIT_GRAPH_MISSING_PARENT);
e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 2 * sizeof(uint32_t)))); e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 2 * sizeof(uint32_t))));
...@@ -700,11 +699,9 @@ int git_commit_graph_writer_add_index_file( ...@@ -700,11 +699,9 @@ int git_commit_graph_writer_add_index_file(
{ {
int error; int error;
struct git_pack_file *p = NULL; struct git_pack_file *p = NULL;
struct object_entry_cb_state state = { struct object_entry_cb_state state = {0};
.repo = repo, state.repo = repo;
.db = NULL, state.commits = &w->commits;
.commits = &w->commits,
};
error = git_repository_odb(&state.db, repo); error = git_repository_odb(&state.db, repo);
if (error < 0) if (error < 0)
...@@ -941,8 +938,7 @@ struct commit_graph_write_hash_context { ...@@ -941,8 +938,7 @@ struct commit_graph_write_hash_context {
static int commit_graph_write_hash(const char *buf, size_t size, void *data) static int commit_graph_write_hash(const char *buf, size_t size, void *data)
{ {
struct commit_graph_write_hash_context *ctx struct commit_graph_write_hash_context *ctx = data;
= (struct commit_graph_write_hash_context *)data;
int error; int error;
error = git_hash_update(ctx->ctx, buf, size); error = git_hash_update(ctx->ctx, buf, size);
...@@ -963,26 +959,25 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v ...@@ -963,26 +959,25 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v
int error = 0; int error = 0;
size_t i; size_t i;
struct packed_commit *packed_commit; struct packed_commit *packed_commit;
struct git_commit_graph_header hdr = { struct git_commit_graph_header hdr = {0};
.signature = htonl(COMMIT_GRAPH_SIGNATURE),
.version = COMMIT_GRAPH_VERSION,
.object_id_version = COMMIT_GRAPH_OBJECT_ID_VERSION,
.chunks = 0,
.base_graph_files = 0,
};
uint32_t oid_fanout_count; uint32_t oid_fanout_count;
uint32_t extra_edge_list_count; uint32_t extra_edge_list_count;
uint32_t oid_fanout[256]; uint32_t oid_fanout[256];
off64_t offset; off64_t offset;
git_buf oid_lookup = GIT_BUF_INIT, git_buf oid_lookup = GIT_BUF_INIT, commit_data = GIT_BUF_INIT,
commit_data = GIT_BUF_INIT, extra_edge_list = GIT_BUF_INIT; extra_edge_list = GIT_BUF_INIT;
git_oid cgraph_checksum = {{0}}; git_oid cgraph_checksum = {{0}};
git_hash_ctx ctx; git_hash_ctx ctx;
struct commit_graph_write_hash_context hash_cb_data = { struct commit_graph_write_hash_context hash_cb_data = {0};
.write_cb = write_cb,
.cb_data = cb_data, hdr.signature = htonl(COMMIT_GRAPH_SIGNATURE);
.ctx = &ctx, hdr.version = COMMIT_GRAPH_VERSION;
}; hdr.object_id_version = COMMIT_GRAPH_OBJECT_ID_VERSION;
hdr.chunks = 0;
hdr.base_graph_files = 0;
hash_cb_data.write_cb = write_cb;
hash_cb_data.cb_data = cb_data;
hash_cb_data.ctx = &ctx;
error = git_hash_ctx_init(&ctx); error = git_hash_ctx_init(&ctx);
if (error < 0) if (error < 0)
...@@ -1024,8 +1019,8 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v ...@@ -1024,8 +1019,8 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v
uint32_t word; uint32_t word;
unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents); unsigned int parentcount = (unsigned int)git_array_size(packed_commit->parents);
error error = git_buf_put(
= git_buf_put(&commit_data, &commit_data,
(const char *)&packed_commit->tree_oid, (const char *)&packed_commit->tree_oid,
sizeof(git_oid)); sizeof(git_oid));
if (error < 0) if (error < 0)
...@@ -1055,8 +1050,8 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v ...@@ -1055,8 +1050,8 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v
word = htonl((uint32_t)( word = htonl((uint32_t)(
*git_array_get(packed_commit->parent_indices, parent_i) *git_array_get(packed_commit->parent_indices, parent_i)
| (parent_i + 1 == parentcount ? 0x80000000u : 0))); | (parent_i + 1 == parentcount ? 0x80000000u : 0)));
error error = git_buf_put(
= git_buf_put(&extra_edge_list, &extra_edge_list,
(const char *)&word, (const char *)&word,
sizeof(word)); sizeof(word));
if (error < 0) if (error < 0)
...@@ -1122,10 +1117,7 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v ...@@ -1122,10 +1117,7 @@ commit_graph_write(git_commit_graph_writer *w, commit_graph_write_cb write_cb, v
error = write_cb(git_buf_cstr(&commit_data), git_buf_len(&commit_data), cb_data); error = write_cb(git_buf_cstr(&commit_data), git_buf_len(&commit_data), cb_data);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
error error = write_cb(git_buf_cstr(&extra_edge_list), git_buf_len(&extra_edge_list), cb_data);
= write_cb(git_buf_cstr(&extra_edge_list),
git_buf_len(&extra_edge_list),
cb_data);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
...@@ -1160,6 +1152,7 @@ int git_commit_graph_writer_commit( ...@@ -1160,6 +1152,7 @@ int git_commit_graph_writer_commit(
git_buf commit_graph_path = GIT_BUF_INIT; git_buf commit_graph_path = GIT_BUF_INIT;
git_filebuf output = GIT_FILEBUF_INIT; git_filebuf output = GIT_FILEBUF_INIT;
/* TODO: support options. */
GIT_UNUSED(opts); GIT_UNUSED(opts);
error = git_buf_joinpath( error = git_buf_joinpath(
...@@ -1188,6 +1181,7 @@ int git_commit_graph_writer_dump( ...@@ -1188,6 +1181,7 @@ int git_commit_graph_writer_dump(
git_commit_graph_writer *w, git_commit_graph_writer *w,
git_commit_graph_writer_options *opts) git_commit_graph_writer_options *opts)
{ {
/* TODO: support options. */
GIT_UNUSED(opts); GIT_UNUSED(opts);
return commit_graph_write(w, commit_graph_write_buf, cgraph); return commit_graph_write(w, commit_graph_write_buf, cgraph);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment