schacon-grit 0.9.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/History.txt +13 -0
  2. data/Manifest.txt +57 -0
  3. data/README.txt +213 -0
  4. data/Rakefile +29 -0
  5. data/grit.gemspec +60 -0
  6. data/lib/grit.rb +53 -0
  7. data/lib/grit/actor.rb +36 -0
  8. data/lib/grit/blob.rb +117 -0
  9. data/lib/grit/commit.rb +221 -0
  10. data/lib/grit/commit_stats.rb +104 -0
  11. data/lib/grit/config.rb +44 -0
  12. data/lib/grit/diff.rb +70 -0
  13. data/lib/grit/errors.rb +7 -0
  14. data/lib/grit/git-ruby.rb +175 -0
  15. data/lib/grit/git-ruby/commit_db.rb +52 -0
  16. data/lib/grit/git-ruby/file_index.rb +186 -0
  17. data/lib/grit/git-ruby/git_object.rb +344 -0
  18. data/lib/grit/git-ruby/internal/loose.rb +136 -0
  19. data/lib/grit/git-ruby/internal/mmap.rb +59 -0
  20. data/lib/grit/git-ruby/internal/pack.rb +332 -0
  21. data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
  22. data/lib/grit/git-ruby/object.rb +319 -0
  23. data/lib/grit/git-ruby/repository.rb +675 -0
  24. data/lib/grit/git.rb +130 -0
  25. data/lib/grit/head.rb +83 -0
  26. data/lib/grit/index.rb +102 -0
  27. data/lib/grit/lazy.rb +31 -0
  28. data/lib/grit/ref.rb +95 -0
  29. data/lib/grit/repo.rb +381 -0
  30. data/lib/grit/status.rb +149 -0
  31. data/lib/grit/tag.rb +71 -0
  32. data/lib/grit/tree.rb +100 -0
  33. data/test/test_actor.rb +35 -0
  34. data/test/test_blob.rb +79 -0
  35. data/test/test_commit.rb +184 -0
  36. data/test/test_config.rb +58 -0
  37. data/test/test_diff.rb +18 -0
  38. data/test/test_git.rb +70 -0
  39. data/test/test_grit.rb +32 -0
  40. data/test/test_head.rb +41 -0
  41. data/test/test_real.rb +19 -0
  42. data/test/test_reality.rb +17 -0
  43. data/test/test_remote.rb +14 -0
  44. data/test/test_repo.rb +277 -0
  45. data/test/test_tag.rb +25 -0
  46. data/test/test_tree.rb +96 -0
  47. metadata +110 -0
