Modify position of filter and date at log dialog
[TortoiseGit.git] / src / TortoiseProc / SVNProgressDlg.cpp
blob08b16bca2640ea8ba7849888166cb26914d76715
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "messagebox.h"
22 #include "SVNProgressDlg.h"
23 #include "LogDlg.h"
24 #include "TGitPath.h"
25 #include "Registry.h"
26 #include "GitStatus.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "StringUtils.h"
30 #include "TempFile.h"
31 #include "UnicodeUtils.h"
32 #include "SoundUtils.h"
33 #include "GitDiff.h"
34 #include "Hooks.h"
35 #include "DropFiles.h"
36 //#include "GitLogHelper.h"
37 #include "RegHistory.h"
38 //#include "ConflictResolveDlg.h"
39 #include "LogFile.h"
40 #include "ShellUpdater.h"
41 #include "IconMenu.h"
42 #include "BugTraqAssociations.h"
43 #include "patch.h"
45 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
47 BOOL CGitProgressDlg::m_bAscending = FALSE;
48 int CGitProgressDlg::m_nSortedColumn = -1;
50 #define TRANSFERTIMER 100
51 #define VISIBLETIMER 101
53 enum SVNProgressDlgContextMenuCommands
55 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
56 ID_COMPARE = 1,
57 ID_EDITCONFLICT,
58 ID_CONFLICTRESOLVE,
59 ID_CONFLICTUSETHEIRS,
60 ID_CONFLICTUSEMINE,
61 ID_LOG,
62 ID_OPEN,
63 ID_OPENWITH,
64 ID_EXPLORE,
65 ID_COPY
68 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
69 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
70 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
71 , m_bCancelled(FALSE)
72 , m_pThread(NULL)
73 #if 0
74 , m_Revision(_T("HEAD"))
75 //, m_RevisionEnd(0)
76 , m_bLockWarning(false)
77 , m_bLockExists(false)
78 , m_bThreadRunning(FALSE)
79 , m_nConflicts(0)
80 , m_bErrorsOccurred(FALSE)
81 , m_bMergesAddsDeletesOccurred(FALSE)
83 , m_options(ProgOptNone)
84 , m_dwCloseOnEnd((DWORD)-1)
85 , m_bFinishedItemAdded(false)
86 , m_bLastVisible(false)
87 // , m_depth(svn_depth_unknown)
88 , m_itemCount(-1)
89 , m_itemCountTotal(-1)
90 , m_AlwaysConflicted(false)
91 , m_BugTraqProvider(NULL)
92 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
93 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
94 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
95 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
96 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
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);
121 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
122 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
123 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
124 ON_WM_CLOSE()
125 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
126 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
127 ON_WM_SETCURSOR()
128 ON_WM_CONTEXTMENU()
129 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
130 ON_WM_TIMER()
131 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
132 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
133 ON_WM_SIZE()
134 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
135 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
136 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
137 END_MESSAGE_MAP()
139 BOOL CGitProgressDlg::Cancel()
141 return m_bCancelled;
144 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM lParam)
146 #if 0
147 CConflictResolveDlg dlg(this);
148 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
149 if (description)
151 dlg.SetConflictDescription(description);
152 if (dlg.DoModal() == IDOK)
154 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
156 // if the result is conflicted and the dialog returned IDOK,
157 // that means we should not ask again in case of a conflict
158 m_AlwaysConflicted = true;
159 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
162 m_mergedfile = dlg.GetMergedFile();
163 m_bCancelled = dlg.IsCancelled();
164 return dlg.GetResult();
167 return svn_wc_conflict_choose_postpone;
168 #endif
169 return 0;
171 #if 0
172 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
174 // we only bother the user when merging
175 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
177 // we're in a worker thread here. That means we must not show a dialog from the thread
178 // but let the UI thread do it.
179 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
180 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
181 mergedfile = m_mergedfile;
182 return (svn_wc_conflict_choice_t)dlgResult;
185 return svn_wc_conflict_choose_postpone;
187 #endif
188 void CGitProgressDlg::AddItemToList()
190 int totalcount = m_ProgList.GetItemCount();
192 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
193 // make columns width fit
194 if (iFirstResized < 30)
196 // only resize the columns for the first 30 or so entries.
197 // after that, don't resize them anymore because that's an
198 // expensive function call and the columns will be sized
199 // close enough already.
200 ResizeColumns();
201 iFirstResized++;
204 // Make sure the item is *entirely* visible even if the horizontal
205 // scroll bar is visible.
206 int count = m_ProgList.GetCountPerPage();
207 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
209 nEnsureVisibleCount++;
210 m_bLastVisible = true;
212 else
214 nEnsureVisibleCount = 0;
215 if (IsIconic() == 0)
216 m_bLastVisible = false;
221 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
222 int status ,
223 CString *strErr
225 svn_node_kind_t kind, const CString& mime_type,
226 svn_wc_notify_state_t content_state,
227 svn_wc_notify_state_t prop_state, LONG rev,
228 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
229 const CString& changelistname,
230 svn_merge_range_t * range,
231 svn_error_t * err, apr_pool_t * pool
234 bool bNoNotify = false;
235 bool bDoAddData = true;
236 NotificationData * data = new NotificationData();
237 data->path = path;
238 data->action = action;
239 data->sPathColumnText=path.GetGitPathString();
240 data->bAuxItem = false;
241 #if 0
242 data->kind = kind;
243 data->mime_type = mime_type;
244 data->content_state = content_state;
245 data->prop_state = prop_state;
246 data->rev = rev;
247 data->lock_state = lock_state;
248 data->changelistname = changelistname;
249 if ((lock)&&(lock->owner))
250 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
251 data->sPathColumnText = path.GetUIPathString();
252 if (!m_basePath.IsEmpty())
253 data->basepath = m_basePath;
254 if (range)
255 data->merge_range = *range;
256 #endif
257 switch (data->action)
259 case git_wc_notify_add:
260 //case svn_wc_notify_update_add:
261 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
262 // {
263 // data->color = m_Colors.GetColor(CColors::Conflict);
264 // data->bConflictedActionItem = true;
265 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
266 // m_nConflicts++;
267 // }
268 // else
269 // {
270 // m_bMergesAddsDeletesOccurred = true;
271 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
272 data->color = m_Colors.GetColor(CColors::Added);
273 // }
274 break;
275 case git_wc_notify_sendmail_start:
276 data->bAuxItem = true;
277 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
278 data->color = m_Colors.GetColor(CColors::Modified);
279 break;
281 case git_wc_notify_sendmail_error:
282 data->bAuxItem = true;
283 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
284 if(strErr)
285 data->sPathColumnText = *strErr;
286 else
287 data->sPathColumnText.Empty();
288 data->color = m_Colors.GetColor(CColors::Modified);
289 break;
291 case git_wc_notify_sendmail_done:
293 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
294 data->sPathColumnText.Empty();
295 data->color = m_Colors.GetColor(CColors::Modified);
296 break;
298 case git_wc_notify_sendmail_retry:
299 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
300 data->sPathColumnText.Empty();
301 data->color = m_Colors.GetColor(CColors::Modified);
302 break;
305 case git_wc_notify_resolved:
306 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
307 break;
309 #if 0
310 case svn_wc_notify_commit_added:
311 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
312 data->color = m_Colors.GetColor(CColors::Added);
313 break;
314 case svn_wc_notify_copy:
315 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
316 break;
317 case svn_wc_notify_commit_modified:
318 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
319 data->color = m_Colors.GetColor(CColors::Modified);
320 break;
321 case svn_wc_notify_delete:
322 case svn_wc_notify_update_delete:
323 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
324 m_bMergesAddsDeletesOccurred = true;
325 data->color = m_Colors.GetColor(CColors::Deleted);
326 break;
327 case svn_wc_notify_commit_deleted:
328 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
329 data->color = m_Colors.GetColor(CColors::Deleted);
330 break;
331 case svn_wc_notify_restore:
332 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
333 break;
334 case svn_wc_notify_revert:
335 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
336 break;
337 case svn_wc_notify_update_replace:
338 case svn_wc_notify_commit_replaced:
339 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
340 data->color = m_Colors.GetColor(CColors::Deleted);
341 break;
342 case svn_wc_notify_exists:
343 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
345 data->color = m_Colors.GetColor(CColors::Conflict);
346 data->bConflictedActionItem = true;
347 m_nConflicts++;
348 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
350 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
352 data->color = m_Colors.GetColor(CColors::Merged);
353 m_bMergesAddsDeletesOccurred = true;
354 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
356 else
357 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
358 break;
359 case svn_wc_notify_update_update:
360 // if this is an inoperative dir change, don't show the notification.
361 // an inoperative dir change is when a directory gets updated without
362 // any real change in either text or properties.
363 if ((kind == svn_node_dir)
364 && ((prop_state == svn_wc_notify_state_inapplicable)
365 || (prop_state == svn_wc_notify_state_unknown)
366 || (prop_state == svn_wc_notify_state_unchanged)))
368 bNoNotify = true;
369 break;
371 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
373 data->color = m_Colors.GetColor(CColors::Conflict);
374 data->bConflictedActionItem = true;
375 m_nConflicts++;
376 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
378 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
380 data->color = m_Colors.GetColor(CColors::Merged);
381 m_bMergesAddsDeletesOccurred = true;
382 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
384 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
385 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
387 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
389 else
391 bNoNotify = true;
392 break;
394 if (lock_state == svn_wc_notify_lock_state_unlocked)
396 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
397 data->sActionColumnText += _T(", ") + temp;
399 break;
401 case svn_wc_notify_update_external:
402 // For some reason we build a list of externals...
403 m_ExtStack.AddHead(path.GetUIPathString());
404 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
405 data->bAuxItem = true;
406 break;
408 case svn_wc_notify_update_completed:
410 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
411 data->bAuxItem = true;
412 bool bEmpty = !!m_ExtStack.IsEmpty();
413 if (!bEmpty)
414 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
415 else
416 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
418 if ((m_nConflicts>0)&&(bEmpty))
420 // We're going to add another aux item - let's shove this current onto the list first
421 // I don't really like this, but it will do for the moment.
422 m_arData.push_back(data);
423 AddItemToList();
425 data = new NotificationData();
426 data->bAuxItem = true;
427 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
428 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
429 data->color = m_Colors.GetColor(CColors::Conflict);
430 CSoundUtils::PlayTSVNWarning();
431 // This item will now be added after the switch statement
433 if (!m_basePath.IsEmpty())
434 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
435 m_RevisionEnd = rev;
436 m_bFinishedItemAdded = true;
438 break;
439 case svn_wc_notify_commit_postfix_txdelta:
440 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
441 break;
442 case svn_wc_notify_failed_revert:
443 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
444 break;
445 case svn_wc_notify_status_completed:
446 case svn_wc_notify_status_external:
447 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
448 break;
449 case svn_wc_notify_skip:
450 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
452 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
454 // The color settings dialog describes the red color with
455 // "possible or real conflict / obstructed" which also applies to
456 // skipped targets during a merge. So we just use the same color.
457 data->color = m_Colors.GetColor(CColors::Conflict);
459 else
460 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
461 break;
462 case svn_wc_notify_locked:
463 if ((lock)&&(lock->owner))
464 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
465 break;
466 case svn_wc_notify_unlocked:
467 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
468 break;
469 case svn_wc_notify_failed_lock:
470 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
471 m_arData.push_back(data);
472 AddItemToList();
473 ReportError(SVN::GetErrorString(err));
474 bDoAddData = false;
475 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
476 m_bLockWarning = true;
477 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
478 m_bLockExists = true;
479 break;
480 case svn_wc_notify_failed_unlock:
481 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
482 m_arData.push_back(data);
483 AddItemToList();
484 ReportError(SVN::GetErrorString(err));
485 bDoAddData = false;
486 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
487 m_bLockWarning = true;
488 break;
489 case svn_wc_notify_changelist_set:
490 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
491 break;
492 case svn_wc_notify_changelist_clear:
493 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
494 break;
495 case svn_wc_notify_changelist_moved:
496 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
497 break;
498 case svn_wc_notify_foreign_merge_begin:
499 case svn_wc_notify_merge_begin:
500 if (range == NULL)
501 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
502 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
503 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
504 else if (data->merge_range.start - 1 == data->merge_range.end)
505 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
506 else if (data->merge_range.start < data->merge_range.end)
507 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
508 else
509 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
510 data->bAuxItem = true;
511 break;
512 #endif
513 default:
514 break;
515 } // switch (data->action)
517 if (bNoNotify)
518 delete data;
519 else
521 if (bDoAddData)
523 m_arData.push_back(data);
524 AddItemToList();
525 if ((!data->bAuxItem) && (m_itemCount > 0))
527 m_itemCount--;
529 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
530 progControl->ShowWindow(SW_SHOW);
531 progControl->SetPos(m_itemCountTotal - m_itemCount);
532 progControl->SetRange32(0, m_itemCountTotal);
535 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
537 // ResizeColumns();
538 // bSecondResized = TRUE;
542 return TRUE;
546 CString CGitProgressDlg::BuildInfoString()
548 CString infotext;
549 #if 0
551 CString temp;
552 int added = 0;
553 int copied = 0;
554 int deleted = 0;
555 int restored = 0;
556 int reverted = 0;
557 int resolved = 0;
558 int conflicted = 0;
559 int updated = 0;
560 int merged = 0;
561 int modified = 0;
562 int skipped = 0;
563 int replaced = 0;
565 for (size_t i=0; i<m_arData.size(); ++i)
567 const NotificationData * dat = m_arData[i];
568 switch (dat->action)
570 case svn_wc_notify_add:
571 case svn_wc_notify_update_add:
572 case svn_wc_notify_commit_added:
573 if (dat->bConflictedActionItem)
574 conflicted++;
575 else
576 added++;
577 break;
578 case svn_wc_notify_copy:
579 copied++;
580 break;
581 case svn_wc_notify_delete:
582 case svn_wc_notify_update_delete:
583 case svn_wc_notify_commit_deleted:
584 deleted++;
585 break;
586 case svn_wc_notify_restore:
587 restored++;
588 break;
589 case svn_wc_notify_revert:
590 reverted++;
591 break;
592 case svn_wc_notify_resolved:
593 resolved++;
594 break;
595 case svn_wc_notify_update_update:
596 if (dat->bConflictedActionItem)
597 conflicted++;
598 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
599 merged++;
600 else
601 updated++;
602 break;
603 case svn_wc_notify_commit_modified:
604 modified++;
605 break;
606 case svn_wc_notify_skip:
607 skipped++;
608 break;
609 case svn_wc_notify_commit_replaced:
610 replaced++;
611 break;
614 if (conflicted)
616 temp.LoadString(IDS_SVNACTION_CONFLICTED);
617 infotext += temp;
618 temp.Format(_T(":%d "), conflicted);
619 infotext += temp;
621 if (skipped)
623 temp.LoadString(IDS_SVNACTION_SKIP);
624 infotext += temp;
625 infotext.AppendFormat(_T(":%d "), skipped);
627 if (merged)
629 temp.LoadString(IDS_SVNACTION_MERGED);
630 infotext += temp;
631 infotext.AppendFormat(_T(":%d "), merged);
633 if (added)
635 temp.LoadString(IDS_SVNACTION_ADD);
636 infotext += temp;
637 infotext.AppendFormat(_T(":%d "), added);
639 if (deleted)
641 temp.LoadString(IDS_SVNACTION_DELETE);
642 infotext += temp;
643 infotext.AppendFormat(_T(":%d "), deleted);
645 if (modified)
647 temp.LoadString(IDS_SVNACTION_MODIFIED);
648 infotext += temp;
649 infotext.AppendFormat(_T(":%d "), modified);
651 if (copied)
653 temp.LoadString(IDS_SVNACTION_COPY);
654 infotext += temp;
655 infotext.AppendFormat(_T(":%d "), copied);
657 if (replaced)
659 temp.LoadString(IDS_SVNACTION_REPLACED);
660 infotext += temp;
661 infotext.AppendFormat(_T(":%d "), replaced);
663 if (updated)
665 temp.LoadString(IDS_SVNACTION_UPDATE);
666 infotext += temp;
667 infotext.AppendFormat(_T(":%d "), updated);
669 if (restored)
671 temp.LoadString(IDS_SVNACTION_RESTORE);
672 infotext += temp;
673 infotext.AppendFormat(_T(":%d "), restored);
675 if (reverted)
677 temp.LoadString(IDS_SVNACTION_REVERT);
678 infotext += temp;
679 infotext.AppendFormat(_T(":%d "), reverted);
681 if (resolved)
683 temp.LoadString(IDS_SVNACTION_RESOLVE);
684 infotext += temp;
685 infotext.AppendFormat(_T(":%d "), resolved);
687 #endif
688 return infotext;
691 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
693 m_selectedPaths = selPaths;
696 void CGitProgressDlg::ResizeColumns()
698 m_ProgList.SetRedraw(FALSE);
700 TCHAR textbuf[MAX_PATH];
702 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
703 for (int col = 0; col <= maxcol; col++)
705 // find the longest width of all items
706 int count = m_ProgList.GetItemCount();
707 HDITEM hdi = {0};
708 hdi.mask = HDI_TEXT;
709 hdi.pszText = textbuf;
710 hdi.cchTextMax = sizeof(textbuf);
711 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
712 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
714 for (int index = 0; index<count; ++index)
716 // get the width of the string and add 12 pixels for the column separator and margins
717 int linewidth = cx;
718 switch (col)
720 case 0:
721 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
722 break;
723 case 1:
724 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
725 break;
726 case 2:
727 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
728 break;
730 if (cx < linewidth)
731 cx = linewidth;
733 m_ProgList.SetColumnWidth(col, cx);
736 m_ProgList.SetRedraw(TRUE);
739 BOOL CGitProgressDlg::OnInitDialog()
741 __super::OnInitDialog();
743 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
745 m_ProgList.DeleteAllItems();
746 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
747 while (c>=0)
748 m_ProgList.DeleteColumn(c--);
749 CString temp;
750 temp.LoadString(IDS_PROGRS_ACTION);
751 m_ProgList.InsertColumn(0, temp);
752 temp.LoadString(IDS_PROGRS_PATH);
753 m_ProgList.InsertColumn(1, temp);
754 temp.LoadString(IDS_PROGRS_MIMETYPE);
755 m_ProgList.InsertColumn(2, temp);
757 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
758 if (m_pThread==NULL)
760 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
762 else
764 m_pThread->m_bAutoDelete = FALSE;
765 m_pThread->ResumeThread();
768 UpdateData(FALSE);
770 // Call this early so that the column headings aren't hidden before any
771 // text gets added.
772 ResizeColumns();
774 SetTimer(VISIBLETIMER, 300, NULL);
776 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
777 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
778 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
779 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
780 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
781 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
782 AddAnchor(IDOK, BOTTOM_RIGHT);
783 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
784 //SetPromptParentWindow(this->m_hWnd);
785 if (hWndExplorer)
786 CenterWindow(CWnd::FromHandle(hWndExplorer));
787 EnableSaveRestore(_T("SVNProgressDlg"));
788 return TRUE;
791 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
793 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
796 #if 0
797 void CGitProgressDlg::ReportSVNError()
799 ReportError(GetLastErrorMessage());
801 #endif
803 void CGitProgressDlg::ReportError(const CString& sError)
805 CSoundUtils::PlayTGitError();
806 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
807 m_bErrorsOccurred = true;
810 void CGitProgressDlg::ReportWarning(const CString& sWarning)
812 CSoundUtils::PlayTGitWarning();
813 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
816 void CGitProgressDlg::ReportNotification(const CString& sNotification)
818 CSoundUtils::PlayTGitNotification();
819 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
822 void CGitProgressDlg::ReportCmd(const CString& sCmd)
824 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
827 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
829 // instead of showing a dialog box with the error message or notification,
830 // just insert the error text into the list control.
831 // that way the user isn't 'interrupted' by a dialog box popping up!
833 // the message may be split up into different lines
834 // so add a new entry for each line of the message
835 while (!sMessage.IsEmpty())
837 NotificationData * data = new NotificationData();
838 data->bAuxItem = true;
839 data->sActionColumnText = sMsgKind;
840 if (sMessage.Find('\n')>=0)
841 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
842 else
843 data->sPathColumnText = sMessage;
844 data->sPathColumnText.Trim(_T("\n\r"));
845 data->color = color;
846 if (sMessage.Find('\n')>=0)
848 sMessage = sMessage.Mid(sMessage.Find('\n'));
849 sMessage.Trim(_T("\n\r"));
851 else
852 sMessage.Empty();
853 m_arData.push_back(data);
854 AddItemToList();
858 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
860 return ((CGitProgressDlg*)pVoid)->ProgressThread();
863 UINT CGitProgressDlg::ProgressThread()
865 // The SetParams function should have loaded something for us
867 CString temp;
868 CString sWindowTitle;
869 bool localoperation = false;
870 bool bSuccess = false;
871 m_AlwaysConflicted = false;
873 DialogEnableWindow(IDOK, FALSE);
874 DialogEnableWindow(IDCANCEL, TRUE);
875 // SetAndClearProgressInfo(m_hWnd);
876 m_itemCount = m_itemCountTotal;
878 InterlockedExchange(&m_bThreadRunning, TRUE);
879 iFirstResized = 0;
880 bSecondResized = FALSE;
881 m_bFinishedItemAdded = false;
882 CTime startTime = CTime::GetCurrentTime();
883 switch (m_Command)
885 case GitProgress_Add:
886 bSuccess = CmdAdd(sWindowTitle, localoperation);
887 break;
888 case GitProgress_Checkout:
889 bSuccess = CmdCheckout(sWindowTitle, localoperation);
890 break;
891 case GitProgress_Commit:
892 bSuccess = CmdCommit(sWindowTitle, localoperation);
893 break;
894 case GitProgress_Copy:
895 bSuccess = CmdCopy(sWindowTitle, localoperation);
896 break;
897 case GitProgress_Export:
898 bSuccess = CmdExport(sWindowTitle, localoperation);
899 break;
900 case GitProgress_Import:
901 bSuccess = CmdImport(sWindowTitle, localoperation);
902 break;
903 case GitProgress_Lock:
904 bSuccess = CmdLock(sWindowTitle, localoperation);
905 break;
906 case GitProgress_Merge:
907 bSuccess = CmdMerge(sWindowTitle, localoperation);
908 break;
909 case GitProgress_MergeAll:
910 bSuccess = CmdMergeAll(sWindowTitle, localoperation);
911 break;
912 case GitProgress_MergeReintegrate:
913 bSuccess = CmdMergeReintegrate(sWindowTitle, localoperation);
914 break;
915 case GitProgress_Rename:
916 bSuccess = CmdRename(sWindowTitle, localoperation);
917 break;
918 case GitProgress_Resolve:
919 bSuccess = CmdResolve(sWindowTitle, localoperation);
920 break;
921 case GitProgress_Revert:
922 bSuccess = CmdRevert(sWindowTitle, localoperation);
923 break;
924 case GitProgress_Switch:
925 bSuccess = CmdSwitch(sWindowTitle, localoperation);
926 break;
927 case GitProgress_Unlock:
928 bSuccess = CmdUnlock(sWindowTitle, localoperation);
929 break;
930 case GitProgress_Update:
931 bSuccess = CmdUpdate(sWindowTitle, localoperation);
932 break;
933 case GitProgress_SendMail:
934 bSuccess = CmdSendMail(sWindowTitle, localoperation);
935 break;
937 if (!bSuccess)
938 temp.LoadString(IDS_PROGRS_TITLEFAILED);
939 else
940 temp.LoadString(IDS_PROGRS_TITLEFIN);
941 sWindowTitle = sWindowTitle + _T(" ") + temp;
942 SetWindowText(sWindowTitle);
944 KillTimer(TRANSFERTIMER);
945 KillTimer(VISIBLETIMER);
947 DialogEnableWindow(IDCANCEL, FALSE);
948 DialogEnableWindow(IDOK, TRUE);
950 CString info = BuildInfoString();
951 if (!bSuccess)
952 info.LoadString(IDS_PROGRS_INFOFAILED);
953 SetDlgItemText(IDC_INFOTEXT, info);
954 ResizeColumns();
955 SendMessage(DM_SETDEFID, IDOK);
956 GetDlgItem(IDOK)->SetFocus();
958 CString sFinalInfo;
959 if (!m_sTotalBytesTransferred.IsEmpty())
961 CTimeSpan time = CTime::GetCurrentTime() - startTime;
962 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
963 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
964 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
966 else
967 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
969 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
971 if (!m_bFinishedItemAdded)
973 // there's no "finished: xxx" line at the end. We add one here to make
974 // sure the user sees that the command is actually finished.
975 NotificationData * data = new NotificationData();
976 data->bAuxItem = true;
977 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
978 m_arData.push_back(data);
979 AddItemToList();
982 int count = m_ProgList.GetItemCount();
983 if ((count > 0)&&(m_bLastVisible))
984 m_ProgList.EnsureVisible(count-1, FALSE);
986 CLogFile logfile;
987 if (logfile.Open())
989 logfile.AddTimeLine();
990 for (size_t i=0; i<m_arData.size(); i++)
992 NotificationData * data = m_arData[i];
993 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
994 logfile.AddLine(temp);
996 if (!sFinalInfo.IsEmpty())
997 logfile.AddLine(sFinalInfo);
998 logfile.Close();
1001 m_bCancelled = TRUE;
1002 InterlockedExchange(&m_bThreadRunning, FALSE);
1003 RefreshCursor();
1005 DWORD dwAutoClose = CRegStdWORD(_T("Software\\TortoiseGit\\AutoClose"));
1006 if (m_options & ProgOptDryRun)
1007 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1008 if (!m_bLastVisible)
1009 dwAutoClose = 0;
1010 if (m_dwCloseOnEnd != (DWORD)-1)
1011 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1012 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1013 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1014 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1015 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1016 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1017 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1018 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1019 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1021 //Don't do anything here which might cause messages to be sent to the window
1022 //The window thread is probably now blocked in OnOK if we've done an auto close
1023 return 0;
1026 void CGitProgressDlg::OnBnClickedLogbutton()
1028 #if 0
1029 if (m_targetPathList.GetCount() != 1)
1030 return;
1031 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1032 svn_revnum_t rev = -1;
1033 if (it != m_UpdateStartRevMap.end())
1035 rev = it->second;
1037 CLogDlg dlg;
1038 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1039 dlg.DoModal();
1040 #endif
1044 void CGitProgressDlg::OnClose()
1046 if (m_bCancelled)
1048 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1049 InterlockedExchange(&m_bThreadRunning, FALSE);
1051 else
1053 m_bCancelled = TRUE;
1054 return;
1056 DialogEnableWindow(IDCANCEL, TRUE);
1057 __super::OnClose();
1060 void CGitProgressDlg::OnOK()
1062 if ((m_bCancelled)&&(!m_bThreadRunning))
1064 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1065 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1066 // don't do any more operations on the window which might require message passing
1067 // If you try to send windows messages once we're waiting here, then the thread can't finished
1068 // because the Window's message loop is blocked at this wait
1069 WaitForSingleObject(m_pThread->m_hThread, 10000);
1070 __super::OnOK();
1072 m_bCancelled = TRUE;
1075 void CGitProgressDlg::OnCancel()
1077 if ((m_bCancelled)&&(!m_bThreadRunning))
1078 __super::OnCancel();
1079 m_bCancelled = TRUE;
1082 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1084 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1086 if (pDispInfo)
1088 if (pDispInfo->item.mask & LVIF_TEXT)
1090 if (pDispInfo->item.iItem < (int)m_arData.size())
1092 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1093 switch (pDispInfo->item.iSubItem)
1095 case 0:
1096 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1097 break;
1098 case 1:
1099 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1100 if (!data->bAuxItem)
1102 int cWidth = m_ProgList.GetColumnWidth(1);
1103 cWidth = max(12, cWidth-12);
1104 CDC * pDC = m_ProgList.GetDC();
1105 if (pDC != NULL)
1107 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1108 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1109 pDC->SelectObject(pFont);
1110 ReleaseDC(pDC);
1113 break;
1114 case 2:
1115 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1116 break;
1117 default:
1118 m_columnbuf[0] = 0;
1120 pDispInfo->item.pszText = m_columnbuf;
1124 *pResult = 0;
1127 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1129 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1131 // Take the default processing unless we set this to something else below.
1132 *pResult = CDRF_DODEFAULT;
1134 // First thing - check the draw stage. If it's the control's prepaint
1135 // stage, then tell Windows we want messages for every item.
1137 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1139 *pResult = CDRF_NOTIFYITEMDRAW;
1141 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1143 // This is the prepaint stage for an item. Here's where we set the
1144 // item's text color. Our return value will tell Windows to draw the
1145 // item itself, but it will use the new color we set here.
1147 // Tell Windows to paint the control itself.
1148 *pResult = CDRF_DODEFAULT;
1150 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1151 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1153 return;
1155 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1156 ASSERT(data != NULL);
1157 if (data == NULL)
1158 return;
1160 // Store the color back in the NMLVCUSTOMDRAW struct.
1161 pLVCD->clrText = data->color;
1165 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1167 #if 0
1168 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1169 *pResult = 0;
1170 if (pNMLV->iItem < 0)
1171 return;
1172 if (m_options & ProgOptDryRun)
1173 return; //don't do anything in a dry-run.
1175 const NotificationData * data = m_arData[pNMLV->iItem];
1176 if (data == NULL)
1177 return;
1179 if (data->bConflictedActionItem)
1181 // We've double-clicked on a conflicted item - do a three-way merge on it
1182 SVNDiff::StartConflictEditor(data->path);
1184 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))
1186 // This is a modified file which has been merged on update. Diff it against base
1187 CTGitPath temporaryFile;
1188 SVNDiff diff(this, this->m_hWnd, true);
1189 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1190 svn_revnum_t baseRev = 0;
1191 diff.DiffFileAgainstBase(data->path, baseRev);
1193 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1195 bool bOpenWith = false;
1196 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1197 if (ret <= HINSTANCE_ERROR)
1198 bOpenWith = true;
1199 if (bOpenWith)
1201 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1202 cmd += data->path.GetWinPathString() + _T(" ");
1203 CAppUtils::LaunchApplication(cmd, NULL, false);
1206 #endif
1209 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1211 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1212 if (m_bThreadRunning)
1213 return;
1214 if (m_nSortedColumn == phdr->iItem)
1215 m_bAscending = !m_bAscending;
1216 else
1217 m_bAscending = TRUE;
1218 m_nSortedColumn = phdr->iItem;
1219 Sort();
1221 CString temp;
1222 m_ProgList.SetRedraw(FALSE);
1223 m_ProgList.DeleteAllItems();
1224 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1226 m_ProgList.SetRedraw(TRUE);
1228 *pResult = 0;
1231 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1233 return pData->bAuxItem;
1236 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM lParam)
1238 #if 0
1239 SVNProgress * pProgressData = (SVNProgress *)lParam;
1240 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1241 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1243 progControl->ShowWindow(SW_SHOW);
1245 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1247 progControl->ShowWindow(SW_HIDE);
1249 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1250 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1251 SetTimer(TRANSFERTIMER, 2000, NULL);
1252 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1254 progControl->SetPos((int)pProgressData->progress);
1255 progControl->SetRange32(0, (int)pProgressData->total);
1257 CString progText;
1258 if (pProgressData->overall_total < 1024)
1259 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1260 else if (pProgressData->overall_total < 1200000)
1261 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1262 else
1263 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1264 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1265 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1266 #endif
1267 return 0;
1270 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1272 if (nIDEvent == TRANSFERTIMER)
1274 CString progText;
1275 CString progSpeed;
1276 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1277 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1278 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1279 KillTimer(TRANSFERTIMER);
1281 if (nIDEvent == VISIBLETIMER)
1283 if (nEnsureVisibleCount)
1284 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1285 nEnsureVisibleCount = 0;
1289 void CGitProgressDlg::Sort()
1291 if(m_arData.size() < 2)
1293 return;
1296 // We need to sort the blocks which lie between the auxiliary entries
1297 // This is so that any aux data stays where it was
1298 NotificationDataVect::iterator actionBlockBegin;
1299 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1301 for(;;)
1303 // Search to the start of the non-aux entry in the next block
1304 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1305 if(actionBlockBegin == m_arData.end())
1307 // There are no more actions
1308 break;
1310 // Now search to find the end of the block
1311 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1312 // Now sort the block
1313 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1317 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1319 int result = 0;
1320 switch (m_nSortedColumn)
1322 case 0: //action column
1323 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1324 break;
1325 case 1: //path column
1326 // Compare happens after switch()
1327 break;
1328 case 2: //mime-type column
1329 result = pData1->mime_type.Compare(pData2->mime_type);
1330 break;
1331 default:
1332 break;
1335 // Sort by path if everything else is equal
1336 if (result == 0)
1338 result = CTGitPath::Compare(pData1->path, pData2->path);
1341 if (!m_bAscending)
1342 result = -result;
1343 return result < 0;
1346 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1348 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1350 // only show the wait cursor over the list control
1351 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1353 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1354 SetCursor(hCur);
1355 return TRUE;
1358 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1359 SetCursor(hCur);
1360 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1363 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1365 if (pMsg->message == WM_KEYDOWN)
1367 if (pMsg->wParam == VK_ESCAPE)
1369 // pressing the ESC key should close the dialog. But since we disabled the escape
1370 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1371 // this won't work.
1372 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1373 // the impression that the OK button was pressed.
1374 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1375 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1377 // since we convert ESC to RETURN, make sure the OK button has the focus.
1378 GetDlgItem(IDOK)->SetFocus();
1379 pMsg->wParam = VK_RETURN;
1382 if (pMsg->wParam == 'A')
1384 if (GetKeyState(VK_CONTROL)&0x8000)
1386 // Ctrl-A -> select all
1387 m_ProgList.SetSelectionMark(0);
1388 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1390 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1394 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1396 int selIndex = m_ProgList.GetSelectionMark();
1397 if (selIndex >= 0)
1399 if (GetKeyState(VK_CONTROL)&0x8000)
1401 //Ctrl-C -> copy to clipboard
1402 CString sClipdata;
1403 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1404 if (pos != NULL)
1406 while (pos)
1408 int nItem = m_ProgList.GetNextSelectedItem(pos);
1409 CString sAction = m_ProgList.GetItemText(nItem, 0);
1410 CString sPath = m_ProgList.GetItemText(nItem, 1);
1411 CString sMime = m_ProgList.GetItemText(nItem, 2);
1412 CString sLogCopyText;
1413 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1414 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1415 sClipdata += sLogCopyText;
1417 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1422 } // if (pMsg->message == WM_KEYDOWN)
1423 return __super::PreTranslateMessage(pMsg);
1426 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1428 #if 0
1429 if (m_options & ProgOptDryRun)
1430 return; // don't do anything in a dry-run.
1432 if (pWnd == &m_ProgList)
1434 int selIndex = m_ProgList.GetSelectionMark();
1435 if ((point.x == -1) && (point.y == -1))
1437 // Menu was invoked from the keyboard rather than by right-clicking
1438 CRect rect;
1439 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1440 m_ProgList.ClientToScreen(&rect);
1441 point = rect.CenterPoint();
1444 if ((selIndex >= 0)&&(!m_bThreadRunning))
1446 // entry is selected, thread has finished with updating so show the popup menu
1447 CIconMenu popup;
1448 if (popup.CreatePopupMenu())
1450 bool bAdded = false;
1451 NotificationData * data = m_arData[selIndex];
1452 if ((data)&&(!data->path.IsDirectory()))
1454 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1456 if (m_ProgList.GetSelectedCount() == 1)
1458 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1459 bAdded = true;
1462 if (data->bConflictedActionItem)
1464 if (m_ProgList.GetSelectedCount() == 1)
1466 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1467 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1468 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1470 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1471 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1473 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1474 popup.SetDefaultItem(ID_COMPARE, FALSE);
1476 if (m_ProgList.GetSelectedCount() == 1)
1478 if ((data->action == svn_wc_notify_add)||
1479 (data->action == svn_wc_notify_update_add)||
1480 (data->action == svn_wc_notify_commit_added)||
1481 (data->action == svn_wc_notify_commit_modified)||
1482 (data->action == svn_wc_notify_restore)||
1483 (data->action == svn_wc_notify_revert)||
1484 (data->action == svn_wc_notify_resolved)||
1485 (data->action == svn_wc_notify_commit_replaced)||
1486 (data->action == svn_wc_notify_commit_modified)||
1487 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1488 (data->action == svn_wc_notify_update_update))
1490 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1491 if (data->action == svn_wc_notify_update_update)
1492 popup.AppendMenu(MF_SEPARATOR, NULL);
1493 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1494 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1495 bAdded = true;
1498 } // if ((data)&&(!data->path.IsDirectory()))
1499 if (m_ProgList.GetSelectedCount() == 1)
1501 if (data)
1503 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1504 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1506 CTGitPath path = CTGitPath(sPath);
1507 if (path.GetDirectory().Exists())
1509 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1510 bAdded = true;
1515 if (m_ProgList.GetSelectedCount() > 0)
1517 if (bAdded)
1518 popup.AppendMenu(MF_SEPARATOR, NULL);
1519 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1520 bAdded = true;
1522 if (bAdded)
1524 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1525 DialogEnableWindow(IDOK, FALSE);
1526 this->SetPromptApp(&theApp);
1527 theApp.DoWaitCursor(1);
1528 bool bOpenWith = false;
1529 switch (cmd)
1531 case ID_COPY:
1533 CString sLines;
1534 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1535 while (pos)
1537 int nItem = m_ProgList.GetNextSelectedItem(pos);
1538 NotificationData * data = m_arData[nItem];
1539 if (data)
1541 sLines += data->sPathColumnText;
1542 sLines += _T("\r\n");
1545 sLines.TrimRight();
1546 if (!sLines.IsEmpty())
1548 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1551 break;
1552 case ID_EXPLORE:
1554 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1556 CTGitPath path = CTGitPath(sPath);
1557 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1559 break;
1560 case ID_COMPARE:
1562 svn_revnum_t rev = -1;
1563 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1564 if (data->basepath.IsEmpty())
1565 it = m_UpdateStartRevMap.begin();
1566 else
1567 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1568 if (it != m_UpdateStartRevMap.end())
1569 rev = it->second;
1570 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1571 if (data->content_state == svn_wc_notify_state_merged)
1573 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1574 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1575 SVN svn;
1576 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1578 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1579 DialogEnableWindow(IDOK, TRUE);
1580 break;
1582 // If necessary, convert the line-endings on the file before diffing
1583 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1585 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1586 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1588 temporaryFile.Reset();
1589 break;
1591 else
1593 newfile = temporaryFile;
1597 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1598 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1599 CString revname, wcname, basename;
1600 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1601 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1602 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1603 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1605 else
1607 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1608 SVN svn;
1609 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1611 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1612 DialogEnableWindow(IDOK, TRUE);
1613 break;
1615 else
1617 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1618 CString revname, wcname;
1619 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1620 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1621 CAppUtils::StartExtDiff(
1622 tempfile, data->path, revname, wcname,
1623 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1627 break;
1628 case ID_EDITCONFLICT:
1630 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1631 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1633 break;
1634 case ID_CONFLICTUSETHEIRS:
1635 case ID_CONFLICTUSEMINE:
1636 case ID_CONFLICTRESOLVE:
1638 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1639 switch (cmd)
1641 case ID_CONFLICTUSETHEIRS:
1642 result = svn_wc_conflict_choose_theirs_full;
1643 break;
1644 case ID_CONFLICTUSEMINE:
1645 result = svn_wc_conflict_choose_mine_full;
1646 break;
1647 case ID_CONFLICTRESOLVE:
1648 result = svn_wc_conflict_choose_merged;
1649 break;
1651 SVN svn;
1652 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1653 CString sResolvedPaths;
1654 while (pos)
1656 int nItem = m_ProgList.GetNextSelectedItem(pos);
1657 NotificationData * data = m_arData[nItem];
1658 if (data)
1660 if (data->bConflictedActionItem)
1662 if (!svn.Resolve(data->path, result, FALSE))
1664 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1665 DialogEnableWindow(IDOK, TRUE);
1666 break;
1668 else
1670 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1671 data->action = svn_wc_notify_resolved;
1672 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1673 data->bConflictedActionItem = false;
1674 m_nConflicts--;
1676 if (m_nConflicts==0)
1678 // When the last conflict is resolved we remove
1679 // the warning which we assume is in the last line.
1680 int nIndex = m_ProgList.GetItemCount()-1;
1681 VERIFY(m_ProgList.DeleteItem(nIndex));
1683 delete m_arData[nIndex];
1684 m_arData.pop_back();
1686 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1691 m_ProgList.Invalidate();
1692 CString info = BuildInfoString();
1693 SetDlgItemText(IDC_INFOTEXT, info);
1695 if (!sResolvedPaths.IsEmpty())
1697 CString msg;
1698 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1699 CMessageBox::Show(m_hWnd, msg, _T("TortoiseSVN"), MB_OK | MB_ICONINFORMATION);
1702 break;
1703 case ID_LOG:
1705 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
1706 int limit = (int)(DWORD)reg;
1707 svn_revnum_t rev = m_RevisionEnd;
1708 if (!data->basepath.IsEmpty())
1710 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1711 if (it != m_FinishedRevMap.end())
1712 rev = it->second;
1714 CLogDlg dlg;
1715 // fetch the log from HEAD, not the revision we updated to:
1716 // the path might be inside an external folder which has its own
1717 // revisions.
1718 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1719 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);
1720 dlg.DoModal();
1722 break;
1723 case ID_OPENWITH:
1724 bOpenWith = true;
1725 case ID_OPEN:
1727 int ret = 0;
1728 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1729 if (!bOpenWith)
1730 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1731 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1733 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1734 cmd += sWinPath + _T(" ");
1735 CAppUtils::LaunchApplication(cmd, NULL, false);
1739 DialogEnableWindow(IDOK, TRUE);
1740 theApp.DoWaitCursor(-1);
1741 } // if (bAdded)
1745 #endif
1748 void CGitProgressDlg::OnEnSetfocusInfotext()
1750 CString sTemp;
1751 GetDlgItemText(IDC_INFOTEXT, sTemp);
1752 if (sTemp.IsEmpty())
1753 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1756 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1758 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1759 #if 0
1760 int selIndex = m_ProgList.GetSelectionMark();
1761 if (selIndex < 0)
1762 return;
1764 CDropFiles dropFiles; // class for creating DROPFILES struct
1766 int index;
1767 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1768 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1770 NotificationData * data = m_arData[index];
1772 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1774 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1776 dropFiles.AddFile( sPath );
1780 if ( dropFiles.GetCount()>0 )
1782 dropFiles.CreateStructure();
1784 #endif
1785 *pResult = 0;
1788 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1790 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1791 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1793 if(!m_ProgList.m_hWnd)
1794 return;
1796 int count = m_ProgList.GetItemCount();
1797 if (count > 0)
1798 m_ProgList.EnsureVisible(count-1, false);
1802 //////////////////////////////////////////////////////////////////////////
1803 /// commands
1804 //////////////////////////////////////////////////////////////////////////
1805 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1808 localoperation = true;
1809 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1810 SetWindowText(sWindowTitle);
1811 SetBackgroundImage(IDI_ADD_BKG);
1812 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1814 for(int i=0;i<m_targetPathList.GetCount();i++)
1816 CString cmd,out;
1817 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());
1818 if(g_Git.Run(cmd,&out,CP_ACP))
1820 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1821 m_bErrorsOccurred=true;
1822 return false;
1824 Notify(m_targetPathList[i],git_wc_notify_add);
1826 #if 0
1827 if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))
1829 ReportSVNError();
1830 return false;
1832 #endif
1833 //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1834 m_bErrorsOccurred=false;
1835 return true;
1838 bool CGitProgressDlg::CmdCheckout(CString& sWindowTitle, bool& /*localoperation*/)
1840 #if 0
1841 ASSERT(m_targetPathList.GetCount() == 1);
1842 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CHECKOUT);
1843 SetBackgroundImage(IDI_CHECKOUT_BKG);
1844 CTGitPathList urls;
1845 urls.LoadFromAsteriskSeparatedString(m_url.GetSVNPathString());
1846 CTGitPath checkoutdir = m_targetPathList[0];
1847 for (int i=0; i<urls.GetCount(); ++i)
1849 sWindowTitle = urls[i].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1850 SetWindowText(sWindowTitle);
1851 checkoutdir = m_targetPathList[0];
1852 if (urls.GetCount() > 1)
1854 CString fileordir = urls[i].GetFileOrDirectoryName();
1855 fileordir = CPathUtils::PathUnescape(fileordir);
1856 checkoutdir.AppendPathString(fileordir);
1858 CString sCmdInfo;
1859 sCmdInfo.Format(IDS_PROGRS_CMD_CHECKOUT,
1860 (LPCTSTR)urls[i].GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
1861 (LPCTSTR)SVNStatus::GetDepthString(m_depth),
1862 m_options & ProgOptIgnoreExternals ? (LPCTSTR)sExtExcluded : (LPCTSTR)sExtIncluded);
1863 ReportCmd(sCmdInfo);
1865 if (!Checkout(urls[i], checkoutdir, m_Revision, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1867 if (m_ProgList.GetItemCount()!=0)
1869 ReportSVNError();
1870 return false;
1872 // if the checkout fails with the peg revision set to the checkout revision,
1873 // try again with HEAD as the peg revision.
1874 else
1876 if (!Checkout(urls[i], checkoutdir, SVNRev::REV_HEAD, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1878 ReportSVNError();
1879 return false;
1884 #endif
1885 return true;
1888 bool CGitProgressDlg::CmdCommit(CString& sWindowTitle, bool& /*localoperation*/)
1890 #if 0
1891 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COMMIT);
1892 SetWindowText(sWindowTitle);
1893 SetBackgroundImage(IDI_COMMIT_BKG);
1894 if (m_targetPathList.GetCount()==0)
1896 SetWindowText(sWindowTitle);
1898 DialogEnableWindow(IDCANCEL, FALSE);
1899 DialogEnableWindow(IDOK, TRUE);
1901 InterlockedExchange(&m_bThreadRunning, FALSE);
1902 return true;
1904 if (m_targetPathList.GetCount()==1)
1906 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1907 SetWindowText(sWindowTitle);
1909 BOOL isTag = FALSE;
1910 BOOL bURLFetched = FALSE;
1911 CString url;
1912 for (int i=0; i<m_targetPathList.GetCount(); ++i)
1914 if (bURLFetched == FALSE)
1916 url = GetURLFromPath(m_targetPathList[i]);
1917 if (!url.IsEmpty())
1918 bURLFetched = TRUE;
1919 CString urllower = url;
1920 urllower.MakeLower();
1921 // test if the commit goes to a tag.
1922 // now since Subversion doesn't force users to
1923 // create tags in the recommended /tags/ folder
1924 // only a warning is shown. This won't work if the tags
1925 // are stored in a non-recommended place, but the check
1926 // still helps those who do.
1927 if (urllower.Find(_T("/tags/"))>=0)
1928 isTag = TRUE;
1929 break;
1932 if (isTag)
1934 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_COMMITT_TRUNK, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)==IDNO)
1935 return false;
1937 DWORD exitcode = 0;
1938 CString error;
1939 if (CHooks::Instance().PreCommit(m_selectedPaths, m_depth, m_sMessage, exitcode, error))
1941 if (exitcode)
1943 CString temp;
1944 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1945 ReportError(temp);
1946 return false;
1950 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)));
1951 CStringArray changelists;
1952 if (!m_changelist.IsEmpty())
1953 changelists.Add(m_changelist);
1954 bool commitSuccessful = true;
1955 if (!Commit(m_targetPathList, m_sMessage, changelists, m_keepchangelist,
1956 m_depth, m_options & ProgOptKeeplocks))
1958 ReportSVNError();
1959 error = GetLastErrorMessage();
1960 // if a non-recursive commit failed with SVN_ERR_UNSUPPORTED_FEATURE,
1961 // that means a folder deletion couldn't be committed.
1962 if ((m_Revision != 0)&&(Err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
1964 ReportError(CString(MAKEINTRESOURCE(IDS_PROGRS_NONRECURSIVEHINT)));
1966 commitSuccessful = false;
1967 return false;
1969 if (!PostCommitErr.IsEmpty())
1971 ReportWarning(PostCommitErr);
1973 if (commitSuccessful)
1975 if (m_BugTraqProvider)
1977 CComPtr<IBugTraqProvider2> pProvider = NULL;
1978 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1979 if (SUCCEEDED(hr))
1981 BSTR commonRoot = SysAllocString(m_targetPathList.GetCommonRoot().GetDirectory().GetWinPath());
1982 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_targetPathList.GetCount());
1984 for (LONG index = 0; index < m_targetPathList.GetCount(); ++index)
1985 SafeArrayPutElement(pathList, &index, m_targetPathList[index].GetSVNPathString().AllocSysString());
1987 BSTR logMessage = m_sMessage.AllocSysString();
1989 BSTR temp = NULL;
1990 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1991 commonRoot,
1992 pathList,
1993 logMessage,
1994 (LONG)m_RevisionEnd,
1995 &temp)))
1997 CString sErr = temp;
1998 if (!sErr.IsEmpty())
1999 ReportError(temp);
2002 SysFreeString(temp);
2006 if (CHooks::Instance().PostCommit(m_selectedPaths, m_depth, m_RevisionEnd, m_sMessage, exitcode, error))
2008 if (exitcode)
2010 CString temp;
2011 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2012 ReportError(temp);
2013 return false;
2016 #endif
2017 return true;
2020 bool CGitProgressDlg::CmdCopy(CString& sWindowTitle, bool& /*localoperation*/)
2022 #if 0
2023 ASSERT(m_targetPathList.GetCount() == 1);
2024 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2025 SetWindowText(sWindowTitle);
2026 SetBackgroundImage(IDI_COPY_BKG);
2028 CString sCmdInfo;
2029 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2030 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2031 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2032 ReportCmd(sCmdInfo);
2034 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2036 ReportSVNError();
2037 return false;
2039 if (m_options & ProgOptSwitchAfterCopy)
2041 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2042 m_targetPathList[0].GetWinPath(),
2043 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2044 ReportCmd(sCmdInfo);
2045 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2047 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2049 ReportSVNError();
2050 return false;
2054 else
2056 if (SVN::PathIsURL(m_url))
2058 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2059 ReportNotification(sMsg);
2062 #endif
2063 return true;
2066 bool CGitProgressDlg::CmdExport(CString& sWindowTitle, bool& /*localoperation*/)
2068 #if 0
2069 ASSERT(m_targetPathList.GetCount() == 1);
2070 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2071 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2072 SetWindowText(sWindowTitle);
2073 SetBackgroundImage(IDI_EXPORT_BKG);
2074 CString eol;
2075 if (m_options & ProgOptEolCRLF)
2076 eol = _T("CRLF");
2077 if (m_options & ProgOptEolLF)
2078 eol = _T("LF");
2079 if (m_options & ProgOptEolCR)
2080 eol = _T("CR");
2081 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2082 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2084 ReportSVNError();
2085 return false;
2087 #endif
2088 return true;
2091 bool CGitProgressDlg::CmdImport(CString& sWindowTitle, bool& /*localoperation*/)
2093 #if 0
2094 ASSERT(m_targetPathList.GetCount() == 1);
2095 sWindowTitle.LoadString(IDS_PROGRS_TITLE_IMPORT);
2096 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2097 SetWindowText(sWindowTitle);
2098 SetBackgroundImage(IDI_IMPORT_BKG);
2099 CString sCmdInfo;
2100 sCmdInfo.Format(IDS_PROGRS_CMD_IMPORT,
2101 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2102 m_options & ProgOptIncludeIgnored ? (LPCTSTR)(_T(", ") + sIgnoredIncluded) : _T(""));
2103 ReportCmd(sCmdInfo);
2104 if (!Import(m_targetPathList[0], m_url, m_sMessage, &m_ProjectProperties, svn_depth_infinity, m_options & ProgOptIncludeIgnored ? true : false, false))
2106 ReportSVNError();
2107 return false;
2109 #endif
2110 return true;
2113 bool CGitProgressDlg::CmdLock(CString& sWindowTitle, bool& /*localoperation*/)
2115 #if 0
2116 sWindowTitle.LoadString(IDS_PROGRS_TITLE_LOCK);
2117 SetWindowText(sWindowTitle);
2118 SetBackgroundImage(IDI_LOCK_BKG);
2119 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_LOCK)));
2120 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2122 ReportSVNError();
2123 return false;
2125 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2126 if (m_bLockWarning)
2128 // the lock failed, because the file was outdated.
2129 // ask the user whether to update the file and try again
2130 if (CMessageBox::Show(m_hWnd, IDS_WARN_LOCKOUTDATED, IDS_APPNAME, MB_ICONQUESTION|MB_YESNO)==IDYES)
2132 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_UPDATEANDRETRY)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2133 if (!Update(m_targetPathList, SVNRev::REV_HEAD, svn_depth_files, false, true))
2135 ReportSVNError();
2136 return false;
2138 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2140 ReportSVNError();
2141 return false;
2145 if (m_bLockExists)
2147 // the locking failed because there already is a lock.
2148 // if the locking-dialog is skipped in the settings, tell the
2149 // user how to steal the lock anyway (i.e., how to get the lock
2150 // dialog back without changing the settings)
2151 if (!DWORD(CRegDWORD(_T("Software\\TortoiseGit\\ShowLockDlg"), TRUE)))
2153 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_LOCKHINT)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2155 return false;
2157 #endif
2158 return true;
2161 bool CGitProgressDlg::CmdMerge(CString& sWindowTitle, bool& /*localoperation*/)
2163 #if 0
2164 bool bFailed = false;
2165 ASSERT(m_targetPathList.GetCount() == 1);
2166 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2167 SetBackgroundImage(IDI_MERGE_BKG);
2168 if (m_options & ProgOptDryRun)
2170 sWindowTitle += _T(" ") + sDryRun;
2172 if (m_options & ProgOptRecordOnly)
2174 sWindowTitle += _T(" ") + sRecordOnly;
2176 SetWindowText(sWindowTitle);
2178 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_HIDE);
2179 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2180 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2181 if (DWORD(nonint))
2183 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2184 m_AlwaysConflicted = true;
2186 // we only accept a revision list to merge for peg merges
2187 ATLASSERT((m_revisionArray.GetCount()==0) || (m_revisionArray.GetCount() && (m_url.IsEquivalentTo(m_url2))));
2189 if (m_url.IsEquivalentTo(m_url2))
2191 CString sSuggestedMessage;
2192 CString sMergedLogMessage;
2193 CString sSeparator = CRegString(_T("Software\\TortoiseGit\\MergeLogSeparator"), _T("........"));
2194 CString temp;
2196 // Merging revisions %s of %s to %s into %s, %s%s
2197 CString sCmdInfo;
2198 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEPEG,
2199 (LPCTSTR)m_revisionArray.ToListString(),
2200 (LPCTSTR)m_url.GetSVNPathString(),
2201 m_targetPathList[0].GetWinPath(),
2202 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2203 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2204 ReportCmd(sCmdInfo);
2206 if (!PegMerge(m_url, m_revisionArray,
2207 m_pegRev.IsValid() ? m_pegRev : (m_url.IsUrl() ? SVNRev::REV_HEAD : SVNRev(SVNRev::REV_WC)),
2208 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2210 // if the merge fails with the peg revision set,
2211 // try again with HEAD as the peg revision.
2212 if (!PegMerge(m_url, m_revisionArray, SVNRev::REV_HEAD,
2213 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2215 ReportSVNError();
2216 bFailed = true;
2220 else
2222 CString sCmdInfo;
2223 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEURL,
2224 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
2225 (LPCTSTR)m_url2.GetSVNPathString(), (LPCTSTR)m_RevisionEnd.ToString(),
2226 m_targetPathList[0].GetWinPath(),
2227 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2228 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2229 ReportCmd(sCmdInfo);
2231 if (!Merge(m_url, m_Revision, m_url2, m_RevisionEnd, m_targetPathList[0],
2232 true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2234 ReportSVNError();
2235 bFailed = true;
2238 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2239 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_SHOW);
2240 return !bFailed;
2241 #endif
2242 return true;
2245 bool CGitProgressDlg::CmdMergeAll(CString& sWindowTitle, bool& /*localoperation*/)
2247 #if 0
2248 ASSERT(m_targetPathList.GetCount() == 1);
2249 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2250 SetBackgroundImage(IDI_MERGE_BKG);
2251 SetWindowText(sWindowTitle);
2253 ATLASSERT(m_targetPathList.GetCount() == 1);
2255 CString sCmdInfo;
2256 sCmdInfo.LoadString(IDS_PROGRS_INFOGETTINGINFO);
2257 ReportCmd(sCmdInfo);
2258 CTGitPathList suggestedSources;
2259 if (!SuggestMergeSources(m_targetPathList[0], m_Revision, suggestedSources))
2261 ReportSVNError();
2262 return false;
2265 if (suggestedSources.GetCount() == 0)
2267 CString sErr;
2268 sErr.Format(IDS_PROGRS_MERGEALLNOSOURCES, m_targetPathList[0].GetWinPath());
2269 ReportError(sErr);
2270 return false;
2272 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEALL,
2273 (LPCTSTR)suggestedSources[0].GetSVNPathString(),
2274 m_targetPathList[0].GetWinPath(),
2275 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry);
2276 ReportCmd(sCmdInfo);
2278 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2279 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2280 if (DWORD(nonint))
2282 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2283 m_AlwaysConflicted = true;
2286 SVNRevRangeArray revarray;
2287 if (!PegMerge(suggestedSources[0], revarray,
2288 SVNRev::REV_HEAD,
2289 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), FALSE))
2291 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2292 ReportSVNError();
2293 return false;
2296 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2297 #endif
2298 return true;
2301 bool CGitProgressDlg::CmdMergeReintegrate(CString& sWindowTitle, bool& /*localoperation*/)
2303 #if 0
2304 ASSERT(m_targetPathList.GetCount() == 1);
2305 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGEREINTEGRATE);
2306 SetBackgroundImage(IDI_MERGE_BKG);
2307 SetWindowText(sWindowTitle);
2309 CString sCmdInfo;
2310 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEREINTEGRATE,
2311 (LPCTSTR)m_url.GetSVNPathString(),
2312 m_targetPathList[0].GetWinPath());
2313 ReportCmd(sCmdInfo);
2315 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2316 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2317 if (DWORD(nonint))
2319 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2320 m_AlwaysConflicted = true;
2323 if (!MergeReintegrate(m_url, SVNRev::REV_HEAD, m_targetPathList[0], !!(m_options & ProgOptDryRun), m_diffoptions))
2325 ReportSVNError();
2326 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2327 return false;
2330 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2331 #endif
2332 return true;
2335 bool CGitProgressDlg::CmdRename(CString& sWindowTitle, bool& localoperation)
2337 #if 0
2338 ASSERT(m_targetPathList.GetCount() == 1);
2339 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2340 localoperation = true;
2341 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2342 SetWindowText(sWindowTitle);
2343 SetBackgroundImage(IDI_RENAME_BKG);
2344 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2345 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2347 ReportSVNError();
2348 return false;
2350 #endif
2351 return true;
2354 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2357 localoperation = true;
2358 ASSERT(m_targetPathList.GetCount() == 1);
2359 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2360 SetWindowText(sWindowTitle);
2361 SetBackgroundImage(IDI_RESOLVE_BKG);
2362 // check if the file may still have conflict markers in it.
2363 BOOL bMarkers = FALSE;
2365 for(int i=0;i<m_targetPathList.GetCount();i++)
2367 CString cmd,out,tempmergefile;
2368 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());
2369 if(g_Git.Run(cmd,&out,CP_ACP))
2371 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2372 m_bErrorsOccurred=true;
2373 return false;
2379 tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),(CTGitPath &)m_targetPathList[i]);
2380 CFile::Remove(tempmergefile);
2381 }catch(...)
2387 tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),(CTGitPath &)m_targetPathList[i]);
2388 CFile::Remove(tempmergefile);
2389 }catch(...)
2395 tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),(CTGitPath &)m_targetPathList[i]);
2396 CFile::Remove(tempmergefile);
2397 }catch(...)
2402 Notify(m_targetPathList[i],git_wc_notify_resolved);
2404 #if 0
2405 if ((m_options & ProgOptSkipConflictCheck) == 0)
2409 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2411 if (!m_targetPathList[fileindex].IsDirectory())
2413 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2414 CString strLine = _T("");
2415 while (file.ReadString(strLine))
2417 if (strLine.Find(_T("<<<<<<<"))==0)
2419 bMarkers = TRUE;
2420 break;
2423 file.Close();
2427 catch (CFileException* pE)
2429 TRACE(_T("CFileException in Resolve!\n"));
2430 TCHAR error[10000] = {0};
2431 pE->GetErrorMessage(error, 10000);
2432 ReportError(error);
2433 pE->Delete();
2434 return false;
2437 if (bMarkers)
2439 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2441 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2442 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2443 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2446 else
2448 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2449 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2450 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2452 #endif
2453 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2455 return true;
2458 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2460 #if 0
2461 localoperation = true;
2462 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2463 SetWindowText(sWindowTitle);
2464 SetBackgroundImage(IDI_REVERT_BKG);
2466 CTGitPathList delList = m_selectedPaths;
2467 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2468 delList.DeleteAllFiles(true);
2470 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2471 if (!Revert(m_targetPathList, CStringArray(), !!(m_options & ProgOptRecursive)))
2473 ReportSVNError();
2474 return false;
2476 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2477 #endif
2478 return true;
2481 bool CGitProgressDlg::CmdSwitch(CString& sWindowTitle, bool& /*localoperation*/)
2483 #if 0
2484 ASSERT(m_targetPathList.GetCount() == 1);
2485 SVNStatus st;
2486 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2487 SetWindowText(sWindowTitle);
2488 SetBackgroundImage(IDI_SWITCH_BKG);
2489 LONG rev = 0;
2490 if (st.GetStatus(m_targetPathList[0]) != (-2))
2492 if (st.status->entry != NULL)
2494 rev = st.status->entry->revision;
2498 CString sCmdInfo;
2499 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2500 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2501 (LPCTSTR)m_Revision.ToString());
2502 ReportCmd(sCmdInfo);
2504 bool depthIsSticky = true;
2505 if (m_depth == svn_depth_unknown)
2506 depthIsSticky = false;
2507 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2509 ReportSVNError();
2510 return false;
2512 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2513 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2514 &&((LONG)m_RevisionEnd > (LONG)rev))
2516 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2518 #endif
2519 return true;
2522 bool CGitProgressDlg::CmdUnlock(CString& sWindowTitle, bool& /*localoperation*/)
2524 #if 0
2525 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UNLOCK);
2526 SetWindowText(sWindowTitle);
2527 SetBackgroundImage(IDI_UNLOCK_BKG);
2528 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UNLOCK)));
2529 if (!Unlock(m_targetPathList, m_options & ProgOptLockForce))
2531 ReportSVNError();
2532 return false;
2534 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2535 #endif
2536 return true;
2539 bool CGitProgressDlg::CmdUpdate(CString& sWindowTitle, bool& /*localoperation*/)
2541 #if 0
2542 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UPDATE);
2543 SetWindowText(sWindowTitle);
2544 SetBackgroundImage(IDI_UPDATE_BKG);
2546 int targetcount = m_targetPathList.GetCount();
2547 CString sfile;
2548 CStringA uuid;
2549 StringRevMap uuidmap;
2550 SVNRev revstore = m_Revision;
2551 int nUUIDs = 0;
2552 for(int nItem = 0; nItem < targetcount; nItem++)
2554 const CTGitPath& targetPath = m_targetPathList[nItem];
2555 SVNStatus st;
2556 LONG headrev = -1;
2557 m_Revision = revstore;
2558 if (m_Revision.IsHead())
2560 if ((targetcount > 1)&&((headrev = st.GetStatus(targetPath, true)) != (-2)))
2562 if (st.status->entry != NULL)
2565 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2566 if (st.status->entry->uuid)
2568 uuid = st.status->entry->uuid;
2569 StringRevMap::iterator iter = uuidmap.lower_bound(uuid);
2570 if (iter == uuidmap.end() || iter->first != uuid)
2572 uuidmap.insert(iter, std::make_pair(uuid, headrev));
2573 nUUIDs++;
2575 else
2576 headrev = iter->second;
2577 m_Revision = headrev;
2579 else
2580 m_Revision = headrev;
2583 else
2585 if ((headrev = st.GetStatus(targetPath, FALSE)) != (-2))
2587 if (st.status->entry != NULL)
2588 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2591 if (uuidmap.size() > 1)
2592 m_Revision = SVNRev::REV_HEAD;
2593 } // if (m_Revision.IsHead())
2594 } // for(int nItem = 0; nItem < targetcount; nItem++)
2595 sWindowTitle = m_targetPathList.GetCommonRoot().GetWinPathString()+_T(" - ")+sWindowTitle;
2596 SetWindowText(sWindowTitle);
2598 DWORD exitcode = 0;
2599 CString error;
2600 if (CHooks::Instance().PreUpdate(m_targetPathList, m_depth, nUUIDs > 1 ? revstore : m_Revision, exitcode, error))
2602 if (exitcode)
2604 CString temp;
2605 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2606 ReportError(temp);
2607 return false;
2610 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UPDATE)));
2611 if (nUUIDs > 1)
2613 // the selected items are from different repositories,
2614 // so we have to update them separately
2615 for(int nItem = 0; nItem < targetcount; nItem++)
2617 const CTGitPath& targetPath = m_targetPathList[nItem];
2618 m_basePath = targetPath;
2619 CString sNotify;
2620 sNotify.Format(IDS_PROGRS_UPDATEPATH, m_basePath.GetWinPath());
2621 ReportString(sNotify, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2622 if (!Update(CTGitPathList(targetPath), revstore, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2624 ReportSVNError();
2625 return false;
2629 else
2631 // if we have only one target path, but that target path does not exist,
2632 // we have to check whether at least the parent path exists. If not,
2633 // then we have to update all paths in between the first path that exists and the
2634 // parent path of the one we want to update
2635 // This is required so a user can create a sparse checkout without having
2636 // to update all intermediate folders manually
2637 if ((m_targetPathList.GetCount() == 1) && (!m_targetPathList[0].Exists()))
2639 CTGitPath wcPath = m_targetPathList[0].GetContainingDirectory();
2640 CTGitPath existingParentPath = wcPath.GetContainingDirectory();
2641 while (!existingParentPath.Exists() && (existingParentPath.GetWinPathString().GetLength() > 2))
2643 existingParentPath = existingParentPath.GetContainingDirectory();
2645 if (existingParentPath.GetWinPathString().GetLength() && !existingParentPath.IsEquivalentTo(wcPath))
2647 // update all intermediate directories with depth 'empty'
2648 CTGitPath intermediatepath = existingParentPath;
2649 bool bSuccess = true;
2650 while (bSuccess && intermediatepath.IsAncestorOf(wcPath) && !intermediatepath.IsEquivalentTo(wcPath))
2652 CString childname = wcPath.GetWinPathString().Mid(intermediatepath.GetWinPathString().GetLength(),
2653 wcPath.GetWinPathString().Find('\\', intermediatepath.GetWinPathString().GetLength()+1)-intermediatepath.GetWinPathString().GetLength());
2654 if (childname.IsEmpty())
2655 intermediatepath = wcPath;
2656 else
2657 intermediatepath.AppendPathString(childname);
2658 bSuccess = !!Update(CTGitPathList(intermediatepath), m_Revision, svn_depth_empty, false, true);
2661 if (!bSuccess)
2663 ReportSVNError();
2664 return false;
2668 if (!Update(m_targetPathList, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2670 ReportSVNError();
2671 return false;
2674 if (CHooks::Instance().PostUpdate(m_targetPathList, m_depth, m_RevisionEnd, exitcode, error))
2676 if (exitcode)
2678 CString temp;
2679 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2680 ReportError(temp);
2681 return false;
2685 // after an update, show the user the log button, but only if only one single item was updated
2686 // (either a file or a directory)
2687 if ((m_targetPathList.GetCount() == 1)&&(m_UpdateStartRevMap.size()>0))
2688 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2689 #endif
2690 return true;
2693 void CGitProgressDlg::OnBnClickedNoninteractive()
2695 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2696 m_AlwaysConflicted = (res == BST_CHECKED);
2697 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2698 nonint = m_AlwaysConflicted;
2701 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2703 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2704 if (sPath.Find(':')<0)
2706 // the path is not absolute: add the common root of all paths to it
2707 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2709 return sPath;
2712 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2714 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2715 SetWindowText(sWindowTitle);
2716 //SetBackgroundImage(IDI_ADD_BKG);
2717 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2718 bool ret=true;
2719 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2721 CString error;
2722 CTGitPath path;
2723 Notify(path,git_wc_notify_sendmail_start);
2724 CString err;
2725 int retry=0;
2726 while(retry <3)
2728 if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,&err))
2730 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2731 ret = false;
2733 else
2735 break;
2738 retry++;
2739 Sleep(2000);
2740 if(m_bCancelled)
2742 Notify(path,git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));
2743 return false;
2746 Notify(path,git_wc_notify_sendmail_done,ret);
2748 }else
2750 for(int i=0;i<m_targetPathList.GetCount();i++)
2752 CPatch patch;
2753 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2755 int retry=0;
2756 while(retry<3)
2758 int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2759 this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT);
2760 if(ret)
2762 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2763 ret = false;
2765 }else
2767 break;
2769 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2771 retry++;
2772 Sleep(2000);
2773 if(m_bCancelled)
2775 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));
2776 return false;
2779 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2783 return ret;