gash 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Rakefile +0 -1
- data/gash.gemspec +4 -4
- data/lib/gash.rb +87 -19
- metadata +3 -3
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/gash.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Gash-0.1.
|
2
|
+
# Gem::Specification for Gash-0.1.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: gash
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.1.
|
8
|
+
version: 0.1.2
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Magnus Holm
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
|
15
|
-
date: 2008-09-
|
15
|
+
date: 2008-09-28 00:00:00 +02:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: "
|
71
|
+
version: "1.2"
|
72
72
|
version:
|
73
73
|
requirements: []
|
74
74
|
|
data/lib/gash.rb
CHANGED
@@ -9,6 +9,9 @@ require 'delegate'
|
|
9
9
|
# * Gash can commit.
|
10
10
|
# * Gash will automatically create branches if they don't exists.
|
11
11
|
# * Gash only loads what it needs, so it handles large repos well.
|
12
|
+
# * Gash got {pretty good documentation}[http://dojo.rubyforge.org/gash].
|
13
|
+
# * Gash got {a bug tracker}[http://dojo.lighthouseapp.com/projects/17529-gash].
|
14
|
+
# * Gash is being {developed at GitHub}[http://github.com/judofyr/gash].
|
12
15
|
#
|
13
16
|
# Some of these "rules" might change it the future.
|
14
17
|
#
|
@@ -22,6 +25,11 @@ require 'delegate'
|
|
22
25
|
# also call those methods.
|
23
26
|
#
|
24
27
|
# <b>See also</b>: #new, #commit, Tree
|
28
|
+
#
|
29
|
+
# == Credits
|
30
|
+
#
|
31
|
+
# This code is based upon git-shelve[http://www.siebert-wd.de/projects/git-shelve],
|
32
|
+
# and is released under the same license; LGPL.
|
25
33
|
class Gash < SimpleDelegator
|
26
34
|
module Errors
|
27
35
|
# This error is raised when the Git-command fails.
|
@@ -59,14 +67,14 @@ class Gash < SimpleDelegator
|
|
59
67
|
|
60
68
|
# Converts the +value+ to a Tree or a Blob, using some rules:
|
61
69
|
#
|
62
|
-
#
|
70
|
+
# ==== If +value+ is already a Tree or a Blob:
|
63
71
|
#
|
64
72
|
# * If +value+ comes from another repo, we load it and return a deep copy.
|
65
73
|
# * If +value+ got no parent, we simply return the same tree.
|
66
74
|
# * If +value+'s parent is +self+, we also return the same tree.
|
67
75
|
# * If +value+'s parent is something else, we return a duplicated tree.
|
68
76
|
#
|
69
|
-
#
|
77
|
+
# ==== If it's something else:
|
70
78
|
#
|
71
79
|
# * If +value+ is a Hash, we create a Tree from it.
|
72
80
|
# * If it's not any of the former rules, we turn it into a string and create a Blob from it.
|
@@ -92,6 +100,36 @@ class Gash < SimpleDelegator
|
|
92
100
|
|
93
101
|
# A Tree is a Hash which can store other instances of Tree and Blob.
|
94
102
|
#
|
103
|
+
# == Special methods
|
104
|
+
#
|
105
|
+
# Internally, a tree is being stored like this:
|
106
|
+
#
|
107
|
+
# {
|
108
|
+
# "README" => blob,
|
109
|
+
# "examples" => {
|
110
|
+
# "test.rb" => blob,
|
111
|
+
# "yay.rb" => blob
|
112
|
+
# }
|
113
|
+
# }
|
114
|
+
#
|
115
|
+
# So you have to do <code>tree["examples"].delete("test.rb")</code> instead
|
116
|
+
# of <code>tree.delete("examples/test.rb")</code>. However, there are some
|
117
|
+
# methods which supports the slash. All of these will work:
|
118
|
+
#
|
119
|
+
# tree["examples/test.rb"]
|
120
|
+
# tree.fetch("examples/test.rb")
|
121
|
+
# tree["examples/another.rb"] = "Content"
|
122
|
+
# tree.store("examples/another.rb", "Content") # Exactly the same as above.
|
123
|
+
#
|
124
|
+
# tree["examples"]["test.rb"] # Or, you could use this
|
125
|
+
#
|
126
|
+
# == Documentation
|
127
|
+
#
|
128
|
+
# The point of Tree is that it should be as close to Hash as possible.
|
129
|
+
# Therefore, methods which behaves exactly equally in Gash and Hash will
|
130
|
+
# not be documentated below. Please see the Ruby documentation if you
|
131
|
+
# wonder what you can do.
|
132
|
+
#
|
95
133
|
# <b>See also</b>: Helpers, Blob
|
96
134
|
class Tree < Hash
|
97
135
|
include Helpers
|
@@ -111,14 +149,7 @@ class Gash < SimpleDelegator
|
|
111
149
|
# # do some other stuff...
|
112
150
|
# blob.load! # Load it now!
|
113
151
|
def [](key, lazy = nil)
|
114
|
-
ret =
|
115
|
-
key, rest = key.split("/", 2)
|
116
|
-
value = super(key)
|
117
|
-
return if value.nil?
|
118
|
-
value[rest]
|
119
|
-
else
|
120
|
-
super(key)
|
121
|
-
end
|
152
|
+
ret = fetch(key, default)
|
122
153
|
ensure
|
123
154
|
ret.load! if ret.respond_to?(:load!) && !lazy
|
124
155
|
end
|
@@ -158,7 +189,7 @@ class Gash < SimpleDelegator
|
|
158
189
|
keys = key.split("/")
|
159
190
|
name = keys.pop
|
160
191
|
keys.inject(self) do |memo, i|
|
161
|
-
memo[i] = Tree.new(:parent => self) unless memo.include?(i)
|
192
|
+
memo[i, not_changed] = Tree.new(:parent => self) unless memo.include?(i)
|
162
193
|
memo[i, true]
|
163
194
|
end[name, not_changed] = value
|
164
195
|
else
|
@@ -169,7 +200,8 @@ class Gash < SimpleDelegator
|
|
169
200
|
ensure
|
170
201
|
self.changed! unless not_changed
|
171
202
|
end
|
172
|
-
|
203
|
+
alias store []=
|
204
|
+
|
173
205
|
# Converts the tree to a Hash.
|
174
206
|
def to_hash
|
175
207
|
inject({}) do |memo, (key, value)|
|
@@ -177,17 +209,54 @@ class Gash < SimpleDelegator
|
|
177
209
|
memo
|
178
210
|
end
|
179
211
|
end
|
212
|
+
|
213
|
+
# :stopdoc:
|
214
|
+
def fetch(*args)
|
215
|
+
key = args.first.to_s
|
216
|
+
|
217
|
+
case args.length
|
218
|
+
when 1
|
219
|
+
r = true
|
220
|
+
when 2
|
221
|
+
r = false
|
222
|
+
default = args.last
|
223
|
+
else
|
224
|
+
raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
|
225
|
+
end
|
226
|
+
|
227
|
+
if key.include?("/")
|
228
|
+
key, rest = key.split("/", 2)
|
229
|
+
value = super(key)
|
230
|
+
value.fetch(rest)
|
231
|
+
else
|
232
|
+
super(key)
|
233
|
+
end
|
234
|
+
rescue IndexError => e
|
235
|
+
(r && raise(e)) || default
|
236
|
+
end
|
180
237
|
|
181
|
-
def
|
238
|
+
def delete(key)
|
239
|
+
super && changed!
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.[](*val)
|
182
243
|
new.merge!(Hash[*val])
|
183
244
|
end
|
245
|
+
|
246
|
+
def ==(other)
|
247
|
+
if other.is_a?(Tree) && sha1 && other.sha1
|
248
|
+
sha1 == other.sha1
|
249
|
+
else
|
250
|
+
super
|
251
|
+
end
|
252
|
+
end
|
184
253
|
|
185
|
-
def merge(hash)
|
254
|
+
def merge(hash)
|
186
255
|
tree = self.dup
|
187
256
|
tree.merge!(hash)
|
188
257
|
end
|
189
258
|
|
190
|
-
def merge!(hash)
|
259
|
+
def merge!(hash)
|
191
260
|
hash.each do |key, value|
|
192
261
|
self[key] = value
|
193
262
|
end
|
@@ -195,7 +264,7 @@ class Gash < SimpleDelegator
|
|
195
264
|
end
|
196
265
|
alias update merge!
|
197
266
|
|
198
|
-
def replace(hash)
|
267
|
+
def replace(hash)
|
199
268
|
if hash.is_a?(Gash::Tree)
|
200
269
|
super
|
201
270
|
else
|
@@ -203,6 +272,7 @@ class Gash < SimpleDelegator
|
|
203
272
|
merge!(hash)
|
204
273
|
end
|
205
274
|
end
|
275
|
+
# :startdoc:
|
206
276
|
end
|
207
277
|
|
208
278
|
# A Blob represent a string:
|
@@ -365,9 +435,7 @@ class Gash < SimpleDelegator
|
|
365
435
|
end
|
366
436
|
|
367
437
|
def git_tree(&blk)
|
368
|
-
git('ls-tree', '-r', '-t', @branch, '2>&1')
|
369
|
-
f.each_line(&blk)
|
370
|
-
end
|
438
|
+
git('ls-tree', '-r', '-t', @branch, '2>&1').each_line(&blk)
|
371
439
|
rescue Errors::Git
|
372
440
|
""
|
373
441
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-28 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: "
|
68
|
+
version: "1.2"
|
69
69
|
version:
|
70
70
|
requirements: []
|
71
71
|
|