1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "DirFileEnum.h"
24 //#include "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
28 #include "PathUtils.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
34 #include "CommonResource.h"
35 #include "UnicodeUtils.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
46 static char THIS_FILE
[] = __FILE__
;
49 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
52 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
53 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
55 , m_bShowUnversioned(FALSE
)
57 , m_bThreadRunning(FALSE
)
60 , m_bWholeProject(FALSE
)
61 , m_bKeepChangeList(TRUE
)
62 , m_bDoNotAutoselectSubmodules(FALSE
)
64 , m_bSelectFilesForCommit(TRUE
)
65 , m_bNoPostActions(FALSE
)
67 , m_bSetCommitDateTime(FALSE
)
69 this->m_bCommitAmend
=FALSE
;
70 m_bPushAfterCommit
= FALSE
;
73 CCommitDlg::~CCommitDlg()
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
)
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
)
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
)
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")))
143 if(file
.Open(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG"), CFile::modeRead
))
146 while(file
.ReadString(str
))
148 m_sLogMessage
+= str
;
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
));
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;
180 m_ListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
| SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("CommitDlg"),(SVNSLC_POPALL
^ (SVNSLC_POPCOMMIT
| SVNSLC_POPSAVEAS
)));
181 m_ListCtrl
.SetSelectButton(&m_SelectAll
);
182 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
183 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
184 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
185 m_ListCtrl
.EnableFileDrop();
186 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
188 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
189 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
191 m_cLogMessage
.Init(m_ProjectProperties
);
192 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
193 m_cLogMessage
.RegisterContextMenuHandler(this);
195 OnEnChangeLogmessage();
197 m_tooltips
.Create(this);
198 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
199 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
200 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
202 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
204 CBugTraqAssociations bugtraq_associations
;
205 bugtraq_associations
.Load();
207 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
209 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
210 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
212 CComPtr
<IBugTraqProvider
> pProvider
;
213 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
216 m_BugTraqProvider
= pProvider
;
218 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
220 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
221 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
222 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
228 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
230 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
232 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
233 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
234 if (!m_ProjectProperties
.sLabel
.IsEmpty())
235 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
236 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
237 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
238 GetDlgItem(IDC_BUGID
)->SetFocus();
239 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
240 if (!sBugID
.IsEmpty())
242 SetDlgItemText(IDC_BUGID
, sBugID
);
247 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
248 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
249 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
250 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
251 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
254 if (!m_sLogMessage
.IsEmpty())
255 m_cLogMessage
.SetText(m_sLogMessage
);
257 GetWindowText(m_sWindowTitle
);
259 AdjustControlSize(IDC_SHOWUNVERSIONED
);
260 AdjustControlSize(IDC_SELECTALL
);
261 AdjustControlSize(IDC_WHOLE_PROJECT
);
263 GetClientRect(m_DlgOrigRect
);
264 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
266 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
267 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
268 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
269 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
270 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
271 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
272 // AddAnchor(IDC_HISTORY, TOP_LEFT);
273 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
274 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
275 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
276 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
277 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
278 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
279 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
280 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
281 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
282 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
283 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
284 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
285 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
286 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
287 AddAnchor(IDOK
, BOTTOM_RIGHT
);
288 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
289 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
290 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
291 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
292 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
293 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
294 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
297 CenterWindow(CWnd::FromHandle(hWndExplorer
));
298 EnableSaveRestore(_T("CommitDlg"));
299 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
300 RECT rcDlg
, rcLogMsg
, rcFileList
;
301 GetClientRect(&rcDlg
);
302 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
303 ScreenToClient(&rcLogMsg
);
304 m_ListCtrl
.GetWindowRect(&rcFileList
);
305 ScreenToClient(&rcFileList
);
309 m_wndSplitter
.GetWindowRect(&rectSplitter
);
310 ScreenToClient(&rectSplitter
);
311 int delta
= yPos
- rectSplitter
.top
;
312 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
314 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
319 // add all directories to the watcher
321 for (int i=0; i<m_pathList.GetCount(); ++i)
323 if (m_pathList[i].IsDirectory())
324 m_pathwatcher.AddPath(m_pathList[i]);
327 m_updatedPathList
= m_pathList
;
329 //first start a thread to obtain the file list with the status without
330 //blocking the dialog
331 InterlockedExchange(&m_bBlock
, TRUE
);
332 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
335 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
336 InterlockedExchange(&m_bBlock
, FALSE
);
340 m_pThread
->m_bAutoDelete
= FALSE
;
341 m_pThread
->ResumeThread();
343 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
344 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
345 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
348 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
352 if (g_Git
.IsInitRepos())
354 m_bCommitAmend
= FALSE
;
355 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
362 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
363 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
366 CGitHash hash
= g_Git
.GetHash(_T("HEAD"));
368 headRevision
.GetParentFromHash(hash
);
369 // do not allow to show diff to "last" revision if it has more that one parent
370 if (headRevision
.ParentsCount() != 1)
372 m_bAmendDiffToLastCommit
= true;
374 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(FALSE
);
378 this->m_ctrlShowPatch
.SetURL(CString());
380 return FALSE
; // return TRUE unless you set the focus to a control
381 // EXCEPTION: OCX Property Pages should return FALSE
384 void CCommitDlg::OnOK()
388 if (m_bThreadRunning
)
391 InterlockedExchange(&m_bRunThread
, FALSE
);
392 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
393 if (m_bThreadRunning
)
395 // we gave the thread a chance to quit. Since the thread didn't
396 // listen to us we have to kill it.
397 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
398 InterlockedExchange(&m_bThreadRunning
, FALSE
);
404 GetDlgItemText(IDC_BUGID
, id
);
405 if (!m_ProjectProperties
.CheckBugID(id
))
407 ShowBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDI_EXCLAMATION
);
410 m_sLogMessage
= m_cLogMessage
.GetText();
411 if ( m_sLogMessage
.IsEmpty() )
413 // no message entered, go round again
414 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
417 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
419 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
423 BOOL bWarnNoSignedOffBy
= FALSE
;
424 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
425 if (bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
427 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"));
430 OnBnClickedSignOff();
431 m_sLogMessage
= m_cLogMessage
.GetText();
433 else if (retval
== 3)
437 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
439 CRegDWORD
regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
);
440 if (!(DWORD
)regUnversionedRecurse
)
442 // Find unversioned directories which are marked for commit. The user might expect them
443 // to be added recursively since he cannot the the files. Let's ask the user if he knows
445 int nListItems
= m_ListCtrl
.GetItemCount();
446 for (int j
=0; j
<nListItems
; j
++)
448 const CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(j
);
449 if (entry
->IsChecked() && (entry
->status
== Git_wc_status_unversioned
) && entry
->IsFolder() )
451 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
457 m_pathwatcher
.Stop();
458 InterlockedExchange(&m_bBlock
, TRUE
);
459 CDWordArray arDeleted
;
460 //first add all the unversioned files the user selected
461 //and check if all versioned files are selected
464 int nListItems
= m_ListCtrl
.GetItemCount();
466 CTGitPathList itemsToAdd
;
467 CTGitPathList itemsToRemove
;
468 //std::set<CString> checkedLists;
469 //std::set<CString> uncheckedLists;
471 // now let the bugtraq plugin check the commit message
472 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
473 if (m_BugTraqProvider
)
475 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
479 CString common
= g_Git
.m_CurrentDir
;
480 BSTR repositoryRoot
= common
.AllocSysString();
481 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
482 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
483 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
484 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
486 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
487 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
489 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
493 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
494 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
498 CString sError
= temp
;
499 if (!sError
.IsEmpty())
501 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
509 //CString checkedfiles;
510 //CString uncheckedfiles;
515 bool bAddSuccess
=true;
516 bool bCloseCommitDlg
=false;
518 for (int j
=0; j
<nListItems
; j
++)
520 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
521 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
522 if (entry
->m_Checked
)
525 if (entry
->status
== Git_wc_status_unversioned
)
527 itemsToAdd
.AddPath(entry
->GetPath());
529 if (entry
->status
== Git_wc_status_conflicted
)
531 bHasConflicted
= true;
533 if (entry
->status
== Git_wc_status_missing
)
535 itemsToRemove
.AddPath(entry
->GetPath());
537 if (entry
->status
== Git_wc_status_deleted
)
541 if (entry
->IsInExternal())
543 bCheckedInExternal
= true;
546 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
547 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
548 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
549 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
551 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
553 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
555 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
556 bAddSuccess
= false ;
560 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
561 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
563 g_Git
.Run(cmd
,&out
,CP_ACP
);
567 //checkedLists.insert(entry->GetGitPathString());
568 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
572 //uncheckedLists.insert(entry->GetGitPathString());
573 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
574 { //To init git repository, there are not HEAD, so we can use git reset command
575 cmd
.Format(_T("git.exe rm --cache -- \"%s\""),entry
->GetGitPathString());
576 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
578 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
579 bAddSuccess
= false ;
580 bCloseCommitDlg
=false;
585 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
587 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
589 cmd
.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry
->GetGitPathString());
593 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
595 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
597 /* when reset a unstage file will report error.
598 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
599 bAddSuccess = false ;
600 bCloseCommitDlg=false;
604 // && !entry->IsDirectory()
605 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
609 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
611 if ((entry
->status
!= Git_wc_status_unversioned
) &&
612 (entry
->status
!= Git_wc_status_ignored
))
615 uncheckedLists
.insert(entry
->GetChangeList());
618 // This algorithm is for the sake of simplicity of the complexity O(N?
619 for (int k
=0; k
<nListItems
; k
++)
621 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
622 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
624 // Fall back to a non-recursive commit to prevent items being
625 // committed which aren't checked although its parent is checked
626 // (property change, directory deletion, ... )
627 m_bRecursive
= false;
636 CShellUpdater::Instance().AddPathForUpdate(*entry
);
639 //if(uncheckedfiles.GetLength()>0)
641 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
642 // g_Git.Run(cmd,&out);
646 if (!m_sBugID
.IsEmpty())
648 m_sBugID
.Replace(_T(", "), _T(","));
649 m_sBugID
.Replace(_T(" ,"), _T(","));
650 CString sBugID
= m_ProjectProperties
.sMessage
;
651 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
652 if (m_ProjectProperties
.bAppend
)
653 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
655 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
659 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
663 //if(checkedfiles.GetLength()>0)
664 if( bAddSuccess
&& (nchecked
||m_bCommitAmend
||bIsMerge
) )
666 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
667 // g_Git.Run(cmd,&out);
669 bCloseCommitDlg
= true;
671 CString tempfile
=::GetTempFile();
673 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
674 //file.WriteString(m_sLogMessage);
676 CTGitPath path
=g_Git
.m_CurrentDir
;
678 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
682 if(this->m_bCommitAmend
)
687 if (m_bSetCommitDateTime
)
690 m_CommitDate
.GetTime(date
);
691 m_CommitTime
.GetTime(time
);
692 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
694 cmd
.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime
, amend
, tempfile
);
698 CCommitProgressDlg progress
;
699 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
700 progress
.m_GitCmd
=cmd
;
701 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
702 progress
.m_PreText
= out
; // show any output already generated in log window
703 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
705 if (!m_bNoPostActions
&& !m_bAutoClose
)
707 progress
.m_PostCmdList
.Add( IsGitSVN
? _T("&DCommit"): _T("&Push"));
708 progress
.m_PostCmdList
.Add(_T("&ReCommit"));
711 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
713 DWORD userResponse
= progress
.DoModal();
715 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
717 bCloseCommitDlg
= false;
718 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
720 this->m_sLogMessage
.Empty();
721 m_cLogMessage
.SetText(m_sLogMessage
);
726 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
728 //User pressed 'Push' button after successful commit.
729 m_bPushAfterCommit
=true;
732 CFile::Remove(tempfile
);
734 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
736 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
737 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
740 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
741 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
743 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
744 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
746 BSTR logMessage
= m_sLogMessage
.AllocSysString();
748 CGitHash hash
=g_Git
.GetHash(_T("HEAD"));
749 LONG version
= g_Git
.Hash2int(hash
);
752 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
761 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
765 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
766 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
774 }else if(bAddSuccess
)
776 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
777 bCloseCommitDlg
=false;
780 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
782 // There are paths which got changed (touched at least).
783 // We have to find out if this affects the selection in the commit dialog
784 // If it could affect the selection, revert back to a non-recursive commit
785 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
786 changedList
.RemoveDuplicates();
787 for (int i
=0; i
<changedList
.GetCount(); ++i
)
789 if (changedList
[i
].IsAdminDir())
791 // something inside an admin dir was changed.
792 // if it's the entries file, then we have to fully refresh because
793 // files may have been added/removed from version control
794 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
795 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
797 m_bRecursive
= false;
801 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
803 // a path which is not shown in the list has changed
804 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
807 // check if the changed path would get committed by a recursive commit
808 if ((!entry
->IsFromDifferentRepository()) &&
809 (!entry
->IsInExternal()) &&
810 (!entry
->IsNested()) &&
811 (!entry
->IsChecked()))
813 m_bRecursive
= false;
822 // Now, do all the adds - make sure that the list is sorted so that parents
823 // are added before their children
824 itemsToAdd
.SortByPathname();
826 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
828 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
829 InterlockedExchange(&m_bBlock
, FALSE
);
834 // Remove any missing items
835 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
836 itemsToRemove
.SortByPathname();
837 Git
.Remove(itemsToRemove
, TRUE
);
839 //the next step: find all deleted files and check if they're
840 //inside a deleted folder. If that's the case, then remove those
841 //files from the list since they'll get deleted by the parent
842 //folder automatically.
843 m_ListCtrl
.Block(TRUE
, FALSE
);
844 INT_PTR nDeleted
= arDeleted
.GetCount();
845 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
847 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
849 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
850 if (path
.IsDirectory())
852 //now find all children of this directory
853 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
857 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
858 if (childEntry
->IsChecked())
860 if (path
.IsAncestorOf(childEntry
->GetPath()))
862 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
871 m_ListCtrl
.Block(FALSE
, FALSE
);
873 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
875 //save only the files the user has checked into the temporary file
876 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
879 // the item count is used in the progress dialog to show the overall commit
881 // deleted items only send one notification event, all others send two
882 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
884 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
886 // all checked items belong to the same changelist
887 // find out if there are any unchecked items which belong to that changelist
888 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
889 m_sChangeList
= *checkedLists
.begin();
893 m_regAddBeforeCommit
= m_bShowUnversioned
;
894 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
895 m_bWholeProject
= FALSE
;
896 m_regKeepChangelists
= m_bKeepChangeList
;
897 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
898 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
899 m_bKeepChangeList
= FALSE
;
900 InterlockedExchange(&m_bBlock
, FALSE
);
902 m_History
.AddEntry(m_sLogMessage
);
907 if( bCloseCommitDlg
)
908 CResizableStandAloneDialog::OnOK();
910 CShellUpdater::Instance().Flush();
913 void CCommitDlg::SaveSplitterPos()
917 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
919 m_wndSplitter
.GetWindowRect(&rectSplitter
);
920 ScreenToClient(&rectSplitter
);
921 regPos
= rectSplitter
.top
;
925 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
927 return ((CCommitDlg
*)pVoid
)->StatusThread();
930 UINT
CCommitDlg::StatusThread()
932 //get the status of all selected file/folders recursively
933 //and show the ones which have to be committed to the user
935 InterlockedExchange(&m_bBlock
, TRUE
);
936 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
937 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
939 m_pathwatcher
.Stop();
941 g_Git
.RefreshGitIndex();
943 m_bCancelled
= false;
945 DialogEnableWindow(IDOK
, false);
946 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
947 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
948 DialogEnableWindow(IDC_SELECTALL
, false);
949 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
950 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
951 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
952 // read the list of recent log entries before querying the WC for status
953 // -> the user may select one and modify / update it while we are crawling the WC
955 if (m_History
.GetCount()==0)
958 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
959 reg
.Replace(_T(':'),_T('_'));
960 m_History
.Load(reg
, _T("logmsgs"));
963 // Initialise the list control with the status of the files/folders below us
966 CTGitPathList
*pList
;
967 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
) && (m_bAmendDiffToLastCommit
==FALSE
);
968 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
975 success
=m_ListCtrl
.GetStatus(pList
);
977 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
978 if(this->m_bShowUnversioned
)
979 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
981 m_ListCtrl
.CheckIfChangelistsArePresent(false);
983 DWORD dwShow
= SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWLOCKS
| SVNSLC_SHOWINCHANGELIST
;
984 dwShow
|= DWORD(m_regAddBeforeCommit
) ? SVNSLC_SHOWUNVERSIONED
: 0;
987 if (m_checkedPathList
.GetCount())
988 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
991 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
992 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
993 m_ListCtrl
.Show(dwShow
, dwCheck
);
994 m_bSelectFilesForCommit
= true;
997 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
999 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1000 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1003 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1004 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1008 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1009 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1010 m_ListCtrl
.Show(dwShow
);
1012 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1013 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
1015 if (CMessageBox::Show(m_hWnd
, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1017 m_bShowUnversioned
= TRUE
;
1018 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1019 DWORD dwShow
= (DWORD
)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWUNVERSIONED
| SVNSLC_SHOWLOCKS
);
1020 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1021 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1028 // we don't have to block the commit dialog while we fetch the
1029 // auto completion list.
1030 m_pathwatcher
.ClearChangedPaths();
1031 InterlockedExchange(&m_bBlock
, FALSE
);
1032 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1034 m_ListCtrl
.Block(TRUE
, TRUE
);
1035 GetAutocompletionList();
1036 m_ListCtrl
.Block(FALSE
, FALSE
);
1041 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1042 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1043 DialogEnableWindow(IDC_SELECTALL
, true);
1044 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1045 if (m_ListCtrl
.HasChangeLists())
1046 DialogEnableWindow(IDC_KEEPLISTS
, true);
1047 if (m_ListCtrl
.HasLocks())
1048 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1049 // we have the list, now signal the main thread about it
1050 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1053 InterlockedExchange(&m_bRunThread
, FALSE
);
1054 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1055 // force the cursor to normal
1061 void CCommitDlg::SetDlgTitle()
1063 if (m_sTitle
.IsEmpty())
1064 GetWindowText(m_sTitle
);
1066 if (m_bWholeProject
)
1067 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1070 if (m_pathList
.GetCount() == 1)
1071 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1073 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1077 void CCommitDlg::OnCancel()
1079 m_bCancelled
= true;
1080 m_pathwatcher
.Stop();
1085 if (m_bThreadRunning
)
1087 InterlockedExchange(&m_bRunThread
, FALSE
);
1088 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1089 if (m_bThreadRunning
)
1091 // we gave the thread a chance to quit. Since the thread didn't
1092 // listen to us we have to kill it.
1093 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1094 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1099 m_sLogMessage
= m_cLogMessage
.GetText();
1100 if (!m_sBugID
.IsEmpty())
1102 m_sBugID
.Replace(_T(", "), _T(","));
1103 m_sBugID
.Replace(_T(" ,"), _T(","));
1104 CString sBugID
= m_ProjectProperties
.sMessage
;
1105 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1106 if (m_ProjectProperties
.bAppend
)
1107 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1109 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1111 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1112 m_History
.AddEntry(m_sLogMessage
);
1115 CResizableStandAloneDialog::OnCancel();
1118 void CCommitDlg::OnBnClickedSelectall()
1120 m_tooltips
.Pop(); // hide the tooltips
1121 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1122 if (state
== BST_INDETERMINATE
)
1124 // It is not at all useful to manually place the checkbox into the indeterminate state...
1125 // We will force this on to the unchecked state
1126 state
= BST_UNCHECKED
;
1127 m_SelectAll
.SetCheck(state
);
1129 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1132 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1135 m_tooltips
.RelayEvent(pMsg
);
1139 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1144 if (pMsg
->message
== WM_KEYDOWN
)
1146 switch (pMsg
->wParam
)
1151 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1157 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1159 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1161 PostMessage(WM_COMMAND
, IDOK
);
1165 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1167 // Pressing RETURN in the bug id control
1168 // moves the focus to the message
1169 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1177 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1180 void CCommitDlg::Refresh()
1182 if (m_bThreadRunning
)
1185 InterlockedExchange(&m_bBlock
, TRUE
);
1186 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1187 if (m_pThread
==NULL
)
1189 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1190 InterlockedExchange(&m_bBlock
, FALSE
);
1194 m_pThread
->m_bAutoDelete
= FALSE
;
1195 m_pThread
->ResumeThread();
1199 void CCommitDlg::OnBnClickedHelp()
1204 void CCommitDlg::OnBnClickedShowunversioned()
1206 m_tooltips
.Pop(); // hide the tooltips
1208 m_regAddBeforeCommit
= m_bShowUnversioned
;
1211 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1212 if (DWORD(m_regAddBeforeCommit
))
1213 dwShow
|= SVNSLC_SHOWUNVERSIONED
;
1215 dwShow
&= ~SVNSLC_SHOWUNVERSIONED
;
1216 if(dwShow
& SVNSLC_SHOWUNVERSIONED
)
1219 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1221 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1223 m_ListCtrl
.Show(dwShow
,0,true,0,true);
1227 void CCommitDlg::OnStnClickedExternalwarning()
1232 void CCommitDlg::OnEnChangeLogmessage()
1237 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1240 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1242 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1244 m_bShowUnversioned
= TRUE
;
1245 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1246 m_ListCtrl
.Show(dwShow
);
1254 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1260 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1264 SetForegroundWindow();
1266 // if multiple files/folders are dropped
1267 // this handler is called for every single item
1269 // To avoid creating multiple refresh threads and
1270 // causing crashes, we only add the items to the
1271 // list control and start a timer.
1272 // When the timer expires, we start the refresh thread,
1273 // but only if it isn't already running - otherwise we
1274 // restart the timer.
1276 path
.SetFromWin((LPCTSTR
)lParam
);
1278 // just add all the items we get here.
1279 // if the item is versioned, the add will fail but nothing
1280 // more will happen.
1282 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1284 if (!m_ListCtrl
.HasPath(path
))
1286 if (m_pathList
.AreAllPathsFiles())
1288 m_pathList
.AddPath(path
);
1289 m_pathList
.RemoveDuplicates();
1290 m_updatedPathList
.AddPath(path
);
1291 m_updatedPathList
.RemoveDuplicates();
1295 // if the path list contains folders, we have to check whether
1296 // our just (maybe) added path is a child of one of those. If it is
1297 // a child of a folder already in the list, we must not add it. Otherwise
1298 // that path could show up twice in the list.
1299 bool bHasParentInList
= false;
1300 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1302 if (m_pathList
[i
].IsAncestorOf(path
))
1304 bHasParentInList
= true;
1308 if (!bHasParentInList
)
1310 m_pathList
.AddPath(path
);
1311 m_pathList
.RemoveDuplicates();
1312 m_updatedPathList
.AddPath(path
);
1313 m_updatedPathList
.RemoveDuplicates();
1318 // Always start the timer, since the status of an existing item might have changed
1319 SetTimer(REFRESHTIMER
, 200, NULL
);
1320 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1325 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1327 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1331 //////////////////////////////////////////////////////////////////////////
1332 // functions which run in the status thread
1333 //////////////////////////////////////////////////////////////////////////
1335 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1340 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1341 while (m_bRunThread
&& file
.ReadString(strLine
))
1343 int eqpos
= strLine
.Find('=');
1345 rgx
= strLine
.Mid(eqpos
+1).Trim();
1348 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1350 mapRegex
[strLine
.Left(pos
)] = rgx
;
1351 strLine
= strLine
.Mid(pos
+1).Trim();
1353 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1357 catch (CFileException
* pE
)
1359 TRACE("CFileException loading auto list regex file\n");
1364 void CCommitDlg::GetAutocompletionList()
1366 // the auto completion list is made of strings from each selected files.
1367 // the strings used are extracted from the files with regexes found
1368 // in the file "autolist.txt".
1369 // the format of that file is:
1370 // file extensions separated with commas '=' regular expression to use
1372 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1373 // .cpp = (?<=[^\s]::)\b\w+\b
1375 std::map
<CString
, CString
> mapRegex
;
1376 CString sRegexFile
= CPathUtils::GetAppDirectory();
1377 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1378 DWORD timeoutvalue
= regtimeout
*1000;
1379 sRegexFile
+= _T("autolist.txt");
1382 ParseRegexFile(sRegexFile
, mapRegex
);
1383 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1384 sRegexFile
.ReleaseBuffer();
1385 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1386 if (PathFileExists(sRegexFile
))
1388 ParseRegexFile(sRegexFile
, mapRegex
);
1390 DWORD starttime
= GetTickCount();
1392 // now we have two arrays of strings, where the first array contains all
1393 // file extensions we can use and the second the corresponding regex strings
1394 // to apply to those files.
1396 // the next step is to go over all files shown in the commit dialog
1397 // and scan them for strings we can use
1398 int nListItems
= m_ListCtrl
.GetItemCount();
1400 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1402 // stop parsing after timeout
1403 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1406 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1411 CString sPartPath
=path
->GetGitPathString();
1412 m_autolist
.insert(sPartPath
);
1414 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1418 // add the path parts to the auto completion list too
1419 // CString sPartPath = entry->GetRelativeGitPath();
1420 // m_autolist.insert(sPartPath);
1425 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1429 m_autolist
.insert(sPartPath
.Mid(pos
));
1432 // Last inserted entry is a file name.
1433 // Some users prefer to also list file name without extension.
1434 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1436 int dotPos
= sPartPath
.ReverseFind('.');
1437 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1438 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1441 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1444 CString sExt
= entry
->GetPath().GetFileExtension();
1446 // find the regex string which corresponds to the file extension
1447 CString rdata
= mapRegex
[sExt
];
1448 if (rdata
.IsEmpty())
1451 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1452 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1453 (entry
->textstatus
!= Git_wc_status_none
) &&
1454 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1455 (entry
->textstatus
!= Git_wc_status_added
) &&
1456 (entry
->textstatus
!= Git_wc_status_normal
))
1458 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1459 if (!basePath
.IsEmpty())
1460 ScanFile(basePath
.GetWinPathString(), rdata
);
1464 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1467 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1469 wstring sFileContent
;
1470 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1471 if (hFile
!= INVALID_HANDLE_VALUE
)
1473 DWORD size
= GetFileSize(hFile
, NULL
);
1474 if (size
> 1000000L)
1476 // no files bigger than 1 Meg
1480 // allocate memory to hold file contents
1481 char * buffer
= new char[size
];
1483 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1486 IsTextUnicode(buffer
, readbytes
, &opts
);
1487 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1492 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1494 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1496 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1498 int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1499 wchar_t * pWideBuf
= new wchar_t[ret
];
1500 int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1502 sFileContent
= wstring(pWideBuf
, ret
);
1507 if (sFileContent
.empty()|| !m_bRunThread
)
1514 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1515 const tr1::wsregex_iterator end
;
1516 wstring s
= sFileContent
;
1517 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1519 const tr1::wsmatch match
= *it
;
1520 for (size_t i
=1; i
<match
.size(); ++i
)
1522 if (match
[i
].second
-match
[i
].first
)
1524 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1525 m_autolist
.insert(wstring(match
[i
]).c_str());
1530 catch (exception
) {}
1533 // CSciEditContextMenuInterface
1534 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1536 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1537 m_nPopupPasteListCmd
= nCmd
++;
1538 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1540 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1541 if(m_History
.GetCount() > 0)
1543 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1544 m_nPopupPasteLastMessage
= nCmd
++;
1545 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1547 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1548 m_nPopupRecentMessage
= nCmd
++;
1549 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1555 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1560 if (cmd
== m_nPopupPasteListCmd
)
1563 int nListItems
= m_ListCtrl
.GetItemCount();
1564 for (int i
=0; i
<nListItems
; ++i
)
1566 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1567 if (entry
&&entry
->m_Checked
)
1570 CString status
= entry
->GetActionName();
1571 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1574 //git_wc_status_kind status = entry->status;
1575 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1576 if (m_ProjectProperties
.bFileListInEnglish
)
1579 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1583 pSciEdit
->InsertText(logmsg
);
1587 if(cmd
== m_nPopupPasteLastMessage
)
1589 if(m_History
.GetCount() ==0 )
1593 logmsg
+=m_History
.GetEntry(0);
1594 pSciEdit
->InsertText(logmsg
);
1598 if(cmd
== m_nPopupRecentMessage
)
1600 OnBnClickedHistory();
1606 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1610 case ENDDIALOGTIMER
:
1611 KillTimer(ENDDIALOGTIMER
);
1615 if (m_bThreadRunning
)
1617 SetTimer(REFRESHTIMER
, 200, NULL
);
1618 ATLTRACE("Wait some more before refreshing\n");
1622 KillTimer(REFRESHTIMER
);
1623 ATLTRACE("Refreshing after items dropped\n");
1628 __super::OnTimer(nIDEvent
);
1631 void CCommitDlg::OnBnClickedHistory()
1633 m_tooltips
.Pop(); // hide the tooltips
1634 if (m_pathList
.GetCount() == 0)
1637 CHistoryDlg historyDlg
;
1638 historyDlg
.SetHistory(m_History
);
1639 if (historyDlg
.DoModal() != IDOK
)
1642 CString sMsg
= historyDlg
.GetSelectedText();
1643 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1645 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1646 if (!sBugID
.IsEmpty())
1648 SetDlgItemText(IDC_BUGID
, sBugID
);
1650 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1651 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1653 m_cLogMessage
.SetText(sMsg
);
1657 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1661 void CCommitDlg::OnBnClickedBugtraqbutton()
1663 m_tooltips
.Pop(); // hide the tooltips
1664 CString sMsg
= m_cLogMessage
.GetText();
1666 if (m_BugTraqProvider
== NULL
)
1669 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1670 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1671 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1673 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1674 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1676 BSTR originalMessage
= sMsg
.AllocSysString();
1678 // m_revProps.clear();
1680 // first try the IBugTraqProvider2 interface
1681 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1682 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1685 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1686 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1687 BSTR bugIDOut
= NULL
;
1688 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1689 BSTR bugID
= m_sBugID
.AllocSysString();
1690 SAFEARRAY
* revPropNames
= NULL
;
1691 SAFEARRAY
* revPropValues
= NULL
;
1692 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1695 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1696 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1702 m_sBugID
= bugIDOut
;
1703 SysFreeString(bugIDOut
);
1704 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1706 SysFreeString(bugID
);
1707 SysFreeString(repositoryRoot
);
1708 m_cLogMessage
.SetText(temp
);
1709 BSTR HUGEP
*pbRevNames
;
1710 BSTR HUGEP
*pbRevValues
;
1712 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1715 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1718 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1720 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1722 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1725 SafeArrayUnaccessData(revPropValues
);
1727 SafeArrayUnaccessData(revPropNames
);
1730 SafeArrayDestroy(revPropNames
);
1732 SafeArrayDestroy(revPropValues
);
1737 // if IBugTraqProvider2 failed, try IBugTraqProvider
1738 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1739 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1743 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1744 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1748 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1751 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1752 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1755 m_cLogMessage
.SetText(temp
);
1757 m_sLogMessage
= m_cLogMessage
.GetText();
1758 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1760 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1761 if (!sBugID
.IsEmpty())
1763 SetDlgItemText(IDC_BUGID
, sBugID
);
1767 m_cLogMessage
.SetFocus();
1769 SysFreeString(parameters
);
1770 SysFreeString(commonRoot
);
1771 SafeArrayDestroy(pathList
);
1772 SysFreeString(originalMessage
);
1773 SysFreeString(temp
);
1777 void CCommitDlg::FillPatchView()
1779 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1781 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1783 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1784 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1789 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1790 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1791 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1793 CString head
= _T("HEAD");
1794 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
1795 head
= _T("HEAD~1");
1796 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
1797 g_Git
.Run(cmd
,&out
,CP_ACP
);
1801 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1802 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1803 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1806 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
1808 this->FillPatchView();
1813 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1819 void CCommitDlg::UpdateOKButton()
1824 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
1825 bool bAmendOrSelectFiles
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
);
1827 DialogEnableWindow(IDOK
, bValidLogSize
&& bAmendOrSelectFiles
);
1830 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1834 if (wParam
== IDC_SPLITTER
)
1836 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1837 DoSize(pHdr
->delta
);
1842 return __super::DefWindowProc(message
, wParam
, lParam
);
1845 void CCommitDlg::SetSplitterRange()
1847 if ((m_ListCtrl
)&&(m_cLogMessage
))
1850 m_cLogMessage
.GetWindowRect(rcTop
);
1851 ScreenToClient(rcTop
);
1853 m_ListCtrl
.GetWindowRect(rcMiddle
);
1854 ScreenToClient(rcMiddle
);
1855 if (rcMiddle
.Height() && rcMiddle
.Width())
1856 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1860 void CCommitDlg::DoSize(int delta
)
1862 RemoveAnchor(IDC_MESSAGEGROUP
);
1863 RemoveAnchor(IDC_LOGMESSAGE
);
1864 RemoveAnchor(IDC_SPLITTER
);
1865 RemoveAnchor(IDC_SIGNOFF
);
1866 RemoveAnchor(IDC_COMMIT_AMEND
);
1867 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
1868 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
1869 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
1870 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
1871 RemoveAnchor(IDC_LISTGROUP
);
1872 RemoveAnchor(IDC_FILELIST
);
1873 RemoveAnchor(IDC_TEXT_INFO
);
1875 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1876 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1877 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1878 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1879 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1880 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1881 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
1882 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
1883 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
1884 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
1885 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1887 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1888 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1889 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1890 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1891 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1892 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1893 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1894 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
1895 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
1896 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
1897 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
1898 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1900 // adjust the minimum size of the dialog to prevent the resizing from
1901 // moving the list control too far down.
1903 m_cLogMessage
.GetClientRect(rcLogMsg
);
1904 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1907 m_cLogMessage
.Invalidate();
1908 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1911 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1913 // first, let the resizing take place
1914 __super::OnSize(nType
, cx
, cy
);
1920 CString
CCommitDlg::GetSignedOffByLine()
1924 CString username
= g_Git
.GetUserName();
1925 CString email
= g_Git
.GetUserEmail();
1926 username
.Remove(_T('\n'));
1927 email
.Remove(_T('\n'));
1929 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
1934 void CCommitDlg::OnBnClickedSignOff()
1936 CString str
= GetSignedOffByLine();
1938 if (m_cLogMessage
.GetText().Find(str
) == -1) {
1939 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
1940 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
1941 int foundByLine
= -1;
1942 if (lastNewline
> 0)
1943 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
1945 if (foundByLine
== -1 || foundByLine
< lastNewline
)
1946 str
= _T("\r\n") + str
;
1948 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
1952 void CCommitDlg::OnBnClickedCommitAmend()
1955 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
1958 rev
.GetCommit(CString(_T("HEAD")));
1959 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
1962 if(this->m_bCommitAmend
)
1964 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
1965 m_cLogMessage
.SetText(m_AmendStr
);
1966 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1970 this->m_AmendStr
=this->m_cLogMessage
.GetText();
1971 m_cLogMessage
.SetText(m_NoAmendStr
);
1972 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1975 OnBnClickedCommitSetDateTime(); // to update the commit date and time
1980 void CCommitDlg::OnBnClickedWholeProject()
1982 m_tooltips
.Pop(); // hide the tooltips
1988 m_ListCtrl
.GetStatus(NULL
,true,false,true);
1990 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
1992 DWORD dwShow
= (DWORD
)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWUNVERSIONED
| SVNSLC_SHOWLOCKS
);
1993 m_ListCtrl
.Show(m_ListCtrl
.GetShowFlags(), dwShow
& (~CTGitPath::LOGACTIONS_UNVER
|~CTGitPath::LOGACTIONS_IGNORE
));
1999 void CCommitDlg::OnFocusMessage()
2001 m_cLogMessage
.SetFocus();
2004 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2006 UNREFERENCED_PARAMETER(pNMHDR
);
2007 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2008 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2009 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2012 str
.Format(_T("%d/%d"),line
+1,column
+1);
2013 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2018 void CCommitDlg::OnStnClickedViewPatch()
2020 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2021 m_patchViewdlg
.m_ParentCommitDlg
= this;
2022 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2024 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2026 this->GetWindowRect(&rect
);
2028 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2030 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2031 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2033 ShowViewPatchText(false);
2038 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2039 m_patchViewdlg
.DestroyWindow();
2040 ShowViewPatchText(true);
2042 this->m_ctrlShowPatch
.Invalidate();
2045 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2047 __super::OnMoving(fwSide
, pRect
);
2049 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2052 m_patchViewdlg
.GetWindowRect(&patchrect
);
2053 if (::IsWindow(m_hWnd
))
2056 GetWindowRect(&thisrect
);
2057 if (patchrect
.left
== thisrect
.right
)
2059 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2060 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2067 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2069 __super::OnSizing(fwSide
, pRect
);
2071 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2073 CRect thisrect
, patchrect
;
2074 this->GetWindowRect(thisrect
);
2075 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2076 if(thisrect
.right
==patchrect
.left
)
2078 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2079 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2081 if( patchrect
.bottom
== thisrect
.bottom
)
2083 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2085 if( patchrect
.top
== thisrect
.top
)
2087 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2089 m_patchViewdlg
.MoveWindow(patchrect
);
2094 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2096 UNREFERENCED_PARAMETER(pNMHDR
);
2098 TRACE("Item Changed\r\n");
2101 int CCommitDlg::CheckHeadDetach()
2104 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2106 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2107 _T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
2109 CAppUtils::CreateBranchTag(FALSE
,NULL
,true);
2115 void CCommitDlg::OnBnClickedCommitAmenddiff()
2121 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2127 void CCommitDlg::OnBnClickedCommitSetDateTime()
2131 if (m_bSetCommitDateTime
)
2133 CTime authordate
= CTime::GetCurrentTime();
2136 GitRev headRevision
;
2137 headRevision
.GetCommit(_T("HEAD"));
2138 authordate
= headRevision
.GetAuthorDate();
2141 m_CommitDate
.SetTime(&authordate
);
2142 m_CommitTime
.SetTime(&authordate
);
2144 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2145 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2149 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2150 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);