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 "ProjectProperties.h"
24 #include "GitStatus.h"
26 //#include "..\IBugTraqProvider\IBugTraqProvider_h.h"
29 #include "UnicodeUtils.h"
32 * \ingroup TortoiseProc
33 * Options which can be used to configure the way the dialog box works
38 ProgOptRecursive
= 0x01,
39 ProgOptNonRecursive
= 0x00,
40 /// Don't actually do the merge - just practice it
42 ProgOptIgnoreExternals
= 0x08,
43 ProgOptKeeplocks
= 0x10,
44 /// for locking this means steal the lock, for unlocking it means breaking the lock
45 ProgOptLockForce
= 0x20,
46 ProgOptSwitchAfterCopy
= 0x40,
47 ProgOptIncludeIgnored
= 0x80,
48 ProgOptIgnoreAncestry
= 0x100,
49 ProgOptEolDefault
= 0x200,
50 ProgOptEolCRLF
= 0x400,
52 ProgOptEolCR
= 0x1000,
53 ProgOptSkipConflictCheck
= 0x2000,
54 ProgOptRecordOnly
= 0x4000
64 } ProgressCloseOptions
;
69 git_wc_notify_sendmail
,
70 git_wc_notify_resolved
,
73 git_wc_notify_checkout
,
74 git_wc_notify_update_ref
,
76 }git_wc_notify_action_t
;
80 SENDMAIL_ATTACHMENT
=0x1,
81 SENDMAIL_COMBINED
=0x2,
85 struct git_transfer_progress
;
86 #define WM_SHOWCONFLICTRESOLVER (WM_APP + 100)
87 #define WM_PROG_CMD_FINISH (WM_APP + 200)
88 #define WM_PROG_CMD_START (WM_APP + 201)
90 class CGitProgressList
: public CListCtrl
92 DECLARE_DYNAMIC(CGitProgressList
)
105 GitProgress_SendMail
,
111 virtual ~CGitProgressList();
113 void SetCommand(CGitProgressList::Command cmd
) {m_Command
= cmd
;}
114 void SetOptions(DWORD opts
) {m_options
= opts
;}
115 void SetPathList(const CTGitPathList
& pathList
) {m_targetPathList
= pathList
;}
116 void SetUrl(const CString
& url
) {m_url
.SetFromUnknown(url
);}
117 void SetSecondUrl(const CString
& url
) {m_url2
.SetFromUnknown(url
);}
118 void SetCommitMessage(const CString
& msg
) {m_sMessage
= msg
;}
119 void SetIsBare(bool b
) { m_bBare
= b
; }
120 void SetNoCheckout(bool b
){ m_bNoCheckout
= b
; }
121 void SetRefSpec(CString spec
){ m_RefSpec
= spec
; }
122 void SetAutoTag(int tag
){ m_AutoTag
= tag
; }
124 // void SetRevision(const GitRev& rev) {m_Revision = rev;}
125 // void SetRevisionEnd(const GitRev& rev) {m_RevisionEnd = rev;}
127 void SetDiffOptions(const CString
& opts
) {m_diffoptions
= opts
;}
128 void SetSendMailOption(CString
&TO
, CString
&CC
,CString
&Subject
,DWORD flags
){m_SendMailTO
=TO
;m_SendMailSubject
=Subject
; m_SendMailCC
=CC
;this->m_SendMailFlags
= flags
;}
129 void SetDepth(git_depth_t depth
= git_depth_unknown
) {m_depth
= depth
;}
130 void SetPegRevision(GitRev pegrev
= GitRev()) {m_pegRev
= pegrev
;}
131 void SetProjectProperties(ProjectProperties props
) {m_ProjectProperties
= props
;}
132 void SetChangeList(const CString
& changelist
, bool keepchangelist
) {m_changelist
= changelist
; m_keepchangelist
= keepchangelist
;}
133 void SetSelectedList(const CTGitPathList
& selPaths
);
134 // void SetRevisionRanges(const GitRevRangeArray& revArray) {m_revisionArray = revArray;}
135 // void SetBugTraqProvider(const CComPtr<IBugTraqProvider> pBugtraqProvider) { m_BugTraqProvider = pBugtraqProvider;}
137 * If the number of items for which the operation is done on is known
138 * beforehand, that number can be set here. It is then used to show a more
139 * accurate progress bar during the operation.
141 void SetItemCount(long count
) {if(count
) m_itemCountTotal
= count
;}
142 bool SetBackgroundImage(UINT nID
);
143 bool DidErrorsOccur() {return m_bErrorsOccurred
;}
144 bool m_bErrorsOccurred
;
145 CWnd
*m_pProgressLabelCtrl
;
147 CAnimateCtrl
*m_pAnimate
;
148 CProgressCtrl
*m_pProgControl
;
151 volatile BOOL
IsCancelled() {return m_bCancelled
;}
152 volatile LONG
IsRunning() {return m_bThreadRunning
;}
153 CWinThread
* m_pThread
;
154 bool m_AlwaysConflicted
;
158 class NotificationData
162 : color(::GetSysColor(COLOR_WINDOWTEXT
))
163 , action((git_wc_notify_action_t
)-1)
164 , bConflictedActionItem(false)
167 git_wc_notify_action_t action
;
169 action((git_wc_notify_action_t
)-1),
171 content_state(git_wc_notify_state_inapplicable
),
172 prop_state(git_wc_notify_state_inapplicable
),
175 bConflictedActionItem(false),
178 // lock_state(git_wc_notify_lock_state_unchanged)
180 // merge_range.end = 0;
181 // merge_range.start = 0;
185 // The text we put into the first column (the Git action for normal items, just text for aux items)
186 CString sActionColumnText
;
189 // CString changelistname;
191 // git_node_kind_t kind;
192 // CString mime_type;
193 // git_wc_notify_state_t content_state;
194 // git_wc_notify_state_t prop_state;
195 // git_wc_notify_lock_state_t lock_state;
196 // git_merge_range_t merge_range;
199 // CString owner; ///< lock owner
200 bool bConflictedActionItem
; // Is this item a conflict?
201 bool bAuxItem
; // Set if this item is not a true 'Git action'
202 CString sPathColumnText
;
207 DECLARE_MESSAGE_MAP()
210 //Need update in the future implement the virtual methods from Git base class
211 virtual BOOL
Notify(const CTGitPath
& path
,
212 git_wc_notify_action_t action
214 git_node_kind_t kind, const CString& mime_type,
215 git_wc_notify_state_t content_state,
216 git_wc_notify_state_t prop_state, LONG rev,
217 const git_lock_t * lock, git_wc_notify_lock_state_t lock_state,
218 const CString& changelistname,
219 git_merge_range_t * range,
220 git_error_t * err, apr_pool_t * pool*/
223 virtual BOOL
Notify(const git_wc_notify_action_t action
, const git_transfer_progress
*stat
);
224 virtual BOOL
Notify(const git_wc_notify_action_t action
, CString str
, const git_oid
*a
, const git_oid
*b
);
226 void SetWindowTitle(UINT id
, const CString
& urlorpath
, CString
& dialogname
);
228 // virtual git_wc_conflict_choice_t ConflictResolveCallback(const git_wc_conflict_description_t *description, CString& mergedfile);
230 static int FetchCallback(const git_transfer_progress
*stats
, void *payload
)
232 return !((CGitProgressList
*)payload
) -> Notify(git_wc_notify_fetch
, stats
);
235 static void CheckoutCallback(const char *path
, size_t cur
, size_t tot
, void *payload
)
237 CTGitPath tpath
= CUnicodeUtils::GetUnicode(CStringA(path
), CP_UTF8
);
238 ((CGitProgressList
*)payload
) -> m_itemCountTotal
= (int)tot
;
239 ((CGitProgressList
*)payload
) -> m_itemCount
= (int)cur
;
240 ((CGitProgressList
*)payload
) -> Notify(tpath
, git_wc_notify_checkout
);
243 static void RemoteProgressCallback(const char *str
, int len
, void *data
)
246 progText
= CUnicodeUtils::GetUnicode(CStringA(str
, len
));
247 ((CGitProgressList
*)data
) -> SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
249 static int RemoteCompletionCallback(git_remote_completion_type
/*type*/, void * /*data*/)
253 static int RemoteUpdatetipsCallback(const char *refname
, const git_oid
*a
, const git_oid
*b
, void *data
)
256 str
= CUnicodeUtils::GetUnicode(refname
);
257 ((CGitProgressList
*)data
) -> Notify(git_wc_notify_update_ref
, str
, a
, b
);
261 afx_msg
void OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
262 afx_msg
void OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
263 afx_msg
void OnNMDblclkSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
264 afx_msg
void OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
265 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
266 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
267 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
268 LRESULT
OnShowConflictResolver(WPARAM
, LPARAM
);
269 afx_msg
void OnLvnBegindragSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
);
272 static bool SortCompare(const NotificationData
* pElem1
, const NotificationData
* pElem2
);
274 static BOOL m_bAscending
;
275 static int m_nSortedColumn
;
276 CStringList m_ExtStack
;
279 static UINT
ProgressThreadEntry(LPVOID pVoid
);
280 UINT
ProgressThread();
283 void ReportGitError();
284 void ReportUserCanceled();
285 void ReportError(const CString
& sError
);
286 void ReportWarning(const CString
& sWarning
);
287 void ReportNotification(const CString
& sNotification
);
288 void ReportCmd(const CString
& sCmd
);
289 void ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
= ::GetSysColor(COLOR_WINDOWTEXT
));
291 void AddItemToList();
292 CString
BuildInfoString();
293 CString
GetPathFromColumnText(const CString
& sColumnText
);
296 * Resizes the columns of the progress list so that the headings are visible.
298 void ResizeColumns();
300 /// Predicate function to tell us if a notification data item is auxiliary or not
301 static bool NotificationDataIsAux(const NotificationData
* pData
);
303 // the commands to execute
304 bool CmdAdd(CString
& sWindowTitle
, bool& localoperation
);
305 bool CmdCheckout(CString
& sWindowTitle
, bool& localoperation
);
306 bool CmdCopy(CString
& sWindowTitle
, bool& localoperation
);
307 bool CmdExport(CString
& sWindowTitle
, bool& localoperation
);
308 bool CmdRename(CString
& sWindowTitle
, bool& localoperation
);
309 bool CmdResolve(CString
& sWindowTitle
, bool& localoperation
);
310 bool CmdRevert(CString
& sWindowTitle
, bool& localoperation
);
311 bool CmdSwitch(CString
& sWindowTitle
, bool& localoperation
);
312 bool CmdSendMail(CString
& sWindowTitle
, bool& localoperation
);
313 bool CmdClone(CString
& sWindowTitle
, bool& localoperation
);
314 bool CmdFetch(CString
& sWindowTitle
, bool& localoperation
);
317 typedef std::map
<CStringA
, git_revnum_t
> StringRevMap
;
318 typedef std::vector
<NotificationData
*> NotificationDataVect
;
320 CString m_mergedfile
;
321 NotificationDataVect m_arData
;
323 volatile LONG m_bThreadRunning
;
325 ProjectProperties m_ProjectProperties
;
327 int m_options
; // Use values from the ProgressOptions enum
329 CTGitPathList m_targetPathList
;
330 CTGitPathList m_selectedPaths
;
334 CString m_diffoptions
;
336 GitRev m_RevisionEnd
;
338 // GitRevRangeArray m_revisionArray;
339 CString m_changelist
;
340 bool m_keepchangelist
;
342 CTGitPath m_basePath
;
343 StringRevMap m_UpdateStartRevMap
;
344 StringRevMap m_FinishedRevMap
;
346 TCHAR m_columnbuf
[MAX_PATH
];
348 volatile BOOL m_bCancelled
;
350 bool m_bMergesAddsDeletesOccurred
;
354 int nEnsureVisibleCount
;
356 CString m_sTotalBytesTransferred
;
357 size_t m_TotalBytesTransferred
;
361 bool m_bFinishedItemAdded
;
365 int m_itemCountTotal
;
367 DWORD m_SendMailFlags
;
368 CString m_SendMailTO
;
369 CString m_SendMailCC
;
370 CString m_SendMailSubject
;
372 /// CComPtr<IBugTraqProvider> m_BugTraqProvider;
374 // some strings different methods can use
383 CComPtr
<ITaskbarList3
> m_pTaskbarList
;
385 afx_msg
void OnClose();
386 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);