[gnumeric] ssdiff: fix handling of hyperlinks.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] ssdiff: fix handling of hyperlinks.
- Date: Fri, 17 Mar 2017 15:44:48 +0000 (UTC)
commit 87ac5117fda25eab9cf9f1fbe690bd8db9836dd7
Author: Morten Welinder <terra gnome org>
Date: Fri Mar 17 11:43:04 2017 -0400
ssdiff: fix handling of hyperlinks.
This checks whether the links are actually changed instead of using
pointer identify which never was right and now will always be false.
ChangeLog | 12 ++++++++++++
NEWS | 1 +
src/hlink.c | 21 +++++++++++++++++++++
src/hlink.h | 2 ++
src/mstyle.c | 39 +++++++++++++++++++++++++++++++++++++++
src/mstyle.h | 3 +++
src/ssdiff.c | 7 ++-----
7 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 199e11e..d5c6cde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-03-17 Morten Welinder <terra gnome org>
+
+ * src/mstyle.c (gnm_style_find_differences): New function.
+
+ * src/ssdiff.c (xml_style_changed): Use
+ gnm_style_find_differences.
+
+ * src/ssdiff.c (cb_diff_sheets_styles_2): Use relaxed
+ gnm_style_find_differences, not gnm_style_equal.
+
+ * src/hlink.c (gnm_hlink_equal): New function.
+
2017-03-13 Morten Welinder <terra gnome org>
* src/hlink.c (gnm_hlink_cur_wb_set_target): Improve parsing of
diff --git a/NEWS b/NEWS
index 553e16f..dc494f2 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Morten:
* Hyperlinks improvements. [#706671]
* Plug leaks.
* Fix issues with sheet-local names.
+ * ssdiff improvements with hyperlinks.
--------------------------------------------------------------------------
Gnumeric 1.12.33
diff --git a/src/hlink.c b/src/hlink.c
index 55134c9..1d512a0 100644
--- a/src/hlink.c
+++ b/src/hlink.c
@@ -227,6 +227,27 @@ gnm_hlink_dup (GnmHLink *lnk)
return new_lnk;
}
+/**
+ * gnm_hlink_equal:
+ * @a: a #GnmHLink
+ * @b: a #GnmHLink
+ * @relax_sheet: if %TRUE, ignore differences solely caused by being linked into different sheets.
+ *
+ * Returns: %TRUE, if links are equal
+ */
+gboolean
+gnm_hlink_equal (GnmHLink const *a, GnmHLink const *b, gboolean relax_sheet)
+{
+ g_return_val_if_fail (GNM_IS_HLINK (a), NULL);
+ g_return_val_if_fail (GNM_IS_HLINK (b), NULL);
+
+ if (!relax_sheet && a->sheet != b->sheet)
+ return FALSE;
+
+ return (g_strcmp0 (a->target, b->target) == 0 &&
+ g_strcmp0 (a->tip, b->tip) == 0);
+}
+
/***************************************************************************/
/* Link to named regions within the current workbook */
typedef struct { GnmHLinkClass hlink; } GnmHLinkCurWBClass;
diff --git a/src/hlink.h b/src/hlink.h
index 8d753a0..85cea42 100644
--- a/src/hlink.h
+++ b/src/hlink.h
@@ -23,6 +23,8 @@ GType gnm_hlink_get_type (void);
GnmHLink *gnm_hlink_new (GType typ, Sheet *sheet);
GnmHLink *gnm_hlink_dup (GnmHLink *lnk);
+gboolean gnm_hlink_equal (GnmHLink const *a, GnmHLink const *b, gboolean relax_sheet);
+
gboolean gnm_hlink_activate (GnmHLink *lnk, WBCGtk *wbcg);
const char *gnm_hlink_get_target (GnmHLink const *lnk);
diff --git a/src/mstyle.c b/src/mstyle.c
index c85b136..1ca5455 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -540,6 +540,45 @@ gnm_style_find_conflicts (GnmStyle *accum, GnmStyle const *overlay,
return conflicts;
}
+/**
+ * gnm_style_find_differences:
+ * @a: A #GnmStyle
+ * @b: A #GnmStyle
+ * @relax_sheet: if %TRUE, ignore differences solely caused by being linked into different sheets.
+ *
+ * Determine how two fully-qualified styles differ.
+ *
+ * Returns differences as a bitset of #GnmStyleElement.
+ **/
+unsigned int
+gnm_style_find_differences (GnmStyle const *a, GnmStyle const *b,
+ gboolean relax_sheet)
+{
+ int i;
+ unsigned int diffs = 0;
+
+ g_assert (MSTYLE_ELEMENT_MAX <= CHAR_BIT * sizeof (diffs));
+
+ for (i = 0; i < MSTYLE_ELEMENT_MAX; i++) {
+ if (elem_is_set (a, i) != elem_is_set (b, i) ||
+ (elem_is_set (a, i) && !elem_is_eq (a, b, i)))
+ diffs |= (1u << i);
+ }
+
+ if (relax_sheet) {
+ if (a->hlink && b->hlink &&
+ gnm_hlink_equal (a->hlink, b->hlink, relax_sheet))
+ diffs &= ~(1u << MSTYLE_HLINK);
+
+ // FIXME: Validations
+
+ // FIXME: Conditions
+ }
+
+ return diffs;
+}
+
+
static inline void
gnm_style_clear_pango (GnmStyle *style)
{
diff --git a/src/mstyle.h b/src/mstyle.h
index 17c4b64..dd87026 100644
--- a/src/mstyle.h
+++ b/src/mstyle.h
@@ -90,6 +90,9 @@ int gnm_style_cmp (GnmStyle const *a, GnmStyle const *b);
unsigned int gnm_style_find_conflicts (GnmStyle *accum, GnmStyle const *overlay,
unsigned int conflicts);
+unsigned int gnm_style_find_differences (GnmStyle const *a, GnmStyle const *b,
+ gboolean relax_sheet);
+
gboolean gnm_style_is_complete (GnmStyle const *style);
gboolean gnm_style_is_element_set (GnmStyle const *style, GnmStyleElement elem);
void gnm_style_unset_element (GnmStyle *style, GnmStyleElement elem);
diff --git a/src/ssdiff.c b/src/ssdiff.c
index cc879aa..f8094a1 100644
--- a/src/ssdiff.c
+++ b/src/ssdiff.c
@@ -487,7 +487,6 @@ xml_style_changed (GnmDiffState *state, GnmRange const *r,
{
unsigned int conflicts;
GnmStyleElement e;
- GnmStyle *os_copy;
xml_close_cells (state);
@@ -502,9 +501,7 @@ xml_style_changed (GnmDiffState *state, GnmRange const *r,
gsf_xml_out_add_uint (state->xml, "endCol", r->end.col);
gsf_xml_out_add_uint (state->xml, "endRow", r->end.row);
- os_copy = gnm_style_dup (os);
- conflicts = gnm_style_find_conflicts (os_copy, ns, 0);
- gnm_style_unref (os_copy);
+ conflicts = gnm_style_find_differences (os, ns, TRUE);
for (e = 0; e < MSTYLE_ELEMENT_MAX; e++) {
if ((conflicts & (1u << e)) == 0)
continue;
@@ -943,7 +940,7 @@ cb_diff_sheets_styles_2 (G_GNUC_UNUSED gpointer key,
struct cb_diff_sheets_styles *data = user_data;
GnmRange r = sr->range;
- if (gnm_style_equal (data->old_style, sr->style))
+ if (gnm_style_find_differences (data->old_style, sr->style, TRUE) == 0)
return;
data->state->actions->style_changed (data->state, &r,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]