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 "DiffFileInfo.h"
13 #include "DiffItemList.h"
14 #include "FilterList.h"
24 class FilterCommentsManager;
26 /** Interface to a provider of plugin info */
30 virtual void FetchPluginInfos(const String& filteredFilenames,
31 PackingInfo ** infoUnpacker,
32 PrediffingInfo ** infoPrediffer) = 0;
36 * The folder compare context.
37 * This class holds data of the current folder compare. There are paths
38 * to compare, filters used, compare options etc. And compare results list
39 * is also contained in this class. Many compare classes and functions have
40 * a pointer to instance of this class.
42 * @note If you add new member variables, remember to copy values in
43 * CDiffContext::CDiffContext(..,CDiffContext) constructor!
45 class CDiffContext : public DiffItemList
48 /** @brief Special values for difference counts. */
51 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
52 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
55 CDiffContext(const PathContext & paths, int compareMethod);
58 void UpdateVersion(DIFFITEM &di, int nIndex) const;
61 * Get the main compare method used in this compare.
62 * @return Compare method used.
64 int GetCompareMethod(void) const { return m_nCompMethod; }
68 * @name Path accessor functions.
70 * These functions return left/right path associated to DiffContext.
71 * There is no setter fuctions and path can be set only via constructor.
72 * Normalized paths are preferred to use - short paths are expanded
73 * and trailing slashes removed (except from root path).
76 * Get left-side compare path.
77 * @return full path in left-side.
79 String GetLeftPath() const { return m_paths.GetLeft(false); }
80 String GetMiddlePath() const { return m_paths.GetMiddle(false); }
82 * Get right-side compare path.
83 * @return full path in right-side.
85 String GetRightPath() const { return m_paths.GetRight(false); }
86 String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, false); }
88 * Get left-side compare path in normalized form.
89 * @return full path in left-side.
91 String GetNormalizedLeft() const { return m_paths.GetLeft(); }
92 String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
94 * Get right-side compare path in normalized form.
95 * @return full path in left-side.
97 String GetNormalizedRight() const { return m_paths.GetRight(); }
98 String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, true); }
99 PathContext GetNormalizedPaths() const
102 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
103 paths.SetPath(nIndex, m_paths.GetPath(nIndex, true));
108 // change an existing difference
109 bool UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex);
110 void UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex);
112 bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
113 CompareOptions * GetCompareOptions(int compareMethod);
115 // retrieve or manufacture plugin info for specified file comparison
116 void FetchPluginInfos(const String& filteredFilenames,
117 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
121 * @name Compare aborting interface.
122 * These functions handle compare aborting using IAbortable interface.
124 bool ShouldAbort() const;
127 * Set pointer to IAbortable interface.
128 * This function sets pointer to interface used to abort the compare when
130 * @param [in] piAbortable Pointer to interface.
132 void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
135 * Returns a pointer to current IAbortable interface.
136 * This function returns a pointer to interface used to abort the compare.
137 * @return Pointer to current IAbortable interface.
139 const IAbortable * GetAbortable() const { return m_piAbortable; }
142 int GetCompareDirs() const { return m_paths.GetSize(); }
144 void Swap(int idx1, int idx2)
147 tmp = m_paths.GetPath(idx1);
148 m_paths.SetPath(idx1, m_paths.GetPath(idx2));
149 m_paths.SetPath(idx2, tmp);
150 DiffItemList::Swap(idx1, idx2);
153 IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
154 IPluginInfos * m_piPluginInfos;
155 int m_iGuessEncodingType;
157 bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
158 CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
161 * Optimize compare by stopping after first difference.
162 * In some compare methods (currently quick compare) we can stop the
163 * compare right after finding the first difference. This speeds up the
164 * compare, but also causes compare statistics to be inaccurate.
166 bool m_bStopAfterFirstDiff;
169 * Threshold size for switching to quick compare.
170 * When diffutils compare is selected, files bigger (in bytes) than this
171 * value are compared using Quick compare. This is because diffutils simply
172 * cannot compare large files. And large files are usually binary files.
174 int m_nQuickCompareLimit;
177 * Walk into unique folders and add contents.
178 * This enables/disables walking into unique folders. If we don't walk into
179 * unique folders, they are shown as such in folder compare results. If we
180 * walk into unique folders, we'll show all files in the unique folder and
181 * in possible subfolders.
183 * This value is true by default.
186 bool m_bIgnoreReparsePoints;
187 bool m_bIgnoreCodepage;
189 bool m_bRecursive; /**< Do we include subfolders to compare? */
190 bool m_bPluginsEnabled; /**< Are plugins enabled? */
191 std::unique_ptr<FilterList> m_pFilterList; /**< Filter list for line filters */
192 FilterCommentsManager *m_pFilterCommentsManager;
196 * The main compare method used.
197 * This is the main compare method set when compare is started. There
198 * can be temporary switches to other method (e.g. for large file) but
199 * this main method must be set back for next file.
203 std::unique_ptr<DIFFOPTIONS> m_pOptions; /**< Generalized compare options. */
204 std::unique_ptr<CompareOptions> m_pContentCompareOptions; /**< Per compare method compare options. */
205 std::unique_ptr<CompareOptions> m_pQuickCompareOptions; /**< Per compare method compare options. */
206 PathContext m_paths; /**< (root) paths for this context */
207 IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
208 Poco::FastMutex m_mutex;