commit e9071c627f6d0a04a388b95402dbddd7ecfc3f52 from: David Hotham date: Thu Jun 30 16:52:25 2022 UTC Special case boolean config values commit - 9d9b5072223e4276793a7c6005786cb87f96cb08 commit + e9071c627f6d0a04a388b95402dbddd7ecfc3f52 blob - f979d3cdf036e519ffd79209a431c3736611ee0c blob + 962e327b7f5096c5030bcf11507d4bde11446fb8 --- dulwich/config.py +++ dulwich/config.py @@ -142,8 +142,8 @@ class CaseInsensitiveOrderedMultiDict(MutableMapping): BytesLike = Union[bytes, str] Key = Tuple[bytes, ...] KeyLike = Union[bytes, str, Tuple[BytesLike, ...]] -Value = Union[bytes, bool] -ValueLike = Union[bytes, str, bool] +Value = bytes +ValueLike = Union[bytes, str] class Config(object): @@ -212,6 +212,18 @@ class Config(object): value: value of the setting """ raise NotImplementedError(self.set) + + def set_boolean(self, section: KeyLike, name: BytesLike, value: bool) -> None: + """Set a boolean configuration value. + + Args: + section: Tuple with section name and optional subsection namee + name: Name of the configuration value, including section + and optional subsection + value: value of the setting + """ + text = b"true" if value else b"false" + self.set(section, name, text) def items(self, section: KeyLike) -> Iterator[Tuple[bytes, Value]]: """Iterate over the configuration pairs for a specific section. @@ -759,9 +771,5 @@ def parse_submodules(config: ConfigFile) -> Iterator[T section_kind, section_name = section if section_kind == b"submodule": sm_path = config.get(section, b"path") - assert isinstance(sm_path, bytes) - assert sm_path is not None sm_url = config.get(section, b"url") - assert sm_url is not None - assert isinstance(sm_url, bytes) yield (sm_path, sm_url, section_name) blob - c7ff6544e509efb2a6c4b4fb4382b581726c6243 blob + d34dac7e8a6f3a6113e2b30e97f9f4f27dbe1a1a --- dulwich/porcelain.py +++ dulwich/porcelain.py @@ -1001,10 +1001,7 @@ def get_remote_repo( if config.has_section(section): remote_name = encoded_location.decode() - url = config.get(section, "url") - assert url is not None - assert isinstance(url, bytes) - encoded_location = url + encoded_location = config.get(section, "url") else: remote_name = None blob - 396069b9de456f1bde341145a311b23b46130da8 blob + 264ab907e6d89a032af4c3251432c66331a9e14f --- dulwich/repo.py +++ dulwich/repo.py @@ -195,16 +195,12 @@ def get_user_identity(config: "StackedConfig", kind: O email = email_uc.encode("utf-8") if user is None: try: - config_value = config.get(("user",), "name") - assert isinstance(config_value, bytes) - user = config_value + user = config.get(("user",), "name") except KeyError: user = None if email is None: try: - config_value = config.get(("user",), "email") - assert isinstance(config_value, bytes) - email = config_value + email = config.get(("user",), "email") except KeyError: email = None default_user, default_email = _get_default_identity() @@ -370,12 +366,12 @@ class BaseRepo(object): cf = ConfigFile() cf.set("core", "repositoryformatversion", "0") if self._determine_file_mode(): - cf.set("core", "filemode", True) + cf.set_boolean("core", "filemode", True) else: - cf.set("core", "filemode", False) + cf.set_boolean("core", "filemode", False) - cf.set("core", "bare", bare) - cf.set("core", "logallrefupdates", True) + cf.set_boolean("core", "bare", bare) + cf.set_boolean("core", "logallrefupdates", True) cf.write_to_file(f) self._put_named_file("config", f.getvalue()) self._put_named_file(os.path.join("info", "exclude"), b"")