Skip to content

Commit 5ee25dd

Browse files
committed
convenient blobId for byte array
1 parent 2f69aaf commit 5ee25dd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scala-git/src/main/scala/com/madgag/git/package.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.eclipse.jgit.api.Git
2424
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm
2525
import org.eclipse.jgit.diff._
2626
import org.eclipse.jgit.internal.storage.file.ObjectDirectory
27+
import org.eclipse.jgit.lib.Constants.OBJ_BLOB
2728
import org.eclipse.jgit.lib.ObjectInserter.Formatter
2829
import org.eclipse.jgit.lib.ObjectReader.OBJ_ANY
2930
import org.eclipse.jgit.lib._
@@ -42,7 +43,11 @@ package object git {
4243

4344
val ObjectFormatter = new Formatter
4445

45-
def storeBlob(bytes: Array[Byte])(implicit i: ObjectInserter): ObjectId = i.insert(Constants.OBJ_BLOB, bytes)
46+
implicit class RichByteArray(bytes: Array[Byte]) {
47+
lazy val blobId = ObjectFormatter.idFor(OBJ_BLOB, bytes)
48+
}
49+
50+
def storeBlob(bytes: Array[Byte])(implicit i: ObjectInserter): ObjectId = i.insert(OBJ_BLOB, bytes)
4651

4752
def storeBlob(text: String)(implicit i: ObjectInserter, charset: Charset): ObjectId = storeBlob(text.getBytes(charset))
4853

@@ -188,7 +193,7 @@ package object git {
188193

189194
def isDiffableType(side: Side) =
190195
// diffEntry.getMode(side) != FileMode.GITLINK &&
191-
diffEntry.getId(side) != null && diffEntry.getMode(side).getObjectType == Constants.OBJ_BLOB
196+
diffEntry.getId(side) != null && diffEntry.getMode(side).getObjectType == OBJ_BLOB
192197

193198
lazy val bothSidesDiffableType: Boolean = Side.values().map(isDiffableType).forall(d => d)
194199

0 commit comments

Comments
 (0)