gitlab_git 2.3.1 → 3.0.0.beta1

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
2
  SHA1:
3
- metadata.gz: 1b908eba48287d7309ed2ac395c3210d57708a86
4
- data.tar.gz: 7106a23af68133322ee9a965188c43196bcecad4
3
+ metadata.gz: c207576fe702ed6a64b24f956856968287325866
4
+ data.tar.gz: 0fc3ac8c449422b760cdac189d84b56691fda26c
5
5
  SHA512:
6
- metadata.gz: 4e31474d89d6bcac44800cea27d1ce363b035a65aaa6076ce6804fd41b5d7c0fe076c169ee5838318fff68673690e649f40009220120b9ab9733d59f6feb762c
7
- data.tar.gz: 794d8dc3f1223e4950748c15e1b18a03f1ef3b21eb7fdcf3abe6420717a066aa81795bcd89cc920dba90f48ae3bd6792d01700dbc07117044d1c680e2493fa3a
6
+ metadata.gz: 8f37199e9248a6681bb127f65dff32026bc2a39bfee7c50eda5a566ec8a94620803a4f184f2e5df882bfa28ff97231b2a8f8837c02ae6afc4821765e0b8e9094
7
+ data.tar.gz: 01909f36d53f1986d1972009d1f7a45ff3907c4eb3d2184e9ffc705d8ca141db444e699099530e4e081ffc246ca79cf2eb66762843005274653c833dce9772ff
@@ -3,42 +3,36 @@ module Gitlab
3
3
  class Blob
4
4
  include Linguist::BlobHelper
5
5
 
6
- attr_accessor :raw_blob
7
-
8
- def initialize(repository, sha, ref, path)
9
- @repository, @sha, @ref = repository, sha, ref
10
-
11
- @commit = @repository.commit(sha)
12
- @raw_blob = @repository.tree(@commit, path)
13
- end
14
-
15
- def data
16
- if raw_blob and raw_blob.respond_to?('data')
17
- raw_blob.data
18
- else
19
- nil
6
+ attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id
7
+
8
+ class << self
9
+ def find(repository, sha, path)
10
+ commit = Commit.find(repository, sha)
11
+ grit_blob = commit.tree / path
12
+
13
+ if grit_blob.kind_of?(Grit::Blob)
14
+ Blob.new(
15
+ id: grit_blob.id,
16
+ name: grit_blob.name,
17
+ size: grit_blob.size,
18
+ data: grit_blob.data,
19
+ mode: grit_blob.mode,
20
+ path: path,
21
+ commit_id: sha,
22
+ )
23
+ end
20
24
  end
21
25
  end
22
26
 
23
- def name
24
- raw_blob.name
25
- end
26
-
27
- def exists?
28
- raw_blob
27
+ def initialize(options)
28
+ %w(id name path size data mode commit_id).each do |key|
29
+ self.send("#{key}=", options[key.to_sym])
30
+ end
29
31
  end
30
32
 
31
33
  def empty?
32
34
  !data || data == ''
33
35
  end
34
-
35
- def mode
36
- raw_blob.mode
37
- end
38
-
39
- def size
40
- raw_blob.size
41
- end
42
36
  end
43
37
  end
44
38
  end
@@ -13,7 +13,7 @@ module Gitlab
13
13
  log = nil
14
14
  Grit::Git.with_timeout(30) do
15
15
  # Limit log to 6k commits to avoid timeout for huge projects
16
- args = [ref, '-6000', '--format=%aN%x0a%aE%x0a%cd', '--date=short', '--shortstat', '--no-merges', '--diff-filter=ACDM']
16
+ args = ['-6000', '--format=%aN%x0a%aE%x0a%cd', '--date=short', '--shortstat', '--no-merges', '--diff-filter=ACDM']
17
17
  log = repo.git.run(nil, 'log', nil, {}, args)
18
18
  end
19
19
 
@@ -8,44 +8,29 @@ module Gitlab
8
8
 
9
9
  class NoRepository < StandardError; end
10
10
 
11
- class << self
12
- attr_accessor :repos_path
13
- end
14
-
15
- # Repository directory name with namespace direcotry
16
- # Examples:
17
- # gitlab/gitolite
18
- # diaspora
19
- #
20
- attr_accessor :path_with_namespace
21
-
22
11
  # Default branch in the repository
23
12
  attr_accessor :root_ref
24
13
 
25
- # Grit repo object
26
- attr_reader :raw
27
-
28
- # compatibility
29
- alias_method :repo, :raw
14
+ # Full path to repo
15
+ attr_reader :path
30
16
 
31
- def initialize(path_with_namespace, root_ref)
32
- @path_with_namespace = path_with_namespace
33
- @root_ref = root_ref || raw.head.name
17
+ # Directory name of repo
18
+ attr_reader :name
34
19
 
35
- # Init grit repo object
36
- raw
37
- end
20
+ # Grit repo object
21
+ attr_reader :grit
38
22
 
39
- def path_to_repo
40
- @path_to_repo ||= File.join(repos_path, "#{path_with_namespace}.git")
41
- end
23
+ # Alias to old method for compatibility
24
+ alias_method :raw, :grit
42
25
 
