allow to add Signed-Off-By line with the warning-message
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob616243e1776d8d67b86dffaa5264098b4493f355
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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "DirFileEnum.h"
24 //#include "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "Git.h"
30 #include "Registry.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
33 #include "Hooks.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"
40 #include "COMError.h"
41 #include "Globals.h"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #undef THIS_FILE
46 static char THIS_FILE[] = __FILE__;
47 #endif
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)
54 , m_bRecursive(FALSE)
55 , m_bShowUnversioned(FALSE)
56 , m_bBlock(FALSE)
57 , m_bThreadRunning(FALSE)
58 , m_bRunThread(FALSE)
59 , m_pThread(NULL)
60 , m_bWholeProject(FALSE)
61 , m_bKeepChangeList(TRUE)
62 , m_bDoNotAutoselectSubmodules(FALSE)
63 , m_itemsCount(0)
64 , m_bSelectFilesForCommit(TRUE)
65 , m_bNoPostActions(FALSE)
66 , m_bAutoClose(false)
68 this->m_bCommitAmend=FALSE;
69 m_bPushAfterCommit = FALSE;
72 CCommitDlg::~CCommitDlg()
74 if(m_pThread != NULL)
76 delete m_pThread;
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)
112 ON_WM_TIMER()
113 ON_WM_SIZE()
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)
120 ON_WM_MOVE()
121 ON_WM_MOVING()
122 ON_WM_SIZING()
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)
126 END_MESSAGE_MAP()
128 BOOL CCommitDlg::OnInitDialog()
130 CResizableStandAloneDialog::OnInitDialog();
131 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
133 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
135 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG")))
137 CStdioFile file;
138 if(file.Open(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG"), CFile::modeRead))
140 CString str;
141 while(file.ReadString(str))
143 m_sLogMessage += str;
144 str.Empty();
145 m_sLogMessage += _T("\n");
149 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
150 m_bShowUnversioned = m_regAddBeforeCommit;
152 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
154 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
155 m_bKeepChangeList = m_regKeepChangelists;
157 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
158 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
160 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
162 // GitConfig config;
163 // m_bWholeProject = config.KeepLocks();
165 if(this->m_pathList.GetCount() == 0)
166 m_bWholeProject =true;
168 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
169 m_bWholeProject =true;
171 UpdateData(FALSE);
173 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT | SVNSLC_POPSAVEAS)));
174 m_ListCtrl.SetSelectButton(&m_SelectAll);
175 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
176 m_ListCtrl.SetCancelBool(&m_bCancelled);
177 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
178 m_ListCtrl.EnableFileDrop();
179 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
181 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
182 m_ProjectProperties.ReadPropsPathList(m_pathList);
184 m_cLogMessage.Init(m_ProjectProperties);
185 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
186 m_cLogMessage.RegisterContextMenuHandler(this);
188 OnEnChangeLogmessage();
190 m_tooltips.Create(this);
191 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
192 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
193 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
195 m_SelectAll.SetCheck(BST_INDETERMINATE);
197 CBugTraqAssociations bugtraq_associations;
198 bugtraq_associations.Load();
200 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
202 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
203 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
205 CComPtr<IBugTraqProvider> pProvider;
206 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
207 if (SUCCEEDED(hr))
209 m_BugTraqProvider = pProvider;
210 BSTR temp = NULL;
211 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
213 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
214 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
215 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
218 SysFreeString(temp);
221 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
223 else if (!m_ProjectProperties.sMessage.IsEmpty())
225 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
226 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
227 if (!m_ProjectProperties.sLabel.IsEmpty())
228 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
229 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
230 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
231 GetDlgItem(IDC_BUGID)->SetFocus();
232 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
233 if (!sBugID.IsEmpty())
235 SetDlgItemText(IDC_BUGID, sBugID);
238 else
240 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
241 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
242 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
243 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
244 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
247 if (!m_sLogMessage.IsEmpty())
248 m_cLogMessage.SetText(m_sLogMessage);
250 GetWindowText(m_sWindowTitle);
252 AdjustControlSize(IDC_SHOWUNVERSIONED);
253 AdjustControlSize(IDC_SELECTALL);
254 AdjustControlSize(IDC_WHOLE_PROJECT);
256 GetClientRect(m_DlgOrigRect);
257 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
259 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
260 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
261 AddAnchor(IDC_BUGID, TOP_RIGHT);
262 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
263 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
264 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
265 // AddAnchor(IDC_HISTORY, TOP_LEFT);
266 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
267 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
268 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
269 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
270 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
271 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
272 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
273 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
274 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
275 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
276 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
277 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
278 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
279 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
280 AddAnchor(IDOK, BOTTOM_RIGHT);
281 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
282 AddAnchor(IDHELP, BOTTOM_RIGHT);
283 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
284 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
286 if (hWndExplorer)
287 CenterWindow(CWnd::FromHandle(hWndExplorer));
288 EnableSaveRestore(_T("CommitDlg"));
289 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
290 RECT rcDlg, rcLogMsg, rcFileList;
291 GetClientRect(&rcDlg);
292 m_cLogMessage.GetWindowRect(&rcLogMsg);
293 ScreenToClient(&rcLogMsg);
294 m_ListCtrl.GetWindowRect(&rcFileList);
295 ScreenToClient(&rcFileList);
296 if (yPos)
298 RECT rectSplitter;
299 m_wndSplitter.GetWindowRect(&rectSplitter);
300 ScreenToClient(&rectSplitter);
301 int delta = yPos - rectSplitter.top;
302 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
304 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
305 DoSize(delta);
309 // add all directories to the watcher
311 for (int i=0; i<m_pathList.GetCount(); ++i)
313 if (m_pathList[i].IsDirectory())
314 m_pathwatcher.AddPath(m_pathList[i]);
317 m_updatedPathList = m_pathList;
319 //first start a thread to obtain the file list with the status without
320 //blocking the dialog
321 InterlockedExchange(&m_bBlock, TRUE);
322 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
323 if (m_pThread==NULL)
325 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
326 InterlockedExchange(&m_bBlock, FALSE);
328 else
330 m_pThread->m_bAutoDelete = FALSE;
331 m_pThread->ResumeThread();
333 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
334 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
335 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
337 historyhint = TRUE;
338 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
340 err = FALSE;
342 if(m_bCommitAmend)
344 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
345 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
348 CGitHash hash = g_Git.GetHash(_T("HEAD"));
349 GitRev headRevision;
350 headRevision.GetParentFromHash(hash);
351 if (headRevision.ParentsCount() != 1)
353 m_bAmendDiffToLastCommit = true;
354 UpdateData(FALSE);
355 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(FALSE);
358 this->m_ctrlShowPatch.SetURL(CString());
360 return FALSE; // return TRUE unless you set the focus to a control
361 // EXCEPTION: OCX Property Pages should return FALSE
364 void CCommitDlg::OnOK()
366 if (m_bBlock)
367 return;
368 if (m_bThreadRunning)
370 m_bCancelled = true;
371 InterlockedExchange(&m_bRunThread, FALSE);
372 WaitForSingleObject(m_pThread->m_hThread, 1000);
373 if (m_bThreadRunning)
375 // we gave the thread a chance to quit. Since the thread didn't
376 // listen to us we have to kill it.
377 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
378 InterlockedExchange(&m_bThreadRunning, FALSE);
381 this->UpdateData();
383 CString id;
384 GetDlgItemText(IDC_BUGID, id);
385 if (!m_ProjectProperties.CheckBugID(id))
387 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
388 return;
390 m_sLogMessage = m_cLogMessage.GetText();
391 if ( m_sLogMessage.IsEmpty() )
393 // no message entered, go round again
394 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
395 return;
397 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
399 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
400 return;
403 BOOL bWarnNoSignedOffBy = FALSE;
404 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
405 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
407 UINT retval = CMessageBox::Show(this->m_hWnd, _T("You haven't entered your Signed-Off-By line!"), _T("TortoiseGit"), 1, IDI_WARNING, _T("&Add it"), _T("&Commit w/o"), _T("A&bort"));
408 if (retval == 1)
410 OnBnClickedSignOff();
411 m_sLogMessage = m_cLogMessage.GetText();
413 else if (retval == 3)
414 return;
417 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
418 #if 0
419 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
420 if (!(DWORD)regUnversionedRecurse)
422 // Find unversioned directories which are marked for commit. The user might expect them
423 // to be added recursively since he cannot the the files. Let's ask the user if he knows
424 // what he is doing.
425 int nListItems = m_ListCtrl.GetItemCount();
426 for (int j=0; j<nListItems; j++)
428 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
429 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
431 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
432 return;
436 #endif
437 m_pathwatcher.Stop();
438 InterlockedExchange(&m_bBlock, TRUE);
439 CDWordArray arDeleted;
440 //first add all the unversioned files the user selected
441 //and check if all versioned files are selected
442 int nchecked = 0;
443 m_bRecursive = true;
444 int nListItems = m_ListCtrl.GetItemCount();
446 CTGitPathList itemsToAdd;
447 CTGitPathList itemsToRemove;
448 //std::set<CString> checkedLists;
449 //std::set<CString> uncheckedLists;
451 // now let the bugtraq plugin check the commit message
452 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
453 if (m_BugTraqProvider)
455 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
456 if (SUCCEEDED(hr))
458 BSTR temp = NULL;
459 CString common = g_Git.m_CurrentDir;
460 BSTR repositoryRoot = common.AllocSysString();
461 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
462 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
463 BSTR commitMessage = m_sLogMessage.AllocSysString();
464 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
466 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
467 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
469 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
471 COMError ce(hr);
472 CString sErr;
473 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
474 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
476 else
478 CString sError = temp;
479 if (!sError.IsEmpty())
481 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
482 return;
484 SysFreeString(temp);
489 //CString checkedfiles;
490 //CString uncheckedfiles;
492 CString cmd;
493 CString out;
495 bool bAddSuccess=true;
496 bool bCloseCommitDlg=false;
498 for (int j=0; j<nListItems; j++)
500 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
501 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
502 if (entry->m_Checked)
504 #if 0
505 if (entry->status == Git_wc_status_unversioned)
507 itemsToAdd.AddPath(entry->GetPath());
509 if (entry->status == Git_wc_status_conflicted)
511 bHasConflicted = true;
513 if (entry->status == Git_wc_status_missing)
515 itemsToRemove.AddPath(entry->GetPath());
517 if (entry->status == Git_wc_status_deleted)
519 arDeleted.Add(j);
521 if (entry->IsInExternal())
523 bCheckedInExternal = true;
525 #endif
526 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
527 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
528 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
529 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
530 else
531 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
533 if(g_Git.Run(cmd,&out,CP_ACP))
535 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
536 bAddSuccess = false ;
537 break;
540 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
541 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
543 g_Git.Run(cmd,&out,CP_ACP);
545 nchecked++;
547 //checkedLists.insert(entry->GetGitPathString());
548 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
550 else
552 //uncheckedLists.insert(entry->GetGitPathString());
553 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
554 { //To init git repository, there are not HEAD, so we can use git reset command
555 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
556 if(g_Git.Run(cmd,&out,CP_ACP))
558 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
559 bAddSuccess = false ;
560 bCloseCommitDlg=false;
561 break;
565 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
567 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
569 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
571 else
573 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
575 if(g_Git.Run(cmd,&out,CP_ACP))
577 /* when reset a unstage file will report error.
578 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
579 bAddSuccess = false ;
580 bCloseCommitDlg=false;
581 break;
584 // && !entry->IsDirectory()
585 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
586 continue;
589 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
590 #if 0
591 if ((entry->status != Git_wc_status_unversioned) &&
592 (entry->status != Git_wc_status_ignored))
594 nUnchecked++;
595 uncheckedLists.insert(entry->GetChangeList());
596 if (m_bRecursive)
598 // This algorithm is for the sake of simplicity of the complexity O(N?
599 for (int k=0; k<nListItems; k++)
601 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
602 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
604 // Fall back to a non-recursive commit to prevent items being
605 // committed which aren't checked although its parent is checked
606 // (property change, directory deletion, ... )
607 m_bRecursive = false;
608 break;
613 #endif
616 CShellUpdater::Instance().AddPathForUpdate(*entry);
619 //if(uncheckedfiles.GetLength()>0)
621 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
622 // g_Git.Run(cmd,&out);
625 m_sBugID.Trim();
626 if (!m_sBugID.IsEmpty())
628 m_sBugID.Replace(_T(", "), _T(","));
629 m_sBugID.Replace(_T(" ,"), _T(","));
630 CString sBugID = m_ProjectProperties.sMessage;
631 sBugID.Replace(_T("%BUGID%"), m_sBugID);
632 if (m_ProjectProperties.bAppend)
633 m_sLogMessage += _T("\n") + sBugID + _T("\n");
634 else
635 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
638 BOOL bIsMerge=false;
639 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
641 bIsMerge=true;
643 //if(checkedfiles.GetLength()>0)
644 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
646 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
647 // g_Git.Run(cmd,&out);
649 bCloseCommitDlg = true;
651 CString tempfile=::GetTempFile();
653 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
654 //file.WriteString(m_sLogMessage);
656 CTGitPath path=g_Git.m_CurrentDir;
658 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
660 out =_T("");
661 CString amend;
662 if(this->m_bCommitAmend)
664 amend=_T("--amend");
666 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
668 CheckHeadDetach();
670 CCommitProgressDlg progress;
671 progress.m_bBufferAll=true; // improve show speed when there are many file added.
672 progress.m_GitCmd=cmd;
673 progress.m_bShowCommand = FALSE; // don't show the commit command
674 progress.m_PreText = out; // show any output already generated in log window
675 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
677 if (!m_bNoPostActions && !m_bAutoClose)
679 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
680 progress.m_PostCmdList.Add(_T("&ReCommit"));
683 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
685 DWORD userResponse = progress.DoModal();
687 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
689 bCloseCommitDlg = false;
690 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
692 this->m_sLogMessage.Empty();
693 m_cLogMessage.SetText(m_sLogMessage);
696 this->Refresh();
698 else if(userResponse == IDC_PROGRESS_BUTTON1)
700 //User pressed 'Push' button after successful commit.
701 m_bPushAfterCommit=true;
704 CFile::Remove(tempfile);
706 if (m_BugTraqProvider && progress.m_GitStatus == 0)
708 CComPtr<IBugTraqProvider2> pProvider = NULL;
709 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
710 if (SUCCEEDED(hr))
712 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
713 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
715 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
716 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
718 BSTR logMessage = m_sLogMessage.AllocSysString();
720 CGitHash hash=g_Git.GetHash(_T("HEAD"));
721 LONG version = g_Git.Hash2int(hash);
723 BSTR temp = NULL;
724 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
725 commonRoot,
726 pathList,
727 logMessage,
728 (LONG)version,
729 &temp)))
731 CString sErr = temp;
732 if (!sErr.IsEmpty())
733 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
734 else
736 COMError ce(hr);
737 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
738 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
742 SysFreeString(temp);
746 }else if(bAddSuccess)
748 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
749 bCloseCommitDlg=false;
751 #if 0
752 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
754 // There are paths which got changed (touched at least).
755 // We have to find out if this affects the selection in the commit dialog
756 // If it could affect the selection, revert back to a non-recursive commit
757 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
758 changedList.RemoveDuplicates();
759 for (int i=0; i<changedList.GetCount(); ++i)
761 if (changedList[i].IsAdminDir())
763 // something inside an admin dir was changed.
764 // if it's the entries file, then we have to fully refresh because
765 // files may have been added/removed from version control
766 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
767 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
769 m_bRecursive = false;
770 break;
773 else if (!m_ListCtrl.IsPathShown(changedList[i]))
775 // a path which is not shown in the list has changed
776 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
777 if (entry)
779 // check if the changed path would get committed by a recursive commit
780 if ((!entry->IsFromDifferentRepository()) &&
781 (!entry->IsInExternal()) &&
782 (!entry->IsNested()) &&
783 (!entry->IsChecked()))
785 m_bRecursive = false;
786 break;
794 // Now, do all the adds - make sure that the list is sorted so that parents
795 // are added before their children
796 itemsToAdd.SortByPathname();
797 Git Git;
798 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
800 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
801 InterlockedExchange(&m_bBlock, FALSE);
802 Refresh();
803 return;
806 // Remove any missing items
807 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
808 itemsToRemove.SortByPathname();
809 Git.Remove(itemsToRemove, TRUE);
811 //the next step: find all deleted files and check if they're
812 //inside a deleted folder. If that's the case, then remove those
813 //files from the list since they'll get deleted by the parent
814 //folder automatically.
815 m_ListCtrl.Block(TRUE, FALSE);
816 INT_PTR nDeleted = arDeleted.GetCount();
817 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
819 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
821 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
822 if (path.IsDirectory())
824 //now find all children of this directory
825 for (int j=0; j<arDeleted.GetCount(); j++)
827 if (i!=j)
829 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
830 if (childEntry->IsChecked())
832 if (path.IsAncestorOf(childEntry->GetPath()))
834 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
835 nDeleted--;
843 m_ListCtrl.Block(FALSE, FALSE);
845 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
847 //save only the files the user has checked into the temporary file
848 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
851 // the item count is used in the progress dialog to show the overall commit
852 // progress.
853 // deleted items only send one notification event, all others send two
854 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
856 if ((m_bRecursive)&&(checkedLists.size() == 1))
858 // all checked items belong to the same changelist
859 // find out if there are any unchecked items which belong to that changelist
860 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
861 m_sChangeList = *checkedLists.begin();
863 #endif
864 UpdateData();
865 m_regAddBeforeCommit = m_bShowUnversioned;
866 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
867 m_bWholeProject = FALSE;
868 m_regKeepChangelists = m_bKeepChangeList;
869 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
870 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
871 m_bKeepChangeList = FALSE;
872 InterlockedExchange(&m_bBlock, FALSE);
874 m_History.AddEntry(m_sLogMessage);
875 m_History.Save();
877 SaveSplitterPos();
879 if( bCloseCommitDlg )
880 CResizableStandAloneDialog::OnOK();
882 CShellUpdater::Instance().Flush();
885 void CCommitDlg::SaveSplitterPos()
887 if (!IsIconic())
889 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
890 RECT rectSplitter;
891 m_wndSplitter.GetWindowRect(&rectSplitter);
892 ScreenToClient(&rectSplitter);
893 regPos = rectSplitter.top;
897 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
899 return ((CCommitDlg*)pVoid)->StatusThread();
902 UINT CCommitDlg::StatusThread()
904 //get the status of all selected file/folders recursively
905 //and show the ones which have to be committed to the user
906 //in a list control.
907 InterlockedExchange(&m_bBlock, TRUE);
908 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
909 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
911 m_pathwatcher.Stop();
913 g_Git.RefreshGitIndex();
915 m_bCancelled = false;
917 DialogEnableWindow(IDOK, false);
918 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
919 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
920 DialogEnableWindow(IDC_SELECTALL, false);
921 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
922 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
923 DialogEnableWindow(IDC_EXTERNALWARNING, false);
924 // read the list of recent log entries before querying the WC for status
925 // -> the user may select one and modify / update it while we are crawling the WC
927 if (m_History.GetCount()==0)
929 CString reg;
930 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
931 reg.Replace(_T(':'),_T('_'));
932 m_History.Load(reg, _T("logmsgs"));
935 // Initialise the list control with the status of the files/folders below us
936 m_ListCtrl.Clear();
937 BOOL success;
938 CTGitPathList *pList;
939 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
940 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
942 if(m_bWholeProject)
943 pList=NULL;
944 else
945 pList = &m_pathList;
947 success=m_ListCtrl.GetStatus(pList);
949 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
950 if(this->m_bShowUnversioned)
951 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
953 m_ListCtrl.CheckIfChangelistsArePresent(false);
955 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
956 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
957 if (success)
959 if (m_checkedPathList.GetCount())
960 m_ListCtrl.Show(dwShow, m_checkedPathList);
961 else
963 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
964 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
965 m_ListCtrl.Show(dwShow, dwCheck);
966 m_bSelectFilesForCommit = true;
969 if (m_ListCtrl.HasExternalsFromDifferentRepos())
971 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
972 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
975 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
976 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
978 if (!success)
980 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
981 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
982 m_ListCtrl.Show(dwShow);
984 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
985 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
987 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
989 m_bShowUnversioned = TRUE;
990 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
991 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
992 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
993 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
997 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
999 if(this->m_bWholeProject)
1000 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T(" (Whole Project)")));
1001 else
1002 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1004 m_autolist.clear();
1005 // we don't have to block the commit dialog while we fetch the
1006 // auto completion list.
1007 m_pathwatcher.ClearChangedPaths();
1008 InterlockedExchange(&m_bBlock, FALSE);
1009 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1011 m_ListCtrl.Block(TRUE, TRUE);
1012 GetAutocompletionList();
1013 m_ListCtrl.Block(FALSE, FALSE);
1015 UpdateOKButton();
1016 if (m_bRunThread)
1018 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1019 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1020 DialogEnableWindow(IDC_SELECTALL, true);
1021 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1022 if (m_ListCtrl.HasChangeLists())
1023 DialogEnableWindow(IDC_KEEPLISTS, true);
1024 if (m_ListCtrl.HasLocks())
1025 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1026 // we have the list, now signal the main thread about it
1027 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1030 InterlockedExchange(&m_bRunThread, FALSE);
1031 InterlockedExchange(&m_bThreadRunning, FALSE);
1032 // force the cursor to normal
1033 RefreshCursor();
1035 return 0;
1038 void CCommitDlg::OnCancel()
1040 m_bCancelled = true;
1041 m_pathwatcher.Stop();
1043 if (m_bBlock)
1044 return;
1046 if (m_bThreadRunning)
1048 InterlockedExchange(&m_bRunThread, FALSE);
1049 WaitForSingleObject(m_pThread->m_hThread, 1000);
1050 if (m_bThreadRunning)
1052 // we gave the thread a chance to quit. Since the thread didn't
1053 // listen to us we have to kill it.
1054 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1055 InterlockedExchange(&m_bThreadRunning, FALSE);
1058 UpdateData();
1059 m_sBugID.Trim();
1060 m_sLogMessage = m_cLogMessage.GetText();
1061 if (!m_sBugID.IsEmpty())
1063 m_sBugID.Replace(_T(", "), _T(","));
1064 m_sBugID.Replace(_T(" ,"), _T(","));
1065 CString sBugID = m_ProjectProperties.sMessage;
1066 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1067 if (m_ProjectProperties.bAppend)
1068 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1069 else
1070 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1072 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1073 m_History.AddEntry(m_sLogMessage);
1074 m_History.Save();
1075 SaveSplitterPos();
1076 CResizableStandAloneDialog::OnCancel();
1079 void CCommitDlg::OnBnClickedSelectall()
1081 m_tooltips.Pop(); // hide the tooltips
1082 UINT state = (m_SelectAll.GetState() & 0x0003);
1083 if (state == BST_INDETERMINATE)
1085 // It is not at all useful to manually place the checkbox into the indeterminate state...
1086 // We will force this on to the unchecked state
1087 state = BST_UNCHECKED;
1088 m_SelectAll.SetCheck(state);
1090 m_ListCtrl.SelectAll(state == BST_CHECKED);
1093 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1095 if (!m_bBlock)
1096 m_tooltips.RelayEvent(pMsg);
1098 if (m_hAccel)
1100 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1101 if (ret)
1102 return TRUE;
1105 if (pMsg->message == WM_KEYDOWN)
1107 switch (pMsg->wParam)
1109 case VK_F5:
1111 if (m_bBlock)
1112 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1113 Refresh();
1115 break;
1116 case VK_RETURN:
1118 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1120 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1122 PostMessage(WM_COMMAND, IDOK);
1124 return TRUE;
1126 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1128 // Pressing RETURN in the bug id control
1129 // moves the focus to the message
1130 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1131 return TRUE;
1134 break;
1138 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1141 void CCommitDlg::Refresh()
1143 if (m_bThreadRunning)
1144 return;
1146 InterlockedExchange(&m_bBlock, TRUE);
1147 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1148 if (m_pThread==NULL)
1150 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1151 InterlockedExchange(&m_bBlock, FALSE);
1153 else
1155 m_pThread->m_bAutoDelete = FALSE;
1156 m_pThread->ResumeThread();
1160 void CCommitDlg::OnBnClickedHelp()
1162 OnHelp();
1165 void CCommitDlg::OnBnClickedShowunversioned()
1167 m_tooltips.Pop(); // hide the tooltips
1168 UpdateData();
1169 m_regAddBeforeCommit = m_bShowUnversioned;
1170 if (!m_bBlock)
1172 DWORD dwShow = m_ListCtrl.GetShowFlags();
1173 if (DWORD(m_regAddBeforeCommit))
1174 dwShow |= SVNSLC_SHOWUNVERSIONED;
1175 else
1176 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1177 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1179 if(m_bWholeProject)
1180 m_ListCtrl.GetStatus(NULL,false,false,true);
1181 else
1182 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1184 m_ListCtrl.Show(dwShow,0,true,0,true);
1188 void CCommitDlg::OnStnClickedExternalwarning()
1190 m_tooltips.Popup();
1193 void CCommitDlg::OnEnChangeLogmessage()
1195 UpdateOKButton();
1198 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1200 #if 0
1201 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1203 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1205 m_bShowUnversioned = TRUE;
1206 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1207 m_ListCtrl.Show(dwShow);
1208 UpdateData(FALSE);
1211 #endif
1212 return 0;
1215 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1217 Refresh();
1218 return 0;
1221 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1223 #if 0
1224 BringWindowToTop();
1225 SetForegroundWindow();
1226 SetActiveWindow();
1227 // if multiple files/folders are dropped
1228 // this handler is called for every single item
1229 // separately.
1230 // To avoid creating multiple refresh threads and
1231 // causing crashes, we only add the items to the
1232 // list control and start a timer.
1233 // When the timer expires, we start the refresh thread,
1234 // but only if it isn't already running - otherwise we
1235 // restart the timer.
1236 CTGitPath path;
1237 path.SetFromWin((LPCTSTR)lParam);
1239 // just add all the items we get here.
1240 // if the item is versioned, the add will fail but nothing
1241 // more will happen.
1242 Git Git;
1243 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1245 if (!m_ListCtrl.HasPath(path))
1247 if (m_pathList.AreAllPathsFiles())
1249 m_pathList.AddPath(path);
1250 m_pathList.RemoveDuplicates();
1251 m_updatedPathList.AddPath(path);
1252 m_updatedPathList.RemoveDuplicates();
1254 else
1256 // if the path list contains folders, we have to check whether
1257 // our just (maybe) added path is a child of one of those. If it is
1258 // a child of a folder already in the list, we must not add it. Otherwise
1259 // that path could show up twice in the list.
1260 bool bHasParentInList = false;
1261 for (int i=0; i<m_pathList.GetCount(); ++i)
1263 if (m_pathList[i].IsAncestorOf(path))
1265 bHasParentInList = true;
1266 break;
1269 if (!bHasParentInList)
1271 m_pathList.AddPath(path);
1272 m_pathList.RemoveDuplicates();
1273 m_updatedPathList.AddPath(path);
1274 m_updatedPathList.RemoveDuplicates();
1279 // Always start the timer, since the status of an existing item might have changed
1280 SetTimer(REFRESHTIMER, 200, NULL);
1281 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1282 #endif
1283 return 0;
1286 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1288 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1289 return 0;
1292 //////////////////////////////////////////////////////////////////////////
1293 // functions which run in the status thread
1294 //////////////////////////////////////////////////////////////////////////
1296 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1298 CString strLine;
1301 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1302 while (m_bRunThread && file.ReadString(strLine))
1304 int eqpos = strLine.Find('=');
1305 CString rgx;
1306 rgx = strLine.Mid(eqpos+1).Trim();
1308 int pos = -1;
1309 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1311 mapRegex[strLine.Left(pos)] = rgx;
1312 strLine = strLine.Mid(pos+1).Trim();
1314 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1316 file.Close();
1318 catch (CFileException* pE)
1320 TRACE("CFileException loading auto list regex file\n");
1321 pE->Delete();
1322 return;
1325 void CCommitDlg::GetAutocompletionList()
1327 // the auto completion list is made of strings from each selected files.
1328 // the strings used are extracted from the files with regexes found
1329 // in the file "autolist.txt".
1330 // the format of that file is:
1331 // file extensions separated with commas '=' regular expression to use
1332 // example:
1333 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1334 // .cpp = (?<=[^\s]::)\b\w+\b
1336 std::map<CString, CString> mapRegex;
1337 CString sRegexFile = CPathUtils::GetAppDirectory();
1338 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1339 DWORD timeoutvalue = regtimeout*1000;
1340 sRegexFile += _T("autolist.txt");
1341 if (!m_bRunThread)
1342 return;
1343 ParseRegexFile(sRegexFile, mapRegex);
1344 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1345 sRegexFile.ReleaseBuffer();
1346 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1347 if (PathFileExists(sRegexFile))
1349 ParseRegexFile(sRegexFile, mapRegex);
1351 DWORD starttime = GetTickCount();
1353 // now we have two arrays of strings, where the first array contains all
1354 // file extensions we can use and the second the corresponding regex strings
1355 // to apply to those files.
1357 // the next step is to go over all files shown in the commit dialog
1358 // and scan them for strings we can use
1359 int nListItems = m_ListCtrl.GetItemCount();
1361 for (int i=0; i<nListItems && m_bRunThread; ++i)
1363 // stop parsing after timeout
1364 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1365 return;
1367 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1369 if(path == NULL)
1370 continue;
1372 CString sPartPath =path->GetGitPathString();
1373 m_autolist.insert(sPartPath);
1375 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1376 // if (!entry)
1377 // continue;
1379 // add the path parts to the auto completion list too
1380 // CString sPartPath = entry->GetRelativeGitPath();
1381 // m_autolist.insert(sPartPath);
1384 int pos = 0;
1385 int lastPos = 0;
1386 while ((pos = sPartPath.Find('/', pos)) >= 0)
1388 pos++;
1389 lastPos = pos;
1390 m_autolist.insert(sPartPath.Mid(pos));
1393 // Last inserted entry is a file name.
1394 // Some users prefer to also list file name without extension.
1395 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1397 int dotPos = sPartPath.ReverseFind('.');
1398 if ((dotPos >= 0) && (dotPos > lastPos))
1399 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1401 #if 0
1402 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1403 continue;
1405 CString sExt = entry->GetPath().GetFileExtension();
1406 sExt.MakeLower();
1407 // find the regex string which corresponds to the file extension
1408 CString rdata = mapRegex[sExt];
1409 if (rdata.IsEmpty())
1410 continue;
1412 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1413 if ((entry->textstatus != Git_wc_status_unversioned) &&
1414 (entry->textstatus != Git_wc_status_none) &&
1415 (entry->textstatus != Git_wc_status_ignored) &&
1416 (entry->textstatus != Git_wc_status_added) &&
1417 (entry->textstatus != Git_wc_status_normal))
1419 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1420 if (!basePath.IsEmpty())
1421 ScanFile(basePath.GetWinPathString(), rdata);
1423 #endif
1425 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1428 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1430 wstring sFileContent;
1431 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1432 if (hFile != INVALID_HANDLE_VALUE)
1434 DWORD size = GetFileSize(hFile, NULL);
1435 if (size > 1000000L)
1437 // no files bigger than 1 Meg
1438 CloseHandle(hFile);
1439 return;
1441 // allocate memory to hold file contents
1442 char * buffer = new char[size];
1443 DWORD readbytes;
1444 ReadFile(hFile, buffer, size, &readbytes, NULL);
1445 CloseHandle(hFile);
1446 int opts = 0;
1447 IsTextUnicode(buffer, readbytes, &opts);
1448 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1450 delete [] buffer;
1451 return;
1453 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1455 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1457 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1459 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1460 wchar_t * pWideBuf = new wchar_t[ret];
1461 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1462 if (ret2 == ret)
1463 sFileContent = wstring(pWideBuf, ret);
1464 delete [] pWideBuf;
1466 delete [] buffer;
1468 if (sFileContent.empty()|| !m_bRunThread)
1470 return;
1475 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1476 const tr1::wsregex_iterator end;
1477 wstring s = sFileContent;
1478 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1480 const tr1::wsmatch match = *it;
1481 for (size_t i=1; i<match.size(); ++i)
1483 if (match[i].second-match[i].first)
1485 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1486 m_autolist.insert(wstring(match[i]).c_str());
1491 catch (exception) {}
1494 // CSciEditContextMenuInterface
1495 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1497 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1498 m_nPopupPasteListCmd = nCmd++;
1499 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1501 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1502 if(m_History.GetCount() > 0)
1504 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1505 m_nPopupPasteLastMessage = nCmd++;
1506 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1508 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1509 m_nPopupRecentMessage = nCmd++;
1510 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1516 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1519 if (m_bBlock)
1520 return false;
1521 if (cmd == m_nPopupPasteListCmd)
1523 CString logmsg;
1524 int nListItems = m_ListCtrl.GetItemCount();
1525 for (int i=0; i<nListItems; ++i)
1527 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1528 if (entry&&entry->m_Checked)
1530 CString line;
1531 CString status = entry->GetActionName();
1532 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1533 status = _T("Add");
1535 //git_wc_status_kind status = entry->status;
1536 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1537 if (m_ProjectProperties.bFileListInEnglish)
1538 langID = 1033;
1540 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1541 logmsg += line;
1544 pSciEdit->InsertText(logmsg);
1545 return true;
1548 if(cmd == m_nPopupPasteLastMessage)
1550 if(m_History.GetCount() ==0 )
1551 return false;
1553 CString logmsg;
1554 logmsg +=m_History.GetEntry(0);
1555 pSciEdit->InsertText(logmsg);
1556 return true;
1559 if(cmd == m_nPopupRecentMessage )
1561 OnBnClickedHistory();
1562 return true;
1564 return false;
1567 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1569 switch (nIDEvent)
1571 case ENDDIALOGTIMER:
1572 KillTimer(ENDDIALOGTIMER);
1573 EndDialog(0);
1574 break;
1575 case REFRESHTIMER:
1576 if (m_bThreadRunning)
1578 SetTimer(REFRESHTIMER, 200, NULL);
1579 ATLTRACE("Wait some more before refreshing\n");
1581 else
1583 KillTimer(REFRESHTIMER);
1584 ATLTRACE("Refreshing after items dropped\n");
1585 Refresh();
1587 break;
1589 __super::OnTimer(nIDEvent);
1592 void CCommitDlg::OnBnClickedHistory()
1594 m_tooltips.Pop(); // hide the tooltips
1595 if (m_pathList.GetCount() == 0)
1596 return;
1598 CHistoryDlg historyDlg;
1599 historyDlg.SetHistory(m_History);
1600 if (historyDlg.DoModal() != IDOK)
1601 return;
1603 CString sMsg = historyDlg.GetSelectedText();
1604 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1606 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1607 if (!sBugID.IsEmpty())
1609 SetDlgItemText(IDC_BUGID, sBugID);
1611 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1612 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1613 else
1614 m_cLogMessage.SetText(sMsg);
1617 UpdateOKButton();
1618 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1622 void CCommitDlg::OnBnClickedBugtraqbutton()
1624 m_tooltips.Pop(); // hide the tooltips
1625 CString sMsg = m_cLogMessage.GetText();
1627 if (m_BugTraqProvider == NULL)
1628 return;
1630 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1631 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1632 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1634 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1635 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1637 BSTR originalMessage = sMsg.AllocSysString();
1638 BSTR temp = NULL;
1639 // m_revProps.clear();
1641 // first try the IBugTraqProvider2 interface
1642 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1643 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1644 if (SUCCEEDED(hr))
1646 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1647 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1648 BSTR bugIDOut = NULL;
1649 GetDlgItemText(IDC_BUGID, m_sBugID);
1650 BSTR bugID = m_sBugID.AllocSysString();
1651 SAFEARRAY * revPropNames = NULL;
1652 SAFEARRAY * revPropValues = NULL;
1653 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1655 CString sErr;
1656 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1657 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1659 else
1661 if (bugIDOut)
1663 m_sBugID = bugIDOut;
1664 SysFreeString(bugIDOut);
1665 SetDlgItemText(IDC_BUGID, m_sBugID);
1667 SysFreeString(bugID);
1668 SysFreeString(repositoryRoot);
1669 m_cLogMessage.SetText(temp);
1670 BSTR HUGEP *pbRevNames;
1671 BSTR HUGEP *pbRevValues;
1673 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1674 if (SUCCEEDED(hr1))
1676 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1677 if (SUCCEEDED(hr2))
1679 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1681 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1683 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1686 SafeArrayUnaccessData(revPropValues);
1688 SafeArrayUnaccessData(revPropNames);
1690 if (revPropNames)
1691 SafeArrayDestroy(revPropNames);
1692 if (revPropValues)
1693 SafeArrayDestroy(revPropValues);
1696 else
1698 // if IBugTraqProvider2 failed, try IBugTraqProvider
1699 CComPtr<IBugTraqProvider> pProvider = NULL;
1700 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1701 if (FAILED(hr))
1703 CString sErr;
1704 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1705 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1706 return;
1709 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1711 CString sErr;
1712 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1713 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1715 else
1716 m_cLogMessage.SetText(temp);
1718 m_sLogMessage = m_cLogMessage.GetText();
1719 if (!m_ProjectProperties.sMessage.IsEmpty())
1721 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1722 if (!sBugID.IsEmpty())
1724 SetDlgItemText(IDC_BUGID, sBugID);
1728 m_cLogMessage.SetFocus();
1730 SysFreeString(parameters);
1731 SysFreeString(commonRoot);
1732 SafeArrayDestroy(pathList);
1733 SysFreeString(originalMessage);
1734 SysFreeString(temp);
1738 void CCommitDlg::FillPatchView()
1740 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1742 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1744 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1745 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1746 CString cmd,out;
1748 while(pos)
1750 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1751 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1752 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1754 CString head;
1755 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1756 head = _T("HEAD~1 ");
1757 cmd.Format(_T("git.exe diff %s-- \"%s\""), head, p->GetGitPathString());
1758 g_Git.Run(cmd,&out,CP_ACP);
1762 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1763 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1764 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1767 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1769 this->FillPatchView();
1770 return 0;
1774 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1776 UpdateOKButton();
1777 return 0;
1780 void CCommitDlg::UpdateOKButton()
1782 if (m_bBlock)
1783 return;
1785 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1786 bool bAmendOrSelectFiles = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit);
1788 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFiles);
1791 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1793 switch (message) {
1794 case WM_NOTIFY:
1795 if (wParam == IDC_SPLITTER)
1797 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1798 DoSize(pHdr->delta);
1800 break;
1803 return __super::DefWindowProc(message, wParam, lParam);
1806 void CCommitDlg::SetSplitterRange()
1808 if ((m_ListCtrl)&&(m_cLogMessage))
1810 CRect rcTop;
1811 m_cLogMessage.GetWindowRect(rcTop);
1812 ScreenToClient(rcTop);
1813 CRect rcMiddle;
1814 m_ListCtrl.GetWindowRect(rcMiddle);
1815 ScreenToClient(rcMiddle);
1816 if (rcMiddle.Height() && rcMiddle.Width())
1817 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1821 void CCommitDlg::DoSize(int delta)
1823 RemoveAnchor(IDC_MESSAGEGROUP);
1824 RemoveAnchor(IDC_LOGMESSAGE);
1825 RemoveAnchor(IDC_SPLITTER);
1826 RemoveAnchor(IDC_SIGNOFF);
1827 RemoveAnchor(IDC_COMMIT_AMEND);
1828 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1829 RemoveAnchor(IDC_LISTGROUP);
1830 RemoveAnchor(IDC_FILELIST);
1831 RemoveAnchor(IDC_TEXT_INFO);
1832 RemoveAnchor(IDC_VIEW_PATCH);
1834 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1835 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1836 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1837 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1838 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1839 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1840 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1841 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1842 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1844 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1845 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1846 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1847 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1848 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1849 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1850 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1851 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1852 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1853 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1854 ArrangeLayout();
1855 // adjust the minimum size of the dialog to prevent the resizing from
1856 // moving the list control too far down.
1857 CRect rcLogMsg;
1858 m_cLogMessage.GetClientRect(rcLogMsg);
1859 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1861 SetSplitterRange();
1862 m_cLogMessage.Invalidate();
1863 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1866 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1868 // first, let the resizing take place
1869 __super::OnSize(nType, cx, cy);
1871 //set range
1872 SetSplitterRange();
1875 CString CCommitDlg::GetSignedOffByLine()
1877 CString str;
1879 CString username = g_Git.GetUserName();
1880 CString email = g_Git.GetUserEmail();
1881 username.Remove(_T('\n'));
1882 email.Remove(_T('\n'));
1884 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
1886 return str;
1889 void CCommitDlg::OnBnClickedSignOff()
1891 CString str = GetSignedOffByLine();
1893 if (m_cLogMessage.GetText().Find(str) == -1) {
1894 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1895 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1896 int foundByLine = -1;
1897 if (lastNewline > 0)
1898 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1900 if (foundByLine == -1 || foundByLine < lastNewline)
1901 str = _T("\r\n") + str;
1903 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1907 void CCommitDlg::OnBnClickedCommitAmend()
1909 this->UpdateData();
1910 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1912 GitRev rev;
1913 rev.GetCommit(CString(_T("HEAD")));
1914 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
1917 if(this->m_bCommitAmend)
1919 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1920 m_cLogMessage.SetText(m_AmendStr);
1921 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1923 else
1925 this->m_AmendStr=this->m_cLogMessage.GetText();
1926 m_cLogMessage.SetText(m_NoAmendStr);
1927 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1929 Refresh();
1932 void CCommitDlg::OnBnClickedWholeProject()
1934 m_tooltips.Pop(); // hide the tooltips
1935 UpdateData();
1936 m_ListCtrl.Clear();
1937 if (!m_bBlock)
1939 if(m_bWholeProject)
1940 m_ListCtrl.GetStatus(NULL,true,false,true);
1941 else
1942 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1944 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
1945 m_ListCtrl.Show(m_ListCtrl.GetShowFlags(), dwShow & (~CTGitPath::LOGACTIONS_UNVER));
1948 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1950 if(this->m_bWholeProject)
1951 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1952 else
1953 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1957 void CCommitDlg::OnFocusMessage()
1959 m_cLogMessage.SetFocus();
1962 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1964 UNREFERENCED_PARAMETER(pNMHDR);
1965 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1966 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1967 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1969 CString str;
1970 str.Format(_T("%d/%d"),line+1,column+1);
1971 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1973 if(*pResult)
1974 *pResult=0;
1976 void CCommitDlg::OnStnClickedViewPatch()
1978 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1979 m_patchViewdlg.m_ParentCommitDlg = this;
1980 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1982 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1983 CRect rect;
1984 this->GetWindowRect(&rect);
1986 m_patchViewdlg.ShowWindow(SW_SHOW);
1988 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1989 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1991 ShowViewPatchText(false);
1992 FillPatchView();
1994 else
1996 m_patchViewdlg.ShowWindow(SW_HIDE);
1997 m_patchViewdlg.DestroyWindow();
1998 ShowViewPatchText(true);
2000 this->m_ctrlShowPatch.Invalidate();
2003 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2005 __super::OnMoving(fwSide, pRect);
2007 if (::IsWindow(m_patchViewdlg.m_hWnd))
2009 RECT patchrect;
2010 m_patchViewdlg.GetWindowRect(&patchrect);
2011 if (::IsWindow(m_hWnd))
2013 RECT thisrect;
2014 GetWindowRect(&thisrect);
2015 if (patchrect.left == thisrect.right)
2017 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2018 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2025 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2027 __super::OnSizing(fwSide, pRect);
2029 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2031 CRect thisrect, patchrect;
2032 this->GetWindowRect(thisrect);
2033 this->m_patchViewdlg.GetWindowRect(patchrect);
2034 if(thisrect.right==patchrect.left)
2036 patchrect.left -= (thisrect.right - pRect->right);
2037 patchrect.right-= (thisrect.right - pRect->right);
2039 if( patchrect.bottom == thisrect.bottom)
2041 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2043 if( patchrect.top == thisrect.top)
2045 patchrect.top -= thisrect.top-pRect->top;
2047 m_patchViewdlg.MoveWindow(patchrect);
2052 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2054 UNREFERENCED_PARAMETER(pNMHDR);
2055 *pResult = 0;
2056 TRACE("Item Changed\r\n");
2059 int CCommitDlg::CheckHeadDetach()
2061 CString output;
2062 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2064 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2065 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2067 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2070 return 0;
2073 void CCommitDlg::OnBnClickedCommitAmenddiff()
2075 UpdateData();
2076 Refresh();
2079 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2081 UpdateData();
2082 Refresh();