comparison hgext/mq.py @ 5981:ca2af0c81c9a

mq: don't allow patches with some reserved names The current list of reserved names includes only mq control files. Also, reserve names starting with ".hg" (to avoid troubles with e.g. .hgignore and .hgtags), and with ".mq" (to allow future extensions). This should fix issue841.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sun, 03 Feb 2008 21:03:46 -0200
parents dcda0c90125c
children f2201aee3dc8
comparison
equal deleted inserted replaced
5980:dcda0c90125c 5981:ca2af0c81c9a
598 raise util.Abort(_("local changes found, refresh first")) 598 raise util.Abort(_("local changes found, refresh first"))
599 else: 599 else:
600 raise util.Abort(_("local changes found")) 600 raise util.Abort(_("local changes found"))
601 return m, a, r, d 601 return m, a, r, d
602 602
603 _reserved = ('series', 'status', 'guards')
604 def check_reserved_name(self, name):
605 if (name in self._reserved or name.startswith('.hg')
606 or name.startswith('.mq')):
607 raise util.Abort(_('"%s" cannot be used as the name of a patch')
608 % name)
609
603 def new(self, repo, patch, *pats, **opts): 610 def new(self, repo, patch, *pats, **opts):
604 msg = opts.get('msg') 611 msg = opts.get('msg')
605 force = opts.get('force') 612 force = opts.get('force')
613 self.check_reserved_name(patch)
606 if os.path.exists(self.join(patch)): 614 if os.path.exists(self.join(patch)):
607 raise util.Abort(_('patch "%s" already exists') % patch) 615 raise util.Abort(_('patch "%s" already exists') % patch)
608 if opts.get('include') or opts.get('exclude') or pats: 616 if opts.get('include') or opts.get('exclude') or pats:
609 fns, match, anypats = cmdutil.matchpats(repo, pats, opts) 617 fns, match, anypats = cmdutil.matchpats(repo, pats, opts)
610 m, a, r, d = repo.status(files=fns, match=match)[:4] 618 m, a, r, d = repo.status(files=fns, match=match)[:4]
1370 % (r, lastparent)) 1378 % (r, lastparent))
1371 lastparent = p1 1379 lastparent = p1
1372 1380
1373 if not patchname: 1381 if not patchname:
1374 patchname = normname('%d.diff' % r) 1382 patchname = normname('%d.diff' % r)
1383 self.check_reserved_name(patchname)
1375 checkseries(patchname) 1384 checkseries(patchname)
1376 checkfile(patchname) 1385 checkfile(patchname)
1377 self.full_series.insert(0, patchname) 1386 self.full_series.insert(0, patchname)
1378 1387
1379 patchf = self.opener(patchname, "w") 1388 patchf = self.opener(patchname, "w")
1392 if existing: 1401 if existing:
1393 if filename == '-': 1402 if filename == '-':
1394 raise util.Abort(_('-e is incompatible with import from -')) 1403 raise util.Abort(_('-e is incompatible with import from -'))
1395 if not patchname: 1404 if not patchname:
1396 patchname = normname(filename) 1405 patchname = normname(filename)
1406 self.check_reserved_name(patchname)
1397 if not os.path.isfile(self.join(patchname)): 1407 if not os.path.isfile(self.join(patchname)):
1398 raise util.Abort(_("patch %s does not exist") % patchname) 1408 raise util.Abort(_("patch %s does not exist") % patchname)
1399 else: 1409 else:
1400 try: 1410 try:
1401 if filename == '-': 1411 if filename == '-':
1406 text = file(filename).read() 1416 text = file(filename).read()
1407 except IOError: 1417 except IOError:
1408 raise util.Abort(_("unable to read %s") % patchname) 1418 raise util.Abort(_("unable to read %s") % patchname)
1409 if not patchname: 1419 if not patchname:
1410 patchname = normname(os.path.basename(filename)) 1420 patchname = normname(os.path.basename(filename))
1421 self.check_reserved_name(patchname)
1411 checkfile(patchname) 1422 checkfile(patchname)
1412 patchf = self.opener(patchname, "w") 1423 patchf = self.opener(patchname, "w")
1413 patchf.write(text) 1424 patchf.write(text)
1414 checkseries(patchname) 1425 checkseries(patchname)
1415 index = self.full_series_end() + i 1426 index = self.full_series_end() + i