comparison hgsubversion/svnexternals.py @ 1555:cff81f35b31e

cleanup: reference Abort from mercurial.error instead of mercurial.util It's been there since hg 1.7 or so, which lets us avoid any need for compat shims.
author Augie Fackler <raf@durin42.com>
date Sat, 24 Mar 2018 16:39:30 -0400
parents 106716ed2ed0
children 53d170a6c3c8
comparison
equal deleted inserted replaced
1554:258fb67fb956 1555:cff81f35b31e
1 import cStringIO 1 import cStringIO
2 2
3 import os, re, shutil, stat, subprocess 3 import os, re, shutil, stat, subprocess
4 from mercurial import error as hgerror
4 from mercurial import util as hgutil 5 from mercurial import util as hgutil
5 from mercurial.i18n import _ 6 from mercurial.i18n import _
6 from mercurial import subrepo 7 from mercurial import subrepo
7 8
8 try: 9 try:
56 if not line.strip(): 57 if not line.strip():
57 continue 58 continue
58 if line.startswith('['): 59 if line.startswith('['):
59 line = line.strip() 60 line = line.strip()
60 if line[-1] != ']': 61 if line[-1] != ']':
61 raise hgutil.Abort('invalid externals section name: %s' % line) 62 raise hgerror.Abort('invalid externals section name: %s' % line)
62 target = line[1:-1] 63 target = line[1:-1]
63 if target == '.': 64 if target == '.':
64 target = '' 65 target = ''
65 elif line.startswith(' '): 66 elif line.startswith(' '):
66 line = line.rstrip('\n') 67 line = line.rstrip('\n')
226 # Check target dirs are not nested 227 # Check target dirs are not nested
227 defs.sort() 228 defs.sort()
228 for i, d in enumerate(defs): 229 for i, d in enumerate(defs):
229 for d2 in defs[i+1:]: 230 for d2 in defs[i+1:]:
230 if d2[0].startswith(d[0] + '/'): 231 if d2[0].startswith(d[0] + '/'):
231 raise hgutil.Abort(_('external directories cannot nest:\n%s\n%s') 232 raise hgerror.Abort(_('external directories cannot nest:\n%s\n%s')
232 % (d[0], d2[0])) 233 % (d[0], d2[0]))
233 return defs 234 return defs
234 235
235 def computeactions(ui, repo, svnroot, ext1, ext2): 236 def computeactions(ui, repo, svnroot, ext1, ext2):
236 237
262 shell = os.name == 'nt' 263 shell = os.name == 'nt'
263 p = subprocess.Popen(args, shell=shell, 264 p = subprocess.Popen(args, shell=shell,
264 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 265 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
265 stdout = p.communicate()[0] 266 stdout = p.communicate()[0]
266 if p.returncode: 267 if p.returncode:
267 raise hgutil.Abort(_('cannot get information about %s') 268 raise hgerror.Abort(_('cannot get information about %s')
268 % svnurl) 269 % svnurl)
269 m = re.search(r'<root>(.*)</root>', stdout, re.S) 270 m = re.search(r'<root>(.*)</root>', stdout, re.S)
270 if not m: 271 if not m:
271 raise hgutil.Abort(_('cannot find SVN repository root from %s') 272 raise hgerror.Abort(_('cannot find SVN repository root from %s')
272 % svnurl) 273 % svnurl)
273 root = m.group(1).rstrip('/') 274 root = m.group(1).rstrip('/')
274 275
275 m = re.search(r'<url>(.*)</url>', stdout, re.S) 276 m = re.search(r'<url>(.*)</url>', stdout, re.S)
276 if not m: 277 if not m:
277 raise hgutil.Abort(_('cannot find SVN repository URL from %s') % svnurl) 278 raise hgerror.Abort(_('cannot find SVN repository URL from %s') % svnurl)
278 url = m.group(1) 279 url = m.group(1)
279 280
280 m = re.search(r'<entry[^>]+revision="([^"]+)"', stdout, re.S) 281 m = re.search(r'<entry[^>]+revision="([^"]+)"', stdout, re.S)
281 if not m: 282 if not m:
282 raise hgutil.Abort(_('cannot find SVN revision from %s') % svnurl) 283 raise hgerror.Abort(_('cannot find SVN revision from %s') % svnurl)
283 rev = m.group(1) 284 rev = m.group(1)
284 return url, root, rev 285 return url, root, rev
285 286
286 class externalsupdater: 287 class externalsupdater:
287 def __init__(self, ui, repo): 288 def __init__(self, ui, repo):
346 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 347 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
347 for line in p.stdout: 348 for line in p.stdout:
348 self.ui.debug(line) 349 self.ui.debug(line)
349 p.wait() 350 p.wait()
350 if p.returncode != 0: 351 if p.returncode != 0:
351 raise hgutil.Abort("subprocess '%s' failed" % ' '.join(args)) 352 raise hgerror.Abort("subprocess '%s' failed" % ' '.join(args))
352 353
353 def updateexternals(ui, args, repo, **opts): 354 def updateexternals(ui, args, repo, **opts):
354 """update repository externals 355 """update repository externals
355 """ 356 """
356 if len(args) > 2: 357 if len(args) > 2:
357 raise hgutil.Abort(_('updateexternals expects at most one changeset')) 358 raise hgerror.Abort(_('updateexternals expects at most one changeset'))
358 node = None 359 node = None
359 if len(args) == 2: 360 if len(args) == 2:
360 svnurl = util.normalize_url(repo.ui.expandpath(args[0])) 361 svnurl = util.normalize_url(repo.ui.expandpath(args[0]))
361 args = args[1:] 362 args = args[1:]
362 else: 363 else:
382 if action == 'u': 383 if action == 'u':
383 updater.update(ext[0], ext[1], ext[2], ext[3]) 384 updater.update(ext[0], ext[1], ext[2], ext[3])
384 elif action == 'd': 385 elif action == 'd':
385 updater.delete(ext[0]) 386 updater.delete(ext[0])
386 else: 387 else:
387 raise hgutil.Abort(_('unknown update actions: %r') % action) 388 raise hgerror.Abort(_('unknown update actions: %r') % action)
388 389
389 file(repo.vfs.join('svn/externals'), 'wb').write(newext) 390 file(repo.vfs.join('svn/externals'), 'wb').write(newext)
390 391
391 def getchanges(ui, repo, parentctx, exts): 392 def getchanges(ui, repo, parentctx, exts):
392 """Take a parent changectx and the new externals definitions as an 393 """Take a parent changectx and the new externals definitions as an
419 files['.hgsub'] = ''.join(hgsub) 420 files['.hgsub'] = ''.join(hgsub)
420 files['.hgsubstate'] = ''.join(hgsubstate) 421 files['.hgsubstate'] = ''.join(hgsubstate)
421 elif mode == 'ignore': 422 elif mode == 'ignore':
422 files = {} 423 files = {}
423 else: 424 else:
424 raise hgutil.Abort(_('unknown externals modes: %s') % mode) 425 raise hgerror.Abort(_('unknown externals modes: %s') % mode)
425 426
426 # Should the really be updated? 427 # Should the really be updated?
427 updates = {} 428 updates = {}
428 for fn, data in files.iteritems(): 429 for fn, data in files.iteritems():
429 if data is not None: 430 if data is not None:
453 line = norevline.replace('{REV}', rev) 454 line = norevline.replace('{REV}', rev)
454 external.setdefault(base, []).append(line) 455 external.setdefault(base, []).append(line)
455 elif mode == 'ignore': 456 elif mode == 'ignore':
456 pass 457 pass
457 else: 458 else:
458 raise hgutil.Abort(_('unknown externals modes: %s') % mode) 459 raise hgerror.Abort(_('unknown externals modes: %s') % mode)
459 return external 460 return external
460 461
461 _notset = object() 462 _notset = object()
462 463
463 class svnsubrepo(subrepo.svnsubrepo): 464 class svnsubrepo(subrepo.svnsubrepo):