2020-02-15 22:13:50 +00:00
|
|
|
package dehub
|
|
|
|
|
|
|
|
import (
|
2020-04-26 20:23:03 +00:00
|
|
|
"encoding/hex"
|
2020-03-14 22:14:18 +00:00
|
|
|
"errors"
|
2020-02-15 22:13:50 +00:00
|
|
|
"fmt"
|
2020-04-26 20:23:03 +00:00
|
|
|
"path/filepath"
|
2020-03-21 18:24:38 +00:00
|
|
|
"strings"
|
2020-02-15 22:13:50 +00:00
|
|
|
|
|
|
|
"gopkg.in/src-d/go-git.v4/plumbing"
|
|
|
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
|
|
|
)
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// Commit wraps a single git commit object, and also contains various fields
|
|
|
|
// which are parsed out of it, including the payload. It is used as a
|
|
|
|
// convenience type, in place of having to manually retrieve and parse specific
|
|
|
|
// information out of commit objects.
|
2020-03-04 23:34:02 +00:00
|
|
|
type Commit struct {
|
2020-04-26 20:23:03 +00:00
|
|
|
Payload PayloadUnion
|
2020-02-15 22:13:50 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
Hash plumbing.Hash
|
|
|
|
Object *object.Commit
|
|
|
|
TreeObject *object.Tree
|
2020-02-15 22:13:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// GetCommit retrieves the Commit at the given hash, and all of its sub-data
|
|
|
|
// which can be pulled out of it.
|
|
|
|
func (proj *Project) GetCommit(h plumbing.Hash) (c Commit, err error) {
|
|
|
|
if c.Object, err = proj.GitRepo.CommitObject(h); err != nil {
|
|
|
|
return c, fmt.Errorf("getting git commit object: %w", err)
|
|
|
|
} else if c.TreeObject, err = proj.GitRepo.TreeObject(c.Object.TreeHash); err != nil {
|
|
|
|
return c, fmt.Errorf("getting git tree object %q: %w",
|
|
|
|
c.Object.TreeHash, err)
|
2020-04-30 21:22:27 +00:00
|
|
|
} else if err = c.Payload.UnmarshalText([]byte(c.Object.Message)); err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return c, fmt.Errorf("decoding commit message: %w", err)
|
2020-02-15 22:13:50 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
c.Hash = c.Object.Hash
|
|
|
|
return
|
2020-03-04 23:34:02 +00:00
|
|
|
}
|
2020-02-15 22:13:50 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// ErrHeadIsZero is used to indicate that HEAD resolves to the zero hash. An
|
|
|
|
// example of when this can happen is if the project was just initialized and
|
|
|
|
// has no commits, or if an orphan branch is checked out.
|
|
|
|
var ErrHeadIsZero = errors.New("HEAD resolves to the zero hash")
|
2020-02-15 22:13:50 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// GetHeadCommit returns the Commit which is currently referenced by HEAD.
|
|
|
|
// This method may return ErrHeadIsZero if HEAD resolves to the zero hash.
|
|
|
|
func (proj *Project) GetHeadCommit() (Commit, error) {
|
|
|
|
headHash, err := proj.ReferenceToHash(plumbing.HEAD)
|
2020-03-04 23:34:02 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return Commit{}, fmt.Errorf("resolving HEAD: %w", err)
|
|
|
|
} else if headHash == plumbing.ZeroHash {
|
|
|
|
return Commit{}, ErrHeadIsZero
|
2020-03-04 23:34:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
c, err := proj.GetCommit(headHash)
|
2020-03-04 23:34:02 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return Commit{}, fmt.Errorf("getting commit %q: %w", headHash, err)
|
2020-03-04 23:34:02 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
return c, nil
|
2020-02-15 22:13:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// GetCommitRange returns an ancestry of Commits, with the first being the
|
|
|
|
// commit immediately following the given starting hash, and the last being the
|
|
|
|
// given ending hash.
|
|
|
|
//
|
|
|
|
// If start is plumbing.ZeroHash then the root commit will be the starting hash.
|
|
|
|
func (proj *Project) GetCommitRange(start, end plumbing.Hash) ([]Commit, error) {
|
|
|
|
curr, err := proj.GetCommit(end)
|
2020-02-16 17:28:59 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return nil, fmt.Errorf("retrieving commit %q: %w", end, err)
|
2020-02-16 17:28:59 +00:00
|
|
|
}
|
2020-03-22 23:54:25 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
var commits []Commit
|
|
|
|
var found bool
|
|
|
|
for {
|
|
|
|
if found = start != plumbing.ZeroHash && curr.Hash == start; found {
|
|
|
|
break
|
|
|
|
}
|
2020-03-22 23:54:25 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
commits = append(commits, curr)
|
|
|
|
numParents := curr.Object.NumParents()
|
|
|
|
if numParents == 0 {
|
|
|
|
break
|
|
|
|
} else if numParents > 1 {
|
|
|
|
return nil, fmt.Errorf("commit %q has more than one parent: %+v",
|
|
|
|
curr.Hash, curr.Object.ParentHashes)
|
|
|
|
}
|
2020-03-22 23:54:25 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
parentHash := curr.Object.ParentHashes[0]
|
|
|
|
parent, err := proj.GetCommit(parentHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("retrieving commit %q: %w", parentHash, err)
|
|
|
|
}
|
|
|
|
curr = parent
|
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
---
type: change
message: |-
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
This commit attempts to normalize git commit interactions in order to reduce
the amount of manual `GitRepo.CommitObject`, `GitRepo.TreeObject`,
`Commit.UnmarshalText`, and `Commit.Interface` calls are done, by creating a
single structure (`GitCommit`) which holds the output of those calls, and is
only created by a single method (`GetGitCommit`), which is then used by a bunch
of other methods to expand its functionality, including implementing a range
request which can be used by verify and the pre-receive hook (though it's only
used by the hook, currently).
change_hash: AMae4PL6+jrxhn2KEGHejstcdT37Gw/jjkl/UuovHcgd
credentials:
- type: pgp_signature
pub_key_id: 95C46FA6A41148AC
body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5uhvoACgkQlcRvpqQRSKzJrhAAqi2LEQVTyVktfsOBv/CZmefclLLqWTChVoeIZt2EAGDDGygmrx88hI0SEAviOzPMn0kiZFDeY5k7ICJMhJ9RVDU9WjH7fbOboMJW19rVhx6Ke/M2ERtrT0OFLRmFVJVDM0P8SEheQvR3HE/iiypBICVCtp+meHEq9mOJWZlZnoCqMaulAy/Nnq4N1VD0yPPlr16+yxMqedKHcgKbcH8K61ltNAjXDT+tCWwCq1huA5MVSuTm5EwqIeKPN6JKgwATv8Ku2GhYZWHSGUwecP1J3x2XTDPeChCQVDpC232Pxwk8z/D36F3J/XOfkdl0QYQ077xL1IJfYOnuuHir47CokDf3G0XCQnJ/+X4pZdtP387rc045o/2bhUi2U4eJ5HgS7Hvyi6EApT0Czv7SeJePTvdnRUYse8ZYuIwYXj5GWWxnbKQzLpyjcHdQc2a3B3RN84zXqqAOS6ObFrFPZQIfz2rfQojZN8kvcmUvYhJXSaT65XmqFjyJ4n6grrEnK/N+MfbnpzyF/yvlzxWPqGFQOQj9meosbTAdgZbmdwYqa5r1ee8DmlkzNJJxze96h503a733yciN8Ef4hGZNlRV6YFegkK/cCgKaA4NCEALKb1t0Uri5gnPldXk4HsPF+23GANbE7mjytY8ra3fhXG4VhaFt/WsLg3Bu7djQ0H74y+g=
account: mediocregopher
2020-03-15 19:50:24 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
if !found && start != plumbing.ZeroHash {
|
|
|
|
return nil, fmt.Errorf("unable to find commit %q as an ancestor of %q",
|
|
|
|
start, end)
|
2020-03-22 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// reverse the commits to be in the expected order
|
|
|
|
for l, r := 0, len(commits)-1; l < r; l, r = l+1, r-1 {
|
|
|
|
commits[l], commits[r] = commits[r], commits[l]
|
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
---
type: change
message: |-
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
This commit attempts to normalize git commit interactions in order to reduce
the amount of manual `GitRepo.CommitObject`, `GitRepo.TreeObject`,
`Commit.UnmarshalText`, and `Commit.Interface` calls are done, by creating a
single structure (`GitCommit`) which holds the output of those calls, and is
only created by a single method (`GetGitCommit`), which is then used by a bunch
of other methods to expand its functionality, including implementing a range
request which can be used by verify and the pre-receive hook (though it's only
used by the hook, currently).
change_hash: AMae4PL6+jrxhn2KEGHejstcdT37Gw/jjkl/UuovHcgd
credentials:
- type: pgp_signature
pub_key_id: 95C46FA6A41148AC
body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5uhvoACgkQlcRvpqQRSKzJrhAAqi2LEQVTyVktfsOBv/CZmefclLLqWTChVoeIZt2EAGDDGygmrx88hI0SEAviOzPMn0kiZFDeY5k7ICJMhJ9RVDU9WjH7fbOboMJW19rVhx6Ke/M2ERtrT0OFLRmFVJVDM0P8SEheQvR3HE/iiypBICVCtp+meHEq9mOJWZlZnoCqMaulAy/Nnq4N1VD0yPPlr16+yxMqedKHcgKbcH8K61ltNAjXDT+tCWwCq1huA5MVSuTm5EwqIeKPN6JKgwATv8Ku2GhYZWHSGUwecP1J3x2XTDPeChCQVDpC232Pxwk8z/D36F3J/XOfkdl0QYQ077xL1IJfYOnuuHir47CokDf3G0XCQnJ/+X4pZdtP387rc045o/2bhUi2U4eJ5HgS7Hvyi6EApT0Czv7SeJePTvdnRUYse8ZYuIwYXj5GWWxnbKQzLpyjcHdQc2a3B3RN84zXqqAOS6ObFrFPZQIfz2rfQojZN8kvcmUvYhJXSaT65XmqFjyJ4n6grrEnK/N+MfbnpzyF/yvlzxWPqGFQOQj9meosbTAdgZbmdwYqa5r1ee8DmlkzNJJxze96h503a733yciN8Ef4hGZNlRV6YFegkK/cCgKaA4NCEALKb1t0Uri5gnPldXk4HsPF+23GANbE7mjytY8ra3fhXG4VhaFt/WsLg3Bu7djQ0H74y+g=
account: mediocregopher
2020-03-15 19:50:24 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
return commits, nil
|
2020-02-16 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
var (
|
|
|
|
hashStrLen = len(plumbing.ZeroHash.String())
|
|
|
|
errNotHex = errors.New("not a valid hex string")
|
|
|
|
)
|
2020-02-22 00:37:19 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
func (proj *Project) findCommitByShortHash(hashStr string) (plumbing.Hash, error) {
|
|
|
|
paddedHashStr := hashStr
|
|
|
|
if len(hashStr)%2 > 0 {
|
|
|
|
paddedHashStr += "0"
|
2020-02-22 00:37:19 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
if hashB, err := hex.DecodeString(paddedHashStr); err != nil {
|
|
|
|
return plumbing.ZeroHash, errNotHex
|
|
|
|
} else if len(hashStr) == hashStrLen {
|
|
|
|
var hash plumbing.Hash
|
|
|
|
copy(hash[:], hashB)
|
|
|
|
return hash, nil
|
|
|
|
} else if len(hashStr) < 2 {
|
|
|
|
return plumbing.ZeroHash, errors.New("hash string must be 2 characters long or more")
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
2020-03-14 22:14:18 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
for i := 2; i < hashStrLen; i++ {
|
|
|
|
hashPrefix, hashTail := hashStr[:i], hashStr[i:]
|
|
|
|
path := filepath.Join("objects", hashPrefix)
|
|
|
|
fileInfos, err := proj.GitDirFS.ReadDir(path)
|
|
|
|
if err != nil {
|
|
|
|
return plumbing.ZeroHash, fmt.Errorf("listing files in %q: %w", path, err)
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
var matchedHash plumbing.Hash
|
|
|
|
for _, fileInfo := range fileInfos {
|
|
|
|
objFileName := fileInfo.Name()
|
|
|
|
if !strings.HasPrefix(objFileName, hashTail) {
|
|
|
|
continue
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
objHash := plumbing.NewHash(hashPrefix + objFileName)
|
|
|
|
obj, err := proj.GitRepo.Storer.EncodedObject(plumbing.AnyObject, objHash)
|
|
|
|
if err != nil {
|
|
|
|
return plumbing.ZeroHash, fmt.Errorf("reading object %q off disk: %w", objHash, err)
|
|
|
|
} else if obj.Type() != plumbing.CommitObject {
|
|
|
|
continue
|
2020-04-05 18:28:32 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
} else if matchedHash == plumbing.ZeroHash {
|
|
|
|
matchedHash = objHash
|
|
|
|
continue
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
return plumbing.ZeroHash, fmt.Errorf("both %q and %q match", matchedHash, objHash)
|
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
---
type: change
message: |-
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
This commit attempts to normalize git commit interactions in order to reduce
the amount of manual `GitRepo.CommitObject`, `GitRepo.TreeObject`,
`Commit.UnmarshalText`, and `Commit.Interface` calls are done, by creating a
single structure (`GitCommit`) which holds the output of those calls, and is
only created by a single method (`GetGitCommit`), which is then used by a bunch
of other methods to expand its functionality, including implementing a range
request which can be used by verify and the pre-receive hook (though it's only
used by the hook, currently).
change_hash: AMae4PL6+jrxhn2KEGHejstcdT37Gw/jjkl/UuovHcgd
credentials:
- type: pgp_signature
pub_key_id: 95C46FA6A41148AC
body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5uhvoACgkQlcRvpqQRSKzJrhAAqi2LEQVTyVktfsOBv/CZmefclLLqWTChVoeIZt2EAGDDGygmrx88hI0SEAviOzPMn0kiZFDeY5k7ICJMhJ9RVDU9WjH7fbOboMJW19rVhx6Ke/M2ERtrT0OFLRmFVJVDM0P8SEheQvR3HE/iiypBICVCtp+meHEq9mOJWZlZnoCqMaulAy/Nnq4N1VD0yPPlr16+yxMqedKHcgKbcH8K61ltNAjXDT+tCWwCq1huA5MVSuTm5EwqIeKPN6JKgwATv8Ku2GhYZWHSGUwecP1J3x2XTDPeChCQVDpC232Pxwk8z/D36F3J/XOfkdl0QYQ077xL1IJfYOnuuHir47CokDf3G0XCQnJ/+X4pZdtP387rc045o/2bhUi2U4eJ5HgS7Hvyi6EApT0Czv7SeJePTvdnRUYse8ZYuIwYXj5GWWxnbKQzLpyjcHdQc2a3B3RN84zXqqAOS6ObFrFPZQIfz2rfQojZN8kvcmUvYhJXSaT65XmqFjyJ4n6grrEnK/N+MfbnpzyF/yvlzxWPqGFQOQj9meosbTAdgZbmdwYqa5r1ee8DmlkzNJJxze96h503a733yciN8Ef4hGZNlRV6YFegkK/cCgKaA4NCEALKb1t0Uri5gnPldXk4HsPF+23GANbE7mjytY8ra3fhXG4VhaFt/WsLg3Bu7djQ0H74y+g=
account: mediocregopher
2020-03-15 19:50:24 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
if matchedHash != plumbing.ZeroHash {
|
|
|
|
return matchedHash, nil
|
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
---
type: change
message: |-
normalize how git commits are interacted with, including changing VerifyComit -> VerifyCommits
This commit attempts to normalize git commit interactions in order to reduce
the amount of manual `GitRepo.CommitObject`, `GitRepo.TreeObject`,
`Commit.UnmarshalText`, and `Commit.Interface` calls are done, by creating a
single structure (`GitCommit`) which holds the output of those calls, and is
only created by a single method (`GetGitCommit`), which is then used by a bunch
of other methods to expand its functionality, including implementing a range
request which can be used by verify and the pre-receive hook (though it's only
used by the hook, currently).
change_hash: AMae4PL6+jrxhn2KEGHejstcdT37Gw/jjkl/UuovHcgd
credentials:
- type: pgp_signature
pub_key_id: 95C46FA6A41148AC
body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5uhvoACgkQlcRvpqQRSKzJrhAAqi2LEQVTyVktfsOBv/CZmefclLLqWTChVoeIZt2EAGDDGygmrx88hI0SEAviOzPMn0kiZFDeY5k7ICJMhJ9RVDU9WjH7fbOboMJW19rVhx6Ke/M2ERtrT0OFLRmFVJVDM0P8SEheQvR3HE/iiypBICVCtp+meHEq9mOJWZlZnoCqMaulAy/Nnq4N1VD0yPPlr16+yxMqedKHcgKbcH8K61ltNAjXDT+tCWwCq1huA5MVSuTm5EwqIeKPN6JKgwATv8Ku2GhYZWHSGUwecP1J3x2XTDPeChCQVDpC232Pxwk8z/D36F3J/XOfkdl0QYQ077xL1IJfYOnuuHir47CokDf3G0XCQnJ/+X4pZdtP387rc045o/2bhUi2U4eJ5HgS7Hvyi6EApT0Czv7SeJePTvdnRUYse8ZYuIwYXj5GWWxnbKQzLpyjcHdQc2a3B3RN84zXqqAOS6ObFrFPZQIfz2rfQojZN8kvcmUvYhJXSaT65XmqFjyJ4n6grrEnK/N+MfbnpzyF/yvlzxWPqGFQOQj9meosbTAdgZbmdwYqa5r1ee8DmlkzNJJxze96h503a733yciN8Ef4hGZNlRV6YFegkK/cCgKaA4NCEALKb1t0Uri5gnPldXk4HsPF+23GANbE7mjytY8ra3fhXG4VhaFt/WsLg3Bu7djQ0H74y+g=
account: mediocregopher
2020-03-15 19:50:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
return plumbing.ZeroHash, errors.New("failed to find a commit object with a matching prefix")
|
2020-03-22 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
func (proj *Project) resolveRev(rev plumbing.Revision) (plumbing.Hash, error) {
|
|
|
|
if rev == plumbing.Revision(plumbing.ZeroHash.String()) {
|
|
|
|
return plumbing.ZeroHash, nil
|
2020-02-15 22:13:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
{
|
|
|
|
// pretend the revision is a short hash until proven otherwise
|
|
|
|
shortHash := string(rev)
|
|
|
|
hash, err := proj.findCommitByShortHash(shortHash)
|
|
|
|
if errors.Is(err, errNotHex) {
|
|
|
|
// ok, continue
|
|
|
|
} else if err != nil {
|
|
|
|
return plumbing.ZeroHash, fmt.Errorf("resolving as short hash: %w", err)
|
2020-04-11 23:10:18 +00:00
|
|
|
} else {
|
2020-04-26 20:23:03 +00:00
|
|
|
// guess it _is_ a short hash, knew it!
|
|
|
|
return hash, nil
|
2020-02-15 22:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
h, err := proj.GitRepo.ResolveRevision(rev)
|
2020-04-18 19:26:32 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return plumbing.ZeroHash, fmt.Errorf("resolving revision %q: %w", rev, err)
|
2020-04-18 19:26:32 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
return *h, nil
|
2020-03-23 23:15:44 +00:00
|
|
|
}
|
2020-04-24 19:33:33 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// GetCommitByRevision resolves the revision and returns the Commit it references.
|
|
|
|
func (proj *Project) GetCommitByRevision(rev plumbing.Revision) (Commit, error) {
|
|
|
|
hash, err := proj.resolveRev(rev)
|
2020-04-24 19:33:33 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return Commit{}, err
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
c, err := proj.GetCommit(hash)
|
2020-04-24 19:33:33 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return Commit{}, fmt.Errorf("getting commit %q: %w", hash, err)
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
return c, nil
|
|
|
|
}
|
2020-04-24 19:33:33 +00:00
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
// GetCommitRangeByRevision is like GetCommitRange, first resolving the given
|
|
|
|
// revisions into hashes before continuing with GetCommitRange's behavior.
|
|
|
|
func (proj *Project) GetCommitRangeByRevision(startRev, endRev plumbing.Revision) ([]Commit, error) {
|
|
|
|
start, err := proj.resolveRev(startRev)
|
2020-04-24 19:33:33 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return nil, err
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 20:23:03 +00:00
|
|
|
end, err := proj.resolveRev(endRev)
|
2020-04-24 19:33:33 +00:00
|
|
|
if err != nil {
|
2020-04-26 20:23:03 +00:00
|
|
|
return nil, err
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|
2020-04-26 20:23:03 +00:00
|
|
|
|
|
|
|
return proj.GetCommitRange(start, end)
|
2020-04-24 19:33:33 +00:00
|
|
|
}
|