4 # Copyright © 2009 Germán Póo-Caamaño <gpoo@gnome.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 from patterns
import patterns
23 class LogPatchSplitter
:
25 LogPatchSplitters provides a iterator to extract every
26 changeset from a git log output.
30 patches = LogPatchSplitter(sys.stdin)
36 def __init__(self
, fd
):
41 # We need to avoid decoding errors during the parsing of
42 # patches and using "surrogateescape" allow for encoding
43 # methods to restore the byte if need.
44 self
.fd
.reconfigure(errors
="surrogateescape")
50 patch
= self
.__grab
_patch
__()
55 def __grab_patch__(self
):
57 Extract a patch from the file descriptor and the
58 patch is returned as a list of lines.
62 line
= self
.buffer or self
.fd
.readline()
65 if line
.startswith('commit '):
68 line
= self
.fd
.readline()
73 line
= self
.fd
.readline()
75 # If this line starts a new commit, drop out.
76 if line
.startswith ('commit '):
82 line
= self
.fd
.readline()
87 if __name__
== '__main__':
88 patches
= LogPatchSplitter(sys
.stdin
)
91 print('---------- NEW PATCH ----------')