mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2015 PingCAP, Inc.
 | 
						|
//
 | 
						|
// 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 a copy of the License at
 | 
						|
//
 | 
						|
//     http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
//
 | 
						|
// Unless required by applicable law or agreed to in writing, software
 | 
						|
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
// See the License for the specific language governing permissions and
 | 
						|
// limitations under the License.
 | 
						|
 | 
						|
package autocommit
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/pingcap/tidb/context"
 | 
						|
)
 | 
						|
 | 
						|
// Checker is the interface checks if it should autocommit in the context.
 | 
						|
// TODO: Choose a better name.
 | 
						|
type Checker interface {
 | 
						|
	// ShouldAutocommit returns true if it should autocommit in the context.
 | 
						|
	ShouldAutocommit(ctx context.Context) bool
 | 
						|
}
 | 
						|
 | 
						|
// keyType is a dummy type to avoid naming collision in context.
 | 
						|
type keyType int
 | 
						|
 | 
						|
// String defines a Stringer function for debugging and pretty printing.
 | 
						|
func (k keyType) String() string {
 | 
						|
	return "autocommit_checker"
 | 
						|
}
 | 
						|
 | 
						|
const key keyType = 0
 | 
						|
 | 
						|
// BindAutocommitChecker binds autocommit checker to context.
 | 
						|
func BindAutocommitChecker(ctx context.Context, checker Checker) {
 | 
						|
	ctx.SetValue(key, checker)
 | 
						|
}
 | 
						|
 | 
						|
// ShouldAutocommit gets checker from ctx and checks if it should autocommit.
 | 
						|
func ShouldAutocommit(ctx context.Context) bool {
 | 
						|
	v, ok := ctx.Value(key).(Checker)
 | 
						|
	if !ok {
 | 
						|
		panic("Miss autocommit checker")
 | 
						|
	}
 | 
						|
	return v.ShouldAutocommit(ctx)
 | 
						|
}
 |