Patch #1199 » patch-redmine-mercurial.patch
| extra/mercurial/hg-template-0.9.5.tmpl (revision 0) | ||
|---|---|---|
|
changeset = 'This template must be used with --debug option\n'
|
||
|
changeset_quiet = 'This template must be used with --debug option\n'
|
||
|
changeset_verbose = 'This template must be used with --debug option\n'
|
||
|
changeset_debug = '<logentry revision="{rev}" node="{node|short}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{files}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
|
||
|
file = '<path action="M">{file|escape}</path>\n'
|
||
|
file_add = '<path action="A">{file_add|escape}</path>\n'
|
||
|
file_del = '<path action="D">{file_del|escape}</path>\n'
|
||
|
file_copy = '<path-copied copyfrom-path="{source|escape}">{name|urlescape}</path-copied>\n'
|
||
|
tag = '<tag>{tag|escape}</tag>\n'
|
||
|
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
|
||
|
# footer="</log>"
|
||
| extra/mercurial/hg-template-1.0.tmpl (revision 0) | ||
|---|---|---|
|
changeset = 'This template must be used with --debug option\n'
|
||
|
changeset_quiet = 'This template must be used with --debug option\n'
|
||
|
changeset_verbose = 'This template must be used with --debug option\n'
|
||
|
changeset_debug = '<logentry revision="{rev}" node="{node|short}">\n<author>{author|escape}</author>\n<date>{date|isodate}</date>\n<paths>\n{file_mods}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n{tags}</logentry>\n\n'
|
||
|
file_mod = '<path action="M">{file_mod|escape}</path>\n'
|
||
|
file_add = '<path action="A">{file_add|escape}</path>\n'
|
||
|
file_del = '<path action="D">{file_del|escape}</path>\n'
|
||
|
file_copy = '<path-copied copyfrom-path="{source|escape}">{name|urlescape}</path-copied>\n'
|
||
|
tag = '<tag>{tag|escape}</tag>\n'
|
||
|
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
|
||
|
# footer="</log>"
|
||
| lib/redmine/scm/adapters/abstract_adapter.rb (working copy) | ||
|---|---|---|
|
path ||= ''
|
||
|
(path[0,1]!="/") ? "/#{path}" : path
|
||
|
end
|
||
|
def with_trailling_slash(path)
|
||
|
path ||= ''
|
||
|
(path[-1,1] == "/") ? path : "#{path}/"
|
||
|
end
|
||
|
|
||
|
def shell_quote(str)
|
||
|
if RUBY_PLATFORM =~ /mswin/
|
||
| ... | ... | |
|
"'" + str.gsub(/'/, "'\"'\"'") + "'"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def retrieve_root_url
|
||
|
info = self.info
|
||
| lib/redmine/scm/adapters/mercurial_adapter.rb (working copy) | ||
|---|---|---|
|
module Scm
|
||
|
module Adapters
|
||
|
class MercurialAdapter < AbstractAdapter
|
||
|
|
||
|
|
||
|
# Mercurial executable name
|
||
|
HG_BIN = "hg"
|
||
|
TEMPLATES_DIR = "#{RAILS_ROOT}/extra/mercurial"
|
||
|
TEMPLATE_NAME = "hg-template"
|
||
|
TEMPLATE_EXTENSION = "tmpl"
|
||
|
|
||
|
def info
|
||
|
cmd = "#{HG_BIN} -R #{target('')} root"
|
||
| ... | ... | |
|
end
|
||
|
return nil if $? && $?.exitstatus != 0
|
||
|
info = Info.new({:root_url => root_url.chomp,
|
||
|
:lastrev => revisions(nil,nil,nil,{:limit => 1}).last
|
||
|
})
|
||
|
:lastrev => revisions(nil,nil,nil,{:limit => 1}).last
|
||
|
})
|
||
|
info
|
||
|
rescue CommandFailed
|
||
|
return nil
|
||
| ... | ... | |
|
def entries(path=nil, identifier=nil)
|
||
|
path ||= ''
|
||
|
entries = Entries.new
|
||
|
cmd = "#{HG_BIN} -R #{target('')} --cwd #{target(path)} locate"
|
||
|
cmd << " -r #{identifier.to_i}" if identifier
|
||
|
cmd << " " + shell_quote('glob:**')
|
||
|
cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} locate"
|
||
|
cmd << " -r " + (identifier ? identifier.to_s : "tip")
|
||
|
cmd << " " + shell_quote("path:#{path}") unless path.empty?
|
||
|
shellout(cmd) do |io|
|
||
|
io.each_line do |line|
|
||
|
e = line.chomp.split(%r{[\/\\]})
|
||
|
entries << Entry.new({:name => e.first,
|
||
|
:path => (path.empty? ? e.first : "#{path}/#{e.first}"),
|
||
|
:kind => (e.size > 1 ? 'dir' : 'file'),
|
||
|
:lastrev => Revision.new
|
||
|
}) unless entries.detect{|entry| entry.name == e.first}
|
||
|
# HG uses antislashs as separator on Windows
|
||
|
line = line.gsub(/\\/, "/")
|
||
|
if path.empty? or e = line.gsub!(%r{^#{with_trailling_slash(path)}},'')
|
||
|
e ||= line
|
||
|
e = e.chomp.split(%r{[\/\\]})
|
||
|
entries << Entry.new({:name => e.first,
|
||
|
:path => (path.nil? or path.empty? ? e.first : "#{with_trailling_slash(path)}#{e.first}"),
|
||
|
:kind => (e.size > 1 ? 'dir' : 'file'),
|
||
|
:lastrev => Revision.new
|
||
|
}) unless entries.detect{|entry| entry.name == e.first}
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
return nil if $? && $?.exitstatus != 0
|
||
|
entries.sort_by_name
|
||
|
end
|
||
|
|
||
|
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
|
||
|
|
||
|
# Fetch the revisions by using a template file that
|
||
|
# makes Mercurial produce a xml output.
|
||
|
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
|
||
|
revisions = Revisions.new
|
||
|
cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{self.class.template_path}"
|
||
|
if identifier_from && identifier_to
|
||
|
cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
|
||
|
elsif identifier_from
|
||
|
cmd << " -r #{identifier_from.to_i}:"
|
||
|
end
|
||
|
cmd << " --limit #{options[:limit].to_i}" if options[:limit]
|
||
|
cmd << " #{path}" if path
|
||
|
shellout(cmd) do |io|
|
||
|
begin
|
||
|
# HG doesn't close the XML Document...
|
||
|
doc = REXML::Document.new(io.read << "</log>")
|
||
|
doc.elements.each("log/logentry") do |logentry|
|
||
|
paths = []
|
||
|
copies = logentry.get_elements('paths/path-copied')
|
||
|
logentry.elements.each("paths/path") do |path|
|
||
|
# Detect if the added file is a copy
|
||
|
if path.attributes['action'] == 'A' and c = copies.find{ |e| e.text == path.text }
|
||
|
from_path = c.attributes['copyfrom-path']
|
||
|
from_rev = logentry.attributes['revision']
|
||
|
end
|
||
|
paths << {:action => path.attributes['action'],
|
||
|
:path => "/#{path.text}",
|
||
|
:from_path => from_path ? "/#{from_path}" : nil,
|
||
|
:from_revision => from_rev ? from_rev : nil
|
||
|
}
|
||
|
end
|
||
|
paths.sort! { |x,y| x[:path] <=> y[:path] }
|
||
|
|
||
|
revisions << Revision.new({:identifier => logentry.attributes['revision'],
|
||
|
:scmid => logentry.attributes['node'],
|
||
|
:author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
|
||
|
:time => Time.parse(logentry.elements['date'].text).localtime,
|
||
|
:message => logentry.elements['msg'].text,
|
||
|
:paths => paths
|
||
|
})
|
||
|
end
|
||
|
rescue
|
||
|
logger.debug($!)
|
||
|
end
|
||
|
end
|
||
|
return nil if $? && $?.exitstatus != 0
|
||
|
revisions
|
||
|
end
|
||
|
|
||
|
|
||
|
def revisions_old(path=nil, identifier_from=nil, identifier_to=nil, options={})
|
||
|
revisions = Revisions.new
|
||
|
cmd = "#{HG_BIN} -v --encoding utf8 -R #{target('')} log"
|
||
|
if identifier_from && identifier_to
|
||
|
cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
|
||
| ... | ... | |
|
|
||
|
def cat(path, identifier=nil)
|
||
|
cmd = "#{HG_BIN} -R #{target('')} cat"
|
||
|
cmd << " -r #{identifier.to_i}" if identifier
|
||
|
cmd << " -r " + (identifier ? identifier.to_s : "tip")
|
||
|
cmd << " #{target(path)}"
|
||
|
cat = nil
|
||
|
shellout(cmd) do |io|
|
||
| ... | ... | |
|
path ||= ''
|
||
|
cmd = "#{HG_BIN} -R #{target('')}"
|
||
|
cmd << " annotate -n -u"
|
||
|
cmd << " -r " + (identifier ? identifier.to_s : "tip")
|
||
|
cmd << " -r #{identifier.to_i}" if identifier
|
||
|
cmd << " #{target(path)}"
|
||
|
blame = Annotate.new
|
||
| ... | ... | |
|
blame
|
||
|
end
|
||
|
|
||
|
# The hg version version is exprimed either as a
|
||
|
# release number (eg 0.9.5 or 1.0) or as a revision
|
||
|
# id composed of 12 hexa characters.
|
||
|
def self.hgversion
|
||
|
@@hgversion ||= begin
|
||
|
theversion = self.hgversion_from_command_line
|
||
|
if theversion.match(/^\d+(\.\d+)+$/)
|
||
|
theversion.split(".").collect(&:to_i)
|
||
|
# elsif match = theversion.match(/[[:xdigit:]]{12}/)
|
||
|
# match[0]
|
||
|
else
|
||
|
"Unknown version"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def self.template_path
|
||
|
if self.hgversion.is_a?(String) or (self.hgversion <=> [0,9,5]) > 0
|
||
|
ver = "1.0"
|
||
|
else
|
||
|
ver = "0.9.5"
|
||
|
end
|
||
|
@@template ||= "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
|
||
|
end
|
||
|
|
||
|
|
||
|
private
|
||
|
|
||
|
# Builds a revision objet from the changeset returned by hg command
|
||
| ... | ... | |
|
|
||
|
# Changes
|
||
|
paths = (rev_id == 0) ?
|
||
|
# Can't get changes for revision 0 with hg status
|
||
|
changeset[:files].to_s.split.collect{|path| {:action => 'A', :path => "/#{path}"}} :
|
||
|
# Can't get changes for revision 0 with hg status
|
||
|
changeset[:files].to_s.split.collect{|path| {:action => 'A', :path => "/#{path}"}} :
|
||
|
status(rev_id)
|
||
|
|
||
|
Revision.new({:identifier => rev_id,
|
||
|
:scmid => changeset[:changeset].to_s.split(':').last,
|
||
|
:author => changeset[:user],
|
||
|
:time => Time.parse(changeset[:date]),
|
||
|
:message => changeset[:description],
|
||
|
:paths => paths
|
||
|
:scmid => changeset[:changeset].to_s.split(':').last,
|
||
|
:author => changeset[:user],
|
||
|
:time => Time.parse(changeset[:date]),
|
||
|
:message => changeset[:description],
|
||
|
:paths => paths
|
||
|
})
|
||
|
end
|
||
|
|
||
| ... | ... | |
|
end
|
||
|
result
|
||
|
end
|
||
|
|
||
|
def self.hgversion_from_command_line
|
||
|
%x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||