ioptimization: only diff the tree when it is needed for the diffstat... - stagit-gemini - Stagit for gemini protocol Openbsd Err thinkerwim.openbsd.amsterdam 70 hgit clone git://thinkerwim.org/stagit-gemini.git URL:git://thinkerwim.org/stagit-gemini.git thinkerwim.org 70 1Log /git/stagit-gemini/log.gph thinkerwim.org 70 1Files /git/stagit-gemini/files.gph thinkerwim.org 70 1Refs /git/stagit-gemini/refs.gph thinkerwim.org 70 1README /git/stagit-gemini/file/README.gph thinkerwim.org 70 1LICENSE /git/stagit-gemini/file/LICENSE.gph thinkerwim.org 70 i--- Err thinkerwim.openbsd.amsterdam 70 1commit ec19160fa44ca478dd7e319eea8ee1ee1a0973e2 /git/stagit-gemini/commit/ec19160fa44ca478dd7e319eea8ee1ee1a0973e2.gph thinkerwim.org 70 1parent ab46ca27fc26888dc6e061c614d085114eb7b1ea /git/stagit-gemini/commit/ab46ca27fc26888dc6e061c614d085114eb7b1ea.gph thinkerwim.org 70 hAuthor: Hiltjo Posthuma URL:mailto:hiltjo@codemadness.org thinkerwim.org 70 iDate: Fri, 9 Feb 2018 16:13:57 +0100 Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 ioptimization: only diff the tree when it is needed for the diffstat... Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i... also clear all fields in the structure on failure. Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 iDiffstat: Err thinkerwim.openbsd.amsterdam 70 i M stagit-gopher.c | 42 ++++++++++++++++++------------- Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i1 file changed, 25 insertions(+), 17 deletions(-) Err thinkerwim.openbsd.amsterdam 70 i--- Err thinkerwim.openbsd.amsterdam 70 1diff --git a/stagit-gopher.c b/stagit-gopher.c /git/stagit-gemini/file/stagit-gopher.c.gph thinkerwim.org 70 i@@ -131,7 +131,7 @@ deltainfo_free(struct deltainfo *di) Err thinkerwim.openbsd.amsterdam 70 i if (!di) Err thinkerwim.openbsd.amsterdam 70 i return; Err thinkerwim.openbsd.amsterdam 70 i git_patch_free(di->patch); Err thinkerwim.openbsd.amsterdam 70 i- di->patch = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ memset(di, 0, sizeof(*di)); Err thinkerwim.openbsd.amsterdam 70 i free(di); Err thinkerwim.openbsd.amsterdam 70 i } Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i@@ -139,6 +139,7 @@ int Err thinkerwim.openbsd.amsterdam 70 i commitinfo_getstats(struct commitinfo *ci) Err thinkerwim.openbsd.amsterdam 70 i { Err thinkerwim.openbsd.amsterdam 70 i struct deltainfo *di; Err thinkerwim.openbsd.amsterdam 70 i+ git_diff_options opts; Err thinkerwim.openbsd.amsterdam 70 i const git_diff_delta *delta; Err thinkerwim.openbsd.amsterdam 70 i const git_diff_hunk *hunk; Err thinkerwim.openbsd.amsterdam 70 i const git_diff_line *line; Err thinkerwim.openbsd.amsterdam 70 i@@ -146,6 +147,20 @@ commitinfo_getstats(struct commitinfo *ci) Err thinkerwim.openbsd.amsterdam 70 i size_t ndeltas, nhunks, nhunklines; Err thinkerwim.openbsd.amsterdam 70 i size_t i, j, k; Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i+ if (git_tree_lookup(&(ci->commit_tree), repo, git_commit_tree_id(ci->commit))) Err thinkerwim.openbsd.amsterdam 70 i+ goto err; Err thinkerwim.openbsd.amsterdam 70 i+ if (!git_commit_parent(&(ci->parent), ci->commit, 0)) { Err thinkerwim.openbsd.amsterdam 70 i+ if (git_tree_lookup(&(ci->parent_tree), repo, git_commit_tree_id(ci->parent))) { Err thinkerwim.openbsd.amsterdam 70 i+ ci->parent = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ ci->parent_tree = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ } Err thinkerwim.openbsd.amsterdam 70 i+ } Err thinkerwim.openbsd.amsterdam 70 i+ Err thinkerwim.openbsd.amsterdam 70 i+ git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION); Err thinkerwim.openbsd.amsterdam 70 i+ opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH; Err thinkerwim.openbsd.amsterdam 70 i+ if (git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts)) Err thinkerwim.openbsd.amsterdam 70 i+ goto err; Err thinkerwim.openbsd.amsterdam 70 i+ Err thinkerwim.openbsd.amsterdam 70 i ndeltas = git_diff_num_deltas(ci->diff); Err thinkerwim.openbsd.amsterdam 70 i if (ndeltas && !(ci->deltas = calloc(ndeltas, sizeof(struct deltainfo *)))) Err thinkerwim.openbsd.amsterdam 70 i err(1, "calloc"); Err thinkerwim.openbsd.amsterdam 70 i@@ -187,6 +202,14 @@ commitinfo_getstats(struct commitinfo *ci) Err thinkerwim.openbsd.amsterdam 70 i return 0; Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i err: Err thinkerwim.openbsd.amsterdam 70 i+ git_diff_free(ci->diff); Err thinkerwim.openbsd.amsterdam 70 i+ ci->diff = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ git_tree_free(ci->commit_tree); Err thinkerwim.openbsd.amsterdam 70 i+ ci->commit_tree = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ git_tree_free(ci->parent_tree); Err thinkerwim.openbsd.amsterdam 70 i+ ci->parent_tree = NULL; Err thinkerwim.openbsd.amsterdam 70 i+ git_commit_free(ci->parent); Err thinkerwim.openbsd.amsterdam 70 i+ ci->parent = NULL; Err thinkerwim.openbsd.amsterdam 70 i if (ci->deltas) Err thinkerwim.openbsd.amsterdam 70 i for (i = 0; i < ci->ndeltas; i++) Err thinkerwim.openbsd.amsterdam 70 i deltainfo_free(ci->deltas[i]); Err thinkerwim.openbsd.amsterdam 70 i@@ -211,12 +234,12 @@ commitinfo_free(struct commitinfo *ci) Err thinkerwim.openbsd.amsterdam 70 i for (i = 0; i < ci->ndeltas; i++) Err thinkerwim.openbsd.amsterdam 70 i deltainfo_free(ci->deltas[i]); Err thinkerwim.openbsd.amsterdam 70 i free(ci->deltas); Err thinkerwim.openbsd.amsterdam 70 i- ci->deltas = NULL; Err thinkerwim.openbsd.amsterdam 70 i git_diff_free(ci->diff); Err thinkerwim.openbsd.amsterdam 70 i git_tree_free(ci->commit_tree); Err thinkerwim.openbsd.amsterdam 70 i git_tree_free(ci->parent_tree); Err thinkerwim.openbsd.amsterdam 70 i git_commit_free(ci->commit); Err thinkerwim.openbsd.amsterdam 70 i git_commit_free(ci->parent); Err thinkerwim.openbsd.amsterdam 70 i+ memset(ci, 0, sizeof(*ci)); Err thinkerwim.openbsd.amsterdam 70 i free(ci); Err thinkerwim.openbsd.amsterdam 70 i } Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i@@ -224,7 +247,6 @@ struct commitinfo * Err thinkerwim.openbsd.amsterdam 70 i commitinfo_getbyoid(const git_oid *id) Err thinkerwim.openbsd.amsterdam 70 i { Err thinkerwim.openbsd.amsterdam 70 i struct commitinfo *ci; Err thinkerwim.openbsd.amsterdam 70 i- git_diff_options opts; Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i if (!(ci = calloc(1, sizeof(struct commitinfo)))) Err thinkerwim.openbsd.amsterdam 70 i err(1, "calloc"); Err thinkerwim.openbsd.amsterdam 70 i@@ -241,20 +263,6 @@ commitinfo_getbyoid(const git_oid *id) Err thinkerwim.openbsd.amsterdam 70 i ci->summary = git_commit_summary(ci->commit); Err thinkerwim.openbsd.amsterdam 70 i ci->msg = git_commit_message(ci->commit); Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i- if (git_tree_lookup(&(ci->commit_tree), repo, git_commit_tree_id(ci->commit))) Err thinkerwim.openbsd.amsterdam 70 i- goto err; Err thinkerwim.openbsd.amsterdam 70 i- if (!git_commit_parent(&(ci->parent), ci->commit, 0)) { Err thinkerwim.openbsd.amsterdam 70 i- if (git_tree_lookup(&(ci->parent_tree), repo, git_commit_tree_id(ci->parent))) { Err thinkerwim.openbsd.amsterdam 70 i- ci->parent = NULL; Err thinkerwim.openbsd.amsterdam 70 i- ci->parent_tree = NULL; Err thinkerwim.openbsd.amsterdam 70 i- } Err thinkerwim.openbsd.amsterdam 70 i- } Err thinkerwim.openbsd.amsterdam 70 i- Err thinkerwim.openbsd.amsterdam 70 i- git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION); Err thinkerwim.openbsd.amsterdam 70 i- opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH; Err thinkerwim.openbsd.amsterdam 70 i- if (git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts)) Err thinkerwim.openbsd.amsterdam 70 i- goto err; Err thinkerwim.openbsd.amsterdam 70 i- Err thinkerwim.openbsd.amsterdam 70 i return ci; Err thinkerwim.openbsd.amsterdam 70 i Err thinkerwim.openbsd.amsterdam 70 i err: Err thinkerwim.openbsd.amsterdam 70 .