git/GitOid.st
author vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
Mon, 10 Sep 2012 10:32:46 +0000
changeset 2 9731a2e41428
parent 0 71c763bbb4bc
child 3 2a4bf4fb54d8
permissions -rw-r--r--
- More API methods...

"{ Package: 'stx:libscm/git' }"

ByteArray variableByteSubclass:#GitOid
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Git-Model'
!


!GitOid class methodsFor:'instance creation'!

fromString: aString
    | sz oid s hi lo |

    sz := aString size.
    sz ~~ 40 ifTrue:[
        self error:'Not a SHA-1 hex string (must have 40 chars)'.
        ^nil
    ].
    oid := self new.
    s := aString readStream.
    1 to: 20 do: [ :idx |
        hi := s next digitValue.
        lo := s next digitValue.
        oid at:idx put: ((hi bitShift:4) bitOr: lo)
    ].
    ^ oid

    "
    GitOid fromString: '7164acf359f5da8a4bc9cd3e03e2e461013c3811'
    "

    "Created: / 10-09-2012 / 10:49:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

new
    ^self new: self structSize

    "Created: / 10-09-2012 / 10:42:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

new: size
    size ~~ "self structSize"20 ifTrue:[
        self error: 'Size GitOid must be exactly 20 bytes, its a SHA-1 hash'.
        ^nil.
    ].
    ^super new: size

    "Created: / 10-09-2012 / 10:44:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GitOid class methodsFor:'accessing'!

libraryName

    OperatingSystem isUNIXlike ifTrue:[^'libgit2.so'].

    OperatingSystem isMSWINDOWSlike ifTrue:[^'git2.dll'].

    self error:'Library name for host OS is not known'
!

structSize
    "Returns size of undelaying structure in bytes"

    ^20
! !

!GitOid class methodsFor:'documentation'!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !