diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2016-07-25 19:15:25 +0900 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-08-05 07:27:16 -0400 |
commit | f2f6981a149572675ec7e59a33fb414440364739 (patch) | |
tree | 77fa61c06d7d3ad8d58d6e0ef4b9c41e922d6546 /tools/moveconfig.py | |
parent | 8ba1f5de4571566be12efaffdad404a506b978e3 (diff) |
tools: moveconfig: show result of header cleaning in unified diff
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>
Diffstat (limited to 'tools/moveconfig.py')
-rwxr-xr-x | tools/moveconfig.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 74d38ec48b..8bca7e4362 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 @@ -275,6 +276,22 @@ def color_text(color_enabled, color, string): else: return string +def show_diff(a, b, file_path): + """Show unidified diff. + + Arguments: + a: A list of lines (before) + b: A list of lines (after) + file_path: Path to the file + """ + + diff = difflib.unified_diff(a, b, + fromfile=os.path.join('a', file_path), + tofile=os.path.join('b', file_path)) + + for line in diff: + print line, + def update_cross_compile(color_enabled): """Update per-arch CROSS_COMPILE via environment variables @@ -414,16 +431,19 @@ 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) + + show_diff(lines, tolines, header_path) 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. |