From 4738d25eb2350effae9b30b2f8eace881a986135 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 23 May 2013 07:39:31 -0400 Subject: [PATCH] add support for downloading packages from bitbucket.org through tag and branch --- README.md | 2 +- doc/bitbucket.go | 17 +++++++++++++---- doc/github.go | 15 ++++++--------- install.go | 2 +- repo/bundles/test_bundle.json | 4 ++-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index bebfc8d3c..d9ad63f5e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This application still in experiment, any change could happen, but it doesn't af ## Todo -- Add support for downloading by tag and branch for packages in bitbucket.org, git.oschina.net, gitcafe.com. +- Add support for downloading by tag and branch for packages in git.oschina.net, gitcafe.com. - Add template projects for testing commands. - Add gpm working principle design. - Add support for downloading tarballs from user sources. diff --git a/doc/bitbucket.go b/doc/bitbucket.go index c90b02446..6259b5ec7 100644 --- a/doc/bitbucket.go +++ b/doc/bitbucket.go @@ -8,6 +8,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "errors" "io" "net/http" "os" @@ -40,8 +41,9 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH // but does not need to download dependencies. isCheckImport := len(node.Value) == 0 - // Check if download with specific revision. - if isCheckImport || len(node.Value) == 1 { + switch { + case isCheckImport || len(node.Value) == 1: + // Get up-to-date version. tags := make(map[string]string) for _, nodeType := range []string{"branches", "tags"} { var nodes map[string]struct { @@ -61,10 +63,17 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH if err != nil { return nil, err } + node.Type = "commit" node.Value = match["commit"] - } else { - match["commit"] = node.Value + case !isCheckImport: // Bundle or snapshot. + // Check downlaod type. + switch node.Type { + case "tag", "commit", "branch": + match["commit"] = node.Value + default: + return nil, errors.New("Unknown node type: " + node.Type) + } } // We use .tar.gz here. diff --git a/doc/github.go b/doc/github.go index 5af666d8f..584c100a1 100644 --- a/doc/github.go +++ b/doc/github.go @@ -76,6 +76,7 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st } node.Type = "commit" + node.Value = match["sha"] case !isCheckImport: // Bundle or snapshot. // Check downlaod type. switch node.Type { @@ -96,11 +97,6 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st return nil, err } - r, err := zip.NewReader(bytes.NewReader(p), int64(len(p))) - if err != nil { - return nil, err - } - shaName := expand("{repo}-{sha}", match) if node.Type == "tag" { shaName = strings.Replace(shaName, "-v", "-", 1) @@ -115,6 +111,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st // Create destination directory. os.MkdirAll(installPath+"/", os.ModePerm) + r, err := zip.NewReader(bytes.NewReader(p), int64(len(p))) + if err != nil { + return nil, err + } + dirs := make([]string, 0, 5) // Need to add root path because we cannot get from tarball. dirs = append(dirs, installPath+"/") @@ -154,10 +155,6 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH st } } - if node.Type == "commit" { - node.Value = match["sha"] - } - var imports []string // Check if need to check imports. diff --git a/install.go b/install.go index 18d7987fc..bc6956ba4 100644 --- a/install.go +++ b/install.go @@ -194,7 +194,7 @@ func downloadPackages(nodes []*doc.Node) { for _, bn := range bnodes { fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value) } - fmt.Printf(fmt.Sprintf("%s", promptMsg["ContinueDownload"])) + fmt.Printf(fmt.Sprintf("%s\n", promptMsg["ContinueDownload"])) var option string fmt.Fscan(os.Stdin, &option) if strings.ToLower(option) != "y" { diff --git a/repo/bundles/test_bundle.json b/repo/bundles/test_bundle.json index 8eee69831..ffba780d3 100644 --- a/repo/bundles/test_bundle.json +++ b/repo/bundles/test_bundle.json @@ -44,8 +44,8 @@ }, { "import_path": "bitbucket.org/zombiezen/gopdf/pdf", - "type": "commit", - "value": "", + "type": "branch", + "value": "default", "deps": null }, {