2008-06-10 19:44:17

by Tim Bird

[permalink] [raw]
Subject: [PATCH] add diffconfig utility

diffconfig is a simple utility for comparing two .config files.
Using standard diff to compare .config files often includes
extraneous and distracting information. This utility produces
sorted output with only the changes in configuration values
between the two files.

I have found this handy for use in testing to
detect when option dependencies unexpectedly affect
other options.

To use, apply the patch and 'chmod a+x scripts/diffconfig'

Signed-off-by: Tim Bird <[email protected]>

diffconfig | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+)

--- linux-2.6.24.orig/scripts/diffconfig 1969-12-31 16:00:00.000000000 -0800
+++ test-linux/scripts/diffconfig 2008-06-10 12:11:14.000000000 -0700
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+# (at least, this was in his bloatwatch source code)
+#
+# diffconfig is a simple utility for comparing two .config files.
+# Using standard diff to compare .config files often includes
+# extraneous and distracting information. This utility produces
+# sorted output with only the changes in configuration values
+# between the two files.
+#
+# Added and removed items are shown with a leading plus or minus,
+# respectively. Changed items show the old and new values on a
+# single line.
+#
+# Example usage:
+# $ diffconfig .config config-test-nfs-off
+# -LOCKD y
+# -LOCKD_V4 y
+# -NFS_COMMON y
+# -NFS_DIRECTIO n
+# -NFS_V3 y
+# -NFS_V3_ACL n
+# -NFS_V4 n
+# -ROOT_NFS y
+# -RPCSEC_GSS_KRB5 n
+# -RPCSEC_GSS_SPKM3 n
+# -SUNRPC y
+# -SUNRPC_BIND34 n
+# NFS_FS y -> n
+
+import sys, os
+
+if len(sys.argv) < 3:
+ print "Usage: diffconfig <config1> <config2>"
+ sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+ d = {}
+ for line in config_file:
+ line = line[:-1]
+ if line[:7] == "CONFIG_":
+ name, val = line[7:].split("=", 1)
+ d[name] = val
+ if line[-11:] == " is not set":
+ d[line[9:-11]] = "n"
+ return d
+
+a = readconfig(file(sys.argv[1]))
+b = readconfig(file(sys.argv[2]))
+
+# print items in a but not b (accumulate, sort and print)
+old = []
+for config in a:
+ if config not in b:
+ old.append(config)
+
+old.sort()
+
+for config in old:
+ print "-%s %s" % (config, a[config])
+ del a[config]
+
+# print items that changed (accumulate, sort, and print)
+changed = []
+for config in a:
+ if a[config] != b[config]:
+ changed.append(config)
+ else:
+ del b[config]
+
+changed.sort()
+
+for config in changed:
+ print " %s %s -> %s" % (config, a[config], b[config])
+ del b[config]
+
+# now print items in b but not in a
+
+# the items from b that were in a (either the same or that changed) were removed
+# the only items left were not in a
+new = b.keys()
+
+new.sort()
+
+for config in new:
+ print "+%s %s" % (config, b[config])


2008-06-10 21:02:42

by Jörn Engel

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, 10 June 2008 12:41:54 -0700, Tim Bird wrote:
> Delivery-date: Tue, 10 Jun 2008 21:44:08 +0200
> From: Tim Bird <[email protected]>
> To: linux-embedded <[email protected]>
> CC: linux kernel <[email protected]>
> Subject: [PATCH] add diffconfig utility

Neat. But I have one nagging question: who do you expect to merge this
patch? ;)

Jörn

--
Premature optimization is the root of all evil.
-- Donald Knuth

2008-06-10 21:18:16

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, Jun 10, 2008 at 11:02:18PM +0200, J?rn Engel wrote:
> On Tue, 10 June 2008 12:41:54 -0700, Tim Bird wrote:
> > Delivery-date: Tue, 10 Jun 2008 21:44:08 +0200
> > From: Tim Bird <[email protected]>
> > To: linux-embedded <[email protected]>
> > CC: linux kernel <[email protected]>
> > Subject: [PATCH] add diffconfig utility
>
> Neat. But I have one nagging question: who do you expect to merge this
> patch? ;)
I will merge it if the feedabck is positive and eventual feedback
is dealt with. (And Tim reminds me to do so in a week or so).

