changeset 34258:61714510220d

error: move patch.PatchError so it can easily implement __bytes__ (API)
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Sep 2017 16:45:33 +0900
parents 448725a2ef73
children c43d055ae405
files mercurial/cmdutil.py mercurial/error.py mercurial/patch.py tests/test-transplant.t
diffstat 4 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Fri Sep 15 00:01:57 2017 -0700
+++ b/mercurial/cmdutil.py	Sun Sep 03 16:45:33 2017 +0900
@@ -278,7 +278,7 @@
         # 1. filter patch, since we are intending to apply subset of it
         try:
             chunks, newopts = filterfn(ui, originalchunks)
-        except patch.PatchError as err:
+        except error.PatchError as err:
             raise error.Abort(_('error parsing patch: %s') % err)
         opts.update(newopts)
 
@@ -360,7 +360,7 @@
                     ui.debug('applying patch\n')
                     ui.debug(fp.getvalue())
                     patch.internalpatch(ui, repo, fp, 1, eolmode=None)
-                except patch.PatchError as err:
+                except error.PatchError as err:
                     raise error.Abort(str(err))
             del fp
 
@@ -1334,7 +1334,7 @@
             try:
                 patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix,
                             files=files, eolmode=None, similarity=sim / 100.0)
-            except patch.PatchError as e:
+            except error.PatchError as e:
                 if not partial:
                     raise error.Abort(str(e))
                 if partial:
@@ -1380,7 +1380,7 @@
                 try:
                     patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
                                     files, eolmode=None)
-                except patch.PatchError as e:
+                except error.PatchError as e:
                     raise error.Abort(str(e))
                 if opts.get('exact'):
                     editor = None
@@ -3729,7 +3729,7 @@
             if reversehunks:
                 chunks = patch.reversehunks(chunks)
 
-        except patch.PatchError as err:
+        except error.PatchError as err:
             raise error.Abort(_('error parsing patch: %s') % err)
 
         newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
@@ -3751,7 +3751,7 @@
         if dopatch:
             try:
                 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None)
-            except patch.PatchError as err:
+            except error.PatchError as err:
                 raise error.Abort(str(err))
         del fp
     else:
--- a/mercurial/error.py	Fri Sep 15 00:01:57 2017 -0700
+++ b/mercurial/error.py	Sun Sep 03 16:45:33 2017 +0900
@@ -115,6 +115,9 @@
     """Raised when parsing config files and {rev,file}sets (msg[, pos])"""
     __bytes__ = _tobytes
 
+class PatchError(Exception):
+    __bytes__ = _tobytes
+
 class UnknownIdentifier(ParseError):
     """Exception raised when a {rev,file}set references an unknown identifier"""
 
--- a/mercurial/patch.py	Fri Sep 15 00:01:57 2017 -0700
+++ b/mercurial/patch.py	Sun Sep 03 16:45:33 2017 +0900
@@ -46,9 +46,7 @@
 gitre = re.compile(br'diff --git a/(.*) b/(.*)')
 tabsplitter = re.compile(br'(\t+|[^\t]+)')
 
-class PatchError(Exception):
-    pass
-
+PatchError = error.PatchError
 
 # public functions
 
--- a/tests/test-transplant.t	Fri Sep 15 00:01:57 2017 -0700
+++ b/tests/test-transplant.t	Sun Sep 03 16:45:33 2017 +0900
@@ -884,7 +884,7 @@
 
   $ cat > $TESTTMP/abort.py <<EOF
   > # emulate that patch.patch() is aborted at patching on "abort" file
-  > from mercurial import extensions, patch as patchmod
+  > from mercurial import error, extensions, patch as patchmod
   > def patch(orig, ui, repo, patchname,
   >           strip=1, prefix='', files=None,
   >           eolmode='strict', similarity=0):
@@ -894,7 +894,7 @@
   >         strip=strip, prefix=prefix, files=files,
   >         eolmode=eolmode, similarity=similarity)
   >     if 'abort' in files:
-  >         raise patchmod.PatchError('intentional error while patching')
+  >         raise error.PatchError('intentional error while patching')
   >     return r
   > def extsetup(ui):
   >     extensions.wrapfunction(patchmod, 'patch', patch)