comparison hgext/mq.py @ 14423:7230aef66b7c

mq: use checkpatchname This also fixes a bug where qrename would allow renaming a patch to a reserved name.
author Idan Kamara <idankk86@gmail.com>
date Tue, 24 May 2011 19:16:51 +0300
parents 2e77525e52d9
children 4eb88d296f63
comparison
equal deleted inserted replaced
14422:2e77525e52d9 14423:7230aef66b7c
890 user = opts.get('user') 890 user = opts.get('user')
891 date = opts.get('date') 891 date = opts.get('date')
892 if date: 892 if date:
893 date = util.parsedate(date) 893 date = util.parsedate(date)
894 diffopts = self.diffopts({'git': opts.get('git')}) 894 diffopts = self.diffopts({'git': opts.get('git')})
895 self.check_reserved_name(patchfn) 895 self.checkpatchname(patchfn)
896 if os.path.exists(self.join(patchfn)):
897 if os.path.isdir(self.join(patchfn)):
898 raise util.Abort(_('"%s" already exists as a directory')
899 % patchfn)
900 else:
901 raise util.Abort(_('patch "%s" already exists') % patchfn)
902
903 inclsubs = self.check_substate(repo) 896 inclsubs = self.check_substate(repo)
904 if inclsubs: 897 if inclsubs:
905 inclsubs.append('.hgsubstate') 898 inclsubs.append('.hgsubstate')
906 if opts.get('include') or opts.get('exclude') or pats: 899 if opts.get('include') or opts.get('exclude') or pats:
907 if inclsubs: 900 if inclsubs:
1745 force=None, git=False): 1738 force=None, git=False):
1746 def checkseries(patchname): 1739 def checkseries(patchname):
1747 if patchname in self.series: 1740 if patchname in self.series:
1748 raise util.Abort(_('patch %s is already in the series file') 1741 raise util.Abort(_('patch %s is already in the series file')
1749 % patchname) 1742 % patchname)
1750 def checkfile(patchname):
1751 if not force and os.path.exists(self.join(patchname)):
1752 raise util.Abort(_('patch "%s" already exists')
1753 % patchname)
1754 1743
1755 if rev: 1744 if rev:
1756 if files: 1745 if files:
1757 raise util.Abort(_('option "-r" not valid when importing ' 1746 raise util.Abort(_('option "-r" not valid when importing '
1758 'files')) 1747 'files'))
1796 % (r, lastparent)) 1785 % (r, lastparent))
1797 lastparent = p1 1786 lastparent = p1
1798 1787
1799 if not patchname: 1788 if not patchname:
1800 patchname = normname('%d.diff' % r) 1789 patchname = normname('%d.diff' % r)
1801 self.check_reserved_name(patchname)
1802 checkseries(patchname) 1790 checkseries(patchname)
1803 checkfile(patchname) 1791 self.checkpatchname(patchname, force)
1804 self.full_series.insert(0, patchname) 1792 self.full_series.insert(0, patchname)
1805 1793
1806 patchf = self.opener(patchname, "w") 1794 patchf = self.opener(patchname, "w")
1807 cmdutil.export(repo, [n], fp=patchf, opts=diffopts) 1795 cmdutil.export(repo, [n], fp=patchf, opts=diffopts)
1808 patchf.close() 1796 patchf.close()
1825 originpath = self.join(filename) 1813 originpath = self.join(filename)
1826 if not os.path.isfile(originpath): 1814 if not os.path.isfile(originpath):
1827 raise util.Abort(_("patch %s does not exist") % filename) 1815 raise util.Abort(_("patch %s does not exist") % filename)
1828 1816
1829 if patchname: 1817 if patchname:
1830 self.check_reserved_name(patchname) 1818 self.checkpatchname(patchname, force)
1831 checkfile(patchname)
1832 1819
1833 self.ui.write(_('renaming %s to %s\n') 1820 self.ui.write(_('renaming %s to %s\n')
1834 % (filename, patchname)) 1821 % (filename, patchname))
1835 util.rename(originpath, self.join(patchname)) 1822 util.rename(originpath, self.join(patchname))
1836 else: 1823 else:
1839 else: 1826 else:
1840 if filename == '-' and not patchname: 1827 if filename == '-' and not patchname:
1841 raise util.Abort(_('need --name to import a patch from -')) 1828 raise util.Abort(_('need --name to import a patch from -'))
1842 elif not patchname: 1829 elif not patchname:
1843 patchname = normname(os.path.basename(filename.rstrip('/'))) 1830 patchname = normname(os.path.basename(filename.rstrip('/')))
1844 self.check_reserved_name(patchname) 1831 self.checkpatchname(patchname, force)
1845 checkfile(patchname)
1846 try: 1832 try:
1847 if filename == '-': 1833 if filename == '-':
1848 text = sys.stdin.read() 1834 text = sys.stdin.read()
1849 else: 1835 else:
1850 fp = url.open(self.ui, filename) 1836 fp = url.open(self.ui, filename)
2604 patch = q.lookup('qtip') 2590 patch = q.lookup('qtip')
2605 absdest = q.join(name) 2591 absdest = q.join(name)
2606 if os.path.isdir(absdest): 2592 if os.path.isdir(absdest):
2607 name = normname(os.path.join(name, os.path.basename(patch))) 2593 name = normname(os.path.join(name, os.path.basename(patch)))
2608 absdest = q.join(name) 2594 absdest = q.join(name)
2609 if os.path.exists(absdest): 2595 q.checkpatchname(name)
2610 raise util.Abort(_('%s already exists') % absdest)
2611
2612 if name in q.series:
2613 raise util.Abort(
2614 _('A patch named %s already exists in the series file') % name)
2615 2596
2616 ui.note(_('renaming %s to %s\n') % (patch, name)) 2597 ui.note(_('renaming %s to %s\n') % (patch, name))
2617 i = q.find_series(patch) 2598 i = q.find_series(patch)
2618 guards = q.guard_re.findall(q.full_series[i]) 2599 guards = q.guard_re.findall(q.full_series[i])
2619 q.full_series[i] = name + ''.join([' #' + g for g in guards]) 2600 q.full_series[i] = name + ''.join([' #' + g for g in guards])