diff options
author | Alberto Cortés <alberto@sourced.tech> | 2015-11-27 12:39:34 +0100 |
---|---|---|
committer | Alberto Cortés <alberto@sourced.tech> | 2015-12-04 09:48:41 +0100 |
commit | 48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc (patch) | |
tree | d96d8dfe4c8e4e18f19f2f50d67befc4d9a88d57 /common.go | |
parent | d643cea1e8a6d618b2eddfdbed086c7bdf208658 (diff) | |
download | go-git-48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc.tar.gz |
fix PR#7 comments
Diffstat (limited to 'common.go')
-rw-r--r-- | common.go | 41 |
1 files changed, 5 insertions, 36 deletions
@@ -1,15 +1,11 @@ package git -import ( - "bytes" - "strings" -) +import "strings" -// CountLines returns the number of lines in a string. -// The newline character is assumed to be '\n'. -// The empty string contains 0 lines. -// If the last line of the string doesn't end with a newline, it will -// still be considered a line. +// CountLines returns the number of lines in a string à la git, this is +// The newline character is assumed to be '\n'. The empty string +// contains 0 lines. If the last line of the string doesn't end with a +// newline, it will still be considered a line. func CountLines(s string) int { if s == "" { return 0 @@ -20,30 +16,3 @@ func CountLines(s string) int { } return nEol + 1 } - -// FindFile searches for a path in a commit. Returns the file and true if found. -// Returns nil and false if not found. -// TODO: should this be a method of git.Commit instead? -func FindFile(path string, commit *Commit) (file *File, found bool) { - tree := commit.Tree() - for file := range tree.Files() { - if file.Name == path { - return file, true - } - } - return nil, false -} - -// Data returns the contents of a file in a commit and true if found. -// Returns an empty string and false if the file is not found in the -// commit. -// TODO: should this be a method of git.Commit instead? -func Data(path string, commit *Commit) (contents string, found bool) { - file, found := FindFile(path, commit) - if !found { - return "", found - } - buf := new(bytes.Buffer) - buf.ReadFrom(file) - return buf.String(), found -} |