diff options
| author | Joanna Wang <jojwang@google.com> | 2022-12-02 09:47:29 -0500 |
|---|---|---|
| committer | Joanna Wang <jojwang@google.com> | 2022-12-02 14:57:56 +0000 |
| commit | ea5239ddd930624532cd1d0edccc0f3e74bec73f (patch) | |
| tree | e0883d5a6e8986ee712c4440c5ed238e00ba652f /git_config.py | |
| parent | 1b8714937c20d43f98bd9ffe498a49fcfb086141 (diff) | |
| download | git-repo-ea5239ddd930624532cd1d0edccc0f3e74bec73f.tar.gz | |
Fix ManifestProject.partial_clone_exclude property.
Bug: b/256358360
Change-Id: Ic6e3a049aa38827123d0324c8b14157562c5986e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/353574
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Joanna Wang <jojwang@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Diffstat (limited to 'git_config.py')
| -rw-r--r-- | git_config.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/git_config.py b/git_config.py index 94378e9a..af1a1015 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -22,6 +22,7 @@ import re | |||
| 22 | import ssl | 22 | import ssl |
| 23 | import subprocess | 23 | import subprocess |
| 24 | import sys | 24 | import sys |
| 25 | from typing import Union | ||
| 25 | import urllib.error | 26 | import urllib.error |
| 26 | import urllib.request | 27 | import urllib.request |
| 27 | 28 | ||
| @@ -117,7 +118,7 @@ class GitConfig(object): | |||
| 117 | return self.defaults.Has(name, include_defaults=True) | 118 | return self.defaults.Has(name, include_defaults=True) |
| 118 | return False | 119 | return False |
| 119 | 120 | ||
| 120 | def GetInt(self, name): | 121 | def GetInt(self, name: str) -> Union[int, None]: |
| 121 | """Returns an integer from the configuration file. | 122 | """Returns an integer from the configuration file. |
| 122 | 123 | ||
| 123 | This follows the git config syntax. | 124 | This follows the git config syntax. |
| @@ -126,7 +127,7 @@ class GitConfig(object): | |||
| 126 | name: The key to lookup. | 127 | name: The key to lookup. |
| 127 | 128 | ||
| 128 | Returns: | 129 | Returns: |
| 129 | None if the value was not defined, or is not a boolean. | 130 | None if the value was not defined, or is not an int. |
| 130 | Otherwise, the number itself. | 131 | Otherwise, the number itself. |
| 131 | """ | 132 | """ |
| 132 | v = self.GetString(name) | 133 | v = self.GetString(name) |
| @@ -152,6 +153,9 @@ class GitConfig(object): | |||
| 152 | try: | 153 | try: |
| 153 | return int(v, base=base) * mult | 154 | return int(v, base=base) * mult |
| 154 | except ValueError: | 155 | except ValueError: |
| 156 | print( | ||
| 157 | f"warning: expected {name} to represent an integer, got {v} instead", | ||
| 158 | file=sys.stderr) | ||
| 155 | return None | 159 | return None |
| 156 | 160 | ||
| 157 | def DumpConfigDict(self): | 161 | def DumpConfigDict(self): |
| @@ -169,7 +173,7 @@ class GitConfig(object): | |||
| 169 | config_dict[key] = self.GetString(key) | 173 | config_dict[key] = self.GetString(key) |
| 170 | return config_dict | 174 | return config_dict |
| 171 | 175 | ||
| 172 | def GetBoolean(self, name): | 176 | def GetBoolean(self, name: str) -> Union[str, None]: |
| 173 | """Returns a boolean from the configuration file. | 177 | """Returns a boolean from the configuration file. |
| 174 | None : The value was not defined, or is not a boolean. | 178 | None : The value was not defined, or is not a boolean. |
| 175 | True : The value was set to true or yes. | 179 | True : The value was set to true or yes. |
| @@ -183,6 +187,8 @@ class GitConfig(object): | |||
| 183 | return True | 187 | return True |
| 184 | if v in ('false', 'no'): | 188 | if v in ('false', 'no'): |
| 185 | return False | 189 | return False |
| 190 | print(f"warning: expected {name} to represent a boolean, got {v} instead", | ||
| 191 | file=sys.stderr) | ||
| 186 | return None | 192 | return None |
| 187 | 193 | ||
| 188 | def SetBoolean(self, name, value): | 194 | def SetBoolean(self, name, value): |
| @@ -191,7 +197,7 @@ class GitConfig(object): | |||
| 191 | value = 'true' if value else 'false' | 197 | value = 'true' if value else 'false' |
| 192 | self.SetString(name, value) | 198 | self.SetString(name, value) |
| 193 | 199 | ||
| 194 | def GetString(self, name, all_keys=False): | 200 | def GetString(self, name: str, all_keys: bool = False) -> Union[str, None]: |
| 195 | """Get the first value for a key, or None if it is not defined. | 201 | """Get the first value for a key, or None if it is not defined. |
| 196 | 202 | ||
| 197 | This configuration file is used first, if the key is not | 203 | This configuration file is used first, if the key is not |
