4 * @brief Declarations of CDiffContext and diff structures
8 #define POCO_NO_UNWINDOWS 1
9 #include <Poco/Mutex.h>
11 #include "PathContext.h"
12 #include "DiffItemList.h"
13 #include "FilterList.h"
23 class FilterCommentsManager;
25 /** Interface to a provider of plugin info */
29 virtual void FetchPluginInfos(const String& filteredFilenames,
30 PackingInfo ** infoUnpacker,
31 PrediffingInfo ** infoPrediffer) = 0;
35 * The folder compare context.
36 * This class holds data of the current folder compare. There are paths
37 * to compare, filters used, compare options etc. And compare results list
38 * is also contained in this class. Many compare classes and functions have
39 * a pointer to instance of this class.
41 * @note If you add new member variables, remember to copy values in
42 * CDiffContext::CDiffContext(..,CDiffContext) constructor!
44 class CDiffContext : public DiffItemList
47 /** @brief Special values for difference counts. */
50 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
51 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
54 CDiffContext(const PathContext & paths, int compareMethod);
57 void UpdateVersion(DIFFITEM &di, int nIndex) const;
60 * Get the main compare method used in this compare.
61 * @return Compare method used.
63 int GetCompareMethod(void) const { return m_nCompMethod; }
67 * @name Path accessor functions.
69 * These functions return left/right path associated to DiffContext.
70 * There is no setter fuctions and path can be set only via constructor.
71 * Normalized paths are preferred to use - short paths are expanded
72 * and trailing slashes removed (except from root path).
75 * Get left-side compare path.
76 * @return full path in left-side.
78 String GetLeftPath() const { return m_paths.GetLeft(false); }
79 String GetMiddlePath() const { return m_paths.GetMiddle(false); }
81 * Get right-side compare path.
82 * @return full path in right-side.
84 String GetRightPath() const { return m_paths.GetRight(false); }
85 String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, false); }
87 * Get left-side compare path in normalized form.
88 * @return full path in left-side.
90 String GetNormalizedLeft() const { return m_paths.GetLeft(); }
91 String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
93 * Get right-side compare path in normalized form.
94 * @return full path in left-side.
96 String GetNormalizedRight() const { return m_paths.GetRight(); }
97 String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, true); }
98 PathContext GetNormalizedPaths() const
101 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
102 paths.SetPath(nIndex, m_paths.GetPath(nIndex, true));
107 // change an existing difference
108 bool UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex);
109 void UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex);
111 bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
112 CompareOptions * GetCompareOptions(int compareMethod);
114 // retrieve or manufacture plugin info for specified file comparison
115 void FetchPluginInfos(const String& filteredFilenames,
116 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
120 * @name Compare aborting interface.
121 * These functions handle compare aborting using IAbortable interface.
123 bool ShouldAbort() const;
126 * Set pointer to IAbortable interface.
127 * This function sets pointer to interface used to abort the compare when
129 * @param [in] piAbortable Pointer to interface.
131 void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
134 * Returns a pointer to current IAbortable interface.
135 * This function returns a pointer to interface used to abort the compare.
136 * @return Pointer to current IAbortable interface.
138 const IAbortable * GetAbortable() const { return m_piAbortable; }
141 int GetCompareDirs() const { return m_paths.GetSize(); }
143 void Swap(int idx1, int idx2)
146 tmp = m_paths.GetPath(idx1);
147 m_paths.SetPath(idx1, m_paths.GetPath(idx2));
148 m_paths.SetPath(idx2, tmp);
149 DiffItemList::Swap(idx1, idx2);
152 IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
153 IPluginInfos * m_piPluginInfos;
154 int m_iGuessEncodingType;
156 bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
157 CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
160 * Optimize compare by stopping after first difference.
161 * In some compare methods (currently quick compare) we can stop the
162 * compare right after finding the first difference. This speeds up the
163 * compare, but also causes compare statistics to be inaccurate.
165 bool m_bStopAfterFirstDiff;
168 * Threshold size for switching to quick compare.
169 * When diffutils compare is selected, files bigger (in bytes) than this
170 * value are compared using Quick compare. This is because diffutils simply
171 * cannot compare large files. And large files are usually binary files.
173 int m_nQuickCompareLimit;
175 int m_nBinaryCompareLimit;
178 * Walk into unique folders and add contents.
179 * This enables/disables walking into unique folders. If we don't walk into
180 * unique folders, they are shown as such in folder compare results. If we
181 * walk into unique folders, we'll show all files in the unique folder and
182 * in possible subfolders.
184 * This value is true by default.
187 bool m_bIgnoreReparsePoints;
188 bool m_bIgnoreCodepage;
190 bool m_bRecursive; /**< Do we include subfolders to compare? */
191 bool m_bPluginsEnabled; /**< Are plugins enabled? */
192 std::unique_ptr<FilterList> m_pFilterList; /**< Filter list for line filters */
193 FilterCommentsManager *m_pFilterCommentsManager;
197 * The main compare method used.
198 * This is the main compare method set when compare is started. There
199 * can be temporary switches to other method (e.g. for large file) but
200 * this main method must be set back for next file.
204 std::unique_ptr<DIFFOPTIONS> m_pOptions; /**< Generalized compare options. */
205 std::unique_ptr<CompareOptions> m_pContentCompareOptions; /**< Per compare method compare options. */
206 std::unique_ptr<CompareOptions> m_pQuickCompareOptions; /**< Per compare method compare options. */
207 PathContext m_paths; /**< (root) paths for this context */
208 IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
209 Poco::FastMutex m_mutex;