changeset 1128:6141895a53c9

compat: switch from hgutil.Abort to error.Abort
author Kevin Bullock <kbullock@ringworld.org>
date Wed, 02 May 2018 20:43:17 -0500
parents 108d9303ef71
children 5edabf9db748
files hggit/git_handler.py hggit/gitdirstate.py hggit/gitrepo.py hggit/hg2git.py hggit/util.py hggit/verify.py
diffstat 6 files changed, 49 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/git_handler.py	Wed May 02 20:43:17 2018 -0500
@@ -22,6 +22,7 @@
     commands,
     context,
     encoding,
+    error,
     phases,
     util as hgutil,
 )
@@ -405,7 +406,7 @@
 
             return old, new
         except (HangupException, GitProtocolError), e:
-            raise hgutil.Abort(_("git remote error: ") + str(e))
+            raise error.Abort(_("git remote error: ") + str(e))
 
     def push(self, remote, revs, force):
         self.export_commits()
@@ -521,8 +522,8 @@
             try:
                 gitcommit = self.git[gitsha]
             except KeyError:
-                raise hgutil.Abort(_('Parent SHA-1 not present in Git'
-                                     'repo: %s' % gitsha))
+                raise error.Abort(_('Parent SHA-1 not present in Git'
+                                    'repo: %s' % gitsha))
 
         exporter = hg2git.IncrementalChangesetExporter(
             self.repo, pctx, self.git.object_store, gitcommit)
@@ -594,8 +595,8 @@
             git_sha = self.map_git_get(hgsha)
             if git_sha:
                 if git_sha not in self.git.object_store:
-                    raise hgutil.Abort(_('Parent SHA-1 not present in Git'
-                                         'repo: %s' % git_sha))
+                    raise error.Abort(_('Parent SHA-1 not present in Git'
+                                        'repo: %s' % git_sha))
 
                 commit.parents.append(git_sha)
 
@@ -614,8 +615,8 @@
         tree_sha = exporter.root_tree_sha
 
         if tree_sha not in self.git.object_store:
-            raise hgutil.Abort(_('Tree SHA-1 not present in Git repo: %s' %
-                                 tree_sha))
+            raise error.Abort(_('Tree SHA-1 not present in Git repo: %s' %
+                                tree_sha))
 
         commit.tree = tree_sha
 
@@ -854,8 +855,8 @@
 
         for parent in gparents:
             if parent not in self.repo:
-                raise hgutil.Abort(_('you appear to have run strip - '
-                                     'please run hg git-cleanup'))
+                raise error.Abort(_('you appear to have run strip - '
+                                    'please run hg git-cleanup'))
 
         # get a list of the changed, added, removed files and gitlinks
         files, gitlinks, git_renames = self.get_files_changed(commit,
@@ -1080,9 +1081,9 @@
                 exportable = {}
                 for rev in (hex(r) for r in revs):
                     if rev not in all_exportable:
-                        raise hgutil.Abort("revision %s cannot be pushed since"
-                                           " it doesn't have a bookmark" %
-                                           self.repo[rev])
+                        raise error.Abort("revision %s cannot be pushed since"
+                                          " it doesn't have a bookmark" %
+                                          self.repo[rev])
                     exportable[rev] = all_exportable[rev]
             return self.get_changed_refs(refs, exportable, force)
 
@@ -1132,7 +1133,7 @@
                                 change_totals.get(Blob, 0)))
             return old_refs, new_refs
         except (HangupException, GitProtocolError), e:
-            raise hgutil.Abort(_("git remote error: ") + str(e))
+            raise error.Abort(_("git remote error: ") + str(e))
 
     def get_changed_refs(self, refs, exportable, force):
         new_refs = refs.copy()
@@ -1169,8 +1170,8 @@
         for rev, rev_refs in exportable.iteritems():
             ctx = self.repo[rev]
             if not rev_refs:
