Skip to content
Snippets Groups Projects
Commit 773d872a authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

Move `os.environ` manipulation to pre_cleanup

Simply initializing a loader would empty the environment, which can
cause seemingly unrelated things to break. Moving the environment
handling to the `pre_cleanup` phase ensures that `cleanup` will also
be called and the environment will not be left in a broken state.

We also add the `HGRCSKIPREPO` variable that I forgot to add in the
test environment. This is still needed because the tests invoke
`hg` directly. We could potentially have a wrapper util that uses a
context-manager to do the environment manipulation closer to the issue,
but we'd have to make sure that no other bare `hg` invocations can
happen, even in random subprocesses.
parent 88847148
No related branches found
No related tags found
No related merge requests found
......@@ -167,10 +167,6 @@ class HgLoaderFromDisk(BaseLoader):
# If set, will override the default value
self._visit_status = None
self.old_environ = os.environ.copy()
os.environ.clear()
os.environ.update(get_minimum_env())
def pre_cleanup(self) -> None:
"""As a first step, will try and check for dangling data to cleanup.
This should do its best to avoid raising issues.
......@@ -182,6 +178,10 @@ class HgLoaderFromDisk(BaseLoader):
log=self.log,
)
self.old_environ = os.environ.copy()
os.environ.clear()
os.environ.update(get_minimum_env())
def cleanup(self) -> None:
"""Last step executed by the loader."""
os.environ.clear()
......
......@@ -47,3 +47,4 @@ def swh_mercurial_set_plain():
"""
os.environ["HGPLAIN"] = ""
os.environ["HGRCPATH"] = ""
os.environ["HGRCSKIPREPO"] = ""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment