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,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  # Scott Chacon <schacon@gmail.com>
@@ -24,7 +24,7 @@ module Grit
24
24
  @email = ''
25
25
  @date = Time.now
26
26
  @offset = 0
27
-
27
+
28
28
  m = /^(.*?) <(.*)> (\d+) ([+-])0*(\d+?)$/.match(str)
29
29
  if !m
30
30
  case str
@@ -50,7 +50,7 @@ module Grit
50
50
  class GitObject
51
51
  attr_accessor :repository
52
52
 
53
- def GitObject.from_raw(rawobject, repository = nil)
53
+ def GitObject.from_raw(rawobject, repository = nil)
54
54
  case rawobject.type
55
55
  when :blob
56
56
  return Blob.from_raw(rawobject, repository)
@@ -110,7 +110,7 @@ module Grit
110
110
  S_IFLNK = 0120000
111
111
  S_IFREG = 0100000
112
112
  S_IFDIR = 0040000
113
- S_IFGITLINK = 0160000
113
+ S_IFGITLINK = 0160000
114
114
  attr_accessor :mode, :name, :sha1
115
115
  def initialize(mode, filename, sha1o)
116
116
  @mode = 0
@@ -170,7 +170,7 @@ module Grit
170
170
  def format_mode
171
171
  "%06o" % @mode
172
172
  end
173
-
173
+
174
174
  def raw
175
175
  "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")]
176
176
  end
@@ -191,20 +191,20 @@ module Grit
191
191
  string
192
192
  end
193
193
 
194
-
194
+
195
195
  class Tree < GitObject
196
196
  attr_accessor :entry
197
197
 
198
198
  def self.from_raw(rawobject, repository=nil)
199
199
  raw = StringIO.new(rawobject.content)
200
-
200
+
201
201
  entries = []
202
202
  while !raw.eof?
203
203
  mode = Grit::GitRuby.read_bytes_until(raw, ' ')
204
204
  file_name = Grit::GitRuby.read_bytes_until(raw, "\0")
205
205
  raw_sha = raw.read(20)
206
206
  sha = raw_sha.unpack("H*").first
207
-
207
+
208
208
  entries << DirectoryEntry.new(mode, file_name, sha)
209
209
  end
210
210
  new(entries, repository)
@@ -224,7 +224,7 @@ module Grit
224
224
  #@entry.sort { |a,b| a.name <=> b.name }.
225
225
  @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
226
226
  end
227
-
227
+
228
228
  def actual_raw
229
229
  #@entry.collect { |e| e.raw.join(' '), e.name].join("\t") }.join("\n")
230
230
  end
@@ -280,28 +280,28 @@ module Grit
280
280
  @parent.collect { |i| "parent %s\n" % i }.join,
281
281
  @author, @committer] + @message
282
282
  end
283
-
283
+
284
284
  def raw_log(sha)
285
285
  output = "commit #{sha}\n"
286
286
  output += @headers + "\n\n"
287
287
  output += @message.split("\n").map { |l| ' ' + l }.join("\n") + "\n\n"
288
288
  end
289
-
289
+
290
290
  end
291
291
 
292
292
  class Tag < GitObject
293
293
  attr_accessor :object, :type, :tag, :tagger, :message
294
294
 
295
295
  def self.from_raw(rawobject, repository=nil)
296
-
296
+
297
297
  headers, message = rawobject.content.split(/\n\n/, 2)
298
298
  headers = headers.split(/\n/).map { |header| header.split(' ', 2) }
299
-
299
+
300
300
  object = ''
301
301
  type = ''
302
302
  tag = ''
303
303
  tagger = ''
304
-
304
+
305
305
  headers.each do |key, value|
306
306
  case key
307
307
  when "object"
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  # Scott Chacon <schacon@gmail.com>
@@ -9,8 +9,8 @@
9
9
  # provides native ruby access to git objects and pack files
10
10
  #
11
11
 
12
- module Grit
13
- module GitRuby
12
+ module Grit
13
+ module GitRuby
14
14
  module Internal
15
15
  class FileWindow
16
16
  def initialize(file, version = 1)
@@ -53,6 +53,6 @@ module Grit
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
57
57
  end
58
58
 
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  # Scott Chacon <schacon@gmail.com>
@@ -14,7 +14,7 @@ require 'digest/sha1'
14
14
  require 'grit/git-ruby/internal/raw_object'
15
15
 
16
16
  module Grit
17
- module GitRuby
17
+ module GitRuby
18
18
  module Internal
19
19
  class LooseObjectError < StandardError
20
20
  end
@@ -65,16 +65,16 @@ module Grit
65
65
  def put_raw_object(content, type)
66
66
  size = content.length.to_s
67
67
  LooseStorage.verify_header(type, size)
68
-
68
+
69
69
  header = "#{type} #{size}\0"
70
70
  store = header + content
71
-
71
+
72
72
  sha1 = Digest::SHA1.hexdigest(store)
73
73
  path = @directory+'/'+sha1[0...2]+'/'+sha1[2..40]