-                raise hgutil.Abort("revision %s cannot be pushed since"
-                                   " it doesn't have a bookmark" % ctx)
+                raise error.Abort("revision %s cannot be pushed since"
+                                  " it doesn't have a bookmark" % ctx)
 
             # Check if the tags the server is advertising are annotated tags,
             # by attempting to retrieve it from the our git repo, and building
@@ -1203,13 +1204,13 @@
                     if rctx.ancestor(ctx) == rctx or force:
                         new_refs[ref] = self.map_git_get(ctx.hex())
                     else:
-                        raise hgutil.Abort("pushing %s overwrites %s"
-                                           % (ref, ctx))
+                        raise error.Abort("pushing %s overwrites %s"
+                                          % (ref, ctx))
                 elif ref in uptodate_annotated_tags:
                     # we already have the annotated tag.
                     pass
                 else:
-                    raise hgutil.Abort(
+                    raise error.Abort(
                         "branch '%s' changed on the server, "
                         "please pull and merge before pushing" % ref)
 
@@ -1265,7 +1266,7 @@
                 ret = compat.FetchPackResult(ret, symrefs, agent)
             return ret
         except (HangupException, GitProtocolError), e:
-            raise hgutil.Abort(_("git remote error: ") + str(e))
+            raise error.Abort(_("git remote error: ") + str(e))
 
     # REFERENCES HANDLING
 
@@ -1290,13 +1291,13 @@
                 else:
                     r = [pair[0] for pair in stripped_refs if pair[1] == h]
                     if not r:
-                        raise hgutil.Abort("ref %s not found on remote server"
-                                           % h)
+                        raise error.Abort("ref %s not found on remote server"
+                                          % h)
                     elif len(r) == 1:
                         filteredrefs.append(r[0])
                     else:
-                        raise hgutil.Abort("ambiguous reference %s: %r"
-                                           % (h, r))
+                        raise error.Abort("ambiguous reference %s: %r"
+                                          % (h, r))
         else:
             for ref, sha in refs.iteritems():
                 if (not ref.endswith('^{}') and
@@ -1601,14 +1602,14 @@
         # disabled by default to avoid surprises
         similarity = compat.config(self.ui, 'int', 'git', 'similarity')
         if similarity < 0 or similarity > 100:
-            raise hgutil.Abort(_('git.similarity must be between 0 and 100'))
+            raise error.Abort(_('git.similarity must be between 0 and 100'))
         if similarity == 0:
             return None
 
         # default is borrowed from Git
         max_files = compat.config(self.ui, 'int', 'git', 'renamelimit')
         if max_files < 0:
-            raise hgutil.Abort(_('git.renamelimit must be non-negative'))
+            raise error.Abort(_('git.renamelimit must be non-negative'))
         if max_files == 0:
             max_files = None
 
@@ -1661,7 +1662,7 @@
     def audit_hg_path(self, path):
         if '.hg' in path.split(os.path.sep):
             if compat.config(self.ui, 'bool', 'git', 'blockdothg'):
-                raise hgutil.Abort(
+                raise error.Abort(
                     ('Refusing to import problematic path %r' % path),
                     hint=("Mercurial cannot check out paths inside nested " +
                           "repositories; if you need to continue, then set " +
--- a/hggit/gitdirstate.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/gitdirstate.py	Wed May 02 20:43:17 2018 -0500
@@ -5,6 +5,7 @@
 
 from mercurial import (
     dirstate,
+    error,
     match as matchmod,
     scmutil,
     util,
@@ -88,21 +89,21 @@
         return util.never
     try:
         ignorefunc = matchmod.match(root, '', [], allpats)
-    except util.Abort:
+    except error.Abort:
         for f, patlist in pats:
             try:
                 matchmod.match(root, '', [], patlist)
-            except util.Abort, inst:
+            except error.Abort, inst:
                 if not ignoremod:
                     # in this case, patlist is ['include: FILE'], and
                     # inst[0] should already include FILE
                     raise
-                raise util.Abort('%s: %s' % (f, inst[0]))
+                raise error.Abort('%s: %s' % (f, inst[0]))
         if extrapatterns:
             try:
                 matchmod.match(root, '', [], extrapatterns)
-            except util.Abort, inst:
-                raise util.Abort('%s: %s' % ('extra patterns', inst[0]))
+            except error.Abort, inst:
+                raise error.Abort('%s: %s' % ('extra patterns', inst[0]))
     return ignorefunc
 
 
--- a/hggit/gitrepo.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/gitrepo.py	Wed May 02 20:43:17 2018 -0500
@@ -1,6 +1,8 @@
 from util import isgitsshuri
-from mercurial import util
-from mercurial.error import RepoError
+from mercurial import (
+    error,
+    util
+)
 
 peerapi = False
 try:
@@ -13,7 +15,7 @@
 class gitrepo(peerrepository):
     def __init__(self, ui, path, create, intents=None):
         if create:  # pragma: no cover
-            raise util.Abort('Cannot create a git repository.')
+            raise error.Abort('Cannot create a git repository.')
         self._ui = ui
         self.path = path
         self.localrepo = None
@@ -39,7 +41,7 @@
 
     def local(self):
         if not self.path:
-            raise RepoError
+            raise error.RepoError
 
     def heads(self):
         return []
--- a/hggit/hg2git.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/hg2git.py	Wed May 02 20:43:17 2018 -0500
@@ -7,7 +7,7 @@
 
 import dulwich.objects as dulobjs
 from mercurial import (
-    util as hgutil,
+    error,
 )
 
 import compat
@@ -60,7 +60,7 @@
                 break
     if dangerous:
         if compat.config(ui, 'bool', 'git', 'blockdotgit'):
-            raise hgutil.Abort(
+            raise error.Abort(
                 ('Refusing to export likely-dangerous path %r' % path),
                 hint=("If you need to continue, read about CVE-2014-9390 and "
                       "then set '[git] blockdotgit = false' in your hgrc."))
--- a/hggit/util.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/util.py	Wed May 02 20:43:17 2018 -0500
@@ -59,7 +59,7 @@
         try:
             return f(*args, **kwargs)
         except errors.NotGitRepository:
-            raise hgutil.Abort('not a git repository')
+            raise error.Abort('not a git repository')
     return inner
 
 
--- a/hggit/verify.py	Thu May 17 07:51:47 2018 +0200
+++ b/hggit/verify.py	Wed May 02 20:43:17 2018 -0500
@@ -8,7 +8,6 @@
 import stat
 
 from mercurial import error
-from mercurial import util as hgutil
 from mercurial.i18n import _
 
 from dulwich import diff_tree
@@ -28,18 +27,18 @@
     gitsha = handler.map_git_get(hgctx.hex())
     if not gitsha:
         # TODO deal better with commits in the middle of octopus merges
-        raise hgutil.Abort(_('no git commit found for rev %s') % hgctx,
-                           hint=_('if this is an octopus merge, '
-                                  'verify against the last rev'))
+        raise error.Abort(_('no git commit found for rev %s') % hgctx,
+                          hint=_('if this is an octopus merge, '
+                                 'verify against the last rev'))
 
     try:
         gitcommit = handler.git.get_object(gitsha)
     except KeyError:
-        raise hgutil.Abort(_('git equivalent %s for rev %s not found!') %
-                           (gitsha, hgctx))
+        raise error.Abort(_('git equivalent %s for rev %s not found!') %
+                          (gitsha, hgctx))
     if not isinstance(gitcommit, Commit):
-        raise hgutil.Abort(_('git equivalent %s for rev %s is not a commit!') %
-                           (gitsha, hgctx))
+        raise error.Abort(_('git equivalent %s for rev %s is not a commit!') %
+                          (gitsha, hgctx))
 
     ui.status(_('verifying rev %s against git commit %s\n') % (hgctx, gitsha))
     failed = False