Changeset 30008 in osm for applications/editors


Ignore:
Timestamp:
2013-10-07T13:20:14+02:00 (11 years ago)
Author:
donvip
Message:

[josm_reverter] fix #josm9162 - another problem with reverter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/DataSetCommandMerger.java

    r30000 r30008  
    44
    55import java.util.ArrayList;
     6import java.util.Collection;
    67import java.util.LinkedList;
    78import java.util.List;
    89
     10import org.openstreetmap.josm.Main;
    911import org.openstreetmap.josm.command.ChangeCommand;
    1012import org.openstreetmap.josm.command.Command;
     
    3234
    3335    private final List<Command> cmds = new LinkedList<Command>();
    34     private final List<OsmPrimitive> undeletedPrimitives = new LinkedList<OsmPrimitive>();
     36    private final List<OsmPrimitive> nominalRevertedPrimitives = new LinkedList<OsmPrimitive>();
    3537
    3638    /**
     
    4345    }
    4446   
    45     private void addChangeCommandIfNotEquals(OsmPrimitive target, OsmPrimitive newTarget) {
     47    private void addChangeCommandIfNotEquals(OsmPrimitive target, OsmPrimitive newTarget, boolean nominal) {
    4648        if (!target.hasEqualSemanticAttributes(newTarget)) {
    4749            cmds.add(new ChangeCommand(target,newTarget));
    48             undeletedPrimitives.add(target);
     50            if (nominal) {
     51                nominalRevertedPrimitives.add(target);
     52            }
     53            Main.debug("Reverting "+target+" to "+newTarget);
    4954        }
    5055    }
     
    7782        Node newTarget = new Node(target);
    7883        mergePrimitive(source, target, newTarget);
    79         addChangeCommandIfNotEquals(target,newTarget);
     84        addChangeCommandIfNotEquals(target,newTarget,true);
    8085    }
    8186
     
    9297        if (!source.isVisible()) return;
    9398        Way target = (Way)getMergeTarget(source);
     99       
     100        Collection<Conflict<OsmPrimitive>> localConflicts = new ArrayList<Conflict<OsmPrimitive>>();
    94101
    95102        List<Node> newNodes = new ArrayList<Node>(source.getNodesCount());
    96103        for (Node sourceNode : source.getNodes()) {
    97104            Node targetNode = (Node)getMergeTarget(sourceNode);
    98             if (!targetNode.isDeleted() || undeletedPrimitives.contains(targetNode)) {
     105            // Target node is not deleted or it will be undeleted when running existing commands
     106            if (!targetNode.isDeleted() || nominalRevertedPrimitives.contains(targetNode)) {
    99107                newNodes.add(targetNode);
    100             } else if (sourceNode.isIncomplete()
    101                     && !conflicts.hasConflictForMy(targetNode)) {
    102                 conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
    103                 Node undeletedTargetNode = new Node(targetNode);
    104                 undeletedTargetNode.setDeleted(false);
    105                 addChangeCommandIfNotEquals(targetNode,undeletedTargetNode);
     108            // Target node has been deleted by a more recent changeset -> conflict
     109            } else if (sourceNode.isIncomplete() && !conflicts.hasConflictForMy(targetNode)) {
     110                localConflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
     111            } else {
     112                Main.info("Skipping target node "+targetNode+" for source node "+sourceNode+" while reverting way "+source);
    106113            }
    107114        }
     
    109116        mergePrimitive(source, target, newTarget);
    110117        newTarget.setNodes(newNodes);
    111         addChangeCommandIfNotEquals(target,newTarget);
     118        if (newNodes.isEmpty()) {
     119            Main.error("Unable to revert "+source+" as it produces 0 nodes way "+newTarget);
     120        } else {
     121            for (Conflict<OsmPrimitive> c : localConflicts) {
     122                Main.warn("New conflict: "+c);
     123                conflicts.add(c);
     124                Node targetNode = (Node)c.getTheir();
     125                Node undeletedTargetNode = new Node(targetNode);
     126                undeletedTargetNode.setDeleted(false);
     127                addChangeCommandIfNotEquals(targetNode,undeletedTargetNode,false);
     128            }
     129            addChangeCommandIfNotEquals(target,newTarget,true);
     130        }
    112131    }
    113132
     
    137156                }
    138157                undeletedTargetMember.setDeleted(false);
    139                 addChangeCommandIfNotEquals(targetMember,undeletedTargetMember);
     158                addChangeCommandIfNotEquals(targetMember,undeletedTargetMember,false);
    140159            }
    141160            newMembers.add(new RelationMember(sourceMember.getRole(), targetMember));
     
    144163        mergePrimitive(source, target, newRelation);
    145164        newRelation.setMembers(newMembers);
    146         addChangeCommandIfNotEquals(target,newRelation);
     165        addChangeCommandIfNotEquals(target,newRelation,true);
    147166    }
    148167   
Note: See TracChangeset for help on using the changeset viewer.