Commit 10489d21e3a115fe345f1e9cc3fcdf95eb2c9a16

updated vendor git lib

Commit diff

vendor/grit/.gitignore

 
11coverage
22pkg
33doc
4test/specifics.rb
toggle raw diff

vendor/grit/Rakefile

 
1010 p.description = p.paragraphs_of('README.txt', 2..2).join("\n\n")
1111 p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[2..-1].map { |u| u.strip }
1212 p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13 p.extra_deps << ['mime-types']
1314end
1415
1516desc "Open an irb session preloaded with this library"
toggle raw diff

vendor/grit/lib/grit.rb

 
22
33# core
44require 'fileutils'
5require 'time'
56
67# stdlib
78
2121require 'grit/blob'
2222require 'grit/actor'
2323require 'grit/diff'
24require 'grit/config'
2425require 'grit/repo'
2526require 'grit/stats'
2627
toggle raw diff

vendor/grit/lib/grit/commit.rb

 
11module Grit
22
33 class Commit
4 include Lazy
5
64 attr_reader :id
75 lazy_reader :parents
86 lazy_reader :tree
3333 @committed_date = committed_date
3434 @message = message.join("\n")
3535 @short_message = message[0] || ''
36
37 __baked__
3836 end
3937
4038 def id_abbrev
5454 #
5555 # Returns Grit::Commit (unbaked)
5656 def create_initialize(repo, atts)
57 @repo = nil
58 @id = nil
59 @parents = nil
60 @tree = nil
61 @author = nil
62 @authored_date = nil
63 @committer = nil
64 @committed_date = nil
65 @message = nil
66 @short_message = nil
67 @__baked__ = nil
68
6957 @repo = repo
7058 atts.each do |k, v|
71 instance_variable_set("@#{k}".to_sym, v)
59 instance_variable_set("@#{k}", v)
7260 end
7361 self
7462 end
7563
76 # Use the id of this instance to populate all of the other fields
77 # when any of them are called.
78 #
79 # Returns nil
80 def __bake__
81 temp = self.class.find_all(@repo, @id, {:max_count => 1}).first
82 @parents = temp.parents
83 @tree = temp.tree
84 @author = temp.author
85 @authored_date = temp.authored_date
86 @committer = temp.committer
87 @committed_date = temp.committed_date
88 @message = temp.message
89 @short_message = temp.short_message
90 nil
64 def lazy_source
65 self.class.find_all(@repo, @id, {:max_count => 1}).first
9166 end
9267
9368 # Count the number of commits reachable from this ref
7676
7777 # Find all commits matching the given criteria.
7878 # +repo+ is the Repo
79 # +ref+ is the ref from which to begin (SHA1 or name)
79 # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all
8080 # +options+ is a Hash of optional arguments to git
8181 # :max_count is the maximum number of commits to fetch
8282 # :skip is the number of commits to skip
8888 default_options = {:pretty => "raw"}
8989 actual_options = default_options.merge(options)
9090
91 output = repo.git.rev_list(actual_options, ref)
91 if ref
92 output = repo.git.rev_list(actual_options, ref)
93 else
94 output = repo.git.rev_list(actual_options.merge(:all => true))
95 end
9296
9397 self.list_from_string(repo, output)
9498 end
199199 m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/)
200200 [Actor.from_string(actor), Time.at(epoch.to_i)]
201201 end
202
203 def to_hash
204 {
205 'id' => id,
206 'parents' => parents.map { |p| { 'id' => p.id } },
207 'tree' => tree.id,
208 'message' => message,
209 'author' => {
210 'name' => author.name,
211 'email' => author.email
212 },
213 'committer' => {
214 'name' => committer.name,
215 'email' => committer.email
216 },
217 'authored_date' => authored_date.xmlschema,
218 'committed_date' => committed_date.xmlschema,
219 }
220 end
202221 end # Commit
203222
204223end # Grit
toggle raw diff

vendor/grit/lib/grit/config.rb

 
1module Grit
2
3 class Config
4 def initialize(repo)
5 @repo = repo
6 end
7
8 def []=(key, value)
9 @repo.git.config({}, key, value)
10 @data = nil
11 end
12
13 def [](key)
14 data[key]
15 end
16
17 def fetch(key, default = nil)
18 data[key] || default || raise(IndexError.new("key not found"))
19 end
20
21 def keys
22 data.keys
23 end
24
25 protected
26 def data
27 @data ||= load_config
28 end
29
30 def load_config
31 hash = {}
32 config_lines.map do |line|
33 key, value = line.split(/=/, 2)
34 hash[key] = value
35 end
36 hash
37 end
38
39 def config_lines
40 @repo.git.config(:list => true).split(/\n/)
41 end
42 end # Config
43
44end # Grit
toggle raw diff

