gollum-rugged_adapter 0.4.4 → 0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7dd22e68aefae79b87ce19c5b29b257b73c387fa
4
- data.tar.gz: 32752e14dc82dd6f7931ef59e6f60748573603f0
2
+ SHA256:
3
+ metadata.gz: f9b5e759dc0448a68c2ef5b03a5da78f81ca2af18e5faa82280b2f707a83e7d4
4
+ data.tar.gz: bcc46ceaab4b1bf5b5dd1d5e05ce9856a9cd6ee63219eaf85dbff7f90c87f9d4
5
5
  SHA512:
6
- metadata.gz: 57bbce0adb29b1e09c63be2072d9919aa47b86ca4c11754cb82d64c28a7048477a9fecf9555cd10b477a84253bd45e9155eb1714518318650572c9f75a075f8d
7
- data.tar.gz: 657feaeaf50d11af8f296bf49f72a693f0534eadb2c422bcc35411b149e7f284a38339192ba44a365394b7beabcab4ac29214a41b8d572dc85f1217cf1e93c86
6
+ metadata.gz: 0abff79a7bdb6ea9ea54a7d6483cb7a8e2daf34d0d28f44a2a7702efe12a2d6bdaed8e59fd3969bd7aa57b5b62b281880f998c2d740cd91dc2f0ab5a9ae370c7
7
+ data.tar.gz: 0b2e7ac0435588fc46a2f4777e5295a26caa370f24a1ec5a0083c5470c4668c3a64596d27112c645c39d4949acabf3cbd45e610405e93c048d5b3438b1cfa69b
@@ -16,20 +16,20 @@ module Gollum
16
16
 
17
17
  DEFAULT_MIME_TYPE = "text/plain"
18
18
  class NoSuchShaFound < StandardError; end
19
-
19
+
20
20
  class Actor
21
-
21
+
22
22
  attr_accessor :name, :email
23
23
 
24
24
  def self.default_actor
25
25
  self.new("Gollum", "Gollum@wiki")
26
26
  end
27
-
27
+
28
28
  def initialize(name, email)
29
29
  @name = name
30
30
  @email = email
31
31
  end
32
-
32
+
33
33
  def output(time)
34
34
  # implementation from grit
35
35
  offset = time.utc_offset / 60
@@ -44,9 +44,9 @@ module Gollum
44
44
  def to_h
45
45
  {:name => @name, :email => @email}
46
46
  end
47
-
47
+
48
48
  end
49
-
49
+
50
50
  class Blob
51
51
 
52
52
  attr_reader :mode
@@ -57,7 +57,7 @@ module Gollum
57
57
  blob = repo.git.lookup(options[:id])
58
58
  self.new(blob, options)
59
59
  end
60
-
60
+
61
61
  def initialize(blob, options = {})
62
62
  @blob = blob
63
63
  @mode = options[:mode]
@@ -65,11 +65,11 @@ module Gollum
65
65
  @size = options[:size]
66
66
  @id = blob.oid
67
67
  end
68
-
68
+
69
69
  def data
70
70
  @content ||= @blob.content
71
71
  end
72
-
72
+
73
73
  def is_symlink
74
74
  @mode == 0120000
75
75
  end
@@ -90,33 +90,34 @@ module Gollum
90
90
  nil
91
91
  end
92
92
  end
93
-
93
+
94
94
  class Commit
95
-
96
- def initialize(commit)
95
+
96
+ def initialize(commit, tracked_pathname = nil)
97
97
  @commit = commit
98
+ @tracked_pathname = tracked_pathname
98
99
  end
99
-
100
+
100
101
  def id
101
102
  @commit.oid
102
103
  end
103
104
  alias_method :sha, :id
104
105
  alias_method :to_s, :id
105
106
 
106
- attr_reader :commit
107
+ attr_reader :commit, :tracked_pathname
107
108
 
108
109
  def author
109
110
  @author ||= Gollum::Git::Actor.new(@commit.author[:name], @commit.author[:email])
110
111
  end
111
-
112
+
112
113
  def authored_date
113
114
  @commit.author[:time]
114
115
  end
115
-
116
+
116
117
  def message
117
118
  @commit.message
118
119
  end
119
-
120
+
120
121
  def tree
121
122
  Gollum::Git::Tree.new(@commit.tree)
122
123
  end
@@ -134,65 +135,92 @@ module Gollum
134
135
  files = []
135
136
  parent = @commit.parents.first
