~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/diffconfig

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/diffconfig (Version linux-6.12-rc7) and /scripts/diffconfig (Version linux-2.6.32.71)


  1 #!/usr/bin/env python3                         !!   1 #!/usr/bin/python
  2 # SPDX-License-Identifier: GPL-2.0             << 
  3 #                                                   2 #
  4 # diffconfig - a tool to compare .config files      3 # diffconfig - a tool to compare .config files.
  5 #                                                   4 #
  6 # originally written in 2006 by Matt Mackall        5 # originally written in 2006 by Matt Mackall
  7 #  (at least, this was in his bloatwatch sourc      6 #  (at least, this was in his bloatwatch source code)
  8 # last worked on 2008 by Tim Bird                   7 # last worked on 2008 by Tim Bird
  9 #                                                   8 #
 10                                                     9 
 11 import sys, os                                     10 import sys, os
 12                                                    11 
 13 def usage():                                       12 def usage():
 14     print("""Usage: diffconfig [-h] [-m] [<con !!  13     print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
 15                                                    14 
 16 Diffconfig is a simple utility for comparing t     15 Diffconfig is a simple utility for comparing two .config files.
 17 Using standard diff to compare .config files o     16 Using standard diff to compare .config files often includes extraneous and
 18 distracting information.  This utility produce     17 distracting information.  This utility produces sorted output with only the
 19 changes in configuration values between the tw     18 changes in configuration values between the two files.
 20                                                    19 
 21 Added and removed items are shown with a leadi     20 Added and removed items are shown with a leading plus or minus, respectively.
 22 Changed items show the old and new values on a     21 Changed items show the old and new values on a single line.
 23                                                    22 
 24 If -m is specified, then output will be in "me     23 If -m is specified, then output will be in "merge" style, which has the
 25 changed and new values in kernel config option     24 changed and new values in kernel config option format.
 26                                                    25 
 27 If no config files are specified, .config and      26 If no config files are specified, .config and .config.old are used.
 28                                                    27 
 29 Example usage:                                     28 Example usage:
 30  $ diffconfig .config config-with-some-changes     29  $ diffconfig .config config-with-some-changes
 31 -EXT2_FS_XATTR  n                                  30 -EXT2_FS_XATTR  n
                                                   >>  31 -EXT2_FS_XIP  n
 32  CRAMFS  n -> y                                    32  CRAMFS  n -> y
 33  EXT2_FS  y -> n                                   33  EXT2_FS  y -> n
 34  LOG_BUF_SHIFT  14 -> 16                           34  LOG_BUF_SHIFT  14 -> 16
 35  PRINTK_TIME  n -> y                               35  PRINTK_TIME  n -> y
 36 """)                                           !!  36 """
 37     sys.exit(0)                                    37     sys.exit(0)
 38                                                    38 
 39 # returns a dictionary of name/value pairs for     39 # returns a dictionary of name/value pairs for config items in the file
 40 def readconfig(config_file):                       40 def readconfig(config_file):
 41     d = {}                                         41     d = {}
 42     for line in config_file:                       42     for line in config_file:
 43         line = line[:-1]                           43         line = line[:-1]
 44         if line[:7] == "CONFIG_":                  44         if line[:7] == "CONFIG_":
 45             name, val = line[7:].split("=", 1)     45             name, val = line[7:].split("=", 1)
 46             d[name] = val                          46             d[name] = val
 47         if line[-11:] == " is not set":            47         if line[-11:] == " is not set":
 48             d[line[9:-11]] = "n"                   48             d[line[9:-11]] = "n"
 49     return d                                       49     return d
 50                                                    50 
 51 def print_config(op, config, value, new_value)     51 def print_config(op, config, value, new_value):
 52     global merge_style                             52     global merge_style
 53                                                    53 
 54     if merge_style:                                54     if merge_style:
 55         if new_value:                              55         if new_value:
 56             if new_value=="n":                     56             if new_value=="n":
 57                 print("# CONFIG_%s is not set" !!  57                 print "# CONFIG_%s is not set" % config
 58             else:                                  58             else:
 59                 print("CONFIG_%s=%s" % (config !!  59                 print "CONFIG_%s=%s" % (config, new_value)
 60     else:                                          60     else:
 61         if op=="-":                                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_valu !!  64             print "+%s %s" % (config, new_value)
 65         else:                                      65         else:
 66             print(" %s %s -> %s" % (config, va !!  66             print " %s %s -> %s" % (config, value, new_value)
 67                                                    67 
 68 def show_diff():                               !!  68 def main():
 69     global merge_style                             69     global merge_style
 70                                                    70 
 71     # parse command line args                      71     # parse command line args
 72     if ("-h" in sys.argv or "--help" in sys.ar     72     if ("-h" in sys.argv or "--help" in sys.argv):
 73         usage()                                !!  73         usage()
 74                                                    74 
 75     merge_style = 0                                75     merge_style = 0
 76     if "-m" in sys.argv:                           76     if "-m" in sys.argv:
 77         merge_style = 1                            77         merge_style = 1
 78         sys.argv.remove("-m")                      78         sys.argv.remove("-m")
 79                                                    79 
 80     argc = len(sys.argv)                           80     argc = len(sys.argv)
 81     if not (argc==1 or argc == 3):                 81     if not (argc==1 or argc == 3):
 82         print("Error: incorrect number of argu !!  82         print "Error: incorrect number of arguments or unrecognized option"
 83         usage()                                    83         usage()
 84                                                    84 
 85     if argc == 1:                                  85     if argc == 1:
 86         # if no filenames given, assume .confi     86         # if no filenames given, assume .config and .config.old
 87         build_dir=""                               87         build_dir=""
 88         if "KBUILD_OUTPUT" in os.environ:      !!  88         if os.environ.has_key("KBUILD_OUTPUT"):
 89             build_dir = os.environ["KBUILD_OUT     89             build_dir = os.environ["KBUILD_OUTPUT"]+"/"
                                                   >>  90 
 90         configa_filename = build_dir + ".confi     91         configa_filename = build_dir + ".config.old"
 91         configb_filename = build_dir + ".confi     92         configb_filename = build_dir + ".config"
 92     else:                                          93     else:
 93         configa_filename = sys.argv[1]             94         configa_filename = sys.argv[1]
 94         configb_filename = sys.argv[2]             95         configb_filename = sys.argv[2]
 95                                                    96 
 96     try:                                       !!  97     a = readconfig(file(configa_filename))
 97         a = readconfig(open(configa_filename)) !!  98     b = readconfig(file(configb_filename))
 98         b = readconfig(open(configb_filename)) << 
 99     except (IOError):                          << 
100         e = sys.exc_info()[1]                  << 
101         print("I/O error[%s]: %s\n" % (e.args[ << 
102         usage()                                << 
103                                                    99 
104     # print items in a but not b (accumulate,     100     # print items in a but not b (accumulate, sort and print)
105     old = []                                      101     old = []
106     for config in a:                              102     for config in a:
107         if config not in b:                       103         if config not in b:
108             old.append(config)                    104             old.append(config)
109     old.sort()                                    105     old.sort()
110     for config in old:                            106     for config in old:
111         print_config("-", config, a[config], N    107         print_config("-", config, a[config], None)
112         del a[config]                             108         del a[config]
113                                                   109 
114     # print items that changed (accumulate, so    110     # print items that changed (accumulate, sort, and print)
115     changed = []                                  111     changed = []
116     for config in a:                              112     for config in a:
117         if a[config] != b[config]:                113         if a[config] != b[config]:
118             changed.append(config)                114             changed.append(config)
119         else:                                     115         else:
120             del b[config]                         116             del b[config]
121     changed.sort()                                117     changed.sort()
122     for config in changed:                        118     for config in changed:
123         print_config("->", config, a[config],     119         print_config("->", config, a[config], b[config])
124         del b[config]                             120         del b[config]
125                                                   121 
126     # now print items in b but not in a           122     # now print items in b but not in a
127     # (items from b that were in a were remove    123     # (items from b that were in a were removed above)
128     new = sorted(b.keys())                     !! 124     new = b.keys()
                                                   >> 125     new.sort()
129     for config in new:                            126     for config in new:
130         print_config("+", config, None, b[conf    127         print_config("+", config, None, b[config])
131                                                   128 
132 def main():                                    !! 129 main()
133     try:                                       << 
134         show_diff()                            << 
135     except BrokenPipeError:                    << 
136         # Python flushes standard streams on e << 
137         # to devnull to avoid another BrokenPi << 
138         devnull = os.open(os.devnull, os.O_WRO << 
139         os.dup2(devnull, sys.stdout.fileno())  << 
140         sys.exit(1)  # Python exits with error << 
141                                                << 
142                                                << 
143 if __name__ == '__main__':                     << 
144     main()                                     << 
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php