mojombo-grit 0.9.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/API.txt +101 -0
  2. data/History.txt +38 -2
  3. data/README.md +210 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/grit.rb +13 -4
  6. data/lib/grit/blame.rb +61 -0
  7. data/lib/grit/blob.rb +11 -2
  8. data/lib/grit/commit.rb +44 -31
  9. data/lib/grit/commit_stats.rb +26 -2
  10. data/lib/grit/diff.rb +6 -6
  11. data/lib/grit/git-ruby.rb +4 -2
  12. data/lib/grit/git-ruby/file_index.rb +10 -3
  13. data/lib/grit/git-ruby/git_object.rb +9 -3
  14. data/lib/grit/git-ruby/internal/{mmap.rb → file_window.rb} +2 -2
  15. data/lib/grit/git-ruby/internal/loose.rb +6 -6
  16. data/lib/grit/git-ruby/internal/pack.rb +19 -19
  17. data/lib/grit/git-ruby/object.rb +8 -2
  18. data/lib/grit/git-ruby/repository.rb +11 -6
  19. data/lib/grit/git.rb +23 -10
  20. data/lib/grit/index.rb +12 -11
  21. data/lib/grit/merge.rb +45 -0
  22. data/lib/grit/ref.rb +20 -16
  23. data/lib/grit/repo.rb +59 -9
  24. data/lib/grit/ruby1.9.rb +7 -0
  25. data/lib/grit/submodule.rb +5 -1
  26. data/lib/grit/tag.rb +61 -66
  27. data/lib/grit/tree.rb +20 -1
  28. metadata +29 -47
  29. data/Manifest.txt +0 -71
  30. data/README.txt +0 -213
  31. data/Rakefile +0 -29
  32. data/grit.gemspec +0 -62
  33. data/lib/grit/head.rb +0 -83
  34. data/test/test_actor.rb +0 -35
  35. data/test/test_blob.rb +0 -79
  36. data/test/test_commit.rb +0 -190
  37. data/test/test_config.rb +0 -58
  38. data/test/test_diff.rb +0 -18
  39. data/test/test_git.rb +0 -64
  40. data/test/test_grit.rb +0 -32
  41. data/test/test_head.rb +0 -47
  42. data/test/test_real.rb +0 -19
  43. data/test/test_reality.rb +0 -17
  44. data/test/test_remote.rb +0 -14
  45. data/test/test_repo.rb +0 -277
  46. data/test/test_tag.rb +0 -25
  47. data/test/test_tree.rb +0 -96
