[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] TortoiseMerge: report if files are identical and optionally exit

From: Flavio Stanchina <flavio_at_stanchina.net>
Date: 2007-03-21 13:16:05 CET

Hello list,
this is my first message to the list and first patch to TortoiseSVN, so
forgive me if I'm doing something wrong.

We've migrated to Subversion+TortoiseSVN from Visual SourceSafe; one of
my boss' complaints was that the VSS "diff" command would report if the
files are identical and just exit, so I implemented it in TortoiseMerge.
The message box is not optional because I didn't feel like touching the
options dialog box and related stuff, but I think there should be a
check box for this. The "exit if identical" behavior is controlled by
the /x command-line switch that I copied from WinMerge; I don't think a
GUI option is needed for that, as it's something that is mostly useful
when invoked from other programs.

I also added a DiffData::GetChanges() method that returns the number of
changes. I'm not sure if this is the way to do it, but I couldn't find a
quick way to tell if there are differences or not and I thought that
this might be useful.

If you like the idea but have issues with the actual implementation,
feel free to make comments. I'm willing to fix things and revise the
implementation to get it accepted.

-- 
Ciao, Flavio

Index: src/TortoiseMerge/DiffData.h
===================================================================
--- src/TortoiseMerge/DiffData.h (revisione 8951)
+++ src/TortoiseMerge/DiffData.h (copia locale)
@@ -95,6 +95,7 @@
 
         BOOL Load();
         void SetBlame(bool bBlame = true) {m_bBlame = bBlame;}
+ long GetChanges() { return m_nChanges; }
         void LoadRegistry();
         int GetLineCount();
         int GetLineActualLength(int index);
@@ -163,4 +164,5 @@
         CRegDWORD m_regForegroundColors[DIFFSTATE_END];
         CRegDWORD m_regBackgroundColors[DIFFSTATE_END];
         bool m_bBlame;
+ long m_nChanges;
 };
Index: src/TortoiseMerge/TortoiseMerge.cpp
===================================================================
--- src/TortoiseMerge/TortoiseMerge.cpp (revisione 8951)
+++ src/TortoiseMerge/TortoiseMerge.cpp (copia locale)
@@ -198,6 +198,8 @@
         pFrame->m_Data.m_sDiffFile.Replace('/', '\\');
         if (parser.HasKey(_T("oneway")))
         pFrame->m_bOneWay = TRUE;
+ if (parser.HasKey(_T("x")))
+ pFrame->m_bQuitIfUnchanged = TRUE;
         if (parser.HasKey(_T("reversedpatch")))
                 pFrame->m_bReversedPatch = TRUE;
         if (pFrame->m_Data.IsBaseFileInUse() && !pFrame->m_Data.IsYourFileInUse() && pFrame->m_Data.IsTheirFileInUse())
Index: src/TortoiseMerge/resource.h
===================================================================
--- src/TortoiseMerge/resource.h (revisione 8951)
+++ src/TortoiseMerge/resource.h (copia locale)
@@ -165,6 +165,7 @@
 #define IDS_WARNMODIFIEDLOOSECHANGESOPTIONS 5007
 #define IDS_WARNBETTERPATCHPATHFOUND 5008
 #define IDS_NOTFOUNDVIEWTITLEINDICATOR 5009
+#define IDS_WARNIDENTICALFILES 5010
 #define IDS_PATCH_ALL 6000
 #define IDS_PATCH_TITLE 6001
 #define IDS_DIFF_TITLE 6002
Index: src/TortoiseMerge/MainFrm.h
===================================================================
--- src/TortoiseMerge/MainFrm.h (revisione 8951)
+++ src/TortoiseMerge/MainFrm.h (copia locale)
@@ -122,6 +122,7 @@
         CRightView * m_pwndRightView;
         CBottomView * m_pwndBottomView;
         BOOL m_bOneWay;
+ BOOL m_bQuitIfUnchanged;
         BOOL m_bReversedPatch;
         CDiffData m_Data;
         bool m_bReadOnly;
Index: src/TortoiseMerge/DiffData.cpp
===================================================================
--- src/TortoiseMerge/DiffData.cpp (revisione 8951)
+++ src/TortoiseMerge/DiffData.cpp (copia locale)
@@ -40,6 +40,7 @@
         g_SVNAdminDir.Init();
 
         m_bBlame = false;
+ m_nChanges = 0;
 
         m_regForegroundColors[DIFFSTATE_UNKNOWN] = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\ColorUnknownF"), DIFFSTATE_UNKNOWN_DEFAULT_FG);
         m_regForegroundColors[DIFFSTATE_NORMAL] = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\ColorNormalF"), DIFFSTATE_NORMAL_DEFAULT_FG);
@@ -312,6 +313,8 @@
         CStringA sBaseFilenameUtf8 = CUnicodeUtils::GetUTF8(sBaseFilename);
         CStringA sYourFilenameUtf8 = CUnicodeUtils::GetUTF8(sYourFilename);
 
+ m_nChanges = 0;
+
         svn_diff_t * diffYourBase = NULL;
         svn_error_t * svnerr = NULL;
         svn_diff_file_options_t * options = svn_diff_file_options_create(pool);
