diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6aeef3e5c5a570c1cc36a2d17628210d50c57c49..d3156de522a132a1254ccde9f4541e3dc0f22ad1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28487,7 +28487,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7f8e43b25c86755d0ca134762958e780014886f3..1d20d28f4662ac5e907cd34596246fc994a79973 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2458,7 +2458,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 0d2721b118dbdc30f4797c1755ad5419a5c9f26a..bf703fe7a5a6528e41de303cc17f4a28b05e0ba8 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -102,18 +102,12 @@ virBufferSetIndent(virBufferPtr buf, int indent) /** * virBufferGetIndent: * @buf: the buffer - * @dynamic: if false, return set value; if true, return 0 unless next - * append would be affected by auto-indent * - * Return the current auto-indent value, or -1 if there has been an error. + * Return the current auto-indent setting of @buf. */ -int -virBufferGetIndent(const virBuffer *buf, bool dynamic) +size_t +virBufferGetIndent(const virBuffer *buf) { - if (!buf || buf->error) - return -1; - if (dynamic && buf->use && buf->content[buf->use - 1] != '\n') - return 0; return buf->indent; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 7156d9d0d8aeeee70de34a05568b18fb7e702d8a..6c41a7ea2050fa3457995fa96133e205e502cfdf 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -107,9 +107,9 @@ void virBufferSetIndent(virBufferPtr, int indent); * child buffer. */ #define virBufferSetChildIndent(childBuf_, parentBuf_) \ - virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2) + virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_) + 2) -int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetIndent(const virBuffer *buf); size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 42b2550a03a1d4007ab90b9349f6e85a9525c6fa..9a1b1fea07d4eccc6537525086151d90f3f47ab1 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -430,7 +430,7 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj, virBufferAddLit(debug, "(\n"); virBufferAdjustIndent(debug, 3); - indent = virBufferGetIndent(debug, false); + indent = virBufferGetIndent(debug); n = virJSONValueArraySize(members); for (i = 0; i < n; i++) { diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 0c806908e19acc20d683c18bfa7c13eb02bd313b..34aa8b678bed5a12d9ecd98eaee23158a6f31b9c 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -18,7 +18,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) char *result = NULL; int ret = 0; - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; @@ -28,28 +28,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 3 || + if (virBufferGetIndent(buf) != 3 || virBufferGetEffectiveIndent(buf) != 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -2); - if (virBufferGetIndent(buf, false) != 1 || + if (virBufferGetIndent(buf) != 1 || virBufferGetEffectiveIndent(buf) != 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret = -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); @@ -65,7 +65,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 2 || + if (virBufferGetIndent(buf) != 2 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1;