Fixed issue #1303: Past Recent Message command in commit dialog doesn't work
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blobe166bd849695c42c48ef8bdfa30b31b31def24f5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 "UnicodeUtils.h"
35 #include "../TGitCache/CacheInterface.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"
42 #include "SysProgressDlg.h"
43 #include "MassiveGitTask.h"
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
51 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
53 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
54 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
55 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
56 , m_bRecursive(FALSE)
57 , m_bShowUnversioned(FALSE)
58 , m_bBlock(FALSE)
59 , m_bThreadRunning(FALSE)
60 , m_bRunThread(FALSE)
61 , m_pThread(NULL)
62 , m_bWholeProject(FALSE)
63 , m_bKeepChangeList(TRUE)
64 , m_bDoNotAutoselectSubmodules(FALSE)
65 , m_itemsCount(0)
66 , m_bSelectFilesForCommit(TRUE)
67 , m_bNoPostActions(FALSE)
68 , m_bAutoClose(false)
69 , m_bSetCommitDateTime(FALSE)
70 , m_bCreateNewBranch(FALSE)
71 , m_bCreateTagAfterCommit(FALSE)
72 , m_bForceCommitAmend(false)
74 this->m_bCommitAmend=FALSE;
75 m_bPushAfterCommit = FALSE;
78 CCommitDlg::~CCommitDlg()
80 if(m_pThread != NULL)
82 delete m_pThread;
86 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
88 CResizableStandAloneDialog::DoDataExchange(pDX);
89 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
90 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
91 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
92 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
93 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
94 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
95 DDX_Text(pDX, IDC_BUGID, m_sBugID);
96 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
97 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
98 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
99 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
100 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
101 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
102 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
103 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
104 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
107 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
108 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
109 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
110 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
111 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
112 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
113 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
114 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
115 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
116 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
117 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
118 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
120 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
121 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
122 ON_WM_TIMER()
123 ON_WM_SIZE()
124 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
125 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
126 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
127 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
128 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
129 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
130 ON_WM_MOVE()
131 ON_WM_MOVING()
132 ON_WM_SIZING()
133 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
134 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
135 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
136 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
137 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
138 END_MESSAGE_MAP()
140 BOOL CCommitDlg::OnInitDialog()
142 CResizableStandAloneDialog::OnInitDialog();
143 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
145 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
147 CString dotGitPath;
148 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
149 if(PathFileExists(dotGitPath + _T("MERGE_MSG")))
151 CStdioFile file;
152 if(file.Open(dotGitPath + _T("MERGE_MSG"), CFile::modeRead))
154 CString str;
155 while(file.ReadString(str))
157 m_sLogMessage += str;
158 str.Empty();
159 m_sLogMessage += _T("\n");
164 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
165 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
167 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
168 m_bShowUnversioned = m_regAddBeforeCommit;
170 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
172 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
173 m_bKeepChangeList = m_regKeepChangelists;
175 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
176 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
178 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
180 // GitConfig config;
181 // m_bWholeProject = config.KeepLocks();
183 if(this->m_pathList.GetCount() == 0)
184 m_bWholeProject =true;
186 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
187 m_bWholeProject =true;
189 SetDlgTitle();
191 UpdateData(FALSE);
193 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)), true, true);
194 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
195 m_ListCtrl.SetCancelBool(&m_bCancelled);
196 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
197 m_ListCtrl.EnableFileDrop();
198 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
200 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
201 m_ProjectProperties.ReadPropsPathList(m_pathList);
203 m_cLogMessage.Init(m_ProjectProperties);
204 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
205 m_cLogMessage.RegisterContextMenuHandler(this);
207 OnEnChangeLogmessage();
209 m_tooltips.Create(this);
210 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
211 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
212 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
214 CBugTraqAssociations bugtraq_associations;
215 bugtraq_associations.Load();
217 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
219 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
220 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
222 CComPtr<IBugTraqProvider> pProvider;
223 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
224 if (SUCCEEDED(hr))
226 m_BugTraqProvider = pProvider;
227 BSTR temp = NULL;
228 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
230 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
231 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
232 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
235 SysFreeString(temp);
238 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
240 else if (!m_ProjectProperties.sMessage.IsEmpty())
242 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
243 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
244 if (!m_ProjectProperties.sLabel.IsEmpty())
245 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
246 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
247 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
248 GetDlgItem(IDC_BUGID)->SetFocus();
249 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
250 if (!sBugID.IsEmpty())
252 SetDlgItemText(IDC_BUGID, sBugID);
255 else
257 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
258 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
259 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
260 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
261 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
264 if (!m_sLogMessage.IsEmpty())
265 m_cLogMessage.SetText(m_sLogMessage);
267 GetWindowText(m_sWindowTitle);
269 AdjustControlSize(IDC_SHOWUNVERSIONED);
270 AdjustControlSize(IDC_WHOLE_PROJECT);
271 AdjustControlSize(IDC_CHECK_NEWBRANCH);
272 AdjustControlSize(IDC_COMMIT_AMEND);
273 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
274 AdjustControlSize(IDC_COMMIT_SETDATETIME);
275 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
276 AdjustControlSize(IDC_KEEPLISTS);
278 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKALL);
279 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKNONE);
280 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKUNVERSIONED);
281 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKVERSIONED);
282 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKADDED);
283 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKDELETED);
284 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKMODIFIED);
285 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKFILES);
286 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKSUBMODULES);
288 // line up all controls and adjust their sizes.
289 #define LINKSPACING 9
290 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
291 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
292 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
293 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
294 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
295 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
296 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
297 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
298 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
299 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
300 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
302 GetClientRect(m_DlgOrigRect);
303 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
305 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
306 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
307 AddAnchor(IDC_BUGID, TOP_RIGHT);
308 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
309 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
310 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
311 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
312 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
313 // AddAnchor(IDC_HISTORY, TOP_LEFT);
314 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
315 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
316 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
317 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
318 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
319 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
320 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
321 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
322 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
323 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
324 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
325 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
326 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
327 AddAnchor(IDOK, BOTTOM_RIGHT);
328 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
329 AddAnchor(IDHELP, BOTTOM_RIGHT);
330 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
331 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
332 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
333 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
334 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
336 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
337 AddAnchor(IDC_CHECKALL, TOP_LEFT);
338 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
339 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
340 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
341 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
342 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
343 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
344 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
345 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
347 if (hWndExplorer)
348 CenterWindow(CWnd::FromHandle(hWndExplorer));
349 EnableSaveRestore(_T("CommitDlg"));
350 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
351 RECT rcDlg, rcLogMsg, rcFileList;
352 GetClientRect(&rcDlg);
353 m_cLogMessage.GetWindowRect(&rcLogMsg);
354 ScreenToClient(&rcLogMsg);
355 m_ListCtrl.GetWindowRect(&rcFileList);
356 ScreenToClient(&rcFileList);
357 if (yPos)
359 RECT rectSplitter;
360 m_wndSplitter.GetWindowRect(&rectSplitter);
361 ScreenToClient(&rectSplitter);
362 int delta = yPos - rectSplitter.top;
363 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
365 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
366 DoSize(delta);
370 // add all directories to the watcher
372 for (int i=0; i<m_pathList.GetCount(); ++i)
374 if (m_pathList[i].IsDirectory())
375 m_pathwatcher.AddPath(m_pathList[i]);
378 m_updatedPathList = m_pathList;
380 //first start a thread to obtain the file list with the status without
381 //blocking the dialog
382 InterlockedExchange(&m_bBlock, TRUE);
383 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
384 if (m_pThread==NULL)
386 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
387 InterlockedExchange(&m_bBlock, FALSE);
389 else
391 m_pThread->m_bAutoDelete = FALSE;
392 m_pThread->ResumeThread();
394 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
395 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
396 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
398 historyhint = TRUE;
399 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
401 err = FALSE;
403 this->m_ctrlShowPatch.SetURL(CString());
405 BOOL viewPatchEnabled = FALSE;
406 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
407 if (viewPatchEnabled)
408 OnStnClickedViewPatch();
410 return FALSE; // return TRUE unless you set the focus to a control
411 // EXCEPTION: OCX Property Pages should return FALSE
414 void CCommitDlg::OnOK()
416 if (m_bBlock)
417 return;
418 if (m_bThreadRunning)
420 m_bCancelled = true;
421 InterlockedExchange(&m_bRunThread, FALSE);
422 WaitForSingleObject(m_pThread->m_hThread, 1000);
423 if (m_bThreadRunning)
425 // we gave the thread a chance to quit. Since the thread didn't
426 // listen to us we have to kill it.
427 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
428 InterlockedExchange(&m_bThreadRunning, FALSE);
431 this->UpdateData();
433 if (m_bCreateNewBranch)
435 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
437 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
438 return;
440 if (g_Git.BranchTagExists(m_sCreateNewBranch))
442 // branch already exists
443 CString msg;
444 msg.LoadString(IDS_B_EXISTS);
445 msg += _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
446 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
447 return;
449 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
451 // tag with the same name exists -> shortref is ambiguous
452 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
453 return;
457 CString id;
458 GetDlgItemText(IDC_BUGID, id);
459 if (!m_ProjectProperties.CheckBugID(id))
461 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
462 return;
464 m_sLogMessage = m_cLogMessage.GetText();
465 if ( m_sLogMessage.IsEmpty() )
467 // no message entered, go round again
468 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
469 return;
471 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
473 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
474 return;
477 BOOL bWarnNoSignedOffBy = FALSE;
478 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
479 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
481 UINT retval = CMessageBox::Show(this->m_hWnd, IDS_PROC_COMMIT_NOSIGNOFFLINE, IDS_APPNAME, 1, IDI_WARNING, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON, IDS_ABORTBUTTON);
482 if (retval == 1)
484 OnBnClickedSignOff();
485 m_sLogMessage = m_cLogMessage.GetText();
487 else if (retval == 3)
488 return;
491 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
492 m_pathwatcher.Stop();
493 InterlockedExchange(&m_bBlock, TRUE);
494 CDWordArray arDeleted;
495 //first add all the unversioned files the user selected
496 //and check if all versioned files are selected
497 int nchecked = 0;
498 m_bRecursive = true;
499 int nListItems = m_ListCtrl.GetItemCount();
501 CTGitPathList itemsToAdd;
502 CTGitPathList itemsToRemove;
503 CMassiveGitTask mgtReAddAfterCommit(_T("add --ignore-errors -f"));
504 //std::set<CString> checkedLists;
505 //std::set<CString> uncheckedLists;
507 //CString checkedfiles;
508 //CString uncheckedfiles;
510 CString cmd;
511 CString out;
513 bool bAddSuccess=true;
514 bool bCloseCommitDlg=false;
516 CSysProgressDlg sysProgressDlg;
517 if (nListItems >= 25 && sysProgressDlg.IsValid())
519 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
520 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
521 sysProgressDlg.SetTime(true);
522 sysProgressDlg.SetShowProgressBar(true);
523 sysProgressDlg.ShowModal(this, true);
526 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
527 DWORD currentTicks = GetTickCount();
529 for (int j=0; j<nListItems; j++)
531 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
532 if (sysProgressDlg.IsValid())
534 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
536 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
537 sysProgressDlg.SetProgress(j, nListItems);
538 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
539 currentTicks = GetTickCount();
542 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
543 if (entry->m_Checked)
545 #if 0
546 if (entry->status == Git_wc_status_unversioned)
548 itemsToAdd.AddPath(entry->GetPath());
550 if (entry->status == Git_wc_status_conflicted)
552 bHasConflicted = true;
554 if (entry->status == Git_wc_status_missing)
556 itemsToRemove.AddPath(entry->GetPath());
558 if (entry->status == Git_wc_status_deleted)
560 arDeleted.Add(j);
562 if (entry->IsInExternal())
564 bCheckedInExternal = true;
566 #endif
567 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
568 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
569 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
570 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
571 else
572 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
574 if (g_Git.Run(cmd, &out, CP_UTF8))
576 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
577 bAddSuccess = false ;
578 break;
581 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
582 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
584 g_Git.Run(cmd, &out, CP_UTF8);
586 nchecked++;
588 //checkedLists.insert(entry->GetGitPathString());
589 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
591 else
593 //uncheckedLists.insert(entry->GetGitPathString());
594 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
595 { //To init git repository, there are not HEAD, so we can use git reset command
596 cmd.Format(_T("git.exe rm -f --cache -- \"%s\""),entry->GetGitPathString());
597 if (g_Git.Run(cmd, &out, CP_UTF8))
599 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
600 bAddSuccess = false ;
601 bCloseCommitDlg=false;
602 break;
604 mgtReAddAfterCommit.AddFile(*entry);
606 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
608 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
610 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
612 else
614 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
616 if (g_Git.Run(cmd, &out, CP_UTF8))
618 /* when reset a unstage file will report error.
619 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
620 bAddSuccess = false ;
621 bCloseCommitDlg=false;
622 break;
625 // && !entry->IsDirectory()
626 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
627 continue;
630 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
631 #if 0
632 if ((entry->status != Git_wc_status_unversioned) &&
633 (entry->status != Git_wc_status_ignored))
635 nUnchecked++;
636 uncheckedLists.insert(entry->GetChangeList());
637 if (m_bRecursive)
639 // This algorithm is for the sake of simplicity of the complexity O(N?
640 for (int k=0; k<nListItems; k++)
642 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
643 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
645 // Fall back to a non-recursive commit to prevent items being
646 // committed which aren't checked although its parent is checked
647 // (property change, directory deletion, ... )
648 m_bRecursive = false;
649 break;
654 #endif
657 if (sysProgressDlg.IsValid() && sysProgressDlg.HasUserCancelled())
659 bAddSuccess = false;
660 break;
663 CShellUpdater::Instance().AddPathForUpdate(*entry);
666 if (sysProgressDlg.IsValid())
667 sysProgressDlg.Stop();
669 if (bAddSuccess && m_bCreateNewBranch)
671 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_UTF8))
673 MessageBox(_T("Creating new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
674 bAddSuccess = false;
676 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_UTF8))
678 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
679 bAddSuccess = false;
683 if (bAddSuccess && CheckHeadDetach())
684 bAddSuccess = false;
686 //if(uncheckedfiles.GetLength()>0)
688 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
689 // g_Git.Run(cmd,&out);
692 m_sBugID.Trim();
693 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
694 sExistingBugID.Trim();
695 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
697 m_sBugID.Replace(_T(", "), _T(","));
698 m_sBugID.Replace(_T(" ,"), _T(","));
699 CString sBugID = m_ProjectProperties.sMessage;
700 sBugID.Replace(_T("%BUGID%"), m_sBugID);
701 if (m_ProjectProperties.bAppend)
702 m_sLogMessage += _T("\n") + sBugID + _T("\n");
703 else
704 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
707 // now let the bugtraq plugin check the commit message
708 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
709 if (m_BugTraqProvider)
711 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
712 if (SUCCEEDED(hr))
714 BSTR temp = NULL;
715 CString common = g_Git.m_CurrentDir;
716 BSTR repositoryRoot = common.AllocSysString();
717 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
718 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
719 BSTR commitMessage = m_sLogMessage.AllocSysString();
720 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
722 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
723 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
725 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
727 COMError ce(hr);
728 CString sErr;
729 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
730 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
732 else
734 CString sError = temp;
735 if (!sError.IsEmpty())
737 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
738 return;
740 SysFreeString(temp);
745 //if(checkedfiles.GetLength()>0)
746 if (bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
748 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
749 // g_Git.Run(cmd,&out);
751 bCloseCommitDlg = true;
753 CString tempfile=::GetTempFile();
755 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
756 //file.WriteString(m_sLogMessage);
758 CTGitPath path=g_Git.m_CurrentDir;
760 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
762 out =_T("");
763 CString amend;
764 if(this->m_bCommitAmend)
766 amend=_T("--amend");
768 CString dateTime;
769 if (m_bSetCommitDateTime)
771 CTime date, time;
772 m_CommitDate.GetTime(date);
773 m_CommitTime.GetTime(time);
774 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
776 cmd.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime, amend, tempfile);
778 CCommitProgressDlg progress;
779 progress.m_bBufferAll=true; // improve show speed when there are many file added.
780 progress.m_GitCmd=cmd;
781 progress.m_bShowCommand = FALSE; // don't show the commit command
782 progress.m_PreText = out; // show any output already generated in log window
783 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
785 int indexReCommit = -1;
786 int indexTag = -1;
788 if (!m_bNoPostActions && !m_bAutoClose)
790 if (IsGitSVN)
791 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT)));
792 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH)));
793 indexReCommit = progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT)));
794 indexTag = progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG)));
797 DWORD userResponse = progress.DoModal();
799 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1 + indexReCommit))
801 bCloseCommitDlg = false;
802 if (userResponse == IDC_PROGRESS_BUTTON1 + indexReCommit)
804 this->m_sLogMessage.Empty();
805 m_cLogMessage.SetText(m_sLogMessage);
808 m_bCommitAmend = FALSE;
809 UpdateData(FALSE);
810 this->Refresh();
812 else if (userResponse == IDC_PROGRESS_BUTTON1 + indexTag)
814 m_bCreateTagAfterCommit=true;
816 else if (userResponse >= IDC_PROGRESS_BUTTON1 && userResponse < IDC_PROGRESS_BUTTON1 + indexReCommit)
818 // User pressed 'DCommit' or 'Push' button after successful commit.
819 m_bPushAfterCommit=true;
820 if (userResponse == IDC_PROGRESS_BUTTON1 && IsGitSVN)
821 m_PostCmd = GIT_POST_CMD_DCOMMIT;
822 else
823 m_PostCmd = GIT_POST_CMD_PUSH;
826 CFile::Remove(tempfile);
828 if (m_BugTraqProvider && progress.m_GitStatus == 0)
830 CComPtr<IBugTraqProvider2> pProvider = NULL;
831 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
832 if (SUCCEEDED(hr))
834 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
835 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
837 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
838 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
840 BSTR logMessage = m_sLogMessage.AllocSysString();
842 CGitHash hash=g_Git.GetHash(_T("HEAD"));
843 LONG version = g_Git.Hash2int(hash);
845 BSTR temp = NULL;
846 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
847 commonRoot,
848 pathList,
849 logMessage,
850 (LONG)version,
851 &temp)))
853 CString sErr = temp;
854 if (!sErr.IsEmpty())
855 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
856 else
858 COMError ce(hr);
859 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
860 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
864 SysFreeString(temp);
867 RestoreFiles(progress.m_GitStatus == 0);
868 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE)) == TRUE)
870 BOOL cancel;
871 mgtReAddAfterCommit.Execute(cancel);
874 else if(bAddSuccess)
876 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
877 bCloseCommitDlg=false;
879 #if 0
880 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
882 // There are paths which got changed (touched at least).
883 // We have to find out if this affects the selection in the commit dialog
884 // If it could affect the selection, revert back to a non-recursive commit
885 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
886 changedList.RemoveDuplicates();
887 for (int i=0; i<changedList.GetCount(); ++i)
889 if (changedList[i].IsAdminDir())
891 // something inside an admin dir was changed.
892 // if it's the entries file, then we have to fully refresh because
893 // files may have been added/removed from version control
894 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
895 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
897 m_bRecursive = false;
898 break;
901 else if (!m_ListCtrl.IsPathShown(changedList[i]))
903 // a path which is not shown in the list has changed
904 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
905 if (entry)
907 // check if the changed path would get committed by a recursive commit
908 if ((!entry->IsFromDifferentRepository()) &&
909 (!entry->IsInExternal()) &&
910 (!entry->IsNested()) &&
911 (!entry->IsChecked()))
913 m_bRecursive = false;
914 break;
922 // Now, do all the adds - make sure that the list is sorted so that parents
923 // are added before their children
924 itemsToAdd.SortByPathname();
925 Git Git;
926 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
928 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
929 InterlockedExchange(&m_bBlock, FALSE);
930 Refresh();
931 return;
934 // Remove any missing items
935 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
936 itemsToRemove.SortByPathname();
937 Git.Remove(itemsToRemove, TRUE);
939 //the next step: find all deleted files and check if they're
940 //inside a deleted folder. If that's the case, then remove those
941 //files from the list since they'll get deleted by the parent
942 //folder automatically.
943 m_ListCtrl.Block(TRUE, FALSE);
944 INT_PTR nDeleted = arDeleted.GetCount();
945 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
947 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
949 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
950 if (path.IsDirectory())
952 //now find all children of this directory
953 for (int j=0; j<arDeleted.GetCount(); j++)
955 if (i!=j)
957 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
958 if (childEntry->IsChecked())
960 if (path.IsAncestorOf(childEntry->GetPath()))
962 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
963 nDeleted--;
971 m_ListCtrl.Block(FALSE, FALSE);
973 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
975 //save only the files the user has checked into the temporary file
976 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
979 // the item count is used in the progress dialog to show the overall commit
980 // progress.
981 // deleted items only send one notification event, all others send two
982 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
984 if ((m_bRecursive)&&(checkedLists.size() == 1))
986 // all checked items belong to the same changelist
987 // find out if there are any unchecked items which belong to that changelist
988 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
989 m_sChangeList = *checkedLists.begin();
991 #endif
992 UpdateData();
993 m_regAddBeforeCommit = m_bShowUnversioned;
994 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
995 m_bWholeProject = FALSE;
996 m_regKeepChangelists = m_bKeepChangeList;
997 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
998 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
999 m_bKeepChangeList = FALSE;
1000 InterlockedExchange(&m_bBlock, FALSE);
1002 m_History.AddEntry(m_sLogMessage);
1003 m_History.Save();
1005 SaveSplitterPos();
1007 if( bCloseCommitDlg )
1008 CResizableStandAloneDialog::OnOK();
1010 CShellUpdater::Instance().Flush();
1013 void CCommitDlg::SaveSplitterPos()
1015 if (!IsIconic())
1017 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1018 RECT rectSplitter;
1019 m_wndSplitter.GetWindowRect(&rectSplitter);
1020 ScreenToClient(&rectSplitter);
1021 regPos = rectSplitter.top;
1025 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1027 return ((CCommitDlg*)pVoid)->StatusThread();
1030 UINT CCommitDlg::StatusThread()
1032 //get the status of all selected file/folders recursively
1033 //and show the ones which have to be committed to the user
1034 //in a list control.
1035 InterlockedExchange(&m_bBlock, TRUE);
1036 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1037 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1039 m_pathwatcher.Stop();
1041 g_Git.RefreshGitIndex();
1043 m_bCancelled = false;
1045 DialogEnableWindow(IDOK, false);
1046 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1047 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1048 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1049 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1050 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1051 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1052 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1053 // read the list of recent log entries before querying the WC for status
1054 // -> the user may select one and modify / update it while we are crawling the WC
1056 DialogEnableWindow(IDC_CHECKALL, false);
1057 DialogEnableWindow(IDC_CHECKNONE, false);
1058 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1059 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1060 DialogEnableWindow(IDC_CHECKADDED, false);
1061 DialogEnableWindow(IDC_CHECKDELETED, false);
1062 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1063 DialogEnableWindow(IDC_CHECKFILES, false);
1064 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1066 if (m_History.GetCount()==0)
1068 CString reg;
1069 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
1070 reg.Replace(_T(':'),_T('_'));
1071 m_History.Load(reg, _T("logmsgs"));
1074 // Initialise the list control with the status of the files/folders below us
1075 m_ListCtrl.Clear();
1076 BOOL success;
1077 CTGitPathList *pList;
1078 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
1079 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1081 if(m_bWholeProject)
1082 pList=NULL;
1083 else
1084 pList = &m_pathList;
1086 success=m_ListCtrl.GetStatus(pList);
1088 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1089 if(this->m_bShowUnversioned)
1090 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1092 m_ListCtrl.CheckIfChangelistsArePresent(false);
1094 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST;
1095 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1096 if (success)
1098 if (m_checkedPathList.GetCount())
1099 m_ListCtrl.Show(dwShow, m_checkedPathList);
1100 else
1102 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1103 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1104 m_ListCtrl.Show(dwShow, dwCheck);
1105 m_bSelectFilesForCommit = true;
1108 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1110 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1111 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1114 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1115 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1117 if (!success)
1119 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1120 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1121 m_ListCtrl.Show(dwShow);
1124 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1125 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
1127 CString temp;
1128 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1129 if (CMessageBox::ShowCheck(m_hWnd, temp, _T("TortoiseGit"), MB_ICONINFORMATION | MB_YESNO, _T("NothingToCommitShowUnversioned"), NULL)==IDYES)
1131 m_bShowUnversioned = TRUE;
1132 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1133 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1134 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1135 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1139 SetDlgTitle();
1141 m_autolist.clear();
1142 // we don't have to block the commit dialog while we fetch the
1143 // auto completion list.
1144 m_pathwatcher.ClearChangedPaths();
1145 InterlockedExchange(&m_bBlock, FALSE);
1146 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1148 m_ListCtrl.Block(TRUE, TRUE);
1149 GetAutocompletionList();
1150 m_ListCtrl.Block(FALSE, FALSE);
1152 UpdateOKButton();
1153 if (m_bRunThread)
1155 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1156 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1157 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1158 if (m_ListCtrl.HasChangeLists())
1159 DialogEnableWindow(IDC_KEEPLISTS, true);
1160 if (m_ListCtrl.HasLocks())
1161 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1163 // activate amend checkbox (if necessary)
1164 if (g_Git.IsInitRepos())
1166 m_bCommitAmend = FALSE;
1167 UpdateData(FALSE);
1169 else
1171 if (m_bForceCommitAmend)
1173 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1174 m_bCommitAmend = TRUE;
1175 UpdateData(FALSE);
1177 else
1178 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(TRUE);
1180 CGitHash hash;
1183 hash = g_Git.GetHash(_T("HEAD"));
1185 catch (char* msg)
1187 CString err(msg);
1188 MessageBox(_T("Could not get HEAD hash.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1190 if (!hash.IsEmpty())
1192 GitRev headRevision;
1195 headRevision.GetParentFromHash(hash);
1197 catch (char* msg)
1199 CString err(msg);
1200 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1202 // do not allow to show diff to "last" revision if it has more that one parent
1203 if (headRevision.ParentsCount() != 1)
1205 m_bAmendDiffToLastCommit = true;
1206 UpdateData(FALSE);
1208 else
1209 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1213 UpdateCheckLinks();
1215 // we have the list, now signal the main thread about it
1216 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1219 InterlockedExchange(&m_bRunThread, FALSE);
1220 InterlockedExchange(&m_bThreadRunning, FALSE);
1221 // force the cursor to normal
1222 RefreshCursor();
1224 return 0;
1227 void CCommitDlg::SetDlgTitle()
1229 if (m_sTitle.IsEmpty())
1230 GetWindowText(m_sTitle);
1232 if (m_bWholeProject)
1233 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1234 else
1236 if (m_pathList.GetCount() == 1)
1237 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1238 else
1239 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1243 void CCommitDlg::OnCancel()
1245 m_bCancelled = true;
1246 m_pathwatcher.Stop();
1248 if (m_bThreadRunning)
1250 InterlockedExchange(&m_bRunThread, FALSE);
1251 WaitForSingleObject(m_pThread->m_hThread, 1000);
1252 if (m_bThreadRunning)
1254 // we gave the thread a chance to quit. Since the thread didn't
1255 // listen to us we have to kill it.
1256 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1257 InterlockedExchange(&m_bThreadRunning, FALSE);
1260 UpdateData();
1261 m_sBugID.Trim();
1262 m_sLogMessage = m_cLogMessage.GetText();
1263 if (!m_sBugID.IsEmpty())
1265 m_sBugID.Replace(_T(", "), _T(","));
1266 m_sBugID.Replace(_T(" ,"), _T(","));
1267 CString sBugID = m_ProjectProperties.sMessage;
1268 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1269 if (m_ProjectProperties.bAppend)
1270 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1271 else
1272 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1274 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1275 m_History.AddEntry(m_sLogMessage);
1276 m_History.Save();
1277 RestoreFiles();
1278 SaveSplitterPos();
1279 CResizableStandAloneDialog::OnCancel();
1282 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1284 if (!m_bBlock)
1285 m_tooltips.RelayEvent(pMsg);
1287 if (m_hAccel)
1289 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1290 if (ret)
1291 return TRUE;
1294 if (pMsg->message == WM_KEYDOWN)
1296 switch (pMsg->wParam)
1298 case VK_F5:
1300 if (m_bBlock)
1301 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1302 Refresh();
1304 break;
1305 case VK_RETURN:
1307 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1309 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1311 PostMessage(WM_COMMAND, IDOK);
1313 return TRUE;
1315 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1317 // Pressing RETURN in the bug id control
1318 // moves the focus to the message
1319 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1320 return TRUE;
1323 break;
1327 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1330 void CCommitDlg::Refresh()
1332 if (m_bThreadRunning)
1333 return;
1335 InterlockedExchange(&m_bBlock, TRUE);
1336 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1337 if (m_pThread==NULL)
1339 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1340 InterlockedExchange(&m_bBlock, FALSE);
1342 else
1344 m_pThread->m_bAutoDelete = FALSE;
1345 m_pThread->ResumeThread();
1349 void CCommitDlg::OnBnClickedHelp()
1351 OnHelp();
1354 void CCommitDlg::OnBnClickedShowunversioned()
1356 m_tooltips.Pop(); // hide the tooltips
1357 UpdateData();
1358 m_regAddBeforeCommit = m_bShowUnversioned;
1359 if (!m_bBlock)
1361 DWORD dwShow = m_ListCtrl.GetShowFlags();
1362 if (DWORD(m_regAddBeforeCommit))
1363 dwShow |= GITSLC_SHOWUNVERSIONED;
1364 else
1365 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1366 if(dwShow & GITSLC_SHOWUNVERSIONED)
1368 if(m_bWholeProject)
1369 m_ListCtrl.GetStatus(NULL,false,false,true);
1370 else
1371 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1373 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1374 UpdateCheckLinks();
1378 void CCommitDlg::OnStnClickedExternalwarning()
1380 m_tooltips.Popup();
1383 void CCommitDlg::OnEnChangeLogmessage()
1385 UpdateOKButton();
1388 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1390 #if 0
1391 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1393 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1395 m_bShowUnversioned = TRUE;
1396 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1397 m_ListCtrl.Show(dwShow);
1398 UpdateData(FALSE);
1401 #endif
1402 return 0;
1405 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1407 Refresh();
1408 return 0;
1411 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1413 #if 0
1414 BringWindowToTop();
1415 SetForegroundWindow();
1416 SetActiveWindow();
1417 // if multiple files/folders are dropped
1418 // this handler is called for every single item
1419 // separately.
1420 // To avoid creating multiple refresh threads and
1421 // causing crashes, we only add the items to the
1422 // list control and start a timer.
1423 // When the timer expires, we start the refresh thread,
1424 // but only if it isn't already running - otherwise we
1425 // restart the timer.
1426 CTGitPath path;
1427 path.SetFromWin((LPCTSTR)lParam);
1429 // just add all the items we get here.
1430 // if the item is versioned, the add will fail but nothing
1431 // more will happen.
1432 Git Git;
1433 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1435 if (!m_ListCtrl.HasPath(path))
1437 if (m_pathList.AreAllPathsFiles())
1439 m_pathList.AddPath(path);
1440 m_pathList.RemoveDuplicates();
1441 m_updatedPathList.AddPath(path);
1442 m_updatedPathList.RemoveDuplicates();
1444 else
1446 // if the path list contains folders, we have to check whether
1447 // our just (maybe) added path is a child of one of those. If it is
1448 // a child of a folder already in the list, we must not add it. Otherwise
1449 // that path could show up twice in the list.
1450 bool bHasParentInList = false;
1451 for (int i=0; i<m_pathList.GetCount(); ++i)
1453 if (m_pathList[i].IsAncestorOf(path))
1455 bHasParentInList = true;
1456 break;
1459 if (!bHasParentInList)
1461 m_pathList.AddPath(path);
1462 m_pathList.RemoveDuplicates();
1463 m_updatedPathList.AddPath(path);
1464 m_updatedPathList.RemoveDuplicates();
1469 // Always start the timer, since the status of an existing item might have changed
1470 SetTimer(REFRESHTIMER, 200, NULL);
1471 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1472 #endif
1473 return 0;
1476 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1478 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1479 return 0;
1482 //////////////////////////////////////////////////////////////////////////
1483 // functions which run in the status thread
1484 //////////////////////////////////////////////////////////////////////////
1486 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1488 CString strLine;
1491 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1492 while (m_bRunThread && file.ReadString(strLine))
1494 int eqpos = strLine.Find('=');
1495 CString rgx;
1496 rgx = strLine.Mid(eqpos+1).Trim();
1498 int pos = -1;
1499 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1501 mapRegex[strLine.Left(pos)] = rgx;
1502 strLine = strLine.Mid(pos+1).Trim();
1504 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1506 file.Close();
1508 catch (CFileException* pE)
1510 TRACE("CFileException loading auto list regex file\n");
1511 pE->Delete();
1512 return;
1515 void CCommitDlg::GetAutocompletionList()
1517 // the auto completion list is made of strings from each selected files.
1518 // the strings used are extracted from the files with regexes found
1519 // in the file "autolist.txt".
1520 // the format of that file is:
1521 // file extensions separated with commas '=' regular expression to use
1522 // example:
1523 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1524 // .cpp = (?<=[^\s]::)\b\w+\b
1526 std::map<CString, CString> mapRegex;
1527 CString sRegexFile = CPathUtils::GetAppDirectory();
1528 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1529 DWORD timeoutvalue = regtimeout*1000;
1530 sRegexFile += _T("autolist.txt");
1531 if (!m_bRunThread)
1532 return;
1533 ParseRegexFile(sRegexFile, mapRegex);
1534 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1535 sRegexFile.ReleaseBuffer();
1536 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1537 if (PathFileExists(sRegexFile))
1539 ParseRegexFile(sRegexFile, mapRegex);
1541 DWORD starttime = GetTickCount();
1543 // now we have two arrays of strings, where the first array contains all
1544 // file extensions we can use and the second the corresponding regex strings
1545 // to apply to those files.
1547 // the next step is to go over all files shown in the commit dialog
1548 // and scan them for strings we can use
1549 int nListItems = m_ListCtrl.GetItemCount();
1551 for (int i=0; i<nListItems && m_bRunThread; ++i)
1553 // stop parsing after timeout
1554 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1555 return;
1557 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1559 if(path == NULL)
1560 continue;
1562 CString sPartPath =path->GetGitPathString();
1563 m_autolist.insert(sPartPath);
1565 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1566 // if (!entry)
1567 // continue;
1569 // add the path parts to the auto completion list too
1570 // CString sPartPath = entry->GetRelativeGitPath();
1571 // m_autolist.insert(sPartPath);
1574 int pos = 0;
1575 int lastPos = 0;
1576 while ((pos = sPartPath.Find('/', pos)) >= 0)
1578 pos++;
1579 lastPos = pos;
1580 m_autolist.insert(sPartPath.Mid(pos));
1583 // Last inserted entry is a file name.
1584 // Some users prefer to also list file name without extension.
1585 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1587 int dotPos = sPartPath.ReverseFind('.');
1588 if ((dotPos >= 0) && (dotPos > lastPos))
1589 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1591 #if 0
1592 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1593 continue;
1595 CString sExt = entry->GetPath().GetFileExtension();
1596 sExt.MakeLower();
1597 // find the regex string which corresponds to the file extension
1598 CString rdata = mapRegex[sExt];
1599 if (rdata.IsEmpty())
1600 continue;
1602 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1603 if ((entry->textstatus != Git_wc_status_unversioned) &&
1604 (entry->textstatus != Git_wc_status_none) &&
1605 (entry->textstatus != Git_wc_status_ignored) &&
1606 (entry->textstatus != Git_wc_status_added) &&
1607 (entry->textstatus != Git_wc_status_normal))
1609 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1610 if (!basePath.IsEmpty())
1611 ScanFile(basePath.GetWinPathString(), rdata);
1613 #endif
1615 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1618 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1620 wstring sFileContent;
1621 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1622 if (hFile != INVALID_HANDLE_VALUE)
1624 DWORD size = GetFileSize(hFile, NULL);
1625 if (size > 1000000L)
1627 // no files bigger than 1 Meg
1628 CloseHandle(hFile);
1629 return;
1631 // allocate memory to hold file contents
1632 char * buffer = new char[size];
1633 DWORD readbytes;
1634 ReadFile(hFile, buffer, size, &readbytes, NULL);
1635 CloseHandle(hFile);
1636 int opts = 0;
1637 IsTextUnicode(buffer, readbytes, &opts);
1638 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1640 delete [] buffer;
1641 return;
1643 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1645 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1647 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1649 int ret = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1650 wchar_t * pWideBuf = new wchar_t[ret];
1651 int ret2 = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1652 if (ret2 == ret)
1653 sFileContent = wstring(pWideBuf, ret);
1654 delete [] pWideBuf;
1656 delete [] buffer;
1658 if (sFileContent.empty()|| !m_bRunThread)
1660 return;
1665 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1666 const tr1::wsregex_iterator end;
1667 wstring s = sFileContent;
1668 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1670 const tr1::wsmatch match = *it;
1671 for (size_t i=1; i<match.size(); ++i)
1673 if (match[i].second-match[i].first)
1675 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1676 m_autolist.insert(wstring(match[i]).c_str());
1681 catch (exception) {}
1684 // CSciEditContextMenuInterface
1685 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1687 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1688 m_nPopupPasteListCmd = nCmd++;
1689 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1691 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1692 if(m_History.GetCount() > 0)
1694 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1695 m_nPopupPasteLastMessage = nCmd++;
1696 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1698 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1699 m_nPopupRecentMessage = nCmd++;
1700 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1706 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1709 if (m_bBlock)
1710 return false;
1711 if (cmd == m_nPopupPasteListCmd)
1713 CString logmsg;
1714 int nListItems = m_ListCtrl.GetItemCount();
1715 for (int i=0; i<nListItems; ++i)
1717 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1718 if (entry&&entry->m_Checked)
1720 CString line;
1721 CString status = entry->GetActionName();
1722 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1723 status = _T("Add"); // I18N TODO
1725 //git_wc_status_kind status = entry->status;
1726 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1727 if (m_ProjectProperties.bFileListInEnglish)
1728 langID = 1033;
1730 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1731 logmsg += line;
1734 pSciEdit->InsertText(logmsg);
1735 return true;
1738 if(cmd == m_nPopupPasteLastMessage)
1740 if(m_History.GetCount() ==0 )
1741 return false;
1743 CString logmsg;
1744 logmsg +=m_History.GetEntry(0);
1745 pSciEdit->InsertText(logmsg);
1746 return true;
1749 if(cmd == m_nPopupRecentMessage )
1751 OnBnClickedHistory();
1752 return true;
1754 return false;
1757 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1759 switch (nIDEvent)
1761 case ENDDIALOGTIMER:
1762 KillTimer(ENDDIALOGTIMER);
1763 EndDialog(0);
1764 break;
1765 case REFRESHTIMER:
1766 if (m_bThreadRunning)
1768 SetTimer(REFRESHTIMER, 200, NULL);
1769 ATLTRACE("Wait some more before refreshing\n");
1771 else
1773 KillTimer(REFRESHTIMER);
1774 ATLTRACE("Refreshing after items dropped\n");
1775 Refresh();
1777 break;
1779 __super::OnTimer(nIDEvent);
1782 void CCommitDlg::OnBnClickedHistory()
1784 m_tooltips.Pop(); // hide the tooltips
1785 if (m_pathList.GetCount() == 0)
1786 return;
1788 CHistoryDlg historyDlg;
1789 historyDlg.SetHistory(m_History);
1790 if (historyDlg.DoModal() != IDOK)
1791 return;
1793 CString sMsg = historyDlg.GetSelectedText();
1794 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1796 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
1797 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
1799 SetDlgItemText(IDC_BUGID, sBugID);
1801 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1802 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1803 else
1804 m_cLogMessage.SetText(sMsg);
1807 UpdateOKButton();
1808 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1812 void CCommitDlg::OnBnClickedBugtraqbutton()
1814 m_tooltips.Pop(); // hide the tooltips
1815 CString sMsg = m_cLogMessage.GetText();
1817 if (m_BugTraqProvider == NULL)
1818 return;
1820 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1821 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1822 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1824 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1825 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1827 BSTR originalMessage = sMsg.AllocSysString();
1828 BSTR temp = NULL;
1829 // m_revProps.clear();
1831 // first try the IBugTraqProvider2 interface
1832 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1833 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1834 bool bugIdOutSet = false;
1835 if (SUCCEEDED(hr))
1837 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1838 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1839 BSTR bugIDOut = NULL;
1840 GetDlgItemText(IDC_BUGID, m_sBugID);
1841 BSTR bugID = m_sBugID.AllocSysString();
1842 SAFEARRAY * revPropNames = NULL;
1843 SAFEARRAY * revPropValues = NULL;
1844 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1846 CString sErr;
1847 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1848 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1850 else
1852 if (bugIDOut)
1854 bugIdOutSet = true;
1855 m_sBugID = bugIDOut;
1856 SysFreeString(bugIDOut);
1857 SetDlgItemText(IDC_BUGID, m_sBugID);
1859 SysFreeString(bugID);
1860 SysFreeString(repositoryRoot);
1861 m_cLogMessage.SetText(temp);
1862 BSTR HUGEP *pbRevNames;
1863 BSTR HUGEP *pbRevValues;
1865 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1866 if (SUCCEEDED(hr1))
1868 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1869 if (SUCCEEDED(hr2))
1871 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1873 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1875 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1878 SafeArrayUnaccessData(revPropValues);
1880 SafeArrayUnaccessData(revPropNames);
1882 if (revPropNames)
1883 SafeArrayDestroy(revPropNames);
1884 if (revPropValues)
1885 SafeArrayDestroy(revPropValues);
1888 else
1890 // if IBugTraqProvider2 failed, try IBugTraqProvider
1891 CComPtr<IBugTraqProvider> pProvider = NULL;
1892 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1893 if (FAILED(hr))
1895 CString sErr;
1896 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1897 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1898 return;
1901 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1903 CString sErr;
1904 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1905 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1907 else
1908 m_cLogMessage.SetText(temp);
1910 m_sLogMessage = m_cLogMessage.GetText();
1911 if (!m_ProjectProperties.sMessage.IsEmpty())
1913 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1914 if (!sBugID.IsEmpty() && !bugIdOutSet)
1916 SetDlgItemText(IDC_BUGID, sBugID);
1920 m_cLogMessage.SetFocus();
1922 SysFreeString(parameters);
1923 SysFreeString(commonRoot);
1924 SafeArrayDestroy(pathList);
1925 SysFreeString(originalMessage);
1926 SysFreeString(temp);
1929 void CCommitDlg::FillPatchView()
1931 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1933 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1935 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1936 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1937 CString cmd,out;
1939 while(pos)
1941 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1942 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1943 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1945 CString head = _T("HEAD");
1946 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1947 head = _T("HEAD~1");
1948 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
1949 g_Git.Run(cmd, &out, CP_UTF8);
1953 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1954 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1955 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1956 CRect rect;
1957 m_patchViewdlg.m_ctrlPatchView.GetClientRect(rect);
1958 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTH, rect.Width() - 4);
1961 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1963 this->FillPatchView();
1964 return 0;
1968 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1970 UpdateOKButton();
1971 return 0;
1974 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
1976 HWND hwnd = (HWND)wnd;
1977 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
1978 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, true);
1979 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
1980 m_ListCtrl.Check(0, true);
1981 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
1982 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, false);
1983 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
1984 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, false);
1985 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
1986 m_ListCtrl.Check(GITSLC_SHOWADDED, false);
1987 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
1988 m_ListCtrl.Check(GITSLC_SHOWREMOVED, false);
1989 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
1990 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, false);
1991 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
1992 m_ListCtrl.Check(GITSLC_SHOWFILES, false);
1993 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
1994 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, false);
1996 return 0;
1999 void CCommitDlg::UpdateOKButton()
2001 if (m_bBlock)
2002 return;
2004 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
2005 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2007 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFilesOrMerge);
2010 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2012 switch (message) {
2013 case WM_NOTIFY:
2014 if (wParam == IDC_SPLITTER)
2016 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2017 DoSize(pHdr->delta);
2019 break;
2022 return __super::DefWindowProc(message, wParam, lParam);
2025 void CCommitDlg::SetSplitterRange()
2027 if ((m_ListCtrl)&&(m_cLogMessage))
2029 CRect rcTop;
2030 m_cLogMessage.GetWindowRect(rcTop);
2031 ScreenToClient(rcTop);
2032 CRect rcMiddle;
2033 m_ListCtrl.GetWindowRect(rcMiddle);
2034 ScreenToClient(rcMiddle);
2035 if (rcMiddle.Height() && rcMiddle.Width())
2036 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
2040 void CCommitDlg::DoSize(int delta)
2042 RemoveAnchor(IDC_MESSAGEGROUP);
2043 RemoveAnchor(IDC_LOGMESSAGE);
2044 RemoveAnchor(IDC_SPLITTER);
2045 RemoveAnchor(IDC_SIGNOFF);
2046 RemoveAnchor(IDC_COMMIT_AMEND);
2047 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2048 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2049 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2050 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2051 RemoveAnchor(IDC_LISTGROUP);
2052 RemoveAnchor(IDC_FILELIST);
2053 RemoveAnchor(IDC_TEXT_INFO);
2054 RemoveAnchor(IDC_SELECTLABEL);
2055 RemoveAnchor(IDC_CHECKALL);
2056 RemoveAnchor(IDC_CHECKNONE);
2057 RemoveAnchor(IDC_CHECKUNVERSIONED);
2058 RemoveAnchor(IDC_CHECKVERSIONED);
2059 RemoveAnchor(IDC_CHECKADDED);
2060 RemoveAnchor(IDC_CHECKDELETED);
2061 RemoveAnchor(IDC_CHECKMODIFIED);
2062 RemoveAnchor(IDC_CHECKFILES);
2063 RemoveAnchor(IDC_CHECKSUBMODULES);
2065 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
2066 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
2067 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
2068 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
2069 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
2070 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
2071 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
2072 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
2073 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
2074 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
2075 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
2076 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
2077 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
2078 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
2079 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
2080 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
2081 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
2082 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
2083 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
2084 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
2085 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
2087 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2088 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2089 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2090 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2091 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2092 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2093 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2094 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2095 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2096 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2097 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2098 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2099 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2100 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2101 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2102 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2103 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2104 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2105 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2106 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2107 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2108 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2109 ArrangeLayout();
2110 // adjust the minimum size of the dialog to prevent the resizing from
2111 // moving the list control too far down.
2112 CRect rcLogMsg;
2113 m_cLogMessage.GetClientRect(rcLogMsg);
2114 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2116 SetSplitterRange();
2117 m_cLogMessage.Invalidate();
2118 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2121 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2123 // first, let the resizing take place
2124 __super::OnSize(nType, cx, cy);
2126 //set range
2127 SetSplitterRange();
2130 CString CCommitDlg::GetSignedOffByLine()
2132 CString str;
2134 CString username = g_Git.GetUserName();
2135 CString email = g_Git.GetUserEmail();
2136 username.Remove(_T('\n'));
2137 email.Remove(_T('\n'));
2139 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
2141 return str;
2144 void CCommitDlg::OnBnClickedSignOff()
2146 CString str = GetSignedOffByLine();
2148 if (m_cLogMessage.GetText().Find(str) == -1) {
2149 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2150 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
2151 int foundByLine = -1;
2152 if (lastNewline > 0)
2153 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
2155 if (foundByLine == -1 || foundByLine < lastNewline)
2156 str = _T("\r\n") + str;
2158 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
2162 void CCommitDlg::OnBnClickedCommitAmend()
2164 this->UpdateData();
2165 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2167 GitRev rev;
2168 rev.GetCommit(CString(_T("HEAD")));
2169 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2172 if(this->m_bCommitAmend)
2174 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2175 m_cLogMessage.SetText(m_AmendStr);
2176 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2178 else
2180 this->m_AmendStr=this->m_cLogMessage.GetText();
2181 m_cLogMessage.SetText(m_NoAmendStr);
2182 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2185 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2187 Refresh();
2190 void CCommitDlg::OnBnClickedWholeProject()
2192 m_tooltips.Pop(); // hide the tooltips
2193 UpdateData();
2194 m_ListCtrl.Clear();
2195 if (!m_bBlock)
2197 if(m_bWholeProject)
2198 m_ListCtrl.GetStatus(NULL,true,false,true);
2199 else
2200 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2202 DWORD dwShow = m_ListCtrl.GetShowFlags();
2203 if (DWORD(m_regAddBeforeCommit))
2204 dwShow |= GITSLC_SHOWUNVERSIONED;
2205 else
2206 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2208 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2209 UpdateCheckLinks();
2212 SetDlgTitle();
2215 void CCommitDlg::OnFocusMessage()
2217 m_cLogMessage.SetFocus();
2220 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
2222 UNREFERENCED_PARAMETER(pNMHDR);
2223 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2224 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2225 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2227 CString str;
2228 str.Format(_T("%d/%d"),line+1,column+1);
2229 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2231 if(*pResult)
2232 *pResult=0;
2234 void CCommitDlg::OnStnClickedViewPatch()
2236 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2237 m_patchViewdlg.m_ParentCommitDlg = this;
2238 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2240 BOOL viewPatchEnabled = FALSE;
2241 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
2242 if (viewPatchEnabled == FALSE)
2243 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2244 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2245 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2246 CRect rect;
2247 this->GetWindowRect(&rect);
2249 m_patchViewdlg.ShowWindow(SW_SHOW);
2251 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2252 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2254 ShowViewPatchText(false);
2255 FillPatchView();
2257 else
2259 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2260 m_patchViewdlg.ShowWindow(SW_HIDE);
2261 m_patchViewdlg.DestroyWindow();
2262 ShowViewPatchText(true);
2264 this->m_ctrlShowPatch.Invalidate();
2267 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2269 __super::OnMoving(fwSide, pRect);
2271 if (::IsWindow(m_patchViewdlg.m_hWnd))
2273 RECT patchrect;
2274 m_patchViewdlg.GetWindowRect(&patchrect);
2275 if (::IsWindow(m_hWnd))
2277 RECT thisrect;
2278 GetWindowRect(&thisrect);
2279 if (patchrect.left == thisrect.right)
2281 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2282 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2289 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2291 __super::OnSizing(fwSide, pRect);
2293 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2295 CRect thisrect, patchrect;
2296 this->GetWindowRect(thisrect);
2297 this->m_patchViewdlg.GetWindowRect(patchrect);
2298 if(thisrect.right==patchrect.left)
2300 patchrect.left -= (thisrect.right - pRect->right);
2301 patchrect.right-= (thisrect.right - pRect->right);
2303 if( patchrect.bottom == thisrect.bottom)
2305 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2307 if( patchrect.top == thisrect.top)
2309 patchrect.top -= thisrect.top-pRect->top;
2311 m_patchViewdlg.MoveWindow(patchrect);
2316 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2318 UNREFERENCED_PARAMETER(pNMHDR);
2319 *pResult = 0;
2320 TRACE("Item Changed\r\n");
2323 int CCommitDlg::CheckHeadDetach()
2325 CString output;
2326 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2328 int retval = CMessageBox::Show(NULL, IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2329 if(retval == IDYES)
2331 if (CAppUtils::CreateBranchTag(FALSE, NULL, true) == FALSE)
2332 return 1;
2334 else if (retval == IDCANCEL)
2335 return 1;
2337 return 0;
2340 void CCommitDlg::OnBnClickedCommitAmenddiff()
2342 UpdateData();
2343 Refresh();
2346 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2348 UpdateData();
2349 Refresh();
2352 void CCommitDlg::OnBnClickedCommitSetDateTime()
2354 UpdateData();
2356 if (m_bSetCommitDateTime)
2358 CTime authordate = CTime::GetCurrentTime();
2359 if (m_bCommitAmend)
2361 GitRev headRevision;
2362 headRevision.GetCommit(_T("HEAD"));
2363 authordate = headRevision.GetAuthorDate();
2366 m_CommitDate.SetTime(&authordate);
2367 m_CommitTime.SetTime(&authordate);
2369 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2370 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2372 else
2374 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2375 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2379 void CCommitDlg::OnBnClickedCheckNewBranch()
2381 UpdateData();
2382 if (m_bCreateNewBranch)
2384 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2385 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2387 else
2389 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2390 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2394 void CCommitDlg::RestoreFiles(bool doNotAsk)
2396 if (m_ListCtrl.m_restorepaths.size() && (doNotAsk || CMessageBox::Show(m_hWnd, IDS_PROC_COMMIT_RESTOREFILES, IDS_APPNAME, 2, IDI_QUESTION, IDS_PROC_COMMIT_RESTOREFILES_RESTORE, IDS_PROC_COMMIT_RESTOREFILES_KEEP) == 1))
2398 for (std::map<CString, CString>::iterator it = m_ListCtrl.m_restorepaths.begin(); it != m_ListCtrl.m_restorepaths.end(); ++it)
2399 CopyFile(it->second, g_Git.m_CurrentDir + _T("\\") + it->first, FALSE);
2400 m_ListCtrl.m_restorepaths.clear();
2404 void CCommitDlg::UpdateCheckLinks()
2406 DialogEnableWindow(IDC_CHECKALL, true);
2407 DialogEnableWindow(IDC_CHECKNONE, true);
2408 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2409 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2410 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2411 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2412 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2413 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2414 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);