@@ -392,6 +395,7 @@
                                                         m_arDiffYourBaseBoth.Add(sCurrentYourLine);
                                                         m_arStateYourBaseBoth.Add(DIFFSTATE_ADDEDWHITESPACE);
                                                         m_arLinesYourBaseBoth.Add(yourline);
+ m_nChanges++;
                                                 }
                                                 else
                                                 {
@@ -406,6 +410,7 @@
                                                 m_arDiffYourBaseBoth.Add(sCurrentYourLine);
                                                 m_arStateYourBaseBoth.Add(DIFFSTATE_ADDEDWHITESPACE);
                                                 m_arLinesYourBaseBoth.Add(yourline);
+ m_nChanges++;
                                         }
                                         else
                                         {
@@ -425,6 +430,7 @@
                                 m_arDiffYourBaseBoth.Add(sCurrentBaseLine);
                                 m_arStateYourBaseBoth.Add(DIFFSTATE_REMOVED);
                                 m_arLinesYourBaseBoth.Add(yourline);
+ m_nChanges++;
                         }
                         baseline++;
                 }
@@ -437,6 +443,7 @@
                                         m_arDiffYourBaseBoth.Add(m_arYourFile.GetAt(yourline));
                                         m_arStateYourBaseBoth.Add(DIFFSTATE_ADDED);
                                         m_arLinesYourBaseBoth.Add(yourline);
+ m_nChanges++;
                                 }
                                 yourline++;
                         }
@@ -564,6 +571,9 @@
         CStringA sBaseFilenameUtf8 = CUnicodeUtils::GetUTF8(sBaseFilename);
         CStringA sYourFilenameUtf8 = CUnicodeUtils::GetUTF8(sYourFilename);
         CStringA sTheirFilenameUtf8 = CUnicodeUtils::GetUTF8(sTheirFilename);
+
+ m_nChanges = 0;
+
         svn_diff_t * diffTheirYourBase = NULL;
         svn_diff_file_options_t * options = svn_diff_file_options_create(pool);
         options->ignore_eol_style = bIgnoreEOL;
@@ -632,6 +642,8 @@
                 }
                 else if (tempdiff->type == svn_diff__type_diff_common)
                 {
+ m_nChanges++;
+
                         ASSERT(tempdiff->latest_length == tempdiff->modified_length);
                         //both theirs and yours have lines replaced
                         for (int i=0; i<tempdiff->original_length; i++)
@@ -681,6 +693,8 @@
                 }
                 else if (tempdiff->type == svn_diff__type_conflict)
                 {
+ m_nChanges++;
+
                         apr_off_t length = max(tempdiff->original_length, tempdiff->modified_length);
                         length = max(tempdiff->latest_length, length);
                         apr_off_t original = tempdiff->original_length;
@@ -885,6 +899,8 @@
                 }
                 else if (tempdiff->type == svn_diff__type_diff_modified)
                 {
+ m_nChanges++;
+
                         //deleted!
                         for (int i=0; i<tempdiff->original_length; i++)
                         {
@@ -934,6 +950,8 @@
                 }
                 else if (tempdiff->type == svn_diff__type_diff_latest)
                 {
+ m_nChanges++;
+
                         //YOURS differs from base
 
                         for (int i=0; i<tempdiff->original_length; i++)
Index: src/TortoiseMerge/MainFrm.cpp
===================================================================
--- src/TortoiseMerge/MainFrm.cpp (revisione 8951)
+++ src/TortoiseMerge/MainFrm.cpp (copia locale)
@@ -101,6 +101,7 @@
         m_nSearchIndex = 0;
         m_bInitSplitter = FALSE;
         m_bOneWay = (0 != ((DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\OnePane"))));
+ m_bQuitIfUnchanged = FALSE;
         m_bReversedPatch = FALSE;
         m_bHasConflicts = false;
 }
@@ -471,6 +472,18 @@
                         m_Data.m_mergedFile.SetOutOfUse();
                         return FALSE;
                 }
+
+ // report if there are no changes
+ // TODO: make this optional?
+ if (/*flagReportEqualFiles &&*/ (this->m_Data.GetChanges() == 0))
+ {
+ CString sTemp;
+ sTemp.LoadString(IDS_WARNIDENTICALFILES);
+ MessageBox(sTemp, NULL, MB_ICONINFORMATION | MB_OK);
+
+ if (m_bQuitIfUnchanged)
+ return FALSE;
+ }
         }
         BOOL bGoFirstDiff = (0 != ((DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\FirstDiffOnLoad"))));
         if (!m_Data.IsBaseFileInUse())
Index: src/Resources/TortoiseMergeENG.rc
===================================================================
--- src/Resources/TortoiseMergeENG.rc (revisione 8951)
+++ src/Resources/TortoiseMergeENG.rc (copia locale)
@@ -651,6 +651,7 @@
     IDS_WARNBETTERPATCHPATHFOUND
                             "The path\n<i>%s</i>\nseems not to match the paths in the patchfile.\nBut TortoiseMerge found the path\n<i>%s</i>\nmatches it better. Do you want to use the suggested path instead?"
     IDS_NOTFOUNDVIEWTITLEINDICATOR "(not found)"
+ IDS_WARNIDENTICALFILES "The files are identical."
 END
 
 STRINGTABLE

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Wed Mar 21 13:16:37 2007

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.