grit 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grit might be problematic. Click here for more details.
- data/History.txt +9 -0
- data/README.md +37 -11
- data/VERSION.yml +3 -3
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +14 -0
- data/lib/grit.rb +10 -3
- data/lib/grit/actor.rb +5 -5
- data/lib/grit/blob.rb +12 -12
- data/lib/grit/commit.rb +3 -3
- data/lib/grit/commit_stats.rb +26 -26
- data/lib/grit/config.rb +9 -9
- data/lib/grit/diff.rb +16 -16
- data/lib/grit/errors.rb +1 -1
- data/lib/grit/git-ruby.rb +108 -27
- data/lib/grit/git-ruby/commit_db.rb +11 -11
- data/lib/grit/git-ruby/file_index.rb +28 -28
- data/lib/grit/git-ruby/git_object.rb +14 -14
- data/lib/grit/git-ruby/internal/file_window.rb +4 -4
- data/lib/grit/git-ruby/internal/loose.rb +10 -10
- data/lib/grit/git-ruby/internal/pack.rb +29 -29
- data/lib/grit/git-ruby/internal/raw_object.rb +4 -4
- data/lib/grit/git-ruby/object.rb +9 -9
- data/lib/grit/git-ruby/repository.rb +111 -107
- data/lib/grit/git.rb +191 -14
- data/lib/grit/index.rb +21 -21
- data/lib/grit/lazy.rb +1 -1
- data/lib/grit/merge.rb +9 -9
- data/lib/grit/ref.rb +6 -31
- data/lib/grit/repo.rb +110 -65
- data/lib/grit/ruby1.9.rb +1 -1
- data/lib/grit/status.rb +24 -24
- data/lib/grit/submodule.rb +15 -15
- data/lib/grit/tag.rb +7 -57
- data/lib/grit/tree.rb +12 -12
- data/test/bench/benchmarks.rb +126 -0
- data/test/helper.rb +18 -0
- data/test/profile.rb +21 -0
- data/test/suite.rb +6 -0
- data/test/test_actor.rb +35 -0
- data/test/test_blame.rb +32 -0
- data/test/test_blame_tree.rb +33 -0
- data/test/test_blob.rb +83 -0
- data/test/test_commit.rb +207 -0
- data/test/test_commit_stats.rb +33 -0
- data/test/test_commit_write.rb +20 -0
- data/test/test_config.rb +58 -0
- data/test/test_diff.rb +18 -0
- data/test/test_file_index.rb +56 -0
- data/test/test_git.rb +105 -0
- data/test/test_grit.rb +32 -0
- data/test/test_head.rb +47 -0
- data/test/test_index_status.rb +40 -0
- data/test/test_merge.rb +17 -0
- data/test/test_raw.rb +16 -0
- data/test/test_real.rb +19 -0
- data/test/test_reality.rb +17 -0
- data/test/test_remote.rb +14 -0
- data/test/test_repo.rb +349 -0
- data/test/test_rubygit.rb +192 -0
- data/test/test_rubygit_alt.rb +40 -0
- data/test/test_rubygit_index.rb +76 -0
- data/test/test_rubygit_iv2.rb +28 -0
- data/test/test_submodule.rb +69 -0
- data/test/test_tag.rb +67 -0
- data/test/test_tree.rb +101 -0
- metadata +43 -13
data/lib/grit/submodule.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Grit
|
2
|
-
|
2
|
+
|
3
3
|
class Submodule
|
4
4
|
attr_reader :id
|
5
5
|
attr_reader :mode
|
6
6
|
attr_reader :name
|
7
|
-
|
7
|
+
|
8
8
|
# Create a Submodule containing just the specified attributes
|
9
9
|
# +repo+ is the Repo
|
10
10
|
# +atts+ is a Hash of instance variable data
|
@@ -13,7 +13,7 @@ module Grit
|
|
13
13
|
def self.create(repo, atts)
|
14
14
|
self.allocate.create_initialize(repo, atts)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Initializer for Submodule.create
|
18
18
|
# +repo+ is the Repo
|
19
19
|
# +atts+ is a Hash of instance variable data
|
@@ -26,23 +26,23 @@ module Grit
|
|
26
26
|
end
|
27
27
|
self
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# The url of this submodule
|
31
31
|
# +ref+ is the committish that should be used to look up the url
|
32
32
|
#
|
33
33
|
# Returns String
|
34
34
|
def url(ref)
|
35
35
|
config = self.class.config(@repo, ref)
|
36
|
-
|
36
|
+
|
37
37
|
lookup = config.keys.inject({}) do |acc, key|
|
38
38
|
id = config[key]['id']
|
39
39
|
acc[id] = config[key]['url']
|
40
40
|
acc
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
lookup[@id]
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
# The configuration information for the given +repo+
|
47
47
|
# +repo+ is the Repo
|
48
48
|
# +ref+ is the committish (defaults to 'master')
|
@@ -53,12 +53,12 @@ module Grit
|
|
53
53
|
commit = repo.commit(ref)
|
54
54
|
blob = commit.tree/'.gitmodules'
|
55
55
|
return {} unless blob
|
56
|
-
|
56
|
+
|
57
57
|
lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
|
58
|
-
|
58
|
+
|
59
59
|
config = {}
|
60
60
|
current = nil
|
61
|
-
|
61
|
+
|
62
62
|
lines.each do |line|
|
63
63
|
if line =~ /^\[submodule "(.+)"\]$/
|
64
64
|
current = $1
|
@@ -71,18 +71,18 @@ module Grit
|
|
71
71
|
# ignore
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
config
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def basename
|
79
79
|
File.basename(name)
|
80
|
-
end
|
81
|
-
|
80
|
+
end
|
81
|
+
|
82
82
|
# Pretty object inspection
|
83
83
|
def inspect
|
84
84
|
%Q{#<Grit::Submodule "#{@id}">}
|
85
85
|
end
|
86
86
|
end # Submodule
|
87
|
-
|
87
|
+
|
88
88
|
end # Grit
|
data/lib/grit/tag.rb
CHANGED
@@ -2,63 +2,13 @@ module Grit
|
|
2
2
|
|
3
3
|
class Tag < Ref
|
4
4
|
def self.find_all(repo, options = {})
|
5
|
-
refs =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
next if !File.file?(ref)
|
13
|
-
|
14
|
-
id = File.read(ref).chomp
|
15
|
-
name = ref.sub("#{prefix}/", '')
|
16
|
-
commit = commit_from_sha(repo, id)
|
17
|
-
|
18
|
-
if !already[name]
|
19
|
-
refs << self.new(name, commit)
|
20
|
-
already[name] = true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
if File.file?('packed-refs')
|
25
|
-
lines = File.readlines('packed-refs')
|
26
|
-
lines.each_with_index do |line, i|
|
27
|
-
if m = /^(\w{40}) (.*?)$/.match(line)
|
28
|
-
next if !Regexp.new('^' + prefix).match(m[2])
|
29
|
-
name = m[2].sub("#{prefix}/", '')
|
30
|
-
|
31
|
-
# Annotated tags in packed-refs include a reference
|
32
|
-
# to the commit object on the following line.
|
33
|
-
next_line = lines[i+1]
|
34
|
-
if next_line && next_line[0] == ?^
|
35
|
-
commit = Commit.create(repo, :id => next_line[1..-1].chomp)
|
36
|
-
else
|
37
|
-
commit = commit_from_sha(repo, m[1])
|
38
|
-
end
|
39
|
-
|
40
|
-
if !already[name]
|
41
|
-
refs << self.new(name, commit)
|
42
|
-
already[name] = true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
refs
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.commit_from_sha(repo, id)
|
53
|
-
git_ruby_repo = GitRuby::Repository.new(repo.path)
|
54
|
-
object = git_ruby_repo.get_object_by_sha1(id)
|
55
|
-
|
56
|
-
if object.type == :commit
|
57
|
-
Commit.create(repo, :id => id)
|
58
|
-
elsif object.type == :tag
|
59
|
-
Commit.create(repo, :id => object.object)
|
60
|
-
else
|
61
|
-
raise "Unknown object type."
|
5
|
+
refs = repo.git.refs(options, prefix)
|
6
|
+
refs.split("\n").map do |ref|
|
7
|
+
name, id = *ref.split(' ')
|
8
|
+
cid = repo.git.commit_from_sha(id)
|
9
|
+
raise "Unknown object type." if cid == ''
|
10
|
+
commit = Commit.create(repo, :id => cid)
|
11
|
+
self.new(name, commit)
|
62
12
|
end
|
63
13
|
end
|
64
14
|
end
|
data/lib/grit/tree.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Grit
|
2
|
-
|
2
|
+
|
3
3
|
class Tree
|
4
4
|
lazy_reader :contents
|
5
5
|
attr_reader :id
|
6
6
|
attr_reader :mode
|
7
7
|
attr_reader :name
|
8
|
-
|
8
|
+
|
9
9
|
# Construct the contents of the tree
|
10
10
|
# +repo+ is the Repo
|
11
11
|
# +treeish+ is the reference
|
@@ -16,12 +16,12 @@ module Grit
|
|
16
16
|
output = repo.git.ls_tree({}, treeish, *paths)
|
17
17
|
self.allocate.construct_initialize(repo, treeish, output)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def construct_initialize(repo, id, text)
|
21
21
|
@repo = repo
|
22
22
|
@id = id
|
23
23
|
@contents = []
|
24
|
-
|
24
|
+
|
25
25
|
text.split("\n").each do |line|
|
26
26
|
@contents << content_from_string(repo, line)
|
27
27
|
end
|
@@ -29,11 +29,11 @@ module Grit
|
|
29
29
|
|
30
30
|
self
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def lazy_source
|
34
34
|
Tree.construct(@repo, @id, [])
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# Create an unbaked Tree containing just the specified attributes
|
38
38
|
# +repo+ is the Repo
|
39
39
|
# +atts+ is a Hash of instance variable data
|
@@ -42,7 +42,7 @@ module Grit
|
|
42
42
|
def self.create(repo, atts)
|
43
43
|
self.allocate.create_initialize(repo, atts)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
# Initializer for Tree.create
|
47
47
|
# +repo+ is the Repo
|
48
48
|
# +atts+ is a Hash of instance variable data
|
@@ -50,13 +50,13 @@ module Grit
|
|
50
50
|
# Returns Grit::Tree (unbaked)
|
51
51
|
def create_initialize(repo, atts)
|
52
52
|
@repo = repo
|
53
|
-
|
53
|
+
|
54
54
|
atts.each do |k, v|
|
55
55
|
instance_variable_set("@#{k}", v)
|
56
56
|
end
|
57
57
|
self
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# Parse a content item and create the appropriate object
|
61
61
|
# +repo+ is the Repo
|
62
62
|
# +text+ is the single line containing the items data in `git ls-tree` format
|
@@ -77,7 +77,7 @@ module Grit
|
|
77
77
|
raise "Invalid type: #{type}"
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# Find the named object in this tree's contents
|
82
82
|
#
|
83
83
|
# Examples
|
@@ -94,11 +94,11 @@ module Grit
|
|
94
94
|
self.contents.find { |c| c.name == file }
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def basename
|
99
99
|
File.basename(name)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
# Pretty object inspection
|
103
103
|
def inspect
|
104
104
|
%Q{#<Grit::Tree "#{@id}">}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ruby-prof'
|
5
|
+
require 'memcache'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
gem 'grit', '=0.7.0'
|
9
|
+
#require '../../lib/grit'
|
10
|
+
|
11
|
+
def main
|
12
|
+
@wbare = File.expand_path(File.join('../../', 'test', 'dot_git'))
|
13
|
+
|
14
|
+
in_temp_dir do
|
15
|
+
#result = RubyProf.profile do
|
16
|
+
|
17
|
+
git = Grit::Repo.new('.')
|
18
|
+
puts Grit::VERSION
|
19
|
+
#Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
|
20
|
+
#Grit.debug = true
|
21
|
+
|
22
|
+
#pp Grit::GitRuby.cache_client.stats
|
23
|
+
|
24
|
+
commit1 = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
|
25
|
+
commit2 = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
|
26
|
+
|
27
|
+
Benchmark.bm(8) do |x|
|
28
|
+
|
29
|
+
run_code(x, 'packobj') do
|
30
|
+
@commit = git.commit('5e3ee1198672257164ce3fe31dea3e40848e68d5')
|
31
|
+
@tree = git.tree('cd7422af5a2e0fff3e94d6fb1a8fff03b2841881')
|
32
|
+
@blob = git.blob('4232d073306f01cf0b895864e5a5cfad7dd76fce')
|
33
|
+
@commit.parents[0].parents[0].parents[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
run_code(x, 'commits 1') do
|
37
|
+
git.commits.size
|
38
|
+
end
|
39
|
+
|
40
|
+
run_code(x, 'commits 2') do
|
41
|
+
log = git.commits('master', 15)
|
42
|
+
log.size
|
43
|
+
log.size
|
44
|
+
log.first
|
45
|
+
git.commits('testing').map { |c| c.message }
|
46
|
+
end
|
47
|
+
|
48
|
+
run_code(x, 'big revlist') do
|
49
|
+
c = git.commits('master', 200)
|
50
|
+
end
|
51
|
+
|
52
|
+
run_code(x, 'log') do
|
53
|
+
log = git.log('master')
|
54
|
+
log.size
|
55
|
+
log.size
|
56
|
+
log.first
|
57
|
+
end
|
58
|
+
|
59
|
+
run_code(x, 'diff') do
|
60
|
+
c = git.diff(commit1, commit2)
|
61
|
+
end
|
62
|
+
|
63
|
+
run_code(x, 'commit-diff') do
|
64
|
+
c = git.commit_diff(commit1)
|
65
|
+
end
|
66
|
+
|
67
|
+
run_code(x, 'heads') do
|
68
|
+
c = git.heads.collect { |b| b.commit.id }
|
69
|
+
end
|
70
|
+
|
71
|
+
# run_code(x, 'config', 100) do
|
72
|
+
# c = git.config['user.name']
|
73
|
+
# c = git.config['user.email']
|
74
|
+
# end
|
75
|
+
|
76
|
+
#run_code(x, 'commit count') do
|
77
|
+
# c = git.commit_count('testing')
|
78
|
+
#end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
#end
|
83
|
+
|
84
|
+
#printer = RubyProf::FlatPrinter.new(result)
|
85
|
+
#printer.print(STDOUT, 0)
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def run_code(x, name, times = 30)
|
94
|
+
x.report(name.ljust(12)) do
|
95
|
+
for i in 1..times do
|
96
|
+
yield i
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#end
|
101
|
+
|
102
|
+
# Print a graph profile to text
|
103
|
+
end
|
104
|
+
|
105
|
+
def new_file(name, contents)
|
106
|
+
File.open(name, 'w') do |f|
|
107
|
+
f.puts contents
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def in_temp_dir(remove_after = true)
|
113
|
+
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
|
114
|
+
tmp_path = File.join("/tmp/", filename)
|
115
|
+
FileUtils.mkdir(tmp_path)
|
116
|
+
Dir.chdir tmp_path do
|
117
|
+
FileUtils.cp_r(@wbare, File.join(tmp_path, '.git'))
|
118
|
+
yield tmp_path
|
119
|
+
end
|
120
|
+
puts tmp_path
|
121
|
+
#FileUtils.rm_r(tmp_path) if remove_after
|
122
|
+
end
|
123
|
+
|
124
|
+
main()
|
125
|
+
|
126
|
+
##pp Grit::GitRuby.cache_client.stats
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib grit])
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
gem "mocha", ">=0"
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
GRIT_REPO = File.join(File.dirname(__FILE__), *%w[..])
|
9
|
+
|
10
|
+
include Grit
|
11
|
+
|
12
|
+
def fixture(name)
|
13
|
+
File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
|
14
|
+
end
|
15
|
+
|
16
|
+
def absolute_project_path
|
17
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
18
|
+
end
|
data/test/profile.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib grit])
|
2
|
+
include Grit
|
3
|
+
|
4
|
+
def recurse(tree, indent = "")
|
5
|
+
tree.contents.each do |c|
|
6
|
+
case c
|
7
|
+
when Tree
|
8
|
+
# puts "#{indent}#{c.name} (#{c.id})"
|
9
|
+
recurse(c, indent + " ")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
10.times do
|
15
|
+
r = Repo.new("/Users/schacon/projects/ambition")
|
16
|
+
t = r.tree
|
17
|
+
|
18
|
+
recurse(t)
|
19
|
+
end
|
20
|
+
|
21
|
+
#500.times { puts `git --git-dir /Users/schacon/projects/ambition/.git ls-tree master` }
|
data/test/suite.rb
ADDED
data/test/test_actor.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestActor < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
# from_string
|
9
|
+
|
10
|
+
def test_from_string_should_separate_name_and_email
|
11
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
12
|
+
assert_equal "Tom Werner", a.name
|
13
|
+
assert_equal "tom@example.com", a.email
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_from_string_should_handle_just_name
|
17
|
+
a = Actor.from_string("Tom Werner")
|
18
|
+
assert_equal "Tom Werner", a.name
|
19
|
+
assert_equal nil, a.email
|
20
|
+
end
|
21
|
+
|
22
|
+
# inspect
|
23
|
+
|
24
|
+
def test_inspect
|
25
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
26
|
+
assert_equal %Q{#<Grit::Actor "Tom Werner <tom@example.com>">}, a.inspect
|
27
|
+
end
|
28
|
+
|
29
|
+
# to_s
|
30
|
+
|
31
|
+
def test_to_s_should_alias_name
|
32
|
+
a = Actor.from_string("Tom Werner <tom@example.com>")
|
33
|
+
assert_equal a.name, a.to_s
|
34
|
+
end
|
35
|
+
end
|