Add volatile to cancel because shared between two thread
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob77a1d3a2b4a199a781509a9ab0beaf67f10840d1
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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
24 #include "LogDlg.h"
25 #include "TGitPath.h"
26 #include "registry.h"
27 #include "GitStatus.h"
28 #include "AppUtils.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "TempFile.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
34 #include "GitDiff.h"
35 #include "Hooks.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
40 #include "LogFile.h"
41 #include "ShellUpdater.h"
42 #include "IconMenu.h"
43 #include "BugTraqAssociations.h"
44 #include "patch.h"
45 #include "MassiveGitTask.h"
46 #include "SmartHandle.h"
48 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
50 BOOL CGitProgressDlg::m_bAscending = FALSE;
51 int CGitProgressDlg::m_nSortedColumn = -1;
53 #define TRANSFERTIMER 100
54 #define VISIBLETIMER 101
56 enum GITProgressDlgContextMenuCommands
58 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
59 ID_COMPARE = 1,
60 ID_EDITCONFLICT,
61 ID_CONFLICTRESOLVE,
62 ID_CONFLICTUSETHEIRS,
63 ID_CONFLICTUSEMINE,
64 ID_LOG,
65 ID_OPEN,
66 ID_OPENWITH,
67 ID_EXPLORE,
68 ID_COPY
71 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
72 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
73 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
74 , m_bCancelled(FALSE)
75 , m_pThread(NULL)
76 , m_bErrorsOccurred(false)
77 , m_bBare(false)
78 , m_bNoCheckout(false)
79 , m_AutoTag(GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
80 , m_options(ProgOptNone)
81 #if 0
82 , m_Revision(_T("HEAD"))
83 //, m_RevisionEnd(0)
84 , m_bLockWarning(false)
85 , m_bLockExists(false)
86 , m_bThreadRunning(FALSE)
87 , m_nConflicts(0)
88 , m_bMergesAddsDeletesOccurred(FALSE)
89 , m_dwCloseOnEnd((DWORD)-1)
90 , m_bFinishedItemAdded(false)
91 , m_bLastVisible(false)
92 // , m_depth(svn_depth_unknown)
93 , m_itemCount(-1)
94 , m_itemCountTotal(-1)
95 , m_AlwaysConflicted(false)
96 , m_BugTraqProvider(NULL)
97 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
98 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
99 #endif
103 CGitProgressDlg::~CGitProgressDlg()
105 for (size_t i = 0; i < m_arData.size(); ++i)
107 delete m_arData[i];
109 if(m_pThread != NULL)
111 delete m_pThread;
115 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
117 CResizableStandAloneDialog::DoDataExchange(pDX);
118 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
119 DDX_Control(pDX, IDC_TITLE_ANIMATE, m_Animate);
122 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
123 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
124 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
125 ON_WM_CLOSE()
126 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
127 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
128 ON_WM_SETCURSOR()
129 ON_WM_CONTEXTMENU()
130 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
131 ON_WM_TIMER()
132 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
133 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
134 ON_WM_SIZE()
135 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
136 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
137 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
138 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
139 ON_WM_CTLCOLOR()
140 END_MESSAGE_MAP()
142 BOOL CGitProgressDlg::Cancel()
144 return m_bCancelled;
147 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
149 #if 0
150 CConflictResolveDlg dlg(this);
151 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
152 if (description)
154 dlg.SetConflictDescription(description);
155 if (m_pTaskbarList)
157 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
159 if (dlg.DoModal() == IDOK)
161 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
163 // if the result is conflicted and the dialog returned IDOK,
164 // that means we should not ask again in case of a conflict
165 m_AlwaysConflicted = true;
166 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
169 m_mergedfile = dlg.GetMergedFile();
170 m_bCancelled = dlg.IsCancelled();
171 if (m_pTaskbarList)
172 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
173 return dlg.GetResult();
176 return svn_wc_conflict_choose_postpone;
177 #endif
178 return 0;
180 #if 0
181 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
183 // we only bother the user when merging
184 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
186 // we're in a worker thread here. That means we must not show a dialog from the thread
187 // but let the UI thread do it.
188 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
189 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
190 mergedfile = m_mergedfile;
191 return (svn_wc_conflict_choice_t)dlgResult;
194 return svn_wc_conflict_choose_postpone;
196 #endif
197 void CGitProgressDlg::AddItemToList()
199 int totalcount = m_ProgList.GetItemCount();
201 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
202 // make columns width fit
203 if (iFirstResized < 30)
205 // only resize the columns for the first 30 or so entries.
206 // after that, don't resize them anymore because that's an
207 // expensive function call and the columns will be sized
208 // close enough already.
209 ResizeColumns();
210 ++iFirstResized;
213 // Make sure the item is *entirely* visible even if the horizontal
214 // scroll bar is visible.
215 int count = m_ProgList.GetCountPerPage();
216 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
218 ++nEnsureVisibleCount;
219 m_bLastVisible = true;
221 else
223 nEnsureVisibleCount = 0;
224 if (IsIconic() == 0)
225 m_bLastVisible = false;
230 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
231 int /*status*/ ,
232 CString *strErr
234 svn_node_kind_t kind, const CString& mime_type,
235 svn_wc_notify_state_t content_state,
236 svn_wc_notify_state_t prop_state, LONG rev,
237 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
238 const CString& changelistname,
239 svn_merge_range_t * range,
240 svn_error_t * err, apr_pool_t * pool
243 bool bNoNotify = false;
244 bool bDoAddData = true;
245 NotificationData * data = new NotificationData();
246 data->path = path;
247 data->action = action;
248 data->sPathColumnText=path.GetGitPathString();
249 data->bAuxItem = false;
251 this->m_Animate.ShowWindow(SW_HIDE);
253 #if 0
254 data->kind = kind;
255 data->mime_type = mime_type;
256 data->content_state = content_state;
257 data->prop_state = prop_state;
258 data->rev = rev;
259 data->lock_state = lock_state;
260 data->changelistname = changelistname;
261 if ((lock)&&(lock->owner))
262 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
263 data->sPathColumnText = path.GetUIPathString();
264 if (!m_basePath.IsEmpty())
265 data->basepath = m_basePath;
266 if (range)
267 data->merge_range = *range;
268 #endif
269 switch (data->action)
271 case git_wc_notify_add:
272 //case svn_wc_notify_update_add:
273 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
274 // {
275 // data->color = m_Colors.GetColor(CColors::Conflict);
276 // data->bConflictedActionItem = true;
277 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
278 // ++m_nConflicts;
279 // }
280 // else
281 // {
282 // m_bMergesAddsDeletesOccurred = true;
283 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
284 data->color = m_Colors.GetColor(CColors::Added);
285 // }
286 break;
287 case git_wc_notify_sendmail_start:
288 data->bAuxItem = true;
289 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
290 data->color = m_Colors.GetColor(CColors::Modified);
291 break;
293 case git_wc_notify_sendmail_error:
294 data->bAuxItem = true;
295 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
296 if(strErr)
297 data->sPathColumnText = *strErr;
298 else
299 data->sPathColumnText.Empty();
300 data->color = m_Colors.GetColor(CColors::Modified);
301 break;
303 case git_wc_notify_sendmail_done:
305 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
306 data->sPathColumnText.Empty();
307 data->color = m_Colors.GetColor(CColors::Modified);
308 break;
310 case git_wc_notify_sendmail_retry:
311 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
312 data->sPathColumnText.Empty();
313 data->color = m_Colors.GetColor(CColors::Modified);
314 break;
317 case git_wc_notify_resolved:
318 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
319 break;
321 case git_wc_notify_revert:
322 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
323 break;
325 case git_wc_notify_checkout:
326 data->sActionColumnText.LoadString(IDS_PROGRS_CMD_CHECKOUT);
327 data->color = m_Colors.GetColor(CColors::Added);
328 data->bAuxItem = false;
329 break;
331 #if 0
332 case svn_wc_notify_commit_added:
333 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
334 data->color = m_Colors.GetColor(CColors::Added);
335 break;
336 case svn_wc_notify_copy:
337 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
338 break;
339 case svn_wc_notify_commit_modified:
340 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
341 data->color = m_Colors.GetColor(CColors::Modified);
342 break;
343 case svn_wc_notify_delete:
344 case svn_wc_notify_update_delete:
345 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
346 m_bMergesAddsDeletesOccurred = true;
347 data->color = m_Colors.GetColor(CColors::Deleted);
348 break;
349 case svn_wc_notify_commit_deleted:
350 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
351 data->color = m_Colors.GetColor(CColors::Deleted);
352 break;
353 case svn_wc_notify_restore:
354 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
355 break;
357 case svn_wc_notify_update_replace:
358 case svn_wc_notify_commit_replaced:
359 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
360 data->color = m_Colors.GetColor(CColors::Deleted);
361 break;
362 case svn_wc_notify_exists:
363 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
365 data->color = m_Colors.GetColor(CColors::Conflict);
366 data->bConflictedActionItem = true;
367 ++m_nConflicts;
368 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
370 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
372 data->color = m_Colors.GetColor(CColors::Merged);
373 m_bMergesAddsDeletesOccurred = true;
374 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
376 else
377 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
378 break;
379 case svn_wc_notify_update_update:
380 // if this is an inoperative dir change, don't show the notification.
381 // an inoperative dir change is when a directory gets updated without
382 // any real change in either text or properties.
383 if ((kind == svn_node_dir)
384 && ((prop_state == svn_wc_notify_state_inapplicable)
385 || (prop_state == svn_wc_notify_state_unknown)
386 || (prop_state == svn_wc_notify_state_unchanged)))
388 bNoNotify = true;
389 break;
391 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
393 data->color = m_Colors.GetColor(CColors::Conflict);
394 data->bConflictedActionItem = true;
395 ++m_nConflicts;
396 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
398 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
400 data->color = m_Colors.GetColor(CColors::Merged);
401 m_bMergesAddsDeletesOccurred = true;
402 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
404 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
405 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
407 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
409 else
411 bNoNotify = true;
412 break;
414 if (lock_state == svn_wc_notify_lock_state_unlocked)
416 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
417 data->sActionColumnText += _T(", ") + temp;
419 break;
421 case svn_wc_notify_update_external:
422 // For some reason we build a list of externals...
423 m_ExtStack.AddHead(path.GetUIPathString());
424 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
425 data->bAuxItem = true;
426 break;
428 case svn_wc_notify_update_completed:
430 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
431 data->bAuxItem = true;
432 bool bEmpty = !!m_ExtStack.IsEmpty();
433 if (!bEmpty)
434 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
435 else
436 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
438 if ((m_nConflicts>0)&&(bEmpty))
440 // We're going to add another aux item - let's shove this current onto the list first
441 // I don't really like this, but it will do for the moment.
442 m_arData.push_back(data);
443 AddItemToList();
445 data = new NotificationData();
446 data->bAuxItem = true;
447 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
448 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
449 data->color = m_Colors.GetColor(CColors::Conflict);
450 CSoundUtils::PlayTSVNWarning();
451 // This item will now be added after the switch statement
453 if (!m_basePath.IsEmpty())
454 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
455 m_RevisionEnd = rev;
456 m_bFinishedItemAdded = true;
458 break;
459 case svn_wc_notify_commit_postfix_txdelta:
460 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
461 break;
462 case svn_wc_notify_failed_revert:
463 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
464 break;
465 case svn_wc_notify_status_completed:
466 case svn_wc_notify_status_external:
467 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
468 break;
469 case svn_wc_notify_skip:
470 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
472 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
474 // The color settings dialog describes the red color with
475 // "possible or real conflict / obstructed" which also applies to
476 // skipped targets during a merge. So we just use the same color.
477 data->color = m_Colors.GetColor(CColors::Conflict);
479 else
480 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
481 break;
482 case svn_wc_notify_locked:
483 if ((lock)&&(lock->owner))
484 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
485 break;
486 case svn_wc_notify_unlocked:
487 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
488 break;
489 case svn_wc_notify_failed_lock:
490 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
491 m_arData.push_back(data);
492 AddItemToList();
493 ReportError(SVN::GetErrorString(err));
494 bDoAddData = false;
495 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
496 m_bLockWarning = true;
497 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
498 m_bLockExists = true;
499 break;
500 case svn_wc_notify_failed_unlock:
501 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
502 m_arData.push_back(data);
503 AddItemToList();
504 ReportError(SVN::GetErrorString(err));
505 bDoAddData = false;
506 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
507 m_bLockWarning = true;
508 break;
509 case svn_wc_notify_changelist_set:
510 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
511 break;
512 case svn_wc_notify_changelist_clear:
513 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
514 break;
515 case svn_wc_notify_changelist_moved:
516 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
517 break;
518 case svn_wc_notify_foreign_merge_begin:
519 case svn_wc_notify_merge_begin:
520 if (range == NULL)
521 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
522 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
523 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
524 else if (data->merge_range.start - 1 == data->merge_range.end)
525 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
526 else if (data->merge_range.start < data->merge_range.end)
527 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
528 else
529 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
530 data->bAuxItem = true;
531 break;
532 #endif
533 default:
534 break;
535 } // switch (data->action)
537 if (bNoNotify)
538 delete data;
539 else
541 if (bDoAddData)
543 m_arData.push_back(data);
544 AddItemToList();
545 if ((!data->bAuxItem) && (m_itemCount > 0))
547 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
548 progControl->ShowWindow(SW_SHOW);
549 progControl->SetPos(m_itemCount);
550 progControl->SetRange32(0, m_itemCountTotal);
551 if (m_pTaskbarList)
553 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
554 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal - m_itemCount, m_itemCountTotal);
555 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCount, m_itemCountTotal);
559 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
561 // ResizeColumns();
562 // bSecondResized = TRUE;
566 return TRUE;
570 CString CGitProgressDlg::BuildInfoString()
572 CString infotext;
573 if(this->m_Command == GitProgress_Resolve)
574 infotext = _T("You need commit your change after resolve conflict");
575 #if 0
577 CString temp;
578 int added = 0;
579 int copied = 0;
580 int deleted = 0;
581 int restored = 0;
582 int reverted = 0;
583 int resolved = 0;
584 int conflicted = 0;
585 int updated = 0;
586 int merged = 0;
587 int modified = 0;
588 int skipped = 0;
589 int replaced = 0;
591 for (size_t i=0; i<m_arData.size(); ++i)
593 const NotificationData * dat = m_arData[i];
594 switch (dat->action)
596 case svn_wc_notify_add:
597 case svn_wc_notify_update_add:
598 case svn_wc_notify_commit_added:
599 if (dat->bConflictedActionItem)
600 ++conflicted;
601 else
602 ++added;
603 break;
604 case svn_wc_notify_copy:
605 ++copied;
606 break;
607 case svn_wc_notify_delete:
608 case svn_wc_notify_update_delete:
609 case svn_wc_notify_commit_deleted:
610 ++deleted;
611 break;
612 case svn_wc_notify_restore:
613 ++restored;
614 break;
615 case svn_wc_notify_revert:
616 ++reverted;
617 break;
618 case svn_wc_notify_resolved:
619 ++resolved;
620 break;
621 case svn_wc_notify_update_update:
622 if (dat->bConflictedActionItem)
623 ++conflicted;
624 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
625 ++merged;
626 else
627 ++updated;
628 break;
629 case svn_wc_notify_commit_modified:
630 ++modified;
631 break;
632 case svn_wc_notify_skip:
633 ++skipped;
634 break;
635 case svn_wc_notify_commit_replaced:
636 ++replaced;
637 break;
640 if (conflicted)
642 temp.LoadString(IDS_SVNACTION_CONFLICTED);
643 infotext += temp;
644 temp.Format(_T(":%d "), conflicted);
645 infotext += temp;
647 if (skipped)
649 temp.LoadString(IDS_SVNACTION_SKIP);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), skipped);
653 if (merged)
655 temp.LoadString(IDS_SVNACTION_MERGED);
656 infotext += temp;
657 infotext.AppendFormat(_T(":%d "), merged);
659 if (added)
661 temp.LoadString(IDS_SVNACTION_ADD);
662 infotext += temp;
663 infotext.AppendFormat(_T(":%d "), added);
665 if (deleted)
667 temp.LoadString(IDS_SVNACTION_DELETE);
668 infotext += temp;
669 infotext.AppendFormat(_T(":%d "), deleted);
671 if (modified)
673 temp.LoadString(IDS_SVNACTION_MODIFIED);
674 infotext += temp;
675 infotext.AppendFormat(_T(":%d "), modified);
677 if (copied)
679 temp.LoadString(IDS_SVNACTION_COPY);
680 infotext += temp;
681 infotext.AppendFormat(_T(":%d "), copied);
683 if (replaced)
685 temp.LoadString(IDS_SVNACTION_REPLACED);
686 infotext += temp;
687 infotext.AppendFormat(_T(":%d "), replaced);
689 if (updated)
691 temp.LoadString(IDS_SVNACTION_UPDATE);
692 infotext += temp;
693 infotext.AppendFormat(_T(":%d "), updated);
695 if (restored)
697 temp.LoadString(IDS_SVNACTION_RESTORE);
698 infotext += temp;
699 infotext.AppendFormat(_T(":%d "), restored);
701 if (reverted)
703 temp.LoadString(IDS_SVNACTION_REVERT);
704 infotext += temp;
705 infotext.AppendFormat(_T(":%d "), reverted);
707 if (resolved)
709 temp.LoadString(IDS_SVNACTION_RESOLVE);
710 infotext += temp;
711 infotext.AppendFormat(_T(":%d "), resolved);
713 #endif
714 return infotext;
717 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
719 m_selectedPaths = selPaths;
722 void CGitProgressDlg::ResizeColumns()
724 m_ProgList.SetRedraw(FALSE);
726 TCHAR textbuf[MAX_PATH];
728 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
729 for (int col = 0; col <= maxcol; ++col)
731 // find the longest width of all items
732 int count = m_ProgList.GetItemCount();
733 HDITEM hdi = {0};
734 hdi.mask = HDI_TEXT;
735 hdi.pszText = textbuf;
736 hdi.cchTextMax = sizeof(textbuf);
737 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
738 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
740 for (int index = 0; index<count; ++index)
742 // get the width of the string and add 12 pixels for the column separator and margins
743 int linewidth = cx;
744 switch (col)
746 case 0:
747 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
748 break;
749 case 1:
750 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
751 break;
753 if (cx < linewidth)
754 cx = linewidth;
756 m_ProgList.SetColumnWidth(col, cx);
759 m_ProgList.SetRedraw(TRUE);
762 BOOL CGitProgressDlg::OnInitDialog()
764 __super::OnInitDialog();
766 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
767 // do this, Explorer would be unable to send that message to our window if we
768 // were running elevated. It's OK to make the call all the time, since if we're
769 // not elevated, this is a no-op.
770 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
771 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
772 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
773 if (hUser)
775 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
776 if (pfnChangeWindowMessageFilterEx)
778 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
781 m_pTaskbarList.Release();
782 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
783 m_pTaskbarList = nullptr;
785 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
787 m_ProgList.DeleteAllItems();
788 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
789 while (c>=0)
790 m_ProgList.DeleteColumn(c--);
791 CString temp;
792 temp.LoadString(IDS_PROGRS_ACTION);
793 m_ProgList.InsertColumn(0, temp);
794 temp.LoadString(IDS_PROGRS_PATH);
795 m_ProgList.InsertColumn(1, temp);
797 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
798 if (m_pThread==NULL)
800 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
802 else
804 m_pThread->m_bAutoDelete = FALSE;
805 m_pThread->ResumeThread();
808 UpdateData(FALSE);
810 // Call this early so that the column headings aren't hidden before any
811 // text gets added.
812 ResizeColumns();
814 SetTimer(VISIBLETIMER, 300, NULL);
816 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
817 AddAnchor(IDC_TITLE_ANIMATE, TOP_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
819 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
820 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
821 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
822 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
823 AddAnchor(IDOK, BOTTOM_RIGHT);
824 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
825 //SetPromptParentWindow(this->m_hWnd);
827 m_Animate.Open(IDR_DOWNLOAD);
829 if (hWndExplorer)
830 CenterWindow(CWnd::FromHandle(hWndExplorer));
831 EnableSaveRestore(_T("GITProgressDlg"));
833 m_background_brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
834 return TRUE;
837 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
839 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
842 void CGitProgressDlg::ReportGitError()
844 ReportError(CGit::GetLibGit2LastErr());
847 void CGitProgressDlg::ReportError(const CString& sError)
849 CSoundUtils::PlayTGitError();
850 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
851 m_bErrorsOccurred = true;
854 void CGitProgressDlg::ReportWarning(const CString& sWarning)
856 CSoundUtils::PlayTGitWarning();
857 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
860 void CGitProgressDlg::ReportNotification(const CString& sNotification)
862 CSoundUtils::PlayTGitNotification();
863 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
866 void CGitProgressDlg::ReportCmd(const CString& sCmd)
868 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
871 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
873 // instead of showing a dialog box with the error message or notification,
874 // just insert the error text into the list control.
875 // that way the user isn't 'interrupted' by a dialog box popping up!
877 // the message may be split up into different lines
878 // so add a new entry for each line of the message
879 while (!sMessage.IsEmpty())
881 NotificationData * data = new NotificationData();
882 data->bAuxItem = true;
883 data->sActionColumnText = sMsgKind;
884 if (sMessage.Find('\n')>=0)
885 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
886 else
887 data->sPathColumnText = sMessage;
888 data->sPathColumnText.Trim(_T("\n\r"));
889 data->color = color;
890 if (sMessage.Find('\n')>=0)
892 sMessage = sMessage.Mid(sMessage.Find('\n'));
893 sMessage.Trim(_T("\n\r"));
895 else
896 sMessage.Empty();
897 m_arData.push_back(data);
898 AddItemToList();
902 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
904 return ((CGitProgressDlg*)pVoid)->ProgressThread();
907 UINT CGitProgressDlg::ProgressThread()
909 // The SetParams function should have loaded something for us
911 CString temp;
912 CString sWindowTitle;
913 bool localoperation = false;
914 bool bSuccess = false;
915 m_AlwaysConflicted = false;
917 DialogEnableWindow(IDOK, FALSE);
918 DialogEnableWindow(IDCANCEL, TRUE);
919 // SetAndClearProgressInfo(m_hWnd);
920 m_itemCount = m_itemCountTotal;
922 InterlockedExchange(&m_bThreadRunning, TRUE);
923 iFirstResized = 0;
924 bSecondResized = FALSE;
925 m_bFinishedItemAdded = false;
926 CTime startTime = CTime::GetCurrentTime();
928 if (m_pTaskbarList)
929 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
931 switch (m_Command)
933 case GitProgress_Add:
934 bSuccess = CmdAdd(sWindowTitle, localoperation);
935 break;
936 case GitProgress_Copy:
937 bSuccess = CmdCopy(sWindowTitle, localoperation);
938 break;
939 case GitProgress_Export:
940 bSuccess = CmdExport(sWindowTitle, localoperation);
941 break;
942 case GitProgress_Rename:
943 bSuccess = CmdRename(sWindowTitle, localoperation);
944 break;
945 case GitProgress_Resolve:
946 bSuccess = CmdResolve(sWindowTitle, localoperation);
947 break;
948 case GitProgress_Revert:
949 bSuccess = CmdRevert(sWindowTitle, localoperation);
950 break;
951 case GitProgress_Switch:
952 bSuccess = CmdSwitch(sWindowTitle, localoperation);
953 break;
954 case GitProgress_SendMail:
955 bSuccess = CmdSendMail(sWindowTitle, localoperation);
956 break;
957 case GitProgress_Clone:
958 bSuccess = CmdClone(sWindowTitle, localoperation);
959 break;
960 case GitProgress_Fetch:
961 bSuccess = CmdFetch(sWindowTitle, localoperation);
962 break;
964 if (!bSuccess)
965 temp.LoadString(IDS_PROGRS_TITLEFAILED);
966 else
967 temp.LoadString(IDS_PROGRS_TITLEFIN);
968 sWindowTitle = sWindowTitle + _T(" ") + temp;
969 SetWindowText(sWindowTitle);
971 KillTimer(TRANSFERTIMER);
972 KillTimer(VISIBLETIMER);
974 if (m_pTaskbarList)
976 if (DidErrorsOccur())
978 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
979 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
981 else
982 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
985 DialogEnableWindow(IDCANCEL, FALSE);
986 DialogEnableWindow(IDOK, TRUE);
988 CString info = BuildInfoString();
989 if (!bSuccess)
990 info.LoadString(IDS_PROGRS_INFOFAILED);
991 SetDlgItemText(IDC_INFOTEXT, info);
992 ResizeColumns();
993 CWnd * pWndOk = GetDlgItem(IDOK);
994 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
996 SendMessage(DM_SETDEFID, IDOK);
997 GetDlgItem(IDOK)->SetFocus();
1000 CString sFinalInfo;
1001 if (!m_sTotalBytesTransferred.IsEmpty())
1003 CTimeSpan time = CTime::GetCurrentTime() - startTime;
1004 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
1005 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
1006 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
1008 else
1009 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
1011 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
1013 if (!m_bFinishedItemAdded)
1015 // there's no "finished: xxx" line at the end. We add one here to make
1016 // sure the user sees that the command is actually finished.
1017 NotificationData * data = new NotificationData();
1018 data->bAuxItem = true;
1019 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1020 m_arData.push_back(data);
1021 AddItemToList();
1024 int count = m_ProgList.GetItemCount();
1025 if ((count > 0)&&(m_bLastVisible))
1026 m_ProgList.EnsureVisible(count-1, FALSE);
1028 CLogFile logfile;
1029 if (logfile.Open())
1031 logfile.AddTimeLine();
1032 for (size_t i = 0; i < m_arData.size(); ++i)
1034 NotificationData * data = m_arData[i];
1035 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1036 logfile.AddLine(temp);
1038 if (!sFinalInfo.IsEmpty())
1039 logfile.AddLine(sFinalInfo);
1040 logfile.Close();
1043 m_bCancelled = TRUE;
1044 InterlockedExchange(&m_bThreadRunning, FALSE);
1045 RefreshCursor();
1047 #if 0
1048 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1049 if (m_options & ProgOptDryRun)
1050 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1051 if (!m_bLastVisible)
1052 dwAutoClose = 0;
1053 if (m_dwCloseOnEnd != (DWORD)-1)
1054 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1055 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1056 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1057 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1058 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1059 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1060 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1061 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1062 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1063 #endif
1065 //Don't do anything here which might cause messages to be sent to the window
1066 //The window thread is probably now blocked in OnOK if we've done an auto close
1067 return 0;
1070 void CGitProgressDlg::OnBnClickedLogbutton()
1072 switch(this->m_Command)
1074 case GitProgress_Add:
1075 case GitProgress_Resolve:
1077 CString cmd = _T(" /command:commit");
1078 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1080 CAppUtils::RunTortoiseGitProc(cmd);
1081 this->EndDialog(IDOK);
1082 break;
1085 #if 0
1086 if (m_targetPathList.GetCount() != 1)
1087 return;
1088 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1089 svn_revnum_t rev = -1;
1090 if (it != m_UpdateStartRevMap.end())
1092 rev = it->second;
1094 CLogDlg dlg;
1095 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1096 dlg.DoModal();
1097 #endif
1101 void CGitProgressDlg::OnClose()
1103 if (m_bCancelled)
1105 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1106 InterlockedExchange(&m_bThreadRunning, FALSE);
1108 else
1110 m_bCancelled = TRUE;
1111 return;
1113 DialogEnableWindow(IDCANCEL, TRUE);
1114 __super::OnClose();
1117 void CGitProgressDlg::OnOK()
1119 if ((m_bCancelled)&&(!m_bThreadRunning))
1121 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1122 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1123 // don't do any more operations on the window which might require message passing
1124 // If you try to send windows messages once we're waiting here, then the thread can't finished
1125 // because the Window's message loop is blocked at this wait
1126 WaitForSingleObject(m_pThread->m_hThread, 10000);
1127 __super::OnOK();
1129 m_bCancelled = TRUE;
1132 void CGitProgressDlg::OnCancel()
1134 if ((m_bCancelled)&&(!m_bThreadRunning))
1135 __super::OnCancel();
1136 m_bCancelled = TRUE;
1139 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1141 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1143 if (pDispInfo)
1145 if (pDispInfo->item.mask & LVIF_TEXT)
1147 if (pDispInfo->item.iItem < (int)m_arData.size())
1149 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1150 switch (pDispInfo->item.iSubItem)
1152 case 0:
1153 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1154 break;
1155 case 1:
1156 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1157 if (!data->bAuxItem)
1159 int cWidth = m_ProgList.GetColumnWidth(1);
1160 cWidth = max(12, cWidth-12);
1161 CDC * pDC = m_ProgList.GetDC();
1162 if (pDC != NULL)
1164 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1165 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1166 pDC->SelectObject(pFont);
1167 ReleaseDC(pDC);
1170 break;
1171 default:
1172 m_columnbuf[0] = 0;
1174 pDispInfo->item.pszText = m_columnbuf;
1178 *pResult = 0;
1181 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1183 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1185 // Take the default processing unless we set this to something else below.
1186 *pResult = CDRF_DODEFAULT;
1188 // First thing - check the draw stage. If it's the control's prepaint
1189 // stage, then tell Windows we want messages for every item.
1191 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1193 *pResult = CDRF_NOTIFYITEMDRAW;
1195 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1197 // This is the prepaint stage for an item. Here's where we set the
1198 // item's text color. Our return value will tell Windows to draw the
1199 // item itself, but it will use the new color we set here.
1201 // Tell Windows to paint the control itself.
1202 *pResult = CDRF_DODEFAULT;
1204 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1205 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1207 return;
1209 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1210 ASSERT(data != NULL);
1211 if (data == NULL)
1212 return;
1214 // Store the color back in the NMLVCUSTOMDRAW struct.
1215 pLVCD->clrText = data->color;
1219 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1221 #if 0
1222 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1223 *pResult = 0;
1224 if (pNMLV->iItem < 0)
1225 return;
1226 if (m_options & ProgOptDryRun)
1227 return; //don't do anything in a dry-run.
1229 const NotificationData * data = m_arData[pNMLV->iItem];
1230 if (data == NULL)
1231 return;
1233 if (data->bConflictedActionItem)
1235 // We've double-clicked on a conflicted item - do a three-way merge on it
1236 SVNDiff::StartConflictEditor(data->path);
1238 else if ((data->action == svn_wc_notify_update_update) && ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)) || (data->action == svn_wc_notify_resolved))
1240 // This is a modified file which has been merged on update. Diff it against base
1241 CTGitPath temporaryFile;
1242 SVNDiff diff(this, this->m_hWnd, true);
1243 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1244 svn_revnum_t baseRev = 0;
1245 diff.DiffFileAgainstBase(data->path, baseRev);
1247 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1249 bool bOpenWith = false;
1250 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1251 if (ret <= HINSTANCE_ERROR)
1252 bOpenWith = true;
1253 if (bOpenWith)
1255 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1256 cmd += data->path.GetWinPathString() + _T(" ");
1257 CAppUtils::LaunchApplication(cmd, NULL, false);
1260 #endif
1263 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1265 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1266 if (m_bThreadRunning)
1267 return;
1268 if (m_nSortedColumn == phdr->iItem)
1269 m_bAscending = !m_bAscending;
1270 else
1271 m_bAscending = TRUE;
1272 m_nSortedColumn = phdr->iItem;
1273 Sort();
1275 CString temp;
1276 m_ProgList.SetRedraw(FALSE);
1277 m_ProgList.DeleteAllItems();
1278 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1280 m_ProgList.SetRedraw(TRUE);
1282 *pResult = 0;
1285 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1287 return pData->bAuxItem;
1289 BOOL CGitProgressDlg::Notify(const git_wc_notify_action_t action, CString str, const git_oid *a, const git_oid *b)
1291 NotificationData * data = new NotificationData();
1292 data->action = action;
1293 data->bAuxItem = false;
1295 if (action == git_wc_notify_update_ref)
1297 data->m_NewHash = b->id;
1298 data->m_OldHash = a->id;
1299 data->sActionColumnText.LoadString(IDS_GITACTION_UPDATE_REF);
1300 data->sPathColumnText.Format(_T("%s\t %s -> %s"), str,
1301 data->m_OldHash.ToString().Left(g_Git.GetShortHASHLength()),
1302 data->m_NewHash.ToString().Left(g_Git.GetShortHASHLength()));
1306 m_arData.push_back(data);
1307 AddItemToList();
1309 m_Animate.Stop();
1310 m_Animate.ShowWindow(SW_HIDE);
1311 return TRUE;
1313 BOOL CGitProgressDlg::Notify(const git_wc_notify_action_t /*action*/, const git_transfer_progress *stat)
1315 static unsigned int start = 0;
1316 unsigned int dt = GetCurrentTime() - start;
1317 size_t ds;
1318 double speed = 0;
1320 if (m_bCancelled)
1321 return FALSE;
1323 if (dt > 100)
1325 start = GetCurrentTime();
1326 ds = stat->received_bytes - m_TotalBytesTransferred;
1327 speed = ds * 1000.0/dt;
1328 m_TotalBytesTransferred = stat->received_bytes;
1330 else
1332 return TRUE;
1335 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1337 int progress;
1338 progress = stat->received_objects + stat->indexed_objects;
1340 if ((stat->total_objects > 1000) && (!progControl->IsWindowVisible()))
1342 progControl->ShowWindow(SW_SHOW);
1343 if (m_pTaskbarList)
1344 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1346 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1347 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1349 progControl->SetPos(progress);
1350 progControl->SetRange32(0, 2 * stat->total_objects);
1351 if (m_pTaskbarList)
1353 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1354 m_pTaskbarList->SetProgressValue(m_hWnd, progress, stat->total_objects);
1357 CString progText;
1358 if (stat->received_bytes < 1024)
1359 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, (int64_t)stat->received_bytes);
1360 else if (stat->received_bytes < 1200000)
1361 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, (int64_t)stat->received_bytes / 1024);
1362 else
1363 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)stat->received_bytes / 1024000.0));
1365 CString str;
1366 if(speed < 1024)
1367 str.Format(_T("%fB/s"), speed);
1368 else if(speed < 1024 * 1024)
1369 str.Format(_T("%.2fKB/s"), speed / 1024);
1370 else
1371 str.Format(_T("%.2fMB/s"), speed / 1024000.0);
1373 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)str);
1374 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1376 return TRUE;
1379 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1381 #if 0
1382 SVNProgress * pProgressData = (SVNProgress *)lParam;
1383 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1384 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1386 progControl->ShowWindow(SW_SHOW);
1387 if (m_pTaskbarList)
1388 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1390 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1392 progControl->ShowWindow(SW_HIDE);
1393 if (m_pTaskbarList)
1394 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1396 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1397 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1398 SetTimer(TRANSFERTIMER, 2000, NULL);
1399 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1401 progControl->SetPos((int)pProgressData->progress);
1402 progControl->SetRange32(0, (int)pProgressData->total);
1403 if (m_pTaskbarList)
1405 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1406 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1409 CString progText;
1410 if (pProgressData->overall_total < 1024)
1411 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1412 else if (pProgressData->overall_total < 1200000)
1413 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1414 else
1415 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1416 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1417 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1418 #endif
1419 return 0;
1422 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1424 if (nIDEvent == TRANSFERTIMER)
1426 CString progText;
1427 CString progSpeed;
1428 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1429 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1430 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1431 KillTimer(TRANSFERTIMER);
1433 if (nIDEvent == VISIBLETIMER)
1435 if (nEnsureVisibleCount)
1436 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1437 nEnsureVisibleCount = 0;
1441 void CGitProgressDlg::Sort()
1443 if(m_arData.size() < 2)
1445 return;
1448 // We need to sort the blocks which lie between the auxiliary entries
1449 // This is so that any aux data stays where it was
1450 NotificationDataVect::iterator actionBlockBegin;
1451 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1453 for(;;)
1455 // Search to the start of the non-aux entry in the next block
1456 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1457 if(actionBlockBegin == m_arData.end())
1459 // There are no more actions
1460 break;
1462 // Now search to find the end of the block
1463 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1464 // Now sort the block
1465 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1469 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1471 int result = 0;
1472 switch (m_nSortedColumn)
1474 case 0: //action column
1475 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1476 break;
1477 case 1: //path column
1478 // Compare happens after switch()
1479 break;
1480 default:
1481 break;
1484 // Sort by path if everything else is equal
1485 if (result == 0)
1487 result = CTGitPath::Compare(pData1->path, pData2->path);
1490 if (!m_bAscending)
1491 result = -result;
1492 return result < 0;
1495 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1497 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1499 // only show the wait cursor over the list control
1500 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1502 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1503 SetCursor(hCur);
1504 return TRUE;
1507 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1508 SetCursor(hCur);
1509 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1512 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1514 if (pMsg->message == WM_KEYDOWN)
1516 if (pMsg->wParam == VK_ESCAPE)
1518 // pressing the ESC key should close the dialog. But since we disabled the escape
1519 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1520 // this won't work.
1521 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1522 // the impression that the OK button was pressed.
1523 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1524 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1526 // since we convert ESC to RETURN, make sure the OK button has the focus.
1527 GetDlgItem(IDOK)->SetFocus();
1528 pMsg->wParam = VK_RETURN;
1531 if (pMsg->wParam == 'A')
1533 if (GetKeyState(VK_CONTROL)&0x8000)
1535 // Ctrl-A -> select all
1536 m_ProgList.SetSelectionMark(0);
1537 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1539 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1543 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1545 int selIndex = m_ProgList.GetSelectionMark();
1546 if (selIndex >= 0)
1548 if (GetKeyState(VK_CONTROL)&0x8000)
1550 //Ctrl-C -> copy to clipboard
1551 CString sClipdata;
1552 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1553 if (pos != NULL)
1555 while (pos)
1557 int nItem = m_ProgList.GetNextSelectedItem(pos);
1558 CString sAction = m_ProgList.GetItemText(nItem, 0);
1559 CString sPath = m_ProgList.GetItemText(nItem, 1);
1560 CString sMime = m_ProgList.GetItemText(nItem, 2);
1561 CString sLogCopyText;
1562 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1563 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1564 sClipdata += sLogCopyText;
1566 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1571 } // if (pMsg->message == WM_KEYDOWN)
1572 return __super::PreTranslateMessage(pMsg);
1575 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1577 if (m_options & ProgOptDryRun)
1578 return; // don't do anything in a dry-run.
1580 if (pWnd == &m_ProgList)
1582 int selIndex = m_ProgList.GetSelectionMark();
1583 if ((point.x == -1) && (point.y == -1))
1585 // Menu was invoked from the keyboard rather than by right-clicking
1586 CRect rect;
1587 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1588 m_ProgList.ClientToScreen(&rect);
1589 point = rect.CenterPoint();
1592 if ((selIndex >= 0)&&(!m_bThreadRunning))
1594 // entry is selected, thread has finished with updating so show the popup menu
1595 CIconMenu popup;
1596 if (popup.CreatePopupMenu())
1598 bool bAdded = false;
1599 NotificationData * data = m_arData[selIndex];
1600 if ((data)&&(!data->path.IsDirectory()))
1603 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1605 if (m_ProgList.GetSelectedCount() == 1)
1607 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1608 bAdded = true;
1612 if (data->bConflictedActionItem)
1614 if (m_ProgList.GetSelectedCount() == 1)
1616 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1617 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1618 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1620 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1621 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1623 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1624 popup.SetDefaultItem(ID_COMPARE, FALSE);
1626 if (m_ProgList.GetSelectedCount() == 1)
1628 if ((data->action == git_wc_notify_add)||
1629 (data->action == git_wc_notify_revert)||
1630 (data->action == git_wc_notify_resolved)||
1631 (data->action == git_wc_notify_checkout)||
1632 (data->action == git_wc_notify_update_ref))
1634 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1635 popup.AppendMenu(MF_SEPARATOR, NULL);
1636 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1637 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1638 bAdded = true;
1641 } // if ((data)&&(!data->path.IsDirectory()))
1642 if (m_ProgList.GetSelectedCount() == 1)
1644 if (data)
1646 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1647 CTGitPath path = CTGitPath(sPath);
1648 if (!sPath.IsEmpty())
1650 if (path.GetDirectory().Exists())
1652 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1653 bAdded = true;
1658 if (m_ProgList.GetSelectedCount() > 0)
1660 if (bAdded)
1661 popup.AppendMenu(MF_SEPARATOR, NULL);
1662 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1663 bAdded = true;
1665 if (bAdded)
1667 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1668 DialogEnableWindow(IDOK, FALSE);
1669 //this->SetPromptApp(&theApp);
1670 theApp.DoWaitCursor(1);
1671 bool bOpenWith = false;
1672 switch (cmd)
1674 case ID_COPY:
1676 CString sLines;
1677 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1678 while (pos)
1680 int nItem = m_ProgList.GetNextSelectedItem(pos);
1681 NotificationData * data = m_arData[nItem];
1682 if (data)
1684 sLines += data->sPathColumnText;
1685 sLines += _T("\r\n");
1688 sLines.TrimRight();
1689 if (!sLines.IsEmpty())
1691 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1694 break;
1695 case ID_EXPLORE:
1697 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1699 CTGitPath path = CTGitPath(sPath);
1700 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1702 break;
1703 #if 0
1704 case ID_COMPARE:
1706 svn_revnum_t rev = -1;
1707 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1708 if (data->basepath.IsEmpty())
1709 it = m_UpdateStartRevMap.begin();
1710 else
1711 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1712 if (it != m_UpdateStartRevMap.end())
1713 rev = it->second;
1714 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1715 if (data->content_state == svn_wc_notify_state_merged)
1717 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1718 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1719 SVN svn;
1720 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1722 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1723 DialogEnableWindow(IDOK, TRUE);
1724 break;
1726 // If necessary, convert the line-endings on the file before diffing
1727 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1729 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1730 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1732 temporaryFile.Reset();
1733 break;
1735 else
1737 newfile = temporaryFile;
1741 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1742 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1743 CString revname, wcname, basename;
1744 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1745 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1746 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1747 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1749 else
1751 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1752 SVN svn;
1753 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1755 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1756 DialogEnableWindow(IDOK, TRUE);
1757 break;
1759 else
1761 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1762 CString revname, wcname;
1763 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1764 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1765 CAppUtils::StartExtDiff(
1766 tempfile, data->path, revname, wcname,
1767 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1771 break;
1772 case ID_EDITCONFLICT:
1774 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1775 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1777 break;
1778 case ID_CONFLICTUSETHEIRS:
1779 case ID_CONFLICTUSEMINE:
1780 case ID_CONFLICTRESOLVE:
1782 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1783 switch (cmd)
1785 case ID_CONFLICTUSETHEIRS:
1786 result = svn_wc_conflict_choose_theirs_full;
1787 break;
1788 case ID_CONFLICTUSEMINE:
1789 result = svn_wc_conflict_choose_mine_full;
1790 break;
1791 case ID_CONFLICTRESOLVE:
1792 result = svn_wc_conflict_choose_merged;
1793 break;
1795 SVN svn;
1796 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1797 CString sResolvedPaths;
1798 while (pos)
1800 int nItem = m_ProgList.GetNextSelectedItem(pos);
1801 NotificationData * data = m_arData[nItem];
1802 if (data)
1804 if (data->bConflictedActionItem)
1806 if (!svn.Resolve(data->path, result, FALSE))
1808 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1809 DialogEnableWindow(IDOK, TRUE);
1810 break;
1812 else
1814 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1815 data->action = svn_wc_notify_resolved;
1816 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1817 data->bConflictedActionItem = false;
1818 m_nConflicts--;
1820 if (m_nConflicts==0)
1822 // When the last conflict is resolved we remove
1823 // the warning which we assume is in the last line.
1824 int nIndex = m_ProgList.GetItemCount()-1;
1825 VERIFY(m_ProgList.DeleteItem(nIndex));
1827 delete m_arData[nIndex];
1828 m_arData.pop_back();
1830 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1835 m_ProgList.Invalidate();
1836 CString info = BuildInfoString();
1837 SetDlgItemText(IDC_INFOTEXT, info);
1839 if (!sResolvedPaths.IsEmpty())
1841 CString msg;
1842 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1843 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1846 break;
1847 #endif
1848 case ID_LOG:
1850 CString cmd = _T("/command:log");
1851 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1852 if(data->action == git_wc_notify_update_ref)
1854 cmd += _T(" /path:\"") + GetPathFromColumnText(CString()) + _T("\"");
1855 if (!data->m_OldHash.IsEmpty())
1856 cmd += _T(" /startrev:") + data->m_OldHash.ToString();
1857 if (!data->m_NewHash.IsEmpty())
1858 cmd += _T(" /endrev:") + data->m_NewHash.ToString();
1860 else
1861 cmd += _T(" /path:\"") + sPath + _T("\"");
1862 CAppUtils::RunTortoiseGitProc(cmd);
1864 break;
1865 case ID_OPENWITH:
1866 bOpenWith = true;
1867 case ID_OPEN:
1869 int ret = 0;
1870 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1871 if (!bOpenWith)
1872 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1873 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1875 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1876 cmd += sWinPath + _T(" ");
1877 CAppUtils::LaunchApplication(cmd, NULL, false);
1881 DialogEnableWindow(IDOK, TRUE);
1882 theApp.DoWaitCursor(-1);
1883 } // if (bAdded)
1889 void CGitProgressDlg::OnEnSetfocusInfotext()
1891 CString sTemp;
1892 GetDlgItemText(IDC_INFOTEXT, sTemp);
1893 if (sTemp.IsEmpty())
1894 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1897 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1899 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1900 #if 0
1901 int selIndex = m_ProgList.GetSelectionMark();
1902 if (selIndex < 0)
1903 return;
1905 CDropFiles dropFiles; // class for creating DROPFILES struct
1907 int index;
1908 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1909 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1911 NotificationData * data = m_arData[index];
1913 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1915 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1917 dropFiles.AddFile( sPath );
1921 if ( dropFiles.GetCount()>0 )
1923 dropFiles.CreateStructure();
1925 #endif
1926 *pResult = 0;
1929 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1931 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1932 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1934 if(!m_ProgList.m_hWnd)
1935 return;
1937 int count = m_ProgList.GetItemCount();
1938 if (count > 0)
1939 m_ProgList.EnsureVisible(count-1, false);
1943 //////////////////////////////////////////////////////////////////////////
1944 /// commands
1945 //////////////////////////////////////////////////////////////////////////
1946 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1948 localoperation = true;
1949 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1950 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1951 SetBackgroundImage(IDI_ADD_BKG);
1952 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1954 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE) == TRUE)
1956 git_repository *repo = NULL;
1957 git_index *index;
1959 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1960 if (git_repository_open(&repo, gitdir.GetBuffer()))
1962 gitdir.ReleaseBuffer();
1963 ReportGitError();
1964 return false;
1966 gitdir.ReleaseBuffer();
1968 git_config * config;
1969 git_config_new(&config);
1971 CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
1972 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE))
1974 projectConfigA.ReleaseBuffer();
1975 ReportGitError();
1976 git_config_free(config);
1977 git_repository_free(repo);
1978 return false;
1980 projectConfigA.ReleaseBuffer();
1981 CString globalConfig = g_Git.GetGitGlobalConfig();
1982 if (PathFileExists(globalConfig))
1984 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1985 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE))
1987 globalConfigA.ReleaseBuffer();
1988 ReportGitError();
1989 git_config_free(config);
1990 git_repository_free(repo);
1991 return false;
1993 globalConfigA.ReleaseBuffer();
1995 CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig();
1996 if (PathFileExists(globalXDGConfig))
1998 CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8);
1999 if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE))
2001 globalXDGConfigA.ReleaseBuffer();
2002 ReportGitError();
2003 git_config_free(config);
2004 git_repository_free(repo);
2005 return false;
2007 globalXDGConfigA.ReleaseBuffer();
2009 CString systemConfig = g_Git.GetGitSystemConfig();
2010 if (!systemConfig.IsEmpty())
2012 CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8);
2013 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE))
2015 systemConfigA.ReleaseBuffer();
2016 ReportGitError();
2017 git_config_free(config);
2018 git_repository_free(repo);
2019 return false;
2021 systemConfigA.ReleaseBuffer();
2024 git_repository_set_config(repo, config);
2026 if (git_repository_index(&index, repo))
2028 ReportGitError();
2029 git_repository_free(repo);
2030 return false;
2032 if (git_index_read(index))
2034 ReportGitError();
2035 git_index_free(index);
2036 git_repository_free(repo);
2037 return false;
2040 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2042 if (git_index_add_bypath(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer()))
2044 ReportGitError();
2045 git_index_free(index);
2046 git_repository_free(repo);
2047 return false;
2049 Notify(m_targetPathList[i],git_wc_notify_add);
2052 if (git_index_write(index))
2054 ReportGitError();
2055 git_index_free(index);
2056 git_repository_free(repo);
2057 return false;
2060 git_index_free(index);
2061 git_repository_free(repo);
2063 else
2065 CMassiveGitTask mgt(L"add -f");
2066 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
2069 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2071 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2072 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2073 return true;
2076 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2078 #if 0
2079 ASSERT(m_targetPathList.GetCount() == 1);
2080 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2081 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2082 SetBackgroundImage(IDI_COPY_BKG);
2084 CString sCmdInfo;
2085 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2086 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2087 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2088 ReportCmd(sCmdInfo);
2090 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2092 ReportSVNError();
2093 return false;
2095 if (m_options & ProgOptSwitchAfterCopy)
2097 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2098 m_targetPathList[0].GetWinPath(),
2099 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2100 ReportCmd(sCmdInfo);
2101 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2103 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2105 ReportSVNError();
2106 return false;
2110 else
2112 if (SVN::PathIsURL(m_url))
2114 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2115 ReportNotification(sMsg);
2118 #endif
2119 return true;
2122 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2124 #if 0
2125 ASSERT(m_targetPathList.GetCount() == 1);
2126 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2127 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2128 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2129 SetBackgroundImage(IDI_EXPORT_BKG);
2130 CString eol;
2131 if (m_options & ProgOptEolCRLF)
2132 eol = _T("CRLF");
2133 if (m_options & ProgOptEolLF)
2134 eol = _T("LF");
2135 if (m_options & ProgOptEolCR)
2136 eol = _T("CR");
2137 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2138 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2140 ReportSVNError();
2141 return false;
2143 #endif
2144 return true;
2147 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2149 #if 0
2150 ASSERT(m_targetPathList.GetCount() == 1);
2151 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2152 localoperation = true;
2153 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2154 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2155 SetBackgroundImage(IDI_RENAME_BKG);
2156 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2157 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2159 ReportSVNError();
2160 return false;
2162 #endif
2163 return true;
2166 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2169 localoperation = true;
2170 ASSERT(m_targetPathList.GetCount() == 1);
2171 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2172 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2173 SetBackgroundImage(IDI_RESOLVE_BKG);
2174 // check if the file may still have conflict markers in it.
2175 //BOOL bMarkers = FALSE;
2177 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2179 CString cmd,out,tempmergefile;
2180 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2181 if (g_Git.Run(cmd, &out, CP_UTF8))
2183 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2184 m_bErrorsOccurred=true;
2185 return false;
2188 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2190 Notify(m_targetPathList[i],git_wc_notify_resolved);
2192 #if 0
2193 if ((m_options & ProgOptSkipConflictCheck) == 0)
2197 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2199 if (!m_targetPathList[fileindex].IsDirectory())
2201 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2202 CString strLine = _T("");
2203 while (file.ReadString(strLine))
2205 if (strLine.Find(_T("<<<<<<<"))==0)
2207 bMarkers = TRUE;
2208 break;
2211 file.Close();
2215 catch (CFileException* pE)
2217 TRACE(_T("CFileException in Resolve!\n"));
2218 TCHAR error[10000] = {0};
2219 pE->GetErrorMessage(error, 10000);
2220 ReportError(error);
2221 pE->Delete();
2222 return false;
2225 if (bMarkers)
2227 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2229 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2230 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2231 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2234 else
2236 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2237 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2238 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2240 #endif
2241 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2243 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON)));
2244 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2246 return true;
2249 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2252 localoperation = true;
2253 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2254 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2255 SetBackgroundImage(IDI_REVERT_BKG);
2257 CTGitPathList delList;
2258 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2260 CTGitPath path;
2261 int action;
2262 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2263 action = m_selectedPaths[i].m_Action;
2264 /* rename file can't delete because it needs original file*/
2265 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2266 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2267 delList.AddPath(path);
2269 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2270 delList.DeleteAllFiles(true);
2272 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2273 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2275 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2277 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2278 m_bErrorsOccurred=true;
2279 return false;
2281 Notify(m_selectedPaths[i],git_wc_notify_revert);
2284 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2286 return true;
2289 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2291 #if 0
2292 ASSERT(m_targetPathList.GetCount() == 1);
2293 SVNStatus st;
2294 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2295 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2296 SetBackgroundImage(IDI_SWITCH_BKG);
2297 LONG rev = 0;
2298 if (st.GetStatus(m_targetPathList[0]) != (-2))
2300 if (st.status->entry != NULL)
2302 rev = st.status->entry->revision;
2306 CString sCmdInfo;
2307 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2308 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2309 (LPCTSTR)m_Revision.ToString());
2310 ReportCmd(sCmdInfo);
2312 bool depthIsSticky = true;
2313 if (m_depth == svn_depth_unknown)
2314 depthIsSticky = false;
2315 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2317 ReportSVNError();
2318 return false;
2320 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2321 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2322 &&((LONG)m_RevisionEnd > (LONG)rev))
2324 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2326 #endif
2327 return true;
2329 bool CGitProgressDlg::CmdClone(CString& sWindowTitle, bool& /*localoperation*/)
2331 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
2333 // should never run to here
2334 ASSERT(FALSE);
2335 return false;
2337 this->m_TotalBytesTransferred = 0;
2339 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CLONE);
2340 CAppUtils::SetWindowTitle(m_hWnd, m_url.GetGitPathString(), sWindowTitle);
2341 SetBackgroundImage(IDI_SWITCH_BKG);
2342 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE)));
2344 if (m_url.IsEmpty() || m_targetPathList.GetCount() == 0)
2345 return false;
2347 CStringA url = CUnicodeUtils::GetMulti(m_url.GetGitPathString(), CP_UTF8);
2348 CStringA path = CUnicodeUtils::GetMulti(m_targetPathList[0].GetWinPathString(),CP_UTF8);
2350 git_repository *cloned_repo = NULL;
2351 git_remote *origin = NULL;
2352 git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
2354 int error = 0;
2356 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
2358 clone_opts.checkout_opts = checkout_opts;
2360 clone_opts.checkout_opts.checkout_strategy = m_bNoCheckout? GIT_CHECKOUT_NONE : GIT_CHECKOUT_SAFE_CREATE;
2361 clone_opts.checkout_opts.progress_cb = CheckoutCallback;
2362 clone_opts.checkout_opts.progress_payload = this;
2364 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
2366 callbacks.update_tips = RemoteUpdatetipsCallback;
2367 callbacks.progress = RemoteProgressCallback;
2368 callbacks.completion = RemoteCompletionCallback;
2369 callbacks.payload = this;
2371 clone_opts.remote_callbacks = &callbacks;
2373 if (!m_RefSpec.IsEmpty())
2374 clone_opts.checkout_branch = CUnicodeUtils::GetMulti(m_RefSpec, CP_UTF8).GetBuffer();
2376 clone_opts.fetch_progress_cb = FetchCallback;
2377 clone_opts.fetch_progress_payload = this;
2379 clone_opts.cred_acquire_cb = CAppUtils::Git2GetUserPassword;
2381 clone_opts.bare = m_bBare;
2383 m_Animate.ShowWindow(SW_SHOW);
2384 m_Animate.Play(0, INT_MAX, INT_MAX);
2385 error = git_clone(&cloned_repo, url, path, &clone_opts);
2386 m_Animate.Stop();
2387 m_Animate.ShowWindow(SW_HIDE);
2389 git_remote_free(origin);
2390 if (error)
2392 ReportGitError();
2393 return false;
2395 else if (cloned_repo)
2396 git_repository_free(cloned_repo);
2397 return true;
2400 void CGitProgressDlg::OnBnClickedNoninteractive()
2402 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2403 m_AlwaysConflicted = (res == BST_CHECKED);
2404 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2405 nonint = m_AlwaysConflicted;
2408 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2410 CString sPath = sColumnText;
2411 if (sPath.Find(':')<0)
2413 // the path is not absolute: add the common root of all paths to it
2414 sPath = g_Git.m_CurrentDir + _T("\\") + sColumnText;
2416 return sPath;
2419 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2421 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2422 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2423 //SetBackgroundImage(IDI_ADD_BKG);
2424 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2425 bool ret=true;
2426 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2428 CString error;
2429 CTGitPath path;
2430 Notify(path,git_wc_notify_sendmail_start);
2431 CString err;
2432 int retry=0;
2433 while(retry <3)
2435 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2437 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2438 ret = false;
2440 else
2442 break;
2445 ++retry;
2446 if (retry < 3)
2447 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2448 Sleep(2000);
2449 if(m_bCancelled)
2451 CString str;
2452 str.LoadString(IDS_SVN_USERCANCELLED);
2453 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2454 return false;
2457 if (ret)
2458 Notify(path,git_wc_notify_sendmail_done,ret);
2460 else
2462 for (int i = 0; ret && i < m_targetPathList.GetCount(); ++i)
2464 CPatch patch;
2465 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2467 int retry=0;
2468 while(retry<3)
2470 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2471 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2473 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2474 ret = false;
2477 else
2479 ret = true;
2480 break;
2482 ++retry;
2483 if (retry < 3)
2484 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2485 Sleep(2000);
2486 if(m_bCancelled)
2488 CString str;
2489 str.LoadString(IDS_SVN_USERCANCELLED);
2490 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2491 return false;
2494 if (ret)
2495 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2498 return ret;
2501 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2503 m_pTaskbarList.Release();
2504 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2505 return 0;
2508 HBRUSH CGitProgressDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
2510 HBRUSH hbr;
2511 if (pWnd->GetDlgCtrlID() == IDC_TITLE_ANIMATE)
2513 pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // add this
2514 pDC->SetBkMode(TRANSPARENT);
2515 return (HBRUSH)m_background_brush.GetSafeHandle();
2517 else
2518 hbr = CResizableStandAloneDialog::OnCtlColor(pDC, pWnd, nCtlColor);
2520 // TODO: Return a different brush if the default is not desired
2521 return hbr;
2523 LRESULT CGitProgressDlg::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
2525 HDC hDC = (HDC)wParam;
2526 HWND hwndCtl = (HWND)lParam;
2528 if (::GetDlgCtrlID(hwndCtl) == IDC_TITLE_ANIMATE)
2530 CDC *pDC = CDC::FromHandle(hDC);
2531 pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
2532 pDC->SetBkMode(TRANSPARENT);
2533 return (LRESULT)(HBRUSH)m_background_brush.GetSafeHandle();
2535 return FALSE;
2538 bool CGitProgressDlg::CmdFetch(CString& sWindowTitle, bool& /*localoperation*/)
2540 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
2542 // should never run to here
2543 ASSERT(0);
2544 return false;
2546 this->m_TotalBytesTransferred = 0;
2548 sWindowTitle.LoadString(IDS_PROGRS_TITLE_FETCH);
2549 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
2550 SetBackgroundImage(IDI_UPDATE_BKG);
2551 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH)));
2553 CStringA url = CUnicodeUtils::GetMulti(m_url.GetGitPathString(), CP_UTF8);
2554 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
2555 CStringA remotebranch = CUnicodeUtils::GetMulti(m_RefSpec, CP_UTF8);
2557 git_remote *remote = NULL;
2558 git_repository *repo = NULL;
2559 bool ret = true;
2563 if (git_repository_open(&repo, gitdir.GetBuffer()))
2565 gitdir.ReleaseBuffer();
2566 ReportGitError();
2567 ret = false;
2568 break;
2571 // first try with a named remote (e.g. "origin")
2572 if (git_remote_load(&remote, repo, url) < 0)
2574 // retry with repository located at a specific url
2575 if (git_remote_create_inmemory(&remote, repo, NULL, url) < 0)
2577 ReportGitError();
2578 ret = false;
2579 break;
2583 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
2585 callbacks.update_tips = RemoteUpdatetipsCallback;
2586 callbacks.progress = RemoteProgressCallback;
2587 callbacks.completion = RemoteCompletionCallback;
2588 callbacks.payload = this;
2590 git_remote_set_callbacks(remote, &callbacks);
2591 git_remote_set_cred_acquire_cb(remote, CAppUtils::Git2GetUserPassword, NULL);
2592 git_remote_set_autotag(remote, (git_remote_autotag_option_t)m_AutoTag);
2594 if (!remotebranch.IsEmpty() && git_remote_set_fetchspec(remote, remotebranch))
2596 ReportGitError();
2597 ret = false;
2598 break;
2601 m_Animate.ShowWindow(SW_SHOW);
2602 m_Animate.Play(0, INT_MAX, INT_MAX);
2604 // Connect to the remote end specifying that we want to fetch
2605 // information from it.
2606 if (git_remote_connect(remote, GIT_DIRECTION_FETCH) < 0) {
2607 ReportGitError();
2608 ret = false;
2609 break;
2612 // Download the packfile and index it. This function updates the
2613 // amount of received data and the indexer stats which lets you
2614 // inform the user about progress.
2615 if (git_remote_download(remote, FetchCallback, this) < 0) {
2616 ReportGitError();
2617 ret = false;
2618 break;
2621 m_Animate.ShowWindow(SW_HIDE);
2622 // Update the references in the remote's namespace to point to the
2623 // right commits. This may be needed even if there was no packfile
2624 // to download, which can happen e.g. when the branches have been
2625 // changed but all the neede objects are available locally.
2626 if (git_remote_update_tips(remote) < 0)
2628 ReportGitError();
2629 ret = false;
2630 break;
2633 git_remote_disconnect(remote);
2635 } while(0);
2637 git_remote_free(remote);
2638 git_repository_free(repo);
2639 m_Animate.ShowWindow(SW_HIDE);
2640 return ret;