author | vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177 |
Wed, 19 Sep 2012 01:08:21 +0000 | |
changeset 8 | 4275f357d3e8 |
parent 5 | 57c20a77e549 |
child 9 | 2783c9882d30 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:libscm/git' }" |
2 |
||
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
3 |
GitModel subclass:#GitRepository |
4 | 4 |
instanceVariableNames:'path workdir' |
0 | 5 |
classVariableNames:'' |
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
6 |
poolDictionaries:'GitObjectType' |
8
4275f357d3e8
- API fixes, more to come
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
5
diff
changeset
|
7 |
category:'SCM-Git-Model' |
0 | 8 |
! |
9 |
||
10 |
||
1 | 11 |
!GitRepository class methodsFor:'instance creation'! |
12 |
||
13 |
open: aString |
|
4 | 14 |
"Opens an existing git repository on given path" |
15 |
||
16 |
| ref | |
|
1 | 17 |
|
18 |
ref := ByteArray new: ExternalBytes sizeofPointer. |
|
4 | 19 |
GitError raiseIfError: (GitPrimitives prim_git_repository_open: ref path: aString). |
20 |
^self new |
|
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
21 |
setHandleFromRef:ref; |
4 | 22 |
setPath: aString; |
23 |
yourself |
|
1 | 24 |
|
25 |
"Created: / 07-09-2012 / 23:45:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
26 |
! ! |
|
27 |
||
0 | 28 |
!GitRepository class methodsFor:'accessing'! |
29 |
||
30 |
structSize |
|
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
31 |
"Returns size of undelaying structure in bytes" |
0 | 32 |
|
33 |
^0 |
|
34 |
! ! |
|
35 |
||
4 | 36 |
!GitRepository methodsFor:'accessing'! |
37 |
||
38 |
workdir |
|
39 |
"Get the path of the working directory for this repository or nil, if |
|
40 |
repository is bare" |
|
41 |
||
42 |
self isBare ifTrue: [ ^ nil ]. |
|
43 |
workdir isNil ifTrue:[ |
|
44 |
workdir := GitPrimitives prim_git_repository_workdir: self. |
|
45 |
workdir := workdir asFilename. |
|
46 |
]. |
|
47 |
^workdir |
|
48 |
||
49 |
"Created: / 10-09-2012 / 19:07:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
50 |
! |
|
51 |
||
52 |
workdir: aStringOrFilename update: aBoolean |
|
53 |
"Set the path of the working directory for this repository. |
|
54 |
if update is true, then create/update gitlink in workdir and set |
|
55 |
config 'core.worktree' (if workdir is not the parent of the |
|
56 |
.git directory)" |
|
57 |
||
58 |
GitError raiseIfError: |
|
59 |
(GitPrimitives prim_git_repository_set_workdir: self |
|
60 |
workdir: aStringOrFilename asString |
|
61 |
update_gitlink: (aBoolean ifTrue:[1] ifFalse:[0])). |
|
62 |
workdir := aStringOrFilename asFilename. |
|
63 |
||
64 |
"Created: / 10-09-2012 / 19:19:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
65 |
! ! |
|
66 |
||
67 |
!GitRepository methodsFor:'copying'! |
|
68 |
||
69 |
shallowCopy |
|
70 |
||
71 |
^self class open: path |
|
72 |
||
73 |
"Created: / 10-09-2012 / 19:04:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
74 |
! ! |
|
75 |
||
76 |
!GitRepository methodsFor:'initialization'! |
|
77 |
||
78 |
setPath: aString |
|
79 |
path := aString |
|
80 |
||
81 |
"Created: / 10-09-2012 / 19:05:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
82 |
! ! |
|
83 |
||
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
84 |
!GitRepository methodsFor:'initialization & release'! |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
85 |
|
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
86 |
free |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
87 |
handle notNil ifTrue:[ |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
88 |
GitPrimitives prim_git_object_free: handle. |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
89 |
handle := nil. |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
90 |
]. |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
91 |
|
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
92 |
"Created: / 17-09-2012 / 21:16:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
93 |
! ! |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
94 |
|
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
95 |
!GitRepository methodsFor:'lookup'! |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
96 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
97 |
lookup: oid |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
98 |
"Lookup an object with given OID" |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
99 |
^self lookup: oid type: OBJ_ANY |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
100 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
101 |
"Created: / 10-09-2012 / 10:53:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
102 |
! |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
103 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
104 |
lookup: oid type: typeId |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
105 |
"Lookup an object with given OID" |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
106 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
107 |
| ref err type obj | |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
108 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
109 |
oid class == GitOid ifFalse:[ |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
110 |
self error: 'Passed oid is not a GitOid'. |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
111 |
^nil. |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
112 |
]. |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
113 |
ref := ByteArray new: ExternalBytes sizeofPointer. |
8
4275f357d3e8
- API fixes, more to come
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
5
diff
changeset
|
114 |
err := GitPrimitives prim_git_object_lookup: ref repo: handle id: oid type: typeId. |
3
2a4bf4fb54d8
- Better error handling
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
2
diff
changeset
|
115 |
GitError raiseIfError: err. |
2a4bf4fb54d8
- Better error handling
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
2
diff
changeset
|
116 |
|
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
117 |
typeId == OBJ_ANY ifTrue:[ |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
118 |
obj := ExternalAddress new setAddressFromBytes:ref. |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
119 |
type := GitPrimitives prim_git_object_type: obj. |
3
2a4bf4fb54d8
- Better error handling
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
2
diff
changeset
|
120 |
] ifFalse:[ |
2a4bf4fb54d8
- Better error handling
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
2
diff
changeset
|
121 |
type := typeId. |
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
122 |
]. |
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
123 |
obj := GitObject newForType: type. |
8
4275f357d3e8
- API fixes, more to come
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
5
diff
changeset
|
124 |
^obj |
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
125 |
setHandleFromRef: ref; |
4 | 126 |
setOid: oid; |
127 |
setRepository: self; |
|
128 |
yourself |
|
2
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
129 |
|
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
130 |
"Created: / 10-09-2012 / 11:01:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
131 |
! ! |
9731a2e41428
- More API methods...
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
1
diff
changeset
|
132 |
|
5
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
133 |
!GitRepository methodsFor:'private-accessing'! |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
134 |
|
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
135 |
getHandleClass |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
136 |
^GitRepositoryHandle |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
137 |
|
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
138 |
"Created: / 17-09-2012 / 21:20:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
139 |
! ! |
57c20a77e549
- Refactored to use handles
vranyj1@bd9d3459-6c23-4dd9-91de-98eeebb81177
parents:
4
diff
changeset
|
140 |
|
4 | 141 |
!GitRepository methodsFor:'testing'! |
142 |
||
143 |
isBare |
|
144 |
"Check if a repository is bare" |
|
145 |
||
146 |
^(GitPrimitives prim_git_repository_is_bare: self) == 1 |
|
147 |
||
148 |
"Created: / 10-09-2012 / 19:11:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
149 |
! |
|
150 |
||
151 |
isEmpty |
|
152 |
"An empty repository has just been initialized and contains |
|
153 |
no commits." |
|
154 |
||
155 |
^(GitPrimitives prim_git_repository_is_empty: self) == 1 |
|
156 |
||
157 |
"Created: / 10-09-2012 / 19:12:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
158 |
! ! |
|
159 |
||
0 | 160 |
!GitRepository class methodsFor:'documentation'! |
161 |
||
162 |
version_SVN |
|
163 |
^ '$Id:: $' |
|
164 |
! ! |