scm: mercurial: annotate accepts both of revision number and changeset id (#3724).

Change annotate revision label to Mercurial style '4:def6d2f1254a'
and use identifier.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4663 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA
2011-01-09 01:30:18 +00:00
parent 5207211b6d
commit ef28bf6d88
3 changed files with 29 additions and 9 deletions
+14 -6
View File
@@ -183,25 +183,33 @@ module Redmine
return nil if $? && $?.exitstatus != 0
cat
end
def annotate(path, identifier=nil)
path ||= ''
cmd = "#{HG_BIN} -R #{target('')}"
cmd << " annotate -n -u"
cmd << " -r " + shell_quote(identifier ? identifier.to_s : "tip")
cmd << " -r #{identifier.to_i}" if identifier
cmd << " annotate -ncu"
cmd << " -r #{hgrev(identifier)}"
cmd << " #{target(path)}"
blame = Annotate.new
shellout(cmd) do |io|
io.each_line do |line|
next unless line =~ %r{^([^:]+)\s(\d+):(.*)$}
blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_i, :author => $1.strip))
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
:identifier => $3)
blame.add_line($4.rstrip, r)
end
end
return nil if $? && $?.exitstatus != 0
blame
end
class Revision < Redmine::Scm::Adapters::Revision
# Returns the readable identifier
def format_identifier
"#{revision}:#{scmid}"
end
end
# Returns correct revision identifier
def hgrev(identifier)
identifier.blank? ? 'tip' : identifier.to_s