diff mbox

[U-Boot,2/4] tools: moveconfig: show result of header cleaning in unified diff

Message ID 1469369859-14277-3-git-send-email-yamada.masahiro@socionext.com
State Superseded
Headers show

Commit Message

Masahiro Yamada July 24, 2016, 2:17 p.m. UTC
The header cleanup feature of this tool now removes empty ifdef's,
successive blank lines as well as moved option defines.  So, we
want to see a little more context to check which lines were deleted.

It is true that we can see it by "git diff", but it would not work
in the --dry-run mode.  So, here, this commit.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 tools/moveconfig.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 7d018e4..27bd958 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -161,6 +161,7 @@  To see the complete list of supported options, run
 """
 
 import copy
+import difflib
 import filecmp
 import fnmatch
 import multiprocessing
@@ -395,16 +396,24 @@  def cleanup_one_header(header_path, patterns, dry_run):
         if matched == old_matched:
             break
 
-    for i in matched:
-        print '%s: %s: %s' % (header_path, i + 1, lines[i]),
+    tolines = copy.copy(lines)
+
+    for i in reversed(matched):
+        tolines.pop(i)
+
+    diff = difflib.unified_diff(lines, tolines,
+                                fromfile=os.path.join('a', header_path),
+                                tofile=os.path.join('b', header_path))
+
+    for line in diff:
+        print line,
 
     if dry_run:
         return
 
     with open(header_path, 'w') as f:
-        for i, line in enumerate(lines):
-            if not i in matched:
-                f.write(line)
+        for line in tolines:
+            f.write(line)
 
 def cleanup_headers(configs, dry_run):
     """Delete config defines from board headers.