HomeClusterLabs Projects

Refactor: libcrmcommon: Best practices for log_xml_changes()

Description

Refactor: libcrmcommon: Best practices for log_xml_changes()

Remove prefix argument (only ever called internally with
prefix == "+ "), add doxygen, streamline prefixes, use const where
appropriate, improve attr variable name, etc.

This function only has one internal caller besides itself. It's called
by log_data_element() via xml_log_changes() with prefix set to "+ ". The
prefix never changes in the recursive calls to log_xml_changes(), so
there's not much reason to keep that argument. With that in mind, we
remove the prefix argument.

This also simplifies the handling of various prefixes. Instead of
copying the passed-in prefix and modifying the copy, we use const
strings for the prefix indicating each type of change. In theory, this
could be problematic, since log_data_element() is public API and accepts
an arbitrary prefix. In practice, log_xml_changes() has always assumed
that the incoming prefix is "+ " (or at least begins with "+ ").
Otherwise, its copy-and-modify strategy would produce garbled or
nonsensical prefixes.

An upcoming commit will deprecate log_data_element(). Considering the
internal logic that it calls (for example, this function), it doesn't
make sense to allow external callers. They could pass in an arbitrary
prefix that, as mentioned above, produces a garbled result.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Dec 18 2022, 4:50 AM
Parents
rP400212a8f208: Refactor: libcrmcommon: Split log_xml_node_and_children: element/comment
Branches
Unknown
Tags
Unknown