From f841ca48c150e8a62728c5875fb01dcf7c5756a7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 18 Feb 2020 21:31:51 -0500 Subject: [PATCH] git_config: add support for repo-specific settings This allows people to write ~/.repoconfig/config akin to ~/.gitconfig and .repo/config akin to .git/config. This allows us to add settings specific to repo without mixing up git, and to persist in general. Change-Id: I1c6fbe31e63fb8ce26aa85335349c6ae5b1712c6 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255832 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- docs/internal-fs-layout.md | 7 +++++++ git_config.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md index 9e724e7..0b6c470 100644 --- a/docs/internal-fs-layout.md +++ b/docs/internal-fs-layout.md @@ -23,6 +23,10 @@ It is always safe to re-run `repo init` in existing repo client checkouts. For example, if you want to change the manifest branch, you can simply run `repo init --manifest-branch=` and repo will take care of the rest. +* `config`: Per-repo client checkout settings using [git-config] file format. +* `.repo_config.json`: JSON cache of the `config` file for repo to + read/process quickly. + ### repo/ state * `repo/`: A git checkout of the repo project. This is how `repo` re-execs @@ -198,12 +202,15 @@ The `[branch]` settings are updated by `repo start` and `git branch`. Repo will create & maintain a few files in the user's home directory. * `.repoconfig/`: Repo's per-user directory for all random config files/state. +* `.repoconfig/config`: Per-user settings using [git-config] file format. * `.repoconfig/keyring-version`: Cache file for checking if the gnupg subdir has all the same keys as the repo launcher. Used to avoid running gpg constantly as that can be quite slow. * `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs to run `gpg`. This provides isolation from the user's normal `~/.gnupg/`. +* `.repoconfig/.repo_config.json`: JSON cache of the `.repoconfig/config` + file for repo to read/process quickly. * `.repo_.gitconfig.json`: JSON cache of the `.gitconfig` file for repo to read/process quickly. diff --git a/git_config.py b/git_config.py index 6b1f710..8c4efac 100644 --- a/git_config.py +++ b/git_config.py @@ -88,10 +88,12 @@ def _key(name): class GitConfig(object): _ForUser = None + _USER_CONFIG = '~/.gitconfig' + @classmethod def ForUser(cls): if cls._ForUser is None: - cls._ForUser = cls(configfile=os.path.expanduser('~/.gitconfig')) + cls._ForUser = cls(configfile=os.path.expanduser(cls._USER_CONFIG)) return cls._ForUser @classmethod @@ -373,6 +375,12 @@ class GitConfig(object): GitError('git config %s: %s' % (str(args), p.stderr)) +class RepoConfig(GitConfig): + """User settings for repo itself.""" + + _USER_CONFIG = '~/.repoconfig/config' + + class RefSpec(object): """A Git refspec line, split into its components: