diff lib/redmine/scm/adapters/mercurial_adapter.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 753f1380d6bc 0c939c159af4
line wrap: on
line diff
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb	Thu Mar 03 11:42:28 2011 +0000
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb	Mon Jun 06 14:24:13 2011 +0100
@@ -1,16 +1,16 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # of the License, or (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
@@ -47,7 +47,7 @@
           end
 
           def client_available
-            !client_version.empty?
+            client_version_above?([0, 9, 5])
           end
 
           def hgversion
@@ -83,7 +83,11 @@
 
         def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
           super
-          @path_encoding = path_encoding || 'UTF-8'
+          @path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
+        end
+
+        def path_encoding
+          @path_encoding
         end
 
         def info
@@ -118,7 +122,7 @@
         end
 
         def summary
-          return @summary if @summary 
+          return @summary if @summary
           hg 'rhsummary' do |io|
             output = io.read
             if output.respond_to?(:force_encoding)
@@ -132,7 +136,7 @@
         end
         private :summary
 
-        def entries(path=nil, identifier=nil)
+        def entries(path=nil, identifier=nil, options={})
           p1 = scm_iconv(@path_encoding, 'UTF-8', path)
           manifest = hg('rhmanifest', '-r', CGI.escape(hgrev(identifier)),
                         CGI.escape(without_leading_slash(p1.to_s))) do |io|
@@ -193,30 +197,39 @@
             rescue
             end
           end
-
           as_ary(log['logentry']).each do |le|
             cpalist = as_ary(le['paths']['path-copied']).map do |e|
-              [e['__content__'], e['copyfrom-path']].map { |s| CGI.unescape(s) }
+              [e['__content__'], e['copyfrom-path']].map do |s|
+                scm_iconv('UTF-8', @path_encoding, CGI.unescape(s))
+              end
             end
             cpmap = Hash[*cpalist.flatten]
-
             paths = as_ary(le['paths']['path']).map do |e|
               p = scm_iconv('UTF-8', @path_encoding, CGI.unescape(e['__content__']) )
-              {:action => e['action'], :path => with_leading_slash(p),
-               :from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil),
-               :from_revision => (cpmap.member?(p) ? le['revision'] : nil)}
+              {:action        => e['action'],
+               :path          => with_leading_slash(p),
+               :from_path     => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil),
+               :from_revision => (cpmap.member?(p) ? le['node'] : nil)}
             end.sort { |a, b| a[:path] <=> b[:path] }
-
             yield Revision.new(:revision => le['revision'],
-                               :scmid => le['node'],
-                               :author => (le['author']['__content__'] rescue ''),
-                               :time => Time.parse(le['date']['__content__']).localtime,
-                               :message => le['msg']['__content__'],
-                               :paths => paths)
+                               :scmid    => le['node'],
+                               :author   => (le['author']['__content__'] rescue ''),
+                               :time     => Time.parse(le['date']['__content__']),
+                               :message  => le['msg']['__content__'],
+                               :paths    => paths)
           end
           self
         end
 
+        # Returns list of nodes in the specified branch
+        def nodes_in_branch(branch, options={})
+          hg_args = ['rhlog', '--template', '{node|short}\n', '--rhbranch', CGI.escape(branch)]
+          hg_args << '--from' << CGI.escape(branch)
+          hg_args << '--to'   << '0'
+          hg_args << '--limit' << options[:limit] if options[:limit]
+          hg(*hg_args) { |io| io.readlines.map { |e| e.chomp } }
+        end
+
         def diff(path, identifier_from, identifier_to=nil)
           hg_args = %w|rhdiff|
           if identifier_to
@@ -241,7 +254,7 @@
 
         def cat(path, identifier=nil)
           p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
-          hg 'rhcat', '-r', hgrev(identifier), hgtarget(p) do |io|
+          hg 'rhcat', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
             io.binmode
             io.read
           end
@@ -252,7 +265,7 @@
         def annotate(path, identifier=nil)
           p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
           blame = Annotate.new
-          hg 'rhannotate', '-ncu', '-r', hgrev(identifier), hgtarget(p) do |io|
+          hg 'rhannotate', '-ncu', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
             io.each_line do |line|
               line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
               next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}