1
0
Fork 0
forked from forgejo/forgejo

update go-git to v4.12.0 - fixes #7248 (#7249)

This commit is contained in:
techknowlogick 2019-06-18 22:14:15 -04:00 committed by Lunny Xiao
parent b209531959
commit 33ad554800
270 changed files with 71049 additions and 14434 deletions

View file

@ -451,7 +451,7 @@ func (r *Repository) Remote(name string) (*Remote, error) {
return nil, ErrRemoteNotFound
}
return newRemote(r.Storer, c), nil
return NewRemote(r.Storer, c), nil
}
// Remotes returns a list with all the remotes
@ -465,7 +465,7 @@ func (r *Repository) Remotes() ([]*Remote, error) {
var i int
for _, c := range cfg.Remotes {
remotes[i] = newRemote(r.Storer, c)
remotes[i] = NewRemote(r.Storer, c)
i++
}
@ -478,7 +478,7 @@ func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error) {
return nil, err
}
remote := newRemote(r.Storer, c)
remote := NewRemote(r.Storer, c)
cfg, err := r.Storer.Config()
if err != nil {
@ -504,7 +504,7 @@ func (r *Repository) CreateRemoteAnonymous(c *config.RemoteConfig) (*Remote, err
return nil, ErrAnonymousRemoteName
}
remote := newRemote(r.Storer, c)
remote := NewRemote(r.Storer, c)
return remote, nil
}
@ -1306,16 +1306,6 @@ func (r *Repository) Worktree() (*Worktree, error) {
return &Worktree{r: r, Filesystem: r.wt}, nil
}
func countTrue(vals ...bool) int {
sum := 0
for _, v := range vals {
if v {
sum++
}
}
return sum
}
// ResolveRevision resolves revision to corresponding hash. It will always
// resolve to a commit hash, not a tree or annotated tag.
//
@ -1336,54 +1326,57 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
switch item.(type) {
case revision.Ref:
revisionRef := item.(revision.Ref)
var ref *plumbing.Reference
var hashCommit, refCommit, tagCommit *object.Commit
var rErr, hErr, tErr error
var tryHashes []plumbing.Hash
maybeHash := plumbing.NewHash(string(revisionRef))
if !maybeHash.IsZero() {
tryHashes = append(tryHashes, maybeHash)
}
for _, rule := range append([]string{"%s"}, plumbing.RefRevParseRules...) {
ref, err = storer.ResolveReference(r.Storer, plumbing.ReferenceName(fmt.Sprintf(rule, revisionRef)))
ref, err := storer.ResolveReference(r.Storer, plumbing.ReferenceName(fmt.Sprintf(rule, revisionRef)))
if err == nil {
tryHashes = append(tryHashes, ref.Hash())
break
}
}
if ref != nil {
tag, tObjErr := r.TagObject(ref.Hash())
if tObjErr != nil {
tErr = tObjErr
} else {
tagCommit, tErr = tag.Commit()
// in ambiguous cases, `git rev-parse` will emit a warning, but
// will always return the oid in preference to a ref; we don't have
// the ability to emit a warning here, so (for speed purposes)
// don't bother to detect the ambiguity either, just return in the
// priority that git would.
gotOne := false
for _, hash := range tryHashes {
commitObj, err := r.CommitObject(hash)
if err == nil {
commit = commitObj
gotOne = true
break
}
tagObj, err := r.TagObject(hash)
if err == nil {
// If the tag target lookup fails here, this most likely
// represents some sort of repo corruption, so let the
// error bubble up.
tagCommit, err := tagObj.Commit()
if err != nil {
return &plumbing.ZeroHash, err
}
commit = tagCommit
gotOne = true
break
}
refCommit, rErr = r.CommitObject(ref.Hash())
} else {
rErr = plumbing.ErrReferenceNotFound
tErr = plumbing.ErrReferenceNotFound
}
maybeHash := plumbing.NewHash(string(revisionRef)).String() == string(revisionRef)
if maybeHash {
hashCommit, hErr = r.CommitObject(plumbing.NewHash(string(revisionRef)))
} else {
hErr = plumbing.ErrReferenceNotFound
}
isTag := tErr == nil
isCommit := rErr == nil
isHash := hErr == nil
switch {
case countTrue(isTag, isCommit, isHash) > 1:
return &plumbing.ZeroHash, fmt.Errorf(`refname "%s" is ambiguous`, revisionRef)
case isTag:
commit = tagCommit
case isCommit:
commit = refCommit
case isHash:
commit = hashCommit
default:
if !gotOne {
return &plumbing.ZeroHash, plumbing.ErrReferenceNotFound
}
case revision.CaretPath:
depth := item.(revision.CaretPath).Depth