updated title
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blobf7226ad754c575c6d37bd88657f9dc7e0d10c91d
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)
67 , m_bSetCommitDateTime(FALSE)
69 this->m_bCommitAmend=FALSE;
70 m_bPushAfterCommit = FALSE;
73 CCommitDlg::~CCommitDlg()
75 if(m_pThread != NULL)
77 delete m_pThread;
81 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
83 CResizableStandAloneDialog::DoDataExchange(pDX);
84 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
85 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
86 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
87 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
88 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
89 DDX_Text(pDX, IDC_BUGID, m_sBugID);
90 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
91 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
92 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
93 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
94 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
95 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
96 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
97 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
98 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
101 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
102 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
103 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
104 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
105 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
106 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
107 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
108 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
109 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
110 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
111 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
112 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
113 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
115 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
116 ON_WM_TIMER()
117 ON_WM_SIZE()
118 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
119 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
120 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
121 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
122 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
123 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
124 ON_WM_MOVE()
125 ON_WM_MOVING()
126 ON_WM_SIZING()
127 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
128 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
129 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
130 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
131 END_MESSAGE_MAP()
133 BOOL CCommitDlg::OnInitDialog()
135 CResizableStandAloneDialog::OnInitDialog();
136 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
138 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
140 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG")))
142 CStdioFile file;
143 if(file.Open(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG"), CFile::modeRead))
145 CString str;
146 while(file.ReadString(str))
148 m_sLogMessage += str;
149 str.Empty();
150 m_sLogMessage += _T("\n");
154 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
155 m_bShowUnversioned = m_regAddBeforeCommit;
157 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
159 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
160 m_bKeepChangeList = m_regKeepChangelists;
162 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
163 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
165 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
167 // GitConfig config;
168 // m_bWholeProject = config.KeepLocks();
170 if(this->m_pathList.GetCount() == 0)
171 m_bWholeProject =true;
173 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
174 m_bWholeProject =true;
176 UpdateData(FALSE);
178 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT | SVNSLC_POPSAVEAS)));
179 m_ListCtrl.SetSelectButton(&m_SelectAll);
180 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
181 m_ListCtrl.SetCancelBool(&m_bCancelled);
182 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
183 m_ListCtrl.EnableFileDrop();
184 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
186 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
187 m_ProjectProperties.ReadPropsPathList(m_pathList);
189 m_cLogMessage.Init(m_ProjectProperties);
190 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
191 m_cLogMessage.RegisterContextMenuHandler(this);
193 OnEnChangeLogmessage();
195 m_tooltips.Create(this);
196 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
197 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
198 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
200 m_SelectAll.SetCheck(BST_INDETERMINATE);
202 CBugTraqAssociations bugtraq_associations;
203 bugtraq_associations.Load();
205 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
207 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
208 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
210 CComPtr<IBugTraqProvider> pProvider;
211 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
212 if (SUCCEEDED(hr))
214 m_BugTraqProvider = pProvider;
215 BSTR temp = NULL;
216 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
218 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
219 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
220 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
223 SysFreeString(temp);
226 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
228 else if (!m_ProjectProperties.sMessage.IsEmpty())
230 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
231 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
232 if (!m_ProjectProperties.sLabel.IsEmpty())
233 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
234 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
235 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
236 GetDlgItem(IDC_BUGID)->SetFocus();
237 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
238 if (!sBugID.IsEmpty())
240 SetDlgItemText(IDC_BUGID, sBugID);
243 else
245 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
246 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
247 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
248 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
249 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
252 if (!m_sLogMessage.IsEmpty())
253 m_cLogMessage.SetText(m_sLogMessage);
255 GetWindowText(m_sWindowTitle);
257 AdjustControlSize(IDC_SHOWUNVERSIONED);
258 AdjustControlSize(IDC_SELECTALL);
259 AdjustControlSize(IDC_WHOLE_PROJECT);
261 GetClientRect(m_DlgOrigRect);
262 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
264 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
265 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
266 AddAnchor(IDC_BUGID, TOP_RIGHT);
267 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
268 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
269 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
270 // AddAnchor(IDC_HISTORY, TOP_LEFT);
271 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
272 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
273 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
274 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
275 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
276 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
277 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
278 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
279 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
280 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
281 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
282 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
283 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
284 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
285 AddAnchor(IDOK, BOTTOM_RIGHT);
286 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
287 AddAnchor(IDHELP, BOTTOM_RIGHT);
288 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
289 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
290 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
291 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
292 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
294 if (hWndExplorer)
295 CenterWindow(CWnd::FromHandle(hWndExplorer));
296 EnableSaveRestore(_T("CommitDlg"));
297 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
298 RECT rcDlg, rcLogMsg, rcFileList;
299 GetClientRect(&rcDlg);
300 m_cLogMessage.GetWindowRect(&rcLogMsg);
301 ScreenToClient(&rcLogMsg);
302 m_ListCtrl.GetWindowRect(&rcFileList);
303 ScreenToClient(&rcFileList);
304 if (yPos)
306 RECT rectSplitter;
307 m_wndSplitter.GetWindowRect(&rectSplitter);
308 ScreenToClient(&rectSplitter);
309 int delta = yPos - rectSplitter.top;
310 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
312 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
313 DoSize(delta);
317 // add all directories to the watcher
319 for (int i=0; i<m_pathList.GetCount(); ++i)
321 if (m_pathList[i].IsDirectory())
322 m_pathwatcher.AddPath(m_pathList[i]);
325 m_updatedPathList = m_pathList;
327 //first start a thread to obtain the file list with the status without
328 //blocking the dialog
329 InterlockedExchange(&m_bBlock, TRUE);
330 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
331 if (m_pThread==NULL)
333 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
334 InterlockedExchange(&m_bBlock, FALSE);
336 else
338 m_pThread->m_bAutoDelete = FALSE;
339 m_pThread->ResumeThread();
341 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
342 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
343 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
345 historyhint = TRUE;
346 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
348 err = FALSE;
350 if (g_Git.IsInitRepos())
352 m_bCommitAmend = FALSE;
353 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
354 UpdateData(FALSE);
356 else
358 if(m_bCommitAmend)
360 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
361 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
364 CGitHash hash = g_Git.GetHash(_T("HEAD"));
365 GitRev headRevision;
366 headRevision.GetParentFromHash(hash);
367 // do not allow to show diff to "last" revision if it has more that one parent
368 if (headRevision.ParentsCount() != 1)
370 m_bAmendDiffToLastCommit = true;
371 UpdateData(FALSE);
372 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(FALSE);
376 this->m_ctrlShowPatch.SetURL(CString());
378 return FALSE; // return TRUE unless you set the focus to a control
379 // EXCEPTION: OCX Property Pages should return FALSE
382 void CCommitDlg::OnOK()
384 if (m_bBlock)
385 return;
386 if (m_bThreadRunning)
388 m_bCancelled = true;
389 InterlockedExchange(&m_bRunThread, FALSE);
390 WaitForSingleObject(m_pThread->m_hThread, 1000);
391 if (m_bThreadRunning)
393 // we gave the thread a chance to quit. Since the thread didn't
394 // listen to us we have to kill it.
395 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
396 InterlockedExchange(&m_bThreadRunning, FALSE);
399 this->UpdateData();
401 CString id;
402 GetDlgItemText(IDC_BUGID, id);
403 if (!m_ProjectProperties.CheckBugID(id))
405 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
406 return;
408 m_sLogMessage = m_cLogMessage.GetText();
409 if ( m_sLogMessage.IsEmpty() )
411 // no message entered, go round again
412 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
413 return;
415 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
417 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
418 return;
421 BOOL bWarnNoSignedOffBy = FALSE;
422 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
423 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
425 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"));
426 if (retval == 1)
428 OnBnClickedSignOff();
429 m_sLogMessage = m_cLogMessage.GetText();
431 else if (retval == 3)
432 return;
435 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
436 #if 0
437 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
438 if (!(DWORD)regUnversionedRecurse)
440 // Find unversioned directories which are marked for commit. The user might expect them
441 // to be added recursively since he cannot the the files. Let's ask the user if he knows
442 // what he is doing.
443 int nListItems = m_ListCtrl.GetItemCount();
444 for (int j=0; j<nListItems; j++)
446 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
447 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
449 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
450 return;
454 #endif
455 m_pathwatcher.Stop();
456 InterlockedExchange(&m_bBlock, TRUE);
457 CDWordArray arDeleted;
458 //first add all the unversioned files the user selected
459 //and check if all versioned files are selected
460 int nchecked = 0;
461 m_bRecursive = true;
462 int nListItems = m_ListCtrl.GetItemCount();
464 CTGitPathList itemsToAdd;
465 CTGitPathList itemsToRemove;
466 //std::set<CString> checkedLists;
467 //std::set<CString> uncheckedLists;
469 // now let the bugtraq plugin check the commit message
470 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
471 if (m_BugTraqProvider)
473 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
474 if (SUCCEEDED(hr))
476 BSTR temp = NULL;
477 CString common = g_Git.m_CurrentDir;
478 BSTR repositoryRoot = common.AllocSysString();
479 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
480 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
481 BSTR commitMessage = m_sLogMessage.AllocSysString();
482 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
484 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
485 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
487 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
489 COMError ce(hr);
490 CString sErr;
491 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
492 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
494 else
496 CString sError = temp;
497 if (!sError.IsEmpty())
499 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
500 return;
502 SysFreeString(temp);
507 //CString checkedfiles;
508 //CString uncheckedfiles;
510 CString cmd;
511 CString out;
513 bool bAddSuccess=true;
514 bool bCloseCommitDlg=false;
516 for (int j=0; j<nListItems; j++)
518 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
519 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
520 if (entry->m_Checked)
522 #if 0
523 if (entry->status == Git_wc_status_unversioned)
525 itemsToAdd.AddPath(entry->GetPath());
527 if (entry->status == Git_wc_status_conflicted)
529 bHasConflicted = true;
531 if (entry->status == Git_wc_status_missing)
533 itemsToRemove.AddPath(entry->GetPath());
535 if (entry->status == Git_wc_status_deleted)
537 arDeleted.Add(j);
539 if (entry->IsInExternal())
541 bCheckedInExternal = true;
543 #endif
544 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
545 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
546 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
547 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
548 else
549 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
551 if(g_Git.Run(cmd,&out,CP_ACP))
553 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
554 bAddSuccess = false ;
555 break;
558 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
559 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
561 g_Git.Run(cmd,&out,CP_ACP);
563 nchecked++;
565 //checkedLists.insert(entry->GetGitPathString());
566 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
568 else
570 //uncheckedLists.insert(entry->GetGitPathString());
571 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
572 { //To init git repository, there are not HEAD, so we can use git reset command
573 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
574 if(g_Git.Run(cmd,&out,CP_ACP))
576 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
577 bAddSuccess = false ;
578 bCloseCommitDlg=false;
579 break;
583 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
585 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
587 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
589 else
591 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
593 if(g_Git.Run(cmd,&out,CP_ACP))
595 /* when reset a unstage file will report error.
596 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
597 bAddSuccess = false ;
598 bCloseCommitDlg=false;
599 break;
602 // && !entry->IsDirectory()
603 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
604 continue;
607 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
608 #if 0
609 if ((entry->status != Git_wc_status_unversioned) &&
610 (entry->status != Git_wc_status_ignored))
612 nUnchecked++;
613 uncheckedLists.insert(entry->GetChangeList());
614 if (m_bRecursive)
616 // This algorithm is for the sake of simplicity of the complexity O(N?
617 for (int k=0; k<nListItems; k++)
619 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
620 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
622 // Fall back to a non-recursive commit to prevent items being
623 // committed which aren't checked although its parent is checked
624 // (property change, directory deletion, ... )
625 m_bRecursive = false;
626 break;
631 #endif
634 CShellUpdater::Instance().AddPathForUpdate(*entry);
637 //if(uncheckedfiles.GetLength()>0)
639 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
640 // g_Git.Run(cmd,&out);
643 m_sBugID.Trim();
644 if (!m_sBugID.IsEmpty())
646 m_sBugID.Replace(_T(", "), _T(","));
647 m_sBugID.Replace(_T(" ,"), _T(","));
648 CString sBugID = m_ProjectProperties.sMessage;
649 sBugID.Replace(_T("%BUGID%"), m_sBugID);
650 if (m_ProjectProperties.bAppend)
651 m_sLogMessage += _T("\n") + sBugID + _T("\n");
652 else
653 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
656 BOOL bIsMerge=false;
657 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
659 bIsMerge=true;
661 //if(checkedfiles.GetLength()>0)
662 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
664 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
665 // g_Git.Run(cmd,&out);
667 bCloseCommitDlg = true;
669 CString tempfile=::GetTempFile();
671 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
672 //file.WriteString(m_sLogMessage);
674 CTGitPath path=g_Git.m_CurrentDir;
676 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
678 out =_T("");
679 CString amend;
680 if(this->m_bCommitAmend)
682 amend=_T("--amend");
684 CString dateTime;
685 if (m_bSetCommitDateTime)
687 CTime date, time;
688 m_CommitDate.GetTime(date);
689 m_CommitTime.GetTime(time);
690 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
692 cmd.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime, amend, tempfile);
694 CheckHeadDetach();
696 CCommitProgressDlg progress;
697 progress.m_bBufferAll=true; // improve show speed when there are many file added.
698 progress.m_GitCmd=cmd;
699 progress.m_bShowCommand = FALSE; // don't show the commit command
700 progress.m_PreText = out; // show any output already generated in log window
701 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
703 if (!m_bNoPostActions && !m_bAutoClose)
705 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
706 progress.m_PostCmdList.Add(_T("&ReCommit"));
709 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
711 DWORD userResponse = progress.DoModal();
713 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
715 bCloseCommitDlg = false;
716 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
718 this->m_sLogMessage.Empty();
719 m_cLogMessage.SetText(m_sLogMessage);
722 this->Refresh();
724 else if(userResponse == IDC_PROGRESS_BUTTON1)
726 //User pressed 'Push' button after successful commit.
727 m_bPushAfterCommit=true;
730 CFile::Remove(tempfile);
732 if (m_BugTraqProvider && progress.m_GitStatus == 0)
734 CComPtr<IBugTraqProvider2> pProvider = NULL;
735 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
736 if (SUCCEEDED(hr))
738 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
739 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
741 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
742 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
744 BSTR logMessage = m_sLogMessage.AllocSysString();
746 CGitHash hash=g_Git.GetHash(_T("HEAD"));
747 LONG version = g_Git.Hash2int(hash);
749 BSTR temp = NULL;
750 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
751 commonRoot,
752 pathList,
753 logMessage,
754 (LONG)version,
755 &temp)))
757 CString sErr = temp;
758 if (!sErr.IsEmpty())
759 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
760 else
762 COMError ce(hr);
763 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
764 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
768 SysFreeString(temp);
772 }else if(bAddSuccess)
774 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
775 bCloseCommitDlg=false;
777 #if 0
778 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
780 // There are paths which got changed (touched at least).
781 // We have to find out if this affects the selection in the commit dialog
782 // If it could affect the selection, revert back to a non-recursive commit
783 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
784 changedList.RemoveDuplicates();
785 for (int i=0; i<changedList.GetCount(); ++i)
787 if (changedList[i].IsAdminDir())
789 // something inside an admin dir was changed.
790 // if it's the entries file, then we have to fully refresh because
791 // files may have been added/removed from version control
792 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
793 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
795 m_bRecursive = false;
796 break;
799 else if (!m_ListCtrl.IsPathShown(changedList[i]))
801 // a path which is not shown in the list has changed
802 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
803 if (entry)
805 // check if the changed path would get committed by a recursive commit
806 if ((!entry->IsFromDifferentRepository()) &&
807 (!entry->IsInExternal()) &&
808 (!entry->IsNested()) &&
809 (!entry->IsChecked()))
811 m_bRecursive = false;
812 break;
820 // Now, do all the adds - make sure that the list is sorted so that parents
821 // are added before their children
822 itemsToAdd.SortByPathname();
823 Git Git;
824 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
826 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
827 InterlockedExchange(&m_bBlock, FALSE);
828 Refresh();
829 return;
832 // Remove any missing items
833 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
834 itemsToRemove.SortByPathname();
835 Git.Remove(itemsToRemove, TRUE);
837 //the next step: find all deleted files and check if they're
838 //inside a deleted folder. If that's the case, then remove those
839 //files from the list since they'll get deleted by the parent
840 //folder automatically.
841 m_ListCtrl.Block(TRUE, FALSE);
842 INT_PTR nDeleted = arDeleted.GetCount();
843 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
845 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
847 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
848 if (path.IsDirectory())
850 //now find all children of this directory
851 for (int j=0; j<arDeleted.GetCount(); j++)
853 if (i!=j)
855 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
856 if (childEntry->IsChecked())
858 if (path.IsAncestorOf(childEntry->GetPath()))
860 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
861 nDeleted--;
869 m_ListCtrl.Block(FALSE, FALSE);
871 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
873 //save only the files the user has checked into the temporary file
874 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
877 // the item count is used in the progress dialog to show the overall commit
878 // progress.
879 // deleted items only send one notification event, all others send two
880 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
882 if ((m_bRecursive)&&(checkedLists.size() == 1))
884 // all checked items belong to the same changelist
885 // find out if there are any unchecked items which belong to that changelist
886 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
887 m_sChangeList = *checkedLists.begin();
889 #endif
890 UpdateData();
891 m_regAddBeforeCommit = m_bShowUnversioned;
892 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
893 m_bWholeProject = FALSE;
894 m_regKeepChangelists = m_bKeepChangeList;
895 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
896 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
897 m_bKeepChangeList = FALSE;
898 InterlockedExchange(&m_bBlock, FALSE);
900 m_History.AddEntry(m_sLogMessage);
901 m_History.Save();
903 SaveSplitterPos();
905 if( bCloseCommitDlg )
906 CResizableStandAloneDialog::OnOK();
908 CShellUpdater::Instance().Flush();
911 void CCommitDlg::SaveSplitterPos()
913 if (!IsIconic())
915 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
916 RECT rectSplitter;
917 m_wndSplitter.GetWindowRect(&rectSplitter);
918 ScreenToClient(&rectSplitter);
919 regPos = rectSplitter.top;
923 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
925 return ((CCommitDlg*)pVoid)->StatusThread();
928 UINT CCommitDlg::StatusThread()
930 //get the status of all selected file/folders recursively
931 //and show the ones which have to be committed to the user
932 //in a list control.
933 InterlockedExchange(&m_bBlock, TRUE);
934 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
935 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
937 m_pathwatcher.Stop();
939 g_Git.RefreshGitIndex();
941 m_bCancelled = false;
943 DialogEnableWindow(IDOK, false);
944 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
945 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
946 DialogEnableWindow(IDC_SELECTALL, false);
947 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
948 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
949 DialogEnableWindow(IDC_EXTERNALWARNING, false);
950 // read the list of recent log entries before querying the WC for status
951 // -> the user may select one and modify / update it while we are crawling the WC
953 if (m_History.GetCount()==0)
955 CString reg;
956 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
957 reg.Replace(_T(':'),_T('_'));
958 m_History.Load(reg, _T("logmsgs"));
961 // Initialise the list control with the status of the files/folders below us
962 m_ListCtrl.Clear();
963 BOOL success;
964 CTGitPathList *pList;
965 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
966 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
968 if(m_bWholeProject)
969 pList=NULL;
970 else
971 pList = &m_pathList;
973 success=m_ListCtrl.GetStatus(pList);
975 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
976 if(this->m_bShowUnversioned)
977 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
979 m_ListCtrl.CheckIfChangelistsArePresent(false);
981 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
982 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
983 if (success)
985 if (m_checkedPathList.GetCount())
986 m_ListCtrl.Show(dwShow, m_checkedPathList);
987 else
989 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
990 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
991 m_ListCtrl.Show(dwShow, dwCheck);
992 m_bSelectFilesForCommit = true;
995 if (m_ListCtrl.HasExternalsFromDifferentRepos())
997 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
998 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1001 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1002 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1004 if (!success)
1006 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1007 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1008 m_ListCtrl.Show(dwShow);
1010 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1011 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
1013 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1015 m_bShowUnversioned = TRUE;
1016 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1017 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
1018 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1019 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1023 SetDlgTitle();
1025 m_autolist.clear();
1026 // we don't have to block the commit dialog while we fetch the
1027 // auto completion list.
1028 m_pathwatcher.ClearChangedPaths();
1029 InterlockedExchange(&m_bBlock, FALSE);
1030 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1032 m_ListCtrl.Block(TRUE, TRUE);
1033 GetAutocompletionList();
1034 m_ListCtrl.Block(FALSE, FALSE);
1036 UpdateOKButton();
1037 if (m_bRunThread)
1039 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1040 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1041 DialogEnableWindow(IDC_SELECTALL, true);
1042 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1043 if (m_ListCtrl.HasChangeLists())
1044 DialogEnableWindow(IDC_KEEPLISTS, true);
1045 if (m_ListCtrl.HasLocks())
1046 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1047 // we have the list, now signal the main thread about it
1048 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1051 InterlockedExchange(&m_bRunThread, FALSE);
1052 InterlockedExchange(&m_bThreadRunning, FALSE);
1053 // force the cursor to normal
1054 RefreshCursor();
1056 return 0;
1059 void CCommitDlg::SetDlgTitle()
1061 if (m_sTitle.IsEmpty())
1062 GetWindowText(m_sTitle);
1064 if (m_bWholeProject)
1065 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1066 else
1068 if (m_pathList.GetCount() == 1)
1069 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString(), m_sTitle);
1070 else
1071 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1075 void CCommitDlg::OnCancel()
1077 m_bCancelled = true;
1078 m_pathwatcher.Stop();
1080 if (m_bBlock)
1081 return;
1083 if (m_bThreadRunning)
1085 InterlockedExchange(&m_bRunThread, FALSE);
1086 WaitForSingleObject(m_pThread->m_hThread, 1000);
1087 if (m_bThreadRunning)
1089 // we gave the thread a chance to quit. Since the thread didn't
1090 // listen to us we have to kill it.
1091 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1092 InterlockedExchange(&m_bThreadRunning, FALSE);
1095 UpdateData();
1096 m_sBugID.Trim();
1097 m_sLogMessage = m_cLogMessage.GetText();
1098 if (!m_sBugID.IsEmpty())
1100 m_sBugID.Replace(_T(", "), _T(","));
1101 m_sBugID.Replace(_T(" ,"), _T(","));
1102 CString sBugID = m_ProjectProperties.sMessage;
1103 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1104 if (m_ProjectProperties.bAppend)
1105 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1106 else
1107 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1109 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1110 m_History.AddEntry(m_sLogMessage);
1111 m_History.Save();
1112 SaveSplitterPos();
1113 CResizableStandAloneDialog::OnCancel();
1116 void CCommitDlg::OnBnClickedSelectall()
1118 m_tooltips.Pop(); // hide the tooltips
1119 UINT state = (m_SelectAll.GetState() & 0x0003);
1120 if (state == BST_INDETERMINATE)
1122 // It is not at all useful to manually place the checkbox into the indeterminate state...
1123 // We will force this on to the unchecked state
1124 state = BST_UNCHECKED;
1125 m_SelectAll.SetCheck(state);
1127 m_ListCtrl.SelectAll(state == BST_CHECKED);
1130 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1132 if (!m_bBlock)
1133 m_tooltips.RelayEvent(pMsg);
1135 if (m_hAccel)
1137 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1138 if (ret)
1139 return TRUE;
1142 if (pMsg->message == WM_KEYDOWN)
1144 switch (pMsg->wParam)
1146 case VK_F5:
1148 if (m_bBlock)
1149 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1150 Refresh();
1152 break;
1153 case VK_RETURN:
1155 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1157 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1159 PostMessage(WM_COMMAND, IDOK);
1161 return TRUE;
1163 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1165 // Pressing RETURN in the bug id control
1166 // moves the focus to the message
1167 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1168 return TRUE;
1171 break;
1175 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1178 void CCommitDlg::Refresh()
1180 if (m_bThreadRunning)
1181 return;
1183 InterlockedExchange(&m_bBlock, TRUE);
1184 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1185 if (m_pThread==NULL)
1187 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1188 InterlockedExchange(&m_bBlock, FALSE);
1190 else
1192 m_pThread->m_bAutoDelete = FALSE;
1193 m_pThread->ResumeThread();
1197 void CCommitDlg::OnBnClickedHelp()
1199 OnHelp();
1202 void CCommitDlg::OnBnClickedShowunversioned()
1204 m_tooltips.Pop(); // hide the tooltips
1205 UpdateData();
1206 m_regAddBeforeCommit = m_bShowUnversioned;
1207 if (!m_bBlock)
1209 DWORD dwShow = m_ListCtrl.GetShowFlags();
1210 if (DWORD(m_regAddBeforeCommit))
1211 dwShow |= SVNSLC_SHOWUNVERSIONED;
1212 else
1213 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1214 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1216 if(m_bWholeProject)
1217 m_ListCtrl.GetStatus(NULL,false,false,true);
1218 else
1219 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1221 m_ListCtrl.Show(dwShow,0,true,0,true);
1225 void CCommitDlg::OnStnClickedExternalwarning()
1227 m_tooltips.Popup();
1230 void CCommitDlg::OnEnChangeLogmessage()
1232 UpdateOKButton();
1235 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1237 #if 0
1238 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1240 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1242 m_bShowUnversioned = TRUE;
1243 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1244 m_ListCtrl.Show(dwShow);
1245 UpdateData(FALSE);
1248 #endif
1249 return 0;
1252 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1254 Refresh();
1255 return 0;
1258 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1260 #if 0
1261 BringWindowToTop();
1262 SetForegroundWindow();
1263 SetActiveWindow();
1264 // if multiple files/folders are dropped
1265 // this handler is called for every single item
1266 // separately.
1267 // To avoid creating multiple refresh threads and
1268 // causing crashes, we only add the items to the
1269 // list control and start a timer.
1270 // When the timer expires, we start the refresh thread,
1271 // but only if it isn't already running - otherwise we
1272 // restart the timer.
1273 CTGitPath path;
1274 path.SetFromWin((LPCTSTR)lParam);
1276 // just add all the items we get here.
1277 // if the item is versioned, the add will fail but nothing
1278 // more will happen.
1279 Git Git;
1280 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1282 if (!m_ListCtrl.HasPath(path))
1284 if (m_pathList.AreAllPathsFiles())
1286 m_pathList.AddPath(path);
1287 m_pathList.RemoveDuplicates();
1288 m_updatedPathList.AddPath(path);
1289 m_updatedPathList.RemoveDuplicates();
1291 else
1293 // if the path list contains folders, we have to check whether
1294 // our just (maybe) added path is a child of one of those. If it is
1295 // a child of a folder already in the list, we must not add it. Otherwise
1296 // that path could show up twice in the list.
1297 bool bHasParentInList = false;
1298 for (int i=0; i<m_pathList.GetCount(); ++i)
1300 if (m_pathList[i].IsAncestorOf(path))
1302 bHasParentInList = true;
1303 break;
1306 if (!bHasParentInList)
1308 m_pathList.AddPath(path);
1309 m_pathList.RemoveDuplicates();
1310 m_updatedPathList.AddPath(path);
1311 m_updatedPathList.RemoveDuplicates();
1316 // Always start the timer, since the status of an existing item might have changed
1317 SetTimer(REFRESHTIMER, 200, NULL);
1318 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1319 #endif
1320 return 0;
1323 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1325 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1326 return 0;
1329 //////////////////////////////////////////////////////////////////////////
1330 // functions which run in the status thread
1331 //////////////////////////////////////////////////////////////////////////
1333 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1335 CString strLine;
1338 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1339 while (m_bRunThread && file.ReadString(strLine))
1341 int eqpos = strLine.Find('=');
1342 CString rgx;
1343 rgx = strLine.Mid(eqpos+1).Trim();
1345 int pos = -1;
1346 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1348 mapRegex[strLine.Left(pos)] = rgx;
1349 strLine = strLine.Mid(pos+1).Trim();
1351 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1353 file.Close();
1355 catch (CFileException* pE)
1357 TRACE("CFileException loading auto list regex file\n");
1358 pE->Delete();
1359 return;
1362 void CCommitDlg::GetAutocompletionList()
1364 // the auto completion list is made of strings from each selected files.
1365 // the strings used are extracted from the files with regexes found
1366 // in the file "autolist.txt".
1367 // the format of that file is:
1368 // file extensions separated with commas '=' regular expression to use
1369 // example:
1370 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1371 // .cpp = (?<=[^\s]::)\b\w+\b
1373 std::map<CString, CString> mapRegex;
1374 CString sRegexFile = CPathUtils::GetAppDirectory();
1375 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1376 DWORD timeoutvalue = regtimeout*1000;
1377 sRegexFile += _T("autolist.txt");
1378 if (!m_bRunThread)
1379 return;
1380 ParseRegexFile(sRegexFile, mapRegex);
1381 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1382 sRegexFile.ReleaseBuffer();
1383 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1384 if (PathFileExists(sRegexFile))
1386 ParseRegexFile(sRegexFile, mapRegex);
1388 DWORD starttime = GetTickCount();
1390 // now we have two arrays of strings, where the first array contains all
1391 // file extensions we can use and the second the corresponding regex strings
1392 // to apply to those files.
1394 // the next step is to go over all files shown in the commit dialog
1395 // and scan them for strings we can use
1396 int nListItems = m_ListCtrl.GetItemCount();
1398 for (int i=0; i<nListItems && m_bRunThread; ++i)
1400 // stop parsing after timeout
1401 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1402 return;
1404 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1406 if(path == NULL)
1407 continue;
1409 CString sPartPath =path->GetGitPathString();
1410 m_autolist.insert(sPartPath);
1412 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1413 // if (!entry)
1414 // continue;
1416 // add the path parts to the auto completion list too
1417 // CString sPartPath = entry->GetRelativeGitPath();
1418 // m_autolist.insert(sPartPath);
1421 int pos = 0;
1422 int lastPos = 0;
1423 while ((pos = sPartPath.Find('/', pos)) >= 0)
1425 pos++;
1426 lastPos = pos;
1427 m_autolist.insert(sPartPath.Mid(pos));
1430 // Last inserted entry is a file name.
1431 // Some users prefer to also list file name without extension.
1432 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1434 int dotPos = sPartPath.ReverseFind('.');
1435 if ((dotPos >= 0) && (dotPos > lastPos))
1436 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1438 #if 0
1439 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1440 continue;
1442 CString sExt = entry->GetPath().GetFileExtension();
1443 sExt.MakeLower();
1444 // find the regex string which corresponds to the file extension
1445 CString rdata = mapRegex[sExt];
1446 if (rdata.IsEmpty())
1447 continue;
1449 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1450 if ((entry->textstatus != Git_wc_status_unversioned) &&
1451 (entry->textstatus != Git_wc_status_none) &&
1452 (entry->textstatus != Git_wc_status_ignored) &&
1453 (entry->textstatus != Git_wc_status_added) &&
1454 (entry->textstatus != Git_wc_status_normal))
1456 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1457 if (!basePath.IsEmpty())
1458 ScanFile(basePath.GetWinPathString(), rdata);
1460 #endif
1462 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1465 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1467 wstring sFileContent;
1468 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1469 if (hFile != INVALID_HANDLE_VALUE)
1471 DWORD size = GetFileSize(hFile, NULL);
1472 if (size > 1000000L)
1474 // no files bigger than 1 Meg
1475 CloseHandle(hFile);
1476 return;
1478 // allocate memory to hold file contents
1479 char * buffer = new char[size];
1480 DWORD readbytes;
1481 ReadFile(hFile, buffer, size, &readbytes, NULL);
1482 CloseHandle(hFile);
1483 int opts = 0;
1484 IsTextUnicode(buffer, readbytes, &opts);
1485 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1487 delete [] buffer;
1488 return;
1490 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1492 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1494 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1496 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1497 wchar_t * pWideBuf = new wchar_t[ret];
1498 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1499 if (ret2 == ret)
1500 sFileContent = wstring(pWideBuf, ret);
1501 delete [] pWideBuf;
1503 delete [] buffer;
1505 if (sFileContent.empty()|| !m_bRunThread)
1507 return;
1512 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1513 const tr1::wsregex_iterator end;
1514 wstring s = sFileContent;
1515 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1517 const tr1::wsmatch match = *it;
1518 for (size_t i=1; i<match.size(); ++i)
1520 if (match[i].second-match[i].first)
1522 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1523 m_autolist.insert(wstring(match[i]).c_str());
1528 catch (exception) {}
1531 // CSciEditContextMenuInterface
1532 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1534 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1535 m_nPopupPasteListCmd = nCmd++;
1536 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1538 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1539 if(m_History.GetCount() > 0)
1541 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1542 m_nPopupPasteLastMessage = nCmd++;
1543 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1545 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1546 m_nPopupRecentMessage = nCmd++;
1547 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1553 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1556 if (m_bBlock)
1557 return false;
1558 if (cmd == m_nPopupPasteListCmd)
1560 CString logmsg;
1561 int nListItems = m_ListCtrl.GetItemCount();
1562 for (int i=0; i<nListItems; ++i)
1564 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1565 if (entry&&entry->m_Checked)
1567 CString line;
1568 CString status = entry->GetActionName();
1569 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1570 status = _T("Add");
1572 //git_wc_status_kind status = entry->status;
1573 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1574 if (m_ProjectProperties.bFileListInEnglish)
1575 langID = 1033;
1577 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1578 logmsg += line;
1581 pSciEdit->InsertText(logmsg);
1582 return true;
1585 if(cmd == m_nPopupPasteLastMessage)
1587 if(m_History.GetCount() ==0 )
1588 return false;
1590 CString logmsg;
1591 logmsg +=m_History.GetEntry(0);
1592 pSciEdit->InsertText(logmsg);
1593 return true;
1596 if(cmd == m_nPopupRecentMessage )
1598 OnBnClickedHistory();
1599 return true;
1601 return false;
1604 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1606 switch (nIDEvent)
1608 case ENDDIALOGTIMER:
1609 KillTimer(ENDDIALOGTIMER);
1610 EndDialog(0);
1611 break;
1612 case REFRESHTIMER:
1613 if (m_bThreadRunning)
1615 SetTimer(REFRESHTIMER, 200, NULL);
1616 ATLTRACE("Wait some more before refreshing\n");
1618 else
1620 KillTimer(REFRESHTIMER);
1621 ATLTRACE("Refreshing after items dropped\n");
1622 Refresh();
1624 break;
1626 __super::OnTimer(nIDEvent);
1629 void CCommitDlg::OnBnClickedHistory()
1631 m_tooltips.Pop(); // hide the tooltips
1632 if (m_pathList.GetCount() == 0)
1633 return;
1635 CHistoryDlg historyDlg;
1636 historyDlg.SetHistory(m_History);
1637 if (historyDlg.DoModal() != IDOK)
1638 return;
1640 CString sMsg = historyDlg.GetSelectedText();
1641 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1643 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1644 if (!sBugID.IsEmpty())
1646 SetDlgItemText(IDC_BUGID, sBugID);
1648 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1649 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1650 else
1651 m_cLogMessage.SetText(sMsg);
1654 UpdateOKButton();
1655 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1659 void CCommitDlg::OnBnClickedBugtraqbutton()
1661 m_tooltips.Pop(); // hide the tooltips
1662 CString sMsg = m_cLogMessage.GetText();
1664 if (m_BugTraqProvider == NULL)
1665 return;
1667 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1668 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1669 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1671 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1672 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1674 BSTR originalMessage = sMsg.AllocSysString();
1675 BSTR temp = NULL;
1676 // m_revProps.clear();
1678 // first try the IBugTraqProvider2 interface
1679 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1680 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1681 if (SUCCEEDED(hr))
1683 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1684 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1685 BSTR bugIDOut = NULL;
1686 GetDlgItemText(IDC_BUGID, m_sBugID);
1687 BSTR bugID = m_sBugID.AllocSysString();
1688 SAFEARRAY * revPropNames = NULL;
1689 SAFEARRAY * revPropValues = NULL;
1690 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1692 CString sErr;
1693 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1694 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1696 else
1698 if (bugIDOut)
1700 m_sBugID = bugIDOut;
1701 SysFreeString(bugIDOut);
1702 SetDlgItemText(IDC_BUGID, m_sBugID);
1704 SysFreeString(bugID);
1705 SysFreeString(repositoryRoot);
1706 m_cLogMessage.SetText(temp);
1707 BSTR HUGEP *pbRevNames;
1708 BSTR HUGEP *pbRevValues;
1710 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1711 if (SUCCEEDED(hr1))
1713 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1714 if (SUCCEEDED(hr2))
1716 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1718 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1720 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1723 SafeArrayUnaccessData(revPropValues);
1725 SafeArrayUnaccessData(revPropNames);
1727 if (revPropNames)
1728 SafeArrayDestroy(revPropNames);
1729 if (revPropValues)
1730 SafeArrayDestroy(revPropValues);
1733 else
1735 // if IBugTraqProvider2 failed, try IBugTraqProvider
1736 CComPtr<IBugTraqProvider> pProvider = NULL;
1737 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1738 if (FAILED(hr))
1740 CString sErr;
1741 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1742 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1743 return;
1746 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1748 CString sErr;
1749 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1750 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1752 else
1753 m_cLogMessage.SetText(temp);
1755 m_sLogMessage = m_cLogMessage.GetText();
1756 if (!m_ProjectProperties.sMessage.IsEmpty())
1758 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1759 if (!sBugID.IsEmpty())
1761 SetDlgItemText(IDC_BUGID, sBugID);
1765 m_cLogMessage.SetFocus();
1767 SysFreeString(parameters);
1768 SysFreeString(commonRoot);
1769 SafeArrayDestroy(pathList);
1770 SysFreeString(originalMessage);
1771 SysFreeString(temp);
1775 void CCommitDlg::FillPatchView()
1777 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1779 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1781 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1782 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1783 CString cmd,out;
1785 while(pos)
1787 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1788 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1789 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1791 CString head = _T("HEAD");
1792 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1793 head = _T("HEAD~1");
1794 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
1795 g_Git.Run(cmd,&out,CP_ACP);
1799 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1800 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1801 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1804 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1806 this->FillPatchView();
1807 return 0;
1811 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1813 UpdateOKButton();
1814 return 0;
1817 void CCommitDlg::UpdateOKButton()
1819 if (m_bBlock)
1820 return;
1822 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1823 bool bAmendOrSelectFiles = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit);
1825 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFiles);
1828 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1830 switch (message) {
1831 case WM_NOTIFY:
1832 if (wParam == IDC_SPLITTER)
1834 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1835 DoSize(pHdr->delta);
1837 break;
1840 return __super::DefWindowProc(message, wParam, lParam);
1843 void CCommitDlg::SetSplitterRange()
1845 if ((m_ListCtrl)&&(m_cLogMessage))
1847 CRect rcTop;
1848 m_cLogMessage.GetWindowRect(rcTop);
1849 ScreenToClient(rcTop);
1850 CRect rcMiddle;
1851 m_ListCtrl.GetWindowRect(rcMiddle);
1852 ScreenToClient(rcMiddle);
1853 if (rcMiddle.Height() && rcMiddle.Width())
1854 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1858 void CCommitDlg::DoSize(int delta)
1860 RemoveAnchor(IDC_MESSAGEGROUP);
1861 RemoveAnchor(IDC_LOGMESSAGE);
1862 RemoveAnchor(IDC_SPLITTER);
1863 RemoveAnchor(IDC_SIGNOFF);
1864 RemoveAnchor(IDC_COMMIT_AMEND);
1865 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1866 RemoveAnchor(IDC_COMMIT_SETDATETIME);
1867 RemoveAnchor(IDC_COMMIT_DATEPICKER);
1868 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
1869 RemoveAnchor(IDC_LISTGROUP);
1870 RemoveAnchor(IDC_FILELIST);
1871 RemoveAnchor(IDC_TEXT_INFO);
1873 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1874 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1875 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1876 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1877 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1878 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1879 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1880 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
1881 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
1882 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
1883 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1885 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1886 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1887 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1888 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1889 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1890 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1891 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1892 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1893 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
1894 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
1895 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
1896 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1897 ArrangeLayout();
1898 // adjust the minimum size of the dialog to prevent the resizing from
1899 // moving the list control too far down.
1900 CRect rcLogMsg;
1901 m_cLogMessage.GetClientRect(rcLogMsg);
1902 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1904 SetSplitterRange();
1905 m_cLogMessage.Invalidate();
1906 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1909 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1911 // first, let the resizing take place
1912 __super::OnSize(nType, cx, cy);
1914 //set range
1915 SetSplitterRange();
1918 CString CCommitDlg::GetSignedOffByLine()
1920 CString str;
1922 CString username = g_Git.GetUserName();
1923 CString email = g_Git.GetUserEmail();
1924 username.Remove(_T('\n'));
1925 email.Remove(_T('\n'));
1927 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
1929 return str;
1932 void CCommitDlg::OnBnClickedSignOff()
1934 CString str = GetSignedOffByLine();
1936 if (m_cLogMessage.GetText().Find(str) == -1) {
1937 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1938 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1939 int foundByLine = -1;
1940 if (lastNewline > 0)
1941 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1943 if (foundByLine == -1 || foundByLine < lastNewline)
1944 str = _T("\r\n") + str;
1946 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1950 void CCommitDlg::OnBnClickedCommitAmend()
1952 this->UpdateData();
1953 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1955 GitRev rev;
1956 rev.GetCommit(CString(_T("HEAD")));
1957 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
1960 if(this->m_bCommitAmend)
1962 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1963 m_cLogMessage.SetText(m_AmendStr);
1964 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1966 else
1968 this->m_AmendStr=this->m_cLogMessage.GetText();
1969 m_cLogMessage.SetText(m_NoAmendStr);
1970 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1973 OnBnClickedCommitSetDateTime(); // to update the commit date and time
1975 Refresh();
1978 void CCommitDlg::OnBnClickedWholeProject()
1980 m_tooltips.Pop(); // hide the tooltips
1981 UpdateData();
1982 m_ListCtrl.Clear();
1983 if (!m_bBlock)
1985 if(m_bWholeProject)
1986 m_ListCtrl.GetStatus(NULL,true,false,true);
1987 else
1988 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1990 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
1991 m_ListCtrl.Show(m_ListCtrl.GetShowFlags(), dwShow & (~CTGitPath::LOGACTIONS_UNVER|~CTGitPath::LOGACTIONS_IGNORE));
1994 SetDlgTitle();
1997 void CCommitDlg::OnFocusMessage()
1999 m_cLogMessage.SetFocus();
2002 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
2004 UNREFERENCED_PARAMETER(pNMHDR);
2005 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2006 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2007 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2009 CString str;
2010 str.Format(_T("%d/%d"),line+1,column+1);
2011 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2013 if(*pResult)
2014 *pResult=0;
2016 void CCommitDlg::OnStnClickedViewPatch()
2018 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2019 m_patchViewdlg.m_ParentCommitDlg = this;
2020 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2022 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2023 CRect rect;
2024 this->GetWindowRect(&rect);
2026 m_patchViewdlg.ShowWindow(SW_SHOW);
2028 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2029 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2031 ShowViewPatchText(false);
2032 FillPatchView();
2034 else
2036 m_patchViewdlg.ShowWindow(SW_HIDE);
2037 m_patchViewdlg.DestroyWindow();
2038 ShowViewPatchText(true);
2040 this->m_ctrlShowPatch.Invalidate();
2043 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2045 __super::OnMoving(fwSide, pRect);
2047 if (::IsWindow(m_patchViewdlg.m_hWnd))
2049 RECT patchrect;
2050 m_patchViewdlg.GetWindowRect(&patchrect);
2051 if (::IsWindow(m_hWnd))
2053 RECT thisrect;
2054 GetWindowRect(&thisrect);
2055 if (patchrect.left == thisrect.right)
2057 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2058 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2065 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2067 __super::OnSizing(fwSide, pRect);
2069 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2071 CRect thisrect, patchrect;
2072 this->GetWindowRect(thisrect);
2073 this->m_patchViewdlg.GetWindowRect(patchrect);
2074 if(thisrect.right==patchrect.left)
2076 patchrect.left -= (thisrect.right - pRect->right);
2077 patchrect.right-= (thisrect.right - pRect->right);
2079 if( patchrect.bottom == thisrect.bottom)
2081 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2083 if( patchrect.top == thisrect.top)
2085 patchrect.top -= thisrect.top-pRect->top;
2087 m_patchViewdlg.MoveWindow(patchrect);
2092 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2094 UNREFERENCED_PARAMETER(pNMHDR);
2095 *pResult = 0;
2096 TRACE("Item Changed\r\n");
2099 int CCommitDlg::CheckHeadDetach()
2101 CString output;
2102 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2104 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2105 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2107 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2110 return 0;
2113 void CCommitDlg::OnBnClickedCommitAmenddiff()
2115 UpdateData();
2116 Refresh();
2119 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2121 UpdateData();
2122 Refresh();
2125 void CCommitDlg::OnBnClickedCommitSetDateTime()
2127 UpdateData();
2129 if (m_bSetCommitDateTime)
2131 CTime authordate = CTime::GetCurrentTime();
2132 if (m_bCommitAmend)
2134 GitRev headRevision;
2135 headRevision.GetCommit(_T("HEAD"));
2136 authordate = headRevision.GetAuthorDate();
2139 m_CommitDate.SetTime(&authordate);
2140 m_CommitTime.SetTime(&authordate);
2142 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2143 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2145 else
2147 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2148 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);