1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2013 - 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 "UnicodeUtils.h"
35 #include "../TGitCache/CacheInterface.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
42 #include "SysProgressDlg.h"
43 #include "MassiveGitTask.h"
48 static char THIS_FILE
[] = __FILE__
;
51 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
52 UINT
CCommitDlg::WM_UPDATEOKBUTTON
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEOKBUTTON"));
53 UINT
CCommitDlg::WM_UPDATEDATAFALSE
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEDATAFALSE"));
55 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
56 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
57 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
59 , m_bShowUnversioned(FALSE
)
61 , m_bThreadRunning(FALSE
)
64 , m_bWholeProject(FALSE
)
65 , m_bKeepChangeList(TRUE
)
66 , m_bDoNotAutoselectSubmodules(FALSE
)
68 , m_bSelectFilesForCommit(TRUE
)
69 , m_bNoPostActions(FALSE
)
71 , m_bSetCommitDateTime(FALSE
)
72 , m_bCreateNewBranch(FALSE
)
73 , m_bCreateTagAfterCommit(FALSE
)
74 , m_bForceCommitAmend(false)
75 , m_bCommitMessageOnly(FALSE
)
78 this->m_bCommitAmend
=FALSE
;
79 m_bPushAfterCommit
= FALSE
;
82 CCommitDlg::~CCommitDlg()
90 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
92 CResizableStandAloneDialog::DoDataExchange(pDX
);
93 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
94 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
95 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
96 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
97 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
98 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
99 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
100 DDX_Text(pDX
, IDC_COMMIT_AUTHORDATA
, m_sAuthor
);
101 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
102 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
103 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
104 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
105 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
106 DDX_Check(pDX
, IDC_COMMIT_MESSAGEONLY
, m_bCommitMessageOnly
);
107 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
108 DDX_Check(pDX
, IDC_COMMIT_SETAUTHOR
, m_bSetAuthor
);
109 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
110 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
111 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
114 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
115 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
116 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
117 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
118 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
119 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
120 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
121 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
122 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
123 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
124 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
125 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
127 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED
, &CCommitDlg::OnCheck
)
128 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
129 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON
, OnUpdateOKButton
)
130 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE
, OnUpdateDataFalse
)
133 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
134 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
135 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
136 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY
, &CCommitDlg::OnBnClickedCommitMessageOnly
)
137 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
138 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
139 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
143 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
144 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
145 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
146 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
147 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
148 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR
, &CCommitDlg::OnBnClickedCommitSetauthor
)
151 BOOL
CCommitDlg::OnInitDialog()
153 CResizableStandAloneDialog::OnInitDialog();
154 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
156 CAppUtils::GetCommitTemplate(this->m_sLogMessage
);
159 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
160 if(PathFileExists(dotGitPath
+ _T("MERGE_MSG")))
163 if(file
.Open(dotGitPath
+ _T("MERGE_MSG"), CFile::modeRead
))
166 while(file
.ReadString(str
))
168 m_sLogMessage
+= str
;
170 m_sLogMessage
+= _T("\n");
175 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
176 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
178 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
179 m_bShowUnversioned
= m_regAddBeforeCommit
;
181 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
183 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
184 m_bKeepChangeList
= m_regKeepChangelists
;
186 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
187 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
189 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
192 // m_bWholeProject = config.KeepLocks();
194 if(this->m_pathList
.GetCount() == 0)
195 m_bWholeProject
=true;
197 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
198 m_bWholeProject
=true;
204 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("CommitDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
)), true, true);
205 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
206 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
207 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
208 m_ListCtrl
.EnableFileDrop();
209 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
211 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
212 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
214 m_cLogMessage
.Init(m_ProjectProperties
);
215 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
216 m_cLogMessage
.RegisterContextMenuHandler(this);
218 OnEnChangeLogmessage();
220 m_tooltips
.Create(this);
221 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
222 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
223 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
225 CBugTraqAssociations bugtraq_associations
;
226 bugtraq_associations
.Load();
228 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
230 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
231 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
233 CComPtr
<IBugTraqProvider
> pProvider
;
234 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
237 m_BugTraqProvider
= pProvider
;
239 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
241 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
242 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
243 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
249 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
251 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
253 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
254 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
255 if (!m_ProjectProperties
.sLabel
.IsEmpty())
256 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
257 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
258 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
259 GetDlgItem(IDC_BUGID
)->SetFocus();
260 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
261 if (!sBugID
.IsEmpty())
263 SetDlgItemText(IDC_BUGID
, sBugID
);
268 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
269 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
270 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
271 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
272 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
275 if (!m_sLogMessage
.IsEmpty())
276 m_cLogMessage
.SetText(m_sLogMessage
);
278 GetWindowText(m_sWindowTitle
);
280 AdjustControlSize(IDC_SHOWUNVERSIONED
);
281 AdjustControlSize(IDC_WHOLE_PROJECT
);
282 AdjustControlSize(IDC_CHECK_NEWBRANCH
);
283 AdjustControlSize(IDC_COMMIT_AMEND
);
284 AdjustControlSize(IDC_COMMIT_MESSAGEONLY
);
285 AdjustControlSize(IDC_COMMIT_AMENDDIFF
);
286 AdjustControlSize(IDC_COMMIT_SETDATETIME
);
287 AdjustControlSize(IDC_COMMIT_SETAUTHOR
);
288 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES
);
289 AdjustControlSize(IDC_KEEPLISTS
);
291 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKALL
);
292 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKNONE
);
293 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKUNVERSIONED
);
294 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKVERSIONED
);
295 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKADDED
);
296 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKDELETED
);
297 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKMODIFIED
);
298 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKFILES
);
299 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKSUBMODULES
);
301 // line up all controls and adjust their sizes.
302 #define LINKSPACING 9
303 RECT rc
= AdjustControlSize(IDC_SELECTLABEL
);
304 rc
.right
-= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
305 rc
= AdjustStaticSize(IDC_CHECKALL
, rc
, LINKSPACING
);
306 rc
= AdjustStaticSize(IDC_CHECKNONE
, rc
, LINKSPACING
);
307 rc
= AdjustStaticSize(IDC_CHECKUNVERSIONED
, rc
, LINKSPACING
);
308 rc
= AdjustStaticSize(IDC_CHECKVERSIONED
, rc
, LINKSPACING
);
309 rc
= AdjustStaticSize(IDC_CHECKADDED
, rc
, LINKSPACING
);
310 rc
= AdjustStaticSize(IDC_CHECKDELETED
, rc
, LINKSPACING
);
311 rc
= AdjustStaticSize(IDC_CHECKMODIFIED
, rc
, LINKSPACING
);
312 rc
= AdjustStaticSize(IDC_CHECKFILES
, rc
, LINKSPACING
);
313 rc
= AdjustStaticSize(IDC_CHECKSUBMODULES
, rc
, LINKSPACING
);
315 GetClientRect(m_DlgOrigRect
);
316 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
318 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
319 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
320 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
321 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
322 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
323 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
324 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
325 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
326 // AddAnchor(IDC_HISTORY, TOP_LEFT);
327 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
328 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
329 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
330 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
331 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
332 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
333 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
334 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
335 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
336 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
337 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
338 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
339 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
340 AddAnchor(IDOK
, BOTTOM_RIGHT
);
341 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
342 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
343 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
344 AddAnchor(IDC_COMMIT_MESSAGEONLY
, BOTTOM_LEFT
);
345 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
346 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
347 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
348 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
349 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
350 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
352 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
353 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
354 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
355 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
356 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
357 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
358 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
359 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
360 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
361 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
364 CenterWindow(CWnd::FromHandle(hWndExplorer
));
365 EnableSaveRestore(_T("CommitDlg"));
366 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
367 RECT rcDlg
, rcLogMsg
, rcFileList
;
368 GetClientRect(&rcDlg
);
369 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
370 ScreenToClient(&rcLogMsg
);
371 m_ListCtrl
.GetWindowRect(&rcFileList
);
372 ScreenToClient(&rcFileList
);
376 m_wndSplitter
.GetWindowRect(&rectSplitter
);
377 ScreenToClient(&rectSplitter
);
378 int delta
= yPos
- rectSplitter
.top
;
379 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
381 m_wndSplitter
.SetWindowPos(NULL
, rectSplitter
.left
, yPos
, 0, 0, SWP_NOSIZE
);
388 // add all directories to the watcher
390 for (int i=0; i<m_pathList.GetCount(); ++i)
392 if (m_pathList[i].IsDirectory())
393 m_pathwatcher.AddPath(m_pathList[i]);
396 m_updatedPathList
= m_pathList
;
398 //first start a thread to obtain the file list with the status without
399 //blocking the dialog
400 InterlockedExchange(&m_bBlock
, TRUE
);
401 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
404 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
405 InterlockedExchange(&m_bBlock
, FALSE
);
409 m_pThread
->m_bAutoDelete
= FALSE
;
410 m_pThread
->ResumeThread();
412 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
413 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
414 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
417 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
421 this->m_ctrlShowPatch
.SetURL(CString());
423 BOOL viewPatchEnabled
= FALSE
;
424 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
425 if (viewPatchEnabled
)
426 OnStnClickedViewPatch();
428 return FALSE
; // return TRUE unless you set the focus to a control
429 // EXCEPTION: OCX Property Pages should return FALSE
432 void CCommitDlg::OnOK()
436 if (m_bThreadRunning
)
439 InterlockedExchange(&m_bRunThread
, FALSE
);
440 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
441 if (m_bThreadRunning
)
443 // we gave the thread a chance to quit. Since the thread didn't
444 // listen to us we have to kill it.
445 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
446 InterlockedExchange(&m_bThreadRunning
, FALSE
);
451 if (m_bCreateNewBranch
)
453 if (!g_Git
.IsBranchNameValid(m_sCreateNewBranch
))
455 ShowEditBalloon(IDC_NEWBRANCH
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
458 if (g_Git
.BranchTagExists(m_sCreateNewBranch
))
460 // branch already exists
462 msg
.LoadString(IDS_B_EXISTS
);
463 msg
+= _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME
));
464 ShowEditBalloon(IDC_NEWBRANCH
, msg
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
467 if (g_Git
.BranchTagExists(m_sCreateNewBranch
, false))
469 // tag with the same name exists -> shortref is ambiguous
470 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
476 GetDlgItemText(IDC_BUGID
, id
);
477 if (!m_ProjectProperties
.CheckBugID(id
))
479 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, TTI_ERROR
);
482 m_sLogMessage
= m_cLogMessage
.GetText();
483 if ( m_sLogMessage
.IsEmpty() )
485 // no message entered, go round again
486 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
489 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
491 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
495 BOOL bWarnNoSignedOffBy
= FALSE
;
496 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
497 if (bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
499 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
);
502 OnBnClickedSignOff();
503 m_sLogMessage
= m_cLogMessage
.GetText();
505 else if (retval
== 3)
509 int nListItems
= m_ListCtrl
.GetItemCount();
510 for (int i
= 0; i
< nListItems
&& !m_bCommitMessageOnly
; ++i
)
512 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
513 if (!entry
->m_Checked
|| !entry
->IsDirectory())
517 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
520 subgit
.m_CurrentDir
= g_Git
.m_CurrentDir
+ _T("\\") + entry
->GetWinPathString();
522 subgit
.Run(_T("git.exe status --porcelain"), &subcmdout
, CP_UTF8
);
523 dirty
= !subcmdout
.IsEmpty();
528 cmd
.Format(_T("git.exe diff -- \"%s\""), entry
->GetWinPathString());
529 g_Git
.Run(cmd
, &cmdout
, CP_UTF8
);
530 dirty
= cmdout
.Right(7) == _T("-dirty\n");
536 message
.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY
)), entry
->GetGitPathString());
537 int result
= CMessageBox::Show(m_hWnd
, message
, _T("TortoiseGit"), 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_IGNORE
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL
)));
541 cmdCommit
.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git
.m_CurrentDir
, entry
->GetWinPathString());
542 CAppUtils::RunTortoiseGitProc(cmdCommit
);
545 else if (result
== 2)
552 if (!m_bCommitMessageOnly
)
553 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
554 m_pathwatcher
.Stop();
555 InterlockedExchange(&m_bBlock
, TRUE
);
556 CDWordArray arDeleted
;
557 //first add all the unversioned files the user selected
558 //and check if all versioned files are selected
562 CTGitPathList itemsToAdd
;
563 CTGitPathList itemsToRemove
;
564 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
569 bool bAddSuccess
=true;
570 bool bCloseCommitDlg
=false;
572 CSysProgressDlg sysProgressDlg
;
573 if (nListItems
>= 25)
575 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
576 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
577 sysProgressDlg
.SetTime(true);
578 sysProgressDlg
.SetShowProgressBar(true);
579 sysProgressDlg
.ShowModal(this, true);
582 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
583 DWORD currentTicks
= GetTickCount();
585 if (g_Git
.m_IsUseLibGit2
)
590 git_repository
*repository
= nullptr;
591 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
592 if (git_repository_open(&repository
, gitdir
.GetBuffer()))
594 gitdir
.ReleaseBuffer();
595 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
598 gitdir
.ReleaseBuffer();
601 git_config_new(&config
);
603 CStringA projectConfigA
= CUnicodeUtils::GetMulti(g_Git
.GetGitLocalConfig(), CP_UTF8
);
604 if (git_config_add_file_ondisk(config
, projectConfigA
.GetBuffer(), 4, FALSE
))
606 projectConfigA
.ReleaseBuffer();
607 git_config_free(config
);
608 git_repository_free(repository
);
609 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open project config.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
612 projectConfigA
.ReleaseBuffer();
613 CString globalConfig
= g_Git
.GetGitGlobalConfig();
614 if (PathFileExists(globalConfig
))
616 CStringA globalConfigA
= CUnicodeUtils::GetMulti(globalConfig
, CP_UTF8
);
617 if (git_config_add_file_ondisk(config
, globalConfigA
.GetBuffer(), 3, FALSE
))
619 globalConfigA
.ReleaseBuffer();
620 git_config_free(config
);
621 git_repository_free(repository
);
622 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open global config.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
625 globalConfigA
.ReleaseBuffer();
627 CString globalXDGConfig
= g_Git
.GetGitGlobalXDGConfig();
628 if (PathFileExists(globalXDGConfig
))
630 CStringA globalXDGConfigA
= CUnicodeUtils::GetMulti(globalXDGConfig
, CP_UTF8
);
631 if (git_config_add_file_ondisk(config
, globalXDGConfigA
.GetBuffer(), 2, FALSE
))
633 globalXDGConfigA
.ReleaseBuffer();
634 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open xdg config config.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
635 git_config_free(config
);
636 git_repository_free(repository
);
639 globalXDGConfigA
.ReleaseBuffer();
641 CString systemConfig
= g_Git
.GetGitSystemConfig();
642 if (!systemConfig
.IsEmpty())
644 CStringA systemConfigA
= CUnicodeUtils::GetMulti(systemConfig
, CP_UTF8
);
645 if (git_config_add_file_ondisk(config
, systemConfigA
.GetBuffer(), 1, FALSE
))
647 systemConfigA
.ReleaseBuffer();
648 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open system config.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
649 git_config_free(config
);
650 git_repository_free(repository
);
653 systemConfigA
.ReleaseBuffer();
656 git_repository_set_config(repository
, config
);
659 CString revRef
= _T("HEAD");
660 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
661 revRef
= _T("HEAD~1");
662 if (g_Git
.GetHash(revHash
, revRef
))
664 git_repository_free(repository
);
665 git_config_free(config
);
666 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
670 git_commit
*commit
= nullptr;
671 if (git_commit_lookup(&commit
, repository
, (const git_oid
*)revHash
.m_hash
))
673 git_repository_free(repository
);
674 git_config_free(config
);
675 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
679 git_tree
*tree
= nullptr;
680 if (git_commit_tree(&tree
, commit
))
682 git_commit_free(commit
);
683 git_repository_free(repository
);
684 git_config_free(config
);
685 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
689 git_index
*index
= nullptr;
690 if (git_repository_index(&index
, repository
))
693 git_commit_free(commit
);
694 git_repository_free(repository
);
695 git_config_free(config
);
696 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get the repository index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
700 // reset index to the one of the reference commit (HEAD or HEAD~1)
701 if (git_index_read_tree(index
, tree
))
703 git_index_free(index
);
705 git_commit_free(commit
);
706 git_repository_free(repository
);
707 git_config_free(config
);
708 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
714 for (int j
= 0; j
< nListItems
; ++j
)
716 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
718 if (sysProgressDlg
.IsVisible())
720 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
722 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
723 sysProgressDlg
.SetProgress(j
, nListItems
);
724 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
725 currentTicks
= GetTickCount();
729 CStringA filePathA
= CUnicodeUtils::GetMulti(entry
->GetGitPathString(), CP_UTF8
);
731 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
733 if (entry
->IsDirectory())
735 git_submodule
*submodule
= nullptr;
736 if (git_submodule_lookup(&submodule
, repository
, filePathA
.GetBuffer()))
738 filePathA
.ReleaseBuffer();
740 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry
->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
743 filePathA
.ReleaseBuffer();
744 if (git_submodule_add_to_index(submodule
, FALSE
))
747 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
751 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
753 git_index_remove_bypath(index
, filePathA
.GetBuffer()); // ignore error
754 filePathA
.ReleaseBuffer();
758 if (git_index_add_bypath(index
, filePathA
.GetBuffer()))
760 filePathA
.ReleaseBuffer();
762 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
765 filePathA
.ReleaseBuffer();
768 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
770 git_index_remove_bypath(index
, filePathA
.GetBuffer()); // ignore error
771 filePathA
.ReleaseBuffer();
776 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
777 mgtReAddAfterCommit
.AddFile(*entry
);
779 if (sysProgressDlg
.HasUserCancelled())
785 CShellUpdater::Instance().AddPathForUpdate(*entry
);
787 if (bAddSuccess
&& git_index_write(index
))
790 git_index_free(index
);
792 git_commit_free(commit
);
793 git_repository_free(repository
);
794 git_config_free(config
);
799 // ***************************************************
800 // ATTENTION: Similar code in RebaseDlg.cpp!!!
801 // ***************************************************
802 for (int j
= 0; j
< nListItems
; ++j
)
804 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
805 if (sysProgressDlg
.IsVisible())
807 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
809 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
810 sysProgressDlg
.SetProgress(j
, nListItems
);
811 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
812 currentTicks
= GetTickCount();
815 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
817 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
818 cmd
.Format(_T("git.exe add -f -- \"%s\""), entry
->GetGitPathString());
819 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
820 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""), entry
->GetGitPathString());
822 cmd
.Format(_T("git.exe update-index -- \"%s\""), entry
->GetGitPathString());
824 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
826 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
827 bAddSuccess
= false ;
831 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
832 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
834 g_Git
.Run(cmd
, &out
, CP_UTF8
);
840 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
841 { //To init git repository, there are not HEAD, so we can use git reset command
842 cmd
.Format(_T("git.exe rm -f --cache -- \"%s\""), entry
->GetGitPathString());
843 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
845 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
846 bAddSuccess
= false ;
847 bCloseCommitDlg
=false;
850 mgtReAddAfterCommit
.AddFile(*entry
);
852 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
854 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
855 cmd
.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry
->GetGitOldPathString());
857 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitOldPathString());
858 g_Git
.Run(cmd
, &out
, CP_UTF8
);
861 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
863 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
865 cmd
.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry
->GetGitPathString());
869 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
871 g_Git
.Run(cmd
, &out
, CP_UTF8
);
872 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
&& !sysProgressDlg
.HasUserCancelled())
877 if (sysProgressDlg
.HasUserCancelled())
883 CShellUpdater::Instance().AddPathForUpdate(*entry
);
887 sysProgressDlg
.Stop();
889 if (bAddSuccess
&& m_bCreateNewBranch
)
891 if (g_Git
.Run(_T("git branch ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
893 MessageBox(_T("Creating new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
896 if (g_Git
.Run(_T("git checkout ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
898 MessageBox(_T("Switching to new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
903 if (bAddSuccess
&& CheckHeadDetach())
907 CString sExistingBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
908 sExistingBugID
.Trim();
909 if (!m_sBugID
.IsEmpty() && m_sBugID
.Compare(sExistingBugID
))
911 m_sBugID
.Replace(_T(", "), _T(","));
912 m_sBugID
.Replace(_T(" ,"), _T(","));
913 CString sBugID
= m_ProjectProperties
.sMessage
;
914 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
915 if (m_ProjectProperties
.bAppend
)
916 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
918 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
921 // now let the bugtraq plugin check the commit message
922 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
923 if (m_BugTraqProvider
)
925 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
929 CString common
= g_Git
.m_CurrentDir
;
930 BSTR repositoryRoot
= common
.AllocSysString();
931 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
932 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
933 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
934 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
936 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
937 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
939 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
943 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
944 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
948 CString sError
= temp
;
949 if (!sError
.IsEmpty())
951 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
959 if (m_bCommitMessageOnly
|| bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
961 bCloseCommitDlg
= true;
963 CString tempfile
=::GetTempFile();
965 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
967 CTGitPath path
=g_Git
.m_CurrentDir
;
969 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
973 if(this->m_bCommitAmend
)
978 if (m_bSetCommitDateTime
)
981 m_CommitDate
.GetTime(date
);
982 m_CommitTime
.GetTime(time
);
983 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
987 author
.Format(_T("--author=\"%s\""), m_sAuthor
);
988 CString allowEmpty
= m_bCommitMessageOnly
? _T("--allow-empty") : _T("");
989 cmd
.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author
, dateTime
, amend
, allowEmpty
, tempfile
);
991 CCommitProgressDlg progress
;
992 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
993 progress
.m_GitCmd
=cmd
;
994 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
995 progress
.m_PreText
= out
; // show any output already generated in log window
996 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
998 int indexReCommit
= -1;
1001 if (!m_bNoPostActions
&& !m_bAutoClose
)
1004 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)));
1005 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
1006 indexReCommit
= (int)progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT
)));
1007 indexTag
= (int)progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG
)));
1010 INT_PTR userResponse
= progress
.DoModal();
1012 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+ indexReCommit
))
1014 bCloseCommitDlg
= false;
1015 if (userResponse
== IDC_PROGRESS_BUTTON1
+ indexReCommit
)
1017 this->m_sLogMessage
.Empty();
1018 m_cLogMessage
.SetText(m_sLogMessage
);
1021 m_bCommitAmend
= FALSE
;
1025 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ indexTag
)
1027 m_bCreateTagAfterCommit
=true;
1029 else if (userResponse
>= IDC_PROGRESS_BUTTON1
&& userResponse
< IDC_PROGRESS_BUTTON1
+ indexReCommit
)
1031 // User pressed 'DCommit' or 'Push' button after successful commit.
1032 m_bPushAfterCommit
=true;
1033 if (userResponse
== IDC_PROGRESS_BUTTON1
&& IsGitSVN
)
1034 m_PostCmd
= GIT_POST_CMD_DCOMMIT
;
1036 m_PostCmd
= GIT_POST_CMD_PUSH
;
1039 CFile::Remove(tempfile
);
1041 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
1043 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
1044 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1047 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1048 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
1050 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1051 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
1053 BSTR logMessage
= m_sLogMessage
.AllocSysString();
1056 if (g_Git
.GetHash(hash
, _T("HEAD")))
1057 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
1058 LONG version
= g_Git
.Hash2int(hash
);
1061 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
1068 CString sErr
= temp
;
1069 if (!sErr
.IsEmpty())
1070 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1074 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
1075 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1079 SysFreeString(temp
);
1082 RestoreFiles(progress
.m_GitStatus
== 0);
1083 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1085 BOOL cancel
= FALSE
;
1086 mgtReAddAfterCommit
.Execute(cancel
);
1089 else if(bAddSuccess
)
1091 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
1092 bCloseCommitDlg
=false;
1096 m_regAddBeforeCommit
= m_bShowUnversioned
;
1097 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
1098 m_bWholeProject
= FALSE
;
1099 m_regKeepChangelists
= m_bKeepChangeList
;
1100 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1101 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1102 m_bKeepChangeList
= FALSE
;
1103 InterlockedExchange(&m_bBlock
, FALSE
);
1105 if (!m_sLogMessage
.IsEmpty())
1107 m_History
.AddEntry(m_sLogMessage
);
1113 if( bCloseCommitDlg
)
1114 CResizableStandAloneDialog::OnOK();
1116 CShellUpdater::Instance().Flush();
1119 void CCommitDlg::SaveSplitterPos()
1123 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1125 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1126 ScreenToClient(&rectSplitter
);
1127 regPos
= rectSplitter
.top
;
1131 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1133 return ((CCommitDlg
*)pVoid
)->StatusThread();
1136 UINT
CCommitDlg::StatusThread()
1138 //get the status of all selected file/folders recursively
1139 //and show the ones which have to be committed to the user
1140 //in a list control.
1141 InterlockedExchange(&m_bBlock
, TRUE
);
1142 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1143 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1145 m_pathwatcher
.Stop();
1147 m_ListCtrl
.SetBusy(true);
1148 g_Git
.RefreshGitIndex();
1150 m_bCancelled
= false;
1152 DialogEnableWindow(IDOK
, false);
1153 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1154 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1155 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1156 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1157 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1158 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1159 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1160 // read the list of recent log entries before querying the WC for status
1161 // -> the user may select one and modify / update it while we are crawling the WC
1163 DialogEnableWindow(IDC_CHECKALL
, false);
1164 DialogEnableWindow(IDC_CHECKNONE
, false);
1165 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1166 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1167 DialogEnableWindow(IDC_CHECKADDED
, false);
1168 DialogEnableWindow(IDC_CHECKDELETED
, false);
1169 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1170 DialogEnableWindow(IDC_CHECKFILES
, false);
1171 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1173 if (m_History
.GetCount()==0)
1176 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1177 reg
.Replace(_T(':'),_T('_'));
1178 m_History
.Load(reg
, _T("logmsgs"));
1181 // Initialise the list control with the status of the files/folders below us
1184 CTGitPathList
*pList
;
1185 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1186 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1191 pList
= &m_pathList
;
1193 success
=m_ListCtrl
.GetStatus(pList
);
1195 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1196 if(this->m_bShowUnversioned
)
1197 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1199 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1201 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
;
1202 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1205 if (m_checkedPathList
.GetCount())
1206 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1209 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1210 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1211 m_ListCtrl
.Show(dwShow
, dwCheck
);
1212 m_bSelectFilesForCommit
= true;
1215 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1217 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1218 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1221 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1222 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1226 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1227 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1228 m_ListCtrl
.Show(dwShow
);
1232 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1233 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1234 && !PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
1237 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1238 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1240 m_bShowUnversioned
= TRUE
;
1241 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1242 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1243 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1244 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1251 // we don't have to block the commit dialog while we fetch the
1252 // auto completion list.
1253 m_pathwatcher
.ClearChangedPaths();
1254 InterlockedExchange(&m_bBlock
, FALSE
);
1255 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1257 m_ListCtrl
.Block(TRUE
, TRUE
);
1258 GetAutocompletionList();
1259 m_ListCtrl
.Block(FALSE
, FALSE
);
1261 SendMessage(WM_UPDATEOKBUTTON
);
1264 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1265 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1266 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1267 if (m_ListCtrl
.HasChangeLists())
1268 DialogEnableWindow(IDC_KEEPLISTS
, true);
1269 if (m_ListCtrl
.HasLocks())
1270 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1272 // activate amend checkbox (if necessary)
1273 if (g_Git
.IsInitRepos())
1275 m_bCommitAmend
= FALSE
;
1276 SendMessage(WM_UPDATEDATAFALSE
);
1280 if (m_bForceCommitAmend
)
1282 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1283 m_bCommitAmend
= TRUE
;
1284 SendMessage(WM_UPDATEDATAFALSE
);
1287 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(TRUE
);
1290 if (g_Git
.GetHash(hash
, _T("HEAD")))
1292 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
1294 if (!hash
.IsEmpty())
1296 GitRev headRevision
;
1299 headRevision
.GetParentFromHash(hash
);
1304 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
1306 // do not allow to show diff to "last" revision if it has more that one parent
1307 if (headRevision
.ParentsCount() != 1)
1309 m_bAmendDiffToLastCommit
= true;
1310 SendMessage(WM_UPDATEDATAFALSE
);
1313 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1319 // we have the list, now signal the main thread about it
1320 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1323 InterlockedExchange(&m_bRunThread
, FALSE
);
1324 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1325 // force the cursor to normal
1331 void CCommitDlg::SetDlgTitle()
1333 if (m_sTitle
.IsEmpty())
1334 GetWindowText(m_sTitle
);
1336 if (m_bWholeProject
)
1337 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1340 if (m_pathList
.GetCount() == 1)
1341 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1343 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1347 void CCommitDlg::OnCancel()
1349 m_bCancelled
= true;
1350 m_pathwatcher
.Stop();
1352 if (m_bThreadRunning
)
1354 InterlockedExchange(&m_bRunThread
, FALSE
);
1355 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1356 if (m_bThreadRunning
)
1358 // we gave the thread a chance to quit. Since the thread didn't
1359 // listen to us we have to kill it.
1360 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1361 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1366 m_sLogMessage
= m_cLogMessage
.GetText();
1367 if (!m_sBugID
.IsEmpty())
1369 m_sBugID
.Replace(_T(", "), _T(","));
1370 m_sBugID
.Replace(_T(" ,"), _T(","));
1371 CString sBugID
= m_ProjectProperties
.sMessage
;
1372 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1373 if (m_ProjectProperties
.bAppend
)
1374 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1376 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1378 if ((m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1380 m_History
.AddEntry(m_sLogMessage
);
1385 CResizableStandAloneDialog::OnCancel();
1388 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1391 m_tooltips
.RelayEvent(pMsg
);
1395 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1400 if (pMsg
->message
== WM_KEYDOWN
)
1402 switch (pMsg
->wParam
)
1407 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1413 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1415 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1417 PostMessage(WM_COMMAND
, IDOK
);
1421 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1423 // Pressing RETURN in the bug id control
1424 // moves the focus to the message
1425 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1433 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1436 void CCommitDlg::Refresh()
1438 if (m_bThreadRunning
)
1441 InterlockedExchange(&m_bBlock
, TRUE
);
1442 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1443 if (m_pThread
==NULL
)
1445 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1446 InterlockedExchange(&m_bBlock
, FALSE
);
1450 m_pThread
->m_bAutoDelete
= FALSE
;
1451 m_pThread
->ResumeThread();
1455 void CCommitDlg::OnBnClickedHelp()
1460 void CCommitDlg::OnBnClickedShowunversioned()
1462 m_tooltips
.Pop(); // hide the tooltips
1464 m_regAddBeforeCommit
= m_bShowUnversioned
;
1467 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1468 if (DWORD(m_regAddBeforeCommit
))
1469 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1471 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1472 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1475 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1477 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1479 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1484 void CCommitDlg::OnStnClickedExternalwarning()
1489 void CCommitDlg::OnEnChangeLogmessage()
1491 SendMessage(WM_UPDATEOKBUTTON
);
1494 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1497 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1499 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1501 m_bShowUnversioned
= TRUE
;
1502 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1503 m_ListCtrl
.Show(dwShow
);
1511 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1517 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1521 SetForegroundWindow();
1523 // if multiple files/folders are dropped
1524 // this handler is called for every single item
1526 // To avoid creating multiple refresh threads and
1527 // causing crashes, we only add the items to the
1528 // list control and start a timer.
1529 // When the timer expires, we start the refresh thread,
1530 // but only if it isn't already running - otherwise we
1531 // restart the timer.
1533 path
.SetFromWin((LPCTSTR
)lParam
);
1535 // just add all the items we get here.
1536 // if the item is versioned, the add will fail but nothing
1537 // more will happen.
1539 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1541 if (!m_ListCtrl
.HasPath(path
))
1543 if (m_pathList
.AreAllPathsFiles())
1545 m_pathList
.AddPath(path
);
1546 m_pathList
.RemoveDuplicates();
1547 m_updatedPathList
.AddPath(path
);
1548 m_updatedPathList
.RemoveDuplicates();
1552 // if the path list contains folders, we have to check whether
1553 // our just (maybe) added path is a child of one of those. If it is
1554 // a child of a folder already in the list, we must not add it. Otherwise
1555 // that path could show up twice in the list.
1556 bool bHasParentInList
= false;
1557 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1559 if (m_pathList
[i
].IsAncestorOf(path
))
1561 bHasParentInList
= true;
1565 if (!bHasParentInList
)
1567 m_pathList
.AddPath(path
);
1568 m_pathList
.RemoveDuplicates();
1569 m_updatedPathList
.AddPath(path
);
1570 m_updatedPathList
.RemoveDuplicates();
1575 // Always start the timer, since the status of an existing item might have changed
1576 SetTimer(REFRESHTIMER
, 200, NULL
);
1577 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1582 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1584 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1588 //////////////////////////////////////////////////////////////////////////
1589 // functions which run in the status thread
1590 //////////////////////////////////////////////////////////////////////////
1592 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1597 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1598 while (m_bRunThread
&& file
.ReadString(strLine
))
1600 int eqpos
= strLine
.Find('=');
1602 rgx
= strLine
.Mid(eqpos
+1).Trim();
1605 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1607 mapRegex
[strLine
.Left(pos
)] = rgx
;
1608 strLine
= strLine
.Mid(pos
+1).Trim();
1610 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1614 catch (CFileException
* pE
)
1616 TRACE("CFileException loading auto list regex file\n");
1621 void CCommitDlg::GetAutocompletionList()
1623 // the auto completion list is made of strings from each selected files.
1624 // the strings used are extracted from the files with regexes found
1625 // in the file "autolist.txt".
1626 // the format of that file is:
1627 // file extensions separated with commas '=' regular expression to use
1629 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1630 // .cpp = (?<=[^\s]::)\b\w+\b
1632 std::map
<CString
, CString
> mapRegex
;
1633 CString sRegexFile
= CPathUtils::GetAppDirectory();
1634 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1635 DWORD timeoutvalue
= regtimeout
*1000;
1636 sRegexFile
+= _T("autolist.txt");
1639 ParseRegexFile(sRegexFile
, mapRegex
);
1640 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1641 sRegexFile
.ReleaseBuffer();
1642 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1643 if (PathFileExists(sRegexFile
))
1645 ParseRegexFile(sRegexFile
, mapRegex
);
1647 DWORD starttime
= GetTickCount();
1649 // now we have two arrays of strings, where the first array contains all
1650 // file extensions we can use and the second the corresponding regex strings
1651 // to apply to those files.
1653 // the next step is to go over all files shown in the commit dialog
1654 // and scan them for strings we can use
1655 int nListItems
= m_ListCtrl
.GetItemCount();
1657 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1659 // stop parsing after timeout
1660 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1663 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1668 CString sPartPath
=path
->GetGitPathString();
1669 m_autolist
.insert(sPartPath
);
1671 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1675 // add the path parts to the auto completion list too
1676 // CString sPartPath = entry->GetRelativeGitPath();
1677 // m_autolist.insert(sPartPath);
1682 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1686 m_autolist
.insert(sPartPath
.Mid(pos
));
1689 // Last inserted entry is a file name.
1690 // Some users prefer to also list file name without extension.
1691 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1693 int dotPos
= sPartPath
.ReverseFind('.');
1694 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1695 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1698 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1701 CString sExt
= entry
->GetPath().GetFileExtension();
1703 // find the regex string which corresponds to the file extension
1704 CString rdata
= mapRegex
[sExt
];
1705 if (rdata
.IsEmpty())
1708 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1709 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1710 (entry
->textstatus
!= Git_wc_status_none
) &&
1711 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1712 (entry
->textstatus
!= Git_wc_status_added
) &&
1713 (entry
->textstatus
!= Git_wc_status_normal
))
1715 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1716 if (!basePath
.IsEmpty())
1717 ScanFile(basePath
.GetWinPathString(), rdata
);
1721 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1724 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1726 wstring sFileContent
;
1727 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1728 if (hFile
!= INVALID_HANDLE_VALUE
)
1730 DWORD size
= GetFileSize(hFile
, NULL
);
1731 if (size
> 1000000L)
1733 // no files bigger than 1 Meg
1737 // allocate memory to hold file contents
1738 char * buffer
= new char[size
];
1740 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1743 IsTextUnicode(buffer
, readbytes
, &opts
);
1744 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1749 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1751 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1753 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1755 int ret
= MultiByteToWideChar(CP_UTF8
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1756 wchar_t * pWideBuf
= new wchar_t[ret
];
1757 int ret2
= MultiByteToWideChar(CP_UTF8
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1759 sFileContent
= wstring(pWideBuf
, ret
);
1764 if (sFileContent
.empty()|| !m_bRunThread
)
1771 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1772 const tr1::wsregex_iterator end
;
1773 wstring s
= sFileContent
;
1774 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1776 const tr1::wsmatch match
= *it
;
1777 for (size_t i
=1; i
<match
.size(); ++i
)
1779 if (match
[i
].second
-match
[i
].first
)
1781 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1782 m_autolist
.insert(wstring(match
[i
]).c_str());
1787 catch (exception
) {}
1790 // CSciEditContextMenuInterface
1791 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1793 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1794 m_nPopupPasteListCmd
= nCmd
++;
1795 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1797 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1798 if(m_History
.GetCount() > 0)
1800 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1801 m_nPopupPasteLastMessage
= nCmd
++;
1802 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1804 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1805 m_nPopupRecentMessage
= nCmd
++;
1806 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1812 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1817 if (cmd
== m_nPopupPasteListCmd
)
1820 int nListItems
= m_ListCtrl
.GetItemCount();
1821 for (int i
=0; i
<nListItems
; ++i
)
1823 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1824 if (entry
&&entry
->m_Checked
)
1827 CString status
= entry
->GetActionName();
1828 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1829 status
= _T("Add"); // I18N TODO
1831 //git_wc_status_kind status = entry->status;
1832 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1833 if (m_ProjectProperties
.bFileListInEnglish
)
1836 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1840 pSciEdit
->InsertText(logmsg
);
1844 if(cmd
== m_nPopupPasteLastMessage
)
1846 if(m_History
.GetCount() ==0 )
1850 logmsg
+=m_History
.GetEntry(0);
1851 pSciEdit
->InsertText(logmsg
);
1855 if(cmd
== m_nPopupRecentMessage
)
1857 OnBnClickedHistory();
1863 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1867 case ENDDIALOGTIMER
:
1868 KillTimer(ENDDIALOGTIMER
);
1872 if (m_bThreadRunning
)
1874 SetTimer(REFRESHTIMER
, 200, NULL
);
1875 ATLTRACE("Wait some more before refreshing\n");
1879 KillTimer(REFRESHTIMER
);
1880 ATLTRACE("Refreshing after items dropped\n");
1884 case FILLPATCHVTIMER
:
1888 __super::OnTimer(nIDEvent
);
1891 void CCommitDlg::OnBnClickedHistory()
1893 m_tooltips
.Pop(); // hide the tooltips
1894 if (m_pathList
.GetCount() == 0)
1897 CHistoryDlg historyDlg
;
1898 historyDlg
.SetHistory(m_History
);
1899 if (historyDlg
.DoModal() != IDOK
)
1902 CString sMsg
= historyDlg
.GetSelectedText();
1903 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1905 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
1906 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
1908 SetDlgItemText(IDC_BUGID
, sBugID
);
1910 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1911 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1913 m_cLogMessage
.SetText(sMsg
);
1916 SendMessage(WM_UPDATEOKBUTTON
);
1917 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1921 void CCommitDlg::OnBnClickedBugtraqbutton()
1923 m_tooltips
.Pop(); // hide the tooltips
1924 CString sMsg
= m_cLogMessage
.GetText();
1926 if (m_BugTraqProvider
== NULL
)
1929 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1930 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1931 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1933 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1934 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1936 BSTR originalMessage
= sMsg
.AllocSysString();
1938 // m_revProps.clear();
1940 // first try the IBugTraqProvider2 interface
1941 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1942 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1943 bool bugIdOutSet
= false;
1946 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1947 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1948 BSTR bugIDOut
= NULL
;
1949 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1950 BSTR bugID
= m_sBugID
.AllocSysString();
1951 SAFEARRAY
* revPropNames
= NULL
;
1952 SAFEARRAY
* revPropValues
= NULL
;
1953 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1956 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1957 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1964 m_sBugID
= bugIDOut
;
1965 SysFreeString(bugIDOut
);
1966 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1968 SysFreeString(bugID
);
1969 SysFreeString(repositoryRoot
);
1970 m_cLogMessage
.SetText(temp
);
1971 BSTR HUGEP
*pbRevNames
;
1972 BSTR HUGEP
*pbRevValues
;
1974 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1977 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1980 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1982 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; ++i
)
1984 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1987 SafeArrayUnaccessData(revPropValues
);
1989 SafeArrayUnaccessData(revPropNames
);
1992 SafeArrayDestroy(revPropNames
);
1994 SafeArrayDestroy(revPropValues
);
1999 // if IBugTraqProvider2 failed, try IBugTraqProvider
2000 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
2001 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2005 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2006 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2010 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2013 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2014 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2017 m_cLogMessage
.SetText(temp
);
2019 m_sLogMessage
= m_cLogMessage
.GetText();
2020 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2022 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2023 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2025 SetDlgItemText(IDC_BUGID
, sBugID
);
2029 m_cLogMessage
.SetFocus();
2031 SysFreeString(parameters
);
2032 SysFreeString(commonRoot
);
2033 SafeArrayDestroy(pathList
);
2034 SysFreeString(originalMessage
);
2035 SysFreeString(temp
);
2038 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2040 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2042 KillTimer(FILLPATCHVTIMER
);
2045 SetTimer(FILLPATCHVTIMER
, 100, NULL
);
2048 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
2050 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2051 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
2056 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2057 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
2058 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2060 CString head
= _T("HEAD");
2061 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2062 head
= _T("HEAD~1");
2063 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
2064 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2068 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
2069 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
2070 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
2072 m_patchViewdlg
.m_ctrlPatchView
.GetClientRect(rect
);
2073 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect
.Width() - 4);
2076 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2078 this->FillPatchView(true);
2083 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2085 SendMessage(WM_UPDATEOKBUTTON
);
2089 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2091 HWND hwnd
= (HWND
)wnd
;
2092 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2093 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2094 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2095 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2096 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2097 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2098 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2099 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2100 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2101 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2102 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2103 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2104 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2105 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2106 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2107 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2108 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2109 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2110 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2115 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2120 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
2121 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2123 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2128 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2134 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2138 if (wParam
== IDC_SPLITTER
)
2140 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2141 DoSize(pHdr
->delta
);
2146 return __super::DefWindowProc(message
, wParam
, lParam
);
2149 void CCommitDlg::SetSplitterRange()
2151 if ((m_ListCtrl
)&&(m_cLogMessage
))
2154 m_cLogMessage
.GetWindowRect(rcTop
);
2155 ScreenToClient(rcTop
);
2157 m_ListCtrl
.GetWindowRect(rcMiddle
);
2158 ScreenToClient(rcMiddle
);
2159 if (rcMiddle
.Height() && rcMiddle
.Width())
2160 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2164 void CCommitDlg::DoSize(int delta
)
2166 RemoveAnchor(IDC_MESSAGEGROUP
);
2167 RemoveAnchor(IDC_LOGMESSAGE
);
2168 RemoveAnchor(IDC_SPLITTER
);
2169 RemoveAnchor(IDC_SIGNOFF
);
2170 RemoveAnchor(IDC_COMMIT_AMEND
);
2171 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2172 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2173 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2174 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2175 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2176 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2177 RemoveAnchor(IDC_LISTGROUP
);
2178 RemoveAnchor(IDC_FILELIST
);
2179 RemoveAnchor(IDC_TEXT_INFO
);
2180 RemoveAnchor(IDC_SELECTLABEL
);
2181 RemoveAnchor(IDC_CHECKALL
);
2182 RemoveAnchor(IDC_CHECKNONE
);
2183 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2184 RemoveAnchor(IDC_CHECKVERSIONED
);
2185 RemoveAnchor(IDC_CHECKADDED
);
2186 RemoveAnchor(IDC_CHECKDELETED
);
2187 RemoveAnchor(IDC_CHECKMODIFIED
);
2188 RemoveAnchor(IDC_CHECKFILES
);
2189 RemoveAnchor(IDC_CHECKSUBMODULES
);
2191 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2192 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2193 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2194 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2195 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2196 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2197 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2198 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2199 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2200 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2201 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2202 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2203 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2204 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2205 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2206 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2207 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2208 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2209 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2210 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2211 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2212 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2213 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2215 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2216 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2217 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2218 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2219 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2220 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2221 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2222 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2223 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2224 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2225 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2226 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2227 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2228 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2229 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2230 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2231 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2232 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2233 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2234 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2235 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2236 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2237 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2238 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2240 // adjust the minimum size of the dialog to prevent the resizing from
2241 // moving the list control too far down.
2243 m_cLogMessage
.GetClientRect(rcLogMsg
);
2244 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2247 m_cLogMessage
.Invalidate();
2248 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2251 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2253 // first, let the resizing take place
2254 __super::OnSize(nType
, cx
, cy
);
2260 CString
CCommitDlg::GetSignedOffByLine()
2264 CString username
= g_Git
.GetUserName();
2265 CString email
= g_Git
.GetUserEmail();
2266 username
.Remove(_T('\n'));
2267 email
.Remove(_T('\n'));
2269 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
2274 void CCommitDlg::OnBnClickedSignOff()
2276 CString str
= GetSignedOffByLine();
2278 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2279 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2280 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
2281 int foundByLine
= -1;
2282 if (lastNewline
> 0)
2283 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2285 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2286 str
= _T("\r\n") + str
;
2288 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2292 void CCommitDlg::OnBnClickedCommitAmend()
2295 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2298 rev
.GetCommit(CString(_T("HEAD")));
2299 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2302 if(this->m_bCommitAmend
)
2304 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2305 m_cLogMessage
.SetText(m_AmendStr
);
2306 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2310 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2311 m_cLogMessage
.SetText(m_NoAmendStr
);
2312 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2315 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2316 OnBnClickedCommitSetauthor(); // to update the commit author
2318 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2322 void CCommitDlg::OnBnClickedCommitMessageOnly()
2325 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2326 SendMessage(WM_UPDATEOKBUTTON
);
2329 void CCommitDlg::OnBnClickedWholeProject()
2331 m_tooltips
.Pop(); // hide the tooltips
2337 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2339 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2341 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2342 if (DWORD(m_regAddBeforeCommit
))
2343 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2345 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2347 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2354 void CCommitDlg::OnFocusMessage()
2356 m_cLogMessage
.SetFocus();
2359 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2361 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2362 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2363 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2366 str
.Format(_T("%d/%d"),line
+1,column
+1);
2367 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2372 void CCommitDlg::OnStnClickedViewPatch()
2374 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2375 m_patchViewdlg
.m_ParentCommitDlg
= this;
2376 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2378 BOOL viewPatchEnabled
= FALSE
;
2379 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
2380 if (viewPatchEnabled
== FALSE
)
2381 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2382 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2383 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2385 this->GetWindowRect(&rect
);
2387 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2389 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2390 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2392 ShowViewPatchText(false);
2397 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2398 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2399 m_patchViewdlg
.DestroyWindow();
2400 ShowViewPatchText(true);
2402 this->m_ctrlShowPatch
.Invalidate();
2405 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2407 __super::OnMoving(fwSide
, pRect
);
2409 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2412 m_patchViewdlg
.GetWindowRect(&patchrect
);
2413 if (::IsWindow(m_hWnd
))
2416 GetWindowRect(&thisrect
);
2417 if (patchrect
.left
== thisrect
.right
)
2419 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2420 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2427 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2429 __super::OnSizing(fwSide
, pRect
);
2431 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2433 CRect thisrect
, patchrect
;
2434 this->GetWindowRect(thisrect
);
2435 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2436 if(thisrect
.right
==patchrect
.left
)
2438 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2439 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2441 if( patchrect
.bottom
== thisrect
.bottom
)
2443 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2445 if( patchrect
.top
== thisrect
.top
)
2447 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2449 m_patchViewdlg
.MoveWindow(patchrect
);
2454 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2457 TRACE("Item Changed\r\n");
2460 int CCommitDlg::CheckHeadDetach()
2463 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2465 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2468 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2471 else if (retval
== IDCANCEL
)
2477 void CCommitDlg::OnBnClickedCommitAmenddiff()
2483 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2489 void CCommitDlg::OnBnClickedCommitSetDateTime()
2493 if (m_bSetCommitDateTime
)
2495 CTime authordate
= CTime::GetCurrentTime();
2498 GitRev headRevision
;
2499 headRevision
.GetCommit(_T("HEAD"));
2500 authordate
= headRevision
.GetAuthorDate();
2503 m_CommitDate
.SetTime(&authordate
);
2504 m_CommitTime
.SetTime(&authordate
);
2506 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2507 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2511 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2512 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2516 void CCommitDlg::OnBnClickedCheckNewBranch()
2519 if (m_bCreateNewBranch
)
2521 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2522 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2526 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2527 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2531 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2533 if (!m_ListCtrl
.m_restorepaths
.empty() && (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))
2535 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2536 CopyFile(it
->second
, g_Git
.m_CurrentDir
+ _T("\\") + it
->first
, FALSE
);
2537 m_ListCtrl
.m_restorepaths
.clear();
2541 void CCommitDlg::UpdateCheckLinks()
2543 DialogEnableWindow(IDC_CHECKALL
, true);
2544 DialogEnableWindow(IDC_CHECKNONE
, true);
2545 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2546 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2547 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2548 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2549 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2550 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2551 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2554 void CCommitDlg::OnBnClickedCommitSetauthor()
2560 m_sAuthor
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
2563 GitRev headRevision
;
2564 headRevision
.GetCommit(_T("HEAD"));
2565 m_sAuthor
.Format(_T("%s <%s>"), headRevision
.GetAuthorName(), headRevision
.GetAuthorEmail());
2570 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2573 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);