Skip to content

Draft: Enforce a code style with clang format

Daniel P. Berrangé requested to merge berrange/libvirt-dbus:clang-format into master

We have talked about using clang-format with libvirt for a long time, but doing so on the main repo is quite a big step. I figured it might be nice to try it out on a smaller scale repo, where impact on backporting is less important.

I thing most of the changes that get made to libvirt-dbus code are inconsequential / boring.

The biggest set of interesting changes are around parameters / arguments. The line length increase to 100 characters allows more cases to fit on one line. The question is how to prioritize style when things don't fit on oneline.

The rules configured by the .clang-format in this MR will end up with three possible styles in order of preference:

  1. Method name and parameters all on the same line
  static void
- virtDBusConnectClose(virtDBusConnect *connect,
-                      gboolean deregisterEvents)
+ virtDBusConnectClose(virtDBusConnect *connect, gboolean deregisterEvents)
  1. Method name and first param on same line, all remaining params on a new line
-        g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                    "no interface defined in '%s'", introspectFile);
+        g_set_error(error,
+                    G_FILE_ERROR,
+                    G_FILE_ERROR_FAILED,
+                    "no interface defined in '%s'",
+                    introspectFile);
  1. Method name on one line, all params on new lines
-    g_dbus_connection_emit_signal(connect->bus,
-                                  NULL,
-                                  path,
-                                  VIRT_DBUS_DOMAIN_INTERFACE,
-                                  "DiskChange",
-                                  g_variant_new("(sssi)", old_src_path,
-                                                new_src_path, device, reason),
-                                  NULL);
+    g_dbus_connection_emit_signal(
+        connect->bus,
+        NULL,
+        path,
+        VIRT_DBUS_DOMAIN_INTERFACE,
+        "DiskChange",
+        g_variant_new("(sssi)", old_src_path, new_src_path, device, reason),
+        NULL);
Edited by Daniel P. Berrangé

Merge request reports