74
-
74
+
75
75
  if !File.exists?(path)
76
76
  content = Zlib::Deflate.deflate(store)
77
-
77
+
78
78
  FileUtils.mkdir_p(@directory+'/'+sha1[0...2])
79
79
  File.open(path, 'wb') do |f|
80
80
  f.write content
@@ -82,17 +82,17 @@ module Grit
82
82
  end
83
83
  return sha1
84
84
  end
85
-
85
+
86
86
  # simply figure out the sha
87
87
  def self.calculate_sha(content, type)
88
88
  size = content.length.to_s
89
89
  verify_header(type, size)
90
90
  header = "#{type} #{size}\0"
91
91
  store = header + content
92
-
92
+
93
93
  Digest::SHA1.hexdigest(store)
94
94
  end
95
-
95
+
96
96
  def self.verify_header(type, size)
97
97
  if !%w(blob tree commit tag).include?(type) || size !~ /^\d+$/
98
98
  raise LooseObjectError, "invalid object header"
@@ -132,6 +132,6 @@ module Grit
132
132
  end
133
133
  private :legacy_loose_object?
134
134
  end
135
- end
135
+ end
136
136
  end
137
137
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  # Scott Chacon <schacon@gmail.com>
@@ -13,11 +13,11 @@ require 'zlib'
13
13
  require 'grit/git-ruby/internal/raw_object'
14
14
  require 'grit/git-ruby/internal/file_window'
15
15
 
16
- PACK_SIGNATURE = "PACK"
17
- PACK_IDX_SIGNATURE = "\377tOc"
16
+ PACK_SIGNATURE = "PACK"
17
+ PACK_IDX_SIGNATURE = "\377tOc"
18
18
 
19
- module Grit
20
- module GitRuby
19
+ module Grit
20
+ module GitRuby
21
21
  module Internal
22
22
  class PackFormatError < StandardError
23
23
  end
@@ -44,7 +44,7 @@ module Grit
44
44
  @cache = {}
45
45
  init_pack
46
46
  end
47
-
47
+
48
48
  def with_idx(index_file = nil)
49
49
  if !index_file
50
50
  index_file = @name
@@ -52,35 +52,35 @@ module Grit
52
52
  else
53
53
  idxfile = File.open(index_file, 'rb')
54
54
  end
55
-
55
+
56
56
  # read header
57
57
  sig = idxfile.read(4)
58
58
  ver = idxfile.read(4).unpack("N")[0]
59
-
59
+
60
60
  if sig == PACK_IDX_SIGNATURE
61
61
  if(ver != 2)
62
62
  raise PackFormatError, "pack #@name has unknown pack file version #{ver}"
63
- end
63
+ end
64
64
  @version = 2
65
65
  else
66
66
  @version = 1
67
67
  end
68
-
68
+
69
69
  idx = FileWindow.new(idxfile, @version)
70
70
  yield idx
71
71
  idx.unmap
72
72
  idxfile.close
73
73
  end
74
-
74
+
75
75
  def with_packfile
76
76
  packfile = File.open(@name, 'rb')
77
77
  yield packfile
78
78
  packfile.close
79
79
  end
80
-
80
+
81
81
  def cache_objects
82
82
  @cache = {}
83
- with_packfile do |packfile|
83
+ with_packfile do |packfile|
84
84
  each_entry do |sha, offset|
85
85
  data, type = unpack_object(packfile, offset, {:caching => true})
86
86
  if data
@@ -93,7 +93,7 @@ module Grit
93
93
  def name
94
94
  @name
95
95
  end
96
-
96
+
97
97
  def close
98
98
  # shouldnt be anything open now
99
99
  end
@@ -104,12 +104,12 @@ module Grit
104
104
  each_sha1 { |sha| shas << sha.unpack("H*")[0] }
105
105
  shas
106
106
  end
107
-
107
+
108
108
  def [](sha1)
109
109
  if obj = @cache[sha1]
110
- return obj
110
+ return obj
111
111
  end
112
-
112
+
113
113
  offset = find_object(sha1)
114
114
  return nil if !offset
115
115
  @cache[sha1] = obj = parse_object(offset)
@@ -129,7 +129,7 @@ module Grit
129
129
  @size = @offsets[-1]
130
130
  end
131
131
  end
132
-
132
+
133
133
  def each_entry
134
134
  with_idx do |idx|
135
135
  if @version == 2
@@ -148,7 +148,7 @@ module Grit
148
148
  end
149
149
  end
150
150
  end
151
-
151
+
152
152
  def read_data_v2(idx)
153
153
  data = []
154
154
  pos = OffsetStart
@@ -169,7 +169,7 @@ module Grit
169
169
  data
170
170
  end
171
171
  private :read_data_v2
172
-
172
+
173
173
  def each_sha1
174
174
  with_idx do |idx|
175
175
  if @version == 2
@@ -191,7 +191,7 @@ module Grit
191
191
  def find_object_in_index(idx, sha1)
