summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-02-27 00:40:22 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-02-27 02:31:08 -0600
commit0efdc0cf6f47278184eecdf47137b6253043e027 (patch)
tree1d67a02b3b7a3c202f505b420747c1aa2e7f48e7 /src
parentbb0c5344145cd79fa54a92f236628eebbe6f2f68 (diff)
downloadfork-ledger-0efdc0cf6f47278184eecdf47137b6253043e027.tar.gz
fork-ledger-0efdc0cf6f47278184eecdf47137b6253043e027.tar.bz2
fork-ledger-0efdc0cf6f47278184eecdf47137b6253043e027.zip
The "id" of an item now maps to its UUID
Diffstat (limited to 'src')
-rw-r--r--src/convert.cc10
-rw-r--r--src/item.cc10
-rw-r--r--src/journal.cc17
-rw-r--r--src/post.cc10
-rw-r--r--src/xact.cc27
-rw-r--r--src/xact.h3
6 files changed, 32 insertions, 45 deletions
diff --git a/src/convert.cc b/src/convert.cc
index da4569cc..15995d05 100644
--- a/src/convert.cc
+++ b/src/convert.cc
@@ -74,21 +74,21 @@ value_t convert_command(call_scope_t& args)
post->amount.in_place_negate();
}
- string ref = (xact->has_tag(_("SHA1")) ?
- xact->get_tag(_("SHA1"))->to_string() :
+ string ref = (xact->has_tag(_("UUID")) ?
+ xact->get_tag(_("UUID"))->to_string() :
sha1sum(reader.get_last_line()));
checksum_map_t::const_iterator entry = journal.checksum_map.find(ref);
if (entry != journal.checksum_map.end()) {
INFO(file_context(reader.get_pathname(),
reader.get_linenum())
- << "Ignoring known SHA1 " << ref);
+ << "Ignoring known UUID " << ref);
checked_delete(xact); // ignore it
continue;
}
- if (report.HANDLED(rich_data) && ! xact->has_tag(_("SHA1")))
- xact->set_tag(_("SHA1"), string_value(ref));
+ if (report.HANDLED(rich_data) && ! xact->has_tag(_("UUID")))
+ xact->set_tag(_("UUID"), string_value(ref));
if (xact->posts.front()->account == NULL) {
if (account_t * acct =
diff --git a/src/item.cc b/src/item.cc
index 7184c0ef..97411512 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -340,6 +340,12 @@ namespace {
value_t get_seq(item_t& item) {
return item.pos ? long(item.pos->sequence) : 0L;
}
+ value_t get_id(item_t& item) {
+ if (optional<value_t> ref = item.get_tag(_("UUID")))
+ return *ref;
+ else
+ return item.pos ? long(item.pos->sequence) : 0L;
+ }
value_t get_addr(item_t& item) {
return long(&item);
@@ -447,6 +453,8 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
case 'i':
if (name == "is_account")
return WRAP_FUNCTOR(get_wrapper<&ignore>);
+ else if (name == "id")
+ return WRAP_FUNCTOR(get_wrapper<&get_id>);
break;
case 'm':
@@ -481,6 +489,8 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind,
case 'u':
if (name == "uncleared")
return WRAP_FUNCTOR(get_wrapper<&get_uncleared>);
+ else if (name == "uuid")
+ return WRAP_FUNCTOR(get_wrapper<&get_id>);
break;
case 'v':
diff --git a/src/journal.cc b/src/journal.cc
index f070ba0e..01cff2dc 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -126,6 +126,23 @@ bool journal_t::add_xact(xact_t * xact)
}
extend_xact(xact);
+
+ // If a transaction with this UUID has already been seen, simply do
+ // not add this one to the journal. However, all automated checks
+ // will have been performed by extend_xact, so asserts can still be
+ // applied to it.
+ if (optional<value_t> ref = xact->get_tag(_("UUID"))) {
+ std::pair<checksum_map_t::iterator, bool> result
+ = checksum_map.insert(checksum_map_t::value_type(ref->to_string(), xact));
+ if (! result.second) {
+ // jww (2012-02-27): Confirm that the xact in
+ // (*result.first).second is exact match in its significant
+ // details to xact.
+ xact->journal = NULL;
+ return false;
+ }
+ }
+
xacts.push_back(xact);
return true;
diff --git a/src/post.cc b/src/post.cc
index b40e31f0..d88dd869 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -186,12 +186,6 @@ namespace {
value_t get_magnitude(post_t& post) {
return post.xact->magnitude();
}
- value_t get_idstring(post_t& post) {
- return string_value(post.xact->idstring());
- }
- value_t get_id(post_t& post) {
- return string_value(post.xact->id());
- }
value_t get_amount(post_t& post) {
if (post.has_xdata() && post.xdata().has_flags(POST_EXT_COMPOUND))
@@ -459,10 +453,6 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind,
case 'i':
if (name == "index")
return WRAP_FUNCTOR(get_wrapper<&get_count>);
- else if (name == "id")
- return WRAP_FUNCTOR(get_wrapper<&get_id>);
- else if (name == "idstring")
- return WRAP_FUNCTOR(get_wrapper<&get_idstring>);
break;
case 'm':
diff --git a/src/xact.cc b/src/xact.cc
index 596b39fa..ce4c032e 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -467,30 +467,10 @@ void xact_t::add_post(post_t * post)
xact_base_t::add_post(post);
}
-string xact_t::idstring() const
-{
- std::ostringstream buf;
- buf << format_date(*_date, FMT_WRITTEN);
- buf << payee;
- magnitude().number().print(buf);
- return buf.str();
-}
-
-string xact_t::id() const
-{
- return sha1sum(idstring());
-}
-
namespace {
value_t get_magnitude(xact_t& xact) {
return xact.magnitude();
}
- value_t get_idstring(xact_t& xact) {
- return string_value(xact.idstring());
- }
- value_t get_id(xact_t& xact) {
- return string_value(xact.id());
- }
value_t get_code(xact_t& xact) {
if (xact.code)
@@ -554,13 +534,6 @@ expr_t::ptr_op_t xact_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(get_wrapper<&get_code>);
break;
- case 'i':
- if (name == "id")
- return WRAP_FUNCTOR(get_wrapper<&get_id>);
- else if (name == "idstring")
- return WRAP_FUNCTOR(get_wrapper<&get_idstring>);
- break;
-
case 'm':
if (name == "magnitude")
return WRAP_FUNCTOR(get_wrapper<&get_magnitude>);
diff --git a/src/xact.h b/src/xact.h
index 5d7912fc..3e628817 100644
--- a/src/xact.h
+++ b/src/xact.h
@@ -129,9 +129,6 @@ public:
virtual void add_post(post_t * post);
- string idstring() const;
- string id() const;
-
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);