r16415 - gnucash/branches/register-rewrite/src/engine - Clean-up the semantics of xaccDupeTransaction.
Chris Shoemaker
chris at cvs.gnucash.org
Sat Aug 11 16:55:44 EDT 2007
Author: chris
Date: 2007-08-11 16:47:13 -0400 (Sat, 11 Aug 2007)
New Revision: 16415
Trac: http://svn.gnucash.org/trac/changeset/16415
Modified:
gnucash/branches/register-rewrite/src/engine/Period.c
gnucash/branches/register-rewrite/src/engine/Transaction.c
Log:
Clean-up the semantics of xaccDupeTransaction.
- If the transaction to be duplicated is being edited and has had
some splits removed, don't dupe those.
- Go ahead and parent the duped splits to the new transaction. There's
no good reason not to do this, and not doing it is just way too confusing.
- Clearly document what to expect from duped transactions, instead of
vaguely warning about weirdness.
Modified: gnucash/branches/register-rewrite/src/engine/Period.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/Period.c 2007-08-11 15:10:15 UTC (rev 16414)
+++ gnucash/branches/register-rewrite/src/engine/Period.c 2007-08-11 20:47:13 UTC (rev 16415)
@@ -76,11 +76,6 @@
ENTER ("trans=%p %s", trans, trans->description);
newtrans = xaccDupeTransaction (trans);
- for (node = newtrans->splits; node; node = node->next)
- {
- Split *s = node->data;
- s->parent = newtrans;
- }
/* Utterly wipe out the transaction from the old book. */
xaccTransBeginEdit (trans);
Modified: gnucash/branches/register-rewrite/src/engine/Transaction.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/Transaction.c 2007-08-11 15:10:15 UTC (rev 16414)
+++ gnucash/branches/register-rewrite/src/engine/Transaction.c 2007-08-11 20:47:13 UTC (rev 16415)
@@ -342,12 +342,17 @@
/********************************************************************\
\********************************************************************/
-/* This routine is not exposed externally, since it does weird things,
- * like not really owning the splits correctly, and other weirdnesses.
- * This routine is prone to programmer snafu if not used correctly.
- * It is used only by the edit-rollback code.
+/* This function must be used carefully. The resulting transaction is
+ * not really a valid transaction. Its splits will be copies of the
+ * original transaction's splits, and they will be correctly parented
+ * to the new, invalid transaction. However, these new splits will
+ * not really belong to any accounts, even though they will claim to
+ * belong to the same accounts as the original transaction's splits.
+ *
+ * Also, the duplicate transaction is created without generating any
+ * of the events that would normally be generated if the transaction
+ * had been created normally.
*/
-/* Actually, it *is* public, and used by Period.c */
Transaction *
xaccDupeTransaction (const Transaction *t)
{
@@ -359,12 +364,16 @@
trans->num = CACHE_INSERT (t->num);
trans->description = CACHE_INSERT (t->description);
- trans->splits = g_list_copy (t->splits);
- for (node = trans->splits; node; node = node->next)
- {
- node->data = xaccDupeSplit (node->data);
- }
+ trans->splits = NULL;
+ FOR_EACH_SPLIT(t, {
+ s = xaccDupeSplit(s);
+ s->parent = trans;
+ trans->splits = g_list_prepend(trans->splits, s);
+ });
+
+ trans->splits = g_list_reverse(trans->splits);
+
trans->date_entered = t->date_entered;
trans->date_posted = t->date_posted;
trans->version = t->version;
@@ -373,7 +382,7 @@
trans->common_currency = t->common_currency;
/* Trash the guid and entity table. We don't want to mistake
- * the cloned transaction as something official. If we ever
+ * the duped transaction as something official. If we ever
* use this transaction, we'll have to fix this up.
*/
trans->inst.entity.e_type = NULL;
More information about the gnucash-changes
mailing list