data/History.txt ADDED
@@ -0,0 +1,13 @@
1
+ == 0.8.3 / 2008-07-07
2
+ * Capture stderr and log if debug is true (rsanheim)
3
+
4
+ == 0.8.2 / 2008-06-27
5
+ * Allow user provided logger (rsanheim)
6
+
7
+ == 0.8.0 / 2008-04-24
8
+ * Lots of fixes and additions
9
+
10
+ == 0.7.0 / 2008-01-07
11
+ * First public release!
12
+
13
+
data/Manifest.txt ADDED
@@ -0,0 +1,57 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ grit.gemspec
6
+ lib/grit.rb
7
+ lib/grit/actor.rb
8
+ lib/grit/blob.rb
9
+ lib/grit/commit.rb
10
+ lib/grit/commit_stats.rb
11
+ lib/grit/config.rb
12
+ lib/grit/diff.rb
13
+ lib/grit/errors.rb
14
+ lib/grit/git.rb
15
+ lib/grit/index.rb
16
+ lib/grit/lazy.rb
17
+ lib/grit/ref.rb
18
+ lib/grit/repo.rb
19
+ lib/grit/tree.rb
20
+ test/fixtures/blame
21
+ test/fixtures/cat_file_blob
22
+ test/fixtures/cat_file_blob_size
23
+ test/fixtures/diff_2
24
+ test/fixtures/diff_2f
25
+ test/fixtures/diff_f
26
+ test/fixtures/diff_i
27
+ test/fixtures/diff_mode_only
28
+ test/fixtures/diff_new_mode
29
+ test/fixtures/diff_p
30
+ test/fixtures/for_each_ref
31
+ test/fixtures/for_each_ref_remotes
32
+ test/fixtures/for_each_ref_tags
33
+ test/fixtures/ls_tree_a
34
+ test/fixtures/ls_tree_b
35
+ test/fixtures/ls_tree_commit
36
+ test/fixtures/rev_list
37
+ test/fixtures/rev_list_count
38
+ test/fixtures/rev_list_single
39
+ test/fixtures/rev_parse
40
+ test/fixtures/show_empty_commit
41
+ test/fixtures/simple_config
42
+ test/helper.rb
43
+ test/profile.rb
44
+ test/suite.rb
45
+ test/test_actor.rb
46
+ test/test_blob.rb
47
+ test/test_commit.rb
48
+ test/test_config.rb
49
+ test/test_diff.rb
50
+ test/test_git.rb
51
+ test/test_grit.rb
52
+ test/test_head.rb
53
+ test/test_reality.rb
54
+ test/test_remote.rb
55
+ test/test_repo.rb
56
+ test/test_tag.rb
57
+ test/test_tree.rb
data/README.txt ADDED
@@ -0,0 +1,213 @@
1
+ grit
2
+ by Tom Preston-Werner, Chris Wanstrath
3
+ http://github.com/mojombo/grit
4
+
5
+ == DESCRIPTION:
6
+
7
+ Grit is a Ruby library for extracting information from a git repository in and
8
+ object oriented manner.
9
+
10
+ == REQUIREMENTS:
11
+
12
+ * git (http://git.or.cz) tested with 1.5.3.4
13
+
14
+ == INSTALL:
15
+
16
+ $ gem sources -a http://gems.github.com/ (you only need to do this once)
17
+ $ gem install mojombo-grit
18
+
19
+ == SOURCE:
20
+
21
+ Grit's git repo is available on GitHub, which can be browsed at:
22
+
23
+ http://github.com/mojombo/grit
24
+
25
+ and cloned from:
26
+
27
+ git://github.com/mojombo/grit.git
28
+
29
+ == USAGE:
30
+
31
+ Grit gives you object model access to your git repository. Once you have
32
+ created a repository object, you can traverse it to find parent commit(s),
33
+ trees, blobs, etc.
34
+
35
+ = Initialize a Repo object
36
+
37
+ The first step is to create a Grit::Repo object to represent your repo. I
38
+ include the Grit module so reduce typing.
39
+
40
+ require 'mojombo-grit'
41
+ include Grit
42
+ repo = Repo.new("/Users/tom/dev/grit")
43
+
44
+ In the above example, the directory /Users/tom/dev/grit is my working
45
+ repo and contains the .git directory. You can also initialize Grit with a
46
+ bare repo.
47
+
48
+ repo = Repo.new("/var/git/grit.git")
49
+
50
+ = Getting a list of commits
51
+
52
+ From the Repo object, you can get a list of commits as an array of Commit
53
+ objects.
54
+
55
+ repo.commits
56
+ # => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
57
+ #<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
58
+ #<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
59
+ #<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
60
+ #<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]
61
+
62
+ Called without arguments, Repo#commits returns a list of up to ten commits
63
+ reachable by the master branch (starting at the latest commit). You can ask
64
+ for commits beginning at a different branch, commit, tag, etc.
65
+
66
+ repo.commits('mybranch')
67
+ repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
68
+ repo.commits('v0.1')
69
+
70
+ You can specify the maximum number of commits to return.
71
+
72
+ repo.commits('master', 100)
73
+
74
+ If you need paging, you can specify a number of commits to skip.
75
+
76
+ repo.commits('master', 10, 20)
77
+
78
+ The above will return commits 21-30 from the commit list.
79
+
80
+ = The Commit object
81
+
82
+ Commit objects contain information about that commit.
83
+
84
+ head = repo.commits.first
85
+
86
+ head.id
87
+ # => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
88
+
89
+ head.parents
90
+ # => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
91
+
92
+ head.tree
93
+ # => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
94
+
95
+ head.author
96
+ # => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
97
+
98
+ head.authored_date
99
+ # => Wed Oct 24 22:02:31 -0700 2007
100
+
101
+ head.committer
102
+ # => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
103
+
104
+ head.committed_date
105
+ # => Wed Oct 24 22:02:31 -0700 2007
106
+
107
+ head.message
108
+ # => "add Actor inspect"
109
+
110
+ You can traverse a commit's ancestry by chaining calls to #parents.
111
+
112
+ repo.commits.first.parents[0].parents[0].parents[0]
113
+
114
+ The above corresponds to master^^^ or master~3 in git parlance.
115
+
116
+ = The Tree object
117
+
118
+ A tree records pointers to the contents of a directory. Let's say you want
119
+ the root tree of the latest commit on the master branch.
120
+
121
+ tree = repo.commits.first.tree
122
+ # => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
123
+
124
+ tree.id
125
+ # => "3536eb9abac69c3e4db583ad38f3d30f8db4771f"
126
+
127
+ Once you have a tree, you can get the contents.
128
+
129
+ contents = tree.contents
130
+ # => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
131
+ #<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
132
+ #<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
133
+ #<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
134
+
135
+ This tree contains two Blob objects and two Tree objects. The trees are
136
+ subdirectories and the blobs are files. Trees below the root have additional
137
+ attributes.
138
+
139
+ contents.last.name
140
+ # => "lib"
141
+
142
+ contents.last.mode
143
+ # => "040000"
144
+
145
+ There is a convenience method that allows you to get a named sub-object
146
+ from a tree.
147
+
148
+ tree/"lib"
149
+ # => #<Grit::Tree "e74893a3d8a25cbb1367cf241cc741bfd503c4b2">
150
+
151
+ You can also get a tree directly from the repo if you know its name.
152
+
153
+ repo.tree
154
+ # => #<Grit::Tree "master">
155
+
156
+ repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
157
+ # => #<Grit::Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
158
+
159
+ = The Blob object
160
+
161
+ A blob represents a file. Trees often contain blobs.
162
+
163
+ blob = tree.contents.first
164
+ # => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
165
+
166
+ A blob has certain attributes.
167
+
168
+ blob.id
169
+ # => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
170
+
171
+ blob.name
172
+ # => "README.txt"
173
+
174
+ blob.mode
175
+ # => "100644"
176
+
177
+ blob.size
178
+ # => 7726
179
+
180
+ You can get the data of a blob as a string.
181
+
182
+ blob.data
183
+ # => "Grit is a library to ..."
184
+
185
+ You can also get a blob directly from the repo if you know its name.
186
+
187
+ repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
188
+ # => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
189
+
190
+ == LICENSE:
191
+
192
+ (The MIT License)
193
+
194
+ Copyright (c) 2007 Tom Preston-Werner
195
+
196
+ Permission is hereby granted, free of charge, to any person obtaining
197
+ a copy of this software and associated documentation files (the
198
+ 'Software'), to deal in the Software without restriction, including
199
+ without limitation the rights to use, copy, modify, merge, publish,
200
+ distribute, sublicense, and/or sell copies of the Software, and to
201
+ permit persons to whom the Software is furnished to do so, subject to
202
+ the following conditions:
203
+
204
+ The above copyright notice and this permission notice shall be
205
+ included in all copies or substantial portions of the Software.
206
+
207
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
208
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
210
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
211
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
212
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
213
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
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
data/grit.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "grit"
3
+ s.version = "0.9.1"
4
+ s.date = "2008-04-24"
5
+ s.summary = "Object model interface to a git repo"
6
+ s.email = "tom@rubyisawesome.com"
7
+ s.homepage = "http://github.com/schacon/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
+ "Manifest.txt",
13
+ "README.txt",
14
+ "Rakefile",
15
+ "grit.gemspec",
16
+ "lib/grit/actor.rb",
17
+ "lib/grit/blob.rb",
18
+ "lib/grit/commit.rb",
19
+ "lib/grit/commit_stats.rb",
20
+ "lib/grit/config.rb",
21
+ "lib/grit/diff.rb",
22
+ "lib/grit/errors.rb",
23
+ "lib/grit/git-ruby/commit_db.rb",
24
+ "lib/grit/git-ruby/file_index.rb",
25
+ "lib/grit/git-ruby/git_object.rb",
26
+ "lib/grit/git-ruby/internal",
27
+ "lib/grit/git-ruby/internal/loose.rb",
28
+ "lib/grit/git-ruby/internal/mmap.rb",
29
+ "lib/grit/git-ruby/internal/pack.rb",
30
+ "lib/grit/git-ruby/internal/raw_object.rb",
31
+ "lib/grit/git-ruby/object.rb",
32
+ "lib/grit/git-ruby/repository.rb",
33
+ "lib/grit/git-ruby.rb",
34
+ "lib/grit/git.rb",
35
+ "lib/grit/head.rb",
36
+ "lib/grit/index.rb",
37
+ "lib/grit/lazy.rb",
38
+ "lib/grit/ref.rb",
39
+ "lib/grit/repo.rb",
40
+ "lib/grit/status.rb",
41
+ "lib/grit/tag.rb",
42
+ "lib/grit/tree.rb",
43
+ "lib/grit.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("mime-types", ["> 0.0.0"])
60
+ end
data/lib/grit.rb ADDED
@@ -0,0 +1,53 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+
3
+ # core
4
+ require 'fileutils'
5
+ require 'time'
6
+
7
+ # stdlib
8
+ require 'timeout'
9
+ require 'logger'
10
+
11
+ # third party
12
+ require 'rubygems'
13
+ require 'mime/types'
14
+ require 'open4'
15
+ require 'digest/sha1'
16
+
17
+ # internal requires
18
+ require 'grit/lazy'
19
+ require 'grit/errors'
20
+ require 'grit/git-ruby'
21
+ require 'grit/git'
22
+ require 'grit/ref'
23
+ require 'grit/commit'
24
+ require 'grit/commit_stats'
25
+ require 'grit/tree'
26
+ require 'grit/blob'
27
+ require 'grit/actor'
28
+ require 'grit/diff'
29
+ require 'grit/config'
30
+ require 'grit/repo'
31
+ require 'grit/index'
32
+ require 'grit/status'
33
+
34
+
35
+ module Grit
36
+
37
+ class << self
38
+ # Set +debug+ to true to log all git calls and responses
39
+ attr_accessor :debug
40
+ attr_accessor :use_git_ruby
41
+ # The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
42
+ attr_accessor :logger
43
+ def log(str)
44
+ logger.debug { str }
45
+ end
46
+ end
47
+ self.debug = false
48
+ self.use_git_ruby = true
49
+
50
+ @logger ||= ::Logger.new(STDOUT)
51
+
52
+ VERSION = '0.9.1'
53
+ end
data/lib/grit/actor.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Grit
2
+
3
+ class Actor
4
+ attr_reader :name
5
+ attr_reader :email
6
+
7
+ def initialize(name, email)
8
+ @name = name
9
+ @email = email
10
+ end
11
+ alias_method :to_s, :name
12
+
13
+ # Create an Actor from a string.
14
+ # +str+ is the string, which is expected to be in regular git format
15
+ #
16
+ # Format
17
+ # John Doe <jdoe@example.com>
18
+ #
19
+ # Returns Actor
20
+ def self.from_string(str)
21
+ case str
22
+ when /<.+>/
23
+ m, name, email = *str.match(/(.*) <(.+?)>/)
24
+ return self.new(name, email)
25
+ else
26
+ return self.new(str, nil)
27
+ end
28
+ end
29
+
30
+ # Pretty object inspection
31
+ def inspect
32
+ %Q{#<Grit::Actor "#{@name} <#{@email}>">}
33
+ end
34
+ end # Actor
35
+
36
+ end # Grit