Bug 3357 - import --exact fails to import MQ-generated patch
Summary: import --exact fails to import MQ-generated patch
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-05 03:02 UTC by Stefan Ring
Modified: 2012-05-13 05:11 UTC (History)
3 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Ring 2012-04-05 03:02 UTC
This is very similar to issue 2790.

The format of the metadata at the beginning of the patch differs between
patches generated via MQ (qrefresh) and via hg export. In the MQ case, it
looks like this:

# Node ID 5f96d29476f51fbd2e2e29c8694ef7fe9fb1b226
# Parent 7b5f756b82327291e62dc7e3360cadd07b7a6207

while hg export produces this:

# Node ID b55f48d8b9d941e8d1e4a70777e032e011104404
# Parent  7b5f756b82327291e62dc7e3360cadd07b7a6207

Consequently, hg import --exact fails to apply the MQ-generated patch. It
complains thusly:

abort: unknown revision 'b5f756b82327291e62dc7e3360cadd07b7a6207'!

Note the stripped first character of the parent hash.

It would be good to make both formats equal for an improved patch handling
experience. Also, hg import --exact should be made more tolerant regarding
the formatting of the patch, like it has been done for qpush --exact before.

$ hg version
Mercurial Distributed SCM (version 2.0.2+145-878bc4a62a73)
Comment 1 Stefan Ring 2012-04-05 03:18 UTC
That the node id is different was an error on my part. The formatting of the
"Parent" line is the important part.
Comment 2 Stefan Ring 2012-04-18 03:07 UTC
I know this is not for patches, but maybe a patch fragment is tolerated.
This makes the import more tolerant.

--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -230,7 +230,7 @@
                         elif line.startswith("# Node ID "):
                             nodeid = line[10:]
                         elif line.startswith("# Parent "):
-                            parents.append(line[10:])
+                            parents.append(line[9:].strip())
                         elif not line.startswith("# "):
                             hgpatchheader = False
                     elif line == '---' and gitsendmail:
Comment 3 Patrick Mézard 2012-04-20 11:26 UTC
Thank you for the report, I have submitted a slightly different patch here:

  http://selenic.com/pipermail/mercurial-devel/2012-April/039378.html

Upgrading to bug.
Comment 4 HG Bot 2012-04-20 16:00 UTC
Fixed by http://selenic.com/repo/hg/rev/1f75c1decdeb
Patrick Mezard <patrick@mezard.eu>
patch: be more tolerant with "Parent" header (issue3356)

(please test the fix)
Comment 5 Stefan Ring 2012-04-21 09:58 UTC
Thanks for the fix. I tested it, and this specific problem is gone.

However, I still cannot import MQ-generated patches because they miss a node 
ID. I don't know where the IDs in my original examples came from, but when I 
use qnew or qrefresh now, no node ID gets written. hg import --exact complains 
about this:

abort: not a Mercurial patch
Comment 6 Patrick Mézard 2012-04-21 10:06 UTC
Could you open another issue about this?
Comment 7 Stefan Ring 2012-04-23 06:04 UTC
Done.
Comment 8 Patrick Mézard 2012-04-23 06:18 UTC
Marking this one resolved.
Comment 9 Bugzilla 2012-05-12 09:29 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:29 EDT  ---

This bug was previously known as _bug_ 3356 at http://mercurial.selenic.com/bts/issue3356