git ssb

0+

cel / ledger-scripts



Commit a175096b83d9b3008dc5b2a06b16c310b92b63b4

Fix merge-ledger somewhat

Charles Lehner committed on 11/1/2015, 2:07:02 AM
Parent: 1d0bfddc48640e483c022b27568c41a6015e9321

Files changed

merge-ledgerchanged
merge-ledgerView
@@ -92,9 +92,8 @@
9292 sub print_entry {
9393 my ($stream, $entry) = @_;
9494 #$stream //= \*STDOUT;
9595 #print $stream "fh: ".($entry->{fh} // 'null').". i: ".$entry->{buffer_i}."\n";
96- print "amounts: ";
9796 print $_ . ", " for keys($entry->{amounts});
9897 print "\n";
9998 print $stream $_ for @{ $entry->{lines} };
10099 }
@@ -102,10 +101,10 @@
102101 sub get_oldest_entry {
103102 return unless scalar @buffer;
104103
105104 # pick the oldest entry
106- my $oldest = shift @buffer;
107- for my $entry (@buffer) {
105+ my $oldest = $buffer[0];
106+ for my $entry (@buffer[1..$#buffer]) {
108107 if ($entry->{date} < $oldest->{date}) {
109108 $oldest = $entry;
110109 }
111110 }
@@ -115,10 +114,10 @@
115114
116115 sub entry_matches_date {
117116 my ($entry, $date) = @_;
118117 my $diff = $date - $entry->{date};
119- printf("%s, %s: %s days\n", $date, $entry->{date}, $diff);
120- return (abs(int($diff->days)) < $time_difference);
118+ printf("%s, %s: %s days\n", $date, $entry->{date}, $diff->days);
119+ return (abs($diff) < $time_difference);
121120 }
122121
123122 sub entry_matches_amounts {
124123 my ($entry, $amounts) = @_;
@@ -138,9 +137,9 @@
138137 my $fh = $entry->{fh};
139138 my @matches = grep {
140139 defined $_ and
141140 $fh != $_->{fh} and
142- #entry_matches_date($_, $date) and
141+ entry_matches_date($_, $date) and
143142 entry_matches_amounts($_, $amounts)
144143 } @buffer;
145144 # append original entry
146145 unshift @matches, $entry if (scalar @matches);
@@ -241,8 +240,9 @@
241240 replace_entry($entry);
242241 }
243242 } else {
244243 # No matching entries.
245- # Print the entry
244+ # Print the entry and pick a new one
246245 print_entry \*OUTFILE, $entry;
246+ replace_entry($entry);
247247 }
248248 }

Built with git-ssb-web