package journal.action; import java.util.HashSet; import java.util.Set; import jargs.gnu.CmdLineParser; import journal.reader.DataJournalEntry; public class Obliterator extends BaseAction { String pattern = ""; Set<Integer> changes = new HashSet<Integer>(); @Override public void putValue(DataJournalEntry dataEntry) { String tableName = dataEntry.getTableName(); if (tableName.startsWith("db.rev") || tableName.equals("db.have") || tableName.startsWith("db.working") || tableName.equals("db.locks")) { String file = (String) dataEntry.getValue("dfile"); if( file.startsWith(pattern)) { return; } } else if (tableName.equals("db.integed")) { String tfile = (String) dataEntry.getValue("tfile"); String ffile = (String) dataEntry.getValue("ffile"); if ( tfile.startsWith(pattern) || ffile.startsWith(pattern)) { return; } } else if (tableName.equals("db.label")) { String file = (String) dataEntry.getValue("file"); if ( file.startsWith(pattern)) { return; } } else if (tableName.equals("db.archmap")) { String afile = (String) dataEntry.getValue("afile"); String dfile = (String) dataEntry.getValue("dfile"); if ( afile.startsWith(pattern) || dfile.startsWith(pattern)) { return; } } else if (tableName.startsWith("db.resolve")) { String afile = (String) dataEntry.getValue("ffile"); String dfile = (String) dataEntry.getValue("bfile"); if ( afile.startsWith(pattern) || dfile.startsWith(pattern)) { return; } } else if (tableName.startsWith("db.change")) { String root = (String) dataEntry.getValue("root"); if ( root.startsWith(pattern)) { Integer change = (Integer) dataEntry.getValue("change"); changes.add(change); return; } } else if (tableName.equals("db.desc")) { Integer key = (Integer) dataEntry.getValue("key"); if (changes.contains(key)) return; } out.println(dataEntry.toJournalString()); } @Override public void help() { System.err.println("\t--action journal.action.Obliterator -- <options>"); System.err.println("\t\tOptions are\n"); System.err.println("\t\t-p --pattern=<file pattern>"); } @Override public String[] parseArgs(String[] args) { CmdLineParser parser = new CmdLineParser(); CmdLineParser.Option patternOption = parser.addStringOption('p', "pattern"); try { parser.parse(args); } catch ( CmdLineParser.OptionException e ) { System.err.println(e.getMessage()); help(); System.exit(2); } pattern = (String) parser.getOptionValue(patternOption, ""); if (pattern.equals("")) { throw new IllegalArgumentException("Need to specify pattern"); } return parser.getRemainingArgs(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 8296 | Sven Erik Knop |
Clean-up: instead of casting in every action, cast only once in the dispatcher. Should make code saner and safer. No functional change. |
||
#2 | 7872 | Sven Erik Knop |
Complete re-write of the Obliterator. This version has successfully cleaned up a customer's database but needs lots more testing. |
||
#1 | 7847 | Sven Erik Knop |
New action journal.action.Obliterator. When 'p4 obliterate' fails, use this to clean up the checkpoint :-) |