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 }
// 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) } } }