Commit b6f60a4d by Ben Straub

Clean up ported code

parent 77db6ff5
...@@ -260,6 +260,8 @@ static int load_blob(git_blame *blame) ...@@ -260,6 +260,8 @@ static int load_blob(git_blame *blame)
{ {
int error; int error;
if (blame->final_blob) return 0;
error = git_commit_lookup(&blame->final, blame->repository, &blame->options.newest_commit); error = git_commit_lookup(&blame->final, blame->repository, &blame->options.newest_commit);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
...@@ -276,20 +278,13 @@ static int blame_internal(git_blame *blame) ...@@ -276,20 +278,13 @@ static int blame_internal(git_blame *blame)
{ {
int error; int error;
git_blame__entry *ent = NULL; git_blame__entry *ent = NULL;
git_blob *blob = NULL;
git_blame__origin *o; git_blame__origin *o;
if ((error = git_commit_lookup(&blame->final, blame->repository, if ((error = load_blob(blame)) < 0 ||
&blame->options.newest_commit)) (error = git_blame__get_origin(&o, blame, blame->final, blame->path)) < 0)
< 0 ||
(error = git_object_lookup_bypath((git_object**)&blob, (git_object*)blame->final,
blame->path, GIT_OBJ_BLOB))
< 0)
goto cleanup;
blame->final_buf = git_blob_rawcontent(blob);
blame->final_buf_size = git_blob_rawsize(blob);
if ((error = get_origin(&o, blame, blame->final, blame->path)) < 0)
goto cleanup; goto cleanup;
blame->final_buf = git_blob_rawcontent(blame->final_blob);
blame->final_buf_size = git_blob_rawsize(blame->final_blob);
ent = git__calloc(1, sizeof(git_blame__entry)); ent = git__calloc(1, sizeof(git_blame__entry));
ent->num_lines = index_blob_lines(blame); ent->num_lines = index_blob_lines(blame);
...@@ -303,8 +298,7 @@ static int blame_internal(git_blame *blame) ...@@ -303,8 +298,7 @@ static int blame_internal(git_blame *blame)
blame->ent = ent; blame->ent = ent;
blame->path = blame->path; blame->path = blame->path;
assign_blame(blame, blame->options.flags); git_blame__like_git(blame, blame->options.flags);
coalesce(blame);
cleanup: cleanup:
for (ent = blame->ent; ent; ) { for (ent = blame->ent; ent; ) {
...@@ -312,12 +306,10 @@ cleanup: ...@@ -312,12 +306,10 @@ cleanup:
git_vector_insert(&blame->hunks, hunk_from_entry(ent)); git_vector_insert(&blame->hunks, hunk_from_entry(ent));
origin_decref(ent->suspect); git_blame__free_entry(ent);
git__free(ent);
ent = e; ent = e;
} }
git_blob_free(blob);
return error; return error;
} }
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_blame_git__ #ifndef INCLUDE_blame_git__
#define INCLUDE_blame_git__ #define INCLUDE_blame_git__
#include "git2.h"
#include "blame.h" #include "blame.h"
#include "xdiff/xinclude.h" #include "xdiff/xinclude.h"
int get_origin(git_blame__origin **out, git_blame *sb, git_commit *commit, const char *path); int git_blame__get_origin(
int make_origin(git_blame__origin **out, git_commit *commit, const char *path); git_blame__origin **out,
git_blame__origin *origin_incref(git_blame__origin *o); git_blame *sb,
void origin_decref(git_blame__origin *o); git_commit *commit,
void assign_blame(git_blame *sb, uint32_t flags); const char *path);
void coalesce(git_blame *sb); void git_blame__free_entry(git_blame__entry *ent);
void git_blame__like_git(git_blame *sb, uint32_t flags);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment