The "id" of an item now maps to its UUID

This commit is contained in:
John Wiegley 2012-02-27 00:40:22 -06:00
parent bb0c534414
commit 0efdc0cf6f
6 changed files with 32 additions and 45 deletions

View file

@ -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 =

View file

@ -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':

View file

@ -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;

View file

@ -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':

View file

@ -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>);

View file

@ -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);