@@ -7,21 +7,30 @@ class GitTagNameDoesNotExist< StandardError
7
7
class Object
8
8
9
9
class AbstractObject
10
- attr_accessor :sha , :size , :type , :mode
10
+ attr_accessor :objectish , :size , :type , :mode
11
11
12
12
@base = nil
13
13
@contents = nil
14
+ @size = nil
15
+ @sha = nil
14
16
15
- def initialize ( base , sha )
17
+ def initialize ( base , objectish )
16
18
@base = base
17
- @sha = sha . to_s
18
- @size = @base . lib . object_size ( @sha )
19
+ @objectish = objectish . to_s
19
20
setup
20
21
end
21
-
22
+
23
+ def sha
24
+ @sha || @sha = @base . lib . revparse ( @objectish )
25
+ end
26
+
27
+ def size
28
+ @size || @size = @base . lib . object_size ( @objectish )
29
+ end
30
+
22
31
# caches the contents of this call in memory
23
32
def contents
24
- @contents || @contents = @base . lib . object_contents ( @sha )
33
+ @contents || @contents = @base . lib . object_contents ( @objectish )
25
34
end
26
35
27
36
def contents_array
@@ -33,26 +42,26 @@ def setup
33
42
end
34
43
35
44
def to_s
36
- @ sha
45
+ sha
37
46
end
38
47
39
48
def grep ( string , path_limiter = nil , opts = { } )
40
- default = { :object => @ sha, :path_limiter => path_limiter }
49
+ default = { :object => sha , :path_limiter => path_limiter }
41
50
grep_options = default . merge ( opts )
42
51
@base . lib . grep ( string , grep_options )
43
52
end
44
53
45
54
def diff ( objectish )
46
- Git ::Diff . new ( @base , @sha , objectish )
55
+ Git ::Diff . new ( @base , @objectish , objectish )
47
56
end
48
57
49
58
def log ( count = 30 )
50
- Git ::Log . new ( @base , count ) . object ( @sha )
59
+ Git ::Log . new ( @base , count ) . object ( @objectish )
51
60
end
52
61
53
62
# creates an archive of this object (tree)
54
63
def archive ( file = nil , opts = { } )
55
- @base . lib . archive ( @sha , file , opts )
64
+ @base . lib . archive ( @objectish , file , opts )
56
65
end
57
66
58
67
def tree?
@@ -126,7 +135,7 @@ def check_tree
126
135
if !@trees
127
136
@trees = { }
128
137
@blobs = { }
129
- data = @base . lib . ls_tree ( @sha )
138
+ data = @base . lib . ls_tree ( @objectish )
130
139
data [ 'tree' ] . each { |k , d | @trees [ k ] = Tree . new ( @base , d [ :sha ] , d [ :mode ] ) }
131
140
data [ 'blob' ] . each { |k , d | @blobs [ k ] = Blob . new ( @base , d [ :sha ] , d [ :mode ] ) }
132
141
end
@@ -148,7 +157,7 @@ def message
148
157
end
149
158
150
159
def name
151
- @base . lib . namerev ( @ sha)
160
+ @base . lib . namerev ( sha )
152
161
end
153
162
154
163
def gtree
@@ -200,7 +209,7 @@ def setup
200
209
# see if this object has been initialized and do so if not
201
210
def check_commit
202
211
if !@tree
203
- data = @base . lib . commit_data ( @sha )
212
+ data = @base . lib . commit_data ( @objectish )
204
213
@committer = Git ::Author . new ( data [ 'committer' ] )
205
214
@author = Git ::Author . new ( data [ 'author' ] )
206
215
@tree = Tree . new ( @base , data [ 'tree' ] )
@@ -230,16 +239,17 @@ def setup
230
239
class << self
231
240
# if we're calling this, we don't know what type it is yet
232
241
# so this is our little factory method
233
- def new ( base , objectish , is_tag = false )
242
+ def new ( base , objectish , type = nil , is_tag = false )
234
243
if is_tag
235
244
sha = base . lib . tag_sha ( objectish )
236
245
if sha == ''
237
246
raise Git ::GitTagNameDoesNotExist . new ( objectish )
238
247
end
239
248
return Tag . new ( base , sha , objectish )
240
249
else
241
- sha = base . lib . revparse ( objectish )
242
- type = base . lib . object_type ( sha )
250
+ if !type
251
+ type = base . lib . object_type ( objectish )
252
+ end
243
253
end
244
254
245
255
klass =
@@ -248,7 +258,7 @@ def new(base, objectish, is_tag = false)
248
258
when /commit/ : Commit
249
259
when /tree/ : Tree
250
260
end
251
- klass ::new ( base , sha )
261
+ klass ::new ( base , objectish )
252
262
end
253
263
end
254
264
0 commit comments