##// END OF EJS Templates
scm: mercurial: replace identifier to hgrev(identifier)....
Toshi MARUYAMA -
r4547:08c093bc8507
parent child
Show More
@@ -22,18 +22,18 module Redmine
22 module Scm
22 module Scm
23 module Adapters
23 module Adapters
24 class MercurialAdapter < AbstractAdapter
24 class MercurialAdapter < AbstractAdapter
25
25
26 # Mercurial executable name
26 # Mercurial executable name
27 HG_BIN = "hg"
27 HG_BIN = "hg"
28 TEMPLATES_DIR = File.dirname(__FILE__) + "/mercurial"
28 TEMPLATES_DIR = File.dirname(__FILE__) + "/mercurial"
29 TEMPLATE_NAME = "hg-template"
29 TEMPLATE_NAME = "hg-template"
30 TEMPLATE_EXTENSION = "tmpl"
30 TEMPLATE_EXTENSION = "tmpl"
31
31
32 class << self
32 class << self
33 def client_version
33 def client_version
34 @@client_version ||= (hgversion || [])
34 @@client_version ||= (hgversion || [])
35 end
35 end
36
36
37 def hgversion
37 def hgversion
38 # The hg version is expressed either as a
38 # The hg version is expressed either as a
39 # release number (eg 0.9.5 or 1.0) or as a revision
39 # release number (eg 0.9.5 or 1.0) or as a revision
@@ -43,15 +43,15 module Redmine
43 m[2].scan(%r{\d+}).collect(&:to_i)
43 m[2].scan(%r{\d+}).collect(&:to_i)
44 end
44 end
45 end
45 end
46
46
47 def hgversion_from_command_line
47 def hgversion_from_command_line
48 shellout("#{HG_BIN} --version") { |io| io.read }.to_s
48 shellout("#{HG_BIN} --version") { |io| io.read }.to_s
49 end
49 end
50
50
51 def template_path
51 def template_path
52 @@template_path ||= template_path_for(client_version)
52 @@template_path ||= template_path_for(client_version)
53 end
53 end
54
54
55 def template_path_for(version)
55 def template_path_for(version)
56 if ((version <=> [0,9,5]) > 0) || version.empty?
56 if ((version <=> [0,9,5]) > 0) || version.empty?
57 ver = "1.0"
57 ver = "1.0"
@@ -61,7 +61,7 module Redmine
61 "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
61 "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
62 end
62 end
63 end
63 end
64
64
65 def info
65 def info
66 cmd = "#{HG_BIN} -R #{target('')} root"
66 cmd = "#{HG_BIN} -R #{target('')} root"
67 root_url = nil
67 root_url = nil
@@ -76,12 +76,12 module Redmine
76 rescue CommandFailed
76 rescue CommandFailed
77 return nil
77 return nil
78 end
78 end
79
79
80 def entries(path=nil, identifier=nil)
80 def entries(path=nil, identifier=nil)
81 path ||= ''
81 path ||= ''
82 entries = Entries.new
82 entries = Entries.new
83 cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} locate"
83 cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} locate"
84 cmd << " -r " + shell_quote(identifier ? identifier.to_s : "tip")
84 cmd << " -r #{hgrev(identifier)}"
85 cmd << " " + shell_quote("path:#{path}") unless path.empty?
85 cmd << " " + shell_quote("path:#{path}") unless path.empty?
86 shellout(cmd) do |io|
86 shellout(cmd) do |io|
87 io.each_line do |line|
87 io.each_line do |line|
@@ -101,16 +101,16 module Redmine
101 return nil if $? && $?.exitstatus != 0
101 return nil if $? && $?.exitstatus != 0
102 entries.sort_by_name
102 entries.sort_by_name
103 end
103 end
104
104
105 # Fetch the revisions by using a template file that
105 # Fetch the revisions by using a template file that
106 # makes Mercurial produce a xml output.
106 # makes Mercurial produce a xml output.
107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
108 revisions = Revisions.new
108 revisions = Revisions.new
109 cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{shell_quote self.class.template_path}"
109 cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{shell_quote self.class.template_path}"
110 if identifier_from && identifier_to
110 if identifier_from && identifier_to
111 cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
111 cmd << " -r #{hgrev(identifier_from)}:#{hgrev(identifier_to)}"
112 elsif identifier_from
112 elsif identifier_from
113 cmd << " -r #{identifier_from.to_i}:"
113 cmd << " -r #{hgrev(identifier_from)}:"
114 end
114 end
115 cmd << " --limit #{options[:limit].to_i}" if options[:limit]
115 cmd << " --limit #{options[:limit].to_i}" if options[:limit]
116 cmd << " #{shell_quote path}" unless path.blank?
116 cmd << " #{shell_quote path}" unless path.blank?
@@ -134,7 +134,7 module Redmine
134 }
134 }
135 end
135 end
136 paths.sort! { |x,y| x[:path] <=> y[:path] }
136 paths.sort! { |x,y| x[:path] <=> y[:path] }
137
137
138 revisions << Revision.new({:identifier => logentry.attributes['revision'],
138 revisions << Revision.new({:identifier => logentry.attributes['revision'],
139 :scmid => logentry.attributes['node'],
139 :scmid => logentry.attributes['node'],
140 :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
140 :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
@@ -150,7 +150,7 module Redmine
150 return nil if $? && $?.exitstatus != 0
150 return nil if $? && $?.exitstatus != 0
151 revisions
151 revisions
152 end
152 end
153
153
154 def diff(path, identifier_from, identifier_to=nil)
154 def diff(path, identifier_from, identifier_to=nil)
155 path ||= ''
155 path ||= ''
156 diff_args = ''
156 diff_args = ''
@@ -170,10 +170,10 module Redmine
170 return nil if $? && $?.exitstatus != 0
170 return nil if $? && $?.exitstatus != 0
171 diff
171 diff
172 end
172 end
173
173
174 def cat(path, identifier=nil)
174 def cat(path, identifier=nil)
175 cmd = "#{HG_BIN} -R #{target('')} cat"
175 cmd = "#{HG_BIN} -R #{target('')} cat"
176 cmd << " -r " + shell_quote(identifier ? identifier.to_s : "tip")
176 cmd << " -r #{hgrev(identifier)}"
177 cmd << " #{target(path)}"
177 cmd << " #{target(path)}"
178 cat = nil
178 cat = nil
179 shellout(cmd) do |io|
179 shellout(cmd) do |io|
General Comments 0
You need to be logged in to leave comments. Login now