Content-Length: 5884 | pFad | http://github.com/gitpython-developers/GitPython/pull/950.patch
thub.com
From d8729cbabfbb8b36e39c46a3ebce255705a0ea02 Mon Sep 17 00:00:00 2001
From: Ben Thayer
Date: Wed, 23 Oct 2019 10:38:31 -0500
Subject: [PATCH 1/4] Construct GitConfigParser without Repo object
---
git/config.py | 41 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/git/config.py b/git/config.py
index edd5750bf..2464865df 100644
--- a/git/config.py
+++ b/git/config.py
@@ -20,7 +20,8 @@
defenc,
force_text,
with_metaclass,
- PY3
+ PY3,
+ is_win,
)
from git.util import LockFile
@@ -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):
@@ -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("repository configuration level not allowed")
+
+ ValueError("Invalid configuration level: %r" % config_level)
+
+
class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, object)):
"""Implements specifics required to read git style configuration files.
@@ -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
@@ -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[:-1]]
+ 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
From d6ace9c9633582ba329d7b9e73d980b9d1b17e70 Mon Sep 17 00:00:00 2001
From: Ben Thayer
Date: Wed, 23 Oct 2019 10:41:01 -0500
Subject: [PATCH 2/4] Changed ValueError
---
git/config.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git/config.py b/git/config.py
index 2464865df..257474a06 100644
--- a/git/config.py
+++ b/git/config.py
@@ -211,7 +211,7 @@ def get_config_path(config_level):
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
elif config_level == "repository":
- raise ValueError("repository configuration level not allowed")
+ raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path")
ValueError("Invalid configuration level: %r" % config_level)
From d6c44151999aefff619469174aa447b7423ebf53 Mon Sep 17 00:00:00 2001
From: Ben Thayer
Date: Wed, 23 Oct 2019 10:53:07 -0500
Subject: [PATCH 3/4] Raised final ValueError
---
git/config.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git/config.py b/git/config.py
index 257474a06..efb4c8959 100644
--- a/git/config.py
+++ b/git/config.py
@@ -213,7 +213,7 @@ def get_config_path(config_level):
elif config_level == "repository":
raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path")
- ValueError("Invalid configuration level: %r" % config_level)
+ raise ValueError("Invalid configuration level: %r" % config_level)
class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, object)):
From 91bde937f6a082f98fcfba002f7cc7c2ec5db77c Mon Sep 17 00:00:00 2001
From: Ben Thayer
Date: Thu, 24 Oct 2019 13:37:58 -0500
Subject: [PATCH 4/4] Filtered out "repository" more explicitly
---
git/config.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git/config.py b/git/config.py
index efb4c8959..762069c75 100644
--- a/git/config.py
+++ b/git/config.py
@@ -281,7 +281,7 @@ def __init__(self, file_or_files=None, read_only=True, merge_includes=True, conf
else:
if config_level is None:
if read_only:
- self._file_or_files = [get_config_path(f) for f in CONFIG_LEVELS[:-1]]
+ 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:
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/gitpython-developers/GitPython/pull/950.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy