]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: virbuffer: Remove @dynamic from virBufferGetIndent
authorPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 10:51:24 +0000 (12:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 17:35:34 +0000 (19:35 +0200)
After the conversion of all callers that would pass true as @dynamic to
a different function we can remove the unused argument now.

Additionally modify the return type to 'size_t' as indentation can't be
negative and remove checks whether @buf is passed as it's caller's duty
to do so.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/network_conf.c
src/util/virbuffer.c
src/util/virbuffer.h
tests/testutilsqemuschema.c
tests/virbuftest.c

index 6aeef3e5c5a570c1cc36a2d17628210d50c57c49..d3156de522a132a1254ccde9f4541e3dc0f22ad1 100644 (file)
@@ -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;
index 7f8e43b25c86755d0ca134762958e780014886f3..1d20d28f4662ac5e907cd34596246fc994a79973 100644 (file)
@@ -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;
index 0d2721b118dbdc30f4797c1755ad5419a5c9f26a..bf703fe7a5a6528e41de303cc17f4a28b05e0ba8 100644 (file)
@@ -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;
 }
 
index 7156d9d0d8aeeee70de34a05568b18fb7e702d8a..6c41a7ea2050fa3457995fa96133e205e502cfdf 100644 (file)
@@ -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);
index 42b2550a03a1d4007ab90b9349f6e85a9525c6fa..9a1b1fea07d4eccc6537525086151d90f3f47ab1 100644 (file)
@@ -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++) {
index 0c806908e19acc20d683c18bfa7c13eb02bd313b..34aa8b678bed5a12d9ecd98eaee23158a6f31b9c 100644 (file)
@@ -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;