Skip to content

Commit 40094a4

Browse files
committed
Update code.gitea.io/git
1 parent f605595 commit 40094a4

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

modules/git/commit_info.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,20 @@ func (state *getCommitsInfoState) getTargetedEntryPath() string {
7272
}
7373

7474
// repeatedly perform targeted searches for unpopulated entries
75-
func targetedSearch(state *getCommitsInfoState, done chan error) {
75+
func targetedSearch(state *getCommitsInfoState, done chan error, cache LastCommitCache) {
7676
for {
7777
entryPath := state.getTargetedEntryPath()
7878
if len(entryPath) == 0 {
7979
done <- nil
8080
return
8181
}
82+
if cache != nil {
83+
commit, err := cache.Get(state.headCommit.repo.Path, state.headCommit.ID.String(), entryPath)
84+
if err == nil && commit != nil {
85+
state.update(entryPath, commit)
86+
continue
87+
}
88+
}
8289
command := NewCommand("rev-list", "-1", state.headCommit.ID.String(), "--", entryPath)
8390
output, err := command.RunInDir(state.headCommit.repo.Path)
8491
if err != nil {
@@ -96,6 +103,9 @@ func targetedSearch(state *getCommitsInfoState, done chan error) {
96103
return
97104
}
98105
state.update(entryPath, commit)
106+
if cache != nil {
107+
cache.Put(state.headCommit.repo.Path, state.headCommit.ID.String(), entryPath, commit)
108+
}
99109
}
100110
}
101111

@@ -118,9 +128,9 @@ func initGetCommitInfoState(entries Entries, headCommit *Commit, treePath string
118128
}
119129

120130
// GetCommitsInfo gets information of all commits that are corresponding to these entries
121-
func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) {
131+
func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCommitCache) ([][]interface{}, error) {
122132
state := initGetCommitInfoState(tes, commit, treePath)
123-
if err := getCommitsInfo(state); err != nil {
133+
if err := getCommitsInfo(state, cache); err != nil {
124134
return nil, err
125135
}
126136
if len(state.commits) < len(state.entryPaths) {
@@ -188,7 +198,7 @@ func (state *getCommitsInfoState) update(entryPath string, commit *Commit) bool
188198

189199
const getCommitsInfoPretty = "--pretty=format:%H %ct %s"
190200

191-
func getCommitsInfo(state *getCommitsInfoState) error {
201+
func getCommitsInfo(state *getCommitsInfoState, cache LastCommitCache) error {
192202
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
193203
defer cancel()
194204

@@ -215,7 +225,7 @@ func getCommitsInfo(state *getCommitsInfoState) error {
215225
numThreads := runtime.NumCPU()
216226
done := make(chan error, numThreads)
217227
for i := 0; i < numThreads; i++ {
218-
go targetedSearch(state, done)
228+
go targetedSearch(state, done, cache)
219229
}
220230

221231
scanner := bufio.NewScanner(readCloser)

modules/git/repo_commit.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ func (repo *Repository) GetBranchCommitID(name string) (string, error) {
3232

3333
// GetTagCommitID returns last commit ID string of given tag.
3434
func (repo *Repository) GetTagCommitID(name string) (string, error) {
35-
return repo.GetRefCommitID(TagPrefix + name)
35+
stdout, err := NewCommand("rev-list", "-n", "1", name).RunInDir(repo.Path)
36+
if err != nil {
37+
if strings.Contains(err.Error(), "unknown revision or path") {
38+
return "", ErrNotExist{name, ""}
39+
}
40+
return "", err
41+
}
42+
return strings.TrimSpace(stdout), nil
3643
}
3744

3845
// parseCommitData parses commit information from the (uncompressed) raw
@@ -94,7 +101,11 @@ l:
94101
sig, err := newGPGSignatureFromCommitline(data, (nextline+1)+sigindex, true)
95102
if err == nil && sig != nil {
96103
// remove signature from commit message
97-
cm = cm[:sigindex-1]
104+
if sigindex == 0 {
105+
cm = ""
106+
} else {
107+
cm = cm[:sigindex-1]
108+
}
98109
commit.Signature = sig
99110
}
100111
}
@@ -146,13 +157,14 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
146157
func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
147158
if len(commitID) != 40 {
148159
var err error
149-
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
160+
actualCommitID, err := NewCommand("rev-parse", commitID).RunInDir(repo.Path)
150161
if err != nil {
151162
if strings.Contains(err.Error(), "unknown revision or path") {
152163
return nil, ErrNotExist{commitID, ""}
153164
}
154165
return nil, err
155166
}
167+
commitID = actualCommitID
156168
}
157169
id, err := NewIDFromString(commitID)
158170
if err != nil {

modules/git/repo_tag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func (repo *Repository) getTag(id SHA1) (*Tag, error) {
7676

7777
// GetTag returns a Git tag by given name.
7878
func (repo *Repository) GetTag(name string) (*Tag, error) {
79-
stdout, err := NewCommand("show-ref", "--tags", name).RunInDir(repo.Path)
79+
idStr, err := repo.GetTagCommitID(name)
8080
if err != nil {
8181
return nil, err
8282
}
8383

84-
id, err := NewIDFromString(strings.Split(stdout, " ")[0])
84+
id, err := NewIDFromString(idStr)
8585
if err != nil {
8686
return nil, err
8787
}

vendor/code.gitea.io/git/MAINTAINERS

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/git/cache.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# code.gitea.io/git v0.0.0-20190207030847-0aea7f12d36e
1+
# code.gitea.io/git v0.0.0-20190321155013-ec4d631f8de6
22
code.gitea.io/git
33
# code.gitea.io/sdk v0.0.0-20190321154058-a669487e86e0
44
code.gitea.io/sdk/gitea

0 commit comments

Comments
 (0)