Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 3293140

Browse files
authored
Merge pull request #795 from shanedasilva/add_commit_hash_to_blame_result
Add commit hash to blame result
2 parents 0c2618b + a3cf123 commit 3293140

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

blame.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ type Line struct {
109109
Text string
110110
// Date is when the original text of the line was introduced
111111
Date time.Time
112+
// Hash is the commit hash that introduced the original line
113+
Hash plumbing.Hash
112114
}
113115

114-
func newLine(author, text string, date time.Time) *Line {
116+
func newLine(author, text string, date time.Time, hash plumbing.Hash) *Line {
115117
return &Line{
116118
Author: author,
117119
Text: text,
120+
Hash: hash,
118121
Date: date,
119122
}
120123
}
@@ -125,7 +128,7 @@ func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
125128
}
126129
result := make([]*Line, 0, len(contents))
127130
for i := range contents {
128-
l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When)
131+
l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When, commits[i].Hash)
129132
result = append(result, l)
130133
}
131134
return result, nil

blame_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (s *BlameSuite) TestBlame(c *C) {
3232
obt, err := Blame(commit, t.path)
3333
c.Assert(err, IsNil)
3434
c.Assert(obt, DeepEquals, exp)
35+
36+
for i, l := range obt.Lines {
37+
c.Assert(l.Hash.String(), Equals, t.blames[i])
38+
}
3539
}
3640
}
3741

@@ -54,6 +58,7 @@ func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameRe
5458
Author: commit.Author.Email,
5559
Text: lines[i],
5660
Date: commit.Author.When,
61+
Hash: commit.Hash,
5762
}
5863
blamedLines = append(blamedLines, l)
5964
}

0 commit comments

Comments
 (0)