OSDN Git Service

PATCH: [ 1182416 ] Fix Compare by date hang
authorKimmo Varis <kimmov@gmail.com>
Thu, 14 Apr 2005 20:00:34 +0000 (20:00 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 14 Apr 2005 20:00:34 +0000 (20:00 +0000)
Src/DiffContext.cpp
Src/DiffContext.h
Src/DiffWrapper.cpp
Src/DiffWrapper.h
Src/DirScan.cpp
Src/readme.txt

index 5c6a2b4..ea4446b 100644 (file)
@@ -62,6 +62,7 @@ CDiffContext::CDiffContext(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*/
 , m_piPluginInfos(NULL)
 , m_msgUpdateStatus(0)
 , m_hDirFrame(NULL)
+, m_nCompMethod(-1)
 {
        m_strLeft = pszLeft;
        m_strRight = pszRight;
@@ -97,6 +98,7 @@ CDiffContext::CDiffContext(LPCTSTR pszLeft, LPCTSTR pszRight, CDiffContext& src)
        m_piFilterGlobal = src.m_piFilterGlobal;
        m_msgUpdateStatus = src.m_msgUpdateStatus;
        m_hDirFrame = src.m_hDirFrame;
+       m_nCompMethod = src.m_nCompMethod;
 
        m_strNormalizedLeft = pszLeft;
        paths_normalize(m_strNormalizedLeft);
index f2fd611..afd1321 100644 (file)
@@ -76,6 +76,9 @@ class CDiffContext;
  * One dimension is existence: both sides, left only, or right only
  *
  * One dimension is type: directory, or file
+ *
+ * @note times in fileinfo's are seconds since January 1, 1970.
+ * See Dirscan.cpp/fentry and Dirscan.cpp/LoadFiles()
  */
 
 struct DIFFITEM : DIFFCODE
@@ -109,8 +112,13 @@ public:
                                       PrediffingInfo ** infoPrediffer) = 0;
 };
 
-
-class CDiffContext  
+/**
+ * @brief Directory compare context.
+ *
+ * @note If you add new member variables, remember to copy values in
+ * CDiffContext::CDiffContext(..,CDiffContext) constructor!
+ */
+class CDiffContext
 {
 public:
        CDiffContext(LPCTSTR pszLeft, LPCTSTR pszRight);
index 95fef81..b9d8794 100644 (file)
@@ -1507,16 +1507,22 @@ DiffFileData::prepAndCompareTwoFiles(CDiffContext * pCtxt, const CString & filep
        }
 
 
-       if (pCtxt->m_nCompMethod == 0)
+       if (pCtxt->m_nCompMethod == CMP_CONTENT)
        {
                // use diffutils
                code = diffutils_compare_files(0);
        }
-       else
+       else if (pCtxt->m_nCompMethod == CMP_QUICK_CONTENT)
        {
                // use our own byte-by-byte compare
                code = byte_compare_files();
        }
+       else
+       {
+               // Print error since we should have handled by date compare earlier
+               _RPTF0(_CRT_ERROR, "Invalid compare type, DiffFileData can't handle it");
+               goto exitPrepAndCompare;
+       }
 
        if ((code & DIFFCODE::CMPERR) == 0)
        {
index b7fa55e..216d223 100644 (file)
@@ -39,6 +39,7 @@ struct DiffFileData;
 enum
 {
        CMP_CONTENT = 0, /**< Normal by content compare */
+       CMP_QUICK_CONTENT, /**< Custom content compare */
        CMP_DATE, /**< Compare by modified date */
 };
 
index eb45e71..3c6aa67 100644 (file)
@@ -27,15 +27,16 @@ static char THIS_FILE[] = __FILE__;
 // Static types (ie, types only used locally)
 /**
  * @brief directory or file info for one row in diff result
+ * @note times are seconds since January 1, 1970.
  */
 struct fentry
 {
        CString name;
        // storing __time_t if MSVC6 (__MSC_VER<1300)
        // storing __time64_t if MSVC7 (VC.NET)
-       __int64 mtime;
-       __int64 ctime;
-       _int64 size;
+       __int64 mtime; /**< Last modify time */
+       __int64 ctime; /**< Creation modify time */
+       __int64 size;
        int attrs;
 };
 typedef CArray<fentry, fentry&> fentryArray;
@@ -183,7 +184,7 @@ int DirScan(const CString & subdir, CDiffContext * pCtxt, bool casesensitive,
                                nDiffCode |= DIFFCODE::SKIPPED;
                                StoreDiffResult(subdir, &leftFiles[i], 0, nDiffCode, pCtxt);
                        }
-                       else if (pCtxt->m_nCompMethod != 1)
+                       else if (pCtxt->m_nCompMethod != CMP_DATE)
                        {
                                // Compare file to itself to detect encoding
                                CString filepath = sLeftDir + backslash + leftFiles[i].name;
@@ -211,7 +212,7 @@ int DirScan(const CString & subdir, CDiffContext * pCtxt, bool casesensitive,
                                nDiffCode |= DIFFCODE::SKIPPED;
                                StoreDiffResult(subdir, 0, &rightFiles[j], nDiffCode, pCtxt);
                        }
-                       else if (pCtxt->m_nCompMethod != 1)
+                       else if (pCtxt->m_nCompMethod != CMP_DATE)
                        {
                                // Compare file to itself to detect encoding
                                CString filepath = sRightDir + backslash + rightFiles[j].name;
@@ -251,7 +252,7 @@ int DirScan(const CString & subdir, CDiffContext * pCtxt, bool casesensitive,
                        gLog.Write(_T("Comparing: n0=%s, n1=%s, d0=%s, d1=%s"), 
                          leftname, rightname, (LPCTSTR)sLeftDir, (LPCTSTR)sRightDir);
 
-                       if (pCtxt->m_nCompMethod == 1)
+                       if (pCtxt->m_nCompMethod == CMP_DATE)
                        {
                                        // Compare only by modified date
                                if (leftFiles[i].mtime == rightFiles[j].mtime)
@@ -310,6 +311,7 @@ void LoadFiles(const CString & sDir, fentryArray * dirs, fentryArray * files)
                        if (dwIsDirectory && StrStr(_T(".."), ff.cFileName))
                                continue;
                        fentry ent;
+                       // Save filetimes as seconds since January 1, 1970
                        ent.ctime = CTime(ff.ftCreationTime).GetTime();
                        ent.mtime = CTime(ff.ftLastWriteTime).GetTime();
                        if (!dwIsDirectory)
index 9ab9612..64a4fb8 100644 (file)
@@ -1,3 +1,7 @@
+2005-04-14 Kimmo
+ PATCH: [ 1182416 ] Fix Compare by date hang
+  Src: DiffContext.cpp DiffContext.h DiffWrapper.cpp DiffWrapper.h DirScan.cpp 
+
 2005-04-13 Perry
  BUG: [ 1181906 ] Comment in LoadFromDirectory maybe wrong?
   (cosmetic)