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.

Files changed (66) hide show
  1. data/History.txt +9 -0
  2. data/README.md +37 -11
  3. data/VERSION.yml +3 -3
  4. data/examples/ex_add_commit.rb +13 -0
  5. data/examples/ex_index.rb +14 -0
  6. data/lib/grit.rb +10 -3
  7. data/lib/grit/actor.rb +5 -5
  8. data/lib/grit/blob.rb +12 -12
  9. data/lib/grit/commit.rb +3 -3
  10. data/lib/grit/commit_stats.rb +26 -26
  11. data/lib/grit/config.rb +9 -9
  12. data/lib/grit/diff.rb +16 -16
  13. data/lib/grit/errors.rb +1 -1
  14. data/lib/grit/git-ruby.rb +108 -27
  15. data/lib/grit/git-ruby/commit_db.rb +11 -11
  16. data/lib/grit/git-ruby/file_index.rb +28 -28
  17. data/lib/grit/git-ruby/git_object.rb +14 -14
  18. data/lib/grit/git-ruby/internal/file_window.rb +4 -4
  19. data/lib/grit/git-ruby/internal/loose.rb +10 -10
  20. data/lib/grit/git-ruby/internal/pack.rb +29 -29
  21. data/lib/grit/git-ruby/internal/raw_object.rb +4 -4
  22. data/lib/grit/git-ruby/object.rb +9 -9
  23. data/lib/grit/git-ruby/repository.rb +111 -107
  24. data/lib/grit/git.rb +191 -14
  25. data/lib/grit/index.rb +21 -21
  26. data/lib/grit/lazy.rb +1 -1
  27. data/lib/grit/merge.rb +9 -9
  28. data/lib/grit/ref.rb +6 -31
  29. data/lib/grit/repo.rb +110 -65
  30. data/lib/grit/ruby1.9.rb +1 -1
  31. data/lib/grit/status.rb +24 -24
  32. data/lib/grit/submodule.rb +15 -15
  33. data/lib/grit/tag.rb +7 -57
  34. data/lib/grit/tree.rb +12 -12
  35. data/test/bench/benchmarks.rb +126 -0
  36. data/test/helper.rb +18 -0
  37. data/test/profile.rb +21 -0
  38. data/test/suite.rb +6 -0
  39. data/test/test_actor.rb +35 -0
  40. data/test/test_blame.rb +32 -0
  41. data/test/test_blame_tree.rb +33 -0
  42. data/test/test_blob.rb +83 -0
  43. data/test/test_commit.rb +207 -0
  44. data/test/test_commit_stats.rb +33 -0
  45. data/test/test_commit_write.rb +20 -0
  46. data/test/test_config.rb +58 -0
  47. data/test/test_diff.rb +18 -0
  48. data/test/test_file_index.rb +56 -0
  49. data/test/test_git.rb +105 -0
  50. data/test/test_grit.rb +32 -0
  51. data/test/test_head.rb +47 -0
  52. data/test/test_index_status.rb +40 -0
  53. data/test/test_merge.rb +17 -0
  54. data/test/test_raw.rb +16 -0
  55. data/test/test_real.rb +19 -0
  56. data/test/test_reality.rb +17 -0
  57. data/test/test_remote.rb +14 -0
  58. data/test/test_repo.rb +349 -0
  59. data/test/test_rubygit.rb +192 -0
  60. data/test/test_rubygit_alt.rb +40 -0
  61. data/test/test_rubygit_index.rb +76 -0
  62. data/test/test_rubygit_iv2.rb +28 -0
  63. data/test/test_submodule.rb +69 -0
  64. data/test/test_tag.rb +67 -0
  65. data/test/test_tree.rb +101 -0
  66. metadata +43 -13
