Маша Глухова wrote on Sat, Dec 24, 2016 at 18:14:16 +0000: > +def order_only_difference(unified_diff): > + diff_lines = unified_diff.splitlines() > + added_lines = [line[1:] for line in diff_lines if line.startswith('+')] > + removed_lines = [line[1:] for line in diff_lines if line.startswith('-')] > + # Faster check: does number of lines match? > + if len(added_lines) != len(removed_lines): > + return False > + # Counter stores line and number of its occurrences. > + return sorted(added_lines) == sorted(removed_lines)
What happens if one of the files has a trailing newline and one does not? Strictly speaking, that's not an "ordering only difference", but this function doesn't seem to handle this case. Example: % diff -u <(echo foo) <(printf foo) --- /proc/self/fd/11 2016-12-24 20:24:22.064115616 +0000 +++ /proc/self/fd/12 2016-12-24 20:24:22.064115616 +0000 @@ -1 +1 @@ -foo +foo \ No newline at end of file Cheers, Daniel