136
137
  diff = Rugged::Tree.diff(@commit.tree.repo, parent ? parent.tree : nil, @commit.tree)
138
+ diff.find_similar!
137
139
  diff = diff.each_patch do |patch|
138
- new_additions = patch.stat[1]
139
- new_deletions = patch.stat[0]
140
+ new_additions = patch.additions
141
+ new_deletions = patch.deletions
140
142
  additions += new_additions
141
143
  deletions += new_deletions
142
144
  total += patch.changes
143
- files << [patch.delta.new_file[:path].force_encoding("UTF-8"), new_deletions, new_additions, patch.changes] # Rugged seems to generate the stat diffs in the other direciton than grit does by default, so switch the order of additions and deletions.
145
+ files << {
146
+ new_file: patch.delta.new_file[:path].force_encoding("UTF-8"),
147
+ old_file: patch.delta.renamed? ? patch.delta.old_file[:path].force_encoding("UTF-8") : nil,
148
+ new_deletions: new_deletions,
149
+ new_additions: new_additions,
150
+ changes: patch.changes
151
+ }
144
152
  end
145
153
  OpenStruct.new(:additions => additions, :deletions => deletions, :files => files, :id => id, :total => total)
146
154
  end
147
-
155
+
148
156
  end
149
-
157
+
150
158
  class Git
151
-
159
+
152
160
  # Rugged does not have a Git class, but the Repository class should allows us to do what's necessary.
153
161
  def initialize(repo)
154
162
  @repo = repo
155
163
  end
156
-
164
+
157
165
  def exist?
158
166
  ::File.exists?(@repo.path)
159
167
  end
160
-
161
- def grep(query, options={})
162
- ref = options[:ref] ? options[:ref] : "HEAD"
163
- tree = @repo.lookup(sha_from_ref(ref)).tree
164
- tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
168
+
169
+ def grep(search_terms, options={}, &block)
170
+ ref = options[:ref] ? options[:ref] : "HEAD"
171
+ tree = @repo.lookup(sha_from_ref(ref)).tree
172
+ tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
173
+ enc = options.fetch(:encoding, 'utf-8')
165
174
  results = []
166
175
  tree.walk_blobs(:postorder) do |root, entry|
