2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org 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 Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
35 # command line arguments
36 my $oldpatchfile = shift;
37 my $newpatchfile = shift;
38 my $sortedfile = shift;
40 show_help
() unless defined $oldpatchfile and defined $newpatchfile and defined $sortedfile;
42 my %oldpatchfile = parse_patch
($oldpatchfile);
43 my %newpatchfile = parse_patch
($newpatchfile);
45 open SORTEDPATCH
, "> $sortedfile";
47 foreach my $file (sort (keys %newpatchfile)) {
48 print SORTEDPATCH
$file."\t";
49 if (defined($oldpatchfile{$file})) {
50 if ( (join '', @
{$oldpatchfile{$file}{'data'}}) eq (join '', @
{$newpatchfile{$file}{'data'}}) ) {
51 # patch data for the file hasn't been modified, use the header from
52 # the old patch, to reduce noise (keep the old timestamps)
53 print SORTEDPATCH
$oldpatchfile{$file}{'origtimestamp'}."\n";
54 print SORTEDPATCH
$oldpatchfile{$file}{'patchedfilename'}."\t";
55 print SORTEDPATCH
$oldpatchfile{$file}{'patchedtimestamp'}."\n";
56 print SORTEDPATCH @
{$oldpatchfile{$file}{'data'}};
60 # either file wasn't patched before, or the patchset changed, so use the new
62 print SORTEDPATCH
$newpatchfile{$file}{'origtimestamp'}."\n";
63 print SORTEDPATCH
$newpatchfile{$file}{'patchedfilename'}."\t";
64 print SORTEDPATCH
$newpatchfile{$file}{'patchedtimestamp'}."\n";
65 print SORTEDPATCH @
{$newpatchfile{$file}{'data'}};
73 print "Usage: $0 oldpatch newpatch outputfilename\n";
74 print "oldpatch and newpatch can be the very same file\n";
75 print "will output a sanitized form of newpatch to outputfilename\n";
76 print "if outputfilename is '-', the patch will be printed to stdout\n";
77 print "sanitized means: It will avoid all unnecessary changes\n";
81 my $patchfile = shift;
88 open PATCHFILE
, "< $patchfile" or die "Cannot open file $patchfile $!";
89 my @patchfile = <PATCHFILE
>;
91 return %hunks if ( $#patchfile == -1 );
92 if ( $patchfile[0] =~ /^---/ ) {
93 $patchtype = "unified";
94 $pfirst = '^--- [^\*]*$';
95 $psecond = '^\+\+\+ [^\*]*$';
96 } elsif ( $patchfile[0] =~ /^\*\*\*/ ) {
97 $patchtype = "content";
98 $pfirst = '^\*\*\* [^\*]*$';
99 $psecond = '^--- .*\t.*$';
101 die "unknown patch format\n";
104 foreach (@patchfile) {
107 # extract the filename, to be able to compare the old
108 # with the new file...
109 ($origfilename, $timestamp) = split(/\t/, $_, 2);
111 # ideally convert the timestamp to iso-format...
112 $hunks{$origfilename}{'origtimestamp'} = $timestamp;
114 } elsif ( $_ =~ /$psecond/ ) {
115 my ($filename, $timestamp) = split(/\t/, $_, 2);
117 # ideally convert the timestamp to iso-format...
118 $hunks{$origfilename}{'patchedfilename'} = $filename;
119 $hunks{$origfilename}{'patchedtimestamp'} = $timestamp;
122 push (@
{$hunks{$origfilename}{'data'}}, $_);