vendor/grit/lib/grit/diff.rb

 
2626 diffs = []
2727
2828 while !lines.empty?
29 m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(\S+) b/(\S+)$})
29 m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
3030
3131 if lines.first =~ /^old mode/
3232 m, a_mode = *lines.shift.match(/^old mode (\d+)/)
3333 m, b_mode = *lines.shift.match(/^new mode (\d+)/)
3434 end
3535
36 if lines.first =~ /^diff --git/
36 if lines.empty? || lines.first =~ /^diff --git/
3737 diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
3838 next
3939 end
6767 end
6868 end # Diff
6969
70end # Grit
70end # Grit
toggle raw diff

vendor/grit/lib/grit/git.rb

 
7373 end
7474 end # Git
7575
76end # Grit
76end # Grit
toggle raw diff

vendor/grit/lib/grit/lazy.rb

 
1##
12# Allows attributes to be declared as lazy, meaning that they won't be
2# computed until they are asked for. Just mix this module in:
3# computed until they are asked for.
34#
4# class Foo
5# include Lazy
6# ...
7# end
8#
9# To specify a lazy reader:
10#
11# lazy_reader :att
5# Works by delegating each lazy_reader to a cached lazy_source method.
126#
13# Then, define a method called __bake__ that computes all your lazy
14# attributes:
7# class Person
8# lazy_reader :eyes
159#
16# def __bake__
17# @att = ...
10# def lazy_source
11# OpenStruct.new(:eyes => 2)
1812# end
13# end
1914#
20# If you happen to have already done all the hard work, you can mark an instance
21# as already baked by calling:
15# >> Person.new.eyes
16# => 2
2217#
23# __baked__
24#
25# That's it! (Tom Preston-Werner: rubyisawesome.com)
2618module Lazy
27 module ClassMethods
28 def lazy_reader(*args)
29 args.each do |arg|
30 define_method(arg) do
31 val = instance_variable_get("@#{arg}")
19 def lazy_reader(*args)
20 args.each do |arg|
21 ivar = "@#{arg}"
22 define_method(arg) do
23 if instance_variables.include?(ivar)
24 val = instance_variable_get(ivar)
3225 return val if val
33 self.__prebake__
34 instance_variable_get("@#{arg}")
3526 end
27 instance_variable_set(ivar, (@lazy_source ||= lazy_source).send(arg))
3628 end
3729 end
3830 end
39
40 def __prebake__
41 return if @__baked__
42 self.__bake__
43 @__baked__ = true
44 end
45
46 def __baked__
47 @__baked__ = true
48 end
49
50 def self.included(base)
51 base.extend(ClassMethods)
52 end
53end
31end
32
33Object.extend Lazy unless Object.ancestors.include? Lazy
toggle raw diff

