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

Commit 199317f

Browse files
authored
Merge pull request #295 from ajnavarro/improvement/package-git-doc
improve git package documentation (fix #231)
2 parents 047a795 + e408162 commit 199317f

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

blame.go

+41-35
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,43 @@ import (
1313
"srcd.works/go-git.v4/utils/diff"
1414
)
1515

16+
// BlameResult represents the result of a Blame operation.
1617
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.
1923
Lines []*Line
2024
}
2125

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`.
5328
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+
//
5453
// TODO: ways to improve the efficiency of this function:
5554
// 1. Improve revlist
5655
// 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) {
8483
return nil, err
8584
}
8685

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.
8791
lines, err := newLines(finalLines, b.sliceGraph(len(b.graph)-1))
8892
if err != nil {
8993
return nil, err
@@ -98,8 +102,10 @@ func Blame(c *object.Commit, path string) (*BlameResult, error) {
98102

99103
// Line values represent the contents and author of a line in BlamedResult values.
100104
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
103109
}
104110

105111
func newLine(author, text string) *Line {

references.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ import (
1010
"github.com/sergi/go-diff/diffmatchpatch"
1111
)
1212

13-
// References returns a References for the file at "path", the commits are
14-
// sorted in commit order. It stops searching a branch for a file upon reaching
15-
// the commit were the file was created.
13+
// References returns a slice of Commits for the file at "path", starting from
14+
// the commit provided that contains the file from the provided path. The last
15+
// commit into the returned slice is the commit where the file was created.
16+
// If the provided commit does not contains the specified path, a nil slice is
17+
// returned. The commits are sorted in commit order, newer to older.
1618
//
1719
// Caveats:
20+
//
1821
// - Moves and copies are not currently supported.
22+
//
1923
// - Cherry-picks are not detected unless there are no commits between them and
20-
// therefore can appear repeated in the list.
21-
// (see git path-id for hints on how to fix this).
24+
// therefore can appear repeated in the list. (see git path-id for hints on how
25+
// to fix this).
2226
func References(c *object.Commit, path string) ([]*object.Commit, error) {
2327
var result []*object.Commit
2428
seen := make(map[plumbing.Hash]struct{}, 0)

remote.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
var NoErrAlreadyUpToDate = errors.New("already up-to-date")
2424

25-
// Remote represents a connection to a remote repository
25+
// Remote represents a connection to a remote repository.
2626
type Remote struct {
2727
c *config.RemoteConfig
2828
s storage.Storer
@@ -32,7 +32,7 @@ func newRemote(s storage.Storer, c *config.RemoteConfig) *Remote {
3232
return &Remote{s: s, c: c}
3333
}
3434

35-
// Config return the config
35+
// Config returns the RemoteConfig object used to instantiate this Remote.
3636
func (r *Remote) Config() *config.RemoteConfig {
3737
return r.c
3838
}

0 commit comments

Comments
 (0)