grit 2.0.0 → 2.1.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.

Files changed (55) hide show
  1. data/History.txt +21 -0
  2. data/PURE_TODO +35 -0
  3. data/Rakefile +149 -0
  4. data/{test/bench/benchmarks.rb → benchmarks.rb} +6 -3
  5. data/benchmarks.txt +21 -0
  6. data/examples/ex_index.rb +7 -0
  7. data/grit.gemspec +76 -0
  8. data/lib/grit.rb +7 -5
  9. data/lib/grit/commit.rb +26 -12
  10. data/lib/grit/diff.rb +22 -13
  11. data/lib/grit/errors.rb +4 -1
  12. data/lib/grit/git-ruby.rb +12 -7
  13. data/lib/grit/git-ruby/git_object.rb +2 -2
  14. data/lib/grit/git-ruby/internal/loose.rb +1 -1
  15. data/lib/grit/git-ruby/internal/pack.rb +2 -0
  16. data/lib/grit/git-ruby/repository.rb +33 -6
  17. data/lib/grit/git.rb +9 -4
  18. data/lib/grit/index.rb +1 -1
  19. data/lib/{open3_detach.rb → grit/open3_detach.rb} +0 -0
  20. data/lib/grit/ref.rb +3 -1
  21. data/lib/grit/repo.rb +81 -1
  22. data/lib/grit/tag.rb +57 -4
  23. data/lib/grit/tree.rb +1 -1
  24. metadata +30 -46
  25. data/VERSION.yml +0 -4
  26. data/test/helper.rb +0 -18
  27. data/test/profile.rb +0 -21
  28. data/test/suite.rb +0 -6
  29. data/test/test_actor.rb +0 -35
  30. data/test/test_blame.rb +0 -32
  31. data/test/test_blame_tree.rb +0 -33
  32. data/test/test_blob.rb +0 -83
  33. data/test/test_commit.rb +0 -207
  34. data/test/test_commit_stats.rb +0 -33
  35. data/test/test_commit_write.rb +0 -20
  36. data/test/test_config.rb +0 -58
  37. data/test/test_diff.rb +0 -18
  38. data/test/test_file_index.rb +0 -56
  39. data/test/test_git.rb +0 -105
  40. data/test/test_grit.rb +0 -32
  41. data/test/test_head.rb +0 -47
  42. data/test/test_index_status.rb +0 -40
  43. data/test/test_merge.rb +0 -17
  44. data/test/test_raw.rb +0 -16
  45. data/test/test_real.rb +0 -19
  46. data/test/test_reality.rb +0 -17
  47. data/test/test_remote.rb +0 -14
  48. data/test/test_repo.rb +0 -349
  49. data/test/test_rubygit.rb +0 -192
  50. data/test/test_rubygit_alt.rb +0 -40
  51. data/test/test_rubygit_index.rb +0 -76
  52. data/test/test_rubygit_iv2.rb +0 -28
  53. data/test/test_submodule.rb +0 -69
  54. data/test/test_tag.rb +0 -67
  55. data/test/test_tree.rb +0 -101
@@ -1,3 +1,24 @@
1
+ == 2.1.0 / 2010-08-04
2
+ * Major Enhancements
3
+ * Add support for parsing annotated tag objects.
4
+ * Add Grit::Repo#recent_tag_name for getting the latest tag name that is
5
+ reachable in a commit.
6
+ * Grit::Diff tracks renames properly if given the :M option.
7
+ * Grit::Commit#diffs and Grit::Commit.diffs both take a git options hash
8
+ that is passed to `git diff`.
9
+ * Minor Enhancements
10
+ * Allow diff to only take one sha
11
+ * Add merge commit diff support
12
+ * Pass along the options to Real Git on a rev-parse miss
13
+ * Raise NoSuchPath with no tree in ls_tree_path
14
+ * Make pure-ruby `ls-tree -r` work with commits
15
+ * Implement select_existing_objects
16
+ * Switch to RakeGem for build management
17
+ * Bug Fixes
18
+ * Add no_quote option for fixing tag listings.
19
+ * Raise custom exceptions on invalid tree objects.
20
+ * Fix Repo#diff (was throwing an error).
21
+
1
22
  == 2.0.0 / 2009-10-27
2
23
  * Major Enhancements
3
24
  * All filesystem calls have been moved into Grit::Git to allow proxying
