Browse Source

Fixed bug: has revision but still force to check(which never changes)

pull/103/head
Unknown 11 years ago
parent
commit
61bcb024f6
  1. 16
      cmd/cmd.go
  2. 10
      cmd/gen.go
  3. 180
      cmd/get.go
  4. 9
      doc/struct.go
  5. 15
      gopm.go

16
cmd/cmd.go

@ -1,4 +1,4 @@
// Copyright 2013 gopm authors.
// Copyright 2013-2014 gopm authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
@ -57,24 +57,22 @@ func validPath(info string) (string, string) {
l := len(infos)
switch {
case l == 1:
// for local imports
// For local imports.
if com.IsFile(infos[0]) {
return doc.LOCAL, infos[0]
}
return doc.BRANCH, ""
case l == 2:
switch infos[1] {
case doc.TRUNK, doc.MASTER, doc.DEFAULT:
infos[1] = ""
}
return infos[0], infos[1]
default:
log.Error("", "Cannot parse dependency version:")
log.Error("", "\t"+info)
log.Help("Try 'gopm help get' to get more information")
return "", ""
}
log.Error("", "Cannot parse dependency version:")
log.Error("", "\t"+info)
log.Help("Try 'gopm help get' to get more information")
return "", ""
}
func versionSuffix(value string) string {

10
cmd/gen.go

@ -41,7 +41,6 @@ Make sure you run this command in the root path of a go project.`,
},
}
// scan a directory and gen a gopm file
func runGen(ctx *cli.Context) {
setup(ctx)
@ -55,15 +54,18 @@ func runGen(ctx *cli.Context) {
log.Fatal("", "\t"+err.Error())
}
targetPath := parseTarget(gf.MustValue("target", "path"))
// Get dependencies.
imports := doc.GetAllImports([]string{workDir},
parseTarget(gf.MustValue("target", "path")), ctx.Bool("example"))
imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example"))
for _, p := range imports {
p = doc.GetProjectPath(p)
if strings.HasSuffix(workDir, p) {
// Skip subpackage(s) of current project.
if strings.HasSuffix(workDir, p) || strings.HasPrefix(p, targetPath) {
continue
}
// Check if user specified the version.
if value := gf.MustValue("deps", p); len(value) == 0 {
gf.SetValue("deps", p, "")
}

180
cmd/get.go

@ -1,4 +1,4 @@
// Copyright 2013 gopm authors.
// Copyright 2013-2014 gopm authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
@ -69,7 +69,6 @@ func init() {
func runGet(ctx *cli.Context) {
setup(ctx)
// Check conflicts.
if ctx.Bool("gopath") && ctx.Bool("remote") {
log.Error("get", "Command options have conflicts")
@ -119,11 +118,17 @@ func getByGopmfile(ctx *cli.Context) {
}
gf := doc.NewGopmfile(".")
targetPath := parseTarget(gf.MustValue("target", "path"))
// Get dependencies.
imports := doc.GetAllImports([]string{workDir},
parseTarget(gf.MustValue("target", "path")), ctx.Bool("example"))
imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example"))
nodes := make([]*doc.Node, 0, len(imports))
for _, p := range imports {
p = doc.GetProjectPath(p)
// Skip subpackage(s) of current project.
if strings.HasSuffix(workDir, p) || strings.HasPrefix(p, targetPath) {
continue
}
node := doc.NewNode(p, p, doc.BRANCH, "", true)
// Check if user specified the version.
@ -140,6 +145,7 @@ func getByGopmfile(ctx *cli.Context) {
}
func getByPath(ctx *cli.Context) {
return
nodes := make([]*doc.Node, 0, len(ctx.Args()))
for _, info := range ctx.Args() {
pkgPath := info
@ -192,90 +198,99 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
if n.Type == doc.LOCAL {
continue
}
// Check if it is a valid remote path.
if doc.IsValidRemotePath(n.ImportPath) {
gopathDir := path.Join(installGopath, n.ImportPath)
n.RootPath = doc.GetProjectPath(n.ImportPath)
installPath := path.Join(installRepoPath, n.RootPath) +
versionSuffix(n.Value)
if !ctx.Bool("update") {
// Check if package has been downloaded.
if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
com.IsExist(installPath) {
log.Trace("Skipped installed package: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
if ctx.Bool("gopath") && com.IsExist(installPath) {
copyToGopath(installPath, gopathDir)
}
continue
} else {
doc.LocalNodes.SetValue(n.RootPath, "value", "")
// Check if it is a valid remote path or C.
if n.ImportPath == "C" {
continue
} else if !doc.IsValidRemotePath(n.ImportPath) {
// Invalid import path.
log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
failConut++
continue
}
// Valid import path.
gopathDir := path.Join(installGopath, n.ImportPath)
n.RootPath = doc.GetProjectPath(n.ImportPath)
installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value)
// Indicates whether need to download package again.
if len(n.Value) > 0 && com.IsExist(installPath) {
n.IsGetDepsOnly = true
}
if !ctx.Bool("update") {
// Check if package has been downloaded.
if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
com.IsExist(installPath) {
log.Trace("Skipped installed package: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
// Only copy when no version control.
if ctx.Bool("gopath") && com.IsExist(installPath) ||
len(getVcsName(gopathDir)) == 0 {
copyToGopath(installPath, gopathDir)
}
continue
} else {
doc.LocalNodes.SetValue(n.RootPath, "value", "")
}
}
if downloadCache[n.RootPath] {
log.Trace("Skipped downloaded package: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
continue
}
// Download package.
nod, imports := downloadPackage(ctx, n)
if len(imports) > 0 {
var gf *goconfig.ConfigFile
// Check if has gopmfile.
if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) {
log.Log("Found gopmfile: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
gf = doc.NewGopmfile(installPath)
}
if !downloadCache[n.RootPath] {
// Download package.
nod, imports := downloadPackage(ctx, n)
if len(imports) > 0 {
var gf *goconfig.ConfigFile
// Check if has gopmfile
if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) {
log.Log("Found gopmfile: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
gf = doc.NewGopmfile(installPath)
}
// Need to download dependencies.
// Generate temporary nodes.
nodes := make([]*doc.Node, len(imports))
for i := range nodes {
nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true)
if gf == nil {
continue
}
// Check if user specified the version.
if v, err := gf.GetValue("deps", imports[i]); err == nil &&
len(v) > 0 {
nodes[i].Type, nodes[i].Value = validPath(v)
}
}
downloadPackages(ctx, nodes)
// Need to download dependencies.
// Generate temporary nodes.
nodes := make([]*doc.Node, len(imports))
for i := range nodes {
nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true)
if gf == nil {
continue
}
// Only save package information with specific commit.
if nod != nil {
// Save record in local nodes.
log.Success("SUCC", "GET", fmt.Sprintf("%s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
downloadCount++
// Only save non-commit node.
if len(nod.Value) == 0 && len(nod.Revision) > 0 {
doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision)
}
if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") &&
len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 {
copyToGopath(installPath, gopathDir)
}
// Check if user specified the version.
if v, err := gf.GetValue("deps", imports[i]); err == nil && len(v) > 0 {
nodes[i].Type, nodes[i].Value = validPath(v)
}
} else {
log.Trace("Skipped downloaded package: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
}
} else if n.ImportPath == "C" {
downloadPackages(ctx, nodes)
}
// Only save package information with specific commit.
if nod == nil {
continue
} else {
// Invalid import path.
log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
failConut++
}
// Save record in local nodes.
log.Success("SUCC", "GET", fmt.Sprintf("%s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
downloadCount++
// Only save non-commit node.
if len(nod.Value) == 0 && len(nod.Revision) > 0 {
doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision)
}
if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") &&
len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 {
copyToGopath(installPath, gopathDir)
}
}
}
@ -296,6 +311,11 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) {
err = updateByVcs(vcs, gopathDir)
imports = doc.GetAllImports([]string{gopathDir}, nod.RootPath, false)
} else {
// If package has revision and exist, then just check dependencies.
if nod.IsGetDepsOnly {
return nod, doc.GetAllImports([]string{path.Join(installRepoPath, nod.RootPath) + versionSuffix(nod.Value)},
nod.RootPath, ctx.Bool("example"))
}
nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value")
imports, err = doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags)
}

9
doc/struct.go

@ -59,10 +59,11 @@ func NewDefaultPkg(importPath string) *Pkg {
type Node struct {
Pkg
DownloadURL string
Synopsis string
IsGetDeps bool
Revision string
DownloadURL string
Synopsis string
IsGetDeps bool
IsGetDepsOnly bool
Revision string
}
func NewNode(importPath, downloadUrl, tp, value string, isGetDeps bool) *Node {

15
gopm.go

@ -1,4 +1,4 @@
// Copyright 2013 gopm authors.
// Copyright 2013-2014 gopm authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
@ -12,7 +12,7 @@
// License for the specific language governing permissions and limitations
// under the License.
// gopm(Go Package Manager) is a Go package manage tool for search, install, update and share packages in Go.
// gopm(Go Package Manager) is a Go package manage tool for searching, installing, updating and sharing your packages in Go.
package main
import (
@ -29,7 +29,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true
const APP_VER = "0.6.0.1211"
const APP_VER = "0.6.1.0110"
// //cmd.CmdSearch,
// cmdClean,
@ -37,7 +37,6 @@ const APP_VER = "0.6.0.1211"
// cmdEnv,
// cmdFix,
// cmdList,
// cmdTest,
// cmdTool,
// cmdVet,
// }
@ -53,11 +52,11 @@ func main() {
app.Version = APP_VER
app.Commands = []cli.Command{
cmd.CmdGet,
cmd.CmdBin,
//cmd.CmdBin,
cmd.CmdGen,
cmd.CmdRun,
cmd.CmdBuild,
cmd.CmdInstall,
//cmd.CmdRun,
//cmd.CmdBuild,
//cmd.CmdInstall,
//cmd.CmdUpdate,
//cmd.CmdTest,
}

Loading…
Cancel
Save