Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Manuel Rüger" <mrueg@g.o>
Subject: [gentoo-portage-dev] [PATCH] GitSync: Support setting environment variables for git
Date: Mon, 05 Jun 2017 08:40:32
Message-Id: 20170605084008.31234-1-zmedico@gentoo.org
1 From: Manuel Rüger <mrueg@g.o>
2
3 This can be used to provide private SSH keys to portage in order to
4 clone repositories from a non-public repository.
5
6 An exemplary usage would be setting this in the repositories' repos.conf:
7 sync-git-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=false
8 sync-git-pull-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=true
9 sync-git-clone-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=true
10 ---
11 man/portage.5 | 24 +++++++++++++++++++++++-
12 pym/portage/sync/modules/git/__init__.py | 5 ++++-
13 pym/portage/sync/modules/git/git.py | 24 ++++++++++++++++++++++--
14 3 files changed, 49 insertions(+), 4 deletions(-)
15
16 diff --git a/man/portage.5 b/man/portage.5
17 index 366a1fa85..5f1f2bbb0 100644
18 --- a/man/portage.5
19 +++ b/man/portage.5
20 @@ -1,4 +1,4 @@
21 -.TH "PORTAGE" "5" "Jan 2017" "Portage VERSION" "Portage"
22 +.TH "PORTAGE" "31" "May 2017" "Portage VERSION" "Portage"
23 .SH NAME
24 portage \- the heart of Gentoo
25 .SH "DESCRIPTION"
26 @@ -979,9 +979,31 @@ Specifies CVS repository.
27 .B sync\-depth
28 This is a deprecated alias for the \fBclone\-depth\fR option.
29 .TP
30 +.B sync\-git\-clone\-env
31 +Set environment variables for git when cloning repository (git clone).
32 +This will override settings from sync-git-env.
33 +.RS
34 +.TP
35 +.I Example:
36 +sync-git-clone-env="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
37 +.br
38 +Gives three variables "VAR1", "VAR2", "VAR3" with the values "word1 word2",
39 +"word3", "$word 5 6".
40 +.RE
41 +.TP
42 .B sync\-git\-clone\-extra\-opts
43 Extra options to give to git when cloning repository (git clone).
44 .TP
45 +.B sync\-git\-env
46 +Set environment variables for git when cloning or pulling the repository.
47 +These will be overridden by setting them again in sync-git-clone-env and sync-git-pull-env.
48 +See also example for sync-git-clone-env.
49 +.TP
50 +.B sync\-git\-pull\-env
51 +Set environment variables for git when updating repository (git pull).
52 +This will override settings from sync-git-env.
53 +See also example for sync-git-clone-env.
54 +.TP
55 .B sync\-git\-pull\-extra\-opts
56 Extra options to give to git when updating repository (git pull).
57 .TP
58 diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py
59 index 60b7395b8..e7206e12d 100644
60 --- a/pym/portage/sync/modules/git/__init__.py
61 +++ b/pym/portage/sync/modules/git/__init__.py
62 @@ -1,4 +1,4 @@
63 -# Copyright 2014 Gentoo Foundation
64 +# Copyright 2014-2017 Gentoo Foundation
65 # Distributed under the terms of the GNU General Public License v2
66
67 doc = """Git plug-in module for portage.
68 @@ -52,7 +52,10 @@ module_spec = {
69 },
70 'validate_config': CheckGitConfig,
71 'module_specific_options': (
72 + 'sync-git-clone-env',
73 'sync-git-clone-extra-opts',
74 + 'sync-git-env',
75 + 'sync-git-pull-env',
76 'sync-git-pull-extra-opts',
77 ),
78 }
79 diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
80 index d432886dd..bea79c7e7 100644
81 --- a/pym/portage/sync/modules/git/git.py
82 +++ b/pym/portage/sync/modules/git/git.py
83 @@ -1,4 +1,4 @@
84 -# Copyright 2005-2015 Gentoo Foundation
85 +# Copyright 2005-2017 Gentoo Foundation
86 # Distributed under the terms of the GNU General Public License v2
87
88 import logging
89 @@ -6,7 +6,7 @@ import subprocess
90
91 import portage
92 from portage import os
93 -from portage.util import writemsg_level
94 +from portage.util import writemsg_level, shlex_split
95 from portage.output import create_color_func
96 good = create_color_func("GOOD")
97 bad = create_color_func("BAD")
98 @@ -50,6 +50,16 @@ class GitSync(NewBase):
99 sync_uri = sync_uri[6:]
100
101 git_cmd_opts = ""
102 + if self.repo.module_specific_options.get('sync-git-env'):
103 + shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-env'])
104 + env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k)
105 + self.spawn_kwargs['env'].update(env)
106 +
107 + if self.repo.module_specific_options.get('sync-git-clone-env'):
108 + shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-clone-env'])
109 + clone_env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k)
110 + self.spawn_kwargs['env'].update(clone_env)
111 +
112 if self.settings.get("PORTAGE_QUIET") == "1":
113 git_cmd_opts += " --quiet"
114 if self.repo.clone_depth is not None:
115 @@ -86,6 +96,16 @@ class GitSync(NewBase):
116 '''
117
118 git_cmd_opts = ""
119 + if self.repo.module_specific_options.get('sync-git-env'):
120 + shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-env'])
121 + env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k)
122 + self.spawn_kwargs['env'].update(env)
123 +
124 + if self.repo.module_specific_options.get('sync-git-pull-env'):
125 + shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-pull-env'])
126 + pull_env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k)
127 + self.spawn_kwargs['env'].update(pull_env)
128 +
129 if self.settings.get("PORTAGE_QUIET") == "1":
130 git_cmd_opts += " --quiet"
131 if self.repo.module_specific_options.get('sync-git-pull-extra-opts'):
132 --
133 2.13.0

Replies