};
/**
- * @brief Default constructor
+ * @brief Default constructor.
+ * Initializes members and creates new FilterCommentsManager.
*/
-CDiffWrapper::CDiffWrapper():m_FilterCommentsManager(new FilterCommentsManager)
+CDiffWrapper::CDiffWrapper()
+: m_FilterCommentsManager(new FilterCommentsManager)
+, m_bCreatePatchFile(FALSE)
+, m_bUseDiffList(FALSE)
+, m_bDetectMovedBlocks(FALSE)
+, m_bAddCmdLine(TRUE)
+, m_bAppendFiles(FALSE)
+, m_nDiffs(0)
+, m_infoPrediffer(NULL)
+, m_pDiffList(NULL)
+, m_bPathsAreTemp(FALSE)
{
ZeroMemory(&m_settings, sizeof(DIFFSETTINGS));
ZeroMemory(&m_globalSettings, sizeof(DIFFSETTINGS));
ZeroMemory(&m_status, sizeof(DIFFSTATUS));
- m_bCreatePatchFile = FALSE;
- m_bUseDiffList = FALSE;
- m_bDetectMovedBlocks = FALSE;
- m_bAddCmdLine = TRUE;
- m_bAppendFiles = FALSE;
- m_nDiffs = 0;
- m_infoPrediffer = NULL;
- m_pDiffList = NULL;
-
m_settings.heuristic = 1;
m_settings.outputStyle = OUTPUT_NORMAL;
m_settings.context = -1;
}
/**
- * @brief Sets filename of produced patch-file.
- * @param [in] file Filename of patch file.
+ * @brief Enables/disables patch-file creation and sets filename.
+ * This function enables or disables patch file creation. When
+ * @p filename is empty, patch files are disabled.
+ * @param [in] filename Filename for patch file, or empty string.
*/
-void CDiffWrapper::SetPatchFile(const CString &file)
+void CDiffWrapper::SetCreatePatchFile(const CString &filename)
{
- m_sPatchFile = file;
- m_sPatchFile.Replace('/', '\\');
+ if (filename.IsEmpty())
+ {
+ m_bCreatePatchFile = FALSE;
+ m_sPatchFile.Empty();
+ }
+ else
+ {
+ m_bCreatePatchFile = TRUE;
+ m_sPatchFile = filename;
+ m_sPatchFile.Replace('/', '\\');
+ }
}
/**
- * @brief Sets pointer to DiffList getting compare results.
- * CDiffWrapper adds compare results to DiffList. This function
- * sets external DiffList which gets compare results.
+ * @brief Enables/disabled DiffList creation ands sets DiffList.
+ * This function enables or disables DiffList creation. When
+ * @p diffList is NULL difflist is not created. When valid DiffList
+ * pointer is given, compare results are stored into it.
* @param [in] difflist Pointer to DiffList getting compare results.
*/
-void CDiffWrapper::SetDiffList(DiffList *diffList)
+void CDiffWrapper::SetCreateDiffList(DiffList *diffList)
{
- ASSERT(diffList);
- m_pDiffList = diffList;
+ if (diffList == NULL)
+ {
+ m_bUseDiffList = FALSE;
+ m_pDiffList = NULL;
+ }
+ else
+ {
+ m_bUseDiffList = TRUE;
+ m_pDiffList = diffList;
+ }
}
/**
}
/**
- * @brief Determines if external results-list is used.
- * When diff'ing files results are stored to external DiffList,
- * set by SetDiffList(). This function determines if we are currently
- * using that external list.
- * @return TRUE if results are added to external DiffList.
- */
-BOOL CDiffWrapper::GetUseDiffList() const
-{
- return m_bUseDiffList;
-}
-
-/**
- * @brief Enables/disables external result-list.
- * CDiffWrapper uses external DiffList to return compare results.
- * This function enables/disables usage of that external DiffList.
- * @param [in] bUseDifList TRUE if external DiffList is used.
- * @return Old value of the setting.
- */
-BOOL CDiffWrapper::SetUseDiffList(BOOL bUseDiffList)
-{
- BOOL temp = m_bUseDiffList;
- m_bUseDiffList = bUseDiffList;
- return temp;
-}
-
-/**
- * @brief Determines if patch-file is created.
- * @return TRUE if patch file will be created.
- */
-BOOL CDiffWrapper::GetCreatePatchFile() const
-{
- return m_bCreatePatchFile;
-}
-
-/**
- * @brief Enables/disables creation of patch-file.
- * @param [in] bCreatePatchFile If TRUE patch file will be created.
- * @return Previous value for setting.
- */
-BOOL CDiffWrapper::SetCreatePatchFile(BOOL bCreatePatchFile)
-{
- BOOL temp = m_bCreatePatchFile;
- m_bCreatePatchFile = bCreatePatchFile;
- return temp;
-}
-
-/**
* @brief Test for trivial only characters in string
* @param [in] Start - Start position in string
* @param [in] End - One character pass the end position of the string
/**
* @brief Set source paths for diffing two files.
- * Sets full paths to two files we are diffing.
+ * Sets full paths to two files we are diffing. Paths can be actual user files
+ * or temporary copies of user files. Parameter @p tempPaths tells if paths
+ * are temporary paths that can be deleted.
* @param [in] filepath1 First file to compare "original file".
* @param [in] filepath2 Second file to compare "changed file".
+ * @param [in] tempPaths Are given paths temporary (can be deleted)?.
*/
-void CDiffWrapper::SetPaths(const CString &filepath1, const CString &filepath2)
+void CDiffWrapper::SetPaths(const CString &filepath1, const CString &filepath2,
+ BOOL tempPaths)
{
m_s1File = filepath1;
m_s2File = filepath2;
+ m_bPathsAreTemp = tempPaths;
}
/**
/**
* @brief Runs diff-engine.
*/
-BOOL CDiffWrapper::RunFileDiff(ARETEMPFILES areTempFiles)
+BOOL CDiffWrapper::RunFileDiff()
{
CString filepath1(m_s1File);
CString filepath2(m_s2File);
if (m_bUseDiffList)
m_nDiffs = m_pDiffList->GetSize();
- // Are our working files overwritable (temp)?
- BOOL bMayOverwrite = (areTempFiles == YESTEMPFILES);
-
// Do the preprocessing now, overwrite the temp files
// NOTE: FileTransform_UCS2ToUTF8() may create new temp
// files and return new names, those created temp files
// are deleted in end of function.
if (m_infoPrediffer->bToBeScanned)
{
- // this can only fail if the data can not be saved back (no more place on disk ???)
- // what to do then ??
- FileTransform_Prediffing(strFile1Temp, m_sToFindPrediffer, m_infoPrediffer, bMayOverwrite);
+ // this can only fail if the data can not be saved back (no more
+ // place on disk ???) What to do then ??
+ FileTransform_Prediffing(strFile1Temp, m_sToFindPrediffer, m_infoPrediffer,
+ m_bPathsAreTemp);
}
else
{
- // this can failed if the prediffer has a problem
- if (FileTransform_Prediffing(strFile1Temp, *m_infoPrediffer, bMayOverwrite) == FALSE)
+ // This can fail if the prediffer has a problem
+ if (FileTransform_Prediffing(strFile1Temp, *m_infoPrediffer,
+ m_bPathsAreTemp) == FALSE)
{
// display a message box
CString sError;
- AfxFormatString2(sError, IDS_PREDIFFER_ERROR, strFile1Temp, m_infoPrediffer->pluginName);
+ AfxFormatString2(sError, IDS_PREDIFFER_ERROR, strFile1Temp,
+ m_infoPrediffer->pluginName);
AfxMessageBox(sError, MB_OK | MB_ICONSTOP);
// don't use any more this prediffer
m_infoPrediffer->bToBeScanned = FALSE;
- m_infoPrediffer->pluginName = _T("");
+ m_infoPrediffer->pluginName.Empty();
}
}
- FileTransform_UCS2ToUTF8(strFile1Temp, bMayOverwrite);
- // we use the same plugin for both files, so it must be defined before second file
+ FileTransform_UCS2ToUTF8(strFile1Temp, m_bPathsAreTemp);
+ // We use the same plugin for both files, so it must be defined before
+ // second file
ASSERT(m_infoPrediffer->bToBeScanned == FALSE);
- if (FileTransform_Prediffing(strFile2Temp, *m_infoPrediffer, bMayOverwrite) == FALSE)
+ if (FileTransform_Prediffing(strFile2Temp, *m_infoPrediffer,
+ m_bPathsAreTemp) == FALSE)
{
// display a message box
CString sError;
- AfxFormatString2(sError, IDS_PREDIFFER_ERROR, strFile2Temp, m_infoPrediffer->pluginName);
+ AfxFormatString2(sError, IDS_PREDIFFER_ERROR, strFile2Temp,
+ m_infoPrediffer->pluginName);
AfxMessageBox(sError, MB_OK | MB_ICONSTOP);
// don't use any more this prediffer
m_infoPrediffer->bToBeScanned = FALSE;
m_infoPrediffer->pluginName = _T("");
}
- FileTransform_UCS2ToUTF8(strFile2Temp, bMayOverwrite);
+ FileTransform_UCS2ToUTF8(strFile2Temp, m_bPathsAreTemp);
DiffFileData diffdata;
diffdata.SetDisplayFilepaths(filepath1, filepath2); // store true names for diff utils patch file
FreeDiffUtilsScript(script);
-
// Done with diffutils filedata
diffdata.Close();
* delimiters from \ to / since we want to keep compatibility with patch-tools.
* @param [in] script list of changes.
* @param [in] inf file_data table containing filenames
- * @todo filepath1 and filepath2 aren't really needed, paths are already in inf.
*/
void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf)
{
/**
* @file DiffWrapper.h
*
- * @brief Declaration file for CDiffWrapper
+ * @brief Declaration file for CDiffWrapper.
*
* @date Created: 2003-08-22
*/
DIFF_OUTPUT_SDIFF
};
-typedef enum {
- YESTEMPFILES // arguments are temp files
- , NOTEMPFILES // arguments not temp files
-} ARETEMPFILES;
-
/**
* @brief Diffutils options users of this class must use
*/
class FilterCommentsManager;
/**
- * @brief Wrapper class for GNU/diffutils
+ * @brief Wrapper class for diffengine (diffutils and ByteComparator).
+ * Diffwappre class is used to run selected diffengine. For folder compare
+ * there are several methods (COMPARE_TYPE), but for file compare diffutils
+ * is used always. For file compare diffutils can output results to external
+ * DiffList or to patch file. Output type must be selected with member
+ * functions SetCreatePatchFile() and SetCreateDiffList().
*/
class CDiffWrapper
{
public:
CDiffWrapper();
~CDiffWrapper();
- void SetPatchFile(const CString &file);
+ void SetCreatePatchFile(const CString &filename);
+ void SetCreateDiffList(DiffList *diffList);
void SetDiffList(DiffList *diffList);
void GetOptions(DIFFOPTIONS *options) const;
void SetOptions(const DIFFOPTIONS *options);
void GetPrediffer(PrediffingInfo * prediffer);
void GetPatchOptions(PATCHOPTIONS *options) const;
void SetPatchOptions(const PATCHOPTIONS *options);
- BOOL GetUseDiffList() const;
- BOOL SetUseDiffList(BOOL bUseDiffList);
void SetDetectMovedBlocks(BOOL bDetectMovedBlocks) { m_bDetectMovedBlocks = bDetectMovedBlocks; }
BOOL GetDetectMovedBlocks() { return m_bDetectMovedBlocks; }
BOOL GetAppendFiles() const;
BOOL SetAppendFiles(BOOL bAppendFiles);
- BOOL GetCreatePatchFile() const;
- BOOL SetCreatePatchFile(BOOL bCreatePatchFile);
- void SetPaths(const CString &filepath1, const CString &filepath2);
+ void SetPaths(const CString &filepath1, const CString &filepath2, BOOL tempPaths);
void SetAlternativePaths(const CString &altPath1, const CString &altPath2);
- BOOL RunFileDiff(ARETEMPFILES areTempFiles);
+ BOOL RunFileDiff();
void GetDiffStatus(DIFFSTATUS *status);
void AddDiffRange(UINT begin0, UINT end0, UINT begin1, UINT end1, BYTE op);
void FixLastDiffRange(int leftBufferLines, int rightBufferLines, BOOL left);
void WritePatchFile(struct change * script, file_data * inf);
private:
- DIFFSETTINGS m_settings;
- DIFFSETTINGS m_globalSettings; // Temp for storing globals
- DIFFSTATUS m_status;
+ DIFFSETTINGS m_settings; /**< Compare settings for current compare */
+ DIFFSETTINGS m_globalSettings; /**< Global compare settings */
+ DIFFSTATUS m_status; /**< Status of last compare */
CString m_s1File; /**< Full path to first diff'ed file. */
CString m_s2File; /**< Full path to second diff'ed file. */
CString m_s1AlternativePath; /**< First file's alternative path (may be relative). */
CString m_sOriginalFile1; /**< First file's original (NON-TEMP) path. */
CString m_sOriginalFile2; /**< Second file's original (NON-TEMP) path. */
CString m_sPatchFile; /**< Full path to created patch file. */
+ BOOL m_bPathsAreTemp; /**< Are compared paths temporary? */
/// prediffer info are stored only for MergeDoc
PrediffingInfo * m_infoPrediffer;
/// prediffer info are stored only for MergeDoc
BOOL m_bCreatePatchFile; /**< Do we create a patch file? */
BOOL m_bAddCmdLine; /**< Do we add commandline to patch file? */
BOOL m_bAppendFiles; /**< Do we append to existing patch file? */
- int m_nDiffs;
- DiffList *m_pDiffList;
- CMap<int, int, int, int> m_moved0;
- CMap<int, int, int, int> m_moved1;
- FilterCommentsManager * m_FilterCommentsManager;
+ int m_nDiffs; /**< Difference count */
+ DiffList *m_pDiffList; /**< Pointer to external DiffList */
+ CMap<int, int, int, int> m_moved0; /**< Moved lines map for first side */
+ CMap<int, int, int, int> m_moved1; /**< Moved lines map for second side */
+ FilterCommentsManager * m_FilterCommentsManager; /**< Comments filtering manager */
};
// forward declarations needed by DiffFileData