/** Display diff output with "--stat", "--numstat", or "--shortstat" */ static void diff_print_stats(git_diff *diff, struct opts *o) { git_diff_stats *stats; git_buf b = GIT_BUF_INIT_CONST(NULL, 0); git_diff_stats_format_t format = 0; check_lg2( git_diff_get_stats(&stats, diff), "generating stats for diff", NULL); if (o->output & OUTPUT_STAT) format |= GIT_DIFF_STATS_FULL; if (o->output & OUTPUT_SHORTSTAT) format |= GIT_DIFF_STATS_SHORT; if (o->output & OUTPUT_NUMSTAT) format |= GIT_DIFF_STATS_NUMBER; if (o->output & OUTPUT_SUMMARY) format |= GIT_DIFF_STATS_INCLUDE_SUMMARY; check_lg2( git_diff_stats_to_buf(&b, stats, format, 80), "formatting stats", NULL); fputs(b.ptr, stdout); git_buf_dispose(&b); git_diff_stats_free(stats); }
static void diff_stats_from_commit_oid( git_diff_stats **stats, const char *oidstr, bool rename) { git_oid oid; git_commit *commit; git_diff *diff; git_oid_fromstr(&oid, oidstr); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); cl_git_pass(git_diff__commit(&diff, _repo, commit, NULL)); if (rename) cl_git_pass(git_diff_find_similar(diff, NULL)); cl_git_pass(git_diff_get_stats(stats, diff)); git_diff_free(diff); git_commit_free(commit); }
PyObject * wrap_diff_stats(git_diff *diff) { git_diff_stats *stats; DiffStats *py_stats; int err; err = git_diff_get_stats(&stats, diff); if (err < 0) return Error_set(err); py_stats = PyObject_New(DiffStats, &DiffStatsType); if (!py_stats) { git_diff_stats_free(stats); return NULL; } py_stats->stats = stats; return (PyObject *) py_stats; }
std::shared_ptr<git_diff_stats> Diff::getStats() const { git_diff_stats* stats = nullptr; int error = git_diff_get_stats(&stats, get()); throw_on_error(error); return std::shared_ptr<git_diff_stats>(stats, git_diff_stats_free); }
int configctl_git_commit(char *path) { int rc; int git_status = -1; git_oid oid_blob; git_oid oid_tree; git_oid oid_commit; git_blob *blob; git_tree *tree_cmt; git_treebuilder *tree_bld; char *file; file = get_file(path); #if 0 // TODO: check if file is changed __debug("%s", file); git_diff_stats *stats; git_diff *diff; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; opts.pathspec.strings = &file; opts.pathspec.count = 1; rc = git_diff_index_to_workdir(&diff, repo, NULL, &opts); if(rc) goto error; int diff_num = git_diff_num_deltas(diff); __debug("%d", diff_num); git_diff_get_stats(&stats, diff); int x = git_diff_stats_files_changed(stats); __debug("%d", x); git_diff_free(diff); #endif rc = git_add(file); if (rc) goto error; rc = git_blob_create_fromworkdir(&oid_blob, repo, file); if (rc) goto error; rc = git_blob_lookup(&blob, repo, &oid_blob); if (rc) goto error; rc = git_treebuilder_new(&tree_bld, repo, NULL ); if (0 == rc) { rc = git_treebuilder_insert(NULL, tree_bld, file, &oid_blob, GIT_FILEMODE_BLOB); if (!rc) { rc = git_treebuilder_write(&oid_tree, tree_bld); if (!rc) { rc = git_tree_lookup(&tree_cmt, repo, &oid_tree); if (0 == rc) { git_commit *commit; commit = get_last_commit(); git_signature_now(&sign, sign_name, sign_email); rc = git_commit_create(&oid_commit, repo, "HEAD", sign, sign, NULL, commit_message, tree_cmt, 1, (const struct git_commit **) &commit); if (!rc) { git_status = 0; __debug("successful git commit"); } git_tree_free( tree_cmt ); git_commit_free(commit); git_signature_free(sign); } } } git_treebuilder_free(tree_bld); } git_blob_free( blob ); error: return git_status; }