[PATCH 1 of 1] import: don't strip '#' lines from patch descriptions (issue 2417)

Mads Kiilerich mads at kiilerich.com
Mon Oct 4 17:20:09 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1286230714 -7200
# Node ID 8ce0d8fad39211a71597ac5193ab42f7287f465d
# Parent  0f78732c5ceb1ed12836ddbe5f74818c0bcd22b4
import: don't strip '#' lines from patch descriptions (issue 2417)

Previously no '# ' lines came through the parser.

Now we only give such lines special handling when reading hg patch headers.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -224,6 +224,7 @@
             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 @@
                 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 @@
                             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 @@
   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 ..


More information about the Mercurial-devel mailing list