Re: [PATCHv2 07/13] snapshot: simplify indentation of sysinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 20, 2011 at 12:14:57PM +0200, Peter Krempa wrote:
> On 09/29/2011 06:22 PM, Eric Blake wrote:
> >The improvements to virBuffer, along with a paradigm shift to pass
> >the original buffer through rather than creating a second buffer,
> >allow us to shave off quite a few lines of code.
> >
> >* src/util/sysinfo.h (virSysinfoFormat): Alter signature.
> >* src/util/sysinfo.c (virSysinfoFormat, virSysinfoBIOSFormat)
> >(virSysinfoSystemFormat, virSysinfoProcessorFormat)
> >(virSysinfoMemoryFormat): Change indentation parameter.
> >* src/conf/domain_conf.c (virDomainSysinfoDefFormat): Adjust
> >caller.
> >* src/qemu/qemu_driver.c (qemuGetSysinfo): Likewise.
> >---
> >  src/conf/domain_conf.c |   12 +-
> >  src/qemu/qemu_driver.c |    9 +-
> >  src/util/sysinfo.c     |  399 ++++++++++++++++--------------------------------
> >  src/util/sysinfo.h     |    3 +-
> >  4 files changed, 147 insertions(+), 276 deletions(-)
> >
> I'd squash in the attached patch, but it's not necessary as it gets
> rid of non automatic indentation whitespace, but makes the code look
> cleaner :)

I'm not entirely convinced this is a good idea.  This means that
when looking at the code, it is no longer obvious what the nesting
of XML elements is supposed to be - they are all the level.

I see the value of the automatic indentation code, being to allow
us to embed 1 XML document, inside another XML document. eg domain
conf XML, inside QEMU state XML.

I don't think we should use it to remove indentation in all our
code.


> diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c
> index de3108a..53636b6 100644
> --- a/src/util/sysinfo.c
> +++ b/src/util/sysinfo.c
> @@ -521,16 +521,18 @@ virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoDefPtr def)
>          !def->bios_date && !def->bios_release)
>          return;
> 
> -    virBufferAddLit(buf, "  <bios>\n");
> -    virBufferEscapeString(buf, "    <entry name='vendor'>%s</entry>\n",
> +    virBufferAddLit(buf, "<bios>\n");
> +    virBufferAdjustIndent(buf, 2);
> +    virBufferEscapeString(buf, "<entry name='vendor'>%s</entry>\n",
>                            def->bios_vendor);
> -    virBufferEscapeString(buf, "    <entry name='version'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
>                            def->bios_version);
> -    virBufferEscapeString(buf, "    <entry name='date'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='date'>%s</entry>\n",
>                            def->bios_date);
> -    virBufferEscapeString(buf, "    <entry name='release'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='release'>%s</entry>\n",
>                            def->bios_release);
> -    virBufferAddLit(buf, "  </bios>\n");
> +    virBufferAdjustIndent(buf, -2);
> +    virBufferAddLit(buf, "</bios>\n");
>  }
> 
>  static void
> @@ -541,22 +543,24 @@ virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def)
>          !def->system_uuid && !def->system_sku && !def->system_family)
>          return;
> 
> -    virBufferAddLit(buf, "  <system>\n");
> -    virBufferEscapeString(buf, "    <entry name='manufacturer'>%s</entry>\n",
> +    virBufferAddLit(buf, "<system>\n");
> +    virBufferAdjustIndent(buf, 2);
> +    virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
>                            def->system_manufacturer);
> -    virBufferEscapeString(buf, "    <entry name='product'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='product'>%s</entry>\n",
>                            def->system_product);
> -    virBufferEscapeString(buf, "    <entry name='version'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
>                            def->system_version);
> -    virBufferEscapeString(buf, "    <entry name='serial'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='serial'>%s</entry>\n",
>                            def->system_serial);
> -    virBufferEscapeString(buf, "    <entry name='uuid'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='uuid'>%s</entry>\n",
>                            def->system_uuid);
> -    virBufferEscapeString(buf, "    <entry name='sku'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='sku'>%s</entry>\n",
>                            def->system_sku);
> -    virBufferEscapeString(buf, "    <entry name='family'>%s</entry>\n",
> +    virBufferEscapeString(buf, "<entry name='family'>%s</entry>\n",
>                            def->system_family);
> -    virBufferAddLit(buf, "  </system>\n");
> +    virBufferAdjustIndent(buf, -2);
> +    virBufferAddLit(buf, "</system>\n");
>  }
> 
>  static void
> @@ -581,8 +585,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
>              !processor->processor_part_number)
>              continue;
> 
> -        virBufferAddLit(buf, "  <processor>\n");
> -        virBufferAdjustIndent(buf, 4);
> +        virBufferAddLit(buf, "<processor>\n");
> +        virBufferAdjustIndent(buf, 2);
>          virBufferEscapeString(buf,
>                                "<entry name='socket_destination'>%s</entry>\n",
>                                processor->processor_socket_destination);
> @@ -606,8 +610,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
>                                processor->processor_serial_number);
>          virBufferEscapeString(buf, "<entry name='part_number'>%s</entry>\n",
>                                processor->processor_part_number);
> -        virBufferAdjustIndent(buf, -4);
> -        virBufferAddLit(buf, "  </processor>\n");
> +        virBufferAdjustIndent(buf, -2);
> +        virBufferAddLit(buf, "</processor>\n");
>      }
>  }
> 
> @@ -632,34 +636,30 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
>              !memory->memory_part_number)
>              continue;
> 
> -        virBufferAddLit(buf, "  <memory_device>\n");
> -        virBufferEscapeString(buf, "    <entry name='size'>%s</entry>\n",
> +        virBufferAddLit(buf, "<memory_device>\n");
> +        virBufferAdjustIndent(buf, 2);
> +        virBufferEscapeString(buf, "<entry name='size'>%s</entry>\n",
>                                memory->memory_size);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='form_factor'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='form_factor'>%s</entry>\n",
>                                memory->memory_form_factor);
> -        virBufferEscapeString(buf, "    <entry name='locator'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='locator'>%s</entry>\n",
>                                memory->memory_locator);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='bank_locator'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='bank_locator'>%s</entry>\n",
>                                memory->memory_bank_locator);
> -        virBufferEscapeString(buf, "    <entry name='type'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='type'>%s</entry>\n",
>                                memory->memory_type);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='type_detail'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='type_detail'>%s</entry>\n",
>                                memory->memory_type_detail);
> -        virBufferEscapeString(buf, "    <entry name='speed'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='speed'>%s</entry>\n",
>                                memory->memory_speed);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='manufacturer'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
>                                memory->memory_manufacturer);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='serial_number'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='serial_number'>%s</entry>\n",
>                                memory->memory_serial_number);
> -        virBufferEscapeString(buf,
> -                              "    <entry name='part_number'>%s</entry>\n",
> +        virBufferEscapeString(buf, "<entry name='part_number'>%s</entry>\n",
>                                memory->memory_part_number);
> -        virBufferAddLit(buf, "  </memory_device>\n");
> +        virBufferAdjustIndent(buf, -2);
> +        virBufferAddLit(buf, "</memory_device>\n");
>      }
>  }
> 
> @@ -684,12 +684,14 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
>      }
> 
>      virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);
> +    virBufferAdjustIndent(buf, 2);
> 
>      virSysinfoBIOSFormat(buf, def);
>      virSysinfoSystemFormat(buf, def);
>      virSysinfoProcessorFormat(buf, def);
>      virSysinfoMemoryFormat(buf, def);
> 
> +    virBufferAdjustIndent(buf, -2);
>      virBufferAddLit(buf, "</sysinfo>\n");
> 
>      if (virBufferError(buf)) {



Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]