Skip to content

Commit

Permalink
parser: fix parsing of patches with headings
Browse files Browse the repository at this point in the history
Some people tend to use lines full of '=' as a fancy way to format headings
in their commit messages in a rst-like style. However, the current parser
treats such lines as a beginning of a diff.

The only currently used tool that produces diffs with '=' lines is quilt in
the default configuration. However, even with quilt, the diff looks this
way:

    Index: dir/file
    ===================================================================
    --- dir.orig/file
    +++ dir/file
    @@ ...etc...

It's enough to match on the "Index:" line. The state of the state machine is
kept at 1 when it encounters the '=' line, thus it's safe to remove the
match on '=' completely.

[This prevents us from properly parsing metadata out of the changelog. -dcz ]

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
Jiri Benc authored and stephenfin committed Jul 13, 2018
1 parent d6491b5 commit 67faf96
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions patchwork/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,15 @@ def parse_patch(content):
# state specified the line we just saw, and what to expect next
state = 0
# 0: text
# 1: suspected patch header (diff, ====, Index:)
# 1: suspected patch header (diff, Index:)
# 2: patch header line 1 (---)
# 3: patch header line 2 (+++)
# 4: patch hunk header line (@@ line)
# 5: patch hunk content
# 6: patch meta header (rename from/rename to)
#
# valid transitions:
# 0 -> 1 (diff, ===, Index:)
# 0 -> 1 (diff, Index:)
# 0 -> 2 (---)
# 1 -> 2 (---)
# 2 -> 3 (+++)
Expand All @@ -776,7 +776,7 @@ def parse_patch(content):
line += '\n'

if state == 0:
if line.startswith('diff ') or line.startswith('===') \
if line.startswith('diff ') \
or line.startswith('Index: '):
state = 1
buf += line
Expand Down

0 comments on commit 67faf96

Please sign in to comment.