From 6b88d9990d1c22a7e19619159db07810de01e747 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 Dec 2017 16:28:38 +0800 Subject: [PATCH 1/4] fix retrieve file last commit branchName --- commit_info.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/commit_info.go b/commit_info.go index 77fe53bdd..60b4c7c4b 100644 --- a/commit_info.go +++ b/commit_info.go @@ -35,6 +35,7 @@ type getCommitsInfoState struct { entries []*TreeEntry // set of filepaths to get info for entryPaths map[string]struct{} + branchName string treePath string headCommit *Commit @@ -79,7 +80,7 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { done <- nil return } - command := NewCommand("rev-list", "-1", "HEAD", "--", entryPath) + command := NewCommand("rev-list", "-1", state.branchName, "--", entryPath) output, err := command.RunInDir(state.headCommit.repo.Path) if err != nil { done <- err @@ -99,7 +100,7 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { } } -func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string) *getCommitsInfoState { +func initGetCommitInfoState(entries Entries, headCommit *Commit, branchName, treePath string) *getCommitsInfoState { entryPaths := make(map[string]struct{}, len(entries)) for _, entry := range entries { entryPaths[path.Join(treePath, entry.Name())] = struct{}{} @@ -112,14 +113,15 @@ func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string entryPaths: entryPaths, commits: make(map[string]*Commit, len(entries)), targetedPaths: make(map[string]struct{}, len(entries)), + branchName: branchName, treePath: treePath, headCommit: headCommit, } } // GetCommitsInfo gets information of all commits that are corresponding to these entries -func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) { - state := initGetCommitInfoState(tes, commit, treePath) +func (tes Entries) GetCommitsInfo(commit *Commit, branchName, treePath string) ([][]interface{}, error) { + state := initGetCommitInfoState(tes, commit, branchName, treePath) if err := getCommitsInfo(state); err != nil { return nil, err } From 4d666434b835911784cd707faec68826aa13c628 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 Dec 2017 16:31:21 +0800 Subject: [PATCH 2/4] fix test --- commit_info_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commit_info_test.go b/commit_info_test.go index 458c8e61b..62bad31a8 100644 --- a/commit_info_test.go +++ b/commit_info_test.go @@ -49,7 +49,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) { b.ResetTimer() b.Run(benchmark.name, func(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := entries.GetCommitsInfo(commit, "") + _, err := entries.GetCommitsInfo(commit, "master", "") if err != nil { b.Fatal(err) } From 5a4099ac061c7265ebfb4bc377477e035edb837a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 16 Dec 2017 12:59:46 +0800 Subject: [PATCH 3/4] fix the commit cache and git log with specify branch or commit --- commit_info.go | 14 +++++++------- commit_info_test.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/commit_info.go b/commit_info.go index 60b4c7c4b..f65071b84 100644 --- a/commit_info.go +++ b/commit_info.go @@ -35,7 +35,6 @@ type getCommitsInfoState struct { entries []*TreeEntry // set of filepaths to get info for entryPaths map[string]struct{} - branchName string treePath string headCommit *Commit @@ -80,7 +79,7 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { done <- nil return } - command := NewCommand("rev-list", "-1", state.branchName, "--", entryPath) + command := NewCommand("rev-list", "-1", state.headCommit.ID.String(), "--", entryPath) output, err := command.RunInDir(state.headCommit.repo.Path) if err != nil { done <- err @@ -91,7 +90,9 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { done <- err return } + state.lock.Lock() commit, err := state.headCommit.repo.getCommit(id) + state.lock.Unlock() if err != nil { done <- err return @@ -100,7 +101,7 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { } } -func initGetCommitInfoState(entries Entries, headCommit *Commit, branchName, treePath string) *getCommitsInfoState { +func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string) *getCommitsInfoState { entryPaths := make(map[string]struct{}, len(entries)) for _, entry := range entries { entryPaths[path.Join(treePath, entry.Name())] = struct{}{} @@ -113,15 +114,14 @@ func initGetCommitInfoState(entries Entries, headCommit *Commit, branchName, tre entryPaths: entryPaths, commits: make(map[string]*Commit, len(entries)), targetedPaths: make(map[string]struct{}, len(entries)), - branchName: branchName, treePath: treePath, headCommit: headCommit, } } // GetCommitsInfo gets information of all commits that are corresponding to these entries -func (tes Entries) GetCommitsInfo(commit *Commit, branchName, treePath string) ([][]interface{}, error) { - state := initGetCommitInfoState(tes, commit, branchName, treePath) +func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) { + state := initGetCommitInfoState(tes, commit, treePath) if err := getCommitsInfo(state); err != nil { return nil, err } @@ -194,7 +194,7 @@ func getCommitsInfo(state *getCommitsInfoState) error { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() - args := []string{"log", getCommitsInfoPretty, "--name-status", "-c"} + args := []string{"log", state.headCommit.ID.String(), getCommitsInfoPretty, "--name-status", "-c"} if len(state.treePath) > 0 { args = append(args, "--", state.treePath) } diff --git a/commit_info_test.go b/commit_info_test.go index 62bad31a8..458c8e61b 100644 --- a/commit_info_test.go +++ b/commit_info_test.go @@ -49,7 +49,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) { b.ResetTimer() b.Run(benchmark.name, func(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := entries.GetCommitsInfo(commit, "master", "") + _, err := entries.GetCommitsInfo(commit, "") if err != nil { b.Fatal(err) } From 14f6f47462a5fc7141c83d51359ab1681e358807 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 17 Dec 2017 19:36:13 +0800 Subject: [PATCH 4/4] remove unused lock --- commit_info.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/commit_info.go b/commit_info.go index f65071b84..106ebc618 100644 --- a/commit_info.go +++ b/commit_info.go @@ -90,9 +90,7 @@ func targetedSearch(state *getCommitsInfoState, done chan error) { done <- err return } - state.lock.Lock() commit, err := state.headCommit.repo.getCommit(id) - state.lock.Unlock() if err != nil { done <- err return