Skip to contentSkip to conversation

qemu-img: sort block formats in help message

PATCH In review Mike Day 5 participants 6 messages May 13, 2014 – May 14, 2014

lore
Share & tools
lore

Mike Day

author
#0 lore raw

PATCH 1/1 qemu-img: sort block formats in help message

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.

[Added suggestions from Fam Zheng <[email protected]> to declare variables at the top of the scope in help() and to omit explicit cast for void* opaque.
--Stefan]

[Removed call to g_sequence_lookup because it breaks the build on
machines with glib < 2.28.
--Mike]

---
 qemu-img.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
qemu-img.c +22 -3
index 96f4463..93e51d1 100644
@@ -32,6 +32,7 @@
 #include "block/block_int.h"
 #include "block/qapi.h"
 #include <getopt.h>
+#include <glib.h>
 
 #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION \
                           ", Copyright (c) 2004-2008 Fabrice Bellard\n"
@@ -55,9 +56,22 @@ typedef enum OutputFormat {
 #define BDRV_O_FLAGS BDRV_O_CACHE_WB
 #define BDRV_DEFAULT_CACHE "writeback"
 
-static void format_print(void *opaque, const char *name)
+static gint compare_data(gconstpointer a, gconstpointer b, gpointer user)
 {
-    printf(" %s", name);
+    return g_strcmp0(a, b);
+}
+
+static void print_format(gpointer data, gpointer user)
+{
+    printf(" %s", (char *)data);
+}
+
+static void add_format_to_seq(void *opaque, const char *fmt_name)
+{
+    GSequence *seq = opaque;
+
+    g_sequence_insert_sorted(seq, (gpointer)fmt_name,
+                             compare_data, NULL);
 }
 
 static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
@@ -142,10 +156,15 @@ static void QEMU_NORETURN help(void)
            "  '-f' first image format\n"
            "  '-F' second image format\n"
            "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
+    GSequence *seq;
 
     printf("%s\nSupported formats:", help_msg);
-    bdrv_iterate_format(format_print, NULL);
+    seq = g_sequence_new(NULL);
+    bdrv_iterate_format(add_format_to_seq, seq);
+    g_sequence_foreach(seq, print_format, NULL);
     printf("\n");
+    g_sequence_free(seq);
+
     exit(EXIT_SUCCESS);
 }
 
Signature · 1 line
1.9.0
#1 lore raw
Quoted 5 lines · Mike Day

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.

Patch revision notes like these

Quoted 5 lines

[Added suggestions from Fam Zheng <[email protected]> to declare variables at the top of the scope in help() and to omit explicit cast for void* opaque.
--Stefan]

Quoted 7 lines

[Removed call to g_sequence_lookup because it breaks the build on
machines with glib < 2.28.
--Mike]

---

... go here, below the '---'.

Furthermore, your previous patch went in already. We need an incremental patch to get rid of the dependency on non-ancient glib.

#2 lore raw
In reply to Mike Day

Am 13.05.2014 um 18:07 hat Mike Day geschrieben:

Quoted 11 lines

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.

[Added suggestions from Fam Zheng <[email protected]> to declare variables at the top of the scope in help() and to omit explicit cast for void* opaque.
--Stefan]

Quoted 6 lines

[Removed call to g_sequence_lookup because it breaks the build on
machines with glib < 2.28.
--Mike]

What happened here? This patch seems to be already applied, and you included Stefan's SoB as well.

Kevin

#3 lore raw
Quoted 16 lines · Kevin Wolf

Am 13.05.2014 um 18:07 hat Mike Day geschrieben:

Quoted 15 lines

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.

[Added suggestions from Fam Zheng <[email protected]> to declare variables at the top of the scope in help() and to omit explicit cast for void* opaque.
--Stefan]

[Removed call to g_sequence_lookup because it breaks the build on
machines with glib < 2.28.
--Mike]

Quoted 6 lines
Quoted 2 lines

What happened here? This patch seems to be already applied, and you included Stefan's SoB as well.

Mike, please fix on top of current master, instead of squashing the removing of g_sequence_lookup into your already merged patch.

Fam

#4 lore raw
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Kevin Wolf

Am 13.05.2014 um 18:07 hat Mike Day geschrieben:

Quoted 17 lines

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.

[Added suggestions from Fam Zheng <[email protected]> to declare variables at the top of the scope in help() and to omit explicit cast for void* opaque.
--Stefan]

[Removed call to g_sequence_lookup because it breaks the build on
machines with glib < 2.28.
--Mike]

Quoted 6 lines
Quoted 3 lines

What happened here? This patch seems to be already applied, and you included Stefan's SoB as well.

Mike, please fix on top of current master, instead of squashing the removing of g_sequence_lookup into your already merged patch.

Yes, we cannot change the git commit history once a commit is in the public qemu.git repository. The only options are to:

1. Add a patch on top that fixes the issue.
2. Use git-revert(1) to undo your commit entirely (this adds a new patch on top the applies the reverse diff).

In this case #1 seems like a good choice.

Stefan

author
#5 lore raw
Quoted 8 lines · Stefan Hajnoczi

Yes, we cannot change the git commit history once a commit is in the public qemu.git repository. The only options are to:

1. Add a patch on top that fixes the issue.
2. Use git-revert(1) to undo your commit entirely (this adds a new patch on top the applies the reverse diff).

In this case #1 seems like a good choice.

I followed your advice and went with #1, I think its already been pulled.

Mike