Merge ~racb/git-ubuntu:derive-env into git-ubuntu:master

Proposed by Robie Basak
Status: Superseded
Proposed branch: ~racb/git-ubuntu:derive-env
Merge into: git-ubuntu:master
Diff against target: 80 lines (+37/-10)
1 file modified
gitubuntu/git_repository.py (+37/-10)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
git-ubuntu developers Pending
Review via email: mp+337269@code.launchpad.net

This proposal has been superseded by a proposal from 2018-02-12.

Commit message

Make Jenkins happy

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:a71ff92849ae06203ce7c2c5d7bdce355f042560
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/279/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/279/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:4d1d2bdb1d514bcf5bf0ac3e736bf88ff372dbca
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/281/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/281/rebuild

review: Approve (continuous-integration)

Unmerged commits

4d1d2bd... by Robie Basak

Replace self._env with a derived property

As part of the drive to reduce stored state to improve testability,
derive self.env when we need it instead of working out in advance in the
constructor.

This is intended to have no functional changes.

GIT_WORK_TREE will end up differently normalised now, such as in
trailing slashes, since in testing pygit2.Repository.workdir was not
normalised like this and so a normalised assertion was needed. This
should not result in any change to git's behaviour.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
2index f3bd406..d2768f8 100644
3--- a/gitubuntu/git_repository.py
4+++ b/gitubuntu/git_repository.py
5@@ -779,10 +779,24 @@ class GitUbuntuRepository:
6 self._local_dir = local_dir
7
8 self.raw_repo = pygit2.init_repository(self._local_dir)
9+ # We rely on raw_repo.workdir to be identical to self._local_dir to
10+ # avoid changing previous behaviour in the setting of GIT_WORK_TREE, so
11+ # assert that it is so. This may not be the case if the git repository
12+ # has a different workdir stored in its configuration or if the git
13+ # repository is a bare repository. We didn't handle these cases before
14+ # anyway, so with this assertion we can fail noisily and early.
15+ assert (
16+ os.path.normpath(self.raw_repo.workdir) ==
17+ os.path.normpath(self._local_dir)
18+ )
19
20- self._env = os.environ.copy()
21- self._env['GIT_DIR'] = self.raw_repo.path
22- self._env['GIT_WORK_TREE'] = self._local_dir
23+ # Since previous behaviour of this class depended on the state of the
24+ # environment at the time it was constructed, save this for later use
25+ # (for example in deriving the environment to use for calls to the git
26+ # CLI). This permits the behaviour to remain identical for now.
27+ # Eventually we can break previous behaviour and eliminate the need for
28+ # this.
29+ self._initial_env = os.environ.copy()
30
31 self.set_git_attributes()
32
33@@ -1224,7 +1238,20 @@ class GitUbuntuRepository:
34
35 @property
36 def env(self):
37- return self._env
38+ return self._derive_env()
39+
40+ @lru_cache()
41+ def _derive_env(self):
42+ """Determine what the git CLI environment should be
43+
44+ This depends on the initial environment saved from the constructor and
45+ the paths associated with self.raw_repo, neither of which should change
46+ in the lifetime of this class instance.
47+ """
48+ env = self._initial_env.copy()
49+ env['GIT_DIR'] = self.raw_repo.path
50+ env['GIT_WORK_TREE'] = self.raw_repo.workdir
51+ return env
52
53 @property
54 def local_dir(self):
55@@ -1308,9 +1335,9 @@ class GitUbuntuRepository:
56 return stdout.strip()
57
58 def git_run(self, args, env=None, **kwargs):
59- # Explicitly take a copy of self._env so the following update doesn't
60- # accidentally update the main instance _env dictionary in-place
61- combined_env = dict(self._env)
62+ # Explicitly take a copy of self.env so the following update doesn't
63+ # accidentally update the main instance env dictionary in-place
64+ combined_env = dict(self.env)
65 if env is not None:
66 combined_env.update(env)
67 return run(['git'] + args, env=combined_env, **kwargs)
68@@ -1626,9 +1653,9 @@ class GitUbuntuRepository:
69 def clean_repository_state(self):
70 """Cleanup working tree"""
71 runq(['git', 'checkout', '--orphan', 'master'],
72- check=False, env=self._env)
73- runq(['git', 'reset', '--hard'], env=self._env)
74- runq(['git', 'clean', '-f', '-d'], env=self._env)
75+ check=False, env=self.env)
76+ runq(['git', 'reset', '--hard'], env=self.env)
77+ runq(['git', 'clean', '-f', '-d'], env=self.env)
78
79 def get_all_changelog_versions_from_treeish(self, treeish):
80 changelog = self.get_changelog_from_treeish(treeish)

Subscribers

People subscribed via source and target branches