##// END OF EJS Templates
Add "--encoding utf8" option to the Mercurial "hg log" command in order to get utf8 encoded commit logs (#834)....
Jean-Philippe Lang -
r1241:451aa6ba4e24
parent child
Show More
@@ -1,175 +1,175
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'redmine/scm/adapters/abstract_adapter'
19 19
20 20 module Redmine
21 21 module Scm
22 22 module Adapters
23 23 class MercurialAdapter < AbstractAdapter
24 24
25 25 # Mercurial executable name
26 26 HG_BIN = "hg"
27 27
28 28 def info
29 29 cmd = "#{HG_BIN} -R #{target('')} root"
30 30 root_url = nil
31 31 shellout(cmd) do |io|
32 32 root_url = io.gets
33 33 end
34 34 return nil if $? && $?.exitstatus != 0
35 35 info = Info.new({:root_url => root_url.chomp,
36 36 :lastrev => revisions(nil,nil,nil,{:limit => 1}).last
37 37 })
38 38 info
39 39 rescue CommandFailed
40 40 return nil
41 41 end
42 42
43 43 def entries(path=nil, identifier=nil)
44 44 path ||= ''
45 45 entries = Entries.new
46 46 cmd = "#{HG_BIN} -R #{target('')} --cwd #{target(path)} locate"
47 47 cmd << " -r #{identifier.to_i}" if identifier
48 48 cmd << " " + shell_quote('glob:**')
49 49 shellout(cmd) do |io|
50 50 io.each_line do |line|
51 51 e = line.chomp.split(%r{[\/\\]})
52 52 entries << Entry.new({:name => e.first,
53 53 :path => (path.empty? ? e.first : "#{path}/#{e.first}"),
54 54 :kind => (e.size > 1 ? 'dir' : 'file'),
55 55 :lastrev => Revision.new
56 56 }) unless entries.detect{|entry| entry.name == e.first}
57 57 end
58 58 end
59 59 return nil if $? && $?.exitstatus != 0
60 60 entries.sort_by_name
61 61 end
62 62
63 63 def entry(path=nil, identifier=nil)
64 64 path ||= ''
65 65 search_path = path.split('/')[0..-2].join('/')
66 66 entry_name = path.split('/').last
67 67 e = entries(search_path, identifier)
68 68 e ? e.detect{|entry| entry.name == entry_name} : nil
69 69 end
70 70
71 71 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
72 72 revisions = Revisions.new
73 cmd = "#{HG_BIN} -v -R #{target('')} log"
73 cmd = "#{HG_BIN} -v --encoding utf8 -R #{target('')} log"
74 74 if identifier_from && identifier_to
75 75 cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
76 76 elsif identifier_from
77 77 cmd << " -r #{identifier_from.to_i}:"
78 78 end
79 79 cmd << " --limit #{options[:limit].to_i}" if options[:limit]
80 80 shellout(cmd) do |io|
81 81 changeset = {}
82 82 parsing_descr = false
83 83 line_feeds = 0
84 84
85 85 io.each_line do |line|
86 86 if line =~ /^(\w+):\s*(.*)$/
87 87 key = $1
88 88 value = $2
89 89 if parsing_descr && line_feeds > 1
90 90 parsing_descr = false
91 91 revisions << Revision.new({:identifier => changeset[:changeset].split(':').first.to_i,
92 92 :scmid => changeset[:changeset].split(':').last,
93 93 :author => changeset[:user],
94 94 :time => Time.parse(changeset[:date]),
95 95 :message => changeset[:description],
96 96 :paths => changeset[:files].to_s.split.collect{|path| {:action => 'X', :path => "/#{path}"}}
97 97 })
98 98 changeset = {}
99 99 end
100 100 if !parsing_descr
101 101 changeset.store key.to_sym, value
102 102 if $1 == "description"
103 103 parsing_descr = true
104 104 line_feeds = 0
105 105 next
106 106 end
107 107 end
108 108 end
109 109 if parsing_descr
110 110 changeset[:description] << line
111 111 line_feeds += 1 if line.chomp.empty?
112 112 end
113 113 end
114 114 revisions << Revision.new({:identifier => changeset[:changeset].split(':').first.to_i,
115 115 :scmid => changeset[:changeset].split(':').last,
116 116 :author => changeset[:user],
117 117 :time => Time.parse(changeset[:date]),
118 118 :message => changeset[:description],
119 119 :paths => changeset[:files].to_s.split.collect{|path| {:action => 'X', :path => "/#{path}"}}
120 120 })
121 121 end
122 122 return nil if $? && $?.exitstatus != 0
123 123 revisions
124 124 end
125 125
126 126 def diff(path, identifier_from, identifier_to=nil, type="inline")
127 127 path ||= ''
128 128 if identifier_to
129 129 identifier_to = identifier_to.to_i
130 130 else
131 131 identifier_to = identifier_from.to_i - 1
132 132 end
133 133 cmd = "#{HG_BIN} -R #{target('')} diff -r #{identifier_to} -r #{identifier_from} --nodates"
134 134 cmd << " -I #{target(path)}" unless path.empty?
135 135 diff = []
136 136 shellout(cmd) do |io|
137 137 io.each_line do |line|
138 138 diff << line
139 139 end
140 140 end
141 141 return nil if $? && $?.exitstatus != 0
142 142 DiffTableList.new diff, type
143 143 end
144 144
145 145 def cat(path, identifier=nil)
146 146 cmd = "#{HG_BIN} -R #{target('')} cat #{target(path)}"
147 147 cat = nil
148 148 shellout(cmd) do |io|
149 149 io.binmode
150 150 cat = io.read
151 151 end
152 152 return nil if $? && $?.exitstatus != 0
153 153 cat
154 154 end
155 155
156 156 def annotate(path, identifier=nil)
157 157 path ||= ''
158 158 cmd = "#{HG_BIN} -R #{target('')}"
159 159 cmd << " annotate -n -u"
160 160 cmd << " -r #{identifier.to_i}" if identifier
161 161 cmd << " #{target(path)}"
162 162 blame = Annotate.new
163 163 shellout(cmd) do |io|
164 164 io.each_line do |line|
165 165 next unless line =~ %r{^([^:]+)\s(\d+):(.*)$}
166 166 blame.add_line($3.rstrip, Revision.new(:identifier => $2.to_i, :author => $1.strip))
167 167 end
168 168 end
169 169 return nil if $? && $?.exitstatus != 0
170 170 blame
171 171 end
172 172 end
173 173 end
174 174 end
175 175 end
General Comments 0
You need to be logged in to leave comments. Login now