changeset 18656:8eb3408bf005

import: don't rollback on failed import --exact (issue3616) The checkexact() helper function was calling repo.rollback() from inside an open transaction. In addition to being insane, this is unnecessary because import will release the transaction on an exception. It turns out that this has been broken since the feature was first introduced, first released in v1.0: changeset: 4263:47ba52121433 user: Brendan Cully <brendan@kublai.com> date: Thu Mar 22 10:44:59 2007 -0700 files: mercurial/commands.py mercurial/patch.py description: Add import --exact. When this option is set, import will apply the patch (which must be generated by export) to the parents specified in the patch, and check that the node produced by the patch matches the node ID in the patch.
author Kevin Bullock <kbullock@ringworld.org>
date Sun, 10 Feb 2013 23:01:12 +0000
parents 882681bc3166
children 5e63a85299ba b946470efed9
files mercurial/commands.py tests/test-import-merge.t
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Feb 10 16:22:32 2013 -0800
+++ b/mercurial/commands.py	Sun Feb 10 23:01:12 2013 +0000
@@ -3812,7 +3812,6 @@
 
     def checkexact(repo, n, nodeid):
         if opts.get('exact') and hex(n) != nodeid:
-            repo.rollback()
             raise util.Abort(_('patch is damaged or loses information'))
 
     def tryone(ui, hunk, parents):
--- a/tests/test-import-merge.t	Sun Feb 10 16:22:32 2013 -0800
+++ b/tests/test-import-merge.t	Sun Feb 10 23:01:12 2013 +0000
@@ -113,3 +113,41 @@
   $ hg strip --no-backup tip
 
   $ cd ..
+
+Test that --exact on a bad header doesn't corrupt the repo (issue3616)
+
+  $ hg init repo3
+  $ cd repo3
+  $ echo a>a
+  $ hg ci -Aqm0
+  $ echo a>>a
+  $ hg ci -m1
+  $ echo a>>a
+  $ hg ci -m2
+  $ echo a>a
+  $ echo b>>a
+  $ echo a>>a
+  $ hg ci -m3
+  $ hg export 2 | head -7 > ../a.patch
+  $ hg export tip | tail -n +8 >> ../a.patch
+
+  $ cd ..
+  $ hg clone -qr0 repo3 repo3-clone
+  $ cd repo3-clone
+  $ hg pull -qr1 ../repo3
+
+  $ hg import --exact ../a.patch
+  applying ../a.patch
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  patching file a
+  Hunk #1 succeeded at 1 with fuzz 1 (offset -1 lines).
+  transaction abort!
+  rollback completed
+  abort: patch is damaged or loses information
+  [255]
+  $ hg verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  1 files, 2 changesets, 2 total revisions