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 "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
27 #include "GitStatus.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
41 #include "ShellUpdater.h"
43 #include "BugTraqAssociations.h"
45 #include "MassiveGitTask.h"
46 #include "SmartHandle.h"
48 static UINT WM_GITPROGRESS
= RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
50 BOOL
CGitProgressDlg::m_bAscending
= FALSE
;
51 int CGitProgressDlg::m_nSortedColumn
= -1;
53 #define TRANSFERTIMER 100
54 #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(CGitProgressDlg
, CResizableStandAloneDialog
)
72 CGitProgressDlg::CGitProgressDlg(CWnd
* pParent
/*=NULL*/)
73 : CResizableStandAloneDialog(CGitProgressDlg::IDD
, pParent
)
76 , m_bErrorsOccurred(false)
78 , m_bNoCheckout(false)
79 , m_AutoTag(GIT_REMOTE_DOWNLOAD_TAGS_AUTO
)
80 , m_options(ProgOptNone
)
82 , m_Revision(_T("HEAD"))
84 , m_bLockWarning(false)
85 , m_bLockExists(false)
86 , m_bThreadRunning(FALSE
)
88 , m_bMergesAddsDeletesOccurred(FALSE
)
89 , m_dwCloseOnEnd((DWORD
)-1)
90 , m_bFinishedItemAdded(false)
91 , m_bLastVisible(false)
92 // , m_depth(svn_depth_unknown)
94 , m_itemCountTotal(-1)
95 , m_AlwaysConflicted(false)
96 , m_BugTraqProvider(NULL
)
97 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN
))
98 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY
))
103 CGitProgressDlg::~CGitProgressDlg()
105 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
109 if(m_pThread
!= NULL
)
115 void CGitProgressDlg::DoDataExchange(CDataExchange
* pDX
)
117 CResizableStandAloneDialog::DoDataExchange(pDX
);
118 DDX_Control(pDX
, IDC_SVNPROGRESS
, m_ProgList
);
119 DDX_Control(pDX
, IDC_TITLE_ANIMATE
, m_Animate
);
122 BEGIN_MESSAGE_MAP(CGitProgressDlg
, CResizableStandAloneDialog
)
123 ON_BN_CLICKED(IDC_LOGBUTTON
, OnBnClickedLogbutton
)
124 ON_NOTIFY(NM_CUSTOMDRAW
, IDC_SVNPROGRESS
, OnNMCustomdrawSvnprogress
)
126 ON_NOTIFY(NM_DBLCLK
, IDC_SVNPROGRESS
, OnNMDblclkSvnprogress
)
127 ON_NOTIFY(HDN_ITEMCLICK
, 0, OnHdnItemclickSvnprogress
)
130 ON_REGISTERED_MESSAGE(WM_GITPROGRESS
, OnGitProgress
)
132 ON_EN_SETFOCUS(IDC_INFOTEXT
, &CGitProgressDlg::OnEnSetfocusInfotext
)
133 ON_NOTIFY(LVN_BEGINDRAG
, IDC_SVNPROGRESS
, &CGitProgressDlg::OnLvnBegindragSvnprogress
)
135 ON_NOTIFY(LVN_GETDISPINFO
, IDC_SVNPROGRESS
, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress
)
136 ON_BN_CLICKED(IDC_NONINTERACTIVE
, &CGitProgressDlg::OnBnClickedNoninteractive
)
137 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER
, OnShowConflictResolver
)
138 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
142 BOOL
CGitProgressDlg::Cancel()
147 LRESULT
CGitProgressDlg::OnShowConflictResolver(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
150 CConflictResolveDlg
dlg(this);
151 const svn_wc_conflict_description_t
*description
= (svn_wc_conflict_description_t
*)lParam
;
154 dlg
.SetConflictDescription(description
);
157 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
159 if (dlg
.DoModal() == IDOK
)
161 if (dlg
.GetResult() == svn_wc_conflict_choose_postpone
)
163 // if the result is conflicted and the dialog returned IDOK,
164 // that means we should not ask again in case of a conflict
165 m_AlwaysConflicted
= true;
166 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE
)->GetSafeHwnd(), BM_SETCHECK
, BST_CHECKED
, 0);
169 m_mergedfile
= dlg
.GetMergedFile();
170 m_bCancelled
= dlg
.IsCancelled();
172 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
173 return dlg
.GetResult();
176 return svn_wc_conflict_choose_postpone
;
181 svn_wc_conflict_choice_t
CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t
*description
, CString
& mergedfile
)
183 // we only bother the user when merging
184 if (((m_Command
== GitProgress_Merge
)||(m_Command
== GitProgress_MergeAll
)||(m_Command
== GitProgress_MergeReintegrate
))&&(!m_AlwaysConflicted
)&&(description
))
186 // we're in a worker thread here. That means we must not show a dialog from the thread
187 // but let the UI thread do it.
188 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
189 LRESULT dlgResult
= ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER
, 0, (LPARAM
)description
);
190 mergedfile
= m_mergedfile
;
191 return (svn_wc_conflict_choice_t
)dlgResult
;
194 return svn_wc_conflict_choose_postpone
;
197 void CGitProgressDlg::AddItemToList()
199 int totalcount
= m_ProgList
.GetItemCount();
201 m_ProgList
.SetItemCountEx(totalcount
+1, LVSICF_NOSCROLL
|LVSICF_NOINVALIDATEALL
);
202 // make columns width fit
203 if (iFirstResized
< 30)
205 // only resize the columns for the first 30 or so entries.
206 // after that, don't resize them anymore because that's an
207 // expensive function call and the columns will be sized
208 // close enough already.
213 // Make sure the item is *entirely* visible even if the horizontal
214 // scroll bar is visible.
215 int count
= m_ProgList
.GetCountPerPage();
216 if (totalcount
<= (m_ProgList
.GetTopIndex() + count
+ nEnsureVisibleCount
+ 2))
218 ++nEnsureVisibleCount
;
219 m_bLastVisible
= true;
223 nEnsureVisibleCount
= 0;
225 m_bLastVisible
= false;
230 BOOL
CGitProgressDlg::Notify(const CTGitPath
& path
, git_wc_notify_action_t action
,
234 svn_node_kind_t kind, const CString& mime_type,
235 svn_wc_notify_state_t content_state,
236 svn_wc_notify_state_t prop_state, LONG rev,
237 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
238 const CString& changelistname,
239 svn_merge_range_t * range,
240 svn_error_t * err, apr_pool_t * pool
243 bool bNoNotify
= false;
244 bool bDoAddData
= true;
245 NotificationData
* data
= new NotificationData();
247 data
->action
= action
;
248 data
->sPathColumnText
=path
.GetGitPathString();
249 data
->bAuxItem
= false;
251 this->m_Animate
.ShowWindow(SW_HIDE
);
255 data
->mime_type
= mime_type
;
256 data
->content_state
= content_state
;
257 data
->prop_state
= prop_state
;
259 data
->lock_state
= lock_state
;
260 data
->changelistname
= changelistname
;
261 if ((lock
)&&(lock
->owner
))
262 data
->owner
= CUnicodeUtils::GetUnicode(lock
->owner
);
263 data
->sPathColumnText
= path
.GetUIPathString();
264 if (!m_basePath
.IsEmpty())
265 data
->basepath
= m_basePath
;
267 data
->merge_range
= *range
;
269 switch (data
->action
)
271 case git_wc_notify_add
:
272 //case svn_wc_notify_update_add:
273 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
275 // data->color = m_Colors.GetColor(CColors::Conflict);
276 // data->bConflictedActionItem = true;
277 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
282 // m_bMergesAddsDeletesOccurred = true;
283 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADD
);
284 data
->color
= m_Colors
.GetColor(CColors::Added
);
287 case git_wc_notify_sendmail_start
:
288 data
->bAuxItem
= true;
289 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_START
);
290 data
->color
= m_Colors
.GetColor(CColors::Modified
);
293 case git_wc_notify_sendmail_error
:
294 data
->bAuxItem
= true;
295 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_ERROR
);
297 data
->sPathColumnText
= *strErr
;
299 data
->sPathColumnText
.Empty();
300 data
->color
= m_Colors
.GetColor(CColors::Modified
);
303 case git_wc_notify_sendmail_done
:
305 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_DONE
);
306 data
->sPathColumnText
.Empty();
307 data
->color
= m_Colors
.GetColor(CColors::Modified
);
310 case git_wc_notify_sendmail_retry
:
311 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SENDMAIL_RETRY
);
312 data
->sPathColumnText
.Empty();
313 data
->color
= m_Colors
.GetColor(CColors::Modified
);
317 case git_wc_notify_resolved
:
318 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
321 case git_wc_notify_revert
:
322 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REVERT
);
325 case git_wc_notify_checkout
:
326 data
->sActionColumnText
.LoadString(IDS_PROGRS_CMD_CHECKOUT
);
327 data
->color
= m_Colors
.GetColor(CColors::Added
);
328 data
->bAuxItem
= false;
332 case svn_wc_notify_commit_added
:
333 data
->sActionColumnText
.LoadString(IDS_SVNACTION_ADDING
);
334 data
->color
= m_Colors
.GetColor(CColors::Added
);
336 case svn_wc_notify_copy
:
337 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COPY
);
339 case svn_wc_notify_commit_modified
:
340 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MODIFIED
);
341 data
->color
= m_Colors
.GetColor(CColors::Modified
);
343 case svn_wc_notify_delete
:
344 case svn_wc_notify_update_delete
:
345 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETE
);
346 m_bMergesAddsDeletesOccurred
= true;
347 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
349 case svn_wc_notify_commit_deleted
:
350 data
->sActionColumnText
.LoadString(IDS_SVNACTION_DELETING
);
351 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
353 case svn_wc_notify_restore
:
354 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESTORE
);
357 case svn_wc_notify_update_replace
:
358 case svn_wc_notify_commit_replaced
:
359 data
->sActionColumnText
.LoadString(IDS_SVNACTION_REPLACED
);
360 data
->color
= m_Colors
.GetColor(CColors::Deleted
);
362 case svn_wc_notify_exists
:
363 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
365 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
366 data
->bConflictedActionItem
= true;
368 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
370 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
372 data
->color
= m_Colors
.GetColor(CColors::Merged
);
373 m_bMergesAddsDeletesOccurred
= true;
374 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
377 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXISTS
);
379 case svn_wc_notify_update_update
:
380 // if this is an inoperative dir change, don't show the notification.
381 // an inoperative dir change is when a directory gets updated without
382 // any real change in either text or properties.
383 if ((kind
== svn_node_dir
)
384 && ((prop_state
== svn_wc_notify_state_inapplicable
)
385 || (prop_state
== svn_wc_notify_state_unknown
)
386 || (prop_state
== svn_wc_notify_state_unchanged
)))
391 if ((data
->content_state
== svn_wc_notify_state_conflicted
) || (data
->prop_state
== svn_wc_notify_state_conflicted
))
393 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
394 data
->bConflictedActionItem
= true;
396 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CONFLICTED
);
398 else if ((data
->content_state
== svn_wc_notify_state_merged
) || (data
->prop_state
== svn_wc_notify_state_merged
))
400 data
->color
= m_Colors
.GetColor(CColors::Merged
);
401 m_bMergesAddsDeletesOccurred
= true;
402 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGED
);
404 else if (((data
->content_state
!= svn_wc_notify_state_unchanged
)&&(data
->content_state
!= svn_wc_notify_state_unknown
)) ||
405 ((data
->prop_state
!= svn_wc_notify_state_unchanged
)&&(data
->prop_state
!= svn_wc_notify_state_unknown
)))
407 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UPDATE
);
414 if (lock_state
== svn_wc_notify_lock_state_unlocked
)
416 CString
temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED
));
417 data
->sActionColumnText
+= _T(", ") + temp
;
421 case svn_wc_notify_update_external
:
422 // For some reason we build a list of externals...
423 m_ExtStack
.AddHead(path
.GetUIPathString());
424 data
->sActionColumnText
.LoadString(IDS_SVNACTION_EXTERNAL
);
425 data
->bAuxItem
= true;
428 case svn_wc_notify_update_completed
:
430 data
->sActionColumnText
.LoadString(IDS_SVNACTION_COMPLETED
);
431 data
->bAuxItem
= true;
432 bool bEmpty
= !!m_ExtStack
.IsEmpty();
434 data
->sPathColumnText
.Format(IDS_PROGRS_PATHATREV
, (LPCTSTR
)m_ExtStack
.RemoveHead(), rev
);
436 data
->sPathColumnText
.Format(IDS_PROGRS_ATREV
, rev
);
438 if ((m_nConflicts
>0)&&(bEmpty
))
440 // We're going to add another aux item - let's shove this current onto the list first
441 // I don't really like this, but it will do for the moment.
442 m_arData
.push_back(data
);
445 data
= new NotificationData();
446 data
->bAuxItem
= true;
447 data
->sActionColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING
);
448 data
->sPathColumnText
.LoadString(IDS_PROGRS_CONFLICTSOCCURED
);
449 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
450 CSoundUtils::PlayTSVNWarning();
451 // This item will now be added after the switch statement
453 if (!m_basePath
.IsEmpty())
454 m_FinishedRevMap
[m_basePath
.GetSVNApiPath(pool
)] = rev
;
456 m_bFinishedItemAdded
= true;
459 case svn_wc_notify_commit_postfix_txdelta
:
460 data
->sActionColumnText
.LoadString(IDS_SVNACTION_POSTFIX
);
462 case svn_wc_notify_failed_revert
:
463 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDREVERT
);
465 case svn_wc_notify_status_completed
:
466 case svn_wc_notify_status_external
:
467 data
->sActionColumnText
.LoadString(IDS_SVNACTION_STATUS
);
469 case svn_wc_notify_skip
:
470 if ((content_state
== svn_wc_notify_state_missing
)||(content_state
== svn_wc_notify_state_obstructed
)||(content_state
== svn_wc_notify_state_conflicted
))
472 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIPMISSING
);
474 // The color settings dialog describes the red color with
475 // "possible or real conflict / obstructed" which also applies to
476 // skipped targets during a merge. So we just use the same color.
477 data
->color
= m_Colors
.GetColor(CColors::Conflict
);
480 data
->sActionColumnText
.LoadString(IDS_SVNACTION_SKIP
);
482 case svn_wc_notify_locked
:
483 if ((lock
)&&(lock
->owner
))
484 data
->sActionColumnText
.Format(IDS_SVNACTION_LOCKEDBY
, (LPCTSTR
)CUnicodeUtils::GetUnicode(lock
->owner
));
486 case svn_wc_notify_unlocked
:
487 data
->sActionColumnText
.LoadString(IDS_SVNACTION_UNLOCKED
);
489 case svn_wc_notify_failed_lock
:
490 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDLOCK
);
491 m_arData
.push_back(data
);
493 ReportError(SVN::GetErrorString(err
));
495 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
496 m_bLockWarning
= true;
497 if (err
->apr_err
== SVN_ERR_FS_PATH_ALREADY_LOCKED
)
498 m_bLockExists
= true;
500 case svn_wc_notify_failed_unlock
:
501 data
->sActionColumnText
.LoadString(IDS_SVNACTION_FAILEDUNLOCK
);
502 m_arData
.push_back(data
);
504 ReportError(SVN::GetErrorString(err
));
506 if (err
->apr_err
== SVN_ERR_FS_OUT_OF_DATE
)
507 m_bLockWarning
= true;
509 case svn_wc_notify_changelist_set
:
510 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTSET
, (LPCTSTR
)data
->changelistname
);
512 case svn_wc_notify_changelist_clear
:
513 data
->sActionColumnText
.LoadString(IDS_SVNACTION_CHANGELISTCLEAR
);
515 case svn_wc_notify_changelist_moved
:
516 data
->sActionColumnText
.Format(IDS_SVNACTION_CHANGELISTMOVED
, (LPCTSTR
)data
->changelistname
);
518 case svn_wc_notify_foreign_merge_begin
:
519 case svn_wc_notify_merge_begin
:
521 data
->sActionColumnText
.LoadString(IDS_SVNACTION_MERGEBEGINNONE
);
522 else if ((data
->merge_range
.start
== data
->merge_range
.end
) || (data
->merge_range
.start
== data
->merge_range
.end
- 1))
523 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLE
, data
->merge_range
.end
);
524 else if (data
->merge_range
.start
- 1 == data
->merge_range
.end
)
525 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE
, data
->merge_range
.start
);
526 else if (data
->merge_range
.start
< data
->merge_range
.end
)
527 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE
, data
->merge_range
.start
+ 1, data
->merge_range
.end
);
529 data
->sActionColumnText
.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE
, data
->merge_range
.start
, data
->merge_range
.end
+ 1);
530 data
->bAuxItem
= true;
535 } // switch (data->action)
543 m_arData
.push_back(data
);
545 if ((!data
->bAuxItem
) && (m_itemCount
> 0))
547 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
548 progControl
->ShowWindow(SW_SHOW
);
549 progControl
->SetPos(m_itemCount
);
550 progControl
->SetRange32(0, m_itemCountTotal
);
553 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
554 m_pTaskbarList
->SetProgressValue(m_hWnd
, m_itemCountTotal
- m_itemCount
, m_itemCountTotal
);
555 m_pTaskbarList
->SetProgressValue(m_hWnd
, m_itemCount
, m_itemCountTotal
);
559 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
562 // bSecondResized = TRUE;
570 CString
CGitProgressDlg::BuildInfoString()
573 if(this->m_Command
== GitProgress_Resolve
)
574 infotext
= _T("You need commit your change after resolve conflict");
591 for (size_t i
=0; i
<m_arData
.size(); ++i
)
593 const NotificationData
* dat
= m_arData
[i
];
596 case svn_wc_notify_add
:
597 case svn_wc_notify_update_add
:
598 case svn_wc_notify_commit_added
:
599 if (dat
->bConflictedActionItem
)
604 case svn_wc_notify_copy
:
607 case svn_wc_notify_delete
:
608 case svn_wc_notify_update_delete
:
609 case svn_wc_notify_commit_deleted
:
612 case svn_wc_notify_restore
:
615 case svn_wc_notify_revert
:
618 case svn_wc_notify_resolved
:
621 case svn_wc_notify_update_update
:
622 if (dat
->bConflictedActionItem
)
624 else if ((dat
->content_state
== svn_wc_notify_state_merged
) || (dat
->prop_state
== svn_wc_notify_state_merged
))
629 case svn_wc_notify_commit_modified
:
632 case svn_wc_notify_skip
:
635 case svn_wc_notify_commit_replaced
:
642 temp
.LoadString(IDS_SVNACTION_CONFLICTED
);
644 temp
.Format(_T(":%d "), conflicted
);
649 temp
.LoadString(IDS_SVNACTION_SKIP
);
651 infotext
.AppendFormat(_T(":%d "), skipped
);
655 temp
.LoadString(IDS_SVNACTION_MERGED
);
657 infotext
.AppendFormat(_T(":%d "), merged
);
661 temp
.LoadString(IDS_SVNACTION_ADD
);
663 infotext
.AppendFormat(_T(":%d "), added
);
667 temp
.LoadString(IDS_SVNACTION_DELETE
);
669 infotext
.AppendFormat(_T(":%d "), deleted
);
673 temp
.LoadString(IDS_SVNACTION_MODIFIED
);
675 infotext
.AppendFormat(_T(":%d "), modified
);
679 temp
.LoadString(IDS_SVNACTION_COPY
);
681 infotext
.AppendFormat(_T(":%d "), copied
);
685 temp
.LoadString(IDS_SVNACTION_REPLACED
);
687 infotext
.AppendFormat(_T(":%d "), replaced
);
691 temp
.LoadString(IDS_SVNACTION_UPDATE
);
693 infotext
.AppendFormat(_T(":%d "), updated
);
697 temp
.LoadString(IDS_SVNACTION_RESTORE
);
699 infotext
.AppendFormat(_T(":%d "), restored
);
703 temp
.LoadString(IDS_SVNACTION_REVERT
);
705 infotext
.AppendFormat(_T(":%d "), reverted
);
709 temp
.LoadString(IDS_SVNACTION_RESOLVE
);
711 infotext
.AppendFormat(_T(":%d "), resolved
);
717 void CGitProgressDlg::SetSelectedList(const CTGitPathList
& selPaths
)
719 m_selectedPaths
= selPaths
;
722 void CGitProgressDlg::ResizeColumns()
724 m_ProgList
.SetRedraw(FALSE
);
726 TCHAR textbuf
[MAX_PATH
];
728 int maxcol
= ((CHeaderCtrl
*)(m_ProgList
.GetDlgItem(0)))->GetItemCount()-1;
729 for (int col
= 0; col
<= maxcol
; ++col
)
731 // find the longest width of all items
732 int count
= m_ProgList
.GetItemCount();
735 hdi
.pszText
= textbuf
;
736 hdi
.cchTextMax
= sizeof(textbuf
);
737 ((CHeaderCtrl
*)(m_ProgList
.GetDlgItem(0)))->GetItem(col
, &hdi
);
738 int cx
= m_ProgList
.GetStringWidth(hdi
.pszText
)+20; // 20 pixels for col separator and margin
740 for (int index
= 0; index
<count
; ++index
)
742 // get the width of the string and add 12 pixels for the column separator and margins
747 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sActionColumnText
) + 12;
750 linewidth
= m_ProgList
.GetStringWidth(m_arData
[index
]->sPathColumnText
) + 12;
756 m_ProgList
.SetColumnWidth(col
, cx
);
759 m_ProgList
.SetRedraw(TRUE
);
762 BOOL
CGitProgressDlg::OnInitDialog()
764 __super::OnInitDialog();
766 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
767 // do this, Explorer would be unable to send that message to our window if we
768 // were running elevated. It's OK to make the call all the time, since if we're
769 // not elevated, this is a no-op.
770 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
771 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
772 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
775 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
776 if (pfnChangeWindowMessageFilterEx
)
778 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
781 m_pTaskbarList
.Release();
782 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
783 m_pTaskbarList
= nullptr;
785 m_ProgList
.SetExtendedStyle (LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
);
787 m_ProgList
.DeleteAllItems();
788 int c
= ((CHeaderCtrl
*)(m_ProgList
.GetDlgItem(0)))->GetItemCount()-1;
790 m_ProgList
.DeleteColumn(c
--);
792 temp
.LoadString(IDS_PROGRS_ACTION
);
793 m_ProgList
.InsertColumn(0, temp
);
794 temp
.LoadString(IDS_PROGRS_PATH
);
795 m_ProgList
.InsertColumn(1, temp
);
797 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
800 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED
)));
804 m_pThread
->m_bAutoDelete
= FALSE
;
805 m_pThread
->ResumeThread();
810 // Call this early so that the column headings aren't hidden before any
814 SetTimer(VISIBLETIMER
, 300, NULL
);
816 AddAnchor(IDC_SVNPROGRESS
, TOP_LEFT
, BOTTOM_RIGHT
);
817 AddAnchor(IDC_TITLE_ANIMATE
, TOP_LEFT
, BOTTOM_RIGHT
);
818 AddAnchor(IDC_PROGRESSLABEL
, BOTTOM_LEFT
, BOTTOM_CENTER
);
819 AddAnchor(IDC_PROGRESSBAR
, BOTTOM_CENTER
, BOTTOM_RIGHT
);
820 AddAnchor(IDC_INFOTEXT
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
821 AddAnchor(IDC_NONINTERACTIVE
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
822 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
823 AddAnchor(IDOK
, BOTTOM_RIGHT
);
824 AddAnchor(IDC_LOGBUTTON
, BOTTOM_RIGHT
);
825 //SetPromptParentWindow(this->m_hWnd);
827 m_Animate
.Open(IDR_DOWNLOAD
);
830 CenterWindow(CWnd::FromHandle(hWndExplorer
));
831 EnableSaveRestore(_T("GITProgressDlg"));
833 m_background_brush
.CreateSolidBrush(GetSysColor(COLOR_WINDOW
));
837 bool CGitProgressDlg::SetBackgroundImage(UINT nID
)
839 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList
.GetSafeHwnd(), nID
);
842 void CGitProgressDlg::ReportGitError()
844 ReportError(CGit::GetLibGit2LastErr());
847 void CGitProgressDlg::ReportError(const CString
& sError
)
849 CSoundUtils::PlayTGitError();
850 ReportString(sError
, CString(MAKEINTRESOURCE(IDS_ERR_ERROR
)), m_Colors
.GetColor(CColors::Conflict
));
851 m_bErrorsOccurred
= true;
854 void CGitProgressDlg::ReportWarning(const CString
& sWarning
)
856 CSoundUtils::PlayTGitWarning();
857 ReportString(sWarning
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)), m_Colors
.GetColor(CColors::Conflict
));
860 void CGitProgressDlg::ReportNotification(const CString
& sNotification
)
862 CSoundUtils::PlayTGitNotification();
863 ReportString(sNotification
, CString(MAKEINTRESOURCE(IDS_WARN_NOTE
)));
866 void CGitProgressDlg::ReportCmd(const CString
& sCmd
)
868 ReportString(sCmd
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO
)), m_Colors
.GetColor(CColors::Cmd
));
871 void CGitProgressDlg::ReportString(CString sMessage
, const CString
& sMsgKind
, COLORREF color
)
873 // instead of showing a dialog box with the error message or notification,
874 // just insert the error text into the list control.
875 // that way the user isn't 'interrupted' by a dialog box popping up!
877 // the message may be split up into different lines
878 // so add a new entry for each line of the message
879 while (!sMessage
.IsEmpty())
881 NotificationData
* data
= new NotificationData();
882 data
->bAuxItem
= true;
883 data
->sActionColumnText
= sMsgKind
;
884 if (sMessage
.Find('\n')>=0)
885 data
->sPathColumnText
= sMessage
.Left(sMessage
.Find('\n'));
887 data
->sPathColumnText
= sMessage
;
888 data
->sPathColumnText
.Trim(_T("\n\r"));
890 if (sMessage
.Find('\n')>=0)
892 sMessage
= sMessage
.Mid(sMessage
.Find('\n'));
893 sMessage
.Trim(_T("\n\r"));
897 m_arData
.push_back(data
);
902 UINT
CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid
)
904 return ((CGitProgressDlg
*)pVoid
)->ProgressThread();
907 UINT
CGitProgressDlg::ProgressThread()
909 // The SetParams function should have loaded something for us
912 CString sWindowTitle
;
913 bool localoperation
= false;
914 bool bSuccess
= false;
915 m_AlwaysConflicted
= false;
917 DialogEnableWindow(IDOK
, FALSE
);
918 DialogEnableWindow(IDCANCEL
, TRUE
);
919 // SetAndClearProgressInfo(m_hWnd);
920 m_itemCount
= m_itemCountTotal
;
922 InterlockedExchange(&m_bThreadRunning
, TRUE
);
924 bSecondResized
= FALSE
;
925 m_bFinishedItemAdded
= false;
926 CTime startTime
= CTime::GetCurrentTime();
929 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
933 case GitProgress_Add
:
934 bSuccess
= CmdAdd(sWindowTitle
, localoperation
);
936 case GitProgress_Copy
:
937 bSuccess
= CmdCopy(sWindowTitle
, localoperation
);
939 case GitProgress_Export
:
940 bSuccess
= CmdExport(sWindowTitle
, localoperation
);
942 case GitProgress_Rename
:
943 bSuccess
= CmdRename(sWindowTitle
, localoperation
);
945 case GitProgress_Resolve
:
946 bSuccess
= CmdResolve(sWindowTitle
, localoperation
);
948 case GitProgress_Revert
:
949 bSuccess
= CmdRevert(sWindowTitle
, localoperation
);
951 case GitProgress_Switch
:
952 bSuccess
= CmdSwitch(sWindowTitle
, localoperation
);
954 case GitProgress_SendMail
:
955 bSuccess
= CmdSendMail(sWindowTitle
, localoperation
);
957 case GitProgress_Clone
:
958 bSuccess
= CmdClone(sWindowTitle
, localoperation
);
960 case GitProgress_Fetch
:
961 bSuccess
= CmdFetch(sWindowTitle
, localoperation
);
965 temp
.LoadString(IDS_PROGRS_TITLEFAILED
);
967 temp
.LoadString(IDS_PROGRS_TITLEFIN
);
968 sWindowTitle
= sWindowTitle
+ _T(" ") + temp
;
969 SetWindowText(sWindowTitle
);
971 KillTimer(TRANSFERTIMER
);
972 KillTimer(VISIBLETIMER
);
976 if (DidErrorsOccur())
978 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
979 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
982 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
985 DialogEnableWindow(IDCANCEL
, FALSE
);
986 DialogEnableWindow(IDOK
, TRUE
);
988 CString info
= BuildInfoString();
990 info
.LoadString(IDS_PROGRS_INFOFAILED
);
991 SetDlgItemText(IDC_INFOTEXT
, info
);
993 CWnd
* pWndOk
= GetDlgItem(IDOK
);
994 if (pWndOk
&& ::IsWindow(pWndOk
->GetSafeHwnd()))
996 SendMessage(DM_SETDEFID
, IDOK
);
997 GetDlgItem(IDOK
)->SetFocus();
1001 if (!m_sTotalBytesTransferred
.IsEmpty())
1003 CTimeSpan time
= CTime::GetCurrentTime() - startTime
;
1004 temp
.Format(IDS_PROGRS_TIME
, (LONG
)time
.GetTotalMinutes(), (LONG
)time
.GetSeconds());
1005 sFinalInfo
.Format(IDS_PROGRS_FINALINFO
, m_sTotalBytesTransferred
, (LPCTSTR
)temp
);
1006 SetDlgItemText(IDC_PROGRESSLABEL
, sFinalInfo
);
1009 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_HIDE
);
1011 GetDlgItem(IDC_PROGRESSBAR
)->ShowWindow(SW_HIDE
);
1013 if (!m_bFinishedItemAdded
)
1015 // there's no "finished: xxx" line at the end. We add one here to make
1016 // sure the user sees that the command is actually finished.
1017 NotificationData
* data
= new NotificationData();
1018 data
->bAuxItem
= true;
1019 data
->sActionColumnText
.LoadString(IDS_PROGRS_FINISHED
);
1020 m_arData
.push_back(data
);
1024 int count
= m_ProgList
.GetItemCount();
1025 if ((count
> 0)&&(m_bLastVisible
))
1026 m_ProgList
.EnsureVisible(count
-1, FALSE
);
1031 logfile
.AddTimeLine();
1032 for (size_t i
= 0; i
< m_arData
.size(); ++i
)
1034 NotificationData
* data
= m_arData
[i
];
1035 temp
.Format(_T("%-20s : %s"), (LPCTSTR
)data
->sActionColumnText
, (LPCTSTR
)data
->sPathColumnText
);
1036 logfile
.AddLine(temp
);
1038 if (!sFinalInfo
.IsEmpty())
1039 logfile
.AddLine(sFinalInfo
);
1043 m_bCancelled
= TRUE
;
1044 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1048 DWORD dwAutoClose
= CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL
);
1049 if (m_options
& ProgOptDryRun
)
1050 dwAutoClose
= 0; // dry run means progress dialog doesn't auto close at all
1051 if (!m_bLastVisible
)
1053 if (m_dwCloseOnEnd
!= (DWORD
)-1)
1054 dwAutoClose
= m_dwCloseOnEnd
; // command line value has priority over setting value
1055 if ((dwAutoClose
== CLOSE_NOERRORS
)&&(!m_bErrorsOccurred
))
1056 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1057 if ((dwAutoClose
== CLOSE_NOCONFLICTS
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0))
1058 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1059 if ((dwAutoClose
== CLOSE_NOMERGES
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(!m_bMergesAddsDeletesOccurred
))
1060 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1061 if ((dwAutoClose
== CLOSE_LOCAL
)&&(!m_bErrorsOccurred
)&&(m_nConflicts
==0)&&(localoperation
))
1062 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
1065 //Don't do anything here which might cause messages to be sent to the window
1066 //The window thread is probably now blocked in OnOK if we've done an auto close
1070 void CGitProgressDlg::OnBnClickedLogbutton()
1072 switch(this->m_Command
)
1074 case GitProgress_Add
:
1075 case GitProgress_Resolve
:
1077 CString cmd
= _T(" /command:commit");
1078 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\"");
1080 CAppUtils::RunTortoiseGitProc(cmd
);
1081 this->EndDialog(IDOK
);
1086 if (m_targetPathList
.GetCount() != 1)
1088 StringRevMap::iterator it
= m_UpdateStartRevMap
.begin();
1089 svn_revnum_t rev
= -1;
1090 if (it
!= m_UpdateStartRevMap
.end())
1095 dlg
.SetParams(m_targetPathList
[0], m_RevisionEnd
, m_RevisionEnd
, rev
, 0, TRUE
);
1101 void CGitProgressDlg::OnClose()
1105 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1106 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1110 m_bCancelled
= TRUE
;
1113 DialogEnableWindow(IDCANCEL
, TRUE
);
1117 void CGitProgressDlg::OnOK()
1119 if ((m_bCancelled
)&&(!m_bThreadRunning
))
1121 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1122 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1123 // don't do any more operations on the window which might require message passing
1124 // If you try to send windows messages once we're waiting here, then the thread can't finished
1125 // because the Window's message loop is blocked at this wait
1126 WaitForSingleObject(m_pThread
->m_hThread
, 10000);
1129 m_bCancelled
= TRUE
;
1132 void CGitProgressDlg::OnCancel()
1134 if ((m_bCancelled
)&&(!m_bThreadRunning
))
1135 __super::OnCancel();
1136 m_bCancelled
= TRUE
;
1139 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1141 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1145 if (pDispInfo
->item
.mask
& LVIF_TEXT
)
1147 if (pDispInfo
->item
.iItem
< (int)m_arData
.size())
1149 const NotificationData
* data
= m_arData
[pDispInfo
->item
.iItem
];
1150 switch (pDispInfo
->item
.iSubItem
)
1153 lstrcpyn(m_columnbuf
, data
->sActionColumnText
, MAX_PATH
);
1156 lstrcpyn(m_columnbuf
, data
->sPathColumnText
, pDispInfo
->item
.cchTextMax
);
1157 if (!data
->bAuxItem
)
1159 int cWidth
= m_ProgList
.GetColumnWidth(1);
1160 cWidth
= max(12, cWidth
-12);
1161 CDC
* pDC
= m_ProgList
.GetDC();
1164 CFont
* pFont
= pDC
->SelectObject(m_ProgList
.GetFont());
1165 PathCompactPath(pDC
->GetSafeHdc(), m_columnbuf
, cWidth
);
1166 pDC
->SelectObject(pFont
);
1174 pDispInfo
->item
.pszText
= m_columnbuf
;
1181 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1183 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1185 // Take the default processing unless we set this to something else below.
1186 *pResult
= CDRF_DODEFAULT
;
1188 // First thing - check the draw stage. If it's the control's prepaint
1189 // stage, then tell Windows we want messages for every item.
1191 if ( CDDS_PREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1193 *pResult
= CDRF_NOTIFYITEMDRAW
;
1195 else if ( CDDS_ITEMPREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
1197 // This is the prepaint stage for an item. Here's where we set the
1198 // item's text color. Our return value will tell Windows to draw the
1199 // item itself, but it will use the new color we set here.
1201 // Tell Windows to paint the control itself.
1202 *pResult
= CDRF_DODEFAULT
;
1204 ASSERT(pLVCD
->nmcd
.dwItemSpec
< m_arData
.size());
1205 if(pLVCD
->nmcd
.dwItemSpec
>= m_arData
.size())
1209 const NotificationData
* data
= m_arData
[pLVCD
->nmcd
.dwItemSpec
];
1210 ASSERT(data
!= NULL
);
1214 // Store the color back in the NMLVCUSTOMDRAW struct.
1215 pLVCD
->clrText
= data
->color
;
1219 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
1222 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1224 if (pNMLV
->iItem
< 0)
1226 if (m_options
& ProgOptDryRun
)
1227 return; //don't do anything in a dry-run.
1229 const NotificationData
* data
= m_arData
[pNMLV
->iItem
];
1233 if (data
->bConflictedActionItem
)
1235 // We've double-clicked on a conflicted item - do a three-way merge on it
1236 SVNDiff::StartConflictEditor(data
->path
);
1238 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
))
1240 // This is a modified file which has been merged on update. Diff it against base
1241 CTGitPath temporaryFile
;
1242 SVNDiff
diff(this, this->m_hWnd
, true);
1243 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1244 svn_revnum_t baseRev
= 0;
1245 diff
.DiffFileAgainstBase(data
->path
, baseRev
);
1247 else if ((!data
->bAuxItem
)&&(data
->path
.Exists())&&(!data
->path
.IsDirectory()))
1249 bool bOpenWith
= false;
1250 int ret
= (int)ShellExecute(m_hWnd
, NULL
, data
->path
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
1251 if (ret
<= HINSTANCE_ERROR
)
1255 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1256 cmd
+= data
->path
.GetWinPathString() + _T(" ");
1257 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1263 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1265 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
1266 if (m_bThreadRunning
)
1268 if (m_nSortedColumn
== phdr
->iItem
)
1269 m_bAscending
= !m_bAscending
;
1271 m_bAscending
= TRUE
;
1272 m_nSortedColumn
= phdr
->iItem
;
1276 m_ProgList
.SetRedraw(FALSE
);
1277 m_ProgList
.DeleteAllItems();
1278 m_ProgList
.SetItemCountEx (static_cast<int>(m_arData
.size()));
1280 m_ProgList
.SetRedraw(TRUE
);
1285 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData
* pData
)
1287 return pData
->bAuxItem
;
1289 BOOL
CGitProgressDlg::Notify(const git_wc_notify_action_t action
, CString str
, const git_oid
*a
, const git_oid
*b
)
1291 NotificationData
* data
= new NotificationData();
1292 data
->action
= action
;
1293 data
->bAuxItem
= false;
1295 if (action
== git_wc_notify_update_ref
)
1297 data
->m_NewHash
= b
->id
;
1298 data
->m_OldHash
= a
->id
;
1299 data
->sActionColumnText
.LoadString(IDS_GITACTION_UPDATE_REF
);
1300 data
->sPathColumnText
.Format(_T("%s\t %s -> %s"), str
,
1301 data
->m_OldHash
.ToString().Left(g_Git
.GetShortHASHLength()),
1302 data
->m_NewHash
.ToString().Left(g_Git
.GetShortHASHLength()));
1306 m_arData
.push_back(data
);
1310 m_Animate
.ShowWindow(SW_HIDE
);
1313 BOOL
CGitProgressDlg::Notify(const git_wc_notify_action_t
/*action*/, const git_transfer_progress
*stat
)
1315 static unsigned int start
= 0;
1316 unsigned int dt
= GetCurrentTime() - start
;
1325 start
= GetCurrentTime();
1326 ds
= stat
->received_bytes
- m_TotalBytesTransferred
;
1327 speed
= ds
* 1000.0/dt
;
1328 m_TotalBytesTransferred
= stat
->received_bytes
;
1335 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1338 progress
= stat
->received_objects
+ stat
->indexed_objects
;
1340 if ((stat
->total_objects
> 1000) && (!progControl
->IsWindowVisible()))
1342 progControl
->ShowWindow(SW_SHOW
);
1344 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1346 if (!GetDlgItem(IDC_PROGRESSLABEL
)->IsWindowVisible())
1347 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_SHOW
);
1349 progControl
->SetPos(progress
);
1350 progControl
->SetRange32(0, 2 * stat
->total_objects
);
1353 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1354 m_pTaskbarList
->SetProgressValue(m_hWnd
, progress
, stat
->total_objects
);
1358 if (stat
->received_bytes
< 1024)
1359 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, (int64_t)stat
->received_bytes
);
1360 else if (stat
->received_bytes
< 1200000)
1361 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, (int64_t)stat
->received_bytes
/ 1024);
1363 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)stat
->received_bytes
/ 1024000.0));
1367 str
.Format(_T("%fB/s"), speed
);
1368 else if(speed
< 1024 * 1024)
1369 str
.Format(_T("%.2fKB/s"), speed
/ 1024);
1371 str
.Format(_T("%.2fMB/s"), speed
/ 1024000.0);
1373 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)str
);
1374 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1379 LRESULT
CGitProgressDlg::OnGitProgress(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1382 SVNProgress
* pProgressData
= (SVNProgress
*)lParam
;
1383 CProgressCtrl
* progControl
= (CProgressCtrl
*)GetDlgItem(IDC_PROGRESSBAR
);
1384 if ((pProgressData
->total
> 1000)&&(!progControl
->IsWindowVisible()))
1386 progControl
->ShowWindow(SW_SHOW
);
1388 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1390 if (((pProgressData
->total
< 0)&&(pProgressData
->progress
> 1000)&&(progControl
->IsWindowVisible()))&&(m_itemCountTotal
<0))
1392 progControl
->ShowWindow(SW_HIDE
);
1394 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_INDETERMINATE
);
1396 if (!GetDlgItem(IDC_PROGRESSLABEL
)->IsWindowVisible())
1397 GetDlgItem(IDC_PROGRESSLABEL
)->ShowWindow(SW_SHOW
);
1398 SetTimer(TRANSFERTIMER
, 2000, NULL
);
1399 if ((pProgressData
->total
> 0)&&(pProgressData
->progress
> 1000))
1401 progControl
->SetPos((int)pProgressData
->progress
);
1402 progControl
->SetRange32(0, (int)pProgressData
->total
);
1405 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1406 m_pTaskbarList
->SetProgressValue(m_hWnd
, pProgressData
->progress
, pProgressData
->total
);
1410 if (pProgressData
->overall_total
< 1024)
1411 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED
, pProgressData
->overall_total
);
1412 else if (pProgressData
->overall_total
< 1200000)
1413 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED
, pProgressData
->overall_total
/ 1024);
1415 m_sTotalBytesTransferred
.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED
, (double)((double)pProgressData
->overall_total
/ 1024000.0));
1416 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)pProgressData
->SpeedString
);
1417 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1422 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent
)
1424 if (nIDEvent
== TRANSFERTIMER
)
1428 progSpeed
.Format(IDS_SVN_PROGRESS_BYTES_SEC
, 0);
1429 progText
.Format(IDS_SVN_PROGRESS_TOTALANDSPEED
, (LPCTSTR
)m_sTotalBytesTransferred
, (LPCTSTR
)progSpeed
);
1430 SetDlgItemText(IDC_PROGRESSLABEL
, progText
);
1431 KillTimer(TRANSFERTIMER
);
1433 if (nIDEvent
== VISIBLETIMER
)
1435 if (nEnsureVisibleCount
)
1436 m_ProgList
.EnsureVisible(m_ProgList
.GetItemCount()-1, false);
1437 nEnsureVisibleCount
= 0;
1441 void CGitProgressDlg::Sort()
1443 if(m_arData
.size() < 2)
1448 // We need to sort the blocks which lie between the auxiliary entries
1449 // This is so that any aux data stays where it was
1450 NotificationDataVect::iterator actionBlockBegin
;
1451 NotificationDataVect::iterator actionBlockEnd
= m_arData
.begin(); // We start searching from here
1455 // Search to the start of the non-aux entry in the next block
1456 actionBlockBegin
= std::find_if(actionBlockEnd
, m_arData
.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux
)));
1457 if(actionBlockBegin
== m_arData
.end())
1459 // There are no more actions
1462 // Now search to find the end of the block
1463 actionBlockEnd
= std::find_if(actionBlockBegin
+1, m_arData
.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux
));
1464 // Now sort the block
1465 std::sort(actionBlockBegin
, actionBlockEnd
, &CGitProgressDlg::SortCompare
);
1469 bool CGitProgressDlg::SortCompare(const NotificationData
* pData1
, const NotificationData
* pData2
)
1472 switch (m_nSortedColumn
)
1474 case 0: //action column
1475 result
= pData1
->sActionColumnText
.Compare(pData2
->sActionColumnText
);
1477 case 1: //path column
1478 // Compare happens after switch()
1484 // Sort by path if everything else is equal
1487 result
= CTGitPath::Compare(pData1
->path
, pData2
->path
);
1495 BOOL
CGitProgressDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
1497 if (!GetDlgItem(IDOK
)->IsWindowEnabled())
1499 // only show the wait cursor over the list control
1500 if ((pWnd
)&&(pWnd
== GetDlgItem(IDC_SVNPROGRESS
)))
1502 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
1507 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
1509 return CResizableStandAloneDialog::OnSetCursor(pWnd
, nHitTest
, message
);
1512 BOOL
CGitProgressDlg::PreTranslateMessage(MSG
* pMsg
)
1514 if (pMsg
->message
== WM_KEYDOWN
)
1516 if (pMsg
->wParam
== VK_ESCAPE
)
1518 // pressing the ESC key should close the dialog. But since we disabled the escape
1519 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1521 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1522 // the impression that the OK button was pressed.
1523 if ((!m_bThreadRunning
)&&(!GetDlgItem(IDCANCEL
)->IsWindowEnabled())
1524 &&(GetDlgItem(IDOK
)->IsWindowEnabled())&&(GetDlgItem(IDOK
)->IsWindowVisible()))
1526 // since we convert ESC to RETURN, make sure the OK button has the focus.
1527 GetDlgItem(IDOK
)->SetFocus();
1528 pMsg
->wParam
= VK_RETURN
;
1531 if (pMsg
->wParam
== 'A')
1533 if (GetKeyState(VK_CONTROL
)&0x8000)
1535 // Ctrl-A -> select all
1536 m_ProgList
.SetSelectionMark(0);
1537 for (int i
=0; i
<m_ProgList
.GetItemCount(); ++i
)
1539 m_ProgList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
1543 if ((pMsg
->wParam
== 'C')||(pMsg
->wParam
== VK_INSERT
))
1545 int selIndex
= m_ProgList
.GetSelectionMark();
1548 if (GetKeyState(VK_CONTROL
)&0x8000)
1550 //Ctrl-C -> copy to clipboard
1552 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1557 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1558 CString sAction
= m_ProgList
.GetItemText(nItem
, 0);
1559 CString sPath
= m_ProgList
.GetItemText(nItem
, 1);
1560 CString sMime
= m_ProgList
.GetItemText(nItem
, 2);
1561 CString sLogCopyText
;
1562 sLogCopyText
.Format(_T("%s: %s %s\r\n"),
1563 (LPCTSTR
)sAction
, (LPCTSTR
)sPath
, (LPCTSTR
)sMime
);
1564 sClipdata
+= sLogCopyText
;
1566 CStringUtils::WriteAsciiStringToClipboard(sClipdata
);
1571 } // if (pMsg->message == WM_KEYDOWN)
1572 return __super::PreTranslateMessage(pMsg
);
1575 void CGitProgressDlg::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1577 if (m_options
& ProgOptDryRun
)
1578 return; // don't do anything in a dry-run.
1580 if (pWnd
== &m_ProgList
)
1582 int selIndex
= m_ProgList
.GetSelectionMark();
1583 if ((point
.x
== -1) && (point
.y
== -1))
1585 // Menu was invoked from the keyboard rather than by right-clicking
1587 m_ProgList
.GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1588 m_ProgList
.ClientToScreen(&rect
);
1589 point
= rect
.CenterPoint();
1592 if ((selIndex
>= 0)&&(!m_bThreadRunning
))
1594 // entry is selected, thread has finished with updating so show the popup menu
1596 if (popup
.CreatePopupMenu())
1598 bool bAdded
= false;
1599 NotificationData
* data
= m_arData
[selIndex
];
1600 if ((data
)&&(!data
->path
.IsDirectory()))
1603 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1605 if (m_ProgList.GetSelectedCount() == 1)
1607 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1612 if (data->bConflictedActionItem)
1614 if (m_ProgList.GetSelectedCount() == 1)
1616 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1617 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1618 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1620 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1621 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1623 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1624 popup.SetDefaultItem(ID_COMPARE, FALSE);
1626 if (m_ProgList
.GetSelectedCount() == 1)
1628 if ((data
->action
== git_wc_notify_add
)||
1629 (data
->action
== git_wc_notify_revert
)||
1630 (data
->action
== git_wc_notify_resolved
)||
1631 (data
->action
== git_wc_notify_checkout
)||
1632 (data
->action
== git_wc_notify_update_ref
))
1634 popup
.AppendMenuIcon(ID_LOG
, IDS_MENULOG
,IDI_LOG
);
1635 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1636 popup
.AppendMenuIcon(ID_OPEN
, IDS_LOG_POPUP_OPEN
, IDI_OPEN
);
1637 popup
.AppendMenuIcon(ID_OPENWITH
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
1641 } // if ((data)&&(!data->path.IsDirectory()))
1642 if (m_ProgList
.GetSelectedCount() == 1)
1646 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1647 CTGitPath path
= CTGitPath(sPath
);
1648 if (!sPath
.IsEmpty())
1650 if (path
.GetDirectory().Exists())
1652 popup
.AppendMenuIcon(ID_EXPLORE
, IDS_SVNPROGRESS_MENUOPENPARENT
, IDI_EXPLORER
);
1658 if (m_ProgList
.GetSelectedCount() > 0)
1661 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1662 popup
.AppendMenuIcon(ID_COPY
, IDS_LOG_POPUP_COPYTOCLIPBOARD
,IDI_COPYCLIP
);
1667 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1668 DialogEnableWindow(IDOK
, FALSE
);
1669 //this->SetPromptApp(&theApp);
1670 theApp
.DoWaitCursor(1);
1671 bool bOpenWith
= false;
1677 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1680 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1681 NotificationData
* data
= m_arData
[nItem
];
1684 sLines
+= data
->sPathColumnText
;
1685 sLines
+= _T("\r\n");
1689 if (!sLines
.IsEmpty())
1691 CStringUtils::WriteAsciiStringToClipboard(sLines
, GetSafeHwnd());
1697 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1699 CTGitPath path
= CTGitPath(sPath
);
1700 ShellExecute(m_hWnd
, _T("explore"), path
.GetDirectory().GetWinPath(), NULL
, path
.GetDirectory().GetWinPath(), SW_SHOW
);
1706 svn_revnum_t rev
= -1;
1707 StringRevMap::iterator it
= m_UpdateStartRevMap
.end();
1708 if (data
->basepath
.IsEmpty())
1709 it
= m_UpdateStartRevMap
.begin();
1711 it
= m_UpdateStartRevMap
.find(data
->basepath
.GetSVNApiPath(pool
));
1712 if (it
!= m_UpdateStartRevMap
.end())
1714 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1715 if (data
->content_state
== svn_wc_notify_state_merged
)
1717 CTGitPath basefile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1718 CTGitPath newfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_HEAD
);
1720 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, basefile
))
1722 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1723 DialogEnableWindow(IDOK
, TRUE
);
1726 // If necessary, convert the line-endings on the file before diffing
1727 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE
))
1729 CTGitPath temporaryFile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, SVNRev::REV_BASE
);
1730 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_BASE
), SVNRev(SVNRev::REV_BASE
), temporaryFile
))
1732 temporaryFile
.Reset();
1737 newfile
= temporaryFile
;
1741 SetFileAttributes(newfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1742 SetFileAttributes(basefile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1743 CString revname
, wcname
, basename
;
1744 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1745 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1746 basename
.Format(IDS_DIFF_BASENAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1747 CAppUtils::StartExtMerge(basefile
, newfile
, data
->path
, data
->path
, basename
, revname
, wcname
, CString(), true);
1751 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, data
->path
, rev
);
1753 if (!svn
.Cat(data
->path
, SVNRev(SVNRev::REV_WC
), rev
, tempfile
))
1755 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1756 DialogEnableWindow(IDOK
, TRUE
);
1761 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
1762 CString revname
, wcname
;
1763 revname
.Format(_T("%s Revision %ld"), (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName(), rev
);
1764 wcname
.Format(IDS_DIFF_WCNAME
, (LPCTSTR
)data
->path
.GetUIFileOrDirectoryName());
1765 CAppUtils::StartExtDiff(
1766 tempfile
, data
->path
, revname
, wcname
,
1767 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000)));
1772 case ID_EDITCONFLICT
:
1774 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1775 SVNDiff::StartConflictEditor(CTGitPath(sPath
));
1778 case ID_CONFLICTUSETHEIRS
:
1779 case ID_CONFLICTUSEMINE
:
1780 case ID_CONFLICTRESOLVE
:
1782 svn_wc_conflict_choice_t result
= svn_wc_conflict_choose_merged
;
1785 case ID_CONFLICTUSETHEIRS
:
1786 result
= svn_wc_conflict_choose_theirs_full
;
1788 case ID_CONFLICTUSEMINE
:
1789 result
= svn_wc_conflict_choose_mine_full
;
1791 case ID_CONFLICTRESOLVE
:
1792 result
= svn_wc_conflict_choose_merged
;
1796 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1797 CString sResolvedPaths
;
1800 int nItem
= m_ProgList
.GetNextSelectedItem(pos
);
1801 NotificationData
* data
= m_arData
[nItem
];
1804 if (data
->bConflictedActionItem
)
1806 if (!svn
.Resolve(data
->path
, result
, FALSE
))
1808 CMessageBox::Show(m_hWnd
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
1809 DialogEnableWindow(IDOK
, TRUE
);
1814 data
->color
= ::GetSysColor(COLOR_WINDOWTEXT
);
1815 data
->action
= svn_wc_notify_resolved
;
1816 data
->sActionColumnText
.LoadString(IDS_SVNACTION_RESOLVE
);
1817 data
->bConflictedActionItem
= false;
1820 if (m_nConflicts
==0)
1822 // When the last conflict is resolved we remove
1823 // the warning which we assume is in the last line.
1824 int nIndex
= m_ProgList
.GetItemCount()-1;
1825 VERIFY(m_ProgList
.DeleteItem(nIndex
));
1827 delete m_arData
[nIndex
];
1828 m_arData
.pop_back();
1830 sResolvedPaths
+= data
->path
.GetWinPathString() + _T("\n");
1835 m_ProgList
.Invalidate();
1836 CString info
= BuildInfoString();
1837 SetDlgItemText(IDC_INFOTEXT
, info
);
1839 if (!sResolvedPaths
.IsEmpty())
1842 msg
.Format(IDS_SVNPROGRESS_RESOLVED
, (LPCTSTR
)sResolvedPaths
);
1843 CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
1850 CString cmd
= _T("/command:log");
1851 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1852 if(data
->action
== git_wc_notify_update_ref
)
1854 cmd
+= _T(" /path:\"") + GetPathFromColumnText(CString()) + _T("\"");
1855 if (!data
->m_OldHash
.IsEmpty())
1856 cmd
+= _T(" /startrev:") + data
->m_OldHash
.ToString();
1857 if (!data
->m_NewHash
.IsEmpty())
1858 cmd
+= _T(" /endrev:") + data
->m_NewHash
.ToString();
1861 cmd
+= _T(" /path:\"") + sPath
+ _T("\"");
1862 CAppUtils::RunTortoiseGitProc(cmd
);
1870 CString sWinPath
= GetPathFromColumnText(data
->sPathColumnText
);
1872 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, (LPCTSTR
)sWinPath
, NULL
, NULL
, SW_SHOWNORMAL
);
1873 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
1875 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1876 cmd
+= sWinPath
+ _T(" ");
1877 CAppUtils::LaunchApplication(cmd
, NULL
, false);
1881 DialogEnableWindow(IDOK
, TRUE
);
1882 theApp
.DoWaitCursor(-1);
1889 void CGitProgressDlg::OnEnSetfocusInfotext()
1892 GetDlgItemText(IDC_INFOTEXT
, sTemp
);
1893 if (sTemp
.IsEmpty())
1894 GetDlgItem(IDC_INFOTEXT
)->HideCaret();
1897 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR
* , LRESULT
*pResult
)
1899 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1901 int selIndex
= m_ProgList
.GetSelectionMark();
1905 CDropFiles dropFiles
; // class for creating DROPFILES struct
1908 POSITION pos
= m_ProgList
.GetFirstSelectedItemPosition();
1909 while ( (index
= m_ProgList
.GetNextSelectedItem(pos
)) >= 0 )
1911 NotificationData
* data
= m_arData
[index
];
1913 if ( data
->kind
==svn_node_file
|| data
->kind
==svn_node_dir
)
1915 CString sPath
= GetPathFromColumnText(data
->sPathColumnText
);
1917 dropFiles
.AddFile( sPath
);
1921 if ( dropFiles
.GetCount()>0 )
1923 dropFiles
.CreateStructure();
1929 void CGitProgressDlg::OnSize(UINT nType
, int cx
, int cy
)
1931 CResizableStandAloneDialog::OnSize(nType
, cx
, cy
);
1932 if ((nType
== SIZE_RESTORED
)&&(m_bLastVisible
))
1934 if(!m_ProgList
.m_hWnd
)
1937 int count
= m_ProgList
.GetItemCount();
1939 m_ProgList
.EnsureVisible(count
-1, false);
1943 //////////////////////////////////////////////////////////////////////////
1945 //////////////////////////////////////////////////////////////////////////
1946 bool CGitProgressDlg::CmdAdd(CString
& sWindowTitle
, bool& localoperation
)
1948 localoperation
= true;
1949 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_ADD
);
1950 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
1951 SetBackgroundImage(IDI_ADD_BKG
);
1952 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD
)));
1954 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE
) == TRUE
)
1956 git_repository
*repo
= NULL
;
1959 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
1960 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
1962 gitdir
.ReleaseBuffer();
1966 gitdir
.ReleaseBuffer();
1968 git_config
* config
;
1969 git_config_new(&config
);
1971 CStringA projectConfigA
= CUnicodeUtils::GetMulti(g_Git
.GetGitLocalConfig(), CP_UTF8
);
1972 if (git_config_add_file_ondisk(config
, projectConfigA
.GetBuffer(), 4, FALSE
))
1974 projectConfigA
.ReleaseBuffer();
1976 git_config_free(config
);
1977 git_repository_free(repo
);
1980 projectConfigA
.ReleaseBuffer();
1981 CString globalConfig
= g_Git
.GetGitGlobalConfig();
1982 if (PathFileExists(globalConfig
))
1984 CStringA globalConfigA
= CUnicodeUtils::GetMulti(globalConfig
, CP_UTF8
);
1985 if (git_config_add_file_ondisk(config
, globalConfigA
.GetBuffer(), 3, FALSE
))
1987 globalConfigA
.ReleaseBuffer();
1989 git_config_free(config
);
1990 git_repository_free(repo
);
1993 globalConfigA
.ReleaseBuffer();
1995 CString globalXDGConfig
= g_Git
.GetGitGlobalXDGConfig();
1996 if (PathFileExists(globalXDGConfig
))
1998 CStringA globalXDGConfigA
= CUnicodeUtils::GetMulti(globalXDGConfig
, CP_UTF8
);
1999 if (git_config_add_file_ondisk(config
, globalXDGConfigA
.GetBuffer(), 2, FALSE
))
2001 globalXDGConfigA
.ReleaseBuffer();
2003 git_config_free(config
);
2004 git_repository_free(repo
);
2007 globalXDGConfigA
.ReleaseBuffer();
2009 CString systemConfig
= g_Git
.GetGitSystemConfig();
2010 if (!systemConfig
.IsEmpty())
2012 CStringA systemConfigA
= CUnicodeUtils::GetMulti(systemConfig
, CP_UTF8
);
2013 if (git_config_add_file_ondisk(config
, systemConfigA
.GetBuffer(), 1, FALSE
))
2015 systemConfigA
.ReleaseBuffer();
2017 git_config_free(config
);
2018 git_repository_free(repo
);
2021 systemConfigA
.ReleaseBuffer();
2024 git_repository_set_config(repo
, config
);
2026 if (git_repository_index(&index
, repo
))
2029 git_repository_free(repo
);
2032 if (git_index_read(index
))
2035 git_index_free(index
);
2036 git_repository_free(repo
);
2040 for (int i
= 0; i
< m_targetPathList
.GetCount(); ++i
)
2042 if (git_index_add_bypath(index
, CStringA(CUnicodeUtils::GetMulti(m_targetPathList
[i
].GetGitPathString(), CP_UTF8
)).GetBuffer()))
2045 git_index_free(index
);
2046 git_repository_free(repo
);
2049 Notify(m_targetPathList
[i
],git_wc_notify_add
);
2052 if (git_index_write(index
))
2055 git_index_free(index
);
2056 git_repository_free(repo
);
2060 git_index_free(index
);
2061 git_repository_free(repo
);
2065 CMassiveGitTask
mgt(L
"add -f");
2066 mgt
.ExecuteWithNotify(&m_targetPathList
, m_bCancelled
, git_wc_notify_add
, this, &CGitProgressDlg::Notify
);
2069 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
2071 this->GetDlgItem(IDC_LOGBUTTON
)->SetWindowText(_T("Commit ..."));
2072 this->GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2076 bool CGitProgressDlg::CmdCopy(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2079 ASSERT(m_targetPathList
.GetCount() == 1);
2080 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_COPY
);
2081 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2082 SetBackgroundImage(IDI_COPY_BKG
);
2085 sCmdInfo
.Format(IDS_PROGRS_CMD_COPY
,
2086 m_targetPathList
[0].IsUrl() ? (LPCTSTR
)m_targetPathList
[0].GetSVNPathString() : m_targetPathList
[0].GetWinPath(),
2087 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
2088 ReportCmd(sCmdInfo
);
2090 if (!Copy(m_targetPathList
, m_url
, m_Revision
, m_pegRev
, m_sMessage
))
2095 if (m_options
& ProgOptSwitchAfterCopy
)
2097 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2098 m_targetPathList
[0].GetWinPath(),
2099 (LPCTSTR
)m_url
.GetSVNPathString(), (LPCTSTR
)m_Revision
.ToString());
2100 ReportCmd(sCmdInfo
);
2101 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, SVNRev::REV_HEAD
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
2103 if (!Switch(m_targetPathList
[0], m_url
, SVNRev::REV_HEAD
, m_Revision
, m_depth
, TRUE
, m_options
& ProgOptIgnoreExternals
))
2112 if (SVN::PathIsURL(m_url
))
2114 CString
sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING
));
2115 ReportNotification(sMsg
);
2122 bool CGitProgressDlg::CmdExport(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2125 ASSERT(m_targetPathList
.GetCount() == 1);
2126 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_EXPORT
);
2127 sWindowTitle
= m_url
.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle
;
2128 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2129 SetBackgroundImage(IDI_EXPORT_BKG
);
2131 if (m_options
& ProgOptEolCRLF
)
2133 if (m_options
& ProgOptEolLF
)
2135 if (m_options
& ProgOptEolCR
)
2137 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT
)));
2138 if (!Export(m_url
, m_targetPathList
[0], m_Revision
, m_Revision
, TRUE
, m_options
& ProgOptIgnoreExternals
, m_depth
, NULL
, FALSE
, eol
))
2147 bool CGitProgressDlg::CmdRename(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2150 ASSERT(m_targetPathList
.GetCount() == 1);
2151 if ((!m_targetPathList
[0].IsUrl())&&(!m_url
.IsUrl()))
2152 localoperation
= true;
2153 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RENAME
);
2154 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2155 SetBackgroundImage(IDI_RENAME_BKG
);
2156 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME
)));
2157 if (!Move(m_targetPathList
, m_url
, m_Revision
, m_sMessage
))
2166 bool CGitProgressDlg::CmdResolve(CString
& sWindowTitle
, bool& localoperation
)
2169 localoperation
= true;
2170 ASSERT(m_targetPathList
.GetCount() == 1);
2171 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_RESOLVE
);
2172 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2173 SetBackgroundImage(IDI_RESOLVE_BKG
);
2174 // check if the file may still have conflict markers in it.
2175 //BOOL bMarkers = FALSE;
2177 for (int i
= 0; i
< m_targetPathList
.GetCount(); ++i
)
2179 CString cmd
,out
,tempmergefile
;
2180 cmd
.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList
[i
].GetGitPathString());
2181 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2183 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2184 m_bErrorsOccurred
=true;
2188 CAppUtils::RemoveTempMergeFile((CTGitPath
&)m_targetPathList
[i
]);
2190 Notify(m_targetPathList
[i
],git_wc_notify_resolved
);
2193 if ((m_options
& ProgOptSkipConflictCheck
) == 0)
2197 for (INT_PTR fileindex
=0; (fileindex
<m_targetPathList
.GetCount()) && (bMarkers
==FALSE
); ++fileindex
)
2199 if (!m_targetPathList
[fileindex
].IsDirectory())
2201 CStdioFile
file(m_targetPathList
[fileindex
].GetWinPath(), CFile::typeBinary
| CFile::modeRead
);
2202 CString strLine
= _T("");
2203 while (file
.ReadString(strLine
))
2205 if (strLine
.Find(_T("<<<<<<<"))==0)
2215 catch (CFileException
* pE
)
2217 TRACE(_T("CFileException in Resolve!\n"));
2218 TCHAR error
[10000] = {0};
2219 pE
->GetErrorMessage(error
, 10000);
2227 if (CMessageBox::Show(m_hWnd
, IDS_PROGRS_REVERTMARKERS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
)==IDYES
)
2229 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2230 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
2231 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
2236 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2237 for (INT_PTR fileindex
=0; fileindex
<m_targetPathList
.GetCount(); ++fileindex
)
2238 Resolve(m_targetPathList
[fileindex
], svn_wc_conflict_choose_merged
, true);
2241 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
2243 this->GetDlgItem(IDC_LOGBUTTON
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_COMMITBUTTON
)));
2244 this->GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2249 bool CGitProgressDlg::CmdRevert(CString
& sWindowTitle
, bool& localoperation
)
2252 localoperation
= true;
2253 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_REVERT
);
2254 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2255 SetBackgroundImage(IDI_REVERT_BKG
);
2257 CTGitPathList delList
;
2258 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
2262 path
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+m_selectedPaths
[i
].GetWinPath());
2263 action
= m_selectedPaths
[i
].m_Action
;
2264 /* rename file can't delete because it needs original file*/
2265 if((!(action
& CTGitPath::LOGACTIONS_ADDED
)) &&
2266 (!(action
& CTGitPath::LOGACTIONS_REPLACED
)))
2267 delList
.AddPath(path
);
2269 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE
)))
2270 delList
.DeleteAllFiles(true);
2272 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT
)));
2273 for (int i
= 0; i
< m_selectedPaths
.GetCount(); ++i
)
2275 if(g_Git
.Revert(_T("HEAD"), (CTGitPath
&)m_selectedPaths
[i
]))
2277 CMessageBox::Show(NULL
,_T("Revert Fail"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2278 m_bErrorsOccurred
=true;
2281 Notify(m_selectedPaths
[i
],git_wc_notify_revert
);
2284 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths
);
2289 bool CGitProgressDlg::CmdSwitch(CString
& /*sWindowTitle*/, bool& /*localoperation*/)
2292 ASSERT(m_targetPathList
.GetCount() == 1);
2294 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SWITCH
);
2295 SetWindowText(sWindowTitle
); // needs to be updated, see TSVN rev. 21375
2296 SetBackgroundImage(IDI_SWITCH_BKG
);
2298 if (st
.GetStatus(m_targetPathList
[0]) != (-2))
2300 if (st
.status
->entry
!= NULL
)
2302 rev
= st
.status
->entry
->revision
;
2307 sCmdInfo
.Format(IDS_PROGRS_CMD_SWITCH
,
2308 m_targetPathList
[0].GetWinPath(), (LPCTSTR
)m_url
.GetSVNPathString(),
2309 (LPCTSTR
)m_Revision
.ToString());
2310 ReportCmd(sCmdInfo
);
2312 bool depthIsSticky
= true;
2313 if (m_depth
== svn_depth_unknown
)
2314 depthIsSticky
= false;
2315 if (!Switch(m_targetPathList
[0], m_url
, m_Revision
, m_Revision
, m_depth
, depthIsSticky
, m_options
& ProgOptIgnoreExternals
))
2320 m_UpdateStartRevMap
[m_targetPathList
[0].GetSVNApiPath(pool
)] = rev
;
2321 if ((m_RevisionEnd
>= 0)&&(rev
>= 0)
2322 &&((LONG
)m_RevisionEnd
> (LONG
)rev
))
2324 GetDlgItem(IDC_LOGBUTTON
)->ShowWindow(SW_SHOW
);
2329 bool CGitProgressDlg::CmdClone(CString
& sWindowTitle
, bool& /*localoperation*/)
2331 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2333 // should never run to here
2337 this->m_TotalBytesTransferred
= 0;
2339 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_CLONE
);
2340 CAppUtils::SetWindowTitle(m_hWnd
, m_url
.GetGitPathString(), sWindowTitle
);
2341 SetBackgroundImage(IDI_SWITCH_BKG
);
2342 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE
)));
2344 if (m_url
.IsEmpty() || m_targetPathList
.GetCount() == 0)
2347 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2348 CStringA path
= CUnicodeUtils::GetMulti(m_targetPathList
[0].GetWinPathString(),CP_UTF8
);
2350 git_repository
*cloned_repo
= NULL
;
2351 git_remote
*origin
= NULL
;
2352 git_checkout_opts checkout_opts
= GIT_CHECKOUT_OPTS_INIT
;
2356 git_clone_options clone_opts
= GIT_CLONE_OPTIONS_INIT
;
2358 clone_opts
.checkout_opts
= checkout_opts
;
2360 clone_opts
.checkout_opts
.checkout_strategy
= m_bNoCheckout
? GIT_CHECKOUT_NONE
: GIT_CHECKOUT_SAFE_CREATE
;
2361 clone_opts
.checkout_opts
.progress_cb
= CheckoutCallback
;
2362 clone_opts
.checkout_opts
.progress_payload
= this;
2364 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2366 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2367 callbacks
.progress
= RemoteProgressCallback
;
2368 callbacks
.completion
= RemoteCompletionCallback
;
2369 callbacks
.payload
= this;
2371 clone_opts
.remote_callbacks
= &callbacks
;
2373 if (!m_RefSpec
.IsEmpty())
2374 clone_opts
.checkout_branch
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
).GetBuffer();
2376 clone_opts
.fetch_progress_cb
= FetchCallback
;
2377 clone_opts
.fetch_progress_payload
= this;
2379 clone_opts
.cred_acquire_cb
= CAppUtils::Git2GetUserPassword
;
2381 clone_opts
.bare
= m_bBare
;
2383 m_Animate
.ShowWindow(SW_SHOW
);
2384 m_Animate
.Play(0, INT_MAX
, INT_MAX
);
2385 error
= git_clone(&cloned_repo
, url
, path
, &clone_opts
);
2387 m_Animate
.ShowWindow(SW_HIDE
);
2389 git_remote_free(origin
);
2395 else if (cloned_repo
)
2396 git_repository_free(cloned_repo
);
2400 void CGitProgressDlg::OnBnClickedNoninteractive()
2402 LRESULT res
= ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE
)->GetSafeHwnd(), BM_GETCHECK
, 0, 0);
2403 m_AlwaysConflicted
= (res
== BST_CHECKED
);
2404 CRegDWORD nonint
= CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE
);
2405 nonint
= m_AlwaysConflicted
;
2408 CString
CGitProgressDlg::GetPathFromColumnText(const CString
& sColumnText
)
2410 CString sPath
= sColumnText
;
2411 if (sPath
.Find(':')<0)
2413 // the path is not absolute: add the common root of all paths to it
2414 sPath
= g_Git
.m_CurrentDir
+ _T("\\") + sColumnText
;
2419 bool CGitProgressDlg::CmdSendMail(CString
& sWindowTitle
, bool& /*localoperation*/)
2421 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_SENDMAIL
);
2422 CAppUtils::SetWindowTitle(m_hWnd
, m_targetPathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
2423 //SetBackgroundImage(IDI_ADD_BKG);
2424 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL
)));
2426 if(this->m_SendMailFlags
&SENDMAIL_COMBINED
)
2430 Notify(path
,git_wc_notify_sendmail_start
);
2435 if(!!CPatch::SendPatchesCombined(m_targetPathList
,m_SendMailTO
,m_SendMailCC
,m_SendMailSubject
,!!(this->m_SendMailFlags
&SENDMAIL_ATTACHMENT
),!!(this->m_SendMailFlags
&SENDMAIL_MAPI
),&err
))
2437 Notify(path
,git_wc_notify_sendmail_error
,ret
,&err
);
2447 Notify(path
,git_wc_notify_sendmail_retry
,ret
,&err
);
2452 str
.LoadString(IDS_SVN_USERCANCELLED
);
2453 Notify(path
,git_wc_notify_sendmail_error
,ret
,&str
);
2458 Notify(path
,git_wc_notify_sendmail_done
,ret
);
2462 for (int i
= 0; ret
&& i
< m_targetPathList
.GetCount(); ++i
)
2465 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_start
);
2470 if(!!patch
.Send((CString
&)m_targetPathList
[i
].GetWinPathString(),this->m_SendMailTO
,
2471 this->m_SendMailCC
,!!(this->m_SendMailFlags
&SENDMAIL_ATTACHMENT
),!!(this->m_SendMailFlags
&SENDMAIL_MAPI
)))
2473 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_error
,ret
,&patch
.m_LastError
);
2484 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_retry
,ret
,&patch
.m_LastError
);
2489 str
.LoadString(IDS_SVN_USERCANCELLED
);
2490 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_error
,ret
,&str
);
2495 Notify(m_targetPathList
[i
],git_wc_notify_sendmail_done
,ret
);
2501 LRESULT
CGitProgressDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
2503 m_pTaskbarList
.Release();
2504 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
2508 HBRUSH
CGitProgressDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
2511 if (pWnd
->GetDlgCtrlID() == IDC_TITLE_ANIMATE
)
2513 pDC
->SetBkColor(GetSysColor(COLOR_WINDOW
)); // add this
2514 pDC
->SetBkMode(TRANSPARENT
);
2515 return (HBRUSH
)m_background_brush
.GetSafeHandle();
2518 hbr
= CResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
2520 // TODO: Return a different brush if the default is not desired
2523 LRESULT
CGitProgressDlg::OnCtlColorStatic(WPARAM wParam
, LPARAM lParam
)
2525 HDC hDC
= (HDC
)wParam
;
2526 HWND hwndCtl
= (HWND
)lParam
;
2528 if (::GetDlgCtrlID(hwndCtl
) == IDC_TITLE_ANIMATE
)
2530 CDC
*pDC
= CDC::FromHandle(hDC
);
2531 pDC
->SetBkColor(GetSysColor(COLOR_WINDOW
));
2532 pDC
->SetBkMode(TRANSPARENT
);
2533 return (LRESULT
)(HBRUSH
)m_background_brush
.GetSafeHandle();
2538 bool CGitProgressDlg::CmdFetch(CString
& sWindowTitle
, bool& /*localoperation*/)
2540 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
2542 // should never run to here
2546 this->m_TotalBytesTransferred
= 0;
2548 sWindowTitle
.LoadString(IDS_PROGRS_TITLE_FETCH
);
2549 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
2550 SetBackgroundImage(IDI_UPDATE_BKG
);
2551 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
)));
2553 CStringA url
= CUnicodeUtils::GetMulti(m_url
.GetGitPathString(), CP_UTF8
);
2554 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
2555 CStringA remotebranch
= CUnicodeUtils::GetMulti(m_RefSpec
, CP_UTF8
);
2557 git_remote
*remote
= NULL
;
2558 git_repository
*repo
= NULL
;
2563 if (git_repository_open(&repo
, gitdir
.GetBuffer()))
2565 gitdir
.ReleaseBuffer();
2571 // first try with a named remote (e.g. "origin")
2572 if (git_remote_load(&remote
, repo
, url
) < 0)
2574 // retry with repository located at a specific url
2575 if (git_remote_create_inmemory(&remote
, repo
, NULL
, url
) < 0)
2583 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
2585 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
2586 callbacks
.progress
= RemoteProgressCallback
;
2587 callbacks
.completion
= RemoteCompletionCallback
;
2588 callbacks
.payload
= this;
2590 git_remote_set_callbacks(remote
, &callbacks
);
2591 git_remote_set_cred_acquire_cb(remote
, CAppUtils::Git2GetUserPassword
, NULL
);
2592 git_remote_set_autotag(remote
, (git_remote_autotag_option_t
)m_AutoTag
);
2594 if (!remotebranch
.IsEmpty() && git_remote_set_fetchspec(remote
, remotebranch
))
2601 m_Animate
.ShowWindow(SW_SHOW
);
2602 m_Animate
.Play(0, INT_MAX
, INT_MAX
);
2604 // Connect to the remote end specifying that we want to fetch
2605 // information from it.
2606 if (git_remote_connect(remote
, GIT_DIRECTION_FETCH
) < 0) {
2612 // Download the packfile and index it. This function updates the
2613 // amount of received data and the indexer stats which lets you
2614 // inform the user about progress.
2615 if (git_remote_download(remote
, FetchCallback
, this) < 0) {
2621 m_Animate
.ShowWindow(SW_HIDE
);
2622 // Update the references in the remote's namespace to point to the
2623 // right commits. This may be needed even if there was no packfile
2624 // to download, which can happen e.g. when the branches have been
2625 // changed but all the neede objects are available locally.
2626 if (git_remote_update_tips(remote
) < 0)
2633 git_remote_disconnect(remote
);
2637 git_remote_free(remote
);
2638 git_repository_free(repo
);
2639 m_Animate
.ShowWindow(SW_HIDE
);