Project

General

Profile

Defect #2664 » issue-2664-0.9-stable-2010-04-11.patch

Yuya Nishihara, 2010-04-11 04:39

View differences:

lib/redmine/scm/adapters/mercurial/hg-template-0.9.5.tmpl
3 3
changeset_verbose = 'This template must be used with --debug option\n'
4 4
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'
5 5

  
6
file = '<path action="M">{file|escape}</path>\n'
7
file_add = '<path action="A">{file_add|escape}</path>\n'
8
file_del = '<path action="D">{file_del|escape}</path>\n'
9
file_copy = '<path-copied copyfrom-path="{source|escape}">{name|urlescape}</path-copied>\n'
6
file = '<path action="M">{file|urlescape}</path>\n'
7
file_add = '<path action="A">{file_add|urlescape}</path>\n'
8
file_del = '<path action="D">{file_del|urlescape}</path>\n'
9
file_copy = '<path-copied copyfrom-path="{source|urlescape}">{name|urlescape}</path-copied>\n'
10 10
tag = '<tag>{tag|escape}</tag>\n'
11 11
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
12 12
# footer="</log>"
lib/redmine/scm/adapters/mercurial/hg-template-1.0.tmpl
3 3
changeset_verbose = 'This template must be used with --debug option\n'
4 4
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'
5 5

  
6
file_mod = '<path action="M">{file_mod|escape}</path>\n'
7
file_add = '<path action="A">{file_add|escape}</path>\n'
8
file_del = '<path action="D">{file_del|escape}</path>\n'
9
file_copy = '<path-copied copyfrom-path="{source|escape}">{name|urlescape}</path-copied>\n'
6
file_mod = '<path action="M">{file_mod|urlescape}</path>\n'
7
file_add = '<path action="A">{file_add|urlescape}</path>\n'
8
file_del = '<path action="D">{file_del|urlescape}</path>\n'
9
file_copy = '<path-copied copyfrom-path="{source|urlescape}">{name|urlescape}</path-copied>\n'
10 10
tag = '<tag>{tag|escape}</tag>\n'
11 11
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
12 12
# footer="</log>"
lib/redmine/scm/adapters/mercurial_adapter.rb
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
require 'cgi'
19 20

  
20 21
module Redmine
21 22
  module Scm
......
127 128
                    from_rev = logentry.attributes['revision']
128 129
                  end
129 130
                  paths << {:action => path.attributes['action'],
130
                    :path => "/#{path.text}",
131
                    :from_path => from_path ? "/#{from_path}" : nil,
131
                    :path => "/#{CGI.unescape(path.text)}",
132
                    :from_path => from_path ? "/#{CGI.unescape(from_path)}" : nil,
132 133
                    :from_revision => from_rev ? from_rev : nil
133 134
                  }
134 135
                end
app/helpers/repositories_helper.rb
160 160
  end
161 161
  
162 162
  def mercurial_field_tags(form, repository)
163
      content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
163
    content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) +
164
    content_tag('p', form.select(:path_encoding, [nil] + Setting::ENCODINGS,
165
                                 :label => 'Path encoding'))
164 166
  end
165 167

  
166 168
  def git_field_tags(form, repository)
app/models/repository.rb
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
require 'redmine/scm/adapters/path_encodable_wrapper'
19

  
18 20
class Repository < ActiveRecord::Base
19 21
  belongs_to :project
20 22
  has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
......
38 40
  end
39 41

  
40 42
  def scm
41
    @scm ||= self.scm_adapter.new url, root_url, login, password
43
    @scm ||= new_scm
42 44
    update_attribute(:root_url, @scm.root_url) if root_url.blank?
43 45
    @scm
44 46
  end
......
198 200
  end
199 201
  
200 202
  private
203

  
204
  def new_scm
205
    scm = self.scm_adapter.new url, root_url, login, password
206
    scm = Redmine::Scm::Adapters::PathEncodableWrapper.new(scm, path_encoding) unless path_encoding.blank?
207
    scm
208
  end
201 209
  
202 210
  def before_save
203 211
    # Strips url and root_url
db/migrate/20100410053957_add_repositories_path_encoding.rb
1
class AddRepositoriesPathEncoding < ActiveRecord::Migration
2
  def self.up
3
    add_column :repositories, :path_encoding, :string, :limit => 64, :default => nil
4
  end
5

  
6
  def self.down
7
    remove_column :repositories, :path_encoding
8
  end
9
end
lib/redmine/scm/adapters/path_encodable_wrapper.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2010  Jean-Philippe Lang
3
# Copyright (C) 2010 Yuya Nishihara <yuya@tcha.org>
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18

  
19
require 'delegate'
20
require 'iconv'
21

  
22
module Redmine
23
  module Scm
24
    module Adapters
25
      # wraps scm adapter to convert path encodings
26
      class PathEncodableWrapper < SimpleDelegator  # :nodoc:
27
        def initialize(scm, path_encoding)
28
          super(scm)
29
          @path_encoding = path_encoding
30
        end
31

  
32
        def entry(path=nil, identifier=nil)
33
          convert_entry!(super(to_scm_path(path), identifier))
34
        end
35

  
36
        def entries(path=nil, identifier=nil)
37
          convert_entries!(super(to_scm_path(path), identifier))
38
        end
39

  
40
        def properties(path, identifier=nil)
41
          super(to_scm_path(path), identifier)
42
        end
43

  
44
        def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
45
          convert_revisions!(super(to_scm_path(path), identifier_from, identifier_to, options))
46
        end
47

  
48
        def diff(path, identifier_from, identifier_to=nil)
49
          super(to_scm_path(path), identifier_from, identifier_to)
50
        end
51

  
52
        def cat(path, identifier=nil)
53
          super(to_scm_path(path), identifier)
54
        end
55

  
56
        def annotate(path, identifier=nil)
57
          super(to_scm_path(path), identifier)
58
        end
59

  
60
        private
61

  
62
        def convert_entry!(entry)
63
          return unless entry
64
          entry.name = from_scm_path(entry.name)
65
          entry.path = from_scm_path(entry.path)
66
          entry
67
        end
68

  
69
        def convert_entries!(entries)
70
          return unless entries
71
          entries.each { |e| convert_entry!(e) }
72
          entries
73
        end
74

  
75
        def convert_revisions!(revisions)
76
          return unless revisions
77
          revisions.each do |rev|
78
            next unless rev.paths
79
            rev.paths.each do |e|
80
              e[:path] = from_scm_path(e[:path])
81
              e[:from_path] = from_scm_path(e[:from_path])
82
            end
83
          end
84
          revisions
85
        end
86

  
87
        # convert repository path string to utf-8
88
        def from_scm_path(s)
89
          return unless s
90
          begin
91
            Iconv.conv('UTF-8', @path_encoding, s)
92
          rescue Iconv::Failure => err
93
            raise CommandFailed, "failed to convert path from #{@path_encoding} to UTF-8. #{err}"
94
          end
95
        end
96

  
97
        # convert utf-8 path string to repository encoding
98
        def to_scm_path(s)
99
          return unless s
100
          begin
101
            Iconv.conv(@path_encoding, 'UTF-8', s)
102
          rescue Iconv::Failure => err
103
            raise CommandFailed, "failed to convert path from UTF-8 to #{@path_encoding}. #{err}"
104
          end
105
        end
106
      end
107
    end
108
  end
109
end
(1-1/8)