Skip to content

Commit

Permalink
survey: add commit-oid to large_item detail
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
  • Loading branch information
jeffhostetler committed May 15, 2024
1 parent 3d233a3 commit 819f5cb
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions builtin/survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,21 @@ static void incr_obj_hist_bin(struct obj_hist_bin *pbin,
struct large_item {
uint64_t size;
struct object_id oid;

/*
* For blobs and trees the name field is the pathname of the
* file or directory. Root trees will have a zero-length
* name. The name field is not currenly used for commits.
*/
struct strbuf *name;

/*
* For blobs and trees remember the transient commit from
* the treewalk so that we can say that this large item
* first appeared in this commit (relative to the treewalk
* order).
*/
struct object_id containing_commit_oid;
};

struct large_item_vec {
Expand Down Expand Up @@ -388,7 +402,8 @@ static void free_large_item_vec(struct large_item_vec *vec)
static void maybe_insert_large_item(struct large_item_vec *vec,
uint64_t size,
struct object_id *oid,
const char *name)
const char *name,
const struct object_id *containing_commit_oid)
{
struct strbuf *pbuf_temp;
size_t rest_len;
Expand Down Expand Up @@ -428,6 +443,7 @@ static void maybe_insert_large_item(struct large_item_vec *vec,
memset(&vec->items[k], 0, sizeof(struct large_item));
vec->items[k].size = size;
oidcpy(&vec->items[k].oid, oid);
oidcpy(&vec->items[k].containing_commit_oid, containing_commit_oid);

vec->items[k].name = pbuf_temp;

Expand Down Expand Up @@ -483,6 +499,14 @@ struct survey_stats_commits {

struct large_item_vec *vec_largest_by_nr_parents;
struct large_item_vec *vec_largest_by_size_bytes;

/*
* Transient OID of the commit currently being visited
* during the treewalk. We can use this to create the
* <ref>:<pathname> pair when a notable large file was
* created, for example.
*/
struct object_id treewalk_transient_commit_oid;
};

/*
Expand Down Expand Up @@ -694,15 +718,18 @@ static void traverse_commit_cb(struct commit *commit, void *data)
unsigned long object_length;
unsigned k;

printf("XXX: commit %s\n", oid_to_hex(&commit->object.oid));
if ((++survey_progress_total % 1000) == 0)
display_progress(survey_progress, survey_progress_total);

oidcpy(&psc->treewalk_transient_commit_oid, &commit->object.oid);

fill_in_base_object(&psc->base, &commit->object, OBJ_COMMIT, &object_length, NULL);

k = commit_list_count(commit->parents);

maybe_insert_large_item(psc->vec_largest_by_nr_parents, k, &commit->object.oid, NULL);
maybe_insert_large_item(psc->vec_largest_by_size_bytes, object_length, &commit->object.oid, NULL);
maybe_insert_large_item(psc->vec_largest_by_nr_parents, k, &commit->object.oid, NULL, null_oid());
maybe_insert_large_item(psc->vec_largest_by_size_bytes, object_length, &commit->object.oid, NULL, null_oid());

if (k >= PVEC_LEN)
k = PVEC_LEN - 1;
Expand All @@ -720,6 +747,8 @@ static void traverse_object_cb_tree(struct object *obj, const char *name)
int nr_entries;
int qb;

printf("YYY: tree %s\n", oid_to_hex(&obj->oid));

if (fill_in_base_object(&pst->base, obj, OBJ_TREE, &object_length, &disk_sizep))
return;

Expand All @@ -733,8 +762,12 @@ static void traverse_object_cb_tree(struct object *obj, const char *name)

pst->sum_entries += nr_entries;

maybe_insert_large_item(pst->vec_largest_by_nr_entries, nr_entries, &obj->oid, name);
maybe_insert_large_item(pst->vec_largest_by_size_bytes, object_length, &obj->oid, name);
maybe_insert_large_item(pst->vec_largest_by_nr_entries, nr_entries,
&obj->oid, name,
&survey_stats.commits.treewalk_transient_commit_oid);
maybe_insert_large_item(pst->vec_largest_by_size_bytes, object_length,
&obj->oid, name,
&survey_stats.commits.treewalk_transient_commit_oid);

qb = qbin(nr_entries);
incr_obj_hist_bin(&pst->entry_qbin[qb], object_length, disk_sizep);
Expand All @@ -747,7 +780,9 @@ static void traverse_object_cb_blob(struct object *obj, const char *name)

fill_in_base_object(&psb->base, obj, OBJ_BLOB, &object_length, NULL);

maybe_insert_large_item(psb->vec_largest_by_size_bytes, object_length, &obj->oid, name);
maybe_insert_large_item(psb->vec_largest_by_size_bytes, object_length,
&obj->oid, name,
&survey_stats.commits.treewalk_transient_commit_oid);
}

static void traverse_object_cb(struct object *obj, const char *name, void *data)
Expand Down Expand Up @@ -780,6 +815,7 @@ static void do_treewalk_reachable(struct ref_array *ref_array)
repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.tree_objects = 1;
rev_info.blob_objects = 1;
rev_info.tree_blobs_in_commit_order = 1;
load_rev_info(&rev_info, ref_array);
if (prepare_revision_walk(&rev_info))
die(_("revision walk setup failed"));
Expand Down Expand Up @@ -1035,6 +1071,9 @@ static void write_large_item_vec_json(struct json_writer *jw,
jw_object_string(jw, "oid", oid_to_hex(&pk->oid));
if (pk->name->len)
jw_object_string(jw, "name", pk->name->buf);
if (!is_null_oid(&pk->containing_commit_oid))
jw_object_string(jw, "commit_oid",
oid_to_hex(&pk->containing_commit_oid));
}
jw_end(jw);
}
Expand Down

0 comments on commit 819f5cb

Please sign in to comment.