[PATCH] sort lots on save for file repeatability and cleaner diffs

Jim Radford radford at blackbean.org
Wed Apr 23 18:47:38 EDT 2008

The following patch is an attempt to make a gnucash saves more
idempotent by sorting the lots when saving them to an XML file.

With this patch when using a revision control system to keep track of
a gnucash file, most of the churn from simple changes is minimized,
allowing just important changes to show up in diffs.  In addition,
adding a transaction, deleting it and then saving gets me back to the
same file consistently now.

Surely there are other fields to be sorted, but sorting just lots has
so far been useful.


diff -u gnucash-2.2.4/src/backend/file/gnc-account-xml-v2.c gnucash-2.2.4-sorted/src/backend/file/gnc-account-xml-v2.c
--- gnucash-2.2.4/src/backend/file/gnc-account-xml-v2.c	2008-03-02 05:24:27.000000000 -0800
+++ gnucash-2.2.4-sorted/src/backend/file/gnc-account-xml-v2.c	2008-04-23 15:06:13.000000000 -0700
@@ -139,6 +139,8 @@
        xmlNodePtr toaddto = xmlNewChild(ret, NULL, BAD_CAST act_lots_string, NULL);
+       lots = g_list_sort(lots, qof_instance_guid_compare);
        for (n = lots; n; n=n->next)
           GNCLot * lot = n->data;

More information about the gnucash-devel mailing list