82 |
82 |
return @branches if @branches
|
83 |
83 |
@branches = []
|
84 |
84 |
cmd_args = %w|branch --no-color --verbose --no-abbrev|
|
85 |
|
scm_cmd(*cmd_args) do |io|
|
|
85 |
scm_cmd(cmd_args) do |io|
|
86 |
86 |
io.each_line do |line|
|
87 |
87 |
branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
|
88 |
88 |
bran = GitBranch.new(branch_rev[2])
|
... | ... | |
100 |
100 |
def tags
|
101 |
101 |
return @tags if @tags
|
102 |
102 |
cmd_args = %w|tag|
|
103 |
|
scm_cmd(*cmd_args) do |io|
|
|
103 |
scm_cmd(cmd_args) do |io|
|
104 |
104 |
@tags = io.readlines.sort!.map{|t| t.strip}
|
105 |
105 |
end
|
106 |
106 |
rescue ScmCommandAborted
|
... | ... | |
138 |
138 |
cmd_args = %w|ls-tree -l|
|
139 |
139 |
cmd_args << "HEAD:#{p}" if identifier.nil?
|
140 |
140 |
cmd_args << "#{identifier}:#{p}" if identifier
|
141 |
|
scm_cmd(*cmd_args) do |io|
|
|
141 |
scm_cmd(cmd_args) do |io|
|
142 |
142 |
io.each_line do |line|
|
143 |
143 |
e = line.chomp.to_s
|
144 |
144 |
if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\t(.+)$/
|
... | ... | |
173 |
173 |
cmd_args << rev if rev
|
174 |
174 |
cmd_args << "--" << path unless path.empty?
|
175 |
175 |
lines = []
|
176 |
|
scm_cmd(*cmd_args) { |io| lines = io.readlines }
|
|
176 |
scm_cmd(cmd_args) { |io| lines = io.readlines }
|
177 |
177 |
begin
|
178 |
178 |
id = lines[0].split[1]
|
179 |
179 |
author = lines[1].match('Author:\s+(.*)$')[1]
|
... | ... | |
197 |
197 |
|
198 |
198 |
def revisions(path, identifier_from, identifier_to, options={})
|
199 |
199 |
revs = Revisions.new
|
200 |
|
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents|
|
|
200 |
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin|
|
201 |
201 |
cmd_args << "--reverse" if options[:reverse]
|
202 |
202 |
cmd_args << "-n" << "#{options[:limit].to_i}" if options[:limit]
|
203 |
|
from_to = ""
|
|
203 |
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
|
|
204 |
revisions = []
|
204 |
205 |
if identifier_from || identifier_to
|
205 |
|
from_to << "#{identifier_from}.." if identifier_from
|
206 |
|
from_to << "#{identifier_to}" if identifier_to
|
207 |
|
cmd_args << from_to if !from_to.empty?
|
|
206 |
revisions << ""
|
|
207 |
revisions[0] << "#{identifier_from}.." if identifier_from
|
|
208 |
revisions[0] << "#{identifier_to}" if identifier_to
|
208 |
209 |
else
|
209 |
|
cmd_args += options[:includes] unless options[:includes].blank?
|
|
210 |
unless options[:includes].blank?
|
|
211 |
revisions += ignore_missing_revisions(options[:includes])
|
|
212 |
end
|
210 |
213 |
unless options[:excludes].blank?
|
211 |
|
cmd_args << "--not"
|
212 |
|
cmd_args += options[:excludes]
|
|
214 |
revisions +=
|
|
215 |
ignore_missing_revisions(options[:excludes]).map{|r| "^#{r}"}
|
213 |
216 |
end
|
214 |
217 |
end
|
215 |
|
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
|
216 |
218 |
|
217 |
|
scm_cmd *cmd_args do |io|
|
|
219 |
scm_cmd(cmd_args, :mode => "r+b") do |io|
|
|
220 |
io.puts(revisions.join("\n"))
|
|
221 |
io.close_write
|
|
222 |
|
218 |
223 |
files=[]
|
219 |
224 |
changeset = {}
|
220 |
225 |
parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
|
... | ... | |
317 |
322 |
end
|
318 |
323 |
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) unless path.empty?
|
319 |
324 |
diff = []
|
320 |
|
scm_cmd *cmd_args do |io|
|
|
325 |
scm_cmd cmd_args do |io|
|
321 |
326 |
io.each_line do |line|
|
322 |
327 |
diff << line
|
323 |
328 |
end
|
... | ... | |
333 |
338 |
cmd_args << "-p" << identifier << "--" << scm_iconv(@path_encoding, 'UTF-8', path)
|
334 |
339 |
blame = Annotate.new
|
335 |
340 |
content = nil
|
336 |
|
scm_cmd(*cmd_args) { |io| io.binmode; content = io.read }
|
|
341 |
scm_cmd(cmd_args) { |io| io.binmode; content = io.read }
|
337 |
342 |
# git annotates binary files
|
338 |
343 |
return nil if content.is_binary_data?
|
339 |
344 |
identifier = ''
|
... | ... | |
367 |
372 |
cmd_args = %w|show --no-color|
|
368 |
373 |
cmd_args << "#{identifier}:#{scm_iconv(@path_encoding, 'UTF-8', path)}"
|
369 |
374 |
cat = nil
|
370 |
|
scm_cmd(*cmd_args) do |io|
|
|
375 |
scm_cmd(cmd_args) do |io|
|
371 |
376 |
io.binmode
|
372 |
377 |
cat = io.read
|
373 |
378 |
end
|
... | ... | |
383 |
388 |
end
|
384 |
389 |
end
|
385 |
390 |
|
386 |
|
def scm_cmd(*args, &block)
|
|
391 |
def scm_cmd(args, options = {}, &block)
|
387 |
392 |
repo_path = root_url || url
|
388 |
393 |
full_args = ['--git-dir', repo_path]
|
389 |
394 |
if self.class.client_version_above?([1, 7, 2])
|
... | ... | |
393 |
398 |
full_args += args
|
394 |
399 |
ret = shellout(
|
395 |
400 |
self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '),
|
|
401 |
options,
|
396 |
402 |
&block
|
397 |
403 |
)
|
398 |
404 |
if $? && $?.exitstatus != 0
|
... | ... | |
401 |
407 |
ret
|
402 |
408 |
end
|
403 |
409 |
private :scm_cmd
|
|
410 |
|
|
411 |
# Return an array containing only the given revisions that exist in the
|
|
412 |
# repository.
|
|
413 |
#
|
|
414 |
# NOTE:
|
|
415 |
# This can be removed once the minimum supported Git version supports
|
|
416 |
# the --ignore-missing option for git-log and #revisions is modified to
|
|
417 |
# use that option.
|
|
418 |
def ignore_missing_revisions(revisions)
|
|
419 |
revisions.select do |revision|
|
|
420 |
begin
|
|
421 |
cmd_args = %w|rev-parse --verify --quiet|
|
|
422 |
cmd_args << revision
|
|
423 |
scm_cmd(cmd_args) do |io|
|
|
424 |
# Read and discard the output in order to make the command
|
|
425 |
# happy.
|
|
426 |
io.read
|
|
427 |
end
|
|
428 |
true
|
|
429 |
rescue ScmCommandAborted
|
|
430 |
false
|
|
431 |
end
|
|
432 |
end
|
|
433 |
end
|
|
434 |
private :ignore_missing_revisions
|
404 |
435 |
end
|
405 |
436 |
end
|
406 |
437 |
end
|