[gnumeric] ssdiff: fix checking of conditional formats.



commit 7054da07e71aba6da35640b3fc85dd427299565f
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 17 12:55:51 2017 -0400

    ssdiff: fix checking of conditional formats.
    
    This fixes the last check that used to trigger spurious differences simply
    because the styles were linked into two different sheets.

 ChangeLog              |    3 +++
 NEWS                   |    3 ++-
 src/mstyle.c           |    5 ++---
 src/ssdiff.c           |    1 -
 src/style-conditions.c |   13 ++++++++-----
 src/style-conditions.h |    3 ++-
 6 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f3371aa..d7215db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2017-03-17  Morten Welinder  <terra gnome org>
 
+       * src/style-conditions.c (gnm_style_conditions_equal): Add new
+       relax_sheet argument.
+
        * src/validation.c (gnm_validation_equal): New function.
 
        * src/mstyle.c (gnm_style_find_differences): New function.
diff --git a/NEWS b/NEWS
index 72559ce..be0b3ea 100644
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,8 @@ Morten:
        * Hyperlinks improvements.  [#706671]
        * Plug leaks.
        * Fix issues with sheet-local names.
-       * ssdiff improvements with hyperlinks, input messages, and validations.
+       * ssdiff improvements with hyperlinks, input messages,
+         conditional formats, and validations.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.33
diff --git a/src/mstyle.c b/src/mstyle.c
index a60c8de..521345f 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -397,7 +397,7 @@ gnm_style_hash (gconstpointer style)
     : (elem == MSTYLE_CONDITIONS                                       \
     ? (a->conditions == b->conditions ||                               \
        (a->conditions && b->conditions &&                              \
-       gnm_style_conditions_equal (a->conditions, b->conditions)))     \
+       gnm_style_conditions_equal (a->conditions, b->conditions, FALSE)))      \
     : FALSE)))))))))))))))))))))))))
 
 /*
@@ -580,8 +580,7 @@ gnm_style_find_differences (GnmStyle const *a, GnmStyle const *b,
                RELAX_CHECK (MSTYLE_HLINK, hlink, gnm_hlink_equal);
                RELAX_CHECK (MSTYLE_VALIDATION, validation, gnm_validation_equal);
                RELAX_CHECK (MSTYLE_INPUT_MSG, input_msg, GNM_INPUT_MSG_EQUAL3);
-
-               // FIXME: Conditions
+               RELAX_CHECK (MSTYLE_CONDITIONS, conditions, gnm_style_conditions_equal);
        }
 
        return diffs;
diff --git a/src/ssdiff.c b/src/ssdiff.c
index d17a7bd..a3fc0c4 100644
--- a/src/ssdiff.c
+++ b/src/ssdiff.c
@@ -691,7 +691,6 @@ xml_style_changed (GnmDiffState *state, GnmRange const *r,
 
                case MSTYLE_CONDITIONS:
                        gsf_xml_out_start_element (state->xml, "Conditions");
-                       gsf_xml_out_add_cstr_unchecked (state->xml, NULL, "<!-- Difference might be spurious 
-->");
                        gsf_xml_out_end_element (state->xml); /* </Conditions> */
                        break;
 
diff --git a/src/style-conditions.c b/src/style-conditions.c
index d6921ad..f2663cd 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -658,7 +658,8 @@ gnm_style_cond_eval (GnmStyleCond const *cond, GnmValue const *cv,
 }
 
 static gboolean
-gnm_style_cond_equal (GnmStyleCond const *ca, GnmStyleCond const *cb)
+gnm_style_cond_equal (GnmStyleCond const *ca, GnmStyleCond const *cb,
+                     gboolean relax_sheet)
 {
        unsigned oi, N;
 
@@ -670,7 +671,7 @@ gnm_style_cond_equal (GnmStyleCond const *ca, GnmStyleCond const *cb)
 
        N = gnm_style_cond_op_operands (ca->op);
        for (oi = 0; oi < N; oi++) {
-               if (ca->deps[oi].sheet != cb->deps[oi].sheet)
+               if (!relax_sheet && ca->deps[oi].sheet != cb->deps[oi].sheet)
                        return FALSE;
                if (!gnm_expr_top_equal (ca->deps[oi].texpr,
                                         cb->deps[oi].texpr))
@@ -792,12 +793,14 @@ gnm_style_conditions_hash (GnmStyleConditions const *sc)
  * gnm_style_conditions_equal:
  * @sca: first #GnmStyleConditions to compare.
  * @scb: second #GnmStyleConditions to compare.
+ * @relax_sheet: if %TRUE, ignore differences solely caused by being linked into different sheets.
  *
  * Returns: %TRUE if the conditions are equal.
  **/
 gboolean
 gnm_style_conditions_equal (GnmStyleConditions const *sca,
-                           GnmStyleConditions const *scb)
+                           GnmStyleConditions const *scb,
+                           gboolean relax_sheet)
 {
        GPtrArray const *ga, *gb;
        unsigned ui;
@@ -805,7 +808,7 @@ gnm_style_conditions_equal (GnmStyleConditions const *sca,
        g_return_val_if_fail (sca != NULL, FALSE);
        g_return_val_if_fail (scb != NULL, FALSE);
 
-       if (sca->sheet != scb->sheet)
+       if (!relax_sheet && sca->sheet != scb->sheet)
                return FALSE;
 
        ga = gnm_style_conditions_details (sca);
@@ -818,7 +821,7 @@ gnm_style_conditions_equal (GnmStyleConditions const *sca,
        for (ui = 0; ui < ga->len; ui++) {
                GnmStyleCond const *ca = g_ptr_array_index (ga, ui);
                GnmStyleCond const *cb = g_ptr_array_index (gb, ui);
-               if (!gnm_style_cond_equal (ca, cb))
+               if (!gnm_style_cond_equal (ca, cb, relax_sheet))
                        return FALSE;
        }
 
diff --git a/src/style-conditions.h b/src/style-conditions.h
index 00d588e..29d6491 100644
--- a/src/style-conditions.h
+++ b/src/style-conditions.h
@@ -85,7 +85,8 @@ void        gnm_style_conditions_set_sheet (GnmStyleConditions *sc,
 guint32     gnm_style_conditions_hash      (GnmStyleConditions const *sc);
 
 gboolean    gnm_style_conditions_equal     (GnmStyleConditions const *sca,
-                                           GnmStyleConditions const *scb);
+                                           GnmStyleConditions const *scb,
+                                           gboolean relax_sheet);
 
 G_END_DECLS
 


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