I take most of the random scripts in scripts/ via kbuild.git.

Sam

2008-06-10 21:21:26

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, Jun 10, 2008 at 12:41:54PM -0700, Tim Bird wrote:
> diffconfig is a simple utility for comparing two .config files.
> Using standard diff to compare .config files often includes
> extraneous and distracting information. This utility produces
> sorted output with only the changes in configuration values
> between the two files.
>
> I have found this handy for use in testing to
> detect when option dependencies unexpectedly affect
> other options.
>
> To use, apply the patch and 'chmod a+x scripts/diffconfig'
>
> Signed-off-by: Tim Bird <[email protected]>
>
> diffconfig | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 90 insertions(+)
>
> --- linux-2.6.24.orig/scripts/diffconfig 1969-12-31 16:00:00.000000000 -0800
> +++ test-linux/scripts/diffconfig 2008-06-10 12:11:14.000000000 -0700
> @@ -0,0 +1,90 @@
> +#!/usr/bin/python
> +#
> +# diffconfig - a tool to compare .config files.
> +#
> +# originally written in 2006 by Matt Mackall
> +# (at least, this was in his bloatwatch source code)
> +#
> +# diffconfig is a simple utility for comparing two .config files.
> +# Using standard diff to compare .config files often includes
> +# extraneous and distracting information. This utility produces
> +# sorted output with only the changes in configuration values
> +# between the two files.
> +#
> +# Added and removed items are shown with a leading plus or minus,
> +# respectively. Changed items show the old and new values on a
> +# single line.
> +#
> +# Example usage:
> +# $ diffconfig .config config-test-nfs-off
> +# -LOCKD y
> +# -LOCKD_V4 y
> +# -NFS_COMMON y
> +# -NFS_DIRECTIO n
> +# -NFS_V3 y
> +# -NFS_V3_ACL n
> +# -NFS_V4 n
> +# -ROOT_NFS y
> +# -RPCSEC_GSS_KRB5 n
> +# -RPCSEC_GSS_SPKM3 n
> +# -SUNRPC y
> +# -SUNRPC_BIND34 n
> +# NFS_FS y -> n
> +
> +import sys, os
> +
> +if len(sys.argv) < 3:
> + print "Usage: diffconfig <config1> <config2>"
> + sys.exit(0)

I know this is unix style to be very short in usage - but then they
have man pages.
Could we add a bit more from the nice description above to usage?


> +
> +# returns a dictionary of name/value pairs for config items in the file
> +def readconfig(config_file):
> + d = {}
> + for line in config_file:
> + line = line[:-1]
> + if line[:7] == "CONFIG_":
> + name, val = line[7:].split("=", 1)
> + d[name] = val
> + if line[-11:] == " is not set":
> + d[line[9:-11]] = "n"
> + return d
> +
> +a = readconfig(file(sys.argv[1]))
> +b = readconfig(file(sys.argv[2]))
> +
> +# print items in a but not b (accumulate, sort and print)
> +old = []
> +for config in a:
> + if config not in b:
> + old.append(config)
> +
> +old.sort()
> +
> +for config in old:
> + print "-%s %s" % (config, a[config])
> + del a[config]
> +
> +# print items that changed (accumulate, sort, and print)
> +changed = []
> +for config in a:
> + if a[config] != b[config]:
> + changed.append(config)
> + else:
> + del b[config]
> +
> +changed.sort()
> +
> +for config in changed:
> + print " %s %s -> %s" % (config, a[config], b[config])
> + del b[config]
> +
> +# now print items in b but not in a
> +
> +# the items from b that were in a (either the same or that changed) were removed
> +# the only items left were not in a
> +new = b.keys()
> +
> +new.sort()
> +
> +for config in new:
> + print "+%s %s" % (config, b[config])

