Skip to content

Commit

Permalink
Update libgit (#53)
Browse files Browse the repository at this point in the history
* update libgit2 to v0.24.1

* fix compile time errors from upgrade

* WIP completion callback

* simplify cloning by cloning in main thread

this should cut down possible race condition errors
  • Loading branch information
cpg1111 authored Aug 2, 2016
1 parent b3ac6b9 commit 9df3318
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Dockerfile_c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ RUN apt-get -qq update && apt-get install -y cmake build-essential pkg-config op
make && make install && \
cd / && \
rm -rf libssh2-1.4.2 && \
curl -L -o v0.22.0.tar.gz -z v0.22.0.tar.gz https://github.com/libgit2/libgit2/archive/v0.22.0.tar.gz && \
tar xzvf v0.22.0.tar.gz && \
cd libgit2-0.22.0 && \
curl -L -o v0.24.1.tar.gz -z v0.24.1.tar.gz https://github.com/libgit2/libgit2/archive/v0.24.1.tar.gz && \
tar xzvf v0.24.1.tar.gz && \
cd libgit2-0.24.1 && \
pwd && \
mkdir build && \
cd build && \
Expand Down
2 changes: 1 addition & 1 deletion credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cpg1111/maestro/config"

prompt "github.com/segmentio/go-prompt"
git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

// RawCredentials is a struct for any credentials
Expand Down
2 changes: 1 addition & 1 deletion pipeline/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package pipeline
import (
"log"

git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

func build(srv *DepService, index string, done chan string, errChan chan error, shouldDeploy *bool) {
Expand Down
57 changes: 16 additions & 41 deletions pipeline/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import (
"fmt"
"log"
"os"
"time"

"github.com/cpg1111/maestro/config"
"github.com/cpg1111/maestro/credentials"
"github.com/cpg1111/maestro/util"

pb "gopkg.in/cheggaaa/pb.v1"
git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

// Project is a struct for the Project in the pipeline
Expand Down Expand Up @@ -53,7 +52,6 @@ var (
progbar *pb.ProgressBar
received uint
hasFinished = false
done = make(chan bool)
)

func handleProgress(stats git.TransferProgress) git.ErrorCode {
Expand All @@ -67,13 +65,15 @@ func handleProgress(stats git.TransferProgress) git.ErrorCode {
received = stats.ReceivedObjects
if (int)(received) == (int)(stats.TotalObjects) && !hasFinished {
hasFinished = true
time.Sleep(time.Second)
done <- true
return git.ErrOk
return handleComplete(git.RemoteCompletionDownload)
}
return git.ErrOk
}

func handleComplete(complete git.RemoteCompletion) git.ErrorCode {
return git.ErrOk
}

// New returns a new instance of a pipeline project
func New(conf *config.Config, creds *credentials.RawCredentials, clonePath, branch, last, curr string) *Project {
var absPath string
Expand All @@ -91,14 +91,18 @@ func New(conf *config.Config, creds *credentials.RawCredentials, clonePath, bran
panic(cwdErr)
}
gitCreds := creds.ToGitCredentials()
cloneOpts := &git.CloneOptions{
RemoteCallbacks: &git.RemoteCallbacks{
fetchOpts := &git.FetchOptions{
RemoteCallbacks: git.RemoteCallbacks{
CredentialsCallback: credCB(&gitCreds),
CertificateCheckCallback: certCheckCB,
TransferProgressCallback: handleProgress,
CompletionCallback: handleComplete,
},
}
cloneOpts := &git.CloneOptions{
FetchOptions: fetchOpts,
CheckoutOpts: &git.CheckoutOpts{
Strategy: git.CheckoutSafeCreate,
Strategy: git.CheckoutSafe,
},
Bare: false,
CheckoutBranch: branch,
Expand All @@ -118,40 +122,11 @@ func New(conf *config.Config, creds *credentials.RawCredentials, clonePath, bran
// Clone clones a git repo
func (p *Project) Clone() (resRepo *git.Repository, resErr error) {
log.Println("Cloning Repo...")
repoChan := make(chan *git.Repository)
errChan := make(chan error)
go func() {
repo, repoErr := git.Clone(p.conf.RepoURL, fmt.Sprintf("%s/", p.clonePath), p.CloneOpts)
repoChan <- repo
errChan <- repoErr
}()
var doneMsg bool
for {
select {
case resRepo = <-repoChan:
if resRepo != nil && doneMsg {
cdErr := os.Chdir(p.ABSPath)
if cdErr != nil {
log.Fatal(cdErr)
}
return
}
case resErr = <-errChan:
if resErr != nil {
panic(resErr)
}
case doneMsg = <-done:
if resRepo != nil && doneMsg {
cdErr := os.Chdir(p.ABSPath)
if cdErr != nil {
log.Fatal(cdErr)
}
return
}
}
}
resRepo, resErr = git.Clone(p.conf.RepoURL, fmt.Sprintf("%s/", p.clonePath), p.CloneOpts)
return
}

// Checkout checks out the repo to the current commit or HEAD of the branch
func (p *Project) Checkout(repo *git.Repository, commit string) error {
tree, treeErr := util.CommitToTree(repo, commit)
if treeErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion pipeline/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cpg1111/maestro/credentials"
"github.com/cpg1111/maestro/util"

git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

// Service is a struct for services in the pipeline
Expand Down
2 changes: 1 addition & 1 deletion pipeline/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"errors"
"log"

git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

// DepTree is a dependency tree to determine whether or not to build services
Expand Down
2 changes: 1 addition & 1 deletion util/commit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package util

import (
git "gopkg.in/libgit2/git2go.v22"
git "gopkg.in/libgit2/git2go.v24"
)

func CommitToTree(repo *git.Repository, hash string) (*git.Tree, error) {
Expand Down
7 changes: 4 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
"revision": "8808370bf63524e115da1371ba42bce6739f3a6b"
},
{
"checksumSHA1": "wQudIit83haY5Ip3FD9Uxlz4QZA=",
"path": "gopkg.in/libgit2/git2go.v22",
"revision": "41ad00f868e7dfcdb04c7538f27350d400f710a3"
"checksumSHA1": "W9y5Ib20WD6Msz3iy7pfS4vRsb0=",
"path": "gopkg.in/libgit2/git2go.v24",
"revision": "8eaae73f85dd3df78df80d2dac066eb0866444ae",
"revisionTime": "2016-04-27T12:53:21Z"
}
],
"rootPath": "github.com/cpg1111/maestro"
Expand Down

0 comments on commit 9df3318

Please sign in to comment.