Gentoo Archives: gentoo-portage-dev

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

Replies