gitlab-gollum-rugged_adapter 0.4.4.2 → 0.4.4.3.gitlab.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 415639f73ca1446976691bb097576d53e077e1b7
4
- data.tar.gz: 9fca45257ca9a9349a347bad320f1319d58ab994
2
+ SHA256:
3
+ metadata.gz: 6b1303d0b8d7932f85d730fe280edff577c0d1dc3fe54699778e7db553a34dc3
4
+ data.tar.gz: c291c4ed819401f11eeddc7af37a332e7b429133f79fea6c4814ecbcbf43e108
5
5
  SHA512:
6
- metadata.gz: 6ad11281e0d2166427d87cb343958021c6ee34aaf8a40a562c3f7c26cf9de0413b4aa178324c74b2f293937c55741c2933e1f97585cb8b845a8d7246494f731d
7
- data.tar.gz: 29f6a3603a7fef2a6e8f813f4c39a5368c551c70e611914158326dbc3e0dba59200c82cd47eb62d08b4509defe1cb4f5b615da47a8cb46e023eb0be37c723396
6
+ metadata.gz: 8b33ca987b9006c581659b6ccf674c8819202de3b065bab35eee125b58a2d921894be1b7b391460caea74e7d488216fc5fed34945668c24ab1d149c00bec7734
7
+ data.tar.gz: 843bf6be50e90c77c5da6bd93d67ccd7671c73314cf58a0e0f400d32e645bcf497194fccde8cccec3ff1ef1bd1e196fbea9d7a38f1e018a306dbe369da8c5dd8
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
- [![Gem Version](https://badge.fury.io/rb/gollum-rugged_adapter.svg)](http://badge.fury.io/rb/gollum-rugged_adapter)
2
- [![Build Status](https://travis-ci.org/gollum/rugged_adapter.svg?branch=master)](https://travis-ci.org/gollum/rugged_adapter)
3
- [![Dependency Status](https://gemnasium.com/gollum/rugged_adapter.svg)](https://gemnasium.com/gollum/rugged_adapter)
1
+ GitLab gollum rugged adapter
4
2
 
5
- ## DESCRIPTION
3
+ ## This is a fork
4
+
5
+ This is a GitLab fork
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/gitlab-gollum-rugged_adapter.svg)](http://badge.fury.io/rb/gitlab-gollum-rugged_adapter)
8
+ [![pipeline status](https://gitlab.com/gitlab-org/gitlab-gollum-rugged_adapter/badges/master/pipeline.svg)](https://gitlab.com/gitlab-org/gitlab-gollum-rugged_adapter/-/commits/master)
9
+
10
+ ## Description
6
11
 
7
12
  Adapter for [gollum](https://github.com/gollum/gollum) to use [Rugged](https://github.com/libgit2/rugged) (libgit2) at the backend. See the [gollum wiki](https://github.com/gollum/gollum/wiki/Git-adapters) for more information on adapters. Currently gollum uses grit as a backend by default, but since that is abandonware, the plan is to make this adapter the default in the future.
8
13
 
9
14
  **Please note that this adapter is currently in beta. It passes the unit tests for gollum and [gollum-lib](https://github.com/gollum/gollum-lib), but it needs more comprehensive testing. Please [report any issues](https://github.com/gollum/rugged_adapter/issues) that you encounter.**
10
15
 
11
- ## USAGE
16
+ ## Usage
12
17
 
13
18
  Install the gem:
14
19
 
@@ -22,7 +27,7 @@ Now run gollum as follows:
22
27
  gollum --adapter rugged
23
28
  ```
24
29
 
25
- ## CONTRIBUTING
30
+ ## Contributing
26
31
 
27
32
  1. Start by cloning the repo [on GitHub](http://github.com/gollum/rugged_adapter).
28
33
  2. From inside the repo's directory, install the (development) dependencies with `bundle install`
@@ -39,6 +44,14 @@ gollum --adapter rugged
39
44
  1. Push the branch up to GitHub.
40
45
  1. Send a pull request to the gollum/rugged_adapter project.
41
46
 
42
- ## RELEASING
47
+ ## Releasing a new GitLab fork version
43
48
 
44
49
  This gem uses [Semantic Versioning](http://semver.org/).
50
+
51
+ 1. Check the upstream gem at https://github.com/gollum/rugged_adapter and merge any needed changes.
52
+ 1. Bump version in `lib/rugged_adapter/version.rb`.
53
+ - Use the version of the upstream gem and add `.gitlab.$VERSION`, e.g. for the `1.0` version use `1.0.gitlab.1`.
54
+ 1. Run `bundle install` to make sure `Gemfile.lock` is up-to-date.
55
+ 1. Commit all changes.
56
+ 1. Tag release and publish gem with `rake release`.
57
+ - Use a personal work account for this.
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rugged_adapter/git_layer_rugged.rb'
@@ -1,4 +1,4 @@
1
- # ~*~ encoding: utf-8 ~*~
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'rugged'
4
4
  require 'ostruct'
@@ -19,15 +19,16 @@ module Gollum
19
19
 
20
20
  class Actor
21
21
 
22
- attr_accessor :name, :email
22
+ attr_accessor :name, :email, :time
23
23
 
24
24
  def self.default_actor
25
25
  self.new("Gollum", "Gollum@wiki")
26
26
  end
27
27
 
28
- def initialize(name, email)
28
+ def initialize(name, email, time = nil)
29
29
  @name = name
30
30
  @email = email
31
+ @time = time
31
32
  end
32
33
 
33
34
  def output(time)
@@ -42,7 +43,7 @@ module Gollum
42
43
  end
43
44
 
44
45
  def to_h
45
- {:name => @name, :email => @email}
46
+ {:name => @name, :email => @email, :time => @time}
46
47
  end
47
48
 
48
49
  end
@@ -93,8 +94,9 @@ module Gollum
93
94
 
94
95
  class Commit
95
96
 
96
- def initialize(commit)
97
+ def initialize(commit, tracked_pathname = nil)
97
98
  @commit = commit
99
+ @tracked_pathname = tracked_pathname
98
100
  end
99
101
 
100
102
  def id
@@ -103,7 +105,7 @@ module Gollum
103
105
  alias_method :sha, :id
104
106
  alias_method :to_s, :id
105
107
 
106
- attr_reader :commit
108
+ attr_reader :commit, :tracked_pathname
107
109
 
108
110
  def author
109
111
  @author ||= Gollum::Git::Actor.new(@commit.author[:name], @commit.author[:email])
@@ -125,6 +127,10 @@ module Gollum
125
127
  @stats ||= build_stats
126
128
  end
127
129
 
130
+ def parent
131
+ @commit.parents.empty? ? nil : Gollum::Git::Commit.new(@commit.parents.first)
132
+ end
133
+
128
134
  private
129
135
 
130
136
  def build_stats
@@ -135,12 +141,12 @@ module Gollum
135
141
  parent = @commit.parents.first
136
142
  diff = Rugged::Tree.diff(@commit.tree.repo, parent ? parent.tree : nil, @commit.tree)
137
143
  diff = diff.each_patch do |patch|
138
- new_additions = patch.stat[1]
139
- new_deletions = patch.stat[0]
144
+ new_additions = patch.additions
145
+ new_deletions = patch.deletions
140
146
  additions += new_additions
141
147
  deletions += new_deletions
142
148
  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.
149
+ files << [patch.delta.new_file[:path].force_encoding("UTF-8"), new_additions, new_deletions, patch.changes]
144
150
  end
145
151
  OpenStruct.new(:additions => additions, :deletions => deletions, :files => files, :id => id, :total => total)
146
152
  end
@@ -162,12 +168,14 @@ module Gollum
162
168
  ref = options[:ref] ? options[:ref] : "HEAD"
163
169
  tree = @repo.lookup(sha_from_ref(ref)).tree
164
170
  tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
171
+ enc = options.fetch(:encoding, 'utf-8')
165
172
  results = []
166
173
  tree.walk_blobs(:postorder) do |root, entry|
167
174
  blob = @repo.lookup(entry[:oid])
168
175
  count = 0
169
- blob.content.each_line do |line|
170
- next unless line.force_encoding("UTF-8").match(/#{Regexp.escape(query)}/i)
176
+ next if blob.binary?
177
+ blob.content.force_encoding(enc).each_line do |line|
178
+ next unless line.match(/#{query}/i)
171
179
  count += 1
172
180
  end
173
181
  path = options[:path] ? ::File.join(options[:path], root, entry[:name]) : "#{root}#{entry[:name]}"
@@ -199,7 +207,7 @@ module Gollum
199
207
  path = path.nil? ? path : [path]
200
208
  options = options.merge({:paths => path, :strategy => :force})
201
209
  if ref == 'HEAD'
202
- @repo.checkout_head(options)
210
+ @repo.checkout_head(**options)
203
211
  else
204
212
  ref = "refs/heads/#{ref}" unless ref =~ /^refs\/heads\//
205
213
  @repo.checkout_tree(sha_from_ref(ref), options)
@@ -308,7 +316,7 @@ module Gollum
308
316
  !!(str =~ /^[0-9a-f]{40}$/)
309
317
  end
310
318
 
311
- # Return an array of log commits, given an SHA hash and a hash of
319
+ # Return an array of log commits, given a SHA hash and a hash of
312
320
  # options. From Gitlab::Git
313
321
  def build_log(sha, options)
314
322
  # Instantiate a Walker and add the SHA hash
@@ -316,8 +324,10 @@ module Gollum
316
324
  walker.push(sha)
317
325
  commits = []
318
326
  skipped = 0
319
- current_path = options[:path]
327
+ current_path = options[:path].dup if options[:path]
320
328
  current_path = nil if current_path == ''
329
+ renamed_path = current_path.nil? ? nil : current_path.dup
330
+ track_pathnames = true if current_path && options[:follow]
321
331
  limit = options[:limit].to_i
322
332
  offset = options[:offset].to_i
323
333
  skip_merges = options[:skip_merges]
@@ -329,13 +339,13 @@ module Gollum
329
339
  # Skip merge commits
330
340
  next if c.parents.length > 1
331
341
  end
332
-
333
- if !current_path ||
334
- commit_touches_path?(c, current_path, options[:follow], walker)
342
+ if !current_path || commit_touches_path?(c, current_path, options[:follow], walker)
335
343
  # This is a commit we care about, unless we haven't skipped enough
336
344
  # yet
337
345
  skipped += 1
338
- commits.push(Gollum::Git::Commit.new(c)) if skipped > offset
346
+
347
+ commits.push(Gollum::Git::Commit.new(c, track_pathnames ? renamed_path : nil)) if skipped > offset
348
+ renamed_path = current_path.nil? ? nil : current_path.dup
339
349
  end
340
350
  end
341
351
  walker.reset
@@ -363,7 +373,7 @@ module Gollum
363
373
 
364
374
  # Only follow the first TREESAME parent for merge commits
365
375
  if num_treesame > 0
366
- walker.hide(parent)
376
+ walker.hide(parent.oid)
367
377
  next
368
378
  end
369
379
 
@@ -388,12 +398,7 @@ module Gollum
388
398
  tmp_entry = nil
389
399
 
390
400
  pathname.each_filename do |dir|
391
- tmp_entry = if tmp_entry.nil?
392
- commit.tree[dir]
393
- else
394
- @repo.lookup(tmp_entry[:oid])[dir]
395
- end
396
-
401
+ tmp_entry = tmp_entry ? @repo.lookup(tmp_entry[:oid])[dir] : commit.tree[dir]
397
402
  return nil unless tmp_entry
398
403
  end
399
404
  tmp_entry
@@ -479,9 +484,13 @@ module Gollum
479
484
  def read_tree(id)
480
485
  id = Gollum::Git::Git.new(@rugged_repo).ref_to_sha(id)
481
486
  return nil if id.nil?
482
- current_tree = @rugged_repo.lookup(id)
483
- current_tree = current_tree.tree unless current_tree.is_a?(Rugged::Tree)
484
- @index.read_tree(current_tree)
487
+ begin
488
+ current_tree = @rugged_repo.lookup(id)
489
+ current_tree = current_tree.tree unless current_tree.is_a?(Rugged::Tree)
490
+ @index.read_tree(current_tree)
491
+ rescue
492
+ raise Gollum::Git::NoSuchShaFound
493
+ end
485
494
  @current_tree = Gollum::Git::Tree.new(current_tree)
486
495
  end
487
496
 
@@ -539,13 +548,7 @@ module Gollum
539
548
  class Repo
540
549
 
541
550
  def initialize(path, options)
542
- begin
543
- @repo = Rugged::Repository.new(path, options)
544
- #rescue Grit::InvalidGitRepositoryError
545
- # raise Gollum::InvalidGitRepositoryError
546
- #rescue Grit::NoSuchPathError
547
- # raise Gollum::NoSuchPathError
548
- end
551
+ @repo = Rugged::Repository.new(path, **options)
549
552
  end
550
553
 
551
554
  def self.init(path)
@@ -571,7 +574,11 @@ module Gollum
571
574
  end
572
575
 
573
576
  def commit(id)
574
- git.commit_from_ref(id)
577
+ begin
578
+ git.commit_from_ref(id)
579
+ rescue
580
+ raise Gollum::Git::NoSuchShaFound
581
+ end
575
582
  end
576
583
 
577
584
  def commits(start = 'refs/heads/master', max_count = 10, skip = 0)
@@ -579,7 +586,11 @@ module Gollum
579
586
  end
580
587
 
581
588
  def head
582
- Gollum::Git::Ref.new(@repo.head)
589
+ begin
590
+ return Gollum::Git::Ref.new(@repo.head)
591
+ rescue Rugged::ReferenceError
592
+ return nil
593
+ end
583
594
  end
584
595
 
585
596
  def index
@@ -587,12 +598,8 @@ module Gollum
587
598
  end
588
599
 
589
600
  def diff(sha1, sha2, *paths)
590
- opts = path == nil ? {} : {:path => path}
591
- patches = @repo.diff(sha1, sha2, opts).patches
592
- if not paths.empty?
593
- patches.keep_if { |p| paths.include? p.delta.new_file[:path] }
594
- end
595
- 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.
601
+ opts = paths.nil? ? {} : {:paths => paths}
602
+ @repo.diff(sha1, sha2, opts).patch
596
603
  end
597
604
 
598
605
  def log(commit = 'refs/heads/master', path = nil, options = {})
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gollum
2
4
  module Lib
3
5
  module Git
4
- VERSION = '0.4.4.2'
6
+ VERSION = '0.4.4.3.gitlab.1'
5
7
  end
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-gollum-rugged_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4.2
4
+ version: 0.4.4.3.gitlab.1
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: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.25'
19
+ version: '1.0'
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: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,14 +59,11 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - Gemfile
63
62
  - LICENSE
64
63
  - README.md
65
- - Rakefile
66
64
  - lib/rugged_adapter.rb
67
65
  - lib/rugged_adapter/git_layer_rugged.rb
68
66
  - lib/rugged_adapter/version.rb
69
- - rugged_adapter.gemspec
70
67
  homepage: https://gitlab.com/gitlab-org/gitlab-gollum-rugged_adapter
71
68
  licenses:
72
69
  - MIT
@@ -82,12 +79,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
79
  version: '0'
83
80
  required_rubygems_version: !ruby/object:Gem::Requirement
84
81
  requirements:
85
- - - ">="
82
+ - - ">"
86
83
  - !ruby/object:Gem::Version
87
- version: '0'
84
+ version: 1.3.1
88
85
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.5.2
86
+ rubygems_version: 3.0.3
91
87
  signing_key:
92
88
  specification_version: 4
93
89
  summary: Adapter for Gollum to use Rugged (libgit2) at the backend.
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
- gem 'rake', '~> 10.4.2'
5
- gem 'adapter_specs', git: 'https://github.com/gollum/adapter_specs.git'
6
-
7
- group :test do
8
- gem "simplecov"
9
- end
data/Rakefile DELETED
@@ -1,126 +0,0 @@
1
- require 'rubygems'
2
-
3
- task :default => :rspec
4
-
5
- require 'rspec/core/rake_task'
6
-
7
- def name
8
- "rugged_adapter"
9
- end
10
-
11
- def version
12
- line = File.read("lib/rugged_adapter/version.rb")[/^\s*VERSION\s*=\s*.*/]
13
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
14
- end
15
-
16
- # assumes x.y.z all digit version
17
- def next_version
18
- # x.y.z
19
- v = version.split '.'
20
- # bump z
21
- v[-1] = v[-1].to_i + 1
22
- v.join '.'
23
- end
24
-
25
- def bump_version
26
- old_file = File.read("lib/#{name}/version.rb")
27
- old_version_line = old_file[/^\s*VERSION\s*=\s*.*/]
28
- new_version = next_version
29
- # replace first match of old version with new version
30
- old_file.sub!(old_version_line, " VERSION = '#{new_version}'")
31
-
32
- File.write("lib/#{name}/version.rb", old_file)
33
-
34
- new_version
35
- end
36
-
37
- def date
38
- Date.today.to_s
39
- end
40
-
41
- def gemspec
42
- "#{name}.gemspec"
43
- end
44
-
45
- def gem_file
46
- "gollum-#{name}-#{version}.gem"
47
- end
48
-
49
- def replace_header(head, header_name)
50
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
51
- end
52
-
53
- desc "Run specs."
54
- RSpec::Core::RakeTask.new(:rspec) do |spec|
55
- ruby_opts = "-w"
56
- spec.pattern = 'spec/**/*_spec.rb'
57
- spec.rspec_opts = ['--backtrace --color']
58
- end
59
-
60
- desc "Update version number and gemspec"
61
- task :bump do
62
- puts "Updated version to #{bump_version}"
63
- # Execute does not invoke dependencies.
64
- # Manually invoke gemspec then validate.
65
- Rake::Task[:gemspec].execute
66
- Rake::Task[:validate].execute
67
- end
68
-
69
- desc 'Create a release build'
70
- task :release => :build do
71
- unless `git branch` =~ /^\* master$/
72
- puts "You must be on the master branch to release!"
73
- exit!
74
- end
75
- sh "git commit --allow-empty -a -m 'Release #{version}'"
76
- sh "git pull --rebase origin master"
77
- sh "git tag v#{version}"
78
- sh "git push origin master"
79
- sh "git push origin v#{version}"
80
- sh "gem push pkg/#{gem_file}"
81
- end
82
-
83
- desc 'Publish to rubygems. Same as release'
84
- task :publish => :release
85
-
86
- desc 'Build gem'
87
- task :build => :gemspec do
88
- sh "mkdir -p pkg"
89
- sh "gem build #{gemspec}"
90
- sh "mv #{gem_file} pkg"
91
- end
92
-
93
- desc 'Update gemspec'
94
- task :gemspec => :validate do
95
- # read spec file and split out manifest section
96
- spec = File.read(gemspec)
97
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
98
-
99
- # replace name version and date
100
- replace_header(head, :name)
101
- replace_header(head, :date)
102
-
103
- # determine file list from git ls-files
104
- files = `git ls-files`.
105
- split("\n").
106
- sort.
107
- reject { |file| file =~ /^\./ }.
108
- reject { |file| file =~ /^(rdoc|pkg|spec|\.gitattributes|Guardfile)/ }.
109
- map { |file| " #{file}" }.
110
- join("\n")
111
-
112
- # piece file back together and write
113
- manifest = " s.files = %w(\n#{files}\n )\n"
114
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
115
- File.open(gemspec, 'w') { |io| io.write(spec) }
116
- puts "Updated #{gemspec}"
117
- end
118
-
119
- desc 'Validate lib files and version file'
120
- task :validate do
121
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
122
- unless libfiles.empty?
123
- puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
124
- exit!
125
- end
126
- end
@@ -1,36 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "rugged_adapter/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "gitlab-gollum-rugged_adapter"
7
- s.version = Gollum::Lib::Git::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Bart Kamphorst, Dawa Ometto"]
10
- s.email = ["fjlopez@gitlab.com"]
11
- s.homepage = "https://gitlab.com/gitlab-org/gitlab-gollum-rugged_adapter"
12
- s.summary = %q{Adapter for Gollum to use Rugged (libgit2) at the backend.}
13
- s.description = %q{Adapter for Gollum to use Rugged (libgit2) at the backend.}
14
- s.license = "MIT"
15
-
16
- s.add_runtime_dependency 'rugged', '~> 0.25'
17
- s.add_runtime_dependency 'mime-types', '>= 1.15'
18
- s.add_development_dependency "rspec", "3.4.0"
19
-
20
- s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
21
- s.require_paths = ["lib"]
22
-
23
- # = MANIFEST =
24
- s.files = %w(
25
- Gemfile
26
- LICENSE
27
- README.md
28
- Rakefile
29
- lib/rugged_adapter.rb
30
- lib/rugged_adapter/git_layer_rugged.rb
31
- lib/rugged_adapter/version.rb
32
- rugged_adapter.gemspec
33
- )
34
- # = MANIFEST =
35
-
36
- end