Merge branch 'restructure-tree'
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob7be9b5221943a5209300d8e211dd867b53a62517
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 f;
350 f.GetParentFromHash(hash);
351 if (f.ParentsCount() == 0)
353 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
355 if (f.ParentsCount() != 1)
357 m_bAmendDiffToLastCommit = true;
358 UpdateData(FALSE);
359 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(FALSE);
362 this->m_ctrlShowPatch.SetURL(CString());
364 return FALSE; // return TRUE unless you set the focus to a control
365 // EXCEPTION: OCX Property Pages should return FALSE
368 void CCommitDlg::OnOK()
370 if (m_bBlock)
371 return;
372 if (m_bThreadRunning)
374 m_bCancelled = true;
375 InterlockedExchange(&m_bRunThread, FALSE);
376 WaitForSingleObject(m_pThread->m_hThread, 1000);
377 if (m_bThreadRunning)
379 // we gave the thread a chance to quit. Since the thread didn't
380 // listen to us we have to kill it.
381 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
382 InterlockedExchange(&m_bThreadRunning, FALSE);
385 this->UpdateData();
387 CString id;
388 GetDlgItemText(IDC_BUGID, id);
389 if (!m_ProjectProperties.CheckBugID(id))
391 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
392 return;
394 m_sLogMessage = m_cLogMessage.GetText();
395 if ( m_sLogMessage.IsEmpty() )
397 // no message entered, go round again
398 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
399 return;
401 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
403 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
404 return;
407 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
408 #if 0
409 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
410 if (!(DWORD)regUnversionedRecurse)
412 // Find unversioned directories which are marked for commit. The user might expect them
413 // to be added recursively since he cannot the the files. Let's ask the user if he knows
414 // what he is doing.
415 int nListItems = m_ListCtrl.GetItemCount();
416 for (int j=0; j<nListItems; j++)
418 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
419 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
421 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
422 return;
426 #endif
427 m_pathwatcher.Stop();
428 InterlockedExchange(&m_bBlock, TRUE);
429 CDWordArray arDeleted;
430 //first add all the unversioned files the user selected
431 //and check if all versioned files are selected
432 int nchecked = 0;
433 m_bRecursive = true;
434 int nListItems = m_ListCtrl.GetItemCount();
436 CTGitPathList itemsToAdd;
437 CTGitPathList itemsToRemove;
438 //std::set<CString> checkedLists;
439 //std::set<CString> uncheckedLists;
441 // now let the bugtraq plugin check the commit message
442 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
443 if (m_BugTraqProvider)
445 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
446 if (SUCCEEDED(hr))
448 BSTR temp = NULL;
449 CString common = g_Git.m_CurrentDir;
450 BSTR repositoryRoot = common.AllocSysString();
451 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
452 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
453 BSTR commitMessage = m_sLogMessage.AllocSysString();
454 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
456 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
457 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
459 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
461 COMError ce(hr);
462 CString sErr;
463 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
464 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
466 else
468 CString sError = temp;
469 if (!sError.IsEmpty())
471 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
472 return;
474 SysFreeString(temp);
479 //CString checkedfiles;
480 //CString uncheckedfiles;
482 CString cmd;
483 CString out;
485 bool bAddSuccess=true;
486 bool bCloseCommitDlg=false;
488 for (int j=0; j<nListItems; j++)
490 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
491 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
492 if (entry->m_Checked)
494 #if 0
495 if (entry->status == Git_wc_status_unversioned)
497 itemsToAdd.AddPath(entry->GetPath());
499 if (entry->status == Git_wc_status_conflicted)
501 bHasConflicted = true;
503 if (entry->status == Git_wc_status_missing)
505 itemsToRemove.AddPath(entry->GetPath());
507 if (entry->status == Git_wc_status_deleted)
509 arDeleted.Add(j);
511 if (entry->IsInExternal())
513 bCheckedInExternal = true;
515 #endif
516 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
517 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
518 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
519 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
520 else
521 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
523 if(g_Git.Run(cmd,&out,CP_ACP))
525 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
526 bAddSuccess = false ;
527 break;
530 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
531 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
533 g_Git.Run(cmd,&out,CP_ACP);
535 nchecked++;
537 //checkedLists.insert(entry->GetGitPathString());
538 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
540 else
542 //uncheckedLists.insert(entry->GetGitPathString());
543 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
544 { //To init git repository, there are not HEAD, so we can use git reset command
545 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
546 if(g_Git.Run(cmd,&out,CP_ACP))
548 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
549 bAddSuccess = false ;
550 bCloseCommitDlg=false;
551 break;
555 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
557 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
559 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
561 else
563 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
565 if(g_Git.Run(cmd,&out,CP_ACP))
567 /* when reset a unstage file will report error.
568 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
569 bAddSuccess = false ;
570 bCloseCommitDlg=false;
571 break;
574 // && !entry->IsDirectory()
575 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
576 continue;
579 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
580 #if 0
581 if ((entry->status != Git_wc_status_unversioned) &&
582 (entry->status != Git_wc_status_ignored))
584 nUnchecked++;
585 uncheckedLists.insert(entry->GetChangeList());
586 if (m_bRecursive)
588 // This algorithm is for the sake of simplicity of the complexity O(N?
589 for (int k=0; k<nListItems; k++)
591 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
592 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
594 // Fall back to a non-recursive commit to prevent items being
595 // committed which aren't checked although its parent is checked
596 // (property change, directory deletion, ... )
597 m_bRecursive = false;
598 break;
603 #endif
606 CShellUpdater::Instance().AddPathForUpdate(*entry);
609 //if(uncheckedfiles.GetLength()>0)
611 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
612 // g_Git.Run(cmd,&out);
615 m_sBugID.Trim();
616 if (!m_sBugID.IsEmpty())
618 m_sBugID.Replace(_T(", "), _T(","));
619 m_sBugID.Replace(_T(" ,"), _T(","));
620 CString sBugID = m_ProjectProperties.sMessage;
621 sBugID.Replace(_T("%BUGID%"), m_sBugID);
622 if (m_ProjectProperties.bAppend)
623 m_sLogMessage += _T("\n") + sBugID + _T("\n");
624 else
625 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
628 BOOL bIsMerge=false;
629 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
631 bIsMerge=true;
633 //if(checkedfiles.GetLength()>0)
634 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
636 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
637 // g_Git.Run(cmd,&out);
639 bCloseCommitDlg = true;
641 CString tempfile=::GetTempFile();
643 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
644 //file.WriteString(m_sLogMessage);
646 CTGitPath path=g_Git.m_CurrentDir;
648 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
650 out =_T("");
651 CString amend;
652 if(this->m_bCommitAmend)
654 amend=_T("--amend");
656 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
658 CheckHeadDetach();
660 CCommitProgressDlg progress;
661 progress.m_bBufferAll=true; // improve show speed when there are many file added.
662 progress.m_GitCmd=cmd;
663 progress.m_bShowCommand = FALSE; // don't show the commit command
664 progress.m_PreText = out; // show any output already generated in log window
665 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
667 if (!m_bNoPostActions && !m_bAutoClose)
669 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
670 progress.m_PostCmdList.Add(_T("&ReCommit"));
673 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
675 DWORD userResponse = progress.DoModal();
677 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
679 bCloseCommitDlg = false;
680 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
682 this->m_sLogMessage.Empty();
683 m_cLogMessage.SetText(m_sLogMessage);
686 this->Refresh();
688 else if(userResponse == IDC_PROGRESS_BUTTON1)
690 //User pressed 'Push' button after successful commit.
691 m_bPushAfterCommit=true;
694 CFile::Remove(tempfile);
696 if (m_BugTraqProvider && progress.m_GitStatus == 0)
698 CComPtr<IBugTraqProvider2> pProvider = NULL;
699 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
700 if (SUCCEEDED(hr))
702 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
703 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
705 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
706 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
708 BSTR logMessage = m_sLogMessage.AllocSysString();
710 CGitHash hash=g_Git.GetHash(_T("HEAD"));
711 LONG version = g_Git.Hash2int(hash);
713 BSTR temp = NULL;
714 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
715 commonRoot,
716 pathList,
717 logMessage,
718 (LONG)version,
719 &temp)))
721 CString sErr = temp;
722 if (!sErr.IsEmpty())
723 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
724 else
726 COMError ce(hr);
727 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
728 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
732 SysFreeString(temp);
736 }else if(bAddSuccess)
738 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
739 bCloseCommitDlg=false;
741 #if 0
742 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
744 // There are paths which got changed (touched at least).
745 // We have to find out if this affects the selection in the commit dialog
746 // If it could affect the selection, revert back to a non-recursive commit
747 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
748 changedList.RemoveDuplicates();
749 for (int i=0; i<changedList.GetCount(); ++i)
751 if (changedList[i].IsAdminDir())
753 // something inside an admin dir was changed.
754 // if it's the entries file, then we have to fully refresh because
755 // files may have been added/removed from version control
756 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
757 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
759 m_bRecursive = false;
760 break;
763 else if (!m_ListCtrl.IsPathShown(changedList[i]))
765 // a path which is not shown in the list has changed
766 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
767 if (entry)
769 // check if the changed path would get committed by a recursive commit
770 if ((!entry->IsFromDifferentRepository()) &&
771 (!entry->IsInExternal()) &&
772 (!entry->IsNested()) &&
773 (!entry->IsChecked()))
775 m_bRecursive = false;
776 break;
784 // Now, do all the adds - make sure that the list is sorted so that parents
785 // are added before their children
786 itemsToAdd.SortByPathname();
787 Git Git;
788 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
790 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
791 InterlockedExchange(&m_bBlock, FALSE);
792 Refresh();
793 return;
796 // Remove any missing items
797 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
798 itemsToRemove.SortByPathname();
799 Git.Remove(itemsToRemove, TRUE);
801 //the next step: find all deleted files and check if they're
802 //inside a deleted folder. If that's the case, then remove those
803 //files from the list since they'll get deleted by the parent
804 //folder automatically.
805 m_ListCtrl.Block(TRUE, FALSE);
806 INT_PTR nDeleted = arDeleted.GetCount();
807 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
809 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
811 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
812 if (path.IsDirectory())
814 //now find all children of this directory
815 for (int j=0; j<arDeleted.GetCount(); j++)
817 if (i!=j)
819 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
820 if (childEntry->IsChecked())
822 if (path.IsAncestorOf(childEntry->GetPath()))
824 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
825 nDeleted--;
833 m_ListCtrl.Block(FALSE, FALSE);
835 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
837 //save only the files the user has checked into the temporary file
838 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
841 // the item count is used in the progress dialog to show the overall commit
842 // progress.
843 // deleted items only send one notification event, all others send two
844 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
846 if ((m_bRecursive)&&(checkedLists.size() == 1))
848 // all checked items belong to the same changelist
849 // find out if there are any unchecked items which belong to that changelist
850 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
851 m_sChangeList = *checkedLists.begin();
853 #endif
854 UpdateData();
855 m_regAddBeforeCommit = m_bShowUnversioned;
856 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
857 m_bWholeProject = FALSE;
858 m_regKeepChangelists = m_bKeepChangeList;
859 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
860 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
861 m_bKeepChangeList = FALSE;
862 InterlockedExchange(&m_bBlock, FALSE);
864 m_History.AddEntry(m_sLogMessage);
865 m_History.Save();
867 SaveSplitterPos();
869 if( bCloseCommitDlg )
870 CResizableStandAloneDialog::OnOK();
872 CShellUpdater::Instance().Flush();
875 void CCommitDlg::SaveSplitterPos()
877 if (!IsIconic())
879 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
880 RECT rectSplitter;
881 m_wndSplitter.GetWindowRect(&rectSplitter);
882 ScreenToClient(&rectSplitter);
883 regPos = rectSplitter.top;
887 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
889 return ((CCommitDlg*)pVoid)->StatusThread();
892 UINT CCommitDlg::StatusThread()
894 //get the status of all selected file/folders recursively
895 //and show the ones which have to be committed to the user
896 //in a list control.
897 InterlockedExchange(&m_bBlock, TRUE);
898 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
899 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
901 m_pathwatcher.Stop();
903 g_Git.RefreshGitIndex();
905 m_bCancelled = false;
907 DialogEnableWindow(IDOK, false);
908 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
909 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
910 DialogEnableWindow(IDC_SELECTALL, false);
911 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
912 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
913 DialogEnableWindow(IDC_EXTERNALWARNING, false);
914 // read the list of recent log entries before querying the WC for status
915 // -> the user may select one and modify / update it while we are crawling the WC
917 if (m_History.GetCount()==0)
919 CString reg;
920 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
921 reg.Replace(_T(':'),_T('_'));
922 m_History.Load(reg, _T("logmsgs"));
925 // Initialise the list control with the status of the files/folders below us
926 m_ListCtrl.Clear();
927 BOOL success;
928 CTGitPathList *pList;
929 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
930 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
932 if(m_bWholeProject)
933 pList=NULL;
934 else
935 pList = &m_pathList;
937 success=m_ListCtrl.GetStatus(pList);
939 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
940 if(this->m_bShowUnversioned)
941 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
943 m_ListCtrl.CheckIfChangelistsArePresent(false);
945 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
946 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
947 if (success)
949 if (m_checkedPathList.GetCount())
950 m_ListCtrl.Show(dwShow, m_checkedPathList);
951 else
953 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
954 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
955 m_ListCtrl.Show(dwShow, dwCheck);
956 m_bSelectFilesForCommit = true;
959 if (m_ListCtrl.HasExternalsFromDifferentRepos())
961 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
962 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
965 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
966 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
968 if (!success)
970 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
971 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
972 m_ListCtrl.Show(dwShow);
974 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
975 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
977 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
979 m_bShowUnversioned = TRUE;
980 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
981 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
982 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
983 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
987 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
989 if(this->m_bWholeProject)
990 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T(" (Whole Project)")));
991 else
992 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
994 m_autolist.clear();
995 // we don't have to block the commit dialog while we fetch the
996 // auto completion list.
997 m_pathwatcher.ClearChangedPaths();
998 InterlockedExchange(&m_bBlock, FALSE);
999 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1001 m_ListCtrl.Block(TRUE, TRUE);
1002 GetAutocompletionList();
1003 m_ListCtrl.Block(FALSE, FALSE);
1005 UpdateOKButton();
1006 if (m_bRunThread)
1008 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1009 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1010 DialogEnableWindow(IDC_SELECTALL, true);
1011 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1012 if (m_ListCtrl.HasChangeLists())
1013 DialogEnableWindow(IDC_KEEPLISTS, true);
1014 if (m_ListCtrl.HasLocks())
1015 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1016 // we have the list, now signal the main thread about it
1017 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1020 InterlockedExchange(&m_bRunThread, FALSE);
1021 InterlockedExchange(&m_bThreadRunning, FALSE);
1022 // force the cursor to normal
1023 RefreshCursor();
1025 return 0;
1028 void CCommitDlg::OnCancel()
1030 m_bCancelled = true;
1031 m_pathwatcher.Stop();
1033 if (m_bBlock)
1034 return;
1036 if (m_bThreadRunning)
1038 InterlockedExchange(&m_bRunThread, FALSE);
1039 WaitForSingleObject(m_pThread->m_hThread, 1000);
1040 if (m_bThreadRunning)
1042 // we gave the thread a chance to quit. Since the thread didn't
1043 // listen to us we have to kill it.
1044 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1045 InterlockedExchange(&m_bThreadRunning, FALSE);
1048 UpdateData();
1049 m_sBugID.Trim();
1050 m_sLogMessage = m_cLogMessage.GetText();
1051 if (!m_sBugID.IsEmpty())
1053 m_sBugID.Replace(_T(", "), _T(","));
1054 m_sBugID.Replace(_T(" ,"), _T(","));
1055 CString sBugID = m_ProjectProperties.sMessage;
1056 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1057 if (m_ProjectProperties.bAppend)
1058 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1059 else
1060 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1062 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1063 m_History.AddEntry(m_sLogMessage);
1064 m_History.Save();
1065 SaveSplitterPos();
1066 CResizableStandAloneDialog::OnCancel();
1069 void CCommitDlg::OnBnClickedSelectall()
1071 m_tooltips.Pop(); // hide the tooltips
1072 UINT state = (m_SelectAll.GetState() & 0x0003);
1073 if (state == BST_INDETERMINATE)
1075 // It is not at all useful to manually place the checkbox into the indeterminate state...
1076 // We will force this on to the unchecked state
1077 state = BST_UNCHECKED;
1078 m_SelectAll.SetCheck(state);
1080 m_ListCtrl.SelectAll(state == BST_CHECKED);
1083 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1085 if (!m_bBlock)
1086 m_tooltips.RelayEvent(pMsg);
1088 if (m_hAccel)
1090 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1091 if (ret)
1092 return TRUE;
1095 if (pMsg->message == WM_KEYDOWN)
1097 switch (pMsg->wParam)
1099 case VK_F5:
1101 if (m_bBlock)
1102 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1103 Refresh();
1105 break;
1106 case VK_RETURN:
1108 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1110 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1112 PostMessage(WM_COMMAND, IDOK);
1114 return TRUE;
1116 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1118 // Pressing RETURN in the bug id control
1119 // moves the focus to the message
1120 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1121 return TRUE;
1124 break;
1128 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1131 void CCommitDlg::Refresh()
1133 if (m_bThreadRunning)
1134 return;
1136 InterlockedExchange(&m_bBlock, TRUE);
1137 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1138 if (m_pThread==NULL)
1140 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1141 InterlockedExchange(&m_bBlock, FALSE);
1143 else
1145 m_pThread->m_bAutoDelete = FALSE;
1146 m_pThread->ResumeThread();
1150 void CCommitDlg::OnBnClickedHelp()
1152 OnHelp();
1155 void CCommitDlg::OnBnClickedShowunversioned()
1157 m_tooltips.Pop(); // hide the tooltips
1158 UpdateData();
1159 m_regAddBeforeCommit = m_bShowUnversioned;
1160 if (!m_bBlock)
1162 DWORD dwShow = m_ListCtrl.GetShowFlags();
1163 if (DWORD(m_regAddBeforeCommit))
1164 dwShow |= SVNSLC_SHOWUNVERSIONED;
1165 else
1166 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1167 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1169 if(m_bWholeProject)
1170 m_ListCtrl.GetStatus(NULL,false,false,true);
1171 else
1172 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1174 m_ListCtrl.Show(dwShow,0,true,0,true);
1178 void CCommitDlg::OnStnClickedExternalwarning()
1180 m_tooltips.Popup();
1183 void CCommitDlg::OnEnChangeLogmessage()
1185 UpdateOKButton();
1188 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1190 #if 0
1191 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1193 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1195 m_bShowUnversioned = TRUE;
1196 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1197 m_ListCtrl.Show(dwShow);
1198 UpdateData(FALSE);
1201 #endif
1202 return 0;
1205 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1207 Refresh();
1208 return 0;
1211 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1213 #if 0
1214 BringWindowToTop();
1215 SetForegroundWindow();
1216 SetActiveWindow();
1217 // if multiple files/folders are dropped
1218 // this handler is called for every single item
1219 // separately.
1220 // To avoid creating multiple refresh threads and
1221 // causing crashes, we only add the items to the
1222 // list control and start a timer.
1223 // When the timer expires, we start the refresh thread,
1224 // but only if it isn't already running - otherwise we
1225 // restart the timer.
1226 CTGitPath path;
1227 path.SetFromWin((LPCTSTR)lParam);
1229 // just add all the items we get here.
1230 // if the item is versioned, the add will fail but nothing
1231 // more will happen.
1232 Git Git;
1233 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1235 if (!m_ListCtrl.HasPath(path))
1237 if (m_pathList.AreAllPathsFiles())
1239 m_pathList.AddPath(path);
1240 m_pathList.RemoveDuplicates();
1241 m_updatedPathList.AddPath(path);
1242 m_updatedPathList.RemoveDuplicates();
1244 else
1246 // if the path list contains folders, we have to check whether
1247 // our just (maybe) added path is a child of one of those. If it is
1248 // a child of a folder already in the list, we must not add it. Otherwise
1249 // that path could show up twice in the list.
1250 bool bHasParentInList = false;
1251 for (int i=0; i<m_pathList.GetCount(); ++i)
1253 if (m_pathList[i].IsAncestorOf(path))
1255 bHasParentInList = true;
1256 break;
1259 if (!bHasParentInList)
1261 m_pathList.AddPath(path);
1262 m_pathList.RemoveDuplicates();
1263 m_updatedPathList.AddPath(path);
1264 m_updatedPathList.RemoveDuplicates();
1269 // Always start the timer, since the status of an existing item might have changed
1270 SetTimer(REFRESHTIMER, 200, NULL);
1271 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1272 #endif
1273 return 0;
1276 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1278 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1279 return 0;
1282 //////////////////////////////////////////////////////////////////////////
1283 // functions which run in the status thread
1284 //////////////////////////////////////////////////////////////////////////
1286 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1288 CString strLine;
1291 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1292 while (m_bRunThread && file.ReadString(strLine))
1294 int eqpos = strLine.Find('=');
1295 CString rgx;
1296 rgx = strLine.Mid(eqpos+1).Trim();
1298 int pos = -1;
1299 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1301 mapRegex[strLine.Left(pos)] = rgx;
1302 strLine = strLine.Mid(pos+1).Trim();
1304 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1306 file.Close();
1308 catch (CFileException* pE)
1310 TRACE("CFileException loading auto list regex file\n");
1311 pE->Delete();
1312 return;
1315 void CCommitDlg::GetAutocompletionList()
1317 // the auto completion list is made of strings from each selected files.
1318 // the strings used are extracted from the files with regexes found
1319 // in the file "autolist.txt".
1320 // the format of that file is:
1321 // file extensions separated with commas '=' regular expression to use
1322 // example:
1323 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1324 // .cpp = (?<=[^\s]::)\b\w+\b
1326 std::map<CString, CString> mapRegex;
1327 CString sRegexFile = CPathUtils::GetAppDirectory();
1328 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1329 DWORD timeoutvalue = regtimeout*1000;
1330 sRegexFile += _T("autolist.txt");
1331 if (!m_bRunThread)
1332 return;
1333 ParseRegexFile(sRegexFile, mapRegex);
1334 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1335 sRegexFile.ReleaseBuffer();
1336 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1337 if (PathFileExists(sRegexFile))
1339 ParseRegexFile(sRegexFile, mapRegex);
1341 DWORD starttime = GetTickCount();
1343 // now we have two arrays of strings, where the first array contains all
1344 // file extensions we can use and the second the corresponding regex strings
1345 // to apply to those files.
1347 // the next step is to go over all files shown in the commit dialog
1348 // and scan them for strings we can use
1349 int nListItems = m_ListCtrl.GetItemCount();
1351 for (int i=0; i<nListItems && m_bRunThread; ++i)
1353 // stop parsing after timeout
1354 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1355 return;
1357 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1359 if(path == NULL)
1360 continue;
1362 CString sPartPath =path->GetGitPathString();
1363 m_autolist.insert(sPartPath);
1365 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1366 // if (!entry)
1367 // continue;
1369 // add the path parts to the auto completion list too
1370 // CString sPartPath = entry->GetRelativeGitPath();
1371 // m_autolist.insert(sPartPath);
1374 int pos = 0;
1375 int lastPos = 0;
1376 while ((pos = sPartPath.Find('/', pos)) >= 0)
1378 pos++;
1379 lastPos = pos;
1380 m_autolist.insert(sPartPath.Mid(pos));
1383 // Last inserted entry is a file name.
1384 // Some users prefer to also list file name without extension.
1385 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1387 int dotPos = sPartPath.ReverseFind('.');
1388 if ((dotPos >= 0) && (dotPos > lastPos))
1389 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1391 #if 0
1392 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1393 continue;
1395 CString sExt = entry->GetPath().GetFileExtension();
1396 sExt.MakeLower();
1397 // find the regex string which corresponds to the file extension
1398 CString rdata = mapRegex[sExt];
1399 if (rdata.IsEmpty())
1400 continue;
1402 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1403 if ((entry->textstatus != Git_wc_status_unversioned) &&
1404 (entry->textstatus != Git_wc_status_none) &&
1405 (entry->textstatus != Git_wc_status_ignored) &&
1406 (entry->textstatus != Git_wc_status_added) &&
1407 (entry->textstatus != Git_wc_status_normal))
1409 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1410 if (!basePath.IsEmpty())
1411 ScanFile(basePath.GetWinPathString(), rdata);
1413 #endif
1415 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1418 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1420 wstring sFileContent;
1421 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1422 if (hFile != INVALID_HANDLE_VALUE)
1424 DWORD size = GetFileSize(hFile, NULL);
1425 if (size > 1000000L)
1427 // no files bigger than 1 Meg
1428 CloseHandle(hFile);
1429 return;
1431 // allocate memory to hold file contents
1432 char * buffer = new char[size];
1433 DWORD readbytes;
1434 ReadFile(hFile, buffer, size, &readbytes, NULL);
1435 CloseHandle(hFile);
1436 int opts = 0;
1437 IsTextUnicode(buffer, readbytes, &opts);
1438 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1440 delete [] buffer;
1441 return;
1443 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1445 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1447 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1449 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1450 wchar_t * pWideBuf = new wchar_t[ret];
1451 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1452 if (ret2 == ret)
1453 sFileContent = wstring(pWideBuf, ret);
1454 delete [] pWideBuf;
1456 delete [] buffer;
1458 if (sFileContent.empty()|| !m_bRunThread)
1460 return;
1465 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1466 const tr1::wsregex_iterator end;
1467 wstring s = sFileContent;
1468 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1470 const tr1::wsmatch match = *it;
1471 for (size_t i=1; i<match.size(); ++i)
1473 if (match[i].second-match[i].first)
1475 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1476 m_autolist.insert(wstring(match[i]).c_str());
1481 catch (exception) {}
1484 // CSciEditContextMenuInterface
1485 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1487 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1488 m_nPopupPasteListCmd = nCmd++;
1489 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1491 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1492 if(m_History.GetCount() > 0)
1494 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1495 m_nPopupPasteLastMessage = nCmd++;
1496 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1498 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1499 m_nPopupRecentMessage = nCmd++;
1500 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1506 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1509 if (m_bBlock)
1510 return false;
1511 if (cmd == m_nPopupPasteListCmd)
1513 CString logmsg;
1514 int nListItems = m_ListCtrl.GetItemCount();
1515 for (int i=0; i<nListItems; ++i)
1517 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1518 if (entry&&entry->m_Checked)
1520 CString line;
1521 CString status = entry->GetActionName();
1522 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1523 status = _T("Add");
1525 //git_wc_status_kind status = entry->status;
1526 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1527 if (m_ProjectProperties.bFileListInEnglish)
1528 langID = 1033;
1530 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1531 logmsg += line;
1534 pSciEdit->InsertText(logmsg);
1535 return true;
1538 if(cmd == m_nPopupPasteLastMessage)
1540 if(m_History.GetCount() ==0 )
1541 return false;
1543 CString logmsg;
1544 logmsg +=m_History.GetEntry(0);
1545 pSciEdit->InsertText(logmsg);
1546 return true;
1549 if(cmd == m_nPopupRecentMessage )
1551 OnBnClickedHistory();
1552 return true;
1554 return false;
1557 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1559 switch (nIDEvent)
1561 case ENDDIALOGTIMER:
1562 KillTimer(ENDDIALOGTIMER);
1563 EndDialog(0);
1564 break;
1565 case REFRESHTIMER:
1566 if (m_bThreadRunning)
1568 SetTimer(REFRESHTIMER, 200, NULL);
1569 ATLTRACE("Wait some more before refreshing\n");
1571 else
1573 KillTimer(REFRESHTIMER);
1574 ATLTRACE("Refreshing after items dropped\n");
1575 Refresh();
1577 break;
1579 __super::OnTimer(nIDEvent);
1582 void CCommitDlg::OnBnClickedHistory()
1584 m_tooltips.Pop(); // hide the tooltips
1585 if (m_pathList.GetCount() == 0)
1586 return;
1588 CHistoryDlg historyDlg;
1589 historyDlg.SetHistory(m_History);
1590 if (historyDlg.DoModal() != IDOK)
1591 return;
1593 CString sMsg = historyDlg.GetSelectedText();
1594 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1596 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1597 if (!sBugID.IsEmpty())
1599 SetDlgItemText(IDC_BUGID, sBugID);
1601 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1602 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1603 else
1604 m_cLogMessage.SetText(sMsg);
1607 UpdateOKButton();
1608 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1612 void CCommitDlg::OnBnClickedBugtraqbutton()
1614 m_tooltips.Pop(); // hide the tooltips
1615 CString sMsg = m_cLogMessage.GetText();
1617 if (m_BugTraqProvider == NULL)
1618 return;
1620 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1621 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1622 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1624 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1625 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1627 BSTR originalMessage = sMsg.AllocSysString();
1628 BSTR temp = NULL;
1629 // m_revProps.clear();
1631 // first try the IBugTraqProvider2 interface
1632 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1633 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1634 if (SUCCEEDED(hr))
1636 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1637 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1638 BSTR bugIDOut = NULL;
1639 GetDlgItemText(IDC_BUGID, m_sBugID);
1640 BSTR bugID = m_sBugID.AllocSysString();
1641 SAFEARRAY * revPropNames = NULL;
1642 SAFEARRAY * revPropValues = NULL;
1643 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1645 CString sErr;
1646 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1647 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1649 else
1651 if (bugIDOut)
1653 m_sBugID = bugIDOut;
1654 SysFreeString(bugIDOut);
1655 SetDlgItemText(IDC_BUGID, m_sBugID);
1657 SysFreeString(bugID);
1658 SysFreeString(repositoryRoot);
1659 m_cLogMessage.SetText(temp);
1660 BSTR HUGEP *pbRevNames;
1661 BSTR HUGEP *pbRevValues;
1663 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1664 if (SUCCEEDED(hr1))
1666 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1667 if (SUCCEEDED(hr2))
1669 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1671 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1673 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1676 SafeArrayUnaccessData(revPropValues);
1678 SafeArrayUnaccessData(revPropNames);
1680 if (revPropNames)
1681 SafeArrayDestroy(revPropNames);
1682 if (revPropValues)
1683 SafeArrayDestroy(revPropValues);
1686 else
1688 // if IBugTraqProvider2 failed, try IBugTraqProvider
1689 CComPtr<IBugTraqProvider> pProvider = NULL;
1690 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1691 if (FAILED(hr))
1693 CString sErr;
1694 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1695 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1696 return;
1699 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1701 CString sErr;
1702 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1703 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1705 else
1706 m_cLogMessage.SetText(temp);
1708 m_sLogMessage = m_cLogMessage.GetText();
1709 if (!m_ProjectProperties.sMessage.IsEmpty())
1711 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1712 if (!sBugID.IsEmpty())
1714 SetDlgItemText(IDC_BUGID, sBugID);
1718 m_cLogMessage.SetFocus();
1720 SysFreeString(parameters);
1721 SysFreeString(commonRoot);
1722 SafeArrayDestroy(pathList);
1723 SysFreeString(originalMessage);
1724 SysFreeString(temp);
1728 void CCommitDlg::FillPatchView()
1730 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1732 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1734 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1735 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1736 CString cmd,out;
1738 while(pos)
1740 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1741 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1742 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1744 CString head;
1745 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1746 head = _T("HEAD~1 ");
1747 cmd.Format(_T("git.exe diff %s-- \"%s\""), head, p->GetGitPathString());
1748 g_Git.Run(cmd,&out,CP_ACP);
1752 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1753 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1754 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1757 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1759 this->FillPatchView();
1760 return 0;
1764 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1766 UpdateOKButton();
1767 return 0;
1770 void CCommitDlg::UpdateOKButton()
1772 if (m_bBlock)
1773 return;
1775 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1776 bool bAmendOrSelectFiles = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit);
1778 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFiles);
1781 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1783 switch (message) {
1784 case WM_NOTIFY:
1785 if (wParam == IDC_SPLITTER)
1787 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1788 DoSize(pHdr->delta);
1790 break;
1793 return __super::DefWindowProc(message, wParam, lParam);
1796 void CCommitDlg::SetSplitterRange()
1798 if ((m_ListCtrl)&&(m_cLogMessage))
1800 CRect rcTop;
1801 m_cLogMessage.GetWindowRect(rcTop);
1802 ScreenToClient(rcTop);
1803 CRect rcMiddle;
1804 m_ListCtrl.GetWindowRect(rcMiddle);
1805 ScreenToClient(rcMiddle);
1806 if (rcMiddle.Height() && rcMiddle.Width())
1807 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1811 void CCommitDlg::DoSize(int delta)
1813 RemoveAnchor(IDC_MESSAGEGROUP);
1814 RemoveAnchor(IDC_LOGMESSAGE);
1815 RemoveAnchor(IDC_SPLITTER);
1816 RemoveAnchor(IDC_SIGNOFF);
1817 RemoveAnchor(IDC_COMMIT_AMEND);
1818 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1819 RemoveAnchor(IDC_LISTGROUP);
1820 RemoveAnchor(IDC_FILELIST);
1821 RemoveAnchor(IDC_TEXT_INFO);
1822 RemoveAnchor(IDC_VIEW_PATCH);
1824 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1825 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1826 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1827 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1828 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1829 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1830 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1831 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1832 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1834 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1835 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1836 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1837 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1838 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1839 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1840 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1841 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1842 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1843 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1844 ArrangeLayout();
1845 // adjust the minimum size of the dialog to prevent the resizing from
1846 // moving the list control too far down.
1847 CRect rcLogMsg;
1848 m_cLogMessage.GetClientRect(rcLogMsg);
1849 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1851 SetSplitterRange();
1852 m_cLogMessage.Invalidate();
1853 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1856 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1858 // first, let the resizing take place
1859 __super::OnSize(nType, cx, cy);
1861 //set range
1862 SetSplitterRange();
1866 void CCommitDlg::OnBnClickedSignOff()
1868 CString str;
1869 CString username;
1870 CString email;
1871 username=g_Git.GetUserName();
1872 email=g_Git.GetUserEmail();
1873 username.Remove(_T('\n'));
1874 email.Remove(_T('\n'));
1875 str.Format(_T("Signed-off-by: %s <%s>"),username,email);
1877 if (m_cLogMessage.GetText().Find(str) == -1) {
1878 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1879 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1880 int foundByLine = -1;
1881 if (lastNewline > 0)
1882 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1884 if (foundByLine == -1 || foundByLine < lastNewline)
1885 str = _T("\r\n") + str;
1887 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1891 void CCommitDlg::OnBnClickedCommitAmend()
1893 this->UpdateData();
1894 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1896 GitRev rev;
1897 rev.GetCommit(CString(_T("HEAD")));
1898 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
1901 if(this->m_bCommitAmend)
1903 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1904 m_cLogMessage.SetText(m_AmendStr);
1905 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1907 else
1909 this->m_AmendStr=this->m_cLogMessage.GetText();
1910 m_cLogMessage.SetText(m_NoAmendStr);
1911 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1913 Refresh();
1916 void CCommitDlg::OnBnClickedWholeProject()
1918 m_tooltips.Pop(); // hide the tooltips
1919 UpdateData();
1920 m_ListCtrl.Clear();
1921 if (!m_bBlock)
1923 if(m_bWholeProject)
1924 m_ListCtrl.GetStatus(NULL,true,false,true);
1925 else
1926 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1928 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());
1931 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1933 if(this->m_bWholeProject)
1934 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1935 else
1936 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1940 void CCommitDlg::OnFocusMessage()
1942 m_cLogMessage.SetFocus();
1945 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1947 UNREFERENCED_PARAMETER(pNMHDR);
1948 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1949 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1950 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1952 CString str;
1953 str.Format(_T("%d/%d"),line+1,column+1);
1954 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1956 if(*pResult)
1957 *pResult=0;
1959 void CCommitDlg::OnStnClickedViewPatch()
1961 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1962 m_patchViewdlg.m_ParentCommitDlg = this;
1963 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1965 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1966 CRect rect;
1967 this->GetWindowRect(&rect);
1969 m_patchViewdlg.ShowWindow(SW_SHOW);
1971 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1972 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1974 ShowViewPatchText(false);
1975 FillPatchView();
1977 else
1979 m_patchViewdlg.ShowWindow(SW_HIDE);
1980 m_patchViewdlg.DestroyWindow();
1981 ShowViewPatchText(true);
1983 this->m_ctrlShowPatch.Invalidate();
1986 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
1988 __super::OnMoving(fwSide, pRect);
1990 if (::IsWindow(m_patchViewdlg.m_hWnd))
1992 RECT patchrect;
1993 m_patchViewdlg.GetWindowRect(&patchrect);
1994 if (::IsWindow(m_hWnd))
1996 RECT thisrect;
1997 GetWindowRect(&thisrect);
1998 if (patchrect.left == thisrect.right)
2000 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2001 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2008 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2010 __super::OnSizing(fwSide, pRect);
2012 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2014 CRect thisrect, patchrect;
2015 this->GetWindowRect(thisrect);
2016 this->m_patchViewdlg.GetWindowRect(patchrect);
2017 if(thisrect.right==patchrect.left)
2019 patchrect.left -= (thisrect.right - pRect->right);
2020 patchrect.right-= (thisrect.right - pRect->right);
2022 if( patchrect.bottom == thisrect.bottom)
2024 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2026 if( patchrect.top == thisrect.top)
2028 patchrect.top -= thisrect.top-pRect->top;
2030 m_patchViewdlg.MoveWindow(patchrect);
2035 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2037 UNREFERENCED_PARAMETER(pNMHDR);
2038 *pResult = 0;
2039 TRACE("Item Changed\r\n");
2042 int CCommitDlg::CheckHeadDetach()
2044 CString output;
2045 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2047 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2048 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2050 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2053 return 0;
2056 void CCommitDlg::OnBnClickedCommitAmenddiff()
2058 UpdateData();
2059 Refresh();
2062 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2064 UpdateData();
2065 Refresh();