private SVNLogEntryPath getFileCopyOrigin(String path) throws SVNException { String[] paths = (String[]) myCopiedPaths.keySet().toArray(new String[myCopiedPaths.size()]); Arrays.sort(paths, 0, paths.length, SVNPathUtil.PATH_COMPARATOR); SVNLogEntryPath realPath = null; List candidates = new ArrayList(); for (int i = 0; i < paths.length; i++) { String copiedPath = (String) paths[i]; if (!path.startsWith(copiedPath + "/")) { continue; } else if (path.equals(copiedPath)) { return (SVNLogEntryPath) myCopiedPaths.get(copiedPath); } candidates.add(copiedPath); } // check candidates from the end of the list for(int i = candidates.size() - 1; i >=0; i--) { String candidateParent = (String) candidates.get(i); if (getSourceRepository().checkPath(candidateParent, myTargetRevision) != SVNNodeKind.DIR) { continue; } SVNLogEntryPath changedPath = (SVNLogEntryPath) myCopiedPaths.get(candidateParent); String fileRelativePath = path.substring(candidateParent.length() + 1); fileRelativePath = SVNPathUtil.append(changedPath.getCopyPath(), fileRelativePath); return new SVNLogEntryPath(path, ' ', fileRelativePath, changedPath.getCopyRevision()); } return realPath; }
private SVNLogEntryPath getFileCopyOrigin(String path) throws SVNException { Object[] paths = myCopiedPaths.keySet().toArray(); Arrays.sort(paths, 0, paths.length, SVNPathUtil.PATH_COMPARATOR); SVNLogEntryPath realPath = null; List candidates = new ArrayList(); for (int i = 0; i < paths.length; i++) { String copiedPath = (String) paths[i]; if (!path.startsWith(copiedPath + "/")) { continue; } else if (path.equals(copiedPath)) { return (SVNLogEntryPath) myCopiedPaths.get(copiedPath); } candidates.add(copiedPath); } // check candidates from the end of the list for(int i = candidates.size() - 1; i >=0; i--) { String candidateParent = (String) candidates.get(i); if (getSourceRepository().checkPath(candidateParent, myTargetRevision) != SVNNodeKind.DIR) { continue; } SVNLogEntryPath changedPath = (SVNLogEntryPath) myCopiedPaths.get(candidateParent); String fileRelativePath = path.substring(candidateParent.length() + 1); fileRelativePath = SVNPathUtil.append(changedPath.getCopyPath(), fileRelativePath); return new SVNLogEntryPath(path, ' ', fileRelativePath, changedPath.getCopyRevision()); } return realPath; }
private SVNLogEntryPath getFileCopyOrigin(String path) throws SVNException { Object[] paths = myCopiedPaths.keySet().toArray(); Arrays.sort(paths, 0, paths.length, SVNPathUtil.PATH_COMPARATOR); SVNLogEntryPath realPath = null; List candidates = new ArrayList(); for (int i = 0; i < paths.length; i++) { String copiedPath = (String) paths[i]; if (!path.startsWith(copiedPath + "/")) { continue; } else if (path.equals(copiedPath)) { return (SVNLogEntryPath) myCopiedPaths.get(copiedPath); } candidates.add(copiedPath); } // check candidates from the end of the list for(int i = candidates.size() - 1; i >=0; i--) { String candidateParent = (String) candidates.get(i); if (getSourceRepository().checkPath(candidateParent, myTargetRevision) != SVNNodeKind.DIR) { continue; } SVNLogEntryPath changedPath = (SVNLogEntryPath) myCopiedPaths.get(candidateParent); String fileRelativePath = path.substring(candidateParent.length() + 1); fileRelativePath = SVNPathUtil.append(changedPath.getCopyPath(), fileRelativePath); return new SVNLogEntryPath(path, ' ', fileRelativePath, changedPath.getCopyRevision()); } return realPath; }
private SVNLogEntryPath getFileCopyOrigin(String path) throws SVNException { Object[] paths = myCopiedPaths.keySet().toArray(); Arrays.sort(paths, 0, paths.length, SVNPathUtil.PATH_COMPARATOR); SVNLogEntryPath realPath = null; List candidates = new ArrayList(); for (int i = 0; i < paths.length; i++) { String copiedPath = (String) paths[i]; if (!path.startsWith(copiedPath + "/")) { continue; } else if (path.equals(copiedPath)) { return (SVNLogEntryPath) myCopiedPaths.get(copiedPath); } candidates.add(copiedPath); } // check candidates from the end of the list for(int i = candidates.size() - 1; i >=0; i--) { String candidateParent = (String) candidates.get(i); if (getSourceRepository().checkPath(candidateParent, myTargetRevision) != SVNNodeKind.DIR) { continue; } SVNLogEntryPath changedPath = (SVNLogEntryPath) myCopiedPaths.get(candidateParent); String fileRelativePath = path.substring(candidateParent.length() + 1); fileRelativePath = SVNPathUtil.append(changedPath.getCopyPath(), fileRelativePath); return new SVNLogEntryPath(path, ' ', fileRelativePath, changedPath.getCopyRevision()); } return realPath; }
SVNLogEntryPath logEntryPath = (SVNLogEntryPath) sortedChangedPaths.get(changedPath); if (logEntryPath.getCopyPath() != null && SVNRevision.isValidRevisionNumber(logEntryPath.getCopyRevision()) && SVNPathUtil.isAncestor(changedPath, myTargetPath)) { String copyFromPath = null; myCopyFromLocation = new SVNLocationEntry(logEntryPath.getCopyRevision(), copyFromPath); break;
SVNLogEntryPath logEntryPath = (SVNLogEntryPath) sortedChangedPaths.get(changedPath); if (logEntryPath.getCopyPath() != null && SVNRevision.isValidRevisionNumber(logEntryPath.getCopyRevision()) && SVNPathUtil.isAncestor(changedPath, myTargetPath)) { String copyFromPath = null; myCopyFromLocation = new SVNLocationEntry(logEntryPath.getCopyRevision(), copyFromPath); break;
private static Set<ChangePath> getChangePaths(Map<String, SVNLogEntryPath> changedPaths) { if (changedPaths == null) { return null; } Set<ChangePath> changePaths = new HashSet<ChangePath>(); for (Map.Entry<String, SVNLogEntryPath> entry : changedPaths.entrySet()) { SVNLogEntryPath svnLogEntryPath = entry.getValue(); //TODO: replace Tristate.Unknown with correct values in the following changePaths.add(new ChangePath(svnLogEntryPath.getPath(), svnLogEntryPath.getCopyRevision(), svnLogEntryPath.getCopyPath(), getChangePathAction(svnLogEntryPath.getType()), getNodeKind(svnLogEntryPath.getKind()), Tristate.Unknown, Tristate.Unknown)); } return changePaths; }
/** * Creates a new replication editor. * * <p> * <code>repository</code> must be created for the root location of * the source repository which is to be replicated. * * @param repository a source repository * @param commitEditor a commit editor received from the destination * repository driver (which also must be point to the * root location of the destination repository) * @param revision log information of the revision to be copied */ public SVNReplicationEditor(SVNRepository repository, ISVNEditor commitEditor, SVNLogEntry revision) { myRepos = repository; myCommitEditor = commitEditor; myPathsToFileBatons = new SVNHashMap(); myDirsStack = new Stack(); myCopiedPaths = new SVNHashMap(); myChangedPaths = revision.getChangedPaths(); for(Iterator paths = myChangedPaths.keySet().iterator(); paths.hasNext();){ String path = (String)paths.next(); SVNLogEntryPath pathChange = (SVNLogEntryPath)myChangedPaths.get(path); //make sure it's a copy if((pathChange.getType() == SVNLogEntryPath.TYPE_REPLACED || pathChange.getType() == SVNLogEntryPath.TYPE_ADDED) && pathChange.getCopyPath() != null && pathChange.getCopyRevision() >= 0){ myCopiedPaths.put(path, pathChange); } } }
/** * Creates a new replication editor. * * <p> * <code>repository</code> must be created for the root location of * the source repository which is to be replicated. * * @param repository a source repository * @param commitEditor a commit editor received from the destination * repository driver (which also must be point to the * root location of the destination repository) * @param revision log information of the revision to be copied */ public SVNReplicationEditor(SVNRepository repository, ISVNEditor commitEditor, SVNLogEntry revision) { myRepos = repository; myCommitEditor = commitEditor; myPathsToFileBatons = new SVNHashMap(); myDirsStack = new Stack(); myCopiedPaths = new SVNHashMap(); myChangedPaths = revision.getChangedPaths(); for(Iterator paths = myChangedPaths.keySet().iterator(); paths.hasNext();){ String path = (String)paths.next(); SVNLogEntryPath pathChange = (SVNLogEntryPath)myChangedPaths.get(path); //make sure it's a copy if((pathChange.getType() == SVNLogEntryPath.TYPE_REPLACED || pathChange.getType() == SVNLogEntryPath.TYPE_ADDED) && pathChange.getCopyPath() != null && pathChange.getCopyRevision() >= 0){ myCopiedPaths.put(path, pathChange); } } }
public static LogMessage createLogMessage(SVNLogEntry logEntry) { if(logEntry == null){ return null; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if(cpaths == null){ cp = new ChangePath[]{}; }else{ Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType())); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); } return new LogMessage(logEntry.getMessage(), logEntry.getDate(), logEntry.getRevision(), logEntry.getAuthor(), cp); }
public static void handleLogMessage(SVNLogEntry logEntry, LogMessageCallback handler) { if(logEntry == null || handler == null) { return; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if (cpaths == null) { cp = new ChangePath[]{}; } else { Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType(), getNodeKind(entryPath.getKind()))); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); } SVNProperties revisionProperties = logEntry.getRevisionProperties(); Map revisionPropertiesMap = new HashMap(); for(Iterator names = revisionProperties.nameSet().iterator(); names.hasNext();) { String name = (String) names.next(); revisionPropertiesMap.put(name, revisionProperties.getStringValue(name)); } handler.singleMessage(cp, logEntry.getRevision(), revisionPropertiesMap, logEntry.hasChildren()); }
public static void handleLogMessage(SVNLogEntry logEntry, LogMessageCallback handler) { if(logEntry == null || handler == null) { return; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if (cpaths == null) { cp = new ChangePath[]{}; } else { Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType(), getNodeKind(entryPath.getKind()))); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); } SVNProperties revisionProperties = logEntry.getRevisionProperties(); Map revisionPropertiesMap = new HashMap(); for(Iterator names = revisionProperties.nameSet().iterator(); names.hasNext();) { String name = (String) names.next(); revisionPropertiesMap.put(name, revisionProperties.getStringValue(name)); } handler.singleMessage(cp, logEntry.getRevision(), revisionPropertiesMap, logEntry.hasChildren()); }
/** * Creates a new replication editor. * * <p> * <code>repository</code> must be created for the root location of * the source repository which is to be replicated. * * @param repository a source repository * @param commitEditor a commit editor received from the destination * repository driver (which also must be point to the * root location of the destination repository) * @param revision log information of the revision to be copied */ public SVNReplicationEditor(SVNRepository repository, ISVNEditor commitEditor, SVNLogEntry revision) { myRepos = repository; myCommitEditor = commitEditor; myPathsToFileBatons = new SVNHashMap(); myDirsStack = new Stack(); myCopiedPaths = new SVNHashMap(); myChangedPaths = revision.getChangedPaths(); myDeletedPaths = new SVNHashSet(); for(Iterator paths = myChangedPaths.keySet().iterator(); paths.hasNext();){ String path = (String)paths.next(); SVNLogEntryPath pathChange = (SVNLogEntryPath)myChangedPaths.get(path); //make sure it's a copy if((pathChange.getType() == SVNLogEntryPath.TYPE_REPLACED || pathChange.getType() == SVNLogEntryPath.TYPE_ADDED) && pathChange.getCopyPath() != null && pathChange.getCopyRevision() >= 0){ myCopiedPaths.put(path, pathChange); } } }
public static void handleLogMessage(SVNLogEntry logEntry, LogMessageCallback handler) { if(logEntry == null || handler == null) { return; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if (cpaths == null) { cp = new ChangePath[]{}; } else { Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType(), getNodeKind(entryPath.getKind()))); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); } SVNProperties revisionProperties = logEntry.getRevisionProperties(); Map revisionPropertiesMap = new HashMap(); for(Iterator names = revisionProperties.nameSet().iterator(); names.hasNext();) { String name = (String) names.next(); revisionPropertiesMap.put(name, revisionProperties.getStringValue(name)); } handler.singleMessage(cp, logEntry.getRevision(), revisionPropertiesMap, logEntry.hasChildren()); }
public static void handleLogMessage(SVNLogEntry logEntry, LogMessageCallback handler) { if(logEntry == null || handler == null) { return; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if (cpaths == null) { cp = new ChangePath[]{}; } else { Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType(), getNodeKind(entryPath.getKind()))); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); } SVNProperties revisionProperties = logEntry.getRevisionProperties(); Map revisionPropertiesMap = new HashMap(); for(Iterator names = revisionProperties.nameSet().iterator(); names.hasNext();) { String name = (String) names.next(); revisionPropertiesMap.put(name, revisionProperties.getStringValue(name)); } handler.singleMessage(cp, logEntry.getRevision(), revisionPropertiesMap, logEntry.hasChildren()); }
private void indexSVNCopyEvents(SVNRepository repository, SVNLogEntry logEntry) { long revision = logEntry.getRevision(); // Looking for copy tags @SuppressWarnings("unchecked") Map<String, SVNLogEntryPath> changedPaths = logEntry.getChangedPaths(); // Copies /* * Looks through all changed paths and retains only copy operations toward branches or tags */ for (SVNLogEntryPath logEntryPath : changedPaths.values()) { // Gets the copy path String copyFromPath = logEntryPath.getCopyPath(); if (StringUtils.isNotBlank(copyFromPath) && logEntryPath.getType() == SVNLogEntryPath.TYPE_ADDED) { // Registers the new history String copyToPath = logEntryPath.getPath(); // Retains only branches and tags if (svnClient.isTagOrBranch(repository, copyToPath)) { long copyFromRevision = logEntryPath.getCopyRevision(); logger.debug(String.format("\tCOPY %s@%d --> %s", copyFromPath, copyFromRevision, copyToPath)); // Adds a copy event eventDao.createCopyEvent(repository.getId(), revision, copyFromPath, copyFromRevision, copyToPath); } } } }
public static LogMessage createLogMessage(SVNLogEntry logEntry) { if(logEntry == null){ return null; } Map cpaths = logEntry.getChangedPaths(); ChangePath[] cp = null; if(cpaths == null){ cp = new ChangePath[]{}; }else{ Collection clientChangePaths = new ArrayList(); for (Iterator iter = cpaths.keySet().iterator(); iter.hasNext();) { String path = (String) iter.next(); SVNLogEntryPath entryPath = (SVNLogEntryPath)cpaths.get(path); if(entryPath != null){ clientChangePaths.add(new ChangePath(path, entryPath.getCopyRevision(), entryPath.getCopyPath(), entryPath.getType(), getNodeKind(entryPath.getKind()))); } } cp = (ChangePath[]) clientChangePaths.toArray(new ChangePath[clientChangePaths.size()]); // sort by paths. Arrays.sort(cp, CHANGE_PATH_COMPARATOR); } long time = 0; if (logEntry.getDate() != null) { time = logEntry.getDate().getTime()*1000; if (logEntry.getDate() instanceof SVNDate) { time = ((SVNDate) logEntry.getDate()).getTimeInMicros(); } } return new LogMessage(cp, logEntry.getRevision(), logEntry.getAuthor(), time, logEntry.getMessage()); }
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory(); final SvnLog log = svnOperationFactory.createLog(); log.setSingleTarget(SvnTarget.fromURL(url)); log.addRange(SvnRevisionRange.create(SVNRevision.create(12345), SVNRevision.create(12345))); log.setDiscoverChangedPaths(true); final SVNLogEntry logEntry = log.run(); final Map<String,SVNLogEntryPath> changedPaths = logEntry.getChangedPaths(); for (Map.Entry<String, SVNLogEntryPath> entry : changedPaths.entrySet()) { final SVNLogEntryPath svnLogEntryPath = entry.getValue(); System.out.println(svnLogEntryPath.getType() + " " + svnLogEntryPath.getPath() + (svnLogEntryPath.getCopyPath() == null ? "" : (" from " + svnLogEntryPath.getCopyPath() + ":" + svnLogEntryPath.getCopyRevision()))); }
private void checkCopyFrom(@NotNull SVNRepository repo, @NotNull CopyFromSVNEditor editor, long revision) throws SVNException { final Map<String, String> copyFrom = new TreeMap<>(); repo.log(new String[]{""}, revision, revision, true, true, logEntry -> { for (SVNLogEntryPath entry : logEntry.getChangedPaths().values()) { if (entry.getCopyPath() != null) { copyFrom.put(entry.getPath(), entry.getCopyPath() + "@" + entry.getCopyRevision()); } } }); Assert.assertEquals(editor.getCopyFrom(), copyFrom); }
public void addDir(String path, String copyFromPath, long copyFromRevision) throws SVNException { String absPath = getSourceRepository().getRepositoryPath(path); EntryBaton baton = new EntryBaton(absPath); myDirsStack.push(baton); SVNLogEntryPath changedPath = (SVNLogEntryPath) myChangedPaths.get(absPath); if (changedPath != null && (changedPath.getType() == SVNLogEntryPath.TYPE_ADDED || changedPath.getType() == SVNLogEntryPath.TYPE_REPLACED) && changedPath.getCopyPath() != null && changedPath.getCopyRevision() >= 0) { baton.myPropsAct = DECIDE; HashMap props = new HashMap(); getSourceRepository().getDir(changedPath.getCopyPath(), changedPath.getCopyRevision(), props, (ISVNDirEntryHandler) null); baton.myProps = props; if (changedPath.getType() == SVNLogEntryPath.TYPE_REPLACED) { myCommitEditor.deleteEntry(path, myPreviousRevision); myChangedPaths.remove(absPath); } myCommitEditor.addDir(path, changedPath.getCopyPath(), changedPath.getCopyRevision()); } else if (changedPath != null && (changedPath.getType() == SVNLogEntryPath.TYPE_ADDED || changedPath.getType() == SVNLogEntryPath.TYPE_REPLACED)) { baton.myPropsAct = ACCEPT; myCommitEditor.addDir(path, null, -1); } else if (changedPath != null && changedPath.getType() == SVNLogEntryPath.TYPE_MODIFIED) { baton.myPropsAct = ACCEPT; myCommitEditor.openDir(path, myPreviousRevision); } else if (changedPath == null) { baton.myPropsAct = IGNORE; myCommitEditor.openDir(path, myPreviousRevision); } else { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Unknown bug in addDir()"); SVNErrorManager.error(err); } }