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
21 import os
, ConfigParser
22 from StringIO
import StringIO
23 from stgit
import basedir
25 config
= ConfigParser
.RawConfigParser()
27 def git_config(filename
):
28 """Open a git config file and convert it to be understood by
38 # continued line, add a space at the beginning
41 if line
and line
[-1] == '\\':
42 line
= line
[:-1].rstrip()
51 cfg_str
= ''.join(lines
)
55 strio
= StringIO(cfg_str
)
64 config
.add_section('stgit')
65 config
.set('stgit', 'autoresolved', 'no')
66 config
.set('stgit', 'smtpserver', 'localhost:25')
67 config
.set('stgit', 'smtpdelay', '5')
68 config
.set('stgit', 'pullcmd', 'git-pull')
69 config
.set('stgit', 'merger',
70 'diff3 -L current -L ancestor -L patched -m -E ' \
71 '"%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s"')
72 config
.set('stgit', 'keeporig', 'yes')
73 config
.set('stgit', 'keepoptimized', 'no')
74 config
.set('stgit', 'extensions', '.ancestor .current .patched')
76 # Read the configuration files (if any) and override the default settings
77 # stgitrc are read for backward compatibility
78 config
.read('/etc/stgitrc')
79 config
.read(os
.path
.expanduser('~/.stgitrc'))
80 config
.read(os
.path
.join(basedir
.get(), 'stgitrc'))
82 # GIT configuration files can have a [stgit] section
84 global_config
= os
.environ
['GIT_CONFIG']
86 global_config
= os
.path
.expanduser('~/.gitconfig')
88 local_config
= os
.environ
['GIT_CONFIG_LOCAL']
90 local_config
= os
.path
.join(basedir
.get(), 'config')
91 config
.readfp(git_config(global_config
))
92 config
.readfp(git_config(local_config
))
94 # Set the PAGER environment to the config value (if any)
95 if config
.has_option('stgit', 'pager'):
96 os
.environ
['PAGER'] = config
.get('stgit', 'pager')
98 # [gitmergeonefile] section is deprecated. In case it exists copy the
99 # options/values to the [stgit] one
100 if config
.has_section('gitmergeonefile'):
101 for option
, value
in config
.items('gitmergeonefile'):
102 config
.set('stgit', option
, value
)
106 """Delayed cached reading of a configuration option.
108 def __init__(self
, section
, option
):
109 self
.__section
= section
110 self
.__option
= option
115 self
.__value
= config
.get(self
.__section
, self
.__option
)
122 def file_extensions():
123 """Returns a dictionary with the conflict file extensions
128 cfg_ext
= config
.get('stgit', 'extensions').split()
129 if len(cfg_ext
) != 3:
130 raise CmdException
, '"extensions" configuration error'
132 __extensions
= { 'ancestor': cfg_ext
[0],
133 'current': cfg_ext
[1],
134 'patched': cfg_ext
[2] }