Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Fix retrieve file last commit branchName #98

Merged
merged 4 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions commit_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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{}{}
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branch name seems redundant here, a commit is enough to identify an entity in a repository. Also changing this signature needlessly changes API of the module

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, sometimes when calling this function there won't be a branch (e.g. viewing the source tree at a particular commit)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it revision like git does https://git-scm.com/docs/gitrevisions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strk maybe right. HEAD -> commit.ID.String(). I will fix this.

state := initGetCommitInfoState(tes, commit, branchName, treePath)
if err := getCommitsInfo(state); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion commit_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down