List rangesToMerge = getSVNEnvironment().getRevisionRanges();
SVNRevision firstRangeStart = SVNRevision.UNDEFINED;
SVNRevision firstRangeEnd = SVNRevision.UNDEFINED;
if (!rangesToMerge.isEmpty()) {
SVNRevisionRange range = (SVNRevisionRange) rangesToMerge.get(0);
firstRangeStart = range.getStartRevision();
firstRangeEnd = range.getEndRevision();
}
if (firstRangeStart != SVNRevision.UNDEFINED) {
if (firstRangeEnd == SVNRevision.UNDEFINED) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS,
"Second revision required");
SVNErrorManager.error(err, SVNLogType.CLIENT);
}
twoSourcesSpecified = false;
}
if (!twoSourcesSpecified) {
if (targets.size() > 2) {
SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.CL_ARG_PARSING_ERROR,
"Too many arguments given"), SVNLogType.CLIENT);
}
if (targets.isEmpty()) {
pegRevision1 = SVNRevision.HEAD;
} else {
source2 = source1;
if (pegRevision1 == null || pegRevision1 == SVNRevision.UNDEFINED) {
pegRevision1 = source1.isURL() ? SVNRevision.HEAD : SVNRevision.WORKING;
}
if (targets.size() == 2) {
target = new SVNPath((String) targets.get(1));
if (target.isURL()) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.CL_ARG_PARSING_ERROR,
"Cannot specifify a revision range with two URLs");
SVNErrorManager.error(err, SVNLogType.CLIENT);
}
}
}
} else {
if (targets.size() < 2) {
SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS), SVNLogType.CLIENT);
} else if (targets.size() > 3) {
SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.CL_ARG_PARSING_ERROR,
"Too many arguments given"), SVNLogType.CLIENT);
}
firstRangeStart = pegRevision1;
firstRangeEnd = pegRevision2;
if (((firstRangeStart == null || firstRangeStart == SVNRevision.UNDEFINED) && !source1.isURL()) ||
((pegRevision2 == null || pegRevision2 == SVNRevision.UNDEFINED) && !source2.isURL())) {
SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.CLIENT_BAD_REVISION,
"A working copy merge source needs an explicit revision"), SVNLogType.CLIENT);
}
if (firstRangeStart == null || firstRangeStart == SVNRevision.UNDEFINED) {
firstRangeStart = SVNRevision.HEAD;
}
if (firstRangeEnd == null || firstRangeEnd == SVNRevision.UNDEFINED) {
firstRangeEnd = SVNRevision.HEAD;
}
if (targets.size() >= 3) {
target = new SVNPath((String) targets.get(2));
}
}
if (source1 != null && source2 != null && target == null) {
if (source1.isURL()) {
String name1 = SVNPathUtil.tail(source1.getTarget());
String name2 = SVNPathUtil.tail(source2.getTarget());
if (name1.equals(name2)) {
String decodedPath = SVNEncodingUtil.uriDecode(name1);
SVNPath decodedPathTarget = new SVNPath(decodedPath);
if (SVNFileType.getType(decodedPathTarget.getFile()) == SVNFileType.FILE) {
target = decodedPathTarget;
}
}
} else if (source1.equals(source2)) {
String decodedPath = SVNEncodingUtil.uriDecode(source1.getTarget());
SVNPath decodedPathTarget = new SVNPath(decodedPath);
if (SVNFileType.getType(decodedPathTarget.getFile()) == SVNFileType.FILE) {
target = decodedPathTarget;
}
}
}
if (target == null) {
target = new SVNPath("");
}
SVNDiffClient client = getSVNEnvironment().getClientManager().getDiffClient();
if (!getSVNEnvironment().isQuiet()) {
client.setEventHandler(new SVNNotifyPrinter(getSVNEnvironment()));
}
try {
client.setMergeOptions(getSVNEnvironment().getDiffOptions());
if (!twoSourcesSpecified) {
if (firstRangeStart == SVNRevision.UNDEFINED && firstRangeEnd == SVNRevision.UNDEFINED) {
SVNRevisionRange range = new SVNRevisionRange(SVNRevision.create(1), pegRevision1);
rangesToMerge = new LinkedList();
rangesToMerge.add(range);
}
if (source1 == null) {