Skip to content

Commit b98f37b

Browse files
committed
Follow wxiaoguang's suggestion
1 parent 7a5da47 commit b98f37b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/git/object_format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ var SupportedObjectFormats = []ObjectFormat{
8383
}
8484

8585
func ObjectFormatFromName(name string) ObjectFormat {
86+
if name == "" {
87+
return Sha1ObjectFormat
88+
}
8689
for _, objectFormat := range SupportedObjectFormats {
8790
if name == objectFormat.Name() {
8891
return objectFormat

modules/git/object_id.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ func (*Sha1Hash) Type() ObjectFormat { return Sha1ObjectFormat }
3636
var _ ObjectID = &Sha1Hash{}
3737

3838
// EmptyObjectID creates a new ObjectID from an object format hash name
39-
func EmptyObjectID(hash string) (ObjectID, error) {
40-
hash = strings.ToLower(hash)
39+
func EmptyObjectID(objectFormatName string) (ObjectID, error) {
40+
if objectFormatName == "" {
41+
return Sha1ObjectFormat.EmptyObjectID(), nil
42+
}
43+
objectFormatName = strings.ToLower(objectFormatName)
4144
for _, objectFormat := range SupportedObjectFormats {
42-
if objectFormat.Name() == hash {
45+
if objectFormat.Name() == objectFormatName {
4346
return objectFormat.EmptyObjectID(), nil
4447
}
4548
}

0 commit comments

Comments
 (0)