diff options
author | gram <gram@f5534014-38df-0310-8fa8-9805f1628bb7> | 2001-02-23 16:30:51 +0000 |
---|---|---|
committer | gram <gram@f5534014-38df-0310-8fa8-9805f1628bb7> | 2001-02-23 16:30:51 +0000 |
commit | 907e5975edda3201e972791b7fb2cc0b477fa958 (patch) | |
tree | 92539f5462e02caded436628bf40f081e6f1aa46 /tools | |
parent | 23127ce53154639278f4c86e68fbb537e7a915b8 (diff) |
Add a little script which takes the output of "cvs diff", which is
a flattened recursive diff, and unflattens it, so that it can
be applied with "patch -p0". This has tested only against the output
of "cvs diff -u".
Usage:
cvs diff -u | cvsdiff-fix.py > file.diff
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@3071 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 3 | ||||
-rwxr-xr-x | tools/cvsdiff-fix.py | 112 |
2 files changed, 114 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index e23a800eaf..05e7068f8c 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,4 +1,5 @@ SUBDIRS = lemon EXTRA_DIST = \ - Makefile.nmake + Makefile.nmake \ + cvsdiff-fix.py diff --git a/tools/cvsdiff-fix.py b/tools/cvsdiff-fix.py new file mode 100755 index 0000000000..93c50def25 --- /dev/null +++ b/tools/cvsdiff-fix.py @@ -0,0 +1,112 @@ +#!/usr/bin/python +# +# cvsdiff-fix +# +# Takes the output of "cvs diff", which produces a flattened +# recursive diff, and unflattens it so that it can be +# applied correctly with "patch". +# +# $Id: cvsdiff-fix.py,v 1.1 2001/02/23 16:30:51 gram Exp $ +# +# Copyright (C) 2001 by Gilbert Ramirez <gram@xiexie.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import sys +import re +import string + +# Open input stream +if len(sys.argv) == 1: + input = sys.stdin +elif len(sys.argv) == 2: + try: + input = open(sys.argv[1]) + except IOError: + (exc_type, exc_value, exc_traceback) = sys.exc_info() + print "Cannot open %s for input: %s" % (sys.argv[1], exc_value) + sys.exit(1) +else: + print "Usage: %s [diff_file]" % (sys.argv[0]) + sys.exit(1) + +# State Meaning +# ----- ------- +# 0 Looking for "^Index: " +# 1 Looking for "^diff " +# 2 Looking for "^---" +# 3 Looking for "^+++" + +state = 0 +pathname = None +basename = None + +re_index = re.compile(r"^Index: (?P<pathname>\S+)") +re_diff = re.compile(r"^diff ") +re_diff_filename = re.compile(r"\S+$") +re_from = re.compile(r"^--- \S+(?P<after>.*)") +re_to = re.compile(r"^\+\+\+ \S+(?P<after>.*)") + + +for line in input.readlines(): + if line[-1] == "\n": + line = line[:-1] + + if state == 0: + match = re_index.search(line) + if match: + pathname = match.group("pathname") + + # Find basename + i = string.rfind(pathname, "/") + if i == -1: + i = string.rfind(pathname, "\\") + + if i == -1: + # if there's no dir info, + # then there's no reason to + # process this section + pass + else: + basename = line[i+1:] + state = 1 + + elif state == 1: + match = re_diff.search(line) + if match: + line = re_diff_filename.sub(pathname, line) + state = 2 + + elif state == 2: + match = re_from.search(line) + if match: + new_line = "--- %s\\g<after>" % (pathname) + line = re_from.sub(new_line, line) + state = 3 + else: + sys.stderr.write("Expected ^---, but found: %s\n" \ + % (line)) + + elif state == 3: + match = re_to.search(line) + if match: + new_line = "+++ %s\\g<after>" % (pathname) + line = re_to.sub(new_line, line) + state = 0 + else: + sys.stderr.write("Expected ^+++, but found: %s\n" \ + % (line)) + + print line |