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

Rebase: honouring rebase_in_progress?

We name the temporary working directory according to the given
rebase_id and the question whether it's in progress boils down
to the workdir being there.

Ideally, some other kind of persistent storage should be used
immediately, but we can use this as a better approximation for
the time being. In upstream GitLab, this is handled by Gitaly,
whose rebase RPC call receives the `rebase_id` and then answers
the question. Later on HGitaly will do the same.

--HG--
branch : heptapod
parent 5f6de060df79
......@@ -276,16 +276,26 @@ def hg_commit(path, username, message, env, add_remove = false)
hgsha_from_rev('.', path)
end
def has_tmp_workdir?(prefix)
!Dir.glob("#{@hgpath}tmp-#{prefix}-*").empty?
end
# Create an independent working directory
#
# this relies onto `hg share`, of which that's one of the main use
# cases.
#
# `update_rev`: revision to update the new working directoy to
# `prefix`: optional prefix used to check if a share is present
# for a given operation.
#
# returns path to the working directory
def hg_tmp_workdir(update_rev)
share_path = @hgpath + "tmp" + SecureRandom.hex
def hg_tmp_workdir(update_rev, prefix: nil)
share_path = @hgpath + "tmp"
unless prefix.nil?
share_path += "-" + prefix + '-'
end
share_path += SecureRandom.hex
begin
hg_exe = Gitlab.config.mercurial.bin_path
......@@ -593,7 +603,8 @@ def rebase(user, rebase_id, branch:, branch_sha:,
# we get by refusing instabilities
# topic naming rules make sure that we need no escaping
revset = "topic(#{topic}) and ::#{end_hgsha}"
rebase_hgsha = hg_tmp_workdir(nil) do |share_path|
rebase_hgsha =
hg_tmp_workdir(nil, prefix: "rebase-#{rebase_id}") do |share_path|
# TODO would be nice to experiment with in-memory rebase (wouldn't
# need a working dir) but not sure what the good use cases are.
# For instance, is a small rebase on a big repo much more efficient
......@@ -641,7 +652,7 @@ def rebase(user, rebase_id, branch:, branch_sha:,
# first approx, but it'd be better to have a way to tell
# TODO use rebase_id in tmp workdir name (same for squash)
def rebase_in_progress?(rebase_id)
false
has_tmp_workdir?("rebase-#{rebase_id}")
end
# Pull a given revision from URL forcing topic on all new changesets
......
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