79cd12f282663a72094316f8592e19d6b05680ce
1 """Handles the Stacked GIT configuration files
5 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from stgit
import basedir
24 class GitConfigException(Exception):
29 'stgit.autoresolved': 'no',
30 'stgit.smtpserver': 'localhost:25',
31 'stgit.smtpdelay': '5',
32 'stgit.pullcmd': 'git-pull',
33 'stgit.fetchcmd': 'git-fetch',
34 'stgit.pull-policy': 'pull',
35 'stgit.merger': 'diff3 -L current -L ancestor -L patched -m -E ' \
36 '"%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s"',
37 'stgit.autoimerge': 'no',
38 'stgit.keeporig': 'yes',
39 'stgit.keepoptimized': 'no',
40 'stgit.extensions': '.ancestor .current .patched',
46 def __run(self
, cmd
, args
=None):
47 """__run: runs cmd using spawnvp.
49 Runs cmd using spawnvp. The shell is avoided so it won't mess up
50 our arguments. If args is very large, the command is run multiple
51 times; args is split xargs style: cmd is passed on each
52 invocation. Unlike xargs, returns immediately if any non-zero
53 return code is received.
59 for i
in range(0, len(args
)+1, 100):
60 r
=os
.spawnvp(os
.P_WAIT
, args_l
[0], args_l
+ args
[i
:min(i
+100, len(args
))])
66 if self
.__cache
.has_key(name
):
67 return self
.__cache
[name
]
69 stream
= os
.popen('git repo-config --get %s' % name
, 'r')
70 value
= stream
.readline().strip()
74 elif (self
.__defaults
.has_key(name
)):
75 value
= self
.__defaults
[name
]
79 self
.__cache
[name
] = value
82 def getall(self
, name
):
83 if self
.__cache
.has_key(name
):
84 return self
.__cache
[name
]
86 stream
= os
.popen('git repo-config --get-all %s' % name
, 'r')
87 values
= [line
.strip() for line
in stream
]
90 self
.__cache
[name
] = values
93 def getint(self
, name
):
94 value
= self
.get(name
)
98 raise GitConfigException
, 'Value for "%s" is not an integer: "%s"' %
(name
, value
)
100 def rename_section(self
, from_name
, to_name
):
101 self
.__run('git-repo-config --rename-section', [from_name
, to_name
])
103 def set(self
, name
, value
):
104 self
.__run('git-repo-config', [name
, value
])
106 def unset(self
, name
):
107 self
.__run('git-repo-config --unset', [name
])
109 def sections_matching(self
, regexp
):
110 """Takes a regexp with a single group, matches it against all
111 config variables, and returns a list whose members are the
112 group contents, for all variable names matching the regexp.
115 stream
= os
.popen('git repo-config --get-regexp "^%s$"' % regexp
, 'r')
117 m
= re
.match('^%s ' % regexp
, line
)
119 result
.append(m
.group(1))
128 # Set the PAGER environment to the config value (if any)
129 pager
= config
.get('stgit.pager')
131 os
.environ
['PAGER'] = pager
132 # FIXME: handle EDITOR the same way ?
135 """Delayed cached reading of a configuration option.
137 def __init__(self
, section
, option
):
138 self
.__section
= section
139 self
.__option
= option
144 self
.__value
= config
.get(self
.__section
+ '.' + self
.__option
)
151 def file_extensions():
152 """Returns a dictionary with the conflict file extensions
157 cfg_ext
= config
.get('stgit.extensions').split()
158 if len(cfg_ext
) != 3:
159 raise CmdException
, '"extensions" configuration error'
161 __extensions
= { 'ancestor': cfg_ext
[0],
162 'current': cfg_ext
[1],
163 'patched': cfg_ext
[2] }