1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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
)
73 CGitProgressList::CGitProgressList():CListCtrl()
76 , m_bErrorsOccurred(false)
78 , m_bNoCheckout(false)
79 , m_AutoTag(GIT_REMOTE_DOWNLOAD_TAGS_AUTO
)
81 , m_options(ProgOptNone
)
83 , m_pTaskbarList(nullptr)
85 , m_Command(GitProgress_none
)
86 , m_AlwaysConflicted(false)
87 , m_bThreadRunning(FALSE
)
88 , m_keepchangelist(false)
90 , m_bMergesAddsDeletesOccurred(FALSE
)
92 , bSecondResized(false)
93 , nEnsureVisibleCount(0)
94 , m_TotalBytesTransferred(0)
95 , m_bFinishedItemAdded(false)
96 , m_bLastVisible(false)
98 , m_itemCountTotal(-1)
100 m_pInfoCtrl
= nullptr;
101 m_pAnimate
= nullptr;
102 m_pProgControl
= nullptr;
103 m_pProgressLabelCtrl
= nullptr;
104 m_pPostWnd
= nullptr;
108 CGitProgressList::~CGitProgressList()
110 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
114 if(m_pThread
!= NULL
)
121 BEGIN_MESSAGE_MAP(CGitProgressList
, CListCtrl
)
122 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawSvnprogress
)
123 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkSvnprogress
)
124 ON_NOTIFY_REFLECT(HDN_ITEMCLICK
, OnHdnItemclickSvnprogress
)
125 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnLvnBegindragSvnprogress
)
126 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoSvnprogress
)
127 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER
, OnShowConflictResolver
)
134 void CGitProgressList::Cancel()
141 // CGitProgressList message handlers
144 LRESULT
CGitProgressList::OnShowConflictResolver(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
147 CConflictResolveDlg
dlg(this);
148 const svn_wc_conflict_description_t
*description
= (svn_wc_conflict_description_t
*)lParam
;
151 dlg
.SetConflictDescription(description
);
154 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
156 if (dlg
.DoModal() == IDOK
)
158 if (dlg
.GetResult() == svn_wc_conflict_choose_postpone
)
160 // if the result is conflicted and the dialog returned IDOK,
161 // that means we should not ask again in case of a conflict
162 m_AlwaysConflicted
= true;
163 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE
)->GetSafeHwnd(), BM_SETCHECK
, BST_CHECKED
, 0);
166 m_mergedfile
= dlg
.GetMergedFile();
167 m_bCancelled
= dlg
.IsCancelled();
169 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
170 return dlg
.GetResult();
173 return svn_wc_conflict_choose_postpone
;
178 svn_wc_conflict_choice_t
CGitProgressList::ConflictResolveCallback(const svn_wc_conflict_description_t
*description
, CString
& mergedfile
)
180 // we only bother the user when merging
181 if (((m_Command
== GitProgress_Merge
)||(m_Command
== GitProgress_MergeAll
)||(m_Command
== GitProgress_MergeReintegrate
))&&(!m_AlwaysConflicted
)&&(description
))
183 // we're in a worker thread here. That means we must not show a dialog from the thread
184 // but let the UI thread do it.
185 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
186 LRESULT dlgResult
= ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER
, 0, (LPARAM
)description
);
187 mergedfile
= m_mergedfile
;
188 return (svn_wc_conflict_choice_t
)dlgResult
;
191 return svn_wc_conflict_choose_postpone
;
194 void CGitProgressList::AddItemToList()
196 int totalcount
= GetItemCount();
198 SetItemCountEx(totalcount
+1, LVSICF_NOSCROLL
|LVSICF_NOINVALIDATEALL
);
199 // make columns width fit
200 if (iFirstResized
< 30)
202 // only resize the columns for the first 30 or so entries.
203 // after that, don't resize them anymore because that's an
204 // expensive function call and the columns will be sized
205 // close enough already.
210 // Make sure the item is *entirely* visible even if the horizontal
211 // scroll bar is visible.
212 int count
= GetCountPerPage();
213 if (totalcount
<= (GetTopIndex() + count
+ nEnsureVisibleCount
+ 2))
215 ++nEnsureVisibleCount
;
216 m_bLastVisible
= true;
220 nEnsureVisibleCount
= 0;
222 m_bLastVisible
= false;
227 BOOL
CGitProgressList::Notify(const CTGitPath
& path
, git_wc_notify_action_t action
229 svn_node_kind_t kind, const CString& mime_type,
230 svn_wc_notify_state_t content_state,
231 svn_wc_notify_state_t prop_state, LONG rev,
232 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
233 const CString& changelistname,
234 svn_merge_range_t * range,
235 svn_error_t * err, apr_pool_t * pool
238 bool bNoNotify
= false;
239 bool bDoAddData
= true;
240 NotificationData
* data
= new NotificationData();
242 data
->action
= action
;
243 data
->sPathColumnText
=path
.GetGitPathString();
244 data
->bAuxItem
= false;
246 if (this->m_pAnimate
)
247 this->m_pAnimate
->ShowWindow(SW_HIDE
);
251 data
->mime_type
= mime_type
;
252 data
->content_state
= content_state
;
253 data
->prop_state
= prop_state
;
255 data
->lock_state
= lock_state
;
256 data
->changelistname
= changelistname
;
257 if ((lock
)&&(lock
->owner
))
258 data
->owner
= CUnicodeUtils::GetUnicode(lock
->owner
);
259 data
->sPathColumnText
= path
.GetUIPathString();
260 if (!m_basePath
.IsEmpty())
261 data
->basepath
= m_basePath
;
263 data
->merge_range
= *range
;
265 switch (data
->action
)
267 case git_wc_notify_add
:
268 //case svn_wc_notify_update_add:
269 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
271 // data->color = m_Colors.GetColor(CColors::Conflict);
272 // data->bConflictedActionItem = true;
273 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
278 // m_bMergesAddsDeletesOccurred = true;
279 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADD
);
280 data
->color
= m_Colors
.GetColor(CColors::Added
);
283 case git_wc_notify_sendmail
:
284 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_START
);
285 data
->color
= m_Colors
.GetColor(CColors::Modified
);
288 case git_wc_notify_resolved
:
289 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
292 case git_wc_notify_revert
:
293 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REVERT
);
296 case git_wc_notify_checkout
:
297 data
->sActionColumnText
.LoadString(IDS_PROGRS_CMD_CHECKOUT
);
298 data
->color
= m_Colors
.GetColor(CColors::Added
);
299 data
->bAuxItem
= false;
303 case svn_wc_notify_commit_added
:
304 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADDING
);
305 data
->color
= m_Colors
.GetColor(CColors::Added
);
307 case svn_wc_notify_copy
:
308 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COPY
);
310 case svn_wc_notify_commit_modified
:
311 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MODIFIED
);
312 data
->color
= m_Colors
.GetColor(CColors::Modified
);
314 case svn_wc_notify_delete
:
315 case svn_wc_notify_update_delete
:
316 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETE
);
317 m_bMergesAddsDeletesOccurred
= true;
318 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
320 case svn_wc_notify_commit_deleted
:
321 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETING
);
322 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
324 case svn_wc_notify_restore
:
325 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESTORE
);
328 case svn_wc_notify_update_replace
:
329 case svn_wc_notify_commit_replaced
:
330 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REPLACED
);
331 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
333 case svn_wc_notify_exists
:
334 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
336 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
337 data
->bConflictedActionItem
= true;
339 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
341 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
343 data
->color
= m_Colors
.GetColor(CColors::Merged
);
344 m_bMergesAddsDeletesOccurred
= true;
345 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
348 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXISTS
);
350 case svn_wc_notify_update_update
:
351 // if this is an inoperative dir change, don't show the notification.
352 // an inoperative dir change is when a directory gets updated without
353 // any real change in either text or properties.
354 if ((kind
== svn_node_dir
)
355 && ((prop_state
== svn_wc_notify_state_inapplicable
)
356 || (prop_state
== svn_wc_notify_state_unknown
)
357 || (prop_state
== svn_wc_notify_state_unchanged
)))
362 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
364 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
365 data
->bConflictedActionItem
= true;
367 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
369 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
371 data
->color
= m_Colors
.GetColor(CColors::Merged
);
372 m_bMergesAddsDeletesOccurred
= true;
373 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
375 else if (((data
->content_state
!= svn_wc_notify_state_unchanged
)&&(data
->content_state
!= svn_wc_notify_state_unknown
)) ||
376 ((data
->prop_state
!= svn_wc_notify_state_unchanged
)&&(data
->prop_state
!= svn_wc_notify_state_unknown
)))
378 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UPDATE
);
385 if (lock_state
== svn_wc_notify_lock_state_unlocked
)
387 CString
temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED
));
388 data
->sActionColumnText
+= _T(", ") + temp
;
392 case svn_wc_notify_update_external
:
393 // For some reason we build a list of externals...
394 m_ExtStack
.AddHead(path
.GetUIPathString());
395 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXTERNAL
);
396 data
->bAuxItem
= true;
399 case svn_wc_notify_update_completed
:
401 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COMPLETED
);
402 data
->bAuxItem
= true;
403 bool bEmpty
= !!m_ExtStack
.IsEmpty();
405 data
->sPathColumnText
.Format(IDS_PROGRS_PATHATREV
, (LPCTSTR
)m_ExtStack
.RemoveHead(), rev
);
407 data
->sPathColumnText
.Format(IDS_PROGRS_ATREV
, rev
);
409 if ((m_nConflicts
>0)&&(bEmpty
))
411 // We're going to add another aux item - let's shove this current onto the list first
412 // I don't really like this, but it will do for the moment.
413 m_arData
.push_back(data
);
416 data
= new NotificationData();
417 data
->bAuxItem
= true;
418 data
->sActionColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING
);
419 data
->sPathColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED
);
420 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
421 CSoundUtils::PlayTSVNWarning();
422 // This item will now be added after the switch statement
424 if (!m_basePath
.IsEmpty())
425 m_FinishedRevMap
[m_basePath
.GetSVNApiPath(pool
)] = rev
;
427 m_bFinishedItemAdded
= true;
430 case svn_wc_notify_commit_postfix_txdelta
:
431 data
->sActionColumnText
.LoadString(IDS_SVNACTION_POSTFIX
);
433 case svn_wc_notify_failed_revert
:
434 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
436 case svn_wc_notify_status_completed
:
437 case svn_wc_notify_status_external
:
438 data
->sActionColumnText
.LoadString(IDS_SVNACTION_STATUS
);
440 case svn_wc_notify_skip
:
441 if ((content_state
== svn_wc_notify_state_missing
)||(content_state
== svn_wc_notify_state_obstructed
)||(content_state
== svn_wc_notify_state_conflicted
))
443 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIPMISSING
);
445 // The color settings dialog describes the red color with
446 // "possible or real conflict / obstructed" which also applies to
447 // skipped targets during a merge. So we just use the same color.
448 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
451 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIP
);
453 case svn_wc_notify_locked
:
454 if ((lock
)&&(lock
->owner
))
455 data
->sActionColumnText
.Format(IDS_SVNACTION_LOCKEDBY
, (LPCTSTR
)CUnicodeUtils::GetUnicode(lock
->owner
));
457 case svn_wc_notify_unlocked
:
458 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UNLOCKED
);
460 case svn_wc_notify_failed_lock
:
461 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDLOCK
);
462 m_arData
.push_back(data
);
464 ReportError(SVN::GetErrorString(err
));
466 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
467 m_bLockWarning
= true;
468 if (err
->apr_err
== SVN_ERR_FS_PATH_ALREADY_LOCKED
)
469 m_bLockExists
= true;
471 case svn_wc_notify_failed_unlock
:
472 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDUNLOCK
);
473 m_arData
.push_back(data
);
475 ReportError(SVN::GetErrorString(err
));
477 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
478 m_bLockWarning
= true;
480 case svn_wc_notify_changelist_set
:
481 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTSET
, (LPCTSTR
)data
->changelistname
);
483 case svn_wc_notify_changelist_clear
:
484 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CHANGELISTCLEAR
);
486 case svn_wc_notify_changelist_moved
:
487 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTMOVED
, (LPCTSTR
)data
->changelistname
);
489 case svn_wc_notify_foreign_merge_begin
:
490 case svn_wc_notify_merge_begin
:
492 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGEBEGINNONE
);
493 else if ((data
->merge_range
.start
== data
->merge_range
.end
) || (data
->merge_range
.start
== data
->merge_range
.end
- 1))
494 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLE
, data
->merge_range
.end
);
495 else if (data
->merge_range
.start
- 1 == data
->merge_range
.end
)
496 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE
, data
->merge_range
.start
);
497 else if (data
->merge_range
.start
< data
->merge_range
.end
)
498 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE
, data
->merge_range
.start
+ 1, data
->merge_range
.end
);
500 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE
, data
->merge_range
.start
, data
->merge_range
.end
+ 1);
501 data
->bAuxItem
= true;
506 } // switch (data->action)
514 m_arData
.push_back(data
);
516 if ((!data
->bAuxItem
) && (m_itemCount
> 0))
520 m_pProgControl
->ShowWindow(SW_SHOW
);
521 m_pProgControl
->SetPos(m_itemCount
);
522 m_pProgControl
->SetRange32(0, m_itemCountTotal
);
524 if (m_pTaskbarList
&& m_pPostWnd
)
526 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NORMAL
);
527 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), m_itemCount
, m_itemCountTotal
);
531 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
534 // bSecondResized = TRUE;
542 CString
CGitProgressList::BuildInfoString()
545 if(this->m_Command
== GitProgress_Resolve
)
546 infotext
= _T("You need commit your change after resolve conflict");
563 for (size_t i
=0; i
<m_arData
.size(); ++i
)
565 const NotificationData
* dat
= m_arData
[i
];
568 case svn_wc_notify_add
:
569 case svn_wc_notify_update_add
:
570 case svn_wc_notify_commit_added
:
571 if (dat
->bConflictedActionItem
)
576 case svn_wc_notify_copy
:
579 case svn_wc_notify_delete
:
580 case svn_wc_notify_update_delete
:
581 case svn_wc_notify_commit_deleted
:
584 case svn_wc_notify_restore
:
587 case svn_wc_notify_revert
:
590 case svn_wc_notify_resolved
:
593 case svn_wc_notify_update_update
:
594 if (dat
->bConflictedActionItem
)
596 else if ((dat
->content_state
== svn_wc_notify_state_merged
) || (dat
->prop_state
== svn_wc_notify_state_merged
))
601 case svn_wc_notify_commit_modified
:
604 case svn_wc_notify_skip
:
607 case svn_wc_notify_commit_replaced
:
614 temp
.LoadString(IDS_SVNACTION_CONFLICTED
);
616 temp
.Format(_T(":%d "), conflicted
);
621 temp
.LoadString(IDS_SVNACTION_SKIP
);
623 infotext
.AppendFormat(_T(":%d "), skipped
);
627 temp
.LoadString(IDS_SVNACTION_MERGED
);
629 infotext
.AppendFormat(_T(":%d "), merged
);
633 temp
.LoadString(IDS_SVNACTION_ADD
);
635 infotext
.AppendFormat(_T(":%d "), added
);
639 temp
.LoadString(IDS_SVNACTION_DELETE
);
641 infotext
.AppendFormat(_T(":%d "), deleted
);
645 temp
.LoadString(IDS_SVNACTION_MODIFIED
);
647 infotext
.AppendFormat(_T(":%d "), modified
);
651 temp
.LoadString(IDS_SVNACTION_COPY
);
653 infotext
.AppendFormat(_T(":%d "), copied
);
657 temp
.LoadString(IDS_SVNACTION_REPLACED
);
659 infotext
.AppendFormat(_T(":%d "), replaced
);
663 temp
.LoadString(IDS_SVNACTION_UPDATE
);
665 infotext
.AppendFormat(_T(":%d "), updated
);
669 temp
.LoadString(IDS_SVNACTION_RESTORE
);
671 infotext
.AppendFormat(_T(":%d "), restored
);
675 temp
.LoadString(IDS_SVNACTION_REVERT
);
677 infotext
.AppendFormat(_T(":%d "), reverted
);
681 temp
.LoadString(IDS_SVNACTION_RESOLVE
);
683 infotext
.AppendFormat(_T(":%d "), resolved
);
689 void CGitProgressList::SetSelectedList(const CTGitPathList
& selPaths
)
691 m_selectedPaths
= selPaths
;
694 void CGitProgressList::ResizeColumns()
698 TCHAR textbuf
[MAX_PATH
];
700 CHeaderCtrl
* pHeaderCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
703 int maxcol
= pHeaderCtrl
->GetItemCount()-1;
704 for (int col
= 0; col
<= maxcol
; ++col
)
706 // find the longest width of all items
707 int count
= GetItemCount();
710 hdi
.pszText
= textbuf
;
711 hdi
.cchTextMax
= _countof(textbuf
);
712 pHeaderCtrl
->GetItem(col
, &hdi
);
713 int cx
= GetStringWidth(hdi
.pszText
)+20; // 20 pixels for col separator and margin
715 for (int index
= 0; index
<count
; ++index
)
717 // get the width of the string and add 12 pixels for the column separator and margins
722 linewidth
= GetStringWidth(m_arData
[index
]->sActionColumnText
) + 12;
725 linewidth
= GetStringWidth(m_arData
[index
]->sPathColumnText
) + 12;
731 SetColumnWidth(col
, cx
);
738 bool CGitProgressList::SetBackgroundImage(UINT nID
)
740 return CAppUtils::SetListCtrlBackgroundImage(GetSafeHwnd(), nID
);
743 void CGitProgressList::ReportGitError()
745 ReportError(CGit::GetLibGit2LastErr());
748 void CGitProgressList::ReportUserCanceled()
750 ReportError(CString(MAKEINTRESOURCE(IDS_SVN_USERCANCELLED
)));
753 void CGitProgressList::ReportError(const CString
& sError
)
755 CSoundUtils::PlayTGitError();
756 ReportString(sError
, CString(MAKEINTRESOURCE(IDS_ERR_ERROR
)), m_Colors
.GetColor(CColors::Conflict
));
757 m_bErrorsOccurred
= true;
760 void CGitProgressList::ReportWarning(const CString
& sWarning
)
762 CSoundUtils::PlayTGitWarning();
763 ReportString(sWarning
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)), m_Colors
.GetColor(CColors::Conflict
));
766 void CGitProgressList::ReportNotification(const CString
& sNotification
)
768 CSoundUtils::PlayTGitNotification();
769 ReportString(sNotification
, CString(MAKEINTRESOURCE(IDS_WARN_NOTE
)));
772 void CGitProgressList::ReportCmd(const CString
& sCmd
)
774 ReportString(sCmd
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO
)), m_Colors
.GetColor(CColors::Cmd
));
777 void CGitProgressList::ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
)
779 // instead of showing a dialog box with the error message or notification,
780 // just insert the error text into the list control.
781 // that way the user isn't 'interrupted' by a dialog box popping up!
783 // the message may be split up into different lines
784 // so add a new entry for each line of the message
785 while (!sMessage
.IsEmpty())
787 NotificationData
* data
= new NotificationData();
788 data
->bAuxItem
= true;
789 data
->sActionColumnText
= sMsgKind
;
790 if (sMessage
.Find('\n')>=0)
791 data
->sPathColumnText
= sMessage
.Left(sMessage
.Find('\n'));
793 data
->sPathColumnText
= sMessage
;
794 data
->sPathColumnText
.Trim(_T("\n\r"));
796 if (sMessage
.Find('\n')>=0)
798 sMessage
= sMessage
.Mid(sMessage
.Find('\n'));
799 sMessage
.Trim(_T("\n\r"));
803 m_arData
.push_back(data
);
808 UINT
CGitProgressList::ProgressThreadEntry(LPVOID pVoid
)
810 return ((CGitProgressList
*)pVoid
)->ProgressThread();
813 UINT
CGitProgressList::ProgressThread()
815 // The SetParams function should have loaded something for us
818 CString sWindowTitle
;
819 bool localoperation
= false;
820 bool bSuccess
= false;
821 m_AlwaysConflicted
= false;
824 m_pPostWnd
->PostMessage(WM_PROG_CMD_START
, m_Command
);
826 if(m_pProgressLabelCtrl
)
828 m_pProgressLabelCtrl
->ShowWindow(SW_SHOW
);
829 m_pProgressLabelCtrl
->SetWindowText(_T(""));
832 // SetAndClearProgressInfo(m_hWnd);
833 m_itemCount
= m_itemCountTotal
;
835 InterlockedExchange(&m_bThreadRunning
, TRUE
);
837 bSecondResized
= FALSE
;
838 m_bFinishedItemAdded
= false;
839 DWORD startTime
= GetCurrentTime();
841 if (m_pTaskbarList
&& m_pPostWnd
)
842 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_INDETERMINATE
);
846 case GitProgress_Add
:
847 bSuccess
= CmdAdd(sWindowTitle
, localoperation
);
849 case GitProgress_Copy
:
850 bSuccess
= CmdCopy(sWindowTitle
, localoperation
);
852 case GitProgress_Export
:
853 bSuccess
= CmdExport(sWindowTitle
, localoperation
);
855 case GitProgress_Rename
:
856 bSuccess
= CmdRename(sWindowTitle
, localoperation
);
858 case GitProgress_Resolve
:
859 bSuccess
= CmdResolve(sWindowTitle
, localoperation
);
861 case GitProgress_Revert
:
862 bSuccess
= CmdRevert(sWindowTitle
, localoperation
);
864 case GitProgress_Switch
:
865 bSuccess
= CmdSwitch(sWindowTitle
, localoperation
);
867 case GitProgress_SendMail
:
868 bSuccess
= CmdSendMail(sWindowTitle
, localoperation
);
870 case GitProgress_Clone
:
871 bSuccess
= CmdClone(sWindowTitle
, localoperation
);
873 case GitProgress_Fetch
:
874 bSuccess
= CmdFetch(sWindowTitle
, localoperation
);
876 case GitProgress_Reset
:
877 bSuccess
= CmdReset(sWindowTitle
, localoperation
);
881 temp
.LoadString(IDS_PROGRS_TITLEFAILED
);
883 temp
.LoadString(IDS_PROGRS_TITLEFIN
);
884 sWindowTitle
= sWindowTitle
+ _T(" ") + temp
;
885 if (m_bSetTitle
&& m_pPostWnd
)
886 ::SetWindowText(m_pPostWnd
->GetSafeHwnd(), sWindowTitle
);
888 KillTimer(TRANSFERTIMER
);
889 KillTimer(VISIBLETIMER
);
891 if (m_pTaskbarList
&& m_pPostWnd
)
893 if (DidErrorsOccur())
895 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_ERROR
);
896 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), 100, 100);
899 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NOPROGRESS
);
902 CString info
= BuildInfoString();
904 info
.LoadString(IDS_PROGRS_INFOFAILED
);
906 m_pInfoCtrl
->SetWindowText(info
);
910 DWORD time
= GetCurrentTime() - startTime
;
913 if (!m_sTotalBytesTransferred
.IsEmpty())
915 temp
.Format(IDS_PROGRS_TIME
, (time
/ 1000) / 60, (time
/ 1000) % 60);
916 sFinalInfo
.Format(IDS_PROGRS_FINALINFO
, m_sTotalBytesTransferred
, (LPCTSTR
)temp
);
917 if (m_pProgressLabelCtrl
)
918 m_pProgressLabelCtrl
->SetWindowText(sFinalInfo
);
922 if (m_pProgressLabelCtrl
)
923 m_pProgressLabelCtrl
->ShowWindow(SW_HIDE
);
927 m_pProgControl
->ShowWindow(SW_HIDE
);
929 if (!m_bFinishedItemAdded
)
933 str
.LoadString(IDS_SUCCESS
);
935 str
.LoadString(IDS_FAIL
);
936 log
.Format(_T("%s (%d ms @ %s)"), str
, time
, CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false));
938 // there's no "finished: xxx" line at the end. We add one here to make
939 // sure the user sees that the command is actually finished.
940 ReportString(log
, CString(MAKEINTRESOURCE(IDS_PROGRS_FINISHED
)), bSuccess
? RGB(0,0,255) : RGB(255,0,0));
943 int count
= GetItemCount();
944 if ((count
> 0)&&(m_bLastVisible
))
945 EnsureVisible(count
-1, FALSE
);
950 logfile
.AddTimeLine();
951 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
953 NotificationData
* data
= m_arData
[i
];
954 temp
.Format(_T("%-20s : %s"), (LPCTSTR
)data
->sActionColumnText
, (LPCTSTR
)data
->sPathColumnText
);
955 logfile
.AddLine(temp
);
957 if (!sFinalInfo
.IsEmpty())
958 logfile
.AddLine(sFinalInfo
);
963 InterlockedExchange(&m_bThreadRunning
, FALSE
);
969 m_pPostWnd
->PostMessage(WM_PROG_CMD_FINISH
, this->m_Command
, 0L);
972 DWORD dwAutoClose
= CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL
);
973 if (m_options
& ProgOptDryRun
)
974 dwAutoClose
= 0; // dry run means progress dialog doesn't auto close at all
977 if (m_dwCloseOnEnd
!= (DWORD
)-1)
978 dwAutoClose
= m_dwCloseOnEnd
; // command line value has priority over setting value
979 if ((dwAutoClose
== CLOSE_NOERRORS
)&&(!m_bErrorsOccurred
))
980 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
981 if ((dwAutoClose
== CLOSE_NOCONFLICTS
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0))
982 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
983 if ((dwAutoClose
== CLOSE_NOMERGES
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(!m_bMergesAddsDeletesOccurred
))
984 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
985 if ((dwAutoClose
== CLOSE_LOCAL
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(localoperation
))
986 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
989 //Don't do anything here which might cause messages to be sent to the window
990 //The window thread is probably now blocked in OnOK if we've done an auto close
994 void CGitProgressList::OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
996 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1000 if (pDispInfo
->item
.mask
& LVIF_TEXT
)
1002 if (pDispInfo
->item
.iItem
< (int)m_arData
.size())
1004 const NotificationData
* data
= m_arData
[pDispInfo
->item
.iItem
];
1005 switch (pDispInfo
->item
.iSubItem
)
1008 lstrcpyn(m_columnbuf
, data
->sActionColumnText
, MAX_PATH
);
1011 lstrcpyn(m_columnbuf
, data
->sPathColumnText
, pDispInfo
->item
.cchTextMax
);
1012 if (!data
->bAuxItem
)
1014 int cWidth
= GetColumnWidth(1);
1015 cWidth
= max(12, cWidth
-12);
1016 CDC
* pDC
= GetDC();
1019 CFont
* pFont
= pDC
->SelectObject(GetFont());
1020 PathCompactPath(pDC
->GetSafeHdc(), m_columnbuf
, cWidth
);
1021 pDC
->SelectObject(pFont
);
1029 pDispInfo
->item
.pszText
= m_columnbuf
;
1036 void CGitProgressList::OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1038 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1040 // Take the default processing unless we set this to something else below.
1041 *pResult
= CDRF_DODEFAULT
;
1043 // First thing - check the draw stage. If it's the control's prepaint
1044 // stage, then tell Windows we want messages for every item.
1046 if ( CDDS_PREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1048 *pResult
= CDRF_NOTIFYITEMDRAW
;
1050 else if ( CDDS_ITEMPREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1052 // This is the prepaint stage for an item. Here's where we set the
1053 // item's text color. Our return value will tell Windows to draw the
1054 // item itself, but it will use the new color we set here.
1056 // Tell Windows to paint the control itself.
1057 *pResult
= CDRF_DODEFAULT
;
1059 ASSERT(pLVCD
->nmcd
.dwItemSpec
< m_arData
.size());
1060 if(pLVCD
->nmcd
.dwItemSpec
>= m_arData
.size())
1064 const NotificationData
* data
= m_arData
[pLVCD
->nmcd
.dwItemSpec
];
1065 ASSERT(data
!= NULL
);
1069 // Store the color back in the NMLVCUSTOMDRAW struct.
1070 pLVCD
->clrText
= data
->color
;
1074 void CGitProgressList::OnNMDblclkSvnprogress(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
1077 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1079 if (pNMLV
->iItem
< 0)
1081 if (m_options
& ProgOptDryRun
)
1082 return; //don't do anything in a dry-run.
1084 const NotificationData
* data
= m_arData
[pNMLV
->iItem
];
1088 if (data
->bConflictedActionItem
)
1090 // We've double-clicked on a conflicted item - do a three-way merge on it
1091 SVNDiff::StartConflictEditor(data
->path
);
1093 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
))
1095 // This is a modified file which has been merged on update. Diff it against base
1096 CTGitPath temporaryFile
;
1097 SVNDiff
diff(this, this->m_hWnd
, true);
1098 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1099 svn_revnum_t baseRev
= 0;
1100 diff
.DiffFileAgainstBase(data
->path
, baseRev
);
1102 else if ((!data
->bAuxItem
)&&(data
->path
.Exists())&&(!data
->path
.IsDirectory()))
1104 bool bOpenWith
= false;
1105 int ret
= (int)ShellExecute(m_hWnd
, NULL
, data
->path
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
1106 if (ret
<= HINSTANCE_ERROR
)
1110 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1111 cmd
+= data
->path
.GetWinPathString() + _T(" ");
1112 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1118 void CGitProgressList::OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1120 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1121 if (m_bThreadRunning
)
1123 if (m_nSortedColumn
== phdr
->iItem
)
1124 m_bAscending
= !m_bAscending
;
1126 m_bAscending
= TRUE
;
1127 m_nSortedColumn
= phdr
->iItem
;
1133 SetItemCountEx (static_cast<int>(m_arData
.size()));
1140 bool CGitProgressList::NotificationDataIsAux(const NotificationData
* pData
)
1142 return pData
->bAuxItem
;
1144 BOOL
CGitProgressList::Notify(const git_wc_notify_action_t action
, CString str
, const git_oid
*a
, const git_oid
*b
)
1146 NotificationData
* data
= new NotificationData();
1147 data
->action
= action
;
1148 data
->bAuxItem
= false;
1150 if (action
== git_wc_notify_update_ref
)
1152 data
->m_NewHash
= b
->id
;
1153 data
->m_OldHash
= a
->id
;
1154 data
->sActionColumnText
.LoadString(IDS_GITACTION_UPDATE_REF
);
1155 data
->sPathColumnText
.Format(_T("%s\t %s -> %s"), str
,
1156 data
->m_OldHash
.ToString().Left(g_Git
.GetShortHASHLength()),
1157 data
->m_NewHash
.ToString().Left(g_Git
.GetShortHASHLength()));
1161 m_arData
.push_back(data
);
1167 m_pAnimate
->ShowWindow(SW_HIDE
);
1170 BOOL
CGitProgressList::Notify(const git_wc_notify_action_t
/*action*/, const git_transfer_progress
*stat
)
1172 static unsigned int start
= 0;
1173 unsigned int dt
= GetCurrentTime() - start
;
1182 start
= GetCurrentTime();
1183 ds
= stat
->received_bytes
- m_TotalBytesTransferred
;
1184 speed
= ds
* 1000.0/dt
;
1185 m_TotalBytesTransferred
= stat
->received_bytes
;
1193 progress
= stat
->received_objects
+ stat
->indexed_objects
;
1195 if ((stat
->total_objects
> 1000) && m_pProgControl
&& (!m_pProgControl
->IsWindowVisible()))
1198 m_pProgControl
->ShowWindow(SW_SHOW
);
1201 if (m_pProgressLabelCtrl
&& m_pProgressLabelCtrl
->IsWindowVisible())
1202 m_pProgressLabelCtrl
->ShowWindow(SW_SHOW
);
1206 m_pProgControl
->SetPos(progress
);
1207 m_pProgControl
->SetRange32(0, 2 * stat
->total_objects
);
1209 if (m_pTaskbarList
&& m_pPostWnd
)
1211 m_pTaskbarList
->SetProgressState(m_pPostWnd
->GetSafeHwnd(), TBPF_NORMAL
);
1212 m_pTaskbarList
->SetProgressValue(m_pPostWnd
->GetSafeHwnd(), progress
, 2 * stat
->total_objects
);
1216 if (stat
->received_bytes
< 1024)
1217 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, (int64_t)stat
->received_bytes
);
1218 else if (stat
->received_bytes
< 1200000)
1219 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, (int64_t)stat
->received_bytes
/ 1024);
1221 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)stat
->received_bytes
/ 1024000.0));
1225 str
.Format(_T("%fB/s"), speed
);
1226 else if(speed
< 1024 * 1024)
1227 str
.Format(_T("%.2fKB/s"), speed
/ 1024);
1229 str
.Format(_T("%.2fMB/s"), speed
/ 1024000.0);
1231 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)str
);
1232 if (m_pProgressLabelCtrl
)
1233 m_pProgressLabelCtrl
->SetWindowText(progText
);
1238 void CGitProgressList::OnTimer(UINT_PTR nIDEvent
)
1240 if (nIDEvent
== TRANSFERTIMER
)
1244 progSpeed
.Format(IDS_SVN_PROGRESS_BYTES_SEC
, 0);
1245 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)progSpeed
);
1246 if (m_pProgressLabelCtrl
)
1247 m_pProgressLabelCtrl
->SetWindowText(progText
);
1249 KillTimer(TRANSFERTIMER
);
1251 if (nIDEvent
== VISIBLETIMER
)
1253 if (nEnsureVisibleCount
)
1254 EnsureVisible(GetItemCount()-1, false);
1255 nEnsureVisibleCount
= 0;
1259 void CGitProgressList::Sort()
1261 if(m_arData
.size() < 2)
1266 // We need to sort the blocks which lie between the auxiliary entries
1267 // This is so that any aux data stays where it was
1268 NotificationDataVect::iterator actionBlockBegin
;
1269 NotificationDataVect::iterator actionBlockEnd
= m_arData
.begin(); // We start searching from here
1273 // Search to the start of the non-aux entry in the next block
1274 actionBlockBegin
= std::find_if(actionBlockEnd
, m_arData
.end(), std::not1(std::ptr_fun(&CGitProgressList::NotificationDataIsAux
)));
1275 if(actionBlockBegin
== m_arData
.end())
1277 // There are no more actions
1280 // Now search to find the end of the block
1281 actionBlockEnd
= std::find_if(actionBlockBegin
+1, m_arData
.end(), std::ptr_fun(&CGitProgressList::NotificationDataIsAux
));
1282 // Now sort the block
1283 std::sort(actionBlockBegin
, actionBlockEnd
, &CGitProgressList::SortCompare
);
1287 bool CGitProgressList::SortCompare(const NotificationData
* pData1
, const NotificationData
* pData2
)
1290 switch (m_nSortedColumn
)
1292 case 0: //action column
1293 result
= pData1
->sActionColumnText
.Compare(pData2
->sActionColumnText
);
1295 case 1: //path column
1296 // Compare happens after switch()
1302 // Sort by path if everything else is equal
1305 result
= CTGitPath::Compare(pData1
->path
, pData2
->path
);
1313 void CGitProgressList::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1315 if (m_options
& ProgOptDryRun
)
1316 return; // don't do anything in a dry-run.
1320 int selIndex
= GetSelectionMark();
1321 if ((point
.x
== -1) && (point
.y
== -1))
1323 // Menu was invoked from the keyboard rather than by right-clicking
1325 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1326 ClientToScreen(&rect
);
1327 point
= rect
.CenterPoint();
1330 if ((selIndex
>= 0)&&(!m_bThreadRunning
))
1332 // entry is selected, thread has finished with updating so show the popup menu
1334 if (popup
.CreatePopupMenu())
1336 bool bAdded
= false;
1337 NotificationData
* data
= m_arData
[selIndex
];
1338 if ((data
)&&(!data
->path
.IsDirectory()))
1341 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1343 if (GetSelectedCount() == 1)
1345 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1350 if (data->bConflictedActionItem)
1352 if (GetSelectedCount() == 1)
1354 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1355 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1356 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1358 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1359 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1361 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1362 popup.SetDefaultItem(ID_COMPARE, FALSE);
1364 if (GetSelectedCount() == 1)
1366 if ((data
->action
== git_wc_notify_add
)||
1367 (data
->action
== git_wc_notify_revert
)||
1368 (data
->action
== git_wc_notify_resolved
)||
1369 (data
->action
== git_wc_notify_checkout
)||
1370 (data
->action
== git_wc_notify_update_ref
))
1372 popup
.AppendMenuIcon(ID_LOG
, IDS_MENULOG
,IDI_LOG
);
1373 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1374 popup
.AppendMenuIcon(ID_OPEN
, IDS_LOG_POPUP_OPEN
, IDI_OPEN
);
1375 popup
.AppendMenuIcon(ID_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1379 } // if ((data)&&(!data->path.IsDirectory()))
1380 if (GetSelectedCount() == 1)
1384 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1385 CTGitPath path
= CTGitPath(sPath
);
1386 if (!sPath
.IsEmpty())
1388 if (path
.GetDirectory().Exists())
1390 popup
.AppendMenuIcon(ID_EXPLORE
, IDS_SVNPROGRESS_MENUOPENPARENT
, IDI_EXPLORER
);
1396 if (GetSelectedCount() > 0)
1399 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1400 popup
.AppendMenuIcon(ID_COPY
, IDS_LOG_POPUP_COPYTOCLIPBOARD
,IDI_COPYCLIP
);
1405 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1407 DialogEnableWindow(IDOK
, FALSE
);
1409 //this->SetPromptApp(&theApp);
1410 theApp
.DoWaitCursor(1);
1411 bool bOpenWith
= false;
1417 POSITION pos
= GetFirstSelectedItemPosition();
1420 int nItem
= GetNextSelectedItem(pos
);
1421 NotificationData
* data
= m_arData
[nItem
];
1424 sLines
+= data
->sPathColumnText
;
1425 sLines
+= _T("\r\n");
1429 if (!sLines
.IsEmpty())
1431 CStringUtils::WriteAsciiStringToClipboard(sLines
, GetSafeHwnd());
1439 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1441 CTGitPath path
= CTGitPath(sPath
);
1442 ShellExecute(m_hWnd
, _T("explore"), path
.GetDirectory().GetWinPath(), NULL
, path
.GetDirectory().GetWinPath(), SW_SHOW
);
1449 svn_revnum_t rev
= -1;
1450 StringRevMap::iterator it
= m_UpdateStartRevMap
.end();
1451 if (data
->basepath
.IsEmpty())
1452 it
= m_UpdateStartRevMap
.begin();
1454 it
= m_UpdateStartRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1455 if (it
!= m_UpdateStartRevMap
.end())
1457 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1458 if (data
->content_state
== svn_wc_notify_state_merged
)
1460 CTGitPath basefile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1461 CTGitPath newfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_HEAD
);
1463 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, basefile
))
1465 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1466 DialogEnableWindow(IDOK
, TRUE
);
1469 // If necessary, convert the line-endings on the file before diffing
1470 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE
))
1472 CTGitPath temporaryFile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_BASE
);
1473 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_BASE
), SVNRev(SVNRev::REV_BASE
), temporaryFile
))
1475 temporaryFile
.Reset();
1480 newfile
= temporaryFile
;
1484 SetFileAttributes(newfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1485 SetFileAttributes(basefile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1486 CString revname
, wcname
, basename
;
1487 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1488 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1489 basename
.Format(IDS_DIFF_BASENAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1490 CAppUtils::StartExtMerge(basefile
, newfile
, data
->path
, data
->path
, basename
, revname
, wcname
, CString(), true);
1494 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1496 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, tempfile
))
1498 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1499 DialogEnableWindow(IDOK
, TRUE
);
1504 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1505 CString revname
, wcname
;
1506 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1507 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1508 CAppUtils::StartExtDiff(
1509 tempfile
, data
->path
, revname
, wcname
,
1510 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)));
1515 case ID_EDITCONFLICT
:
1517 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1518 SVNDiff::StartConflictEditor(CTGitPath(sPath
));
1521 case ID_CONFLICTUSETHEIRS
:
1522 case ID_CONFLICTUSEMINE
:
1523 case ID_CONFLICTRESOLVE
:
1525 svn_wc_conflict_choice_t result
= svn_wc_conflict_choose_merged
;
1528 case ID_CONFLICTUSETHEIRS
:
1529 result
= svn_wc_conflict_choose_theirs_full
;
1531 case ID_CONFLICTUSEMINE
:
1532 result
= svn_wc_conflict_choose_mine_full
;
1534 case ID_CONFLICTRESOLVE
:
1535 result
= svn_wc_conflict_choose_merged
;
1539 POSITION pos
= GetFirstSelectedItemPosition();
1540 CString sResolvedPaths
;
1543 int nItem
= GetNextSelectedItem(pos
);
1544 NotificationData
* data
= m_arData
[nItem
];
1547 if (data
->bConflictedActionItem
)
1549 if (!svn
.Resolve(data
->path
, result
, FALSE
))
1551 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1552 DialogEnableWindow(IDOK
, TRUE
);
1557 data
->color
= ::GetSysColor(COLOR_WINDOWTEXT
);
1558 data
->action
= svn_wc_notify_resolved
;
1559 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
1560 data
->bConflictedActionItem
= false;
1563 if (m_nConflicts
==0)
1565 // When the last conflict is resolved we remove
1566 // the warning which we assume is in the last line.
1567 int nIndex
= GetItemCount()-1;
1568 VERIFY(DeleteItem(nIndex
));
1570 delete m_arData
[nIndex
];
1571 m_arData
.pop_back();
1573 sResolvedPaths
+= data
->path
.GetWinPathString() + _T("\n");
1579 CString info
= BuildInfoString();
1580 SetDlgItemText(IDC_INFOTEXT
, info
);
1582 if (!sResolvedPaths
.IsEmpty())
1585 msg
.Format(IDS_SVNPROGRESS_RESOLVED
, (LPCTSTR
)sResolvedPaths
);
1586 CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
1593 CString cmd
= _T("/command:log");
1594 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1595 if(data
->action
== git_wc_notify_update_ref
)
1597 cmd
+= _T(" /path:\"") + GetPathFromColumnText(CString()) + _T("\"");
1598 if (!data
->m_OldHash
.IsEmpty())
1599 cmd
+= _T(" /startrev:") + data
->m_OldHash
.ToString();
1600 if (!data
->m_NewHash
.IsEmpty())
1601 cmd
+= _T(" /endrev:") + data
->m_NewHash
.ToString();
1604 cmd
+= _T(" /path:\"") + sPath
+ _T("\"");
1605 CAppUtils::RunTortoiseGitProc(cmd
);
1613 CString sWinPath
= GetPathFromColumnText(data
->sPathColumnText
);
1615 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, (LPCTSTR
)sWinPath
, NULL
, NULL
, SW_SHOWNORMAL
);
1616 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
1618 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1619 cmd
+= sWinPath
+ _T(" ");
1620 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1625 DialogEnableWindow(IDOK
, TRUE
);
1627 theApp
.DoWaitCursor(-1);
1634 void CGitProgressList::OnLvnBegindragSvnprogress(NMHDR
* , LRESULT
*pResult
)
1636 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1638 int selIndex
= GetSelectionMark();
1642 CDropFiles dropFiles
; // class for creating DROPFILES struct
1645 POSITION pos
= GetFirstSelectedItemPosition();
1646 while ( (index
= GetNextSelectedItem(pos
)) >= 0 )
1648 NotificationData
* data
= m_arData
[index
];
1650 if ( data
->kind
==svn_node_file
|| data
->kind
==svn_node_dir
)
1652 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1654 dropFiles
.AddFile( sPath
);
1658 if ( dropFiles
.GetCount()>0 )
1660 dropFiles
.CreateStructure();
1666 void CGitProgressList::OnSize(UINT nType
, int cx
, int cy
)
1668 CListCtrl::OnSize(nType
, cx
, cy
);
1669 if ((nType
== SIZE_RESTORED
)&&(m_bLastVisible
))
1674 int count
= GetItemCount();
1676 EnsureVisible(count
-1, false);
1680 //////////////////////////////////////////////////////////////////////////
1682 //////////////////////////////////////////////////////////////////////////
1683 bool CGitProgressList::CmdAdd(CString
& sWindowTitle
, bool& localoperation
)
1685 localoperation
= true;
1686 SetWindowTitle(IDS_PROGRS_TITLE_ADD
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1687 SetBackgroundImage(IDI_ADD_BKG
);
1688 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD
)));
1690 m_itemCountTotal
= m_targetPathList
.GetCount();
1692 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE
) == TRUE
)
1694 git_repository
*repo
= NULL
;
1697 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
1698 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
1700 gitdir
.ReleaseBuffer();
1704 gitdir
.ReleaseBuffer();
1706 if (git_repository_index(&index
, repo
))
1709 git_repository_free(repo
);
1712 if (git_index_read(index
))
1715 git_index_free(index
);
1716 git_repository_free(repo
);
1720 for (m_itemCount
= 0; m_itemCount
< m_itemCountTotal
; ++m_itemCount
)
1722 if (git_index_add_bypath(index
, CStringA(CUnicodeUtils::GetMulti(m_targetPathList
[m_itemCount
].GetGitPathString(), CP_UTF8
)).GetBuffer()))
1725 git_index_free(index
);
1726 git_repository_free(repo
);
1729 Notify(m_targetPathList
[m_itemCount
], git_wc_notify_add
);
1731 if (IsCancelled() == TRUE
)
1733 git_index_free(index
);
1734 git_repository_free(repo
);
1736 ReportUserCanceled();
1741 if (git_index_write(index
))
1744 git_index_free(index
);
1745 git_repository_free(repo
);
1749 git_index_free(index
);
1750 git_repository_free(repo
);
1754 CMassiveGitTask
mgt(L
"add -f");
1755 if (!mgt
.ExecuteWithNotify(&m_targetPathList
, m_bCancelled
, git_wc_notify_add
, this))
1759 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
1764 bool CGitProgressList::CmdCopy(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1767 ASSERT(m_targetPathList
.GetCount() == 1);
1768 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_COPY
);
1769 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1770 SetBackgroundImage(IDI_COPY_BKG
);
1773 sCmdInfo
.Format(IDS_PROGRS_CMD_COPY
,
1774 m_targetPathList
[0].IsUrl() ? (LPCTSTR
)m_targetPathList
[0].GetSVNPathString() : m_targetPathList
[0].GetWinPath(),
1775 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
1776 ReportCmd(sCmdInfo
);
1778 if (!Copy(m_targetPathList
, m_url
, m_Revision
, m_pegRev
, m_sMessage
))
1783 if (m_options
& ProgOptSwitchAfterCopy
)
1785 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
1786 m_targetPathList
[0].GetWinPath(),
1787 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
1788 ReportCmd(sCmdInfo
);
1789 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, SVNRev::REV_HEAD
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
1791 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, m_Revision
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
1800 if (SVN::PathIsURL(m_url
))
1802 CString
sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING
));
1803 ReportNotification(sMsg
);
1810 bool CGitProgressList::CmdExport(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1813 ASSERT(m_targetPathList
.GetCount() == 1);
1814 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_EXPORT
);
1815 sWindowTitle
= m_url
.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle
;
1816 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1817 SetBackgroundImage(IDI_EXPORT_BKG
);
1819 if (m_options
& ProgOptEolCRLF
)
1821 if (m_options
& ProgOptEolLF
)
1823 if (m_options
& ProgOptEolCR
)
1825 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT
)));
1826 if (!Export(m_url
, m_targetPathList
[0], m_Revision
, m_Revision
, TRUE
, m_options
& ProgOptIgnoreExternals
, m_depth
, NULL
, FALSE
, eol
))
1835 bool CGitProgressList::CmdRename(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1838 ASSERT(m_targetPathList
.GetCount() == 1);
1839 if ((!m_targetPathList
[0].IsUrl())&&(!m_url
.IsUrl()))
1840 localoperation
= true;
1841 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RENAME
);
1842 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1843 SetBackgroundImage(IDI_RENAME_BKG
);
1844 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME
)));
1845 if (!Move(m_targetPathList
, m_url
, m_Revision
, m_sMessage
))
1854 bool CGitProgressList::CmdResolve(CString
& sWindowTitle
, bool& localoperation
)
1857 localoperation
= true;
1858 ASSERT(m_targetPathList
.GetCount() == 1);
1859 SetWindowTitle(IDS_PROGRS_TITLE_RESOLVE
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1860 SetBackgroundImage(IDI_RESOLVE_BKG
);
1861 // check if the file may still have conflict markers in it.
1862 //BOOL bMarkers = FALSE;
1864 m_itemCountTotal
= m_targetPathList
.GetCount();
1865 for (m_itemCount
= 0; m_itemCount
< m_itemCountTotal
; ++m_itemCount
)
1867 CString cmd
,out
,tempmergefile
;
1868 cmd
.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList
[m_itemCount
].GetGitPathString());
1869 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1871 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1872 m_bErrorsOccurred
=true;
1876 CAppUtils::RemoveTempMergeFile((CTGitPath
&)m_targetPathList
[m_itemCount
]);
1878 Notify(m_targetPathList
[m_itemCount
], git_wc_notify_resolved
);
1881 if ((m_options
& ProgOptSkipConflictCheck
) == 0)
1885 for (INT_PTR fileindex
=0; (fileindex
<m_targetPathList
.GetCount()) && (bMarkers
==FALSE
); ++fileindex
)
1887 if (!m_targetPathList
[fileindex
].IsDirectory())
1889 CStdioFile
file(m_targetPathList
[fileindex
].GetWinPath(), CFile::typeBinary
| CFile::modeRead
);
1890 CString strLine
= _T("");
1891 while (file
.ReadString(strLine
))
1893 if (strLine
.Find(_T("<<<<<<<"))==0)
1903 catch (CFileException
* pE
)
1905 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException in Resolve!\n");
1906 TCHAR error
[10000] = {0};
1907 pE
->GetErrorMessage(error
, 10000);
1915 if (CMessageBox::Show(m_hWnd
, IDS_PROGRS_REVERTMARKERS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
1917 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
1918 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
1919 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
1924 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
1925 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
1926 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
1929 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
1934 bool CGitProgressList::CmdRevert(CString
& sWindowTitle
, bool& localoperation
)
1937 localoperation
= true;
1938 SetWindowTitle(IDS_PROGRS_TITLE_REVERT
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1939 SetBackgroundImage(IDI_REVERT_BKG
);
1941 m_itemCountTotal
= 2 * m_selectedPaths
.GetCount();
1942 CTGitPathList delList
;
1943 for (m_itemCount
= 0; m_itemCount
< m_selectedPaths
.GetCount(); ++m_itemCount
)
1947 path
.SetFromWin(g_Git
.m_CurrentDir
+ _T("\\") + m_selectedPaths
[m_itemCount
].GetWinPath());
1948 action
= m_selectedPaths
[m_itemCount
].m_Action
;
1949 /* rename file can't delete because it needs original file*/
1950 if((!(action
& CTGitPath::LOGACTIONS_ADDED
)) &&
1951 (!(action
& CTGitPath::LOGACTIONS_REPLACED
)))
1952 delList
.AddPath(path
);
1954 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
1955 delList
.DeleteAllFiles(true);
1957 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT
)));
1958 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
1960 if(g_Git
.Revert(_T("HEAD"), (CTGitPath
&)m_selectedPaths
[i
]))
1962 CMessageBox::Show(NULL
,_T("Revert Fail"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1963 m_bErrorsOccurred
=true;
1966 Notify(m_selectedPaths
[i
], git_wc_notify_revert
);
1969 if (IsCancelled() == TRUE
)
1971 ReportUserCanceled();
1976 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths
);
1981 bool CGitProgressList::CmdSwitch(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
1984 ASSERT(m_targetPathList
.GetCount() == 1);
1986 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SWITCH
);
1987 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
1988 SetBackgroundImage(IDI_SWITCH_BKG
);
1990 if (st
.GetStatus(m_targetPathList
[0]) != (-2))
1992 if (st
.status
->entry
!= NULL
)
1994 rev
= st
.status
->entry
->revision
;
1999 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2000 m_targetPathList
[0].GetWinPath(), (LPCTSTR
)m_url
.GetSVNPathString(),
2001 (LPCTSTR
)m_Revision
.ToString());
2002 ReportCmd(sCmdInfo
);
2004 bool depthIsSticky
= true;
2005 if (m_depth
== svn_depth_unknown
)
2006 depthIsSticky
= false;
2007 if (!Switch(m_targetPathList
[0], m_url
, m_Revision
, m_Revision
, m_depth
, depthIsSticky
, m_options
& ProgOptIgnoreExternals
))
2012 m_UpdateStartRevMap
[m_targetPathList
[0].GetSVNApiPath(pool
)] = rev
;
2013 if ((m_RevisionEnd
>= 0)&&(rev
>= 0)
2014 &&((LONG
)m_RevisionEnd
> (LONG
)rev
))
2016 GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2021 bool CGitProgressList::CmdClone(CString
& sWindowTitle
, bool& /*localoperation*/)
2023 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2025 // should never run to here
2029 this->m_TotalBytesTransferred
= 0;
2031 SetWindowTitle(IDS_PROGRS_TITLE_CLONE
, m_url
.GetGitPathString(), sWindowTitle
);
2032 SetBackgroundImage(IDI_SWITCH_BKG
);
2033 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE
)));
2035 if (m_url
.IsEmpty() || m_targetPathList
.GetCount() == 0)
2038 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2039 CStringA path
= CUnicodeUtils::GetMulti(m_targetPathList
[0].GetWinPathString(),CP_UTF8
);
2041 git_repository
*cloned_repo
= NULL
;
2042 git_remote
*origin
= NULL
;
2043 git_checkout_opts checkout_opts
= GIT_CHECKOUT_OPTS_INIT
;
2047 git_clone_options clone_opts
= GIT_CLONE_OPTIONS_INIT
;
2049 clone_opts
.checkout_opts
= checkout_opts
;
2051 clone_opts
.checkout_opts
.checkout_strategy
= m_bNoCheckout
? GIT_CHECKOUT_NONE
: GIT_CHECKOUT_SAFE_CREATE
;
2052 clone_opts
.checkout_opts
.progress_cb
= CheckoutCallback
;
2053 clone_opts
.checkout_opts
.progress_payload
= this;
2055 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2057 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2058 callbacks
.progress
= RemoteProgressCallback
;
2059 callbacks
.completion
= RemoteCompletionCallback
;
2060 callbacks
.payload
= this;
2062 clone_opts
.remote_callbacks
= &callbacks
;
2064 CStringA refspecA
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
);
2065 if (!m_RefSpec
.IsEmpty())
2066 clone_opts
.checkout_branch
= refspecA
.GetBuffer();
2067 CStringA remoteA
= CUnicodeUtils::GetMulti(m_remote
, CP_UTF8
);
2068 if (!m_remote
.IsEmpty())
2069 clone_opts
.remote_name
= remoteA
.GetBuffer();
2071 clone_opts
.fetch_progress_cb
= FetchCallback
;
2072 clone_opts
.fetch_progress_payload
= this;
2074 clone_opts
.cred_acquire_cb
= CAppUtils::Git2GetUserPassword
;
2076 clone_opts
.bare
= m_bBare
;
2078 git_repository_init_options init_options
= GIT_REPOSITORY_INIT_OPTIONS_INIT
;
2079 init_options
.flags
= GIT_REPOSITORY_INIT_MKPATH
| GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE
;
2080 init_options
.flags
|= m_bBare
? GIT_REPOSITORY_INIT_BARE
: 0;
2081 clone_opts
.init_options
= &init_options
;
2085 m_pAnimate
->ShowWindow(SW_SHOW
);
2086 m_pAnimate
->Play(0, INT_MAX
, INT_MAX
);
2088 error
= git_clone(&cloned_repo
, url
, path
, &clone_opts
);
2093 m_pAnimate
->ShowWindow(SW_HIDE
);
2096 refspecA
.ReleaseBuffer();
2097 remoteA
.ReleaseBuffer();
2098 git_remote_free(origin
);
2104 else if (cloned_repo
)
2105 git_repository_free(cloned_repo
);
2108 bool CGitProgressList::CmdSendMail(CString
& sWindowTitle
, bool& /*localoperation*/)
2111 SetWindowTitle(IDS_PROGRS_TITLE_SENDMAIL
, g_Git
.m_CurrentDir
+ _T("\\") + m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2112 //SetBackgroundImage(IDI_ADD_BKG);
2113 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL
)));
2115 return m_SendMail
->Send(m_targetPathList
, this) == 0;
2118 bool CGitProgressList::CmdFetch(CString
& sWindowTitle
, bool& /*localoperation*/)
2120 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2122 // should never run to here
2126 this->m_TotalBytesTransferred
= 0;
2128 SetWindowTitle(IDS_PROGRS_TITLE_FETCH
, g_Git
.m_CurrentDir
, sWindowTitle
);
2129 SetBackgroundImage(IDI_UPDATE_BKG
);
2130 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
)) + _T(" ") + m_url
.GetGitPathString() + _T(" ") + m_RefSpec
);
2132 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2133 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
2134 CStringA remotebranch
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
);
2136 git_remote
*remote
= NULL
;
2137 git_repository
*repo
= NULL
;
2144 m_pAnimate
->ShowWindow(SW_SHOW
);
2145 m_pAnimate
->Play(0, INT_MAX
, INT_MAX
);
2148 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
2150 gitdir
.ReleaseBuffer();
2156 // first try with a named remote (e.g. "origin")
2157 if (git_remote_load(&remote
, repo
, url
) < 0)
2159 // retry with repository located at a specific url
2160 if (git_remote_create_inmemory(&remote
, repo
, NULL
, url
) < 0)
2168 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2170 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2171 callbacks
.progress
= RemoteProgressCallback
;
2172 callbacks
.completion
= RemoteCompletionCallback
;
2173 callbacks
.payload
= this;
2175 git_remote_set_callbacks(remote
, &callbacks
);
2176 git_remote_set_cred_acquire_cb(remote
, CAppUtils::Git2GetUserPassword
, NULL
);
2177 git_remote_set_autotag(remote
, (git_remote_autotag_option_t
)m_AutoTag
);
2179 if (!remotebranch
.IsEmpty() && git_remote_add_fetch(remote
, remotebranch
))
2186 // Connect to the remote end specifying that we want to fetch
2187 // information from it.
2188 if (git_remote_connect(remote
, GIT_DIRECTION_FETCH
) < 0) {
2194 // Download the packfile and index it. This function updates the
2195 // amount of received data and the indexer stats which lets you
2196 // inform the user about progress.
2197 if (git_remote_download(remote
, FetchCallback
, this) < 0) {
2205 m_pAnimate
->ShowWindow(SW_HIDE
);
2207 // Update the references in the remote's namespace to point to the
2208 // right commits. This may be needed even if there was no packfile
2209 // to download, which can happen e.g. when the branches have been
2210 // changed but all the neede objects are available locally.
2211 if (git_remote_update_tips(remote
) < 0)
2218 git_remote_disconnect(remote
);
2222 git_remote_free(remote
);
2223 git_repository_free(repo
);
2225 m_pAnimate
->ShowWindow(SW_HIDE
);
2229 bool CGitProgressList::CmdReset(CString
& sWindowTitle
, bool& /*localoperation*/)
2231 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
2233 // should never run to here
2238 SetWindowTitle(IDS_PROGRS_TITLE_RESET
, g_Git
.m_CurrentDir
, sWindowTitle
);
2239 SetBackgroundImage(IDI_UPDATE_BKG
);
2240 int resetTypesResource
[] = { IDS_RESET_SOFT
, IDS_RESET_MIXED
, IDS_RESET_HARD
};
2241 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_RESET
)) + _T(" ") + CString(MAKEINTRESOURCE(resetTypesResource
[m_resetType
])) + _T(" ") + m_revision
);
2243 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
2245 git_repository
*repo
= NULL
;
2252 m_pAnimate
->ShowWindow(SW_SHOW
);
2253 m_pAnimate
->Play(0, INT_MAX
, INT_MAX
);
2256 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
2258 gitdir
.ReleaseBuffer();
2264 CStringA revstr
= CUnicodeUtils::GetUTF8(m_revision
);
2266 git_revparse_single(&target
, repo
, revstr
);
2267 if (git_reset(repo
, target
, (git_reset_t
)(m_resetType
+ 1)))
2275 git_repository_free(repo
);
2277 m_pAnimate
->ShowWindow(SW_HIDE
);
2282 void CGitProgressList::Init()
2284 SetExtendedStyle (LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
);
2287 int c
= ((CHeaderCtrl
*)(GetDlgItem(0)))->GetItemCount()-1;
2292 temp
.LoadString(IDS_PROGRS_ACTION
);
2293 InsertColumn(0, temp
);
2294 temp
.LoadString(IDS_PROGRS_PATH
);
2295 InsertColumn(1, temp
);
2297 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
2298 if (m_pThread
==NULL
)
2300 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED
)));
2304 m_pThread
->m_bAutoDelete
= FALSE
;
2305 m_pThread
->ResumeThread();
2308 // Call this early so that the column headings aren't hidden before any
2312 SetTimer(VISIBLETIMER
, 300, NULL
);
2316 void CGitProgressList::OnClose()
2318 // TODO: Add your message handler code here and/or call default
2321 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
2322 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2326 m_bCancelled
= TRUE
;
2329 CListCtrl::OnClose();
2333 BOOL
CGitProgressList::PreTranslateMessage(MSG
* pMsg
)
2335 // TODO: Add your specialized code here and/or call the base class
2336 if (pMsg
->message
== WM_KEYDOWN
)
2338 if (pMsg
->wParam
== 'A')
2340 if (GetKeyState(VK_CONTROL
)&0x8000)
2342 // Ctrl-A -> select all
2343 SetSelectionMark(0);
2344 for (int i
=0; i
<GetItemCount(); ++i
)
2346 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2350 if ((pMsg
->wParam
== 'C')||(pMsg
->wParam
== VK_INSERT
))
2352 int selIndex
= GetSelectionMark();
2355 if (GetKeyState(VK_CONTROL
)&0x8000)
2357 //Ctrl-C -> copy to clipboard
2359 POSITION pos
= GetFirstSelectedItemPosition();
2364 int nItem
= GetNextSelectedItem(pos
);
2365 CString sAction
= GetItemText(nItem
, 0);
2366 CString sPath
= GetItemText(nItem
, 1);
2367 CString sMime
= GetItemText(nItem
, 2);
2368 CString sLogCopyText
;
2369 sLogCopyText
.Format(_T("%s: %s %s\r\n"),
2370 (LPCTSTR
)sAction
, (LPCTSTR
)sPath
, (LPCTSTR
)sMime
);
2371 sClipdata
+= sLogCopyText
;
2373 CStringUtils::WriteAsciiStringToClipboard(sClipdata
);
2378 } // if (pMsg->message == WM_KEYDOWN)
2379 return CListCtrl::PreTranslateMessage(pMsg
);
2382 CString
CGitProgressList::GetPathFromColumnText(const CString
& sColumnText
)
2384 CString sPath
= sColumnText
;
2385 if (sPath
.Find(':')<0)
2387 // the path is not absolute: add the common root of all paths to it
2388 sPath
= g_Git
.m_CurrentDir
+ _T("\\") + sColumnText
;
2393 void CGitProgressList::SetWindowTitle(UINT id
, const CString
& urlorpath
, CString
& dialogname
)
2395 if (!m_bSetTitle
|| !m_pPostWnd
)
2398 dialogname
.LoadString(id
);
2399 CAppUtils::SetWindowTitle(m_pPostWnd
->GetSafeHwnd(), urlorpath
, dialogname
);