X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=apps%2Fpatchwork%2Fparser.py;h=82959803adad45e8de0ee768ddd8e8c534cf1ca1;hb=011ee687fda0d3baf66831279565c14e411eab11;hp=2b5e9a093c478756d65ef001cdb59e48eb0af0c5;hpb=6f02427039f0a80484f99ebd4595e2ecdfc907bb;p=patchwork diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py index 2b5e9a0..8295980 100644 --- a/apps/patchwork/parser.py +++ b/apps/patchwork/parser.py @@ -45,6 +45,7 @@ def parse_patch(text): # 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:) @@ -54,6 +55,9 @@ def parse_patch(text): # 3 -> 4 (@@ line) # 4 -> 5 (patch content) # 5 -> 1 (run out of lines from @@-specifed count) + # 1 -> 6 (rename from / rename to) + # 6 -> 2 (---) + # 6 -> 1 (other text) # # Suspected patch header is stored into buf, and appended to # patchbuf if we find a following hunk. Otherwise, append to @@ -68,7 +72,7 @@ def parse_patch(text): line += '\n' if state == 0: - if line.startswith('diff') or line.startswith('===') \ + if line.startswith('diff ') or line.startswith('===') \ or line.startswith('Index: '): state = 1 buf += line @@ -85,6 +89,9 @@ def parse_patch(text): if line.startswith('--- '): state = 2 + if line.startswith('rename from ') or line.startswith('rename to '): + state = 6 + elif state == 2: if line.startswith('+++ '): state = 3 @@ -148,6 +155,20 @@ def parse_patch(text): else: state = 5 + elif state == 6: + if line.startswith('rename to ') or line.startswith('rename from '): + patchbuf += buf + line + buf = '' + + elif line.startswith('--- '): + patchbuf += buf + line + buf = '' + state = 2 + + else: + buf += line + state = 1 + else: raise Exception("Unknown state %d! (line '%s')" % (state, line))