1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - 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 "CommonResource.h"
35 #include "UnicodeUtils.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
46 static char THIS_FILE
[] = __FILE__
;
49 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
52 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
53 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
55 , m_bShowUnversioned(FALSE
)
57 , m_bThreadRunning(FALSE
)
60 , m_bWholeProject(FALSE
)
61 , m_bKeepChangeList(TRUE
)
62 , m_bDoNotAutoselectSubmodules(FALSE
)
64 , m_bSelectFilesForCommit(TRUE
)
65 , m_bNoPostActions(FALSE
)
68 this->m_bCommitAmend
=FALSE
;
69 m_bPushAfterCommit
= FALSE
;
72 CCommitDlg::~CCommitDlg()
80 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
82 CResizableStandAloneDialog::DoDataExchange(pDX
);
83 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
84 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
85 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
86 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
87 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
88 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
89 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
90 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
91 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
92 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
93 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
94 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
97 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
98 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
99 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
100 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
101 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
102 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
103 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
104 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
105 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
106 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
107 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE
, OnFileDropped
)
108 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
109 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
111 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
114 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
115 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
116 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
117 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
118 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
119 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
123 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
124 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
125 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
128 BOOL
CCommitDlg::OnInitDialog()
130 CResizableStandAloneDialog::OnInitDialog();
132 CAppUtils::GetCommitTemplate(this->m_sLogMessage
);
134 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG")))
137 if(file
.Open(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG"), CFile::modeRead
))
140 while(file
.ReadString(str
))
142 m_sLogMessage
+= str
;
144 m_sLogMessage
+= _T("\n");
148 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
149 m_bShowUnversioned
= m_regAddBeforeCommit
;
151 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
153 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
154 m_bKeepChangeList
= m_regKeepChangelists
;
156 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
157 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
159 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
162 // m_bWholeProject = config.KeepLocks();
164 if(this->m_pathList
.GetCount() == 0)
165 m_bWholeProject
=true;
167 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
168 m_bWholeProject
=true;
172 m_ListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
| SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("CommitDlg"),(SVNSLC_POPALL
^ (SVNSLC_POPCOMMIT
| SVNSLC_POPSAVEAS
)));
173 m_ListCtrl
.SetSelectButton(&m_SelectAll
);
174 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
175 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
176 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
177 m_ListCtrl
.EnableFileDrop();
178 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
180 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
181 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
183 m_cLogMessage
.Init(m_ProjectProperties
);
184 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
185 m_cLogMessage
.RegisterContextMenuHandler(this);
187 OnEnChangeLogmessage();
189 m_tooltips
.Create(this);
190 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
191 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
192 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
194 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
196 CBugTraqAssociations bugtraq_associations
;
197 bugtraq_associations
.Load();
199 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
201 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
202 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
204 CComPtr
<IBugTraqProvider
> pProvider
;
205 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
208 m_BugTraqProvider
= pProvider
;
210 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
212 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
213 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
214 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
220 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
222 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
224 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
225 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
226 if (!m_ProjectProperties
.sLabel
.IsEmpty())
227 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
228 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
229 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
230 GetDlgItem(IDC_BUGID
)->SetFocus();
231 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
232 if (!sBugID
.IsEmpty())
234 SetDlgItemText(IDC_BUGID
, sBugID
);
239 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
240 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
241 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
242 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
243 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
246 if (!m_sLogMessage
.IsEmpty())
247 m_cLogMessage
.SetText(m_sLogMessage
);
249 GetWindowText(m_sWindowTitle
);
251 AdjustControlSize(IDC_SHOWUNVERSIONED
);
252 AdjustControlSize(IDC_SELECTALL
);
253 AdjustControlSize(IDC_WHOLE_PROJECT
);
255 GetClientRect(m_DlgOrigRect
);
256 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
258 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
259 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
260 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
261 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
262 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
263 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
264 // AddAnchor(IDC_HISTORY, TOP_LEFT);
265 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
266 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
267 AddAnchor(IDC_VIEW_PATCH
,TOP_RIGHT
);
268 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
269 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
270 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
271 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
272 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
273 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
274 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
275 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
276 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
277 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
278 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
279 AddAnchor(IDOK
, BOTTOM_RIGHT
);
280 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
281 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
282 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
283 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
286 CenterWindow(CWnd::FromHandle(hWndExplorer
));
287 EnableSaveRestore(_T("CommitDlg"));
288 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
289 RECT rcDlg
, rcLogMsg
, rcFileList
;
290 GetClientRect(&rcDlg
);
291 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
292 ScreenToClient(&rcLogMsg
);
293 m_ListCtrl
.GetWindowRect(&rcFileList
);
294 ScreenToClient(&rcFileList
);
298 m_wndSplitter
.GetWindowRect(&rectSplitter
);
299 ScreenToClient(&rectSplitter
);
300 int delta
= yPos
- rectSplitter
.top
;
301 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
303 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
308 // add all directories to the watcher
310 for (int i=0; i<m_pathList.GetCount(); ++i)
312 if (m_pathList[i].IsDirectory())
313 m_pathwatcher.AddPath(m_pathList[i]);
316 m_updatedPathList
= m_pathList
;
318 //first start a thread to obtain the file list with the status without
319 //blocking the dialog
320 InterlockedExchange(&m_bBlock
, TRUE
);
321 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
324 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
325 InterlockedExchange(&m_bBlock
, FALSE
);
329 m_pThread
->m_bAutoDelete
= FALSE
;
330 m_pThread
->ResumeThread();
332 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
333 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
334 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
337 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
343 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
344 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
347 CGitHash hash
= g_Git
.GetHash(_T("HEAD"));
349 f
.GetParentFromHash(hash
);
350 if (f
.ParentsCount() == 0)
352 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
354 if (f
.ParentsCount() != 1)
356 m_bAmendDiffToLastCommit
= true;
358 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(FALSE
);
361 this->m_ctrlShowPatch
.SetURL(CString());
363 return FALSE
; // return TRUE unless you set the focus to a control
364 // EXCEPTION: OCX Property Pages should return FALSE
367 void CCommitDlg::OnOK()
371 if (m_bThreadRunning
)
374 InterlockedExchange(&m_bRunThread
, FALSE
);
375 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
376 if (m_bThreadRunning
)
378 // we gave the thread a chance to quit. Since the thread didn't
379 // listen to us we have to kill it.
380 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
381 InterlockedExchange(&m_bThreadRunning
, FALSE
);
387 GetDlgItemText(IDC_BUGID
, id
);
388 if (!m_ProjectProperties
.CheckBugID(id
))
390 ShowBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDI_EXCLAMATION
);
393 m_sLogMessage
= m_cLogMessage
.GetText();
394 if ( m_sLogMessage
.IsEmpty() )
396 // no message entered, go round again
397 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
400 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
402 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
406 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
408 CRegDWORD
regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
);
409 if (!(DWORD
)regUnversionedRecurse
)
411 // Find unversioned directories which are marked for commit. The user might expect them
412 // to be added recursively since he cannot the the files. Let's ask the user if he knows
414 int nListItems
= m_ListCtrl
.GetItemCount();
415 for (int j
=0; j
<nListItems
; j
++)
417 const CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(j
);
418 if (entry
->IsChecked() && (entry
->status
== Git_wc_status_unversioned
) && entry
->IsFolder() )
420 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
426 m_pathwatcher
.Stop();
427 InterlockedExchange(&m_bBlock
, TRUE
);
428 CDWordArray arDeleted
;
429 //first add all the unversioned files the user selected
430 //and check if all versioned files are selected
433 int nListItems
= m_ListCtrl
.GetItemCount();
435 CTGitPathList itemsToAdd
;
436 CTGitPathList itemsToRemove
;
437 //std::set<CString> checkedLists;
438 //std::set<CString> uncheckedLists;
440 // now let the bugtraq plugin check the commit message
441 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
442 if (m_BugTraqProvider
)
444 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
448 CString common
= g_Git
.m_CurrentDir
;
449 BSTR repositoryRoot
= common
.AllocSysString();
450 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
451 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
452 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
453 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
455 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
456 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
458 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
462 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
463 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
467 CString sError
= temp
;
468 if (!sError
.IsEmpty())
470 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
478 //CString checkedfiles;
479 //CString uncheckedfiles;
484 bool bAddSuccess
=true;
485 bool bCloseCommitDlg
=false;
487 for (int j
=0; j
<nListItems
; j
++)
489 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
490 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
491 if (entry
->m_Checked
)
494 if (entry
->status
== Git_wc_status_unversioned
)
496 itemsToAdd
.AddPath(entry
->GetPath());
498 if (entry
->status
== Git_wc_status_conflicted
)
500 bHasConflicted
= true;
502 if (entry
->status
== Git_wc_status_missing
)
504 itemsToRemove
.AddPath(entry
->GetPath());
506 if (entry
->status
== Git_wc_status_deleted
)
510 if (entry
->IsInExternal())
512 bCheckedInExternal
= true;
515 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
516 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
517 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
518 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
520 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
522 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
524 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
525 bAddSuccess
= false ;
529 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
530 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
532 g_Git
.Run(cmd
,&out
,CP_ACP
);
536 //checkedLists.insert(entry->GetGitPathString());
537 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
541 //uncheckedLists.insert(entry->GetGitPathString());
542 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
543 { //To init git repository, there are not HEAD, so we can use git reset command
544 cmd
.Format(_T("git.exe rm --cache -- \"%s\""),entry
->GetGitPathString());
545 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
547 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
548 bAddSuccess
= false ;
549 bCloseCommitDlg
=false;
554 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
556 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
558 cmd
.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry
->GetGitPathString());
562 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
564 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
566 /* when reset a unstage file will report error.
567 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
568 bAddSuccess = false ;
569 bCloseCommitDlg=false;
573 // && !entry->IsDirectory()
574 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
578 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
580 if ((entry
->status
!= Git_wc_status_unversioned
) &&
581 (entry
->status
!= Git_wc_status_ignored
))
584 uncheckedLists
.insert(entry
->GetChangeList());
587 // This algorithm is for the sake of simplicity of the complexity O(N?
588 for (int k
=0; k
<nListItems
; k
++)
590 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
591 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
593 // Fall back to a non-recursive commit to prevent items being
594 // committed which aren't checked although its parent is checked
595 // (property change, directory deletion, ... )
596 m_bRecursive
= false;
605 CShellUpdater::Instance().AddPathForUpdate(*entry
);
608 //if(uncheckedfiles.GetLength()>0)
610 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
611 // g_Git.Run(cmd,&out);
615 if (!m_sBugID
.IsEmpty())
617 m_sBugID
.Replace(_T(", "), _T(","));
618 m_sBugID
.Replace(_T(" ,"), _T(","));
619 CString sBugID
= m_ProjectProperties
.sMessage
;
620 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
621 if (m_ProjectProperties
.bAppend
)
622 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
624 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
628 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
632 //if(checkedfiles.GetLength()>0)
633 if( bAddSuccess
&& (nchecked
||m_bCommitAmend
||bIsMerge
) )
635 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
636 // g_Git.Run(cmd,&out);
638 bCloseCommitDlg
= true;
640 CString tempfile
=::GetTempFile();
642 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
643 //file.WriteString(m_sLogMessage);
645 CTGitPath path
=g_Git
.m_CurrentDir
;
647 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
651 if(this->m_bCommitAmend
)
655 cmd
.Format(_T("git.exe commit %s -F \"%s\""),amend
, tempfile
);
659 CCommitProgressDlg progress
;
660 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
661 progress
.m_GitCmd
=cmd
;
662 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
663 progress
.m_PreText
= out
; // show any output already generated in log window
664 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
666 if (!m_bNoPostActions
&& !m_bAutoClose
)
668 progress
.m_PostCmdList
.Add( IsGitSVN
? _T("&DCommit"): _T("&Push"));
669 progress
.m_PostCmdList
.Add(_T("&ReCommit"));
672 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
674 DWORD userResponse
= progress
.DoModal();
676 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
678 bCloseCommitDlg
= false;
679 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
681 this->m_sLogMessage
.Empty();
682 m_cLogMessage
.SetText(m_sLogMessage
);
687 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
689 //User pressed 'Push' button after successful commit.
690 m_bPushAfterCommit
=true;
693 CFile::Remove(tempfile
);
695 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
697 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
698 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
701 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
702 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
704 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
705 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
707 BSTR logMessage
= m_sLogMessage
.AllocSysString();
709 CGitHash hash
=g_Git
.GetHash(_T("HEAD"));
710 LONG version
= g_Git
.Hash2int(hash
);
713 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
722 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
726 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
727 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
735 }else if(bAddSuccess
)
737 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
738 bCloseCommitDlg
=false;
741 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
743 // There are paths which got changed (touched at least).
744 // We have to find out if this affects the selection in the commit dialog
745 // If it could affect the selection, revert back to a non-recursive commit
746 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
747 changedList
.RemoveDuplicates();
748 for (int i
=0; i
<changedList
.GetCount(); ++i
)
750 if (changedList
[i
].IsAdminDir())
752 // something inside an admin dir was changed.
753 // if it's the entries file, then we have to fully refresh because
754 // files may have been added/removed from version control
755 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
756 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
758 m_bRecursive
= false;
762 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
764 // a path which is not shown in the list has changed
765 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
768 // check if the changed path would get committed by a recursive commit
769 if ((!entry
->IsFromDifferentRepository()) &&
770 (!entry
->IsInExternal()) &&
771 (!entry
->IsNested()) &&
772 (!entry
->IsChecked()))
774 m_bRecursive
= false;
783 // Now, do all the adds - make sure that the list is sorted so that parents
784 // are added before their children
785 itemsToAdd
.SortByPathname();
787 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
789 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
790 InterlockedExchange(&m_bBlock
, FALSE
);
795 // Remove any missing items
796 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
797 itemsToRemove
.SortByPathname();
798 Git
.Remove(itemsToRemove
, TRUE
);
800 //the next step: find all deleted files and check if they're
801 //inside a deleted folder. If that's the case, then remove those
802 //files from the list since they'll get deleted by the parent
803 //folder automatically.
804 m_ListCtrl
.Block(TRUE
, FALSE
);
805 INT_PTR nDeleted
= arDeleted
.GetCount();
806 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
808 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
810 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
811 if (path
.IsDirectory())
813 //now find all children of this directory
814 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
818 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
819 if (childEntry
->IsChecked())
821 if (path
.IsAncestorOf(childEntry
->GetPath()))
823 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
832 m_ListCtrl
.Block(FALSE
, FALSE
);
834 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
836 //save only the files the user has checked into the temporary file
837 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
840 // the item count is used in the progress dialog to show the overall commit
842 // deleted items only send one notification event, all others send two
843 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
845 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
847 // all checked items belong to the same changelist
848 // find out if there are any unchecked items which belong to that changelist
849 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
850 m_sChangeList
= *checkedLists
.begin();
854 m_regAddBeforeCommit
= m_bShowUnversioned
;
855 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
856 m_bWholeProject
= FALSE
;
857 m_regKeepChangelists
= m_bKeepChangeList
;
858 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
859 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
860 m_bKeepChangeList
= FALSE
;
861 InterlockedExchange(&m_bBlock
, FALSE
);
863 m_History
.AddEntry(m_sLogMessage
);
868 if( bCloseCommitDlg
)
869 CResizableStandAloneDialog::OnOK();
871 CShellUpdater::Instance().Flush();
874 void CCommitDlg::SaveSplitterPos()
878 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
880 m_wndSplitter
.GetWindowRect(&rectSplitter
);
881 ScreenToClient(&rectSplitter
);
882 regPos
= rectSplitter
.top
;
886 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
888 return ((CCommitDlg
*)pVoid
)->StatusThread();
891 UINT
CCommitDlg::StatusThread()
893 //get the status of all selected file/folders recursively
894 //and show the ones which have to be committed to the user
896 InterlockedExchange(&m_bBlock
, TRUE
);
897 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
898 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
900 m_pathwatcher
.Stop();
902 g_Git
.RefreshGitIndex();
904 m_bCancelled
= false;
906 DialogEnableWindow(IDOK
, false);
907 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
908 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
909 DialogEnableWindow(IDC_SELECTALL
, false);
910 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
911 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
912 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
913 // read the list of recent log entries before querying the WC for status
914 // -> the user may select one and modify / update it while we are crawling the WC
916 if (m_History
.GetCount()==0)
919 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
920 reg
.Replace(_T(':'),_T('_'));
921 m_History
.Load(reg
, _T("logmsgs"));
924 // Initialise the list control with the status of the files/folders below us
927 CTGitPathList
*pList
;
928 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
) && (m_bAmendDiffToLastCommit
==FALSE
);
929 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
936 success
=m_ListCtrl
.GetStatus(pList
);
938 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
939 if(this->m_bShowUnversioned
)
940 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
942 m_ListCtrl
.CheckIfChangelistsArePresent(false);
944 DWORD dwShow
= SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWLOCKS
| SVNSLC_SHOWINCHANGELIST
;
945 dwShow
|= DWORD(m_regAddBeforeCommit
) ? SVNSLC_SHOWUNVERSIONED
: 0;
948 if (m_checkedPathList
.GetCount())
949 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
952 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
953 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
954 m_ListCtrl
.Show(dwShow
, dwCheck
);
955 m_bSelectFilesForCommit
= true;
958 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
960 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
961 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
964 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
965 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
969 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
970 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
971 m_ListCtrl
.Show(dwShow
);
973 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
974 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
976 if (CMessageBox::Show(m_hWnd
, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
978 m_bShowUnversioned
= TRUE
;
979 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
980 DWORD dwShow
= (DWORD
)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWUNVERSIONED
| SVNSLC_SHOWLOCKS
);
981 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
982 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
986 CTGitPath commonDir
= m_ListCtrl
.GetCommonDirectory(false);
988 if(this->m_bWholeProject
)
989 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString() + CString(_T(" (Whole Project)")));
991 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString());
994 // we don't have to block the commit dialog while we fetch the
995 // auto completion list.
996 m_pathwatcher
.ClearChangedPaths();
997 InterlockedExchange(&m_bBlock
, FALSE
);
998 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1000 m_ListCtrl
.Block(TRUE
, TRUE
);
1001 GetAutocompletionList();
1002 m_ListCtrl
.Block(FALSE
, FALSE
);
1007 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1008 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1009 DialogEnableWindow(IDC_SELECTALL
, true);
1010 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1011 if (m_ListCtrl
.HasChangeLists())
1012 DialogEnableWindow(IDC_KEEPLISTS
, true);
1013 if (m_ListCtrl
.HasLocks())
1014 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1015 // we have the list, now signal the main thread about it
1016 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1019 InterlockedExchange(&m_bRunThread
, FALSE
);
1020 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1021 // force the cursor to normal
1027 void CCommitDlg::OnCancel()
1029 m_bCancelled
= true;
1030 m_pathwatcher
.Stop();
1035 if (m_bThreadRunning
)
1037 InterlockedExchange(&m_bRunThread
, FALSE
);
1038 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1039 if (m_bThreadRunning
)
1041 // we gave the thread a chance to quit. Since the thread didn't
1042 // listen to us we have to kill it.
1043 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1044 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1049 m_sLogMessage
= m_cLogMessage
.GetText();
1050 if (!m_sBugID
.IsEmpty())
1052 m_sBugID
.Replace(_T(", "), _T(","));
1053 m_sBugID
.Replace(_T(" ,"), _T(","));
1054 CString sBugID
= m_ProjectProperties
.sMessage
;
1055 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1056 if (m_ProjectProperties
.bAppend
)
1057 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1059 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1061 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1062 m_History
.AddEntry(m_sLogMessage
);
1065 CResizableStandAloneDialog::OnCancel();
1068 void CCommitDlg::OnBnClickedSelectall()
1070 m_tooltips
.Pop(); // hide the tooltips
1071 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1072 if (state
== BST_INDETERMINATE
)
1074 // It is not at all useful to manually place the checkbox into the indeterminate state...
1075 // We will force this on to the unchecked state
1076 state
= BST_UNCHECKED
;
1077 m_SelectAll
.SetCheck(state
);
1079 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1082 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1085 m_tooltips
.RelayEvent(pMsg
);
1089 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1094 if (pMsg
->message
== WM_KEYDOWN
)
1096 switch (pMsg
->wParam
)
1101 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1107 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1109 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1111 PostMessage(WM_COMMAND
, IDOK
);
1115 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1117 // Pressing RETURN in the bug id control
1118 // moves the focus to the message
1119 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1127 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1130 void CCommitDlg::Refresh()
1132 if (m_bThreadRunning
)
1135 InterlockedExchange(&m_bBlock
, TRUE
);
1136 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1137 if (m_pThread
==NULL
)
1139 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1140 InterlockedExchange(&m_bBlock
, FALSE
);
1144 m_pThread
->m_bAutoDelete
= FALSE
;
1145 m_pThread
->ResumeThread();
1149 void CCommitDlg::OnBnClickedHelp()
1154 void CCommitDlg::OnBnClickedShowunversioned()
1156 m_tooltips
.Pop(); // hide the tooltips
1158 m_regAddBeforeCommit
= m_bShowUnversioned
;
1161 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1162 if (DWORD(m_regAddBeforeCommit
))
1163 dwShow
|= SVNSLC_SHOWUNVERSIONED
;
1165 dwShow
&= ~SVNSLC_SHOWUNVERSIONED
;
1166 if(dwShow
& SVNSLC_SHOWUNVERSIONED
)
1169 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1171 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1173 m_ListCtrl
.Show(dwShow
,0,true,0,true);
1177 void CCommitDlg::OnStnClickedExternalwarning()
1182 void CCommitDlg::OnEnChangeLogmessage()
1187 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1190 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1192 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1194 m_bShowUnversioned
= TRUE
;
1195 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1196 m_ListCtrl
.Show(dwShow
);
1204 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1210 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1214 SetForegroundWindow();
1216 // if multiple files/folders are dropped
1217 // this handler is called for every single item
1219 // To avoid creating multiple refresh threads and
1220 // causing crashes, we only add the items to the
1221 // list control and start a timer.
1222 // When the timer expires, we start the refresh thread,
1223 // but only if it isn't already running - otherwise we
1224 // restart the timer.
1226 path
.SetFromWin((LPCTSTR
)lParam
);
1228 // just add all the items we get here.
1229 // if the item is versioned, the add will fail but nothing
1230 // more will happen.
1232 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1234 if (!m_ListCtrl
.HasPath(path
))
1236 if (m_pathList
.AreAllPathsFiles())
1238 m_pathList
.AddPath(path
);
1239 m_pathList
.RemoveDuplicates();
1240 m_updatedPathList
.AddPath(path
);
1241 m_updatedPathList
.RemoveDuplicates();
1245 // if the path list contains folders, we have to check whether
1246 // our just (maybe) added path is a child of one of those. If it is
1247 // a child of a folder already in the list, we must not add it. Otherwise
1248 // that path could show up twice in the list.
1249 bool bHasParentInList
= false;
1250 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1252 if (m_pathList
[i
].IsAncestorOf(path
))
1254 bHasParentInList
= true;
1258 if (!bHasParentInList
)
1260 m_pathList
.AddPath(path
);
1261 m_pathList
.RemoveDuplicates();
1262 m_updatedPathList
.AddPath(path
);
1263 m_updatedPathList
.RemoveDuplicates();
1268 // Always start the timer, since the status of an existing item might have changed
1269 SetTimer(REFRESHTIMER
, 200, NULL
);
1270 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1275 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1277 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1281 //////////////////////////////////////////////////////////////////////////
1282 // functions which run in the status thread
1283 //////////////////////////////////////////////////////////////////////////
1285 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1290 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1291 while (m_bRunThread
&& file
.ReadString(strLine
))
1293 int eqpos
= strLine
.Find('=');
1295 rgx
= strLine
.Mid(eqpos
+1).Trim();
1298 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1300 mapRegex
[strLine
.Left(pos
)] = rgx
;
1301 strLine
= strLine
.Mid(pos
+1).Trim();
1303 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1307 catch (CFileException
* pE
)
1309 TRACE("CFileException loading auto list regex file\n");
1314 void CCommitDlg::GetAutocompletionList()
1316 // the auto completion list is made of strings from each selected files.
1317 // the strings used are extracted from the files with regexes found
1318 // in the file "autolist.txt".
1319 // the format of that file is:
1320 // file extensions separated with commas '=' regular expression to use
1322 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1323 // .cpp = (?<=[^\s]::)\b\w+\b
1325 std::map
<CString
, CString
> mapRegex
;
1326 CString sRegexFile
= CPathUtils::GetAppDirectory();
1327 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1328 DWORD timeoutvalue
= regtimeout
*1000;
1329 sRegexFile
+= _T("autolist.txt");
1332 ParseRegexFile(sRegexFile
, mapRegex
);
1333 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1334 sRegexFile
.ReleaseBuffer();
1335 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1336 if (PathFileExists(sRegexFile
))
1338 ParseRegexFile(sRegexFile
, mapRegex
);
1340 DWORD starttime
= GetTickCount();
1342 // now we have two arrays of strings, where the first array contains all
1343 // file extensions we can use and the second the corresponding regex strings
1344 // to apply to those files.
1346 // the next step is to go over all files shown in the commit dialog
1347 // and scan them for strings we can use
1348 int nListItems
= m_ListCtrl
.GetItemCount();
1350 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1352 // stop parsing after timeout
1353 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1356 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1361 CString sPartPath
=path
->GetGitPathString();
1362 m_autolist
.insert(sPartPath
);
1364 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1368 // add the path parts to the auto completion list too
1369 // CString sPartPath = entry->GetRelativeGitPath();
1370 // m_autolist.insert(sPartPath);
1375 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1379 m_autolist
.insert(sPartPath
.Mid(pos
));
1382 // Last inserted entry is a file name.
1383 // Some users prefer to also list file name without extension.
1384 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1386 int dotPos
= sPartPath
.ReverseFind('.');
1387 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1388 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1391 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1394 CString sExt
= entry
->GetPath().GetFileExtension();
1396 // find the regex string which corresponds to the file extension
1397 CString rdata
= mapRegex
[sExt
];
1398 if (rdata
.IsEmpty())
1401 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1402 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1403 (entry
->textstatus
!= Git_wc_status_none
) &&
1404 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1405 (entry
->textstatus
!= Git_wc_status_added
) &&
1406 (entry
->textstatus
!= Git_wc_status_normal
))
1408 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1409 if (!basePath
.IsEmpty())
1410 ScanFile(basePath
.GetWinPathString(), rdata
);
1414 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1417 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1419 wstring sFileContent
;
1420 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1421 if (hFile
!= INVALID_HANDLE_VALUE
)
1423 DWORD size
= GetFileSize(hFile
, NULL
);
1424 if (size
> 1000000L)
1426 // no files bigger than 1 Meg
1430 // allocate memory to hold file contents
1431 char * buffer
= new char[size
];
1433 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1436 IsTextUnicode(buffer
, readbytes
, &opts
);
1437 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1442 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1444 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1446 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1448 int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1449 wchar_t * pWideBuf
= new wchar_t[ret
];
1450 int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1452 sFileContent
= wstring(pWideBuf
, ret
);
1457 if (sFileContent
.empty()|| !m_bRunThread
)
1464 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1465 const tr1::wsregex_iterator end
;
1466 wstring s
= sFileContent
;
1467 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1469 const tr1::wsmatch match
= *it
;
1470 for (size_t i
=1; i
<match
.size(); ++i
)
1472 if (match
[i
].second
-match
[i
].first
)
1474 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1475 m_autolist
.insert(wstring(match
[i
]).c_str());
1480 catch (exception
) {}
1483 // CSciEditContextMenuInterface
1484 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1486 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1487 m_nPopupPasteListCmd
= nCmd
++;
1488 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1490 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1491 if(m_History
.GetCount() > 0)
1493 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1494 m_nPopupPasteLastMessage
= nCmd
++;
1495 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1497 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1498 m_nPopupRecentMessage
= nCmd
++;
1499 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1505 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1510 if (cmd
== m_nPopupPasteListCmd
)
1513 int nListItems
= m_ListCtrl
.GetItemCount();
1514 for (int i
=0; i
<nListItems
; ++i
)
1516 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1517 if (entry
&&entry
->m_Checked
)
1520 CString status
= entry
->GetActionName();
1521 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1524 //git_wc_status_kind status = entry->status;
1525 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1526 if (m_ProjectProperties
.bFileListInEnglish
)
1529 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1533 pSciEdit
->InsertText(logmsg
);
1537 if(cmd
== m_nPopupPasteLastMessage
)
1539 if(m_History
.GetCount() ==0 )
1543 logmsg
+=m_History
.GetEntry(0);
1544 pSciEdit
->InsertText(logmsg
);
1548 if(cmd
== m_nPopupRecentMessage
)
1550 OnBnClickedHistory();
1556 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1560 case ENDDIALOGTIMER
:
1561 KillTimer(ENDDIALOGTIMER
);
1565 if (m_bThreadRunning
)
1567 SetTimer(REFRESHTIMER
, 200, NULL
);
1568 ATLTRACE("Wait some more before refreshing\n");
1572 KillTimer(REFRESHTIMER
);
1573 ATLTRACE("Refreshing after items dropped\n");
1578 __super::OnTimer(nIDEvent
);
1581 void CCommitDlg::OnBnClickedHistory()
1583 m_tooltips
.Pop(); // hide the tooltips
1584 if (m_pathList
.GetCount() == 0)
1587 CHistoryDlg historyDlg
;
1588 historyDlg
.SetHistory(m_History
);
1589 if (historyDlg
.DoModal() != IDOK
)
1592 CString sMsg
= historyDlg
.GetSelectedText();
1593 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1595 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1596 if (!sBugID
.IsEmpty())
1598 SetDlgItemText(IDC_BUGID
, sBugID
);
1600 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1601 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1603 m_cLogMessage
.SetText(sMsg
);
1607 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1611 void CCommitDlg::OnBnClickedBugtraqbutton()
1613 m_tooltips
.Pop(); // hide the tooltips
1614 CString sMsg
= m_cLogMessage
.GetText();
1616 if (m_BugTraqProvider
== NULL
)
1619 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1620 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1621 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1623 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1624 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1626 BSTR originalMessage
= sMsg
.AllocSysString();
1628 // m_revProps.clear();
1630 // first try the IBugTraqProvider2 interface
1631 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1632 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1635 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1636 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1637 BSTR bugIDOut
= NULL
;
1638 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1639 BSTR bugID
= m_sBugID
.AllocSysString();
1640 SAFEARRAY
* revPropNames
= NULL
;
1641 SAFEARRAY
* revPropValues
= NULL
;
1642 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1645 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1646 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1652 m_sBugID
= bugIDOut
;
1653 SysFreeString(bugIDOut
);
1654 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1656 SysFreeString(bugID
);
1657 SysFreeString(repositoryRoot
);
1658 m_cLogMessage
.SetText(temp
);
1659 BSTR HUGEP
*pbRevNames
;
1660 BSTR HUGEP
*pbRevValues
;
1662 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1665 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1668 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1670 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1672 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1675 SafeArrayUnaccessData(revPropValues
);
1677 SafeArrayUnaccessData(revPropNames
);
1680 SafeArrayDestroy(revPropNames
);
1682 SafeArrayDestroy(revPropValues
);
1687 // if IBugTraqProvider2 failed, try IBugTraqProvider
1688 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1689 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1693 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1694 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1698 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1701 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1702 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1705 m_cLogMessage
.SetText(temp
);
1707 m_sLogMessage
= m_cLogMessage
.GetText();
1708 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1710 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1711 if (!sBugID
.IsEmpty())
1713 SetDlgItemText(IDC_BUGID
, sBugID
);
1717 m_cLogMessage
.SetFocus();
1719 SysFreeString(parameters
);
1720 SysFreeString(commonRoot
);
1721 SafeArrayDestroy(pathList
);
1722 SysFreeString(originalMessage
);
1723 SysFreeString(temp
);
1727 void CCommitDlg::FillPatchView()
1729 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1731 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1733 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1734 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1739 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1740 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1741 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1744 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
1745 head
= _T("HEAD~1 ");
1746 cmd
.Format(_T("git.exe diff %s-- \"%s\""), head
, p
->GetGitPathString());
1747 g_Git
.Run(cmd
,&out
,CP_ACP
);
1751 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1752 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1753 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1756 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
1758 this->FillPatchView();
1763 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1769 void CCommitDlg::UpdateOKButton()
1774 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
1775 bool bAmendOrSelectFiles
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
);
1777 DialogEnableWindow(IDOK
, bValidLogSize
&& bAmendOrSelectFiles
);
1780 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1784 if (wParam
== IDC_SPLITTER
)
1786 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1787 DoSize(pHdr
->delta
);
1792 return __super::DefWindowProc(message
, wParam
, lParam
);
1795 void CCommitDlg::SetSplitterRange()
1797 if ((m_ListCtrl
)&&(m_cLogMessage
))
1800 m_cLogMessage
.GetWindowRect(rcTop
);
1801 ScreenToClient(rcTop
);
1803 m_ListCtrl
.GetWindowRect(rcMiddle
);
1804 ScreenToClient(rcMiddle
);
1805 if (rcMiddle
.Height() && rcMiddle
.Width())
1806 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1810 void CCommitDlg::DoSize(int delta
)
1812 RemoveAnchor(IDC_MESSAGEGROUP
);
1813 RemoveAnchor(IDC_LOGMESSAGE
);
1814 RemoveAnchor(IDC_SPLITTER
);
1815 RemoveAnchor(IDC_SIGNOFF
);
1816 RemoveAnchor(IDC_COMMIT_AMEND
);
1817 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
1818 RemoveAnchor(IDC_LISTGROUP
);
1819 RemoveAnchor(IDC_FILELIST
);
1820 RemoveAnchor(IDC_TEXT_INFO
);
1821 RemoveAnchor(IDC_VIEW_PATCH
);
1823 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1824 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1825 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1826 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1827 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1828 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1829 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
1830 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1831 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH
),0,delta
);
1833 AddAnchor(IDC_VIEW_PATCH
,TOP_RIGHT
);
1834 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1835 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1836 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1837 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1838 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1839 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1840 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1841 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
1842 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1844 // adjust the minimum size of the dialog to prevent the resizing from
1845 // moving the list control too far down.
1847 m_cLogMessage
.GetClientRect(rcLogMsg
);
1848 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1851 m_cLogMessage
.Invalidate();
1852 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1855 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1857 // first, let the resizing take place
1858 __super::OnSize(nType
, cx
, cy
);
1865 void CCommitDlg::OnBnClickedSignOff()
1870 username
=g_Git
.GetUserName();
1871 email
=g_Git
.GetUserEmail();
1872 username
.Remove(_T('\n'));
1873 email
.Remove(_T('\n'));
1874 str
.Format(_T("Signed-off-by: %s <%s>"),username
,email
);
1876 if (m_cLogMessage
.GetText().Find(str
) == -1) {
1877 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
1878 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
1879 int foundByLine
= -1;
1880 if (lastNewline
> 0)
1881 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
1883 if (foundByLine
== -1 || foundByLine
< lastNewline
)
1884 str
= _T("\r\n") + str
;
1886 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
1890 void CCommitDlg::OnBnClickedCommitAmend()
1893 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
1896 rev
.GetCommit(CString(_T("HEAD")));
1897 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
1900 if(this->m_bCommitAmend
)
1902 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
1903 m_cLogMessage
.SetText(m_AmendStr
);
1904 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1908 this->m_AmendStr
=this->m_cLogMessage
.GetText();
1909 m_cLogMessage
.SetText(m_NoAmendStr
);
1910 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1915 void CCommitDlg::OnBnClickedWholeProject()
1917 m_tooltips
.Pop(); // hide the tooltips
1923 m_ListCtrl
.GetStatus(NULL
,true,false,true);
1925 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
1927 m_ListCtrl
.Show(m_ListCtrl
.GetShowFlags());
1930 CTGitPath commonDir
= m_ListCtrl
.GetCommonDirectory(false);
1932 if(this->m_bWholeProject
)
1933 SetWindowText(m_sWindowTitle
+ _T(" - ") + CString(_T("Whole Project")));
1935 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString());
1939 void CCommitDlg::OnFocusMessage()
1941 m_cLogMessage
.SetFocus();
1944 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1946 UNREFERENCED_PARAMETER(pNMHDR
);
1947 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
1948 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
1949 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
1952 str
.Format(_T("%d/%d"),line
+1,column
+1);
1953 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
1958 void CCommitDlg::OnStnClickedViewPatch()
1960 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
1961 m_patchViewdlg
.m_ParentCommitDlg
= this;
1962 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
1964 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
1966 this->GetWindowRect(&rect
);
1968 m_patchViewdlg
.ShowWindow(SW_SHOW
);
1970 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
1971 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
1973 ShowViewPatchText(false);
1978 m_patchViewdlg
.ShowWindow(SW_HIDE
);
1979 m_patchViewdlg
.DestroyWindow();
1980 ShowViewPatchText(true);
1982 this->m_ctrlShowPatch
.Invalidate();
1985 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
1987 __super::OnMoving(fwSide
, pRect
);
1989 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
1992 m_patchViewdlg
.GetWindowRect(&patchrect
);
1993 if (::IsWindow(m_hWnd
))
1996 GetWindowRect(&thisrect
);
1997 if (patchrect
.left
== thisrect
.right
)
1999 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2000 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2007 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2009 __super::OnSizing(fwSide
, pRect
);
2011 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2013 CRect thisrect
, patchrect
;
2014 this->GetWindowRect(thisrect
);
2015 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2016 if(thisrect
.right
==patchrect
.left
)
2018 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2019 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2021 if( patchrect
.bottom
== thisrect
.bottom
)
2023 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2025 if( patchrect
.top
== thisrect
.top
)
2027 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2029 m_patchViewdlg
.MoveWindow(patchrect
);
2034 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2036 UNREFERENCED_PARAMETER(pNMHDR
);
2038 TRACE("Item Changed\r\n");
2041 int CCommitDlg::CheckHeadDetach()
2044 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2046 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2047 _T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
2049 CAppUtils::CreateBranchTag(FALSE
,NULL
,true);
2055 void CCommitDlg::OnBnClickedCommitAmenddiff()
2061 void CCommitDlg::OnBnClickedNoautoselectsubmodules()