Received: from eggs.gnu.org ([2001:4830:134:3::10]:35901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhJ9l-0007VB-PZ for qemu-devel@nongnu.org; Mon, 05 May 2014 09:42:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhJ9h-0001lB-6s for qemu-devel@nongnu.org; Mon, 05 May 2014 09:42:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhJ9g-0001l0-Vl for qemu-devel@nongnu.org; Mon, 05 May 2014 09:42:05 -0400 Date: Mon, 5 May 2014 15:42:00 +0200 From: Stefan Hajnoczi Message-ID: <20140505134200.GI16173@stefanha-thinkpad.redhat.com> References: <1399036275-9219-1-git-send-email-ncmike@ncultra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399036275-9219-1-git-send-email-ncmike@ncultra.org> Subject: Re: [Qemu-devel] [PATCH] qemu-img: sort block formats in help message List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mike Day Cc: kwolf@redhat.com, Jeff Cody , qemu-devel@nongnu.org On Fri, May 02, 2014 at 09:11:15AM -0400, Mike Day wrote: > The help message for qemu-img lists the supported block formats, of > which there are 27 as of version 2.0.50. The formats are printed in > the order of their driver's position in a linked list, which appears > random. This patch prints the formats in sorted order, making it > easier to read and to find a specific format in the list. Looks useful, thanks! > Signed-off-by: Mike Day > --- This patch is whitespace-damaged so git-am(1) refuses to apply it. Please use git-send-email(1) to send patches so that the right format is used. $ git am Applying: qemu-img: sort block formats in help message fatal: unrecognized input > qemu-img.c | 33 ++++++++++++++++++++++++++++++++- > 1 file changed, 32 insertions(+), 1 deletion(-) > > diff --git a/qemu-img.c b/qemu-img.c > index 96f4463..d8b7ef4 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -32,6 +32,7 @@ > #include "block/block_int.h" > #include "block/qapi.h" > #include > +#include > > #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \ > ", Copyright (c) 2004-2008 Fabrice Bellard\n" > @@ -60,6 +61,32 @@ static void format_print(void *opaque, const char *name) > printf(" %s", name); > } > > +static gint compare_data(gconstpointer a, gconstpointer b, gpointer user) > +{ > + return g_strcmp0((const char *)a, (const char *)b); > +} > + > +static void GFunc_print_format(gpointer data, gpointer user) QEMU coding style is lowercase function and variable names. The scripts/checkpatch.pl script should identify coding style violations, please run it. > +{ > + format_print(user, data); > +} format_print() isn't called anywhere else, please inline it here since we no longer need it as its own function. > + > +static GSequence *init_sequence(void) > +{ > + return g_sequence_new(NULL); > +} Any reason to hide g_sequence_new(NULL) in it's own helper function? > + > +static void add_format_to_seq(void *opaque, const char *fmt_name) > +{ > + GSequence *seq = (GSequence *)opaque; > + > + if (!g_sequence_lookup(seq, (gpointer)fmt_name, > + compare_data, NULL)) { > + g_sequence_insert_sorted(seq, (gpointer)fmt_name, > + compare_data, NULL); > + } The type casts in this patch aren't necessary. In C void* casts to and from any type without an explicit cast. Only C++ demands explicit casts of void*.