3 # Merge conflicted ChangeLogs
4 # tromey Mon Aug 15 1994
8 # cl-merge [-i] file ...
10 # With -i, it works in place (backups put in a ~ file). Otherwise the
11 # merged ChangeLog is printed to stdout.
13 # Please report any bugs to me. I wrote this yesterday, so there are no
14 # guarantees about its performance. I recommend checking its output
15 # carefully. If you do send a bug report, please include the failing
16 # ChangeLog, so I can include it in my test suite.
20 # tromey@busco.lanl.gov Member, League for Programming Freedom
21 # Sadism and farce are always inexplicably linked.
22 # -- Alexander Theroux
25 # Month->number mapping. Used for sorting.
39 # If '-i' is given, do it in-place.
40 if ($ARGV[0] eq '-i') {
52 # Simple state machine. The states:
54 # 0 Not in conflict. Just copy input to output.
55 # 1 Beginning an entry. Next non-blank line is key.
56 # 2 In entry. Entry beginner transitions to state 1.
58 if (/^<<<</ || /^====/) {
59 # Start of a conflict.
61 # Copy last key into array.
63 $conflist{$lastkey} = $lastval;
71 # End of conflict. Output.
73 # Copy last key into array.
75 $conflist{$lastkey} = $lastval;
81 foreach (reverse sort clcmp
keys %conflist) {
82 print STDERR
"doing $_" if $tjd;
91 } elsif ($conf == 1) {
92 # Beginning an entry. Skip empty lines. Error if not a real
95 # Empty line; just skip at this point.
96 } elsif (/^[MTWFS]/) {
97 # Looks like the name of a day; assume opener and move to
101 print STDERR
"found $_" if $tjd;
103 die ("conflict crosses entry boundaries: $_");
105 } elsif ($conf == 2) {
106 # In entry. Copy into variable until we see beginner line.
108 # Entry beginner line.
110 # Copy last key into array.
111 if ($lastkey ne '') {
112 $conflist{$lastkey} = $lastval;
119 print STDERR
"found $_" if $tjd;
130 # Compare ChangeLog time strings like <=>.
133 # Thu Aug 11 13:22:42 1994 Tom Tromey (tromey@creche.colorado.edu)
134 # 0123456789012345678901234567890
138 $r = substr ($a, 20, 4) <=> substr ($b, 20, 4);
141 $r = $months{substr ($a, 4, 3)} <=> $months{substr ($b, 4, 3)} if !$r;
144 $r = substr ($a, 8, 2) <=> substr ($b, 8, 2) if !$r;
146 # Now check time (3 parts).
147 $r = substr ($a, 11, 2) <=> substr ($b, 11, 2) if !$r;
148 $r = substr ($a, 14, 2) <=> substr ($b, 14, 2) if !$r;
149 $r = substr ($a, 17, 2) <=> substr ($b, 17, 2) if !$r;