[jhbuild] [git] execute all git commands in a clean environment
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Subject: [jhbuild] [git] execute all git commands in a clean environment
- Date: Fri, 5 Jun 2009 09:42:26 -0400 (EDT)
commit 58878e003174d22d03bc9b9576651750c1c30419
Author: Frédéric Péters <fpeters 0d be>
Date: Fri Jun 5 15:37:41 2009 +0200
[git] execute all git commands in a clean environment
Run git without the JHBuild PATH and LD_LIBRARY_PATH, as it can lead to
errors if it picks up jhbuilded libraries, such as NSS.
---
jhbuild/config.py | 1 +
jhbuild/versioncontrol/git.py | 120 ++++++++++++++++++++++++++--------------
2 files changed, 79 insertions(+), 42 deletions(-)
diff --git a/jhbuild/config.py b/jhbuild/config.py
index a3ce1de..f8bc495 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -151,6 +151,7 @@ class Config:
if not self._orig_environ:
self.__dict__['_orig_environ'] = os.environ.copy()
+ os.environ['UNMANGLED_PATH'] = os.environ.get('PATH', '')
try:
SRCDIR
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 2fe42af..53c9f8e 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -50,6 +50,12 @@ if 'git+ssh' not in urlparse.uses_relative:
if 'ssh' not in urlparse.uses_relative:
urlparse.uses_relative.append('ssh')
+def get_git_extra_env():
+ # we run git without the JHBuild LD_LIBRARY_PATH, as it can lead to
+ # errors if it picks up jhbuilded libraries, such as nss
+ return { 'LD_LIBRARY_PATH': os.environ.get('UNMANGLED_LD_LIBRARY_PATH'),
+ 'PATH': os.environ.get('UNMANGLED_PATH')}
+
class GitUnknownBranchNameError(Exception):
pass
@@ -128,9 +134,11 @@ class GitBranch(Branch):
try:
cmd = ['git', 'show-ref', '--quiet', '--verify', 'refs/heads/' + branch]
if buildscript:
- buildscript.execute(cmd, cwd=self.get_checkoutdir())
+ buildscript.execute(cmd, cwd=self.get_checkoutdir(),
+ extra_env=get_git_extra_env())
else:
- get_output(cmd, cwd=self.get_checkoutdir())
+ get_output(cmd, cwd=self.get_checkoutdir(),
+ extra_env=get_git_extra_env())
except CommandError:
return False
return True
@@ -140,18 +148,21 @@ class GitBranch(Branch):
branchname = property(branchname)
def get_current_branch(self):
- for line in get_output(['git', 'branch'], cwd=self.get_checkoutdir()).splitlines():
+ for line in get_output(['git', 'branch'],
+ cwd=self.get_checkoutdir(), extra_env=get_git_extra_env()).splitlines():
if line[0] == '*':
return line[2:]
return None
def get_remote_branches_list(self):
return [x.strip() for x in get_output(['git', 'branch', '-r'],
- cwd=self.get_checkoutdir()).splitlines()]
+ cwd=self.get_checkoutdir(),
+ extra_env=get_git_extra_env()).splitlines()]
def exists(self):
try:
- refs = get_output(['git', 'ls-remote', self.module])
+ refs = get_output(['git', 'ls-remote', self.module],
+ extra_env=get_git_extra_env())
except:
return False
@@ -164,7 +175,8 @@ class GitBranch(Branch):
'--until=%s' % self.config.sticky_date]
cmd_desc = ' '.join(cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- cwd=self.get_checkoutdir())
+ cwd=self.get_checkoutdir(),
+ env=get_git_extra_env())
stdout = proc.communicate()[0]
if not stdout.strip():
raise CommandError(_('Command %s returned no output') % cmd_desc)
@@ -182,9 +194,11 @@ class GitBranch(Branch):
def _update_submodules(self, buildscript):
if os.path.exists(os.path.join(self.get_checkoutdir(), '.gitmodules')):
cmd = ['git', 'submodule', 'init']
- buildscript.execute(cmd, cwd=self.get_checkoutdir())
+ buildscript.execute(cmd, cwd=self.get_checkoutdir(),
+ extra_env=get_git_extra_env())
cmd = ['git', 'submodule', 'update']
- buildscript.execute(cmd, cwd=self.get_checkoutdir())
+ buildscript.execute(cmd, cwd=self.get_checkoutdir(),
+ extra_env=get_git_extra_env())
def update_dvcs_mirror(self, buildscript):
if not self.config.dvcs_mirror_dir:
@@ -194,11 +208,13 @@ class GitBranch(Branch):
os.path.basename(self.module) + '.git')
if os.path.exists(mirror_dir):
- buildscript.execute(['git', 'fetch'], cwd=mirror_dir)
+ buildscript.execute(['git', 'fetch'], cwd=mirror_dir,
+ extra_env=get_git_extra_env())
else:
buildscript.execute(
['git', 'clone', '--mirror', self.unmirrored_module],
- cwd=self.config.dvcs_mirror_dir)
+ cwd=self.config.dvcs_mirror_dir,
+ extra_env=get_git_extra_env())
def _checkout(self, buildscript, copydir=None):
@@ -214,15 +230,17 @@ class GitBranch(Branch):
cmd.append(self.checkoutdir)
if copydir:
- buildscript.execute(cmd, cwd=copydir)
+ buildscript.execute(cmd, cwd=copydir, extra_env=get_git_extra_env())
else:
- buildscript.execute(cmd, cwd=self.config.checkoutroot)
+ buildscript.execute(cmd, cwd=self.config.checkoutroot,
+ extra_env=get_git_extra_env())
self._update(buildscript, copydir=copydir, update_mirror=False)
def _update(self, buildscript, copydir=None, update_mirror=True):
cwd = self.get_checkoutdir()
+ git_extra_args = {'cwd': cwd, 'extra_env': get_git_extra_env()}
if not os.path.exists(os.path.join(cwd, '.git')):
if os.path.exists(os.path.join(cwd, '.svn')):
@@ -238,13 +256,14 @@ class GitBranch(Branch):
self.update_dvcs_mirror(buildscript)
stashed = False
- if get_output(['git', 'diff'], cwd=cwd):
+ if get_output(['git', 'diff'], **git_extra_args):
stashed = True
- buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'],
+ **git_extra_args)
would_be_branch = self.branch or 'master'
if self.tag:
- buildscript.execute(['git', 'checkout', self.tag], cwd=cwd)
+ buildscript.execute(['git', 'checkout', self.tag], **git_extra_args)
else:
current_branch = self.get_current_branch()
if current_branch != would_be_branch or current_branch == '(no branch)':
@@ -255,33 +274,36 @@ class GitBranch(Branch):
# a local work branch, and it won't be changed
if ('origin/' + current_branch) in self.get_remote_branches_list():
if self.local_branch_exist(would_be_branch, buildscript):
- buildscript.execute(['git', 'checkout', would_be_branch], cwd=cwd)
+ buildscript.execute(['git', 'checkout', would_be_branch],
+ **git_extra_args)
else:
buildscript.execute(['git', 'checkout', '--track', '-b',
- would_be_branch, 'origin/' + would_be_branch], cwd=cwd)
+ would_be_branch, 'origin/' + would_be_branch],
+ **git_extra_args)
current_branch = self.get_current_branch()
if current_branch != '(no branch)':
- buildscript.execute(['git', 'pull', '--rebase'], cwd=cwd)
+ buildscript.execute(['git', 'pull', '--rebase'], **git_extra_args)
if stashed:
# git stash pop was introduced in 1.5.5,
if check_version(['git', '--version'],
r'git version ([\d.]+)', '1.5.5'):
- buildscript.execute(['git', 'stash', 'pop'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'pop'], **git_extra_args)
else:
- buildscript.execute(['git', 'stash', 'apply', 'jhbuild-stash'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'apply', 'jhbuild-stash'],
+ **git_extra_args)
if self.config.sticky_date:
commit = self._get_commit_from_date()
branch = 'jhbuild-date-branch'
branch_cmd = ['git', 'checkout'] + quiet + [branch]
try:
- buildscript.execute(branch_cmd, cwd=cwd)
+ buildscript.execute(branch_cmd, **git_extra_args)
except CommandError:
branch_cmd = ['git', 'checkout'] + quiet + ['-b', branch]
- buildscript.execute(branch_cmd, cwd=cwd)
- buildscript.execute(['git', 'reset', '--hard', commit], cwd=cwd)
+ buildscript.execute(branch_cmd, **git_extra_args)
+ buildscript.execute(['git', 'reset', '--hard', commit], **git_extra_args)
self._update_submodules(buildscript)
@@ -296,7 +318,8 @@ class GitBranch(Branch):
return None
try:
output = get_output(['git', 'rev-parse', 'HEAD'],
- cwd = self.get_checkoutdir(), get_stderr=False)
+ cwd = self.get_checkoutdir(), get_stderr=False,
+ extra_env=get_git_extra_env())
except CommandError:
return None
except GitUnknownBranchNameError:
@@ -339,7 +362,8 @@ class GitSvnBranch(GitBranch):
# we couldn't find an unhandled.log to parse so try
# git svn show-externals - note this is broken in git < 1.5.6
try:
- output = get_output(['git', 'svn', 'show-externals'], cwd=cwd)
+ output = get_output(['git', 'svn', 'show-externals'], cwd=cwd,
+ extra_env=get_git_extra_env())
# we search for comment lines to strip them out
comment_line = re.compile(r"^#.*")
ext = ''
@@ -397,19 +421,23 @@ class GitSvnBranch(GitBranch):
raise FatalError(_('Cannot get last revision from %s. Check the module location.') % self.module)
if copydir:
- buildscript.execute(cmd, cwd=copydir)
+ buildscript.execute(cmd, cwd=copydir,
+ extra_env=get_git_extra_env())
else:
- buildscript.execute(cmd, cwd=self.config.checkoutroot)
+ buildscript.execute(cmd, cwd=self.config.checkoutroot,
+ extra_env=get_git_extra_env())
try:
# is known to fail on some versions
cmd = ['git', 'svn', 'show-ignore']
- s = get_output(cmd, cwd = self.get_checkoutdir(copydir))
+ s = get_output(cmd, cwd = self.get_checkoutdir(copydir),
+ extra_env=get_git_extra_env())
fd = file(os.path.join(
self.get_checkoutdir(copydir), '.git/info/exclude'), 'a')
fd.write(s)
fc.close()
- buildscript.execute(cmd, cwd=self.get_checkoutdir(copydir))
+ buildscript.execute(cmd, cwd=self.get_checkoutdir(copydir),
+ extra_env=get_git_extra_env())
except:
pass
@@ -426,28 +454,33 @@ class GitSvnBranch(GitBranch):
quiet = []
cwd = self.get_checkoutdir()
+ git_extra_args = {'cwd': cwd, 'extra_env': get_git_extra_env()}
- last_revision = get_output(['git', 'svn', 'find-rev', 'HEAD'], cwd=cwd)
+ last_revision = get_output(['git', 'svn', 'find-rev', 'HEAD'],
+ **git_extra_args)
stashed = False
- if get_output(['git', 'diff'], cwd=cwd):
+ if get_output(['git', 'diff'], **git_extra_args):
# stash uncommitted changes on the current branch
stashed = True
- buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'],
+ **git_extra_args)
- buildscript.execute(['git', 'checkout'] + quiet + ['master'], cwd=cwd)
- buildscript.execute(['git', 'svn', 'rebase'], cwd=cwd)
+ buildscript.execute(['git', 'checkout'] + quiet + ['master'],
+ **git_extra_args)
+ buildscript.execute(['git', 'svn', 'rebase'], **git_extra_args)
if stashed:
- buildscript.execute(['git', 'stash', 'pop'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'pop'], **git_extra_args)
- current_revision = get_output(['git', 'svn', 'find-rev', 'HEAD'], cwd=cwd)
+ current_revision = get_output(['git', 'svn', 'find-rev', 'HEAD'],
+ **git_extra_args)
if last_revision != current_revision:
try:
# is known to fail on some versions
cmd = "git svn show-ignore >> .git/info/exclude"
- buildscript.execute(cmd, cwd=cwd)
+ buildscript.execute(cmd, **git_extra_args)
except:
pass
@@ -479,26 +512,29 @@ class GitCvsBranch(GitBranch):
cmd.append(self.module)
if copydir:
- buildscript.execute(cmd, cwd=copydir)
+ buildscript.execute(cmd, cwd=copydir, extra_env=get_git_extra_env())
else:
- buildscript.execute(cmd, cwd=self.config.checkoutroot)
+ buildscript.execute(cmd, cwd=self.config.checkoutroot,
+ extra_env=get_git_extra_env())
def _update(self, buildscript, copydir=None):
if self.config.sticky_date:
raise FatalError(_('date based checkout not yet supported\n'))
cwd = self.get_checkoutdir()
+ git_extra_args = {'cwd': cwd, 'extra_env': get_git_extra_env()}
stashed = False
# stash uncommitted changes on the current branch
- if get_output(['git', 'diff'], cwd=cwd):
+ if get_output(['git', 'diff'], **git_extra_args):
# stash uncommitted changes on the current branch
stashed = True
- buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'],
+ **git_extra_args)
self._checkout(buildscript, copydir=copydir)
if stashed:
- buildscript.execute(['git', 'stash', 'pop'], cwd=cwd)
+ buildscript.execute(['git', 'stash', 'pop'], **git_extra_args)
register_repo_type('git', GitRepository)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]