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

Re: [libvirt] [PATCHv2] spec: indent %if to make it easier to see conditions

On 01/21/2013 04:58 AM, Daniel P. Berrange wrote:
> On Fri, Jan 18, 2013 at 09:58:22AM -0700, Eric Blake wrote:
>> Nested conditionals are hard to read if they are not indented.
>> We can't add arbitrary whitespace to everything in spec files,
>> but we CAN add spaces before %if and %define.  Use this trick,
>> plus a fancy sed script that rewrites a spec file into a C
>> file, so we can use cppi to keep our spec file nice.
> What would you say to making the indent level either 2 or 4
> space. With only one space, I still find it rather hard to
> visually match up vertical alignment in our header files.
> 4 space indent would match our source code indent, but if
> you didn't want to go that far, 2 would be acceptable
> compromise.

My use of cppi limits us to 1 space indentation in the C file that it
checks; but since I'm already processing things through a sed script to
get to a C file, I can rather easily alter the number of spaces that
cppi sees :)

Here's the diff I squashed in to convert the syntax check to 4-space
indent; the one-time actual diff of the files themselves was trivial
(done with:
 sed -i 's/^\( *\)%/\1\1\1\1%/' *.spec.in
and does not show up to 'git diff -b' in relation to the posted v2), so
I've gone ahead and pushed this patch (given that you acked the concept
in v1 and that I resolved your concern about indentation level).

diff --git i/cfg.mk w/cfg.mk
index 7c8ba2e..d9ab2da 100644
--- i/cfg.mk
+++ w/cfg.mk
@@ -630,7 +630,7 @@ sc_spec_indentation:
 	  for f in $$($(VC_LIST_EXCEPT) | grep '\.spec\.in$$'); do	\
 	    sed -e 's|#|// #|; s|%ifn*\(arch\)* |#if a // |'		\
 		-e 's/%\(else\|endif\|define\)/#\1/'			\
-		-e 's/^\( *\)#/#\1/; s|^\([^#/]\)|// \1|' $$f 		\
+		-e 's/^\( *\)\1\1\1#/#\1/; s|^\( *[^#/]\)|// \1|' $$f	\
 	    | cppi -a -c 2>&1 | sed "s|standard input|$$f|";		\
 	  done | { if grep . >&2; then false; else :; fi; }		\
 	    || { echo '$(ME): incorrect preprocessor indentation' 1>&2;	\

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]