diff options
author | Mike Frysinger <vapier@google.com> | 2020-02-18 21:31:51 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-02-20 00:53:39 +0000 |
commit | f841ca48c150e8a62728c5875fb01dcf7c5756a7 (patch) | |
tree | 29983898948da9ada7ea80dd33386cf643fa4c1b | |
parent | c0d1866b35d3e8d0bee3760a9f52574fa2ab8491 (diff) | |
download | git-repo-f841ca48c150e8a62728c5875fb01dcf7c5756a7.tar.gz |
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 <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | docs/internal-fs-layout.md | 7 | ||||
-rw-r--r-- | git_config.py | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md index 9e724e7b..0b6c4709 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. | |||
23 | For example, if you want to change the manifest branch, you can simply run | 23 | For example, if you want to change the manifest branch, you can simply run |
24 | `repo init --manifest-branch=<new name>` and repo will take care of the rest. | 24 | `repo init --manifest-branch=<new name>` and repo will take care of the rest. |
25 | 25 | ||
26 | * `config`: Per-repo client checkout settings using [git-config] file format. | ||
27 | * `.repo_config.json`: JSON cache of the `config` file for repo to | ||
28 | read/process quickly. | ||
29 | |||
26 | ### repo/ state | 30 | ### repo/ state |
27 | 31 | ||
28 | * `repo/`: A git checkout of the repo project. This is how `repo` re-execs | 32 | * `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`. | |||
198 | Repo will create & maintain a few files in the user's home directory. | 202 | Repo will create & maintain a few files in the user's home directory. |
199 | 203 | ||
200 | * `.repoconfig/`: Repo's per-user directory for all random config files/state. | 204 | * `.repoconfig/`: Repo's per-user directory for all random config files/state. |
205 | * `.repoconfig/config`: Per-user settings using [git-config] file format. | ||
201 | * `.repoconfig/keyring-version`: Cache file for checking if the gnupg subdir | 206 | * `.repoconfig/keyring-version`: Cache file for checking if the gnupg subdir |
202 | has all the same keys as the repo launcher. Used to avoid running gpg | 207 | has all the same keys as the repo launcher. Used to avoid running gpg |
203 | constantly as that can be quite slow. | 208 | constantly as that can be quite slow. |
204 | * `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs | 209 | * `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs |
205 | to run `gpg`. This provides isolation from the user's normal `~/.gnupg/`. | 210 | to run `gpg`. This provides isolation from the user's normal `~/.gnupg/`. |
206 | 211 | ||
212 | * `.repoconfig/.repo_config.json`: JSON cache of the `.repoconfig/config` | ||
213 | file for repo to read/process quickly. | ||
207 | * `.repo_.gitconfig.json`: JSON cache of the `.gitconfig` file for repo to | 214 | * `.repo_.gitconfig.json`: JSON cache of the `.gitconfig` file for repo to |
208 | read/process quickly. | 215 | read/process quickly. |
209 | 216 | ||
diff --git a/git_config.py b/git_config.py index 6b1f7107..8c4efac8 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -88,10 +88,12 @@ def _key(name): | |||
88 | class GitConfig(object): | 88 | class GitConfig(object): |
89 | _ForUser = None | 89 | _ForUser = None |
90 | 90 | ||
91 | _USER_CONFIG = '~/.gitconfig' | ||
92 | |||
91 | @classmethod | 93 | @classmethod |
92 | def ForUser(cls): | 94 | def ForUser(cls): |
93 | if cls._ForUser is None: | 95 | if cls._ForUser is None: |
94 | cls._ForUser = cls(configfile=os.path.expanduser('~/.gitconfig')) | 96 | cls._ForUser = cls(configfile=os.path.expanduser(cls._USER_CONFIG)) |
95 | return cls._ForUser | 97 | return cls._ForUser |
96 | 98 | ||
97 | @classmethod | 99 | @classmethod |
@@ -373,6 +375,12 @@ class GitConfig(object): | |||
373 | GitError('git config %s: %s' % (str(args), p.stderr)) | 375 | GitError('git config %s: %s' % (str(args), p.stderr)) |
374 | 376 | ||
375 | 377 | ||
378 | class RepoConfig(GitConfig): | ||
379 | """User settings for repo itself.""" | ||
380 | |||
381 | _USER_CONFIG = '~/.repoconfig/config' | ||
382 | |||
383 | |||
376 | class RefSpec(object): | 384 | class RefSpec(object): |
377 | """A Git refspec line, split into its components: | 385 | """A Git refspec line, split into its components: |
378 | 386 | ||