43
- def repos_path
44
- self.class.repos_path
26
+ def initialize(path)
27
+ @path = path
28
+ @name = path.split("/").last
29
+ @root_ref = discover_default_branch
45
30
  end
46
31
 
47
- def raw
48
- @raw ||= Grit::Repo.new(path_to_repo)
32
+ def grit
33
+ @grit ||= Grit::Repo.new(path)
49
34
  rescue Grit::NoSuchPathError
50
35
  raise NoRepository.new('no repository for such path')
51
36
  end
@@ -58,7 +43,7 @@ module Gitlab
58
43
 
59
44
  # Returns an Array of Branches
60
45
  def branches
61
- raw.branches.sort_by(&:name)
46
+ grit.branches.sort_by(&:name)
62
47
  end
63
48
 
64
49
  # Returns an Array of tag names
@@ -68,7 +53,7 @@ module Gitlab
68
53
 
69
54
  # Returns an Array of Tags
70
55
  def tags
71
- raw.tags.sort_by(&:name).reverse
56
+ grit.tags.sort_by(&:name).reverse
72
57
  end
73
58
 
74
59
  # Returns an Array of branch and tag names
@@ -77,13 +62,7 @@ module Gitlab
77
62
  end
78
63
 
79
64
  def heads
80
- @heads ||= raw.heads.sort_by(&:name)
81
- end
82
-
83
- def tree(fcommit, path = nil)
84
- fcommit = commit if fcommit == :head
85
- tree = fcommit.tree
86
- path ? (tree / path) : tree
65
+ @heads ||= grit.heads.sort_by(&:name)
87
66
  end
88
67
 
89
68
  def has_commits?
@@ -100,15 +79,18 @@ module Gitlab
100
79
  #
101
80
  # - If no branches are present, returns nil
102
81
  # - If one branch is present, returns its name
103
- # - If two or more branches are present, returns the one that has a name
104
- # matching root_ref (default_branch or 'master' if default_branch is nil)
82
+ # - If two or more branches are present, returns current HEAD or master or first branch
105
83
  def discover_default_branch
106
84
  if branch_names.length == 0
107
85
  nil
108
86
  elsif branch_names.length == 1
109
87
  branch_names.first
110
- else
111
- branch_names.select { |v| v == root_ref }.first
88
+ elsif grit.head
89
+ grit.head.name
90
+ elsif branch_names.include?("master")
91
+ "master"
92
+ elsif
93
+ branch_names.first
112
94
  end
113
95
  end
114
96
 
@@ -123,16 +105,16 @@ module Gitlab
123
105
  return nil unless commit
124
106
 
125
107
  # Build file path
126
- file_name = self.path_with_namespace.gsub("/","_") + "-" + commit.id.to_s + ".tar.gz"
127
- file_path = File.join(storage_path, self.path_with_namespace, file_name)
108
+ file_name = self.name.gsub("\.git", "") + "-" + commit.id.to_s + ".tar.gz"
109
+ file_path = File.join(storage_path, self.name, file_name)
128
110
 
129
111
  # Put files into a directory before archiving
130
- prefix = File.basename(self.path_with_namespace) + "/"
112
+ prefix = File.basename(self.name) + "/"
131
113
 
132
114
  # Create file if not exists
133
115
  unless File.exists?(file_path)
134
116
  FileUtils.mkdir_p File.dirname(file_path)
135
- file = self.raw.archive_to_file(ref, prefix, file_path)
117
+ file = self.grit.archive_to_file(ref, prefix, file_path)
136
118
  end
137
119
 
138
120
  file_path
@@ -140,7 +122,7 @@ module Gitlab
140
122
 
141
123
  # Return repo size in megabytes
142
124
  def size
143
- size = popen('du -s', path_to_repo).first.strip.to_i
125
+ size = popen('du -s', path).first.strip.to_i
144
126
  (size.to_f / 1024).round(2)
145
127
  end
146
128
 
@@ -149,7 +131,7 @@ module Gitlab
149
131
  ref = root_ref
150
132
  end
151
133
 
152
- greps = raw.grep(query, 3, ref)
134
+ greps = grit.grep(query, 3, ref)
153
135
 
154
136
  greps.map do |grep|
155
137
  Gitlab::Git::BlobSnippet.new(ref, grep.content, grep.startline, grep.filename)
@@ -177,7 +159,7 @@ module Gitlab
177
159
 
178
160
  options = default_options.merge(options)
179
161
 
180
- raw.log(
162
+ grit.log(
181
163
  options[:ref] || root_ref,
182
164
  options[:path],
183
165
  max_count: options[:limit].to_i,
@@ -189,15 +171,15 @@ module Gitlab
189
171
  # Delegate commits_between to Grit method
190
172
  #
191
173
  def commits_between(from, to)
192
- raw.commits_between(from, to)
174
+ grit.commits_between(from, to)
193
175
  end
194
176
 
195
177
  def merge_base_commit(from, to)
196
- raw.git.native(:merge_base, {}, [to, from]).strip
178
+ grit.git.native(:merge_base, {}, [to, from]).strip
197
179
  end
198
180
 
199
181
  def diff(from, to)
200
- raw.diff(from, to)
182
+ grit.diff(from, to)
201
183
  end
202
184
 
203
185
  # Returns commits collection
@@ -253,9 +235,9 @@ module Gitlab
253
235
  actual_options[:all] = true
254
236
  end
255
237
 
256
- output = raw.git.native(:rev_list, actual_options, *args)
238
+ output = grit.git.native(:rev_list, actual_options, *args)
257
239
 
258
- Grit::Commit.list_from_string(raw, output).map do |commit|
240
+ Grit::Commit.list_from_string(grit, output).map do |commit|
259
241
  Gitlab::Git::Commit.decorate(commit)
260
242
  end
261
243
  rescue Grit::GitRuby::Repository::NoSuchShaFound
@@ -268,7 +250,7 @@ module Gitlab
268
250
  # repo.branch_names_contains('master')
269
251
  #
270
252
  def branch_names_contains(commit)
271
- output = raw.git.native(:branch, {contains: true}, commit)
253
+ output = grit.git.native(:branch, {contains: true}, commit)
272
254
  # The output is expected as follow
273
255
  # fix-aaa
274
256
  # fix-bbb
@@ -276,17 +258,17 @@ module Gitlab
276
258
  output.scan(/[^* \n]+/)
277
259
  end
278
260
 
279
- # Get refs hash which key is SHA1 and value is ref object(Grit::Head or Grit::Remote or Grit::Tag)
261
+ # Get refs hash which key is SHA1
262
+ # and value is ref object(Grit::Head or Grit::Remote or Grit::Tag)
280
263
  def refs_hash
281
264
  # Initialize only when first call
282
265
  if @refs_hash.nil?
283
266
  @refs_hash = Hash.new { |h, k| h[k] = [] }
284
267
 
285
- @raw.refs.each do |r|
268
+ grit.refs.each do |r|
286
269
  @refs_hash[r.commit.id] << r
287
270
  end
288
271
  end
289
-
290
272
  @refs_hash
291
273
  end
292
274
  end
@@ -1,54 +1,52 @@
1
1
  module Gitlab
2
2
  module Git
3
3
  class Tree
4
- attr_accessor :repository, :sha, :path, :ref, :raw_tree, :id
4
+ attr_accessor :id, :name, :path, :type, :mode, :commit_id
5
5
 
6
- def initialize(repository, sha, ref = nil, path = nil)
7
- @repository, @sha, @ref, @path = repository, sha, ref, path
6
+ class << self
7
+ def where(repository, sha, path = '/')
8
+ commit = Commit.find(repository, sha)
9
+ grit_tree = commit.tree / path
8
10
 
9
- @path = nil if !@path || @path == ''
11
+ if grit_tree && grit_tree.respond_to?(:contents)
12
+ grit_tree.contents.map do |entry|
13
+ type = entry.class.to_s.split("::").last.downcase.to_sym
10
14
 
11
- # Load tree from repository
12
- @commit = Gitlab::Git::Commit.find(@repository, @sha)
13
- @raw_tree = @repository.tree(@commit, @path)
15
+ Tree.new(
16
+ id: entry.id,
17
+ name: entry.name,
18
+ type: type,
19
+ mode: entry.mode,
20
+ path: path == '/' ? entry.name : File.join(path, entry.name),
21
+ commit_id: sha,
22
+ )
23
+ end
24
+ else
25
+ []
26
+ end
27
+ end
14
28
  end
15
29
 
16
- def exists?
17
- raw_tree
30
+ def initialize(options)
31
+ %w(id name path type mode commit_id).each do |key|
32
+ self.send("#{key}=", options[key.to_sym])
33
+ end
18
34
  end
19
35
 
20
- def empty?
21
- trees.empty? && blobs.empty?
36
+ def dir?
37
+ type == :tree
22
38
  end
23
39
 
24
- def trees
25
- entries.select { |t| t.is_a?(Grit::Tree) }
40
+ def file?
41
+ type == :blob
26
42
  end
27
43
 
28
- def blobs
29
- entries.select { |t| t.is_a?(Grit::Blob) }
44
+ def submodule?
45
+ type == :submodule
30
46
  end
31
47
 
32
- def submodules
33
- entries.select { |t| t.is_a?(Grit::Submodule) }
34
- end
35
-
36
- def is_blob?
37
- raw_tree.is_a?(Grit::Blob)
38
- end
39
-
40
- def up_dir?
41
- path && path != ''
42
- end
43
-
44
- def readme
45
- @readme ||= blobs.find { |c| c.name =~ /^readme/i }
46
- end
47
-
48
- protected
49
-
50
- def entries
51
- raw_tree.contents
48
+ def readme?
49
+ name =~ /^readme/i
52
50
  end
53
51
  end
54
52
  end
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: 2.3.1
4
+ version: 3.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-21 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-linguist
@@ -86,9 +86,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - '>'
90
90
  - !ruby/object:Gem::Version
91
- version: '0'
91
+ version: 1.3.1
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 2.0.3