schacon-grit 0.9.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ class String
2
+ if ((defined? RUBY_VERSION) && (RUBY_VERSION[0..2] == "1.9"))
3
+ def getord(offset); self[offset].ord; end
4
+ else
5
+ alias :getord :[]
6
+ end
7
+ end
@@ -54,7 +54,7 @@ module Grit
54
54
  blob = commit.tree/'.gitmodules'
55
55
  return {} unless blob
56
56
 
57
- lines = blob.data.split("\n")
57
+ lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
58
58
 
59
59
  config = {}
60
60
  current = nil
@@ -75,6 +75,10 @@ module Grit
75
75
  config
76
76
  end
77
77
 
78
+ def basename
79
+ File.basename(name)
80
+ end
81
+
78
82
  # Pretty object inspection
79
83
  def inspect
80
84
  %Q{#<Grit::Submodule "#{@id}">}
data/lib/grit/tag.rb CHANGED
@@ -1,71 +1,27 @@
1
1
  module Grit
2
-
3
- class Tag
4
- attr_reader :name
5
- attr_reader :commit
6
-
7
- # Instantiate a new Tag
8
- # +name+ is the name of the head
9
- # +commit+ is the Commit that the head points to
10
- #
11
- # Returns Grit::Tag (baked)
12
- def initialize(name, commit)
13
- @name = name
14
- @commit = commit
15
- end
16
-
17
- # Find all Tags
18
- # +repo+ is the Repo
19
- # +options+ is a Hash of options
20
- #
21
- # Returns Grit::Tag[] (baked)
2
+
3
+ class Tag < Ref
22
4
  def self.find_all(repo, options = {})
23
- default_options = {:sort => "committerdate",
24
- :format => "%(refname)%00%(objectname)"}
25
-
26
- actual_options = default_options.merge(options)
27
-
28
- output = repo.git.for_each_ref(actual_options, "refs/tags")
29
-
30
- self.list_from_string(repo, output)
31
- end
32
-
33
- # Parse out tag information into an array of baked Tag objects
34
- # +repo+ is the Repo
35
- # +text+ is the text output from the git command
36
- #
37
- # Returns Grit::Tag[] (baked)
38
- def self.list_from_string(repo, text)
39
- tags = []
40
-
41
- text.split("\n").each do |line|
42
- tags << self.from_string(repo, line)
5
+ refs = repo.git.refs(options, prefix)
6
+ refs.split("\n").map do |ref|
7
+ name, id = *ref.split(' ')
8
+ commit = commit_from_sha(repo, id)
9
+ self.new(name, commit)
43
10
  end
44
-
45
- tags
46
11
  end
47
-
48
- # Create a new Tag instance from the given string.
49
- # +repo+ is the Repo
50
- # +line+ is the formatted tag information
51
- #
52
- # Format
53
- # name: [a-zA-Z_/]+
54
- # <null byte>
55
- # id: [0-9A-Fa-f]{40}
56
- #
57
- # Returns Grit::Tag (baked)
58
- def self.from_string(repo, line)
59
- full_name, id = line.split("\0")
60
- name = full_name.split("/").last
61
- commit = Commit.create(repo, :id => id)
62
- self.new(name, commit)
63
- end
64
-
65
- # Pretty object inspection
66
- def inspect
67
- %Q{#<Grit::Tag "#{@name}">}
12
+
13
+ def self.commit_from_sha(repo, id)
14
+ git_ruby_repo = GitRuby::Repository.new(repo.path)
15
+ object = git_ruby_repo.get_object_by_sha1(id)
16
+
17
+ if object.type == :commit
18
+ Commit.create(repo, :id => id)
19
+ elsif object.type == :tag
20
+ Commit.create(repo, :id => object.object)
21
+ else
22
+ raise "Unknown object type."
23
+ end
68
24
  end
69
- end # Tag
70
-
71
- end # Grit
25
+ end
26
+
27
+ end
data/lib/grit/tree.rb CHANGED
@@ -95,10 +95,29 @@ module Grit
95
95
  end
96
96
  end
97
97
 
98
+ def basename
99
+ File.basename(name)
100
+ end
101
+
98
102
  # Pretty object inspection
99
103
  def inspect
100
104
  %Q{#<Grit::Tree "#{@id}">}
101
105
  end
106
+
107
+ # Find only Tree objects from contents
108
+ def trees
109
+ contents.select {|v| v.kind_of? Tree}
110
+ end
111
+
112
+ # Find only Blob objects from contents
113
+ def blobs
114
+ contents.select {|v| v.kind_of? Blob}
115
+ end
116
+
117
+ # Compares trees by name
118
+ def <=>(other)
119
+ name <=> other.name
120
+ end
102
121
  end # Tree
103
-
122
+
104
123
  end # Grit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schacon-grit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -10,87 +10,85 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-11-07 00:00:00 -08:00
13
+ date: 2009-03-31 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: diff-lcs
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
16
  - !ruby/object:Gem::Dependency
26
17
  name: mime-types
18
+ type: :runtime
27
19
  version_requirement:
28
20
  version_requirements: !ruby/object:Gem::Requirement
29
21
  requirements:
30
- - - ">"
22
+ - - ">="
31
23
  - !ruby/object:Gem::Version
32
- version: 0.0.0
24
+ version: "1.15"
33
25
  version:
34
26
  - !ruby/object:Gem::Dependency
35
- name: open4
27
+ name: diff-lcs
28
+ type: :runtime
36
29
  version_requirement:
37
30
  version_requirements: !ruby/object:Gem::Requirement
38
31
  requirements:
39
- - - ">"
32
+ - - ">="
40
33
  - !ruby/object:Gem::Version
41
- version: 0.0.0
34
+ version: 1.1.2
42
35
  version:
43
- description: Grit is a Ruby library for extracting information from a git repository in and object oriented manner.
44
- email: tom@rubyisawesome.com
36
+ description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
37
+ email: tom@mojombo.com
45
38
  executables: []
46
39
 
47
40
  extensions: []
48
41
 
49
42
  extra_rdoc_files:
50
- - History.txt
51
- - Manifest.txt
52
- - README.txt
43
+ - README.md
44
+ - LICENSE
53
45
  files:
46
+ - API.txt
54
47
  - History.txt
55
- - README.txt
56
- - Rakefile
57
- - grit.gemspec
48
+ - README.md
49
+ - VERSION.yml
50
+ - lib/grit
58
51
  - lib/grit/actor.rb
52
+ - lib/grit/blame.rb
59
53
  - lib/grit/blob.rb
60
54
  - lib/grit/commit.rb
61
55
  - lib/grit/commit_stats.rb
62
56
  - lib/grit/config.rb
63
57
  - lib/grit/diff.rb
64
58
  - lib/grit/errors.rb
59
+ - lib/grit/git-ruby
65
60
  - lib/grit/git-ruby/commit_db.rb
66
61
  - lib/grit/git-ruby/file_index.rb
67
62
  - lib/grit/git-ruby/git_object.rb
63
+ - lib/grit/git-ruby/internal
64
+ - lib/grit/git-ruby/internal/file_window.rb
68
65
  - lib/grit/git-ruby/internal/loose.rb
69
- - lib/grit/git-ruby/internal/mmap.rb
70
66
  - lib/grit/git-ruby/internal/pack.rb
71
67
  - lib/grit/git-ruby/internal/raw_object.rb
72
68
  - lib/grit/git-ruby/object.rb
73
69
  - lib/grit/git-ruby/repository.rb
74
70
  - lib/grit/git-ruby.rb
75
71
  - lib/grit/git.rb
76
- - lib/grit/head.rb
77
72
  - lib/grit/index.rb
78
73
  - lib/grit/lazy.rb
74
+ - lib/grit/merge.rb
79
75
  - lib/grit/ref.rb
80
76
  - lib/grit/repo.rb
77
+ - lib/grit/ruby1.9.rb
81
78
  - lib/grit/status.rb
82
79
  - lib/grit/submodule.rb
83
80
  - lib/grit/tag.rb
84
81
  - lib/grit/tree.rb
85
82
  - lib/grit.rb
86
83
  - lib/open3_detach.rb
87
- - Manifest.txt
84
+ - LICENSE
88
85
  has_rdoc: true
89
86
  homepage: http://github.com/mojombo/grit
87
+ licenses:
90
88
  post_install_message:
91
89
  rdoc_options:
92
- - --main
93
- - README.txt
90
+ - --inline-source
91
+ - --charset=UTF-8
94
92
  require_paths:
95
93
  - lib
96
94
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -107,23 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
105
  version:
108
106
  requirements: []
109
107
 
110
- rubyforge_project:
111
- rubygems_version: 1.2.0
108
+ rubyforge_project: grit
109
+ rubygems_version: 1.3.5
112
110
  signing_key:
113
111
  specification_version: 2
114
- summary: Object model interface to a git repo
115
- test_files:
116
- - test/test_actor.rb
117
- - test/test_blob.rb
118
- - test/test_commit.rb
119
- - test/test_config.rb
120
- - test/test_diff.rb
121
- - test/test_git.rb
122
- - test/test_grit.rb
123
- - test/test_head.rb
124
- - test/test_real.rb
125
- - test/test_reality.rb
126
- - test/test_remote.rb
127
- - test/test_repo.rb
128
- - test/test_tag.rb
129
- - test/test_tree.rb
112
+ summary: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
113
+ test_files: []
114
+
data/Manifest.txt DELETED
@@ -1,71 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- grit.gemspec
6
- lib/grit/actor.rb
7
- lib/grit/blob.rb
8
- lib/grit/commit.rb
9
- lib/grit/commit_stats.rb
10
- lib/grit/config.rb
11
- lib/grit/diff.rb
12
- lib/grit/errors.rb
13
- lib/grit/git-ruby/commit_db.rb
14
- lib/grit/git-ruby/file_index.rb
15
- lib/grit/git-ruby/git_object.rb
16
- lib/grit/git-ruby/internal/loose.rb
17
- lib/grit/git-ruby/internal/mmap.rb
18
- lib/grit/git-ruby/internal/pack.rb
19
- lib/grit/git-ruby/internal/raw_object.rb
20
- lib/grit/git-ruby/object.rb
21
- lib/grit/git-ruby/repository.rb
22
- lib/grit/git-ruby.rb
23
- lib/grit/git.rb
24
- lib/grit/head.rb
25
- lib/grit/index.rb
26
- lib/grit/lazy.rb
27
- lib/grit/ref.rb
28
- lib/grit/repo.rb
29
- lib/grit/status.rb
30
- lib/grit/submodule.rb
31
- lib/grit/tag.rb
32
- lib/grit/tree.rb
33
- lib/grit.rb
34
- test/fixtures/blame
35
- test/fixtures/cat_file_blob
36
- test/fixtures/cat_file_blob_size
37
- test/fixtures/diff_2
38
- test/fixtures/diff_2f
39
- test/fixtures/diff_f
40
- test/fixtures/diff_i
41
- test/fixtures/diff_mode_only
42
- test/fixtures/diff_new_mode
43
- test/fixtures/diff_p
44
- test/fixtures/for_each_ref
45
- test/fixtures/for_each_ref_remotes
46
- test/fixtures/for_each_ref_tags
47
- test/fixtures/ls_tree_a
48
- test/fixtures/ls_tree_b
49
- test/fixtures/ls_tree_commit
50
- test/fixtures/rev_list
51
- test/fixtures/rev_list_count
52
- test/fixtures/rev_list_single
53
- test/fixtures/rev_parse
54
- test/fixtures/show_empty_commit
55
- test/fixtures/simple_config
56
- test/helper.rb
57
- test/profile.rb
58
- test/suite.rb
59
- test/test_actor.rb
60
- test/test_blob.rb
61
- test/test_commit.rb
62
- test/test_config.rb
63
- test/test_diff.rb
64
- test/test_git.rb
65
- test/test_grit.rb
66
- test/test_head.rb
67
- test/test_reality.rb
68
- test/test_remote.rb
69
- test/test_repo.rb
70
- test/test_tag.rb
71
- test/test_tree.rb
data/README.txt DELETED
@@ -1,213 +0,0 @@
1
- grit
2
- by Tom Preston-Werner, Scott Chacon
3
- http://github.com/mojombo/grit
4
-
5
- == DESCRIPTION:
6
-
7
- Grit is a Ruby library for extracting information from a git repository in an
8
- object oriented manner.
9
-
10
- == REQUIREMENTS:
11
-
12
- * git (http://git-scm.com) tested with 1.6.0.2
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.