No feedback on the implmentation - I do not speak phython.

Sam

2008-06-10 22:04:45

by Tim Bird

[permalink] [raw]
Subject: execute bit on scripts (was Re: [PATCH] add diffconfig utility)

Sam Ravnborg wrote:
> I will merge it if the feedabck is positive and eventual feedback
> is dealt with. (And Tim reminds me to do so in a week or so).

Thanks.

> I take most of the random scripts in scripts/ via kbuild.git.

OK - sounds like you're the right person to ask a question
that has been nagging me.

Is there a proper way to get the execute bit set in the git tree
on patches that contain scripts? I think patches
produced by git have something that sets the file permissions?
Is this something that can (or should) be hand-added to
a non-git patch? (I use quilt).

I put that blurb in the patch description about doing a
'chmod a+x', but that doesn't seem reliable.
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-06-10 22:07:31

by David Woodhouse

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, 2008-06-10 at 12:41 -0700, Tim Bird wrote:
> +# Added and removed items are shown with a leading plus or minus,
> +# respectively. Changed items show the old and new values on a
> +# single line.

It'd be really nice if it could give its output in the same form as
the .config file itself -- so it'd look something like:

# CONFIG_FOO is not set
CONFIG_BAR=y

That can be used with this kind of tool too...

--
dwmw2


Attachments:
merge.pl (1.37 kB)

2008-06-10 22:26:27

by Jan Engelhardt

[permalink] [raw]
Subject: Re: execute bit on scripts (was Re: [PATCH] add diffconfig utility)


On Tuesday 2008-06-10 23:33, Tim Bird wrote:
>
>> I take most of the random scripts in scripts/ via kbuild.git.
>
>OK - sounds like you're the right person to ask a question
>that has been nagging me.
>
>Is there a proper way to get the execute bit set in the git tree
>on patches that contain scripts? I think patches
>produced by git have something that sets the file permissions?

If the patch was produced with git it should have a line like
new file mode 100755

2008-06-10 23:02:20

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, 10 Jun 2008 23:07:04 +0100
David Woodhouse <[email protected]> wrote:

> On Tue, 2008-06-10 at 12:41 -0700, Tim Bird wrote:
> > +# Added and removed items are shown with a leading plus or minus,
> > +# respectively. Changed items show the old and new values on a
> > +# single line.
>
> It'd be really nice if it could give its output in the same form as
> the .config file itself -- so it'd look something like:
>
> # CONFIG_FOO is not set
> CONFIG_BAR=y
>
> That can be used with this kind of tool too...
>

the person who wrote that tool also wrote a similar diff tool ;)
but it's horrible perl I suspect.



--
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2008-06-10 23:10:47

by David Woodhouse

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, 2008-06-10 at 16:02 -0700, Arjan van de Ven wrote:
> the person who wrote that tool also wrote a similar diff tool ;)
> but it's horrible perl I suspect.

Yeah, but I can't find it in CVS right now for some reason.

--
dwmw2

2008-06-10 23:53:31

by Tim Bird

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

David Woodhouse wrote:
> On Tue, 2008-06-10 at 12:41 -0700, Tim Bird wrote:
>> +# Added and removed items are shown with a leading plus or minus,
>> +# respectively. Changed items show the old and new values on a
>> +# single line.
>
> It'd be really nice if it could give its output in the same form as
> the .config file itself -- so it'd look something like:
>
> # CONFIG_FOO is not set
> CONFIG_BAR=y

Would an option for that style of output be OK?

The tool currently produces something similar
to a diff (but with changed lines compressed to
a single line for conciseness). It should be easy
to produce something that can be used with another
tool to transform one config into another.

