// MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
421031
func MakeGitContext(gitURL string) (builder.Source, error) {
	root, err := git.Clone(gitURL)
	if err != nil {
		return nil, err
	}

	c, err := archive.Tar(root, archive.Uncompressed)
	if err != nil {
		return nil, err
	}

	defer func() {
		err := c.Close()
		if err != nil {
			logrus.WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while closing git context")
		}
		err = os.RemoveAll(root)
		if err != nil {
			logrus.WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while removing path and children of root")
		}
	}()
	return FromArchive(c)
}
420111
func (h *LangHandler) BuildContext(ctx context.Context) *build.Context {
	var bctx *build.Context
	if override := h.init.BuildContext; override != nil {
		bctx = &build.Context{
			GOOS:        override.GOOS,
			GOARCH:      override.GOARCH,
			GOPATH:      override.GOPATH,
			GOROOT:      override.GOROOT,
			CgoEnabled:  override.CgoEnabled,
			UseAllFiles: override.UseAllFiles,
			Compiler:    override.Compiler,
			BuildTags:   override.BuildTags,

			// Enable analysis of all go version build tags that
			// our compiler should understand.
			ReleaseTags: build.Default.ReleaseTags,
		}
	} else {
		// make a copy since we will mutate it
		copy := build.Default
		bctx = &copy
	}

	h.Mu.Lock()
	fs := h.FS
	h.Mu.Unlock()

	util.PrepareContext(bctx, ctx, fs)
	return bctx
}
444416
func (l *Logger) AddContext(key, val string) {
	l.globalsL.Lock()
	defer l.globalsL.Unlock()
	updateContextMapIfNotReserved(l.globals, key, val)
}
1076701
func (r *cmdRun) ModifyContext(ctx context.Context) context.Context {
	if r.verbose {
		ctx = logging.SetLevel(ctx, logging.Debug)
	}
	return ctx
}
733253
func makeContext() ctx {
	c := ctx{
		DemoTypes:   []ctxType{},
		PacketTypes: []ctxType{},
	}

	demoIds := []int{}
	demoMap := map[int]ctxType{}
	packetIds := []int{}
	packetMap := map[int]ctxType{}

	for _, t := range messageTypes {
		for vs, n := range t.enumValues {
			// Find an enum type for the enum value
			if ts, ok := t.enumToType(vs); ok {
				// Find a struct type for the enum type
				if messageTypeNames[ts] {
					cs, ok := t.enumToCallback(vs)
					if !ok {
						cs = ts
					}
					if t.isPacket {
						packetIds = append(packetIds, n)
						packetMap[n] = ctxType{
							Id:       n,
							Callback: cs,
							EnumName: vs,
							TypeName: ts,
						}
					} else {
						demoIds = append(demoIds, n)
						demoMap[n] = ctxType{
							Id:       n,
							Callback: cs,
							EnumName: vs,
							TypeName: ts,
						}
					}
				} else {
					fmt.Printf("warning: no matching type %s for enum: type %s %s = %d\n", ts, vs, t.enumName, n)
				}
			} else {
				fmt.Printf("notice: skipped manually excluded enum: type %s %s = %d\n", vs, t.enumName, n)
			}
		}
	}

	sort.Ints(demoIds)
	sort.Ints(packetIds)

	for _, id := range demoIds {
		c.DemoTypes = append(c.DemoTypes, demoMap[id])
	}
	for _, id := range packetIds {
		c.PacketTypes = append(c.PacketTypes, packetMap[id])
	}

	return c
}
666255
func newContext(store kv.Storage) sessionctx.Context {
	c := mock.NewContext()
	c.Store = store
	c.GetSessionVars().SetStatusFlag(mysql.ServerStatusAutocommit, false)
	c.GetSessionVars().StmtCtx.TimeZone = time.UTC
	return c
}
947501
func (o *CreateParams) WithContext(ctx context.Context) *CreateParams {
	o.SetContext(ctx)
	return o
}
480218
func NewContext(p Project, opts ...func(*Context) error) (*Context, error) {
	envOr := func(key, def string) string {
		if v := os.Getenv(key); v != "" {
			return v
		}
		return def
	}

	defaults := []func(*Context) error{
		// must come before GcToolchain()
		func(c *Context) error {
			c.gohostos = runtime.GOOS
			c.gohostarch = runtime.GOARCH
			c.gotargetos = envOr("GOOS", runtime.GOOS)
			c.gotargetarch = envOr("GOARCH", runtime.GOARCH)
			c.debug = func(string, ...interface{}) {} // null logger
			return nil
		},
		GcToolchain(),
	}
	workdir, err := ioutil.TempDir("", "gb")
	if err != nil {
		return nil, err
	}

	ctx := Context{
		Project:   p,
		workdir:   workdir,
		buildmode: "exe",
		pkgs:      make(map[string]*Package),
	}

	for _, opt := range append(defaults, opts...) {
		err := opt(&ctx)
		if err != nil {
			return nil, err
		}
	}

	// sort build tags to ensure the ctxSring and Suffix is stable
	sort.Strings(ctx.buildtags)

	bc := build.Default
	bc.GOOS = ctx.gotargetos
	bc.GOARCH = ctx.gotargetarch
	bc.CgoEnabled = cgoEnabled(ctx.gohostos, ctx.gohostarch, ctx.gotargetos, ctx.gotargetarch)
	bc.ReleaseTags = releaseTags
	bc.BuildTags = ctx.buildtags

	i, err := buildImporter(&bc, &ctx)
	if err != nil {
		return nil, err
	}

	ctx.importer = i

	// C and unsafe are fake packages synthesised by the compiler.
	// Insert fake packages into the package cache.
	for _, name := range []string{"C", "unsafe"} {
		pkg, err := ctx.newPackage(&build.Package{
			Name:       name,
			ImportPath: name,
			Dir:        name, // fake, but helps diagnostics
			Goroot:     true,
		})
		if err != nil {
			return nil, err
		}
		pkg.NotStale = true
		ctx.pkgs[pkg.ImportPath] = pkg
	}

	return &ctx, err
}
30865
func (b *Batch) WithContext(ctx context.Context) *Batch {
	b2 := *b
	b2.context = ctx
	return &b2
}
89674
func (call *PushMessageCall) WithContext(ctx context.Context) *PushMessageCall {
	call.ctx = ctx
	return call
}
455239
func DefaultContext() *Context {
	globalLock.Lock()
	defer globalLock.Unlock()
	if globalCtx == nil {
		var err error
		if globalCtx, err = NewContext(); err != nil {
			panic(err)
		}
	}
	return globalCtx
}
517682
func NewContext(res http.ResponseWriter, req *http.Request) *Context {
	return NewContextWith(res, req, nil)
}
1197534
func (call *GetMessageQuotaCall) WithContext(ctx context.Context) *GetMessageQuotaCall {
	call.ctx = ctx
	return call
}
1033961
func (o *GetMetricsParams) WithContext(ctx context.Context) *GetMetricsParams {
	o.SetContext(ctx)
	return o
}
1327574
func (o *GetHelloParams) WithContext(ctx context.Context) *GetHelloParams {
	o.SetContext(ctx)
	return o
}
864327
func (call *AddLIFFCall) WithContext(ctx context.Context) *AddLIFFCall {
	call.ctx = ctx
	return call
}
898564
func newContext(ctx context.Context, resource, name string, gvk schema.GroupVersionKind) context.Context {
	oldInfo, found := genericapirequest.RequestInfoFrom(ctx)
	if !found {
		return ctx
	}
	newInfo := genericapirequest.RequestInfo{
		IsResourceRequest: true,
		Verb:              "get",
		Namespace:         oldInfo.Namespace,
		Resource:          resource,
		Name:              name,
		Parts:             []string{resource, name},
		APIGroup:          gvk.Group,
		APIVersion:        gvk.Version,
	}
	return genericapirequest.WithRequestInfo(ctx, &newInfo)
}