@@ -1,3 +1,12 @@
1
+ == 2.0.0 / 2009-10-27
2
+ * Major Enhancements
3
+ * All filesystem calls have been moved into Grit::Git to allow proxying
4
+ * Non-code changes
5
+ * Removed all trailing whitespace in code files
6
+ * Bug Fixes
7
+ * Repo.archive_tar_gz now passes -n option to gzip to be idempotent
8
+ * Fix RubyGit's diff to detect additions and deletions [github.com/defunkt]
9
+
1
10
  == 1.1.1 / 2009-03-31
2
11
  * Changes
3
12
  * Don't include test directory in gem package (it's too big)
data/README.md CHANGED
@@ -9,12 +9,13 @@ reimplementations of core Git functionality. This choice, however, is
9
9
  transparent to end users, and you need not know which method is being used.
10
10
 
11
11
  This software was developed to power GitHub, and should be considered
12
- production ready. An extensive test suite is provided to verify its correctness.
12
+ production ready. An extensive test suite is provided to verify its
13
+ correctness.
13
14
 
14
15
  Grit is maintained by Tom Preston-Werner, Scott Chacon, Chris Wanstrath, and
15
16
  PJ Hyett.
16
17
 
17
- This documentation is accurate as of Grit 1.0.2.
18
+ This documentation is accurate as of Grit 2.0.
18
19
 
19
20
 
20
21
  ## Requirements #############################################################
@@ -26,15 +27,7 @@ This documentation is accurate as of Grit 1.0.2.
26
27
 
27
28
  Easiest install is via RubyGems:
28
29
 
29
- $ gem install grit
30
-
31
- or
32
-
33
- $ gem sources -a http://gems.github.com/ (you only need to do this once)
34
- $ gem install mojombo-grit
35
-
36
- The gem from GitHub will generally be available sooner than the gem from
37
- Rubyforge. Both sources will eventually contain the same releases.
30
+ $ gem install grit -s http://gemcutter.org
38
31
 
39
32
 
40
33
  ## Source ###################################################################
@@ -48,12 +41,29 @@ and cloned with:
48
41
  git clone git://github.com/mojombo/grit.git
49
42
 
50
43
 
44
+ ### Development
45
+
46
+ You will need these gems to get tests to pass:
47
+
48
+ * jeweler
49
+ * mocha
50
+
51
+
52
+ ### Contributing
53
+
54
+ If you'd like to contribute to Grit, we ask that you fork mojombo/grit on
55
+ GitHub, and push up a topic branch for each feature you add or bug you fix.
56
+ Then create an issue and link to the topic branch and explain what the code
57
+ does. This allows us to discuss and merge each change separately.
58
+
59
+
51
60
  ## Usage ####################################################################
52
61
 
53
62
  Grit gives you object model access to your Git repositories. Once you have
54
63
  created a `Repo` object, you can traverse it to find parent commits,
55
64
  trees, blobs, etc.
56
65
 
66
+
57
67
  ### Initialize a Repo object
58
68
 
59
69
  The first step is to create a `Grit::Repo` object to represent your repo. In
@@ -69,6 +79,7 @@ a bare repo.
69
79
 
70
80
  repo = Repo.new("/var/git/grit.git")
71
81
 
82
+
72
83
  ### Getting a list of commits
73
84
 
74
85
  From the `Repo` object, you can get a list of commits as an array of `Commit`
@@ -99,6 +110,7 @@ If you need paging, you can specify a number of commits to skip.
99
110
 
100
111
  The above will return commits 21-30 from the commit list.
101
112
 
113
+
102
114
  ### The Commit object
103
115
 
104
116
  `Commit` objects contain information about that commit.
@@ -135,6 +147,7 @@ You can traverse a commit's ancestry by chaining calls to `#parents`.
135
147
 
136
148
  The above corresponds to **master^^^** or **master~3** in Git parlance.
137
149
 
150
+
138
151
  ### The Tree object
139
152
 
140
153
  A tree records pointers to the contents of a directory. Let's say you want
@@ -178,6 +191,7 @@ You can also get a tree directly from the repo if you know its name.
178
191
  repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
