Project

General

Profile

Patch #1199 » patch-1199_against_r1441.patch

Frédéric Moulins, 2008-05-21 12:04

View differences:

extra/mercurial/hg-template-0.9.5.tmpl (révision 0)
1
changeset = 'This template must be used with --debug option\n'
2
changeset_quiet =  'This template must be used with --debug option\n'
3
changeset_verbose = 'This template must be used with --debug option\n'
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|strip|escape|addbreaks}</msg>\n{tags}</logentry>\n\n'
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'
10
tag = '<tag>{tag|escape}</tag>\n'
11
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
12
# footer="</log>"
extra/mercurial/hg-template-1.0.tmpl (révision 0)
1
changeset = 'This template must be used with --debug option\n'
2
changeset_quiet =  'This template must be used with --debug option\n'
3
changeset_verbose = 'This template must be used with --debug option\n'
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|strip|escape|addbreaks}</msg>\n{tags}</logentry>\n\n'
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'
10
tag = '<tag>{tag|escape}</tag>\n'
11
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
12
# footer="</log>"
lib/redmine/scm/adapters/abstract_adapter.rb (copie de travail)
94 94
          path ||= ''
95 95
          (path[0,1]!="/") ? "/#{path}" : path
96 96
        end
97
        
97

  
98
        def with_trailling_slash(path)
99
          path ||= ''
100
          (path[-1,1] == "/") ? path : "#{path}/"
101
        end
102

  
98 103
        def shell_quote(str)
99 104
          if RUBY_PLATFORM =~ /mswin/
