Update git module (#2074)

tokarchuk/v1.17
Jonas Östanbäck 8 years ago committed by Lunny Xiao
parent 858197b453
commit 1f4d84b7b2
  1. 211
      vendor/code.gitea.io/git/tree_entry.go
  2. 6
      vendor/vendor.json

@ -7,6 +7,8 @@ package git
import ( import (
"fmt" "fmt"
"path" "path"
"path/filepath"
"runtime"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -145,159 +147,112 @@ func (tes Entries) Sort() {
sort.Sort(tes) sort.Sort(tes)
} }
// getCommitInfoState transient state for getting commit info for entries type commitInfo struct {
type getCommitInfoState struct { entryName string
entries map[string]*TreeEntry // map from filepath to entry infos []interface{}
commits map[string]*Commit // map from filepath to commit err error
lastCommitHash string
lastCommit *Commit
treePath string
headCommit *Commit
nextSearchSize int // next number of commits to search for
} }
func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string) *getCommitInfoState { // GetCommitsInfo takes advantages of concurrency to speed up getting information
entriesByPath := make(map[string]*TreeEntry, len(entries)) // of all commits that are corresponding to these entries. This method will automatically
for _, entry := range entries { // choose the right number of goroutine (concurrency) to use related of the host CPU.
entriesByPath[path.Join(treePath, entry.Name())] = entry
}
if treePath = path.Clean(treePath); treePath == "." {
treePath = ""
}
return &getCommitInfoState{
entries: entriesByPath,
commits: make(map[string]*Commit, len(entriesByPath)),
treePath: treePath,
headCommit: headCommit,
nextSearchSize: 16,
}
}
// GetCommitsInfo gets information of all commits that are corresponding to these entries
func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) { func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) {
state := initGetCommitInfoState(tes, commit, treePath) return tes.GetCommitsInfoWithCustomConcurrency(commit, treePath, 0)
if err := getCommitsInfo(state); err != nil {
return nil, err
} }
commitsInfo := make([][]interface{}, len(tes)) // GetCommitsInfoWithCustomConcurrency takes advantages of concurrency to speed up getting information
for i, entry := range tes { // of all commits that are corresponding to these entries. If the given maxConcurrency is negative or
commit = state.commits[path.Join(treePath, entry.Name())] // equal to zero: the right number of goroutine (concurrency) to use will be chosen related of the
switch entry.Type { // host CPU.
case ObjectCommit: func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath string, maxConcurrency int) ([][]interface{}, error) {
subModuleURL := "" if len(tes) == 0 {
if subModule, err := state.headCommit.GetSubModule(entry.Name()); err != nil { return nil, nil
return nil, err
} else if subModule != nil {
subModuleURL = subModule.URL
}
subModuleFile := NewSubModuleFile(commit, subModuleURL, entry.ID.String())
commitsInfo[i] = []interface{}{entry, subModuleFile}
default:
commitsInfo[i] = []interface{}{entry, commit}
}
}
return commitsInfo, nil
} }
func (state *getCommitInfoState) nextCommit(hash string) { if maxConcurrency <= 0 {
state.lastCommitHash = hash maxConcurrency = runtime.NumCPU()
state.lastCommit = nil
} }
func (state *getCommitInfoState) commit() (*Commit, error) { // Length of taskChan determines how many goroutines (subprocesses) can run at the same time.
var err error // The length of revChan should be same as taskChan so goroutines whoever finished job can
if state.lastCommit == nil { // exit as early as possible, only store data inside channel.
state.lastCommit, err = state.headCommit.repo.GetCommit(state.lastCommitHash) taskChan := make(chan bool, maxConcurrency)
} revChan := make(chan commitInfo, maxConcurrency)
return state.lastCommit, err doneChan := make(chan error)
}
func (state *getCommitInfoState) update(entryPath string) error { // Receive loop will exit when it collects same number of data pieces as tree entries.
var entryNameStartIndex int // It notifies doneChan before exits or notify early with possible error.
if len(state.treePath) > 0 { infoMap := make(map[string][]interface{}, len(tes))
entryNameStartIndex = len(state.treePath) + 1 go func() {
i := 0
for info := range revChan {
if info.err != nil {
doneChan <- info.err
return
} }
if index := strings.IndexByte(entryPath[entryNameStartIndex:], '/'); index >= 0 { infoMap[info.entryName] = info.infos
entryPath = entryPath[:entryNameStartIndex+index] i++
if i == len(tes) {
break
} }
if _, ok := state.entries[entryPath]; !ok {
return nil
} else if _, ok := state.commits[entryPath]; ok {
return nil
} }
doneChan <- nil
}()
var err error for i := range tes {
state.commits[entryPath], err = state.commit() // When taskChan is idle (or has empty slots), put operation will not block.
return err // However when taskChan is full, code will block and wait any running goroutines to finish.
} taskChan <- true
func getCommitsInfo(state *getCommitInfoState) error { if tes[i].Type != ObjectCommit {
for len(state.entries) > len(state.commits) { go func(i int) {
if err := getNextCommitInfos(state); err != nil { cinfo := commitInfo{entryName: tes[i].Name()}
return err c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name()))
}
}
return nil
}
func getNextCommitInfos(state *getCommitInfoState) error {
logOutput, err := logCommand(state.lastCommitHash, state).RunInDir(state.headCommit.repo.Path)
if err != nil { if err != nil {
return err cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err)
} } else {
lines := strings.Split(logOutput, "\n") cinfo.infos = []interface{}{tes[i], c}
i := 0
for i < len(lines) {
state.nextCommit(lines[i])
i++
for ; i < len(lines); i++ {
entryPath := lines[i]
if entryPath == "" {
break
}
if entryPath[0] == '"' {
entryPath, err = strconv.Unquote(entryPath)
if err != nil {
return fmt.Errorf("Unquote: %v", err)
}
}
if err = state.update(entryPath); err != nil {
return err
} }
revChan <- cinfo
<-taskChan // Clear one slot from taskChan to allow new goroutines to start.
}(i)
continue
} }
i++ // skip blank line
if len(state.entries) == len(state.commits) { // Handle submodule
break go func(i int) {
} cinfo := commitInfo{entryName: tes[i].Name()}
sm, err := commit.GetSubModule(path.Join(treePath, tes[i].Name()))
if err != nil && !IsErrNotExist(err) {
cinfo.err = fmt.Errorf("GetSubModule (%s/%s): %v", treePath, tes[i].Name(), err)
revChan <- cinfo
return
} }
return nil
smURL := ""
if sm != nil {
smURL = sm.URL
} }
func logCommand(exclusiveStartHash string, state *getCommitInfoState) *Command { c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name()))
var commitHash string if err != nil {
if len(exclusiveStartHash) == 0 { cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err)
commitHash = state.headCommit.ID.String()
} else { } else {
commitHash = exclusiveStartHash + "^" cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smURL, tes[i].ID.String())}
} }
var command *Command revChan <- cinfo
numRemainingEntries := len(state.entries) - len(state.commits) <-taskChan
if numRemainingEntries < 32 { }(i)
searchSize := (numRemainingEntries + 1) / 2
command = NewCommand("log", prettyLogFormat, "--name-only",
"-"+strconv.Itoa(searchSize), commitHash, "--")
for entryPath := range state.entries {
if _, ok := state.commits[entryPath]; !ok {
command.AddArguments(entryPath)
} }
if err := <-doneChan; err != nil {
return nil, err
} }
} else {
command = NewCommand("log", prettyLogFormat, "--name-only", commitsInfo := make([][]interface{}, len(tes))
"-"+strconv.Itoa(state.nextSearchSize), commitHash, "--", state.treePath) for i := 0; i < len(tes); i++ {
commitsInfo[i] = infoMap[tes[i].Name()]
} }
state.nextSearchSize += state.nextSearchSize return commitsInfo, nil
return command
} }

@ -3,10 +3,10 @@
"ignore": "test appengine", "ignore": "test appengine",
"package": [ "package": [
{ {
"checksumSHA1": "Ju4zZF8u/DPrZYEEY40rogh3hyQ=", "checksumSHA1": "bjwnhCgzLl8EtrjX+vsz7POSaWw=",
"path": "code.gitea.io/git", "path": "code.gitea.io/git",
"revision": "51eca9e92242b93a0510edd19f1db6fc11ca1028", "revision": "7c4fc4e5ca3aab313bbe68b4b19ca253830bc60f",
"revisionTime": "2017-06-21T01:06:07Z" "revisionTime": "2017-06-28T06:06:37Z"
}, },
{ {
"checksumSHA1": "nLhT+bLMj8uLICP+EZbrdoQe6mM=", "checksumSHA1": "nLhT+bLMj8uLICP+EZbrdoQe6mM=",

Loading…
Cancel
Save