gitlab_git 5.0.0 → 5.1.0
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 +4 -4
- data/VERSION +1 -0
- data/lib/gitlab_git.rb +4 -0
- data/lib/gitlab_git/blob.rb +54 -12
- data/lib/gitlab_git/branch.rb +6 -0
- data/lib/gitlab_git/commit.rb +1 -1
- data/lib/gitlab_git/ref.rb +26 -0
- data/lib/gitlab_git/repository.rb +39 -12
- data/lib/gitlab_git/tag.rb +6 -0
- data/lib/gitlab_git/tree.rb +61 -22
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27529cfedcde0463fd58df616dd0ccfc0f8d747
|
4
|
+
data.tar.gz: d9b76853f6e0ab13439e56fd8cc4c67c8d3b75ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce2de00ee1416fd9fe88d3d8987df62f046ef0c4443df8e3c1a64a24d93ca194706bb4795635ff86e4d01ab5b3087954ee00ac480b0613e33099c92ab8f10b5
|
7
|
+
data.tar.gz: b0c00d55181cb8bd403322bae01bd5f73d73578a9cac7a1b110b81997ff85d81f95f5ed4ea3932519a07ad3f35510118a3b089608e559873a4337ea41e85137e
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
5.1.0
|
data/lib/gitlab_git.rb
CHANGED
@@ -6,6 +6,7 @@ require 'linguist'
|
|
6
6
|
require 'active_support/core_ext/hash/keys'
|
7
7
|
require 'grit'
|
8
8
|
require 'grit_ext'
|
9
|
+
require 'rugged'
|
9
10
|
|
10
11
|
Grit::Blob.class_eval do
|
11
12
|
include Linguist::BlobHelper
|
@@ -24,3 +25,6 @@ require_relative "gitlab_git/tree"
|
|
24
25
|
require_relative "gitlab_git/blob_snippet"
|
25
26
|
require_relative "gitlab_git/git_stats"
|
26
27
|
require_relative "gitlab_git/log_parser"
|
28
|
+
require_relative "gitlab_git/ref"
|
29
|
+
require_relative "gitlab_git/branch"
|
30
|
+
require_relative "gitlab_git/tag"
|
data/lib/gitlab_git/blob.rb
CHANGED
@@ -7,16 +7,22 @@ module Gitlab
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def find(repository, sha, path)
|
10
|
-
commit =
|
11
|
-
|
10
|
+
commit = repository.lookup(sha)
|
11
|
+
root_tree = commit.tree
|
12
12
|
|
13
|
-
|
13
|
+
blob_entry = find_entry_by_path(repository, root_tree.oid, path)
|
14
|
+
|
15
|
+
return nil unless blob_entry
|
16
|
+
|
17
|
+
blob = repository.lookup(blob_entry[:oid])
|
18
|
+
|
19
|
+
if blob
|
14
20
|
Blob.new(
|
15
|
-
id:
|
16
|
-
name:
|
17
|
-
size:
|
18
|
-
data:
|
19
|
-
mode:
|
21
|
+
id: blob.oid,
|
22
|
+
name: blob_entry[:name],
|
23
|
+
size: blob.size,
|
24
|
+
data: blob.content,
|
25
|
+
mode: blob_entry[:mode],
|
20
26
|
path: path,
|
21
27
|
commit_id: sha,
|
22
28
|
)
|
@@ -24,13 +30,49 @@ module Gitlab
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def raw(repository, sha)
|
27
|
-
|
33
|
+
blob = repository.lookup(sha)
|
34
|
+
|
28
35
|
Blob.new(
|
29
|
-
id:
|
30
|
-
size:
|
31
|
-
data:
|
36
|
+
id: blob.oid,
|
37
|
+
size: blob.size,
|
38
|
+
data: blob.content,
|
32
39
|
)
|
33
40
|
end
|
41
|
+
|
42
|
+
# Recursive search of blob id by path
|
43
|
+
#
|
44
|
+
# Ex.
|
45
|
+
# blog/ # oid: 1a
|
46
|
+
# app/ # oid: 2a
|
47
|
+
# models/ # oid: 3a
|
48
|
+
# file.rb # oid: 4a
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# Blob.find_entry_by_path(repo, '1a', 'app/file.rb') # => '4a'
|
52
|
+
#
|
53
|
+
def find_entry_by_path(repository, root_id, path)
|
54
|
+
root_tree = repository.lookup(root_id)
|
55
|
+
path_arr = path.split('/')
|
56
|
+
|
57
|
+
entry = root_tree.find do |entry|
|
58
|
+
entry[:name] == path_arr[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
return nil unless entry
|
62
|
+
|
63
|
+
if path_arr.size > 1
|
64
|
+
return nil unless entry[:type] == :tree
|
65
|
+
else
|
66
|
+
return nil unless entry[:type] == :blob
|
67
|
+
end
|
68
|
+
|
69
|
+
if path_arr.size > 1
|
70
|
+
path_arr.shift
|
71
|
+
find_entry_by_path(repository, entry[:oid], path_arr.join('/'))
|
72
|
+
else
|
73
|
+
entry
|
74
|
+
end
|
75
|
+
end
|
34
76
|
end
|
35
77
|
|
36
78
|
def initialize(options)
|
data/lib/gitlab_git/commit.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Gitlab
|
2
|
+
module Git
|
3
|
+
class Ref
|
4
|
+
# Branch or tag name
|
5
|
+
# without "refs/tags|heads" prefix
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
# Target sha.
|
9
|
+
# Usually it is commit sha but in case
|
10
|
+
# when tag reference on other tag it can be tag sha
|
11
|
+
attr_reader :target
|
12
|
+
|
13
|
+
# Extract branch name from full ref path
|
14
|
+
#
|
15
|
+
# Ex.
|
16
|
+
# Ref.extract_branch_name('refs/heads/master') #=> 'master'
|
17
|
+
def self.extract_branch_name(str)
|
18
|
+
str.gsub(/\Arefs\/heads\//, '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(name, target)
|
22
|
+
@name, @target = name.gsub(/\Arefs\/(tags|heads)\//, ''), target
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -20,8 +20,8 @@ module Gitlab
|
|
20
20
|
# Grit repo object
|
21
21
|
attr_reader :grit
|
22
22
|
|
23
|
-
#
|
24
|
-
|
23
|
+
# Rugged repo object
|
24
|
+
attr_reader :rugged
|
25
25
|
|
26
26
|
def initialize(path)
|
27
27
|
@path = path
|
@@ -35,6 +35,17 @@ module Gitlab
|
|
35
35
|
raise NoRepository.new('no repository for such path')
|
36
36
|
end
|
37
37
|
|
38
|
+
# Alias to old method for compatibility
|
39
|
+
def raw
|
40
|
+
grit
|
41
|
+
end
|
42
|
+
|
43
|
+
def rugged
|
44
|
+
@rugged ||= Rugged::Repository.new(path)
|
45
|
+
rescue Rugged::RepositoryError, Rugged::OSError
|
46
|
+
raise NoRepository.new('no repository for such path')
|
47
|
+
end
|
48
|
+
|
38
49
|
# Returns an Array of branch names
|
39
50
|
# sorted by name ASC
|
40
51
|
def branch_names
|
@@ -43,7 +54,11 @@ module Gitlab
|
|
43
54
|
|
44
55
|
# Returns an Array of Branches
|
45
56
|
def branches
|
46
|
-
|
57
|
+
rugged.refs.select do |ref|
|
58
|
+
ref.name =~ /\Arefs\/heads/
|
59
|
+
end.map do |rugged_ref|
|
60
|
+
Branch.new(rugged_ref.name, rugged_ref.target)
|
61
|
+
end.sort_by(&:name)
|
47
62
|
end
|
48
63
|
|
49
64
|
# Returns an Array of tag names
|
@@ -53,7 +68,11 @@ module Gitlab
|
|
53
68
|
|
54
69
|
# Returns an Array of Tags
|
55
70
|
def tags
|
56
|
-
|
71
|
+
rugged.refs.select do |ref|
|
72
|
+
ref.name =~ /\Arefs\/tags/
|
73
|
+
end.map do |rugged_ref|
|
74
|
+
Tag.new(rugged_ref.name, rugged_ref.target)
|
75
|
+
end.sort_by(&:name)
|
57
76
|
end
|
58
77
|
|
59
78
|
# Returns an Array of branch and tag names
|
@@ -61,18 +80,21 @@ module Gitlab
|
|
61
80
|
branch_names + tag_names
|
62
81
|
end
|
63
82
|
|
83
|
+
# Deprecated. Will be removed in 5.2
|
64
84
|
def heads
|
65
85
|
@heads ||= grit.heads.sort_by(&:name)
|
66
86
|
end
|
67
87
|
|
68
88
|
def has_commits?
|
69
|
-
|
70
|
-
rescue Grit::NoSuchPathError
|
71
|
-
false
|
89
|
+
!empty?
|
72
90
|
end
|
73
91
|
|
74
92
|
def empty?
|
75
|
-
|
93
|
+
rugged.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
def repo_exists?
|
97
|
+
!!rugged
|
76
98
|
end
|
77
99
|
|
78
100
|
# Discovers the default branch based on the repository's available branches
|
@@ -85,8 +107,8 @@ module Gitlab
|
|
85
107
|
nil
|
86
108
|
elsif branch_names.length == 1
|
87
109
|
branch_names.first
|
88
|
-
elsif
|
89
|
-
|
110
|
+
elsif rugged.head
|
111
|
+
Ref.extract_branch_name(rugged.head.name)
|
90
112
|
elsif branch_names.include?("master")
|
91
113
|
"master"
|
92
114
|
elsif
|
@@ -103,11 +125,11 @@ module Gitlab
|
|
103
125
|
ref = ref || self.root_ref
|
104
126
|
commit = Gitlab::Git::Commit.find(self, ref)
|
105
127
|
return nil unless commit
|
106
|
-
|
128
|
+
|
107
129
|
extension = nil
|
108
130
|
git_archive_format = nil
|
109
131
|
pipe_cmd = nil
|
110
|
-
|
132
|
+
|
111
133
|
case format
|
112
134
|
when "tar.bz2", "tbz", "tbz2", "tb2", "bz2"
|
113
135
|
extension = ".tar.bz2"
|
@@ -293,6 +315,11 @@ module Gitlab
|
|
293
315
|
end
|
294
316
|
@refs_hash
|
295
317
|
end
|
318
|
+
|
319
|
+
# Lookup for rugged object by oid
|
320
|
+
def lookup(oid)
|
321
|
+
rugged.lookup(oid)
|
322
|
+
end
|
296
323
|
end
|
297
324
|
end
|
298
325
|
end
|
data/lib/gitlab_git/tree.rb
CHANGED
@@ -1,35 +1,75 @@
|
|
1
1
|
module Gitlab
|
2
2
|
module Git
|
3
3
|
class Tree
|
4
|
-
attr_accessor :id, :name, :path, :type,
|
4
|
+
attr_accessor :id, :root_id, :name, :path, :type,
|
5
|
+
:mode, :commit_id, :submodule_url
|
5
6
|
|
6
7
|
class << self
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
# Get list of tree objects
|
9
|
+
# for repository based on commit sha and path
|
10
|
+
# Uses rugged for raw objects
|
11
|
+
def where(repository, sha, path = nil)
|
12
|
+
path = nil if path == '' || path == '/'
|
13
|
+
|
14
|
+
commit = repository.lookup(sha)
|
15
|
+
root_tree = commit.tree
|
16
|
+
|
17
|
+
tree = if path
|
18
|
+
id = Tree.find_id_by_path(repository, root_tree.oid, path)
|
19
|
+
if id
|
20
|
+
repository.lookup(id)
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
else
|
25
|
+
root_tree
|
26
|
+
end
|
27
|
+
|
28
|
+
tree.map do |entry|
|
29
|
+
Tree.new(
|
30
|
+
id: entry[:oid],
|
31
|
+
root_id: root_tree.oid,
|
32
|
+
name: entry[:name],
|
33
|
+
type: entry[:type] || :submodule,
|
34
|
+
mode: entry[:filemode],
|
35
|
+
path: path ? File.join(path, entry[:name]) : entry[:name],
|
36
|
+
commit_id: sha,
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Recursive search of tree id for path
|
42
|
+
#
|
43
|
+
# Ex.
|
44
|
+
# blog/ # oid: 1a
|
45
|
+
# app/ # oid: 2a
|
46
|
+
# models/ # oid: 3a
|
47
|
+
# views/ # oid: 4a
|
48
|
+
#
|
49
|
+
#
|
50
|
+
# Tree.find_id_by_path(repo, '1a', 'app/models') # => '3a'
|
51
|
+
#
|
52
|
+
def find_id_by_path(repository, root_id, path)
|
53
|
+
root_tree = repository.lookup(root_id)
|
54
|
+
path_arr = path.split('/')
|
55
|
+
|
56
|
+
entry = root_tree.find do |entry|
|
57
|
+
entry[:name] == path_arr[0] && entry[:type] == :tree
|
58
|
+
end
|
59
|
+
|
60
|
+
return nil unless entry
|
61
|
+
|
62
|
+
if path_arr.size > 1
|
63
|
+
path_arr.shift
|
64
|
+
find_id_by_path(repository, entry[:oid], path_arr.join('/'))
|
25
65
|
else
|
26
|
-
[]
|
66
|
+
entry[:oid]
|
27
67
|
end
|
28
68
|
end
|
29
69
|
end
|
30
70
|
|
31
71
|
def initialize(options)
|
32
|
-
%w(id name path type mode commit_id
|
72
|
+
%w(id root_id name path type mode commit_id).each do |key|
|
33
73
|
self.send("#{key}=", options[key.to_sym])
|
34
74
|
end
|
35
75
|
end
|
@@ -52,4 +92,3 @@ module Gitlab
|
|
52
92
|
end
|
53
93
|
end
|
54
94
|
end
|
55
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Zaporozhets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab-linguist
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 4.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rugged
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.19.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.19.0
|
55
69
|
description: GitLab wrapper around git objects
|
56
70
|
email: dmitriy.zaporozhets@gmail.com
|
57
71
|
executables: []
|
@@ -62,15 +76,19 @@ files:
|
|
62
76
|
- lib/gitlab_git/blame.rb
|
63
77
|
- lib/gitlab_git/blob.rb
|
64
78
|
- lib/gitlab_git/blob_snippet.rb
|
79
|
+
- lib/gitlab_git/branch.rb
|
65
80
|
- lib/gitlab_git/commit.rb
|
66
81
|
- lib/gitlab_git/compare.rb
|
67
82
|
- lib/gitlab_git/diff.rb
|
68
83
|
- lib/gitlab_git/git_stats.rb
|
69
84
|
- lib/gitlab_git/log_parser.rb
|
70
85
|
- lib/gitlab_git/popen.rb
|
86
|
+
- lib/gitlab_git/ref.rb
|
71
87
|
- lib/gitlab_git/repository.rb
|
72
88
|
- lib/gitlab_git/stats.rb
|
89
|
+
- lib/gitlab_git/tag.rb
|
73
90
|
- lib/gitlab_git/tree.rb
|
91
|
+
- VERSION
|
74
92
|
homepage: http://rubygems.org/gems/gitlab_git
|
75
93
|
licenses:
|
76
94
|
- MIT
|