001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc;
013:
014: import java.io.File;
015: import java.io.IOException;
016: import java.io.OutputStream;
017: import java.io.RandomAccessFile;
018:
019: import org.tmatesoft.svn.core.SVNErrorCode;
020: import org.tmatesoft.svn.core.SVNErrorMessage;
021: import org.tmatesoft.svn.core.SVNException;
022: import org.tmatesoft.svn.core.wc.ISVNMerger;
023: import org.tmatesoft.svn.core.wc.SVNDiffOptions;
024: import org.tmatesoft.svn.core.wc.SVNStatusType;
025:
026: import de.regnis.q.sequence.line.QSequenceLineRAData;
027: import de.regnis.q.sequence.line.QSequenceLineRAFileData;
028:
029: /**
030: * @version 1.1.1
031: * @author TMate Software Ltd.
032: */
033: public class DefaultSVNMerger implements ISVNMerger {
034:
035: private byte[] myStart;
036: private byte[] mySeparator;
037: private byte[] myEnd;
038:
039: public DefaultSVNMerger(byte[] start, byte[] sep, byte[] end) {
040: myStart = start;
041: mySeparator = sep;
042: myEnd = end;
043: }
044:
045: public SVNStatusType mergeText(File baseFile, File localFile,
046: File latestFile, boolean dryRun, SVNDiffOptions options,
047: OutputStream result) throws SVNException {
048: FSMergerBySequence merger = new FSMergerBySequence(myStart,
049: mySeparator, myEnd);
050: int mergeResult = 0;
051: RandomAccessFile localIS = null;
052: RandomAccessFile latestIS = null;
053: RandomAccessFile baseIS = null;
054: try {
055: localIS = new RandomAccessFile(localFile, "r");
056: latestIS = new RandomAccessFile(latestFile, "r");
057: baseIS = new RandomAccessFile(baseFile, "r");
058:
059: QSequenceLineRAData baseData = new QSequenceLineRAFileData(
060: baseIS);
061: QSequenceLineRAData localData = new QSequenceLineRAFileData(
062: localIS);
063: QSequenceLineRAData latestData = new QSequenceLineRAFileData(
064: latestIS);
065: mergeResult = merger.merge(baseData, localData, latestData,
066: options, result);
067: } catch (IOException e) {
068: SVNErrorMessage err = SVNErrorMessage.create(
069: SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
070: SVNErrorManager.error(err, e);
071: } finally {
072: if (localIS != null) {
073: try {
074: localIS.close();
075: } catch (IOException e) {
076: //
077: }
078: }
079: if (baseIS != null) {
080: try {
081: baseIS.close();
082: } catch (IOException e) {
083: //
084: }
085: }
086: if (latestIS != null) {
087: try {
088: latestIS.close();
089: } catch (IOException e) {
090: //
091: }
092: }
093: }
094: SVNStatusType status = SVNStatusType.UNCHANGED;
095: if (mergeResult == FSMergerBySequence.CONFLICTED) {
096: status = SVNStatusType.CONFLICTED;
097: } else if (mergeResult == FSMergerBySequence.MERGED) {
098: status = SVNStatusType.MERGED;
099: }
100:
101: return status;
102: }
103:
104: public SVNStatusType mergeBinary(File baseFile, File localFile,
105: File latestFile, boolean dryRun, OutputStream out)
106: throws SVNException {
107: return SVNStatusType.CONFLICTED;
108: }
109:
110: }
|