public
Fork of Caged/gitnub
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/dustin/gitnub.git
Search Repo:
Update grit to mojombo's latest
Caged (author)
Tue Apr 01 19:28:29 -0700 2008
commit  7942044256859e81e12ad8ebfd0ea310916ff5a9
tree    de0612e13b84b41917c5465390455987a38d4b6f
parent  ceda7cf41a1720008e7ecfd6b87dff6144ff0879
...
1
2
3
 
...
1
2
3
4
0
@@ -1,4 +1,5 @@
0
 coverage
0
 pkg
0
 doc
0
+test/specifics.rb
...
10
11
12
 
13
14
15
...
10
11
12
13
14
15
16
0
@@ -10,6 +10,7 @@
0
   p.description = p.paragraphs_of('README.txt', 2..2).join("\n\n")
0
   p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[2..-1].map { |u| u.strip }
0
   p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
0
+ p.extra_deps << ['mime-types']
0
 end
0
 
0
 desc "Open an irb session preloaded with this library"
...
1
2
3
4
5
6
7
8
...
35
36
37
38
39
40
41
42
43
44
...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
95
96
97
...
212
213
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
216
217
...
1
2
3
 
 
4
5
6
...
33
34
35
 
 
36
37
38
39
40
...
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
57
58
 
59
60
61
62
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
65
66
67
68
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
0
@@ -1,8 +1,6 @@
0
 module Grit
0
   
0
   class Commit
0
- include Lazy
0
-
0
     attr_reader :id
0
     lazy_reader :parents
0
     lazy_reader :tree
0
@@ -35,8 +33,6 @@
0
       @committed_date = committed_date
0
       @message = message.join("\n")
0
       @short_message = message[0] || ''
0
-
0
- __baked__
0
     end
0
     
0
     def id_abbrev
0
0
0
@@ -58,40 +54,15 @@
0
     #
0
     # Returns Grit::Commit (unbaked)
0
     def create_initialize(repo, atts)
0
- @repo = nil
0
- @id = nil
0
- @parents = nil
0
- @tree = nil
0
- @author = nil
0
- @authored_date = nil
0
- @committer = nil
0
- @committed_date = nil
0
- @message = nil
0
- @short_message = nil
0
- @__baked__ = nil
0
-
0
       @repo = repo
0
       atts.each do |k, v|
0
- instance_variable_set("@#{k}".to_sym, v)
0
+ instance_variable_set("@#{k}", v)
0
       end
0
       self
0
     end
0
     
0
- # Use the id of this instance to populate all of the other fields
0
- # when any of them are called.
0
- #
0
- # Returns nil
0
- def __bake__
0
- temp = self.class.find_all(@repo, @id, {:max_count => 1}).first
0
- @parents = temp.parents
0
- @tree = temp.tree
0
- @author = temp.author
0
- @authored_date = temp.authored_date
0
- @committer = temp.committer
0
- @committed_date = temp.committed_date
0
- @message = temp.message
0
- @short_message = temp.short_message
0
- nil
0
+ def lazy_source
0
+ self.class.find_all(@repo, @id, {:max_count => 1}).first
0
     end
0
     
0
     # Count the number of commits reachable from this ref
0
@@ -212,6 +183,25 @@
0
     def self.actor(line)
0
       m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/)
0
       [Actor.from_string(actor), Time.at(epoch.to_i)]
0
+ end
0
+
0
+ def to_hash
0
+ {
0
+ 'id' => id,
0
+ 'parents' => parents.map { |p| { 'id' => p.id } },
0
+ 'tree' => tree.id,
0
+ 'message' => message,
0
+ 'author' => {
0
+ 'name' => author.name,
0
+ 'email' => author.email
0
+ },
0
+ 'committer' => {
0
+ 'name' => committer.name,
0
+ 'email' => committer.email
0
+ },
0
+ 'authored_date' => authored_date.xmlschema,
0
+ 'committed_date' => committed_date.xmlschema,
0
+ }
0
     end
0
   end # Commit
0
   
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -1 +1,45 @@
0
+module Grit
0
+
0
+ class Config
0
+ def initialize(repo)
0
+ @repo = repo
0
+ end
0
+
0
+ def []=(key, value)
0
+ @repo.git.config({}, key, value)
0
+ @data = nil
0
+ end
0
+
0
+ def [](key)
0
+ data[key]
0
+ end
0
+
0
+ def fetch(key, default = nil)
0
+ data[key] || default || raise(IndexError.new("key not found"))
0
+ end
0
+
0
+ def keys
0
+ data.keys
0
+ end
0
+
0
+ protected
0
+ def data
0
+ @data ||= load_config
0
+ end
0
+
0
+ def load_config
0
+ hash = {}
0
+ config_lines.map do |line|
0
+ key, value = line.split(/=/, 2)
0
+ hash[key] = value
0
+ end
0
+ hash
0
+ end
0
+
0
+ def config_lines
0
+ @repo.git.config(:list => true).split(/\n/)
0
+ end
0
+ end # Config
0
+
0
+end # Grit
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@
0
       diffs = []
