Commit 630b98b9 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Merge from heptapod into release branch

--HG--
branch : heptapod-0-13
......@@ -86,22 +86,18 @@ def backup_hg_repo(project)
FileUtils.mkdir_p(path_to_hg_tars(project))
# Backup the hg config and necessary caches
# In Heptapod 0.12, we won't need to backup the `.hg/git`,
# In Heptapod 0.12, we don't need to backup the `.hg/git`,
# which is the only binary (platform dependent) thing we have here
output, status = Gitlab::Popen.popen(
['tar',
cmd = ['tar',
'-cf', path_to_hg_tars(project, "config-and-cache"),
'-C', path_to_hg_repo,
'--ignore-failed-read',
'.hg/hgrc',
'.hg/hgrc.managed',
'.hg/git-mapfile',
'.hg/git/'
])
unless status.zero?
progress_warn(project, cmd.join(' '), output)
end
]
output, status = Gitlab::Popen.popen(cmd)
progress_warn(project, cmd.join(' '), output) unless status.zero?
# Backup the hg repository itself
cmd = [hg_exe, "-R", path_to_hg_repo,
......
......@@ -284,22 +284,28 @@ def hg_commit(path, username, message, env, add_remove = false)
# `update_rev`: revision to update the new working directoy to
#
# returns path to the working directory
def hg_new_workdir(update_rev)
def hg_tmp_workdir(update_rev)
share_path = @hgpath + "tmp" + SecureRandom.hex
hg_exe = Gitlab.config.mercurial.bin_path
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
output, status = popen([hg_exe, 'share',
@hgpath, share_path,
'--noupdate', '--bookmarks'],
nil, env)
raise HgError, "Could not share repo at #{@hgpath} to #{share_path}: #{output}" if status != 0
unless update_rev.nil?
output, status = popen([hg_exe, 'up', update_rev], share_path, env)
raise HgError, "Could not update shared repo to #{update_rev}: #{output}" if status != 0
begin
hg_exe = Gitlab.config.mercurial.bin_path
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
output, status = popen([hg_exe, 'share',
@hgpath, share_path,
'--noupdate', '--bookmarks'],
nil, env)
raise HgError, "Could not share repo at #{@hgpath} to #{share_path}: #{output}" if status != 0
unless update_rev.nil?
output, status = popen([hg_exe, 'up', update_rev], share_path, env)
raise HgError, "Could not update shared repo to #{update_rev}: #{output}" if status != 0
end
yield share_path
ensure
FileUtils.rm_rf(share_path)
end
share_path
end
# Produce a Mercurial merge changeset
......@@ -323,9 +329,7 @@ def hg_merge_changeset(user, source_hgsha, target_hgsha, message,
hg_env_for_write(user)
end
share_path = nil
begin
share_path = hg_new_workdir(target_hgsha)
hg_tmp_workdir(target_hgsha) do |share_path|
logger.info("#{logprefix} calling #{hg_exe} merge -r #{source_hgsha}")
output, status = popen([hg_exe, 'merge',
'-t', 'internal:merge3',
......@@ -343,10 +347,8 @@ def hg_merge_changeset(user, source_hgsha, target_hgsha, message,
username = hg_prepare_user_encoding(hg_env, user, message)
commit_hgsha = hg_commit(share_path, username, message, hg_env)
logger.info("#{logprefix} merge done, final changeset is #{commit_hgsha}")
ensure
FileUtils.rm_rf(share_path) unless share_path.nil?
commit_hgsha
end
commit_hgsha
end
def merge(user, source_sha, target_branch, message)
......@@ -489,16 +491,13 @@ def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:)
end_hgsha = hgsha_from_sha(end_sha)
username = hg_prepare_user_encoding(hg_env, author, message)
share_path = nil
begin
hg_tmp_workdir(nil) do |share_path|
# TODO: gracinet not 100% sure we need a workdir, but I don't see
# an explicit "inmemory" option as there is for `hg rebase`
# If we update to target_hgsha, then the fold will look like
# an extra head and be rejected (probably because it is kept active by being the
# working dir parent). Let's not update anywhere.
share_path = hg_new_workdir(nil)
revset = "ancestor(#{start_hgsha}, #{end_hgsha})::#{end_hgsha} "\
"- ancestor(#{start_hgsha}, #{end_hgsha})"
logger.info("#{logprefix} calling `hg squash --exact` "\
......@@ -535,8 +534,6 @@ def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:)
hg_git_invalidate_maps!
sha_from_hgsha(squash_hgsha)
ensure
FileUtils.rm_rf(share_path) unless share_path.nil?
end
end
......@@ -628,16 +625,14 @@ def multi_action(user, branch_name:, message:, actions:,
start_branch_name ||= branch_name
share_path = nil
begin
start_hg_branch, start_topic = parse_gitlab_branch_for_hg(start_branch_name)
# using the branchmap notation to perform just one update
start_hg = if empty?
nil
else
hg_branchmap_branch(start_hg_branch, start_topic)
end
share_path = hg_new_workdir(start_hg)
start_hg_branch, start_topic = parse_gitlab_branch_for_hg(start_branch_name)
# using the branchmap notation to perform just one update
start_hg = if empty?
nil
else
hg_branchmap_branch(start_hg_branch, start_topic)
end
commit_hgsha = hg_tmp_workdir(start_hg) do |share_path|
hg_branch, topic = parse_gitlab_branch_for_hg(branch_name)
if hg_branch != start_hg_branch
......@@ -755,8 +750,7 @@ def multi_action(user, branch_name:, message:, actions:,
publish = ['yes', 'true', 'on', '1'].include?(publish_str.downcase.strip)
hg_changeset_publish(user, commit_hgsha) if publish
end
ensure
FileUtils.rm_rf(share_path) unless share_path.nil?
commit_hgsha
end
hg_git_invalidate_maps!
commit_gitsha = sha_from_hgsha commit_hgsha
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment