Commit 19a383fd authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

HgGitRepository: more Rubocop rules

The less underlined in Emacs, the best it will be.

--HG--
branch : heptapod
parent 7e59f88589ed
......@@ -631,28 +631,28 @@ def hg_merge_changeset(user, source_hgsha, target_hgsha, message,
logprefix += "for #{@relative_path} #{source_hgsha} into #{target_hgsha}"
logger = Rails.logger # could need to be adapted for gitaly-ruby (see initialize())
hg_exe = Gitlab.config.mercurial.bin_path
hg_env = if user.nil?
# TODO time to have a method for minimal hg_env
{'HGRCPATH' => Gitlab::Mercurial.hgrc_path}
else
hg_env_for_write(user)
end
hg_env =
if user.nil?
# TODO time to have a method for minimal hg_env
{ 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
else
hg_env_for_write(user)
end
hg_env.delete('HEPTAPOD_SKIP_ALL_GITLAB_HOOKS') unless unit_tests_skip_hooks
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',
'-r', source_hgsha
],
'-r', source_hgsha],
share_path, hg_env)
if status != 0
raise MergeError, "Could not merge hg #{source_hgsha} onto hg #{target_hgsha}: #{output}"
end
# note for non-rubyists: 'ensure' condition is still executed
# with early returns.
return if simulate
next if simulate
username = hg_prepare_user_encoding(hg_env, user, message)
commit_hgsha = hg_commit(share_path, username, message, hg_env)
......@@ -736,10 +736,12 @@ def can_be_merged?(source_sha, target_branch)
return false unless source_sha
target_sha = find_branch(target_branch)&.target
if target_sha.nil?
logger.warn("#{logprefix} could not resolve Git branch #{target_branch}")
return false
end
if ancestor?(target_sha, source_sha)
# always doable: true fast forward or merge changeset only
# involving metadata (e.g., branch change)
......@@ -749,11 +751,13 @@ def can_be_merged?(source_sha, target_branch)
source_hgsha = hgsha_from_sha(source_sha)
target_hgsha = hgsha_from_sha(target_sha)
if source_hgsha.nil?
logger.warn(
"#{logprefix} could not find Hg changeset for source Git commit #{source_sha}")
return false
end
if target_hgsha.nil?
logger.warn(
"#{logprefix} could not find Hg changeset for target Git commit #{target_sha}")
......@@ -836,24 +840,27 @@ def squash(user, squash_id, start_sha:, end_sha:, author:, message:)
# `allowunstable=no` protects us against all instabilities,
# in particular against orphaning dependent topics.
output, status = popen(
[hg_exe, 'fold', '--exact',
'-r', revset,
'-m', message,
'-u', username,
'--config', 'experimental.evolution.allowunstable=no',
],
share_path, hg_env)
[hg_exe, 'fold', '--exact',
'-r', revset,
'-m', message,
'-u', username,
'--config', 'experimental.evolution.allowunstable=no'],
share_path, hg_env)
if status != 0
raise HgError, "Could not fold revset `#{revset}` Error: #{output}"
end
logger.info("#{logprefix} squash done, finding successor")
output, status = popen(
[hg_exe, 'hpd-unique-successor', '-r', end_hgsha],
share_path, hg_env)
[hg_exe, 'hpd-unique-successor', '-r', end_hgsha],
share_path, hg_env)
if status != 0
raise HgError, "Could not retrieve folded changeset "\
"(successor of #{end_hgsha})"
end
squash_hgsha = output.strip
logger.info("#{logprefix} squash successor changeset #{squash_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