It's unclear what to do with variables that are
supposed to be removed from the config (as opposed
to be set to "CONFIG_FOO is not set" Does merge.pl
handle this, or is this left to something like
'make oldconfig'?
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-06-11 00:28:13

by Tim Bird

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

Sam Ravnborg wrote:
> I know this is unix style to be very short in usage - but then they
> have man pages.
> Could we add a bit more from the nice description above to usage?
Good idea. Might as well make it visible.

David Woodhouse wrote:
> It'd be really nice if it could give its output in the same form as
> the .config file itself -- so it'd look something like:
>
> # CONFIG_FOO is not set
> CONFIG_BAR=y

OK, a new version is below. Right now, when printing in "merge" style,
the code omits items that are absent in the new config. These should get set
correctly (removed) if you do a 'make oldconfig'. It would be trivial
to have them output as well, if you think that would be better.

I am experimentally trying to attach a git-style file mode
to this patch. I did this by hand, so it might not work.
(The index line is totally made up). Let me know if there are problems.

Diffconfig is a simple utility for comparing two .config files.
See usage in the script for more info.

Signed-off-by: Tim Bird <[email protected]>

scripts/diffconfig | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
create mode 100755 scripts/diffconfig

diff --git a/scripts/diffconfig b/scripts/diffconfig
new file mode 100755
index 0000000..aa6cfe1
--- /dev/null
+++ b/scripts/diffconfig
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+# (at least, this was in his bloatwatch source code)
+# last worked on 2008 by Tim Bird
+#
+
+import sys, os
+
+merge_style = 0
+if "-m" in sys.argv:
+ merge_style = 1
+ sys.argv.remove("-m")
+
+if "-h" in sys.argv or len(sys.argv) < 3:
+ print "Usage: diffconfig [-h] [-m] <config1> <config2>\n"
+ print """Diffconfig is a simple utility for comparing two .config files.
+Using standard diff to compare .config files often includes
+extraneous and distracting information. This utility produces
+sorted output with only the changes in configuration values
+between the two files.
+
+Added and removed items are shown with a leading plus or minus,
+respectively. Changed items show the old and new values on a
+single line.
+
+If -m is specified, then output will be in "merge" style,
+which has the changed and new values in kernel config option format.
+
+Example usage:
+ $ diffconfig .config config-with-some-changes
+-EXT2_FS_XATTR n
+-EXT2_FS_XIP n
+ CRAMFS n -> y
+ EXT2_FS y -> n
+ LOG_BUF_SHIFT 14 -> 16
+ PRINTK_TIME n -> y
+"""
+ sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+ d = {}
+ for line in config_file:
+ line = line[:-1]
+ if line[:7] == "CONFIG_":
+ name, val = line[7:].split("=", 1)
+ d[name] = val
+ if line[-11:] == " is not set":
+ d[line[9:-11]] = "n"
+ return d
+
+a = readconfig(file(sys.argv[1]))
+b = readconfig(file(sys.argv[2]))
+
+def print_config(op, config, value, new_value):
+ if merge_style:
+ if new_value:
+ if new_value=="n":
+ print "# CONFIG_%s is not set" % config
+ else:
+ print "CONFIG_%s=%s" % (config, new_value)
+ else:
+ if op=="-":
+ print "-%s %s" % (config, value)
+ elif op=="+":
+ print "+%s %s" % (config, new_value)
+ else:
+ print " %s %s -> %s" % (config, value, new_value)
+
+# print items in a but not b (accumulate, sort and print)
+old = []
+for config in a:
+ if config not in b:
+ old.append(config)
+
+old.sort()
+
+for config in old:
+ print_config("-", config, a[config], None)
+ del a[config]
+
+# print items that changed (accumulate, sort, and print)
+changed = []
+for config in a:
+ if a[config] != b[config]:
+ changed.append(config)
+ else:
+ del b[config]
+
+changed.sort()
+
+for config in changed:
+ print_config("->", config, a[config], b[config])
+ del b[config]
+
+# now print items in b but not in a
+
+# the items from b that were in a (either the same or that changed) were removed
+# the only items left were not in a
+new = b.keys()
+
+new.sort()
+
+for config in new:
+ print_config("+", config, None, b[config])

2008-06-11 07:00:18

by Holger Schurig

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

Nice.

Would it be helpful to compare .config.old to .config if you
don't provide any command line arguments?

scripts/diffconfig

would then do the job.

2008-06-11 11:28:53

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

On Tue, 10 Jun 2008, Tim Bird wrote:
> +merge_style = 0
> +if "-m" in sys.argv:
> + merge_style = 1
> + sys.argv.remove("-m")
> +
> +if "-h" in sys.argv or len(sys.argv) < 3:
^^^
No checking for excess arguments?

With kind regards,

Geert Uytterhoeven
Software Architect

Sony Techsoft Centre
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium

Phone: +32 (0)2 700 8453
Fax: +32 (0)2 700 8622
E-mail: [email protected]
Internet: http://www.sony-europe.com/

Sony Technology and Software Centre Europe
A division of Sony Service Centre (Europe) N.V.
Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium
VAT BE 0413.825.160 · RPR Brussels
Fortis 293-0376800-10 GEBA-BE-BB

2008-06-11 18:57:45

by Tim Bird

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

Geert Uytterhoeven wrote:
> No checking for excess arguments?

Holger Schurig wrote:
> Would it be helpful to compare .config.old to .config if you
> don't provide any command line arguments?

Both good ideas. These are implemented in the latest version.
Note that I check for and use KBUILD_OUTPUT. (I always put
my build output outside the source directory, since
I usually build for multiple arches from a single tree.)

The program is also now better structured, IMHO.
-- Tim

Diffconfig is a simple utility for comparing two .config files.
See usage in the script for more info.

Signed-off-by: Tim Bird <[email protected]>

scripts/diffconfig | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)
create mode 100755 scripts/diffconfig

