// NewTrackerQueryRepository constructs a TrackerQueryRepository
14865
func NewTrackerQueryRepository(db *gorm.DB) *GormTrackerQueryRepository {
	return &GormTrackerQueryRepository{
		db:   db,
		witr: workitem.NewWorkItemTypeRepository(db),
		wir:  workitem.NewWorkItemRepository(db),
	}
}
1084123
func NewToolsGetter(f state.EntityFinder, c environs.EnvironConfigGetter, s ToolsStorageGetter, t ToolsURLGetter, getCanRead GetAuthFunc) *ToolsGetter {
	return &ToolsGetter{f, c, s, t, getCanRead}
}
252598
func (h Home) LocalRepository(elem ...string) string {
	p := []string{"repository", "local"}
	p = append(p, elem...)
	return h.Path(p...)
}
1251099
func NewTrackerController(service *goa.Service, db application.DB, scheduler *remoteworkitem.Scheduler, configuration trackerConfiguration) *TrackerController {
	return &TrackerController{
		Controller:    service.NewController("TrackerController"),
		db:            db,
		scheduler:     scheduler,
		configuration: configuration}
}
176804
func (r *GormTrackerQueryRepository) Create(ctx context.Context, tq TrackerQuery) (*TrackerQuery, error) {
	wiType, err := r.witr.Load(ctx, tq.WorkItemTypeID)
	if err != nil {
		return nil, errors.NewBadParameterError("WorkItemTypeID", tq.WorkItemTypeID)
	}

	allowedWIT, err := r.wir.CheckTypeAndSpaceShareTemplate(ctx, wiType, tq.SpaceID)
	if err != nil {
		return nil, err

	}
	if !allowedWIT {
		return nil, err
	}

	if err := r.db.Create(&tq).Error; err != nil {
		return nil, errors.NewInternalError(ctx, r.db.Error)
	}
	return &tq, nil
}
31216
func (s *AppsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*Installation, *Response, error) {
	return s.getInstallation(ctx, fmt.Sprintf("repos/%v/%v/installation", owner, repo))
}
381471
func (i *Installation) GetRepositorySelection() string {
	if i == nil || i.RepositorySelection == nil {
		return ""
	}
	return *i.RepositorySelection
}
430563
func (c *repoCacheManager) storeRepository(repo ImageRepository) error {
	repoKey := NewRepositoryKey(c.repoID.CanonicalName())
	bytes, err := json.Marshal(repo)
	if err != nil {
		return err
	}
	return c.cacheClient.SetKey(repoKey, c.now.Add(repoRefresh), bytes)
}
631181
func NewTarringArchiver(checker Checker, uploader Uploader) *TarringArchiver {

	return &TarringArchiver{checker: checker, uploader: uploader}
}
889696
func NewTemplateQuery(name string) TemplateQuery {
	return TemplateQuery{
		template: name,
		vars:     make(map[string]interface{}),
	}
}
157078
func ravenTrace(repoPath string, stack []*event.StackFrame) *raven.Stacktrace {
	if repoPath != "" && repoPath[len(repoPath)-1] != '/' {
		repoPath = repoPath + "/"
	}

	stackLen := len(stack)
	ravenFrames := make([]*raven.StacktraceFrame, stackLen)
	for i, frame := range stack {
		filePath := frame.File
		inApp := false
		if repoPath != "" && strings.HasPrefix(filePath, repoPath) {
			filePath = filePath[len(repoPath):]

			if !strings.Contains(frame.File, "/Godeps/_workspace/src/") {
				//TODO come up with a better way of filtering external packages
				inApp = true
			}
		}

		sourceBefore, source, sourceAfter := frame.SourceContext(3, 0)
		sourceBeforeStrs := make([]string, len(sourceBefore))
		for i, line := range sourceBefore {
			sourceBeforeStrs[i] = string(line)
		}
		sourceAfterStrs := make([]string, len(sourceAfter))
		for i, line := range sourceAfter {
			sourceAfterStrs[i] = string(line)
		}

		ravenFrame := &raven.StacktraceFrame{
			Filename:     filePath,
			Function:     frame.Func,
			Module:       frame.Package,
			Lineno:       frame.Line,
			AbsolutePath: frame.File,
			InApp:        inApp,
			ContextLine:  string(source),
			PreContext:   sourceBeforeStrs,
			PostContext:  sourceAfterStrs,
		}
		ravenFrames[stackLen-1-i] = ravenFrame
	}

	return &raven.Stacktrace{Frames: ravenFrames}
}
175335
func newTimedcache(ttl time.Duration, getter getFunc) (*timedCache, error) {
	if getter == nil {
		return nil, fmt.Errorf("getter is not provided")
	}

	return &timedCache{
		getter: getter,
		store:  cache.NewTTLStore(cacheKeyFunc, ttl),
	}, nil
}
85297
func IsRepositoryExist(u *User, repoName string) (bool, error) {
	return isRepositoryExist(x, u, repoName)
}
265879
func (qe *QueryEngine) peekQuery(sql string) *TabletPlan {
	if cacheResult, ok := qe.plans.Peek(sql); ok {
		return cacheResult.(*TabletPlan)
	}
	return nil
}
970358
func (db *Database) followCursor(ctx context.Context, r Response) ([]byte, error) {
	// If the result only has one page
	if !r.HasMore() {
		if len(r.RawResult()) != 0 {
			// Parsed result is not empty, so return this
			return r.RawResult(), nil
		}
		// Return the raw result
		return r.Raw(), nil
	}

	buf := bytes.NewBuffer(r.RawResult()[:len(r.RawResult())-1])
	buf.WriteRune(',')

	q := &requests.FollowCursor{Cursor: r.Cursor()}
	var err error

	for r.HasMore() {
		r, err = db.Send(ctx, q)
		if err != nil {
			return nil, err
		}
		buf.Write(r.RawResult()[1 : len(r.RawResult())-1])
		buf.WriteRune(',')
	}

	buf.Truncate(buf.Len() - 1)
	buf.WriteRune(']')

	return buf.Bytes(), nil
}
864279
func (cl *Client) newTorrent(ih metainfo.Hash, specStorage storage.ClientImpl) (t *Torrent) {
	// use provided storage, if provided
	storageClient := cl.defaultStorage
	if specStorage != nil {
		storageClient = storage.NewClient(specStorage)
	}

	t = &Torrent{
		cl:       cl,
		infoHash: ih,
		peers: prioritizedPeers{
			om: btree.New(32),
			getPrio: func(p Peer) peerPriority {
				return bep40PriorityIgnoreError(cl.publicAddr(p.IP), p.addr())
			},
		},
		conns: make(map[*connection]struct{}, 2*cl.config.EstablishedConnsPerTorrent),

		halfOpen:          make(map[string]Peer),
		pieceStateChanges: pubsub.NewPubSub(),

		storageOpener:       storageClient,
		maxEstablishedConns: cl.config.EstablishedConnsPerTorrent,

		networkingEnabled: true,
		requestStrategy:   2,
		metadataChanged: sync.Cond{
			L: cl.locker(),
		},
		duplicateRequestTimeout: 1 * time.Second,
	}
	t.logger = cl.logger.Clone().AddValue(t)
	t.setChunkSize(defaultChunkSize)
	return
}
907637
func newTransactionManager(maxCursor uint64, dht *DHT) *transactionManager {
	return &transactionManager{
		RWMutex:      &sync.RWMutex{},
		transactions: newSyncedMap(),
		index:        newSyncedMap(),
		maxCursor:    maxCursor,
		queryChan:    make(chan *query, 1024),
		dht:          dht,
	}
}