diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -224,6 +224,7 @@ def extract(ui, fileobj): m = diffre.search(payload) if m: hgpatch = False + hgpatchheader = False ignoretext = False ui.debug('found patch at byte %d\n' % m.start(0)) @@ -232,12 +233,12 @@ def extract(ui, fileobj): for line in payload[:m.start(0)].splitlines(): if line.startswith('# HG changeset patch'): ui.debug('patch generated by hg export\n') - hgpatch = True + hgpatchheader = True # drop earlier commit message content cfp.seek(0) cfp.truncate() subject = None - elif hgpatch: + elif hgpatchheader: if line.startswith('# User '): user = line[7:] ui.debug('From: %s\n' % user) @@ -249,9 +250,12 @@ def extract(ui, fileobj): nodeid = line[10:] elif line.startswith("# Parent "): parents.append(line[10:]) + elif not line.startswith("# "): + hgpatchheader = False + hgpatch = True elif line == '---' and gitsendmail: ignoretext = True - if not line.startswith('# ') and not ignoretext: + if not hgpatchheader and not ignoretext: cfp.write(line) cfp.write('\n') message = cfp.getvalue() diff --git a/tests/test-patch.t b/tests/test-patch.t --- a/tests/test-patch.t +++ b/tests/test-patch.t @@ -39,3 +39,47 @@ check custom patch options are honored applying ../a.diff Using custom patch + +Issue2417: hg import with # comments in description + +Prepare source repo and patch: + + $ rm $HGRCPATH + $ hg init c + $ cd c + $ echo 0 > a + $ hg ci -A -m 0 a -d '0 0' + $ echo 1 >> a + $ cat << eof > log + > 1 + > # comment for 1 + > eof + $ hg ci -l log -d '0 0' + $ hg export -o p 1 + $ cd .. + +Clone and apply patch: + + $ hg clone -r 0 c d + requesting all changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + updating to branch default + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ cd d + $ hg import ../c/p + applying ../c/p + $ hg log -v -r 1 + changeset: 1:89bf2f6d8088 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + files: a + description: + 1 + # comment for 1 + + + $ cd ..