Просмотр исходного кода

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>
Mike Frysinger 6 лет назад
Родитель
Сommit
f841ca48c1
2 измененных файлов с 16 добавлено и 1 удалено
  1. 7 0
      docs/internal-fs-layout.md
  2. 9 1
      git_config.py

+ 7 - 0
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
 For example, if you want to change the manifest branch, you can simply run
 `repo init --manifest-branch=<new name>` and repo will take care of the rest.
 `repo init --manifest-branch=<new name>` 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/ state
 
 
 *   `repo/`: A git checkout of the repo project.  This is how `repo` re-execs
 *   `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.
 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/`: 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
 *   `.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
     has all the same keys as the repo launcher.  Used to avoid running gpg
     constantly as that can be quite slow.
     constantly as that can be quite slow.
 *   `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs
 *   `.repoconfig/gnupg/`: GnuPG's internal state directory used when repo needs
     to run `gpg`.  This provides isolation from the user's normal `~/.gnupg/`.
     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
 *   `.repo_.gitconfig.json`: JSON cache of the `.gitconfig` file for repo to
     read/process quickly.
     read/process quickly.
 
 

+ 9 - 1
git_config.py

@@ -88,10 +88,12 @@ def _key(name):
 class GitConfig(object):
 class GitConfig(object):
   _ForUser = None
   _ForUser = None
 
 
+  _USER_CONFIG = '~/.gitconfig'
+
   @classmethod
   @classmethod
   def ForUser(cls):
   def ForUser(cls):
     if cls._ForUser is None:
     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
     return cls._ForUser
 
 
   @classmethod
   @classmethod
@@ -373,6 +375,12 @@ class GitConfig(object):
       GitError('git config %s: %s' % (str(args), p.stderr))
       GitError('git config %s: %s' % (str(args), p.stderr))
 
 
 
 
+class RepoConfig(GitConfig):
+  """User settings for repo itself."""
+
+  _USER_CONFIG = '~/.repoconfig/config'
+
+
 class RefSpec(object):
 class RefSpec(object):
   """A Git refspec line, split into its components:
   """A Git refspec line, split into its components: