Fixed Issue #138: "Format patch" in "Show log" dialog doesn't work
[TortoiseGit.git] / src / TortoiseProc / SVNProgressDlg.cpp
blobec9ea41034808b6d9164c4ff6321b591743e1e72
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 case git_wc_notify_revert:
310 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
311 break;
313 #if 0
314 case svn_wc_notify_commit_added:
315 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
316 data->color = m_Colors.GetColor(CColors::Added);
317 break;
318 case svn_wc_notify_copy:
319 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
320 break;
321 case svn_wc_notify_commit_modified:
322 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
323 data->color = m_Colors.GetColor(CColors::Modified);
324 break;
325 case svn_wc_notify_delete:
326 case svn_wc_notify_update_delete:
327 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
328 m_bMergesAddsDeletesOccurred = true;
329 data->color = m_Colors.GetColor(CColors::Deleted);
330 break;
331 case svn_wc_notify_commit_deleted:
332 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
333 data->color = m_Colors.GetColor(CColors::Deleted);
334 break;
335 case svn_wc_notify_restore:
336 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
337 break;
339 case svn_wc_notify_update_replace:
340 case svn_wc_notify_commit_replaced:
341 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
342 data->color = m_Colors.GetColor(CColors::Deleted);
343 break;
344 case svn_wc_notify_exists:
345 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
347 data->color = m_Colors.GetColor(CColors::Conflict);
348 data->bConflictedActionItem = true;
349 m_nConflicts++;
350 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
352 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
354 data->color = m_Colors.GetColor(CColors::Merged);
355 m_bMergesAddsDeletesOccurred = true;
356 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
358 else
359 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
360 break;
361 case svn_wc_notify_update_update:
362 // if this is an inoperative dir change, don't show the notification.
363 // an inoperative dir change is when a directory gets updated without
364 // any real change in either text or properties.
365 if ((kind == svn_node_dir)
366 && ((prop_state == svn_wc_notify_state_inapplicable)
367 || (prop_state == svn_wc_notify_state_unknown)
368 || (prop_state == svn_wc_notify_state_unchanged)))
370 bNoNotify = true;
371 break;
373 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
375 data->color = m_Colors.GetColor(CColors::Conflict);
376 data->bConflictedActionItem = true;
377 m_nConflicts++;
378 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
380 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
382 data->color = m_Colors.GetColor(CColors::Merged);
383 m_bMergesAddsDeletesOccurred = true;
384 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
386 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
387 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
389 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
391 else
393 bNoNotify = true;
394 break;
396 if (lock_state == svn_wc_notify_lock_state_unlocked)
398 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
399 data->sActionColumnText += _T(", ") + temp;
401 break;
403 case svn_wc_notify_update_external:
404 // For some reason we build a list of externals...
405 m_ExtStack.AddHead(path.GetUIPathString());
406 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
407 data->bAuxItem = true;
408 break;
410 case svn_wc_notify_update_completed:
412 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
413 data->bAuxItem = true;
414 bool bEmpty = !!m_ExtStack.IsEmpty();
415 if (!bEmpty)
416 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
417 else
418 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
420 if ((m_nConflicts>0)&&(bEmpty))
422 // We're going to add another aux item - let's shove this current onto the list first
423 // I don't really like this, but it will do for the moment.
424 m_arData.push_back(data);
425 AddItemToList();
427 data = new NotificationData();
428 data->bAuxItem = true;
429 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
430 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
431 data->color = m_Colors.GetColor(CColors::Conflict);
432 CSoundUtils::PlayTSVNWarning();
433 // This item will now be added after the switch statement
435 if (!m_basePath.IsEmpty())
436 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
437 m_RevisionEnd = rev;
438 m_bFinishedItemAdded = true;
440 break;
441 case svn_wc_notify_commit_postfix_txdelta:
442 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
443 break;
444 case svn_wc_notify_failed_revert:
445 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
446 break;
447 case svn_wc_notify_status_completed:
448 case svn_wc_notify_status_external:
449 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
450 break;
451 case svn_wc_notify_skip:
452 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
454 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
456 // The color settings dialog describes the red color with
457 // "possible or real conflict / obstructed" which also applies to
458 // skipped targets during a merge. So we just use the same color.
459 data->color = m_Colors.GetColor(CColors::Conflict);
461 else
462 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
463 break;
464 case svn_wc_notify_locked:
465 if ((lock)&&(lock->owner))
466 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
467 break;
468 case svn_wc_notify_unlocked:
469 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
470 break;
471 case svn_wc_notify_failed_lock:
472 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
473 m_arData.push_back(data);
474 AddItemToList();
475 ReportError(SVN::GetErrorString(err));
476 bDoAddData = false;
477 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
478 m_bLockWarning = true;
479 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
480 m_bLockExists = true;
481 break;
482 case svn_wc_notify_failed_unlock:
483 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
484 m_arData.push_back(data);
485 AddItemToList();
486 ReportError(SVN::GetErrorString(err));
487 bDoAddData = false;
488 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
489 m_bLockWarning = true;
490 break;
491 case svn_wc_notify_changelist_set:
492 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
493 break;
494 case svn_wc_notify_changelist_clear:
495 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
496 break;
497 case svn_wc_notify_changelist_moved:
498 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
499 break;
500 case svn_wc_notify_foreign_merge_begin:
501 case svn_wc_notify_merge_begin:
502 if (range == NULL)
503 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
504 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
505 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
506 else if (data->merge_range.start - 1 == data->merge_range.end)
507 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
508 else if (data->merge_range.start < data->merge_range.end)
509 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
510 else
511 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
512 data->bAuxItem = true;
513 break;
514 #endif
515 default:
516 break;
517 } // switch (data->action)
519 if (bNoNotify)
520 delete data;
521 else
523 if (bDoAddData)
525 m_arData.push_back(data);
526 AddItemToList();
527 if ((!data->bAuxItem) && (m_itemCount > 0))
529 m_itemCount--;
531 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
532 progControl->ShowWindow(SW_SHOW);
533 progControl->SetPos(m_itemCountTotal - m_itemCount);
534 progControl->SetRange32(0, m_itemCountTotal);
537 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
539 // ResizeColumns();
540 // bSecondResized = TRUE;
544 return TRUE;
548 CString CGitProgressDlg::BuildInfoString()
550 CString infotext;
551 #if 0
553 CString temp;
554 int added = 0;
555 int copied = 0;
556 int deleted = 0;
557 int restored = 0;
558 int reverted = 0;
559 int resolved = 0;
560 int conflicted = 0;
561 int updated = 0;
562 int merged = 0;
563 int modified = 0;
564 int skipped = 0;
565 int replaced = 0;
567 for (size_t i=0; i<m_arData.size(); ++i)
569 const NotificationData * dat = m_arData[i];
570 switch (dat->action)
572 case svn_wc_notify_add:
573 case svn_wc_notify_update_add:
574 case svn_wc_notify_commit_added:
575 if (dat->bConflictedActionItem)
576 conflicted++;
577 else
578 added++;
579 break;
580 case svn_wc_notify_copy:
581 copied++;
582 break;
583 case svn_wc_notify_delete:
584 case svn_wc_notify_update_delete:
585 case svn_wc_notify_commit_deleted:
586 deleted++;
587 break;
588 case svn_wc_notify_restore:
589 restored++;
590 break;
591 case svn_wc_notify_revert:
592 reverted++;
593 break;
594 case svn_wc_notify_resolved:
595 resolved++;
596 break;
597 case svn_wc_notify_update_update:
598 if (dat->bConflictedActionItem)
599 conflicted++;
600 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
601 merged++;
602 else
603 updated++;
604 break;
605 case svn_wc_notify_commit_modified:
606 modified++;
607 break;
608 case svn_wc_notify_skip:
609 skipped++;
610 break;
611 case svn_wc_notify_commit_replaced:
612 replaced++;
613 break;
616 if (conflicted)
618 temp.LoadString(IDS_SVNACTION_CONFLICTED);
619 infotext += temp;
620 temp.Format(_T(":%d "), conflicted);
621 infotext += temp;
623 if (skipped)
625 temp.LoadString(IDS_SVNACTION_SKIP);
626 infotext += temp;
627 infotext.AppendFormat(_T(":%d "), skipped);
629 if (merged)
631 temp.LoadString(IDS_SVNACTION_MERGED);
632 infotext += temp;
633 infotext.AppendFormat(_T(":%d "), merged);
635 if (added)
637 temp.LoadString(IDS_SVNACTION_ADD);
638 infotext += temp;
639 infotext.AppendFormat(_T(":%d "), added);
641 if (deleted)
643 temp.LoadString(IDS_SVNACTION_DELETE);
644 infotext += temp;
645 infotext.AppendFormat(_T(":%d "), deleted);
647 if (modified)
649 temp.LoadString(IDS_SVNACTION_MODIFIED);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), modified);
653 if (copied)
655 temp.LoadString(IDS_SVNACTION_COPY);
656 infotext += temp;
657 infotext.AppendFormat(_T(":%d "), copied);
659 if (replaced)
661 temp.LoadString(IDS_SVNACTION_REPLACED);
662 infotext += temp;
663 infotext.AppendFormat(_T(":%d "), replaced);
665 if (updated)
667 temp.LoadString(IDS_SVNACTION_UPDATE);
668 infotext += temp;
669 infotext.AppendFormat(_T(":%d "), updated);
671 if (restored)
673 temp.LoadString(IDS_SVNACTION_RESTORE);
674 infotext += temp;
675 infotext.AppendFormat(_T(":%d "), restored);
677 if (reverted)
679 temp.LoadString(IDS_SVNACTION_REVERT);
680 infotext += temp;
681 infotext.AppendFormat(_T(":%d "), reverted);
683 if (resolved)
685 temp.LoadString(IDS_SVNACTION_RESOLVE);
686 infotext += temp;
687 infotext.AppendFormat(_T(":%d "), resolved);
689 #endif
690 return infotext;
693 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
695 m_selectedPaths = selPaths;
698 void CGitProgressDlg::ResizeColumns()
700 m_ProgList.SetRedraw(FALSE);
702 TCHAR textbuf[MAX_PATH];
704 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
705 for (int col = 0; col <= maxcol; col++)
707 // find the longest width of all items
708 int count = m_ProgList.GetItemCount();
709 HDITEM hdi = {0};
710 hdi.mask = HDI_TEXT;
711 hdi.pszText = textbuf;
712 hdi.cchTextMax = sizeof(textbuf);
713 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
714 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
716 for (int index = 0; index<count; ++index)
718 // get the width of the string and add 12 pixels for the column separator and margins
719 int linewidth = cx;
720 switch (col)
722 case 0:
723 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
724 break;
725 case 1:
726 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
727 break;
728 case 2:
729 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
730 break;
732 if (cx < linewidth)
733 cx = linewidth;
735 m_ProgList.SetColumnWidth(col, cx);
738 m_ProgList.SetRedraw(TRUE);
741 BOOL CGitProgressDlg::OnInitDialog()
743 __super::OnInitDialog();
745 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
747 m_ProgList.DeleteAllItems();
748 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
749 while (c>=0)
750 m_ProgList.DeleteColumn(c--);
751 CString temp;
752 temp.LoadString(IDS_PROGRS_ACTION);
753 m_ProgList.InsertColumn(0, temp);
754 temp.LoadString(IDS_PROGRS_PATH);
755 m_ProgList.InsertColumn(1, temp);
756 temp.LoadString(IDS_PROGRS_MIMETYPE);
757 m_ProgList.InsertColumn(2, temp);
759 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
760 if (m_pThread==NULL)
762 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
764 else
766 m_pThread->m_bAutoDelete = FALSE;
767 m_pThread->ResumeThread();
770 UpdateData(FALSE);
772 // Call this early so that the column headings aren't hidden before any
773 // text gets added.
774 ResizeColumns();
776 SetTimer(VISIBLETIMER, 300, NULL);
778 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
779 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
780 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
781 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
782 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
783 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
784 AddAnchor(IDOK, BOTTOM_RIGHT);
785 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
786 //SetPromptParentWindow(this->m_hWnd);
787 if (hWndExplorer)
788 CenterWindow(CWnd::FromHandle(hWndExplorer));
789 EnableSaveRestore(_T("SVNProgressDlg"));
790 return TRUE;
793 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
795 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
798 #if 0
799 void CGitProgressDlg::ReportSVNError()
801 ReportError(GetLastErrorMessage());
803 #endif
805 void CGitProgressDlg::ReportError(const CString& sError)
807 CSoundUtils::PlayTGitError();
808 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
809 m_bErrorsOccurred = true;
812 void CGitProgressDlg::ReportWarning(const CString& sWarning)
814 CSoundUtils::PlayTGitWarning();
815 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
818 void CGitProgressDlg::ReportNotification(const CString& sNotification)
820 CSoundUtils::PlayTGitNotification();
821 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
824 void CGitProgressDlg::ReportCmd(const CString& sCmd)
826 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
829 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
831 // instead of showing a dialog box with the error message or notification,
832 // just insert the error text into the list control.
833 // that way the user isn't 'interrupted' by a dialog box popping up!
835 // the message may be split up into different lines
836 // so add a new entry for each line of the message
837 while (!sMessage.IsEmpty())
839 NotificationData * data = new NotificationData();
840 data->bAuxItem = true;
841 data->sActionColumnText = sMsgKind;
842 if (sMessage.Find('\n')>=0)
843 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
844 else
845 data->sPathColumnText = sMessage;
846 data->sPathColumnText.Trim(_T("\n\r"));
847 data->color = color;
848 if (sMessage.Find('\n')>=0)
850 sMessage = sMessage.Mid(sMessage.Find('\n'));
851 sMessage.Trim(_T("\n\r"));
853 else
854 sMessage.Empty();
855 m_arData.push_back(data);
856 AddItemToList();
860 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
862 return ((CGitProgressDlg*)pVoid)->ProgressThread();
865 UINT CGitProgressDlg::ProgressThread()
867 // The SetParams function should have loaded something for us
869 CString temp;
870 CString sWindowTitle;
871 bool localoperation = false;
872 bool bSuccess = false;
873 m_AlwaysConflicted = false;
875 DialogEnableWindow(IDOK, FALSE);
876 DialogEnableWindow(IDCANCEL, TRUE);
877 // SetAndClearProgressInfo(m_hWnd);
878 m_itemCount = m_itemCountTotal;
880 InterlockedExchange(&m_bThreadRunning, TRUE);
881 iFirstResized = 0;
882 bSecondResized = FALSE;
883 m_bFinishedItemAdded = false;
884 CTime startTime = CTime::GetCurrentTime();
885 switch (m_Command)
887 case GitProgress_Add:
888 bSuccess = CmdAdd(sWindowTitle, localoperation);
889 break;
890 case GitProgress_Checkout:
891 bSuccess = CmdCheckout(sWindowTitle, localoperation);
892 break;
893 case GitProgress_Commit:
894 bSuccess = CmdCommit(sWindowTitle, localoperation);
895 break;
896 case GitProgress_Copy:
897 bSuccess = CmdCopy(sWindowTitle, localoperation);
898 break;
899 case GitProgress_Export:
900 bSuccess = CmdExport(sWindowTitle, localoperation);
901 break;
902 case GitProgress_Import:
903 bSuccess = CmdImport(sWindowTitle, localoperation);
904 break;
905 case GitProgress_Lock:
906 bSuccess = CmdLock(sWindowTitle, localoperation);
907 break;
908 case GitProgress_Merge:
909 bSuccess = CmdMerge(sWindowTitle, localoperation);
910 break;
911 case GitProgress_MergeAll:
912 bSuccess = CmdMergeAll(sWindowTitle, localoperation);
913 break;
914 case GitProgress_MergeReintegrate:
915 bSuccess = CmdMergeReintegrate(sWindowTitle, localoperation);
916 break;
917 case GitProgress_Rename:
918 bSuccess = CmdRename(sWindowTitle, localoperation);
919 break;
920 case GitProgress_Resolve:
921 bSuccess = CmdResolve(sWindowTitle, localoperation);
922 break;
923 case GitProgress_Revert:
924 bSuccess = CmdRevert(sWindowTitle, localoperation);
925 break;
926 case GitProgress_Switch:
927 bSuccess = CmdSwitch(sWindowTitle, localoperation);
928 break;
929 case GitProgress_Unlock:
930 bSuccess = CmdUnlock(sWindowTitle, localoperation);
931 break;
932 case GitProgress_Update:
933 bSuccess = CmdUpdate(sWindowTitle, localoperation);
934 break;
935 case GitProgress_SendMail:
936 bSuccess = CmdSendMail(sWindowTitle, localoperation);
937 break;
939 if (!bSuccess)
940 temp.LoadString(IDS_PROGRS_TITLEFAILED);
941 else
942 temp.LoadString(IDS_PROGRS_TITLEFIN);
943 sWindowTitle = sWindowTitle + _T(" ") + temp;
944 SetWindowText(sWindowTitle);
946 KillTimer(TRANSFERTIMER);
947 KillTimer(VISIBLETIMER);
949 DialogEnableWindow(IDCANCEL, FALSE);
950 DialogEnableWindow(IDOK, TRUE);
952 CString info = BuildInfoString();
953 if (!bSuccess)
954 info.LoadString(IDS_PROGRS_INFOFAILED);
955 SetDlgItemText(IDC_INFOTEXT, info);
956 ResizeColumns();
957 SendMessage(DM_SETDEFID, IDOK);
958 GetDlgItem(IDOK)->SetFocus();
960 CString sFinalInfo;
961 if (!m_sTotalBytesTransferred.IsEmpty())
963 CTimeSpan time = CTime::GetCurrentTime() - startTime;
964 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
965 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
966 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
968 else
969 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
971 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
973 if (!m_bFinishedItemAdded)
975 // there's no "finished: xxx" line at the end. We add one here to make
976 // sure the user sees that the command is actually finished.
977 NotificationData * data = new NotificationData();
978 data->bAuxItem = true;
979 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
980 m_arData.push_back(data);
981 AddItemToList();
984 int count = m_ProgList.GetItemCount();
985 if ((count > 0)&&(m_bLastVisible))
986 m_ProgList.EnsureVisible(count-1, FALSE);
988 CLogFile logfile;
989 if (logfile.Open())
991 logfile.AddTimeLine();
992 for (size_t i=0; i<m_arData.size(); i++)
994 NotificationData * data = m_arData[i];
995 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
996 logfile.AddLine(temp);
998 if (!sFinalInfo.IsEmpty())
999 logfile.AddLine(sFinalInfo);
1000 logfile.Close();
1003 m_bCancelled = TRUE;
1004 InterlockedExchange(&m_bThreadRunning, FALSE);
1005 RefreshCursor();
1007 DWORD dwAutoClose = CRegStdWORD(_T("Software\\TortoiseGit\\AutoClose"));
1008 if (m_options & ProgOptDryRun)
1009 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1010 if (!m_bLastVisible)
1011 dwAutoClose = 0;
1012 if (m_dwCloseOnEnd != (DWORD)-1)
1013 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1014 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1015 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1016 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1017 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1018 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1019 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1020 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1021 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1023 //Don't do anything here which might cause messages to be sent to the window
1024 //The window thread is probably now blocked in OnOK if we've done an auto close
1025 return 0;
1028 void CGitProgressDlg::OnBnClickedLogbutton()
1030 #if 0
1031 if (m_targetPathList.GetCount() != 1)
1032 return;
1033 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1034 svn_revnum_t rev = -1;
1035 if (it != m_UpdateStartRevMap.end())
1037 rev = it->second;
1039 CLogDlg dlg;
1040 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1041 dlg.DoModal();
1042 #endif
1046 void CGitProgressDlg::OnClose()
1048 if (m_bCancelled)
1050 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1051 InterlockedExchange(&m_bThreadRunning, FALSE);
1053 else
1055 m_bCancelled = TRUE;
1056 return;
1058 DialogEnableWindow(IDCANCEL, TRUE);
1059 __super::OnClose();
1062 void CGitProgressDlg::OnOK()
1064 if ((m_bCancelled)&&(!m_bThreadRunning))
1066 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1067 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1068 // don't do any more operations on the window which might require message passing
1069 // If you try to send windows messages once we're waiting here, then the thread can't finished
1070 // because the Window's message loop is blocked at this wait
1071 WaitForSingleObject(m_pThread->m_hThread, 10000);
1072 __super::OnOK();
1074 m_bCancelled = TRUE;
1077 void CGitProgressDlg::OnCancel()
1079 if ((m_bCancelled)&&(!m_bThreadRunning))
1080 __super::OnCancel();
1081 m_bCancelled = TRUE;
1084 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1086 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1088 if (pDispInfo)
1090 if (pDispInfo->item.mask & LVIF_TEXT)
1092 if (pDispInfo->item.iItem < (int)m_arData.size())
1094 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1095 switch (pDispInfo->item.iSubItem)
1097 case 0:
1098 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1099 break;
1100 case 1:
1101 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1102 if (!data->bAuxItem)
1104 int cWidth = m_ProgList.GetColumnWidth(1);
1105 cWidth = max(12, cWidth-12);
1106 CDC * pDC = m_ProgList.GetDC();
1107 if (pDC != NULL)
1109 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1110 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1111 pDC->SelectObject(pFont);
1112 ReleaseDC(pDC);
1115 break;
1116 case 2:
1117 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1118 break;
1119 default:
1120 m_columnbuf[0] = 0;
1122 pDispInfo->item.pszText = m_columnbuf;
1126 *pResult = 0;
1129 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1131 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1133 // Take the default processing unless we set this to something else below.
1134 *pResult = CDRF_DODEFAULT;
1136 // First thing - check the draw stage. If it's the control's prepaint
1137 // stage, then tell Windows we want messages for every item.
1139 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1141 *pResult = CDRF_NOTIFYITEMDRAW;
1143 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1145 // This is the prepaint stage for an item. Here's where we set the
1146 // item's text color. Our return value will tell Windows to draw the
1147 // item itself, but it will use the new color we set here.
1149 // Tell Windows to paint the control itself.
1150 *pResult = CDRF_DODEFAULT;
1152 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1153 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1155 return;
1157 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1158 ASSERT(data != NULL);
1159 if (data == NULL)
1160 return;
1162 // Store the color back in the NMLVCUSTOMDRAW struct.
1163 pLVCD->clrText = data->color;
1167 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1169 #if 0
1170 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1171 *pResult = 0;
1172 if (pNMLV->iItem < 0)
1173 return;
1174 if (m_options & ProgOptDryRun)
1175 return; //don't do anything in a dry-run.
1177 const NotificationData * data = m_arData[pNMLV->iItem];
1178 if (data == NULL)
1179 return;
1181 if (data->bConflictedActionItem)
1183 // We've double-clicked on a conflicted item - do a three-way merge on it
1184 SVNDiff::StartConflictEditor(data->path);
1186 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))
1188 // This is a modified file which has been merged on update. Diff it against base
1189 CTGitPath temporaryFile;
1190 SVNDiff diff(this, this->m_hWnd, true);
1191 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1192 svn_revnum_t baseRev = 0;
1193 diff.DiffFileAgainstBase(data->path, baseRev);
1195 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1197 bool bOpenWith = false;
1198 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1199 if (ret <= HINSTANCE_ERROR)
1200 bOpenWith = true;
1201 if (bOpenWith)
1203 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1204 cmd += data->path.GetWinPathString() + _T(" ");
1205 CAppUtils::LaunchApplication(cmd, NULL, false);
1208 #endif
1211 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1213 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1214 if (m_bThreadRunning)
1215 return;
1216 if (m_nSortedColumn == phdr->iItem)
1217 m_bAscending = !m_bAscending;
1218 else
1219 m_bAscending = TRUE;
1220 m_nSortedColumn = phdr->iItem;
1221 Sort();
1223 CString temp;
1224 m_ProgList.SetRedraw(FALSE);
1225 m_ProgList.DeleteAllItems();
1226 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1228 m_ProgList.SetRedraw(TRUE);
1230 *pResult = 0;
1233 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1235 return pData->bAuxItem;
1238 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM lParam)
1240 #if 0
1241 SVNProgress * pProgressData = (SVNProgress *)lParam;
1242 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1243 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1245 progControl->ShowWindow(SW_SHOW);
1247 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1249 progControl->ShowWindow(SW_HIDE);
1251 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1252 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1253 SetTimer(TRANSFERTIMER, 2000, NULL);
1254 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1256 progControl->SetPos((int)pProgressData->progress);
1257 progControl->SetRange32(0, (int)pProgressData->total);
1259 CString progText;
1260 if (pProgressData->overall_total < 1024)
1261 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1262 else if (pProgressData->overall_total < 1200000)
1263 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1264 else
1265 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1266 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1267 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1268 #endif
1269 return 0;
1272 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1274 if (nIDEvent == TRANSFERTIMER)
1276 CString progText;
1277 CString progSpeed;
1278 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1279 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1280 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1281 KillTimer(TRANSFERTIMER);
1283 if (nIDEvent == VISIBLETIMER)
1285 if (nEnsureVisibleCount)
1286 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1287 nEnsureVisibleCount = 0;
1291 void CGitProgressDlg::Sort()
1293 if(m_arData.size() < 2)
1295 return;
1298 // We need to sort the blocks which lie between the auxiliary entries
1299 // This is so that any aux data stays where it was
1300 NotificationDataVect::iterator actionBlockBegin;
1301 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1303 for(;;)
1305 // Search to the start of the non-aux entry in the next block
1306 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1307 if(actionBlockBegin == m_arData.end())
1309 // There are no more actions
1310 break;
1312 // Now search to find the end of the block
1313 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1314 // Now sort the block
1315 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1319 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1321 int result = 0;
1322 switch (m_nSortedColumn)
1324 case 0: //action column
1325 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1326 break;
1327 case 1: //path column
1328 // Compare happens after switch()
1329 break;
1330 case 2: //mime-type column
1331 result = pData1->mime_type.Compare(pData2->mime_type);
1332 break;
1333 default:
1334 break;
1337 // Sort by path if everything else is equal
1338 if (result == 0)
1340 result = CTGitPath::Compare(pData1->path, pData2->path);
1343 if (!m_bAscending)
1344 result = -result;
1345 return result < 0;
1348 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1350 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1352 // only show the wait cursor over the list control
1353 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1355 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1356 SetCursor(hCur);
1357 return TRUE;
1360 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1361 SetCursor(hCur);
1362 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1365 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1367 if (pMsg->message == WM_KEYDOWN)
1369 if (pMsg->wParam == VK_ESCAPE)
1371 // pressing the ESC key should close the dialog. But since we disabled the escape
1372 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1373 // this won't work.
1374 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1375 // the impression that the OK button was pressed.
1376 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1377 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1379 // since we convert ESC to RETURN, make sure the OK button has the focus.
1380 GetDlgItem(IDOK)->SetFocus();
1381 pMsg->wParam = VK_RETURN;
1384 if (pMsg->wParam == 'A')
1386 if (GetKeyState(VK_CONTROL)&0x8000)
1388 // Ctrl-A -> select all
1389 m_ProgList.SetSelectionMark(0);
1390 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1392 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1396 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1398 int selIndex = m_ProgList.GetSelectionMark();
1399 if (selIndex >= 0)
1401 if (GetKeyState(VK_CONTROL)&0x8000)
1403 //Ctrl-C -> copy to clipboard
1404 CString sClipdata;
1405 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1406 if (pos != NULL)
1408 while (pos)
1410 int nItem = m_ProgList.GetNextSelectedItem(pos);
1411 CString sAction = m_ProgList.GetItemText(nItem, 0);
1412 CString sPath = m_ProgList.GetItemText(nItem, 1);
1413 CString sMime = m_ProgList.GetItemText(nItem, 2);
1414 CString sLogCopyText;
1415 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1416 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1417 sClipdata += sLogCopyText;
1419 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1424 } // if (pMsg->message == WM_KEYDOWN)
1425 return __super::PreTranslateMessage(pMsg);
1428 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1430 #if 0
1431 if (m_options & ProgOptDryRun)
1432 return; // don't do anything in a dry-run.
1434 if (pWnd == &m_ProgList)
1436 int selIndex = m_ProgList.GetSelectionMark();
1437 if ((point.x == -1) && (point.y == -1))
1439 // Menu was invoked from the keyboard rather than by right-clicking
1440 CRect rect;
1441 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1442 m_ProgList.ClientToScreen(&rect);
1443 point = rect.CenterPoint();
1446 if ((selIndex >= 0)&&(!m_bThreadRunning))
1448 // entry is selected, thread has finished with updating so show the popup menu
1449 CIconMenu popup;
1450 if (popup.CreatePopupMenu())
1452 bool bAdded = false;
1453 NotificationData * data = m_arData[selIndex];
1454 if ((data)&&(!data->path.IsDirectory()))
1456 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1458 if (m_ProgList.GetSelectedCount() == 1)
1460 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1461 bAdded = true;
1464 if (data->bConflictedActionItem)
1466 if (m_ProgList.GetSelectedCount() == 1)
1468 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1469 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1470 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1472 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1473 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1475 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1476 popup.SetDefaultItem(ID_COMPARE, FALSE);
1478 if (m_ProgList.GetSelectedCount() == 1)
1480 if ((data->action == svn_wc_notify_add)||
1481 (data->action == svn_wc_notify_update_add)||
1482 (data->action == svn_wc_notify_commit_added)||
1483 (data->action == svn_wc_notify_commit_modified)||
1484 (data->action == svn_wc_notify_restore)||
1485 (data->action == svn_wc_notify_revert)||
1486 (data->action == svn_wc_notify_resolved)||
1487 (data->action == svn_wc_notify_commit_replaced)||
1488 (data->action == svn_wc_notify_commit_modified)||
1489 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1490 (data->action == svn_wc_notify_update_update))
1492 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1493 if (data->action == svn_wc_notify_update_update)
1494 popup.AppendMenu(MF_SEPARATOR, NULL);
1495 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1496 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1497 bAdded = true;
1500 } // if ((data)&&(!data->path.IsDirectory()))
1501 if (m_ProgList.GetSelectedCount() == 1)
1503 if (data)
1505 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1506 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1508 CTGitPath path = CTGitPath(sPath);
1509 if (path.GetDirectory().Exists())
1511 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1512 bAdded = true;
1517 if (m_ProgList.GetSelectedCount() > 0)
1519 if (bAdded)
1520 popup.AppendMenu(MF_SEPARATOR, NULL);
1521 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1522 bAdded = true;
1524 if (bAdded)
1526 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1527 DialogEnableWindow(IDOK, FALSE);
1528 this->SetPromptApp(&theApp);
1529 theApp.DoWaitCursor(1);
1530 bool bOpenWith = false;
1531 switch (cmd)
1533 case ID_COPY:
1535 CString sLines;
1536 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1537 while (pos)
1539 int nItem = m_ProgList.GetNextSelectedItem(pos);
1540 NotificationData * data = m_arData[nItem];
1541 if (data)
1543 sLines += data->sPathColumnText;
1544 sLines += _T("\r\n");
1547 sLines.TrimRight();
1548 if (!sLines.IsEmpty())
1550 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1553 break;
1554 case ID_EXPLORE:
1556 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1558 CTGitPath path = CTGitPath(sPath);
1559 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1561 break;
1562 case ID_COMPARE:
1564 svn_revnum_t rev = -1;
1565 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1566 if (data->basepath.IsEmpty())
1567 it = m_UpdateStartRevMap.begin();
1568 else
1569 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1570 if (it != m_UpdateStartRevMap.end())
1571 rev = it->second;
1572 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1573 if (data->content_state == svn_wc_notify_state_merged)
1575 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1576 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1577 SVN svn;
1578 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1580 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1581 DialogEnableWindow(IDOK, TRUE);
1582 break;
1584 // If necessary, convert the line-endings on the file before diffing
1585 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1587 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1588 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1590 temporaryFile.Reset();
1591 break;
1593 else
1595 newfile = temporaryFile;
1599 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1600 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1601 CString revname, wcname, basename;
1602 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1603 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1604 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1605 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1607 else
1609 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1610 SVN svn;
1611 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1613 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1614 DialogEnableWindow(IDOK, TRUE);
1615 break;
1617 else
1619 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1620 CString revname, wcname;
1621 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1622 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1623 CAppUtils::StartExtDiff(
1624 tempfile, data->path, revname, wcname,
1625 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1629 break;
1630 case ID_EDITCONFLICT:
1632 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1633 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1635 break;
1636 case ID_CONFLICTUSETHEIRS:
1637 case ID_CONFLICTUSEMINE:
1638 case ID_CONFLICTRESOLVE:
1640 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1641 switch (cmd)
1643 case ID_CONFLICTUSETHEIRS:
1644 result = svn_wc_conflict_choose_theirs_full;
1645 break;
1646 case ID_CONFLICTUSEMINE:
1647 result = svn_wc_conflict_choose_mine_full;
1648 break;
1649 case ID_CONFLICTRESOLVE:
1650 result = svn_wc_conflict_choose_merged;
1651 break;
1653 SVN svn;
1654 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1655 CString sResolvedPaths;
1656 while (pos)
1658 int nItem = m_ProgList.GetNextSelectedItem(pos);
1659 NotificationData * data = m_arData[nItem];
1660 if (data)
1662 if (data->bConflictedActionItem)
1664 if (!svn.Resolve(data->path, result, FALSE))
1666 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1667 DialogEnableWindow(IDOK, TRUE);
1668 break;
1670 else
1672 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1673 data->action = svn_wc_notify_resolved;
1674 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1675 data->bConflictedActionItem = false;
1676 m_nConflicts--;
1678 if (m_nConflicts==0)
1680 // When the last conflict is resolved we remove
1681 // the warning which we assume is in the last line.
1682 int nIndex = m_ProgList.GetItemCount()-1;
1683 VERIFY(m_ProgList.DeleteItem(nIndex));
1685 delete m_arData[nIndex];
1686 m_arData.pop_back();
1688 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1693 m_ProgList.Invalidate();
1694 CString info = BuildInfoString();
1695 SetDlgItemText(IDC_INFOTEXT, info);
1697 if (!sResolvedPaths.IsEmpty())
1699 CString msg;
1700 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1701 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1704 break;
1705 case ID_LOG:
1707 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
1708 int limit = (int)(DWORD)reg;
1709 svn_revnum_t rev = m_RevisionEnd;
1710 if (!data->basepath.IsEmpty())
1712 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1713 if (it != m_FinishedRevMap.end())
1714 rev = it->second;
1716 CLogDlg dlg;
1717 // fetch the log from HEAD, not the revision we updated to:
1718 // the path might be inside an external folder which has its own
1719 // revisions.
1720 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1721 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);
1722 dlg.DoModal();
1724 break;
1725 case ID_OPENWITH:
1726 bOpenWith = true;
1727 case ID_OPEN:
1729 int ret = 0;
1730 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1731 if (!bOpenWith)
1732 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1733 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1735 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1736 cmd += sWinPath + _T(" ");
1737 CAppUtils::LaunchApplication(cmd, NULL, false);
1741 DialogEnableWindow(IDOK, TRUE);
1742 theApp.DoWaitCursor(-1);
1743 } // if (bAdded)
1747 #endif
1750 void CGitProgressDlg::OnEnSetfocusInfotext()
1752 CString sTemp;
1753 GetDlgItemText(IDC_INFOTEXT, sTemp);
1754 if (sTemp.IsEmpty())
1755 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1758 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1760 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1761 #if 0
1762 int selIndex = m_ProgList.GetSelectionMark();
1763 if (selIndex < 0)
1764 return;
1766 CDropFiles dropFiles; // class for creating DROPFILES struct
1768 int index;
1769 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1770 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1772 NotificationData * data = m_arData[index];
1774 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1776 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1778 dropFiles.AddFile( sPath );
1782 if ( dropFiles.GetCount()>0 )
1784 dropFiles.CreateStructure();
1786 #endif
1787 *pResult = 0;
1790 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1792 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1793 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1795 if(!m_ProgList.m_hWnd)
1796 return;
1798 int count = m_ProgList.GetItemCount();
1799 if (count > 0)
1800 m_ProgList.EnsureVisible(count-1, false);
1804 //////////////////////////////////////////////////////////////////////////
1805 /// commands
1806 //////////////////////////////////////////////////////////////////////////
1807 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1810 localoperation = true;
1811 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1812 SetWindowText(sWindowTitle);
1813 SetBackgroundImage(IDI_ADD_BKG);
1814 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1816 for(int i=0;i<m_targetPathList.GetCount();i++)
1818 CString cmd,out;
1819 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1820 if(g_Git.Run(cmd,&out,CP_ACP))
1822 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1823 m_bErrorsOccurred=true;
1824 return false;
1826 Notify(m_targetPathList[i],git_wc_notify_add);
1828 #if 0
1829 if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))
1831 ReportSVNError();
1832 return false;
1834 #endif
1835 //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1836 m_bErrorsOccurred=false;
1837 return true;
1840 bool CGitProgressDlg::CmdCheckout(CString& sWindowTitle, bool& /*localoperation*/)
1842 #if 0
1843 ASSERT(m_targetPathList.GetCount() == 1);
1844 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CHECKOUT);
1845 SetBackgroundImage(IDI_CHECKOUT_BKG);
1846 CTGitPathList urls;
1847 urls.LoadFromAsteriskSeparatedString(m_url.GetSVNPathString());
1848 CTGitPath checkoutdir = m_targetPathList[0];
1849 for (int i=0; i<urls.GetCount(); ++i)
1851 sWindowTitle = urls[i].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1852 SetWindowText(sWindowTitle);
1853 checkoutdir = m_targetPathList[0];
1854 if (urls.GetCount() > 1)
1856 CString fileordir = urls[i].GetFileOrDirectoryName();
1857 fileordir = CPathUtils::PathUnescape(fileordir);
1858 checkoutdir.AppendPathString(fileordir);
1860 CString sCmdInfo;
1861 sCmdInfo.Format(IDS_PROGRS_CMD_CHECKOUT,
1862 (LPCTSTR)urls[i].GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
1863 (LPCTSTR)SVNStatus::GetDepthString(m_depth),
1864 m_options & ProgOptIgnoreExternals ? (LPCTSTR)sExtExcluded : (LPCTSTR)sExtIncluded);
1865 ReportCmd(sCmdInfo);
1867 if (!Checkout(urls[i], checkoutdir, m_Revision, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1869 if (m_ProgList.GetItemCount()!=0)
1871 ReportSVNError();
1872 return false;
1874 // if the checkout fails with the peg revision set to the checkout revision,
1875 // try again with HEAD as the peg revision.
1876 else
1878 if (!Checkout(urls[i], checkoutdir, SVNRev::REV_HEAD, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1880 ReportSVNError();
1881 return false;
1886 #endif
1887 return true;
1890 bool CGitProgressDlg::CmdCommit(CString& sWindowTitle, bool& /*localoperation*/)
1892 #if 0
1893 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COMMIT);
1894 SetWindowText(sWindowTitle);
1895 SetBackgroundImage(IDI_COMMIT_BKG);
1896 if (m_targetPathList.GetCount()==0)
1898 SetWindowText(sWindowTitle);
1900 DialogEnableWindow(IDCANCEL, FALSE);
1901 DialogEnableWindow(IDOK, TRUE);
1903 InterlockedExchange(&m_bThreadRunning, FALSE);
1904 return true;
1906 if (m_targetPathList.GetCount()==1)
1908 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1909 SetWindowText(sWindowTitle);
1911 BOOL isTag = FALSE;
1912 BOOL bURLFetched = FALSE;
1913 CString url;
1914 for (int i=0; i<m_targetPathList.GetCount(); ++i)
1916 if (bURLFetched == FALSE)
1918 url = GetURLFromPath(m_targetPathList[i]);
1919 if (!url.IsEmpty())
1920 bURLFetched = TRUE;
1921 CString urllower = url;
1922 urllower.MakeLower();
1923 // test if the commit goes to a tag.
1924 // now since Subversion doesn't force users to
1925 // create tags in the recommended /tags/ folder
1926 // only a warning is shown. This won't work if the tags
1927 // are stored in a non-recommended place, but the check
1928 // still helps those who do.
1929 if (urllower.Find(_T("/tags/"))>=0)
1930 isTag = TRUE;
1931 break;
1934 if (isTag)
1936 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_COMMITT_TRUNK, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)==IDNO)
1937 return false;
1939 DWORD exitcode = 0;
1940 CString error;
1941 if (CHooks::Instance().PreCommit(m_selectedPaths, m_depth, m_sMessage, exitcode, error))
1943 if (exitcode)
1945 CString temp;
1946 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1947 ReportError(temp);
1948 return false;
1952 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)));
1953 CStringArray changelists;
1954 if (!m_changelist.IsEmpty())
1955 changelists.Add(m_changelist);
1956 bool commitSuccessful = true;
1957 if (!Commit(m_targetPathList, m_sMessage, changelists, m_keepchangelist,
1958 m_depth, m_options & ProgOptKeeplocks))
1960 ReportSVNError();
1961 error = GetLastErrorMessage();
1962 // if a non-recursive commit failed with SVN_ERR_UNSUPPORTED_FEATURE,
1963 // that means a folder deletion couldn't be committed.
1964 if ((m_Revision != 0)&&(Err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
1966 ReportError(CString(MAKEINTRESOURCE(IDS_PROGRS_NONRECURSIVEHINT)));
1968 commitSuccessful = false;
1969 return false;
1971 if (!PostCommitErr.IsEmpty())
1973 ReportWarning(PostCommitErr);
1975 if (commitSuccessful)
1977 if (m_BugTraqProvider)
1979 CComPtr<IBugTraqProvider2> pProvider = NULL;
1980 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1981 if (SUCCEEDED(hr))
1983 BSTR commonRoot = SysAllocString(m_targetPathList.GetCommonRoot().GetDirectory().GetWinPath());
1984 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_targetPathList.GetCount());
1986 for (LONG index = 0; index < m_targetPathList.GetCount(); ++index)
1987 SafeArrayPutElement(pathList, &index, m_targetPathList[index].GetSVNPathString().AllocSysString());
1989 BSTR logMessage = m_sMessage.AllocSysString();
1991 BSTR temp = NULL;
1992 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1993 commonRoot,
1994 pathList,
1995 logMessage,
1996 (LONG)m_RevisionEnd,
1997 &temp)))
1999 CString sErr = temp;
2000 if (!sErr.IsEmpty())
2001 ReportError(temp);
2004 SysFreeString(temp);
2008 if (CHooks::Instance().PostCommit(m_selectedPaths, m_depth, m_RevisionEnd, m_sMessage, exitcode, error))
2010 if (exitcode)
2012 CString temp;
2013 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2014 ReportError(temp);
2015 return false;
2018 #endif
2019 return true;
2022 bool CGitProgressDlg::CmdCopy(CString& sWindowTitle, bool& /*localoperation*/)
2024 #if 0
2025 ASSERT(m_targetPathList.GetCount() == 1);
2026 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2027 SetWindowText(sWindowTitle);
2028 SetBackgroundImage(IDI_COPY_BKG);
2030 CString sCmdInfo;
2031 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2032 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2033 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2034 ReportCmd(sCmdInfo);
2036 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2038 ReportSVNError();
2039 return false;
2041 if (m_options & ProgOptSwitchAfterCopy)
2043 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2044 m_targetPathList[0].GetWinPath(),
2045 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2046 ReportCmd(sCmdInfo);
2047 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2049 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2051 ReportSVNError();
2052 return false;
2056 else
2058 if (SVN::PathIsURL(m_url))
2060 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2061 ReportNotification(sMsg);
2064 #endif
2065 return true;
2068 bool CGitProgressDlg::CmdExport(CString& sWindowTitle, bool& /*localoperation*/)
2070 #if 0
2071 ASSERT(m_targetPathList.GetCount() == 1);
2072 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2073 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2074 SetWindowText(sWindowTitle);
2075 SetBackgroundImage(IDI_EXPORT_BKG);
2076 CString eol;
2077 if (m_options & ProgOptEolCRLF)
2078 eol = _T("CRLF");
2079 if (m_options & ProgOptEolLF)
2080 eol = _T("LF");
2081 if (m_options & ProgOptEolCR)
2082 eol = _T("CR");
2083 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2084 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2086 ReportSVNError();
2087 return false;
2089 #endif
2090 return true;
2093 bool CGitProgressDlg::CmdImport(CString& sWindowTitle, bool& /*localoperation*/)
2095 #if 0
2096 ASSERT(m_targetPathList.GetCount() == 1);
2097 sWindowTitle.LoadString(IDS_PROGRS_TITLE_IMPORT);
2098 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2099 SetWindowText(sWindowTitle);
2100 SetBackgroundImage(IDI_IMPORT_BKG);
2101 CString sCmdInfo;
2102 sCmdInfo.Format(IDS_PROGRS_CMD_IMPORT,
2103 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2104 m_options & ProgOptIncludeIgnored ? (LPCTSTR)(_T(", ") + sIgnoredIncluded) : _T(""));
2105 ReportCmd(sCmdInfo);
2106 if (!Import(m_targetPathList[0], m_url, m_sMessage, &m_ProjectProperties, svn_depth_infinity, m_options & ProgOptIncludeIgnored ? true : false, false))
2108 ReportSVNError();
2109 return false;
2111 #endif
2112 return true;
2115 bool CGitProgressDlg::CmdLock(CString& sWindowTitle, bool& /*localoperation*/)
2117 #if 0
2118 sWindowTitle.LoadString(IDS_PROGRS_TITLE_LOCK);
2119 SetWindowText(sWindowTitle);
2120 SetBackgroundImage(IDI_LOCK_BKG);
2121 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_LOCK)));
2122 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2124 ReportSVNError();
2125 return false;
2127 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2128 if (m_bLockWarning)
2130 // the lock failed, because the file was outdated.
2131 // ask the user whether to update the file and try again
2132 if (CMessageBox::Show(m_hWnd, IDS_WARN_LOCKOUTDATED, IDS_APPNAME, MB_ICONQUESTION|MB_YESNO)==IDYES)
2134 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_UPDATEANDRETRY)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2135 if (!Update(m_targetPathList, SVNRev::REV_HEAD, svn_depth_files, false, true))
2137 ReportSVNError();
2138 return false;
2140 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2142 ReportSVNError();
2143 return false;
2147 if (m_bLockExists)
2149 // the locking failed because there already is a lock.
2150 // if the locking-dialog is skipped in the settings, tell the
2151 // user how to steal the lock anyway (i.e., how to get the lock
2152 // dialog back without changing the settings)
2153 if (!DWORD(CRegDWORD(_T("Software\\TortoiseGit\\ShowLockDlg"), TRUE)))
2155 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_LOCKHINT)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2157 return false;
2159 #endif
2160 return true;
2163 bool CGitProgressDlg::CmdMerge(CString& sWindowTitle, bool& /*localoperation*/)
2165 #if 0
2166 bool bFailed = false;
2167 ASSERT(m_targetPathList.GetCount() == 1);
2168 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2169 SetBackgroundImage(IDI_MERGE_BKG);
2170 if (m_options & ProgOptDryRun)
2172 sWindowTitle += _T(" ") + sDryRun;
2174 if (m_options & ProgOptRecordOnly)
2176 sWindowTitle += _T(" ") + sRecordOnly;
2178 SetWindowText(sWindowTitle);
2180 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_HIDE);
2181 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2182 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2183 if (DWORD(nonint))
2185 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2186 m_AlwaysConflicted = true;
2188 // we only accept a revision list to merge for peg merges
2189 ATLASSERT((m_revisionArray.GetCount()==0) || (m_revisionArray.GetCount() && (m_url.IsEquivalentTo(m_url2))));
2191 if (m_url.IsEquivalentTo(m_url2))
2193 CString sSuggestedMessage;
2194 CString sMergedLogMessage;
2195 CString sSeparator = CRegString(_T("Software\\TortoiseGit\\MergeLogSeparator"), _T("........"));
2196 CString temp;
2198 // Merging revisions %s of %s to %s into %s, %s%s
2199 CString sCmdInfo;
2200 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEPEG,
2201 (LPCTSTR)m_revisionArray.ToListString(),
2202 (LPCTSTR)m_url.GetSVNPathString(),
2203 m_targetPathList[0].GetWinPath(),
2204 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2205 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2206 ReportCmd(sCmdInfo);
2208 if (!PegMerge(m_url, m_revisionArray,
2209 m_pegRev.IsValid() ? m_pegRev : (m_url.IsUrl() ? SVNRev::REV_HEAD : SVNRev(SVNRev::REV_WC)),
2210 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2212 // if the merge fails with the peg revision set,
2213 // try again with HEAD as the peg revision.
2214 if (!PegMerge(m_url, m_revisionArray, SVNRev::REV_HEAD,
2215 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2217 ReportSVNError();
2218 bFailed = true;
2222 else
2224 CString sCmdInfo;
2225 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEURL,
2226 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
2227 (LPCTSTR)m_url2.GetSVNPathString(), (LPCTSTR)m_RevisionEnd.ToString(),
2228 m_targetPathList[0].GetWinPath(),
2229 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2230 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2231 ReportCmd(sCmdInfo);
2233 if (!Merge(m_url, m_Revision, m_url2, m_RevisionEnd, m_targetPathList[0],
2234 true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2236 ReportSVNError();
2237 bFailed = true;
2240 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2241 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_SHOW);
2242 return !bFailed;
2243 #endif
2244 return true;
2247 bool CGitProgressDlg::CmdMergeAll(CString& sWindowTitle, bool& /*localoperation*/)
2249 #if 0
2250 ASSERT(m_targetPathList.GetCount() == 1);
2251 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2252 SetBackgroundImage(IDI_MERGE_BKG);
2253 SetWindowText(sWindowTitle);
2255 ATLASSERT(m_targetPathList.GetCount() == 1);
2257 CString sCmdInfo;
2258 sCmdInfo.LoadString(IDS_PROGRS_INFOGETTINGINFO);
2259 ReportCmd(sCmdInfo);
2260 CTGitPathList suggestedSources;
2261 if (!SuggestMergeSources(m_targetPathList[0], m_Revision, suggestedSources))
2263 ReportSVNError();
2264 return false;
2267 if (suggestedSources.GetCount() == 0)
2269 CString sErr;
2270 sErr.Format(IDS_PROGRS_MERGEALLNOSOURCES, m_targetPathList[0].GetWinPath());
2271 ReportError(sErr);
2272 return false;
2274 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEALL,
2275 (LPCTSTR)suggestedSources[0].GetSVNPathString(),
2276 m_targetPathList[0].GetWinPath(),
2277 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry);
2278 ReportCmd(sCmdInfo);
2280 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2281 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2282 if (DWORD(nonint))
2284 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2285 m_AlwaysConflicted = true;
2288 SVNRevRangeArray revarray;
2289 if (!PegMerge(suggestedSources[0], revarray,
2290 SVNRev::REV_HEAD,
2291 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), FALSE))
2293 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2294 ReportSVNError();
2295 return false;
2298 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2299 #endif
2300 return true;
2303 bool CGitProgressDlg::CmdMergeReintegrate(CString& sWindowTitle, bool& /*localoperation*/)
2305 #if 0
2306 ASSERT(m_targetPathList.GetCount() == 1);
2307 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGEREINTEGRATE);
2308 SetBackgroundImage(IDI_MERGE_BKG);
2309 SetWindowText(sWindowTitle);
2311 CString sCmdInfo;
2312 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEREINTEGRATE,
2313 (LPCTSTR)m_url.GetSVNPathString(),
2314 m_targetPathList[0].GetWinPath());
2315 ReportCmd(sCmdInfo);
2317 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2318 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2319 if (DWORD(nonint))
2321 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2322 m_AlwaysConflicted = true;
2325 if (!MergeReintegrate(m_url, SVNRev::REV_HEAD, m_targetPathList[0], !!(m_options & ProgOptDryRun), m_diffoptions))
2327 ReportSVNError();
2328 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2329 return false;
2332 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2333 #endif
2334 return true;
2337 bool CGitProgressDlg::CmdRename(CString& sWindowTitle, bool& localoperation)
2339 #if 0
2340 ASSERT(m_targetPathList.GetCount() == 1);
2341 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2342 localoperation = true;
2343 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2344 SetWindowText(sWindowTitle);
2345 SetBackgroundImage(IDI_RENAME_BKG);
2346 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2347 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2349 ReportSVNError();
2350 return false;
2352 #endif
2353 return true;
2356 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2359 localoperation = true;
2360 ASSERT(m_targetPathList.GetCount() == 1);
2361 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2362 SetWindowText(sWindowTitle);
2363 SetBackgroundImage(IDI_RESOLVE_BKG);
2364 // check if the file may still have conflict markers in it.
2365 BOOL bMarkers = FALSE;
2367 for(int i=0;i<m_targetPathList.GetCount();i++)
2369 CString cmd,out,tempmergefile;
2370 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2371 if(g_Git.Run(cmd,&out,CP_ACP))
2373 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2374 m_bErrorsOccurred=true;
2375 return false;
2381 tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),(CTGitPath &)m_targetPathList[i]);
2382 CFile::Remove(tempmergefile);
2383 }catch(...)
2389 tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),(CTGitPath &)m_targetPathList[i]);
2390 CFile::Remove(tempmergefile);
2391 }catch(...)
2397 tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),(CTGitPath &)m_targetPathList[i]);
2398 CFile::Remove(tempmergefile);
2399 }catch(...)
2404 Notify(m_targetPathList[i],git_wc_notify_resolved);
2406 #if 0
2407 if ((m_options & ProgOptSkipConflictCheck) == 0)
2411 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2413 if (!m_targetPathList[fileindex].IsDirectory())
2415 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2416 CString strLine = _T("");
2417 while (file.ReadString(strLine))
2419 if (strLine.Find(_T("<<<<<<<"))==0)
2421 bMarkers = TRUE;
2422 break;
2425 file.Close();
2429 catch (CFileException* pE)
2431 TRACE(_T("CFileException in Resolve!\n"));
2432 TCHAR error[10000] = {0};
2433 pE->GetErrorMessage(error, 10000);
2434 ReportError(error);
2435 pE->Delete();
2436 return false;
2439 if (bMarkers)
2441 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2443 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2444 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2445 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2448 else
2450 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2451 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2452 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2454 #endif
2455 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2457 return true;
2460 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2463 localoperation = true;
2464 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2465 SetWindowText(sWindowTitle);
2466 SetBackgroundImage(IDI_REVERT_BKG);
2468 //CTGitPathList delList = m_selectedPaths;
2469 //if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2470 // delList.DeleteAllFiles(true);
2472 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2473 for(int i=0;i<m_selectedPaths.GetCount();i++)
2475 if(g_Git.Revert((CTGitPath&)m_selectedPaths[i],true))
2477 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2478 m_bErrorsOccurred=true;
2479 return false;
2481 Notify(m_selectedPaths[i],git_wc_notify_revert);
2484 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2486 return true;
2489 bool CGitProgressDlg::CmdSwitch(CString& sWindowTitle, bool& /*localoperation*/)
2491 #if 0
2492 ASSERT(m_targetPathList.GetCount() == 1);
2493 SVNStatus st;
2494 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2495 SetWindowText(sWindowTitle);
2496 SetBackgroundImage(IDI_SWITCH_BKG);
2497 LONG rev = 0;
2498 if (st.GetStatus(m_targetPathList[0]) != (-2))
2500 if (st.status->entry != NULL)
2502 rev = st.status->entry->revision;
2506 CString sCmdInfo;
2507 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2508 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2509 (LPCTSTR)m_Revision.ToString());
2510 ReportCmd(sCmdInfo);
2512 bool depthIsSticky = true;
2513 if (m_depth == svn_depth_unknown)
2514 depthIsSticky = false;
2515 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2517 ReportSVNError();
2518 return false;
2520 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2521 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2522 &&((LONG)m_RevisionEnd > (LONG)rev))
2524 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2526 #endif
2527 return true;
2530 bool CGitProgressDlg::CmdUnlock(CString& sWindowTitle, bool& /*localoperation*/)
2532 #if 0
2533 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UNLOCK);
2534 SetWindowText(sWindowTitle);
2535 SetBackgroundImage(IDI_UNLOCK_BKG);
2536 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UNLOCK)));
2537 if (!Unlock(m_targetPathList, m_options & ProgOptLockForce))
2539 ReportSVNError();
2540 return false;
2542 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2543 #endif
2544 return true;
2547 bool CGitProgressDlg::CmdUpdate(CString& sWindowTitle, bool& /*localoperation*/)
2549 #if 0
2550 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UPDATE);
2551 SetWindowText(sWindowTitle);
2552 SetBackgroundImage(IDI_UPDATE_BKG);
2554 int targetcount = m_targetPathList.GetCount();
2555 CString sfile;
2556 CStringA uuid;
2557 StringRevMap uuidmap;
2558 SVNRev revstore = m_Revision;
2559 int nUUIDs = 0;
2560 for(int nItem = 0; nItem < targetcount; nItem++)
2562 const CTGitPath& targetPath = m_targetPathList[nItem];
2563 SVNStatus st;
2564 LONG headrev = -1;
2565 m_Revision = revstore;
2566 if (m_Revision.IsHead())
2568 if ((targetcount > 1)&&((headrev = st.GetStatus(targetPath, true)) != (-2)))
2570 if (st.status->entry != NULL)
2573 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2574 if (st.status->entry->uuid)
2576 uuid = st.status->entry->uuid;
2577 StringRevMap::iterator iter = uuidmap.lower_bound(uuid);
2578 if (iter == uuidmap.end() || iter->first != uuid)
2580 uuidmap.insert(iter, std::make_pair(uuid, headrev));
2581 nUUIDs++;
2583 else
2584 headrev = iter->second;
2585 m_Revision = headrev;
2587 else
2588 m_Revision = headrev;
2591 else
2593 if ((headrev = st.GetStatus(targetPath, FALSE)) != (-2))
2595 if (st.status->entry != NULL)
2596 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2599 if (uuidmap.size() > 1)
2600 m_Revision = SVNRev::REV_HEAD;
2601 } // if (m_Revision.IsHead())
2602 } // for(int nItem = 0; nItem < targetcount; nItem++)
2603 sWindowTitle = m_targetPathList.GetCommonRoot().GetWinPathString()+_T(" - ")+sWindowTitle;
2604 SetWindowText(sWindowTitle);
2606 DWORD exitcode = 0;
2607 CString error;
2608 if (CHooks::Instance().PreUpdate(m_targetPathList, m_depth, nUUIDs > 1 ? revstore : m_Revision, exitcode, error))
2610 if (exitcode)
2612 CString temp;
2613 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2614 ReportError(temp);
2615 return false;
2618 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UPDATE)));
2619 if (nUUIDs > 1)
2621 // the selected items are from different repositories,
2622 // so we have to update them separately
2623 for(int nItem = 0; nItem < targetcount; nItem++)
2625 const CTGitPath& targetPath = m_targetPathList[nItem];
2626 m_basePath = targetPath;
2627 CString sNotify;
2628 sNotify.Format(IDS_PROGRS_UPDATEPATH, m_basePath.GetWinPath());
2629 ReportString(sNotify, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2630 if (!Update(CTGitPathList(targetPath), revstore, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2632 ReportSVNError();
2633 return false;
2637 else
2639 // if we have only one target path, but that target path does not exist,
2640 // we have to check whether at least the parent path exists. If not,
2641 // then we have to update all paths in between the first path that exists and the
2642 // parent path of the one we want to update
2643 // This is required so a user can create a sparse checkout without having
2644 // to update all intermediate folders manually
2645 if ((m_targetPathList.GetCount() == 1) && (!m_targetPathList[0].Exists()))
2647 CTGitPath wcPath = m_targetPathList[0].GetContainingDirectory();
2648 CTGitPath existingParentPath = wcPath.GetContainingDirectory();
2649 while (!existingParentPath.Exists() && (existingParentPath.GetWinPathString().GetLength() > 2))
2651 existingParentPath = existingParentPath.GetContainingDirectory();
2653 if (existingParentPath.GetWinPathString().GetLength() && !existingParentPath.IsEquivalentTo(wcPath))
2655 // update all intermediate directories with depth 'empty'
2656 CTGitPath intermediatepath = existingParentPath;
2657 bool bSuccess = true;
2658 while (bSuccess && intermediatepath.IsAncestorOf(wcPath) && !intermediatepath.IsEquivalentTo(wcPath))
2660 CString childname = wcPath.GetWinPathString().Mid(intermediatepath.GetWinPathString().GetLength(),
2661 wcPath.GetWinPathString().Find('\\', intermediatepath.GetWinPathString().GetLength()+1)-intermediatepath.GetWinPathString().GetLength());
2662 if (childname.IsEmpty())
2663 intermediatepath = wcPath;
2664 else
2665 intermediatepath.AppendPathString(childname);
2666 bSuccess = !!Update(CTGitPathList(intermediatepath), m_Revision, svn_depth_empty, false, true);
2669 if (!bSuccess)
2671 ReportSVNError();
2672 return false;
2676 if (!Update(m_targetPathList, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2678 ReportSVNError();
2679 return false;
2682 if (CHooks::Instance().PostUpdate(m_targetPathList, m_depth, m_RevisionEnd, exitcode, error))
2684 if (exitcode)
2686 CString temp;
2687 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2688 ReportError(temp);
2689 return false;
2693 // after an update, show the user the log button, but only if only one single item was updated
2694 // (either a file or a directory)
2695 if ((m_targetPathList.GetCount() == 1)&&(m_UpdateStartRevMap.size()>0))
2696 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2697 #endif
2698 return true;
2701 void CGitProgressDlg::OnBnClickedNoninteractive()
2703 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2704 m_AlwaysConflicted = (res == BST_CHECKED);
2705 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2706 nonint = m_AlwaysConflicted;
2709 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2711 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2712 if (sPath.Find(':')<0)
2714 // the path is not absolute: add the common root of all paths to it
2715 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2717 return sPath;
2720 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2722 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2723 SetWindowText(sWindowTitle);
2724 //SetBackgroundImage(IDI_ADD_BKG);
2725 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2726 bool ret=true;
2727 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2729 CString error;
2730 CTGitPath path;
2731 Notify(path,git_wc_notify_sendmail_start);
2732 CString err;
2733 int retry=0;
2734 while(retry <3)
2736 if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,&err))
2738 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2739 ret = false;
2741 else
2743 break;
2746 retry++;
2747 Sleep(2000);
2748 if(m_bCancelled)
2750 Notify(path,git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));
2751 return false;
2754 Notify(path,git_wc_notify_sendmail_done,ret);
2756 }else
2758 for(int i=0;i<m_targetPathList.GetCount();i++)
2760 CPatch patch;
2761 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2763 int retry=0;
2764 while(retry<3)
2766 int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2767 this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT);
2768 if(ret)
2770 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2771 ret = false;
2773 }else
2775 break;
2777 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2779 retry++;
2780 Sleep(2000);
2781 if(m_bCancelled)
2783 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));
2784 return false;
2787 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2791 return ret;