179
192
  # => #<Grit::Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
180
193
 
194
+
181
195
  ### The Blob object
182
196
 
183
197
  A blob represents a file. Trees often contain blobs.
@@ -208,3 +222,15 @@ You can also get a blob directly from the repo if you know its name.
208
222
 
209
223
  repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
210
224
  # => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
225
+
226
+
227
+ ### Other
228
+
229
+ There are many more API methods available that are not documented here. Please
230
+ reference the code for more functionality.
231
+
232
+
233
+ Copyright
234
+ ---------
235
+
236
+ Copyright (c) 2008 Tom Preston-Werner. See LICENSE for details.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 1
3
- :minor: 1
4
- :patch: 1
2
+ :major: 2
3
+ :minor: 0
4
+ :patch: 0
@@ -0,0 +1,13 @@
1
+ require '../lib/grit'
2
+
3
+ count = 1
4
+ Dir.chdir("/Users/schacon/projects/atest") do
5
+ r = Grit::Repo.new('.')
6
+ while(count < 10) do
7
+ fname = Time.now.to_i.to_s + count.to_s
8
+ File.open(fname, 'w') { |f| f.write('hellor ' + fname) }
9
+ r.add(fname)
10
+ count += 1
11
+ end
12
+ r.commit_index('my commit')
13
+ end
@@ -0,0 +1,14 @@
1
+ require '../lib/grit'
2
+
3
+ count = 1
4
+ Dir.chdir("/Users/schacon/projects/atest") do
5
+ r = Grit::Repo.new('.')
6
+ i = r.index
7
+ while(count < 10) do
8
+ fname = Time.now.to_i.to_s + count.to_s
9
+ i.add(fname, 'hello ' + fname)
10
+ count += 1
11
+ end
12
+ puts i.commit('my commit')
13
+ puts i.inspect
14
+ end
@@ -9,16 +9,23 @@ require 'timeout'
9
9
  require 'logger'
10
10
  require 'digest/sha1'
11
11
 
12
+
12
13
  if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby'
13
14
  require 'open3'
15
+ elsif RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
16
+ require 'win32/open3'
14
17
  else
15
18
  require 'open3_detach'
16
19
  end
17
20
 
18
21
  # third party
19
22
  require 'rubygems'
20
- gem "mime-types", ">=0"
21
- require 'mime/types'
23
+ begin
24
+ gem "mime-types", ">=0"
25
+ require 'mime/types'
26
+ rescue Gem::LoadError => e
27
+ puts "WARNING: Gem LoadError: #{e.message}"
28
+ end
22
29
 
23
30
  # ruby 1.9 compatibility
24
31
  require 'grit/ruby1.9'
@@ -27,7 +34,7 @@ require 'grit/ruby1.9'
27
34
  require 'grit/lazy'
28
35
  require 'grit/errors'
29
36
  require 'grit/git-ruby'
30
- require 'grit/git'
37
+ require 'grit/git' unless defined? Grit::Git
31
38
  require 'grit/ref'
32
39
  require 'grit/tag'
33
40
  require 'grit/commit'
@@ -1,15 +1,15 @@
1
1
  module Grit
2
-
2
+
3
3
  class Actor
4
4
  attr_reader :name
5
5
  attr_reader :email
6
-
6
+
7
7
  def initialize(name, email)
8
8
  @name = name
9
9
  @email = email
10
10
  end
11
11
  alias_method :to_s, :name
12
-
12
+
13
13
  # Create an Actor from a string.
14
14
  # +str+ is the string, which is expected to be in regular git format
15
15
  #
@@ -26,11 +26,11 @@ module Grit
26
26
  return self.new(str, nil)
27
27
  end
28
28
  end
29
-
29
+
30
30
  # Pretty object inspection
31
31
  def inspect
