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

Commit 07218eb

Browse files
authored
blame: make line and its members public so they can be actually used (#213)
1 parent 8d553bc commit 07218eb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

blame.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
type BlameResult struct {
1717
Path string
1818
Rev plumbing.Hash
19-
Lines []*line
19+
Lines []*Line
2020
}
2121

2222
// Blame returns the last commit that modified each line of a file in a
@@ -100,23 +100,24 @@ func Blame(c *object.Commit, path string) (*BlameResult, error) {
100100
}, nil
101101
}
102102

103-
type line struct {
104-
author string
105-
text string
103+
// Line values represent the contents and author of a line in BlamedResult values.
104+
type Line struct {
105+
Author string // email address of the author of the line.
106+
Text string // original text of the line.
106107
}
107108

108-
func newLine(author, text string) *line {
109-
return &line{
110-
author: author,
111-
text: text,
109+
func newLine(author, text string) *Line {
110+
return &Line{
111+
Author: author,
112+
Text: text,
112113
}
113114
}
114115

115-
func newLines(contents []string, commits []*object.Commit) ([]*line, error) {
116+
func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
116117
if len(contents) != len(commits) {
117118
return nil, errors.New("contents and commits have different length")
118119
}
119-
result := make([]*line, 0, len(contents))
120+
result := make([]*Line, 0, len(contents))
120121
for i := range contents {
121122
l := newLine(commits[i].Author.Email, contents[i])
122123
result = append(result, l)

blame_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameRe
4646
c.Assert(len(t.blames), Equals, len(lines), Commentf(
4747
"repo=%s, path=%s, rev=%s: the number of lines in the file and the number of expected blames differ (len(blames)=%d, len(lines)=%d)\nblames=%#q\nlines=%#q", t.repo, t.path, t.rev, len(t.blames), len(lines), t.blames, lines))
4848

49-
blamedLines := make([]*line, 0, len(t.blames))
49+
blamedLines := make([]*Line, 0, len(t.blames))
5050
for i := range t.blames {
5151
commit, err := r.Commit(plumbing.NewHash(t.blames[i]))
5252
c.Assert(err, IsNil)
53-
l := &line{
54-
author: commit.Author.Email,
55-
text: lines[i],
53+
l := &Line{
54+
Author: commit.Author.Email,
55+
Text: lines[i],
5656
}
5757
blamedLines = append(blamedLines, l)
5858
}

0 commit comments

Comments
 (0)