Commit b5d47920 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Mercurial: reduce code duplication in branchmap key logic

This is essentially promoting `HgGitRepository#hg_branchmap_branch`,
as the proper base for `Mercurial.branchmap_key_for_gitlab_branch`.
It can also turn out to be useful elsewhere.

--HG--
branch : heptapod
parent 5cb8d73d6e30
......@@ -26,20 +26,27 @@ def parse_gitlab_branch_for_hg(gitlab_branch)
end
end
# Convert GitLab branch to corresponding branchmap key
#
# Provide branchmap key for named branch and topic
# Branchmap keys are displayed when using `hg heads`, and can
# be used directly for some operations, notably to address remote
# revisions.
def branchmap_key_for_gitlab_branch(gitlab_branch)
branch, topic = self.parse_gitlab_branch_for_hg(gitlab_branch)
def branchmap_key(hg_branch, topic)
if topic.nil?
branch
hg_branch
else
"#{branch}:#{topic}"
"#{hg_branch}:#{topic}"
end
end
# Convert GitLab branch to corresponding branchmap key
#
# Branchmap keys are displayed when using `hg heads`, and can
# be used directly for some operations, notably to address remote
# revisions.
def branchmap_key_for_gitlab_branch(gitlab_branch)
self.branchmap_key(*self.parse_gitlab_branch_for_hg(gitlab_branch))
end
def parse_hg_archival(lines)
arch = {}
lines.each do |l|
......
......@@ -369,14 +369,6 @@ def hg_changeset_branch(hgsha)
out.strip
end
def hg_branchmap_branch(hg_branch, topic)
if topic.nil?
hg_branch
else
"#{hg_branch}:#{topic}"
end
end
# Return a suitable environment for write operations (merge etc.)
#
# This method assumes that write permission is already granted,
......@@ -1067,7 +1059,8 @@ def multi_action(user, branch_name:, message:, actions:,
start_hg = if empty?
nil
else
hg_branchmap_branch(start_hg_branch, start_topic)
Gitlab::Mercurial::branchmap_key(start_hg_branch,
start_topic)
end
commit_hgsha = hg_tmp_workdir(start_hg) do |share_path|
......
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