コード例 #1
0
ファイル: env.go プロジェクト: pombredanne/dep
func (o *Environment) Diff(pkg *gdf.Package, includeImportTypeDiffs bool) (diff *pkgDiff, err error) {
	dbpkg, exps, imps, e := o.db.GetPackage(pkg.Path, true, true)
	if e != nil {
		err = fmt.Errorf("package not registered: %s\n", pkg.Path)
		return
	}

	if pkg.JsonMd5() != dbpkg.JsonMd5 {
		pkgjs := pkg

		var oldExports = map[string]string{}

		for _, dbExp := range exps {
			oldExports[dbExp.Name] = dbExp.Value
		}

		pDiff := &pkgDiff{}
		pDiff.Path = pkg.Path
		pDiff.Exports = mapDiff(oldExports, pkgjs.Exports, true)

		var oldImports = map[string]string{}

		for _, dbImp := range imps {
			oldImports[dbImp.Import+"."+dbImp.Name] = dbImp.Value
		}
		pDiff.Imports = mapDiff(oldImports, pkgjs.Imports, includeImportTypeDiffs)

		if len(pDiff.Exports) > 0 || len(pDiff.Imports) > 0 {
			return pDiff, nil
		}
	}
	return nil, nil
}
コード例 #2
0
ファイル: env.go プロジェクト: pombredanne/dep
func (env *Environment) Dump() (all []*gdf.Package, err error) {
	var allP []*dbPkg
	allP, err = env.db.GetAllPackages()

	if err != nil {
		return
	}

	var allI []*imp
	allI, err = env.db.GetAllImports()

	if err != nil {
		return
	}
	pkgImports := map[string]map[string]string{}

	for _, dbI := range allI {
		_, exists := pkgImports[dbI.Package]
		if !exists {
			pkgImports[dbI.Package] = map[string]string{}
		}
		pkgImports[dbI.Package][dbI.Import+"."+dbI.Name] = dbI.Value
	}

	var allE []*exp
	allE, err = env.db.GetAllExports()

	if err != nil {
		return
	}
	pkgExports := map[string]map[string]string{}

	for _, dbE := range allE {
		_, exists := pkgExports[dbE.Package]
		if !exists {
			pkgExports[dbE.Package] = map[string]string{}
		}
		pkgExports[dbE.Package][dbE.Name] = dbE.Value
	}

	all = make([]*gdf.Package, len(allP))

	for i, p := range allP {
		pkg := gdf.Package{}
		pkg.Path = p.Package
		pkgImp, hasImp := pkgImports[p.Package]
		if !hasImp {
			pkgImp = map[string]string{}
		}
		pkg.Imports = pkgImp

		pkgExp, hasExp := pkgExports[p.Package]
		if !hasExp {
			pkgExp = map[string]string{}
		}
		pkg.Exports = pkgExp
		all[i] = &pkg
	}
	return
}
コード例 #3
0
ファイル: env.go プロジェクト: pombredanne/dep
func (o *Environment) Track(pkg *gdf.Package, recursive bool) (data []byte, err error) {
	revisions := map[string]revision{}
	for im, _ := range pkg.ImportedPackages {
		//o.trackedImportRevisions(pkg.Path)
		iPkg, e := o.GetPkg(im)

		if e != nil {
			err = e
			return
		}
		if iPkg.Internal {
			continue
		}
		if !iPkg.IsInPath(pkg.Path) && !pkg.IsInPath(iPkg.Path) {
			revisions[im] = o.getRevision(iPkg.Dir(), pkg.Path)
		}
		if recursive {
			o.recursiveImportRevisions(revisions, iPkg, pkg.Path)
			continue
		}
	}

	data, err = json.MarshalIndent(revisions, "", "  ")
	if err != nil {
		return
	}

	filename := path.Join(pkg.Dir(), revFileName)
	err = ioutil.WriteFile(filename, data, 0644)
	return
}
コード例 #4
0
ファイル: env.go プロジェクト: pombredanne/dep
// TODO: get rid of it
func (env *Environment) packageToDBFormat(pkgMap map[string]*dbPkg, pkg *gdf.Package, includeImported bool) (dbExps []*exp, dbImps []*imp) {
	p := &dbPkg{}
	p.Package = pkg.Path
	p.Json = niceJson(pkg)
	p.JsonMd5 = pkg.JsonMd5()
	pkgMap[pkg.Path] = p
	dbExps = []*exp{}
	dbImps = []*imp{}

	if includeImported {
		for im, _ := range pkg.ImportedPackages {
			if _, has := pkgMap[im]; has {
				continue
			}
			imPkg, err := env.GetPkg(im)
			if err != nil {
				panic(fmt.Sprintf("%s imports not existing package %s", pkg.Path, im))
			}
			pExp, pImp := env.packageToDBFormat(pkgMap, imPkg, includeImported)
			dbExps = append(dbExps, pExp...)
			dbImps = append(dbImps, pImp...)
		}
	}

	pkgjs := pkg

	for k, v := range pkgjs.Exports {
		dbE := &exp{}
		dbE.Package = pkg.Path
		dbE.Name = k
		dbE.Value = v
		dbExps = append(dbExps, dbE)
	}

	for k, v := range pkgjs.Imports {
		dbI := &imp{}
		dbI.Package = pkg.Path
		importPath, name := gdf.SplitImportSymbol(k)
		dbI.Name = name
		dbI.Value = v
		dbI.Import = importPath
		dbImps = append(dbImps, dbI)
	}
	return
}
コード例 #5
0
ファイル: env.go プロジェクト: pombredanne/dep
// for each import, get the revisions
func (o *Environment) recursiveImportRevisions(revisions map[string]revision, pkg *gdf.Package, parent string) {
	for im, _ := range pkg.ImportedPackages {
		if _, has := revisions[im]; !has {
			p, err := o.GetPkg(im)
			if err != nil {
				panic(fmt.Sprintf("package %s does not exist", im))
			}
			var d string
			var internal bool
			d, internal, err = o.PkgDir(im)
			if internal {
				continue
			}
			if !p.IsInPath(pkg.Path) && !pkg.IsInPath(p.Path) {
				revisions[im] = o.getRevision(d, pkg.Path)
			}
			o.recursiveImportRevisions(revisions, p, pkg.Path)
		}
	}
}