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

Re: [libvirt] [PATCH 5/6] maint: use consistent if-else braces in remaining spots



On 09/04/2014 06:41 AM, Peter Krempa wrote:
> On 09/03/14 23:25, Eric Blake wrote:
>> I'm about to add a syntax check that enforces our documented
>> HACKING style of always using matching {} on if-else statements.
>>

>> @@ -873,9 +873,7 @@ esxVI_Type_FromString(const char *type)
>>
>>  #include "esx_vi_types.generated.typefromstring"
> 
> This file doesn't adhere to the style. (Generated by esx_vi_generator.py)
> 
>>
>> -    else {
>> -        return esxVI_Type_Other;
>> -    }
>> +    return esxVI_Type_Other;
>>  }

Easy enough to fix.


>>
>>      if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
>>          dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
>> -        if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML)
>> +        if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML) {
>>              ret = umlDomainDetachUmlDisk(driver, vm, dev);
>> -        else {
>> +        } else {
>>              virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>                             _("This type of disk cannot be hot unplugged"));
> 
> This is technically a single statement. I presume it's a false positive
> from your checker.

It was just as easy to fix it in either direction; the checker flagged
'else {' as being unbalanced.  I'll drop the else{} instead of adding if{}.


>> +++ b/src/util/virnetdev.c
>> @@ -1047,9 +1047,9 @@ int virNetDevValidateConfig(const char *ifname,
>>      }
>>
>>      if (ifindex != -1) {
>> -        if (virNetDevGetIndex(ifname, &idx) < 0)
>> +        if (virNetDevGetIndex(ifname, &idx) < 0) {
>>              goto cleanup;
> 
> In the previous patch you've solved one of such situations by dropping
> the else keyword and letting the next if to be free-standing. Anyways,
> this is correct.

Fixed.


>> -        /* Or if we have "name=" here (works around annoying
>> -         * problem when calling xmlURIUnescapeString with len = 0).
>> -         */
>> -        else if (eq+1 == end) {
>> +        } else if (eq+1 == end) {
> 
> Aren't we enforcing spaces around operators?

Not consistently :(
But not something for this patch to tweak.  Maybe I'll have to look into
why the syntax checker isn't flagging this, but it would be another day.

> 
> ACK,

Here's what I squashed in:

diff --git i/src/esx/esx_vi_generator.py w/src/esx/esx_vi_generator.py
index 0b75f18..bc026bd 100755
--- i/src/esx/esx_vi_generator.py
+++ w/src/esx/esx_vi_generator.py
@@ -3,6 +3,7 @@
 #
 # esx_vi_generator.py: generates most of the SOAP type mapping code
 #
+# Copyright (C) 2014 Red Hat, Inc.
 # Copyright (C) 2010-2012 Matthias Bolte <matthias bolte googlemail com>
 # Copyright (C) 2013 Ata E Husain Bohra <ata husain hotmail com>
 #
@@ -433,9 +434,8 @@ class Type:


     def generate_typefromstring(self):
-        string =  "           else if (STREQ(type, \"%s\")) {\n" %
self.name
+        string =  "           if (STREQ(type, \"%s\"))\n" % self.name
         string += "               return esxVI_Type_%s;\n" % self.name
-        string += "           }\n"

         return string

diff --git i/src/uml/uml_driver.c w/src/uml/uml_driver.c
index 22fa6db..5bede07 100644
--- i/src/uml/uml_driver.c
+++ w/src/uml/uml_driver.c
@@ -2362,12 +2362,11 @@ static int umlDomainDetachDevice(virDomainPtr
dom, const char *xml)

     if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
         dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-        if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML) {
+        if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML)
             ret = umlDomainDetachUmlDisk(driver, vm, dev);
-        } else {
+        else
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("This type of disk cannot be hot unplugged"));
-        }
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        "%s", _("This type of device cannot be hot
unplugged"));
diff --git i/src/util/virnetdev.c w/src/util/virnetdev.c
index cf526ec..6a8c6ae 100644
--- i/src/util/virnetdev.c
+++ w/src/util/virnetdev.c
@@ -1047,9 +1047,9 @@ int virNetDevValidateConfig(const char *ifname,
     }

     if (ifindex != -1) {
-        if (virNetDevGetIndex(ifname, &idx) < 0) {
+        if (virNetDevGetIndex(ifname, &idx) < 0)
             goto cleanup;
-        } else if (idx != ifindex) {
+        if (idx != ifindex) {
             ret = 0;
             goto cleanup;
         }

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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