@@ -0,0 +1,35 @@
1
+ This is a listing of all the places I can find that Grit actually does a
2
+ 'git' system call. My goal is to add native Ruby versions of all of them.
3
+
4
+ Completed
5
+ ===========================
6
+ ** lib/grit/blob.rb:36: @size ||= @repo.git.cat_file({:s => true}, id).chomp.to_i
7
+ ** lib/grit/blob.rb:43: @data ||= @repo.git.cat_file({:p => true}, id)
8
+ ** lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
9
+
10
+
11
+
12
+ lib/grit/commit.rb:74: repo.git.rev_list({}, ref).strip.split("\n").size
13
+ lib/grit/commit.rb:92: output = repo.git.rev_list(actual_options, ref)
14
+ lib/grit/commit.rb:94: output = repo.git.rev_list(actual_options.merge(:all => true))
15
+
16
+
17
+ Next to do
18
+ ===========================
19
+ lib/grit/tag.rb:28: output = repo.git.for_each_ref(actual_options, "refs/tags")
20
+ lib/grit/head.rb:37: output = repo.git.for_each_ref(actual_options, HEAD_PREFIX)
21
+ lib/grit/head.rb:50: self.new($1, repo.git.rev_parse(options, 'HEAD'))
22
+ lib/grit/config.rb:9: @repo.git.config({}, key, value)
23
+ lib/grit/config.rb:40: @repo.git.config(:list => true).split(/\n/)
24
+
25
+
26
+ May not be fast enough
27
+ =============================
28
+ lib/grit/blob.rb:58: data = repo.git.blame({:p => true}, commit, '--', file)
29
+
30
+
31
+ More Difficult
32
+ ===========================
33
+ lib/grit/commit.rb:39: @id_abbrev ||= @repo.git.rev_parse({:short => true}, self.id).chomp
34
+ lib/grit/commit.rb:150: text = repo.git.diff({:full_index => true}, *paths)
35
+ lib/grit/commit.rb:156: diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
@@ -0,0 +1,149 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rake/rdoctask'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+ desc "Upload site to Rubyforge"
83
+ task :site do
84
+ sh "scp -r doc/* mojombo@grit.rubyforge.org:/var/www/gforge-projects/grit"
85
+ end
86
+
87
+ #############################################################################
88
+ #
89
+ # Packaging tasks
90
+ #
91
+ #############################################################################
92
+
93
+ task :release => :build do
94
+ unless `git branch` =~ /^\* master$/
95
+ puts "You must be on the master branch to release!"
96
+ exit!
97
+ end
98
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
99
+ sh "git tag v#{version}"
100
+ sh "git push origin master"
101
+ sh "git push v#{version}"
102
+ sh "gem push pkg/#{name}-#{version}.gem"
103
+ end
104
+
105
+ task :build => :gemspec do
106
+ sh "mkdir -p pkg"
107
+ sh "gem build #{gemspec_file}"
108
+ sh "mv #{gem_file} pkg"
109
+ end
110
+
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg|test)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ task :validate do
140
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
141
+ unless libfiles.empty?
142
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
143
+ exit!
144
+ end
145
+ unless Dir['VERSION*'].empty?
146
+ puts "A `VERSION` file at root level violates Gem best practices."
147
+ exit!
148
+ end
149
+ end
@@ -5,17 +5,20 @@ require 'ruby-prof'
5
5
  require 'memcache'
6
6
  require 'pp'
7
7
 
8
- gem 'grit', '=0.7.0'
9
- #require '../../lib/grit'
8
+
9
+ #require 'grit'
10
+ require 'lib/grit'
10
11
 
11
12
  def main
12
- @wbare = File.expand_path(File.join('../../', 'test', 'dot_git'))
13
+ @wbare = File.expand_path(File.join('test', 'dot_git'))
13
14
 
14
15
  in_temp_dir do
15
16
  #result = RubyProf.profile do
16
17
 
17
18
  git = Grit::Repo.new('.')
18
19
  puts Grit::VERSION
20
+
21
+ Grit::GitRuby.use_commit_db = true
19
22
  #Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
20
23
  #Grit.debug = true
21
24
 
