1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "GitProgressList.h"
22 #include "TortoiseProc.h"
23 #include "MessageBox.h"
24 #include "GitProgressDlg.h"
28 #include "GitStatus.h"
30 #include "PathUtils.h"
31 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
34 #include "SoundUtils.h"
37 #include "DropFiles.h"
38 //#include "GitLogHelper.h"
39 #include "RegHistory.h"
41 #include "ShellUpdater.h"
43 #include "BugTraqAssociations.h"
45 #include "MassiveGitTask.h"
46 #include "SmartHandle.h"
47 #include "LoglistUtils.h"
49 BOOL
CGitProgressList::m_bAscending
= FALSE
;
50 int CGitProgressList::m_nSortedColumn
= -1;
52 #define TRANSFERTIMER 100
53 #define VISIBLETIMER 101
56 enum GITProgressDlgContextMenuCommands
58 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
71 IMPLEMENT_DYNAMIC(CGitProgressList
, CListCtrl
)
75 CAnimateCtrl
* m_pAnimate
;
78 CSmartAnimation(CAnimateCtrl
* pAnimate
)
80 m_pAnimate
= pAnimate
;
83 m_pAnimate
->ShowWindow(SW_SHOW
);
84 m_pAnimate
->Play(0, INT_MAX
, INT_MAX
);
92 m_pAnimate
->ShowWindow(SW_HIDE
);
97 CGitProgressList::CGitProgressList():CListCtrl()
100 , m_bErrorsOccurred(false)
102 , m_bNoCheckout(false)
103 , m_AutoTag(GIT_REMOTE_DOWNLOAD_TAGS_AUTO
)
105 , m_options(ProgOptNone
)
107 , m_pTaskbarList(nullptr)
108 , m_SendMail(nullptr)
109 , m_Command(GitProgress_none
)
110 , m_AlwaysConflicted(false)
111 , m_bThreadRunning(FALSE
)
112 , m_keepchangelist(false)
114 , m_bMergesAddsDeletesOccurred(FALSE
)
116 , bSecondResized(false)
117 , nEnsureVisibleCount(0)
118 , m_TotalBytesTransferred(0)
119 , m_bFinishedItemAdded(false)
120 , m_bLastVisible(false)
122 , m_itemCountTotal(-1)
124 m_pInfoCtrl
= nullptr;
125 m_pAnimate
= nullptr;
126 m_pProgControl
= nullptr;
127 m_pProgressLabelCtrl
= nullptr;
128 m_pPostWnd
= nullptr;
132 CGitProgressList::~CGitProgressList()
134 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
138 if(m_pThread
!= NULL
)
145 BEGIN_MESSAGE_MAP(CGitProgressList
, CListCtrl
)
146 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawSvnprogress
)
147 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkSvnprogress
)
148 ON_NOTIFY_REFLECT(HDN_ITEMCLICK
, OnHdnItemclickSvnprogress
)
149 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnLvnBegindragSvnprogress
)
150 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoSvnprogress
)
151 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER
, OnShowConflictResolver
)
158 void CGitProgressList::Cancel()
165 // CGitProgressList message handlers
168 LRESULT
CGitProgressList::OnShowConflictResolver(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
171 CConflictResolveDlg
dlg(this);
172 const svn_wc_conflict_description_t
*description
= (svn_wc_conflict_description_t
*)lParam
;
175 dlg
.SetConflictDescription(description
);
178 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
180 if (dlg
.DoModal() == IDOK
)
182 if (dlg
.GetResult() == svn_wc_conflict_choose_postpone
)
184 // if the result is conflicted and the dialog returned IDOK,
185 // that means we should not ask again in case of a conflict
186 m_AlwaysConflicted
= true;
187 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE
)->GetSafeHwnd(), BM_SETCHECK
, BST_CHECKED
, 0);
190 m_mergedfile
= dlg
.GetMergedFile();
191 m_bCancelled
= dlg
.IsCancelled();
193 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
194 return dlg
.GetResult();
197 return svn_wc_conflict_choose_postpone
;
202 svn_wc_conflict_choice_t
CGitProgressList::ConflictResolveCallback(const svn_wc_conflict_description_t
*description
, CString
& mergedfile
)
204 // we only bother the user when merging
205 if (((m_Command
== GitProgress_Merge
)||(m_Command
== GitProgress_MergeAll
)||(m_Command
== GitProgress_MergeReintegrate
))&&(!m_AlwaysConflicted
)&&(description
))
207 // we're in a worker thread here. That means we must not show a dialog from the thread
208 // but let the UI thread do it.
209 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
210 LRESULT dlgResult
= ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER
, 0, (LPARAM
)description
);
211 mergedfile
= m_mergedfile
;
212 return (svn_wc_conflict_choice_t
)dlgResult
;
215 return svn_wc_conflict_choose_postpone
;
218 void CGitProgressList::AddItemToList()
220 int totalcount
= GetItemCount();
222 SetItemCountEx(totalcount
+1, LVSICF_NOSCROLL
|LVSICF_NOINVALIDATEALL
);
223 // make columns width fit
224 if (iFirstResized
< 30)
226 // only resize the columns for the first 30 or so entries.
227 // after that, don't resize them anymore because that's an
228 // expensive function call and the columns will be sized
229 // close enough already.
234 // Make sure the item is *entirely* visible even if the horizontal
235 // scroll bar is visible.
236 int count
= GetCountPerPage();
237 if (totalcount
<= (GetTopIndex() + count
+ nEnsureVisibleCount
+ 2))
239 ++nEnsureVisibleCount
;
240 m_bLastVisible
= true;
244 nEnsureVisibleCount
= 0;
246 m_bLastVisible
= false;
251 BOOL
CGitProgressList::Notify(const CTGitPath
& path
, git_wc_notify_action_t action
253 svn_node_kind_t kind, const CString& mime_type,
254 svn_wc_notify_state_t content_state,
255 svn_wc_notify_state_t prop_state, LONG rev,
256 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
257 const CString& changelistname,
258 svn_merge_range_t * range,
259 svn_error_t * err, apr_pool_t * pool
262 bool bNoNotify
= false;
263 bool bDoAddData
= true;
264 NotificationData
* data
= new NotificationData();
266 data
->action
= action
;
267 data
->sPathColumnText
=path
.GetGitPathString();
268 data
->bAuxItem
= false;
270 if (this->m_pAnimate
)
271 this->m_pAnimate
->ShowWindow(SW_HIDE
);
275 data
->mime_type
= mime_type
;
276 data
->content_state
= content_state
;
277 data
->prop_state
= prop_state
;
279 data
->lock_state
= lock_state
;
280 data
->changelistname
= changelistname
;
281 if ((lock
)&&(lock
->owner
))
282 data
->owner
= CUnicodeUtils::GetUnicode(lock
->owner
);
283 data
->sPathColumnText
= path
.GetUIPathString();
284 if (!m_basePath
.IsEmpty())
285 data
->basepath
= m_basePath
;
287 data
->merge_range
= *range
;
289 switch (data
->action
)
291 case git_wc_notify_add
:
292 //case svn_wc_notify_update_add:
293 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
295 // data->color = m_Colors.GetColor(CColors::Conflict);
296 // data->bConflictedActionItem = true;
297 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
302 // m_bMergesAddsDeletesOccurred = true;
303 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADD
);
304 data
->color
= m_Colors
.GetColor(CColors::Added
);
307 case git_wc_notify_sendmail
:
308 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_START
);
309 data
->color
= m_Colors
.GetColor(CColors::Modified
);
312 case git_wc_notify_resolved
:
313 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
316 case git_wc_notify_revert
:
317 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REVERT
);
320 case git_wc_notify_checkout
:
321 data
->sActionColumnText
.LoadString(IDS_PROGRS_CMD_CHECKOUT
);
322 data
->color
= m_Colors
.GetColor(CColors::Added
);
323 data
->bAuxItem
= false;
327 case svn_wc_notify_commit_added
:
328 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADDING
);
329 data
->color
= m_Colors
.GetColor(CColors::Added
);
331 case svn_wc_notify_copy
:
332 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COPY
);
334 case svn_wc_notify_commit_modified
:
335 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MODIFIED
);
336 data
->color
= m_Colors
.GetColor(CColors::Modified
);
338 case svn_wc_notify_delete
:
339 case svn_wc_notify_update_delete
:
340 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETE
);
341 m_bMergesAddsDeletesOccurred
= true;
342 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
344 case svn_wc_notify_commit_deleted
:
345 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETING
);
346 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
348 case svn_wc_notify_restore
:
349 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESTORE
);
352 case svn_wc_notify_update_replace
:
353 case svn_wc_notify_commit_replaced
:
354 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REPLACED
);
355 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
357 case svn_wc_notify_exists
:
358 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
360 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
361 data
->bConflictedActionItem
= true;
363 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
365 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
367 data
->color
= m_Colors
.GetColor(CColors::Merged
);
368 m_bMergesAddsDeletesOccurred
= true;
369 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
372 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXISTS
);
374 case svn_wc_notify_update_update
:
375 // if this is an inoperative dir change, don't show the notification.
376 // an inoperative dir change is when a directory gets updated without
377 // any real change in either text or properties.
378 if ((kind
== svn_node_dir
)
379 && ((prop_state
== svn_wc_notify_state_inapplicable
)
380 || (prop_state
== svn_wc_notify_state_unknown
)
381 || (prop_state
== svn_wc_notify_state_unchanged
)))
386 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
388 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
389 data
->bConflictedActionItem
= true;
391 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
393 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
395 data
->color
= m_Colors
.GetColor(CColors::Merged
);
396 m_bMergesAddsDeletesOccurred
= true;
397 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
399 else if (((data
->content_state
!= svn_wc_notify_state_unchanged
)&&(data
->content_state
!= svn_wc_notify_state_unknown
)) ||
400 ((data
->prop_state
!= svn_wc_notify_state_unchanged
)&&(data
->prop_state
!= svn_wc_notify_state_unknown
)))
402 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UPDATE
);
409 if (lock_state
== svn_wc_notify_lock_state_unlocked
)
411 CString
temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED
));
412 data
->sActionColumnText
+= _T(", ") + temp
;
416 case svn_wc_notify_update_external
:
417 // For some reason we build a list of externals...
418 m_ExtStack
.AddHead(path
.GetUIPathString());
419 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXTERNAL
);
420 data
->bAuxItem
= true;
423 case svn_wc_notify_update_completed
:
425 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COMPLETED
);
426 data
->bAuxItem
= true;
427 bool bEmpty
= !!m_ExtStack
.IsEmpty();
429 data
->sPathColumnText
.Format(IDS_PROGRS_PATHATREV
, (LPCTSTR
)m_ExtStack
.RemoveHead(), rev
);
431 data
->sPathColumnText
.Format(IDS_PROGRS_ATREV
, rev
);
433 if ((m_nConflicts
>0)&&(bEmpty
))
435 // We're going to add another aux item - let's shove this current onto the list first
436 // I don't really like this, but it will do for the moment.
437 m_arData
.push_back(data
);
440 data
= new NotificationData();
441 data
->bAuxItem
= true;
442 data
->sActionColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING
);
443 data
->sPathColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED
);
444 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
445 CSoundUtils::PlayTSVNWarning();
446 // This item will now be added after the switch statement
448 if (!m_basePath
.IsEmpty())
449 m_FinishedRevMap
[m_basePath
.GetSVNApiPath(pool
)] = rev
;
451 m_bFinishedItemAdded
= true;
454 case svn_wc_notify_commit_postfix_txdelta
:
455 data
->sActionColumnText
.LoadString(IDS_SVNACTION_POSTFIX
);
457 case svn_wc_notify_failed_revert
:
458 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
460 case svn_wc_notify_status_completed
:
461 case svn_wc_notify_status_external
:
462 data
->sActionColumnText
.LoadString(IDS_SVNACTION_STATUS
);
464 case svn_wc_notify_skip
:
465 if ((content_state
== svn_wc_notify_state_missing
)||(content_state
== svn_wc_notify_state_obstructed
)||(content_state
== svn_wc_notify_state_conflicted
))
467 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIPMISSING
);
469 // The color settings dialog describes the red color with
470 // "possible or real conflict / obstructed" which also applies to
471 // skipped targets during a merge. So we just use the same color.
472 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
475 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIP
);
477 case svn_wc_notify_locked
:
478 if ((lock
)&&(lock
->owner
))
479 data
->sActionColumnText
.Format(IDS_SVNACTION_LOCKEDBY
, (LPCTSTR
)CUnicodeUtils::GetUnicode(lock
->owner
));
481 case svn_wc_notify_unlocked
:
482 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UNLOCKED
);
484 case svn_wc_notify_failed_lock
:
485 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDLOCK
);
486 m_arData
.push_back(data
);
488 ReportError(SVN::GetErrorString(err
));
490 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
491 m_bLockWarning
= true;
492 if (err
->apr_err
== SVN_ERR_FS_PATH_ALREADY_LOCKED
)
493 m_bLockExists
= true;
495 case svn_wc_notify_failed_unlock
:
496 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDUNLOCK
);
497 m_arData
.push_back(data
);
499 ReportError(SVN::GetErrorString(err
));
501 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
502 m_bLockWarning
= true;
504 case svn_wc_notify_changelist_set
:
505 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTSET
, (LPCTSTR
)data
->changelistname
);
507 case svn_wc_notify_changelist_clear
:
508 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CHANGELISTCLEAR
);
510 case svn_wc_notify_changelist_moved
:
511 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTMOVED
, (LPCTSTR
)data
->changelistname
);
513 case svn_wc_notify_foreign_merge_begin
:
514 case svn_wc_notify_merge_begin
:
516 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGEBEGINNONE
);
517 else if ((data
->merge_range
.start
== data
->merge_range
.end
) || (data
->merge_range
.start
== data
->merge_range
.end
- 1))
518 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLE
, data
->merge_range
.end
);
519 else if (data
->merge_range
.start
- 1 == data
->merge_range
.end
)
520 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE
, data
->merge_range
.start
);
521 else if (data
->merge_range
.start
< data
->merge_range
.end
)
522 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE
, data
->merge_range
.start
+ 1, data
->merge_range
.end
);
524 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE
, data
->merge_range
.start
, data
->merge_range
.end
+ 1);
525 data
->bAuxItem
= true;
530 } // switch (data->action)
538 m_arData
.push_back(data
);
540 if ((!data
->bAuxItem
) && (m_itemCount
> 0))
544 m_pProgControl
->ShowWindow(SW_SHOW
);
545 m_pProgControl
->SetPos(m_itemCount
);
546 m_pProgControl
->SetRange32(0, m_itemCountTotal
);
548 if (m_pTaskbarList
&& m_pPostWnd
)
550 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NORMAL
);
551 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), m_itemCount
, m_itemCountTotal
);
555 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
558 // bSecondResized = TRUE;
566 CString
CGitProgressList::BuildInfoString()
569 if(this->m_Command
== GitProgress_Resolve
)
570 infotext
= _T("You need commit your change after resolve conflict");
587 for (size_t i
=0; i
<m_arData
.size(); ++i
)
589 const NotificationData
* dat
= m_arData
[i
];
592 case svn_wc_notify_add
:
593 case svn_wc_notify_update_add
:
594 case svn_wc_notify_commit_added
:
595 if (dat
->bConflictedActionItem
)
600 case svn_wc_notify_copy
:
603 case svn_wc_notify_delete
:
604 case svn_wc_notify_update_delete
:
605 case svn_wc_notify_commit_deleted
:
608 case svn_wc_notify_restore
:
611 case svn_wc_notify_revert
:
614 case svn_wc_notify_resolved
:
617 case svn_wc_notify_update_update
:
618 if (dat
->bConflictedActionItem
)
620 else if ((dat
->content_state
== svn_wc_notify_state_merged
) || (dat
->prop_state
== svn_wc_notify_state_merged
))
625 case svn_wc_notify_commit_modified
:
628 case svn_wc_notify_skip
:
631 case svn_wc_notify_commit_replaced
:
638 temp
.LoadString(IDS_SVNACTION_CONFLICTED
);
640 temp
.Format(_T(":%d "), conflicted
);
645 temp
.LoadString(IDS_SVNACTION_SKIP
);
647 infotext
.AppendFormat(_T(":%d "), skipped
);
651 temp
.LoadString(IDS_SVNACTION_MERGED
);
653 infotext
.AppendFormat(_T(":%d "), merged
);
657 temp
.LoadString(IDS_SVNACTION_ADD
);
659 infotext
.AppendFormat(_T(":%d "), added
);
663 temp
.LoadString(IDS_SVNACTION_DELETE
);
665 infotext
.AppendFormat(_T(":%d "), deleted
);
669 temp
.LoadString(IDS_SVNACTION_MODIFIED
);
671 infotext
.AppendFormat(_T(":%d "), modified
);
675 temp
.LoadString(IDS_SVNACTION_COPY
);
677 infotext
.AppendFormat(_T(":%d "), copied
);
681 temp
.LoadString(IDS_SVNACTION_REPLACED
);
683 infotext
.AppendFormat(_T(":%d "), replaced
);
687 temp
.LoadString(IDS_SVNACTION_UPDATE
);
689 infotext
.AppendFormat(_T(":%d "), updated
);
693 temp
.LoadString(IDS_SVNACTION_RESTORE
);
695 infotext
.AppendFormat(_T(":%d "), restored
);
699 temp
.LoadString(IDS_SVNACTION_REVERT
);
701 infotext
.AppendFormat(_T(":%d "), reverted
);
705 temp
.LoadString(IDS_SVNACTION_RESOLVE
);
707 infotext
.AppendFormat(_T(":%d "), resolved
);
713 void CGitProgressList::SetSelectedList(const CTGitPathList
& selPaths
)
715 m_selectedPaths
= selPaths
;
718 void CGitProgressList::ResizeColumns()
722 TCHAR textbuf
[MAX_PATH
] = {0};
724 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
727 int maxcol
= pHeaderCtrl
->GetItemCount()-1;
728 for (int col
= 0; col
<= maxcol
; ++col
)
730 // find the longest width of all items
731 int count
= GetItemCount();
734 hdi
.pszText
= textbuf
;
735 hdi
.cchTextMax
= _countof(textbuf
);
736 pHeaderCtrl
->GetItem(col
, &hdi
);
737 int cx
= GetStringWidth(hdi
.pszText
)+20; // 20 pixels for col separator and margin
739 for (int index
= 0; index
<count
; ++index
)
741 // get the width of the string and add 12 pixels for the column separator and margins
746 linewidth
= GetStringWidth(m_arData
[index
]->sActionColumnText
) + 12;
749 linewidth
= GetStringWidth(m_arData
[index
]->sPathColumnText
) + 12;
755 SetColumnWidth(col
, cx
);
762 bool CGitProgressList::SetBackgroundImage(UINT nID
)
764 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
767 void CGitProgressList::ReportGitError()
769 ReportError(CGit::GetLibGit2LastErr());
772 void CGitProgressList::ReportUserCanceled()
774 ReportError(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
)));
777 void CGitProgressList::ReportError(const CString
& sError
)
779 CSoundUtils::PlayTGitError();
780 ReportString(sError
, CString(MAKEINTRESOURCE(IDS_ERR_ERROR
)), m_Colors
.GetColor(CColors::Conflict
));
781 m_bErrorsOccurred
= true;
784 void CGitProgressList::ReportWarning(const CString
& sWarning
)
786 CSoundUtils::PlayTGitWarning();
787 ReportString(sWarning
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)), m_Colors
.GetColor(CColors::Conflict
));
790 void CGitProgressList::ReportNotification(const CString
& sNotification
)
792 CSoundUtils::PlayTGitNotification();
793 ReportString(sNotification
, CString(MAKEINTRESOURCE(IDS_WARN_NOTE
)));
796 void CGitProgressList::ReportCmd(const CString
& sCmd
)
798 ReportString(sCmd
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO
)), m_Colors
.GetColor(CColors::Cmd
));
801 void CGitProgressList::ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
)
803 // instead of showing a dialog box with the error message or notification,
804 // just insert the error text into the list control.
805 // that way the user isn't 'interrupted' by a dialog box popping up!
807 // the message may be split up into different lines
808 // so add a new entry for each line of the message
809 while (!sMessage
.IsEmpty())
811 NotificationData
* data
= new NotificationData();
812 data
->bAuxItem
= true;
813 data
->sActionColumnText
= sMsgKind
;
814 if (sMessage
.Find('\n')>=0)
815 data
->sPathColumnText
= sMessage
.Left(sMessage
.Find('\n'));
817 data
->sPathColumnText
= sMessage
;
818 data
->sPathColumnText
.Trim(_T("\n\r"));
820 if (sMessage
.Find('\n')>=0)
822 sMessage
= sMessage
.Mid(sMessage
.Find('\n'));
823 sMessage
.Trim(_T("\n\r"));
827 m_arData
.push_back(data
);
832 UINT
CGitProgressList::ProgressThreadEntry(LPVOID pVoid
)
834 return ((CGitProgressList
*)pVoid
)->ProgressThread();
837 UINT
CGitProgressList::ProgressThread()
839 // The SetParams function should have loaded something for us
842 CString sWindowTitle
;
843 bool localoperation
= false;
844 bool bSuccess
= false;
845 m_AlwaysConflicted
= false;
848 m_pPostWnd
->PostMessage(WM_PROG_CMD_START
, m_Command
);
850 if(m_pProgressLabelCtrl
)
852 m_pProgressLabelCtrl
->ShowWindow(SW_SHOW
);
853 m_pProgressLabelCtrl
->SetWindowText(_T(""));
856 // SetAndClearProgressInfo(m_hWnd);
857 m_itemCount
= m_itemCountTotal
;
859 InterlockedExchange(&m_bThreadRunning
, TRUE
);
861 bSecondResized
= FALSE
;
862 m_bFinishedItemAdded
= false;
863 DWORD startTime
= GetCurrentTime();
865 if (m_pTaskbarList
&& m_pPostWnd
)
866 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_INDETERMINATE
);
870 case GitProgress_Add
:
871 bSuccess
= CmdAdd(sWindowTitle
, localoperation
);
873 case GitProgress_Copy
:
874 bSuccess
= CmdCopy(sWindowTitle
, localoperation
);
876 case GitProgress_Export
:
877 bSuccess
= CmdExport(sWindowTitle
, localoperation
);
879 case GitProgress_Rename
:
880 bSuccess
= CmdRename(sWindowTitle
, localoperation
);
882 case GitProgress_Resolve
:
883 bSuccess
= CmdResolve(sWindowTitle
, localoperation
);
885 case GitProgress_Revert
:
886 bSuccess
= CmdRevert(sWindowTitle
, localoperation
);
888 case GitProgress_Switch
:
889 bSuccess
= CmdSwitch(sWindowTitle
, localoperation
);
891 case GitProgress_SendMail
:
892 bSuccess
= CmdSendMail(sWindowTitle
, localoperation
);
894 case GitProgress_Clone
:
895 bSuccess
= CmdClone(sWindowTitle
, localoperation
);
897 case GitProgress_Fetch
:
898 bSuccess
= CmdFetch(sWindowTitle
, localoperation
);
900 case GitProgress_Reset
:
901 bSuccess
= CmdReset(sWindowTitle
, localoperation
);
905 temp
.LoadString(IDS_PROGRS_TITLEFAILED
);
907 temp
.LoadString(IDS_PROGRS_TITLEFIN
);
908 sWindowTitle
= sWindowTitle
+ _T(" ") + temp
;
909 if (m_bSetTitle
&& m_pPostWnd
)
910 ::SetWindowText(m_pPostWnd
->GetSafeHwnd(), sWindowTitle
);
912 KillTimer(TRANSFERTIMER
);
913 KillTimer(VISIBLETIMER
);
915 if (m_pTaskbarList
&& m_pPostWnd
)
917 if (DidErrorsOccur())
919 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_ERROR
);
920 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), 100, 100);
923 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NOPROGRESS
);
926 CString info
= BuildInfoString();
928 info
.LoadString(IDS_PROGRS_INFOFAILED
);
930 m_pInfoCtrl
->SetWindowText(info
);
934 DWORD time
= GetCurrentTime() - startTime
;
937 if (!m_sTotalBytesTransferred
.IsEmpty())
939 temp
.Format(IDS_PROGRS_TIME
, (time
/ 1000) / 60, (time
/ 1000) % 60);
940 sFinalInfo
.Format(IDS_PROGRS_FINALINFO
, m_sTotalBytesTransferred
, (LPCTSTR
)temp
);
941 if (m_pProgressLabelCtrl
)
942 m_pProgressLabelCtrl
->SetWindowText(sFinalInfo
);
946 if (m_pProgressLabelCtrl
)
947 m_pProgressLabelCtrl
->ShowWindow(SW_HIDE
);
951 m_pProgControl
->ShowWindow(SW_HIDE
);
953 if (!m_bFinishedItemAdded
)
957 str
.LoadString(IDS_SUCCESS
);
959 str
.LoadString(IDS_FAIL
);
960 log
.Format(_T("%s (%lu ms @ %s)"), str
, time
, CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false));
962 // there's no "finished: xxx" line at the end. We add one here to make
963 // sure the user sees that the command is actually finished.
964 ReportString(log
, CString(MAKEINTRESOURCE(IDS_PROGRS_FINISHED
)), bSuccess
? RGB(0,0,255) : RGB(255,0,0));
967 int count
= GetItemCount();
968 if ((count
> 0)&&(m_bLastVisible
))
969 EnsureVisible(count
-1, FALSE
);
971 CLogFile
logfile(g_Git
.m_CurrentDir
);
974 logfile
.AddTimeLine();
975 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
977 NotificationData
* data
= m_arData
[i
];
978 temp
.Format(_T("%-20s : %s"), (LPCTSTR
)data
->sActionColumnText
, (LPCTSTR
)data
->sPathColumnText
);
979 logfile
.AddLine(temp
);
981 if (!sFinalInfo
.IsEmpty())
982 logfile
.AddLine(sFinalInfo
);
987 InterlockedExchange(&m_bThreadRunning
, FALSE
);
993 m_pPostWnd
->PostMessage(WM_PROG_CMD_FINISH
, this->m_Command
, 0L);
996 DWORD dwAutoClose
= CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL
);
997 if (m_options
& ProgOptDryRun
)
998 dwAutoClose
= 0; // dry run means progress dialog doesn't auto close at all
1001 if (m_dwCloseOnEnd
!= (DWORD
)-1)
1002 dwAutoClose
= m_dwCloseOnEnd
; // command line value has priority over setting value
1003 if ((dwAutoClose
== CLOSE_NOERRORS
)&&(!m_bErrorsOccurred
))
1004 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1005 if ((dwAutoClose
== CLOSE_NOCONFLICTS
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0))
1006 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1007 if ((dwAutoClose
== CLOSE_NOMERGES
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(!m_bMergesAddsDeletesOccurred
))
1008 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1009 if ((dwAutoClose
== CLOSE_LOCAL
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(localoperation
))
1010 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1013 //Don't do anything here which might cause messages to be sent to the window
1014 //The window thread is probably now blocked in OnOK if we've done an auto close
1018 void CGitProgressList::OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1020 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1024 if (pDispInfo
->item
.mask
& LVIF_TEXT
)
1026 if (pDispInfo
->item
.iItem
< (int)m_arData
.size())
1028 const NotificationData
* data
= m_arData
[pDispInfo
->item
.iItem
];
1029 switch (pDispInfo
->item
.iSubItem
)
1032 lstrcpyn(m_columnbuf
, data
->sActionColumnText
, MAX_PATH
);
1035 lstrcpyn(m_columnbuf
, data
->sPathColumnText
, pDispInfo
->item
.cchTextMax
);
1036 if (!data
->bAuxItem
)
1038 int cWidth
= GetColumnWidth(1);
1039 cWidth
= max(12, cWidth
-12);
1040 CDC
* pDC
= GetDC();
1043 CFont
* pFont
= pDC
->SelectObject(GetFont());
1044 PathCompactPath(pDC
->GetSafeHdc(), m_columnbuf
, cWidth
);
1045 pDC
->SelectObject(pFont
);
1053 pDispInfo
->item
.pszText
= m_columnbuf
;
1060 void CGitProgressList::OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1062 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1064 // Take the default processing unless we set this to something else below.
1065 *pResult
= CDRF_DODEFAULT
;
1067 // First thing - check the draw stage. If it's the control's prepaint
1068 // stage, then tell Windows we want messages for every item.
1070 if ( CDDS_PREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1072 *pResult
= CDRF_NOTIFYITEMDRAW
;
1074 else if ( CDDS_ITEMPREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1076 // This is the prepaint stage for an item. Here's where we set the
1077 // item's text color. Our return value will tell Windows to draw the
1078 // item itself, but it will use the new color we set here.
1080 // Tell Windows to paint the control itself.
1081 *pResult
= CDRF_DODEFAULT
;
1083 ASSERT(pLVCD
->nmcd
.dwItemSpec
< m_arData
.size());
1084 if(pLVCD
->nmcd
.dwItemSpec
>= m_arData
.size())
1088 const NotificationData
* data
= m_arData
[pLVCD
->nmcd
.dwItemSpec
];
1089 ASSERT(data
!= NULL
);
1093 // Store the color back in the NMLVCUSTOMDRAW struct.
1094 pLVCD
->clrText
= data
->color
;
1098 void CGitProgressList::OnNMDblclkSvnprogress(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
1101 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1103 if (pNMLV
->iItem
< 0)
1105 if (m_options
& ProgOptDryRun
)
1106 return; //don't do anything in a dry-run.
1108 const NotificationData
* data
= m_arData
[pNMLV
->iItem
];
1112 if (data
->bConflictedActionItem
)
1114 // We've double-clicked on a conflicted item - do a three-way merge on it
1115 SVNDiff::StartConflictEditor(data
->path
);
1117 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
))
1119 // This is a modified file which has been merged on update. Diff it against base
1120 CTGitPath temporaryFile
;
1121 SVNDiff
diff(this, this->m_hWnd
, true);
1122 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1123 svn_revnum_t baseRev
= 0;
1124 diff
.DiffFileAgainstBase(data
->path
, baseRev
);
1126 else if ((!data
->bAuxItem
)&&(data
->path
.Exists())&&(!data
->path
.IsDirectory()))
1128 bool bOpenWith
= false;
1129 int ret
= (int)ShellExecute(m_hWnd
, NULL
, data
->path
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
1130 if (ret
<= HINSTANCE_ERROR
)
1134 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1135 cmd
+= data
->path
.GetWinPathString() + _T(" ");
1136 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1142 void CGitProgressList::OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1144 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1145 if (m_bThreadRunning
)
1147 if (m_nSortedColumn
== phdr
->iItem
)
1148 m_bAscending
= !m_bAscending
;
1150 m_bAscending
= TRUE
;
1151 m_nSortedColumn
= phdr
->iItem
;
1157 SetItemCountEx (static_cast<int>(m_arData
.size()));
1164 bool CGitProgressList::NotificationDataIsAux(const NotificationData
* pData
)
1166 return pData
->bAuxItem
;
1168 BOOL
CGitProgressList::Notify(const git_wc_notify_action_t action
, CString str
, const git_oid
*a
, const git_oid
*b
)
1170 NotificationData
* data
= new NotificationData();
1171 data
->action
= action
;
1172 data
->bAuxItem
= false;
1174 if (action
== git_wc_notify_update_ref
)
1176 data
->m_NewHash
= b
->id
;
1177 data
->m_OldHash
= a
->id
;
1178 data
->sActionColumnText
.LoadString(IDS_GITACTION_UPDATE_REF
);
1179 data
->sPathColumnText
.Format(_T("%s\t %s -> %s"), str
,
1180 data
->m_OldHash
.ToString().Left(g_Git
.GetShortHASHLength()),
1181 data
->m_NewHash
.ToString().Left(g_Git
.GetShortHASHLength()));
1185 m_arData
.push_back(data
);
1191 m_pAnimate
->ShowWindow(SW_HIDE
);
1194 BOOL
CGitProgressList::Notify(const git_wc_notify_action_t
/*action*/, const git_transfer_progress
*stat
)
1196 static unsigned int start
= 0;
1197 unsigned int dt
= GetCurrentTime() - start
;
1205 start
= GetCurrentTime();
1206 size_t ds
= stat
->received_bytes
- m_TotalBytesTransferred
;
1207 speed
= ds
* 1000.0/dt
;
1208 m_TotalBytesTransferred
= stat
->received_bytes
;
1216 progress
= stat
->received_objects
+ stat
->indexed_objects
;
1218 if ((stat
->total_objects
> 1000) && m_pProgControl
&& (!m_pProgControl
->IsWindowVisible()))
1221 m_pProgControl
->ShowWindow(SW_SHOW
);
1224 if (m_pProgressLabelCtrl
&& m_pProgressLabelCtrl
->IsWindowVisible())
1225 m_pProgressLabelCtrl
->ShowWindow(SW_SHOW
);
1229 m_pProgControl
->SetPos(progress
);
1230 m_pProgControl
->SetRange32(0, 2 * stat
->total_objects
);
1232 if (m_pTaskbarList
&& m_pPostWnd
)
1234 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NORMAL
);
1235 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), progress
, 2 * stat
->total_objects
);
1239 if (stat
->received_bytes
< 1024)
1240 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, (int64_t)stat
->received_bytes
);
1241 else if (stat
->received_bytes
< 1200000)
1242 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, (int64_t)stat
->received_bytes
/ 1024);
1244 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)stat
->received_bytes
/ 1024000.0));
1248 str
.Format(_T("%fB/s"), speed
);
1249 else if(speed
< 1024 * 1024)
1250 str
.Format(_T("%.2fKB/s"), speed
/ 1024);
1252 str
.Format(_T("%.2fMB/s"), speed
/ 1024000.0);
1254 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)str
);
1255 if (m_pProgressLabelCtrl
)
1256 m_pProgressLabelCtrl
->SetWindowText(progText
);
1261 void CGitProgressList::OnTimer(UINT_PTR nIDEvent
)
1263 if (nIDEvent
== TRANSFERTIMER
)
1267 progSpeed
.Format(IDS_SVN_PROGRESS_BYTES_SEC
, 0);
1268 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)progSpeed
);
1269 if (m_pProgressLabelCtrl
)
1270 m_pProgressLabelCtrl
->SetWindowText(progText
);
1272 KillTimer(TRANSFERTIMER
);
1274 if (nIDEvent
== VISIBLETIMER
)
1276 if (nEnsureVisibleCount
)
1277 EnsureVisible(GetItemCount()-1, false);
1278 nEnsureVisibleCount
= 0;
1282 void CGitProgressList::Sort()
1284 if(m_arData
.size() < 2)
1289 // We need to sort the blocks which lie between the auxiliary entries
1290 // This is so that any aux data stays where it was
1291 NotificationDataVect::iterator actionBlockBegin
;
1292 NotificationDataVect::iterator actionBlockEnd
= m_arData
.begin(); // We start searching from here
1296 // Search to the start of the non-aux entry in the next block
1297 actionBlockBegin
= std::find_if(actionBlockEnd
, m_arData
.end(), std::not1(std::ptr_fun(&CGitProgressList::NotificationDataIsAux
)));
1298 if(actionBlockBegin
== m_arData
.end())
1300 // There are no more actions
1303 // Now search to find the end of the block
1304 actionBlockEnd
= std::find_if(actionBlockBegin
+1, m_arData
.end(), std::ptr_fun(&CGitProgressList::NotificationDataIsAux
));
1305 // Now sort the block
1306 std::sort(actionBlockBegin
, actionBlockEnd
, &CGitProgressList::SortCompare
);
1310 bool CGitProgressList::SortCompare(const NotificationData
* pData1
, const NotificationData
* pData2
)
1313 switch (m_nSortedColumn
)
1315 case 0: //action column
1316 result
= pData1
->sActionColumnText
.Compare(pData2
->sActionColumnText
);
1318 case 1: //path column
1319 // Compare happens after switch()
1325 // Sort by path if everything else is equal
1328 result
= CTGitPath::Compare(pData1
->path
, pData2
->path
);
1336 void CGitProgressList::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1338 if (m_options
& ProgOptDryRun
)
1339 return; // don't do anything in a dry-run.
1343 int selIndex
= GetSelectionMark();
1344 if ((point
.x
== -1) && (point
.y
== -1))
1346 // Menu was invoked from the keyboard rather than by right-clicking
1348 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1349 ClientToScreen(&rect
);
1350 point
= rect
.CenterPoint();
1353 if ((selIndex
>= 0)&&(!m_bThreadRunning
))
1355 // entry is selected, thread has finished with updating so show the popup menu
1357 if (popup
.CreatePopupMenu())
1359 bool bAdded
= false;
1360 NotificationData
* data
= m_arData
[selIndex
];
1361 if ((data
)&&(!data
->path
.IsDirectory()))
1364 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1366 if (GetSelectedCount() == 1)
1368 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1373 if (data->bConflictedActionItem)
1375 if (GetSelectedCount() == 1)
1377 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1378 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1379 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1381 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1382 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1384 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1385 popup.SetDefaultItem(ID_COMPARE, FALSE);
1387 if (GetSelectedCount() == 1)
1389 if ((data
->action
== git_wc_notify_add
)||
1390 (data
->action
== git_wc_notify_revert
)||
1391 (data
->action
== git_wc_notify_resolved
)||
1392 (data
->action
== git_wc_notify_checkout
)||
1393 (data
->action
== git_wc_notify_update_ref
))
1395 popup
.AppendMenuIcon(ID_LOG
, IDS_MENULOG
,IDI_LOG
);
1396 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1397 popup
.AppendMenuIcon(ID_OPEN
, IDS_LOG_POPUP_OPEN
, IDI_OPEN
);
1398 popup
.AppendMenuIcon(ID_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1402 } // if ((data)&&(!data->path.IsDirectory()))
1403 if (GetSelectedCount() == 1)
1407 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1408 CTGitPath path
= CTGitPath(sPath
);
1409 if (!sPath
.IsEmpty())
1411 if (path
.GetDirectory().Exists())
1413 popup
.AppendMenuIcon(ID_EXPLORE
, IDS_SVNPROGRESS_MENUOPENPARENT
, IDI_EXPLORER
);
1419 if (GetSelectedCount() > 0)
1422 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1423 popup
.AppendMenuIcon(ID_COPY
, IDS_LOG_POPUP_COPYTOCLIPBOARD
,IDI_COPYCLIP
);
1428 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1430 DialogEnableWindow(IDOK
, FALSE
);
1432 //this->SetPromptApp(&theApp);
1433 theApp
.DoWaitCursor(1);
1434 bool bOpenWith
= false;
1440 POSITION pos
= GetFirstSelectedItemPosition();
1443 int nItem
= GetNextSelectedItem(pos
);
1444 NotificationData
* data
= m_arData
[nItem
];
1447 sLines
+= data
->sPathColumnText
;
1448 sLines
+= _T("\r\n");
1452 if (!sLines
.IsEmpty())
1454 CStringUtils::WriteAsciiStringToClipboard(sLines
, GetSafeHwnd());
1462 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1464 CTGitPath path
= CTGitPath(sPath
);
1465 ShellExecute(m_hWnd
, _T("explore"), path
.GetDirectory().GetWinPath(), NULL
, path
.GetDirectory().GetWinPath(), SW_SHOW
);
1472 svn_revnum_t rev
= -1;
1473 StringRevMap::iterator it
= m_UpdateStartRevMap
.end();
1474 if (data
->basepath
.IsEmpty())
1475 it
= m_UpdateStartRevMap
.begin();
1477 it
= m_UpdateStartRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1478 if (it
!= m_UpdateStartRevMap
.end())
1480 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1481 if (data
->content_state
== svn_wc_notify_state_merged
)
1483 CTGitPath basefile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1484 CTGitPath newfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_HEAD
);
1486 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, basefile
))
1488 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1489 DialogEnableWindow(IDOK
, TRUE
);
1492 // If necessary, convert the line-endings on the file before diffing
1493 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE
))
1495 CTGitPath temporaryFile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_BASE
);
1496 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_BASE
), SVNRev(SVNRev::REV_BASE
), temporaryFile
))
1498 temporaryFile
.Reset();
1503 newfile
= temporaryFile
;
1507 SetFileAttributes(newfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1508 SetFileAttributes(basefile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1509 CString revname
, wcname
, basename
;
1510 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1511 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1512 basename
.Format(IDS_DIFF_BASENAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1513 CAppUtils::StartExtMerge(basefile
, newfile
, data
->path
, data
->path
, basename
, revname
, wcname
, CString(), true);
1517 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1519 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, tempfile
))
1521 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1522 DialogEnableWindow(IDOK
, TRUE
);
1527 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1528 CString revname
, wcname
;
1529 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1530 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1531 CAppUtils::StartExtDiff(
1532 tempfile
, data
->path
, revname
, wcname
,
1533 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)));
1538 case ID_EDITCONFLICT
:
1540 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1541 SVNDiff::StartConflictEditor(CTGitPath(sPath
));
1544 case ID_CONFLICTUSETHEIRS
:
1545 case ID_CONFLICTUSEMINE
:
1546 case ID_CONFLICTRESOLVE
:
1548 svn_wc_conflict_choice_t result
= svn_wc_conflict_choose_merged
;
1551 case ID_CONFLICTUSETHEIRS
:
1552 result
= svn_wc_conflict_choose_theirs_full
;
1554 case ID_CONFLICTUSEMINE
:
1555 result
= svn_wc_conflict_choose_mine_full
;
1557 case ID_CONFLICTRESOLVE
:
1558 result
= svn_wc_conflict_choose_merged
;
1562 POSITION pos
= GetFirstSelectedItemPosition();
1563 CString sResolvedPaths
;
1566 int nItem
= GetNextSelectedItem(pos
);
1567 NotificationData
* data
= m_arData
[nItem
];
1570 if (data
->bConflictedActionItem
)
1572 if (!svn
.Resolve(data
->path
, result
, FALSE
))
1574 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1575 DialogEnableWindow(IDOK
, TRUE
);
1580 data
->color
= ::GetSysColor(COLOR_WINDOWTEXT
);
1581 data
->action
= svn_wc_notify_resolved
;
1582 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
1583 data
->bConflictedActionItem
= false;
1586 if (m_nConflicts
==0)
1588 // When the last conflict is resolved we remove
1589 // the warning which we assume is in the last line.
1590 int nIndex
= GetItemCount()-1;
1591 VERIFY(DeleteItem(nIndex
));
1593 delete m_arData
[nIndex
];
1594 m_arData
.pop_back();
1596 sResolvedPaths
+= data
->path
.GetWinPathString() + _T("\n");
1602 CString info
= BuildInfoString();
1603 SetDlgItemText(IDC_INFOTEXT
, info
);
1605 if (!sResolvedPaths
.IsEmpty())
1608 msg
.Format(IDS_SVNPROGRESS_RESOLVED
, (LPCTSTR
)sResolvedPaths
);
1609 CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
1618 CString cmd
= _T("/command:log");
1619 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1620 if(data
->action
== git_wc_notify_update_ref
)
1622 cmd
+= _T(" /path:\"") + GetPathFromColumnText(CString()) + _T("\"");
1623 if (!data
->m_OldHash
.IsEmpty())
1624 cmd
+= _T(" /startrev:") + data
->m_OldHash
.ToString();
1625 if (!data
->m_NewHash
.IsEmpty())
1626 cmd
+= _T(" /endrev:") + data
->m_NewHash
.ToString();
1629 cmd
+= _T(" /path:\"") + sPath
+ _T("\"");
1630 CAppUtils::RunTortoiseGitProc(cmd
);
1640 CString sWinPath
= GetPathFromColumnText(data
->sPathColumnText
);
1642 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, (LPCTSTR
)sWinPath
, NULL
, NULL
, SW_SHOWNORMAL
);
1643 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
1645 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1646 cmd
+= sWinPath
+ _T(" ");
1647 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1652 DialogEnableWindow(IDOK
, TRUE
);
1654 theApp
.DoWaitCursor(-1);
1661 void CGitProgressList::OnLvnBegindragSvnprogress(NMHDR
* , LRESULT
*pResult
)
1663 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1665 int selIndex
= GetSelectionMark();
1669 CDropFiles dropFiles
; // class for creating DROPFILES struct
1672 POSITION pos
= GetFirstSelectedItemPosition();
1673 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
1675 NotificationData
* data
= m_arData
[index
];
1677 if ( data
->kind
==svn_node_file
|| data
->kind
==svn_node_dir
)
1679 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1681 dropFiles
.AddFile( sPath
);
1685 if (!dropFiles
.IsEmpty())
1687 dropFiles
.CreateStructure();
1693 void CGitProgressList::OnSize(UINT nType
, int cx
, int cy
)
1695 CListCtrl::OnSize(nType
, cx
, cy
);
1696 if ((nType
== SIZE_RESTORED
)&&(m_bLastVisible
))
1701 int count
= GetItemCount();
1703 EnsureVisible(count
-1, false);
1707 //////////////////////////////////////////////////////////////////////////
1709 //////////////////////////////////////////////////////////////////////////
1710 bool CGitProgressList::CmdAdd(CString
& sWindowTitle
, bool& localoperation
)
1712 localoperation
= true;
1713 SetWindowTitle(IDS_PROGRS_TITLE_ADD
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1714 SetBackgroundImage(IDI_ADD_BKG
);
1715 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD
)));
1717 m_itemCountTotal
= m_targetPathList
.GetCount();
1719 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE
) == TRUE
)
1721 git_repository
*repo
= NULL
;
1724 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
1725 if (git_repository_open(&repo
, gitdir
))
1731 if (git_repository_index(&index
, repo
))
1734 git_repository_free(repo
);
1737 if (git_index_read(index
, true))
1740 git_index_free(index
);
1741 git_repository_free(repo
);
1745 for (m_itemCount
= 0; m_itemCount
< m_itemCountTotal
; ++m_itemCount
)
1747 if (git_index_add_bypath(index
, CUnicodeUtils::GetMulti(m_targetPathList
[m_itemCount
].GetGitPathString(), CP_UTF8
)))
1750 git_index_free(index
);
1751 git_repository_free(repo
);
1754 Notify(m_targetPathList
[m_itemCount
], git_wc_notify_add
);
1756 if (IsCancelled() == TRUE
)
1758 git_index_free(index
);
1759 git_repository_free(repo
);
1761 ReportUserCanceled();
1766 if (git_index_write(index
))
1769 git_index_free(index
);
1770 git_repository_free(repo
);
1774 git_index_free(index
);
1775 git_repository_free(repo
);
1779 CMassiveGitTask
mgt(L
"add -f");
1780 if (!mgt
.ExecuteWithNotify(&m_targetPathList
, m_bCancelled
, git_wc_notify_add
, this))
1784 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
1789 bool CGitProgressList::CmdCopy(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1792 ASSERT(m_targetPathList
.GetCount() == 1);
1793 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_COPY
);
1794 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1795 SetBackgroundImage(IDI_COPY_BKG
);
1798 sCmdInfo
.Format(IDS_PROGRS_CMD_COPY
,
1799 m_targetPathList
[0].IsUrl() ? (LPCTSTR
)m_targetPathList
[0].GetSVNPathString() : m_targetPathList
[0].GetWinPath(),
1800 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
1801 ReportCmd(sCmdInfo
);
1803 if (!Copy(m_targetPathList
, m_url
, m_Revision
, m_pegRev
, m_sMessage
))
1808 if (m_options
& ProgOptSwitchAfterCopy
)
1810 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
1811 m_targetPathList
[0].GetWinPath(),
1812 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
1813 ReportCmd(sCmdInfo
);
1814 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, SVNRev::REV_HEAD
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
1816 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, m_Revision
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
1825 if (SVN::PathIsURL(m_url
))
1827 CString
sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING
));
1828 ReportNotification(sMsg
);
1835 bool CGitProgressList::CmdExport(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1838 ASSERT(m_targetPathList
.GetCount() == 1);
1839 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_EXPORT
);
1840 sWindowTitle
= m_url
.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle
;
1841 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1842 SetBackgroundImage(IDI_EXPORT_BKG
);
1844 if (m_options
& ProgOptEolCRLF
)
1846 if (m_options
& ProgOptEolLF
)
1848 if (m_options
& ProgOptEolCR
)
1850 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT
)));
1851 if (!Export(m_url
, m_targetPathList
[0], m_Revision
, m_Revision
, TRUE
, m_options
& ProgOptIgnoreExternals
, m_depth
, NULL
, FALSE
, eol
))
1860 bool CGitProgressList::CmdRename(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1863 ASSERT(m_targetPathList
.GetCount() == 1);
1864 if ((!m_targetPathList
[0].IsUrl())&&(!m_url
.IsUrl()))
1865 localoperation
= true;
1866 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RENAME
);
1867 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1868 SetBackgroundImage(IDI_RENAME_BKG
);
1869 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME
)));
1870 if (!Move(m_targetPathList
, m_url
, m_Revision
, m_sMessage
))
1879 bool CGitProgressList::CmdResolve(CString
& sWindowTitle
, bool& localoperation
)
1882 localoperation
= true;
1883 ASSERT(m_targetPathList
.GetCount() == 1);
1884 SetWindowTitle(IDS_PROGRS_TITLE_RESOLVE
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1885 SetBackgroundImage(IDI_RESOLVE_BKG
);
1886 // check if the file may still have conflict markers in it.
1887 //BOOL bMarkers = FALSE;
1889 m_itemCountTotal
= m_targetPathList
.GetCount();
1890 for (m_itemCount
= 0; m_itemCount
< m_itemCountTotal
; ++m_itemCount
)
1892 CString cmd
,out
,tempmergefile
;
1893 cmd
.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList
[m_itemCount
].GetGitPathString());
1894 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1896 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1897 m_bErrorsOccurred
=true;
1901 CAppUtils::RemoveTempMergeFile((CTGitPath
&)m_targetPathList
[m_itemCount
]);
1903 Notify(m_targetPathList
[m_itemCount
], git_wc_notify_resolved
);
1906 if ((m_options
& ProgOptSkipConflictCheck
) == 0)
1910 for (INT_PTR fileindex
=0; (fileindex
<m_targetPathList
.GetCount()) && (bMarkers
==FALSE
); ++fileindex
)
1912 if (!m_targetPathList
[fileindex
].IsDirectory())
1914 CStdioFile
file(m_targetPathList
[fileindex
].GetWinPath(), CFile::typeBinary
| CFile::modeRead
);
1915 CString strLine
= _T("");
1916 while (file
.ReadString(strLine
))
1918 if (strLine
.Find(_T("<<<<<<<"))==0)
1928 catch (CFileException
* pE
)
1930 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException in Resolve!\n");
1931 TCHAR error
[10000] = {0};
1932 pE
->GetErrorMessage(error
, 10000);
1940 if (CMessageBox::Show(m_hWnd
, IDS_PROGRS_REVERTMARKERS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
1942 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
1943 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
1944 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
1949 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
1950 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
1951 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
1954 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
1959 bool CGitProgressList::CmdRevert(CString
& sWindowTitle
, bool& localoperation
)
1962 localoperation
= true;
1963 SetWindowTitle(IDS_PROGRS_TITLE_REVERT
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1964 SetBackgroundImage(IDI_REVERT_BKG
);
1966 m_itemCountTotal
= 2 * m_selectedPaths
.GetCount();
1967 CTGitPathList delList
;
1968 for (m_itemCount
= 0; m_itemCount
< m_selectedPaths
.GetCount(); ++m_itemCount
)
1972 path
.SetFromWin(g_Git
.m_CurrentDir
+ _T("\\") + m_selectedPaths
[m_itemCount
].GetWinPath());
1973 action
= m_selectedPaths
[m_itemCount
].m_Action
;
1974 /* rename file can't delete because it needs original file*/
1975 if((!(action
& CTGitPath::LOGACTIONS_ADDED
)) &&
1976 (!(action
& CTGitPath::LOGACTIONS_REPLACED
)))
1977 delList
.AddPath(path
);
1979 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
1980 delList
.DeleteAllFiles(true);
1982 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT
)));
1983 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
1985 if(g_Git
.Revert(_T("HEAD"), (CTGitPath
&)m_selectedPaths
[i
]))
1987 CMessageBox::Show(NULL
,_T("Revert Fail"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1988 m_bErrorsOccurred
=true;
1991 Notify(m_selectedPaths
[i
], git_wc_notify_revert
);
1994 if (IsCancelled() == TRUE
)
1996 ReportUserCanceled();
2001 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths
);
2006 bool CGitProgressList::CmdSwitch(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2009 ASSERT(m_targetPathList
.GetCount() == 1);
2011 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SWITCH
);
2012 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2013 SetBackgroundImage(IDI_SWITCH_BKG
);
2015 if (st
.GetStatus(m_targetPathList
[0]) != (-2))
2017 if (st
.status
->entry
!= NULL
)
2019 rev
= st
.status
->entry
->revision
;
2024 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2025 m_targetPathList
[0].GetWinPath(), (LPCTSTR
)m_url
.GetSVNPathString(),
2026 (LPCTSTR
)m_Revision
.ToString());
2027 ReportCmd(sCmdInfo
);
2029 bool depthIsSticky
= true;
2030 if (m_depth
== svn_depth_unknown
)
2031 depthIsSticky
= false;
2032 if (!Switch(m_targetPathList
[0], m_url
, m_Revision
, m_Revision
, m_depth
, depthIsSticky
, m_options
& ProgOptIgnoreExternals
))
2037 m_UpdateStartRevMap
[m_targetPathList
[0].GetSVNApiPath(pool
)] = rev
;
2038 if ((m_RevisionEnd
>= 0)&&(rev
>= 0)
2039 &&((LONG
)m_RevisionEnd
> (LONG
)rev
))
2041 GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2046 bool CGitProgressList::CmdClone(CString
& sWindowTitle
, bool& /*localoperation*/)
2048 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2050 // should never run to here
2054 this->m_TotalBytesTransferred
= 0;
2056 SetWindowTitle(IDS_PROGRS_TITLE_CLONE
, m_url
.GetGitPathString(), sWindowTitle
);
2057 SetBackgroundImage(IDI_SWITCH_BKG
);
2058 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE
)));
2060 if (m_url
.IsEmpty() || m_targetPathList
.IsEmpty())
2063 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2064 CStringA path
= CUnicodeUtils::GetMulti(m_targetPathList
[0].GetWinPathString(),CP_UTF8
);
2066 git_repository
*cloned_repo
= NULL
;
2067 git_remote
*origin
= NULL
;
2068 git_checkout_options checkout_opts
= GIT_CHECKOUT_OPTIONS_INIT
;
2072 checkout_opts
.checkout_strategy
= m_bNoCheckout
? GIT_CHECKOUT_NONE
: GIT_CHECKOUT_SAFE_CREATE
;
2073 checkout_opts
.progress_cb
= CheckoutCallback
;
2074 checkout_opts
.progress_payload
= this;
2076 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2078 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2079 callbacks
.sideband_progress
= RemoteProgressCallback
;
2080 callbacks
.completion
= RemoteCompletionCallback
;
2081 callbacks
.transfer_progress
= FetchCallback
;
2082 callbacks
.credentials
= CAppUtils::Git2GetUserPassword
;
2083 callbacks
.payload
= this;
2085 CStringA refspecA
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
);
2086 CStringA remoteA
= CUnicodeUtils::GetMulti(m_remote
, CP_UTF8
);
2088 git_repository_init_options init_options
= GIT_REPOSITORY_INIT_OPTIONS_INIT
;
2089 init_options
.flags
= GIT_REPOSITORY_INIT_MKPATH
| GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE
;
2090 init_options
.flags
|= m_bBare
? GIT_REPOSITORY_INIT_BARE
: 0;
2092 CSmartAnimation
animate(m_pAnimate
);
2095 if ((error
= git_repository_init_ext(&cloned_repo
, path
, &init_options
)) < 0)
2097 if ((error
= git_remote_create(&origin
, cloned_repo
, remoteA
.IsEmpty() ? "origin" : remoteA
, url
)) < 0)
2099 git_remote_set_callbacks(origin
, &callbacks
);
2100 error
= git_clone_into(cloned_repo
, origin
, &checkout_opts
, refspecA
.IsEmpty() ? nullptr : (const char*)refspecA
, nullptr);
2103 refspecA
.ReleaseBuffer();
2104 remoteA
.ReleaseBuffer();
2105 git_remote_free(origin
);
2111 else if (cloned_repo
)
2112 git_repository_free(cloned_repo
);
2115 bool CGitProgressList::CmdSendMail(CString
& sWindowTitle
, bool& /*localoperation*/)
2118 SetWindowTitle(IDS_PROGRS_TITLE_SENDMAIL
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2119 //SetBackgroundImage(IDI_ADD_BKG);
2120 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL
)));
2122 return m_SendMail
->Send(m_targetPathList
, this) == 0;
2125 bool CGitProgressList::CmdFetch(CString
& sWindowTitle
, bool& /*localoperation*/)
2127 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2129 // should never run to here
2133 this->m_TotalBytesTransferred
= 0;
2135 SetWindowTitle(IDS_PROGRS_TITLE_FETCH
, g_Git
.m_CurrentDir
, sWindowTitle
);
2136 SetBackgroundImage(IDI_UPDATE_BKG
);
2137 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
)) + _T(" ") + m_url
.GetGitPathString() + _T(" ") + m_RefSpec
);
2139 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2140 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
2141 CStringA remotebranch
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
);
2143 CSmartAnimation
animate(m_pAnimate
);
2145 git_remote
*remote
= NULL
;
2146 git_repository
*repo
= NULL
;
2151 if (git_repository_open(&repo
, gitdir
))
2158 // first try with a named remote (e.g. "origin")
2159 if (git_remote_load(&remote
, repo
, url
) < 0)
2161 // retry with repository located at a specific url
2162 if (git_remote_create_anonymous(&remote
, repo
, url
, nullptr) < 0)
2170 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2172 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2173 callbacks
.sideband_progress
= RemoteProgressCallback
;
2174 callbacks
.transfer_progress
= FetchCallback
;
2175 callbacks
.completion
= RemoteCompletionCallback
;
2176 callbacks
.credentials
= CAppUtils::Git2GetUserPassword
;
2177 callbacks
.payload
= this;
2179 git_remote_set_callbacks(remote
, &callbacks
);
2180 git_remote_set_autotag(remote
, (git_remote_autotag_option_t
)m_AutoTag
);
2182 if (!remotebranch
.IsEmpty() && git_remote_add_fetch(remote
, remotebranch
))
2189 // Connect to the remote end specifying that we want to fetch
2190 // information from it.
2191 if (git_remote_connect(remote
, GIT_DIRECTION_FETCH
) < 0) {
2197 // Download the packfile and index it. This function updates the
2198 // amount of received data and the indexer stats which lets you
2199 // inform the user about progress.
2200 if (git_remote_download(remote
) < 0) {
2206 // Update the references in the remote's namespace to point to the
2207 // right commits. This may be needed even if there was no packfile
2208 // to download, which can happen e.g. when the branches have been
2209 // changed but all the neede objects are available locally.
2210 if (git_remote_update_tips(remote
, nullptr, nullptr) < 0)
2217 git_remote_disconnect(remote
);
2221 git_remote_free(remote
);
2222 git_repository_free(repo
);
2226 bool CGitProgressList::CmdReset(CString
& sWindowTitle
, bool& /*localoperation*/)
2228 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
2230 // should never run to here
2235 SetWindowTitle(IDS_PROGRS_TITLE_RESET
, g_Git
.m_CurrentDir
, sWindowTitle
);
2236 SetBackgroundImage(IDI_UPDATE_BKG
);
2237 int resetTypesResource
[] = { IDS_RESET_SOFT
, IDS_RESET_MIXED
, IDS_RESET_HARD
};
2238 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_RESET
)) + _T(" ") + CString(MAKEINTRESOURCE(resetTypesResource
[m_resetType
])) + _T(" ") + m_revision
);
2240 CSmartAnimation
animate(m_pAnimate
);
2242 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
2244 git_repository
*repo
= NULL
;
2249 if (git_repository_open(&repo
, gitdir
))
2257 if (git_revparse_single(&target
, repo
, CUnicodeUtils::GetUTF8(m_revision
)))
2263 if (git_reset(repo
, target
, (git_reset_t
)(m_resetType
+ 1), nullptr, nullptr))
2269 git_object_free(target
);
2272 git_repository_free(repo
);
2277 void CGitProgressList::Init()
2279 SetExtendedStyle (LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
);
2282 int c
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
2287 temp
.LoadString(IDS_PROGRS_ACTION
);
2288 InsertColumn(0, temp
);
2289 temp
.LoadString(IDS_PROGRS_PATH
);
2290 InsertColumn(1, temp
);
2292 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
2293 if (m_pThread
==NULL
)
2295 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED
)));
2299 m_pThread
->m_bAutoDelete
= FALSE
;
2300 m_pThread
->ResumeThread();
2303 // Call this early so that the column headings aren't hidden before any
2307 SetTimer(VISIBLETIMER
, 300, NULL
);
2311 void CGitProgressList::OnClose()
2313 // TODO: Add your message handler code here and/or call default
2316 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
2317 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2321 m_bCancelled
= TRUE
;
2324 CListCtrl::OnClose();
2328 BOOL
CGitProgressList::PreTranslateMessage(MSG
* pMsg
)
2330 // TODO: Add your specialized code here and/or call the base class
2331 if (pMsg
->message
== WM_KEYDOWN
)
2333 if (pMsg
->wParam
== 'A')
2335 if (GetKeyState(VK_CONTROL
)&0x8000)
2337 // Ctrl-A -> select all
2338 SetSelectionMark(0);
2339 for (int i
=0; i
<GetItemCount(); ++i
)
2341 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2345 if ((pMsg
->wParam
== 'C')||(pMsg
->wParam
== VK_INSERT
))
2347 int selIndex
= GetSelectionMark();
2350 if (GetKeyState(VK_CONTROL
)&0x8000)
2352 //Ctrl-C -> copy to clipboard
2354 POSITION pos
= GetFirstSelectedItemPosition();
2359 int nItem
= GetNextSelectedItem(pos
);
2360 CString sAction
= GetItemText(nItem
, 0);
2361 CString sPath
= GetItemText(nItem
, 1);
2362 CString sMime
= GetItemText(nItem
, 2);
2363 CString sLogCopyText
;
2364 sLogCopyText
.Format(_T("%s: %s %s\r\n"),
2365 (LPCTSTR
)sAction
, (LPCTSTR
)sPath
, (LPCTSTR
)sMime
);
2366 sClipdata
+= sLogCopyText
;
2368 CStringUtils::WriteAsciiStringToClipboard(sClipdata
);
2373 } // if (pMsg->message == WM_KEYDOWN)
2374 return CListCtrl::PreTranslateMessage(pMsg
);
2377 CString
CGitProgressList::GetPathFromColumnText(const CString
& sColumnText
)
2379 CString sPath
= sColumnText
;
2380 if (sPath
.Find(':')<0)
2382 // the path is not absolute: add the common root of all paths to it
2383 sPath
= g_Git
.m_CurrentDir
+ _T("\\") + sColumnText
;
2388 void CGitProgressList::SetWindowTitle(UINT id
, const CString
& urlorpath
, CString
& dialogname
)
2390 if (!m_bSetTitle
|| !m_pPostWnd
)
2393 dialogname
.LoadString(id
);
2394 CAppUtils::SetWindowTitle(m_pPostWnd
->GetSafeHwnd(), urlorpath
, dialogname
);