summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-06-12 13:29:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-12 18:20:53 (GMT)
commitef5b83f2cfe11c2feb98b962881e9a8e6281e3ff (patch)
tree30fb99e6048b58838878d5b9c274ec487652ad2c /commit-graph.c
parentc9905beade13efff6be9c15ebe03d07fe5278ccc (diff)
downloadgit-ef5b83f2cfe11c2feb98b962881e9a8e6281e3ff.zip
git-ef5b83f2cfe11c2feb98b962881e9a8e6281e3ff.tar.gz
git-ef5b83f2cfe11c2feb98b962881e9a8e6281e3ff.tar.bz2
commit-graph: extract fill_oids_from_packs()
The write_commit_graph() method is too complex, so we are extracting helper functions one by one. This extracts fill_oids_from_packs() that reads the given pack-file list and fills the oid list in the context. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 6d7e83c..02e5f8c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -867,6 +867,51 @@ int write_commit_graph_reachable(const char *obj_dir, unsigned int flags)
return result;
}
+static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
+ struct string_list *pack_indexes)
+{
+ uint32_t i;
+ struct strbuf progress_title = STRBUF_INIT;
+ struct strbuf packname = STRBUF_INIT;
+ int dirlen;
+
+ strbuf_addf(&packname, "%s/pack/", ctx->obj_dir);
+ dirlen = packname.len;
+ if (ctx->report_progress) {
+ strbuf_addf(&progress_title,
+ Q_("Finding commits for commit graph in %d pack",
+ "Finding commits for commit graph in %d packs",
+ pack_indexes->nr),
+ pack_indexes->nr);
+ ctx->progress = start_delayed_progress(progress_title.buf, 0);
+ ctx->progress_done = 0;
+ }
+ for (i = 0; i < pack_indexes->nr; i++) {
+ struct packed_git *p;
+ strbuf_setlen(&packname, dirlen);
+ strbuf_addstr(&packname, pack_indexes->items[i].string);
+ p = add_packed_git(packname.buf, packname.len, 1);
+ if (!p) {
+ error(_("error adding pack %s"), packname.buf);
+ return -1;
+ }
+ if (open_pack_index(p)) {
+ error(_("error opening index for %s"), packname.buf);
+ return -1;
+ }
+ for_each_object_in_pack(p, add_packed_commits, ctx,
+ FOR_EACH_OBJECT_PACK_ORDER);
+ close_pack(p);
+ free(p);
+ }
+
+ stop_progress(&ctx->progress);
+ strbuf_reset(&progress_title);
+ strbuf_release(&packname);
+
+ return 0;
+}
+
int write_commit_graph(const char *obj_dir,
struct string_list *pack_indexes,
struct string_list *commit_hex,
@@ -916,42 +961,8 @@ int write_commit_graph(const char *obj_dir,
}
if (pack_indexes) {
- struct strbuf packname = STRBUF_INIT;
- int dirlen;
- strbuf_addf(&packname, "%s/pack/", obj_dir);
- dirlen = packname.len;
- if (ctx->report_progress) {
- strbuf_addf(&progress_title,
- Q_("Finding commits for commit graph in %d pack",
- "Finding commits for commit graph in %d packs",
- pack_indexes->nr),
- pack_indexes->nr);
- ctx->progress = start_delayed_progress(progress_title.buf, 0);
- ctx->progress_done = 0;
- }
- for (i = 0; i < pack_indexes->nr; i++) {
- struct packed_git *p;
- strbuf_setlen(&packname, dirlen);
- strbuf_addstr(&packname, pack_indexes->items[i].string);
- p = add_packed_git(packname.buf, packname.len, 1);
- if (!p) {
- error(_("error adding pack %s"), packname.buf);
- res = -1;
- goto cleanup;
- }
- if (open_pack_index(p)) {
- error(_("error opening index for %s"), packname.buf);
- res = -1;
- goto cleanup;
- }
- for_each_object_in_pack(p, add_packed_commits, ctx,
- FOR_EACH_OBJECT_PACK_ORDER);
- close_pack(p);
- free(p);
- }
- stop_progress(&ctx->progress);
- strbuf_reset(&progress_title);
- strbuf_release(&packname);
+ if ((res = fill_oids_from_packs(ctx, pack_indexes)))
+ goto cleanup;
}
if (commit_hex) {