Skip to content

Commit 7f3410c

Browse files
committed
Fix test
1 parent f3cb4a3 commit 7f3410c

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

modules/git/object_format.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ package git
55

66
import (
77
"crypto/sha1"
8+
"encoding/hex"
9+
"fmt"
810
"regexp"
911
"strconv"
12+
"strings"
1013
)
1114

12-
// sha1Pattern can be used to determine if a string is an valid sha
13-
var sha1Pattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
14-
1515
type ObjectFormat interface {
1616
// Name returns the name of the object format
1717
Name() string
@@ -31,29 +31,36 @@ type ObjectFormat interface {
3131

3232
type Sha1ObjectFormatImpl struct{}
3333

34-
var (
35-
emptyObjectID = &Sha1Hash{}
36-
emptyTree = &Sha1Hash{
37-
0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
38-
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04,
39-
}
40-
)
41-
4234
func (Sha1ObjectFormatImpl) Name() string { return "sha1" }
4335
func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID {
44-
return emptyObjectID
36+
return &Sha1Hash{}
4537
}
4638

4739
func (Sha1ObjectFormatImpl) EmptyTree() ObjectID {
48-
return emptyTree
40+
return &Sha1Hash{
41+
0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60,
42+
0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04,
43+
}
4944
}
5045
func (Sha1ObjectFormatImpl) FullLength() int { return 40 }
46+
47+
// sha1Pattern can be used to determine if a string is an valid sha
48+
var sha1Pattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
49+
5150
func (Sha1ObjectFormatImpl) IsValid(objIDStr string) bool {
5251
return sha1Pattern.MatchString(objIDStr)
5352
}
5453

5554
func (h Sha1ObjectFormatImpl) NewIDFromString(objIDStr string) (ObjectID, error) {
56-
return genericIDFromString(h, objIDStr)
55+
objIDStr = strings.TrimSpace(objIDStr)
56+
if len(objIDStr) != h.FullLength() {
57+
return h.EmptyObjectID(), fmt.Errorf("length must be %d: %s", h.FullLength(), s)
58+
}
59+
b, err := hex.DecodeString(objIDStr)
60+
if err != nil {
61+
return h.EmptyObjectID(), err
62+
}
63+
return IDFromRaw(h, b)
5764
}
5865

5966
// ComputeHash compute the hash for a given ObjectType and content

modules/git/object_id.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/hex"
99
"errors"
1010
"fmt"
11-
"strings"
1211
)
1312

1413
type ObjectID interface {
@@ -69,18 +68,6 @@ func MustIDFromString(h ObjectFormat, s string) ObjectID {
6968
return MustID(h, b)
7069
}
7170

72-
func genericIDFromString(h ObjectFormat, s string) (ObjectID, error) {
73-
s = strings.TrimSpace(s)
74-
if len(s) != h.FullLength() {
75-
return h.EmptyObjectID(), fmt.Errorf("length must be %d: %s", h.FullLength(), s)
76-
}
77-
b, err := hex.DecodeString(s)
78-
if err != nil {
79-
return h.EmptyObjectID(), err
80-
}
81-
return IDFromRaw(h, b)
82-
}
83-
8471
func IDFromString(hexHash string) (ObjectID, error) {
8572
for _, objectFormat := range SupportedObjectFormats {
8673
if len(hexHash) == objectFormat.FullLength() {

services/repository/files/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
143143
t, err := NewTemporaryUploadRepository(ctx, repo)
144144
if err != nil {
145145
log.Error("%v", err)
146+
return nil, err
146147
}
147148
defer t.Close()
148149
hasOldBranch := true

services/repository/fork.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
7676
defaultBranch = opts.SingleBranch
7777
}
7878
repo := &repo_model.Repository{
79-
OwnerID: owner.ID,
80-
Owner: owner,
81-
OwnerName: owner.Name,
82-
Name: opts.Name,
83-
LowerName: strings.ToLower(opts.Name),
84-
Description: opts.Description,
85-
DefaultBranch: defaultBranch,
86-
IsPrivate: opts.BaseRepo.IsPrivate || opts.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate,
87-
IsEmpty: opts.BaseRepo.IsEmpty,
88-
IsFork: true,
89-
ForkID: opts.BaseRepo.ID,
79+
OwnerID: owner.ID,
80+
Owner: owner,
81+
OwnerName: owner.Name,
82+
Name: opts.Name,
83+
LowerName: strings.ToLower(opts.Name),
84+
Description: opts.Description,
85+
DefaultBranch: defaultBranch,
86+
IsPrivate: opts.BaseRepo.IsPrivate || opts.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate,
87+
IsEmpty: opts.BaseRepo.IsEmpty,
88+
IsFork: true,
89+
ForkID: opts.BaseRepo.ID,
90+
ObjectFormatName: opts.BaseRepo.ObjectFormatName,
9091
}
9192

9293
oldRepoPath := opts.BaseRepo.RepoPath()

0 commit comments

Comments
 (0)