git-svn: reduce check_cherry_pick cache overhead

We do not need to store entire lists of commits, only the number of incomplete and the first commit for reference. This reduces the amount of data we need to store in memory and on disk stores. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Oct 19, 2014 at 04:08 UTC d0b34f241dc59fe2352cb1a724d0c5e8f0d2ff82
1 file changed +15 -13
perl/Git/SVN.pm
+15 -13
@@ -1537,7 +1537,7 @@ sub _rev_list {
1537 @rv;
1538 }
1539
1540 -sub check_cherry_pick {
1540 +sub check_cherry_pick2 {
1541 my $base = shift;
1542 my $tip = shift;
1543 my $parents = shift;
@@ -1552,7 +1552,8 @@ sub check_cherry_pick {
1552 delete $commits{$commit};
1553 }
1554 }
1555 - return (keys %commits);
1555 + my @k = (keys %commits);
1556 + return (scalar @k, $k[0]);
1557 }
1558
1559 sub has_no_changes {
@@ -1597,7 +1598,7 @@ sub tie_for_persistent_memoization {
1598 mkpath([$cache_path]) unless -d $cache_path;
1599
1600 my %lookup_svn_merge_cache;
1600 - my %check_cherry_pick_cache;
1601 + my %check_cherry_pick2_cache;
1602 my %has_no_changes_cache;
1603 my %_rev_list_cache;
1604
@@ -1608,11 +1609,11 @@ sub tie_for_persistent_memoization {
1609 LIST_CACHE => ['HASH' => \%lookup_svn_merge_cache],
1610 ;
1611
1611 - tie_for_persistent_memoization(\%check_cherry_pick_cache,
1612 - "$cache_path/check_cherry_pick");
1613 - memoize 'check_cherry_pick',
1612 + tie_for_persistent_memoization(\%check_cherry_pick2_cache,
1613 + "$cache_path/check_cherry_pick2");
1614 + memoize 'check_cherry_pick2',
1615 SCALAR_CACHE => 'FAULT',
1615 - LIST_CACHE => ['HASH' => \%check_cherry_pick_cache],
1616 + LIST_CACHE => ['HASH' => \%check_cherry_pick2_cache],
1617 ;
1618
1619 tie_for_persistent_memoization(\%has_no_changes_cache,
@@ -1636,7 +1637,7 @@ sub tie_for_persistent_memoization {
1637 $memoized = 0;
1638
1639 Memoize::unmemoize 'lookup_svn_merge';
1639 - Memoize::unmemoize 'check_cherry_pick';
1640 + Memoize::unmemoize 'check_cherry_pick2';
1641 Memoize::unmemoize 'has_no_changes';
1642 Memoize::unmemoize '_rev_list';
1643 }
@@ -1648,7 +1649,8 @@ sub tie_for_persistent_memoization {
1649 return unless -d $cache_path;
1650
1651 for my $cache_file (("$cache_path/lookup_svn_merge",
1651 - "$cache_path/check_cherry_pick",
1652 + "$cache_path/check_cherry_pick", # old
1653 + "$cache_path/check_cherry_pick2",
1654 "$cache_path/has_no_changes")) {
1655 for my $suffix (qw(yaml db)) {
1656 my $file = "$cache_file.$suffix";
@@ -1817,15 +1819,15 @@ sub find_extra_svn_parents {
1819 }
1820
1821 # double check that there are no missing non-merge commits
1820 - my (@incomplete) = check_cherry_pick(
1822 + my ($ninc, $ifirst) = check_cherry_pick2(
1823 $merge_base, $merge_tip,
1824 $parents,
1825 @all_ranges,
1826 );
1827
1826 - if ( @incomplete ) {
1827 - warn "W:svn cherry-pick ignored ($spec) - missing "
1828 - .@incomplete." commit(s) (eg $incomplete[0])\n";
1828 + if ($ninc) {
1829 + warn "W:svn cherry-pick ignored ($spec) - missing " .
1830 + "$ninc commit(s) (eg $ifirst)\n";
1831 } else {
1832 warn
1833 "Found merge parent ($spec): ",