Patchwork [2,of,2] record: ignore trailing content when parsing patches - introduce 'other' lines

login
register
mail settings
Submitter Mads Kiilerich
Date April 11, 2013, 8:34 p.m.
Message ID <d4beb04d87b5bbd88870.1365712449@mk-desktop>
Download mbox | patch
Permalink /patch/1276/
State Superseded
Commit b1639e98e8a1aef318ff6de5ae8afd0b9d015f7f
Headers show

Comments

Mads Kiilerich - April 11, 2013, 8:34 p.m.
# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1339621594 -7200
#      Wed Jun 13 23:06:34 2012 +0200
# Node ID d4beb04d87b5bbd88870b6d1fd87a72e30d62cd3
# Parent  fe1960882df771438b584169b37608f2ffb74923
record: ignore trailing content when parsing patches - introduce 'other' lines

This makes record work more like import which ignores for instance mail footers
in a patch file.

This also makes it possible for TortoiseHg to preview unapplied patches
containing such footers.
Bryan O'Sullivan - April 12, 2013, 4:37 p.m.
On Thu, Apr 11, 2013 at 1:34 PM, Mads Kiilerich <mads@kiilerich.com> wrote:

> record: ignore trailing content when parsing patches - introduce 'other'
> lines
>

Looks reasonable. I assume these 'other' things are generated by the patch
code?
Mads Kiilerich - April 12, 2013, 4:53 p.m.
On 04/12/2013 06:37 PM, Bryan O'Sullivan wrote:
>
> On Thu, Apr 11, 2013 at 1:34 PM, Mads Kiilerich <mads@kiilerich.com 
> <mailto:mads@kiilerich.com>> wrote:
>
>     record: ignore trailing content when parsing patches - introduce
>     'other' lines
>
>
> Looks reasonable. I assume these 'other' things are generated by the 
> patch code?

EPARSE. But yes, it is code all the way down ;-)

'other' is a new line type I introduce and thus a new state in your 
state machine.

/Mads

Patch

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -76,7 +76,7 @@ 
             if m:
                 yield 'range', m.groups()
             else:
-                raise patch.PatchError('unknown patch content: %r' % line)
+                yield 'other', line
 
 class header(object):
     """patch header
@@ -228,6 +228,9 @@ 
             self.headers.append(h)
             self.header = h
 
+        def addother(self, line):
+            pass # 'other' lines are ignored
+
         def finished(self):
             self.addcontext([])
             return self.headers
@@ -239,12 +242,14 @@ 
                      'range': addrange},
             'context': {'file': newfile,
                         'hunk': addhunk,
-                        'range': addrange},
+                        'range': addrange,
+                        'other': addother},
             'hunk': {'context': addcontext,
                      'file': newfile,
                      'range': addrange},
             'range': {'context': addcontext,
                       'hunk': addhunk},
+            'other': {'other': addother},
             }
 
     p = parser()
diff --git a/tests/test-record.t b/tests/test-record.t
--- a/tests/test-record.t
+++ b/tests/test-record.t
@@ -1036,10 +1036,10 @@ 
   $ hg up -C
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
 
-Editing patch
+Editing patch (and ignoring trailing text)
 
   $ cat > editor.sh << '__EOF__'
-  > sed -e 7d -e '5s/^-/ /' "$1" > tmp
+  > sed -e 7d -e '5s/^-/ /' -e '/^# ---/itrailing\nditto' "$1" > tmp
   > mv tmp "$1"
   > __EOF__
   $ cat > editedfile << '__EOF__'
@@ -1201,6 +1201,8 @@ 
   abort: error parsing patch: unhandled transition: range -> range
   [255]
 
+random text in random positions is still an error
+
   $ cat > editor.sh << '__EOF__'
   > sed -e '/^@/iother' "$1" > tmp
   > mv tmp "$1"
@@ -1220,7 +1222,7 @@ 
   +This is the second line
   +This line has been added
   record this change to 'editedfile'? [Ynesfdaq?] 
-  abort: error parsing patch: unknown patch content: 'other\n'
+  abort: error parsing patch: unhandled transition: file -> other
   [255]
 
   $ hg up -C