167
- blob = @repo.lookup(entry[:oid])
168
- count = 0
169
- blob.content.each_line do |line|
170
- next unless line.force_encoding("UTF-8").match(/#{Regexp.escape(query)}/i)
171
- count += 1
172
- end
173
- path = options[:path] ? ::File.join(options[:path], root, entry[:name]) : "#{root}#{entry[:name]}"
174
- results << {:name => path, :count => count} unless count == 0
176
+ blob = @repo.lookup(entry[:oid])
177
+ path = options[:path] ? ::File.join(options[:path], root, entry[:name]) : "#{root}#{entry[:name]}"
178
+ data = blob.binary? ? nil : blob.content.force_encoding(enc)
179
+ results << yield(path, data)
175
180
  end
176
- results
181
+ results.compact
177
182
  end
178
-
183
+
179
184
  def rm(path, options = {})
180
185
  index = @repo.index
181
186
  index.write
182
- ::File.unlink ::File.join(@repo.workdir, path)
187
+ to_delete = ::File.join(@repo.workdir, path)
188
+ ::File.unlink to_delete if ::File.exist?(to_delete)
183
189
  end
184
190
 
185
191
  def cat_file(options, sha)
186
192
  @repo.lookup(sha).read_raw
187
193
  end
188
194
 
189
- def apply_patch(head_sha = 'HEAD', patch=nil)
190
- false # Rewrite gollum-lib's revert so that it doesn't require a direct equivalent of Grit's apply_patch
195
+ def revert_path(path, sha1, sha2)
196
+ diff = @repo.diff(sha2, sha1, {:paths => [path]}).first.diff
197
+ begin
198
+ result = @repo.apply(diff, {:location => :index, :path => path})
199
+ rescue RuntimeError
200
+ return false
201
+ end
202
+ begin
203
+ return @repo.index.write_tree
204
+ rescue Rugged::IndexError
205
+ return false
206
+ end
191
207
  end
192
208
 
193
- def revert(path, sha1, sha2, ref)
194
- # FIXME: See https://github.com/gollum/grit_adapter/pull/14
195
- fail NotImplementedError
209
+ def revert_commit(sha1, sha2)
210
+ diff = @repo.diff(sha2, sha1)
211
+ index = @repo.revert_commit(sha2, sha1)
212
+ return false unless index
213
+ paths = []
214
+ diff.each_delta do |delta|
215
+ paths << delta.new_file[:path]
216
+ paths << delta.old_file[:path]
217
+ end
218
+ paths.uniq!
219
+ begin
220
+ return index.write_tree(@repo), paths
221
+ rescue Rugged::IndexError
222
+ return false
223
+ end
196
224
  end
197
225
 
198
226
  def checkout(path, ref = 'HEAD', options = {})
@@ -230,7 +258,7 @@ module Gollum
230
258
  def versions_for_path(path = nil, ref = nil, options = {})
231
259
  log(ref, path, options)
232
260
  end
233
-
261
+
234
262
  def ls_files(query, options = {})
235
263
  ref = options[:ref] || "refs/heads/master"
236
264
  tree = @repo.lookup(sha_from_ref(ref)).tree
@@ -270,7 +298,7 @@ module Gollum
270
298
  end
271
299
  end
272
300
  alias_method :sha_from_ref, :sha_or_commit_from_ref
273
-
301
+
274
302
  def commit_from_ref(ref)
275
303
  sha_or_commit_from_ref(ref, :commit)
276
304
  end
@@ -308,7 +336,7 @@ module Gollum
308
336
  !!(str =~ /^[0-9a-f]{40}$/)
309
337
  end
310
338
 
311
- # Return an array of log commits, given an SHA hash and a hash of
339
+ # Return an array of log commits, given a SHA hash and a hash of
312
340
  # options. From Gitlab::Git
313
341
  def build_log(sha, options)
314
342
  # Instantiate a Walker and add the SHA hash
@@ -316,8 +344,9 @@ module Gollum
316
344
  walker.push(sha)
317
345
  commits = []
318
346
  skipped = 0
319
- current_path = options[:path]
347
+ current_path = options[:path].dup if options[:path]
320
348
  current_path = nil if current_path == ''
349
+ track_pathnames = true if current_path && options[:follow]
321
350
  limit = options[:limit].to_i
322
351
  offset = options[:offset].to_i
323
352
  skip_merges = options[:skip_merges]
@@ -330,12 +359,11 @@ module Gollum
330
359
  next if c.parents.length > 1
331
360
  end
332
361
 
333
- if !current_path ||
334
- commit_touches_path?(c, current_path, options[:follow], walker)
362
+ if !current_path || commit_touches_path?(c, current_path, options[:follow], walker)
335
363
  # This is a commit we care about, unless we haven't skipped enough
336
364
  # yet
337
365
  skipped += 1
338
- commits.push(Gollum::Git::Commit.new(c)) if skipped > offset
366
+ commits.push(Gollum::Git::Commit.new(c, track_pathnames ? current_path.dup : nil)) if skipped > offset
339
367
  end
340
368
  end
341
369
  walker.reset
@@ -363,7 +391,7 @@ module Gollum
363
391
 
364
392
  # Only follow the first TREESAME parent for merge commits
365
393
  if num_treesame > 0
366
- walker.hide(parent)
394
+ walker.hide(parent.oid)
367
395
  next
368
396
  end
369
397
 
@@ -388,11 +416,8 @@ module Gollum
388
416
  tmp_entry = nil
389
417
 
390
418
  pathname.each_filename do |dir|
391
- if tmp_entry.nil?
392
- tmp_entry = commit.tree[dir]
393
- else
394
- tmp_entry = @repo.lookup(tmp_entry[:oid])[dir]
395
- end
419
+ tmp_entry = tmp_entry ? @repo.lookup(tmp_entry[:oid])[dir] : commit.tree[dir]
420
+ return nil unless tmp_entry
396
421
  end
397
422
  tmp_entry
398
423
  end
@@ -405,7 +430,7 @@ module Gollum
405
430
  # If +path+ is a filename, not a directory, then we should only have
406
431
  # one delta. We don't need to follow renames for directories.
407
432
  return nil if diff.each_delta.count > 1
408
-
433
+
409
434
  delta = diff.each_delta.first
410
435
  if delta.added?
411
436
  full_diff = parent.diff(commit)
@@ -419,23 +444,23 @@ module Gollum
419
444
  end
420
445
  end
421
446
  end
422
-
447
+
423
448
  end
424
-
449
+
425
450
  class Index
426
-
451
+
427
452
  def initialize(index, repo)
428
453
  @index = index
429
454
  @rugged_repo = repo
430
455
  @treemap = {}
431
456
  end
432
-
457
+
433
458
  def delete(path)
434
459
  @index.remove_all(path)
435
460
  update_treemap(path, false)
436
461
  false
437
462
  end
438
-
463
+
439
464
  def add(path, data)
440
465
  blob = @rugged_repo.write(data, :blob)
441
466
  @index.add(:path => path, :oid => blob, :mode => 0100644)
@@ -446,7 +471,7 @@ module Gollum
446
471
  def index
447
472
  @index
448
473
  end
449
-
474
+
450
475
  def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
451
476
  commit_options = {}
452
477
  head = "refs/heads/#{head}" unless head =~ /^refs\/heads\//
@@ -460,11 +485,11 @@ module Gollum
460
485
  commit_options[:update_ref] = head
461
486
  Rugged::Commit.create(@rugged_repo, commit_options)
462
487
  end
463
-
488
+
464
489
  def tree
465
490
  @treemap
466
491
  end
467
-
492
+
468
493
  def read_tree(id)
469
494
  id = Gollum::Git::Git.new(@rugged_repo).ref_to_sha(id)
470
495
  return nil if id.nil?
@@ -473,7 +498,7 @@ module Gollum
473
498
  @index.read_tree(current_tree)
474
499
  @current_tree = Gollum::Git::Tree.new(current_tree)
475
500
  end
476
-
501
+
477
502
  def current_tree
478
503
  @current_tree
479
504
  end
@@ -495,115 +520,111 @@ module Gollum
495
520
  path = path[1..-1] if path[0] == ::File::SEPARATOR
496
521
  path = path.split(::File::SEPARATOR)
497
522
  last = path.pop
498
-
523
+
499
524
  current = @treemap
500
-
525
+
501
526
  path.each do |dir|
502
527
  current[dir] ||= {}
503
528
  node = current[dir]
504
529
  current = node
505
530
  end
506
-
531
+
507
532
  current[last] = data
508
533
  @treemap
509
534
  end
510
535
 
511
536
  end
512
-
537
+
513
538
  class Ref
514
539
  def initialize(ref)
515
540
  @ref = ref
516
541
  end
517
-
542
+
518
543
  def name
519
544
  @ref.name
520
545
  end
521
-
546
+
522
547
  def commit
523
548
  Gollum::Git::Commit.new(@ref.target)
524
549
  end
525
-
550
+
526
551
  end
527
-
552
+
528
553
  class Repo
529
-
554
+
530
555
  def initialize(path, options)
531
- begin
532
- @repo = Rugged::Repository.new(path, options)
533
- #rescue Grit::InvalidGitRepositoryError
534
- # raise Gollum::InvalidGitRepositoryError
535
- #rescue Grit::NoSuchPathError
536
- # raise Gollum::NoSuchPathError
537
- end
556
+ @repo = Rugged::Repository.new(path, options)
538
557
  end
539
-
558
+
540
559
  def self.init(path)
541
560
  Rugged::Repository.init_at(path, false)
542
561
  self.new(path, :is_bare => false)
543
562
  end
544
-
563
+
545
564
  def self.init_bare(path)
546
565
  Rugged::Repository.init_at(path, true)
547
566
  self.new(path, :is_bare => true)
548
567
  end
549
-
568
+
550
569
  def bare
551
570
  @repo.bare?
552
571
  end
553
-
572
+
554
573
  def config
555
574
  @repo.config
556
575
  end
557
-
576
+
558
577
  def git
559
578
  @git ||= Gollum::Git::Git.new(@repo)
560
579
  end
561
-
580
+
562
581
  def commit(id)
563
582
  git.commit_from_ref(id)
564
583
  end
565
-
584
+
566
585
  def commits(start = 'refs/heads/master', max_count = 10, skip = 0)
567
586
  git.log(start, nil, :max_count => max_count, :skip => skip)
568
587
  end
569
-
588
+
570
589
  def head
571
- Gollum::Git::Ref.new(@repo.head)
590
+ begin
591
+ return Gollum::Git::Ref.new(@repo.head)
592
+ rescue Rugged::ReferenceError
593
+ return nil
594
+ end
572
595
  end
573
-
596
+
574
597
  def index
575
598
  @index ||= Gollum::Git::Index.new(@repo.index, @repo)
576
599
  end
577
600
 
578
601
  def diff(sha1, sha2, *paths)
579
- opts = path == nil ? {} : {:path => path}
580
- patches = @repo.diff(sha1, sha2, opts).patches
581
- if not paths.empty?
582
- patches.keep_if { |p| paths.include? p.delta.new_file[:path] }
583
- end
584
- patches.map {|patch| OpenStruct.new(:diff => patch.to_s.split("\n")[2..-1].join("\n").force_encoding("UTF-8"))}.reverse # First remove two superfluous lines. Rugged seems to order the diffs differently than Grit, so reverse.
602
+ opts = paths.nil? ? {} : {:paths => paths}
603
+ @repo.diff(sha1, sha2, opts).diff.patches.map do |patch|
604
+ OpenStruct.new(:diff => patch.to_s.split("\n")[2..-1].join("\n").force_encoding("UTF-8")) # First remove two superfluous lines.
605
+ end.reverse # Rugged seems to order the diffs differently than Grit, so reverse.
585
606
  end
586
-
607
+
587
608
  def log(commit = 'refs/heads/master', path = nil, options = {})
588
609
  git.log(commit, path, options)
589
610
  end
590
-
611
+
591
612
  def lstree(sha, options = {})
592
613
  results = []
593
614
  @repo.lookup(sha).tree.walk(:postorder) do |root, entry|
594
615
  entry[:sha] = entry[:oid]
595
616
  entry[:mode] = entry[:filemode].to_s(8)
596
617
  entry[:type] = entry[:type].to_s
597
- entry[:path] = "#{root}#{entry[:name]}"
618
+ entry[:path] = "#{root}#{entry[:name]}"
598
619
  results << entry
599
620
  end
600
621
  results
601
622
  end
602
-
623
+
603
624
  def path
604
625
  @repo.path
605
626
  end
606
-
627
+
607
628
  # Checkout branch and if necessary first create it. Currently used only in gollum-lib's tests.
608
629
  def update_ref(ref, commit_sha)
609
630
  ref = "refs/heads/#{ref}" unless ref =~ /^refs\/heads\//
@@ -617,23 +638,23 @@ module Gollum
617
638
  end
618
639
 
619
640
  class Tree
620
-
641
+
621
642
  def initialize(tree)
622
643
  @tree = tree
623
644
  end
624
-
645
+
625
646
  def keys
626
647
  @tree.map{|entry| entry[:name]}
627
648
  end
628
-
649
+
629
650
  def [](i)
630
651
  @tree[i]
631
652
  end
632
-
653
+
633
654
  def id
634
655
  @tree.oid
635
656
  end
636
-
657
+
637
658
  def /(file)
638
659
  return self if file == '/'
639
660
  begin
@@ -645,7 +666,7 @@ module Gollum
645
666
  obj = @tree.owner.lookup(obj[:oid])
646
667
  obj.is_a?(Rugged::Tree) ? Gollum::Git::Tree.new(obj) : Gollum::Git::Blob.new(obj)
647
668
  end
648
-
669
+
649
670
  def blobs
650
671
  blobs = []
651
672
  @tree.each_blob {|blob| blobs << Gollum::Git::Blob.new(@tree.owner.lookup(blob[:oid]), blob) }
@@ -653,6 +674,6 @@ module Gollum
653
674
  end
654
675
 
655
676
  end
656
-
677
+
657
678
  end
658
679
  end
@@ -1,7 +1,7 @@
1
1
  module Gollum
2
2
  module Lib
3
3
  module Git
4
- VERSION = '0.4.4'
4
+ VERSION = '0.99'
5
5
  end
6
6
  end
7
7
  end
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Adapter for Gollum to use Rugged (libgit2) at the backend.}
14
14
  s.license = "MIT"
15
15
 
16
- s.add_runtime_dependency 'rugged', '~> 0.25'
16
+ s.add_runtime_dependency 'rugged', '~> 0.99'
17
17
  s.add_runtime_dependency 'mime-types', '>= 1.15'
18
- s.add_development_dependency "rspec", "3.4.0"
18
+ s.add_development_dependency 'rspec', "3.4.0"
19
19
 
20
20
  s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
21
21
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-rugged_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: '0.99'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bart Kamphorst, Dawa Ometto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2020-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.25'
19
+ version: '0.99'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.25'
26
+ version: '0.99'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.15'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.15'
41
41
  - !ruby/object:Gem::Dependency
@@ -77,17 +77,17 @@ require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.2.2
90
+ rubygems_version: 2.7.8
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Adapter for Gollum to use Rugged (libgit2) at the backend.