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