aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlberto Cortés <alberto@sourced.tech>2015-12-11 17:57:10 +0100
committerAlberto Cortés <alberto@sourced.tech>2015-12-11 17:57:10 +0100
commitc347e978b52212b5aa968a14d81c8fff47ab24d7 (patch)
treea558263e31121ff3c7defbf5ee3d38b7a18527c9
parent48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc (diff)
downloadgo-git-c347e978b52212b5aa968a14d81c8fff47ab24d7.tar.gz
Extra fixes for #7
-rw-r--r--blame/blame.go19
-rw-r--r--revlist/revlist.go6
2 files changed, 12 insertions, 13 deletions
diff --git a/blame/blame.go b/blame/blame.go
index 9475f2a..7256a7b 100644
--- a/blame/blame.go
+++ b/blame/blame.go
@@ -50,10 +50,9 @@ import (
// assigned the new commit as its origin. Modified lines also get
// this new commit. Untouched lines retain the old commit.
//
-// All this work is done in the assignOrigin function.
-//
-// This function holds all the internal relevant data in a blame
-// struct, that is not exported.
+// All this work is done in the assignOrigin function which holds all
+// the internal relevant data in a "blame" struct, that is not
+// exported.
//
// TODO: ways to improve the efficiency of this function:
//
@@ -64,9 +63,9 @@ import (
//
// TODO: ways to improve the function in general:
//
-// 1. Add memoization betweenn revlist and assign.
+// 1. Add memoization between revlist and assign.
//
-// 2. It is using much more memmory than needed, see the TODOs below.
+// 2. It is using much more memory than needed, see the TODOs below.
type Blame struct {
Repo string
@@ -126,8 +125,6 @@ func newLine(author, text string) *line {
func newLines(contents []string, commits []*git.Commit) ([]*line, error) {
if len(contents) != len(commits) {
- fmt.Println(len(contents))
- fmt.Println(len(commits))
return nil, errors.New("contents and commits have different length")
}
result := make([]*line, 0, len(contents))
@@ -149,7 +146,7 @@ type blame struct {
graph [][]*git.Commit // the graph of the lines in the file across all the revisions TODO: not all commits are needed, only the current rev and the prev
}
-// calculte the history of a file "path", from commit "from, sorted by commit date.
+// calculte the history of a file "path", starting from commit "from", sorted by commit date.
func (b *blame) fillRevs() error {
var err error
b.revs, err = revlist.NewRevs(b.repo, b.fRev, b.path)
@@ -231,8 +228,8 @@ func (b *blame) assignOrigin(c, p int) {
}
}
-// PrettyPrint prints the results of a Blame using git-blame's style.
-func (b *blame) PrettyPrint() string {
+// GoString prints the results of a Blame using git-blame's style.
+func (b *blame) GoString() string {
var buf bytes.Buffer
file, err := b.fRev.File(b.path)
diff --git a/revlist/revlist.go b/revlist/revlist.go
index 181e56d..bbc7e1f 100644
--- a/revlist/revlist.go
+++ b/revlist/revlist.go
@@ -175,10 +175,12 @@ func blobHash(path string, commit *git.Commit) (hash core.Hash, found bool) {
return file.Hash, true
}
+type contentsComparatorFn func(path string, a, b *git.Commit) (bool, error)
+
// Returns a new slice of commits, with duplicates removed. Expects a
// sorted commit list. Duplication is defined according to "comp". It
// will always keep the first commit of a series of duplicated commits.
-func removeComp(path string, cs []*git.Commit, comp func(string, *git.Commit, *git.Commit) (bool, error)) ([]*git.Commit, error) {
+func removeComp(path string, cs []*git.Commit, comp contentsComparatorFn) ([]*git.Commit, error) {
result := make([]*git.Commit, 0, len(cs))
if len(cs) == 0 {
return result, nil
@@ -196,7 +198,7 @@ func removeComp(path string, cs []*git.Commit, comp func(string, *git.Commit, *g
return result, nil
}
-// Equivalent commits are commits whos patch is the same.
+// Equivalent commits are commits whose patch is the same.
func equivalent(path string, a, b *git.Commit) (bool, error) {
numParentsA := a.NumParents()
numParentsB := b.NumParents()