From 302b5ff8e1f1cc086b78658206670743ec04881a Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 12 Jan 2017 09:11:08 -0600
Subject: [PATCH 1/2] Low: libcrmcommon: add convenience function for copying
XML element
---
include/crm/common/xml.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/crm/common/xml.h b/include/crm/common/xml.h
index 150055b..a948915 100644
--- a/include/crm/common/xml.h
+++ b/include/crm/common/xml.h
@@ -210,6 +210,24 @@ crm_element_name(xmlNode *xml)
const char *crm_element_value(xmlNode * data, const char *name);
+/*!
+ * \brief Copy an element from one XML object to another
+ *
+ * \param[in] obj1 Source XML
+ * \param[in,out] obj2 Destination XML
+ * \param[in] element Name of element to copy
+ *
+ * \return Pointer to copied value (from source)
+ */
+static inline const char *
+crm_copy_xml_element(xmlNode *obj1, xmlNode *obj2, const char *element)
+{
+ const char *value = crm_element_value(obj1, element);
+
+ crm_xml_add(obj2, element, value);
+ return value;
+}
+
void xml_validate(const xmlNode * root);
gboolean xml_has_children(const xmlNode * root);
--
1.8.3.1
From 20a74b9d377c812abca651cb7ed7b4625ead76b1 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 12 Jan 2017 12:48:40 -0600
Subject: [PATCH 2/2] Fix: tools: properly ignore version with crm_diff
--no-version
Previously, crm_diff --no-version would remove the <version> information from
the generated patch, but it would still generate a change to update the
version. Now, it doesn't generate that change.
Based on patch originally provided by Andrew Beekhof <andrew@beekhof.net>
---
tools/xml_diff.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/tools/xml_diff.c b/tools/xml_diff.c
index cd3cb29..b27bd13 100644
--- a/tools/xml_diff.c
+++ b/tools/xml_diff.c
@@ -158,6 +158,13 @@ main(int argc, char **argv)
crm_help('?', EX_USAGE);
}
+ if (apply && no_version) {
+ fprintf(stderr, "warning: -u/--no-version ignored with -p/--patch\n");
+ } else if (as_cib && no_version) {
+ fprintf(stderr, "error: -u/--no-version incompatible with -c/--cib\n");
+ return 1;
+ }
+
if (raw_1) {
object_1 = string2xml(xml_file_1);
@@ -199,6 +206,21 @@ main(int argc, char **argv)
return rc;
}
} else {
+ int lpc = 0;
+ const char *vfields[] = {
+ XML_ATTR_GENERATION_ADMIN,
+ XML_ATTR_GENERATION,
+ XML_ATTR_NUMUPDATES,
+ };
+
+ /* If we're ignoring the version, make the version information
+ * identical, so it isn't detected as a change. */
+ if (no_version) {
+ for (lpc = 0; lpc < DIMOF(vfields); lpc++) {
+ crm_copy_xml_element(object_1, object_2, vfields[lpc]);
+ }
+ }
+
xml_track_changes(object_2, NULL, object_2, FALSE);
xml_calculate_changes(object_1, object_2);
crm_log_xml_debug(object_2, xml_file_2?xml_file_2:"target");
@@ -247,19 +269,11 @@ main(int argc, char **argv)
XML_TAG_DIFF_ADDED,
};
- const char *vfields[] = {
- XML_ATTR_GENERATION_ADMIN,
- XML_ATTR_GENERATION,
- XML_ATTR_NUMUPDATES,
- };
-
for (i = 0; i < DIMOF(tags); i++) {
xmlNode *tmp = NULL;
tmp = find_xml_node(output, tags[i], FALSE);
if (tmp) {
- int lpc = 0;
-
for (lpc = 0; lpc < DIMOF(vfields); lpc++) {
xml_remove_prop(tmp, vfields[lpc]);
}
--
1.8.3.1