Fixed Issue 55: "resolved" function doesn't delete temporary files.
[TortoiseGit.git] / src / TortoiseProc / SVNProgressDlg.cpp
blob00c7a38995456a4aea270a9cee30509d475da81e
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"
44 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
46 BOOL CGitProgressDlg::m_bAscending = FALSE;
47 int CGitProgressDlg::m_nSortedColumn = -1;
49 #define TRANSFERTIMER 100
50 #define VISIBLETIMER 101
52 enum SVNProgressDlgContextMenuCommands
54 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
55 ID_COMPARE = 1,
56 ID_EDITCONFLICT,
57 ID_CONFLICTRESOLVE,
58 ID_CONFLICTUSETHEIRS,
59 ID_CONFLICTUSEMINE,
60 ID_LOG,
61 ID_OPEN,
62 ID_OPENWITH,
63 ID_EXPLORE,
64 ID_COPY
67 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
68 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
69 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
70 #if 0
71 , m_Revision(_T("HEAD"))
72 //, m_RevisionEnd(0)
73 , m_bLockWarning(false)
74 , m_bLockExists(false)
75 , m_bCancelled(FALSE)
76 , m_bThreadRunning(FALSE)
77 , m_nConflicts(0)
78 , m_bErrorsOccurred(FALSE)
79 , m_bMergesAddsDeletesOccurred(FALSE)
80 , m_pThread(NULL)
81 , m_options(ProgOptNone)
82 , m_dwCloseOnEnd((DWORD)-1)
83 , m_bFinishedItemAdded(false)
84 , m_bLastVisible(false)
85 // , m_depth(svn_depth_unknown)
86 , m_itemCount(-1)
87 , m_itemCountTotal(-1)
88 , m_AlwaysConflicted(false)
89 , m_BugTraqProvider(NULL)
90 , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))
91 , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))
92 , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))
93 , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))
94 , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))
95 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
96 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
97 #endif
101 CGitProgressDlg::~CGitProgressDlg()
103 for (size_t i=0; i<m_arData.size(); i++)
105 delete m_arData[i];
107 if(m_pThread != NULL)
109 delete m_pThread;
113 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
115 CResizableStandAloneDialog::DoDataExchange(pDX);
116 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
119 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
120 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
121 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
122 ON_WM_CLOSE()
123 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
124 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
125 ON_WM_SETCURSOR()
126 ON_WM_CONTEXTMENU()
127 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
128 ON_WM_TIMER()
129 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
130 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
131 ON_WM_SIZE()
132 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
133 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
134 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
135 END_MESSAGE_MAP()
137 BOOL CGitProgressDlg::Cancel()
139 return m_bCancelled;
142 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM lParam)
144 #if 0
145 CConflictResolveDlg dlg(this);
146 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
147 if (description)
149 dlg.SetConflictDescription(description);
150 if (dlg.DoModal() == IDOK)
152 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
154 // if the result is conflicted and the dialog returned IDOK,
155 // that means we should not ask again in case of a conflict
156 m_AlwaysConflicted = true;
157 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
160 m_mergedfile = dlg.GetMergedFile();
161 m_bCancelled = dlg.IsCancelled();
162 return dlg.GetResult();
165 return svn_wc_conflict_choose_postpone;
166 #endif
167 return 0;
169 #if 0
170 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
172 // we only bother the user when merging
173 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
175 // we're in a worker thread here. That means we must not show a dialog from the thread
176 // but let the UI thread do it.
177 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
178 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
179 mergedfile = m_mergedfile;
180 return (svn_wc_conflict_choice_t)dlgResult;
183 return svn_wc_conflict_choose_postpone;
185 #endif
186 void CGitProgressDlg::AddItemToList()
188 int totalcount = m_ProgList.GetItemCount();
190 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
191 // make columns width fit
192 if (iFirstResized < 30)
194 // only resize the columns for the first 30 or so entries.
195 // after that, don't resize them anymore because that's an
196 // expensive function call and the columns will be sized
197 // close enough already.
198 ResizeColumns();
199 iFirstResized++;
202 // Make sure the item is *entirely* visible even if the horizontal
203 // scroll bar is visible.
204 int count = m_ProgList.GetCountPerPage();
205 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
207 nEnsureVisibleCount++;
208 m_bLastVisible = true;
210 else
212 nEnsureVisibleCount = 0;
213 if (IsIconic() == 0)
214 m_bLastVisible = false;
219 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action
221 svn_node_kind_t kind, const CString& mime_type,
222 svn_wc_notify_state_t content_state,
223 svn_wc_notify_state_t prop_state, LONG rev,
224 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
225 const CString& changelistname,
226 svn_merge_range_t * range,
227 svn_error_t * err, apr_pool_t * pool
230 bool bNoNotify = false;
231 bool bDoAddData = true;
232 NotificationData * data = new NotificationData();
233 data->path = path;
234 data->action = action;
235 data->sPathColumnText=path.GetGitPathString();
236 #if 0
237 data->kind = kind;
238 data->mime_type = mime_type;
239 data->content_state = content_state;
240 data->prop_state = prop_state;
241 data->rev = rev;
242 data->lock_state = lock_state;
243 data->changelistname = changelistname;
244 if ((lock)&&(lock->owner))
245 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
246 data->sPathColumnText = path.GetUIPathString();
247 if (!m_basePath.IsEmpty())
248 data->basepath = m_basePath;
249 if (range)
250 data->merge_range = *range;
251 #endif
252 switch (data->action)
254 case git_wc_notify_add:
255 //case svn_wc_notify_update_add:
256 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
257 // {
258 // data->color = m_Colors.GetColor(CColors::Conflict);
259 // data->bConflictedActionItem = true;
260 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
261 // m_nConflicts++;
262 // }
263 // else
264 // {
265 // m_bMergesAddsDeletesOccurred = true;
266 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
267 data->color = m_Colors.GetColor(CColors::Added);
268 // }
269 break;
271 case git_wc_notify_resolved:
272 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
273 break;
275 #if 0
276 case svn_wc_notify_commit_added:
277 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
278 data->color = m_Colors.GetColor(CColors::Added);
279 break;
280 case svn_wc_notify_copy:
281 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
282 break;
283 case svn_wc_notify_commit_modified:
284 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
285 data->color = m_Colors.GetColor(CColors::Modified);
286 break;
287 case svn_wc_notify_delete:
288 case svn_wc_notify_update_delete:
289 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
290 m_bMergesAddsDeletesOccurred = true;
291 data->color = m_Colors.GetColor(CColors::Deleted);
292 break;
293 case svn_wc_notify_commit_deleted:
294 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
295 data->color = m_Colors.GetColor(CColors::Deleted);
296 break;
297 case svn_wc_notify_restore:
298 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
299 break;
300 case svn_wc_notify_revert:
301 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
302 break;
303 case svn_wc_notify_update_replace:
304 case svn_wc_notify_commit_replaced:
305 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
306 data->color = m_Colors.GetColor(CColors::Deleted);
307 break;
308 case svn_wc_notify_exists:
309 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
311 data->color = m_Colors.GetColor(CColors::Conflict);
312 data->bConflictedActionItem = true;
313 m_nConflicts++;
314 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
316 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
318 data->color = m_Colors.GetColor(CColors::Merged);
319 m_bMergesAddsDeletesOccurred = true;
320 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
322 else
323 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
324 break;
325 case svn_wc_notify_update_update:
326 // if this is an inoperative dir change, don't show the notification.
327 // an inoperative dir change is when a directory gets updated without
328 // any real change in either text or properties.
329 if ((kind == svn_node_dir)
330 && ((prop_state == svn_wc_notify_state_inapplicable)
331 || (prop_state == svn_wc_notify_state_unknown)
332 || (prop_state == svn_wc_notify_state_unchanged)))
334 bNoNotify = true;
335 break;
337 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
339 data->color = m_Colors.GetColor(CColors::Conflict);
340 data->bConflictedActionItem = true;
341 m_nConflicts++;
342 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
344 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
346 data->color = m_Colors.GetColor(CColors::Merged);
347 m_bMergesAddsDeletesOccurred = true;
348 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
350 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
351 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
353 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
355 else
357 bNoNotify = true;
358 break;
360 if (lock_state == svn_wc_notify_lock_state_unlocked)
362 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
363 data->sActionColumnText += _T(", ") + temp;
365 break;
367 case svn_wc_notify_update_external:
368 // For some reason we build a list of externals...
369 m_ExtStack.AddHead(path.GetUIPathString());
370 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
371 data->bAuxItem = true;
372 break;
374 case svn_wc_notify_update_completed:
376 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
377 data->bAuxItem = true;
378 bool bEmpty = !!m_ExtStack.IsEmpty();
379 if (!bEmpty)
380 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
381 else
382 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
384 if ((m_nConflicts>0)&&(bEmpty))
386 // We're going to add another aux item - let's shove this current onto the list first
387 // I don't really like this, but it will do for the moment.
388 m_arData.push_back(data);
389 AddItemToList();
391 data = new NotificationData();
392 data->bAuxItem = true;
393 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
394 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
395 data->color = m_Colors.GetColor(CColors::Conflict);
396 CSoundUtils::PlayTSVNWarning();
397 // This item will now be added after the switch statement
399 if (!m_basePath.IsEmpty())
400 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
401 m_RevisionEnd = rev;
402 m_bFinishedItemAdded = true;
404 break;
405 case svn_wc_notify_commit_postfix_txdelta:
406 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
407 break;
408 case svn_wc_notify_failed_revert:
409 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
410 break;
411 case svn_wc_notify_status_completed:
412 case svn_wc_notify_status_external:
413 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
414 break;
415 case svn_wc_notify_skip:
416 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
418 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
420 // The color settings dialog describes the red color with
421 // "possible or real conflict / obstructed" which also applies to
422 // skipped targets during a merge. So we just use the same color.
423 data->color = m_Colors.GetColor(CColors::Conflict);
425 else
426 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
427 break;
428 case svn_wc_notify_locked:
429 if ((lock)&&(lock->owner))
430 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
431 break;
432 case svn_wc_notify_unlocked:
433 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
434 break;
435 case svn_wc_notify_failed_lock:
436 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
437 m_arData.push_back(data);
438 AddItemToList();
439 ReportError(SVN::GetErrorString(err));
440 bDoAddData = false;
441 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
442 m_bLockWarning = true;
443 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
444 m_bLockExists = true;
445 break;
446 case svn_wc_notify_failed_unlock:
447 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
448 m_arData.push_back(data);
449 AddItemToList();
450 ReportError(SVN::GetErrorString(err));
451 bDoAddData = false;
452 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
453 m_bLockWarning = true;
454 break;
455 case svn_wc_notify_changelist_set:
456 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
457 break;
458 case svn_wc_notify_changelist_clear:
459 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
460 break;
461 case svn_wc_notify_changelist_moved:
462 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
463 break;
464 case svn_wc_notify_foreign_merge_begin:
465 case svn_wc_notify_merge_begin:
466 if (range == NULL)
467 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
468 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
469 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
470 else if (data->merge_range.start - 1 == data->merge_range.end)
471 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
472 else if (data->merge_range.start < data->merge_range.end)
473 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
474 else
475 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
476 data->bAuxItem = true;
477 break;
478 #endif
479 default:
480 break;
481 } // switch (data->action)
483 if (bNoNotify)
484 delete data;
485 else
487 if (bDoAddData)
489 m_arData.push_back(data);
490 AddItemToList();
491 if (/*(!data->bAuxItem)&&*/(m_itemCount > 0))
493 m_itemCount--;
495 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
496 progControl->ShowWindow(SW_SHOW);
497 progControl->SetPos(m_itemCountTotal - m_itemCount);
498 progControl->SetRange32(0, m_itemCountTotal);
501 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
503 // ResizeColumns();
504 // bSecondResized = TRUE;
508 return TRUE;
512 CString CGitProgressDlg::BuildInfoString()
514 CString infotext;
515 #if 0
517 CString temp;
518 int added = 0;
519 int copied = 0;
520 int deleted = 0;
521 int restored = 0;
522 int reverted = 0;
523 int resolved = 0;
524 int conflicted = 0;
525 int updated = 0;
526 int merged = 0;
527 int modified = 0;
528 int skipped = 0;
529 int replaced = 0;
531 for (size_t i=0; i<m_arData.size(); ++i)
533 const NotificationData * dat = m_arData[i];
534 switch (dat->action)
536 case svn_wc_notify_add:
537 case svn_wc_notify_update_add:
538 case svn_wc_notify_commit_added:
539 if (dat->bConflictedActionItem)
540 conflicted++;
541 else
542 added++;
543 break;
544 case svn_wc_notify_copy:
545 copied++;
546 break;
547 case svn_wc_notify_delete:
548 case svn_wc_notify_update_delete:
549 case svn_wc_notify_commit_deleted:
550 deleted++;
551 break;
552 case svn_wc_notify_restore:
553 restored++;
554 break;
555 case svn_wc_notify_revert:
556 reverted++;
557 break;
558 case svn_wc_notify_resolved:
559 resolved++;
560 break;
561 case svn_wc_notify_update_update:
562 if (dat->bConflictedActionItem)
563 conflicted++;
564 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
565 merged++;
566 else
567 updated++;
568 break;
569 case svn_wc_notify_commit_modified:
570 modified++;
571 break;
572 case svn_wc_notify_skip:
573 skipped++;
574 break;
575 case svn_wc_notify_commit_replaced:
576 replaced++;
577 break;
580 if (conflicted)
582 temp.LoadString(IDS_SVNACTION_CONFLICTED);
583 infotext += temp;
584 temp.Format(_T(":%d "), conflicted);
585 infotext += temp;
587 if (skipped)
589 temp.LoadString(IDS_SVNACTION_SKIP);
590 infotext += temp;
591 infotext.AppendFormat(_T(":%d "), skipped);
593 if (merged)
595 temp.LoadString(IDS_SVNACTION_MERGED);
596 infotext += temp;
597 infotext.AppendFormat(_T(":%d "), merged);
599 if (added)
601 temp.LoadString(IDS_SVNACTION_ADD);
602 infotext += temp;
603 infotext.AppendFormat(_T(":%d "), added);
605 if (deleted)
607 temp.LoadString(IDS_SVNACTION_DELETE);
608 infotext += temp;
609 infotext.AppendFormat(_T(":%d "), deleted);
611 if (modified)
613 temp.LoadString(IDS_SVNACTION_MODIFIED);
614 infotext += temp;
615 infotext.AppendFormat(_T(":%d "), modified);
617 if (copied)
619 temp.LoadString(IDS_SVNACTION_COPY);
620 infotext += temp;
621 infotext.AppendFormat(_T(":%d "), copied);
623 if (replaced)
625 temp.LoadString(IDS_SVNACTION_REPLACED);
626 infotext += temp;
627 infotext.AppendFormat(_T(":%d "), replaced);
629 if (updated)
631 temp.LoadString(IDS_SVNACTION_UPDATE);
632 infotext += temp;
633 infotext.AppendFormat(_T(":%d "), updated);
635 if (restored)
637 temp.LoadString(IDS_SVNACTION_RESTORE);
638 infotext += temp;
639 infotext.AppendFormat(_T(":%d "), restored);
641 if (reverted)
643 temp.LoadString(IDS_SVNACTION_REVERT);
644 infotext += temp;
645 infotext.AppendFormat(_T(":%d "), reverted);
647 if (resolved)
649 temp.LoadString(IDS_SVNACTION_RESOLVE);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), resolved);
653 #endif
654 return infotext;
657 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
659 m_selectedPaths = selPaths;
662 void CGitProgressDlg::ResizeColumns()
664 m_ProgList.SetRedraw(FALSE);
666 TCHAR textbuf[MAX_PATH];
668 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
669 for (int col = 0; col <= maxcol; col++)
671 // find the longest width of all items
672 int count = m_ProgList.GetItemCount();
673 HDITEM hdi = {0};
674 hdi.mask = HDI_TEXT;
675 hdi.pszText = textbuf;
676 hdi.cchTextMax = sizeof(textbuf);
677 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
678 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
680 for (int index = 0; index<count; ++index)
682 // get the width of the string and add 12 pixels for the column separator and margins
683 int linewidth = cx;
684 switch (col)
686 case 0:
687 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
688 break;
689 case 1:
690 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
691 break;
692 case 2:
693 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
694 break;
696 if (cx < linewidth)
697 cx = linewidth;
699 m_ProgList.SetColumnWidth(col, cx);
702 m_ProgList.SetRedraw(TRUE);
705 BOOL CGitProgressDlg::OnInitDialog()
707 __super::OnInitDialog();
709 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
711 m_ProgList.DeleteAllItems();
712 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
713 while (c>=0)
714 m_ProgList.DeleteColumn(c--);
715 CString temp;
716 temp.LoadString(IDS_PROGRS_ACTION);
717 m_ProgList.InsertColumn(0, temp);
718 temp.LoadString(IDS_PROGRS_PATH);
719 m_ProgList.InsertColumn(1, temp);
720 temp.LoadString(IDS_PROGRS_MIMETYPE);
721 m_ProgList.InsertColumn(2, temp);
723 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
724 if (m_pThread==NULL)
726 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
728 else
730 m_pThread->m_bAutoDelete = FALSE;
731 m_pThread->ResumeThread();
734 UpdateData(FALSE);
736 // Call this early so that the column headings aren't hidden before any
737 // text gets added.
738 ResizeColumns();
740 SetTimer(VISIBLETIMER, 300, NULL);
742 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
743 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
744 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
745 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
746 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
747 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
748 AddAnchor(IDOK, BOTTOM_RIGHT);
749 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
750 //SetPromptParentWindow(this->m_hWnd);
751 if (hWndExplorer)
752 CenterWindow(CWnd::FromHandle(hWndExplorer));
753 EnableSaveRestore(_T("SVNProgressDlg"));
754 return TRUE;
757 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
759 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
762 #if 0
763 void CGitProgressDlg::ReportSVNError()
765 ReportError(GetLastErrorMessage());
767 #endif
769 void CGitProgressDlg::ReportError(const CString& sError)
771 CSoundUtils::PlayTGitError();
772 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
773 m_bErrorsOccurred = true;
776 void CGitProgressDlg::ReportWarning(const CString& sWarning)
778 CSoundUtils::PlayTGitWarning();
779 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
782 void CGitProgressDlg::ReportNotification(const CString& sNotification)
784 CSoundUtils::PlayTGitNotification();
785 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
788 void CGitProgressDlg::ReportCmd(const CString& sCmd)
790 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
793 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
795 // instead of showing a dialog box with the error message or notification,
796 // just insert the error text into the list control.
797 // that way the user isn't 'interrupted' by a dialog box popping up!
799 // the message may be split up into different lines
800 // so add a new entry for each line of the message
801 while (!sMessage.IsEmpty())
803 NotificationData * data = new NotificationData();
804 data->bAuxItem = true;
805 data->sActionColumnText = sMsgKind;
806 if (sMessage.Find('\n')>=0)
807 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
808 else
809 data->sPathColumnText = sMessage;
810 data->sPathColumnText.Trim(_T("\n\r"));
811 data->color = color;
812 if (sMessage.Find('\n')>=0)
814 sMessage = sMessage.Mid(sMessage.Find('\n'));
815 sMessage.Trim(_T("\n\r"));
817 else
818 sMessage.Empty();
819 m_arData.push_back(data);
820 AddItemToList();
824 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
826 return ((CGitProgressDlg*)pVoid)->ProgressThread();
829 UINT CGitProgressDlg::ProgressThread()
831 // The SetParams function should have loaded something for us
833 CString temp;
834 CString sWindowTitle;
835 bool localoperation = false;
836 bool bSuccess = false;
837 m_AlwaysConflicted = false;
839 DialogEnableWindow(IDOK, FALSE);
840 DialogEnableWindow(IDCANCEL, TRUE);
841 // SetAndClearProgressInfo(m_hWnd);
842 m_itemCount = m_itemCountTotal;
844 InterlockedExchange(&m_bThreadRunning, TRUE);
845 iFirstResized = 0;
846 bSecondResized = FALSE;
847 m_bFinishedItemAdded = false;
848 CTime startTime = CTime::GetCurrentTime();
849 switch (m_Command)
851 case GitProgress_Add:
852 bSuccess = CmdAdd(sWindowTitle, localoperation);
853 break;
854 case GitProgress_Checkout:
855 bSuccess = CmdCheckout(sWindowTitle, localoperation);
856 break;
857 case GitProgress_Commit:
858 bSuccess = CmdCommit(sWindowTitle, localoperation);
859 break;
860 case GitProgress_Copy:
861 bSuccess = CmdCopy(sWindowTitle, localoperation);
862 break;
863 case GitProgress_Export:
864 bSuccess = CmdExport(sWindowTitle, localoperation);
865 break;
866 case GitProgress_Import:
867 bSuccess = CmdImport(sWindowTitle, localoperation);
868 break;
869 case GitProgress_Lock:
870 bSuccess = CmdLock(sWindowTitle, localoperation);
871 break;
872 case GitProgress_Merge:
873 bSuccess = CmdMerge(sWindowTitle, localoperation);
874 break;
875 case GitProgress_MergeAll:
876 bSuccess = CmdMergeAll(sWindowTitle, localoperation);
877 break;
878 case GitProgress_MergeReintegrate:
879 bSuccess = CmdMergeReintegrate(sWindowTitle, localoperation);
880 break;
881 case GitProgress_Rename:
882 bSuccess = CmdRename(sWindowTitle, localoperation);
883 break;
884 case GitProgress_Resolve:
885 bSuccess = CmdResolve(sWindowTitle, localoperation);
886 break;
887 case GitProgress_Revert:
888 bSuccess = CmdRevert(sWindowTitle, localoperation);
889 break;
890 case GitProgress_Switch:
891 bSuccess = CmdSwitch(sWindowTitle, localoperation);
892 break;
893 case GitProgress_Unlock:
894 bSuccess = CmdUnlock(sWindowTitle, localoperation);
895 break;
896 case GitProgress_Update:
897 bSuccess = CmdUpdate(sWindowTitle, localoperation);
898 break;
900 if (!bSuccess)
901 temp.LoadString(IDS_PROGRS_TITLEFAILED);
902 else
903 temp.LoadString(IDS_PROGRS_TITLEFIN);
904 sWindowTitle = sWindowTitle + _T(" ") + temp;
905 SetWindowText(sWindowTitle);
907 KillTimer(TRANSFERTIMER);
908 KillTimer(VISIBLETIMER);
910 DialogEnableWindow(IDCANCEL, FALSE);
911 DialogEnableWindow(IDOK, TRUE);
913 CString info = BuildInfoString();
914 if (!bSuccess)
915 info.LoadString(IDS_PROGRS_INFOFAILED);
916 SetDlgItemText(IDC_INFOTEXT, info);
917 ResizeColumns();
918 SendMessage(DM_SETDEFID, IDOK);
919 GetDlgItem(IDOK)->SetFocus();
921 CString sFinalInfo;
922 if (!m_sTotalBytesTransferred.IsEmpty())
924 CTimeSpan time = CTime::GetCurrentTime() - startTime;
925 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
926 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
927 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
929 else
930 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
932 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
934 if (!m_bFinishedItemAdded)
936 // there's no "finished: xxx" line at the end. We add one here to make
937 // sure the user sees that the command is actually finished.
938 NotificationData * data = new NotificationData();
939 data->bAuxItem = true;
940 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
941 m_arData.push_back(data);
942 AddItemToList();
945 int count = m_ProgList.GetItemCount();
946 if ((count > 0)&&(m_bLastVisible))
947 m_ProgList.EnsureVisible(count-1, FALSE);
949 CLogFile logfile;
950 if (logfile.Open())
952 logfile.AddTimeLine();
953 for (size_t i=0; i<m_arData.size(); i++)
955 NotificationData * data = m_arData[i];
956 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
957 logfile.AddLine(temp);
959 if (!sFinalInfo.IsEmpty())
960 logfile.AddLine(sFinalInfo);
961 logfile.Close();
964 m_bCancelled = TRUE;
965 InterlockedExchange(&m_bThreadRunning, FALSE);
966 RefreshCursor();
968 DWORD dwAutoClose = CRegStdWORD(_T("Software\\TortoiseGit\\AutoClose"));
969 if (m_options & ProgOptDryRun)
970 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
971 if (!m_bLastVisible)
972 dwAutoClose = 0;
973 if (m_dwCloseOnEnd != (DWORD)-1)
974 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
975 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
976 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
977 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
978 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
979 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
980 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
981 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
982 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
984 //Don't do anything here which might cause messages to be sent to the window
985 //The window thread is probably now blocked in OnOK if we've done an auto close
986 return 0;
989 void CGitProgressDlg::OnBnClickedLogbutton()
991 #if 0
992 if (m_targetPathList.GetCount() != 1)
993 return;
994 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
995 svn_revnum_t rev = -1;
996 if (it != m_UpdateStartRevMap.end())
998 rev = it->second;
1000 CLogDlg dlg;
1001 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1002 dlg.DoModal();
1003 #endif
1007 void CGitProgressDlg::OnClose()
1009 if (m_bCancelled)
1011 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1012 InterlockedExchange(&m_bThreadRunning, FALSE);
1014 else
1016 m_bCancelled = TRUE;
1017 return;
1019 DialogEnableWindow(IDCANCEL, TRUE);
1020 __super::OnClose();
1023 void CGitProgressDlg::OnOK()
1025 if ((m_bCancelled)&&(!m_bThreadRunning))
1027 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1028 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1029 // don't do any more operations on the window which might require message passing
1030 // If you try to send windows messages once we're waiting here, then the thread can't finished
1031 // because the Window's message loop is blocked at this wait
1032 WaitForSingleObject(m_pThread->m_hThread, 10000);
1033 __super::OnOK();
1035 m_bCancelled = TRUE;
1038 void CGitProgressDlg::OnCancel()
1040 if ((m_bCancelled)&&(!m_bThreadRunning))
1041 __super::OnCancel();
1042 m_bCancelled = TRUE;
1045 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1047 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1049 if (pDispInfo)
1051 if (pDispInfo->item.mask & LVIF_TEXT)
1053 if (pDispInfo->item.iItem < (int)m_arData.size())
1055 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1056 switch (pDispInfo->item.iSubItem)
1058 case 0:
1059 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1060 break;
1061 case 1:
1062 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1063 if (!data->bAuxItem)
1065 int cWidth = m_ProgList.GetColumnWidth(1);
1066 cWidth = max(12, cWidth-12);
1067 CDC * pDC = m_ProgList.GetDC();
1068 if (pDC != NULL)
1070 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1071 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1072 pDC->SelectObject(pFont);
1073 ReleaseDC(pDC);
1076 break;
1077 case 2:
1078 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1079 break;
1080 default:
1081 m_columnbuf[0] = 0;
1083 pDispInfo->item.pszText = m_columnbuf;
1087 *pResult = 0;
1090 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1092 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1094 // Take the default processing unless we set this to something else below.
1095 *pResult = CDRF_DODEFAULT;
1097 // First thing - check the draw stage. If it's the control's prepaint
1098 // stage, then tell Windows we want messages for every item.
1100 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1102 *pResult = CDRF_NOTIFYITEMDRAW;
1104 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1106 // This is the prepaint stage for an item. Here's where we set the
1107 // item's text color. Our return value will tell Windows to draw the
1108 // item itself, but it will use the new color we set here.
1110 // Tell Windows to paint the control itself.
1111 *pResult = CDRF_DODEFAULT;
1113 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1114 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1116 return;
1118 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1119 ASSERT(data != NULL);
1120 if (data == NULL)
1121 return;
1123 // Store the color back in the NMLVCUSTOMDRAW struct.
1124 pLVCD->clrText = data->color;
1128 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1130 #if 0
1131 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1132 *pResult = 0;
1133 if (pNMLV->iItem < 0)
1134 return;
1135 if (m_options & ProgOptDryRun)
1136 return; //don't do anything in a dry-run.
1138 const NotificationData * data = m_arData[pNMLV->iItem];
1139 if (data == NULL)
1140 return;
1142 if (data->bConflictedActionItem)
1144 // We've double-clicked on a conflicted item - do a three-way merge on it
1145 SVNDiff::StartConflictEditor(data->path);
1147 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))
1149 // This is a modified file which has been merged on update. Diff it against base
1150 CTGitPath temporaryFile;
1151 SVNDiff diff(this, this->m_hWnd, true);
1152 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1153 svn_revnum_t baseRev = 0;
1154 diff.DiffFileAgainstBase(data->path, baseRev);
1156 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1158 bool bOpenWith = false;
1159 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1160 if (ret <= HINSTANCE_ERROR)
1161 bOpenWith = true;
1162 if (bOpenWith)
1164 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1165 cmd += data->path.GetWinPathString() + _T(" ");
1166 CAppUtils::LaunchApplication(cmd, NULL, false);
1169 #endif
1172 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1174 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1175 if (m_bThreadRunning)
1176 return;
1177 if (m_nSortedColumn == phdr->iItem)
1178 m_bAscending = !m_bAscending;
1179 else
1180 m_bAscending = TRUE;
1181 m_nSortedColumn = phdr->iItem;
1182 Sort();
1184 CString temp;
1185 m_ProgList.SetRedraw(FALSE);
1186 m_ProgList.DeleteAllItems();
1187 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1189 m_ProgList.SetRedraw(TRUE);
1191 *pResult = 0;
1194 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1196 return pData->bAuxItem;
1199 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM lParam)
1201 #if 0
1202 SVNProgress * pProgressData = (SVNProgress *)lParam;
1203 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1204 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1206 progControl->ShowWindow(SW_SHOW);
1208 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1210 progControl->ShowWindow(SW_HIDE);
1212 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1213 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1214 SetTimer(TRANSFERTIMER, 2000, NULL);
1215 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1217 progControl->SetPos((int)pProgressData->progress);
1218 progControl->SetRange32(0, (int)pProgressData->total);
1220 CString progText;
1221 if (pProgressData->overall_total < 1024)
1222 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1223 else if (pProgressData->overall_total < 1200000)
1224 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1225 else
1226 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1227 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1228 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1229 #endif
1230 return 0;
1233 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1235 if (nIDEvent == TRANSFERTIMER)
1237 CString progText;
1238 CString progSpeed;
1239 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1240 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1241 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1242 KillTimer(TRANSFERTIMER);
1244 if (nIDEvent == VISIBLETIMER)
1246 if (nEnsureVisibleCount)
1247 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1248 nEnsureVisibleCount = 0;
1252 void CGitProgressDlg::Sort()
1254 if(m_arData.size() < 2)
1256 return;
1259 // We need to sort the blocks which lie between the auxiliary entries
1260 // This is so that any aux data stays where it was
1261 NotificationDataVect::iterator actionBlockBegin;
1262 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1264 for(;;)
1266 // Search to the start of the non-aux entry in the next block
1267 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1268 if(actionBlockBegin == m_arData.end())
1270 // There are no more actions
1271 break;
1273 // Now search to find the end of the block
1274 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1275 // Now sort the block
1276 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1280 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1282 int result = 0;
1283 switch (m_nSortedColumn)
1285 case 0: //action column
1286 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1287 break;
1288 case 1: //path column
1289 // Compare happens after switch()
1290 break;
1291 case 2: //mime-type column
1292 result = pData1->mime_type.Compare(pData2->mime_type);
1293 break;
1294 default:
1295 break;
1298 // Sort by path if everything else is equal
1299 if (result == 0)
1301 result = CTGitPath::Compare(pData1->path, pData2->path);
1304 if (!m_bAscending)
1305 result = -result;
1306 return result < 0;
1309 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1311 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1313 // only show the wait cursor over the list control
1314 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1316 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1317 SetCursor(hCur);
1318 return TRUE;
1321 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1322 SetCursor(hCur);
1323 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1326 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1328 if (pMsg->message == WM_KEYDOWN)
1330 if (pMsg->wParam == VK_ESCAPE)
1332 // pressing the ESC key should close the dialog. But since we disabled the escape
1333 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1334 // this won't work.
1335 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1336 // the impression that the OK button was pressed.
1337 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1338 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1340 // since we convert ESC to RETURN, make sure the OK button has the focus.
1341 GetDlgItem(IDOK)->SetFocus();
1342 pMsg->wParam = VK_RETURN;
1345 if (pMsg->wParam == 'A')
1347 if (GetKeyState(VK_CONTROL)&0x8000)
1349 // Ctrl-A -> select all
1350 m_ProgList.SetSelectionMark(0);
1351 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1353 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1357 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1359 int selIndex = m_ProgList.GetSelectionMark();
1360 if (selIndex >= 0)
1362 if (GetKeyState(VK_CONTROL)&0x8000)
1364 //Ctrl-C -> copy to clipboard
1365 CString sClipdata;
1366 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1367 if (pos != NULL)
1369 while (pos)
1371 int nItem = m_ProgList.GetNextSelectedItem(pos);
1372 CString sAction = m_ProgList.GetItemText(nItem, 0);
1373 CString sPath = m_ProgList.GetItemText(nItem, 1);
1374 CString sMime = m_ProgList.GetItemText(nItem, 2);
1375 CString sLogCopyText;
1376 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1377 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1378 sClipdata += sLogCopyText;
1380 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1385 } // if (pMsg->message == WM_KEYDOWN)
1386 return __super::PreTranslateMessage(pMsg);
1389 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1391 #if 0
1392 if (m_options & ProgOptDryRun)
1393 return; // don't do anything in a dry-run.
1395 if (pWnd == &m_ProgList)
1397 int selIndex = m_ProgList.GetSelectionMark();
1398 if ((point.x == -1) && (point.y == -1))
1400 // Menu was invoked from the keyboard rather than by right-clicking
1401 CRect rect;
1402 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1403 m_ProgList.ClientToScreen(&rect);
1404 point = rect.CenterPoint();
1407 if ((selIndex >= 0)&&(!m_bThreadRunning))
1409 // entry is selected, thread has finished with updating so show the popup menu
1410 CIconMenu popup;
1411 if (popup.CreatePopupMenu())
1413 bool bAdded = false;
1414 NotificationData * data = m_arData[selIndex];
1415 if ((data)&&(!data->path.IsDirectory()))
1417 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1419 if (m_ProgList.GetSelectedCount() == 1)
1421 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1422 bAdded = true;
1425 if (data->bConflictedActionItem)
1427 if (m_ProgList.GetSelectedCount() == 1)
1429 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1430 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1431 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1433 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1434 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1436 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1437 popup.SetDefaultItem(ID_COMPARE, FALSE);
1439 if (m_ProgList.GetSelectedCount() == 1)
1441 if ((data->action == svn_wc_notify_add)||
1442 (data->action == svn_wc_notify_update_add)||
1443 (data->action == svn_wc_notify_commit_added)||
1444 (data->action == svn_wc_notify_commit_modified)||
1445 (data->action == svn_wc_notify_restore)||
1446 (data->action == svn_wc_notify_revert)||
1447 (data->action == svn_wc_notify_resolved)||
1448 (data->action == svn_wc_notify_commit_replaced)||
1449 (data->action == svn_wc_notify_commit_modified)||
1450 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1451 (data->action == svn_wc_notify_update_update))
1453 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1454 if (data->action == svn_wc_notify_update_update)
1455 popup.AppendMenu(MF_SEPARATOR, NULL);
1456 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1457 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1458 bAdded = true;
1461 } // if ((data)&&(!data->path.IsDirectory()))
1462 if (m_ProgList.GetSelectedCount() == 1)
1464 if (data)
1466 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1467 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1469 CTGitPath path = CTGitPath(sPath);
1470 if (path.GetDirectory().Exists())
1472 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1473 bAdded = true;
1478 if (m_ProgList.GetSelectedCount() > 0)
1480 if (bAdded)
1481 popup.AppendMenu(MF_SEPARATOR, NULL);
1482 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1483 bAdded = true;
1485 if (bAdded)
1487 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1488 DialogEnableWindow(IDOK, FALSE);
1489 this->SetPromptApp(&theApp);
1490 theApp.DoWaitCursor(1);
1491 bool bOpenWith = false;
1492 switch (cmd)
1494 case ID_COPY:
1496 CString sLines;
1497 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1498 while (pos)
1500 int nItem = m_ProgList.GetNextSelectedItem(pos);
1501 NotificationData * data = m_arData[nItem];
1502 if (data)
1504 sLines += data->sPathColumnText;
1505 sLines += _T("\r\n");
1508 sLines.TrimRight();
1509 if (!sLines.IsEmpty())
1511 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1514 break;
1515 case ID_EXPLORE:
1517 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1519 CTGitPath path = CTGitPath(sPath);
1520 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1522 break;
1523 case ID_COMPARE:
1525 svn_revnum_t rev = -1;
1526 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1527 if (data->basepath.IsEmpty())
1528 it = m_UpdateStartRevMap.begin();
1529 else
1530 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1531 if (it != m_UpdateStartRevMap.end())
1532 rev = it->second;
1533 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1534 if (data->content_state == svn_wc_notify_state_merged)
1536 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1537 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1538 SVN svn;
1539 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1541 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1542 DialogEnableWindow(IDOK, TRUE);
1543 break;
1545 // If necessary, convert the line-endings on the file before diffing
1546 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1548 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1549 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1551 temporaryFile.Reset();
1552 break;
1554 else
1556 newfile = temporaryFile;
1560 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1561 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1562 CString revname, wcname, basename;
1563 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1564 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1565 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1566 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1568 else
1570 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1571 SVN svn;
1572 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1574 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1575 DialogEnableWindow(IDOK, TRUE);
1576 break;
1578 else
1580 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1581 CString revname, wcname;
1582 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1583 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1584 CAppUtils::StartExtDiff(
1585 tempfile, data->path, revname, wcname,
1586 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1590 break;
1591 case ID_EDITCONFLICT:
1593 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1594 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1596 break;
1597 case ID_CONFLICTUSETHEIRS:
1598 case ID_CONFLICTUSEMINE:
1599 case ID_CONFLICTRESOLVE:
1601 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1602 switch (cmd)
1604 case ID_CONFLICTUSETHEIRS:
1605 result = svn_wc_conflict_choose_theirs_full;
1606 break;
1607 case ID_CONFLICTUSEMINE:
1608 result = svn_wc_conflict_choose_mine_full;
1609 break;
1610 case ID_CONFLICTRESOLVE:
1611 result = svn_wc_conflict_choose_merged;
1612 break;
1614 SVN svn;
1615 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1616 CString sResolvedPaths;
1617 while (pos)
1619 int nItem = m_ProgList.GetNextSelectedItem(pos);
1620 NotificationData * data = m_arData[nItem];
1621 if (data)
1623 if (data->bConflictedActionItem)
1625 if (!svn.Resolve(data->path, result, FALSE))
1627 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
1628 DialogEnableWindow(IDOK, TRUE);
1629 break;
1631 else
1633 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1634 data->action = svn_wc_notify_resolved;
1635 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1636 data->bConflictedActionItem = false;
1637 m_nConflicts--;
1639 if (m_nConflicts==0)
1641 // When the last conflict is resolved we remove
1642 // the warning which we assume is in the last line.
1643 int nIndex = m_ProgList.GetItemCount()-1;
1644 VERIFY(m_ProgList.DeleteItem(nIndex));
1646 delete m_arData[nIndex];
1647 m_arData.pop_back();
1649 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1654 m_ProgList.Invalidate();
1655 CString info = BuildInfoString();
1656 SetDlgItemText(IDC_INFOTEXT, info);
1658 if (!sResolvedPaths.IsEmpty())
1660 CString msg;
1661 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1662 CMessageBox::Show(m_hWnd, msg, _T("TortoiseSVN"), MB_OK | MB_ICONINFORMATION);
1665 break;
1666 case ID_LOG:
1668 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
1669 int limit = (int)(DWORD)reg;
1670 svn_revnum_t rev = m_RevisionEnd;
1671 if (!data->basepath.IsEmpty())
1673 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1674 if (it != m_FinishedRevMap.end())
1675 rev = it->second;
1677 CLogDlg dlg;
1678 // fetch the log from HEAD, not the revision we updated to:
1679 // the path might be inside an external folder which has its own
1680 // revisions.
1681 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1682 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);
1683 dlg.DoModal();
1685 break;
1686 case ID_OPENWITH:
1687 bOpenWith = true;
1688 case ID_OPEN:
1690 int ret = 0;
1691 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1692 if (!bOpenWith)
1693 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1694 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1696 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1697 cmd += sWinPath + _T(" ");
1698 CAppUtils::LaunchApplication(cmd, NULL, false);
1702 DialogEnableWindow(IDOK, TRUE);
1703 theApp.DoWaitCursor(-1);
1704 } // if (bAdded)
1708 #endif
1711 void CGitProgressDlg::OnEnSetfocusInfotext()
1713 CString sTemp;
1714 GetDlgItemText(IDC_INFOTEXT, sTemp);
1715 if (sTemp.IsEmpty())
1716 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1719 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1721 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1722 #if 0
1723 int selIndex = m_ProgList.GetSelectionMark();
1724 if (selIndex < 0)
1725 return;
1727 CDropFiles dropFiles; // class for creating DROPFILES struct
1729 int index;
1730 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1731 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1733 NotificationData * data = m_arData[index];
1735 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1737 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1739 dropFiles.AddFile( sPath );
1743 if ( dropFiles.GetCount()>0 )
1745 dropFiles.CreateStructure();
1747 #endif
1748 *pResult = 0;
1751 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1753 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1754 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1756 if(!m_ProgList.m_hWnd)
1757 return;
1759 int count = m_ProgList.GetItemCount();
1760 if (count > 0)
1761 m_ProgList.EnsureVisible(count-1, false);
1765 //////////////////////////////////////////////////////////////////////////
1766 /// commands
1767 //////////////////////////////////////////////////////////////////////////
1768 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1771 localoperation = true;
1772 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1773 SetWindowText(sWindowTitle);
1774 SetBackgroundImage(IDI_ADD_BKG);
1775 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1777 for(int i=0;i<m_targetPathList.GetCount();i++)
1779 CString cmd,out;
1780 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());
1781 if(g_Git.Run(cmd,&out,CP_OEMCP))
1783 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1784 m_bErrorsOccurred=true;
1785 return false;
1787 Notify(m_targetPathList[i],git_wc_notify_add);
1789 #if 0
1790 if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))
1792 ReportSVNError();
1793 return false;
1795 #endif
1796 //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1797 m_bErrorsOccurred=false;
1798 return true;
1801 bool CGitProgressDlg::CmdCheckout(CString& sWindowTitle, bool& /*localoperation*/)
1803 #if 0
1804 ASSERT(m_targetPathList.GetCount() == 1);
1805 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CHECKOUT);
1806 SetBackgroundImage(IDI_CHECKOUT_BKG);
1807 CTGitPathList urls;
1808 urls.LoadFromAsteriskSeparatedString(m_url.GetSVNPathString());
1809 CTGitPath checkoutdir = m_targetPathList[0];
1810 for (int i=0; i<urls.GetCount(); ++i)
1812 sWindowTitle = urls[i].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1813 SetWindowText(sWindowTitle);
1814 checkoutdir = m_targetPathList[0];
1815 if (urls.GetCount() > 1)
1817 CString fileordir = urls[i].GetFileOrDirectoryName();
1818 fileordir = CPathUtils::PathUnescape(fileordir);
1819 checkoutdir.AppendPathString(fileordir);
1821 CString sCmdInfo;
1822 sCmdInfo.Format(IDS_PROGRS_CMD_CHECKOUT,
1823 (LPCTSTR)urls[i].GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
1824 (LPCTSTR)SVNStatus::GetDepthString(m_depth),
1825 m_options & ProgOptIgnoreExternals ? (LPCTSTR)sExtExcluded : (LPCTSTR)sExtIncluded);
1826 ReportCmd(sCmdInfo);
1828 if (!Checkout(urls[i], checkoutdir, m_Revision, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1830 if (m_ProgList.GetItemCount()!=0)
1832 ReportSVNError();
1833 return false;
1835 // if the checkout fails with the peg revision set to the checkout revision,
1836 // try again with HEAD as the peg revision.
1837 else
1839 if (!Checkout(urls[i], checkoutdir, SVNRev::REV_HEAD, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1841 ReportSVNError();
1842 return false;
1847 #endif
1848 return true;
1851 bool CGitProgressDlg::CmdCommit(CString& sWindowTitle, bool& /*localoperation*/)
1853 #if 0
1854 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COMMIT);
1855 SetWindowText(sWindowTitle);
1856 SetBackgroundImage(IDI_COMMIT_BKG);
1857 if (m_targetPathList.GetCount()==0)
1859 SetWindowText(sWindowTitle);
1861 DialogEnableWindow(IDCANCEL, FALSE);
1862 DialogEnableWindow(IDOK, TRUE);
1864 InterlockedExchange(&m_bThreadRunning, FALSE);
1865 return true;
1867 if (m_targetPathList.GetCount()==1)
1869 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1870 SetWindowText(sWindowTitle);
1872 BOOL isTag = FALSE;
1873 BOOL bURLFetched = FALSE;
1874 CString url;
1875 for (int i=0; i<m_targetPathList.GetCount(); ++i)
1877 if (bURLFetched == FALSE)
1879 url = GetURLFromPath(m_targetPathList[i]);
1880 if (!url.IsEmpty())
1881 bURLFetched = TRUE;
1882 CString urllower = url;
1883 urllower.MakeLower();
1884 // test if the commit goes to a tag.
1885 // now since Subversion doesn't force users to
1886 // create tags in the recommended /tags/ folder
1887 // only a warning is shown. This won't work if the tags
1888 // are stored in a non-recommended place, but the check
1889 // still helps those who do.
1890 if (urllower.Find(_T("/tags/"))>=0)
1891 isTag = TRUE;
1892 break;
1895 if (isTag)
1897 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_COMMITT_TRUNK, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)==IDNO)
1898 return false;
1900 DWORD exitcode = 0;
1901 CString error;
1902 if (CHooks::Instance().PreCommit(m_selectedPaths, m_depth, m_sMessage, exitcode, error))
1904 if (exitcode)
1906 CString temp;
1907 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1908 ReportError(temp);
1909 return false;
1913 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)));
1914 CStringArray changelists;
1915 if (!m_changelist.IsEmpty())
1916 changelists.Add(m_changelist);
1917 bool commitSuccessful = true;
1918 if (!Commit(m_targetPathList, m_sMessage, changelists, m_keepchangelist,
1919 m_depth, m_options & ProgOptKeeplocks))
1921 ReportSVNError();
1922 error = GetLastErrorMessage();
1923 // if a non-recursive commit failed with SVN_ERR_UNSUPPORTED_FEATURE,
1924 // that means a folder deletion couldn't be committed.
1925 if ((m_Revision != 0)&&(Err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
1927 ReportError(CString(MAKEINTRESOURCE(IDS_PROGRS_NONRECURSIVEHINT)));
1929 commitSuccessful = false;
1930 return false;
1932 if (!PostCommitErr.IsEmpty())
1934 ReportWarning(PostCommitErr);
1936 if (commitSuccessful)
1938 if (m_BugTraqProvider)
1940 CComPtr<IBugTraqProvider2> pProvider = NULL;
1941 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1942 if (SUCCEEDED(hr))
1944 BSTR commonRoot = SysAllocString(m_targetPathList.GetCommonRoot().GetDirectory().GetWinPath());
1945 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_targetPathList.GetCount());
1947 for (LONG index = 0; index < m_targetPathList.GetCount(); ++index)
1948 SafeArrayPutElement(pathList, &index, m_targetPathList[index].GetSVNPathString().AllocSysString());
1950 BSTR logMessage = m_sMessage.AllocSysString();
1952 BSTR temp = NULL;
1953 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1954 commonRoot,
1955 pathList,
1956 logMessage,
1957 (LONG)m_RevisionEnd,
1958 &temp)))
1960 CString sErr = temp;
1961 if (!sErr.IsEmpty())
1962 ReportError(temp);
1965 SysFreeString(temp);
1969 if (CHooks::Instance().PostCommit(m_selectedPaths, m_depth, m_RevisionEnd, m_sMessage, exitcode, error))
1971 if (exitcode)
1973 CString temp;
1974 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1975 ReportError(temp);
1976 return false;
1979 #endif
1980 return true;
1983 bool CGitProgressDlg::CmdCopy(CString& sWindowTitle, bool& /*localoperation*/)
1985 #if 0
1986 ASSERT(m_targetPathList.GetCount() == 1);
1987 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
1988 SetWindowText(sWindowTitle);
1989 SetBackgroundImage(IDI_COPY_BKG);
1991 CString sCmdInfo;
1992 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
1993 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
1994 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
1995 ReportCmd(sCmdInfo);
1997 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
1999 ReportSVNError();
2000 return false;
2002 if (m_options & ProgOptSwitchAfterCopy)
2004 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2005 m_targetPathList[0].GetWinPath(),
2006 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2007 ReportCmd(sCmdInfo);
2008 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2010 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2012 ReportSVNError();
2013 return false;
2017 else
2019 if (SVN::PathIsURL(m_url))
2021 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2022 ReportNotification(sMsg);
2025 #endif
2026 return true;
2029 bool CGitProgressDlg::CmdExport(CString& sWindowTitle, bool& /*localoperation*/)
2031 #if 0
2032 ASSERT(m_targetPathList.GetCount() == 1);
2033 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2034 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2035 SetWindowText(sWindowTitle);
2036 SetBackgroundImage(IDI_EXPORT_BKG);
2037 CString eol;
2038 if (m_options & ProgOptEolCRLF)
2039 eol = _T("CRLF");
2040 if (m_options & ProgOptEolLF)
2041 eol = _T("LF");
2042 if (m_options & ProgOptEolCR)
2043 eol = _T("CR");
2044 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2045 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2047 ReportSVNError();
2048 return false;
2050 #endif
2051 return true;
2054 bool CGitProgressDlg::CmdImport(CString& sWindowTitle, bool& /*localoperation*/)
2056 #if 0
2057 ASSERT(m_targetPathList.GetCount() == 1);
2058 sWindowTitle.LoadString(IDS_PROGRS_TITLE_IMPORT);
2059 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2060 SetWindowText(sWindowTitle);
2061 SetBackgroundImage(IDI_IMPORT_BKG);
2062 CString sCmdInfo;
2063 sCmdInfo.Format(IDS_PROGRS_CMD_IMPORT,
2064 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2065 m_options & ProgOptIncludeIgnored ? (LPCTSTR)(_T(", ") + sIgnoredIncluded) : _T(""));
2066 ReportCmd(sCmdInfo);
2067 if (!Import(m_targetPathList[0], m_url, m_sMessage, &m_ProjectProperties, svn_depth_infinity, m_options & ProgOptIncludeIgnored ? true : false, false))
2069 ReportSVNError();
2070 return false;
2072 #endif
2073 return true;
2076 bool CGitProgressDlg::CmdLock(CString& sWindowTitle, bool& /*localoperation*/)
2078 #if 0
2079 sWindowTitle.LoadString(IDS_PROGRS_TITLE_LOCK);
2080 SetWindowText(sWindowTitle);
2081 SetBackgroundImage(IDI_LOCK_BKG);
2082 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_LOCK)));
2083 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2085 ReportSVNError();
2086 return false;
2088 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2089 if (m_bLockWarning)
2091 // the lock failed, because the file was outdated.
2092 // ask the user whether to update the file and try again
2093 if (CMessageBox::Show(m_hWnd, IDS_WARN_LOCKOUTDATED, IDS_APPNAME, MB_ICONQUESTION|MB_YESNO)==IDYES)
2095 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_UPDATEANDRETRY)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2096 if (!Update(m_targetPathList, SVNRev::REV_HEAD, svn_depth_files, false, true))
2098 ReportSVNError();
2099 return false;
2101 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2103 ReportSVNError();
2104 return false;
2108 if (m_bLockExists)
2110 // the locking failed because there already is a lock.
2111 // if the locking-dialog is skipped in the settings, tell the
2112 // user how to steal the lock anyway (i.e., how to get the lock
2113 // dialog back without changing the settings)
2114 if (!DWORD(CRegDWORD(_T("Software\\TortoiseGit\\ShowLockDlg"), TRUE)))
2116 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_LOCKHINT)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2118 return false;
2120 #endif
2121 return true;
2124 bool CGitProgressDlg::CmdMerge(CString& sWindowTitle, bool& /*localoperation*/)
2126 #if 0
2127 bool bFailed = false;
2128 ASSERT(m_targetPathList.GetCount() == 1);
2129 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2130 SetBackgroundImage(IDI_MERGE_BKG);
2131 if (m_options & ProgOptDryRun)
2133 sWindowTitle += _T(" ") + sDryRun;
2135 if (m_options & ProgOptRecordOnly)
2137 sWindowTitle += _T(" ") + sRecordOnly;
2139 SetWindowText(sWindowTitle);
2141 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_HIDE);
2142 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2143 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2144 if (DWORD(nonint))
2146 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2147 m_AlwaysConflicted = true;
2149 // we only accept a revision list to merge for peg merges
2150 ATLASSERT((m_revisionArray.GetCount()==0) || (m_revisionArray.GetCount() && (m_url.IsEquivalentTo(m_url2))));
2152 if (m_url.IsEquivalentTo(m_url2))
2154 CString sSuggestedMessage;
2155 CString sMergedLogMessage;
2156 CString sSeparator = CRegString(_T("Software\\TortoiseGit\\MergeLogSeparator"), _T("........"));
2157 CString temp;
2159 // Merging revisions %s of %s to %s into %s, %s%s
2160 CString sCmdInfo;
2161 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEPEG,
2162 (LPCTSTR)m_revisionArray.ToListString(),
2163 (LPCTSTR)m_url.GetSVNPathString(),
2164 m_targetPathList[0].GetWinPath(),
2165 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2166 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2167 ReportCmd(sCmdInfo);
2169 if (!PegMerge(m_url, m_revisionArray,
2170 m_pegRev.IsValid() ? m_pegRev : (m_url.IsUrl() ? SVNRev::REV_HEAD : SVNRev(SVNRev::REV_WC)),
2171 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2173 // if the merge fails with the peg revision set,
2174 // try again with HEAD as the peg revision.
2175 if (!PegMerge(m_url, m_revisionArray, SVNRev::REV_HEAD,
2176 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2178 ReportSVNError();
2179 bFailed = true;
2183 else
2185 CString sCmdInfo;
2186 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEURL,
2187 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
2188 (LPCTSTR)m_url2.GetSVNPathString(), (LPCTSTR)m_RevisionEnd.ToString(),
2189 m_targetPathList[0].GetWinPath(),
2190 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2191 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2192 ReportCmd(sCmdInfo);
2194 if (!Merge(m_url, m_Revision, m_url2, m_RevisionEnd, m_targetPathList[0],
2195 true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2197 ReportSVNError();
2198 bFailed = true;
2201 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2202 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_SHOW);
2203 return !bFailed;
2204 #endif
2205 return true;
2208 bool CGitProgressDlg::CmdMergeAll(CString& sWindowTitle, bool& /*localoperation*/)
2210 #if 0
2211 ASSERT(m_targetPathList.GetCount() == 1);
2212 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2213 SetBackgroundImage(IDI_MERGE_BKG);
2214 SetWindowText(sWindowTitle);
2216 ATLASSERT(m_targetPathList.GetCount() == 1);
2218 CString sCmdInfo;
2219 sCmdInfo.LoadString(IDS_PROGRS_INFOGETTINGINFO);
2220 ReportCmd(sCmdInfo);
2221 CTGitPathList suggestedSources;
2222 if (!SuggestMergeSources(m_targetPathList[0], m_Revision, suggestedSources))
2224 ReportSVNError();
2225 return false;
2228 if (suggestedSources.GetCount() == 0)
2230 CString sErr;
2231 sErr.Format(IDS_PROGRS_MERGEALLNOSOURCES, m_targetPathList[0].GetWinPath());
2232 ReportError(sErr);
2233 return false;
2235 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEALL,
2236 (LPCTSTR)suggestedSources[0].GetSVNPathString(),
2237 m_targetPathList[0].GetWinPath(),
2238 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry);
2239 ReportCmd(sCmdInfo);
2241 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2242 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2243 if (DWORD(nonint))
2245 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2246 m_AlwaysConflicted = true;
2249 SVNRevRangeArray revarray;
2250 if (!PegMerge(suggestedSources[0], revarray,
2251 SVNRev::REV_HEAD,
2252 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), FALSE))
2254 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2255 ReportSVNError();
2256 return false;
2259 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2260 #endif
2261 return true;
2264 bool CGitProgressDlg::CmdMergeReintegrate(CString& sWindowTitle, bool& /*localoperation*/)
2266 #if 0
2267 ASSERT(m_targetPathList.GetCount() == 1);
2268 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGEREINTEGRATE);
2269 SetBackgroundImage(IDI_MERGE_BKG);
2270 SetWindowText(sWindowTitle);
2272 CString sCmdInfo;
2273 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEREINTEGRATE,
2274 (LPCTSTR)m_url.GetSVNPathString(),
2275 m_targetPathList[0].GetWinPath());
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 if (!MergeReintegrate(m_url, SVNRev::REV_HEAD, m_targetPathList[0], !!(m_options & ProgOptDryRun), m_diffoptions))
2288 ReportSVNError();
2289 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2290 return false;
2293 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2294 #endif
2295 return true;
2298 bool CGitProgressDlg::CmdRename(CString& sWindowTitle, bool& localoperation)
2300 #if 0
2301 ASSERT(m_targetPathList.GetCount() == 1);
2302 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2303 localoperation = true;
2304 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2305 SetWindowText(sWindowTitle);
2306 SetBackgroundImage(IDI_RENAME_BKG);
2307 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2308 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2310 ReportSVNError();
2311 return false;
2313 #endif
2314 return true;
2317 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2320 localoperation = true;
2321 ASSERT(m_targetPathList.GetCount() == 1);
2322 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2323 SetWindowText(sWindowTitle);
2324 SetBackgroundImage(IDI_RESOLVE_BKG);
2325 // check if the file may still have conflict markers in it.
2326 BOOL bMarkers = FALSE;
2328 for(int i=0;i<m_targetPathList.GetCount();i++)
2330 CString cmd,out,tempmergefile;
2331 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());
2332 if(g_Git.Run(cmd,&out,CP_OEMCP))
2334 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2335 m_bErrorsOccurred=true;
2336 return false;
2342 tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),(CTGitPath &)m_targetPathList[i]);
2343 CFile::Remove(tempmergefile);
2344 }catch(...)
2350 tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),(CTGitPath &)m_targetPathList[i]);
2351 CFile::Remove(tempmergefile);
2352 }catch(...)
2358 tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),(CTGitPath &)m_targetPathList[i]);
2359 CFile::Remove(tempmergefile);
2360 }catch(...)
2365 Notify(m_targetPathList[i],git_wc_notify_resolved);
2367 #if 0
2368 if ((m_options & ProgOptSkipConflictCheck) == 0)
2372 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2374 if (!m_targetPathList[fileindex].IsDirectory())
2376 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2377 CString strLine = _T("");
2378 while (file.ReadString(strLine))
2380 if (strLine.Find(_T("<<<<<<<"))==0)
2382 bMarkers = TRUE;
2383 break;
2386 file.Close();
2390 catch (CFileException* pE)
2392 TRACE(_T("CFileException in Resolve!\n"));
2393 TCHAR error[10000] = {0};
2394 pE->GetErrorMessage(error, 10000);
2395 ReportError(error);
2396 pE->Delete();
2397 return false;
2400 if (bMarkers)
2402 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2404 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2405 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2406 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2409 else
2411 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2412 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2413 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2415 #endif
2416 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2418 return true;
2421 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2423 #if 0
2424 localoperation = true;
2425 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2426 SetWindowText(sWindowTitle);
2427 SetBackgroundImage(IDI_REVERT_BKG);
2429 CTGitPathList delList = m_selectedPaths;
2430 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2431 delList.DeleteAllFiles(true);
2433 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2434 if (!Revert(m_targetPathList, CStringArray(), !!(m_options & ProgOptRecursive)))
2436 ReportSVNError();
2437 return false;
2439 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2440 #endif
2441 return true;
2444 bool CGitProgressDlg::CmdSwitch(CString& sWindowTitle, bool& /*localoperation*/)
2446 #if 0
2447 ASSERT(m_targetPathList.GetCount() == 1);
2448 SVNStatus st;
2449 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2450 SetWindowText(sWindowTitle);
2451 SetBackgroundImage(IDI_SWITCH_BKG);
2452 LONG rev = 0;
2453 if (st.GetStatus(m_targetPathList[0]) != (-2))
2455 if (st.status->entry != NULL)
2457 rev = st.status->entry->revision;
2461 CString sCmdInfo;
2462 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2463 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2464 (LPCTSTR)m_Revision.ToString());
2465 ReportCmd(sCmdInfo);
2467 bool depthIsSticky = true;
2468 if (m_depth == svn_depth_unknown)
2469 depthIsSticky = false;
2470 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2472 ReportSVNError();
2473 return false;
2475 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2476 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2477 &&((LONG)m_RevisionEnd > (LONG)rev))
2479 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2481 #endif
2482 return true;
2485 bool CGitProgressDlg::CmdUnlock(CString& sWindowTitle, bool& /*localoperation*/)
2487 #if 0
2488 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UNLOCK);
2489 SetWindowText(sWindowTitle);
2490 SetBackgroundImage(IDI_UNLOCK_BKG);
2491 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UNLOCK)));
2492 if (!Unlock(m_targetPathList, m_options & ProgOptLockForce))
2494 ReportSVNError();
2495 return false;
2497 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2498 #endif
2499 return true;
2502 bool CGitProgressDlg::CmdUpdate(CString& sWindowTitle, bool& /*localoperation*/)
2504 #if 0
2505 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UPDATE);
2506 SetWindowText(sWindowTitle);
2507 SetBackgroundImage(IDI_UPDATE_BKG);
2509 int targetcount = m_targetPathList.GetCount();
2510 CString sfile;
2511 CStringA uuid;
2512 StringRevMap uuidmap;
2513 SVNRev revstore = m_Revision;
2514 int nUUIDs = 0;
2515 for(int nItem = 0; nItem < targetcount; nItem++)
2517 const CTGitPath& targetPath = m_targetPathList[nItem];
2518 SVNStatus st;
2519 LONG headrev = -1;
2520 m_Revision = revstore;
2521 if (m_Revision.IsHead())
2523 if ((targetcount > 1)&&((headrev = st.GetStatus(targetPath, true)) != (-2)))
2525 if (st.status->entry != NULL)
2528 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2529 if (st.status->entry->uuid)
2531 uuid = st.status->entry->uuid;
2532 StringRevMap::iterator iter = uuidmap.lower_bound(uuid);
2533 if (iter == uuidmap.end() || iter->first != uuid)
2535 uuidmap.insert(iter, std::make_pair(uuid, headrev));
2536 nUUIDs++;
2538 else
2539 headrev = iter->second;
2540 m_Revision = headrev;
2542 else
2543 m_Revision = headrev;
2546 else
2548 if ((headrev = st.GetStatus(targetPath, FALSE)) != (-2))
2550 if (st.status->entry != NULL)
2551 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2554 if (uuidmap.size() > 1)
2555 m_Revision = SVNRev::REV_HEAD;
2556 } // if (m_Revision.IsHead())
2557 } // for(int nItem = 0; nItem < targetcount; nItem++)
2558 sWindowTitle = m_targetPathList.GetCommonRoot().GetWinPathString()+_T(" - ")+sWindowTitle;
2559 SetWindowText(sWindowTitle);
2561 DWORD exitcode = 0;
2562 CString error;
2563 if (CHooks::Instance().PreUpdate(m_targetPathList, m_depth, nUUIDs > 1 ? revstore : m_Revision, exitcode, error))
2565 if (exitcode)
2567 CString temp;
2568 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2569 ReportError(temp);
2570 return false;
2573 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UPDATE)));
2574 if (nUUIDs > 1)
2576 // the selected items are from different repositories,
2577 // so we have to update them separately
2578 for(int nItem = 0; nItem < targetcount; nItem++)
2580 const CTGitPath& targetPath = m_targetPathList[nItem];
2581 m_basePath = targetPath;
2582 CString sNotify;
2583 sNotify.Format(IDS_PROGRS_UPDATEPATH, m_basePath.GetWinPath());
2584 ReportString(sNotify, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2585 if (!Update(CTGitPathList(targetPath), revstore, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2587 ReportSVNError();
2588 return false;
2592 else
2594 // if we have only one target path, but that target path does not exist,
2595 // we have to check whether at least the parent path exists. If not,
2596 // then we have to update all paths in between the first path that exists and the
2597 // parent path of the one we want to update
2598 // This is required so a user can create a sparse checkout without having
2599 // to update all intermediate folders manually
2600 if ((m_targetPathList.GetCount() == 1) && (!m_targetPathList[0].Exists()))
2602 CTGitPath wcPath = m_targetPathList[0].GetContainingDirectory();
2603 CTGitPath existingParentPath = wcPath.GetContainingDirectory();
2604 while (!existingParentPath.Exists() && (existingParentPath.GetWinPathString().GetLength() > 2))
2606 existingParentPath = existingParentPath.GetContainingDirectory();
2608 if (existingParentPath.GetWinPathString().GetLength() && !existingParentPath.IsEquivalentTo(wcPath))
2610 // update all intermediate directories with depth 'empty'
2611 CTGitPath intermediatepath = existingParentPath;
2612 bool bSuccess = true;
2613 while (bSuccess && intermediatepath.IsAncestorOf(wcPath) && !intermediatepath.IsEquivalentTo(wcPath))
2615 CString childname = wcPath.GetWinPathString().Mid(intermediatepath.GetWinPathString().GetLength(),
2616 wcPath.GetWinPathString().Find('\\', intermediatepath.GetWinPathString().GetLength()+1)-intermediatepath.GetWinPathString().GetLength());
2617 if (childname.IsEmpty())
2618 intermediatepath = wcPath;
2619 else
2620 intermediatepath.AppendPathString(childname);
2621 bSuccess = !!Update(CTGitPathList(intermediatepath), m_Revision, svn_depth_empty, false, true);
2624 if (!bSuccess)
2626 ReportSVNError();
2627 return false;
2631 if (!Update(m_targetPathList, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2633 ReportSVNError();
2634 return false;
2637 if (CHooks::Instance().PostUpdate(m_targetPathList, m_depth, m_RevisionEnd, exitcode, error))
2639 if (exitcode)
2641 CString temp;
2642 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2643 ReportError(temp);
2644 return false;
2648 // after an update, show the user the log button, but only if only one single item was updated
2649 // (either a file or a directory)
2650 if ((m_targetPathList.GetCount() == 1)&&(m_UpdateStartRevMap.size()>0))
2651 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2652 #endif
2653 return true;
2656 void CGitProgressDlg::OnBnClickedNoninteractive()
2658 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2659 m_AlwaysConflicted = (res == BST_CHECKED);
2660 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2661 nonint = m_AlwaysConflicted;
2664 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2666 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2667 if (sPath.Find(':')<0)
2669 // the path is not absolute: add the common root of all paths to it
2670 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2672 return sPath;