[Gnucash-changes] r12322 - gnucash/trunk/src/engine - Factor-out cut-n-paste job from xaccCloneAccount{Simple}.

Chris Shoemaker chris at cvs.gnucash.org
Tue Jan 10 23:39:12 EST 2006


Author: chris
Date: 2006-01-10 23:39:12 -0500 (Tue, 10 Jan 2006)
New Revision: 12322
Trac: http://svn.gnucash.org/trac/changeset/12322

Modified:
   gnucash/trunk/src/engine/Account.c
Log:
Factor-out cut-n-paste job from xaccCloneAccount{Simple}.


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2006-01-11 04:30:20 UTC (rev 12321)
+++ gnucash/trunk/src/engine/Account.c	2006-01-11 04:39:12 UTC (rev 12322)
@@ -121,8 +121,8 @@
   return acc;
 }
 
-Account *
-xaccCloneAccountSimple(const Account *from, QofBook *book)
+static Account *
+xaccCloneAccountCommon(const Account *from, QofBook *book)
 {
     Account *ret;
 
@@ -151,47 +151,24 @@
 
     ret->commodity_scu = from->commodity_scu;
     ret->non_standard_scu = from->non_standard_scu;
-    ret->inst.dirty   = TRUE;
 
     LEAVE (" ");
     return ret;
 }
 
-//TODO: Factor from xaccCloneAccount and xaccCloneAccountSimple.
 Account *
 xaccCloneAccount (const Account *from, QofBook *book)
 {
-    Account *ret;
-
-    if (!from || !book) return NULL;
-    ENTER (" ");
-
-    ret = g_new (Account, 1);
-    g_return_val_if_fail (ret, NULL);
-
-    xaccInitAccount (ret, book);
-
-    /* Do not Begin/CommitEdit() here; give the caller 
-     * a chance to fix things up, and let them do it.
-     * Also let caller issue the generate_event (EVENT_CREATE) */
-    ret->type = from->type;
-
-    ret->accountName = CACHE_INSERT(from->accountName);
-    ret->accountCode = CACHE_INSERT(from->accountCode);
-    ret->description = CACHE_INSERT(from->description);
-
-    ret->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
-
-    /* The new book should contain a commodity that matches
-     * the one in the old book. Find it, use it. */
-    ret->commodity = gnc_commodity_obtain_twin (from->commodity, book);
-
-    ret->commodity_scu = from->commodity_scu;
-    ret->non_standard_scu = from->non_standard_scu;
-
+    Account *ret = xaccCloneAccountCommon(from, book);
     qof_instance_gemini (&ret->inst, (QofInstance *) &from->inst);
+    return ret;
+}
 
-    LEAVE (" ");
+Account *
+xaccCloneAccountSimple (const Account *from, QofBook *book)
+{
+    Account *ret = xaccCloneAccountCommon(from, book);    
+    ret->inst.dirty = TRUE;
     return ret;
 }
 



More information about the gnucash-changes mailing list