Revision: 7428
http://winmerge.svn.sourceforge.net/winmerge/?rev=7428&view=rev
Author: gerundt
Date: 2010-11-16 14:27:33 +0000 (Tue, 16 Nov 2010)
Log Message:
-----------
PATCH: [ 2805717 ] Refactor Date/Size compare to own compare engine
Modified Paths:
--------------
branches/R2_14/Src/FolderCmp.cpp
branches/R2_14/Src/FolderCmp.h
branches/R2_14/Src/Merge.vcproj
branches/R2_14/Src/MergeX64.vcproj
Added Paths:
-----------
branches/R2_14/Src/CompareEngines/TimeSizeCompare.cpp
branches/R2_14/Src/CompareEngines/TimeSizeCompare.h
Added: branches/R2_14/Src/CompareEngines/TimeSizeCompare.cpp
===================================================================
--- branches/R2_14/Src/CompareEngines/TimeSizeCompare.cpp (rev 0)
+++ branches/R2_14/Src/CompareEngines/TimeSizeCompare.cpp 2010-11-16 14:27:33 UTC (rev 7428)
@@ -0,0 +1,87 @@
+/**
+ * @file TimeSizeCompare.cpp
+ *
+ * @brief Implementation file for TimeSizeCompare
+ */
+// ID line follows -- this is updated by SVN
+// $Id$
+
+#include "stdafx.h"
+#include "DiffItem.h"
+#include "TimeSizeCompare.h"
+#include "DiffWrapper.h"
+
+namespace CompareEngines
+{
+
+TimeSizeCompare::TimeSizeCompare()
+ : m_ignoreSmallDiff(false)
+{
+}
+
+TimeSizeCompare::~TimeSizeCompare()
+{
+}
+
+/**
+ * @brief Set compare-type specific options.
+ * @param [in] ignoreSmallDiff Ignore small time differences?
+ */
+void TimeSizeCompare::SetAdditionalOptions(bool ignoreSmallDiff)
+{
+ m_ignoreSmallDiff = ignoreSmallDiff;
+}
+
+/**
+ * @brief Compare two specified files, byte-by-byte
+ * @param [in] compMethod Compare method used.
+ * @param [in] di Diffitem info.
+ * @return DIFFCODE
+ */
+int TimeSizeCompare::CompareFiles(int compMethod, const DIFFITEM &di)
+{
+ UINT code = 0;
+
+ // Compare by modified date
+ // Check that we have both filetimes
+ if (di.left.mtime != 0 && di.right.mtime != 0)
+ {
+ INT64 nTimeDiff = di.left.mtime - di.right.mtime;
+ // Remove sign
+ nTimeDiff = (nTimeDiff > 0 ? nTimeDiff : -nTimeDiff);
+ if (m_ignoreSmallDiff)
+ {
+ // If option to ignore small timediffs (couple of seconds)
+ // is set, decrease absolute difference by allowed diff
+ nTimeDiff -= SmallTimeDiff;
+ }
+ if (nTimeDiff <= 0)
+ code = DIFFCODE::SAME;
+ else
+ code = DIFFCODE::DIFF;
+ }
+ else
+ {
+ // Filetimes for item(s) could not be read. So we have to
+ // set error status, unless we have DATE_SIZE -compare
+ // when we have still hope for size compare..
+ if (compMethod == CMP_DATE_SIZE)
+ code = DIFFCODE::SAME;
+ else
+ code = DIFFCODE::CMPERR;
+ }
+
+ // This is actual CMP_DATE_SIZE method..
+ // If file sizes differ mark them different
+ if (compMethod == CMP_DATE_SIZE)
+ {
+ if (di.left.size != di.right.size)
+ {
+ code &= ~DIFFCODE::SAME;
+ code = DIFFCODE::DIFF;
+ }
+ }
+ return code;
+}
+
+} // namespace CompareEngines
Property changes on: branches/R2_14/Src/CompareEngines/TimeSizeCompare.cpp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/R2_14/Src/CompareEngines/TimeSizeCompare.h
===================================================================
--- branches/R2_14/Src/CompareEngines/TimeSizeCompare.h (rev 0)
+++ branches/R2_14/Src/CompareEngines/TimeSizeCompare.h 2010-11-16 14:27:33 UTC (rev 7428)
@@ -0,0 +1,33 @@
+/**
+ * @file TimeSizeCompare.h
+ *
+ * @brief Declaration file for TimeSizeCompare compare engine.
+ */
+// ID line follows -- this is updated by SVN
+// $Id$
+
+#ifndef _TIMESIZE_COMPARE_H_
+#define _TIMESIZE_COMPARE_H_
+
+namespace CompareEngines
+{
+
+/**
+ * @brief A time/size compare class.
+ * This compare method compares files by their times and sizes.
+ */
+class TimeSizeCompare
+{
+public:
+ TimeSizeCompare();
+ ~TimeSizeCompare();
+ void SetAdditionalOptions(bool ignoreSmallDiff);
+ int CompareFiles(int compMethod, const DIFFITEM &di);
+
+private:
+ bool m_ignoreSmallDiff;
+};
+
+} // namespace CompareEngines
+
+#endif // _TIMESIZE_COMPARE_H_
Property changes on: branches/R2_14/Src/CompareEngines/TimeSizeCompare.h
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/R2_14/Src/FolderCmp.cpp
===================================================================
--- branches/R2_14/Src/FolderCmp.cpp 2010-11-16 13:31:14 UTC (rev 7427)
+++ branches/R2_14/Src/FolderCmp.cpp 2010-11-16 14:27:33 UTC (rev 7428)
@@ -21,8 +21,10 @@
#include "FolderCmp.h"
#include "ByteComparator.h"
#include "codepage_detect.h"
+#include "TimeSizeCompare.h"
using CompareEngines::ByteCompare;
+using CompareEngines::TimeSizeCompare;
static void GetComparePaths(CDiffContext * pCtxt, const DIFFITEM &di, String & left, String & right);
static bool Unpack(String & filepathTransformed,
@@ -31,6 +33,7 @@
FolderCmp::FolderCmp()
: m_pDiffUtilsEngine(NULL)
, m_pByteCompare(NULL)
+, m_pTimeSizeCompare(NULL)
, m_ndiffs(CDiffContext::DIFFS_UNKNOWN)
, m_ntrivialdiffs(CDiffContext::DIFFS_UNKNOWN)
{
@@ -40,6 +43,7 @@
{
delete m_pDiffUtilsEngine;
delete m_pByteCompare;
+ delete m_pTimeSizeCompare;
}
bool FolderCmp::RunPlugins(CDiffContext * pCtxt, PluginsContext * plugCtxt, CString &errStr)
@@ -276,57 +280,15 @@
di.left.m_textStats = m_diffFileData.m_textStats0;
di.right.m_textStats = m_diffFileData.m_textStats1;
}
- else if (pCtxt->m_nCompMethod == CMP_DATE ||
- pCtxt->m_nCompMethod == CMP_DATE_SIZE)
+ else if (nCompMethod == CMP_DATE || nCompMethod == CMP_DATE_SIZE || nCompMethod == CMP_SIZE)
{
- // Compare by modified date
- // Check that we have both filetimes
- if (di.left.mtime != 0 && di.right.mtime != 0)
- {
- __int64 nTimeDiff = di.left.mtime - di.right.mtime;
- // Remove sign
- nTimeDiff = (nTimeDiff > 0 ? nTimeDiff : -nTimeDiff);
- if (pCtxt->m_bIgnoreSmallTimeDiff)
- {
- // If option to ignore small timediffs (couple of seconds)
- // is set, decrease absolute difference by allowed diff
- nTimeDiff -= SmallTimeDiff;
- }
- if (nTimeDiff <= 0)
- code = DIFFCODE::SAME;
- else
- code = DIFFCODE::DIFF;
- }
- else
- {
- // Filetimes for item(s) could not be read. So we have to
- // set error status, unless we have DATE_SIZE -compare
- // when we have still hope for size compare..
- if (pCtxt->m_nCompMethod == CMP_DATE_SIZE)
- code = DIFFCODE::SAME;
- else
- code = DIFFCODE::CMPERR;
- }
-
- // This is actual CMP_DATE_SIZE method..
- // If file sizes differ mark them different
- if (pCtxt->m_nCompMethod == CMP_DATE_SIZE)
- {
- if (di.left.size != di.right.size)
- {
- code &= ~DIFFCODE::SAME;
- code = DIFFCODE::DIFF;
- }
- }
+ if (m_pTimeSizeCompare == NULL)
+ m_pTimeSizeCompare = new TimeSizeCompare();
+
+ m_pTimeSizeCompare->SetAdditionalOptions(!!pCtxt->m_bIgnoreSmallTimeDiff);
+ code = m_pTimeSizeCompare->CompareFiles(nCompMethod, di);
+
}
- else if (pCtxt->m_nCompMethod == CMP_SIZE)
- {
- // Compare by size
- if (di.left.size == di.right.size)
- code = DIFFCODE::SAME;
- else
- code = DIFFCODE::DIFF;
- }
else
{
// Print error since we should have handled by date compare earlier
Modified: branches/R2_14/Src/FolderCmp.h
===================================================================
--- branches/R2_14/Src/FolderCmp.h 2010-11-16 13:31:14 UTC (rev 7427)
+++ branches/R2_14/Src/FolderCmp.h 2010-11-16 14:27:33 UTC (rev 7428)
@@ -12,6 +12,7 @@
#include "DiffFileData.h"
#include "DiffUtils.h"
#include "ByteCompare.h"
+#include "TimeSizeCompare.h"
class CDiffContext;
class PackingInfo;
@@ -56,6 +57,7 @@
private:
CompareEngines::DiffUtils *m_pDiffUtilsEngine;
CompareEngines::ByteCompare *m_pByteCompare;
+ CompareEngines::TimeSizeCompare *m_pTimeSizeCompare;
};
Modified: branches/R2_14/Src/Merge.vcproj
===================================================================
--- branches/R2_14/Src/Merge.vcproj 2010-11-16 13:31:14 UTC (rev 7427)
+++ branches/R2_14/Src/Merge.vcproj 2010-11-16 14:27:33 UTC (rev 7428)
@@ -6760,6 +6760,35 @@
RelativePath="CompareEngines\DiffUtils.h"
>
</File>
+ <File
+ RelativePath="CompareEngines\TimeSizeCompare.cpp"
+ >
+ <FileConfiguration
+ Name="UnicodeRelease|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="UnicodeDebug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ BrowseInformation="1"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="CompareEngines\TimeSizeCompare.h"
+ >
+ </File>
</Filter>
<Filter
Name="Batch files"
Modified: branches/R2_14/Src/MergeX64.vcproj
===================================================================
--- branches/R2_14/Src/MergeX64.vcproj 2010-11-16 13:31:14 UTC (rev 7427)
+++ branches/R2_14/Src/MergeX64.vcproj 2010-11-16 14:27:33 UTC (rev 7428)
@@ -11386,6 +11386,14 @@
RelativePath="CompareEngines\DiffUtils.h"
>
</File>
+ <File
+ RelativePath=".\CompareEngines\TimeSizeCompare.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CompareEngines\TimeSizeCompare.h"
+ >
+ </File>
</Filter>
</Files>
<Globals>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|