changeset 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
files hgext/mq.py
diffstat 1 files changed, 5 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Tue May 24 19:16:51 2011 +0300
+++ b/hgext/mq.py	Tue May 24 19:16:51 2011 +0300
@@ -892,14 +892,7 @@
         if date:
             date = util.parsedate(date)
         diffopts = self.diffopts({'git': opts.get('git')})
-        self.check_reserved_name(patchfn)
-        if os.path.exists(self.join(patchfn)):
-            if os.path.isdir(self.join(patchfn)):
-                raise util.Abort(_('"%s" already exists as a directory')
-                                 % patchfn)
-            else:
-                raise util.Abort(_('patch "%s" already exists') % patchfn)
-
+        self.checkpatchname(patchfn)
         inclsubs = self.check_substate(repo)
         if inclsubs:
             inclsubs.append('.hgsubstate')
@@ -1747,10 +1740,6 @@
             if patchname in self.series:
                 raise util.Abort(_('patch %s is already in the series file')
                                  % patchname)
-        def checkfile(patchname):
-            if not force and os.path.exists(self.join(patchname)):
-                raise util.Abort(_('patch "%s" already exists')
-                                 % patchname)
 
         if rev:
             if files:
@@ -1798,9 +1787,8 @@
 
                 if not patchname:
                     patchname = normname('%d.diff' % r)
-                self.check_reserved_name(patchname)
                 checkseries(patchname)
-                checkfile(patchname)
+                self.checkpatchname(patchname, force)
                 self.full_series.insert(0, patchname)
 
                 patchf = self.opener(patchname, "w")
@@ -1827,8 +1815,7 @@
                     raise util.Abort(_("patch %s does not exist") % filename)
 
                 if patchname:
-                    self.check_reserved_name(patchname)
-                    checkfile(patchname)
+                    self.checkpatchname(patchname, force)
 
                     self.ui.write(_('renaming %s to %s\n')
                                         % (filename, patchname))
@@ -1841,8 +1828,7 @@
                     raise util.Abort(_('need --name to import a patch from -'))
                 elif not patchname:
                     patchname = normname(os.path.basename(filename.rstrip('/')))
-                self.check_reserved_name(patchname)
-                checkfile(patchname)
+                self.checkpatchname(patchname, force)
                 try:
                     if filename == '-':
                         text = sys.stdin.read()
@@ -2606,12 +2592,7 @@
     if os.path.isdir(absdest):
         name = normname(os.path.join(name, os.path.basename(patch)))
         absdest = q.join(name)
-    if os.path.exists(absdest):
-        raise util.Abort(_('%s already exists') % absdest)
-
-    if name in q.series:
-        raise util.Abort(
-            _('A patch named %s already exists in the series file') % name)
+    q.checkpatchname(name)
 
     ui.note(_('renaming %s to %s\n') % (patch, name))
     i = q.find_series(patch)