[gnumeric] ssdiff: fix cell diffs with inter-sheet references.



commit 96b22d1e4dcce4786a88d07d8503d862899fcb6c
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 17 14:35:36 2017 -0400

    ssdiff: fix cell diffs with inter-sheet references.

 ChangeLog    |    3 +++
 NEWS         |    1 +
 src/ssdiff.c |   26 ++++++++++++++++++++++++--
 3 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 39f1fec..5fef8c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 2017-03-17  Morten Welinder  <terra gnome org>
 
        * src/ssdiff.c (main): Exit 2 on error, 1 of diffs, 0 if no diff.
+       (compare_corresponding_cells): Fall back to string comparison.
+       References like Sheet1!A1 should match even if they, obviously,
+       refer to sheets in different workbooks.
 
        * src/style-conditions.c (gnm_style_conditions_equal): Add new
        relax_sheet argument.
diff --git a/NEWS b/NEWS
index e024f9d..60a8fd5 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ Morten:
        * ssdiff improvements with hyperlinks, input messages,
          conditional formats, and validations.
        * Make exit code from ssdiff follow diff's.
+       * Fix ssdiff with inter-sheet references.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.33
diff --git a/src/ssdiff.c b/src/ssdiff.c
index f0c8ad7..5565b18 100644
--- a/src/ssdiff.c
+++ b/src/ssdiff.c
@@ -812,8 +812,30 @@ compare_corresponding_cells (GnmCell const *co, GnmCell const *cn)
 
        if (has_expr != gnm_cell_has_expr (cn))
                return TRUE;
-       if (has_expr)
-               return !gnm_expr_top_equal (co->base.texpr, cn->base.texpr);
+       if (has_expr) {
+               char *so, *sn;
+               GnmParsePos ppo, ppn;
+               gboolean eq;
+
+               if (gnm_expr_top_equal (co->base.texpr, cn->base.texpr))
+                       return FALSE;
+
+               // Not equal, but with references to sheets, that is not
+               // necessary.  Compare as strings.
+
+               parse_pos_init_cell (&ppo, co);
+               so = gnm_expr_top_as_string (co->base.texpr, &ppo, sheet_get_conventions (co->base.sheet));
+
+               parse_pos_init_cell (&ppn, cn);
+               sn = gnm_expr_top_as_string (cn->base.texpr, &ppn, sheet_get_conventions (cn->base.sheet));
+
+               eq = g_strcmp0 (so, sn) == 0;
+
+               g_free (so);
+               g_free (sn);
+
+               return !eq;
+       }
 
        if (has_value != (cn->value != NULL))
                return TRUE;


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