}
return reverted;
}
private boolean revert(SVNAdminArea dir, String name, SVNEntry entry, boolean useCommitTime) throws SVNException {
SVNLog log = dir.getLog();
boolean reverted = false;
boolean revertBase = false;
SVNVersionedProperties baseProperties = null;
Map command = new HashMap();
if (entry.isScheduledForReplacement()) {
String propRevertPath = SVNAdminUtil.getPropRevertPath(name, entry.getKind(), false);
File propRevertFile = dir.getFile(propRevertPath);
revertBase = true;
if (!propRevertFile.isFile()) {
propRevertPath = SVNAdminUtil.getPropBasePath(name, entry.getKind(), false);
revertBase = false;
}
if (dir.getFile(propRevertPath).isFile()) {
baseProperties = revertBase ? dir.getRevertProperties(name) : dir.getBaseProperties(name);
if (revertBase) {
command.put(SVNLog.NAME_ATTR, propRevertPath);
log.addCommand(SVNLog.DELETE, command, false);
command.clear();
}
reverted = true;
}
}
boolean reinstallWorkingFile = false;
if (baseProperties == null) {
if (dir.hasPropModifications(name)) {
baseProperties = dir.getBaseProperties(name);
SVNVersionedProperties propDiff = dir.getProperties(name).compareTo(baseProperties);
Collection propNames = propDiff.getPropertyNames(null);
reinstallWorkingFile = propNames.contains(SVNProperty.EXECUTABLE) ||
propNames.contains(SVNProperty.KEYWORDS) ||
propNames.contains(SVNProperty.EOL_STYLE) ||
propNames.contains(SVNProperty.SPECIAL) ||
propNames.contains(SVNProperty.NEEDS_LOCK);
}
}
if (baseProperties != null) {
// save base props both to base and working.
Map newProperties = baseProperties.asMap();
SVNVersionedProperties originalBaseProperties = dir.getBaseProperties(name);
SVNVersionedProperties workProperties = dir.getProperties(name);
if (revertBase) {
originalBaseProperties.removeAll();
}
workProperties.removeAll();
for(Iterator names = newProperties.keySet().iterator(); names.hasNext();) {
String propName = (String) names.next();
if (revertBase) {
originalBaseProperties.setPropertyValue(propName, (String) newProperties.get(propName));
}
workProperties.setPropertyValue(propName, (String) newProperties.get(propName));
}
dir.saveVersionedProperties(log, false);
reverted = true;
}
Map newEntryProperties = new HashMap();
if (entry.isScheduledForReplacement() && entry.isCopied()) {
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.COPIED), null);
reverted = true;
}
if (entry.getKind() == SVNNodeKind.FILE) {
if (!reinstallWorkingFile) {
SVNFileType fileType = SVNFileType.getType(dir.getFile(name));
if (fileType == SVNFileType.NONE) {
reinstallWorkingFile = true;
}
}
String basePath = SVNAdminUtil.getTextBasePath(name, false);
if (!dir.getFile(basePath).isFile()) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Error restoring text for ''{0}''", dir.getFile(name));
SVNErrorManager.error(err);
}
File revertFile = dir.getFile(SVNAdminUtil.getTextRevertPath(name, false));
if (revertFile.isFile()) {
command.put(SVNLog.NAME_ATTR, SVNAdminUtil.getTextRevertPath(name, false));
command.put(SVNLog.DEST_ATTR, SVNAdminUtil.getTextBasePath(name, false));
log.addCommand(SVNLog.MOVE, command, false);
command.clear();
reinstallWorkingFile = true;
}
if (!reinstallWorkingFile) {
reinstallWorkingFile = dir.hasTextModifications(name, false, false, false);
}
if (reinstallWorkingFile) {
command.put(SVNLog.NAME_ATTR, SVNAdminUtil.getTextBasePath(name, false));
command.put(SVNLog.DEST_ATTR, name);
log.addCommand(SVNLog.COPY_AND_TRANSLATE, command, false);
command.clear();
if (useCommitTime && entry.getCommittedDate() != null) {
command.put(SVNLog.NAME_ATTR, name);
command.put(SVNLog.TIMESTAMP_ATTR, entry.getCommittedDate());
log.addCommand(SVNLog.SET_TIMESTAMP, command, false);
command.clear();
} else {
command.put(SVNLog.NAME_ATTR, name);
command.put(SVNLog.TIMESTAMP_ATTR, SVNTimeUtil.formatDate(new Date(System.currentTimeMillis())));
log.addCommand(SVNLog.SET_TIMESTAMP, command, false);
command.clear();
}
command.put(SVNLog.NAME_ATTR, name);
command.put(SVNProperty.shortPropertyName(SVNProperty.TEXT_TIME), SVNLog.WC_TIMESTAMP);
log.addCommand(SVNLog.MODIFY_ENTRY, command, false);
command.clear();
}
reverted |= reinstallWorkingFile;
}
if (entry.getConflictNew() != null) {
command.put(SVNLog.NAME_ATTR, entry.getConflictNew());
log.addCommand(SVNLog.DELETE, command, false);
command.clear();
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.CONFLICT_NEW), null);
if (!reverted) {
reverted |= dir.getFile(entry.getConflictNew()).exists();
}
}
if (entry.getConflictOld() != null) {
command.put(SVNLog.NAME_ATTR, entry.getConflictOld());
log.addCommand(SVNLog.DELETE, command, false);
command.clear();
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.CONFLICT_OLD), null);
if (!reverted) {
reverted |= dir.getFile(entry.getConflictOld()).exists();
}
}
if (entry.getConflictWorking() != null) {
command.put(SVNLog.NAME_ATTR, entry.getConflictWorking());
log.addCommand(SVNLog.DELETE, command, false);
command.clear();
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.CONFLICT_WRK), null);
if (!reverted) {
reverted |= dir.getFile(entry.getConflictWorking()).exists();
}
}
if (entry.getPropRejectFile() != null) {
command.put(SVNLog.NAME_ATTR, entry.getPropRejectFile());
log.addCommand(SVNLog.DELETE, command, false);
command.clear();
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.PROP_REJECT_FILE), null);
if (!reverted) {
reverted |= dir.getFile(entry.getPropRejectFile()).exists();
}
}
if (entry.getSchedule() != null) {
newEntryProperties.put(SVNProperty.shortPropertyName(SVNProperty.SCHEDULE), null);
reverted = true;
}
if (!newEntryProperties.isEmpty()) {
newEntryProperties.put(SVNLog.NAME_ATTR, name);
log.addCommand(SVNLog.MODIFY_ENTRY, newEntryProperties, false);
}
log.save();
dir.runLogs();
return reverted;
}