3 # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # Merge conflicted ChangeLogs
16 # tromey Mon Aug 15 1994
20 # cl-merge [-i] file ...
22 # With -i, it works in place (backups put in a ~ file). Otherwise the
23 # merged ChangeLog is printed to stdout.
25 # Please report any bugs to me. I wrote this yesterday, so there are no
26 # guarantees about its performance. I recommend checking its output
27 # carefully. If you do send a bug report, please include the failing
28 # ChangeLog, so I can include it in my test suite.
32 # tromey@busco.lanl.gov Member, League for Programming Freedom
33 # Sadism and farce are always inexplicably linked.
34 # -- Alexander Theroux
37 # Month->number mapping. Used for sorting.
51 # If '-i' is given, do it in-place.
52 if ($ARGV[0] eq '-i') {
64 # Simple state machine. The states:
66 # 0 Not in conflict. Just copy input to output.
67 # 1 Beginning an entry. Next non-blank line is key.
68 # 2 In entry. Entry beginner transitions to state 1.
70 if (/^<<<</ || /^====/) {
71 # Start of a conflict.
73 # Copy last key into array.
75 $conflist{$lastkey} = $lastval;
83 # End of conflict. Output.
85 # Copy last key into array.
87 $conflist{$lastkey} = $lastval;
93 foreach (reverse sort clcmp keys %conflist) {
94 print STDERR "doing $_" if $tjd;
103 } elsif ($conf == 1) {
104 # Beginning an entry. Skip empty lines. Error if not a real
107 # Empty line; just skip at this point.
108 } elsif (/^[MTWFS]/) {
109 # Looks like the name of a day; assume opener and move to
113 print STDERR "found $_" if $tjd;
115 die ("conflict crosses entry boundaries: $_");
117 } elsif ($conf == 2) {
118 # In entry. Copy into variable until we see beginner line.
120 # Entry beginner line.
122 # Copy last key into array.
123 if ($lastkey ne '') {
124 $conflist{$lastkey} = $lastval;
131 print STDERR "found $_" if $tjd;
142 # Compare ChangeLog time strings like <=>.
145 # Thu Aug 11 13:22:42 1994 Tom Tromey (tromey@creche.colorado.edu)
146 # 0123456789012345678901234567890
150 $r = substr ($a, 20, 4) <=> substr ($b, 20, 4);
153 $r = $months{substr ($a, 4, 3)} <=> $months{substr ($b, 4, 3)} if !$r;
156 $r = substr ($a, 8, 2) <=> substr ($b, 8, 2) if !$r;
158 # Now check time (3 parts).
159 $r = substr ($a, 11, 2) <=> substr ($b, 11, 2) if !$r;
160 $r = substr ($a, 14, 2) <=> substr ($b, 14, 2) if !$r;
161 $r = substr ($a, 17, 2) <=> substr ($b, 17, 2) if !$r;