in plugin/src/com/microsoft/alm/plugin/idea/tfvc/core/tfs/conflicts/ResolveConflictHelper.java [375:455]
protected void populateThreeWayDiff(final Conflict conflict, final File conflictPath, final FilePath localPath,
final ServerContext context, final ContentTriplet contentTriplet) throws VcsException {
// virtual file can be out of the current project so force its discovery
TfsFileUtil.refreshAndFindFile(localPath);
// update progress
IdeaHelper.setProgress(ProgressManager.getInstance().getProgressIndicator(), 0.1, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_MERGE_ORIGINAL));
try {
// only get diff contents if it is an edited file
if (conflictPath.isFile()) {
final String original;
final String serverChanges;
final String myLocalChanges;
String conflictLocalPath = conflict.getLocalPath();
List<PendingChange> pendingChange = TfvcClient.getInstance()
.getStatusForFiles(project, context, Collections.singletonList(conflictLocalPath));
if (pendingChange.size() > 1) {
logger.warn(
"Count of local changes for file \"{}\" is greater than 1: {}",
conflictLocalPath,
pendingChange.size());
}
PendingChange originalChange = pendingChange.size() > 0 ? pendingChange.get(0) : null;
if (isMergeConflict(conflict, null)) {
final String workingFolder = localPath.isDirectory() ?
localPath.getPath() :
localPath.getParentPath().getPath();
final MergeConflict mergeConflict = (MergeConflict) conflict;
final String sourcePath = mergeConflict.getMapping().getFromServerItem();
final String targetPath = mergeConflict.getMapping().getToServerItem();
final VersionSpec baseVersion = CommandUtils.getBaseVersion(context, workingFolder, sourcePath, targetPath);
original = TFSContentRevision.createRenameRevision(project, localPath,
SystemHelper.toInt(baseVersion.getValue(), 1), originalChange.getDate(), sourcePath).getContent();
serverChanges = TFSContentRevision.createRenameRevision(project, localPath,
getMergeFromVersion(mergeConflict), originalChange.getDate(), sourcePath).getContent();
myLocalChanges = CurrentContentRevision.create(localPath).getContent();
} else {
// get original contents of file
if (originalChange != null) {
final int version = Integer.parseInt(originalChange.getVersion());
if (isNameConflict(conflict)) {
final FilePath renamePath = VersionControlPath.getFilePath(conflictLocalPath, conflictPath.isDirectory());
original = TFSContentRevision.createRenameRevision(project, renamePath,
version, originalChange.getDate(), ((RenameConflict) conflict).getOldPath()).getContent();
} else {
original = TFSContentRevision.create(project, localPath,
version, originalChange.getDate()).getContent();
}
} else {
original = null;
}
// update progress
IdeaHelper.setProgress(ProgressManager.getInstance().getProgressIndicator(), 0.5, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_MERGE_SERVER));
// get content from local file
myLocalChanges = CurrentContentRevision.create(localPath).getContent();
// get content from server
if (isNameConflict(conflict)) {
final ChangeSet serverChange = CommandUtils.getLastHistoryEntryForAnyUser(context, ((RenameConflict) conflict).getServerPath());
final FilePath renamePath = VersionControlPath.getFilePath(conflictLocalPath, conflictPath.isDirectory());
serverChanges = TFSContentRevision.createRenameRevision(project, renamePath, serverChange.getIdAsInt(), serverChange.getDate(), ((RenameConflict) conflict).getServerPath()).getContent();
} else {
final ChangeSet serverChange = CommandUtils.getLastHistoryEntryForAnyUser(context, conflictLocalPath);
serverChanges = TFSContentRevision.create(project, localPath, serverChange.getIdAsInt(), serverChange.getDate()).getContent();
}
}
contentTriplet.baseContent = original != null ? original : StringUtils.EMPTY;
contentTriplet.localContent = myLocalChanges != null ? myLocalChanges : StringUtils.EMPTY;
contentTriplet.serverContent = serverChanges != null ? serverChanges : StringUtils.EMPTY;
}
} catch (Exception e) {
logger.error("Error loading contents for files");
throw new VcsException(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_LOAD_FAILED, localPath.getPresentableUrl(), e.getMessage()));
}
}