added new log filter (for subject)
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blob73a5202bedbceeab962790f23f330cec97ff863c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 "git2.h"
47 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
49 BOOL CGitProgressDlg::m_bAscending = FALSE;
50 int CGitProgressDlg::m_nSortedColumn = -1;
52 #define TRANSFERTIMER 100
53 #define VISIBLETIMER 101
55 enum GITProgressDlgContextMenuCommands
57 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
58 ID_COMPARE = 1,
59 ID_EDITCONFLICT,
60 ID_CONFLICTRESOLVE,
61 ID_CONFLICTUSETHEIRS,
62 ID_CONFLICTUSEMINE,
63 ID_LOG,
64 ID_OPEN,
65 ID_OPENWITH,
66 ID_EXPLORE,
67 ID_COPY
70 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
71 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
72 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
73 , m_bCancelled(FALSE)
74 , m_pThread(NULL)
75 #if 0
76 , m_Revision(_T("HEAD"))
77 //, m_RevisionEnd(0)
78 , m_bLockWarning(false)
79 , m_bLockExists(false)
80 , m_bThreadRunning(FALSE)
81 , m_nConflicts(0)
82 , m_bErrorsOccurred(FALSE)
83 , m_bMergesAddsDeletesOccurred(FALSE)
85 , m_options(ProgOptNone)
86 , m_dwCloseOnEnd((DWORD)-1)
87 , m_bFinishedItemAdded(false)
88 , m_bLastVisible(false)
89 // , m_depth(svn_depth_unknown)
90 , m_itemCount(-1)
91 , m_itemCountTotal(-1)
92 , m_AlwaysConflicted(false)
93 , m_BugTraqProvider(NULL)
94 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
95 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
96 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
97 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
98 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
99 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
100 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
101 #endif
105 CGitProgressDlg::~CGitProgressDlg()
107 for (size_t i=0; i<m_arData.size(); i++)
109 delete m_arData[i];
111 if(m_pThread != NULL)
113 delete m_pThread;
117 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
119 CResizableStandAloneDialog::DoDataExchange(pDX);
120 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
123 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
124 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
125 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
126 ON_WM_CLOSE()
127 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
128 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
129 ON_WM_SETCURSOR()
130 ON_WM_CONTEXTMENU()
131 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
132 ON_WM_TIMER()
133 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
134 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
135 ON_WM_SIZE()
136 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
137 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
138 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
139 END_MESSAGE_MAP()
141 BOOL CGitProgressDlg::Cancel()
143 return m_bCancelled;
146 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
148 #if 0
149 CConflictResolveDlg dlg(this);
150 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
151 if (description)
153 dlg.SetConflictDescription(description);
154 if (dlg.DoModal() == IDOK)
156 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
158 // if the result is conflicted and the dialog returned IDOK,
159 // that means we should not ask again in case of a conflict
160 m_AlwaysConflicted = true;
161 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
164 m_mergedfile = dlg.GetMergedFile();
165 m_bCancelled = dlg.IsCancelled();
166 return dlg.GetResult();
169 return svn_wc_conflict_choose_postpone;
170 #endif
171 return 0;
173 #if 0
174 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
176 // we only bother the user when merging
177 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
179 // we're in a worker thread here. That means we must not show a dialog from the thread
180 // but let the UI thread do it.
181 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
182 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
183 mergedfile = m_mergedfile;
184 return (svn_wc_conflict_choice_t)dlgResult;
187 return svn_wc_conflict_choose_postpone;
189 #endif
190 void CGitProgressDlg::AddItemToList()
192 int totalcount = m_ProgList.GetItemCount();
194 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
195 // make columns width fit
196 if (iFirstResized < 30)
198 // only resize the columns for the first 30 or so entries.
199 // after that, don't resize them anymore because that's an
200 // expensive function call and the columns will be sized
201 // close enough already.
202 ResizeColumns();
203 iFirstResized++;
206 // Make sure the item is *entirely* visible even if the horizontal
207 // scroll bar is visible.
208 int count = m_ProgList.GetCountPerPage();
209 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
211 nEnsureVisibleCount++;
212 m_bLastVisible = true;
214 else
216 nEnsureVisibleCount = 0;
217 if (IsIconic() == 0)
218 m_bLastVisible = false;
223 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
224 int /*status*/ ,
225 CString *strErr
227 svn_node_kind_t kind, const CString& mime_type,
228 svn_wc_notify_state_t content_state,
229 svn_wc_notify_state_t prop_state, LONG rev,
230 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
231 const CString& changelistname,
232 svn_merge_range_t * range,
233 svn_error_t * err, apr_pool_t * pool
236 bool bNoNotify = false;
237 bool bDoAddData = true;
238 NotificationData * data = new NotificationData();
239 data->path = path;
240 data->action = action;
241 data->sPathColumnText=path.GetGitPathString();
242 data->bAuxItem = false;
243 #if 0
244 data->kind = kind;
245 data->mime_type = mime_type;
246 data->content_state = content_state;
247 data->prop_state = prop_state;
248 data->rev = rev;
249 data->lock_state = lock_state;
250 data->changelistname = changelistname;
251 if ((lock)&&(lock->owner))
252 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
253 data->sPathColumnText = path.GetUIPathString();
254 if (!m_basePath.IsEmpty())
255 data->basepath = m_basePath;
256 if (range)
257 data->merge_range = *range;
258 #endif
259 switch (data->action)
261 case git_wc_notify_add:
262 //case svn_wc_notify_update_add:
263 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
264 // {
265 // data->color = m_Colors.GetColor(CColors::Conflict);
266 // data->bConflictedActionItem = true;
267 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
268 // m_nConflicts++;
269 // }
270 // else
271 // {
272 // m_bMergesAddsDeletesOccurred = true;
273 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
274 data->color = m_Colors.GetColor(CColors::Added);
275 // }
276 break;
277 case git_wc_notify_sendmail_start:
278 data->bAuxItem = true;
279 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
280 data->color = m_Colors.GetColor(CColors::Modified);
281 break;
283 case git_wc_notify_sendmail_error:
284 data->bAuxItem = true;
285 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
286 if(strErr)
287 data->sPathColumnText = *strErr;
288 else
289 data->sPathColumnText.Empty();
290 data->color = m_Colors.GetColor(CColors::Modified);
291 break;
293 case git_wc_notify_sendmail_done:
295 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
296 data->sPathColumnText.Empty();
297 data->color = m_Colors.GetColor(CColors::Modified);
298 break;
300 case git_wc_notify_sendmail_retry:
301 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
302 data->sPathColumnText.Empty();
303 data->color = m_Colors.GetColor(CColors::Modified);
304 break;
307 case git_wc_notify_resolved:
308 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
309 break;
311 case git_wc_notify_revert:
312 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
313 break;
315 #if 0
316 case svn_wc_notify_commit_added:
317 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
318 data->color = m_Colors.GetColor(CColors::Added);
319 break;
320 case svn_wc_notify_copy:
321 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
322 break;
323 case svn_wc_notify_commit_modified:
324 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
325 data->color = m_Colors.GetColor(CColors::Modified);
326 break;
327 case svn_wc_notify_delete:
328 case svn_wc_notify_update_delete:
329 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
330 m_bMergesAddsDeletesOccurred = true;
331 data->color = m_Colors.GetColor(CColors::Deleted);
332 break;
333 case svn_wc_notify_commit_deleted:
334 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
335 data->color = m_Colors.GetColor(CColors::Deleted);
336 break;
337 case svn_wc_notify_restore:
338 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
339 break;
341 case svn_wc_notify_update_replace:
342 case svn_wc_notify_commit_replaced:
343 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
344 data->color = m_Colors.GetColor(CColors::Deleted);
345 break;
346 case svn_wc_notify_exists:
347 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
349 data->color = m_Colors.GetColor(CColors::Conflict);
350 data->bConflictedActionItem = true;
351 m_nConflicts++;
352 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
354 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
356 data->color = m_Colors.GetColor(CColors::Merged);
357 m_bMergesAddsDeletesOccurred = true;
358 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
360 else
361 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
362 break;
363 case svn_wc_notify_update_update:
364 // if this is an inoperative dir change, don't show the notification.
365 // an inoperative dir change is when a directory gets updated without
366 // any real change in either text or properties.
367 if ((kind == svn_node_dir)
368 && ((prop_state == svn_wc_notify_state_inapplicable)
369 || (prop_state == svn_wc_notify_state_unknown)
370 || (prop_state == svn_wc_notify_state_unchanged)))
372 bNoNotify = true;
373 break;
375 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
377 data->color = m_Colors.GetColor(CColors::Conflict);
378 data->bConflictedActionItem = true;
379 m_nConflicts++;
380 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
382 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
384 data->color = m_Colors.GetColor(CColors::Merged);
385 m_bMergesAddsDeletesOccurred = true;
386 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
388 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
389 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
391 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
393 else
395 bNoNotify = true;
396 break;
398 if (lock_state == svn_wc_notify_lock_state_unlocked)
400 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
401 data->sActionColumnText += _T(", ") + temp;
403 break;
405 case svn_wc_notify_update_external:
406 // For some reason we build a list of externals...
407 m_ExtStack.AddHead(path.GetUIPathString());
408 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
409 data->bAuxItem = true;
410 break;
412 case svn_wc_notify_update_completed:
414 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
415 data->bAuxItem = true;
416 bool bEmpty = !!m_ExtStack.IsEmpty();
417 if (!bEmpty)
418 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
419 else
420 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
422 if ((m_nConflicts>0)&&(bEmpty))
424 // We're going to add another aux item - let's shove this current onto the list first
425 // I don't really like this, but it will do for the moment.
426 m_arData.push_back(data);
427 AddItemToList();
429 data = new NotificationData();
430 data->bAuxItem = true;
431 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
432 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
433 data->color = m_Colors.GetColor(CColors::Conflict);
434 CSoundUtils::PlayTSVNWarning();
435 // This item will now be added after the switch statement
437 if (!m_basePath.IsEmpty())
438 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
439 m_RevisionEnd = rev;
440 m_bFinishedItemAdded = true;
442 break;
443 case svn_wc_notify_commit_postfix_txdelta:
444 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
445 break;
446 case svn_wc_notify_failed_revert:
447 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
448 break;
449 case svn_wc_notify_status_completed:
450 case svn_wc_notify_status_external:
451 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
452 break;
453 case svn_wc_notify_skip:
454 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
456 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
458 // The color settings dialog describes the red color with
459 // "possible or real conflict / obstructed" which also applies to
460 // skipped targets during a merge. So we just use the same color.
461 data->color = m_Colors.GetColor(CColors::Conflict);
463 else
464 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
465 break;
466 case svn_wc_notify_locked:
467 if ((lock)&&(lock->owner))
468 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
469 break;
470 case svn_wc_notify_unlocked:
471 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
472 break;
473 case svn_wc_notify_failed_lock:
474 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
475 m_arData.push_back(data);
476 AddItemToList();
477 ReportError(SVN::GetErrorString(err));
478 bDoAddData = false;
479 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
480 m_bLockWarning = true;
481 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
482 m_bLockExists = true;
483 break;
484 case svn_wc_notify_failed_unlock:
485 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
486 m_arData.push_back(data);
487 AddItemToList();
488 ReportError(SVN::GetErrorString(err));
489 bDoAddData = false;
490 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
491 m_bLockWarning = true;
492 break;
493 case svn_wc_notify_changelist_set:
494 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
495 break;
496 case svn_wc_notify_changelist_clear:
497 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
498 break;
499 case svn_wc_notify_changelist_moved:
500 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
501 break;
502 case svn_wc_notify_foreign_merge_begin:
503 case svn_wc_notify_merge_begin:
504 if (range == NULL)
505 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
506 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
507 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
508 else if (data->merge_range.start - 1 == data->merge_range.end)
509 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
510 else if (data->merge_range.start < data->merge_range.end)
511 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
512 else
513 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
514 data->bAuxItem = true;
515 break;
516 #endif
517 default:
518 break;
519 } // switch (data->action)
521 if (bNoNotify)
522 delete data;
523 else
525 if (bDoAddData)
527 m_arData.push_back(data);
528 AddItemToList();
529 if ((!data->bAuxItem) && (m_itemCount > 0))
531 m_itemCount--;
533 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
534 progControl->ShowWindow(SW_SHOW);
535 progControl->SetPos(m_itemCountTotal - m_itemCount);
536 progControl->SetRange32(0, m_itemCountTotal);
539 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
541 // ResizeColumns();
542 // bSecondResized = TRUE;
546 return TRUE;
550 CString CGitProgressDlg::BuildInfoString()
552 CString infotext;
553 if(this->m_Command == GitProgress_Resolve)
554 infotext = _T("You need commit your change after resolve conflict");
555 #if 0
557 CString temp;
558 int added = 0;
559 int copied = 0;
560 int deleted = 0;
561 int restored = 0;
562 int reverted = 0;
563 int resolved = 0;
564 int conflicted = 0;
565 int updated = 0;
566 int merged = 0;
567 int modified = 0;
568 int skipped = 0;
569 int replaced = 0;
571 for (size_t i=0; i<m_arData.size(); ++i)
573 const NotificationData * dat = m_arData[i];
574 switch (dat->action)
576 case svn_wc_notify_add:
577 case svn_wc_notify_update_add:
578 case svn_wc_notify_commit_added:
579 if (dat->bConflictedActionItem)
580 conflicted++;
581 else
582 added++;
583 break;
584 case svn_wc_notify_copy:
585 copied++;
586 break;
587 case svn_wc_notify_delete:
588 case svn_wc_notify_update_delete:
589 case svn_wc_notify_commit_deleted:
590 deleted++;
591 break;
592 case svn_wc_notify_restore:
593 restored++;
594 break;
595 case svn_wc_notify_revert:
596 reverted++;
597 break;
598 case svn_wc_notify_resolved:
599 resolved++;
600 break;
601 case svn_wc_notify_update_update:
602 if (dat->bConflictedActionItem)
603 conflicted++;
604 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
605 merged++;
606 else
607 updated++;
608 break;
609 case svn_wc_notify_commit_modified:
610 modified++;
611 break;
612 case svn_wc_notify_skip:
613 skipped++;
614 break;
615 case svn_wc_notify_commit_replaced:
616 replaced++;
617 break;
620 if (conflicted)
622 temp.LoadString(IDS_SVNACTION_CONFLICTED);
623 infotext += temp;
624 temp.Format(_T(":%d "), conflicted);
625 infotext += temp;
627 if (skipped)
629 temp.LoadString(IDS_SVNACTION_SKIP);
630 infotext += temp;
631 infotext.AppendFormat(_T(":%d "), skipped);
633 if (merged)
635 temp.LoadString(IDS_SVNACTION_MERGED);
636 infotext += temp;
637 infotext.AppendFormat(_T(":%d "), merged);
639 if (added)
641 temp.LoadString(IDS_SVNACTION_ADD);
642 infotext += temp;
643 infotext.AppendFormat(_T(":%d "), added);
645 if (deleted)
647 temp.LoadString(IDS_SVNACTION_DELETE);
648 infotext += temp;
649 infotext.AppendFormat(_T(":%d "), deleted);
651 if (modified)
653 temp.LoadString(IDS_SVNACTION_MODIFIED);
654 infotext += temp;
655 infotext.AppendFormat(_T(":%d "), modified);
657 if (copied)
659 temp.LoadString(IDS_SVNACTION_COPY);
660 infotext += temp;
661 infotext.AppendFormat(_T(":%d "), copied);
663 if (replaced)
665 temp.LoadString(IDS_SVNACTION_REPLACED);
666 infotext += temp;
667 infotext.AppendFormat(_T(":%d "), replaced);
669 if (updated)
671 temp.LoadString(IDS_SVNACTION_UPDATE);
672 infotext += temp;
673 infotext.AppendFormat(_T(":%d "), updated);
675 if (restored)
677 temp.LoadString(IDS_SVNACTION_RESTORE);
678 infotext += temp;
679 infotext.AppendFormat(_T(":%d "), restored);
681 if (reverted)
683 temp.LoadString(IDS_SVNACTION_REVERT);
684 infotext += temp;
685 infotext.AppendFormat(_T(":%d "), reverted);
687 if (resolved)
689 temp.LoadString(IDS_SVNACTION_RESOLVE);
690 infotext += temp;
691 infotext.AppendFormat(_T(":%d "), resolved);
693 #endif
694 return infotext;
697 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
699 m_selectedPaths = selPaths;
702 void CGitProgressDlg::ResizeColumns()
704 m_ProgList.SetRedraw(FALSE);
706 TCHAR textbuf[MAX_PATH];
708 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
709 for (int col = 0; col <= maxcol; col++)
711 // find the longest width of all items
712 int count = m_ProgList.GetItemCount();
713 HDITEM hdi = {0};
714 hdi.mask = HDI_TEXT;
715 hdi.pszText = textbuf;
716 hdi.cchTextMax = sizeof(textbuf);
717 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
718 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
720 for (int index = 0; index<count; ++index)
722 // get the width of the string and add 12 pixels for the column separator and margins
723 int linewidth = cx;
724 switch (col)
726 case 0:
727 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
728 break;
729 case 1:
730 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
731 break;
732 case 2:
733 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
734 break;
736 if (cx < linewidth)
737 cx = linewidth;
739 m_ProgList.SetColumnWidth(col, cx);
742 m_ProgList.SetRedraw(TRUE);
745 BOOL CGitProgressDlg::OnInitDialog()
747 __super::OnInitDialog();
749 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
751 m_ProgList.DeleteAllItems();
752 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
753 while (c>=0)
754 m_ProgList.DeleteColumn(c--);
755 CString temp;
756 temp.LoadString(IDS_PROGRS_ACTION);
757 m_ProgList.InsertColumn(0, temp);
758 temp.LoadString(IDS_PROGRS_PATH);
759 m_ProgList.InsertColumn(1, temp);
760 temp.LoadString(IDS_PROGRS_MIMETYPE);
761 m_ProgList.InsertColumn(2, temp);
763 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
764 if (m_pThread==NULL)
766 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
768 else
770 m_pThread->m_bAutoDelete = FALSE;
771 m_pThread->ResumeThread();
774 UpdateData(FALSE);
776 // Call this early so that the column headings aren't hidden before any
777 // text gets added.
778 ResizeColumns();
780 SetTimer(VISIBLETIMER, 300, NULL);
782 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
783 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
784 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
785 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
786 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
787 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
788 AddAnchor(IDOK, BOTTOM_RIGHT);
789 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
790 //SetPromptParentWindow(this->m_hWnd);
791 if (hWndExplorer)
792 CenterWindow(CWnd::FromHandle(hWndExplorer));
793 EnableSaveRestore(_T("GITProgressDlg"));
794 return TRUE;
797 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
799 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
802 void CGitProgressDlg::ReportGitError()
804 ReportError(CString(git_lasterror()));
807 void CGitProgressDlg::ReportError(const CString& sError)
809 CSoundUtils::PlayTGitError();
810 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
811 m_bErrorsOccurred = true;
814 void CGitProgressDlg::ReportWarning(const CString& sWarning)
816 CSoundUtils::PlayTGitWarning();
817 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
820 void CGitProgressDlg::ReportNotification(const CString& sNotification)
822 CSoundUtils::PlayTGitNotification();
823 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
826 void CGitProgressDlg::ReportCmd(const CString& sCmd)
828 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
831 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
833 // instead of showing a dialog box with the error message or notification,
834 // just insert the error text into the list control.
835 // that way the user isn't 'interrupted' by a dialog box popping up!
837 // the message may be split up into different lines
838 // so add a new entry for each line of the message
839 while (!sMessage.IsEmpty())
841 NotificationData * data = new NotificationData();
842 data->bAuxItem = true;
843 data->sActionColumnText = sMsgKind;
844 if (sMessage.Find('\n')>=0)
845 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
846 else
847 data->sPathColumnText = sMessage;
848 data->sPathColumnText.Trim(_T("\n\r"));
849 data->color = color;
850 if (sMessage.Find('\n')>=0)
852 sMessage = sMessage.Mid(sMessage.Find('\n'));
853 sMessage.Trim(_T("\n\r"));
855 else
856 sMessage.Empty();
857 m_arData.push_back(data);
858 AddItemToList();
862 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
864 return ((CGitProgressDlg*)pVoid)->ProgressThread();
867 UINT CGitProgressDlg::ProgressThread()
869 // The SetParams function should have loaded something for us
871 CString temp;
872 CString sWindowTitle;
873 bool localoperation = false;
874 bool bSuccess = false;
875 m_AlwaysConflicted = false;
877 DialogEnableWindow(IDOK, FALSE);
878 DialogEnableWindow(IDCANCEL, TRUE);
879 // SetAndClearProgressInfo(m_hWnd);
880 m_itemCount = m_itemCountTotal;
882 InterlockedExchange(&m_bThreadRunning, TRUE);
883 iFirstResized = 0;
884 bSecondResized = FALSE;
885 m_bFinishedItemAdded = false;
886 CTime startTime = CTime::GetCurrentTime();
887 switch (m_Command)
889 case GitProgress_Add:
890 bSuccess = CmdAdd(sWindowTitle, localoperation);
891 break;
892 case GitProgress_Copy:
893 bSuccess = CmdCopy(sWindowTitle, localoperation);
894 break;
895 case GitProgress_Export:
896 bSuccess = CmdExport(sWindowTitle, localoperation);
897 break;
898 case GitProgress_Rename:
899 bSuccess = CmdRename(sWindowTitle, localoperation);
900 break;
901 case GitProgress_Resolve:
902 bSuccess = CmdResolve(sWindowTitle, localoperation);
903 break;
904 case GitProgress_Revert:
905 bSuccess = CmdRevert(sWindowTitle, localoperation);
906 break;
907 case GitProgress_Switch:
908 bSuccess = CmdSwitch(sWindowTitle, localoperation);
909 break;
910 case GitProgress_SendMail:
911 bSuccess = CmdSendMail(sWindowTitle, localoperation);
912 break;
914 if (!bSuccess)
915 temp.LoadString(IDS_PROGRS_TITLEFAILED);
916 else
917 temp.LoadString(IDS_PROGRS_TITLEFIN);
918 sWindowTitle = sWindowTitle + _T(" ") + temp;
919 SetWindowText(sWindowTitle);
921 KillTimer(TRANSFERTIMER);
922 KillTimer(VISIBLETIMER);
924 DialogEnableWindow(IDCANCEL, FALSE);
925 DialogEnableWindow(IDOK, TRUE);
927 CString info = BuildInfoString();
928 if (!bSuccess)
929 info.LoadString(IDS_PROGRS_INFOFAILED);
930 SetDlgItemText(IDC_INFOTEXT, info);
931 ResizeColumns();
932 SendMessage(DM_SETDEFID, IDOK);
933 GetDlgItem(IDOK)->SetFocus();
935 CString sFinalInfo;
936 if (!m_sTotalBytesTransferred.IsEmpty())
938 CTimeSpan time = CTime::GetCurrentTime() - startTime;
939 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
940 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
941 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
943 else
944 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
946 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
948 if (!m_bFinishedItemAdded)
950 // there's no "finished: xxx" line at the end. We add one here to make
951 // sure the user sees that the command is actually finished.
952 NotificationData * data = new NotificationData();
953 data->bAuxItem = true;
954 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
955 m_arData.push_back(data);
956 AddItemToList();
959 int count = m_ProgList.GetItemCount();
960 if ((count > 0)&&(m_bLastVisible))
961 m_ProgList.EnsureVisible(count-1, FALSE);
963 CLogFile logfile;
964 if (logfile.Open())
966 logfile.AddTimeLine();
967 for (size_t i=0; i<m_arData.size(); i++)
969 NotificationData * data = m_arData[i];
970 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
971 logfile.AddLine(temp);
973 if (!sFinalInfo.IsEmpty())
974 logfile.AddLine(sFinalInfo);
975 logfile.Close();
978 m_bCancelled = TRUE;
979 InterlockedExchange(&m_bThreadRunning, FALSE);
980 RefreshCursor();
982 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"));
983 if (m_options & ProgOptDryRun)
984 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
985 if (!m_bLastVisible)
986 dwAutoClose = 0;
987 if (m_dwCloseOnEnd != (DWORD)-1)
988 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
989 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
990 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
991 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
992 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
993 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
994 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
995 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
996 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
998 //Don't do anything here which might cause messages to be sent to the window
999 //The window thread is probably now blocked in OnOK if we've done an auto close
1000 return 0;
1003 void CGitProgressDlg::OnBnClickedLogbutton()
1005 switch(this->m_Command)
1007 case GitProgress_Add:
1008 case GitProgress_Resolve:
1010 CString cmd;
1011 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
1012 cmd += _T(" /command:commit");
1014 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1016 CAppUtils::LaunchApplication(cmd,NULL,false);
1017 this->EndDialog(IDOK);
1018 break;
1021 #if 0
1022 if (m_targetPathList.GetCount() != 1)
1023 return;
1024 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1025 svn_revnum_t rev = -1;
1026 if (it != m_UpdateStartRevMap.end())
1028 rev = it->second;
1030 CLogDlg dlg;
1031 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1032 dlg.DoModal();
1033 #endif
1037 void CGitProgressDlg::OnClose()
1039 if (m_bCancelled)
1041 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1042 InterlockedExchange(&m_bThreadRunning, FALSE);
1044 else
1046 m_bCancelled = TRUE;
1047 return;
1049 DialogEnableWindow(IDCANCEL, TRUE);
1050 __super::OnClose();
1053 void CGitProgressDlg::OnOK()
1055 if ((m_bCancelled)&&(!m_bThreadRunning))
1057 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1058 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1059 // don't do any more operations on the window which might require message passing
1060 // If you try to send windows messages once we're waiting here, then the thread can't finished
1061 // because the Window's message loop is blocked at this wait
1062 WaitForSingleObject(m_pThread->m_hThread, 10000);
1063 __super::OnOK();
1065 m_bCancelled = TRUE;
1068 void CGitProgressDlg::OnCancel()
1070 if ((m_bCancelled)&&(!m_bThreadRunning))
1071 __super::OnCancel();
1072 m_bCancelled = TRUE;
1075 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1077 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1079 if (pDispInfo)
1081 if (pDispInfo->item.mask & LVIF_TEXT)
1083 if (pDispInfo->item.iItem < (int)m_arData.size())
1085 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1086 switch (pDispInfo->item.iSubItem)
1088 case 0:
1089 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1090 break;
1091 case 1:
1092 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1093 if (!data->bAuxItem)
1095 int cWidth = m_ProgList.GetColumnWidth(1);
1096 cWidth = max(12, cWidth-12);
1097 CDC * pDC = m_ProgList.GetDC();
1098 if (pDC != NULL)
1100 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1101 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1102 pDC->SelectObject(pFont);
1103 ReleaseDC(pDC);
1106 break;
1107 case 2:
1108 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1109 break;
1110 default:
1111 m_columnbuf[0] = 0;
1113 pDispInfo->item.pszText = m_columnbuf;
1117 *pResult = 0;
1120 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1122 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1124 // Take the default processing unless we set this to something else below.
1125 *pResult = CDRF_DODEFAULT;
1127 // First thing - check the draw stage. If it's the control's prepaint
1128 // stage, then tell Windows we want messages for every item.
1130 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1132 *pResult = CDRF_NOTIFYITEMDRAW;
1134 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1136 // This is the prepaint stage for an item. Here's where we set the
1137 // item's text color. Our return value will tell Windows to draw the
1138 // item itself, but it will use the new color we set here.
1140 // Tell Windows to paint the control itself.
1141 *pResult = CDRF_DODEFAULT;
1143 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1144 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1146 return;
1148 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1149 ASSERT(data != NULL);
1150 if (data == NULL)
1151 return;
1153 // Store the color back in the NMLVCUSTOMDRAW struct.
1154 pLVCD->clrText = data->color;
1158 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1160 #if 0
1161 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1162 *pResult = 0;
1163 if (pNMLV->iItem < 0)
1164 return;
1165 if (m_options & ProgOptDryRun)
1166 return; //don't do anything in a dry-run.
1168 const NotificationData * data = m_arData[pNMLV->iItem];
1169 if (data == NULL)
1170 return;
1172 if (data->bConflictedActionItem)
1174 // We've double-clicked on a conflicted item - do a three-way merge on it
1175 SVNDiff::StartConflictEditor(data->path);
1177 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))
1179 // This is a modified file which has been merged on update. Diff it against base
1180 CTGitPath temporaryFile;
1181 SVNDiff diff(this, this->m_hWnd, true);
1182 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1183 svn_revnum_t baseRev = 0;
1184 diff.DiffFileAgainstBase(data->path, baseRev);
1186 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1188 bool bOpenWith = false;
1189 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1190 if (ret <= HINSTANCE_ERROR)
1191 bOpenWith = true;
1192 if (bOpenWith)
1194 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1195 cmd += data->path.GetWinPathString() + _T(" ");
1196 CAppUtils::LaunchApplication(cmd, NULL, false);
1199 #endif
1202 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1204 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1205 if (m_bThreadRunning)
1206 return;
1207 if (m_nSortedColumn == phdr->iItem)
1208 m_bAscending = !m_bAscending;
1209 else
1210 m_bAscending = TRUE;
1211 m_nSortedColumn = phdr->iItem;
1212 Sort();
1214 CString temp;
1215 m_ProgList.SetRedraw(FALSE);
1216 m_ProgList.DeleteAllItems();
1217 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1219 m_ProgList.SetRedraw(TRUE);
1221 *pResult = 0;
1224 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1226 return pData->bAuxItem;
1229 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1231 #if 0
1232 SVNProgress * pProgressData = (SVNProgress *)lParam;
1233 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1234 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1236 progControl->ShowWindow(SW_SHOW);
1238 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1240 progControl->ShowWindow(SW_HIDE);
1242 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1243 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1244 SetTimer(TRANSFERTIMER, 2000, NULL);
1245 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1247 progControl->SetPos((int)pProgressData->progress);
1248 progControl->SetRange32(0, (int)pProgressData->total);
1250 CString progText;
1251 if (pProgressData->overall_total < 1024)
1252 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1253 else if (pProgressData->overall_total < 1200000)
1254 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1255 else
1256 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1257 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1258 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1259 #endif
1260 return 0;
1263 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1265 if (nIDEvent == TRANSFERTIMER)
1267 CString progText;
1268 CString progSpeed;
1269 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1270 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1271 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1272 KillTimer(TRANSFERTIMER);
1274 if (nIDEvent == VISIBLETIMER)
1276 if (nEnsureVisibleCount)
1277 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1278 nEnsureVisibleCount = 0;
1282 void CGitProgressDlg::Sort()
1284 if(m_arData.size() < 2)
1286 return;
1289 // We need to sort the blocks which lie between the auxiliary entries
1290 // This is so that any aux data stays where it was
1291 NotificationDataVect::iterator actionBlockBegin;
1292 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1294 for(;;)
1296 // Search to the start of the non-aux entry in the next block
1297 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1298 if(actionBlockBegin == m_arData.end())
1300 // There are no more actions
1301 break;
1303 // Now search to find the end of the block
1304 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1305 // Now sort the block
1306 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1310 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1312 int result = 0;
1313 switch (m_nSortedColumn)
1315 case 0: //action column
1316 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1317 break;
1318 case 1: //path column
1319 // Compare happens after switch()
1320 break;
1321 case 2: //mime-type column
1322 result = pData1->mime_type.Compare(pData2->mime_type);
1323 break;
1324 default:
1325 break;
1328 // Sort by path if everything else is equal
1329 if (result == 0)
1331 result = CTGitPath::Compare(pData1->path, pData2->path);
1334 if (!m_bAscending)
1335 result = -result;
1336 return result < 0;
1339 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1341 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1343 // only show the wait cursor over the list control
1344 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1346 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1347 SetCursor(hCur);
1348 return TRUE;
1351 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1352 SetCursor(hCur);
1353 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1356 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1358 if (pMsg->message == WM_KEYDOWN)
1360 if (pMsg->wParam == VK_ESCAPE)
1362 // pressing the ESC key should close the dialog. But since we disabled the escape
1363 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1364 // this won't work.
1365 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1366 // the impression that the OK button was pressed.
1367 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1368 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1370 // since we convert ESC to RETURN, make sure the OK button has the focus.
1371 GetDlgItem(IDOK)->SetFocus();
1372 pMsg->wParam = VK_RETURN;
1375 if (pMsg->wParam == 'A')
1377 if (GetKeyState(VK_CONTROL)&0x8000)
1379 // Ctrl-A -> select all
1380 m_ProgList.SetSelectionMark(0);
1381 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1383 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1387 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1389 int selIndex = m_ProgList.GetSelectionMark();
1390 if (selIndex >= 0)
1392 if (GetKeyState(VK_CONTROL)&0x8000)
1394 //Ctrl-C -> copy to clipboard
1395 CString sClipdata;
1396 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1397 if (pos != NULL)
1399 while (pos)
1401 int nItem = m_ProgList.GetNextSelectedItem(pos);
1402 CString sAction = m_ProgList.GetItemText(nItem, 0);
1403 CString sPath = m_ProgList.GetItemText(nItem, 1);
1404 CString sMime = m_ProgList.GetItemText(nItem, 2);
1405 CString sLogCopyText;
1406 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1407 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1408 sClipdata += sLogCopyText;
1410 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1415 } // if (pMsg->message == WM_KEYDOWN)
1416 return __super::PreTranslateMessage(pMsg);
1419 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1421 #if 0
1422 if (m_options & ProgOptDryRun)
1423 return; // don't do anything in a dry-run.
1425 if (pWnd == &m_ProgList)
1427 int selIndex = m_ProgList.GetSelectionMark();
1428 if ((point.x == -1) && (point.y == -1))
1430 // Menu was invoked from the keyboard rather than by right-clicking
1431 CRect rect;
1432 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1433 m_ProgList.ClientToScreen(&rect);
1434 point = rect.CenterPoint();
1437 if ((selIndex >= 0)&&(!m_bThreadRunning))
1439 // entry is selected, thread has finished with updating so show the popup menu
1440 CIconMenu popup;
1441 if (popup.CreatePopupMenu())
1443 bool bAdded = false;
1444 NotificationData * data = m_arData[selIndex];
1445 if ((data)&&(!data->path.IsDirectory()))
1447 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1449 if (m_ProgList.GetSelectedCount() == 1)
1451 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1452 bAdded = true;
1455 if (data->bConflictedActionItem)
1457 if (m_ProgList.GetSelectedCount() == 1)
1459 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1460 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1461 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1463 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1464 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1466 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1467 popup.SetDefaultItem(ID_COMPARE, FALSE);
1469 if (m_ProgList.GetSelectedCount() == 1)
1471 if ((data->action == svn_wc_notify_add)||
1472 (data->action == svn_wc_notify_update_add)||
1473 (data->action == svn_wc_notify_commit_added)||
1474 (data->action == svn_wc_notify_commit_modified)||
1475 (data->action == svn_wc_notify_restore)||
1476 (data->action == svn_wc_notify_revert)||
1477 (data->action == svn_wc_notify_resolved)||
1478 (data->action == svn_wc_notify_commit_replaced)||
1479 (data->action == svn_wc_notify_commit_modified)||
1480 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1481 (data->action == svn_wc_notify_update_update))
1483 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1484 if (data->action == svn_wc_notify_update_update)
1485 popup.AppendMenu(MF_SEPARATOR, NULL);
1486 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1487 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1488 bAdded = true;
1491 } // if ((data)&&(!data->path.IsDirectory()))
1492 if (m_ProgList.GetSelectedCount() == 1)
1494 if (data)
1496 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1497 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1499 CTGitPath path = CTGitPath(sPath);
1500 if (path.GetDirectory().Exists())
1502 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1503 bAdded = true;
1508 if (m_ProgList.GetSelectedCount() > 0)
1510 if (bAdded)
1511 popup.AppendMenu(MF_SEPARATOR, NULL);
1512 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1513 bAdded = true;
1515 if (bAdded)
1517 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1518 DialogEnableWindow(IDOK, FALSE);
1519 this->SetPromptApp(&theApp);
1520 theApp.DoWaitCursor(1);
1521 bool bOpenWith = false;
1522 switch (cmd)
1524 case ID_COPY:
1526 CString sLines;
1527 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1528 while (pos)
1530 int nItem = m_ProgList.GetNextSelectedItem(pos);
1531 NotificationData * data = m_arData[nItem];
1532 if (data)
1534 sLines += data->sPathColumnText;
1535 sLines += _T("\r\n");
1538 sLines.TrimRight();
1539 if (!sLines.IsEmpty())
1541 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1544 break;
1545 case ID_EXPLORE:
1547 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1549 CTGitPath path = CTGitPath(sPath);
1550 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1552 break;
1553 case ID_COMPARE:
1555 svn_revnum_t rev = -1;
1556 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1557 if (data->basepath.IsEmpty())
1558 it = m_UpdateStartRevMap.begin();
1559 else
1560 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1561 if (it != m_UpdateStartRevMap.end())
1562 rev = it->second;
1563 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1564 if (data->content_state == svn_wc_notify_state_merged)
1566 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1567 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1568 SVN svn;
1569 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1571 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1572 DialogEnableWindow(IDOK, TRUE);
1573 break;
1575 // If necessary, convert the line-endings on the file before diffing
1576 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1578 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1579 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1581 temporaryFile.Reset();
1582 break;
1584 else
1586 newfile = temporaryFile;
1590 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1591 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1592 CString revname, wcname, basename;
1593 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1594 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1595 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1596 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1598 else
1600 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1601 SVN svn;
1602 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1604 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1605 DialogEnableWindow(IDOK, TRUE);
1606 break;
1608 else
1610 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1611 CString revname, wcname;
1612 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1613 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1614 CAppUtils::StartExtDiff(
1615 tempfile, data->path, revname, wcname,
1616 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1620 break;
1621 case ID_EDITCONFLICT:
1623 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1624 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1626 break;
1627 case ID_CONFLICTUSETHEIRS:
1628 case ID_CONFLICTUSEMINE:
1629 case ID_CONFLICTRESOLVE:
1631 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1632 switch (cmd)
1634 case ID_CONFLICTUSETHEIRS:
1635 result = svn_wc_conflict_choose_theirs_full;
1636 break;
1637 case ID_CONFLICTUSEMINE:
1638 result = svn_wc_conflict_choose_mine_full;
1639 break;
1640 case ID_CONFLICTRESOLVE:
1641 result = svn_wc_conflict_choose_merged;
1642 break;
1644 SVN svn;
1645 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1646 CString sResolvedPaths;
1647 while (pos)
1649 int nItem = m_ProgList.GetNextSelectedItem(pos);
1650 NotificationData * data = m_arData[nItem];
1651 if (data)
1653 if (data->bConflictedActionItem)
1655 if (!svn.Resolve(data->path, result, FALSE))
1657 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1658 DialogEnableWindow(IDOK, TRUE);
1659 break;
1661 else
1663 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1664 data->action = svn_wc_notify_resolved;
1665 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1666 data->bConflictedActionItem = false;
1667 m_nConflicts--;
1669 if (m_nConflicts==0)
1671 // When the last conflict is resolved we remove
1672 // the warning which we assume is in the last line.
1673 int nIndex = m_ProgList.GetItemCount()-1;
1674 VERIFY(m_ProgList.DeleteItem(nIndex));
1676 delete m_arData[nIndex];
1677 m_arData.pop_back();
1679 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1684 m_ProgList.Invalidate();
1685 CString info = BuildInfoString();
1686 SetDlgItemText(IDC_INFOTEXT, info);
1688 if (!sResolvedPaths.IsEmpty())
1690 CString msg;
1691 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1692 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1695 break;
1696 case ID_LOG:
1698 svn_revnum_t rev = m_RevisionEnd;
1699 if (!data->basepath.IsEmpty())
1701 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1702 if (it != m_FinishedRevMap.end())
1703 rev = it->second;
1705 CLogDlg dlg;
1706 // fetch the log from HEAD, not the revision we updated to:
1707 // the path might be inside an external folder which has its own
1708 // revisions.
1709 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1710 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1711 dlg.DoModal();
1713 break;
1714 case ID_OPENWITH:
1715 bOpenWith = true;
1716 case ID_OPEN:
1718 int ret = 0;
1719 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1720 if (!bOpenWith)
1721 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1722 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1724 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1725 cmd += sWinPath + _T(" ");
1726 CAppUtils::LaunchApplication(cmd, NULL, false);
1730 DialogEnableWindow(IDOK, TRUE);
1731 theApp.DoWaitCursor(-1);
1732 } // if (bAdded)
1736 #endif
1739 void CGitProgressDlg::OnEnSetfocusInfotext()
1741 CString sTemp;
1742 GetDlgItemText(IDC_INFOTEXT, sTemp);
1743 if (sTemp.IsEmpty())
1744 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1747 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1749 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1750 #if 0
1751 int selIndex = m_ProgList.GetSelectionMark();
1752 if (selIndex < 0)
1753 return;
1755 CDropFiles dropFiles; // class for creating DROPFILES struct
1757 int index;
1758 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1759 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1761 NotificationData * data = m_arData[index];
1763 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1765 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1767 dropFiles.AddFile( sPath );
1771 if ( dropFiles.GetCount()>0 )
1773 dropFiles.CreateStructure();
1775 #endif
1776 *pResult = 0;
1779 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1781 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1782 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1784 if(!m_ProgList.m_hWnd)
1785 return;
1787 int count = m_ProgList.GetItemCount();
1788 if (count > 0)
1789 m_ProgList.EnsureVisible(count-1, false);
1793 //////////////////////////////////////////////////////////////////////////
1794 /// commands
1795 //////////////////////////////////////////////////////////////////////////
1796 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1798 localoperation = true;
1799 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1800 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1801 SetBackgroundImage(IDI_ADD_BKG);
1802 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1804 git_repository *repo = NULL;
1805 git_index *index;
1807 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString() + _T("/.git"), CP_ACP);
1808 if (git_repository_open(&repo, gitdir.GetBuffer()))
1810 ReportGitError();
1811 return false;
1813 if (git_repository_index(&index, repo))
1815 ReportGitError();
1816 git_repository_free(repo);
1817 return false;
1819 if (git_index_read(index))
1821 ReportGitError();
1822 git_index_free(index);
1823 git_repository_free(repo);
1824 return false;
1827 for(int i=0;i<m_targetPathList.GetCount();i++)
1829 if (git_index_add(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_ACP)).GetBuffer(), 0))
1831 ReportGitError();
1832 git_index_free(index);
1833 git_repository_free(repo);
1834 return false;
1836 Notify(m_targetPathList[i],git_wc_notify_add);
1839 if (git_index_write(index))
1841 ReportGitError();
1842 git_index_free(index);
1843 git_repository_free(repo);
1844 return false;
1847 git_index_free(index);
1848 git_repository_free(repo);
1850 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1851 m_bErrorsOccurred=false;
1853 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1854 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1855 return true;
1858 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1860 #if 0
1861 ASSERT(m_targetPathList.GetCount() == 1);
1862 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1863 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1864 SetBackgroundImage(IDI_COPY_BKG);
1866 CString sCmdInfo;
1867 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1868 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1869 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1870 ReportCmd(sCmdInfo);
1872 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1874 ReportSVNError();
1875 return false;
1877 if (m_options & ProgOptSwitchAfterCopy)
1879 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
1880 m_targetPathList[0].GetWinPath(),
1881 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1882 ReportCmd(sCmdInfo);
1883 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1885 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
1887 ReportSVNError();
1888 return false;
1892 else
1894 if (SVN::PathIsURL(m_url))
1896 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
1897 ReportNotification(sMsg);
1900 #endif
1901 return true;
1904 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1906 #if 0
1907 ASSERT(m_targetPathList.GetCount() == 1);
1908 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
1909 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1910 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1911 SetBackgroundImage(IDI_EXPORT_BKG);
1912 CString eol;
1913 if (m_options & ProgOptEolCRLF)
1914 eol = _T("CRLF");
1915 if (m_options & ProgOptEolLF)
1916 eol = _T("LF");
1917 if (m_options & ProgOptEolCR)
1918 eol = _T("CR");
1919 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
1920 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
1922 ReportSVNError();
1923 return false;
1925 #endif
1926 return true;
1929 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
1931 #if 0
1932 ASSERT(m_targetPathList.GetCount() == 1);
1933 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
1934 localoperation = true;
1935 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
1936 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
1937 SetBackgroundImage(IDI_RENAME_BKG);
1938 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
1939 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
1941 ReportSVNError();
1942 return false;
1944 #endif
1945 return true;
1948 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
1951 localoperation = true;
1952 ASSERT(m_targetPathList.GetCount() == 1);
1953 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
1954 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1955 SetBackgroundImage(IDI_RESOLVE_BKG);
1956 // check if the file may still have conflict markers in it.
1957 //BOOL bMarkers = FALSE;
1959 for(int i=0;i<m_targetPathList.GetCount();i++)
1961 CString cmd,out,tempmergefile;
1962 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1963 if(g_Git.Run(cmd,&out,CP_ACP))
1965 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1966 m_bErrorsOccurred=true;
1967 return false;
1970 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
1972 Notify(m_targetPathList[i],git_wc_notify_resolved);
1974 #if 0
1975 if ((m_options & ProgOptSkipConflictCheck) == 0)
1979 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
1981 if (!m_targetPathList[fileindex].IsDirectory())
1983 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
1984 CString strLine = _T("");
1985 while (file.ReadString(strLine))
1987 if (strLine.Find(_T("<<<<<<<"))==0)
1989 bMarkers = TRUE;
1990 break;
1993 file.Close();
1997 catch (CFileException* pE)
1999 TRACE(_T("CFileException in Resolve!\n"));
2000 TCHAR error[10000] = {0};
2001 pE->GetErrorMessage(error, 10000);
2002 ReportError(error);
2003 pE->Delete();
2004 return false;
2007 if (bMarkers)
2009 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2011 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2012 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2013 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2016 else
2018 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2019 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2020 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2022 #endif
2023 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2025 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2026 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2028 return true;
2031 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2034 localoperation = true;
2035 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2036 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2037 SetBackgroundImage(IDI_REVERT_BKG);
2039 CTGitPathList delList;
2040 for(int i=0;i<m_selectedPaths.GetCount();i++)
2042 CTGitPath path;
2043 int action;
2044 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2045 action = m_selectedPaths[i].m_Action;
2046 /* rename file can't delete because it needs original file*/
2047 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2048 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2049 delList.AddPath(path);
2051 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2052 delList.DeleteAllFiles(true);
2054 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2055 for(int i=0;i<m_selectedPaths.GetCount();i++)
2057 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2059 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2060 m_bErrorsOccurred=true;
2061 return false;
2063 Notify(m_selectedPaths[i],git_wc_notify_revert);
2066 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2068 return true;
2071 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2073 #if 0
2074 ASSERT(m_targetPathList.GetCount() == 1);
2075 SVNStatus st;
2076 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2077 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2078 SetBackgroundImage(IDI_SWITCH_BKG);
2079 LONG rev = 0;
2080 if (st.GetStatus(m_targetPathList[0]) != (-2))
2082 if (st.status->entry != NULL)
2084 rev = st.status->entry->revision;
2088 CString sCmdInfo;
2089 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2090 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2091 (LPCTSTR)m_Revision.ToString());
2092 ReportCmd(sCmdInfo);
2094 bool depthIsSticky = true;
2095 if (m_depth == svn_depth_unknown)
2096 depthIsSticky = false;
2097 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2099 ReportSVNError();
2100 return false;
2102 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2103 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2104 &&((LONG)m_RevisionEnd > (LONG)rev))
2106 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2108 #endif
2109 return true;
2112 void CGitProgressDlg::OnBnClickedNoninteractive()
2114 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2115 m_AlwaysConflicted = (res == BST_CHECKED);
2116 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2117 nonint = m_AlwaysConflicted;
2120 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2122 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2123 if (sPath.Find(':')<0)
2125 // the path is not absolute: add the common root of all paths to it
2126 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2128 return sPath;
2131 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2133 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2134 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2135 //SetBackgroundImage(IDI_ADD_BKG);
2136 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2137 bool ret=true;
2138 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2140 CString error;
2141 CTGitPath path;
2142 Notify(path,git_wc_notify_sendmail_start);
2143 CString err;
2144 int retry=0;
2145 while(retry <3)
2147 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2149 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2150 ret = false;
2152 else
2154 break;
2157 retry++;
2158 if (retry < 3)
2159 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2160 Sleep(2000);
2161 if(m_bCancelled)
2163 CString str(_T("User Canceled"));
2164 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2165 return false;
2168 if (ret)
2169 Notify(path,git_wc_notify_sendmail_done,ret);
2171 else
2173 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2175 CPatch patch;
2176 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2178 int retry=0;
2179 while(retry<3)
2181 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2182 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2184 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2185 ret = false;
2188 else
2190 ret = true;
2191 break;
2193 retry++;
2194 if (retry < 3)
2195 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2196 Sleep(2000);
2197 if(m_bCancelled)
2199 CString str(_T("User Canceled"));
2200 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2201 return false;
2204 if (ret)
2205 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2208 return ret;