From 8a35585bd21c08140f5a4c05b6d4e86e3ce0b4ce Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sun, 2 Feb 2014 00:41:16 +0000 Subject: [PATCH] scm: mercurial: add method to switch short or long id by existing value in DB (#14361) git-svn-id: http://svn.redmine.org/redmine/trunk@12755 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository/mercurial.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index 5eedbb7eb..cafc74bd3 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -100,15 +100,20 @@ class Repository::Mercurial < Repository all end + def scmid_for_inserting_db(scmid) + # TODO: switch short or long by existing value in DB + scmid[0, 12] + end + def nodes_in_branch(rev, branch_limit) scm.nodes_in_branch(rev, :limit => branch_limit).collect do |b| - b[0, 12] + scmid_for_inserting_db(b) end end def tag_scmid(rev) scmid = scm.tagmap[rev] - scmid.nil? ? nil : scmid[0, 12] + scmid.nil? ? nil : scmid_for_inserting_db(scmid) end def latest_changesets_cond(path, rev, limit) @@ -152,16 +157,23 @@ class Repository::Mercurial < Repository (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| transaction do - parents = (re.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact + parents = (re.parents || []).collect do |rp| + find_changeset_by_name(scmid_for_inserting_db(rp)) + end.compact cs = Changeset.create(:repository => self, :revision => re.revision, - :scmid => re.scmid, + :scmid => scmid_for_inserting_db(re.scmid), :committer => re.author, :committed_on => re.time, :comments => re.message, :parents => parents) unless cs.new_record? - re.paths.each { |e| cs.create_change(e) } + re.paths.each do |e| + if from_revision = e[:from_revision] + e[:from_revision] = scmid_for_inserting_db(from_revision) + end + cs.create_change(e) + end end end end