diff --git a/scripts/diffconfig b/scripts/diffconfig
new file mode 100755
index 0000000..aa6cfe1
--- /dev/null
+++ b/scripts/diffconfig
@@ -0,0 +1,128 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+# (at least, this was in his bloatwatch source code)
+# last worked on 2008 by Tim Bird
+#
+
+import sys, os
+
+def usage():
+ print "Usage: diffconfig [-h] [-m] [<config1> <config2>]\n"
+ print """Diffconfig is a simple utility for comparing two .config files.
+Using standard diff to compare .config files often includes extraneous and
+distracting information. This utility produces sorted output with only the
+changes in configuration values between the two files.
+
+Added and removed items are shown with a leading plus or minus, respectively.
+Changed items show the old and new values on a single line.
+
+If -m is specified, then output will be in "merge" style, which has the changed
+and new values in kernel config option format.
+
+If no config files are specified, .config and .config.old are used.
+
+Example usage:
+ $ diffconfig .config config-with-some-changes
+-EXT2_FS_XATTR n
+-EXT2_FS_XIP n
+ CRAMFS n -> y
+ EXT2_FS y -> n
+ LOG_BUF_SHIFT 14 -> 16
+ PRINTK_TIME n -> y
+"""
+ sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+ d = {}
+ for line in config_file:
+ line = line[:-1]
+ if line[:7] == "CONFIG_":
+ name, val = line[7:].split("=", 1)
+ d[name] = val
+ if line[-11:] == " is not set":
+ d[line[9:-11]] = "n"
+ return d
+
+def print_config(op, config, value, new_value):
+ global merge_style
+
+ if merge_style:
+ if new_value:
+ if new_value=="n":
+ print "# CONFIG_%s is not set" % config
+ else:
+ print "CONFIG_%s=%s" % (config, new_value)
+ else:
+ if op=="-":
+ print "-%s %s" % (config, value)
+ elif op=="+":
+ print "+%s %s" % (config, new_value)
+ else:
+ print " %s %s -> %s" % (config, value, new_value)
+
+def main():
+ global merge_style
+
+ # parse command line args
+ if ("-h" in sys.argv or "--help" in sys.argv):
+ usage()
+
+ merge_style = 0
+ if "-m" in sys.argv:
+ merge_style = 1
+ sys.argv.remove("-m")
+
+ argc = len(sys.argv)
+ if not (argc==1 or argc == 3):
+ print "Error: incorrect number of arguments or unrecognized option"
+ usage()
+
+ if argc == 1:
+ # if no filenames given, assume .config and .config.old
+ build_dir=""
+ if os.environ.has_key("KBUILD_OUTPUT"):
+ build_dir = os.environ["KBUILD_OUTPUT"]+"/"
+
+ configa_filename = build_dir + ".config.old"
+ configb_filename = build_dir + ".config"
+ else:
+ configa_filename = sys.argv[1]
+ configb_filename = sys.argv[2]
+
+ a = readconfig(file(configa_filename))
+ b = readconfig(file(configb_filename))
+
+ # print items in a but not b (accumulate, sort and print)
+ old = []
+ for config in a:
+ if config not in b:
+ old.append(config)
+ old.sort()
+ for config in old:
+ print_config("-", config, a[config], None)
+ del a[config]
+
+ # print items that changed (accumulate, sort, and print)
+ changed = []
+ for config in a:
+ if a[config] != b[config]:
+ changed.append(config)
+ else:
+ del b[config]
+ changed.sort()
+ for config in changed:
+ print_config("->", config, a[config], b[config])
+ del b[config]
+
+ # now print items in b but not in a
+ # (items from b that were in a were removed above)
+ new = b.keys()
+ new.sort()
+ for config in new:
+ print_config("+", config, None, b[config])
+
+main()

