public static ByteArrayOutputStream diff( SVNClientManager clientManager, File baseDir, SVNRevision startRevision, SVNRevision endRevision ) throws SVNException { ByteArrayOutputStream result = new ByteArrayOutputStream(); /* * SVNRevision.HEAD means the latest revision. * Returns SVNCommitInfo containing information on the new revision committed * (revision number, etc.) */ clientManager.getDiffClient().doDiff( baseDir, startRevision, startRevision, endRevision, true, true, result ); return result; }
/** * Diffs one url against another one providing short status-like change information to the provided * handler. This method functionality is equivalent to the 'svn diff --summarize' command. * * @param url1 the url of a left-hand item to diff * @param rN a revision of <code>url1</code> * @param url2 the url of a right-hand item to diff * @param rM a revision of <code>url2</code> * @param recursive controls whether operation must recurse or not * @param useAncestry if <span class="javakeyword">true</span> then * the paths ancestry will be noticed while calculating differences, * otherwise not * @param handler a diff status handler * @throws SVNException * @since 1.1, new in Subversion 1.4 * @deprecated use {@link #doDiffStatus(SVNURL, SVNRevision, SVNURL, SVNRevision, SVNDepth, boolean, ISVNDiffStatusHandler)} * instead */ public void doDiffStatus(SVNURL url1, SVNRevision rN, SVNURL url2, SVNRevision rM, boolean recursive, boolean useAncestry, ISVNDiffStatusHandler handler) throws SVNException { doDiffStatus(url1, rN, url2, rM, SVNDepth.getInfinityOrFilesDepth(recursive), useAncestry, handler); }
doMerge(path1, revision1, url2, revision2, dstPath, SVNDepth.getInfinityOrFilesDepth(recursive), useAncestry, force, dryRun, false);
/** * Returns an instance of the {@link SVNDiffClient} class. * * <p> * If it's the first time this method is being called the object is * created, initialized and then returned. Further calls to this * method will get the same object instantiated at that moment of * the first call. <b>SVNClientManager</b> does not reinstantiate * its <b>SVN</b>*<b>Client</b> objects. * * @return an <b>SVNDiffClient</b> instance */ public SVNDiffClient getDiffClient() { if (myDiffClient == null) { myDiffClient = new SVNDiffClient(this, myOptions); myDiffClient.setEventHandler(myEventHandler); myDiffClient.setDebugLog(getDebugLog()); myDiffClient.setIgnoreExternals(myIsIgnoreExternals); } return myDiffClient; }
public ByteArrayOutputStream getDiff(String text) throws IOException { File pathToFile = new File(checkoutdir, fileName); SVNDiffClient diffClient = new SVNDiffClient(manager, svnOption); FileUtils.writeStringToFile(pathToFile, text, "UTF-8"); ByteArrayOutputStream diff = new ByteArrayOutputStream(); try { diffClient.doDiff(pathToFile, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD, SVNDepth.INFINITY, true, diff, null); } catch (SVNException e) { log.error("Diff fail", e); } return diff; }
/** * Returns an instance of the {@link SVNDiffClient} class. * * <p> * If it's the first time this method is being called the object is * created, initialized and then returned. Further calls to this * method will get the same object instantiated at that moment of * the first call. <b>SVNClientManager</b> does not reinstantiate * its <b>SVN</b>*<b>Client</b> objects. * * @return an <b>SVNDiffClient</b> instance */ public SVNDiffClient getDiffClient() { if (myDiffClient == null) { myDiffClient = new SVNDiffClient(this, myOptions); myDiffClient.setEventHandler(myEventHandler); myDiffClient.setDebugLog(getDebugLog()); } return myDiffClient; }
public void diff(String target, Revision pegRevision, Revision startRevision, Revision endRevision, String relativeToDir, String outFileName, int depth, String[] changelists, boolean ignoreAncestry, boolean noDiffDeleted, boolean force) throws ClientException { SVNDiffClient differ = getSVNDiffClient(); differ.getDiffGenerator().setDiffDeleted(!noDiffDeleted); differ.getDiffGenerator().setForcedBinaryDiff(force); differ.setOptions(getOptions()); SVNRevision peg = JavaHLObjectFactory.getSVNRevision(pegRevision); SVNRevision rev1 = JavaHLObjectFactory.getSVNRevision(startRevision); SVNRevision rev2 = JavaHLObjectFactory.getSVNRevision(endRevision); try { differ.getDiffGenerator().setBasePath(getDiffBasePath(relativeToDir)); OutputStream out = SVNFileUtil.openFileForWriting(new File(outFileName)); if (isURL(target)) { SVNURL url = SVNURL.parseURIEncoded(target); differ.doDiff(url, peg, rev1, rev2, JavaHLObjectFactory.getSVNDepth(depth), !ignoreAncestry, out); } else { differ.doDiff(new File(target).getAbsoluteFile(), peg, rev1, rev2, JavaHLObjectFactory.getSVNDepth(depth), !ignoreAncestry, out, JavaHLObjectFactory.getChangeListsCollection(changelists)); } SVNFileUtil.closeFile(out); } catch (SVNException e) { throwException(e); } finally { resetLog(); } }
client.setEventHandler(printer); SVNCommandEnvironment environment = (SVNCommandEnvironment) getEnvironment(); client.setShowCopiesAsAdds(environment.isShowCopiesAsAdds()); client.setGitDiffFormat(environment.isGitDiffFormat()); SvnNewDiffGenerator generator = createDiffGenerator(getSVNEnvironment()); client.setDiffGenerator(generator); this.anchor = target1; if (target1.isURL() && target2.isURL()) { client.doDiffStatus(target1.getURL(), start, target2.getURL(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), this); } else if (target1.isURL()) { client.doDiffStatus(target1.getURL(), start, target2.getFile(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), this); } else if (target2.isURL()) { client.doDiffStatus(target1.getFile(), start, target2.getURL(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), this); } else { client.doDiffStatus(target1.getFile(), start, target2.getFile(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), this); client.doDiff(target1.getURL(), start, target2.getURL(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), ps); } else if (target1.isURL()) { client.doDiff(target1.getURL(), start, target2.getFile(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), ps, changeLists); } else if (target2.isURL()) { client.doDiff(target1.getFile(), start, target2.getURL(), end, getSVNEnvironment().getDepth(), getSVNEnvironment().isNoticeAncestry(), ps, changeLists); } else { client.doDiff(target1.getFile(), start, target2.getFile(), end,
private void doDiffURLWC(SVNURL url1, SVNRevision revision1, SVNRevision pegRevision, File path2, SVNRevision revision2, boolean reverse, SVNDepth depth, boolean useAncestry, OutputStream result, Collection changeLists) throws SVNException { SVNWCAccess wcAccess = createWCAccess(); try { SVNAdminAreaInfo info = wcAccess.openAnchor(path2, false, SVNDepth.recurseFromDepth(depth) ? SVNWCAccess.INFINITE_DEPTH : 0); SVNRepositoryLocation[] locations = getLocations(url1, null, null, pegRevision, revision1, SVNRevision.UNDEFINED); url1 = locations[0].getURL(); String anchorPath2 = SVNPathUtil.append(anchorURL.toString(), target == null ? "" : target); getDiffGenerator().init(url1.toString(), anchorPath2); SVNRepository repository = createRepository(anchorURL, null, null, true); long revNumber = getRevisionNumber(revision1, repository, null); AbstractDiffCallback callback = new SVNDiffCallback(info.getAnchor(), getDiffGenerator(), reverse ? -1 : revNumber, reverse ? revNumber : -1, result); SVNDiffEditor editor = new SVNDiffEditor(wcAccess, info, callback, useAncestry, reverse /* reverse */, boolean serverSupportsDepth = repository.hasCapability(SVNCapability.DEPTH); SVNReporter reporter = new SVNReporter(info, info.getAnchor().getFile(info.getTargetName()), false, !serverSupportsDepth, depth, false, false, true, getDebugLog()); long pegRevisionNumber = getRevisionNumber(revision2, repository, path2); try { repository.diff(url1, revNumber, pegRevisionNumber, target, !useAncestry, depth, true, reporter, SVNCancellableEditor.newInstance(editor, this, getDebugLog())); } finally { editor.cleanup();
SVNNotifyPrinter printer = new SVNNotifyPrinter(getSVNEnvironment()); if (!getSVNEnvironment().isQuiet()) { client.setEventHandler(printer); client.setAllowMixedRevisionsWCForMerge(getSVNEnvironment().isAllowMixedRevisions()); try { client.setMergeOptions(getSVNEnvironment().getDiffOptions()); try { if (!twoSourcesSpecified) { client.doMergeReIntegrate(source1.getURL(), pegRevision1, target.getFile(), getSVNEnvironment().isDryRun()); } else { client.doMergeReIntegrate(source1.getFile(), pegRevision1, target.getFile(), getSVNEnvironment().isDryRun()); client.doMerge(source1.getURL(), pegRevision1, rangesToMerge, target.getFile(), getSVNEnvironment().getDepth(), !getSVNEnvironment().isIgnoreAncestry(), getSVNEnvironment().isForce(), getSVNEnvironment().isDryRun(), getSVNEnvironment().isRecordOnly()); } else { client.doMerge(source1.getFile(), pegRevision1, rangesToMerge, target.getFile(), getSVNEnvironment().getDepth(), !getSVNEnvironment().isIgnoreAncestry(), getSVNEnvironment().isForce(), getSVNEnvironment().isDryRun(), client.doMerge(source1.getURL(), firstRangeStart, source2.getURL(), firstRangeEnd, target.getFile(), getSVNEnvironment().getDepth(), !getSVNEnvironment().isIgnoreAncestry(), getSVNEnvironment().isForce(), getSVNEnvironment().isDryRun(), getSVNEnvironment().isRecordOnly());
public void diff(String target, Revision pegRevision, Revision startRevision, Revision endRevision, String outFileName, boolean recurse, boolean ignoreAncestry, boolean noDiffDeleted, boolean force) throws ClientException { SVNDiffClient differ = getSVNDiffClient(); differ.getDiffGenerator().setDiffDeleted(!noDiffDeleted); differ.getDiffGenerator().setForcedBinaryDiff(force); SVNRevision peg = JavaHLObjectFactory.getSVNRevision(pegRevision); SVNRevision rev1 = JavaHLObjectFactory.getSVNRevision(startRevision); SVNRevision rev2 = JavaHLObjectFactory.getSVNRevision(endRevision); try { OutputStream out = SVNFileUtil.openFileForWriting(new File(outFileName)); if(isURL(target)){ SVNURL url = SVNURL.parseURIEncoded(target); differ.doDiff(url, peg, rev1, rev2, recurse, !ignoreAncestry, out); }else{ differ.doDiff(new File(target).getAbsoluteFile(), peg, rev1, rev2, recurse, !ignoreAncestry, out); } SVNFileUtil.closeFile(out); } catch (SVNException e) { throwException(e); } }
private void doDiffWCWC(File path1, SVNRevision revision1, File path2, SVNRevision revision2, SVNDepth depth, boolean useAncestry, OutputStream result, Collection changeLists) throws SVNException { if (!path1.equals(path2) || !(revision1 == SVNRevision.BASE && revision2 == SVNRevision.WORKING)) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE, "Only diffs between a path's text-base and its working files are supported at this time (-rBASE:WORKING)"); SVNErrorManager.error(err, SVNLogType.WC); } SVNWCAccess wcAccess = createWCAccess(); try { int admDepth = getAdminDepth(depth); SVNAdminAreaInfo info = wcAccess.openAnchor(path1, false, admDepth); wcAccess.getVersionedEntry(path1, false); long rev = getRevisionNumber(revision1, null, path1); AbstractDiffCallback callback = new SVNDiffCallback(info.getAnchor(), getDiffGenerator(), rev, -1, result); SVNDiffEditor editor = new SVNDiffEditor(wcAccess, info, callback, useAncestry, false, false, depth, changeLists); try { editor.closeEdit(); } finally { editor.cleanup(); } } finally { wcAccess.close(); } }
File path = paths[i]; try { doDiff(path, pegRevision, rN, rM, depth, useAncestry, result, changeLists); } catch (SVNException svne) { dispatchEvent(SVNEventFactory.createErrorEvent(svne.getErrorMessage(), null));
SVNURL reposRoot = getReposRoot(null, url, pegRevision, null, null); SVNLocationEntry copyFromInfo = getCopySource(null, url, pegRevision); String copyFromPath = copyFromInfo.getPath(); Map mergeInfo = doGetMergedMergeInfo(url, pegRevision); if (mergeInfo != null) { for (Iterator mergeSrcURLs = mergeInfo.keySet().iterator(); mergeSrcURLs.hasNext();) {
javaRepo.getClientManager().getDiffClient().setEventHandler( handler ); javaRepo.getClientManager().getDiffClient().setEventHandler( null );
SVNDiffClient client = getSVNEnvironment().getClientManager().getDiffClient(); final SVNNotifyPrinter printer = new SVNNotifyPrinter(getSVNEnvironment()); client.setEventHandler(printer); SvnOperationFactory of = client.getOperationsFactory(); SVNDepth depth = getSVNEnvironment().getDepth(); if (depth == SVNDepth.UNKNOWN) {
final SvnDiff diff = getOperationsFactory().createDiff(); diff.setDiffGenerator(getDiffGenerator()); diff.setSource(SvnTarget.fromFile(path, pegRevision), rN, rM); diff.setDepth(depth); diff.setIgnoreAncestry(!useAncestry); diff.setRecurseIntoDeletedDirectories(isRecurseIntoDeletedDirectories()); diff.setOutput(result); diff.setApplicalbeChangelists(changeLists); diff.setShowCopiesAsAdds(isShowCopiesAsAdds()); diff.setUseGitDiffFormat(isGitDiffFormat()); diff.run();
private void doDiffWCWC(File path1, SVNRevision revision1, File path2, SVNRevision revision2, boolean recursive, boolean useAncestry, OutputStream result) throws SVNException { if (!path1.equals(path2) || !(revision1 == SVNRevision.BASE && revision2 == SVNRevision.WORKING)) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE, "Only diffs between a path's text-base " + "and its working files are supported at this time (-rBASE:WORKING)"); SVNErrorManager.error(err); } SVNWCAccess wcAccess = createWCAccess(); try { SVNAdminAreaInfo info = wcAccess.openAnchor(path1, false, recursive ? SVNWCAccess.INFINITE_DEPTH: 0); SVNEntry entry = wcAccess.getEntry(path1, false); if (entry == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "''{0}'' is not under version control", path1); SVNErrorManager.error(err); } long rev = getRevisionNumber(revision1, null, path1); AbstractDiffCallback callback = new SVNDiffCallback(info, getDiffGenerator(), rev, -1, result); SVNDiffEditor editor = new SVNDiffEditor(wcAccess, info, callback, useAncestry, false, false, recursive); try { editor.closeEdit(); } finally { editor.cleanup(); } } finally { wcAccess.close(); } }
public void run() throws SVNException { final List targets = getSVNEnvironment().combineTargets(getSVNEnvironment().getTargets(), true); final int targetsCount = targets.size(); if (targetsCount < 1 || targetsCount > 2) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CL_ARG_PARSING_ERROR); SVNErrorManager.error(err, SVNLogType.CLIENT); } final SVNDiffClient client = getSVNEnvironment().getClientManager().getDiffClient(); SVNNotifyPrinter printer = new SVNNotifyPrinter(getSVNEnvironment()); if (!getSVNEnvironment().isQuiet()) { client.setEventHandler(printer); } final File patchPath = new File((String) targets.get(0)); final File targetPath = new File(targetsCount != 2 ? "." : (String) targets.get(1)); try { client.doPatch(patchPath.getAbsoluteFile(), targetPath.getAbsoluteFile(), getSVNEnvironment().isDryRun(), getSVNEnvironment().getStripCount(), getSVNEnvironment().isIgnoreWhitespace(), true, getSVNEnvironment().isReverseDiff()); } catch (SVNException e) { getSVNEnvironment().handleWarning(e.getErrorMessage(), new SVNErrorCode[] { SVNErrorCode.ENTRY_EXISTS, SVNErrorCode.WC_PATH_NOT_FOUND }, getSVNEnvironment().isQuiet()); } finally { if (!getSVNEnvironment().isQuiet()) { StringBuffer status = new StringBuffer(); printer.printConflictStatus(status); getSVNEnvironment().getOut().print(status); } } }
SVNErrorManager.error(err); getDiffGenerator().init(url1.toString(), url2.toString()); doDiffURLURL(url1, null, rN, url2, null, rM, SVNRevision.UNDEFINED, recursive, useAncestry, result);