Skip to content

Commit 49402cc

Browse files
committed
blame: add commit summary information
1 parent 5378b80 commit 49402cc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/git2/blame.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ typedef struct git_blame_hunk {
204204
*/
205205
git_signature *orig_committer;
206206

207+
/*
208+
* The summary of the commit.
209+
*/
210+
const char *summary;
211+
207212
/**
208213
* The 1 iff the hunk has been tracked to a boundary commit (the root,
209214
* or the commit specified in git_blame_options.oldest_commit)

src/libgit2/blame.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ static git_blame_hunk *new_hunk(
8080

8181
static void free_hunk(git_blame_hunk *hunk)
8282
{
83-
git__free((void*)hunk->orig_path);
83+
git__free((char *)hunk->orig_path);
84+
git__free((char *)hunk->summary);
8485
git_signature_free(hunk->final_signature);
8586
git_signature_free(hunk->final_committer);
8687
git_signature_free(hunk->orig_signature);
@@ -107,7 +108,8 @@ static git_blame_hunk *dup_hunk(git_blame_hunk *hunk, git_blame *blame)
107108
if (git_signature_dup(&newhunk->final_signature, hunk->final_signature) < 0 ||
108109
git_signature_dup(&newhunk->final_committer, hunk->final_committer) < 0 ||
109110
git_signature_dup(&newhunk->orig_signature, hunk->orig_signature) < 0 ||
110-
git_signature_dup(&newhunk->orig_committer, hunk->orig_committer) < 0) {
111+
git_signature_dup(&newhunk->orig_committer, hunk->orig_committer) < 0 ||
112+
(newhunk->summary = git__strdup(hunk->summary)) == NULL) {
111113
free_hunk(newhunk);
112114
return NULL;
113115
}
@@ -338,6 +340,7 @@ static int index_blob_lines(git_blame *blame)
338340

339341
static git_blame_hunk *hunk_from_entry(git_blame__entry *e, git_blame *blame)
340342
{
343+
const char *summary;
341344
git_blame_hunk *h = new_hunk(
342345
e->lno+1, e->num_lines, e->s_lno+1, e->suspect->path,
343346
blame);
@@ -353,7 +356,9 @@ static git_blame_hunk *hunk_from_entry(git_blame__entry *e, git_blame *blame)
353356
git_commit_committer_with_mailmap(
354357
&h->final_committer, e->suspect->commit, blame->mailmap) < 0 ||
355358
git_signature_dup(&h->orig_signature, h->final_signature) < 0 ||
356-
git_signature_dup(&h->orig_committer, h->final_committer) < 0) {
359+
git_signature_dup(&h->orig_committer, h->final_committer) < 0 ||
360+
(summary = git_commit_summary(e->suspect->commit)) == NULL ||
361+
(h->summary = git__strdup(summary)) == NULL) {
357362
free_hunk(h);
358363
return NULL;
359364
}

0 commit comments

Comments
 (0)