32
32
  %Q{#<Grit::Actor "#{@name} <#{@email}>">}
33
33
  end
34
34
  end # Actor
35
-
35
+
36
36
  end # Grit
@@ -1,12 +1,12 @@
1
1
  module Grit
2
-
2
+
3
3
  class Blob
4
4
  DEFAULT_MIME_TYPE = "text/plain"
5
-
5
+
6
6
  attr_reader :id
7
7
  attr_reader :mode
8
8
  attr_reader :name
9
-
9
+
10
10
  # Create an unbaked Blob containing just the specified attributes
11
11
  # +repo+ is the Repo
12
12
  # +atts+ is a Hash of instance variable data
@@ -15,7 +15,7 @@ module Grit
15
15
  def self.create(repo, atts)
16
16
  self.allocate.create_initialize(repo, atts)
17
17
  end
18
-
18
+
19
19
  # Initializer for Blob.create
20
20
  # +repo+ is the Repo
21
21
  # +atts+ is a Hash of instance variable data
@@ -28,21 +28,21 @@ module Grit
28
28
  end
29
29
  self
30
30
  end
31
-
31
+
32
32
  # The size of this blob in bytes
33
33
  #
34
34
  # Returns Integer
35
35
  def size
36
36
  @size ||= @repo.git.cat_file({:s => true}, id).chomp.to_i
37
37
  end
38
-
38
+
39
39
  # The binary contents of this blob.
40
40
  #
41
41
  # Returns String
42
42
  def data
43
43
  @data ||= @repo.git.cat_file({:p => true}, id)
44
44
  end
45
-
45
+
46
46
  # The mime type of this file (based on the filename)
47
47
  #
48
48
  # Returns String
@@ -50,17 +50,17 @@ module Grit
50
50
  guesses = MIME::Types.type_for(self.name) rescue []
51
51
  guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE
52
52
  end
53
-
53
+
54
54
  # The blame information for the given file at the given commit
55
55
  #
56
56
  # Returns Array: [Grit::Commit, Array: [<line>]]
57
57
  def self.blame(repo, commit, file)
58
58
  data = repo.git.blame({:p => true}, commit, '--', file)
59
-
59
+
60
60
  commits = {}
61
61
  blames = []
62
62
  info = nil
63
-
63
+
64
64
  data.split("\n").each do |line|
65
65
  parts = line.split(/\s+/, 2)
66
66
  case parts.first
@@ -107,11 +107,11 @@ module Grit
107
107
 
108
108
  blames
109
109
  end
110
-
110
+
111
111
  def basename
112
112
  File.basename(name)
113
113
  end
114
-
114
+
115
115
  # Pretty object inspection
116
116
  def inspect
117
117
  %Q{#<Grit::Blob "#{@id}">}
@@ -33,7 +33,7 @@ module Grit
33
33
  @committer = committer
34
34
  @committed_date = committed_date
35
35
  @message = message.join("\n")
36
- @short_message = message[0] || ''
36
+ @short_message = message.select { |x| !x.strip.empty? }[0] || ''
37
37
  end
38
38
 
39
39
  def id_abbrev
@@ -178,11 +178,11 @@ module Grit
178
178
  self.class.diff(@repo, parents.first.id, @id)
179
179
  end
180
180
  end
181
-
181
+
182
182
  def stats
183
183
  stats = @repo.commit_stats(self.sha, 1)[0][-1]
184
184
  end
185
-
185
+
186
186
  # Convert this Commit to a String which is just the SHA1 id
187
187
  def to_s
188
188
  @id
@@ -1,9 +1,9 @@
1
1
  module Grit
2
-
2
+
3
3
  class CommitStats
4
-
4
+
5
5
  attr_reader :id, :files, :additions, :deletions, :total
6
-
6
+
7
7
  # Instantiate a new CommitStats
8
8
  # +id+ is the id of the commit
9
9
  # +files+ is an array of :
@@ -16,11 +16,11 @@ module Grit
16
16
  @repo = repo
17
17
  @id = id
18
18
  @files = files
19
- @additions = files.inject(0) { |total, a| total += a[1] }
20
- @deletions = files.inject(0) { |total, a| total += a[2] }
21
- @total = files.inject(0) { |total, a| total += a[3] }
19
+ @additions = files.inject(0) { |total, a| total += a[1] }
20
+ @deletions = files.inject(0) { |total, a| total += a[2] }
21
+ @total = files.inject(0) { |total, a| total += a[3] }
22
22
  end
23
-
23
+
24
24
  # Find all commit stats matching the given criteria.
25
25
  # +repo+ is the Repo
26
26
  # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all
@@ -31,19 +31,19 @@ module Grit
31
31
  # Returns assoc array [sha, Grit::Commit[] (baked)]
32
32
  def self.find_all(repo, ref, options = {})
33
33
  allowed_options = [:max_count, :skip, :since]
34
-
34
+
35
35
  default_options = {:numstat => true}
36
36
  actual_options = default_options.merge(options)
37
-
37
+
38
38
  if ref
39
39
  output = repo.git.log(actual_options, ref)
40
40
  else
41
41
  output = repo.git.log(actual_options.merge(:all => true))
42
42
  end
43
-
43
+
44
44
  self.list_from_string(repo, output)
45
45
  end
46
-
46
+
47
47
  # Parse out commit information into an array of baked Commit objects
48
48
  # +repo+ is the Repo
49
49
  # +text+ is the text output from the git command (raw format)
@@ -51,19 +51,19 @@ module Grit
51
51
  # Returns assoc array [sha, Grit::Commit[] (baked)]
52
52
  def self.list_from_string(repo, text)
53
53
  lines = text.split("\n")
54
-
54
+
55
55
  commits = []
56
56
 
57
57
  while !lines.empty?
58
58
  id = lines.shift.split.last
59
-
59
+
60
60
  lines.shift
61
61
  lines.shift
62
62
  lines.shift
63
-
63
+
64
64
  message_lines = []
65
65
  message_lines << lines.shift[4..-1] while lines.first =~ /^ {4}/ || lines.first == ''
66
-
66
+
67
67
  lines.shift while lines.first && lines.first.empty?
68
68
 
69
69
  files = []
@@ -74,29 +74,29 @@ module Grit
74
74
  total = additions + deletions
75
75
  files << [filename, additions, deletions, total]
76
76
  end
77
-
77
+
78
78
  lines.shift while lines.first && lines.first.empty?
79
-
79
+
80
80
  commits << [id, CommitStats.new(repo, id, files)]
81
81
  end
82
-
82
+
83
83
  commits
84
84
  end
85
-
85
+
86
86
  # Pretty object inspection
87
87
  def inspect
88
88
  %Q{#<Grit::CommitStats "#{@id}">}
89
89
  end
90
-
90
+
91
91
  # Convert to an easy-to-traverse structure
92
92
  def to_diffstat
93
93
  files.map do |metadata|
94
94
  DiffStat.new(*metadata)
95
95
  end
96
96
  end
97
-
97
+
98
98
  # private
99
-
99
+
100
100
  def to_hash
101
101
  {
102
102
  'id' => id,
@@ -106,16 +106,16 @@ module Grit
106
106
  'total' => total
107
107
  }
108
108
  end
109
-
109
+
110
110
  end # CommitStats
111
-
111
+
112
112
  class DiffStat
113
113
  attr_reader :filename, :additions, :deletions
114
114
 
115
115
  def initialize(filename, additions, deletions, total=nil)
116
116
  @filename, @additions, @deletions = filename, additions, deletions
117
117
  end
118
-
118
+
119
119
  def net
120
120
  additions - deletions
121
121
  end
@@ -124,5 +124,5 @@ module Grit
124
124
  "#{filename}: +#{additions} -#{deletions}"
125
125
  end
126
126
  end
127
-
127
+
128
128
  end # Grit