commit bc28ebfb8ddc9ae90f68ab51b1a5cbe8be587e06 from: Jelmer Vernooij date: Wed Mar 15 18:10:08 2023 UTC Make sure GitProtocolError's first argument is a string commit - d87326ab44010855fb3fb6b174f06393981ab44b commit + bc28ebfb8ddc9ae90f68ab51b1a5cbe8be587e06 blob - 9b92f946642f1a60cd839833f8e878e9650cd0b4 blob + 511bc3ce273087fd5733e3ee3895bd3185bfb55e --- dulwich/config.py +++ dulwich/config.py @@ -26,6 +26,7 @@ TODO: subsections """ +from contextlib import suppress import os import sys from typing import (BinaryIO, Iterable, Iterator, KeysView, List, @@ -641,13 +642,11 @@ def _find_git_in_win_reg(): ) for key in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE): # type: ignore - try: + with suppress(OSError): with winreg.OpenKey(key, subkey) as k: # type: ignore val, typ = winreg.QueryValueEx(k, "InstallLocation") # type: ignore if typ == winreg.REG_SZ: # type: ignore yield val - except OSError: - pass # There is no set standard for system config dirs on windows. We try the blob - 03fb03161da4e4d5cd9da2e45166263a581c4ed4 blob + a4629b53cc38ce46b2429d9549e0be652d4a4d7b --- dulwich/errors.py +++ dulwich/errors.py @@ -134,17 +134,6 @@ class SendPackError(GitProtocolError): """An error occurred during send_pack.""" -# N.B.: UpdateRefsError is no longer used and will be result in -# Dulwich 0.21. -# remove: >= 0.21 -class UpdateRefsError(GitProtocolError): - """The server reported errors updating refs.""" - - def __init__(self, *args, **kwargs): - self.ref_status = kwargs.pop("ref_status") - super().__init__(*args, **kwargs) - - class HangupException(GitProtocolError): """Hangup exception.""" blob - c7c9f616c41f56e0a917484a3f05dbaeaf2ee590 blob + bd60a70feb1086b00451b57fb191f98974a0ac51 --- dulwich/ignore.py +++ dulwich/ignore.py @@ -22,6 +22,7 @@ For details for the matching rules, see https://git-scm.com/docs/gitignore """ +from contextlib import suppress import os.path import re from typing import (TYPE_CHECKING, BinaryIO, Dict, Iterable, List, Optional, @@ -380,10 +381,8 @@ class IgnoreFilterManager: os.path.join(repo.controldir(), "info", "exclude"), default_user_ignore_filter_path(repo.get_config_stack()), ]: - try: + with suppress(OSError): global_filters.append(IgnoreFilter.from_path(os.path.expanduser(p))) - except OSError: - pass config = repo.get_config_stack() ignorecase = config.get_boolean((b"core"), (b"ignorecase"), False) return cls(repo.path, global_filters, ignorecase) blob - 82d7c93ba44596757c0cfb1bb5c5e26dae3d0375 blob + b08cb14285c5509954f0dafda86521364ef37ec9 --- dulwich/protocol.py +++ dulwich/protocol.py @@ -223,7 +223,7 @@ class Protocol: except ConnectionResetError as exc: raise HangupException() from exc except OSError as exc: - raise GitProtocolError(exc) from exc + raise GitProtocolError(str(exc)) from exc else: if len(pkt_contents) + 4 != size: raise GitProtocolError( @@ -286,7 +286,7 @@ class Protocol: if self.report_activity: self.report_activity(len(line), "write") except OSError as exc: - raise GitProtocolError(exc) from exc + raise GitProtocolError(str(exc)) from exc def write_sideband(self, channel, blob): """Write multiplexed data to the sideband. blob - 1e2414034c97ed545ff0e932da9c7fb4d40e498d blob + fe47dc7dbd8ce9c3e81fc689ac4a35dc4ebbe72f --- dulwich/refs.py +++ dulwich/refs.py @@ -734,10 +734,8 @@ class DiskRefsContainer(RefsContainer): # remove any loose refs pointing to this one -- please # note that this bypasses remove_if_equals as we don't # want to affect packed refs in here - try: + with suppress(OSError): os.remove(self.refpath(ref)) - except OSError: - pass if target is not None: packed_refs[ref] = target blob - 02ab6c0a887864fd54fbdd96cf2418a586f5b7f5 blob + 15ed1dadb225cf581fc7f385dc61dc3d2bd4116b --- dulwich/tests/compat/test_client.py +++ dulwich/tests/compat/test_client.py @@ -20,6 +20,7 @@ """Compatibility tests between the Dulwich client and the cgit server.""" +from contextlib import suppress import copy import http.server import os @@ -386,11 +387,9 @@ class DulwichTCPClientTest(CompatTestCase, DulwichClie ctypes.windll.kernel32.TerminateProcess(handle, -1) ctypes.windll.kernel32.CloseHandle(handle) else: - try: + with suppress(OSError): os.kill(pid, signal.SIGKILL) os.unlink(self.pidfile) - except OSError: - pass self.process.wait() self.process.stdout.close() self.process.stderr.close()