changeset 12728:80a3d1121c10

import: only the first hg patch marker should be processed (issue2417) Proper use of the hgpatch state variable had been lost in the final edits of d7452292f9d3 - now it works more like intended.
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 14 Oct 2010 01:28:29 +0200
parents 52971985be14
children 55f0648c7e2d
files mercurial/patch.py tests/test-patch.t
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Fri Sep 10 10:28:18 2010 +0200
+++ b/mercurial/patch.py	Thu Oct 14 01:28:29 2010 +0200
@@ -228,8 +228,9 @@
                 diffs_seen += 1
                 cfp = cStringIO.StringIO()
                 for line in payload[:m.start(0)].splitlines():
-                    if line.startswith('# HG changeset patch'):
+                    if line.startswith('# HG changeset patch') and not hgpatch:
                         ui.debug('patch generated by hg export\n')
+                        hgpatch = True
                         hgpatchheader = True
                         # drop earlier commit message content
                         cfp.seek(0)
@@ -249,7 +250,6 @@
                             parents.append(line[10:])
                         elif not line.startswith("# "):
                             hgpatchheader = False
-                            hgpatch = True
                     elif line == '---' and gitsendmail:
                         ignoretext = True
                     if not hgpatchheader and not ignoretext:
--- a/tests/test-patch.t	Fri Sep 10 10:28:18 2010 +0200
+++ b/tests/test-patch.t	Thu Oct 14 01:28:29 2010 +0200
@@ -51,8 +51,11 @@
   $ hg ci -A -m 0 a -d '0 0'
   $ echo 1 >> a
   $ cat << eof > log
-  > 1
-  > # comment for 1
+  > first line which can't start with '# '
+  > # second line is a comment but that shouldn't be a problem.
+  > A patch marker like this was more problematic even after d7452292f9d3:
+  > # HG changeset patch
+  > # User lines looks like this - but it _is_ just a comment
   > eof
   $ hg ci -l log -d '0 0'
   $ hg export -o p 1
@@ -72,14 +75,17 @@
   $ hg import ../c/p
   applying ../c/p
   $ hg log -v -r 1
-  changeset:   1:89bf2f6d8088
+  changeset:   1:e8cc66fbbaa6
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   files:       a
   description:
-  1
-  # comment for 1
+  first line which can't start with '# '
+  # second line is a comment but that shouldn't be a problem.
+  A patch marker like this was more problematic even after d7452292f9d3:
+  # HG changeset patch
+  # User lines looks like this - but it _is_ just a comment
   
   
   $ cd ..