Changeset 34958 in osm for applications/editors/josm


Ignore:
Timestamp:
2019-04-02T07:57:58+02:00 (6 years ago)
Author:
gerdp
Message:

see #17459: remove duplicated code in reverter corehacks
Step 2: Use new core methods instead of corehacks (requires JOSM r14946 or newer)

Location:
applications/editors/josm/plugins/reverter
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/build.xml

    r34552 r34958  
    44    <property name="commit.message" value="Reverter: Update MultiOsmReader to support null data after redaction"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="14153"/>
     6    <property name="plugin.main.version" value="14946"/>
    77
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r34953 r34958  
    1010import java.util.Collection;
    1111import java.util.Collections;
     12import java.util.HashMap;
    1213import java.util.HashSet;
    1314import java.util.Iterator;
     
    2021import org.openstreetmap.josm.data.coor.LatLon;
    2122import org.openstreetmap.josm.data.osm.Changeset;
     23import org.openstreetmap.josm.data.osm.ChangesetDataSet;
     24import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
     25import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
    2226import org.openstreetmap.josm.data.osm.DataSet;
    2327import org.openstreetmap.josm.data.osm.Node;
     
    3943import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
    4044import org.openstreetmap.josm.io.OsmApiException;
     45import org.openstreetmap.josm.io.OsmServerChangesetReader;
    4146import org.openstreetmap.josm.io.OsmTransferException;
    4247import org.openstreetmap.josm.tools.Logging;
    4348import org.openstreetmap.josm.tools.Utils;
    44 
    45 import reverter.corehacks.ChangesetDataSet;
    46 import reverter.corehacks.ChangesetDataSet.ChangesetDataSetEntry;
    47 import reverter.corehacks.ChangesetDataSet.ChangesetModificationType;
    48 import reverter.corehacks.OsmServerChangesetReader;
    4949
    5050/**
     
    8080    private final HashSet<HistoryOsmPrimitive> updated = new HashSet<>();
    8181    private final HashSet<HistoryOsmPrimitive> deleted = new HashSet<>();
     82    private final HashMap<PrimitiveId, Integer> earliestVersions = new HashMap<>();
    8283
    8384    //// Handling missing objects
     
    142143        this.revertType = revertType;
    143144
    144         OsmServerChangesetReader csr = new OsmServerChangesetReader();
     145        OsmServerChangesetReader csr = new OsmServerChangesetReader(true);
    145146        monitor.beginTask("", 2);
    146         changeset = csr.readChangeset(changesetId, monitor.createSubTaskMonitor(1, false));
     147        changeset = csr.readChangeset(changesetId, false, monitor.createSubTaskMonitor(1, false));
    147148        if (MODERATOR_REDACTION_ACCOUNTS.contains(changeset.getUser().getId())) {
    148149            throw new RevertRedactedChangesetException(tr("It is not allowed to revert changeset from {0}", changeset.getUser().getName()));
     
    158159
    159160        // Build our own lists of created/updated/modified objects for better performance
    160         for (Iterator<ChangesetDataSetEntry> it = cds.iterator(); it.hasNext();) {
    161             ChangesetDataSetEntry entry = it.next();
    162             if (!checkOsmChangeEntry(entry)) continue;
    163             if (entry.getModificationType() == ChangesetModificationType.CREATED) {
    164                 created.add(entry.getPrimitive());
    165             } else if (entry.getModificationType() == ChangesetModificationType.UPDATED) {
    166                 updated.add(entry.getPrimitive());
    167             } else if (entry.getModificationType() == ChangesetModificationType.DELETED) {
    168                 deleted.add(entry.getPrimitive());
    169             } else throw new AssertionError();
     161        for (PrimitiveId id : cds.getIds()) {
     162            ChangesetDataSetEntry first = cds.getFirstEntry(id);
     163            ChangesetDataSetEntry last = cds.getLastEntry(id);
     164            earliestVersions.put(id, (int) first.getPrimitive().getVersion());
     165            if (first.getModificationType() == ChangesetModificationType.CREATED)
     166                created.add(first.getPrimitive());
     167            else if (last.getModificationType() == ChangesetModificationType.UPDATED)
     168                updated.add(last.getPrimitive());
     169            else if (last.getModificationType() == ChangesetModificationType.DELETED)
     170                deleted.add(last.getPrimitive());
    170171        }
    171172    }
     
    220221                for (HistoryOsmPrimitive entry : collection) {
    221222                    PrimitiveId id = entry.getPrimitiveId();
    222                     readObjectVersion(rdr, id, cds.getEarliestVersion(id)-1, progressMonitor);
     223                    Integer earliestVersion = earliestVersions.get(id);
     224                    if (earliestVersion == null || earliestVersion <= 1)
     225                        throw new OsmTransferException(tr("Unexpected data in changeset #{1}" , String.valueOf(changesetId)));
     226                    readObjectVersion(rdr, id, earliestVersion - 1, progressMonitor);
    223227                    if (progressMonitor.isCanceled()) return;
    224228                }
Note: See TracChangeset for help on using the changeset viewer.