setEntriesChanged(mergeResult == SVNStatusType.CONFLICTED);
setEntriesChanged(mergeResult == SVNStatusType.CONFLICTED); } else if (SVNLog.COMMIT.equals(name)) { if (attributes.get(SVNLog.REVISION_ATTR) == null) { SVNErrorManager.error("svn: Missing revision attribute for '" + fileName + "'"); } SVNEntry entry = dir.getEntries().getEntry(fileName, true); if (entry == null || (!"".equals(fileName) && entry.getKind() != SVNNodeKind.FILE)) { SVNErrorManager.error("svn: Log command for directory '" + dir.getRoot() + "' is mislocated"); } long revisionNumber = Long.parseLong((String) attributes.get(SVNLog.REVISION_ATTR)); if (entry.isScheduledForDeletion()) { if ("".equals(fileName)) { entry.setRevision(revisionNumber); entry.setKind(SVNNodeKind.DIR); File killMe = dir.getFile(".svn/KILLME", false); if (killMe.getParentFile().isDirectory()) { try { killMe.createNewFile(); } catch (IOException e) { SVNErrorManager.error(0, e); } } } else { dir.destroy(fileName, false); SVNEntry parentEntry = dir.getEntries().getEntry("", true); if (revisionNumber > parentEntry.getRevision()) { SVNEntry fileEntry = dir.getEntries().addEntry(fileName); fileEntry.setKind(SVNNodeKind.FILE); fileEntry.setDeleted(true); fileEntry.setRevision(revisionNumber); } } setEntriesChanged(true); return; }  if (entry.isScheduledForReplacement() && "".equals(fileName)) { for (Iterator ents = dir.getEntries().entries(true); ents.hasNext();) { SVNEntry currentEntry = (SVNEntry) ents.next(); if (!currentEntry.isScheduledForDeletion()) { continue; } if (currentEntry.getKind() == SVNNodeKind.FILE || currentEntry.getKind() == SVNNodeKind.DIR) { dir.destroy(currentEntry.getName(), false); } } }  long textTime = 0; if (!"".equals(fileName)) { File tmpFile = dir.getBaseFile(fileName, true); SVNFileType fileType = SVNFileType.getType(tmpFile); if (fileType == SVNFileType.FILE || fileType == SVNFileType.SYMLINK) {  File tmpFile2 = SVNFileUtil.createUniqueFile(tmpFile.getParentFile(), fileName, ".tmp"); boolean equals = true; try { String tmpFile2Path = SVNFileUtil.getBasePath(tmpFile2); SVNTranslator.translate(dir, fileName, fileName, tmpFile2Path, false, false); equals = SVNFileUtil.compareFiles(tmpFile, tmpFile2, null); } finally { tmpFile2.delete(); } if (equals) { textTime = dir.getFile(fileName, false).lastModified(); } else { textTime = tmpFile.lastModified(); } } } SVNProperties baseProps = dir.getBaseProperties(fileName, false); SVNProperties wcProps = dir.getProperties(fileName, false); SVNProperties tmpProps = dir.getBaseProperties(fileName, true); if (entry.isScheduledForReplacement()) { baseProps.delete(); } long propTime = 0; boolean setReadWrite = false; boolean setNotExecutable = false;  SVNFileType tmpPropsType = SVNFileType.getType(tmpProps.getFile()); if (tmpPropsType == SVNFileType.FILE) { boolean equals = SVNFileUtil.compareFiles(wcProps.getFile(), tmpProps.getFile(), null); propTime = equals ? wcProps.getFile().lastModified() : tmpProps.getFile().lastModified(); if (!"".equals(fileName)) { Map propDiff = baseProps.compareTo(tmpProps); setReadWrite = propDiff != null && propDiff.containsKey(SVNProperty.NEEDS_LOCK) && propDiff.get(SVNProperty.NEEDS_LOCK) == null; setNotExecutable = propDiff != null && propDiff.containsKey(SVNProperty.EXECUTABLE) && propDiff.get(SVNProperty.EXECUTABLE) == null; } try { SVNFileUtil.rename(tmpProps.getFile(), baseProps.getFile()); SVNFileUtil.setReadonly(baseProps.getFile(), true); } catch (IOException e) { SVNErrorManager.error(0, e); } finally { tmpProps.delete(); } }  if (!"".equals(fileName)) { File tmpFile = dir.getBaseFile(fileName, true); File baseFile = dir.getBaseFile(fileName, false); File wcFile = dir.getFile(fileName, false); File tmpFile2 = SVNFileUtil.createUniqueFile(tmpFile.getParentFile(), fileName, ".tmp"); try { boolean overwritten = false; SVNFileType fileType = SVNFileType.getType(tmpFile); boolean special = dir.getProperties(fileName, false).getPropertyValue(SVNProperty.SPECIAL) != null; if (fileType == SVNFileType.FILE) { SVNTranslator.translate(dir, fileName, SVNFileUtil.getBasePath(tmpFile), SVNFileUtil.getBasePath(tmpFile2), true, false); } else { SVNTranslator.translate(dir, fileName, fileName, SVNFileUtil.getBasePath(tmpFile2), true, false); } if (!special && !SVNFileUtil.compareFiles(tmpFile2, wcFile, null)) { try { SVNFileUtil.copy(tmpFile2, wcFile, true); overwritten = true; } catch (IOException e) { SVNErrorManager.error(0, e); } } boolean needsReadonly = dir.getProperties(fileName, false).getPropertyValue(SVNProperty.NEEDS_LOCK) != null && entry.getLockToken() == null; boolean needsExecutable = dir.getProperties(fileName, false).getPropertyValue(SVNProperty.EXECUTABLE) != null; if (needsReadonly) { try { SVNFileUtil.setReadonly(wcFile, true); overwritten = true; } catch (IOException e) { SVNErrorManager.error(0, e); } } if (needsExecutable) { SVNFileUtil.setExecutable(wcFile, true); overwritten = true; } if (fileType == SVNFileType.FILE) { try { SVNFileUtil.rename(tmpFile, baseFile); } catch (IOException e) { SVNErrorManager.error(0, e); } } if (setReadWrite) { try { SVNFileUtil.setReadonly(wcFile, false); overwritten = true; } catch (IOException e) { SVNErrorManager.error(0, e); } } if (setNotExecutable) { SVNFileUtil.setExecutable(wcFile, false); overwritten = true; } if (overwritten) { textTime = wcFile.lastModified(); } } finally { tmpFile2.delete(); tmpFile.delete(); } }  entry.setRevision(revisionNumber); entry.setKind("".equals(fileName) ? SVNNodeKind.DIR : SVNNodeKind.FILE); entry.unschedule(); entry.setCopied(false); entry.setDeleted(false); entry.setTextTime(textTime == 0 ? null : TimeUtil.formatDate(new Date(textTime))); entry.setPropTime(propTime == 0 ? null : TimeUtil.formatDate(new Date(propTime))); entry.setConflictNew(null); entry.setConflictOld(null); entry.setConflictWorking(null); entry.setPropRejectFile(null); entry.setCopyFromRevision(-1); entry.setCopyFromURL(null); setEntriesChanged(true);  if (!"".equals(fileName)) { return; }  File dirFile = dir.getRoot(); if (SVNWCUtil.isWorkingCopyRoot(dirFile, true)) { return; } String parentPath = "".equals(dir.getPath()) ? null : PathUtil.removeTail(dir.getPath()); if (PathUtil.isEmpty(parentPath)) { parentPath = ""; } SVNDirectory parentDir = dir.getWCAccess().getDirectory(parentPath); SVNWCAccess parentAccess = null; if (parentDir == null) { parentDir = new SVNDirectory(null, "", dirFile); parentAccess = new SVNWCAccess(parentDir, parentDir, ""); parentAccess.open(true, false); } String nameInParent = dirFile.getName(); SVNEntry entryInParent = parentDir.getEntries().getEntry(nameInParent, false); if (entryInParent != null) { entryInParent.unschedule(); entryInParent.setCopied(false); entryInParent.setDeleted(false); } parentDir.getEntries().save(false); if (parentAccess != null) { parentAccess.close(true); }
    public void runCommand(SVNDirectory dir, String name, Map attributes) throws SVNException {        String fileName = (String) attributes.remove(SVNLog.NAME_ATTR);        DebugLog.log("running: " + name + ":" + fileName + " : " + attributes);        if (SVNLog.DELETE_ENTRY.equals(name)) {            // check if it is not disjoint entry not to delete another wc?            dir.destroy(fileName, true);        } else if (SVNLog.MODIFY_ENTRY.equals(name)) {            SVNEntries entries = dir.getEntries();            boolean modified = false;            if (entries.getEntry(fileName, true) == null) {                entries.addEntry(fileName);                modified = true;            }            for (Iterator atts = attributes.keySet().iterator(); atts.hasNext();) {                String attName = (String) atts.next();                String value = (String) attributes.get(attName);                attName = SVNProperty.SVN_ENTRY_PREFIX + attName;                if (SVNLog.WC_TIMESTAMP.equals(value)) {                    if (SVNProperty.PROP_TIME.equals(attName)) {                        String path = "".equals(fileName) ? ".svn/dir-props" : ".svn/props/" + fileName + ".svn-work";                        File file = new File(dir.getRoot(), path);                        value = TimeUtil.formatDate(new Date(file.lastModified()));                    } else if (SVNProperty.TEXT_TIME.equals(attName)) {                        String path = "".equals(fileName) ? "" : fileName;                        File file = new File(dir.getRoot(), path);                        value = TimeUtil.formatDate(new Date(file.lastModified()));                    }                }                                entries.setPropertyValue(fileName, attName, value);                modified = true;            }            setEntriesChanged(modified);        } else if (SVNLog.MODIFY_WC_PROPERTY.equals(name)) {            SVNProperties props = dir.getWCProperties(fileName);            String propName = (String) attributes.get(SVNLog.PROPERTY_NAME_ATTR);            String propValue = (String) attributes.get(SVNLog.PROPERTY_VALUE_ATTR);            props.setPropertyValue(propName, propValue);        } else if (SVNLog.DELETE_LOCK.equals(name)) {            SVNEntries entries = dir.getEntries();            SVNEntry entry = entries.getEntry(fileName, true);            if (entry != null) {                entry.setLockToken(null);                entry.setLockOwner(null);                entry.setLockCreationDate(null);                entry.setLockComment(null);                setEntriesChanged(true);            }        } else if (SVNLog.DELETE.equals(name)) {            File file = new File(dir.getRoot(), fileName);            file.delete();        } else if (SVNLog.READONLY.equals(name)) {            File file = new File(dir.getRoot(), fileName);            try {                SVNFileUtil.setReadonly(file, true);            } catch (IOException e) {                SVNErrorManager.error(0, e);            }        } else if (SVNLog.MOVE.equals(name)) {            File src = new File(dir.getRoot(), fileName);            File dst = new File(dir.getRoot(), (String) attributes.get(SVNLog.DEST_ATTR));            try {                SVNFileUtil.rename(src, dst);            } catch (IOException e) {                SVNErrorManager.error(0, e);            }        } else if (SVNLog.APPEND.equals(name)) {            File src = new File(dir.getRoot(), fileName);            File dst = new File(dir.getRoot(), (String) attributes.get(SVNLog.DEST_ATTR));            OutputStream os = null;            InputStream is = null;            try {                os = SVNFileUtil.openFileForWriting(dst, true);                is = SVNFileUtil.openFileForReading(src);                while(true) {                    int r = is.read();                    if (r < 0) {                        break;                    }                    os.write(r);                }            } catch (IOException e) {                SVNErrorManager.error(0, e);            } finally {                SVNFileUtil.closeFile(os);                SVNFileUtil.closeFile(is);            }        } else if (SVNLog.SET_TIMESTAMP.equals(name)) {            File file = new File(dir.getRoot(), fileName);            Date time = TimeUtil.parseDate((String) attributes.get(SVNLog.TIMESTAMP_ATTR));            file.setLastModified(time.getTime());                    } else if (SVNLog.MAYBE_READONLY.equals(name)) {            SVNEntries entries = dir.getEntries();            if (entries.getEntry(fileName, true) != null &&                    entries.getEntry(fileName, true).getLockToken() == null) {                try {                    SVNFileUtil.setReadonly(new File(dir.getRoot(), fileName), true);                } catch (IOException e) {                    SVNErrorManager.error(0, e);                }            }        } else if (SVNLog.COPY_AND_TRANSLATE.equals(name)) {            String dstName = (String) attributes.get(SVNLog.DEST_ATTR);            File dst = new File(dir.getRoot(), dstName);            // get properties for this entry.            SVNProperties props = dir.getProperties(dstName, false);            boolean executable = props.getPropertyValue(SVNProperty.EXECUTABLE) != null;                        SVNTranslator.translate(dir, dstName, fileName, dstName, true, true);            if (executable) {                SVNFileUtil.setExecutable(dst, true);            }            SVNEntry entry = dir.getEntries().getEntry(dstName, true);            if (entry.getLockToken() == null && props.getPropertyValue(SVNProperty.NEEDS_LOCK) != null) {                try {                    SVNFileUtil.setReadonly(dst, true);                } catch (IOException e) {                    SVNErrorManager.error(0, e);                }            }        } else if (SVNLog.COPY_AND_DETRANSLATE.equals(name)) {            String dstName = (String) attributes.get(SVNLog.DEST_ATTR);            SVNTranslator.translate(dir, fileName, fileName, dstName, false, true);        } else if (SVNLog.MERGE.equals(name)) {            File target = new File(dir.getRoot(), fileName);            String leftPath = (String) attributes.get(SVNLog.ATTR1);            String rightPath = (String) attributes.get(SVNLog.ATTR2);            String leftLabel = (String) attributes.get(SVNLog.ATTR3);            leftLabel = leftLabel == null ? ".old" : leftLabel;            String rightLabel = (String) attributes.get(SVNLog.ATTR4);            rightLabel = rightLabel == null ? ".new" : rightLabel;            String targetLabel = (String) attributes.get(SVNLog.ATTR5);            targetLabel = targetLabel == null ? ".working" : targetLabel;                        SVNProperties props = dir.getProperties(fileName, false);            SVNEntry entry = dir.getEntries().getEntry(fileName, true);                        SVNStatusType mergeResult = dir.mergeText(fileName, leftPath, rightPath, targetLabel, leftLabel, rightLabel, false);            if (props.getPropertyValue(SVNProperty.EXECUTABLE) != null) {                SVNFileUtil.setExecutable(target, true);            }            if (props.getPropertyValue(SVNProperty.NEEDS_LOCK) != null && entry.getLockToken() == null) {                try {                    SVNFileUtil.setReadonly(target, true);                } catch (IOException e) {                    SVNErrorManager.error(0, e);                }            }            setEntriesChanged(mergeResult == SVNStatusType.CONFLICTED);                    }    }