0
       
0
       while !lines.empty?
0
- m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(\S+) b/(\S+)$})
0
+ m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
0
         
0
         if lines.first =~ /^old mode/
0
           m, a_mode = *lines.shift.match(/^old mode (\d+)/)
...
 
1
2
 
3
4
5
6
7
 
8
9
 
 
10
11
12
13
14
15
16
17
 
 
18
 
19
20
21
 
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
 
 
 
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
...
1
2
 
3
4
 
 
 
 
5
6
 
7
8
9
 
 
 
 
 
 
 
10
11
12
13
14
 
 
15
16
17
 
 
 
18
 
 
 
 
 
 
 
 
 
19
20
21
22
23
24
25
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
0
@@ -1,54 +1,32 @@
0
+##
0
 # Allows attributes to be declared as lazy, meaning that they won't be
0
-# computed until they are asked for. Just mix this module in:
0
+# computed until they are asked for.
0
 #
0
-# class Foo
0
-# include Lazy
0
-# ...
0
-# end
0
+# Works by delegating each lazy_reader to a cached lazy_source method.
0
 #
0
-# To specify a lazy reader:
0
+# class Person
0
+# lazy_reader :eyes
0
 #
0
-# lazy_reader :att
0
-#
0
-# Then, define a method called __bake__ that computes all your lazy
0
-# attributes:
0
-#
0
-# def __bake__
0
-# @att = ...
0
+# def lazy_source
0
+# OpenStruct.new(:eyes => 2)
0
 # end
0
+# end
0
 #
0
-# If you happen to have already done all the hard work, you can mark an instance
0
-# as already baked by calling:
0
+# >> Person.new.eyes
0
+# => 2
0
 #
0
-# __baked__
0
-#
0
-# That's it! (Tom Preston-Werner: rubyisawesome.com)
0
 module Lazy
0
- module ClassMethods
0
- def lazy_reader(*args)
0
- args.each do |arg|
0
- define_method(arg) do
0
- val = instance_variable_get("@#{arg}")
0
- return val if val
0
- self.__prebake__
0
- instance_variable_get("@#{arg}")
0
- end
0
+ def lazy_reader(*args)
0
+ args.each do |arg|
0
+ ivar = "@#{arg}"
0
+ define_method(arg) do
0
+ val = instance_variable_get(ivar)
0
+ return val if val
0
+ instance_variable_set(ivar, (@lazy_source ||= lazy_source).send(arg))
0
       end
0
     end
0
   end
0
-
0
- def __prebake__
0
- return if @__baked__
0
- self.__bake__
0
- @__baked__ = true
0
- end
0
-
0
- def __baked__
0
- @__baked__ = true
0
- end
0
-
0
- def self.included(base)
0
- base.extend(ClassMethods)
0
- end
0
 end
0
+
0
+Object.extend Lazy unless Object.ancestors.include? Lazy
...
234
235
236
237
238
239
240
241
 
242
243
244
...
246
247
248
249
250
251
252
253
 
254
255
256
...
284
285
286
 
 
 
 
287
288
289
...
234
235
236
 
 
 
 
 
237
238
239
240
...
242
243
244
 
 
 
 
 
245
246
247
248
...
276
277
278
279
280
281
282
283
284
285
0
@@ -234,11 +234,7 @@
0
     #
0
     # Returns nothing
0
     def enable_daemon_serve
