Simplified the code for excluding non-trunk revisions a bit, using higher-level methods for some changes. Added missing revision destruction.