// Check an import path and before and after revision for changes. Import path
// maybe empty, if so, the current working directory will be used. If a
// revision is blank, the default VCS revision is used.
966792
func (c *Checker) Check(rel string, recurse bool, beforeRev, afterRev string) ([]Change, error) {
	// If revision is unset use VCS's default revision
	dBefore, dAfter := c.vcs.DefaultRevision()
	if beforeRev == "" {
		beforeRev = dBefore
	}
	if afterRev == "" {
		afterRev = dAfter
	}
	c.recurse = recurse

	var err error
	c.path, err = importPathTo(rel)
	if err != nil {
		return nil, err
	}

	c.logf("import path: %q before: %q after: %q recursive: %v\n", c.path, beforeRev, afterRev, c.recurse)

	// Parse revisions from VCS into go/ast
	start := time.Now()
	if c.b, err = c.parse(beforeRev); err != nil {
		return nil, err
	}
	if c.a, err = c.parse(afterRev); err != nil {
		return nil, err
	}
	parse := time.Since(start)

	start = time.Now()
	changes, err := c.compareDecls()
	if err != nil {
		var buf bytes.Buffer
		fmt.Fprintf(&buf, "error comparing declarations: %s\n", err)
		if derr, ok := err.(*diffError); ok {
			_ = ast.Fprint(&buf, c.b[derr.pkg].fset, derr.bdecl, ast.NotNilFilter)
			_ = ast.Fprint(&buf, c.a[derr.pkg].fset, derr.adecl, ast.NotNilFilter)
		}
		return nil, errors.New(buf.String())
	}
	diff := time.Since(start)

	start = time.Now()
	sort.Sort(byID(changes))
	sort := time.Since(start)

	c.logf("Timing: parse: %v, diff: %v, sort: %v, total: %v\n", parse, diff, sort, parse+diff+sort)
	c.logf("Changes detected: %v\n", len(changes))

	return changes, nil
}
3843
func (dir *Directory) Import(ctx *build.Context, mode build.ImportMode) (*build.Package, error) {
	safeCopy := *ctx
	ctx = &safeCopy
	ctx.JoinPath = path.Join
	ctx.IsAbsPath = path.IsAbs
	ctx.SplitPathList = func(list string) []string { return strings.Split(list, ":") }
	ctx.IsDir = func(path string) bool { return path == "." }
	ctx.HasSubdir = func(root, dir string) (rel string, ok bool) { return "", false }
	ctx.ReadDir = dir.readDir
	ctx.OpenFile = dir.openFile
	return ctx.ImportDir(".", mode)
}
595186
func checkPrefixAndFetchRelativePath(childpath string, parentpath string) (bool, string) {
	// Windows (local) file systems - NTFS, as well as FAT and variants
	// are case insensitive.
	cp, pp := childpath, parentpath
	if goruntime.GOOS == "windows" {
		cp = strings.ToLower(cp)
		pp = strings.ToLower(pp)
	}

	if strings.HasPrefix(cp, pp) {
		pth, err := filepath.Rel(parentpath, childpath)
		if err != nil {
			log.Fatalln(err)
		}
		return true, pth
	}

	return false, ""

}
845201
func (b *backend) pathConfigCertificateExistenceCheck(ctx context.Context, req *logical.Request, data *framework.FieldData) (bool, error) {
	certName := data.Get("cert_name").(string)
	if certName == "" {
		return false, fmt.Errorf("missing cert_name")
	}

	entry, err := b.lockedAWSPublicCertificateEntry(ctx, req.Storage, certName)
	if err != nil {
		return false, err
	}
	return entry != nil, nil
}
1247588
func main() {
	CheckArgs("<path>")
	path := os.Args[1]

	// We instanciate a new repository targeting the given path (the .git folder)
	r, err := git.PlainOpen(path)
	CheckIfError(err)

	// Length of the HEAD history
	Info("git rev-list HEAD --count")

	// ... retrieving the HEAD reference
	ref, err := r.Head()
	CheckIfError(err)

	// ... retrieves the commit history
	cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
	CheckIfError(err)

	// ... just iterates over the commits
	var cCount int
	err = cIter.ForEach(func(c *object.Commit) error {
		cCount++

		return nil
	})
	CheckIfError(err)

	fmt.Println(cCount)
}
596469
func (upc *unflushedPathCache) prepUnflushedPaths(ctx context.Context,
	uid keybase1.UID, key kbfscrypto.VerifyingKey, codec kbfscodec.Codec,
	log logger.Logger, osg idutil.OfflineStatusGetter, mdInfo unflushedPathMDInfo) (
	unflushedPathsPerRevMap, error) {
	cpp := func() chainsPathPopulator {
		upc.lock.Lock()
		defer upc.lock.Unlock()
		return upc.chainsPopulator
	}()

	// The unflushed paths haven't been initialized yet.
	if cpp == nil {
		return nil, nil
	}

	newUnflushedPaths := make(unflushedPathsMap)
	mdInfos := []unflushedPathMDInfo{mdInfo}

	err := addUnflushedPaths(
		ctx, uid, key, codec, log, osg, mdInfos, cpp, newUnflushedPaths)
	if err != nil {
		return nil, err
	}
	if len(newUnflushedPaths) > 1 {
		return nil, fmt.Errorf("%d unflushed revisions on a single put",
			len(newUnflushedPaths))
	}

	perRevMap, ok := newUnflushedPaths[mdInfo.revision]
	if !ok {
		panic(fmt.Errorf("Cannot find per-revision map for revision %d",
			mdInfo.revision))
	}

	return perRevMap, nil
}
403204
func NewRevelPaths(mode, importPath, srcPath string, callback RevelCallback) (rp *RevelContainer, err error) {
	rp = &RevelContainer{ModulePathMap: map[string]string{}}
	// Ignore trailing slashes.
	rp.ImportPath = strings.TrimRight(importPath, "/")
	rp.SourcePath = srcPath
	rp.RunMode = mode

	// If the SourcePath is not specified, find it using build.Import.
	var revelSourcePath string // may be different from the app source path
	if rp.SourcePath == "" {
		rp.SourcePath, revelSourcePath, err = utils.FindSrcPaths(importPath, RevelImportPath, callback.PackageResolver)
		if err != nil {
			return
		}
	} else {
		// If the SourcePath was specified, assume both Revel and the app are within it.
		rp.SourcePath = filepath.Clean(rp.SourcePath)
		revelSourcePath = rp.SourcePath
	}

	// Setup paths for application
	rp.RevelPath = filepath.Join(revelSourcePath, filepath.FromSlash(RevelImportPath))
	rp.BasePath = filepath.Join(rp.SourcePath, filepath.FromSlash(importPath))
	rp.PackageInfo.Vendor = utils.Exists(filepath.Join(rp.BasePath, "vendor"))
	rp.AppPath = filepath.Join(rp.BasePath, "app")

	// Sanity check , ensure app and conf paths exist
	if !utils.DirExists(rp.AppPath)  {
		return rp, fmt.Errorf("No application found at path %s", rp.AppPath)
	}
	if !utils.DirExists(filepath.Join(rp.BasePath, "conf")) {
		return rp, fmt.Errorf("No configuration found at path %s", filepath.Join(rp.BasePath, "conf"))
	}

	rp.ViewsPath = filepath.Join(rp.AppPath, "views")
	rp.CodePaths = []string{rp.AppPath}
	rp.TemplatePaths = []string{}

	if rp.ConfPaths == nil {
		rp.ConfPaths = []string{}
	}

	// Config load order
	// 1. framework (revel/conf/*)
	// 2. application (conf/*)
	// 3. user supplied configs (...) - User configs can override/add any from above
	rp.ConfPaths = append(
		[]string{
			filepath.Join(rp.RevelPath, "conf"),
			filepath.Join(rp.BasePath, "conf"),
		},
		rp.ConfPaths...)

	rp.Config, err = config.LoadContext("app.conf", rp.ConfPaths)
	if err != nil {
		return rp, fmt.Errorf("Unable to load configuartion file %s", err)
	}

	// Ensure that the selected runmode appears in app.conf.
	// If empty string is passed as the mode, treat it as "DEFAULT"
	if mode == "" {
		mode = config.DefaultSection
	}
	if !rp.Config.HasSection(mode) {
		return rp, fmt.Errorf("app.conf: No mode found: %s %s", "run-mode", mode)
	}
	rp.Config.SetSection(mode)

	// Configure properties from app.conf
	rp.DevMode = rp.Config.BoolDefault("mode.dev", false)
	rp.HTTPPort = rp.Config.IntDefault("http.port", 9000)
	rp.HTTPAddr = rp.Config.StringDefault("http.addr", "")
	rp.HTTPSsl = rp.Config.BoolDefault("http.ssl", false)
	rp.HTTPSslCert = rp.Config.StringDefault("http.sslcert", "")
	rp.HTTPSslKey = rp.Config.StringDefault("http.sslkey", "")
	if rp.HTTPSsl {
		if rp.HTTPSslCert == "" {
			return rp, errors.New("No http.sslcert provided.")
		}
		if rp.HTTPSslKey == "" {
			return rp, errors.New("No http.sslkey provided.")
		}
	}
	//
	rp.AppName = rp.Config.StringDefault("app.name", "(not set)")
	rp.AppRoot = rp.Config.StringDefault("app.root", "")
	rp.CookiePrefix = rp.Config.StringDefault("cookie.prefix", "REVEL")
	rp.CookieDomain = rp.Config.StringDefault("cookie.domain", "")
	rp.CookieSecure = rp.Config.BoolDefault("cookie.secure", rp.HTTPSsl)
	rp.SecretStr = rp.Config.StringDefault("app.secret", "")

	callback.FireEvent(REVEL_BEFORE_MODULES_LOADED, nil)
	if err := rp.loadModules(callback); err != nil {
		return rp, err
	}

	callback.FireEvent(REVEL_AFTER_MODULES_LOADED, nil)

	return
}
776836
func vendorlessImportPath(ipath string, currentPackagePath string) (string, bool) {
	split := strings.Split(ipath, "vendor/")
	// no vendor in path
	if len(split) == 1 {
		return ipath, true
	}
	// this import path does not belong to the current package
	if currentPackagePath != "" && !strings.Contains(currentPackagePath, split[0]) {
		return "", false
	}
	// Devendorize for use in import statement.
	if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 {
		return ipath[i+len("/vendor/"):], true
	}
	if strings.HasPrefix(ipath, "vendor/") {
		return ipath[len("vendor/"):], true
	}
	return ipath, true
}
439753
func (ccpack *CDSPackage) InitFromPath(ccname string, ccversion string, path string) ([]byte, *pb.ChaincodeDeploymentSpec, error) {
	//incase ccpack is reused
	ccpack.reset()

	buf, err := GetChaincodePackageFromPath(ccname, ccversion, path)
	if err != nil {
		return nil, nil, err
	}

	ccdata, err := ccpack.InitFromBuffer(buf)
	if err != nil {
		return nil, nil, err
	}

	if err := ccpack.ValidateCC(ccdata); err != nil {
		return nil, nil, err
	}

	return ccpack.buf, ccpack.depSpec, nil
}
904702
func (v *Module) GetImportPath() (o string) {
	if v != nil {
		o = v.ImportPath
	}
	return
}
1125958
func calcGlockfilePath(importPath string, repo *managedRepo) string {
	var pkg, err = build.Import(importPath, "", build.FindOnly)
	if err != nil {
		perror(err)
	}

	var relPath = ""
	if len(repo.dir) < len(pkg.Dir) {
		relPath = pkg.Dir[len(repo.dir)+1:]
	}

	return filepath.Join(relPath, "GLOCKFILE")
}
531079
func setApplicationPath(c *model.CommandConfig) (err error) {

	// revel/revel#1014 validate relative path, we cannot use built-in functions
	// since Go import path is valid relative path too.
	// so check basic part of the path, which is "."
	if filepath.IsAbs(c.ImportPath) || strings.HasPrefix(c.ImportPath, ".") {
		utils.Logger.Fatalf("Abort: '%s' looks like a directory.  Please provide a Go import path instead.",
			c.ImportPath)
	}

	// If we are running a vendored version of Revel we do not need to check for it.
	if !c.New.Vendored {
		_, err = build.Import(model.RevelImportPath, "", build.FindOnly)
		if err != nil {
			//// Go get the revel project
			err = c.PackageResolver(model.RevelImportPath)
			if err != nil {
				return utils.NewBuildIfError(err, "Failed to fetch revel "+model.RevelImportPath)
			}
		}
	}

	c.AppName = filepath.Base(c.AppPath)

	return nil
}
784216
func (a *API) ImportPath() string {
	return path.Join(a.BaseImportPath, a.PackageName())
}
39141
func (r *SourceResource) Find(owner, slug, revision, path string) (*Source, error) {
	src := Source{}
	url_path := fmt.Sprintf("/repositories/%s/%s/src/%s/%s", owner, slug, revision, path)

	if err := r.client.do("GET", url_path, nil, nil, &src); err != nil {
		return nil, err
	}

	return &src, nil
}
59514
func importPathsNoDotExpansion(args []string) []string {
	if len(args) == 0 {
		return []string{"."}
	}
	var out []string
	for _, a := range args {
		// Arguments are supposed to be import paths, but
		// as a courtesy to Windows developers, rewrite \ to /
		// in command-line arguments.  Handles .\... and so on.
		if filepath.Separator == '\\' {
			a = strings.Replace(a, `\`, `/`, -1)
		}

		// Put argument in canonical form, but preserve leading ./.
		if strings.HasPrefix(a, "./") {
			a = "./" + path.Clean(a)
			if a == "./." {
				a = "."
			}
		} else {
			a = path.Clean(a)
		}
		if a == "all" || a == "std" || a == "cmd" {
			out = append(out, allPackages(a)...)
			continue
		}
		out = append(out, a)
	}
	return out
}
1091163
func getDefaultOCISettingsPath() (string, error) {
	u, err := user.Current()
	if err != nil {
		return "", err
	}

	if u.HomeDir == "" {
		return "", fmt.Errorf("Unable to determine the home directory for the current user.")
	}

	path := filepath.Join(u.HomeDir, ".oci", "config")
	if _, err := os.Stat(path); err != nil {
		return "", err
	}

	return path, nil
}
1093311
func (t *UniversalTranslator) Import(format ImportExportFormat, dirnameOrFilename string) error {

	fi, err := os.Stat(dirnameOrFilename)
	if err != nil {
		return err
	}

	processFn := func(filename string) error {

		f, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer f.Close()

		return t.ImportByReader(format, f)
	}

	if !fi.IsDir() {
		return processFn(dirnameOrFilename)
	}

	// recursively go through directory
	walker := func(path string, info os.FileInfo, err error) error {

		if info.IsDir() {
			return nil
		}

		switch format {
		case FormatJSON:
			// skip non JSON files
			if filepath.Ext(info.Name()) != ".json" {
				return nil
			}
		}

		return processFn(path)
	}

	return filepath.Walk(dirnameOrFilename, walker)
}