1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - TortoiseGit
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 "CommitDlg.h"
23 #include "DirFileEnum.h"
24 //#include "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
28 #include "PathUtils.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
34 #include "UnicodeUtils.h"
35 #include "../TGitCache/CacheInterface.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
42 #include "SysProgressDlg.h"
47 static char THIS_FILE
[] = __FILE__
;
50 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
52 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
53 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
54 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
56 , m_bShowUnversioned(FALSE
)
58 , m_bThreadRunning(FALSE
)
61 , m_bWholeProject(FALSE
)
62 , m_bKeepChangeList(TRUE
)
63 , m_bDoNotAutoselectSubmodules(FALSE
)
65 , m_bSelectFilesForCommit(TRUE
)
66 , m_bNoPostActions(FALSE
)
68 , m_bSetCommitDateTime(FALSE
)
69 , m_bCreateNewBranch(FALSE
)
70 , m_bCreateTagAfterCommit(FALSE
)
72 this->m_bCommitAmend
=FALSE
;
73 m_bPushAfterCommit
= FALSE
;
76 CCommitDlg::~CCommitDlg()
84 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
86 CResizableStandAloneDialog::DoDataExchange(pDX
);
87 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
88 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
89 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
90 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
91 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
92 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
93 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
94 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
95 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
96 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
97 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
98 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
99 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
100 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
101 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
102 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
103 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
106 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
107 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
108 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
109 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
110 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
111 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
112 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
113 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
114 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
115 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
116 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
117 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
118 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
120 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
123 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
124 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
125 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
126 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
127 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
128 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
132 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
133 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
134 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
135 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
136 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
139 BOOL
CCommitDlg::OnInitDialog()
141 CResizableStandAloneDialog::OnInitDialog();
142 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
144 CAppUtils::GetCommitTemplate(this->m_sLogMessage
);
147 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
148 if(PathFileExists(dotGitPath
+ _T("MERGE_MSG")))
151 if(file
.Open(dotGitPath
+ _T("MERGE_MSG"), CFile::modeRead
))
154 while(file
.ReadString(str
))
156 m_sLogMessage
+= str
;
158 m_sLogMessage
+= _T("\n");
163 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
164 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
166 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
167 m_bShowUnversioned
= m_regAddBeforeCommit
;
169 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
171 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
172 m_bKeepChangeList
= m_regKeepChangelists
;
174 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
175 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
177 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
180 // m_bWholeProject = config.KeepLocks();
182 if(this->m_pathList
.GetCount() == 0)
183 m_bWholeProject
=true;
185 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
186 m_bWholeProject
=true;
192 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
|GITSLC_COLDEL
, _T("CommitDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
)));
193 m_ListCtrl
.SetSelectButton(&m_SelectAll
);
194 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
195 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
196 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
197 m_ListCtrl
.EnableFileDrop();
198 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
200 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
201 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
203 m_cLogMessage
.Init(m_ProjectProperties
);
204 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
205 m_cLogMessage
.RegisterContextMenuHandler(this);
207 OnEnChangeLogmessage();
209 m_tooltips
.Create(this);
210 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
211 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
212 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
214 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
216 CBugTraqAssociations bugtraq_associations
;
217 bugtraq_associations
.Load();
219 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
221 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
222 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
224 CComPtr
<IBugTraqProvider
> pProvider
;
225 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
228 m_BugTraqProvider
= pProvider
;
230 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
232 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
233 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
234 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
240 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
242 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
244 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
245 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
246 if (!m_ProjectProperties
.sLabel
.IsEmpty())
247 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
248 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
249 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
250 GetDlgItem(IDC_BUGID
)->SetFocus();
251 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
252 if (!sBugID
.IsEmpty())
254 SetDlgItemText(IDC_BUGID
, sBugID
);
259 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
260 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
261 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
262 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
263 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
266 if (!m_sLogMessage
.IsEmpty())
267 m_cLogMessage
.SetText(m_sLogMessage
);
269 GetWindowText(m_sWindowTitle
);
271 AdjustControlSize(IDC_SHOWUNVERSIONED
);
272 AdjustControlSize(IDC_SELECTALL
);
273 AdjustControlSize(IDC_WHOLE_PROJECT
);
275 GetClientRect(m_DlgOrigRect
);
276 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
278 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
279 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
280 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
281 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
282 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
283 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
284 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
285 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
286 // AddAnchor(IDC_HISTORY, TOP_LEFT);
287 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
288 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
289 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
290 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
291 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
292 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
293 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
294 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
295 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
296 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
297 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
298 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
299 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
300 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
301 AddAnchor(IDOK
, BOTTOM_RIGHT
);
302 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
303 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
304 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
305 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
306 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
307 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
308 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
311 CenterWindow(CWnd::FromHandle(hWndExplorer
));
312 EnableSaveRestore(_T("CommitDlg"));
313 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
314 RECT rcDlg
, rcLogMsg
, rcFileList
;
315 GetClientRect(&rcDlg
);
316 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
317 ScreenToClient(&rcLogMsg
);
318 m_ListCtrl
.GetWindowRect(&rcFileList
);
319 ScreenToClient(&rcFileList
);
323 m_wndSplitter
.GetWindowRect(&rectSplitter
);
324 ScreenToClient(&rectSplitter
);
325 int delta
= yPos
- rectSplitter
.top
;
326 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
328 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
333 // add all directories to the watcher
335 for (int i=0; i<m_pathList.GetCount(); ++i)
337 if (m_pathList[i].IsDirectory())
338 m_pathwatcher.AddPath(m_pathList[i]);
341 m_updatedPathList
= m_pathList
;
343 //first start a thread to obtain the file list with the status without
344 //blocking the dialog
345 InterlockedExchange(&m_bBlock
, TRUE
);
346 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
349 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
350 InterlockedExchange(&m_bBlock
, FALSE
);
354 m_pThread
->m_bAutoDelete
= FALSE
;
355 m_pThread
->ResumeThread();
357 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
358 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
359 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
362 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
366 if (g_Git
.IsInitRepos())
368 m_bCommitAmend
= FALSE
;
369 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
376 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
377 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
380 CGitHash hash
= g_Git
.GetHash(_T("HEAD"));
382 headRevision
.GetParentFromHash(hash
);
383 // do not allow to show diff to "last" revision if it has more that one parent
384 if (headRevision
.ParentsCount() != 1)
386 m_bAmendDiffToLastCommit
= true;
388 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(FALSE
);
392 this->m_ctrlShowPatch
.SetURL(CString());
394 BOOL viewPatchEnabled
= FALSE
;
395 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
396 if (viewPatchEnabled
)
397 OnStnClickedViewPatch();
399 return FALSE
; // return TRUE unless you set the focus to a control
400 // EXCEPTION: OCX Property Pages should return FALSE
403 void CCommitDlg::OnOK()
407 if (m_bThreadRunning
)
410 InterlockedExchange(&m_bRunThread
, FALSE
);
411 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
412 if (m_bThreadRunning
)
414 // we gave the thread a chance to quit. Since the thread didn't
415 // listen to us we have to kill it.
416 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
417 InterlockedExchange(&m_bThreadRunning
, FALSE
);
422 if (m_bCreateNewBranch
&& !g_Git
.IsBranchNameValid(m_sCreateNewBranch
))
424 ShowEditBalloon(IDC_NEWBRANCH
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
429 GetDlgItemText(IDC_BUGID
, id
);
430 if (!m_ProjectProperties
.CheckBugID(id
))
432 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, TTI_ERROR
);
435 m_sLogMessage
= m_cLogMessage
.GetText();
436 if ( m_sLogMessage
.IsEmpty() )
438 // no message entered, go round again
439 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
442 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
444 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
448 BOOL bWarnNoSignedOffBy
= FALSE
;
449 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
450 if (bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
452 UINT retval
= CMessageBox::Show(this->m_hWnd
, IDS_PROC_COMMIT_NOSIGNOFFLINE
, IDS_APPNAME
, 1, IDI_WARNING
, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON
, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON
, IDS_ABORTBUTTON
);
455 OnBnClickedSignOff();
456 m_sLogMessage
= m_cLogMessage
.GetText();
458 else if (retval
== 3)
462 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
463 m_pathwatcher
.Stop();
464 InterlockedExchange(&m_bBlock
, TRUE
);
465 CDWordArray arDeleted
;
466 //first add all the unversioned files the user selected
467 //and check if all versioned files are selected
470 int nListItems
= m_ListCtrl
.GetItemCount();
472 CTGitPathList itemsToAdd
;
473 CTGitPathList itemsToRemove
;
474 //std::set<CString> checkedLists;
475 //std::set<CString> uncheckedLists;
477 // now let the bugtraq plugin check the commit message
478 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
479 if (m_BugTraqProvider
)
481 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
485 CString common
= g_Git
.m_CurrentDir
;
486 BSTR repositoryRoot
= common
.AllocSysString();
487 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
488 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
489 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
490 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
492 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
493 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
495 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
499 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
500 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
504 CString sError
= temp
;
505 if (!sError
.IsEmpty())
507 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
515 //CString checkedfiles;
516 //CString uncheckedfiles;
521 bool bAddSuccess
=true;
522 bool bCloseCommitDlg
=false;
524 CSysProgressDlg sysProgressDlg
;
525 if (nListItems
>= 25 && sysProgressDlg
.IsValid())
527 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
528 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
529 sysProgressDlg
.SetTime(true);
530 sysProgressDlg
.SetShowProgressBar(true);
531 sysProgressDlg
.ShowModal(this, true);
534 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
535 DWORD currentTicks
= GetTickCount();
537 for (int j
=0; j
<nListItems
; j
++)
539 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
540 if (sysProgressDlg
.IsValid())
542 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
544 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
545 sysProgressDlg
.SetProgress(j
, nListItems
);
546 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
547 currentTicks
= GetTickCount();
550 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
551 if (entry
->m_Checked
)
554 if (entry
->status
== Git_wc_status_unversioned
)
556 itemsToAdd
.AddPath(entry
->GetPath());
558 if (entry
->status
== Git_wc_status_conflicted
)
560 bHasConflicted
= true;
562 if (entry
->status
== Git_wc_status_missing
)
564 itemsToRemove
.AddPath(entry
->GetPath());
566 if (entry
->status
== Git_wc_status_deleted
)
570 if (entry
->IsInExternal())
572 bCheckedInExternal
= true;
575 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
576 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
577 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
578 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
580 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
582 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
584 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
585 bAddSuccess
= false ;
589 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
590 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
592 g_Git
.Run(cmd
, &out
, CP_UTF8
);
596 //checkedLists.insert(entry->GetGitPathString());
597 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
601 //uncheckedLists.insert(entry->GetGitPathString());
602 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
603 { //To init git repository, there are not HEAD, so we can use git reset command
604 cmd
.Format(_T("git.exe rm -f --cache -- \"%s\""),entry
->GetGitPathString());
605 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
607 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
608 bAddSuccess
= false ;
609 bCloseCommitDlg
=false;
614 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
616 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
618 cmd
.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry
->GetGitPathString());
622 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
624 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
626 /* when reset a unstage file will report error.
627 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
628 bAddSuccess = false ;
629 bCloseCommitDlg=false;
633 // && !entry->IsDirectory()
634 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
638 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
640 if ((entry
->status
!= Git_wc_status_unversioned
) &&
641 (entry
->status
!= Git_wc_status_ignored
))
644 uncheckedLists
.insert(entry
->GetChangeList());
647 // This algorithm is for the sake of simplicity of the complexity O(N?
648 for (int k
=0; k
<nListItems
; k
++)
650 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
651 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
653 // Fall back to a non-recursive commit to prevent items being
654 // committed which aren't checked although its parent is checked
655 // (property change, directory deletion, ... )
656 m_bRecursive
= false;
665 if (sysProgressDlg
.IsValid() && sysProgressDlg
.HasUserCancelled())
671 CShellUpdater::Instance().AddPathForUpdate(*entry
);
674 if (sysProgressDlg
.IsValid())
675 sysProgressDlg
.Stop();
677 if (bAddSuccess
&& m_bCreateNewBranch
)
679 if (g_Git
.Run(_T("git branch ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
681 MessageBox(_T("Creating new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
684 if (g_Git
.Run(_T("git checkout ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
686 MessageBox(_T("Switching to new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
691 if (bAddSuccess
&& CheckHeadDetach())
694 //if(uncheckedfiles.GetLength()>0)
696 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
697 // g_Git.Run(cmd,&out);
701 if (!m_sBugID
.IsEmpty())
703 m_sBugID
.Replace(_T(", "), _T(","));
704 m_sBugID
.Replace(_T(" ,"), _T(","));
705 CString sBugID
= m_ProjectProperties
.sMessage
;
706 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
707 if (m_ProjectProperties
.bAppend
)
708 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
710 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
713 //if(checkedfiles.GetLength()>0)
714 if (bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
716 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
717 // g_Git.Run(cmd,&out);
719 bCloseCommitDlg
= true;
721 CString tempfile
=::GetTempFile();
723 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
724 //file.WriteString(m_sLogMessage);
726 CTGitPath path
=g_Git
.m_CurrentDir
;
728 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
732 if(this->m_bCommitAmend
)
737 if (m_bSetCommitDateTime
)
740 m_CommitDate
.GetTime(date
);
741 m_CommitTime
.GetTime(time
);
742 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
744 cmd
.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime
, amend
, tempfile
);
746 CCommitProgressDlg progress
;
747 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
748 progress
.m_GitCmd
=cmd
;
749 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
750 progress
.m_PreText
= out
; // show any output already generated in log window
751 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
753 if (!m_bNoPostActions
&& !m_bAutoClose
)
755 progress
.m_PostCmdList
.Add( IsGitSVN
? CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)): CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
756 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT
)));
757 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG
)));
760 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
762 DWORD userResponse
= progress
.DoModal();
764 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
766 bCloseCommitDlg
= false;
767 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
769 this->m_sLogMessage
.Empty();
770 m_cLogMessage
.SetText(m_sLogMessage
);
775 else if(userResponse
== IDC_PROGRESS_BUTTON1
+ 2)
777 m_bCreateTagAfterCommit
=true;
779 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
781 //User pressed 'Push' button after successful commit.
782 m_bPushAfterCommit
=true;
785 CFile::Remove(tempfile
);
787 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
789 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
790 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
793 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
794 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
796 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
797 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
799 BSTR logMessage
= m_sLogMessage
.AllocSysString();
801 CGitHash hash
=g_Git
.GetHash(_T("HEAD"));
802 LONG version
= g_Git
.Hash2int(hash
);
805 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
814 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
818 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
819 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
826 RestoreFiles(progress
.m_GitStatus
== 0);
830 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
831 bCloseCommitDlg
=false;
834 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
836 // There are paths which got changed (touched at least).
837 // We have to find out if this affects the selection in the commit dialog
838 // If it could affect the selection, revert back to a non-recursive commit
839 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
840 changedList
.RemoveDuplicates();
841 for (int i
=0; i
<changedList
.GetCount(); ++i
)
843 if (changedList
[i
].IsAdminDir())
845 // something inside an admin dir was changed.
846 // if it's the entries file, then we have to fully refresh because
847 // files may have been added/removed from version control
848 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
849 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
851 m_bRecursive
= false;
855 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
857 // a path which is not shown in the list has changed
858 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
861 // check if the changed path would get committed by a recursive commit
862 if ((!entry
->IsFromDifferentRepository()) &&
863 (!entry
->IsInExternal()) &&
864 (!entry
->IsNested()) &&
865 (!entry
->IsChecked()))
867 m_bRecursive
= false;
876 // Now, do all the adds - make sure that the list is sorted so that parents
877 // are added before their children
878 itemsToAdd
.SortByPathname();
880 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
882 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
883 InterlockedExchange(&m_bBlock
, FALSE
);
888 // Remove any missing items
889 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
890 itemsToRemove
.SortByPathname();
891 Git
.Remove(itemsToRemove
, TRUE
);
893 //the next step: find all deleted files and check if they're
894 //inside a deleted folder. If that's the case, then remove those
895 //files from the list since they'll get deleted by the parent
896 //folder automatically.
897 m_ListCtrl
.Block(TRUE
, FALSE
);
898 INT_PTR nDeleted
= arDeleted
.GetCount();
899 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
901 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
903 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
904 if (path
.IsDirectory())
906 //now find all children of this directory
907 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
911 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
912 if (childEntry
->IsChecked())
914 if (path
.IsAncestorOf(childEntry
->GetPath()))
916 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
925 m_ListCtrl
.Block(FALSE
, FALSE
);
927 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
929 //save only the files the user has checked into the temporary file
930 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
933 // the item count is used in the progress dialog to show the overall commit
935 // deleted items only send one notification event, all others send two
936 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
938 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
940 // all checked items belong to the same changelist
941 // find out if there are any unchecked items which belong to that changelist
942 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
943 m_sChangeList
= *checkedLists
.begin();
947 m_regAddBeforeCommit
= m_bShowUnversioned
;
948 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
949 m_bWholeProject
= FALSE
;
950 m_regKeepChangelists
= m_bKeepChangeList
;
951 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
952 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
953 m_bKeepChangeList
= FALSE
;
954 InterlockedExchange(&m_bBlock
, FALSE
);
956 m_History
.AddEntry(m_sLogMessage
);
961 if( bCloseCommitDlg
)
962 CResizableStandAloneDialog::OnOK();
964 CShellUpdater::Instance().Flush();
967 void CCommitDlg::SaveSplitterPos()
971 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
973 m_wndSplitter
.GetWindowRect(&rectSplitter
);
974 ScreenToClient(&rectSplitter
);
975 regPos
= rectSplitter
.top
;
979 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
981 return ((CCommitDlg
*)pVoid
)->StatusThread();
984 UINT
CCommitDlg::StatusThread()
986 //get the status of all selected file/folders recursively
987 //and show the ones which have to be committed to the user
989 InterlockedExchange(&m_bBlock
, TRUE
);
990 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
991 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
993 m_pathwatcher
.Stop();
995 g_Git
.RefreshGitIndex();
997 m_bCancelled
= false;
999 DialogEnableWindow(IDOK
, false);
1000 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1001 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1002 DialogEnableWindow(IDC_SELECTALL
, false);
1003 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1004 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1005 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1006 // read the list of recent log entries before querying the WC for status
1007 // -> the user may select one and modify / update it while we are crawling the WC
1009 if (m_History
.GetCount()==0)
1012 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1013 reg
.Replace(_T(':'),_T('_'));
1014 m_History
.Load(reg
, _T("logmsgs"));
1017 // Initialise the list control with the status of the files/folders below us
1020 CTGitPathList
*pList
;
1021 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
) && (m_bAmendDiffToLastCommit
==FALSE
);
1022 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1027 pList
= &m_pathList
;
1029 success
=m_ListCtrl
.GetStatus(pList
);
1031 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1032 if(this->m_bShowUnversioned
)
1033 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1035 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1037 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
;
1038 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1041 if (m_checkedPathList
.GetCount())
1042 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1045 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1046 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1047 m_ListCtrl
.Show(dwShow
, dwCheck
);
1048 m_bSelectFilesForCommit
= true;
1051 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1053 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1054 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1057 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1058 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1062 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1063 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1064 m_ListCtrl
.Show(dwShow
);
1067 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1068 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
1071 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1072 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1074 m_bShowUnversioned
= TRUE
;
1075 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1076 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1077 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1078 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1085 // we don't have to block the commit dialog while we fetch the
1086 // auto completion list.
1087 m_pathwatcher
.ClearChangedPaths();
1088 InterlockedExchange(&m_bBlock
, FALSE
);
1089 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1091 m_ListCtrl
.Block(TRUE
, TRUE
);
1092 GetAutocompletionList();
1093 m_ListCtrl
.Block(FALSE
, FALSE
);
1098 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1099 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1100 DialogEnableWindow(IDC_SELECTALL
, true);
1101 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1102 if (m_ListCtrl
.HasChangeLists())
1103 DialogEnableWindow(IDC_KEEPLISTS
, true);
1104 if (m_ListCtrl
.HasLocks())
1105 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1106 // we have the list, now signal the main thread about it
1107 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1110 InterlockedExchange(&m_bRunThread
, FALSE
);
1111 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1112 // force the cursor to normal
1118 void CCommitDlg::SetDlgTitle()
1120 if (m_sTitle
.IsEmpty())
1121 GetWindowText(m_sTitle
);
1123 if (m_bWholeProject
)
1124 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1127 if (m_pathList
.GetCount() == 1)
1128 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1130 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1134 void CCommitDlg::OnCancel()
1136 m_bCancelled
= true;
1137 m_pathwatcher
.Stop();
1139 if (m_bThreadRunning
)
1141 InterlockedExchange(&m_bRunThread
, FALSE
);
1142 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1143 if (m_bThreadRunning
)
1145 // we gave the thread a chance to quit. Since the thread didn't
1146 // listen to us we have to kill it.
1147 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1148 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1153 m_sLogMessage
= m_cLogMessage
.GetText();
1154 if (!m_sBugID
.IsEmpty())
1156 m_sBugID
.Replace(_T(", "), _T(","));
1157 m_sBugID
.Replace(_T(" ,"), _T(","));
1158 CString sBugID
= m_ProjectProperties
.sMessage
;
1159 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1160 if (m_ProjectProperties
.bAppend
)
1161 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1163 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1165 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1166 m_History
.AddEntry(m_sLogMessage
);
1170 CResizableStandAloneDialog::OnCancel();
1173 void CCommitDlg::OnBnClickedSelectall()
1175 m_tooltips
.Pop(); // hide the tooltips
1176 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1177 if (state
== BST_INDETERMINATE
)
1179 // It is not at all useful to manually place the checkbox into the indeterminate state...
1180 // We will force this on to the unchecked state
1181 state
= BST_UNCHECKED
;
1182 m_SelectAll
.SetCheck(state
);
1184 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1187 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1190 m_tooltips
.RelayEvent(pMsg
);
1194 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1199 if (pMsg
->message
== WM_KEYDOWN
)
1201 switch (pMsg
->wParam
)
1206 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1212 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1214 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1216 PostMessage(WM_COMMAND
, IDOK
);
1220 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1222 // Pressing RETURN in the bug id control
1223 // moves the focus to the message
1224 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1232 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1235 void CCommitDlg::Refresh()
1237 if (m_bThreadRunning
)
1240 InterlockedExchange(&m_bBlock
, TRUE
);
1241 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1242 if (m_pThread
==NULL
)
1244 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1245 InterlockedExchange(&m_bBlock
, FALSE
);
1249 m_pThread
->m_bAutoDelete
= FALSE
;
1250 m_pThread
->ResumeThread();
1254 void CCommitDlg::OnBnClickedHelp()
1259 void CCommitDlg::OnBnClickedShowunversioned()
1261 m_tooltips
.Pop(); // hide the tooltips
1263 m_regAddBeforeCommit
= m_bShowUnversioned
;
1266 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1267 if (DWORD(m_regAddBeforeCommit
))
1268 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1270 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1271 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1274 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1276 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1278 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1282 void CCommitDlg::OnStnClickedExternalwarning()
1287 void CCommitDlg::OnEnChangeLogmessage()
1292 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1295 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1297 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1299 m_bShowUnversioned
= TRUE
;
1300 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1301 m_ListCtrl
.Show(dwShow
);
1309 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1315 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1319 SetForegroundWindow();
1321 // if multiple files/folders are dropped
1322 // this handler is called for every single item
1324 // To avoid creating multiple refresh threads and
1325 // causing crashes, we only add the items to the
1326 // list control and start a timer.
1327 // When the timer expires, we start the refresh thread,
1328 // but only if it isn't already running - otherwise we
1329 // restart the timer.
1331 path
.SetFromWin((LPCTSTR
)lParam
);
1333 // just add all the items we get here.
1334 // if the item is versioned, the add will fail but nothing
1335 // more will happen.
1337 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1339 if (!m_ListCtrl
.HasPath(path
))
1341 if (m_pathList
.AreAllPathsFiles())
1343 m_pathList
.AddPath(path
);
1344 m_pathList
.RemoveDuplicates();
1345 m_updatedPathList
.AddPath(path
);
1346 m_updatedPathList
.RemoveDuplicates();
1350 // if the path list contains folders, we have to check whether
1351 // our just (maybe) added path is a child of one of those. If it is
1352 // a child of a folder already in the list, we must not add it. Otherwise
1353 // that path could show up twice in the list.
1354 bool bHasParentInList
= false;
1355 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1357 if (m_pathList
[i
].IsAncestorOf(path
))
1359 bHasParentInList
= true;
1363 if (!bHasParentInList
)
1365 m_pathList
.AddPath(path
);
1366 m_pathList
.RemoveDuplicates();
1367 m_updatedPathList
.AddPath(path
);
1368 m_updatedPathList
.RemoveDuplicates();
1373 // Always start the timer, since the status of an existing item might have changed
1374 SetTimer(REFRESHTIMER
, 200, NULL
);
1375 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1380 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1382 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1386 //////////////////////////////////////////////////////////////////////////
1387 // functions which run in the status thread
1388 //////////////////////////////////////////////////////////////////////////
1390 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1395 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1396 while (m_bRunThread
&& file
.ReadString(strLine
))
1398 int eqpos
= strLine
.Find('=');
1400 rgx
= strLine
.Mid(eqpos
+1).Trim();
1403 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1405 mapRegex
[strLine
.Left(pos
)] = rgx
;
1406 strLine
= strLine
.Mid(pos
+1).Trim();
1408 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1412 catch (CFileException
* pE
)
1414 TRACE("CFileException loading auto list regex file\n");
1419 void CCommitDlg::GetAutocompletionList()
1421 // the auto completion list is made of strings from each selected files.
1422 // the strings used are extracted from the files with regexes found
1423 // in the file "autolist.txt".
1424 // the format of that file is:
1425 // file extensions separated with commas '=' regular expression to use
1427 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1428 // .cpp = (?<=[^\s]::)\b\w+\b
1430 std::map
<CString
, CString
> mapRegex
;
1431 CString sRegexFile
= CPathUtils::GetAppDirectory();
1432 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1433 DWORD timeoutvalue
= regtimeout
*1000;
1434 sRegexFile
+= _T("autolist.txt");
1437 ParseRegexFile(sRegexFile
, mapRegex
);
1438 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1439 sRegexFile
.ReleaseBuffer();
1440 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1441 if (PathFileExists(sRegexFile
))
1443 ParseRegexFile(sRegexFile
, mapRegex
);
1445 DWORD starttime
= GetTickCount();
1447 // now we have two arrays of strings, where the first array contains all
1448 // file extensions we can use and the second the corresponding regex strings
1449 // to apply to those files.
1451 // the next step is to go over all files shown in the commit dialog
1452 // and scan them for strings we can use
1453 int nListItems
= m_ListCtrl
.GetItemCount();
1455 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1457 // stop parsing after timeout
1458 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1461 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1466 CString sPartPath
=path
->GetGitPathString();
1467 m_autolist
.insert(sPartPath
);
1469 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1473 // add the path parts to the auto completion list too
1474 // CString sPartPath = entry->GetRelativeGitPath();
1475 // m_autolist.insert(sPartPath);
1480 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1484 m_autolist
.insert(sPartPath
.Mid(pos
));
1487 // Last inserted entry is a file name.
1488 // Some users prefer to also list file name without extension.
1489 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1491 int dotPos
= sPartPath
.ReverseFind('.');
1492 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1493 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1496 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1499 CString sExt
= entry
->GetPath().GetFileExtension();
1501 // find the regex string which corresponds to the file extension
1502 CString rdata
= mapRegex
[sExt
];
1503 if (rdata
.IsEmpty())
1506 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1507 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1508 (entry
->textstatus
!= Git_wc_status_none
) &&
1509 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1510 (entry
->textstatus
!= Git_wc_status_added
) &&
1511 (entry
->textstatus
!= Git_wc_status_normal
))
1513 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1514 if (!basePath
.IsEmpty())
1515 ScanFile(basePath
.GetWinPathString(), rdata
);
1519 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1522 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1524 wstring sFileContent
;
1525 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1526 if (hFile
!= INVALID_HANDLE_VALUE
)
1528 DWORD size
= GetFileSize(hFile
, NULL
);
1529 if (size
> 1000000L)
1531 // no files bigger than 1 Meg
1535 // allocate memory to hold file contents
1536 char * buffer
= new char[size
];
1538 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1541 IsTextUnicode(buffer
, readbytes
, &opts
);
1542 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1547 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1549 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1551 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1553 int ret
= MultiByteToWideChar(CP_UTF8
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1554 wchar_t * pWideBuf
= new wchar_t[ret
];
1555 int ret2
= MultiByteToWideChar(CP_UTF8
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1557 sFileContent
= wstring(pWideBuf
, ret
);
1562 if (sFileContent
.empty()|| !m_bRunThread
)
1569 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1570 const tr1::wsregex_iterator end
;
1571 wstring s
= sFileContent
;
1572 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1574 const tr1::wsmatch match
= *it
;
1575 for (size_t i
=1; i
<match
.size(); ++i
)
1577 if (match
[i
].second
-match
[i
].first
)
1579 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1580 m_autolist
.insert(wstring(match
[i
]).c_str());
1585 catch (exception
) {}
1588 // CSciEditContextMenuInterface
1589 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1591 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1592 m_nPopupPasteListCmd
= nCmd
++;
1593 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1595 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1596 if(m_History
.GetCount() > 0)
1598 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1599 m_nPopupPasteLastMessage
= nCmd
++;
1600 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1602 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1603 m_nPopupRecentMessage
= nCmd
++;
1604 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1610 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1615 if (cmd
== m_nPopupPasteListCmd
)
1618 int nListItems
= m_ListCtrl
.GetItemCount();
1619 for (int i
=0; i
<nListItems
; ++i
)
1621 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1622 if (entry
&&entry
->m_Checked
)
1625 CString status
= entry
->GetActionName();
1626 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1627 status
= _T("Add"); // I18N TODO
1629 //git_wc_status_kind status = entry->status;
1630 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1631 if (m_ProjectProperties
.bFileListInEnglish
)
1634 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1638 pSciEdit
->InsertText(logmsg
);
1642 if(cmd
== m_nPopupPasteLastMessage
)
1644 if(m_History
.GetCount() ==0 )
1648 logmsg
+=m_History
.GetEntry(0);
1649 pSciEdit
->InsertText(logmsg
);
1653 if(cmd
== m_nPopupRecentMessage
)
1655 OnBnClickedHistory();
1661 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1665 case ENDDIALOGTIMER
:
1666 KillTimer(ENDDIALOGTIMER
);
1670 if (m_bThreadRunning
)
1672 SetTimer(REFRESHTIMER
, 200, NULL
);
1673 ATLTRACE("Wait some more before refreshing\n");
1677 KillTimer(REFRESHTIMER
);
1678 ATLTRACE("Refreshing after items dropped\n");
1683 __super::OnTimer(nIDEvent
);
1686 void CCommitDlg::OnBnClickedHistory()
1688 m_tooltips
.Pop(); // hide the tooltips
1689 if (m_pathList
.GetCount() == 0)
1692 CHistoryDlg historyDlg
;
1693 historyDlg
.SetHistory(m_History
);
1694 if (historyDlg
.DoModal() != IDOK
)
1697 CString sMsg
= historyDlg
.GetSelectedText();
1698 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1700 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1701 if (!sBugID
.IsEmpty())
1703 SetDlgItemText(IDC_BUGID
, sBugID
);
1705 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1706 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1708 m_cLogMessage
.SetText(sMsg
);
1712 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1716 void CCommitDlg::OnBnClickedBugtraqbutton()
1718 m_tooltips
.Pop(); // hide the tooltips
1719 CString sMsg
= m_cLogMessage
.GetText();
1721 if (m_BugTraqProvider
== NULL
)
1724 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1725 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1726 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1728 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1729 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1731 BSTR originalMessage
= sMsg
.AllocSysString();
1733 // m_revProps.clear();
1735 // first try the IBugTraqProvider2 interface
1736 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1737 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1740 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1741 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1742 BSTR bugIDOut
= NULL
;
1743 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1744 BSTR bugID
= m_sBugID
.AllocSysString();
1745 SAFEARRAY
* revPropNames
= NULL
;
1746 SAFEARRAY
* revPropValues
= NULL
;
1747 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1750 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1751 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1757 m_sBugID
= bugIDOut
;
1758 SysFreeString(bugIDOut
);
1759 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1761 SysFreeString(bugID
);
1762 SysFreeString(repositoryRoot
);
1763 m_cLogMessage
.SetText(temp
);
1764 BSTR HUGEP
*pbRevNames
;
1765 BSTR HUGEP
*pbRevValues
;
1767 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1770 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1773 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1775 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1777 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1780 SafeArrayUnaccessData(revPropValues
);
1782 SafeArrayUnaccessData(revPropNames
);
1785 SafeArrayDestroy(revPropNames
);
1787 SafeArrayDestroy(revPropValues
);
1792 // if IBugTraqProvider2 failed, try IBugTraqProvider
1793 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1794 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1798 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1799 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1803 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1806 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1807 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1810 m_cLogMessage
.SetText(temp
);
1812 m_sLogMessage
= m_cLogMessage
.GetText();
1813 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1815 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1816 if (!sBugID
.IsEmpty())
1818 SetDlgItemText(IDC_BUGID
, sBugID
);
1822 m_cLogMessage
.SetFocus();
1824 SysFreeString(parameters
);
1825 SysFreeString(commonRoot
);
1826 SafeArrayDestroy(pathList
);
1827 SysFreeString(originalMessage
);
1828 SysFreeString(temp
);
1832 void CCommitDlg::FillPatchView()
1834 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1836 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1838 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1839 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1844 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1845 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1846 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1848 CString head
= _T("HEAD");
1849 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
1850 head
= _T("HEAD~1");
1851 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
1852 g_Git
.Run(cmd
, &out
, CP_UTF8
);
1856 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1857 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1858 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1860 m_patchViewdlg
.m_ctrlPatchView
.GetClientRect(rect
);
1861 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect
.Width() - 4);
1864 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
1866 this->FillPatchView();
1871 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1877 void CCommitDlg::UpdateOKButton()
1882 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
1883 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1885 DialogEnableWindow(IDOK
, bValidLogSize
&& bAmendOrSelectFilesOrMerge
);
1888 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1892 if (wParam
== IDC_SPLITTER
)
1894 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1895 DoSize(pHdr
->delta
);
1900 return __super::DefWindowProc(message
, wParam
, lParam
);
1903 void CCommitDlg::SetSplitterRange()
1905 if ((m_ListCtrl
)&&(m_cLogMessage
))
1908 m_cLogMessage
.GetWindowRect(rcTop
);
1909 ScreenToClient(rcTop
);
1911 m_ListCtrl
.GetWindowRect(rcMiddle
);
1912 ScreenToClient(rcMiddle
);
1913 if (rcMiddle
.Height() && rcMiddle
.Width())
1914 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1918 void CCommitDlg::DoSize(int delta
)
1920 RemoveAnchor(IDC_MESSAGEGROUP
);
1921 RemoveAnchor(IDC_LOGMESSAGE
);
1922 RemoveAnchor(IDC_SPLITTER
);
1923 RemoveAnchor(IDC_SIGNOFF
);
1924 RemoveAnchor(IDC_COMMIT_AMEND
);
1925 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
1926 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
1927 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
1928 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
1929 RemoveAnchor(IDC_LISTGROUP
);
1930 RemoveAnchor(IDC_FILELIST
);
1931 RemoveAnchor(IDC_TEXT_INFO
);
1933 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1934 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1935 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1936 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1937 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1938 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1939 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
1940 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
1941 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
1942 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
1943 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1945 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1946 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1947 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1948 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1949 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1950 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1951 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1952 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
1953 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
1954 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
1955 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
1956 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1958 // adjust the minimum size of the dialog to prevent the resizing from
1959 // moving the list control too far down.
1961 m_cLogMessage
.GetClientRect(rcLogMsg
);
1962 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1965 m_cLogMessage
.Invalidate();
1966 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1969 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1971 // first, let the resizing take place
1972 __super::OnSize(nType
, cx
, cy
);
1978 CString
CCommitDlg::GetSignedOffByLine()
1982 CString username
= g_Git
.GetUserName();
1983 CString email
= g_Git
.GetUserEmail();
1984 username
.Remove(_T('\n'));
1985 email
.Remove(_T('\n'));
1987 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
1992 void CCommitDlg::OnBnClickedSignOff()
1994 CString str
= GetSignedOffByLine();
1996 if (m_cLogMessage
.GetText().Find(str
) == -1) {
1997 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
1998 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
1999 int foundByLine
= -1;
2000 if (lastNewline
> 0)
2001 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2003 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2004 str
= _T("\r\n") + str
;
2006 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2010 void CCommitDlg::OnBnClickedCommitAmend()
2013 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2016 rev
.GetCommit(CString(_T("HEAD")));
2017 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2020 if(this->m_bCommitAmend
)
2022 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2023 m_cLogMessage
.SetText(m_AmendStr
);
2024 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2028 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2029 m_cLogMessage
.SetText(m_NoAmendStr
);
2030 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2033 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2038 void CCommitDlg::OnBnClickedWholeProject()
2040 m_tooltips
.Pop(); // hide the tooltips
2046 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2048 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2050 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2051 if (DWORD(m_regAddBeforeCommit
))
2052 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2054 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2056 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2062 void CCommitDlg::OnFocusMessage()
2064 m_cLogMessage
.SetFocus();
2067 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2069 UNREFERENCED_PARAMETER(pNMHDR
);
2070 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2071 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2072 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2075 str
.Format(_T("%d/%d"),line
+1,column
+1);
2076 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2081 void CCommitDlg::OnStnClickedViewPatch()
2083 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2084 m_patchViewdlg
.m_ParentCommitDlg
= this;
2085 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2087 BOOL viewPatchEnabled
= FALSE
;
2088 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
2089 if (viewPatchEnabled
== FALSE
)
2090 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2091 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2092 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2094 this->GetWindowRect(&rect
);
2096 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2098 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2099 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2101 ShowViewPatchText(false);
2106 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2107 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2108 m_patchViewdlg
.DestroyWindow();
2109 ShowViewPatchText(true);
2111 this->m_ctrlShowPatch
.Invalidate();
2114 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2116 __super::OnMoving(fwSide
, pRect
);
2118 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2121 m_patchViewdlg
.GetWindowRect(&patchrect
);
2122 if (::IsWindow(m_hWnd
))
2125 GetWindowRect(&thisrect
);
2126 if (patchrect
.left
== thisrect
.right
)
2128 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2129 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2136 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2138 __super::OnSizing(fwSide
, pRect
);
2140 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2142 CRect thisrect
, patchrect
;
2143 this->GetWindowRect(thisrect
);
2144 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2145 if(thisrect
.right
==patchrect
.left
)
2147 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2148 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2150 if( patchrect
.bottom
== thisrect
.bottom
)
2152 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2154 if( patchrect
.top
== thisrect
.top
)
2156 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2158 m_patchViewdlg
.MoveWindow(patchrect
);
2163 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2165 UNREFERENCED_PARAMETER(pNMHDR
);
2167 TRACE("Item Changed\r\n");
2170 int CCommitDlg::CheckHeadDetach()
2173 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2175 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2178 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2181 else if (retval
== IDCANCEL
)
2187 void CCommitDlg::OnBnClickedCommitAmenddiff()
2193 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2199 void CCommitDlg::OnBnClickedCommitSetDateTime()
2203 if (m_bSetCommitDateTime
)
2205 CTime authordate
= CTime::GetCurrentTime();
2208 GitRev headRevision
;
2209 headRevision
.GetCommit(_T("HEAD"));
2210 authordate
= headRevision
.GetAuthorDate();
2213 m_CommitDate
.SetTime(&authordate
);
2214 m_CommitTime
.SetTime(&authordate
);
2216 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2217 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2221 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2222 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2226 void CCommitDlg::OnBnClickedCheckNewBranch()
2229 if (m_bCreateNewBranch
)
2231 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2232 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2236 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2237 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2241 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2243 if (m_ListCtrl
.m_restorepaths
.size() && (doNotAsk
|| CMessageBox::Show(m_hWnd
, IDS_PROC_COMMIT_RESTOREFILES
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_PROC_COMMIT_RESTOREFILES_RESTORE
, IDS_PROC_COMMIT_RESTOREFILES_KEEP
) == 1))
2245 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2246 CopyFile(it
->second
, g_Git
.m_CurrentDir
+ _T("\\") + it
->first
, FALSE
);
2247 m_ListCtrl
.m_restorepaths
.clear();