rundiff (354:fbfbff4f09c3) | rundiff (404:9d95995db57c) |
---|---|
1#! /usr/bin/env perl 2 3# Copyright (c) 2003 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 177 unchanged lines hidden (view full) --- 186 # complete diff of both lookahead buffers, all we use it for 187 # is to figure out how many lines to discard off the front of 188 # each buffer to resync the streams. 189 traverse_sequences( \@lines1, \@lines2, 190 { MATCH => \&match, 191 DISCARD_A => \&discard1, 192 DISCARD_B => \&discard2 }); 193 | 1#! /usr/bin/env perl 2 3# Copyright (c) 2003 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 177 unchanged lines hidden (view full) --- 186 # complete diff of both lookahead buffers, all we use it for 187 # is to figure out how many lines to discard off the front of 188 # each buffer to resync the streams. 189 traverse_sequences( \@lines1, \@lines2, 190 { MATCH => \&match, 191 DISCARD_A => \&discard1, 192 DISCARD_B => \&discard2 }); 193 |
194 die "Lost sync!" if (!$match_found); | 194 if (!$match_found) { 195 printdiff(scalar(@lines1), scalar(@lines2)); 196 die "Lost sync!"; 197 } |
195 196 # Since we shouldn't get here unless the first lines of the 197 # buffers are different, then we must discard some lines off 198 # at least one of the buffers. 199 die if ($discard_lines1 == 0 && $discard_lines2 == 0); 200 201 printdiff($discard_lines1, $discard_lines2); 202 } --- 12 unchanged lines hidden (view full) --- 215 my ($n1, $n2) = @_; 216 217 # Check if two adjacent lines match, to reduce false resyncs 218 # (particularly on unrelated blank lines). This generates 219 # larger-than-necessary diffs when a single line really should be 220 # treated as common; if that bugs you, use Algorithm::Diff. 221 if ($lines1[$n1] eq $lines2[$n2] && $lines1[$n1+1] eq $lines2[$n2+1]) { 222 printdiff($n1, $n2); | 198 199 # Since we shouldn't get here unless the first lines of the 200 # buffers are different, then we must discard some lines off 201 # at least one of the buffers. 202 die if ($discard_lines1 == 0 && $discard_lines2 == 0); 203 204 printdiff($discard_lines1, $discard_lines2); 205 } --- 12 unchanged lines hidden (view full) --- 218 my ($n1, $n2) = @_; 219 220 # Check if two adjacent lines match, to reduce false resyncs 221 # (particularly on unrelated blank lines). This generates 222 # larger-than-necessary diffs when a single line really should be 223 # treated as common; if that bugs you, use Algorithm::Diff. 224 if ($lines1[$n1] eq $lines2[$n2] && $lines1[$n1+1] eq $lines2[$n2+1]) { 225 printdiff($n1, $n2); |
226 return 1; |
|
223 } | 227 } |
228 229 return 0; |
|
224} 225 226sub simple_diff 227{ 228 # Look for differences of $cnt lines to resync, 229 # increasing $cnt from 1 to $lookahead_lines until we find 230 # something. 231 for (my $cnt = 1; $cnt < $lookahead_lines-1; ++$cnt) { 232 # Check for n lines in one file being replaced by 233 # n lines in the other. 234 return if checkmatch($cnt, $cnt); 235 # Find differences where n lines in one file were 236 # replaced by m lines in the other. We let m = $cnt 237 # and iterate for n = 0 to $cnt-1. 238 for (my $n = 0; $n < $cnt; ++$n) { 239 return if checkmatch($n, $cnt); 240 return if checkmatch($cnt, $n); 241 } 242 } | 230} 231 232sub simple_diff 233{ 234 # Look for differences of $cnt lines to resync, 235 # increasing $cnt from 1 to $lookahead_lines until we find 236 # something. 237 for (my $cnt = 1; $cnt < $lookahead_lines-1; ++$cnt) { 238 # Check for n lines in one file being replaced by 239 # n lines in the other. 240 return if checkmatch($cnt, $cnt); 241 # Find differences where n lines in one file were 242 # replaced by m lines in the other. We let m = $cnt 243 # and iterate for n = 0 to $cnt-1. 244 for (my $n = 0; $n < $cnt; ++$n) { 245 return if checkmatch($n, $cnt); 246 return if checkmatch($cnt, $n); 247 } 248 } |
249 250 printdiff(scalar(@lines1), scalar(@lines2)); |
|
243 die "Lost sync!"; 244} 245 246# Set the pointer to the appropriate diff function. 247# 248# Note that in either case the function determines how many lines to 249# discard from the front of each lookahead buffer to resync the 250# streams, then prints the appropriate diff output and discards them. --- 48 unchanged lines hidden --- | 251 die "Lost sync!"; 252} 253 254# Set the pointer to the appropriate diff function. 255# 256# Note that in either case the function determines how many lines to 257# discard from the front of each lookahead buffer to resync the 258# streams, then prints the appropriate diff output and discards them. --- 48 unchanged lines hidden --- |