1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "StandAloneDlg.h"
24 #include "ProjectProperties.h"
26 #include "GitStatus.h"
28 //#include "..\IBugTraqProvider\IBugTraqProvider_h.h"
31 #include "UnicodeUtils.h"
33 typedef int (__cdecl
*GENERICCOMPAREFN
)(const void * elem1
, const void * elem2
);
34 struct git_transfer_progress
;
37 * \ingroup TortoiseProc
38 * Options which can be used to configure the way the dialog box works
43 ProgOptRecursive
= 0x01,
44 ProgOptNonRecursive
= 0x00,
45 /// Don't actually do the merge - just practice it
47 ProgOptIgnoreExternals
= 0x08,
48 ProgOptKeeplocks
= 0x10,
49 /// for locking this means steal the lock, for unlocking it means breaking the lock
50 ProgOptLockForce
= 0x20,
51 ProgOptSwitchAfterCopy
= 0x40,
52 ProgOptIncludeIgnored
= 0x80,
53 ProgOptIgnoreAncestry
= 0x100,
54 ProgOptEolDefault
= 0x200,
55 ProgOptEolCRLF
= 0x400,
57 ProgOptEolCR
= 0x1000,
58 ProgOptSkipConflictCheck
= 0x2000,
59 ProgOptRecordOnly
= 0x4000
69 } ProgressCloseOptions
;
71 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
76 git_wc_notify_sendmail_start
,
77 git_wc_notify_sendmail_error
,
78 git_wc_notify_sendmail_retry
,
79 git_wc_notify_sendmail_done
,
80 git_wc_notify_resolved
,
83 git_wc_notify_checkout
,
85 }git_wc_notify_action_t
;
88 SENDMAIL_ATTACHMENT
=0x1,
89 SENDMAIL_COMBINED
=0x2,
93 * \ingroup TortoiseProc
94 * Handles different Subversion commands and shows the notify messages
95 * in a listbox. Since several Subversion commands have similar notify
96 * messages they are grouped together in this single class.
98 class CGitProgressDlg
: public CResizableStandAloneDialog
104 GitProgress_Checkout
,
111 GitProgress_SendMail
,
116 DECLARE_DYNAMIC(CGitProgressDlg
)
120 CGitProgressDlg(CWnd
* pParent
= NULL
);
121 virtual ~CGitProgressDlg();
124 void SetCommand(Command cmd
) {m_Command
= cmd
;}
125 void SetAutoClose(DWORD ac
) {m_dwCloseOnEnd
= ac
;}
126 void SetOptions(DWORD opts
) {m_options
= opts
;}
127 void SetPathList(const CTGitPathList
& pathList
) {m_targetPathList
= pathList
;}
128 void SetUrl(const CString
& url
) {m_url
.SetFromUnknown(url
);}
129 void SetSecondUrl(const CString
& url
) {m_url2
.SetFromUnknown(url
);}
130 void SetCommitMessage(const CString
& msg
) {m_sMessage
= msg
;}
131 void SetIsBare(bool b
) { m_bBare
= b
; }
132 void SetNoCheckout(bool b
){ m_bNoCheckout
= b
; }
133 void SetRefSpec(CString
&spec
){ m_RefSpec
= spec
; }
135 // void SetRevision(const GitRev& rev) {m_Revision = rev;}
136 // void SetRevisionEnd(const GitRev& rev) {m_RevisionEnd = rev;}
138 void SetDiffOptions(const CString
& opts
) {m_diffoptions
= opts
;}
139 void SetSendMailOption(CString
&TO
, CString
&CC
,CString
&Subject
,DWORD flags
){m_SendMailTO
=TO
;m_SendMailSubject
=Subject
; m_SendMailCC
=CC
;this->m_SendMailFlags
= flags
;}
140 void SetDepth(git_depth_t depth
= git_depth_unknown
) {m_depth
= depth
;}
141 void SetPegRevision(GitRev pegrev
= GitRev()) {m_pegRev
= pegrev
;}
142 void SetProjectProperties(ProjectProperties props
) {m_ProjectProperties
= props
;}
143 void SetChangeList(const CString
& changelist
, bool keepchangelist
) {m_changelist
= changelist
; m_keepchangelist
= keepchangelist
;}
144 void SetSelectedList(const CTGitPathList
& selPaths
);
145 // void SetRevisionRanges(const GitRevRangeArray& revArray) {m_revisionArray = revArray;}
146 // void SetBugTraqProvider(const CComPtr<IBugTraqProvider> pBugtraqProvider) { m_BugTraqProvider = pBugtraqProvider;}
148 * If the number of items for which the operation is done on is known
149 * beforehand, that number can be set here. It is then used to show a more
150 * accurate progress bar during the operation.
152 void SetItemCount(long count
) {if(count
) m_itemCountTotal
= count
;}
154 bool SetBackgroundImage(UINT nID
);
156 bool DidErrorsOccur() {return m_bErrorsOccurred
;}
158 enum { IDD
= IDD_SVNPROGRESS
};
161 class NotificationData
165 : color(::GetSysColor(COLOR_WINDOWTEXT
))
166 , action((git_wc_notify_action_t
)-1)
167 , bConflictedActionItem(false)
170 git_wc_notify_action_t action
;
172 action((git_wc_notify_action_t
)-1),
174 content_state(git_wc_notify_state_inapplicable
),
175 prop_state(git_wc_notify_state_inapplicable
),
178 bConflictedActionItem(false),
181 // lock_state(git_wc_notify_lock_state_unchanged)
183 // merge_range.end = 0;
184 // merge_range.start = 0;
188 // The text we put into the first column (the Git action for normal items, just text for aux items)
189 CString sActionColumnText
;
192 // CString changelistname;
194 /// git_wc_notify_action_t action;
195 // git_node_kind_t kind;
196 // CString mime_type;
197 // git_wc_notify_state_t content_state;
198 // git_wc_notify_state_t prop_state;
199 // git_wc_notify_lock_state_t lock_state;
200 // git_merge_range_t merge_range;
203 // CString owner; ///< lock owner
204 bool bConflictedActionItem
; // Is this item a conflict?
205 bool bAuxItem
; // Set if this item is not a true 'Git action'
206 CString sPathColumnText
;
211 //Need update in the future implement the virtual methods from Git base class
212 virtual BOOL
Notify(const CTGitPath
& path
,
213 git_wc_notify_action_t action
,
215 CString
*strErr
=NULL
217 git_node_kind_t kind, const CString& mime_type,
218 git_wc_notify_state_t content_state,
219 git_wc_notify_state_t prop_state, LONG rev,
220 const git_lock_t * lock, git_wc_notify_lock_state_t lock_state,
221 const CString& changelistname,
222 git_merge_range_t * range,
223 git_error_t * err, apr_pool_t * pool*/
226 // virtual git_wc_conflict_choice_t ConflictResolveCallback(const git_wc_conflict_description_t *description, CString& mergedfile);
228 virtual BOOL
Notify(const git_wc_notify_action_t action
, const git_transfer_progress
*stat
);
229 static void FetchCallback(const git_transfer_progress
*stats
, void *payload
)
231 ((CGitProgressDlg
*)payload
) -> Notify(git_wc_notify_fetch
, stats
);
234 static void CheckoutCallback(const char *path
, size_t cur
, size_t tot
, void *payload
)
236 CTGitPath tpath
= CUnicodeUtils::GetUnicode(CStringA(path
), CP_UTF8
);
237 ((CGitProgressDlg
*)payload
) -> m_itemCountTotal
= tot
;
238 ((CGitProgressDlg
*)payload
) -> m_itemCount
= cur
;
239 ((CGitProgressDlg
*)payload
) -> Notify(tpath
, git_wc_notify_checkout
);
242 virtual BOOL
OnInitDialog();
243 virtual BOOL
Cancel();
244 virtual void OnCancel();
245 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
246 virtual void DoDataExchange(CDataExchange
* pDX
);
248 afx_msg
void OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
249 afx_msg
void OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
250 afx_msg
void OnNMDblclkSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
251 afx_msg
void OnBnClickedLogbutton();
252 afx_msg
void OnBnClickedOk();
253 afx_msg
void OnBnClickedNoninteractive();
254 afx_msg
void OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
255 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
256 afx_msg
void OnClose();
257 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
258 afx_msg LRESULT
OnGitProgress(WPARAM wParam
, LPARAM lParam
);
259 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
260 afx_msg
void OnEnSetfocusInfotext();
261 afx_msg
void OnLvnBegindragSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
262 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
263 afx_msg LRESULT
OnTaskbarBtnCreated(WPARAM wParam
, LPARAM lParam
);
264 afx_msg LRESULT
OnCtlColorStatic(WPARAM wParam
, LPARAM lParam
);
265 afx_msg HBRUSH
OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
);
266 LRESULT
OnShowConflictResolver(WPARAM
, LPARAM
);
268 DECLARE_MESSAGE_MAP()
271 static bool SortCompare(const NotificationData
* pElem1
, const NotificationData
* pElem2
);
273 static BOOL m_bAscending
;
274 static int m_nSortedColumn
;
275 CStringList m_ExtStack
;
278 static UINT
ProgressThreadEntry(LPVOID pVoid
);
279 UINT
ProgressThread();
281 void ReportGitError();
282 void ReportError(const CString
& sError
);
283 void ReportWarning(const CString
& sWarning
);
284 void ReportNotification(const CString
& sNotification
);
285 void ReportCmd(const CString
& sCmd
);
286 void ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
= ::GetSysColor(COLOR_WINDOWTEXT
));
287 void AddItemToList();
288 CString
BuildInfoString();
289 CString
GetPathFromColumnText(const CString
& sColumnText
);
292 * Resizes the columns of the progress list so that the headings are visible.
294 void ResizeColumns();
296 /// Predicate function to tell us if a notification data item is auxiliary or not
297 static bool NotificationDataIsAux(const NotificationData
* pData
);
299 // the commands to execute
300 bool CmdAdd(CString
& sWindowTitle
, bool& localoperation
);
301 bool CmdCheckout(CString
& sWindowTitle
, bool& localoperation
);
302 bool CmdCopy(CString
& sWindowTitle
, bool& localoperation
);
303 bool CmdExport(CString
& sWindowTitle
, bool& localoperation
);
304 bool CmdRename(CString
& sWindowTitle
, bool& localoperation
);
305 bool CmdResolve(CString
& sWindowTitle
, bool& localoperation
);
306 bool CmdRevert(CString
& sWindowTitle
, bool& localoperation
);
307 bool CmdSwitch(CString
& sWindowTitle
, bool& localoperation
);
308 bool CmdSendMail(CString
& sWindowTitle
, bool& localoperation
);
309 bool CmdClone(CString
& sWindowTitle
, bool& localoperation
);
312 typedef std::map
<CStringA
, git_revnum_t
> StringRevMap
;
313 typedef std::vector
<NotificationData
*> NotificationDataVect
;
316 CString m_mergedfile
;
317 NotificationDataVect m_arData
;
318 CAnimateCtrl m_Animate
;
319 CWinThread
* m_pThread
;
320 volatile LONG m_bThreadRunning
;
322 ProjectProperties m_ProjectProperties
;
323 CListCtrl m_ProgList
;
325 int m_options
; // Use values from the ProgressOptions enum
327 CTGitPathList m_targetPathList
;
328 CTGitPathList m_selectedPaths
;
332 CString m_diffoptions
;
334 GitRev m_RevisionEnd
;
336 // GitRevRangeArray m_revisionArray;
337 CString m_changelist
;
338 bool m_keepchangelist
;
340 DWORD m_dwCloseOnEnd
;
342 CTGitPath m_basePath
;
343 StringRevMap m_UpdateStartRevMap
;
344 StringRevMap m_FinishedRevMap
;
346 TCHAR m_columnbuf
[MAX_PATH
];
350 bool m_bErrorsOccurred
;
351 bool m_bMergesAddsDeletesOccurred
;
355 int nEnsureVisibleCount
;
357 CString m_sTotalBytesTransferred
;
358 size_t m_TotalBytesTransferred
;
362 bool m_bFinishedItemAdded
;
366 int m_itemCountTotal
;
368 bool m_AlwaysConflicted
;
370 DWORD m_SendMailFlags
;
371 CString m_SendMailTO
;
372 CString m_SendMailCC
;
373 CString m_SendMailSubject
;
375 /// CComPtr<IBugTraqProvider> m_BugTraqProvider;
376 CComPtr
<ITaskbarList3
> m_pTaskbarList
;
378 // some strings different methods can use
385 CBrush m_background_brush
;