From b112bac30470cd6e16c0bb900b395ee1f465bc64 Mon Sep 17 00:00:00 2001 From: Skyler Curtis Date: Thu, 25 Apr 2024 16:45:46 -0400 Subject: [PATCH 1/2] added --new-file option for GNU diff compatibility --- icdiff | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/icdiff b/icdiff index b2a1306..53edabe 100755 --- a/icdiff +++ b/icdiff @@ -700,6 +700,11 @@ def create_option_parser(): help="compare the file permissions as well as the " "content of the file", ) + parser.add_option( + "--new-file", + default=False, + action="store_true" + ) parser.add_option( "--strip-trailing-cr", default=False, @@ -834,6 +839,7 @@ def diff(options, a, b): is_a_file = not os.path.isdir(a) is_b_file = not os.path.isdir(b) + if is_a_file and is_b_file: try: if not ( @@ -856,13 +862,23 @@ def diff(options, a, b): for child in sorted(a_contents.union(b_contents)): if should_be_excluded(child, options.exclude): continue + + a_file_path = os.path.join(a, child) + b_file_path = os.path.join(b, child) + if child not in b_contents: - print_meta("Only in %s: %s" % (a, child)) + if not options.new_file: + print_meta("Only in %s: %s" % (a, child)) + continue + b_file_path = "/dev/null" elif child not in a_contents: - print_meta("Only in %s: %s" % (b, child)) - elif options.recursive: + if not options.new_file: + print_meta("Only in %s: %s" % (b, child)) + continue + a_file_path = "/dev/null" + if options.recursive: diffs_found = diffs_found | diff( - options, os.path.join(a, child), os.path.join(b, child) + options, a_file_path, b_file_path ) elif not is_a_file and is_b_file: print_meta("File %s is a directory while %s is a file" % (a, b)) From 9314292399ac742e0f00c422eaaf5c5b8f748c0d Mon Sep 17 00:00:00 2001 From: Skyler Curtis Date: Thu, 25 Apr 2024 16:57:17 -0400 Subject: [PATCH 2/2] cross platform devnull support --- icdiff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/icdiff b/icdiff index 53edabe..f097606 100755 --- a/icdiff +++ b/icdiff @@ -870,12 +870,12 @@ def diff(options, a, b): if not options.new_file: print_meta("Only in %s: %s" % (a, child)) continue - b_file_path = "/dev/null" + b_file_path = os.devnull elif child not in a_contents: if not options.new_file: print_meta("Only in %s: %s" % (b, child)) continue - a_file_path = "/dev/null" + a_file_path = os.devnull if options.recursive: diffs_found = diffs_found | diff( options, a_file_path, b_file_path