blob: ecdad744429617295a8359b4e2b289d966289c71 [file] [log] [blame]
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.googlesource.gerrit.plugins.serverconfig;
import org.eclipse.jgit.diff.DiffAlgorithm;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.MyersDiff;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class UnifiedDiffer {
static final String CHARSET_NAME = "UTF-8";
public String diff(RawText v0, RawText v1) throws IOException {
DiffAlgorithm algorithm = MyersDiff.INSTANCE;
EditList editList = algorithm.diff(RawTextComparator.DEFAULT, v0, v1);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (DiffFormatter formatter = new DiffFormatter(os)) {
formatter.format(editList, v0, v1);
}
return os.toString(CHARSET_NAME);
}
}