package journal.action; import java.util.HashMap; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import journal.reader.DataJournalEntry; public class CheckCase extends BaseAction { public CheckCase() { root = new Node("/"); } @Override public void finish() throws Exception { out.println("Conflicts:\n"); for(String path : conflicts.keySet()) { out.println(conflicts.get(path)); } super.finish(); } @Override public void putValue(DataJournalEntry data) throws Exception { if( data.getTableName().equals("db.rev") ) { String depotFile = (String) data.getValue("dfile"); // cut of the first two chars (always //), // then split into directories String[] dirs = depotFile.substring(2).split("/"); Node node = root; StringBuilder fullName = new StringBuilder("/"); for (String dir : dirs) { fullName.append('/'); fullName.append(dir); Node subNode = node.findNode(dir); if( subNode != null ) { if( subNode.getName().equals(dir)) { subNode.incCount(); } else { addConflicts(fullName.toString(), subNode); } } else { subNode = new Node(dir, node); node.addNode(subNode); } node = subNode; } } } private void addConflicts(String fullName, Node subNode) { Conflict conflict = null; if( conflicts.containsKey(fullName) ) { conflict = conflicts.get(fullName); conflict.incCount(); } else { conflict = new Conflict(fullName, subNode); } conflicts.put(fullName, conflict); } class Node { private String name; private Node parent; private String canonicalName; private long count; private Map<String, Node> subNodes = new HashMap<String, Node>(); public Node(String name) { this.name = name; this.canonicalName = name.toLowerCase(); this.count = 1; this.parent = null; } public Node(String name, Node parent) { this(name); this.parent = parent; } public void addNode(Node subNode) { subNodes.put(subNode.getCanonicalName(), subNode); } public Node findNode(String subNode) { String key = subNode.toLowerCase(); if( subNodes.containsKey(key) ) { return subNodes.get(key); } else return null; } public String getName() { return name; } public String getCanonicalName() { return canonicalName; } public long getCount() { return count; } public Node getParent() { return parent; } public void incCount() { count++; } public String getFullName() { return getFullNameRecursive(name); } private String getFullNameRecursive(String postfix) { if( parent != null ) { return parent.getFullNameRecursive(parent.name + "/" + postfix); } else { return postfix; } } } class Conflict { public int count; public Node conflictNode; public String fullName; public Conflict(String fullName, Node node) { this.fullName = fullName; this.count = 1; this.conflictNode = node; } public void incCount() { count++; } @Override public String toString() { StringBuilder b = new StringBuilder(fullName); b.append(" :\t\t"); b.append(count); b.append(" ( "); b.append(conflictNode.getFullName()); b.append(" : "); b.append(count); b.append(" ) "); return b.toString(); } } private Node root; private SortedMap<String, Conflict> conflicts = new TreeMap<String, Conflict>(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 24773 | Norman Morse |
Moving journalReader from sven's private branch to perforce_software. This is because journalReader is used in the perfsplit test harness, and should be updated over time. Merging //guest/sven_erik_knop/java/JournalReader/... to //guest/perforce_software/journalReader/... |
||
//guest/sven_erik_knop/java/JournalReader/src/journal/action/CheckCase.java | |||||
#5 | 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. |
||
#4 | 8204 | Sven Erik Knop | conflict count is correct, now original count is off. | ||
#3 | 8201 | Sven Erik Knop |
CheckCase printed wrong count for conflicts. SQlUpdater had missing method for Java 1.7 |
||
#2 | 8167 | Sven Erik Knop |
Updated CheckCase action with additional information. Now each conflict reports which path it conflicts with and a full count. The idea is to see which version is dominant to make an informed decision which version is correct. |
||
#1 | 8166 | Sven Erik Knop |
First attempt at a CaseCheck action. Reads a checkpoint and spits out a list of files and directories that have an evil cases twin, followed by a count. Usage: java -jar journalReader.jar -a journal.action.CaseCheck <checkpoint> |