Bug 2148 - Allow “hg import” to import patches generated by “git-format-patch”
Summary: Allow “hg import” to import patches generated by “git-format-patch”
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: wish feature
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-21 02:17 UTC by Denis Defreyne
Modified: 2013-11-07 17:38 UTC (History)
7 users (show)

See Also:
Python Version: ---


Attachments
(34 bytes, application/octet-stream)
2010-04-21 02:17 UTC, Denis Defreyne
Details
Sample patchfile (1.09 KB, patch)
2012-05-21 11:46 UTC, devurandom
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Defreyne 2010-04-21 02:17 UTC
“hg import” is unable to correctly import patches generated by “git-format-
patch”.

STEPS TO REPRODUCE:

1. Create a patch from a git repository using e.g. “git format-patch -3” to 
generate patches for the last three changesets. If you don’t want to touch 
git, use the attached file. :)

2. Import the patch using “hg import <filename>”

Note: I don’t know much about git, so it’s possible that with different 
invocations of git-format-patch, the format will be different.

EXPECTED RESULTS:

The commit message should be taken from the subject. If the commit message is 
multi-line, read lines up to (but not including) a line containing only “---”.

For example, the attached patch should result in a commit message “updated 
sass test to make it work with sass 3”.

ACTUAL RESULTS:

The commit message is the following:

    updated sass test to make it work with sass 3
    ---
    test/filters/test_sass.rb | 6 +++---
    1 files changed, 3 insertions(+), 3 deletions(-)

The last three lines should not be present in the commit message.
Comment 1 Denis Defreyne 2010-04-21 02:22 UTC
One more thing: the subject, which contains the changeset message, includes a 
prefix (usually [PATCH] or [PATCH x/y] according to the man page) that should 
be stripped from the subject.

Given the large amount of options for git-format-patch, it looks like checking 
the source code for the git-am tool may be useful in order to figure out how 
these e-mails are parsed.
Comment 2 Nicolas Dumazet 2010-04-21 04:27 UTC
[PATCH] or [PATCH x/y] is already stripped correctly. Or do you have an
actual example of hg import failing to interpret those tags?

For the stats/scissors issue, I am working on a patch to add options to
import to support those.

Cheers,
Comment 3 Denis Defreyne 2010-04-21 06:03 UTC
I haven’t actually checked whether the [PATCH] or [PATCH x/y] is stripped; I 
merely wanted to mention it, just in case.
Comment 4 Keshav Kini 2012-01-17 09:17 UTC
There seems to be some activity related to this on github, if anyone's
interested: https://github.com/froydnj/patch-converter
Comment 5 Matt Mackall 2012-01-17 11:05 UTC
Pretty sure this has worked for a while now already. Tests here confirm that
bits after "--- " are properly stripped and description is subject + body.
Comment 6 Bugzilla 2012-05-12 09:08 UTC

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

This bug was previously known as _bug_ 2148 at http://mercurial.selenic.com/bts/issue2148
Imported an attachment (id=1375)
Comment 7 devurandom 2012-05-21 11:46 UTC
Created attachment 1668 [details]
Sample patchfile

The issue is back in Mercurial version 2.2.1 (maybe earlier).

Symptoms:
1) The following is not ignored:
---
 ... stats ...
diff ...

2) The Date: field is not respected.

Sample patchfile attached.
Comment 8 devurandom 2012-05-21 11:51 UTC
Further issues: Git formats Subject: lines with linebreaks, but hg does not reconcat them again.
Comment 9 devurandom 2012-05-21 11:52 UTC
(In reply to comment #8)
> Further issues: Git formats Subject: lines with linebreaks, but hg does not reconcat them again.
Sorry, that is actually a bug in https://github.com/MarkLodato/patch-converter which I used as a workaround.
Comment 10 Matt Mackall 2012-05-21 12:04 UTC
a) We expect the diffstat separator is "---[ \t]", git is apparently now generating only "---"

b) We've apparently never supported Date: headers.
Comment 11 Matt Mackall 2013-07-27 19:35 UTC
Unassign some bugs with no activity.
Comment 12 HG Bot 2013-07-30 15:45 UTC
Fixed by http://selenic.com/repo/hg/rev/9e8298a324ac
Matt Mackall <mpm@selenic.com>
import: cut commit messages at --- unconditionally (issue2148)

We used to do this based on X-mailer: mentioning git, but git doesn't
put X-mailer in its git-format-patch output.

(please test the fix)