vendor/grit/lib/grit/repo.rb

 
8989 # Commits are returned in chronological order.
9090 # +start+ is the branch/commit name (default 'master')
9191 # +since+ is a string represeting a date/time
92 # +extra_options+ is a hash of extra options
9293 #
9394 # Returns Grit::Commit[] (baked)
94 def commits_since(start = 'master', since = '1970-01-01')
95 options = {:since => since}
95 def commits_since(start = 'master', since = '1970-01-01', extra_options = {})
96 options = {:since => since}.merge(extra_options)
9697
9798 Commit.find_all(self, start, options)
9899 end
254254 #
255255 # Returns nothing
256256 def enable_daemon_serve
257 if @bare
258 FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
259 else
260 FileUtils.touch(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
261 end
257 FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
262258 end
263259
264260 # Disable git-daemon serving of this repository by ensuring there is no
262262 #
263263 # Returns nothing
264264 def disable_daemon_serve
265 if @bare
266 FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
267 else
268 FileUtils.rm_f(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
269 end
265 FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
270266 end
271267
272268 # The list of alternates for this repo
298298 end
299299 end
300300
301 def config
302 @config ||= Config.new(self)
303 end
304
301305 # Pretty object inspection
302306 def inspect
303307 %Q{#<Grit::Repo "#{@path}">}
toggle raw diff

vendor/grit/lib/grit/tree.rb

 
11module Grit
22
33 class Tree
4 include Lazy
5
64 lazy_reader :contents
75 attr_reader :id
86 attr_reader :mode
97 attr_reader :name
108
11 def initialize
12 @contents = nil
13 @__baked__ = nil
14 end
15
169 # Construct the contents of the tree
1710 # +repo+ is the Repo
1811 # +treeish+ is the reference
2222 @repo = repo
2323 @id = id
2424 @contents = []
25 @__baked__ = nil
2625
2726 text.split("\n").each do |line|
2827 @contents << content_from_string(repo, line)
2928 end
3029 @contents.compact!
31 __baked__
30
3231 self
3332 end
3433
35 def __bake__
36 temp = Tree.construct(@repo, @id, [])
37 @contents = temp.contents
34 def lazy_source
35 Tree.construct(@repo, @id, [])
3836 end
3937
4038 # Create an unbaked Tree containing just the specified attributes
5151 # Returns Grit::Tree (unbaked)
5252 def create_initialize(repo, atts)
5353 @repo = repo
54 @contents = nil
55 @__baked__ = nil
5654
5755 atts.each do |k, v|
58 instance_variable_set("@#{k}".to_sym, v)
56 instance_variable_set("@#{k}", v)
5957 end
6058 self
6159 end
100100 end
101101 end # Tree
102102
103end # Grit
103end # Grit
toggle raw diff

vendor/grit/test/fixtures/diff_new_mode

 
1212 "django.middleware.common.CommonMiddleware",
1313 "django.contrib.sessions.middleware.SessionMiddleware",
1414 "django.contrib.auth.middleware.AuthenticationMiddleware",
15diff --git a/moo b/moo
16old mode 100755
17new mode 100644
toggle raw diff

vendor/grit/test/fixtures/simple_config

 
1core.bare=false
2remote.origin.url=git://github.com/mojombo/grit.git
toggle raw diff

vendor/grit/test/test_commit.rb

 
172172 @c = Commit.create(@r, :id => 'abc')
173173 assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
174174 end
175
176 # to_hash
177
178 def test_to_hash
179 @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
180
181 expected = {
182 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
183 'committed_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
184 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
185 'authored_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
186 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
187 'message' => "implement Grit#heads",
188 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
189 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017"
190 }
191
192 generated_hash = @c.to_hash
193 expected.keys.each do |exp_key|
194 assert_equal expected[exp_key], generated_hash[exp_key]
195 end
196 end
175197end
toggle raw diff

vendor/grit/test/test_config.rb

 
1require File.dirname(__FILE__) + '/helper'
2
3class TestConfig < Test::Unit::TestCase
4 def setup
5 @r = Repo.new(GRIT_REPO)
6 end
7
8 # data
9
10 def test_bracketed_fetch
11 Git.any_instance.expects(:config).returns(fixture('simple_config'))
12
13 config = @r.config
14
15 assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"]
16 end
17
18 def test_bracketed_fetch_returns_nil
19 Git.any_instance.expects(:config).returns(fixture('simple_config'))
20
21 config = @r.config
22
23 assert_equal nil, config["unknown"]
24 end
25
26 def test_fetch
27 Git.any_instance.expects(:config).returns(fixture('simple_config'))
28
29 config = @r.config
30
31 assert_equal "false", config.fetch("core.bare")
32 end
33
34 def test_fetch_with_default
35 Git.any_instance.expects(:config).returns(fixture('simple_config'))
36
37 config = @r.config
38
39 assert_equal "default", config.fetch("unknown", "default")
40 end
41
42 def test_fetch_without_default_raises
43 Git.any_instance.expects(:config).returns(fixture('simple_config'))
44
45 config = @r.config
46
47 assert_raise(IndexError) do
48 config.fetch("unknown")
49 end
50 end
51
52 def test_set_value
53 Git.any_instance.expects(:config).with({}, 'unknown', 'default')
54
55 config = @r.config
56 config["unknown"] = "default"
57 end
58end
toggle raw diff

vendor/grit/test/test_diff.rb

 
1111 output = fixture('diff_new_mode')
1212
1313 diffs = Diff.list_from_string(@r, output)
14 assert_equal 1, diffs.size
14 assert_equal 2, diffs.size
1515 assert_equal 10, diffs.first.diff.split("\n").size
16 assert_equal nil, diffs.last.diff
1617 end
1718end
toggle raw diff

vendor/grit/test/test_git.rb

 
2121 assert_equal "\\'foo\\'", @git.e("'foo'")
2222 end
2323
24 def test_method_missing
25 assert_match(/^git version [\w\.]*$/, @git.version)
26 end
27
2428 def test_transform_options
2529 assert_equal ["-s"], @git.transform_options({:s => true})
2630 assert_equal ["-s '5'"], @git.transform_options({:s => 5})
5151 @git.expects(:execute).with("#{@git_bin_base} foo 'bar\\'s'")
5252 @git.foo({}, "bar's")
5353 end
54end
54end
55
toggle raw diff

vendor/grit/test/test_repo.rb

 
186186 # enable_daemon_serve
187187
188188 def test_enable_daemon_serve
189 FileUtils.expects(:touch).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
189 FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
190190 @r.enable_daemon_serve
191191 end
192192
193193 # disable_daemon_serve
194194
195195 def test_disable_daemon_serve
196 FileUtils.expects(:rm_f).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
196 FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
197197 @r.disable_daemon_serve
198198 end
199199
toggle raw diff