git/GitRepository.st
changeset 16 83e178bfe891
parent 15 40921d056f87
child 18 d359fb6d415c
--- a/git/GitRepository.st	Mon Sep 24 22:43:25 2012 +0000
+++ b/git/GitRepository.st	Tue Sep 25 15:35:04 2012 +0000
@@ -1,6 +1,6 @@
 "{ Package: 'stx:libscm/git' }"
 
-GitModel subclass:#GitRepository
+GitLibraryObject subclass:#GitRepository
 	instanceVariableNames:'path workdir index'
 	classVariableNames:''
 	poolDictionaries:'GitObjectType GitStatusCodes'
@@ -63,6 +63,17 @@
 
 !GitRepository methodsFor:'accessing'!
 
+head
+    | ref err |
+    ref := ByteArray new: ExternalBytes sizeofPointer.
+    err := GitPrimitives prim_git_repository_head: ref repo: handle.
+    GitError raiseIfError: err.
+
+    ^GitReference new setHandleFromRef: ref
+
+    "Created: / 25-09-2012 / 10:48:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 workingCopy
     self isBare ifTrue:[
         GitError raiseErrorString: 'Repository is bare'.
@@ -97,6 +108,40 @@
     "Created: / 19-09-2012 / 09:48:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GitRepository methodsFor:'actions'!
+
+commit: message tree: tree parents: parents update: refOrNil commiter: commiterOrNil author: authorOrNil
+    | oid err committer author parentsA |
+
+    committer := commiterOrNil notNil 
+                    ifTrue:[committer copyNow]
+                    ifFalse:[GitCommitterQuery query copyNow].
+    author := commiterOrNil notNil
+                    ifTrue:[author]
+                    ifFalse:[committer copy].
+    parentsA := ByteArray new: (ExternalBytes sizeofPointer * parents size).
+    parents withIndexDo:[:each :idx|
+        parentsA pointerAt: (1 + ((idx - 1) * ExternalBytes sizeofPointer)) put: each getHandle.
+    ].
+    oid := GitOid new.
+
+    err := GitPrimitives prim_git_commit_create: oid 
+                                           repo: handle 
+                                     update_ref: (refOrNil notNil ifTrue:[refOrNil getHandle] ifFalse:[nil]) 
+                                         author: author getHandle
+                                      committer: committer getHandle
+                               message_encoding: 'utf-8'
+                                        message: message utf8Encoded
+                                           tree: tree getHandle
+                                   parent_count: parents size
+                                        parents: parentsA.
+    GitError raiseIfError: err.
+
+    ^self lookup: oid type: OBJ_COMMIT.
+
+    "Created: / 25-09-2012 / 14:51:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GitRepository methodsFor:'copying'!
 
 shallowCopy
@@ -237,6 +282,18 @@
 
 !GitRepository methodsFor:'testing'!
 
+headIsDetached
+    ^(GitPrimitives prim_git_repository_head_detached: handle) == 1
+
+    "Created: / 25-09-2012 / 11:06:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+headIsOrphan
+    ^(GitPrimitives prim_git_repository_head_orphan: handle) == 1
+
+    "Created: / 25-09-2012 / 11:06:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 isBare
     "Check if a repository is bare"