aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/commit_walker_path.go (renamed from plumbing/object/commit_walker_file.go)36
-rw-r--r--plumbing/object/object.go18
2 files changed, 34 insertions, 20 deletions
diff --git a/plumbing/object/commit_walker_file.go b/plumbing/object/commit_walker_path.go
index b73e4ce..6a49fd1 100644
--- a/plumbing/object/commit_walker_file.go
+++ b/plumbing/object/commit_walker_path.go
@@ -8,27 +8,39 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)
-type commitFileIter struct {
- fileName string
+type commitPathIter struct {
+ pathFilter func(string) bool
sourceIter CommitIter
currentCommit *Commit
checkParent bool
}
-// NewCommitFileIterFromIter returns a commit iterator which performs diffTree between
+// NewCommitPathIterFromIter returns a commit iterator which performs diffTree between
// successive trees returned from the commit iterator from the argument. The purpose of this is
// to find the commits that explain how the files that match the path came to be.
// If checkParent is true then the function double checks if potential parent (next commit in a path)
// is one of the parents in the tree (it's used by `git log --all`).
-func NewCommitFileIterFromIter(fileName string, commitIter CommitIter, checkParent bool) CommitIter {
- iterator := new(commitFileIter)
+// pathFilter is a function that takes path of file as argument and returns true if we want it
+func NewCommitPathIterFromIter(pathFilter func(string) bool, commitIter CommitIter, checkParent bool) CommitIter {
+ iterator := new(commitPathIter)
iterator.sourceIter = commitIter
- iterator.fileName = fileName
+ iterator.pathFilter = pathFilter
iterator.checkParent = checkParent
return iterator
}
-func (c *commitFileIter) Next() (*Commit, error) {
+// this function is kept for compatibilty, can be replaced with NewCommitPathIterFromIter
+func NewCommitFileIterFromIter(fileName string, commitIter CommitIter, checkParent bool) CommitIter {
+ return NewCommitPathIterFromIter(
+ func(path string) bool {
+ return path == fileName
+ },
+ commitIter,
+ checkParent,
+ )
+}
+
+func (c *commitPathIter) Next() (*Commit, error) {
if c.currentCommit == nil {
var err error
c.currentCommit, err = c.sourceIter.Next()
@@ -45,7 +57,7 @@ func (c *commitFileIter) Next() (*Commit, error) {
return commit, commitErr
}
-func (c *commitFileIter) getNextFileCommit() (*Commit, error) {
+func (c *commitPathIter) getNextFileCommit() (*Commit, error) {
for {
// Parent-commit can be nil if the current-commit is the initial commit
parentCommit, parentCommitErr := c.sourceIter.Next()
@@ -96,9 +108,9 @@ func (c *commitFileIter) getNextFileCommit() (*Commit, error) {
}
}
-func (c *commitFileIter) hasFileChange(changes Changes, parent *Commit) bool {
+func (c *commitPathIter) hasFileChange(changes Changes, parent *Commit) bool {
for _, change := range changes {
- if change.name() != c.fileName {
+ if !c.pathFilter(change.name()) {
continue
}
@@ -125,7 +137,7 @@ func isParentHash(hash plumbing.Hash, commit *Commit) bool {
return false
}
-func (c *commitFileIter) ForEach(cb func(*Commit) error) error {
+func (c *commitPathIter) ForEach(cb func(*Commit) error) error {
for {
commit, nextErr := c.Next()
if nextErr == io.EOF {
@@ -144,6 +156,6 @@ func (c *commitFileIter) ForEach(cb func(*Commit) error) error {
return nil
}
-func (c *commitFileIter) Close() {
+func (c *commitPathIter) Close() {
c.sourceIter.Close()
}
diff --git a/plumbing/object/object.go b/plumbing/object/object.go
index e960e50..c48a18d 100644
--- a/plumbing/object/object.go
+++ b/plumbing/object/object.go
@@ -138,17 +138,19 @@ func (s *Signature) decodeTimeAndTimeZone(b []byte) {
return
}
- // Include a dummy year in this time.Parse() call to avoid a bug in Go:
- // https://github.com/golang/go/issues/19750
- //
- // Parsing the timezone with no other details causes the tl.Location() call
- // below to return time.Local instead of the parsed zone in some cases
- tl, err := time.Parse("2006 -0700", "1970 "+string(b[tzStart:tzStart+timeZoneLength]))
- if err != nil {
+ timezone := string(b[tzStart : tzStart+timeZoneLength])
+ tzhours, err1 := strconv.ParseInt(timezone[0:3], 10, 64)
+ tzmins, err2 := strconv.ParseInt(timezone[3:], 10, 64)
+ if err1 != nil || err2 != nil {
return
}
+ if tzhours < 0 {
+ tzmins *= -1
+ }
+
+ tz := time.FixedZone("", int(tzhours*60*60+tzmins*60))
- s.When = s.When.In(tl.Location())
+ s.When = s.When.In(tz)
}
func (s *Signature) encodeTimeAndTimeZone(w io.Writer) error {