Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 16b24f8

Browse files
committed
plumbing: add IsDelta method to ObjectType
ObjectType.IsDelta is a convenience function to match both offset and reference delta types.
1 parent 87413ce commit 16b24f8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

plumbing/format/packfile/delta_selector.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ func (dw *deltaSelector) fixAndBreakChains(objectsToPack []*ObjectToPack) error
9696
}
9797

9898
func (dw *deltaSelector) fixAndBreakChainsOne(objectsToPack map[plumbing.Hash]*ObjectToPack, otp *ObjectToPack) error {
99-
isDelta := otp.Object.Type() == plumbing.OFSDeltaObject ||
100-
otp.Object.Type() == plumbing.REFDeltaObject
101-
if !isDelta {
99+
if !otp.Object.Type().IsDelta() {
102100
return nil
103101
}
104102

@@ -141,9 +139,7 @@ func (dw *deltaSelector) restoreOriginal(otp *ObjectToPack) error {
141139
return nil
142140
}
143141

144-
isDelta := otp.Object.Type() == plumbing.OFSDeltaObject ||
145-
otp.Object.Type() == plumbing.REFDeltaObject
146-
if !isDelta {
142+
if !otp.Object.Type().IsDelta() {
147143
return nil
148144
}
149145

plumbing/object.go

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func (t ObjectType) Valid() bool {
8282
return t >= CommitObject && t <= REFDeltaObject
8383
}
8484

85+
// IsDelta returns true for any ObjectTyoe that represents a delta (i.e.
86+
// REFDeltaObject or OFSDeltaObject).
87+
func (t ObjectType) IsDelta() bool {
88+
return t == REFDeltaObject || t == OFSDeltaObject
89+
}
90+
8591
// ParseObjectType parses a string representation of ObjectType. It returns an
8692
// error on parse failure.
8793
func ParseObjectType(value string) (typ ObjectType, err error) {

0 commit comments

Comments
 (0)