0
- if @bare
0
- FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
0
- else
0
- FileUtils.touch(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
0
- end
0
+ FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
0
     end
0
     
0
     # Disable git-daemon serving of this repository by ensuring there is no
0
@@ -246,11 +242,7 @@
0
     #
0
     # Returns nothing
0
     def disable_daemon_serve
0
- if @bare
0
- FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
0
- else
0
- FileUtils.rm_f(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
0
- end
0
+ FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
0
     end
0
     
0
     # The list of alternates for this repo
0
@@ -284,6 +276,10 @@
0
           f.write alts.join("\n")
0
         end
0
       end
0
+ end
0
+
0
+ def config
0
+ @config ||= Config.new(self)
0
     end
0
     
0
     # Pretty object inspection
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
29
30
31
32
33
34
35
36
37
38
 
39
40
41
42
43
44
 
 
45
46
47
48
...
60
61
62
63
64
65
66
67
 
68
69
70
...
1
2
3
 
 
4
5
6
7
8
 
 
 
 
 
9
10
11
12
13
...
22
23
24
 
25
26
27
28
29
 
30
31
32
33
 
 
 
34
35
36
37
38
39
...
51
52
53
 
 
54
55
 
56
57
58
59
0
@@ -1,18 +1,11 @@
0
 module Grit
0
   
0
   class Tree
0
- include Lazy
0
-
0
     lazy_reader :contents
0
     attr_reader :id
0
     attr_reader :mode
0
     attr_reader :name
0
     
0
- def initialize
0
- @contents = nil
0
- @__baked__ = nil
0
- end
0
-
0
     # Construct the contents of the tree
0
     # +repo+ is the Repo
0
     # +treeish+ is the reference
0
0
0
@@ -29,19 +22,17 @@
0
       @repo = repo
0
       @id = id
0
       @contents = []
0
- @__baked__ = nil
0
       
0
       text.split("\n").each do |line|
0
         @contents << content_from_string(repo, line)
0
       end
0
       @contents.compact!
0
- __baked__
0
+
0
       self
0
     end
0
     
0
- def __bake__
0
- temp = Tree.construct(@repo, @id, [])
0
- @contents = temp.contents
0
+ def lazy_source
0
+ Tree.construct(@repo, @id, [])
0
     end
0
     
0
     # Create an unbaked Tree containing just the specified attributes
0
0
@@ -60,11 +51,9 @@
0
     # Returns Grit::Tree (unbaked)
0
     def create_initialize(repo, atts)
0
       @repo = repo
0
- @contents = nil
0
- @__baked__ = nil
0
       
0
       atts.each do |k, v|
0
- instance_variable_set("@#{k}".to_sym, v)
0
+ instance_variable_set("@#{k}", v)
0
       end
0
       self
0
     end
...
 
 
...
1
2
0
@@ -1 +1,3 @@
0
+core.bare=false
0
+remote.origin.url=git://github.com/mojombo/grit.git
...
160
161
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
0
@@ -160,5 +160,24 @@
0
     @c = Commit.create(@r, :id => 'abc')
0
     assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
0
   end
0
+
0
+ # to_hash
0
+
0
+ def test_to_hash
0
+ @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
0
+
0
+ expected = {
0
+ 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
0
+ 'committed_date' => "2007-10-10T00:06:12-07:00",
0
+ 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
0
+ 'authored_date' => "2007-10-10T00:06:12-07:00",
0
+ 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
0
+ 'message' => "implement Grit#heads",
0
+ 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
0
+ 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017"
0
+ }
0
+
0
+ assert_equal expected, @c.to_hash
0
+ end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -1 +1,59 @@
0
+require File.dirname(__FILE__) + '/helper'
0
+
0
+class TestConfig < Test::Unit::TestCase
0
+ def setup
0
+ @r = Repo.new(GRIT_REPO)
0
+ end
0
+
0
+ # data
0
+
0
+ def test_bracketed_fetch
0
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
0
+
0
+ config = @r.config
0
+
0
+ assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"]
0
+ end
0
+
0
+ def test_bracketed_fetch_returns_nil
0
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
0
+
0
+ config = @r.config
0
+
0
+ assert_equal nil, config["unknown"]
0
+ end
0
+
0
+ def test_fetch
0
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
0
+
0
+ config = @r.config
0
+
0
+ assert_equal "false", config.fetch("core.bare")
0
+ end
0
+
0
+ def test_fetch_with_default
0
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
0
+
0
+ config = @r.config
0
+
0
+ assert_equal "default", config.fetch("unknown", "default")
0
+ end
0
+
0
+ def test_fetch_without_default_raises
0
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
0
+
0
+ config = @r.config
0
+
0
+ assert_raise(IndexError) do
0
+ config.fetch("unknown")
0
+ end
0
+ end
0
+
0
+ def test_set_value
0
+ Git.any_instance.expects(:config).with({}, 'unknown', 'default')
0
+
0
+ config = @r.config
0
+ config["unknown"] = "default"
0
+ end
0
+end
...
186
187
188
189
 
190
191
192
193
194
195
196
 
197
198
199
...
186
187
188
 
189
190
191
192
193
194
195
 
196
197
198
199
0
@@ -186,14 +186,14 @@
0
   # enable_daemon_serve
0
   
0
   def test_enable_daemon_serve
0
- FileUtils.expects(:touch).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
0
+ FileUtils.expects(:touch).with(File.join(@r.path, ', 'git-daemon-export-ok'))
0
     @r.enable_daemon_serve
0
   end
0
   
0
   # disable_daemon_serve
0
   
0
   def test_disable_daemon_serve
0
- FileUtils.expects(:rm_f).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
0
+ FileUtils.expects(:rm_f).with(File.join(@r.path, ', 'git-daemon-export-ok'))
0
     @r.disable_daemon_serve
0
   end
0
   

Comments

    No one has commented yet.