This instance will be upgraded to Heptapod 0.23.2 on 2021-08-05 at 11:00 UTC+2 (a few minutes of down time)

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

HgGitRepository: factorized minimal environ for hg

Wanted to do this a long time ago, much more comfortable
with this now that we have extensive tests.

Will be needed to add `HGMODULEPOLICY` to the game

--HG--
branch : heptapod
parent eac0a704e209
......@@ -9,8 +9,8 @@ module Mercurial
BookmarksUnsupportedError = Class.new(StandardError)
class << self
# Suitable value for HGRCPATH so that structural and default settings
# are loaded and an application wide can override them.
# Application-wide HGRC files, in a suitable form for the HGRCPATH
# environment variable.
def hgrc_path
Gitlab.config.mercurial.hgrc.join(":")
end
......
......@@ -74,11 +74,9 @@ def hg_full_path
end
def hg_config_item_bool?(full_dotted_name)
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
val_str, status = popen(
[Gitlab.config.mercurial.bin_path,
'config', full_dotted_name],
@hgpath, env)
[Gitlab.config.mercurial.bin_path, 'config', full_dotted_name],
@hgpath, hg_env_minimal)
return false if status == 1 # status 1 means value is missing
raise HgError, "Could not read `#{full_dotted_name}` config item for #{@hgpath}" unless status == 0
......@@ -107,13 +105,12 @@ def create_hg_repository(namespace_fs_path:, in_subgroup:)
"in_subgroup: #{in_subgroup}")
begin
out, status = popen(
[Gitlab.config.mercurial.bin_path, "init", @hgpath],
# Rails.root can be a Mercurial repo, that can lead to
# complications. Let's run from a path that's very unlikely
# to be one:
@hg_storage_root,
{ 'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
})
[Gitlab.config.mercurial.bin_path, "init", @hgpath],
# Rails.root can be a Mercurial repo, that can lead to
# complications. Let's run from a path that's very unlikely
# to be one:
@hg_storage_root, hg_env_minimal)
if status != 0
raise HgError, "Could not execute `hg init` for #{@hgpath}: #{out}"
end
......@@ -149,10 +146,9 @@ def import_repository(url, **create_args)
create_repository(**create_args)
hg_exe = Gitlab.config.mercurial.bin_path
hg_env = {'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes',
'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
}
hg_env = hg_env_minimal
hg_env.update({ 'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes' })
Rails.logger.info("#{logprefix} Pulling")
pid = Process.spawn(hg_env,
hg_exe, "pull", "-q",
......@@ -193,10 +189,9 @@ def import_repository(url, **create_args)
#
# See heptapod#192 for details about implications of various options
def hg_optim
hg_env = {'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes',
'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
}
hg_env = hg_env_minimal
hg_env.update({ 'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes' })
output, status = popen(
[Gitlab.config.mercurial.bin_path,
"debugupgraderepo",
......@@ -212,10 +207,9 @@ def hg_optim
# Run `hg recover`.
# This is idempotent and reasonably fast if there's nothing to recover
def hg_recover
hg_env = {'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes',
'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
}
hg_env = hg_env_minimal
hg_env.update({ 'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes' })
output, status = popen(
[Gitlab.config.mercurial.bin_path,
"recover",
......@@ -358,18 +352,17 @@ def hg_git_invalidate_maps!
# obtained through `hg share`, hence taking advantage of working dir
# revisions (`.`)
def hgsha_from_rev(hgrev, path = nil)
hg_env = {'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
}
path = @hgpath if path.nil?
sha, status = popen([Gitlab.config.mercurial.bin_path,
'log', '--limit', '1', '-r', hgrev,
'-T', '{node}'],
path, hg_env)
path, hg_env_minimal)
if status != 0
raise HgRevisionError,
"Could not find changeset #{hgrev} in #{@hgpath}"
end
sha
end
......@@ -378,14 +371,19 @@ def hg_changeset_branch(hgsha)
out, status = popen([Gitlab.config.mercurial.bin_path,
'log', '-r', hgsha, '-T', '{branch}'],
@hgpath,
{'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
})
hg_env_minimal)
if status != 0
raise HgError, "Could not get hg branch of changeset #{hgsha}: #{out}"
end
out.strip
end
def hg_env_minimal
{ 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
end
# Return a suitable environment for write operations (merge etc.)
#
# This method assumes that write permission is already granted,
......@@ -399,7 +397,8 @@ def hg_env_for_write(user, force_system_user: false)
"without force_system_user flag"
end
env = {
env = hg_env_minimal
env.update({
# `name` and `email` are as in `committer` (which
# does not have `username`) but the purpose here is
# different: we want to pass them
......@@ -414,9 +413,8 @@ def hg_env_for_write(user, force_system_user: false)
'HEPTAPOD_USERINFO_EMAIL' => user&.email,
'HEPTAPOD_HG_NATIVE' => 'no',
'GL_REPOSITORY' => @gl_repository,
'HGUSER' => nil,
'HGRCPATH' => Gitlab::Mercurial.hgrc_path
}
'HGUSER' => nil
})
unless @hg_project_for_perms.nil?
env.update(
......@@ -505,7 +503,7 @@ def hg_call(args, user, path, env: nil, for_write: false,
if for_write
env = hg_env_for_write(user, force_system_user: force_system_user)
else
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
env = hg_env_minimal
end
end
username = hg_prepare_user_encoding(env, user, "")
......@@ -638,7 +636,7 @@ def hg_tmp_workdir(update_rev, prefix: nil)
begin
hg_exe = Gitlab.config.mercurial.bin_path
env = { 'HGRCPATH' => Gitlab::Mercurial.hgrc_path }
env = hg_env_minimal
output, status = popen([hg_exe, 'share',
@hgpath, share_path,
'--noupdate', '--bookmarks'],
......@@ -686,8 +684,7 @@ def hg_merge_changeset(user, source_hgsha, target_hgsha, message,
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 }
hg_env_minimal
else
hg_env_for_write(user)
end
......@@ -1101,10 +1098,9 @@ def rebase_in_progress?(rebase_id)
def pull_force_topic(url, hgsha, topic)
# necessary to amend changesets
# TODO do better and think of encoding, as well
hg_env = {'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes',
'HGRCPATH' => Gitlab::Mercurial.hgrc_path,
}
hg_env = hg_env_minimal
hg_env.update({ 'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes' })
hg_exe = Gitlab.config.mercurial.bin_path
_output, status = popen(
[hg_exe,
......@@ -1474,10 +1470,12 @@ def rpath_to_namespace_if_hgrc_included(new_disk_path)
HG_CONFIG_TRUE = ["1", "yes", "true", "on"].freeze
def get_hg_heptapod_config(local: false)
hg_env = {'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes',
'HGRCPATH' => local ? "" : Gitlab::Mercurial.hgrc_path,
}
hg_env = hg_env_minimal
hg_env.update({ 'HGUSER' => 'Heptapod system',
'HEPTAPOD_SKIP_ALL_GITLAB_HOOKS' => 'yes' })
del hg_env['HGRCPATH'] if local
hg_exe = Gitlab.config.mercurial.bin_path
out, status = popen([hg_exe, 'config', 'heptapod'],
@hgpath, hg_env)
......
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