comparison mercurial/subrepo.py @ 25660:328739ea70c3

global: mass rewrite to use modern exception syntax Python 2.6 introduced the "except type as instance" syntax, replacing the "except type, instance" syntax that came before. Python 3 dropped support for the latter syntax. Since we no longer support Python 2.4 or 2.5, we have no need to continue supporting the "except type, instance". This patch mass rewrites the exception syntax to be Python 2.6+ and Python 3 compatible. This patch was produced by running `2to3 -f except -w -n .`.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 23 Jun 2015 22:20:08 -0700
parents e93036747902
children 7a9ef8608a1d
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
42 42
43 def annotatesubrepoerror(func): 43 def annotatesubrepoerror(func):
44 def decoratedmethod(self, *args, **kargs): 44 def decoratedmethod(self, *args, **kargs):
45 try: 45 try:
46 res = func(self, *args, **kargs) 46 res = func(self, *args, **kargs)
47 except SubrepoAbort, ex: 47 except SubrepoAbort as ex:
48 # This exception has already been handled 48 # This exception has already been handled
49 raise ex 49 raise ex
50 except error.Abort, ex: 50 except error.Abort as ex:
51 subrepo = subrelpath(self) 51 subrepo = subrelpath(self)
52 errormsg = str(ex) + ' ' + _('(in subrepo %s)') % subrepo 52 errormsg = str(ex) + ' ' + _('(in subrepo %s)') % subrepo
53 # avoid handling this exception by raising a SubrepoAbort exception 53 # avoid handling this exception by raising a SubrepoAbort exception
54 raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo, 54 raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo,
55 cause=sys.exc_info()) 55 cause=sys.exc_info())
64 p = config.config() 64 p = config.config()
65 def read(f, sections=None, remap=None): 65 def read(f, sections=None, remap=None):
66 if f in ctx: 66 if f in ctx:
67 try: 67 try:
68 data = ctx[f].data() 68 data = ctx[f].data()
69 except IOError, err: 69 except IOError as err:
70 if err.errno != errno.ENOENT: 70 if err.errno != errno.ENOENT:
71 raise 71 raise
72 # handle missing subrepo spec files as removed 72 # handle missing subrepo spec files as removed
73 ui.warn(_("warning: subrepo spec file \'%s\' not found\n") % 73 ui.warn(_("warning: subrepo spec file \'%s\' not found\n") %
74 util.pathto(ctx.repo().root, ctx.repo().getcwd(), f)) 74 util.pathto(ctx.repo().root, ctx.repo().getcwd(), f))
99 raise util.Abort(_("invalid subrepository revision " 99 raise util.Abort(_("invalid subrepository revision "
100 "specifier in \'%s\' line %d") 100 "specifier in \'%s\' line %d")
101 % (util.pathto(repo.root, repo.getcwd(), 101 % (util.pathto(repo.root, repo.getcwd(),
102 '.hgsubstate'), (i + 1))) 102 '.hgsubstate'), (i + 1)))
103 rev[path] = revision 103 rev[path] = revision
104 except IOError, err: 104 except IOError as err:
105 if err.errno != errno.ENOENT: 105 if err.errno != errno.ENOENT:
106 raise 106 raise
107 107
108 def remap(src): 108 def remap(src):
109 for pattern, repl in p.items('subpaths'): 109 for pattern, repl in p.items('subpaths'):
114 # through unharmed, so we turn r'\\1' into r'\1'. Again, 114 # through unharmed, so we turn r'\\1' into r'\1'. Again,
115 # extra escapes are needed because re.sub string decodes. 115 # extra escapes are needed because re.sub string decodes.
116 repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl) 116 repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl)
117 try: 117 try:
118 src = re.sub(pattern, repl, src, 1) 118 src = re.sub(pattern, repl, src, 1)
119 except re.error, e: 119 except re.error as e:
120 raise util.Abort(_("bad subrepository pattern in %s: %s") 120 raise util.Abort(_("bad subrepository pattern in %s: %s")
121 % (p.source('subpaths', pattern), e)) 121 % (p.source('subpaths', pattern), e))
122 return src 122 return src
123 123
124 state = {} 124 state = {}
732 try: 732 try:
733 rev1 = self._state[1] 733 rev1 = self._state[1]
734 ctx1 = self._repo[rev1] 734 ctx1 = self._repo[rev1]
735 ctx2 = self._repo[rev2] 735 ctx2 = self._repo[rev2]
736 return self._repo.status(ctx1, ctx2, **opts) 736 return self._repo.status(ctx1, ctx2, **opts)
737 except error.RepoLookupError, inst: 737 except error.RepoLookupError as inst:
738 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') 738 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
739 % (inst, subrelpath(self))) 739 % (inst, subrelpath(self)))
740 return scmutil.status([], [], [], [], [], [], []) 740 return scmutil.status([], [], [], [], [], [], [])
741 741
742 @annotatesubrepoerror 742 @annotatesubrepoerror
749 node2 = node.bin(node2) 749 node2 = node.bin(node2)
750 cmdutil.diffordiffstat(ui, self._repo, diffopts, 750 cmdutil.diffordiffstat(ui, self._repo, diffopts,
751 node1, node2, match, 751 node1, node2, match,
752 prefix=posixpath.join(prefix, self._path), 752 prefix=posixpath.join(prefix, self._path),
753 listsubrepos=True, **opts) 753 listsubrepos=True, **opts)
754 except error.RepoLookupError, inst: 754 except error.RepoLookupError as inst:
755 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') 755 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
756 % (inst, subrelpath(self))) 756 % (inst, subrelpath(self)))
757 757
758 @annotatesubrepoerror 758 @annotatesubrepoerror
759 def archive(self, archiver, prefix, match=None): 759 def archive(self, archiver, prefix, match=None):
1278 1278
1279 def _ensuregit(self): 1279 def _ensuregit(self):
1280 try: 1280 try:
1281 self._gitexecutable = 'git' 1281 self._gitexecutable = 'git'
1282 out, err = self._gitnodir(['--version']) 1282 out, err = self._gitnodir(['--version'])
1283 except OSError, e: 1283 except OSError as e:
1284 if e.errno != 2 or os.name != 'nt': 1284 if e.errno != 2 or os.name != 'nt':
1285 raise 1285 raise
1286 self._gitexecutable = 'git.cmd' 1286 self._gitexecutable = 'git.cmd'
1287 out, err = self._gitnodir(['--version']) 1287 out, err = self._gitnodir(['--version'])
1288 versionstatus = self._checkversion(out) 1288 versionstatus = self._checkversion(out)