diffconfig (6bf2e84b8cebc4c53bf44343ed4e9b88aa73e34d) diffconfig (c8272faf5e3f0f97f5cd15af69e3a515efbe212d)
1#!/usr/bin/python
2#
3# diffconfig - a tool to compare .config files.
4#
5# originally written in 2006 by Matt Mackall
6# (at least, this was in his bloatwatch source code)
7# last worked on 2008 by Tim Bird
8#
9
10import sys, os
11
12def usage():
1#!/usr/bin/python
2#
3# diffconfig - a tool to compare .config files.
4#
5# originally written in 2006 by Matt Mackall
6# (at least, this was in his bloatwatch source code)
7# last worked on 2008 by Tim Bird
8#
9
10import sys, os
11
12def usage():
13 print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
13 print("""Usage: diffconfig [-h] [-m] [<config1> <config2>]
14
15Diffconfig is a simple utility for comparing two .config files.
16Using standard diff to compare .config files often includes extraneous and
17distracting information. This utility produces sorted output with only the
18changes in configuration values between the two files.
19
20Added and removed items are shown with a leading plus or minus, respectively.
21Changed items show the old and new values on a single line.

--- 6 unchanged lines hidden (view full) ---

28Example usage:
29 $ diffconfig .config config-with-some-changes
30-EXT2_FS_XATTR n
31-EXT2_FS_XIP n
32 CRAMFS n -> y
33 EXT2_FS y -> n
34 LOG_BUF_SHIFT 14 -> 16
35 PRINTK_TIME n -> y
14
15Diffconfig is a simple utility for comparing two .config files.
16Using standard diff to compare .config files often includes extraneous and
17distracting information. This utility produces sorted output with only the
18changes in configuration values between the two files.
19
20Added and removed items are shown with a leading plus or minus, respectively.
21Changed items show the old and new values on a single line.

--- 6 unchanged lines hidden (view full) ---

28Example usage:
29 $ diffconfig .config config-with-some-changes
30-EXT2_FS_XATTR n
31-EXT2_FS_XIP n
32 CRAMFS n -> y
33 EXT2_FS y -> n
34 LOG_BUF_SHIFT 14 -> 16
35 PRINTK_TIME n -> y
36"""
36""")
37 sys.exit(0)
38
39# returns a dictionary of name/value pairs for config items in the file
40def readconfig(config_file):
41 d = {}
42 for line in config_file:
43 line = line[:-1]
44 if line[:7] == "CONFIG_":

--- 4 unchanged lines hidden (view full) ---

49 return d
50
51def print_config(op, config, value, new_value):
52 global merge_style
53
54 if merge_style:
55 if new_value:
56 if new_value=="n":
37 sys.exit(0)
38
39# returns a dictionary of name/value pairs for config items in the file
40def readconfig(config_file):
41 d = {}
42 for line in config_file:
43 line = line[:-1]
44 if line[:7] == "CONFIG_":

--- 4 unchanged lines hidden (view full) ---

49 return d
50
51def print_config(op, config, value, new_value):
52 global merge_style
53
54 if merge_style:
55 if new_value:
56 if new_value=="n":
57 print "# CONFIG_%s is not set" % config
57 print("# CONFIG_%s is not set" % config)
58 else:
58 else:
59 print "CONFIG_%s=%s" % (config, new_value)
59 print("CONFIG_%s=%s" % (config, new_value))
60 else:
61 if op=="-":
60 else:
61 if op=="-":
62 print "-%s %s" % (config, value)
62 print("-%s %s" % (config, value))
63 elif op=="+":
63 elif op=="+":
64 print "+%s %s" % (config, new_value)
64 print("+%s %s" % (config, new_value))
65 else:
65 else:
66 print " %s %s -> %s" % (config, value, new_value)
66 print(" %s %s -> %s" % (config, value, new_value))
67
68def main():
69 global merge_style
70
71 # parse command line args
72 if ("-h" in sys.argv or "--help" in sys.argv):
67
68def main():
69 global merge_style
70
71 # parse command line args
72 if ("-h" in sys.argv or "--help" in sys.argv):
73 usage()
73 usage()
74
75 merge_style = 0
76 if "-m" in sys.argv:
77 merge_style = 1
78 sys.argv.remove("-m")
79
80 argc = len(sys.argv)
81 if not (argc==1 or argc == 3):
74
75 merge_style = 0
76 if "-m" in sys.argv:
77 merge_style = 1
78 sys.argv.remove("-m")
79
80 argc = len(sys.argv)
81 if not (argc==1 or argc == 3):
82 print "Error: incorrect number of arguments or unrecognized option"
82 print("Error: incorrect number of arguments or unrecognized option")
83 usage()
84
85 if argc == 1:
86 # if no filenames given, assume .config and .config.old
87 build_dir=""
83 usage()
84
85 if argc == 1:
86 # if no filenames given, assume .config and .config.old
87 build_dir=""
88 if os.environ.has_key("KBUILD_OUTPUT"):
88 if "KBUILD_OUTPUT" in os.environ:
89 build_dir = os.environ["KBUILD_OUTPUT"]+"/"
89 build_dir = os.environ["KBUILD_OUTPUT"]+"/"
90
91 configa_filename = build_dir + ".config.old"
92 configb_filename = build_dir + ".config"
93 else:
94 configa_filename = sys.argv[1]
95 configb_filename = sys.argv[2]
96
97 try:
90 configa_filename = build_dir + ".config.old"
91 configb_filename = build_dir + ".config"
92 else:
93 configa_filename = sys.argv[1]
94 configb_filename = sys.argv[2]
95
96 try:
98 a = readconfig(file(configa_filename))
99 b = readconfig(file(configb_filename))
97 a = readconfig(open(configa_filename))
98 b = readconfig(open(configb_filename))
100 except (IOError):
101 e = sys.exc_info()[1]
102 print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
103 usage()
104
105 # print items in a but not b (accumulate, sort and print)
106 old = []
107 for config in a:

--- 13 unchanged lines hidden (view full) ---

121 del b[config]
122 changed.sort()
123 for config in changed:
124 print_config("->", config, a[config], b[config])
125 del b[config]
126
127 # now print items in b but not in a
128 # (items from b that were in a were removed above)
99 except (IOError):
100 e = sys.exc_info()[1]
101 print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
102 usage()
103
104 # print items in a but not b (accumulate, sort and print)
105 old = []
106 for config in a:

--- 13 unchanged lines hidden (view full) ---

120 del b[config]
121 changed.sort()
122 for config in changed:
123 print_config("->", config, a[config], b[config])
124 del b[config]
125
126 # now print items in b but not in a
127 # (items from b that were in a were removed above)
129 new = b.keys()
130 new.sort()
128 new = sorted(b.keys())
131 for config in new:
132 print_config("+", config, None, b[config])
133
134main()
129 for config in new:
130 print_config("+", config, None, b[config])
131
132main()