mercurial/commands.py
changeset 2933 439fd013360d
parent 2922 773c5b82d052
child 2942 f4fc0575e8fa
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1683,44 +1683,7 @@ def import_(ui, repo, patch1, *patches, 
             ui.debug(_('message:\n%s\n') % message)
 
             files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root)
-            removes = []
-            if len(files) > 0:
-                cfiles = files.keys()
-                copies = []
-                copts = {'after': False, 'force': False}
-                cwd = repo.getcwd()
-                if cwd:
-                    cfiles = [util.pathto(cwd, f) for f in files.keys()]
-                for f in files:
-                    ctype, gp = files[f]
-                    if ctype == 'RENAME':
-                        copies.append((gp.oldpath, gp.path, gp.copymod))
-                        removes.append(gp.oldpath)
-                    elif ctype == 'COPY':
-                        copies.append((gp.oldpath, gp.path, gp.copymod))
-                    elif ctype == 'DELETE':
-                        removes.append(gp.path)
-                for src, dst, after in copies:
-                    absdst = os.path.join(repo.root, dst)
-                    if not after and os.path.exists(absdst):
-                        raise util.Abort(_('patch creates existing file %s') % dst)
-                    if cwd:
-                        src, dst = [util.pathto(cwd, f) for f in (src, dst)]
-                    copts['after'] = after
-                    errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock)
-                    if errs:
-                        raise util.Abort(errs)
-                if removes:
-                    repo.remove(removes, True, wlock=wlock)
-                for f in files:
-                    ctype, gp = files[f]
-                    if gp and gp.mode:
-                        x = gp.mode & 0100 != 0
-                        dst = os.path.join(repo.root, gp.path)
-                        util.set_exec(dst, x)
-                cmdutil.addremove(repo, cfiles, wlock=wlock)
-            files = files.keys()
-            files.extend([r for r in removes if r not in files])
+            files = patch.updatedir(ui, repo, files, wlock=wlock)
             repo.commit(files, message, user, date, wlock=wlock, lock=lock)
         finally:
             os.unlink(tmpname)