100 105
            '"' + str.gsub(/"/, '\\"') + '"'
lib/redmine/scm/adapters/mercurial_adapter.rb (copie de travail)
24 24
      
25 25
        # Mercurial executable name
26 26
        HG_BIN = "hg"
27
        TEMPLATES_DIR = "#{RAILS_ROOT}/extra/mercurial"
28
        TEMPLATE_NAME = "hg-template"
29
        TEMPLATE_EXTENSION = "tmpl"
27 30
        
28 31
        def info
29 32
          cmd = "#{HG_BIN} -R #{target('')} root"
......
40 43
          return nil
41 44
        end
42 45
        
43
        def entries(path=nil, identifier=nil)
44
          path ||= ''
46
        def entries(path="", identifier=nil)
45 47
          entries = Entries.new
46
          cmd = "#{HG_BIN} -R #{target('')} --cwd #{target(path)} locate"
47
          cmd << " -r #{identifier.to_i}" if identifier
48
          cmd << " " + shell_quote('glob:**')
48
          cmd = "#{HG_BIN} -R #{target('')} --cwd #{target('')} locate"
49
          cmd << " -r " + (identifier ? identifier.to_s : "tip")
50
          cmd << " " + shell_quote("path:#{path}") unless path.empty?
49 51
          shellout(cmd) do |io|
50 52
            io.each_line do |line|
51
              e = line.chomp.split(%r{[\/\\]})
52
              entries << Entry.new({:name => e.first,
53
                                    :path => (path.empty? ? e.first : "#{path}/#{e.first}"),
54
                                    :kind => (e.size > 1 ? 'dir' : 'file'),
55
                                    :lastrev => Revision.new
56
                                    }) unless entries.detect{|entry| entry.name == e.first}
53
              # HG uses antislashs as separator on Windows
54
              line = line.gsub(/\\/, "/")
55
              if path.empty? or e = line.gsub!(%r{^#{with_trailling_slash(path)}},'')
56
                e ||= line
57
                e = e.chomp.split(%r{[\/\\]})
58
                entries << Entry.new({:name => e.first,
59
                                       :path => (path.nil? or path.empty? ? e.first : "#{with_trailling_slash(path)}#{e.first}"),
60
                                       :kind => (e.size > 1 ? 'dir' : 'file'),
61
                                       :lastrev => Revision.new
62
                                     }) unless entries.detect{|entry| entry.name == e.first}
63
              end
57 64
            end
58 65
          end
59 66
          return nil if $? && $?.exitstatus != 0
60 67
          entries.sort_by_name
61 68
        end
62 69
          
70
        
71
        # Fetch the revisions by using a template file that make Mercurial producing a xml output.
63 72
        def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
64 73
          revisions = Revisions.new
74
          cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{self.class.template_path}"
75
          if identifier_from && identifier_to
76
            cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
77
          elsif identifier_from
78
            cmd << " -r #{identifier_from.to_i}:"
79
          end
80
          cmd << " --limit #{options[:limit].to_i}" if options[:limit]
81
          cmd << " #{path}" if path
82
          shellout(cmd) do |io|
83
            begin
84
              # HG doesn't close the XML Document...
85
              doc = REXML::Document.new(io.read << "</log>")
86
              doc.elements.each("log/logentry") do |logentry|
87
                paths = []
88
                copies = logentry.get_elements('paths/path-copied')
89
                logentry.elements.each("paths/path") do |path|
90
                  # Detect if the added file is a copy
91
                  if path.attributes['action'] == 'A' and c = copies.find{ |e| e.text == path.text }
92
                    from_path = c.attributes['copyfrom-path']
93
                    from_rev = logentry.attributes['revision']
94
                  end
95
                  paths << {:action => path.attributes['action'],
96
                    :path => "/#{path.text}",
97
                    :from_path => from_path ? "/#{from_path}" : nil,
98
                    :from_revision => from_rev ? from_rev : nil
99
                  }
100
                end
101
                paths.sort! { |x,y| x[:path] <=> y[:path] }
102
                
103
                revisions << Revision.new({:identifier => logentry.attributes['revision'],
104
                                            :scmid => logentry.attributes['node'],
105
                                            :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
106
                                            :time => Time.parse(logentry.elements['date'].text).localtime,
107
                                            :message => logentry.elements['msg'].text,
108
                                            :paths => paths
109
                                          })
110
              end
111
            rescue
112
              logger.debug($!)
113
            end
114
          end
115
          return nil if $? && $?.exitstatus != 0
116
          revisions
117
        end
118
        
119
        
120
        def revisions_old(path=nil, identifier_from=nil, identifier_to=nil, options={})
121
          revisions = Revisions.new
65 122
          cmd = "#{HG_BIN} -v --encoding utf8 -R #{target('')} log"
66 123
          if identifier_from && identifier_to
67 124
            cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
......
125 182
        
126 183
        def cat(path, identifier=nil)
127 184
          cmd = "#{HG_BIN} -R #{target('')} cat"
128
          cmd << " -r #{identifier.to_i}" if identifier
185
          cmd << " -r " + (identifier ? identifier.to_s : "tip")
129 186
          cmd << " #{target(path)}"
130 187
          cat = nil
131 188
          shellout(cmd) do |io|
......
140 197
          path ||= ''
141 198
          cmd = "#{HG_BIN} -R #{target('')}"
142 199
          cmd << " annotate -n -u"
143
          cmd << " -r #{identifier.to_i}" if identifier
200
          cmd << " -r " + (identifier ? identifier.to_s : "tip")
144 201
          cmd << " #{target(path)}"
145 202
          blame = Annotate.new
146 203
          shellout(cmd) do |io|
......
161 218
          
162 219
          # Changes
163 220
          paths = (rev_id == 0) ?
164
            # Can't get changes for revision 0 with hg status
165
            changeset[:files].to_s.split.collect{|path| {:action => 'A', :path => "/#{path}"}} :
221
          # Can't get changes for revision 0 with hg status
222
          changeset[:files].to_s.split.collect{|path| {:action => 'A', :path => "/#{path}"}} :
166 223
            status(rev_id)
167 224
          
168 225
          Revision.new({:identifier => rev_id,
......
193 250
          end
194 251
          result
195 252
        end
253

  
254
        def self.hgversion
255
          @@hgversion ||= %x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1].split(".").collect(&:to_i)
256
        end
257

  
258
        def self.template_path
259
          if (self.hgversion <=> [0,9,5]) > 0
260
            ver = "1.0"
261
          else
262
            ver = "0.9.5"
263
          end
264
          @@template ||= "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
265
        end
266
        
196 267
      end
197 268
    end
198 269
  end
(3-3/5)