public
Description: Gitorious aims to provide a great way of doing distributed opensource code collaboration.
Homepage: http://gitorious.org/projects/gitorious
Clone URL: git://github.com/dysinger/gitorious.git
Search Repo:
updated vendor git lib
Johan Sørensen (author)
Sun Apr 06 09:27:31 -0700 2008
commit  10489d21e3a115fe345f1e9cc3fcdf95eb2c9a16
tree    cfc77de91450cab643b6191fcbb43511c35dfbaa
parent  77de21f9a57ac3ccaf3470e1d7270a71bc468a75
...
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"
...
2
3
4
 
5
6
7
...
20
21
22
 
23
24
25
...
2
3
4
5
6
7
8
...
21
22
23
24
25
26
27
0
@@ -2,6 +2,7 @@
0
 
0
 # core
0
 require 'fileutils'
0
+require 'time'
0
 
0
 # stdlib
0
 
0
@@ -20,6 +21,7 @@
0
 require 'grit/blob'
0
 require 'grit/actor'
0
 require 'grit/diff'
0
+require 'grit/config'
0
 require 'grit/repo'
0
 require 'grit/stats'
0
 
...
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
...
105
106
107
108
 
109
110
111
...
117
118
119
120
 
 
 
 
 
121
122
123
...
223
224
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
227
228
...
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
...
76
77
78
 
79
80
81
82
...
88
89
90
 
91
92
93
94
95
96
97
98
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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
@@ -105,7 +76,7 @@
0
     
0
     # Find all commits matching the given criteria.
0
     # +repo+ is the Repo
0
- # +ref+ is the ref from which to begin (SHA1 or name)
0
+ # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all
0
     # +options+ is a Hash of optional arguments to git
0
     # :max_count is the maximum number of commits to fetch
0
     # :skip is the number of commits to skip
0
@@ -117,7 +88,11 @@
0
       default_options = {:pretty => "raw"}
0
       actual_options = default_options.merge(options)
0
       
0
- output = repo.git.rev_list(actual_options, ref)
0
+ if ref
0
+ output = repo.git.rev_list(actual_options, ref)
0
+ else
0
+ output = repo.git.rev_list(actual_options.merge(:all => true))
0
+ end
0
       
0
       self.list_from_string(repo, output)
0
     end
0
@@ -223,6 +198,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
33
34
35
36
 
37
38
39
...
26
27
28
 
29
30
31
32
33
34
35
 
36
37
38
39
0
@@ -26,14 +26,14 @@
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+)/)
0
           m, b_mode = *lines.shift.match(/^new mode (\d+)/)
0
         end
0
         
0
- if lines. lines.first =~ /^diff --git/
0
+ if lines.empty? || lines.first =~ /^diff --git/
0
           diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
0
           next
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
 
 
...
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
0
@@ -1,54 +1,34 @@
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
+ def lazy_reader(*args)
0
+ args.each do |arg|
0
+ ivar = "@#{arg}"
0
+ define_method(arg) do
0
+ if instance_variables.include?(ivar)
0
+ val = instance_variable_get(ivar)
0
           return val if val
0
- self.__prebake__
0
- instance_variable_get("@#{arg}")
0
         end
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
...
89
90
91
 
92
93
94
95
 
 
96
97
98
...
253
254
255
256
257
258
259
260
 
261
262
263
...
265
266
267
268
269
270
271
272
 
273
274
275
...
303
304
305
 
 
 
 
306
307
308
...
89
90
91
92
93
94
 
 
95
96
97
98
99
...
254
255
256
 
 
 
 
 
257
258
259
260
...
262
263
264
 
 
 
 
 
265
266
267
268
...
296
297
298
299
300
301
302
303
304
305
0
@@ -89,10 +89,11 @@
0
     # Commits are returned in chronological order.
0
     # +start+ is the branch/commit name (default 'master')
0
     # +since+ is a string represeting a date/time
0
+ # +extra_options+ is a hash of extra options
0
     #
0
     # Returns Grit::Commit[] (baked)
0
- def commits_since(start = 'master', since = '1970-01-01')
0
- options = {:since => since}
0
+ def commits_since(start = 'master', since = '1970-01-01', extra_options = {})
0
+ options = {:since => since}.merge(extra_options)
0
       
0
       Commit.find_all(self, start, options)
0
     end
0
@@ -253,11 +254,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
@@ -265,11 +262,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
@@ -303,6 +296,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
...
12
13
14
 
 
 
...
12
13
14
15
16
17
0
@@ -12,4 +12,7 @@
0
      "django.middleware.common.CommonMiddleware",
0
      "django.contrib.sessions.middleware.SessionMiddleware",
0
      "django.contrib.auth.middleware.AuthenticationMiddleware",
0
+diff --git a/moo b/moo
0
+old mode 100755
0
+new mode 100644
...
 
 
...
1
2
0
@@ -1 +1,3 @@
0
+core.bare=false
0
+remote.origin.url=git://github.com/mojombo/grit.git
...
172
173
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
0
@@ -172,5 +172,27 @@
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' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
0
+ 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
0
+ 'authored_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
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
+ generated_hash = @c.to_hash
0
+ expected.keys.each do |exp_key|
0
+ assert_equal expected[exp_key], generated_hash[exp_key]
0
+ end
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
...
11
12
13
14
 
15
 
16
17
...
11
12
13
 
14
15
16
17
18
0
@@ -11,8 +11,9 @@
0
     output = fixture('diff_new_mode')
0
     
0
     diffs = Diff.list_from_string(@r, output)
0
- assert_equal 1, diffs.size
0
+ assert_equal 2, diffs.size
0
     assert_equal 10, diffs.first.diff.split("\n").size
0
+ assert_equal nil, diffs.last.diff
0
   end
0
 end
...
21
22
23
 
 
 
 
24
25
26
...
21
22
23
24
25
26
27
28
29
30
0
@@ -21,6 +21,10 @@
0
     assert_equal "\\'foo\\'", @git.e("'foo'")
0
   end
0
   
0
+ def test_method_missing
0
+ assert_match(/^git version [\w\.]*$/, @git.version)
0
+ end
0
+
0
   def test_transform_options
0
     assert_equal ["-s"], @git.transform_options({:s => true})
0
     assert_equal ["-s '5'"], @git.transform_options({:s => 5})
...
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.