scm: mercurial: use long id in adapter level (#14361)

git-svn-id: http://svn.redmine.org/redmine/trunk@12752 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-02-01 07:47:04 +00:00
parent 6ea2b7a43b
commit ae68ff1100
5 changed files with 51 additions and 43 deletions

View File

@ -152,16 +152,24 @@ class Repository::Mercurial < Repository
(db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| (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| scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
transaction do transaction do
parents = (re.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact scmid = re.scmid[0, 12]
parents = (re.parents || []).collect do |rp|
find_changeset_by_name(rp[0, 12])
end.compact
cs = Changeset.create(:repository => self, cs = Changeset.create(:repository => self,
:revision => re.revision, :revision => re.revision,
:scmid => re.scmid, :scmid => scmid,
:committer => re.author, :committer => re.author,
:committed_on => re.time, :committed_on => re.time,
:comments => re.message, :comments => re.message,
:parents => parents) :parents => parents)
unless cs.new_record? 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] = from_revision[0, 12]
end
cs.create_change(e)
end
end end
end end
end end

View File

@ -1,12 +1,12 @@
changeset = 'This template must be used with --debug option\n' changeset = 'This template must be used with --debug option\n'
changeset_quiet = 'This template must be used with --debug option\n' changeset_quiet = 'This template must be used with --debug option\n'
changeset_verbose = 'This template must be used with --debug option\n' changeset_verbose = 'This template must be used with --debug option\n'
changeset_debug = '<logentry revision="{rev}" node="{node|short}">\n<author>{author|escape}</author>\n<date>{date|isodatesec}</date>\n<paths>\n{file_mods}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n<parents>\n{parents}</parents>\n</logentry>\n\n' changeset_debug = '<logentry revision="{rev}" node="{node}">\n<author>{author|escape}</author>\n<date>{date|isodatesec}</date>\n<paths>\n{file_mods}{file_adds}{file_dels}{file_copies}</paths>\n<msg>{desc|escape}</msg>\n<parents>\n{parents}</parents>\n</logentry>\n\n'
file_mod = '<path action="M">{file_mod|urlescape}</path>\n' file_mod = '<path action="M">{file_mod|urlescape}</path>\n'
file_add = '<path action="A">{file_add|urlescape}</path>\n' file_add = '<path action="A">{file_add|urlescape}</path>\n'
file_del = '<path action="D">{file_del|urlescape}</path>\n' file_del = '<path action="D">{file_del|urlescape}</path>\n'
file_copy = '<path-copied copyfrom-path="{source|urlescape}">{name|urlescape}</path-copied>\n' file_copy = '<path-copied copyfrom-path="{source|urlescape}">{name|urlescape}</path-copied>\n'
parent = '<parent>{node|short}</parent>\n' parent = '<parent>{node}</parent>\n'
header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n' header='<?xml version="1.0" encoding="UTF-8" ?>\n<log>\n\n'
# footer="</log>" # footer="</log>"

View File

@ -16,7 +16,7 @@ I/O encoding:
:file path: urlencoded, raw string :file path: urlencoded, raw string
:tag name: utf-8 :tag name: utf-8
:branch name: utf-8 :branch name: utf-8
:node: 12-digits (short) hex string :node: hex string
Output example of rhsummary:: Output example of rhsummary::
@ -60,7 +60,7 @@ def _tip(ui, repo):
return repo.changelog.count() - 1 return repo.changelog.count() - 1
tipctx = repo.changectx(tiprev()) tipctx = repo.changectx(tiprev())
ui.write('<tip revision="%d" node="%s"/>\n' ui.write('<tip revision="%d" node="%s"/>\n'
% (tipctx.rev(), _x(node.short(tipctx.node())))) % (tipctx.rev(), _x(node.hex(tipctx.node()))))
_SPECIAL_TAGS = ('tip',) _SPECIAL_TAGS = ('tip',)
@ -74,7 +74,7 @@ def _tags(ui, repo):
except error.LookupError: except error.LookupError:
continue continue
ui.write('<tag revision="%d" node="%s" name="%s"/>\n' ui.write('<tag revision="%d" node="%s" name="%s"/>\n'
% (r, _x(node.short(n)), _x(t))) % (r, _x(node.hex(n)), _x(t)))
def _branches(ui, repo): def _branches(ui, repo):
# see mercurial/commands.py:branches # see mercurial/commands.py:branches
@ -89,7 +89,7 @@ def _branches(ui, repo):
for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True): for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
if repo.lookup(r) in branchheads(t): if repo.lookup(r) in branchheads(t):
ui.write('<branch revision="%d" node="%s" name="%s"/>\n' ui.write('<branch revision="%d" node="%s" name="%s"/>\n'
% (r, _x(node.short(n)), _x(t))) % (r, _x(node.hex(n)), _x(t)))
def _manifest(ui, repo, path, rev): def _manifest(ui, repo, path, rev):
ctx = repo.changectx(rev) ctx = repo.changectx(rev)
@ -114,7 +114,7 @@ def _manifest(ui, repo, path, rev):
tm, tzoffset = fctx.date() tm, tzoffset = fctx.date()
ui.write('<file name="%s" revision="%d" node="%s" ' ui.write('<file name="%s" revision="%d" node="%s" '
'time="%d" size="%d"/>\n' 'time="%d" size="%d"/>\n'
% (_u(name), fctx.rev(), _x(node.short(fctx.node())), % (_u(name), fctx.rev(), _x(node.hex(fctx.node())),
tm, fctx.size(), )) tm, fctx.size(), ))
ui.write('</manifest>\n') ui.write('</manifest>\n')

View File

@ -219,7 +219,7 @@ module Redmine
end.sort { |a, b| a[:path] <=> b[:path] } end.sort { |a, b| a[:path] <=> b[:path] }
parents_ary = [] parents_ary = []
as_ary(le['parents']['parent']).map do |par| as_ary(le['parents']['parent']).map do |par|
parents_ary << par['__content__'] if par['__content__'] != "000000000000" parents_ary << par['__content__'] if par['__content__'] != "0000000000000000000000000000000000000000"
end end
yield Revision.new(:revision => le['revision'], yield Revision.new(:revision => le['revision'],
:scmid => le['node'], :scmid => le['node'],
@ -234,7 +234,7 @@ module Redmine
# Returns list of nodes in the specified branch # Returns list of nodes in the specified branch
def nodes_in_branch(branch, options={}) def nodes_in_branch(branch, options={})
hg_args = ['rhlog', '--template', '{node|short}\n', '--rhbranch', CGI.escape(branch)] hg_args = ['rhlog', '--template', '{node}\n', '--rhbranch', CGI.escape(branch)]
hg_args << '--from' << CGI.escape(branch) hg_args << '--from' << CGI.escape(branch)
hg_args << '--to' << '0' hg_args << '--to' << '0'
hg_args << '--limit' << options[:limit] if options[:limit] hg_args << '--limit' << options[:limit] if options[:limit]

View File

@ -90,7 +90,7 @@ begin
repo_path = adp.info.root_url.gsub(/\\/, "/") repo_path = adp.info.root_url.gsub(/\\/, "/")
assert_equal REPOSITORY_PATH, repo_path assert_equal REPOSITORY_PATH, repo_path
assert_equal '31', adp.info.lastrev.revision assert_equal '31', adp.info.lastrev.revision
assert_equal '31eeee7395c8',adp.info.lastrev.scmid assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355',adp.info.lastrev.scmid
end end
end end
@ -98,14 +98,14 @@ begin
revisions = @adapter.revisions(nil, 2, 4) revisions = @adapter.revisions(nil, 2, 4)
assert_equal 3, revisions.size assert_equal 3, revisions.size
assert_equal '2', revisions[0].revision assert_equal '2', revisions[0].revision
assert_equal '400bb8672109', revisions[0].scmid assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
assert_equal '4', revisions[2].revision assert_equal '4', revisions[2].revision
assert_equal 'def6d2f1254a', revisions[2].scmid assert_equal 'def6d2f1254a56fb8fbe9ec3b5c0451674dbd8b8', revisions[2].scmid
revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
assert_equal 2, revisions.size assert_equal 2, revisions.size
assert_equal '2', revisions[0].revision assert_equal '2', revisions[0].revision
assert_equal '400bb8672109', revisions[0].scmid assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
end end
def test_parents def test_parents
@ -115,12 +115,12 @@ begin
revs2 = @adapter.revisions(nil, 1, 1) revs2 = @adapter.revisions(nil, 1, 1)
assert_equal 1, revs2.size assert_equal 1, revs2.size
assert_equal 1, revs2[0].parents.size assert_equal 1, revs2[0].parents.size
assert_equal "0885933ad4f6", revs2[0].parents[0] assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", revs2[0].parents[0]
revs3 = @adapter.revisions(nil, 30, 30) revs3 = @adapter.revisions(nil, 30, 30)
assert_equal 1, revs3.size assert_equal 1, revs3.size
assert_equal 2, revs3[0].parents.size assert_equal 2, revs3[0].parents.size
assert_equal "a94b0528f24f", revs3[0].parents[0] assert_equal "a94b0528f24fe05ebaef496ae0500bb050772e36", revs3[0].parents[0]
assert_equal "3a330eb32958", revs3[0].parents[1] assert_equal "3a330eb329586ea2adb3f83237c23310e744ebe9", revs3[0].parents[1]
end end
def test_diff def test_diff
@ -213,7 +213,7 @@ begin
assert_equal 'file', readme.kind assert_equal 'file', readme.kind
assert_equal 27, readme.size assert_equal 27, readme.size
assert_equal '1', readme.lastrev.revision assert_equal '1', readme.lastrev.revision
assert_equal '9d5b5b004199', readme.lastrev.identifier assert_equal '9d5b5b00419901478496242e0768deba1ce8c51e', readme.lastrev.identifier
# 2007-12-14 10:24:01 +0100 # 2007-12-14 10:24:01 +0100
assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
@ -242,7 +242,7 @@ begin
assert_equal 'file', readme.kind assert_equal 'file', readme.kind
assert_equal 21, readme.size assert_equal 21, readme.size
assert_equal '0', readme.lastrev.revision assert_equal '0', readme.lastrev.revision
assert_equal '0885933ad4f6', readme.lastrev.identifier assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', readme.lastrev.identifier
# 2007-12-14 10:22:52 +0100 # 2007-12-14 10:22:52 +0100
assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
end end
@ -260,7 +260,7 @@ begin
assert_equal 'file', readme.kind assert_equal 'file', readme.kind
assert_equal 365, readme.size assert_equal 365, readme.size
assert_equal '8', readme.lastrev.revision assert_equal '8', readme.lastrev.revision
assert_equal 'c51f5bb613cd', readme.lastrev.identifier assert_equal 'c51f5bb613cd60793c2a9fe9df29332e74bb949f', readme.lastrev.identifier
# 2001-02-01 00:00:00 -0900 # 2001-02-01 00:00:00 -0900
assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
end end
@ -288,9 +288,9 @@ begin
def test_tagmap def test_tagmap
tm = { tm = {
@tag_char_1 => 'adf805632193', @tag_char_1 => 'adf805632193500ad3b615cd04f58f9b0769f576',
'tag_test.00' => '6987191f453a', 'tag_test.00' => '6987191f453a5f6557018d522feea2c450d5588d',
'tag-init-revision' => '0885933ad4f6', 'tag-init-revision' => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
} }
assert_equal tm, @adapter.tagmap assert_equal tm, @adapter.tagmap
end end
@ -303,36 +303,36 @@ begin
assert_equal 7, brs.length assert_equal 7, brs.length
assert_equal 'default', brs[0].to_s assert_equal 'default', brs[0].to_s
assert_equal '31', brs[0].revision assert_equal '31', brs[0].revision
assert_equal '31eeee7395c8', brs[0].scmid assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355', brs[0].scmid
assert_equal 'test-branch-01', brs[1].to_s assert_equal 'test-branch-01', brs[1].to_s
assert_equal '30', brs[1].revision assert_equal '30', brs[1].revision
assert_equal 'ad4dc4f80284', brs[1].scmid assert_equal 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7', brs[1].scmid
assert_equal @branch_char_1, brs[2].to_s assert_equal @branch_char_1, brs[2].to_s
assert_equal '27', brs[2].revision assert_equal '27', brs[2].revision
assert_equal '7bbf4c738e71', brs[2].scmid assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', brs[2].scmid
assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
assert_equal '25', brs[3].revision assert_equal '25', brs[3].revision
assert_equal 'afc61e85bde7', brs[3].scmid assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', brs[3].scmid
assert_equal @branch_char_0, brs[4].to_s assert_equal @branch_char_0, brs[4].to_s
assert_equal '23', brs[4].revision assert_equal '23', brs[4].revision
assert_equal 'c8d3e4887474', brs[4].scmid assert_equal 'c8d3e4887474af6a589190140508037ebaa9d9c3', brs[4].scmid
assert_equal 'test_branch.latin-1', brs[5].to_s assert_equal 'test_branch.latin-1', brs[5].to_s
assert_equal '22', brs[5].revision assert_equal '22', brs[5].revision
assert_equal 'c2ffe7da686a', brs[5].scmid assert_equal 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768', brs[5].scmid
assert_equal 'test-branch-00', brs[6].to_s assert_equal 'test-branch-00', brs[6].to_s
assert_equal '13', brs[6].revision assert_equal '13', brs[6].revision
assert_equal '3a330eb32958', brs[6].scmid assert_equal '3a330eb329586ea2adb3f83237c23310e744ebe9', brs[6].scmid
end end
def test_branchmap def test_branchmap
bm = { bm = {
'default' => '31eeee7395c8', 'default' => '31eeee7395c8c78e66dd54c50addd078d10b2355',
'test_branch.latin-1' => 'c2ffe7da686a', 'test_branch.latin-1' => 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768',
'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', 'branch (1)[2]&,%.-3_4' => 'afc61e85bde74de930e5846c8451bd55b5bafc9c',
'test-branch-00' => '3a330eb32958', 'test-branch-00' => '3a330eb329586ea2adb3f83237c23310e744ebe9',
"test-branch-01" => 'ad4dc4f80284', "test-branch-01" => 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7',
@branch_char_0 => 'c8d3e4887474', @branch_char_0 => 'c8d3e4887474af6a589190140508037ebaa9d9c3',
@branch_char_1 => '7bbf4c738e71', @branch_char_1 => '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914',
} }
assert_equal bm, @adapter.branchmap assert_equal bm, @adapter.branchmap
end end
@ -378,18 +378,18 @@ begin
when 'branch (1)[2]&,%.-3_4' when 'branch (1)[2]&,%.-3_4'
if @adapter.class.client_version_above?([1, 6]) if @adapter.class.client_version_above?([1, 6])
assert_equal 3, nib0.size assert_equal 3, nib0.size
assert_equal nib0[0], 'afc61e85bde7' assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
nib2 = @adapter.nodes_in_branch(bra, :limit => 2) nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
assert_equal 2, nib2.size assert_equal 2, nib2.size
assert_equal nib2[1], '933ca60293d7' assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
end end
when @branch_char_1 when @branch_char_1
if @adapter.class.client_version_above?([1, 6]) if @adapter.class.client_version_above?([1, 6])
assert_equal 2, nib0.size assert_equal 2, nib0.size
assert_equal nib0[1], '08ff3227303e' assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
nib2 = @adapter.nodes_in_branch(bra, :limit => 1) nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
assert_equal 1, nib2.size assert_equal 1, nib2.size
assert_equal nib2[0], '7bbf4c738e71' assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
end end
end end
end end