Fixed some unused variables warnings
[TortoiseGit.git] / src / TortoiseProc / SVNProgressDlg.cpp
blob30aa2c60795e6dbe0e2e71111daa3d5f174dbf71
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(this->m_Command == GitProgress_Resolve)
552 infotext = _T("You need commit your change after resolve conflict");
553 #if 0
555 CString temp;
556 int added = 0;
557 int copied = 0;
558 int deleted = 0;
559 int restored = 0;
560 int reverted = 0;
561 int resolved = 0;
562 int conflicted = 0;
563 int updated = 0;
564 int merged = 0;
565 int modified = 0;
566 int skipped = 0;
567 int replaced = 0;
569 for (size_t i=0; i<m_arData.size(); ++i)
571 const NotificationData * dat = m_arData[i];
572 switch (dat->action)
574 case svn_wc_notify_add:
575 case svn_wc_notify_update_add:
576 case svn_wc_notify_commit_added:
577 if (dat->bConflictedActionItem)
578 conflicted++;
579 else
580 added++;
581 break;
582 case svn_wc_notify_copy:
583 copied++;
584 break;
585 case svn_wc_notify_delete:
586 case svn_wc_notify_update_delete:
587 case svn_wc_notify_commit_deleted:
588 deleted++;
589 break;
590 case svn_wc_notify_restore:
591 restored++;
592 break;
593 case svn_wc_notify_revert:
594 reverted++;
595 break;
596 case svn_wc_notify_resolved:
597 resolved++;
598 break;
599 case svn_wc_notify_update_update:
600 if (dat->bConflictedActionItem)
601 conflicted++;
602 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
603 merged++;
604 else
605 updated++;
606 break;
607 case svn_wc_notify_commit_modified:
608 modified++;
609 break;
610 case svn_wc_notify_skip:
611 skipped++;
612 break;
613 case svn_wc_notify_commit_replaced:
614 replaced++;
615 break;
618 if (conflicted)
620 temp.LoadString(IDS_SVNACTION_CONFLICTED);
621 infotext += temp;
622 temp.Format(_T(":%d "), conflicted);
623 infotext += temp;
625 if (skipped)
627 temp.LoadString(IDS_SVNACTION_SKIP);
628 infotext += temp;
629 infotext.AppendFormat(_T(":%d "), skipped);
631 if (merged)
633 temp.LoadString(IDS_SVNACTION_MERGED);
634 infotext += temp;
635 infotext.AppendFormat(_T(":%d "), merged);
637 if (added)
639 temp.LoadString(IDS_SVNACTION_ADD);
640 infotext += temp;
641 infotext.AppendFormat(_T(":%d "), added);
643 if (deleted)
645 temp.LoadString(IDS_SVNACTION_DELETE);
646 infotext += temp;
647 infotext.AppendFormat(_T(":%d "), deleted);
649 if (modified)
651 temp.LoadString(IDS_SVNACTION_MODIFIED);
652 infotext += temp;
653 infotext.AppendFormat(_T(":%d "), modified);
655 if (copied)
657 temp.LoadString(IDS_SVNACTION_COPY);
658 infotext += temp;
659 infotext.AppendFormat(_T(":%d "), copied);
661 if (replaced)
663 temp.LoadString(IDS_SVNACTION_REPLACED);
664 infotext += temp;
665 infotext.AppendFormat(_T(":%d "), replaced);
667 if (updated)
669 temp.LoadString(IDS_SVNACTION_UPDATE);
670 infotext += temp;
671 infotext.AppendFormat(_T(":%d "), updated);
673 if (restored)
675 temp.LoadString(IDS_SVNACTION_RESTORE);
676 infotext += temp;
677 infotext.AppendFormat(_T(":%d "), restored);
679 if (reverted)
681 temp.LoadString(IDS_SVNACTION_REVERT);
682 infotext += temp;
683 infotext.AppendFormat(_T(":%d "), reverted);
685 if (resolved)
687 temp.LoadString(IDS_SVNACTION_RESOLVE);
688 infotext += temp;
689 infotext.AppendFormat(_T(":%d "), resolved);
691 #endif
692 return infotext;
695 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
697 m_selectedPaths = selPaths;
700 void CGitProgressDlg::ResizeColumns()
702 m_ProgList.SetRedraw(FALSE);
704 TCHAR textbuf[MAX_PATH];
706 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
707 for (int col = 0; col <= maxcol; col++)
709 // find the longest width of all items
710 int count = m_ProgList.GetItemCount();
711 HDITEM hdi = {0};
712 hdi.mask = HDI_TEXT;
713 hdi.pszText = textbuf;
714 hdi.cchTextMax = sizeof(textbuf);
715 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
716 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
718 for (int index = 0; index<count; ++index)
720 // get the width of the string and add 12 pixels for the column separator and margins
721 int linewidth = cx;
722 switch (col)
724 case 0:
725 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
726 break;
727 case 1:
728 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
729 break;
730 case 2:
731 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;
732 break;
734 if (cx < linewidth)
735 cx = linewidth;
737 m_ProgList.SetColumnWidth(col, cx);
740 m_ProgList.SetRedraw(TRUE);
743 BOOL CGitProgressDlg::OnInitDialog()
745 __super::OnInitDialog();
747 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
749 m_ProgList.DeleteAllItems();
750 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
751 while (c>=0)
752 m_ProgList.DeleteColumn(c--);
753 CString temp;
754 temp.LoadString(IDS_PROGRS_ACTION);
755 m_ProgList.InsertColumn(0, temp);
756 temp.LoadString(IDS_PROGRS_PATH);
757 m_ProgList.InsertColumn(1, temp);
758 temp.LoadString(IDS_PROGRS_MIMETYPE);
759 m_ProgList.InsertColumn(2, temp);
761 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
762 if (m_pThread==NULL)
764 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
766 else
768 m_pThread->m_bAutoDelete = FALSE;
769 m_pThread->ResumeThread();
772 UpdateData(FALSE);
774 // Call this early so that the column headings aren't hidden before any
775 // text gets added.
776 ResizeColumns();
778 SetTimer(VISIBLETIMER, 300, NULL);
780 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
781 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
782 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
783 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
784 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
785 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
786 AddAnchor(IDOK, BOTTOM_RIGHT);
787 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
788 //SetPromptParentWindow(this->m_hWnd);
789 if (hWndExplorer)
790 CenterWindow(CWnd::FromHandle(hWndExplorer));
791 EnableSaveRestore(_T("SVNProgressDlg"));
792 return TRUE;
795 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
797 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
800 #if 0
801 void CGitProgressDlg::ReportSVNError()
803 ReportError(GetLastErrorMessage());
805 #endif
807 void CGitProgressDlg::ReportError(const CString& sError)
809 CSoundUtils::PlayTGitError();
810 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
811 m_bErrorsOccurred = true;
814 void CGitProgressDlg::ReportWarning(const CString& sWarning)
816 CSoundUtils::PlayTGitWarning();
817 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
820 void CGitProgressDlg::ReportNotification(const CString& sNotification)
822 CSoundUtils::PlayTGitNotification();
823 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
826 void CGitProgressDlg::ReportCmd(const CString& sCmd)
828 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
831 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
833 // instead of showing a dialog box with the error message or notification,
834 // just insert the error text into the list control.
835 // that way the user isn't 'interrupted' by a dialog box popping up!
837 // the message may be split up into different lines
838 // so add a new entry for each line of the message
839 while (!sMessage.IsEmpty())
841 NotificationData * data = new NotificationData();
842 data->bAuxItem = true;
843 data->sActionColumnText = sMsgKind;
844 if (sMessage.Find('\n')>=0)
845 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
846 else
847 data->sPathColumnText = sMessage;
848 data->sPathColumnText.Trim(_T("\n\r"));
849 data->color = color;
850 if (sMessage.Find('\n')>=0)
852 sMessage = sMessage.Mid(sMessage.Find('\n'));
853 sMessage.Trim(_T("\n\r"));
855 else
856 sMessage.Empty();
857 m_arData.push_back(data);
858 AddItemToList();
862 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
864 return ((CGitProgressDlg*)pVoid)->ProgressThread();
867 UINT CGitProgressDlg::ProgressThread()
869 // The SetParams function should have loaded something for us
871 CString temp;
872 CString sWindowTitle;
873 bool localoperation = false;
874 bool bSuccess = false;
875 m_AlwaysConflicted = false;
877 DialogEnableWindow(IDOK, FALSE);
878 DialogEnableWindow(IDCANCEL, TRUE);
879 // SetAndClearProgressInfo(m_hWnd);
880 m_itemCount = m_itemCountTotal;
882 InterlockedExchange(&m_bThreadRunning, TRUE);
883 iFirstResized = 0;
884 bSecondResized = FALSE;
885 m_bFinishedItemAdded = false;
886 CTime startTime = CTime::GetCurrentTime();
887 switch (m_Command)
889 case GitProgress_Add:
890 bSuccess = CmdAdd(sWindowTitle, localoperation);
891 break;
892 case GitProgress_Checkout:
893 bSuccess = CmdCheckout(sWindowTitle, localoperation);
894 break;
895 case GitProgress_Commit:
896 bSuccess = CmdCommit(sWindowTitle, localoperation);
897 break;
898 case GitProgress_Copy:
899 bSuccess = CmdCopy(sWindowTitle, localoperation);
900 break;
901 case GitProgress_Export:
902 bSuccess = CmdExport(sWindowTitle, localoperation);
903 break;
904 case GitProgress_Import:
905 bSuccess = CmdImport(sWindowTitle, localoperation);
906 break;
907 case GitProgress_Lock:
908 bSuccess = CmdLock(sWindowTitle, localoperation);
909 break;
910 case GitProgress_Merge:
911 bSuccess = CmdMerge(sWindowTitle, localoperation);
912 break;
913 case GitProgress_MergeAll:
914 bSuccess = CmdMergeAll(sWindowTitle, localoperation);
915 break;
916 case GitProgress_MergeReintegrate:
917 bSuccess = CmdMergeReintegrate(sWindowTitle, localoperation);
918 break;
919 case GitProgress_Rename:
920 bSuccess = CmdRename(sWindowTitle, localoperation);
921 break;
922 case GitProgress_Resolve:
923 bSuccess = CmdResolve(sWindowTitle, localoperation);
924 break;
925 case GitProgress_Revert:
926 bSuccess = CmdRevert(sWindowTitle, localoperation);
927 break;
928 case GitProgress_Switch:
929 bSuccess = CmdSwitch(sWindowTitle, localoperation);
930 break;
931 case GitProgress_Unlock:
932 bSuccess = CmdUnlock(sWindowTitle, localoperation);
933 break;
934 case GitProgress_Update:
935 bSuccess = CmdUpdate(sWindowTitle, localoperation);
936 break;
937 case GitProgress_SendMail:
938 bSuccess = CmdSendMail(sWindowTitle, localoperation);
939 break;
941 if (!bSuccess)
942 temp.LoadString(IDS_PROGRS_TITLEFAILED);
943 else
944 temp.LoadString(IDS_PROGRS_TITLEFIN);
945 sWindowTitle = sWindowTitle + _T(" ") + temp;
946 SetWindowText(sWindowTitle);
948 KillTimer(TRANSFERTIMER);
949 KillTimer(VISIBLETIMER);
951 DialogEnableWindow(IDCANCEL, FALSE);
952 DialogEnableWindow(IDOK, TRUE);
954 CString info = BuildInfoString();
955 if (!bSuccess)
956 info.LoadString(IDS_PROGRS_INFOFAILED);
957 SetDlgItemText(IDC_INFOTEXT, info);
958 ResizeColumns();
959 SendMessage(DM_SETDEFID, IDOK);
960 GetDlgItem(IDOK)->SetFocus();
962 CString sFinalInfo;
963 if (!m_sTotalBytesTransferred.IsEmpty())
965 CTimeSpan time = CTime::GetCurrentTime() - startTime;
966 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
967 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
968 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
970 else
971 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
973 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
975 if (!m_bFinishedItemAdded)
977 // there's no "finished: xxx" line at the end. We add one here to make
978 // sure the user sees that the command is actually finished.
979 NotificationData * data = new NotificationData();
980 data->bAuxItem = true;
981 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
982 m_arData.push_back(data);
983 AddItemToList();
986 int count = m_ProgList.GetItemCount();
987 if ((count > 0)&&(m_bLastVisible))
988 m_ProgList.EnsureVisible(count-1, FALSE);
990 CLogFile logfile;
991 if (logfile.Open())
993 logfile.AddTimeLine();
994 for (size_t i=0; i<m_arData.size(); i++)
996 NotificationData * data = m_arData[i];
997 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
998 logfile.AddLine(temp);
1000 if (!sFinalInfo.IsEmpty())
1001 logfile.AddLine(sFinalInfo);
1002 logfile.Close();
1005 m_bCancelled = TRUE;
1006 InterlockedExchange(&m_bThreadRunning, FALSE);
1007 RefreshCursor();
1009 DWORD dwAutoClose = CRegStdWORD(_T("Software\\TortoiseGit\\AutoClose"));
1010 if (m_options & ProgOptDryRun)
1011 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1012 if (!m_bLastVisible)
1013 dwAutoClose = 0;
1014 if (m_dwCloseOnEnd != (DWORD)-1)
1015 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1016 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1017 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1018 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1019 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1020 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1021 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1022 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1023 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1025 //Don't do anything here which might cause messages to be sent to the window
1026 //The window thread is probably now blocked in OnOK if we've done an auto close
1027 return 0;
1030 void CGitProgressDlg::OnBnClickedLogbutton()
1032 switch(this->m_Command)
1034 case GitProgress_Add:
1035 case GitProgress_Resolve:
1037 CString cmd;
1038 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
1039 cmd += _T(" /command:commit");
1041 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1043 CAppUtils::LaunchApplication(cmd,NULL,false);
1044 this->EndDialog(IDOK);
1045 break;
1048 #if 0
1049 if (m_targetPathList.GetCount() != 1)
1050 return;
1051 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1052 svn_revnum_t rev = -1;
1053 if (it != m_UpdateStartRevMap.end())
1055 rev = it->second;
1057 CLogDlg dlg;
1058 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1059 dlg.DoModal();
1060 #endif
1064 void CGitProgressDlg::OnClose()
1066 if (m_bCancelled)
1068 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1069 InterlockedExchange(&m_bThreadRunning, FALSE);
1071 else
1073 m_bCancelled = TRUE;
1074 return;
1076 DialogEnableWindow(IDCANCEL, TRUE);
1077 __super::OnClose();
1080 void CGitProgressDlg::OnOK()
1082 if ((m_bCancelled)&&(!m_bThreadRunning))
1084 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1085 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1086 // don't do any more operations on the window which might require message passing
1087 // If you try to send windows messages once we're waiting here, then the thread can't finished
1088 // because the Window's message loop is blocked at this wait
1089 WaitForSingleObject(m_pThread->m_hThread, 10000);
1090 __super::OnOK();
1092 m_bCancelled = TRUE;
1095 void CGitProgressDlg::OnCancel()
1097 if ((m_bCancelled)&&(!m_bThreadRunning))
1098 __super::OnCancel();
1099 m_bCancelled = TRUE;
1102 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1104 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1106 if (pDispInfo)
1108 if (pDispInfo->item.mask & LVIF_TEXT)
1110 if (pDispInfo->item.iItem < (int)m_arData.size())
1112 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1113 switch (pDispInfo->item.iSubItem)
1115 case 0:
1116 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1117 break;
1118 case 1:
1119 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1120 if (!data->bAuxItem)
1122 int cWidth = m_ProgList.GetColumnWidth(1);
1123 cWidth = max(12, cWidth-12);
1124 CDC * pDC = m_ProgList.GetDC();
1125 if (pDC != NULL)
1127 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1128 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1129 pDC->SelectObject(pFont);
1130 ReleaseDC(pDC);
1133 break;
1134 case 2:
1135 lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);
1136 break;
1137 default:
1138 m_columnbuf[0] = 0;
1140 pDispInfo->item.pszText = m_columnbuf;
1144 *pResult = 0;
1147 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1149 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1151 // Take the default processing unless we set this to something else below.
1152 *pResult = CDRF_DODEFAULT;
1154 // First thing - check the draw stage. If it's the control's prepaint
1155 // stage, then tell Windows we want messages for every item.
1157 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1159 *pResult = CDRF_NOTIFYITEMDRAW;
1161 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1163 // This is the prepaint stage for an item. Here's where we set the
1164 // item's text color. Our return value will tell Windows to draw the
1165 // item itself, but it will use the new color we set here.
1167 // Tell Windows to paint the control itself.
1168 *pResult = CDRF_DODEFAULT;
1170 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1171 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1173 return;
1175 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1176 ASSERT(data != NULL);
1177 if (data == NULL)
1178 return;
1180 // Store the color back in the NMLVCUSTOMDRAW struct.
1181 pLVCD->clrText = data->color;
1185 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1187 #if 0
1188 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1189 *pResult = 0;
1190 if (pNMLV->iItem < 0)
1191 return;
1192 if (m_options & ProgOptDryRun)
1193 return; //don't do anything in a dry-run.
1195 const NotificationData * data = m_arData[pNMLV->iItem];
1196 if (data == NULL)
1197 return;
1199 if (data->bConflictedActionItem)
1201 // We've double-clicked on a conflicted item - do a three-way merge on it
1202 SVNDiff::StartConflictEditor(data->path);
1204 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))
1206 // This is a modified file which has been merged on update. Diff it against base
1207 CTGitPath temporaryFile;
1208 SVNDiff diff(this, this->m_hWnd, true);
1209 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1210 svn_revnum_t baseRev = 0;
1211 diff.DiffFileAgainstBase(data->path, baseRev);
1213 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1215 bool bOpenWith = false;
1216 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1217 if (ret <= HINSTANCE_ERROR)
1218 bOpenWith = true;
1219 if (bOpenWith)
1221 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1222 cmd += data->path.GetWinPathString() + _T(" ");
1223 CAppUtils::LaunchApplication(cmd, NULL, false);
1226 #endif
1229 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1231 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1232 if (m_bThreadRunning)
1233 return;
1234 if (m_nSortedColumn == phdr->iItem)
1235 m_bAscending = !m_bAscending;
1236 else
1237 m_bAscending = TRUE;
1238 m_nSortedColumn = phdr->iItem;
1239 Sort();
1241 CString temp;
1242 m_ProgList.SetRedraw(FALSE);
1243 m_ProgList.DeleteAllItems();
1244 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1246 m_ProgList.SetRedraw(TRUE);
1248 *pResult = 0;
1251 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1253 return pData->bAuxItem;
1256 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM lParam)
1258 #if 0
1259 SVNProgress * pProgressData = (SVNProgress *)lParam;
1260 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1261 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1263 progControl->ShowWindow(SW_SHOW);
1265 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1267 progControl->ShowWindow(SW_HIDE);
1269 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1270 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1271 SetTimer(TRANSFERTIMER, 2000, NULL);
1272 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1274 progControl->SetPos((int)pProgressData->progress);
1275 progControl->SetRange32(0, (int)pProgressData->total);
1277 CString progText;
1278 if (pProgressData->overall_total < 1024)
1279 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1280 else if (pProgressData->overall_total < 1200000)
1281 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1282 else
1283 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1284 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1285 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1286 #endif
1287 return 0;
1290 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1292 if (nIDEvent == TRANSFERTIMER)
1294 CString progText;
1295 CString progSpeed;
1296 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1297 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1298 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1299 KillTimer(TRANSFERTIMER);
1301 if (nIDEvent == VISIBLETIMER)
1303 if (nEnsureVisibleCount)
1304 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1305 nEnsureVisibleCount = 0;
1309 void CGitProgressDlg::Sort()
1311 if(m_arData.size() < 2)
1313 return;
1316 // We need to sort the blocks which lie between the auxiliary entries
1317 // This is so that any aux data stays where it was
1318 NotificationDataVect::iterator actionBlockBegin;
1319 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1321 for(;;)
1323 // Search to the start of the non-aux entry in the next block
1324 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1325 if(actionBlockBegin == m_arData.end())
1327 // There are no more actions
1328 break;
1330 // Now search to find the end of the block
1331 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1332 // Now sort the block
1333 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1337 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1339 int result = 0;
1340 switch (m_nSortedColumn)
1342 case 0: //action column
1343 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1344 break;
1345 case 1: //path column
1346 // Compare happens after switch()
1347 break;
1348 case 2: //mime-type column
1349 result = pData1->mime_type.Compare(pData2->mime_type);
1350 break;
1351 default:
1352 break;
1355 // Sort by path if everything else is equal
1356 if (result == 0)
1358 result = CTGitPath::Compare(pData1->path, pData2->path);
1361 if (!m_bAscending)
1362 result = -result;
1363 return result < 0;
1366 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1368 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1370 // only show the wait cursor over the list control
1371 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1373 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1374 SetCursor(hCur);
1375 return TRUE;
1378 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1379 SetCursor(hCur);
1380 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1383 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1385 if (pMsg->message == WM_KEYDOWN)
1387 if (pMsg->wParam == VK_ESCAPE)
1389 // pressing the ESC key should close the dialog. But since we disabled the escape
1390 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1391 // this won't work.
1392 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1393 // the impression that the OK button was pressed.
1394 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1395 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1397 // since we convert ESC to RETURN, make sure the OK button has the focus.
1398 GetDlgItem(IDOK)->SetFocus();
1399 pMsg->wParam = VK_RETURN;
1402 if (pMsg->wParam == 'A')
1404 if (GetKeyState(VK_CONTROL)&0x8000)
1406 // Ctrl-A -> select all
1407 m_ProgList.SetSelectionMark(0);
1408 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1410 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1414 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1416 int selIndex = m_ProgList.GetSelectionMark();
1417 if (selIndex >= 0)
1419 if (GetKeyState(VK_CONTROL)&0x8000)
1421 //Ctrl-C -> copy to clipboard
1422 CString sClipdata;
1423 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1424 if (pos != NULL)
1426 while (pos)
1428 int nItem = m_ProgList.GetNextSelectedItem(pos);
1429 CString sAction = m_ProgList.GetItemText(nItem, 0);
1430 CString sPath = m_ProgList.GetItemText(nItem, 1);
1431 CString sMime = m_ProgList.GetItemText(nItem, 2);
1432 CString sLogCopyText;
1433 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1434 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1435 sClipdata += sLogCopyText;
1437 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1442 } // if (pMsg->message == WM_KEYDOWN)
1443 return __super::PreTranslateMessage(pMsg);
1446 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)
1448 #if 0
1449 if (m_options & ProgOptDryRun)
1450 return; // don't do anything in a dry-run.
1452 if (pWnd == &m_ProgList)
1454 int selIndex = m_ProgList.GetSelectionMark();
1455 if ((point.x == -1) && (point.y == -1))
1457 // Menu was invoked from the keyboard rather than by right-clicking
1458 CRect rect;
1459 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1460 m_ProgList.ClientToScreen(&rect);
1461 point = rect.CenterPoint();
1464 if ((selIndex >= 0)&&(!m_bThreadRunning))
1466 // entry is selected, thread has finished with updating so show the popup menu
1467 CIconMenu popup;
1468 if (popup.CreatePopupMenu())
1470 bool bAdded = false;
1471 NotificationData * data = m_arData[selIndex];
1472 if ((data)&&(!data->path.IsDirectory()))
1474 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1476 if (m_ProgList.GetSelectedCount() == 1)
1478 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1479 bAdded = true;
1482 if (data->bConflictedActionItem)
1484 if (m_ProgList.GetSelectedCount() == 1)
1486 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1487 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1488 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1490 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1491 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1493 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1494 popup.SetDefaultItem(ID_COMPARE, FALSE);
1496 if (m_ProgList.GetSelectedCount() == 1)
1498 if ((data->action == svn_wc_notify_add)||
1499 (data->action == svn_wc_notify_update_add)||
1500 (data->action == svn_wc_notify_commit_added)||
1501 (data->action == svn_wc_notify_commit_modified)||
1502 (data->action == svn_wc_notify_restore)||
1503 (data->action == svn_wc_notify_revert)||
1504 (data->action == svn_wc_notify_resolved)||
1505 (data->action == svn_wc_notify_commit_replaced)||
1506 (data->action == svn_wc_notify_commit_modified)||
1507 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1508 (data->action == svn_wc_notify_update_update))
1510 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1511 if (data->action == svn_wc_notify_update_update)
1512 popup.AppendMenu(MF_SEPARATOR, NULL);
1513 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1514 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1515 bAdded = true;
1518 } // if ((data)&&(!data->path.IsDirectory()))
1519 if (m_ProgList.GetSelectedCount() == 1)
1521 if (data)
1523 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1524 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1526 CTGitPath path = CTGitPath(sPath);
1527 if (path.GetDirectory().Exists())
1529 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1530 bAdded = true;
1535 if (m_ProgList.GetSelectedCount() > 0)
1537 if (bAdded)
1538 popup.AppendMenu(MF_SEPARATOR, NULL);
1539 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1540 bAdded = true;
1542 if (bAdded)
1544 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1545 DialogEnableWindow(IDOK, FALSE);
1546 this->SetPromptApp(&theApp);
1547 theApp.DoWaitCursor(1);
1548 bool bOpenWith = false;
1549 switch (cmd)
1551 case ID_COPY:
1553 CString sLines;
1554 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1555 while (pos)
1557 int nItem = m_ProgList.GetNextSelectedItem(pos);
1558 NotificationData * data = m_arData[nItem];
1559 if (data)
1561 sLines += data->sPathColumnText;
1562 sLines += _T("\r\n");
1565 sLines.TrimRight();
1566 if (!sLines.IsEmpty())
1568 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1571 break;
1572 case ID_EXPLORE:
1574 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1576 CTGitPath path = CTGitPath(sPath);
1577 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1579 break;
1580 case ID_COMPARE:
1582 svn_revnum_t rev = -1;
1583 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1584 if (data->basepath.IsEmpty())
1585 it = m_UpdateStartRevMap.begin();
1586 else
1587 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1588 if (it != m_UpdateStartRevMap.end())
1589 rev = it->second;
1590 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1591 if (data->content_state == svn_wc_notify_state_merged)
1593 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1594 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1595 SVN svn;
1596 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1598 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1599 DialogEnableWindow(IDOK, TRUE);
1600 break;
1602 // If necessary, convert the line-endings on the file before diffing
1603 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1605 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1606 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1608 temporaryFile.Reset();
1609 break;
1611 else
1613 newfile = temporaryFile;
1617 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1618 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1619 CString revname, wcname, basename;
1620 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1621 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1622 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1623 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1625 else
1627 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1628 SVN svn;
1629 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1631 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1632 DialogEnableWindow(IDOK, TRUE);
1633 break;
1635 else
1637 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1638 CString revname, wcname;
1639 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1640 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1641 CAppUtils::StartExtDiff(
1642 tempfile, data->path, revname, wcname,
1643 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1647 break;
1648 case ID_EDITCONFLICT:
1650 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1651 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1653 break;
1654 case ID_CONFLICTUSETHEIRS:
1655 case ID_CONFLICTUSEMINE:
1656 case ID_CONFLICTRESOLVE:
1658 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1659 switch (cmd)
1661 case ID_CONFLICTUSETHEIRS:
1662 result = svn_wc_conflict_choose_theirs_full;
1663 break;
1664 case ID_CONFLICTUSEMINE:
1665 result = svn_wc_conflict_choose_mine_full;
1666 break;
1667 case ID_CONFLICTRESOLVE:
1668 result = svn_wc_conflict_choose_merged;
1669 break;
1671 SVN svn;
1672 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1673 CString sResolvedPaths;
1674 while (pos)
1676 int nItem = m_ProgList.GetNextSelectedItem(pos);
1677 NotificationData * data = m_arData[nItem];
1678 if (data)
1680 if (data->bConflictedActionItem)
1682 if (!svn.Resolve(data->path, result, FALSE))
1684 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1685 DialogEnableWindow(IDOK, TRUE);
1686 break;
1688 else
1690 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1691 data->action = svn_wc_notify_resolved;
1692 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1693 data->bConflictedActionItem = false;
1694 m_nConflicts--;
1696 if (m_nConflicts==0)
1698 // When the last conflict is resolved we remove
1699 // the warning which we assume is in the last line.
1700 int nIndex = m_ProgList.GetItemCount()-1;
1701 VERIFY(m_ProgList.DeleteItem(nIndex));
1703 delete m_arData[nIndex];
1704 m_arData.pop_back();
1706 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1711 m_ProgList.Invalidate();
1712 CString info = BuildInfoString();
1713 SetDlgItemText(IDC_INFOTEXT, info);
1715 if (!sResolvedPaths.IsEmpty())
1717 CString msg;
1718 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1719 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1722 break;
1723 case ID_LOG:
1725 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
1726 int limit = (int)(DWORD)reg;
1727 svn_revnum_t rev = m_RevisionEnd;
1728 if (!data->basepath.IsEmpty())
1730 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1731 if (it != m_FinishedRevMap.end())
1732 rev = it->second;
1734 CLogDlg dlg;
1735 // fetch the log from HEAD, not the revision we updated to:
1736 // the path might be inside an external folder which has its own
1737 // revisions.
1738 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1739 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);
1740 dlg.DoModal();
1742 break;
1743 case ID_OPENWITH:
1744 bOpenWith = true;
1745 case ID_OPEN:
1747 int ret = 0;
1748 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1749 if (!bOpenWith)
1750 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1751 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1753 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1754 cmd += sWinPath + _T(" ");
1755 CAppUtils::LaunchApplication(cmd, NULL, false);
1759 DialogEnableWindow(IDOK, TRUE);
1760 theApp.DoWaitCursor(-1);
1761 } // if (bAdded)
1765 #endif
1768 void CGitProgressDlg::OnEnSetfocusInfotext()
1770 CString sTemp;
1771 GetDlgItemText(IDC_INFOTEXT, sTemp);
1772 if (sTemp.IsEmpty())
1773 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1776 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1778 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1779 #if 0
1780 int selIndex = m_ProgList.GetSelectionMark();
1781 if (selIndex < 0)
1782 return;
1784 CDropFiles dropFiles; // class for creating DROPFILES struct
1786 int index;
1787 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1788 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1790 NotificationData * data = m_arData[index];
1792 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1794 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1796 dropFiles.AddFile( sPath );
1800 if ( dropFiles.GetCount()>0 )
1802 dropFiles.CreateStructure();
1804 #endif
1805 *pResult = 0;
1808 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1810 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1811 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1813 if(!m_ProgList.m_hWnd)
1814 return;
1816 int count = m_ProgList.GetItemCount();
1817 if (count > 0)
1818 m_ProgList.EnsureVisible(count-1, false);
1822 //////////////////////////////////////////////////////////////////////////
1823 /// commands
1824 //////////////////////////////////////////////////////////////////////////
1825 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1828 localoperation = true;
1829 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1830 SetWindowText(sWindowTitle);
1831 SetBackgroundImage(IDI_ADD_BKG);
1832 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1834 for(int i=0;i<m_targetPathList.GetCount();i++)
1836 CString cmd,out;
1837 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
1838 if(g_Git.Run(cmd,&out,CP_ACP))
1840 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1841 m_bErrorsOccurred=true;
1842 return false;
1844 Notify(m_targetPathList[i],git_wc_notify_add);
1846 #if 0
1847 if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))
1849 ReportSVNError();
1850 return false;
1852 #endif
1853 //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
1854 m_bErrorsOccurred=false;
1856 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
1857 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
1858 return true;
1861 bool CGitProgressDlg::CmdCheckout(CString& sWindowTitle, bool& /*localoperation*/)
1863 #if 0
1864 ASSERT(m_targetPathList.GetCount() == 1);
1865 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CHECKOUT);
1866 SetBackgroundImage(IDI_CHECKOUT_BKG);
1867 CTGitPathList urls;
1868 urls.LoadFromAsteriskSeparatedString(m_url.GetSVNPathString());
1869 CTGitPath checkoutdir = m_targetPathList[0];
1870 for (int i=0; i<urls.GetCount(); ++i)
1872 sWindowTitle = urls[i].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1873 SetWindowText(sWindowTitle);
1874 checkoutdir = m_targetPathList[0];
1875 if (urls.GetCount() > 1)
1877 CString fileordir = urls[i].GetFileOrDirectoryName();
1878 fileordir = CPathUtils::PathUnescape(fileordir);
1879 checkoutdir.AppendPathString(fileordir);
1881 CString sCmdInfo;
1882 sCmdInfo.Format(IDS_PROGRS_CMD_CHECKOUT,
1883 (LPCTSTR)urls[i].GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
1884 (LPCTSTR)SVNStatus::GetDepthString(m_depth),
1885 m_options & ProgOptIgnoreExternals ? (LPCTSTR)sExtExcluded : (LPCTSTR)sExtIncluded);
1886 ReportCmd(sCmdInfo);
1888 if (!Checkout(urls[i], checkoutdir, m_Revision, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1890 if (m_ProgList.GetItemCount()!=0)
1892 ReportSVNError();
1893 return false;
1895 // if the checkout fails with the peg revision set to the checkout revision,
1896 // try again with HEAD as the peg revision.
1897 else
1899 if (!Checkout(urls[i], checkoutdir, SVNRev::REV_HEAD, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))
1901 ReportSVNError();
1902 return false;
1907 #endif
1908 return true;
1911 bool CGitProgressDlg::CmdCommit(CString& sWindowTitle, bool& /*localoperation*/)
1913 #if 0
1914 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COMMIT);
1915 SetWindowText(sWindowTitle);
1916 SetBackgroundImage(IDI_COMMIT_BKG);
1917 if (m_targetPathList.GetCount()==0)
1919 SetWindowText(sWindowTitle);
1921 DialogEnableWindow(IDCANCEL, FALSE);
1922 DialogEnableWindow(IDOK, TRUE);
1924 InterlockedExchange(&m_bThreadRunning, FALSE);
1925 return true;
1927 if (m_targetPathList.GetCount()==1)
1929 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
1930 SetWindowText(sWindowTitle);
1932 BOOL isTag = FALSE;
1933 BOOL bURLFetched = FALSE;
1934 CString url;
1935 for (int i=0; i<m_targetPathList.GetCount(); ++i)
1937 if (bURLFetched == FALSE)
1939 url = GetURLFromPath(m_targetPathList[i]);
1940 if (!url.IsEmpty())
1941 bURLFetched = TRUE;
1942 CString urllower = url;
1943 urllower.MakeLower();
1944 // test if the commit goes to a tag.
1945 // now since Subversion doesn't force users to
1946 // create tags in the recommended /tags/ folder
1947 // only a warning is shown. This won't work if the tags
1948 // are stored in a non-recommended place, but the check
1949 // still helps those who do.
1950 if (urllower.Find(_T("/tags/"))>=0)
1951 isTag = TRUE;
1952 break;
1955 if (isTag)
1957 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_COMMITT_TRUNK, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)==IDNO)
1958 return false;
1960 DWORD exitcode = 0;
1961 CString error;
1962 if (CHooks::Instance().PreCommit(m_selectedPaths, m_depth, m_sMessage, exitcode, error))
1964 if (exitcode)
1966 CString temp;
1967 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1968 ReportError(temp);
1969 return false;
1973 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)));
1974 CStringArray changelists;
1975 if (!m_changelist.IsEmpty())
1976 changelists.Add(m_changelist);
1977 bool commitSuccessful = true;
1978 if (!Commit(m_targetPathList, m_sMessage, changelists, m_keepchangelist,
1979 m_depth, m_options & ProgOptKeeplocks))
1981 ReportSVNError();
1982 error = GetLastErrorMessage();
1983 // if a non-recursive commit failed with SVN_ERR_UNSUPPORTED_FEATURE,
1984 // that means a folder deletion couldn't be committed.
1985 if ((m_Revision != 0)&&(Err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
1987 ReportError(CString(MAKEINTRESOURCE(IDS_PROGRS_NONRECURSIVEHINT)));
1989 commitSuccessful = false;
1990 return false;
1992 if (!PostCommitErr.IsEmpty())
1994 ReportWarning(PostCommitErr);
1996 if (commitSuccessful)
1998 if (m_BugTraqProvider)
2000 CComPtr<IBugTraqProvider2> pProvider = NULL;
2001 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
2002 if (SUCCEEDED(hr))
2004 BSTR commonRoot = SysAllocString(m_targetPathList.GetCommonRoot().GetDirectory().GetWinPath());
2005 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_targetPathList.GetCount());
2007 for (LONG index = 0; index < m_targetPathList.GetCount(); ++index)
2008 SafeArrayPutElement(pathList, &index, m_targetPathList[index].GetSVNPathString().AllocSysString());
2010 BSTR logMessage = m_sMessage.AllocSysString();
2012 BSTR temp = NULL;
2013 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
2014 commonRoot,
2015 pathList,
2016 logMessage,
2017 (LONG)m_RevisionEnd,
2018 &temp)))
2020 CString sErr = temp;
2021 if (!sErr.IsEmpty())
2022 ReportError(temp);
2025 SysFreeString(temp);
2029 if (CHooks::Instance().PostCommit(m_selectedPaths, m_depth, m_RevisionEnd, m_sMessage, exitcode, error))
2031 if (exitcode)
2033 CString temp;
2034 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2035 ReportError(temp);
2036 return false;
2039 #endif
2040 return true;
2043 bool CGitProgressDlg::CmdCopy(CString& sWindowTitle, bool& /*localoperation*/)
2045 #if 0
2046 ASSERT(m_targetPathList.GetCount() == 1);
2047 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2048 SetWindowText(sWindowTitle);
2049 SetBackgroundImage(IDI_COPY_BKG);
2051 CString sCmdInfo;
2052 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2053 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2054 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2055 ReportCmd(sCmdInfo);
2057 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2059 ReportSVNError();
2060 return false;
2062 if (m_options & ProgOptSwitchAfterCopy)
2064 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2065 m_targetPathList[0].GetWinPath(),
2066 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2067 ReportCmd(sCmdInfo);
2068 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2070 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2072 ReportSVNError();
2073 return false;
2077 else
2079 if (SVN::PathIsURL(m_url))
2081 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2082 ReportNotification(sMsg);
2085 #endif
2086 return true;
2089 bool CGitProgressDlg::CmdExport(CString& sWindowTitle, bool& /*localoperation*/)
2091 #if 0
2092 ASSERT(m_targetPathList.GetCount() == 1);
2093 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2094 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2095 SetWindowText(sWindowTitle);
2096 SetBackgroundImage(IDI_EXPORT_BKG);
2097 CString eol;
2098 if (m_options & ProgOptEolCRLF)
2099 eol = _T("CRLF");
2100 if (m_options & ProgOptEolLF)
2101 eol = _T("LF");
2102 if (m_options & ProgOptEolCR)
2103 eol = _T("CR");
2104 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2105 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2107 ReportSVNError();
2108 return false;
2110 #endif
2111 return true;
2114 bool CGitProgressDlg::CmdImport(CString& sWindowTitle, bool& /*localoperation*/)
2116 #if 0
2117 ASSERT(m_targetPathList.GetCount() == 1);
2118 sWindowTitle.LoadString(IDS_PROGRS_TITLE_IMPORT);
2119 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2120 SetWindowText(sWindowTitle);
2121 SetBackgroundImage(IDI_IMPORT_BKG);
2122 CString sCmdInfo;
2123 sCmdInfo.Format(IDS_PROGRS_CMD_IMPORT,
2124 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2125 m_options & ProgOptIncludeIgnored ? (LPCTSTR)(_T(", ") + sIgnoredIncluded) : _T(""));
2126 ReportCmd(sCmdInfo);
2127 if (!Import(m_targetPathList[0], m_url, m_sMessage, &m_ProjectProperties, svn_depth_infinity, m_options & ProgOptIncludeIgnored ? true : false, false))
2129 ReportSVNError();
2130 return false;
2132 #endif
2133 return true;
2136 bool CGitProgressDlg::CmdLock(CString& sWindowTitle, bool& /*localoperation*/)
2138 #if 0
2139 sWindowTitle.LoadString(IDS_PROGRS_TITLE_LOCK);
2140 SetWindowText(sWindowTitle);
2141 SetBackgroundImage(IDI_LOCK_BKG);
2142 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_LOCK)));
2143 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2145 ReportSVNError();
2146 return false;
2148 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2149 if (m_bLockWarning)
2151 // the lock failed, because the file was outdated.
2152 // ask the user whether to update the file and try again
2153 if (CMessageBox::Show(m_hWnd, IDS_WARN_LOCKOUTDATED, IDS_APPNAME, MB_ICONQUESTION|MB_YESNO)==IDYES)
2155 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_UPDATEANDRETRY)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2156 if (!Update(m_targetPathList, SVNRev::REV_HEAD, svn_depth_files, false, true))
2158 ReportSVNError();
2159 return false;
2161 if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))
2163 ReportSVNError();
2164 return false;
2168 if (m_bLockExists)
2170 // the locking failed because there already is a lock.
2171 // if the locking-dialog is skipped in the settings, tell the
2172 // user how to steal the lock anyway (i.e., how to get the lock
2173 // dialog back without changing the settings)
2174 if (!DWORD(CRegDWORD(_T("Software\\TortoiseGit\\ShowLockDlg"), TRUE)))
2176 ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_LOCKHINT)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2178 return false;
2180 #endif
2181 return true;
2184 bool CGitProgressDlg::CmdMerge(CString& sWindowTitle, bool& /*localoperation*/)
2186 #if 0
2187 bool bFailed = false;
2188 ASSERT(m_targetPathList.GetCount() == 1);
2189 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2190 SetBackgroundImage(IDI_MERGE_BKG);
2191 if (m_options & ProgOptDryRun)
2193 sWindowTitle += _T(" ") + sDryRun;
2195 if (m_options & ProgOptRecordOnly)
2197 sWindowTitle += _T(" ") + sRecordOnly;
2199 SetWindowText(sWindowTitle);
2201 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_HIDE);
2202 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2203 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2204 if (DWORD(nonint))
2206 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2207 m_AlwaysConflicted = true;
2209 // we only accept a revision list to merge for peg merges
2210 ATLASSERT((m_revisionArray.GetCount()==0) || (m_revisionArray.GetCount() && (m_url.IsEquivalentTo(m_url2))));
2212 if (m_url.IsEquivalentTo(m_url2))
2214 CString sSuggestedMessage;
2215 CString sMergedLogMessage;
2216 CString sSeparator = CRegString(_T("Software\\TortoiseGit\\MergeLogSeparator"), _T("........"));
2217 CString temp;
2219 // Merging revisions %s of %s to %s into %s, %s%s
2220 CString sCmdInfo;
2221 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEPEG,
2222 (LPCTSTR)m_revisionArray.ToListString(),
2223 (LPCTSTR)m_url.GetSVNPathString(),
2224 m_targetPathList[0].GetWinPath(),
2225 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2226 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2227 ReportCmd(sCmdInfo);
2229 if (!PegMerge(m_url, m_revisionArray,
2230 m_pegRev.IsValid() ? m_pegRev : (m_url.IsUrl() ? SVNRev::REV_HEAD : SVNRev(SVNRev::REV_WC)),
2231 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2233 // if the merge fails with the peg revision set,
2234 // try again with HEAD as the peg revision.
2235 if (!PegMerge(m_url, m_revisionArray, SVNRev::REV_HEAD,
2236 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2238 ReportSVNError();
2239 bFailed = true;
2243 else
2245 CString sCmdInfo;
2246 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEURL,
2247 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString(),
2248 (LPCTSTR)m_url2.GetSVNPathString(), (LPCTSTR)m_RevisionEnd.ToString(),
2249 m_targetPathList[0].GetWinPath(),
2250 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,
2251 m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));
2252 ReportCmd(sCmdInfo);
2254 if (!Merge(m_url, m_Revision, m_url2, m_RevisionEnd, m_targetPathList[0],
2255 true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))
2257 ReportSVNError();
2258 bFailed = true;
2261 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2262 GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_SHOW);
2263 return !bFailed;
2264 #endif
2265 return true;
2268 bool CGitProgressDlg::CmdMergeAll(CString& sWindowTitle, bool& /*localoperation*/)
2270 #if 0
2271 ASSERT(m_targetPathList.GetCount() == 1);
2272 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);
2273 SetBackgroundImage(IDI_MERGE_BKG);
2274 SetWindowText(sWindowTitle);
2276 ATLASSERT(m_targetPathList.GetCount() == 1);
2278 CString sCmdInfo;
2279 sCmdInfo.LoadString(IDS_PROGRS_INFOGETTINGINFO);
2280 ReportCmd(sCmdInfo);
2281 CTGitPathList suggestedSources;
2282 if (!SuggestMergeSources(m_targetPathList[0], m_Revision, suggestedSources))
2284 ReportSVNError();
2285 return false;
2288 if (suggestedSources.GetCount() == 0)
2290 CString sErr;
2291 sErr.Format(IDS_PROGRS_MERGEALLNOSOURCES, m_targetPathList[0].GetWinPath());
2292 ReportError(sErr);
2293 return false;
2295 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEALL,
2296 (LPCTSTR)suggestedSources[0].GetSVNPathString(),
2297 m_targetPathList[0].GetWinPath(),
2298 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry);
2299 ReportCmd(sCmdInfo);
2301 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2302 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2303 if (DWORD(nonint))
2305 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2306 m_AlwaysConflicted = true;
2309 SVNRevRangeArray revarray;
2310 if (!PegMerge(suggestedSources[0], revarray,
2311 SVNRev::REV_HEAD,
2312 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), FALSE))
2314 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2315 ReportSVNError();
2316 return false;
2319 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2320 #endif
2321 return true;
2324 bool CGitProgressDlg::CmdMergeReintegrate(CString& sWindowTitle, bool& /*localoperation*/)
2326 #if 0
2327 ASSERT(m_targetPathList.GetCount() == 1);
2328 sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGEREINTEGRATE);
2329 SetBackgroundImage(IDI_MERGE_BKG);
2330 SetWindowText(sWindowTitle);
2332 CString sCmdInfo;
2333 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEREINTEGRATE,
2334 (LPCTSTR)m_url.GetSVNPathString(),
2335 m_targetPathList[0].GetWinPath());
2336 ReportCmd(sCmdInfo);
2338 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);
2339 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2340 if (DWORD(nonint))
2342 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
2343 m_AlwaysConflicted = true;
2346 if (!MergeReintegrate(m_url, SVNRev::REV_HEAD, m_targetPathList[0], !!(m_options & ProgOptDryRun), m_diffoptions))
2348 ReportSVNError();
2349 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2350 return false;
2353 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);
2354 #endif
2355 return true;
2358 bool CGitProgressDlg::CmdRename(CString& sWindowTitle, bool& localoperation)
2360 #if 0
2361 ASSERT(m_targetPathList.GetCount() == 1);
2362 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2363 localoperation = true;
2364 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2365 SetWindowText(sWindowTitle);
2366 SetBackgroundImage(IDI_RENAME_BKG);
2367 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2368 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2370 ReportSVNError();
2371 return false;
2373 #endif
2374 return true;
2377 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2380 localoperation = true;
2381 ASSERT(m_targetPathList.GetCount() == 1);
2382 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2383 SetWindowText(sWindowTitle);
2384 SetBackgroundImage(IDI_RESOLVE_BKG);
2385 // check if the file may still have conflict markers in it.
2386 //BOOL bMarkers = FALSE;
2388 for(int i=0;i<m_targetPathList.GetCount();i++)
2390 CString cmd,out,tempmergefile;
2391 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2392 if(g_Git.Run(cmd,&out,CP_ACP))
2394 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2395 m_bErrorsOccurred=true;
2396 return false;
2399 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2401 Notify(m_targetPathList[i],git_wc_notify_resolved);
2403 #if 0
2404 if ((m_options & ProgOptSkipConflictCheck) == 0)
2408 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2410 if (!m_targetPathList[fileindex].IsDirectory())
2412 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2413 CString strLine = _T("");
2414 while (file.ReadString(strLine))
2416 if (strLine.Find(_T("<<<<<<<"))==0)
2418 bMarkers = TRUE;
2419 break;
2422 file.Close();
2426 catch (CFileException* pE)
2428 TRACE(_T("CFileException in Resolve!\n"));
2429 TCHAR error[10000] = {0};
2430 pE->GetErrorMessage(error, 10000);
2431 ReportError(error);
2432 pE->Delete();
2433 return false;
2436 if (bMarkers)
2438 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2440 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2441 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2442 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2445 else
2447 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2448 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2449 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2451 #endif
2452 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2454 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2455 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
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;
2469 for(int i=0;i<m_selectedPaths.GetCount();i++)
2471 CTGitPath path;
2472 int action;
2473 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2474 action = m_selectedPaths[i].m_Action;
2475 /* rename file can't delete because it needs original file*/
2476 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2477 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2478 delList.AddPath(path);
2480 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2481 delList.DeleteAllFiles(true);
2483 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2484 for(int i=0;i<m_selectedPaths.GetCount();i++)
2486 if(g_Git.Revert((CTGitPath&)m_selectedPaths[i],true))
2488 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2489 m_bErrorsOccurred=true;
2490 return false;
2492 Notify(m_selectedPaths[i],git_wc_notify_revert);
2495 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2497 return true;
2500 bool CGitProgressDlg::CmdSwitch(CString& sWindowTitle, bool& /*localoperation*/)
2502 #if 0
2503 ASSERT(m_targetPathList.GetCount() == 1);
2504 SVNStatus st;
2505 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2506 SetWindowText(sWindowTitle);
2507 SetBackgroundImage(IDI_SWITCH_BKG);
2508 LONG rev = 0;
2509 if (st.GetStatus(m_targetPathList[0]) != (-2))
2511 if (st.status->entry != NULL)
2513 rev = st.status->entry->revision;
2517 CString sCmdInfo;
2518 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2519 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2520 (LPCTSTR)m_Revision.ToString());
2521 ReportCmd(sCmdInfo);
2523 bool depthIsSticky = true;
2524 if (m_depth == svn_depth_unknown)
2525 depthIsSticky = false;
2526 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2528 ReportSVNError();
2529 return false;
2531 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2532 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2533 &&((LONG)m_RevisionEnd > (LONG)rev))
2535 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2537 #endif
2538 return true;
2541 bool CGitProgressDlg::CmdUnlock(CString& sWindowTitle, bool& /*localoperation*/)
2543 #if 0
2544 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UNLOCK);
2545 SetWindowText(sWindowTitle);
2546 SetBackgroundImage(IDI_UNLOCK_BKG);
2547 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UNLOCK)));
2548 if (!Unlock(m_targetPathList, m_options & ProgOptLockForce))
2550 ReportSVNError();
2551 return false;
2553 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2554 #endif
2555 return true;
2558 bool CGitProgressDlg::CmdUpdate(CString& sWindowTitle, bool& /*localoperation*/)
2560 #if 0
2561 sWindowTitle.LoadString(IDS_PROGRS_TITLE_UPDATE);
2562 SetWindowText(sWindowTitle);
2563 SetBackgroundImage(IDI_UPDATE_BKG);
2565 int targetcount = m_targetPathList.GetCount();
2566 CString sfile;
2567 CStringA uuid;
2568 StringRevMap uuidmap;
2569 SVNRev revstore = m_Revision;
2570 int nUUIDs = 0;
2571 for(int nItem = 0; nItem < targetcount; nItem++)
2573 const CTGitPath& targetPath = m_targetPathList[nItem];
2574 SVNStatus st;
2575 LONG headrev = -1;
2576 m_Revision = revstore;
2577 if (m_Revision.IsHead())
2579 if ((targetcount > 1)&&((headrev = st.GetStatus(targetPath, true)) != (-2)))
2581 if (st.status->entry != NULL)
2584 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2585 if (st.status->entry->uuid)
2587 uuid = st.status->entry->uuid;
2588 StringRevMap::iterator iter = uuidmap.lower_bound(uuid);
2589 if (iter == uuidmap.end() || iter->first != uuid)
2591 uuidmap.insert(iter, std::make_pair(uuid, headrev));
2592 nUUIDs++;
2594 else
2595 headrev = iter->second;
2596 m_Revision = headrev;
2598 else
2599 m_Revision = headrev;
2602 else
2604 if ((headrev = st.GetStatus(targetPath, FALSE)) != (-2))
2606 if (st.status->entry != NULL)
2607 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;
2610 if (uuidmap.size() > 1)
2611 m_Revision = SVNRev::REV_HEAD;
2612 } // if (m_Revision.IsHead())
2613 } // for(int nItem = 0; nItem < targetcount; nItem++)
2614 sWindowTitle = m_targetPathList.GetCommonRoot().GetWinPathString()+_T(" - ")+sWindowTitle;
2615 SetWindowText(sWindowTitle);
2617 DWORD exitcode = 0;
2618 CString error;
2619 if (CHooks::Instance().PreUpdate(m_targetPathList, m_depth, nUUIDs > 1 ? revstore : m_Revision, exitcode, error))
2621 if (exitcode)
2623 CString temp;
2624 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2625 ReportError(temp);
2626 return false;
2629 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UPDATE)));
2630 if (nUUIDs > 1)
2632 // the selected items are from different repositories,
2633 // so we have to update them separately
2634 for(int nItem = 0; nItem < targetcount; nItem++)
2636 const CTGitPath& targetPath = m_targetPathList[nItem];
2637 m_basePath = targetPath;
2638 CString sNotify;
2639 sNotify.Format(IDS_PROGRS_UPDATEPATH, m_basePath.GetWinPath());
2640 ReportString(sNotify, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
2641 if (!Update(CTGitPathList(targetPath), revstore, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2643 ReportSVNError();
2644 return false;
2648 else
2650 // if we have only one target path, but that target path does not exist,
2651 // we have to check whether at least the parent path exists. If not,
2652 // then we have to update all paths in between the first path that exists and the
2653 // parent path of the one we want to update
2654 // This is required so a user can create a sparse checkout without having
2655 // to update all intermediate folders manually
2656 if ((m_targetPathList.GetCount() == 1) && (!m_targetPathList[0].Exists()))
2658 CTGitPath wcPath = m_targetPathList[0].GetContainingDirectory();
2659 CTGitPath existingParentPath = wcPath.GetContainingDirectory();
2660 while (!existingParentPath.Exists() && (existingParentPath.GetWinPathString().GetLength() > 2))
2662 existingParentPath = existingParentPath.GetContainingDirectory();
2664 if (existingParentPath.GetWinPathString().GetLength() && !existingParentPath.IsEquivalentTo(wcPath))
2666 // update all intermediate directories with depth 'empty'
2667 CTGitPath intermediatepath = existingParentPath;
2668 bool bSuccess = true;
2669 while (bSuccess && intermediatepath.IsAncestorOf(wcPath) && !intermediatepath.IsEquivalentTo(wcPath))
2671 CString childname = wcPath.GetWinPathString().Mid(intermediatepath.GetWinPathString().GetLength(),
2672 wcPath.GetWinPathString().Find('\\', intermediatepath.GetWinPathString().GetLength()+1)-intermediatepath.GetWinPathString().GetLength());
2673 if (childname.IsEmpty())
2674 intermediatepath = wcPath;
2675 else
2676 intermediatepath.AppendPathString(childname);
2677 bSuccess = !!Update(CTGitPathList(intermediatepath), m_Revision, svn_depth_empty, false, true);
2680 if (!bSuccess)
2682 ReportSVNError();
2683 return false;
2687 if (!Update(m_targetPathList, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2689 ReportSVNError();
2690 return false;
2693 if (CHooks::Instance().PostUpdate(m_targetPathList, m_depth, m_RevisionEnd, exitcode, error))
2695 if (exitcode)
2697 CString temp;
2698 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2699 ReportError(temp);
2700 return false;
2704 // after an update, show the user the log button, but only if only one single item was updated
2705 // (either a file or a directory)
2706 if ((m_targetPathList.GetCount() == 1)&&(m_UpdateStartRevMap.size()>0))
2707 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2708 #endif
2709 return true;
2712 void CGitProgressDlg::OnBnClickedNoninteractive()
2714 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2715 m_AlwaysConflicted = (res == BST_CHECKED);
2716 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2717 nonint = m_AlwaysConflicted;
2720 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2722 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2723 if (sPath.Find(':')<0)
2725 // the path is not absolute: add the common root of all paths to it
2726 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2728 return sPath;
2731 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2733 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2734 SetWindowText(sWindowTitle);
2735 //SetBackgroundImage(IDI_ADD_BKG);
2736 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2737 bool ret=true;
2738 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2740 CString error;
2741 CTGitPath path;
2742 Notify(path,git_wc_notify_sendmail_start);
2743 CString err;
2744 int retry=0;
2745 while(retry <3)
2747 if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,this->m_SendMailFlags&SENDMAIL_MAPI,&err))
2749 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2750 ret = false;
2752 else
2754 break;
2757 retry++;
2758 if (retry < 3)
2759 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2760 Sleep(2000);
2761 if(m_bCancelled)
2763 Notify(path,git_wc_notify_sendmail_error,ret,&CString("User Canceled"));
2764 return false;
2767 if (ret)
2768 Notify(path,git_wc_notify_sendmail_done,ret);
2770 else
2772 for(int i=0;ret && i<m_targetPathList.GetCount();i++)
2774 CPatch patch;
2775 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2777 int retry=0;
2778 while(retry<3)
2780 if(patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2781 this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,this->m_SendMailFlags&SENDMAIL_MAPI))
2783 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2784 ret = false;
2786 }else
2788 break;
2790 retry++;
2791 if (retry < 3)
2792 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2793 Sleep(2000);
2794 if(m_bCancelled)
2796 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&CString("User Canceled"));
2797 return false;
2800 if (ret)
2801 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2804 return ret;