Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Global ConfigParser#950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 4 commits intogitpython-developers:masterfrombenthayer:global_config
Oct 28, 2019
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletionsgit/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,8 @@
defenc,
force_text,
with_metaclass,
PY3
PY3,
is_win,
)
from git.util import LockFile

Expand All@@ -40,6 +41,10 @@
log = logging.getLogger('git.config')
log.addHandler(logging.NullHandler())

# invariants
# represents the configuration level of a configuration file
CONFIG_LEVELS = ("system", "user", "global", "repository")


class MetaParserBuilder(abc.ABCMeta):

Expand DownExpand Up@@ -191,6 +196,26 @@ def items_all(self):
return [(k, self.getall(k)) for k in self]


def get_config_path(config_level):

# we do not support an absolute path of the gitconfig on windows ,
# use the global config instead
if is_win and config_level == "system":
config_level = "global"

if config_level == "system":
return "/etc/gitconfig"
elif config_level == "user":
config_home = os.environ.get("XDG_CONFIG_HOME") or osp.join(os.environ.get("HOME", '~'), ".config")
return osp.normpath(osp.expanduser(osp.join(config_home, "git", "config")))
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
elif config_level == "repository":
raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path")

raise ValueError("Invalid configuration level: %r" % config_level)


class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, object)):

"""Implements specifics required to read git style configuration files.
Expand DownExpand Up@@ -229,7 +254,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
# list of RawConfigParser methods able to change the instance
_mutating_methods_ = ("add_section", "remove_section", "remove_option", "set")

def __init__(self, file_or_files, read_only=True, merge_includes=True):
def __init__(self, file_or_files=None, read_only=True, merge_includes=True, config_level=None):
"""Initialize a configuration reader to read the given file_or_files and to
possibly allow changes to it by setting read_only False

Expand All@@ -251,7 +276,17 @@ def __init__(self, file_or_files, read_only=True, merge_includes=True):
if not hasattr(self, '_proxies'):
self._proxies = self._dict()

self._file_or_files = file_or_files
if file_or_files is not None:
self._file_or_files = file_or_files
else:
if config_level is None:
if read_only:
self._file_or_files = [get_config_path(f) for f in CONFIG_LEVELS if f != 'repository']
else:
raise ValueError("No configuration level or configuration files specified")
else:
self._file_or_files = [get_config_path(config_level)]

self._read_only = read_only
self._dirty = False
self._is_initialized = False
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp