using System;
using System.Text;
using p4dn;
using System.IO;
namespace P4API
{
///
/// Actions to take when resolving a file.
///
///
///
public enum MergeAction
{
///
/// Quit the resolve workflow.
///
Quit, // CMS_QUIT user wants to quit
///
/// Skip this file in the resolve workflow.
///
Skip, // CMS_SKIP skip the integration record
///
/// Accept the merged file from Perforce. This file must not be edited.
///
AcceptMerged, // CMS_MERGED accepted merged theirs and yours
///
/// Accept the result file with your edits. The result file should be edited before returning this merge action.
///
AcceptEdit, // CMS_EDIT accepted edited merge
///
/// Accept 'their' file ('your' changes will be lost).
///
AcceptTheirs, // CMS_THEIRS accepted theirs
///
/// Accept 'your' file ('thier' changes will be lost).
///
AcceptYours // CMS_YOUR accepted yours
}
///
/// Contains information about the files being merged.
///
public class MergeData : IDisposable
{
private P4MergeData _mergeData;
internal MergeData(P4MergeData mergeData)
{
_mergeData = mergeData;
}
///
/// Base file for the 3-way merge.
///
public FileInfo BaseFile
{
get
{
return _mergeData.GetBasePath();
}
}
///
/// Your file for the 3-way merge.
///
public FileInfo YourFile
{
get
{
return _mergeData.GetYourPath();
}
}
///
/// Perforce's recommended merge action.
///
public MergeAction MergeHint
{
get
{
switch (_mergeData.GetMergeHint())
{
case P4MergeStatus.CMS_QUIT:
return MergeAction.Quit;
case P4MergeStatus.CMS_SKIP:
return MergeAction.Skip;
case P4MergeStatus.CMS_EDIT:
return MergeAction.AcceptEdit;
case P4MergeStatus.CMS_MERGED:
return MergeAction.AcceptMerged;
case P4MergeStatus.CMS_YOURS:
return MergeAction.AcceptYours;
case P4MergeStatus.CMS_THEIRS:
return MergeAction.AcceptTheirs;
}
return MergeAction.Quit;
}
}
///
/// Thier file for the 3-way merge.
///
public FileInfo TheirFile
{
get
{
return _mergeData.GetTheirPath();
}
}
///
/// File where merged result should be written.
///
public FileInfo ResultFile
{
get
{
return _mergeData.GetResultPath();
}
}
///
/// Perforce name of the base file. Format is '//depot/path/file.ext#rev'.
///
public string BaseName
{
get
{
return _mergeData.GetBaseName();
}
}
///
/// Perforce name of your file. Format is '//client/path/file.ext'.
///
public string YourName
{
get
{
return _mergeData.GetYourName();
}
}
///
/// Perforce name of their file. Format is '//depot/path/file.ext#rev'.
///
public string TheirName
{
get
{
return _mergeData.GetTheirName();
}
}
///
/// Returns the number of chunks changed in your file.
///
public int YourChunks
{
get
{
return _mergeData.GetYourChunks();
}
}
///
/// Returns the MD5 checksum of WHAT?? file.
///
public string MergeDigest
{
get
{
return _mergeData.GetMergeDigest();
}
}
///
/// Returns the MD5 checksum of your file.
///
public string YourDigest
{
get
{
return _mergeData.GetYourDigest();
}
}
///
/// Returns the MD5 checksum of their file.
///
public string TheirDigest
{
get
{
return _mergeData.GetTheirDigest();
}
}
///
/// Returns the number of chunks with changes in their file.
///
public int TheirChunks
{
get
{
return _mergeData.GetTheirChunks();
}
}
///
/// Returns the number of chunks that have the same change in both files.
///
public int BothChunks
{
get
{
return _mergeData.GetBothChunks();
}
}
///
/// Returns the number of chunks that have conflicts.
///
public int ConflictChunks
{
get
{
return _mergeData.GetConflictChunks();
}
}
///
/// Runs the external merge tool configured by P4MERGE.
///
/// True if the merge tool exits with code 0, false otherwise.
public bool RunMergeTool()
{
return _mergeData.RunMergeTool();
}
#region IDisposable Members
///
/// Frees unmanaged memory.
///
public void Dispose()
{
_mergeData.Dispose();
}
#endregion
}
}