192
192
  slot = sha1.getord(0)
193
193
  return nil if !slot
194
- first, last = @offsets[slot,2]
194
+ first, last = @offsets[slot,2]
195
195
  while first < last
196
196
  mid = (first + last) / 2
197
197
  if @version == 2
@@ -224,16 +224,16 @@ module Grit
224
224
  end
225
225
  nil
226
226
  end
227
-
227
+
228
228
  def find_object(sha1)
229
229
  obj = nil
230
230
  with_idx do |idx|
231
231
  obj = find_object_in_index(idx, sha1)
232
232
  end
233
233
  obj
234
- end
234
+ end
235
235
  private :find_object
236
-
236
+
237
237
  def parse_object(offset)
238
238
  obj = nil
239
239
  with_packfile do |packfile|
@@ -259,9 +259,9 @@ module Grit
259
259
  shift += 7
260
260
  offset += 1
261
261
  end
262
-
262
+
263
263
  return [false, false] if !(type == OBJ_COMMIT || type == OBJ_TREE) && options[:caching]
264
-
264
+
265
265
  case type
266
266
  when OBJ_OFS_DELTA, OBJ_REF_DELTA
267
267
  data, type = unpack_deltified(packfile, type, offset, obj_offset, size, options)
@@ -297,9 +297,9 @@ module Grit
297
297
  end
298
298
 
299
299
  base, type = unpack_object(packfile, base_offset)
300
-
300
+
301
301
  return [false, false] if !(type == OBJ_COMMIT || type == OBJ_TREE) && options[:caching]
302
-
302
+
303
303
  delta = unpack_compressed(offset, size)
304
304
  [patch_delta(base, delta), type]
305
305
  end
@@ -378,5 +378,5 @@ module Grit
378
378
  private :patch_delta_header_size
379
379
  end
380
380
  end
381
- end
381
+ end
382
382
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  #
@@ -10,8 +10,8 @@
10
10
 
11
11
  require 'digest/sha1'
12
12
 
13
- module Grit
14
- module GitRuby
13
+ module Grit
14
+ module GitRuby
15
15
  module Internal
16
16
  OBJ_NONE = 0
17
17
  OBJ_COMMIT = 1
@@ -32,6 +32,6 @@ module Grit
32
32
  Digest::SHA1.digest("%s %d\0" % [@type, @content.length] + @content)
33
33
  end
34
34
  end
35
- end
35
+ end
36
36
  end
37
37
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # converted from the gitrb project
3
3
  #
4
- # authors:
4
+ # authors:
5
5
  # Matthias Lederhofer <matled@gmx.net>
6
6
  # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
7
7
  # Scott Chacon <schacon@gmail.com>
@@ -40,7 +40,7 @@ module Grit
40
40
  class Object
41
41
  attr_accessor :repository
42
42
 
43
- def Object.from_raw(rawobject, repository = nil)
43
+ def Object.from_raw(rawobject, repository = nil)
44
44
  case rawobject.type
45
45
  when :blob
46
46
  return Blob.from_raw(rawobject, repository)
@@ -154,7 +154,7 @@ module Grit
154
154
  def format_mode
155
155
  "%06o" % @mode
156
156
  end
157
-
157
+
158
158
  def raw
159
159
  "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")]
160
160
  end
@@ -175,20 +175,20 @@ module Grit
175
175
  string
176
176
  end
177
177
 
178
-
178
+
179
179
  class Tree < Object
180
180
  attr_accessor :entry
181
181
 
182
182
  def self.from_raw(rawobject, repository=nil)
183
183
  raw = StringIO.new(rawobject.content)
184
-
184
+
185
185
  entries = []
186
186
  while !raw.eof?
187
187
  mode = Grit::GitRuby.read_bytes_until(raw, ' ')
188
188
  file_name = Grit::GitRuby.read_bytes_until(raw, "\0")
189
189
  raw_sha = raw.read(20)
190
190
  sha = raw_sha.unpack("H*").first
191
-
191
+
192
192
  entries << DirectoryEntry.new(mode, file_name, sha)
193
193
  end
194
194
  new(entries, repository)
@@ -208,7 +208,7 @@ module Grit
208
208
  #@entry.sort { |a,b| a.name <=> b.name }.
209
209
  @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
210
210
  end
211
-
211
+
212
212
  def actual_raw
213
213
  #@entry.collect { |e| e.raw.join(' '), e.name].join("\t") }.join("\n")
214
214
  end
@@ -264,13 +264,13 @@ module Grit
264
264
  @parent.collect { |i| "parent %s\n" % i }.join,
265
265
  @author, @committer] + @message
266
266
  end
267
-
267
+
268
268
  def raw_log(sha)
269
269
  output = "commit #{sha}\n"
270
270
  output += @headers + "\n\n"
271
271
  output += @message.split("\n").map { |l| ' ' + l }.join("\n") + "\n\n"
272
272
  end
273
-
273
+
274
274
  end
275
275
 
276
276
  class Tag < Object