@@ -0,0 +1,21 @@
1
+ Grit :
2
+ user system total real
3
+ packobj 0.030000 0.270000 1.380000 ( 1.507250)
4
+ commits 1 0.030000 0.070000 0.390000 ( 0.409931)
5
+ commits 2 0.110000 0.170000 0.860000 ( 0.896371)
6
+ log 0.350000 0.130000 0.850000 ( 0.875035)
7
+ diff 0.190000 0.140000 1.940000 ( 2.031911)
8
+ commit-diff 0.540000 0.220000 1.390000 ( 1.463839)
9
+ heads 0.010000 0.070000 0.390000 ( 0.413918)
10
+
11
+
12
+ Grit (with GitRuby) :
13
+
14
+ user system total real
15
+ packobj 0.050000 0.010000 0.060000 ( 0.078318)
16
+ commits 1 0.150000 0.010000 0.160000 ( 0.174296)
17
+ commits 2 0.440000 0.040000 0.480000 ( 0.522310)
18
+ log 0.490000 0.040000 0.530000 ( 0.538128)
19
+ diff 0.370000 0.230000 2.250000 ( 2.255974)
20
+ commit-diff 0.580000 0.260000 1.500000 ( 1.553000)
21
+ heads 0.020000 0.100000 0.430000 ( 0.455464)
@@ -9,6 +9,13 @@ Dir.chdir("/Users/schacon/projects/atest") do
9
9
  i.add(fname, 'hello ' + fname)
10
10
  count += 1
11
11
  end
12
+ count = 5
13
+ while(count < 10) do
14
+ puts "HELLO"
15
+ fname = Time.now.to_i.to_s + count.to_s
16
+ i.add('test/' + fname, 'hello ' + fname)
17
+ count += 1
18
+ end
12
19
  puts i.commit('my commit')
13
20
  puts i.inspect
14
21
  end
@@ -0,0 +1,76 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'grit'
7
+ s.version = '2.1.0'
8
+ s.date = '2010-08-04'
9
+ s.rubyforge_project = 'grit'
10
+
11
+ s.summary = "Ruby Git bindings."
12
+ s.description = "Grit is a Ruby library for extracting information from a git repository in an object oriented manner."
13
+
14
+ s.authors = ["Tom Preston-Werner", "Scott Chacon"]
15
+ s.email = 'tom@github.com'
16
+ s.homepage = 'http://github.com/github/gollum'
17
+
18
+ s.require_paths = %w[lib]
19
+
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.extra_rdoc_files = %w[README.md LICENSE]
22
+
23
+ s.add_dependency('mime-types', "~> 1.15")
24
+ s.add_dependency('diff-lcs', "~> 1.1")
25
+
26
+ s.add_development_dependency('mocha')
27
+
28
+ # = MANIFEST =
29
+ s.files = %w[
30
+ API.txt
31
+ History.txt
32
+ LICENSE
33
+ PURE_TODO
34
+ README.md
35
+ Rakefile
36
+ benchmarks.rb
37
+ benchmarks.txt
38
+ examples/ex_add_commit.rb
39
+ examples/ex_index.rb
40
+ grit.gemspec
41
+ lib/grit.rb
42
+ lib/grit/actor.rb
43
+ lib/grit/blame.rb
44
+ lib/grit/blob.rb
45
+ lib/grit/commit.rb
46
+ lib/grit/commit_stats.rb
47
+ lib/grit/config.rb
48
+ lib/grit/diff.rb
49
+ lib/grit/errors.rb
50
+ lib/grit/git-ruby.rb
51
+ lib/grit/git-ruby/commit_db.rb
52
+ lib/grit/git-ruby/file_index.rb
53
+ lib/grit/git-ruby/git_object.rb
54
+ lib/grit/git-ruby/internal/file_window.rb
55
+ lib/grit/git-ruby/internal/loose.rb
56
+ lib/grit/git-ruby/internal/pack.rb
57
+ lib/grit/git-ruby/internal/raw_object.rb
58
+ lib/grit/git-ruby/object.rb
59
+ lib/grit/git-ruby/repository.rb
60
+ lib/grit/git.rb
61
+ lib/grit/index.rb
62
+ lib/grit/lazy.rb
63
+ lib/grit/merge.rb
64
+ lib/grit/open3_detach.rb
65
+ lib/grit/ref.rb
66
+ lib/grit/repo.rb
67
+ lib/grit/ruby1.9.rb
68
+ lib/grit/status.rb
69
+ lib/grit/submodule.rb
70
+ lib/grit/tag.rb
71
+ lib/grit/tree.rb
72
+ ]
73
+ # = MANIFEST =
74
+
75
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
76
+ end
@@ -9,13 +9,12 @@ require 'timeout'
9
9
  require 'logger'
