r18962 - gnucash/trunk/src/engine - Extend xaccXXXXXEqual() routines so that they can compare objects in different books to see if they have the same contents.

Phil Longstaff plongstaff at code.gnucash.org
Thu Mar 25 14:32:41 EDT 2010


Author: plongstaff
Date: 2010-03-25 14:32:40 -0400 (Thu, 25 Mar 2010)
New Revision: 18962
Trac: http://svn.gnucash.org/trac/changeset/18962

Modified:
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-commodity.c
Log:
Extend xaccXXXXXEqual() routines so that they can compare objects in different books to see if they have the same contents.


Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2010-03-24 19:28:20 UTC (rev 18961)
+++ gnucash/trunk/src/engine/Split.c	2010-03-25 18:32:40 UTC (rev 18962)
@@ -540,6 +540,8 @@
                gboolean check_balances,
                gboolean check_txn_splits)
 {
+    gboolean same_book;
+
     if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
 
     if (!sa || !sb)
@@ -550,6 +552,8 @@
 
     if (sa == sb) return TRUE;
 
+    same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
+
     if (check_guids)
     {
         if (qof_instance_guid_compare(sa, sb) != 0)
@@ -559,15 +563,15 @@
         }
     }
 
-    /* Since these strings are cached we can just use pointer equality */
-    if (sa->memo != sb->memo)
+    /* If the same book, since these strings are cached we can just use pointer equality */
+    if ((same_book && sa->memo != sb->memo) || (!same_book && safe_strcmp(sa->memo, sb->memo) != 0))
     {
         PWARN ("memos differ: (%p)%s vs (%p)%s",
                sa->memo, sa->memo, sb->memo, sb->memo);
         return FALSE;
     }
 
-    if (sa->action != sb->action)
+    if ((same_book && sa->action != sb->action) || (!same_book && safe_strcmp(sa->action, sb->action) != 0))
     {
         PWARN ("actions differ: %s vs %s", sa->action, sb->action);
         return FALSE;

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2010-03-24 19:28:20 UTC (rev 18961)
+++ gnucash/trunk/src/engine/Transaction.c	2010-03-25 18:32:40 UTC (rev 18962)
@@ -677,6 +677,8 @@
                gboolean check_balances,
                gboolean assume_ordered)
 {
+    gboolean same_book;
+
     if (!ta && !tb) return TRUE; /* Arguable.  FALSE may be better. */
 
     if (!ta || !tb)
@@ -687,6 +689,8 @@
 
     if (ta == tb) return TRUE;
 
+    same_book = qof_instance_get_book(QOF_INSTANCE(ta)) == qof_instance_get_book(QOF_INSTANCE(tb));
+
     if (check_guids)
     {
         if (qof_instance_guid_compare(ta, tb) != 0)
@@ -706,26 +710,37 @@
 
     if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
     {
-        PWARN ("date entered differs");
+        char buf1[100];
+        char buf2[100];
+
+        (void)gnc_timespec_to_iso8601_buff(ta->date_entered, buf1);
+        (void)gnc_timespec_to_iso8601_buff(tb->date_entered, buf2);
+        PWARN ("date entered differs: '%s' vs '%s'", buf1, buf2);
         return FALSE;
     }
 
     if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
     {
-        PWARN ("date posted differs");
+        char buf1[100];
+        char buf2[100];
+
+        (void)gnc_timespec_to_iso8601_buff(ta->date_posted, buf1);
+        (void)gnc_timespec_to_iso8601_buff(tb->date_posted, buf2);
+        PWARN ("date posted differs: '%s' vs '%s'", buf1, buf2);
         return FALSE;
     }
 
-    /* Since we use cached strings, we can just compare pointer
+    /* If the same book, since we use cached strings, we can just compare pointer
      * equality for num and description
      */
-    if (ta->num != tb->num)
+    if ((same_book && ta->num != tb->num) || (!same_book && safe_strcmp(ta->num, tb->num) != 0))
     {
         PWARN ("num differs: %s vs %s", ta->num, tb->num);
         return FALSE;
     }
 
-    if (ta->description != tb->description)
+    if ((same_book && ta->description != tb->description)
+        || (!same_book && safe_strcmp(ta->description, tb->description)))
     {
         PWARN ("descriptions differ: %s vs %s", ta->description, tb->description);
         return FALSE;
@@ -1338,7 +1353,7 @@
         tv.tv_usec = 0;
 #endif
         trans->date_entered.tv_sec = tv.tv_sec;
-        trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
+//        trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
         qof_instance_set_dirty(QOF_INSTANCE(trans));
     }
 

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2010-03-24 19:28:20 UTC (rev 18961)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2010-03-25 18:32:40 UTC (rev 18962)
@@ -1454,6 +1454,7 @@
 {
     CommodityPrivate* priv_a;
     CommodityPrivate* priv_b;
+    gboolean same_book;
 
     if (a == b) return TRUE;
 
@@ -1465,8 +1466,11 @@
 
     priv_a = GET_PRIVATE(a);
     priv_b = GET_PRIVATE(b);
+    same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));
 
-    if (priv_a->namespace != priv_b->namespace)
+    if ((same_book && priv_a->namespace != priv_b->namespace)
+            || (!same_book && safe_strcmp( gnc_commodity_namespace_get_name(priv_a->namespace),
+                                           gnc_commodity_namespace_get_name(priv_b->namespace)) != 0))
     {
         DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
                priv_a->namespace, gnc_commodity_namespace_get_name(priv_a->namespace),



More information about the gnucash-changes mailing list