From ea5239ddd930624532cd1d0edccc0f3e74bec73f Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Fri, 2 Dec 2022 09:47:29 -0500 Subject: 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 Tested-by: Joanna Wang Reviewed-by: Josip Sokcevic --- git_config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'git_config.py') 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 import ssl import subprocess import sys +from typing import Union import urllib.error import urllib.request @@ -117,7 +118,7 @@ class GitConfig(object): return self.defaults.Has(name, include_defaults=True) return False - def GetInt(self, name): + def GetInt(self, name: str) -> Union[int, None]: """Returns an integer from the configuration file. This follows the git config syntax. @@ -126,7 +127,7 @@ class GitConfig(object): name: The key to lookup. Returns: - None if the value was not defined, or is not a boolean. + None if the value was not defined, or is not an int. Otherwise, the number itself. """ v = self.GetString(name) @@ -152,6 +153,9 @@ class GitConfig(object): try: return int(v, base=base) * mult except ValueError: + print( + f"warning: expected {name} to represent an integer, got {v} instead", + file=sys.stderr) return None def DumpConfigDict(self): @@ -169,7 +173,7 @@ class GitConfig(object): config_dict[key] = self.GetString(key) return config_dict - def GetBoolean(self, name): + def GetBoolean(self, name: str) -> Union[str, None]: """Returns a boolean from the configuration file. None : The value was not defined, or is not a boolean. True : The value was set to true or yes. @@ -183,6 +187,8 @@ class GitConfig(object): return True if v in ('false', 'no'): return False + print(f"warning: expected {name} to represent a boolean, got {v} instead", + file=sys.stderr) return None def SetBoolean(self, name, value): @@ -191,7 +197,7 @@ class GitConfig(object): value = 'true' if value else 'false' self.SetString(name, value) - def GetString(self, name, all_keys=False): + def GetString(self, name: str, all_keys: bool = False) -> Union[str, None]: """Get the first value for a key, or None if it is not defined. This configuration file is used first, if the key is not -- cgit v1.2.3-54-g00ecf