2008-06-12 13:19:00

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

Hi Tim.

> The program is also now better structured, IMHO.
> -- Tim

Seeing this programs gets frequent updates (good!) I have not
yet applied it.

When you consider it stabilized could you please drop me a
new mail including full changelog and updated patch.

And please cc: [email protected] + linux-kernel on the
submission.

Thanks,
Sam

2008-06-12 16:28:46

by Tim Bird

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility

Sam Ravnborg wrote:
> Hi Tim.
>
>> The program is also now better structured, IMHO.
>> -- Tim
>
> Seeing this programs gets frequent updates (good!) I have not
> yet applied it.
>
> When you consider it stabilized could you please drop me a
> new mail including full changelog and updated patch.
>
> And please cc: [email protected] + linux-kernel on the
> submission.

Will do. I'll give it a little settle time, and then
notify you.
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

2008-06-24 17:58:52

by Tim Bird

[permalink] [raw]
Subject: [PATCH] add diffconfig utility (v2)

Sam Ravnborg wrote:
> When you consider it stabilized could you please drop me a
> new mail including full changelog and updated patch.
>
> And please cc: [email protected] + linux-kernel on the
> submission.

Sam,

I haven't gotten any more feedback, and I believe I've addressed
all previous feedback.

As for the ChangeLog, here's some information about history and
recent changes. I can put this in the patch/script if desired.

CHANGELOG:
2008-06-24 - Tim Bird <[email protected]> - add usage function,
add -m feature for merge-style output, use .config and .config.old
by default, improve command line handling
~2007 - Tim Bird - re-format code for internal use at Sony
~2006 - Matt Mackall - create original diffconfig tool as part of
bloatwatch project


Diffconfig is a simple utility for comparing two kernel configuration files.
See usage in the script for more info.

Signed-off-by: Tim Bird <[email protected]>

scripts/diffconfig | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
create mode 100755 scripts/diffconfig

