gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Fri Apr 15 00:42:28 EDT 2022
Updated via https://github.com/Gnucash/gnucash/commit/07a9494d (commit)
via https://github.com/Gnucash/gnucash/commit/560f3125 (commit)
via https://github.com/Gnucash/gnucash/commit/d2ad1aa3 (commit)
via https://github.com/Gnucash/gnucash/commit/7cf3a5d9 (commit)
via https://github.com/Gnucash/gnucash/commit/fae7ea02 (commit)
from https://github.com/Gnucash/gnucash/commit/07fbcc0e (commit)
commit 07a9494d8dd42e56801f1d929953bc44d65adc87
Merge: 07fbcc0e9 560f31250
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Apr 15 12:27:31 2022 +0800
Merge branch 'maint-progress1' into maint #1306
export and use gnc_accounts_and_all_descendants
commit 560f31250ec8ed15644663475ce4558cdec46bac
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Apr 15 11:15:06 2022 +0800
[reports] use new function names
gnc:accounts-and-all-descendants-sorted
gnc-accounts-and-all-descendants
diff --git a/gnucash/report/html-acct-table.scm b/gnucash/report/html-acct-table.scm
index d77ce79da..9d8952fa3 100644
--- a/gnucash/report/html-acct-table.scm
+++ b/gnucash/report/html-acct-table.scm
@@ -697,7 +697,7 @@
(for-each
(lambda (acct)
(this-collector 'merge (get-balance acct-balances acct) #f))
- (gnc:accounts-and-all-descendants (list account)))
+ (cons account (gnc-account-get-descendants-sorted account)))
this-collector))
(let lp ((accounts (if less-p (sort accts less-p) accts))
diff --git a/gnucash/report/reports/example/average-balance.scm b/gnucash/report/reports/example/average-balance.scm
index 66a285a49..d0f937b7d 100644
--- a/gnucash/report/reports/example/average-balance.scm
+++ b/gnucash/report/reports/example/average-balance.scm
@@ -296,7 +296,7 @@
(accounts (get-option gnc:pagename-accounts (N_ "Accounts")))
(dosubs? (get-option gnc:pagename-accounts optname-subacct))
(accounts (if dosubs?
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
accounts))
(plot-type (get-option gnc:pagename-display (N_ "Plot Type")))
(show-plot? (get-option gnc:pagename-display (N_ "Show plot")))
diff --git a/gnucash/report/reports/example/daily-reports.scm b/gnucash/report/reports/example/daily-reports.scm
index 2dc965866..239aa39cc 100644
--- a/gnucash/report/reports/example/daily-reports.scm
+++ b/gnucash/report/reports/example/daily-reports.scm
@@ -186,7 +186,7 @@
;; needed so as to amortize the cpu time properly.
(gnc:report-percent-done 1)
(set! commodity-list (gnc:accounts-get-commodities
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
report-currency))
(gnc:report-percent-done 5)
(set! exchange-fn (gnc:case-exchange-time-fn
@@ -208,7 +208,7 @@
(gnc:report-percent-done 25)
(if dosubs?
(set! accounts
- (gnc:accounts-and-all-descendants accounts)))
+ (gnc-accounts-and-all-descendants accounts)))
(gnc:report-percent-done 30)
(xaccQueryAddAccountMatch
diff --git a/gnucash/report/reports/standard/account-summary.scm b/gnucash/report/reports/standard/account-summary.scm
index 96b8c273f..cd4259e0a 100644
--- a/gnucash/report/reports/standard/account-summary.scm
+++ b/gnucash/report/reports/standard/account-summary.scm
@@ -444,7 +444,7 @@
(gnc:html-document-add-object!
doc (gnc:html-make-rates-table
report-commodity price-fn
- (gnc:accounts-and-all-descendants accounts))))))
+ (gnc-accounts-and-all-descendants accounts))))))
(gnc:report-finished)
doc))
diff --git a/gnucash/report/reports/standard/budget.scm b/gnucash/report/reports/standard/budget.scm
index a960d50c7..76ba6ee05 100644
--- a/gnucash/report/reports/standard/budget.scm
+++ b/gnucash/report/reports/standard/budget.scm
@@ -686,7 +686,7 @@
optname-period-collapse-after)))
(doc (gnc:make-html-document))
(accounts (if show-subaccts?
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
accounts)))
;; end of defines
diff --git a/gnucash/report/reports/standard/cash-flow.scm b/gnucash/report/reports/standard/cash-flow.scm
index 1dd900e6f..5a08b5ac0 100644
--- a/gnucash/report/reports/standard/cash-flow.scm
+++ b/gnucash/report/reports/standard/cash-flow.scm
@@ -156,7 +156,7 @@
;;add subaccounts if requested
(accounts (if show-subaccts?
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
accounts))
(accounts (sort accounts gnc:account-full-name<?)))
diff --git a/gnucash/report/reports/standard/category-barchart.scm b/gnucash/report/reports/standard/category-barchart.scm
index 6e35961dd..d90de8754 100644
--- a/gnucash/report/reports/standard/category-barchart.scm
+++ b/gnucash/report/reports/standard/category-barchart.scm
@@ -294,7 +294,7 @@ developing over time"))
(else
(let* ((commodity-list (gnc:accounts-get-commodities
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
report-currency))
(exchange-fn (gnc:case-exchange-time-fn
price-source report-currency
@@ -394,7 +394,7 @@ developing over time"))
#:nosplit->elt (gnc:make-gnc-monetary comm 0)))))
;; all selected accounts (of report-specific type), *and*
;; their descendants (of any type) need to be scanned.
- (gnc:accounts-and-all-descendants accounts)))
+ (gnc-accounts-and-all-descendants accounts)))
;; Creates the <balance-list> to be used in the function
;; below.
diff --git a/gnucash/report/reports/standard/net-charts.scm b/gnucash/report/reports/standard/net-charts.scm
index 6d9d0f7d5..1f58450f7 100644
--- a/gnucash/report/reports/standard/net-charts.scm
+++ b/gnucash/report/reports/standard/net-charts.scm
@@ -299,7 +299,7 @@
(gnc:report-percent-done 1)
(set! commodity-list (gnc:accounts-get-commodities
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
report-currency))
(gnc:report-percent-done 10)
(set! exchange-fn (gnc:case-exchange-time-fn
diff --git a/gnucash/report/reports/standard/portfolio.scm b/gnucash/report/reports/standard/portfolio.scm
index 45272d12c..020e867de 100644
--- a/gnucash/report/reports/standard/portfolio.scm
+++ b/gnucash/report/reports/standard/portfolio.scm
@@ -195,7 +195,7 @@
;(gnc:debug "accounts" accounts)
(if (not (null? accounts))
(let* ((commodity-list (gnc:accounts-get-commodities
- (gnc:accounts-and-all-descendants accounts)
+ (gnc-accounts-and-all-descendants accounts)
currency))
(pricedb (gnc-pricedb-get-db (gnc-get-current-book)))
(exchange-fn (gnc:case-exchange-fn price-source currency to-date))
diff --git a/gnucash/report/reports/standard/test/test-income-gst.scm b/gnucash/report/reports/standard/test/test-income-gst.scm
index a78bb4c64..8c069d8b9 100644
--- a/gnucash/report/reports/standard/test/test-income-gst.scm
+++ b/gnucash/report/reports/standard/test/test-income-gst.scm
@@ -232,10 +232,10 @@
(define (default-testing-options)
(let ((options (gnc:make-report-options rpt-uuid)))
(set-option! options "Accounts" "Sales"
- (gnc:accounts-and-all-descendants
+ (gnc-accounts-and-all-descendants
(list (get-acct "Income"))))
(set-option! options "Accounts" "Purchases"
- (gnc:accounts-and-all-descendants
+ (gnc-accounts-and-all-descendants
(list (get-acct "Expenses"))))
(set-option! options "Accounts" "Tax Accounts"
(list (get-acct "Purchases VAT")
commit d2ad1aa35df0ae40fa8ee6a36821db995aaaf7df
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Apr 7 09:49:24 2022 +0800
[html-acct-table] deprecate gnc:account-path-less-p
diff --git a/gnucash/report/html-acct-table.scm b/gnucash/report/html-acct-table.scm
index 6a04c2fcb..d77ce79da 100644
--- a/gnucash/report/html-acct-table.scm
+++ b/gnucash/report/html-acct-table.scm
@@ -555,6 +555,7 @@
(gnc:string-locale<? (xaccAccountGetName a)
(xaccAccountGetName b)))
(define (gnc:account-path-less-p a b)
+ (issue-deprecation-warning "gnc:account-path-less-p is deprecated. use gnc:account-full-name<? instead")
(gnc:string-locale<? (gnc-account-get-full-name a)
(gnc-account-get-full-name b)))
commit 7cf3a5d93d3dea2e7dc36914024acbaa61bc0a8d
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Apr 2 10:26:39 2022 +0800
[report-utilities.scm] deprecate gnc:accounts-and-all-descendants
diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index 126e2aaae..1d2901158 100644
--- a/gnucash/report/report-utilities.scm
+++ b/gnucash/report/report-utilities.scm
@@ -234,9 +234,10 @@
;; Return accountslist *and* their descendant accounts
(define (gnc:accounts-and-all-descendants accountslist)
- (sort-and-delete-duplicates
- (apply append accountslist (map gnc-account-get-descendants accountslist))
- gnc:account-path-less-p equal?))
+ (issue-deprecation-warning "gnc:accounts-and-all-descendants is \
+now deprecated, use gnc-accounts-and-all-descendants instead. sort \
+with gnc:account-full-name<? if necessary.")
+ (sort (gnc-accounts-and-all-descendants accountslist) gnc:account-full-name<?))
;;; Here's a statistics collector... Collects max, min, total, and makes
;;; it easy to get at the mean.
diff --git a/gnucash/report/test/test-report-utilities.scm b/gnucash/report/test/test-report-utilities.scm
index 647540b2d..ce3816673 100644
--- a/gnucash/report/test/test-report-utilities.scm
+++ b/gnucash/report/test/test-report-utilities.scm
@@ -546,9 +546,11 @@
(account-lookup "GBP Savings")
(account-lookup "Expenses")
(account-lookup "Fuel"))
- (gnc:accounts-and-all-descendants
- (list (account-lookup "Expenses")
- (account-lookup "GBP Bank"))))
+ (sort
+ (gnc-accounts-and-all-descendants
+ (list (account-lookup "Expenses")
+ (account-lookup "GBP Bank")))
+ gnc:account-full-name<?))
(teardown)))
commit fae7ea02cd078ea08c90bcff57979079d403e22c
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Apr 2 10:26:34 2022 +0800
[account.cpp] gnc_accounts_and_all_descendants converted from scm
much more efficient than guile algorithm, avoids numerous repeated
GList<->SCM conversions, and traversals of account descendants.
diff --git a/bindings/engine-common.i b/bindings/engine-common.i
index b4d861dd6..d85e7ef8d 100644
--- a/bindings/engine-common.i
+++ b/bindings/engine-common.i
@@ -48,10 +48,14 @@ AccountList * gnc_account_get_descendants (const Account *account);
%newobject gnc_account_get_descendants_sorted;
AccountList * gnc_account_get_descendants_sorted (const Account *account);
+%newobject gnc_accounts_and_all_descendants;
+AccountList * gnc_accounts_and_all_descendants (AccountList *accounts);
+
%ignore gnc_account_get_children;
%ignore gnc_account_get_children_sorted;
%ignore gnc_account_get_descendants;
%ignore gnc_account_get_descendants_sorted;
+%ignore gnc_accounts_and_all_descendants;
%include <Account.h>
%include <Transaction.h>
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 92f4d2bf5..4140ca1f6 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -49,6 +49,7 @@ extern "C" {
#include <numeric>
#include <map>
+#include <unordered_set>
static QofLogModule log_module = GNC_MOD_ACCOUNT;
@@ -6228,6 +6229,21 @@ gboolean xaccAccountRegister (void)
return qof_object_register (&account_object_def);
}
+using AccountSet = std::unordered_set<Account*>;
+static void maybe_add_descendants (Account* acc, gpointer arg)
+{
+ if (static_cast <AccountSet*> (arg)->insert (acc).second)
+ g_list_foreach (GET_PRIVATE(acc)->children, (GFunc) maybe_add_descendants, arg);
+};
+
+GList *
+gnc_accounts_and_all_descendants (GList *accounts)
+{
+ AccountSet accset;
+ g_list_foreach (accounts, (GFunc) maybe_add_descendants, &accset);
+ return std::accumulate (accset.begin(), accset.end(), (GList*) nullptr, g_list_prepend);
+}
+
/* ======================= UNIT TESTING ACCESS =======================
* The following functions are for unit testing use only.
*/
diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h
index 19093036c..868c1b955 100644
--- a/libgnucash/engine/Account.h
+++ b/libgnucash/engine/Account.h
@@ -1620,6 +1620,7 @@ void dxaccAccountSetQuoteTZ (Account *account, const char *tz);
const char * dxaccAccountGetQuoteTZ (const Account *account);
/** @} */
+GList * gnc_accounts_and_all_descendants (GList *accounts);
/** @name Account parameter names
@{
Summary of changes:
bindings/engine-common.i | 4 ++++
gnucash/report/html-acct-table.scm | 3 ++-
gnucash/report/report-utilities.scm | 7 ++++---
gnucash/report/reports/example/average-balance.scm | 2 +-
gnucash/report/reports/example/daily-reports.scm | 4 ++--
gnucash/report/reports/standard/account-summary.scm | 2 +-
gnucash/report/reports/standard/budget.scm | 2 +-
gnucash/report/reports/standard/cash-flow.scm | 2 +-
gnucash/report/reports/standard/category-barchart.scm | 4 ++--
gnucash/report/reports/standard/net-charts.scm | 2 +-
gnucash/report/reports/standard/portfolio.scm | 2 +-
gnucash/report/reports/standard/test/test-income-gst.scm | 4 ++--
gnucash/report/test/test-report-utilities.scm | 8 +++++---
libgnucash/engine/Account.cpp | 16 ++++++++++++++++
libgnucash/engine/Account.h | 1 +
15 files changed, 44 insertions(+), 19 deletions(-)
More information about the gnucash-changes
mailing list