data/Rakefile DELETED
@@ -1,29 +0,0 @@
1
- require 'rubygems'
2
- require 'hoe'
3
- require './lib/grit.rb'
4
-
5
- Hoe.new('grit', Grit::VERSION) do |p|
6
- p.author = 'Tom Preston-Werner'
7
- p.email = 'tom@rubyisawesome.com'
8
- p.summary = 'Object model interface to a git repo'
9
- p.description = p.paragraphs_of('README.txt', 2..2).join("\n\n")
10
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[2..-1].map { |u| u.strip }
11
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
12
- p.extra_deps << ['mime-types']
13
- end
14
-
15
- desc "Open an irb session preloaded with this library"
16
- task :console do
17
- sh "irb -rubygems -r ./lib/grit.rb"
18
- end
19
-
20
- task :coverage do
21
- system("rm -fr coverage")
22
- system("rcov test/test_*.rb")
23
- system("open coverage/index.html")
24
- end
25
-
26
- desc "Upload site to Rubyforge"
27
- task :site do
28
- sh "scp -r doc/* mojombo@grit.rubyforge.org:/var/www/gforge-projects/grit"
29
- end
@@ -1,62 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "grit"
3
- s.version = "0.9.4"
4
- s.date = "2008-11-07"
5
- s.summary = "Object model interface to a git repo"
6
- s.email = "tom@rubyisawesome.com"
7
- s.homepage = "http://github.com/mojombo/grit"
8
- s.description = "Grit is a Ruby library for extracting information from a git repository in and object oriented manner."
9
- s.has_rdoc = true
10
- s.authors = ["Tom Preston-Werner", "Scott Chacon"]
11
- s.files = ["History.txt",
12
- "README.txt",
13
- "Rakefile",
14
- "grit.gemspec",
15
- "lib/grit/actor.rb",
16
- "lib/grit/blob.rb",
17
- "lib/grit/commit.rb",
18
- "lib/grit/commit_stats.rb",
19
- "lib/grit/config.rb",
20
- "lib/grit/diff.rb",
21
- "lib/grit/errors.rb",
22
- "lib/grit/git-ruby/commit_db.rb",
23
- "lib/grit/git-ruby/file_index.rb",
24
- "lib/grit/git-ruby/git_object.rb",
25
- "lib/grit/git-ruby/internal/loose.rb",
26
- "lib/grit/git-ruby/internal/mmap.rb",
27
- "lib/grit/git-ruby/internal/pack.rb",
28
- "lib/grit/git-ruby/internal/raw_object.rb",
29
- "lib/grit/git-ruby/object.rb",
30
- "lib/grit/git-ruby/repository.rb",
31
- "lib/grit/git-ruby.rb",
32
- "lib/grit/git.rb",
33
- "lib/grit/head.rb",
34
- "lib/grit/index.rb",
35
- "lib/grit/lazy.rb",
36
- "lib/grit/ref.rb",
37
- "lib/grit/repo.rb",
38
- "lib/grit/status.rb",
39
- "lib/grit/submodule.rb",
40
- "lib/grit/tag.rb",
41
- "lib/grit/tree.rb",
42
- "lib/grit.rb",
43
- "lib/open3_detach.rb"]
44
- s.test_files = ["test/test_actor.rb",
45
- "test/test_blob.rb", "test/test_commit.rb",
46
- "test/test_config.rb",
47
- "test/test_diff.rb",
48
- "test/test_git.rb",
49
- "test/test_grit.rb",
50
- "test/test_head.rb",
51
- "test/test_real.rb",
52
- "test/test_reality.rb",
53
- "test/test_remote.rb",
54
- "test/test_repo.rb",
55
- "test/test_tag.rb",
56
- "test/test_tree.rb"]
57
- s.rdoc_options = ["--main", "README.txt"]
58
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
59
- s.add_dependency("diff-lcs", ["> 0.0.0"])
60
- s.add_dependency("mime-types", ["> 0.0.0"])
61
- s.add_dependency("open4", ["> 0.0.0"])
62
- end
@@ -1,83 +0,0 @@
1
- module Grit
2
- HEAD_PREFIX = 'refs/heads'
3
-
4
- # A Head is a named reference to a Commit. Every Head instance contains a name
5
- # and a Commit object.
6
- #
7
- # r = Grit::Repo.new("/path/to/repo")
8
- # h = r.heads.first
9
- # h.name # => "master"
10
- # h.commit # => #<Grit::Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">
11
- # h.commit.id # => "1c09f116cbc2cb4100fb6935bb162daa4723f455"
12
- class Head
13
- attr_reader :name
14
- attr_reader :commit
15
-
16
- # Instantiate a new Head
17
- # +name+ is the name of the head
18
- # +commit+ is the Commit that the head points to
19
- #
20
- # Returns Grit::Head (baked)
21
- def initialize(name, commit)
22
- @name = name
23
- @commit = commit
24
- end
25
-
26
- # Find all Heads
27
- # +repo+ is the Repo
28
- # +options+ is a Hash of options
29
- #
30
- # Returns Grit::Head[] (baked)
31
- def self.find_all(repo, options = {})
32
- default_options = {
33
- :sort => "committerdate",
34
- :format => "%(refname)%00%(objectname)",
35
- :timeout => false
36
- }
37
-
38
- actual_options = default_options.merge(options)
39
-
40
- output = repo.git.for_each_ref(actual_options, HEAD_PREFIX)
41
-
42
- self.list_from_string(repo, output)
43
- end
44
-
45
- # Parse out head information into an array of baked head objects
46
- # +repo+ is the Repo
47
- # +text+ is the text output from the git command
48
- #
49
- # Returns Grit::Head[] (baked)
50
- def self.list_from_string(repo, text)
51
- heads = []
52
-
53
- text.split("\n").each do |line|
54
- heads << self.from_string(repo, line)
55
- end
56
-
57
- heads
58
- end
59
-
60
- # Create a new Head instance from the given string.
61
- # +repo+ is the Repo
62
- # +line+ is the formatted head information
63
- #
64
- # Format
65
- # name: [a-zA-Z_/]+
66
- # <null byte>
67
- # id: [0-9A-Fa-f]{40}
68
- #
69
- # Returns Grit::Head (baked)
70
- def self.from_string(repo, line)
71
- full_name, id = line.split("\0")
72
- name = full_name.sub("#{HEAD_PREFIX}/", '')
73
- commit = Commit.create(repo, :id => id)
74
- self.new(name, commit)
75
- end
76
-
77
- # Pretty object inspection
78
- def inspect
79
- %Q{#<Grit::Head "#{@name}">}
80
- end
81
- end # Head
82
-
83
- end # Grit
@@ -1,35 +0,0 @@
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
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestBlob < Test::Unit::TestCase
4
- def setup
5
- @r = Repo.new(GRIT_REPO)
6
- @b = Blob.allocate
7
- end
8
-
9
- # blob
10
- def test_nosuch_blob
11
- t = @r.blob('blahblah')
12
- puts t.data
13
- assert t.is_a?(Blob)
14
- end
15
-
16
- def test_data_should_return_blob_contents
17
- Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob'))
18
- blob = Blob.create(@r, :id => 'abc')
19
- assert_equal "Hello world", blob.data
20
- end
21
-
22
- def test_data_should_cache
23
- Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob')).times(1)
24
- blob = Blob.create(@r, :id => 'abc')
25
- blob.data
26
- blob.data
27
- end
28
-
29
- # size
30
-
31
- def test_size_should_return_file_size
32
- Git.any_instance.expects(:cat_file).returns(fixture('cat_file_blob_size'))
33
- blob = Blob.create(@r, :id => 'abc')
34
- assert_equal 11, blob.size
35
- end
36
-
37
- # data
38
-
39
- # mime_type
40
-
41
- def test_mime_type_should_return_mime_type_for_known_types
42
- blob = Blob.create(@r, :id => 'abc', :name => 'foo.png')
43
- assert_equal "image/png", blob.mime_type
44
- end
45
-
46
- def test_mime_type_should_return_text_plain_for_unknown_types
47
- blob = Blob.create(@r, :id => 'abc')
48
- assert_equal "text/plain", blob.mime_type
49
- end
50
-
51
- # blame
52
-
53
- def test_blame
54
- Git.any_instance.expects(:blame).returns(fixture('blame'))
55
- b = Blob.blame(@r, 'master', 'lib/grit.rb')
56
- assert_equal 13, b.size
57
- assert_equal 25, b.inject(0) { |acc, x| acc + x.last.size }
58
- assert_equal b[0].first.object_id, b[9].first.object_id
59
- c = b.first.first
60
- c.expects(:__bake__).times(0)
61
- assert_equal '634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id
62
- assert_equal 'Tom Preston-Werner', c.author.name
63
- assert_equal 'tom@mojombo.com', c.author.email
64
- assert_equal Time.at(1191997100), c.authored_date
65
- assert_equal 'Tom Preston-Werner', c.committer.name
66
- assert_equal 'tom@mojombo.com', c.committer.email
67
- assert_equal Time.at(1191997100), c.committed_date
68
- assert_equal 'initial grit setup', c.message
69
- # c.expects(:__bake__).times(1)
70
- # assert_equal Tree, c.tree.class
71
- end
72
-
73
- # inspect
74
-
75
- def test_inspect
76
- @b = Blob.create(@r, :id => 'abc')
77
- assert_equal %Q{#<Grit::Blob "abc">}, @b.inspect
78
- end
79
- end
@@ -1,190 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestCommit < Test::Unit::TestCase
4
- def setup
5
- @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true)
6
- end
7
-
8
- # __bake__
9
-
10
- def test_bake
11
- Git.any_instance.expects(:rev_list).returns(fixture('rev_list_single'))
12
- @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
13
- @c.author # bake
14
-
15
- assert_equal "Tom Preston-Werner", @c.author.name
16
- assert_equal "tom@mojombo.com", @c.author.email
17
- end
18
-
19
- # short_name
20
-
21
- def test_id_abbrev
22
- assert_equal '80f136f', @r.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev
23
- end
24
-
25
- # count
26
-
27
- def test_count
28
- assert_equal 107, Commit.count(@r, 'master')
29
- end
30
-
31
- # diff
32
-
33
- def test_diff
34
- # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
35
-
36
- Git.any_instance.expects(:diff).with({:full_index => true}, 'master').returns(fixture('diff_p'))
37
- diffs = Commit.diff(@r, 'master')
38
-
39
- assert_equal 15, diffs.size
40
-
41
- assert_equal '.gitignore', diffs.first.a_path
42
- assert_equal '.gitignore', diffs.first.b_path
43
- assert_equal '4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs.first.a_commit.id
44
- assert_equal '2dd02534615434d88c51307beb0f0092f21fd103', diffs.first.b_commit.id
45
- assert_equal '100644', diffs.first.b_mode
46
- assert_equal false, diffs.first.new_file
47
- assert_equal false, diffs.first.deleted_file
48
- assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
49
-
50
- assert_equal 'lib/grit/actor.rb', diffs[5].a_path
51
- assert_equal nil, diffs[5].a_commit
52
- assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id
53
- assert_equal true, diffs[5].new_file
54
- end
55
-
56
- def test_diff_with_two_commits
57
- # git diff --full-index 59ddc32 13d27d5 > test/fixtures/diff_2
58
- Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5').returns(fixture('diff_2'))
59
- diffs = Commit.diff(@r, '59ddc32', '13d27d5')
60
-
61
- assert_equal 3, diffs.size
62
- assert_equal %w(lib/grit/commit.rb test/fixtures/show_empty_commit test/test_commit.rb), diffs.collect { |d| d.a_path }
63
- end
64
-
65
- def test_diff_with_files
66
- # git diff --full-index 59ddc32 -- lib > test/fixtures/diff_f
67
- Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '--', 'lib').returns(fixture('diff_f'))
68
- diffs = Commit.diff(@r, '59ddc32', %w(lib))
69
-
70
- assert_equal 1, diffs.size
71
- assert_equal 'lib/grit/diff.rb', diffs.first.a_path
72
- end
73
-
74
- def test_diff_with_two_commits_and_files
75
- # git diff --full-index 59ddc32 13d27d5 -- lib > test/fixtures/diff_2f
76
- Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5', '--', 'lib').returns(fixture('diff_2f'))
77
- diffs = Commit.diff(@r, '59ddc32', '13d27d5', %w(lib))
78
-
79
- assert_equal 1, diffs.size
80
- assert_equal 'lib/grit/commit.rb', diffs.first.a_path
81
- end
82
-
83
- # diffs
84
- def test_diffs
85
- # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
86
-
87
- Git.any_instance.expects(:diff).returns(fixture('diff_p'))
88
- @c = Commit.create(@r, :id => '91169e1f5fa4de2eaea3f176461f5dc784796769')
89
- diffs = @c.diffs
90
-
91
- assert_equal 15, diffs.size
92
-
93
- assert_equal '.gitignore', diffs.first.a_path
94
- assert_equal '.gitignore', diffs.first.b_path
95
- assert_equal '4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs.first.a_commit.id
96
- assert_equal '2dd02534615434d88c51307beb0f0092f21fd103', diffs.first.b_commit.id
97
- assert_equal '100644', diffs.first.b_mode
98
- assert_equal false, diffs.first.new_file
99
- assert_equal false, diffs.first.deleted_file
100
- assert_equal "--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs.first.diff
101
-
102
- assert_equal 'lib/grit/actor.rb', diffs[5].a_path
103
- assert_equal nil, diffs[5].a_commit
104
- assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id
105
- assert_equal true, diffs[5].new_file
106
- end
107
-
108
- def test_diffs_on_initial_import
109
- # git show --full-index 634396b2f541a9f2d58b00be1a07f0c358b999b3 > test/fixtures/diff_i
110
-
111
- Git.any_instance.expects(:show).with({:full_index => true, :pretty => 'raw'}, '634396b2f541a9f2d58b00be1a07f0c358b999b3').returns(fixture('diff_i'))
112
- @c = Commit.create(@r, :id => '634396b2f541a9f2d58b00be1a07f0c358b999b3')
113
- diffs = @c.diffs
114
-
115
- assert_equal 10, diffs.size
116
-
117
- assert_equal 'History.txt', diffs.first.a_path
118
- assert_equal 'History.txt', diffs.first.b_path
119
- assert_equal nil, diffs.first.a_commit
120
- assert_equal nil, diffs.first.b_mode
121
- assert_equal '81d2c27608b352814cbe979a6acd678d30219678', diffs.first.b_commit.id
122
- assert_equal true, diffs.first.new_file
123
- assert_equal false, diffs.first.deleted_file
124
- assert_equal "--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs.first.diff
125
-
126
-
127
- assert_equal 'lib/grit.rb', diffs[5].a_path
128
- assert_equal nil, diffs[5].a_commit
129
- assert_equal '32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_commit.id
130
- assert_equal true, diffs[5].new_file
131
- end
132
-
133
- def test_diffs_on_initial_import_with_empty_commit
134
- Git.any_instance.expects(:show).with(
135
- {:full_index => true, :pretty => 'raw'},
136
- '634396b2f541a9f2d58b00be1a07f0c358b999b3'
137
- ).returns(fixture('show_empty_commit'))
138
-
139
- @c = Commit.create(@r, :id => '634396b2f541a9f2d58b00be1a07f0c358b999b3')
140
- diffs = @c.diffs
141
-
142
- assert_equal [], diffs
143
- end
144
-
145
- def test_diffs_with_mode_only_change
146
- Git.any_instance.expects(:diff).returns(fixture('diff_mode_only'))
147
- @c = Commit.create(@r, :id => '91169e1f5fa4de2eaea3f176461f5dc784796769')
148
- diffs = @c.diffs
149
-
150
- assert_equal 23, diffs.size
151
- assert_equal '100644', diffs[0].a_mode
152
- assert_equal '100755', diffs[0].b_mode
153
- end
154
-
155
- # to_s
156
-
157
- def test_to_s
158
- @c = Commit.create(@r, :id => 'abc')
159
- assert_equal "abc", @c.to_s
160
- end
161
-
162
- # inspect
163
-
164
- def test_inspect
165
- @c = Commit.create(@r, :id => 'abc')
166
- assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
167
- end
168
-
169
- # to_hash
170
-
171
- def test_to_hash
172
- old_tz, ENV["TZ"] = ENV["TZ"], "US/Pacific"
173
- @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
174
- date = Time.parse('Wed Oct 10 03:06:12 -0400 2007')
175
- expected = {
176
- 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
177
- 'committed_date' => date.xmlschema,
178
- 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
179
- 'authored_date' => date.xmlschema,
180
- 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
181
- 'message' => "implement Grit#heads",
182
- 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
183
- 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017"
184
- }
185
-
186
- assert_equal expected, @c.to_hash
187
- ensure
188
- ENV["TZ"] = old_tz
189
- end
190
- end