[PATCH 1 of 2 RFC] subrepo: add constructor to SubrepoAbort

Matt Harbison matt_harbison at yahoo.com
Sun Jan 6 22:40:54 CST 2013


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1357526787 18000
# Node ID c8d4cc041ba1ad2572d7d139802831e0ac062bfb
# Parent  2c1276825e938872ebc099c191eb202f0dbadfcc
subrepo: add constructor to SubrepoAbort

This is Angel's patch [1] with SubrepoAbort property support, but with a
--traceback in a test so that the next patch shows the effect of the code that
prints chained exception information.

[1] http://www.selenic.com/pipermail/mercurial-devel/2013-January/047464.html

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -16,6 +16,9 @@
 
 class SubrepoAbort(error.Abort):
     """Exception class used to avoid handling a subrepo error more than once"""
+    def __init__(self, *args, **kw):
+        super(SubrepoAbort, self).__init__(*args, **kw)
+        self.subrepo = kw.get('subrepo')
 
 def annotatesubrepoerror(func):
     def decoratedmethod(self, *args, **kargs):
@@ -25,9 +28,10 @@
             # This exception has already been handled
             raise ex
         except error.Abort, ex:
-            errormsg = _('%s (in subrepo %s)') % (str(ex), subrelpath(self))
+            subrepo = subrelpath(self)
+            errormsg = _('%s (in subrepo %s)') % (str(ex), subrepo)
             # avoid handling this exception by raising a SubrepoAbort exception
-            raise SubrepoAbort(errormsg, hint=ex.hint)
+            raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo)
         return res
     return decoratedmethod
 
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -644,7 +644,37 @@
   adding file changes
   added 2 changesets with 3 changes to 2 files
   (run 'hg update' to get a working copy)
-  $ hg -R issue1852b update
+  $ hg -R issue1852b update --traceback
+  Traceback (most recent call last):
+    File "*/mercurial/dispatch.py", line *, in _runcatch (glob)
+      return _dispatch(req)
+    File "*/mercurial/dispatch.py", line *, in _dispatch (glob)
+      cmdpats, cmdoptions)
+    File "*/mercurial/dispatch.py", line *, in runcommand (glob)
+      ret = _runcommand(ui, options, cmd, d)
+    File "*/mercurial/dispatch.py", line *, in _runcommand (glob)
+      return checkargs()
+    File "*/mercurial/dispatch.py", line *, in checkargs (glob)
+      return cmdfunc()
+    File "*/mercurial/dispatch.py", line *, in <lambda> (glob)
+      d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
+    File "*/mercurial/util.py", line *, in check (glob)
+      return func(*args, **kwargs)
+    File "*/mercurial/commands.py", line *, in update (glob)
+      ret = hg.update(repo, rev)
+    File "*/mercurial/hg.py", line *, in update (glob)
+      stats = updaterepo(repo, node, False)
+    File "*/mercurial/hg.py", line *, in updaterepo (glob)
+      return mergemod.update(repo, node, False, overwrite, None)
+    File "*/mercurial/merge.py", line *, in update (glob)
+      stats = applyupdates(repo, action, wc, p2, pa, overwrite)
+    File "*/mercurial/merge.py", line *, in applyupdates (glob)
+      subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
+    File "*/mercurial/subrepo.py", line *, in submerge (glob)
+      mctx.sub(s).get(r)
+    File "*/mercurial/subrepo.py", line *, in decoratedmethod (glob)
+      raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo)
+  SubrepoAbort: default path for subrepository not found (in subrepo sub/repo) (glob)
   abort: default path for subrepository not found (in subrepo sub/repo) (glob)
   [255]
 


More information about the Mercurial-devel mailing list