@@ -13,44 +13,43 @@ import (
13
13
"srcd.works/go-git.v4/utils/diff"
14
14
)
15
15
16
+ // BlameResult represents the result of a Blame operation.
16
17
type BlameResult struct {
17
- Path string
18
- Rev plumbing.Hash
18
+ // Path is the path of the File that we're blaming.
19
+ Path string
20
+ // Rev (Revision) is the hash of the specified Commit used to generate this result.
21
+ Rev plumbing.Hash
22
+ // Lines contains every line with its authorship.
19
23
Lines []* Line
20
24
}
21
25
22
- // Blame returns the last commit that modified each line of a file in a
23
- // repository.
24
- //
25
- // The file to blame is identified by the input arguments: repo, commit and path.
26
- // The output is a slice of commits, one for each line in the file.
27
- //
28
- // Blaming a file is a two step process:
29
- //
30
- // 1. Create a linear history of the commits affecting a file. We use
31
- // revlist.New for that.
32
- //
33
- // 2. Then build a graph with a node for every line in every file in
34
- // the history of the file.
35
- //
36
- // Each node (line) holds the commit where it was introduced or
37
- // last modified. To achieve that we use the FORWARD algorithm
38
- // described in Zimmermann, et al. "Mining Version Archives for
39
- // Co-changed Lines", in proceedings of the Mining Software
40
- // Repositories workshop, Shanghai, May 22-23, 2006.
41
- //
42
- // Each node is assigned a commit: Start by the nodes in the first
43
- // commit. Assign that commit as the creator of all its lines.
44
- //
45
- // Then jump to the nodes in the next commit, and calculate the diff
46
- // between the two files. Newly created lines get
47
- // assigned the new commit as its origin. Modified lines also get
48
- // this new commit. Untouched lines retain the old commit.
49
- //
50
- // All this work is done in the assignOrigin function which holds all
51
- // the internal relevant data in a "blame" struct, that is not
52
- // exported.
26
+ // Blame returns a BlameResult with the information about the last author of
27
+ // each line from file `path` at commit `c`.
53
28
func Blame (c * object.Commit , path string ) (* BlameResult , error ) {
29
+ // The file to blame is identified by the input arguments:
30
+ // commit and path. commit is a Commit object obtained from a Repository. Path
31
+ // represents a path to a specific file contained into the repository.
32
+ //
33
+ // Blaming a file is a two step process:
34
+ //
35
+ // 1. Create a linear history of the commits affecting a file. We use
36
+ // revlist.New for that.
37
+ //
38
+ // 2. Then build a graph with a node for every line in every file in
39
+ // the history of the file.
40
+ //
41
+ // Each node is assigned a commit: Start by the nodes in the first
42
+ // commit. Assign that commit as the creator of all its lines.
43
+ //
44
+ // Then jump to the nodes in the next commit, and calculate the diff
45
+ // between the two files. Newly created lines get
46
+ // assigned the new commit as its origin. Modified lines also get
47
+ // this new commit. Untouched lines retain the old commit.
48
+ //
49
+ // All this work is done in the assignOrigin function which holds all
50
+ // the internal relevant data in a "blame" struct, that is not
51
+ // exported.
52
+ //
54
53
// TODO: ways to improve the efficiency of this function:
55
54
// 1. Improve revlist
56
55
// 2. Improve how to traverse the history (example a backward traversal will
@@ -84,6 +83,11 @@ func Blame(c *object.Commit, path string) (*BlameResult, error) {
84
83
return nil , err
85
84
}
86
85
86
+ // Each node (line) holds the commit where it was introduced or
87
+ // last modified. To achieve that we use the FORWARD algorithm
88
+ // described in Zimmermann, et al. "Mining Version Archives for
89
+ // Co-changed Lines", in proceedings of the Mining Software
90
+ // Repositories workshop, Shanghai, May 22-23, 2006.
87
91
lines , err := newLines (finalLines , b .sliceGraph (len (b .graph )- 1 ))
88
92
if err != nil {
89
93
return nil , err
@@ -98,8 +102,10 @@ func Blame(c *object.Commit, path string) (*BlameResult, error) {
98
102
99
103
// Line values represent the contents and author of a line in BlamedResult values.
100
104
type Line struct {
101
- Author string // email address of the author of the line.
102
- Text string // original text of the line.
105
+ // Author is the email address of the last author that modified the line.
106
+ Author string
107
+ // Text is the original text of the line.
108
+ Text string
103
109
}
104
110
105
111
func newLine (author , text string ) * Line {
0 commit comments