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

Re: [libvirt] [PATCH 01/14] snapshot: indent domain xml when nesting, round 1



On 09/27/2011 03:03 AM, Daniel P. Berrange wrote:
On Thu, Sep 22, 2011 at 02:34:55PM -0600, Eric Blake wrote:
Future patches can take advantage of this to generate nicer
XML output with parameterizable indentation.


Hmm, is there any way we can work with virBuffer so that we don't
need to pass an indent level to every single API call ?

eg, can we have something which lets us do

    virBufferSetIndent(buf, "     ");

and then it will automagically prepend that indent every time
a API call is made following a newline. If we could do this,
then pretty much all of your patches would disappear

I think there's still some other aspects in the other patches that may mean that things won't disappear entirely, but I like the idea. I see several potential usage styles:

virBufferIndent...(indent, "<parent>\n");
virBufferIndent...(indent + 2, "<child/>\n");
virBufferIndent...(indent, "</parent>\n");

or

virBufferAddIndent(indent);
virBuffer...("<parent>\n");
virBuffer...("  <child/>\n");
virBuffer...("</parent>\n");
virBufferAddIndent(-indent);

or

virBufferAddIndent(indent);
virBuffer...("<parent>\n");
virBufferAddIndent(2);
virBuffer...("<child/>\n");
virBufferAddIndent(-2);
virBuffer...("</parent>\n");
virBufferAddIndent(-indent);

and so on. And for all three styles above, there's code modifications, whether to pass the indentation, or to prep and cleanup indentation before the unchanged original text. But I definitely like your idea, since there are fewer points to prep and cleanup instead of changing every single format line. Having virBuffer track an indent to automagically add on any new API call if the previous API left a trailing newline makes sense, so I'll roll out a v2 with that incorporated.

--
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


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