diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 15:04:04 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-19 15:04:04 +0200 |
commit | 8f42db54c6b2cfbd7d68e6d34ac2ed70578402f7 (patch) | |
tree | 1a0ce488e628df94f61048e1e9c691c59a83e867 /lib/git/repo.py | |
parent | 657a57adbff49c553752254c106ce1d5b5690cf8 (diff) | |
parent | 26029c29765043376370a2877b7e635c17f5e76d (diff) | |
download | gitpython-8f42db54c6b2cfbd7d68e6d34ac2ed70578402f7.tar.gz |
Merge branch 'config' into improvements
* config:
added additional testing for the configuration, concurrent access and config reading, all tests work
implemented config class as far as necessary, one check is still failing
Added frame for configuration reader involving a meta class, decorators and tests - most of which still has to be filled out
Diffstat (limited to 'lib/git/repo.py')
-rw-r--r-- | lib/git/repo.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py index cc4a6c6b..c53a4d9b 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -5,6 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os +import sys import re import gzip import StringIO @@ -15,7 +16,7 @@ from cmd import Git from actor import Actor from refs import * from objects import * - +from config import GitConfigParser class Repo(object): """ @@ -30,6 +31,10 @@ class Repo(object): re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') re_author_committer_start = re.compile(r'^(author|committer)') re_tab_full_line = re.compile(r'^\t(.*)$') + + # invariants + # represents the configuration level of a configuration file + config_level = ("system", "global", "repository") def __init__(self, path=None): """ @@ -125,6 +130,52 @@ class Repo(object): """ return Tag.list_items(self) + def _get_config_path(self, config_level ): + # we do not support an absolute path of the gitconfig on windows , + # use the global config instead + if sys.platform == "win32" and config_level == "system": + config_level = "global" + + if config_level == "system": + return "/etc/gitconfig" + elif config_level == "global": + return os.path.expanduser("~/.gitconfig") + elif config_level == "repository": + return "%s/config" % self.git.git_dir + + raise ValueError( "Invalid configuration level: %r" % config_level ) + + @property + def config_reader(self): + """ + Returns + GitConfigParser allowing to read the full git configuration, but not to write it + + The configuration will include values from the system, user and repository + configuration files. + + NOTE: On windows, system configuration cannot currently be read as the path is + unknown, instead the global path will be used. + """ + files = [ self._get_config_path(f) for f in self.config_level ] + return GitConfigParser(files, read_only=True) + + def config_writer(self, config_level="repository"): + """ + Returns + GitConfigParser allowing to write values of the specified configuration file level. + Config writers should be retrieved, used to change the configuration ,and written + right away as they will lock the configuration file in question and prevent other's + to write it. + + ``config_level`` + One of the following values + system = sytem wide configuration file + global = user level configuration file + repository = configuration file for this repostory only + """ + return GitConfigParser(self._get_config_path(config_level), read_only = False) + def commit(self, rev=None): """ The Commit object for the specified revision |