5 # Takes the output of "cvs diff", which produces a flattened
6 # recursive diff, and unflattens it so that it can be
7 # applied correctly with "patch".
11 # Copyright (C) 2001 by Gilbert Ramirez <gram@alumni.rice.edu>
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 if len(sys.argv) == 1:
34 elif len(sys.argv) == 2:
36 input = open(sys.argv[1])
38 (exc_type, exc_value, exc_traceback) = sys.exc_info()
39 print "Cannot open %s for input: %s" % (sys.argv[1], exc_value)
42 print "Usage: %s [diff_file]" % (sys.argv[0])
47 # 0 Looking for "^Index: "
48 # 1 Looking for "^diff "
49 # 2 Looking for "^---"
50 # 3 Looking for "^+++"
56 re_index = re.compile(r"^Index: (?P<pathname>\S+)")
57 re_diff = re.compile(r"^diff ")
58 re_diff_filename = re.compile(r"\S+$")
59 re_from = re.compile(r"^--- \S+(?P<after>.*)")
60 re_to = re.compile(r"^\+\+\+ \S+(?P<after>.*)")
63 for line in input.readlines():
68 match = re_index.search(line)
70 pathname = match.group("pathname")
73 i = string.rfind(pathname, "/")
75 i = string.rfind(pathname, "\\")
78 # if there's no dir info,
79 # then there's no reason to
80 # process this section
87 match = re_diff.search(line)
89 line = re_diff_filename.sub(pathname, line)
93 if line.find("Binary files") == 0:
97 match = re_from.search(line)
99 new_line = "--- %s\\g<after>" % (pathname)
100 line = re_from.sub(new_line, line)
103 sys.stderr.write("Expected ^---, but found: %s\n" \
107 match = re_to.search(line)
109 new_line = "+++ %s\\g<after>" % (pathname)
110 line = re_to.sub(new_line, line)
113 sys.stderr.write("Expected ^+++, but found: %s\n" \