10
10
  require 'digest/sha1'
11
11
 
12
-
13
12
  if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby'
14
13
  require 'open3'
15
14
  elsif RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
16
15
  require 'win32/open3'
17
16
  else
18
- require 'open3_detach'
17
+ require 'grit/open3_detach'
19
18
  end
20
19
 
21
20
  # third party
@@ -51,12 +50,15 @@ require 'grit/submodule'
51
50
  require 'grit/blame'
52
51
  require 'grit/merge'
53
52
 
54
-
55
53
  module Grit
54
+ VERSION = '2.1.0'
55
+
56
56
  class << self
57
57
  # Set +debug+ to true to log all git calls and responses
58
58
  attr_accessor :debug
59
59
  attr_accessor :use_git_ruby
60
+ attr_accessor :no_quote
61
+
60
62
  # The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
61
63
  attr_accessor :logger
62
64
  def log(str)
@@ -65,11 +67,11 @@ module Grit
65
67
  end
66
68
  self.debug = false
67
69
  self.use_git_ruby = true
70
+ self.no_quote = false
68
71
 
69
72
  @logger ||= ::Logger.new(STDOUT)
70
73
 
71
74
  def self.version
72
- yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
73
- "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
75
+ VERSION
74
76
  end
75
77
  end
@@ -2,6 +2,7 @@ module Grit
2
2
 
3
3
  class Commit
4
4
  attr_reader :id
5
+ attr_reader :repo
5
6
  lazy_reader :parents
6
7
  lazy_reader :tree
7
8
  lazy_reader :author
@@ -140,16 +141,18 @@ module Grit
140
141
  commits
141
142
  end
142
143
 
143
- # Show diffs between two trees:
144
- # +repo+ is the Repo
145
- # +a+ is a named commit
146
- # +b+ is an optional named commit. Passing an array assumes you
147
- # wish to omit the second named commit and limit the diff to the
148
- # given paths.
149
- # +paths* is an array of paths to limit the diff.
144
+ # Show diffs between two trees.
145
+ #
146
+ # repo - The current Grit::Repo instance.
147
+ # a - A String named commit.
148
+ # b - An optional String named commit. Passing an array assumes you
149
+ # wish to omit the second named commit and limit the diff to the
150
+ # given paths.
151
+ # paths - An optional Array of paths to limit the diff.
152
+ # options - An optional Hash of options. Merged into {:full_index => true}.
150
153
  #
151
154
  # Returns Grit::Diff[] (baked)
152
- def self.diff(repo, a, b = nil, paths = [])
155
+ def self.diff(repo, a, b = nil, paths = [], options = {})
153
156
  if b.is_a?(Array)
154
157
  paths = b
155
158
  b = nil
@@ -157,12 +160,18 @@ module Grit
157
160
  paths.unshift("--") unless paths.empty?
158
161
  paths.unshift(b) unless b.nil?
159
162
  paths.unshift(a)
160
- text = repo.git.diff({:full_index => true}, *paths)
163
+ options = {:full_index => true}.update(options)
164
+ text = repo.git.diff(options, *paths)
161
165
  Diff.list_from_string(repo, text)
162
166
  end
163
167
 
164
168
  def show
165
- diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
169
+ if parents.size > 1
170
+ diff = @repo.git.native("diff #{parents[0].id}...#{parents[1].id}", {:full_index => true})
171
+ else
172
+ diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
173
+ end
174
+
166
175
  if diff =~ /diff --git a/
167
176
  diff = diff.sub(/.+?(diff --git a)/m, '\1')
168
177
  else
@@ -171,11 +180,16 @@ module Grit
171
180
  Diff.list_from_string(@repo, diff)
172
181
  end
173
182
 
174
- def diffs
183
+ # Shows diffs between the commit's parent and the commit.
184
+ #
185
+ # options - An optional Hash of options, passed to Grit::Commit.diff.
186
+ #
187
+ # Returns Grit::Diff[] (baked)
188
+ def diffs(options = {})
175
189
  if parents.empty?
176
190
  show
177
191
  else
178
- self.class.diff(@repo, parents.first.id, @id)
192
+ self.class.diff(@repo, parents.first.id, @id, [], options)
179
193
  end
180
194
  end
181
195