Commit b6f60a4d by Ben Straub

Clean up ported code

parent 77db6ff5
......@@ -260,6 +260,8 @@ static int load_blob(git_blame *blame)
{
int error;
if (blame->final_blob) return 0;
error = git_commit_lookup(&blame->final, blame->repository, &blame->options.newest_commit);
if (error < 0)
goto cleanup;
......@@ -276,20 +278,13 @@ static int blame_internal(git_blame *blame)
{
int error;
git_blame__entry *ent = NULL;
git_blob *blob = NULL;
git_blame__origin *o;
if ((error = git_commit_lookup(&blame->final, blame->repository,
&blame->options.newest_commit))
< 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)
if ((error = load_blob(blame)) < 0 ||
(error = git_blame__get_origin(&o, blame, blame->final, blame->path)) < 0)
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->num_lines = index_blob_lines(blame);
......@@ -303,8 +298,7 @@ static int blame_internal(git_blame *blame)
blame->ent = ent;
blame->path = blame->path;
assign_blame(blame, blame->options.flags);
coalesce(blame);
git_blame__like_git(blame, blame->options.flags);
cleanup:
for (ent = blame->ent; ent; ) {
......@@ -312,12 +306,10 @@ cleanup:
git_vector_insert(&blame->hunks, hunk_from_entry(ent));
origin_decref(ent->suspect);
git__free(ent);
git_blame__free_entry(ent);
ent = e;
}
git_blob_free(blob);
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__
#define INCLUDE_blame_git__
#include "git2.h"
#include "blame.h"
#include "xdiff/xinclude.h"
int get_origin(git_blame__origin **out, git_blame *sb, git_commit *commit, const char *path);
int make_origin(git_blame__origin **out, git_commit *commit, const char *path);
git_blame__origin *origin_incref(git_blame__origin *o);
void origin_decref(git_blame__origin *o);
void assign_blame(git_blame *sb, uint32_t flags);
void coalesce(git_blame *sb);
int git_blame__get_origin(
git_blame__origin **out,
git_blame *sb,
git_commit *commit,
const char *path);
void git_blame__free_entry(git_blame__entry *ent);
void git_blame__like_git(git_blame *sb, uint32_t flags);
#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