diff --git a/scripts/diffconfig b/scripts/diffconfig
new file mode 100755
index 0000000..aa6cfe1
--- /dev/null
+++ b/scripts/diffconfig
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+# (at least, this was in his bloatwatch source code)
+# last worked on 2008 by Tim Bird
+#
+
+import sys, os
+
+def usage():
+ print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
+
+Diffconfig is a simple utility for comparing two .config files.
+Using standard diff to compare .config files often includes extraneous and
+distracting information. This utility produces sorted output with only the
+changes in configuration values between the two files.
+
+Added and removed items are shown with a leading plus or minus, respectively.
+Changed items show the old and new values on a single line.
+
+If -m is specified, then output will be in "merge" style, which has the
+changed and new values in kernel config option format.
+
+If no config files are specified, .config and .config.old are used.
+
+Example usage:
+ $ diffconfig .config config-with-some-changes
+-EXT2_FS_XATTR n
+-EXT2_FS_XIP n
+ CRAMFS n -> y
+ EXT2_FS y -> n
+ LOG_BUF_SHIFT 14 -> 16
+ PRINTK_TIME n -> y
+"""
+ sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+ d = {}
+ for line in config_file:
+ line = line[:-1]
+ if line[:7] == "CONFIG_":
+ name, val = line[7:].split("=", 1)
+ d[name] = val
+ if line[-11:] == " is not set":
+ d[line[9:-11]] = "n"
+ return d
+
+def print_config(op, config, value, new_value):
+ global merge_style
+
+ if merge_style:
+ if new_value:
+ if new_value=="n":
+ print "# CONFIG_%s is not set" % config
+ else:
+ print "CONFIG_%s=%s" % (config, new_value)
+ else:
+ if op=="-":
+ print "-%s %s" % (config, value)
+ elif op=="+":
+ print "+%s %s" % (config, new_value)
+ else:
+ print " %s %s -> %s" % (config, value, new_value)
+
+def main():
+ global merge_style
+
+ # parse command line args
+ if ("-h" in sys.argv or "--help" in sys.argv):
+ usage()
+
+ merge_style = 0
+ if "-m" in sys.argv:
+ merge_style = 1
+ sys.argv.remove("-m")
+
+ argc = len(sys.argv)
+ if not (argc==1 or argc == 3):
+ print "Error: incorrect number of arguments or unrecognized option"
+ usage()
+
+ if argc == 1:
+ # if no filenames given, assume .config and .config.old
+ build_dir=""
+ if os.environ.has_key("KBUILD_OUTPUT"):
+ build_dir = os.environ["KBUILD_OUTPUT"]+"/"
+
+ configa_filename = build_dir + ".config.old"
+ configb_filename = build_dir + ".config"
+ else:
+ configa_filename = sys.argv[1]
+ configb_filename = sys.argv[2]
+
+ a = readconfig(file(configa_filename))
+ b = readconfig(file(configb_filename))
+
+ # print items in a but not b (accumulate, sort and print)
+ old = []
+ for config in a:
+ if config not in b:
+ old.append(config)
+ old.sort()
+ for config in old:
+ print_config("-", config, a[config], None)
+ del a[config]
+
+ # print items that changed (accumulate, sort, and print)
+ changed = []
+ for config in a:
+ if a[config] != b[config]:
+ changed.append(config)
+ else:
+ del b[config]
+ changed.sort()
+ for config in changed:
+ print_config("->", config, a[config], b[config])
+ del b[config]
+
+ # now print items in b but not in a
+ # (items from b that were in a were removed above)
+ new = b.keys()
+ new.sort()
+ for config in new:
+ print_config("+", config, None, b[config])
+
+main()


2008-06-25 05:38:22

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility (v2)

On Tue, Jun 24, 2008 at 10:56:06AM -0700, Tim Bird wrote:
> Sam Ravnborg wrote:
> > When you consider it stabilized could you please drop me a
> > new mail including full changelog and updated patch.
> >
> > And please cc: [email protected] + linux-kernel on the
> > submission.
>
> Sam,
>
> I haven't gotten any more feedback, and I believe I've addressed
> all previous feedback.
>
> As for the ChangeLog, here's some information about history and
> recent changes. I can put this in the patch/script if desired.

Very cool tool, I like it a lot, thanks for pushing this.

greg k-h

2008-06-27 21:09:39

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] add diffconfig utility (v2)

On Tue, Jun 24, 2008 at 10:56:06AM -0700, Tim Bird wrote:
> Sam Ravnborg wrote:
> > When you consider it stabilized could you please drop me a
> > new mail including full changelog and updated patch.
> >
> > And please cc: [email protected] + linux-kernel on the
> > submission.
>
> Sam,
>
> I haven't gotten any more feedback, and I believe I've addressed
> all previous feedback.
Thanks, applied

Sam