Skip to content

Commit e9aa027

Browse files
committed
fix
1 parent fd63b96 commit e9aa027

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

modules/git/pipeline/lfs_common.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package pipeline
5+
6+
import (
7+
"fmt"
8+
"time"
9+
10+
"code.gitea.io/gitea/modules/git"
11+
)
12+
13+
// LFSResult represents commits found using a provided pointer file hash
14+
type LFSResult struct {
15+
Name string
16+
SHA string
17+
Summary string
18+
When time.Time
19+
ParentHashes []git.ObjectID
20+
BranchName string
21+
FullCommitName string
22+
}
23+
24+
type lfsResultSlice []*LFSResult
25+
26+
func (a lfsResultSlice) Len() int { return len(a) }
27+
func (a lfsResultSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
28+
func (a lfsResultSlice) Less(i, j int) bool { return a[j].When.After(a[i].When) }
29+
30+
func lfsError(msg string, err error) error {
31+
return fmt.Errorf("LFS error occurred, %s: err: %w", msg, err)
32+
}

modules/git/pipeline/lfs.go renamed to modules/git/pipeline/lfs_gogit.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,17 @@ package pipeline
77

88
import (
99
"bufio"
10-
"fmt"
1110
"io"
1211
"sort"
1312
"strings"
1413
"sync"
15-
"time"
1614

1715
"code.gitea.io/gitea/modules/git"
18-
1916
gogit "github.com/go-git/go-git/v5"
2017
"github.com/go-git/go-git/v5/plumbing"
2118
"github.com/go-git/go-git/v5/plumbing/object"
2219
)
2320

24-
// LFSResult represents commits found using a provided pointer file hash
25-
type LFSResult struct {
26-
Name string
27-
SHA string
28-
Summary string
29-
When time.Time
30-
ParentHashes []git.ObjectID
31-
BranchName string
32-
FullCommitName string
33-
}
34-
35-
type lfsResultSlice []*LFSResult
36-
37-
func (a lfsResultSlice) Len() int { return len(a) }
38-
func (a lfsResultSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
39-
func (a lfsResultSlice) Less(i, j int) bool { return a[j].When.After(a[i].When) }
40-
4121
// FindLFSFile finds commits that contain a provided pointer file hash
4222
func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, error) {
4323
resultsMap := map[string]*LFSResult{}
@@ -51,7 +31,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
5131
All: true,
5232
})
5333
if err != nil {
54-
return nil, fmt.Errorf("Failed to get GoGit CommitsIter. Error: %w", err)
34+
return nil, lfsError("failed to get GoGit CommitsIter", err)
5535
}
5636

5737
err = commitsIter.ForEach(func(gitCommit *object.Commit) error {
@@ -85,7 +65,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
8565
return nil
8666
})
8767
if err != nil && err != io.EOF {
88-
return nil, fmt.Errorf("Failure in CommitIter.ForEach: %w", err)
68+
return nil, lfsError("failure in CommitIter.ForEach", err)
8969
}
9070

9171
for _, result := range resultsMap {
@@ -156,7 +136,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
156136
select {
157137
case err, has := <-errChan:
158138
if has {
159-
return nil, fmt.Errorf("Unable to obtain name for LFS files. Error: %w", err)
139+
return nil, lfsError("unable to obtain name for LFS files", err)
160140
}
161141
default:
162142
}

modules/git/pipeline/lfs_nogogit.go

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,14 @@ package pipeline
88
import (
99
"bufio"
1010
"bytes"
11-
"fmt"
1211
"io"
1312
"sort"
1413
"strings"
1514
"sync"
16-
"time"
1715

1816
"code.gitea.io/gitea/modules/git"
1917
)
2018

21-
// LFSResult represents commits found using a provided pointer file hash
22-
type LFSResult struct {
23-
Name string
24-
SHA string
25-
Summary string
26-
When time.Time
27-
ParentIDs []git.ObjectID
28-
BranchName string
29-
FullCommitName string
30-
}
31-
32-
type lfsResultSlice []*LFSResult
33-
34-
func (a lfsResultSlice) Len() int { return len(a) }
35-
func (a lfsResultSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
36-
func (a lfsResultSlice) Less(i, j int) bool { return a[j].When.After(a[i].When) }
37-
3819
// FindLFSFile finds commits that contain a provided pointer file hash
3920
func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, error) {
4021
resultsMap := map[string]*LFSResult{}
@@ -137,11 +118,11 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
137118
n += int64(count)
138119
if bytes.Equal(binObjectID, objectID.RawValue()) {
139120
result := LFSResult{
140-
Name: curPath + string(fname),
141-
SHA: curCommit.ID.String(),
142-
Summary: strings.Split(strings.TrimSpace(curCommit.CommitMessage), "\n")[0],
143-
When: curCommit.Author.When,
144-
ParentIDs: curCommit.Parents,
121+
Name: curPath + string(fname),
122+
SHA: curCommit.ID.String(),
123+
Summary: strings.Split(strings.TrimSpace(curCommit.CommitMessage), "\n")[0],
124+
When: curCommit.Author.When,
125+
ParentHashes: curCommit.Parents,
145126
}
146127
resultsMap[curCommit.ID.String()+":"+curPath+string(fname)] = &result
147128
} else if string(mode) == git.EntryModeTree.String() {
@@ -183,7 +164,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
183164

184165
for _, result := range resultsMap {
185166
hasParent := false
186-
for _, parentID := range result.ParentIDs {
167+
for _, parentID := range result.ParentHashes {
187168
if _, hasParent = resultsMap[parentID.String()+":"+result.Name]; hasParent {
188169
break
189170
}
@@ -240,7 +221,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
240221
select {
241222
case err, has := <-errChan:
242223
if has {
243-
return nil, fmt.Errorf("Unable to obtain name for LFS files. Error: %w", err)
224+
return nil, lfsError("unable to obtain name for LFS files", err)
244225
}
245226
default:
246227
}

0 commit comments

Comments
 (0)