]> source.dussan.org Git - redmine.git/commitdiff
scm: mercurial: accept both of revision and nodeid as changeset id (#3724).
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 8 Jan 2011 06:24:27 +0000 (06:24 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 8 Jan 2011 06:24:27 +0000 (06:24 +0000)
Contributed by Yuya Nishihara.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4654 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/mercurial.rb
test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
test/unit/repository_mercurial_test.rb

index 9ce3b63ebd8503518b63b3197bd1db4c4b54c76a..8e2ed4517e5294b26a98b0a4aa2e6603be84da71 100644 (file)
@@ -55,6 +55,17 @@ class Repository::Mercurial < Repository
     entries
   end
 
+  # Finds and returns a revision with a number or the beginning of a hash
+  def find_changeset_by_name(name)
+    if /[^\d]/ =~ name or name.to_s.size > 8
+      e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
+    else
+      e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
+    end
+    return e if e
+    changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])  # last ditch
+  end
+
   # Returns the latest changesets for +path+; sorted by revision number
   def latest_changesets(path, rev, limit=10)
     if path.blank?
index 642415812fbfe6b2af0eabad1a8fe4f372a31529..db050c83652726ca596cac08da3edd79beb1d581 100644 (file)
@@ -47,6 +47,17 @@ begin
         assert_nil @adapter.cat("sources/welcome_controller.rb")
       end
 
+      def test_access_by_nodeid
+        path = 'sources/welcome_controller.rb'
+        assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
+      end
+
+      def test_access_by_fuzzy_nodeid
+        path = 'sources/welcome_controller.rb'
+        # falls back to nodeid
+        assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
+      end
+
       private
 
       def test_hgversion_for(hgversion, version)
index d8daf0f9a98f33eec7839cac977df26149a1bfaf..37ef1a7ed4481660e588a36355d58e494d8563a5 100644 (file)
@@ -35,7 +35,8 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
       
       assert_equal 17, @repository.changesets.count
       assert_equal 25, @repository.changes.count
-      assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
+      assert_equal "Initial import.\nThe repository contains 3 files.",
+                   @repository.changesets.find_by_revision('0').comments
     end
     
     def test_fetch_changesets_incremental
@@ -51,7 +52,9 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
     
     def test_entries
       assert_equal 2, @repository.entries("sources", 2).size
+      assert_equal 2, @repository.entries("sources", '400bb8672109').size
       assert_equal 1, @repository.entries("sources", 3).size
+      assert_equal 1, @repository.entries("sources", 'b3a615152df8').size
     end
 
     def test_locate_on_outdated_repository
@@ -122,6 +125,20 @@ class RepositoryMercurialTest < ActiveSupport::TestCase
       assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
       assert_equal '/README', c2[0].from_path
     end
+
+    def test_find_changeset_by_name
+      @repository.fetch_changesets
+      @repository.reload
+      %w|2 400bb8672109 400|.each do |r|
+        assert_equal @repository.find_changeset_by_name(r).revision, '2'
+      end
+    end
+
+    def test_find_changeset_by_invalid_name
+      @repository.fetch_changesets
+      @repository.reload
+      assert_nil @repository.find_changeset_by_name('100000')
+    end
   else
     puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
     def test_fake; assert true end