1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2011 - TortoiseSVN
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.
22 #include "TortoiseProc.h"
23 #include "PathUtils.h"
25 //#include "GitProperties.h"
26 #include "StringUtils.h"
27 #include "MessageBox.h"
31 //#include "RepositoryBrowser.h"
32 //#include "BrowseFolder.h"
33 #include "UnicodeUtils.h"
34 #include "ExportDlg.h"
35 #include "ProgressDlg.h"
36 #include "GitAdminDir.h"
37 #include "ProgressDlg.h"
38 #include "BrowseFolder.h"
39 #include "DirFileEnum.h"
40 #include "MessageBox.h"
41 #include "GitStatus.h"
42 #include "CreateBranchTagDlg.h"
43 #include "GitSwitchDlg.h"
45 #include "DeleteConflictDlg.h"
46 #include "ChangedDlg.h"
47 #include "SendMailDlg.h"
48 #include "GITProgressDlg.h"
50 #include "CommitDlg.h"
53 #include "..\Settings\Settings.h"
55 #include "SVNDCommitDlg.h"
56 #include "requestpulldlg.h"
57 #include "PullFetchDlg.h"
58 #include "RebaseDlg.h"
60 #include "StashSave.h"
61 #include "FormatMessageWrapper.h"
63 CAppUtils::CAppUtils(void)
67 CAppUtils::~CAppUtils(void)
71 bool CAppUtils::StashSave()
75 if (dlg
.DoModal() == IDOK
)
78 cmd
= _T("git.exe stash save");
80 if (dlg
.m_bIncludeUntracked
&& CAppUtils::GetMsysgitVersion() >= 0x01070700)
81 cmd
+= _T(" --include-untracked");
83 if (!dlg
.m_sMessage
.IsEmpty())
85 CString message
= dlg
.m_sMessage
;
86 message
.Replace(_T("\""), _T("\"\""));
87 cmd
+= _T(" \"") + message
+ _T("\"");
90 if (g_Git
.Run(cmd
, &out
, CP_ACP
))
92 CMessageBox::Show(NULL
, CString(_T("<ct=0x0000FF>Stash Fail!!!</ct>\n")) + out
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
96 CMessageBox::Show(NULL
, CString(_T("<ct=0xff0000>Stash Success</ct>\n")) + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
103 int CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
106 cmd
= _T("git.exe stash apply ");
107 if (ref
.Find(_T("refs/")) == 0)
109 if (ref
.Find(_T("stash{")) == 0)
110 ref
= _T("stash@") + ref
.Mid(5);
113 int ret
= g_Git
.Run(cmd
, &out
, CP_ACP
);
114 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
115 if (ret
&& !(ret
== 1 && hasConflicts
))
117 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
121 CString withConflicts
;
123 withConflicts
= _T(" with conflicts");
126 if(CMessageBox::Show(NULL
,CString(_T("<ct=0xff0000>Stash Apply Success") + withConflicts
+ _T("</ct>\nDo you want to show change?"))
127 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
130 dlg
.m_pathList
.AddPath(CTGitPath());
137 CMessageBox::Show(NULL
, _T("<ct=0xff0000>Stash Apply Success") + withConflicts
+ _T("</ct>") ,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
144 int CAppUtils::StashPop(bool showChanges
/* true */)
147 cmd
=_T("git.exe stash pop ");
149 int ret
= g_Git
.Run(cmd
, &out
, CP_ACP
);
150 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
151 if (ret
&& !(ret
== 1 && hasConflicts
))
153 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash POP Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
157 CString message
= _T("<ct=0xff0000>Stash POP Success</ct>");
159 message
= _T("<ct=0x000000ff>Stash POP Failed, there are conflicts</ct>");
162 if(CMessageBox::Show(NULL
,CString(message
+ _T("\nDo you want to show change?"))
163 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
166 dlg
.m_pathList
.AddPath(CTGitPath());
173 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
180 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
183 GitProperties
props(file
, GitRev::REV_WC
, false);
184 for (int i
= 0; i
< props
.GetCount(); ++i
)
186 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
188 mimetype
= props
.GetItemValue(i
).c_str();
196 BOOL
CAppUtils::StartExtMerge(
197 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
198 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
201 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
202 CString ext
= mergedfile
.GetFileExtension();
203 CString com
= regCom
;
204 bool bInternal
= false;
209 // is there an extension specific merge tool?
210 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
211 if (CString(mergetool
) != "")
216 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
218 // is there a mime type specific merge tool?
219 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
220 if (CString(mergetool
) != "")
226 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
230 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
231 com
= tortoiseMergePath
;
234 com
= CPathUtils::GetAppDirectory();
235 com
+= _T("TortoiseMerge.exe");
237 com
= _T("\"") + com
+ _T("\"");
238 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
239 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
241 // check if the params are set. If not, just add the files to the command line
242 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
244 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
245 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
246 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
247 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
249 if (basefile
.IsEmpty())
251 com
.Replace(_T("/base:%base"), _T(""));
252 com
.Replace(_T("%base"), _T(""));
255 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
256 if (theirfile
.IsEmpty())
258 com
.Replace(_T("/theirs:%theirs"), _T(""));
259 com
.Replace(_T("%theirs"), _T(""));
262 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
263 if (yourfile
.IsEmpty())
265 com
.Replace(_T("/mine:%mine"), _T(""));
266 com
.Replace(_T("%mine"), _T(""));
269 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
270 if (mergedfile
.IsEmpty())
272 com
.Replace(_T("/merged:%merged"), _T(""));
273 com
.Replace(_T("%merged"), _T(""));
276 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
277 if (basename
.IsEmpty())
279 if (basefile
.IsEmpty())
281 com
.Replace(_T("/basename:%bname"), _T(""));
282 com
.Replace(_T("%bname"), _T(""));
286 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
290 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
291 if (theirname
.IsEmpty())
293 if (theirfile
.IsEmpty())
295 com
.Replace(_T("/theirsname:%tname"), _T(""));
296 com
.Replace(_T("%tname"), _T(""));
300 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
304 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
305 if (yourname
.IsEmpty())
307 if (yourfile
.IsEmpty())
309 com
.Replace(_T("/minename:%yname"), _T(""));
310 com
.Replace(_T("%yname"), _T(""));
314 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
318 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
319 if (mergedname
.IsEmpty())
321 if (mergedfile
.IsEmpty())
323 com
.Replace(_T("/mergedname:%mname"), _T(""));
324 com
.Replace(_T("%mname"), _T(""));
328 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
332 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
334 if ((bReadOnly
)&&(bInternal
))
335 com
+= _T(" /readonly");
337 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
345 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
349 viewer
= CPathUtils::GetAppDirectory();
350 viewer
+= _T("TortoiseMerge.exe");
352 viewer
= _T("\"") + viewer
+ _T("\"");
353 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
354 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
356 viewer
+= _T(" /reversedpatch");
357 if (!sOriginalDescription
.IsEmpty())
358 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
359 if (!sPatchedDescription
.IsEmpty())
360 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
361 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
368 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
370 // Is there a mime type specific diff tool?
372 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
374 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
375 if (!difftool
.IsEmpty())
379 // Is there an extension specific diff tool?
380 CString ext
= file2
.GetFileExtension().MakeLower();
383 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
384 if (!difftool
.IsEmpty())
386 // Maybe we should use TortoiseIDiff?
387 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
388 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
389 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
390 (ext
== _T(".dib")) || (ext
== _T(".emf")))
393 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
394 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
398 // Finally, pick a generic external diff tool
399 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
403 bool CAppUtils::StartExtDiff(
404 const CString
& file1
, const CString
& file2
,
405 const CString
& sName1
, const CString
& sName2
,
406 const DiffFlags
& flags
)
410 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
411 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
413 viewer
= PickDiffTool(file1
, file2
);
414 // If registry entry for a diff program is commented out, use TortoiseMerge.
415 bool bCommentedOut
= viewer
.Left(1) == _T("#");
416 if (flags
.bAlternativeTool
)
418 // Invert external vs. internal diff tool selection.
420 viewer
.Delete(0); // uncomment
424 else if (bCommentedOut
)
428 bool bInternal
= viewer
.IsEmpty();
432 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
433 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
435 viewer
+= _T(" /blame");
437 // check if the params are set. If not, just add the files to the command line
438 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
440 viewer
+= _T(" \"")+file1
+_T("\"");
441 viewer
+= _T(" \"")+file2
+_T("\"");
443 if (viewer
.Find(_T("%base")) >= 0)
445 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
447 if (viewer
.Find(_T("%mine")) >= 0)
449 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
452 if (sName1
.IsEmpty())
453 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
455 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
457 if (sName2
.IsEmpty())
458 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
460 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
462 if (flags
.bReadOnly
&& bInternal
)
463 viewer
+= _T(" /readonly");
465 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
468 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
471 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
473 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
476 viewer
= CPathUtils::GetAppDirectory();
477 viewer
+= _T("TortoiseUDiff.exe");
478 // enquote the path to TortoiseUDiff
479 viewer
= _T("\"") + viewer
+ _T("\"");
481 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
484 if (viewer
.Find(_T("%1"))>=0)
486 if (viewer
.Find(_T("\"%1\"")) >= 0)
487 viewer
.Replace(_T("%1"), patchfile
);
489 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
492 viewer
+= _T(" \"") + patchfile
+ _T("\"");
493 if (viewer
.Find(_T("%title")) >= 0)
495 viewer
.Replace(_T("%title"), title
);
498 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
505 BOOL
CAppUtils::StartTextViewer(CString file
)
508 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
510 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
511 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
514 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
515 TCHAR
* buf
= new TCHAR
[len
+1];
516 ExpandEnvironmentStrings(viewer
, buf
, len
);
519 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
520 buf
= new TCHAR
[len
+1];
521 ExpandEnvironmentStrings(file
, buf
, len
);
524 file
= _T("\"")+file
+_T("\"");
525 if (viewer
.IsEmpty())
527 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
529 if (viewer
.Find(_T("\"%1\"")) >= 0)
531 viewer
.Replace(_T("\"%1\""), file
);
533 else if (viewer
.Find(_T("%1")) >= 0)
535 viewer
.Replace(_T("%1"), file
);
543 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
550 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
553 HANDLE hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
554 if (hFile
== INVALID_HANDLE_VALUE
)
556 length
= ::GetFileSize(hFile
, NULL
);
557 ::CloseHandle(hFile
);
564 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
567 HDC hScreenDC
= ::GetDC(NULL
);
568 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
569 ::ReleaseDC(NULL
, hScreenDC
);
571 logFont
.lfEscapement
= 0;
572 logFont
.lfOrientation
= 0;
573 logFont
.lfWeight
= FW_NORMAL
;
574 logFont
.lfItalic
= 0;
575 logFont
.lfUnderline
= 0;
576 logFont
.lfStrikeOut
= 0;
577 logFont
.lfCharSet
= DEFAULT_CHARSET
;
578 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
579 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
580 logFont
.lfQuality
= DRAFT_QUALITY
;
581 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
582 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
583 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
586 bool CAppUtils::LaunchApplication(const CString
& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
)
589 PROCESS_INFORMATION process
;
590 memset(&startup
, 0, sizeof(startup
));
591 startup
.cb
= sizeof(startup
);
592 memset(&process
, 0, sizeof(process
));
594 CString
cleanCommandLine(sCommandLine
);
596 if (CreateProcess(NULL
, const_cast<TCHAR
*>((LPCTSTR
)cleanCommandLine
), NULL
, NULL
, FALSE
, 0, 0, g_Git
.m_CurrentDir
, &startup
, &process
)==0)
598 if(idErrMessageFormat
!= 0)
601 temp
.Format(idErrMessageFormat
, CFormatMessageWrapper());
602 MessageBox(NULL
, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
609 WaitForInputIdle(process
.hProcess
, 10000);
612 CloseHandle(process
.hThread
);
613 CloseHandle(process
.hProcess
);
616 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
630 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
631 key
= g_Git
.GetConfigValue(cmd
);
633 key
= key
.Tokenize(_T("\n"),start
);
641 CString proc
=CPathUtils::GetAppDirectory();
642 proc
+= _T("pageant.exe \"");
646 CString tempfile
= GetTempFile();
647 ::DeleteFile(tempfile
);
649 proc
+= _T(" -c \"");
650 proc
+= CPathUtils::GetAppDirectory();
651 proc
+= _T("touch.exe\"");
656 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true);
661 while(!::PathFileExists(tempfile
))
666 break; //timeout 5 minutes
671 CMessageBox::Show(NULL
, _T("Fail wait for pageant finish load key"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
673 ::DeleteFile(tempfile
);
676 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
)
678 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
679 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
680 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
684 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
686 LaunchApplication(sCmd
, NULL
, false);
689 bool CAppUtils::LaunchRemoteSetting()
691 CTGitPath
path(g_Git
.m_CurrentDir
);
692 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
693 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
694 //dlg.SetTreeWidth(220);
695 dlg
.m_DefaultPage
= _T("gitremote");
702 * Launch the external blame viewer
704 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
706 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
707 viewer
+= _T("TortoiseGitBlame.exe");
708 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
709 //viewer += _T(" \"") + sLogFile + _T("\"");
710 //viewer += _T(" \"") + sOriginalFile + _T("\"");
711 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
712 viewer
+= CString(_T(" /rev:"))+Rev
;
713 viewer
+= _T(" ")+sParams
;
715 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
718 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
723 bool bStyled
= false;
724 pWnd
->GetWindowText(sText
);
725 // the rich edit control doesn't count the CR char!
726 // to be exact: CRLF is treated as one char.
729 // style each line separately
734 nNewlinePos
= sText
.Find('\n', offset
);
735 CString sLine
= sText
.Mid(offset
);
737 sLine
= sLine
.Left(nNewlinePos
-offset
);
740 while (FindStyleChars(sLine
, '*', start
, end
))
742 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
743 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
745 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
746 format
.cbSize
= sizeof(CHARFORMAT2
);
747 format
.dwMask
= CFM_BOLD
;
748 format
.dwEffects
= CFE_BOLD
;
749 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
755 while (FindStyleChars(sLine
, '^', start
, end
))
757 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
758 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
760 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
761 format
.cbSize
= sizeof(CHARFORMAT2
);
762 format
.dwMask
= CFM_ITALIC
;
763 format
.dwEffects
= CFE_ITALIC
;
764 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
770 while (FindStyleChars(sLine
, '_', start
, end
))
772 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
773 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
775 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
776 format
.cbSize
= sizeof(CHARFORMAT2
);
777 format
.dwMask
= CFM_UNDERLINE
;
778 format
.dwEffects
= CFE_UNDERLINE
;
779 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
783 offset
= nNewlinePos
+1;
784 } while(nNewlinePos
>=0);
788 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
791 bool bFoundMarker
= false;
792 // find a starting marker
793 while (sText
[i
] != 0)
795 if (sText
[i
] == stylechar
)
797 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
798 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
810 // find ending marker
811 bFoundMarker
= false;
812 while (sText
[i
] != 0)
814 if (sText
[i
] == stylechar
)
816 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
817 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
830 bool CAppUtils::FileOpenSave(CString
& path
, int * filterindex
, UINT title
, UINT filter
, bool bOpen
, HWND hwndOwner
)
832 OPENFILENAME ofn
= {0}; // common dialog box structure
833 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
834 ofn
.lStructSize
= sizeof(OPENFILENAME
);
835 ofn
.hwndOwner
= hwndOwner
;
836 _tcscpy_s(szFile
, MAX_PATH
, (LPCTSTR
)path
);
837 ofn
.lpstrFile
= szFile
;
838 ofn
.nMaxFile
= _countof(szFile
);
840 TCHAR
* pszFilters
= NULL
;
843 sFilter
.LoadString(filter
);
844 pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
845 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
846 // Replace '|' delimiters with '\0's
847 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
848 while (ptr
!= pszFilters
)
854 ofn
.lpstrFilter
= pszFilters
;
856 ofn
.nFilterIndex
= 1;
857 ofn
.lpstrFileTitle
= NULL
;
858 ofn
.nMaxFileTitle
= 0;
859 ofn
.lpstrInitialDir
= NULL
;
863 temp
.LoadString(title
);
864 CStringUtils::RemoveAccelerators(temp
);
866 ofn
.lpstrTitle
= temp
;
868 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_EXPLORER
;
870 ofn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_EXPLORER
;
873 // Display the Open dialog box.
877 bRet
= !!GetOpenFileName(&ofn
);
881 bRet
= !!GetSaveFileName(&ofn
);
886 delete [] pszFilters
;
887 path
= CString(ofn
.lpstrFile
);
889 *filterindex
= ofn
.nFilterIndex
;
893 delete [] pszFilters
;
897 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl
, UINT nID
, int width
/* = 128 */, int height
/* = 128 */)
899 ListView_SetTextBkColor(hListCtrl
, CLR_NONE
);
900 COLORREF bkColor
= ListView_GetBkColor(hListCtrl
);
901 // create a bitmap from the icon
902 HICON hIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID
), IMAGE_ICON
, width
, height
, LR_DEFAULTCOLOR
);
908 rect
.bottom
= height
;
911 HWND desktop
= ::GetDesktopWindow();
914 HDC screen_dev
= ::GetDC(desktop
);
917 // Create a compatible DC
918 HDC dst_hdc
= ::CreateCompatibleDC(screen_dev
);
921 // Create a new bitmap of icon size
922 bmp
= ::CreateCompatibleBitmap(screen_dev
, rect
.right
, rect
.bottom
);
925 // Select it into the compatible DC
926 HBITMAP old_dst_bmp
= (HBITMAP
)::SelectObject(dst_hdc
, bmp
);
927 // Fill the background of the compatible DC with the given color
928 ::SetBkColor(dst_hdc
, bkColor
);
929 ::ExtTextOut(dst_hdc
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
931 // Draw the icon into the compatible DC
932 ::DrawIconEx(dst_hdc
, 0, 0, hIcon
, rect
.right
, rect
.bottom
, 0, NULL
, DI_NORMAL
);
933 ::SelectObject(dst_hdc
, old_dst_bmp
);
938 ::ReleaseDC(desktop
, screen_dev
);
948 lv
.ulFlags
= LVBKIF_TYPE_WATERMARK
;
950 lv
.xOffsetPercent
= 100;
951 lv
.yOffsetPercent
= 100;
952 ListView_SetBkImage(hListCtrl
, &lv
);
956 CString
CAppUtils::GetProjectNameFromURL(CString url
)
959 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
960 (name
.CompareNoCase(_T("tags"))==0) ||
961 (name
.CompareNoCase(_T("trunk"))==0))
963 name
= url
.Mid(url
.ReverseFind('/')+1);
964 url
= url
.Left(url
.ReverseFind('/'));
966 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
968 // a name of svn or svnroot indicates that it's not really the project name. In that
969 // case, we try the first part of the URL
970 // of course, this won't work in all cases (but it works for Google project hosting)
971 url
.Replace(_T("http://"), _T(""));
972 url
.Replace(_T("https://"), _T(""));
973 url
.Replace(_T("svn://"), _T(""));
974 url
.Replace(_T("svn+ssh://"), _T(""));
975 url
.TrimLeft(_T("/"));
976 name
= url
.Left(url
.Find('.'));
981 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
982 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
983 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
984 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
987 CString tempfile
=GetTempFile();
989 if(rev1
== GitRev::GetWorkingCopy())
991 cmd
.Format(_T("git.exe diff --stat -p %s "),rev2
);
999 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
1002 if( !url1
.IsEmpty() )
1004 cmd
+= _T(" -- \"");
1005 cmd
+= url1
.GetGitPathString();
1008 g_Git
.RunLogFile(cmd
,tempfile
);
1009 CAppUtils::StartUnifiedDiffViewer(tempfile
,rev1
.Left(6)+_T(":")+rev2
.Left(6));
1014 sCmd
.Format(_T("%s /command:showcompare /unified"),
1015 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1016 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1018 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1019 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1021 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1023 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1024 if (headpeg
.IsValid())
1025 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1028 sCmd
+= _T(" /alternatediff");
1030 if (bIgnoreAncestry
)
1031 sCmd
+= _T(" /ignoreancestry");
1035 sCmd
+= _T(" /hwnd:");
1037 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1041 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1047 bool CAppUtils::Export(CString
*BashHash
)
1051 // ask from where the export has to be done
1054 dlg
.m_Revision
=*BashHash
;
1056 if (dlg
.DoModal() == IDOK
)
1059 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
1060 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1070 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1072 CCreateBranchTagDlg dlg
;
1074 dlg
.m_bSwitch
=switch_new_brach
;
1077 dlg
.m_Base
= *CommitHash
;
1079 if(dlg
.DoModal()==IDOK
)
1085 track
=_T(" --track ");
1096 cmd
.Format(_T("git.exe tag %s %s %s %s %s"),
1100 dlg
.m_BranchTagName
,
1101 g_Git
.FixBranchName(dlg
.m_VersionName
)
1104 CString tempfile
=::GetTempFile();
1105 if(!dlg
.m_Message
.Trim().IsEmpty())
1107 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1108 cmd
+= _T(" -F ")+tempfile
;
1113 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1116 dlg
.m_BranchTagName
,
1117 g_Git
.FixBranchName(dlg
.m_VersionName
)
1121 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1123 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1125 if( !IsTag
&& dlg
.m_bSwitch
)
1127 // it is a new branch and the user has requested to switch to it
1128 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1129 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1130 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1138 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
, bool autoclose
)
1142 dlg
.m_Base
=*CommitHash
;
1143 if(!initialRefName
.IsEmpty())
1144 dlg
.m_initialRefName
= initialRefName
;
1146 if (dlg
.DoModal() == IDOK
)
1150 branch
= dlg
.m_NewBranch
;
1152 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
== TRUE
, autoclose
);
1157 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, bool bTrack
/* false */, bool autoClose
/* false */)
1164 if(!sNewBranch
.IsEmpty()){
1165 if (bBranchOverride
)
1167 branch
.Format(_T("-B %s"), sNewBranch
);
1171 branch
.Format(_T("-b %s"), sNewBranch
);
1174 track
= _T("--track");
1179 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1183 g_Git
.FixBranchName(ref
));
1185 CProgressDlg progress
;
1186 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1187 progress
.m_GitCmd
= cmd
;
1189 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1190 if (gitPath
.HasSubmodules())
1191 progress
.m_PostCmdList
.Add(_T("Update Submodules"));
1193 int ret
= progress
.DoModal();
1194 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1197 sCmd
.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR
)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), (LPCTSTR
)g_Git
.m_CurrentDir
);
1199 LaunchApplication(sCmd
, NULL
, false);
1202 else if (ret
== IDOK
)
1208 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1211 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1215 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1220 ignorefile
+= _T("\\.gitignore");
1224 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1226 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1234 //file.ReadString(ignorelist);
1236 for(int i
=0;i
<path
.GetCount();i
++)
1240 mask
=_T("*")+path
[i
].GetFileExtension();
1241 if(ignorelist
.Find(mask
)<0)
1242 ignorelist
+= _T("\n")+mask
;
1246 ignorelist
+= _T("\n/")+path
[i
].GetGitPathString();
1249 file
.WriteString(ignorelist
);
1263 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1266 dlg
.m_ResetType
=type
;
1267 dlg
.m_ResetToVersion
=*CommitHash
;
1268 if (dlg
.DoModal() == IDOK
)
1272 switch(dlg
.m_ResetType
)
1287 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1289 CProgressDlg progress
;
1290 progress
.m_GitCmd
=cmd
;
1292 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1293 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1294 progress
.m_PostCmdList
.Add(_T("Update Submodules"));
1296 int ret
= progress
.DoModal();
1297 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1300 sCmd
.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)g_Git
.m_CurrentDir
);
1302 LaunchApplication(sCmd
, NULL
, false);
1305 else if (ret
== IDOK
)
1312 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1316 descript
=_T("Deleted");
1321 descript
=_T("Modified");
1324 descript
=_T("Created");
1328 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1330 CString tempmergefile
;
1333 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1334 CFile::Remove(tempmergefile
);
1341 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1342 CFile::Remove(tempmergefile
);
1349 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1350 CFile::Remove(tempmergefile
);
1355 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1358 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1363 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1367 CTGitPath merge
=path
;
1368 CTGitPath directory
= merge
.GetDirectory();
1370 // we have the conflicted file (%merged)
1371 // now look for the other required files
1373 //stat.GetStatus(merge);
1374 //if (stat.status == NULL)
1380 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1382 if (g_Git
.Run(cmd
, &vector
))
1388 list
.ParserFromLsFile(vector
);
1390 if(list
.GetCount() == 0)
1397 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1398 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1399 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1403 //format=_T("git.exe cat-file blob \":%d:%s\"");
1404 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1406 //create a empty file, incase stage is not three
1407 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1409 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1411 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1414 bool b_base
=false, b_local
=false, b_remote
=false;
1416 for(int i
=0;i
<list
.GetCount();i
++)
1423 if( list
[i
].m_Stage
== 1)
1425 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1427 outfile
= base
.GetWinPathString();
1430 if( list
[i
].m_Stage
== 2 )
1432 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1434 outfile
= mine
.GetWinPathString();
1437 if( list
[i
].m_Stage
== 3 )
1439 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1441 outfile
= theirs
.GetWinPathString();
1443 CString output
, err
;
1444 if(!outfile
.IsEmpty())
1445 if (!g_Git
.Run(cmd
, &output
, &err
, CP_ACP
))
1449 file
= output
.Tokenize(_T("\t"), start
);
1450 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1454 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1458 if(b_local
&& b_remote
)
1460 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1462 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1464 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1469 CFile::Remove(mine
.GetWinPathString());
1470 CFile::Remove(theirs
.GetWinPathString());
1471 CFile::Remove(base
.GetWinPathString());
1473 CDeleteConflictDlg dlg
;
1474 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1475 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1476 dlg
.m_bShowModifiedButton
=b_base
;
1477 dlg
.m_File
=merge
.GetGitPathString();
1478 if(dlg
.DoModal() == IDOK
)
1483 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1486 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1488 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
1490 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1500 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1501 base
, theirs
, mine
, merge
);
1504 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1506 // we have a text conflict, use our merge tool to resolve the conflict
1508 CTSVNPath
theirs(directory
);
1509 CTSVNPath
mine(directory
);
1510 CTSVNPath
base(directory
);
1511 bool bConflictData
= false;
1513 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1515 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1516 bConflictData
= true;
1518 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1520 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1521 bConflictData
= true;
1523 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1525 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1526 bConflictData
= true;
1533 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1534 base
, theirs
, mine
, merge
);
1537 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1539 // we have a property conflict
1540 CTSVNPath
prej(directory
);
1541 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1543 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1544 // there's a problem: the prej file contains a _description_ of the conflict, and
1545 // that description string might be translated. That means we have no way of parsing
1546 // the file to find out the conflicting values.
1547 // The only thing we can do: show a dialog with the conflict description, then
1548 // let the user either accept the existing property or open the property edit dialog
1549 // to manually change the properties and values. And a button to mark the conflict as
1551 CEditPropConflictDlg dlg
;
1552 dlg
.SetPrejFile(prej
);
1553 dlg
.SetConflictedItem(merge
);
1554 bRet
= (dlg
.DoModal() != IDCANCEL
);
1558 if (stat
.status
->tree_conflict
)
1560 // we have a tree conflict
1562 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1565 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1567 CTSVNPath
theirs(directory
);
1568 CTSVNPath
mine(directory
);
1569 CTSVNPath
base(directory
);
1570 bool bConflictData
= false;
1572 if (pInfoData
->treeconflict_theirfile
)
1574 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1575 bConflictData
= true;
1577 if (pInfoData
->treeconflict_basefile
)
1579 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1580 bConflictData
= true;
1582 if (pInfoData
->treeconflict_myfile
)
1584 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1585 bConflictData
= true;
1592 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1593 base
, theirs
, mine
, merge
);
1595 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1597 CString sConflictAction
;
1598 CString sConflictReason
;
1599 CString sResolveTheirs
;
1600 CString sResolveMine
;
1601 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1602 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1604 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1606 switch (pInfoData
->treeconflict_operation
)
1608 case svn_wc_operation_update
:
1609 switch (pInfoData
->treeconflict_action
)
1611 case svn_wc_conflict_action_edit
:
1612 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1613 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1615 case svn_wc_conflict_action_add
:
1616 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1617 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1619 case svn_wc_conflict_action_delete
:
1620 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1621 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1625 case svn_wc_operation_switch
:
1626 switch (pInfoData
->treeconflict_action
)
1628 case svn_wc_conflict_action_edit
:
1629 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1630 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1632 case svn_wc_conflict_action_add
:
1633 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1634 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1636 case svn_wc_conflict_action_delete
:
1637 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1638 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1642 case svn_wc_operation_merge
:
1643 switch (pInfoData
->treeconflict_action
)
1645 case svn_wc_conflict_action_edit
:
1646 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1647 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1649 case svn_wc_conflict_action_add
:
1650 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1651 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1653 case svn_wc_conflict_action_delete
:
1654 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1655 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1661 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1663 switch (pInfoData
->treeconflict_operation
)
1665 case svn_wc_operation_update
:
1666 switch (pInfoData
->treeconflict_action
)
1668 case svn_wc_conflict_action_edit
:
1669 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1670 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1672 case svn_wc_conflict_action_add
:
1673 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1674 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1676 case svn_wc_conflict_action_delete
:
1677 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1678 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1682 case svn_wc_operation_switch
:
1683 switch (pInfoData
->treeconflict_action
)
1685 case svn_wc_conflict_action_edit
:
1686 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1687 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1689 case svn_wc_conflict_action_add
:
1690 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1691 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1693 case svn_wc_conflict_action_delete
:
1694 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1695 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1699 case svn_wc_operation_merge
:
1700 switch (pInfoData
->treeconflict_action
)
1702 case svn_wc_conflict_action_edit
:
1703 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1704 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1706 case svn_wc_conflict_action_add
:
1707 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1708 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1710 case svn_wc_conflict_action_delete
:
1711 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1712 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1720 switch (pInfoData
->treeconflict_reason
)
1722 case svn_wc_conflict_reason_edited
:
1723 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1724 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1726 case svn_wc_conflict_reason_obstructed
:
1727 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1728 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1730 case svn_wc_conflict_reason_deleted
:
1731 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1732 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1734 case svn_wc_conflict_reason_added
:
1735 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1736 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1738 case svn_wc_conflict_reason_missing
:
1739 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1740 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1742 case svn_wc_conflict_reason_unversioned
:
1743 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1744 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1747 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1749 CTreeConflictEditorDlg dlg
;
1750 dlg
.SetConflictInfoText(sConflictReason
);
1751 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1752 dlg
.SetPath(treeConflictPath
);
1753 INT_PTR dlgRet
= dlg
.DoModal();
1754 bRet
= (dlgRet
!= IDCANCEL
);
1763 * FUNCTION : FormatDateAndTime
1764 * DESCRIPTION : Generates a displayable string from a CTime object in
1765 * system short or long format or as a relative value
1767 * option - DATE_SHORTDATE or DATE_LONGDATE
1768 * bIncluedeTime - whether to show time as well as date
1769 * bRelative - if true then relative time is shown if reasonable
1770 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1771 * rather than locale
1772 * RETURN : CString containing date/time
1774 CString
CAppUtils::FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
/*=true*/,
1775 bool bRelative
/*=false*/)
1780 datetime
= ToRelativeTimeString( cTime
);
1784 // should we use the locale settings for formatting the date/time?
1785 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
))
1789 cTime
.GetAsSystemTime( sysTime
);
1793 GetDateFormat(LOCALE_USER_DEFAULT
, option
, &sysTime
, NULL
, buf
,
1798 datetime
+= _T(" ");
1799 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &sysTime
, NULL
, buf
, _countof(buf
) - 1);
1805 // no, so fixed format
1808 datetime
= cTime
.Format(_T("%Y-%m-%d %H:%M:%S"));
1812 datetime
= cTime
.Format(_T("%Y-%m-%d"));
1820 * Converts a given time to a relative display string (relative to current time)
1821 * Given time must be in local timezone
1823 CString
CAppUtils::ToRelativeTimeString(CTime time
)
1826 // convert to COleDateTime
1828 time
.GetAsSystemTime( sysTime
);
1829 COleDateTime
oleTime( sysTime
);
1830 answer
= ToRelativeTimeString(oleTime
, COleDateTime::GetCurrentTime());
1835 * Generates a display string showing the relative time between the two given times as COleDateTimes
1837 CString
CAppUtils::ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
)
1840 COleDateTimeSpan ts
= RelativeTo
- time
;
1842 if(fabs(ts
.GetTotalDays()) >= 3*365)
1844 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/365, IDS_YEAR_AGO
, IDS_YEARS_AGO
);
1847 if(fabs(ts
.GetTotalDays()) >= 60)
1849 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/30, IDS_MONTH_AGO
, IDS_MONTHS_AGO
);
1853 if(fabs(ts
.GetTotalDays()) >= 14)
1855 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/7, IDS_WEEK_AGO
, IDS_WEEKS_AGO
);
1859 if(fabs(ts
.GetTotalDays()) >= 2)
1861 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays(), IDS_DAY_AGO
, IDS_DAYS_AGO
);
1865 if(fabs(ts
.GetTotalHours()) >= 2)
1867 answer
= ExpandRelativeTime( (int)ts
.GetTotalHours(), IDS_HOUR_AGO
, IDS_HOURS_AGO
);
1871 if(fabs(ts
.GetTotalMinutes()) >= 2)
1873 answer
= ExpandRelativeTime( (int)ts
.GetTotalMinutes(), IDS_MINUTE_AGO
, IDS_MINUTES_AGO
);
1877 answer
= ExpandRelativeTime( (int)ts
.GetTotalSeconds(), IDS_SECOND_AGO
, IDS_SECONDS_AGO
);
1882 * Passed a value and two resource string ids
1883 * if count is 1 then FormatString is called with format_1 and the value
1884 * otherwise format_2 is used
1885 * the formatted string is returned
1887 CString
CAppUtils::ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
)
1892 answer
.FormatMessage( format_1
, count
);
1896 answer
.FormatMessage( format_n
, count
);
1901 bool CAppUtils::IsSSHPutty()
1903 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1904 sshclient
=sshclient
.MakeLower();
1905 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1912 CString
CAppUtils::GetClipboardLink()
1914 if (!OpenClipboard(NULL
))
1917 CString sClipboardText
;
1918 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1921 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1922 sClipboardText
= CString(lpstr
);
1925 hglb
= GetClipboardData(CF_UNICODETEXT
);
1928 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1929 sClipboardText
= lpstr
;
1934 if(!sClipboardText
.IsEmpty())
1936 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1937 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1939 if(sClipboardText
.Find( _T("http://")) == 0)
1940 return sClipboardText
;
1942 if(sClipboardText
.Find( _T("https://")) == 0)
1943 return sClipboardText
;
1945 if(sClipboardText
.Find( _T("git://")) == 0)
1946 return sClipboardText
;
1948 if(sClipboardText
.Find( _T("ssh://")) == 0)
1949 return sClipboardText
;
1951 if(sClipboardText
.GetLength()>=2)
1952 if( sClipboardText
[1] == _T(':') )
1953 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1954 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1955 return sClipboardText
;
1958 return CString(_T(""));
1961 CString
CAppUtils::ChooseRepository(CString
*path
)
1963 CBrowseFolder browseFolder
;
1964 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1966 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1967 CString strCloneDirectory
;
1969 strCloneDirectory
=*path
;
1972 strCloneDirectory
= regLastResopitory
;
1976 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1978 browseFolder
.SetInfo(title
);
1980 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1982 regLastResopitory
= strCloneDirectory
;
1983 return strCloneDirectory
;
1991 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1995 dlg
.m_PathList
= list
;
1997 if(dlg
.DoModal()==IDOK
)
1999 if(dlg
.m_PathList
.GetCount() == 0)
2002 CGitProgressDlg progDlg
;
2004 theApp
.m_pMainWnd
= &progDlg
;
2005 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
2007 progDlg
.SetAutoClose(autoclose
);
2009 progDlg
.SetPathList(dlg
.m_PathList
);
2010 //ProjectProperties props;
2011 //props.ReadPropsPathList(dlg.m_pathList);
2012 //progDlg.SetProjectProperties(props);
2013 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2016 if(dlg
.m_bAttachment
)
2017 flags
|= SENDMAIL_ATTACHMENT
;
2019 flags
|= SENDMAIL_COMBINED
;
2021 flags
|= SENDMAIL_MAPI
;
2023 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
2032 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
2035 CString log
=formatpatchoutput
;
2036 int start
=log
.Find(cmd
);
2038 CString one
=log
.Tokenize(_T("\n"),start
);
2044 CString one
=log
.Tokenize(_T("\n"),start
);
2046 if(one
.IsEmpty() || one
== _T("Success"))
2048 one
.Replace(_T('/'),_T('\\'));
2050 path
.SetFromWin(one
);
2053 if (list
.GetCount() > 0)
2055 return SendPatchMail(list
, autoclose
);
2059 CMessageBox::Show(NULL
, _T("Not patches generated."), _T("TortoiseGit"), MB_ICONINFORMATION
);
2065 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2070 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2071 if(output
.IsEmpty())
2073 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
2074 if(output
.IsEmpty())
2078 output
=output
.Tokenize(_T("\n"),start
);
2079 return CUnicodeUtils::GetCPCode(output
);
2084 output
=output
.Tokenize(_T("\n"),start
);
2085 return CUnicodeUtils::GetCPCode(output
);
2088 int CAppUtils::GetCommitTemplate(CString
&temp
)
2092 output
= g_Git
.GetConfigValue(_T("commit.template"),CP_ACP
);
2093 if( output
.IsEmpty() )
2096 if( output
.GetLength()<1)
2099 if( output
[0] == _T('/'))
2101 if(output
.GetLength()>=3)
2102 if(output
[2] == _T('/'))
2104 output
.GetBuffer()[0] = output
[1];
2105 output
.GetBuffer()[1] = _T(':');
2110 output
=output
.Tokenize(_T("\n"),start
);
2112 output
.Replace(_T('/'),_T('\\'));
2116 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
2118 while(file
.ReadString(str
))
2129 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2131 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2135 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
2136 if(output
.IsEmpty())
2140 output
=output
.Tokenize(_T("\n"),start
);
2141 cp
=CUnicodeUtils::GetCPCode(output
);
2143 int len
=message
.GetLength();
2146 buf
= new char[len
*4 + 4];
2147 SecureZeroMemory(buf
, (len
*4 + 4));
2149 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2151 file
.Write(buf
,lengthIncTerminator
-1);
2157 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
2160 dlg
.m_PreSelectRemote
= remoteName
;
2161 dlg
.m_bAllowRebase
= allowRebase
;
2164 if(dlg
.DoModal()==IDOK
)
2168 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
2172 url
=dlg
.m_RemoteURL
;
2176 int ver
= CAppUtils::GetMsysgitVersion();
2178 if(ver
>= 0x01070203) //above 1.7.0.2
2179 arg
= _T("--progress ");
2182 arg
+= _T("--prune ");
2185 if (dlg
.m_bFetchTags
) {
2186 arg
+= _T("--tags ");
2189 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg
, url
,dlg
.m_RemoteBranchName
);
2190 CProgressDlg progress
;
2192 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2194 progress
.m_PostCmdList
.Add(_T("Show Log"));
2196 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2198 progress
.m_PostCmdList
.Add(_T("&Rebase"));
2201 progress
.m_GitCmd
=cmd
;
2202 int userResponse
=progress
.DoModal();
2204 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2207 cmd
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
2208 cmd
+= _T(" /command:log");
2209 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2210 CAppUtils::LaunchApplication(cmd
, IDS_ERR_PROC
, false);
2213 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2218 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
2219 dlg
.m_PostButtonTexts
.Add(_T("Restart Rebase"));
2220 int response
= dlg
.DoModal();
2221 if(response
== IDOK
)
2225 if(response
== IDC_REBASE_POST_BUTTON
)
2227 CString cmd
, out
, err
;
2228 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2230 g_Git
.FixBranchName(dlg
.m_Upstream
),
2231 g_Git
.FixBranchName(dlg
.m_Branch
));
2232 if (g_Git
.Run(cmd
, &out
, &err
, CP_ACP
))
2234 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2238 CAppUtils::SendPatchMail(cmd
,out
);
2242 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2245 if(response
== IDCANCEL
)
2254 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2257 dlg
.m_BranchSourceName
= selectLocalBranch
;
2259 DWORD exitcode
= 0xFFFFFFFF;
2261 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2262 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2267 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2268 //ReportError(temp);
2269 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2274 if(dlg
.DoModal()==IDOK
)
2281 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2285 arg
+= _T("--thin ");
2286 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2287 arg
+= _T("--tags ");
2289 arg
+= _T("--force ");
2291 int ver
= CAppUtils::GetMsysgitVersion();
2293 if(ver
>= 0x01070203) //above 1.7.0.2
2294 arg
+= _T("--progress ");
2296 if (dlg
.m_bPushAllBranches
)
2298 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2304 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2307 dlg
.m_BranchSourceName
);
2308 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2310 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2314 CProgressDlg progress
;
2315 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2316 progress
.m_GitCmd
=cmd
;
2317 progress
.m_PostCmdList
.Add(_T("&Request pull"));
2318 progress
.m_PostCmdList
.Add(_T("Re&Push"));
2319 int ret
= progress
.DoModal();
2321 if(!progress
.m_GitStatus
)
2323 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2328 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2329 //ReportError(temp);
2330 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2334 if(ret
== IDC_PROGRESS_BUTTON1
)
2336 RequestPull(dlg
.m_BranchRemoteName
);
2338 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2349 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2351 CRequestPullDlg dlg
;
2352 dlg
.m_RepositoryURL
= repositoryUrl
;
2353 dlg
.m_EndRevision
= endrevision
;
2354 if (dlg
.DoModal()==IDOK
)
2357 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2359 CProgressDlg progress
;
2360 progress
.m_GitCmd
=cmd
;
2366 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2368 CString
strDir(szPath
);
2369 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2371 strDir
.AppendChar(_T('\\'));
2373 std::vector
<CString
> vPath
;
2375 bool bSuccess
= false;
2377 for (int i
=0;i
<strDir
.GetLength();++i
)
2379 if (strDir
.GetAt(i
) != _T('\\'))
2381 strTemp
.AppendChar(strDir
.GetAt(i
));
2385 vPath
.push_back(strTemp
);
2386 strTemp
.AppendChar(_T('\\'));
2390 std::vector
<CString
>::const_iterator vIter
;
2391 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2393 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2399 void CAppUtils::RemoveTrailSlash(CString
&path
)
2404 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2406 path
=path
.Left(path
.GetLength()-1);
2412 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2413 CTGitPathList
&pathList
,
2414 CTGitPathList
&selectedList
,
2415 bool bSelectFilesForCommit
,
2418 bool bFailed
= true;
2420 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetConfigValue(_T("user.email")).IsEmpty())
2422 if(CMessageBox::Show(NULL
,_T("User name and email must be set before commit.\r\n Do you want to set these now?\r\n"),
2423 _T("TortoiseGit"),MB_YESNO
| MB_ICONERROR
) == IDYES
)
2425 CTGitPath
path(g_Git
.m_CurrentDir
);
2426 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2427 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2428 dlg
.SetTreeWidth(220);
2429 dlg
.m_DefaultPage
= _T("gitconfig");
2432 dlg
.HandleRestart();
2443 dlg
.m_sBugID
= bugid
;
2445 dlg
.m_bWholeProject
= bWholeProject
;
2447 dlg
.m_sLogMessage
= sLogMsg
;
2448 dlg
.m_pathList
= pathList
;
2449 dlg
.m_checkedPathList
= selectedList
;
2450 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2451 dlg
.m_bAutoClose
= autoClose
;
2452 if (dlg
.DoModal() == IDOK
)
2454 if (dlg
.m_pathList
.GetCount()==0)
2456 // if the user hasn't changed the list of selected items
2457 // we don't use that list. Because if we would use the list
2458 // of pre-checked items, the dialog would show different
2459 // checked items on the next startup: it would only try
2460 // to check the parent folder (which might not even show)
2461 // instead, we simply use an empty list and let the
2462 // default checking do its job.
2463 if (!dlg
.m_pathList
.IsEqual(pathList
))
2464 selectedList
= dlg
.m_pathList
;
2465 pathList
= dlg
.m_updatedPathList
;
2466 sLogMsg
= dlg
.m_sLogMessage
;
2467 bSelectFilesForCommit
= true;
2469 if( dlg
.m_bPushAfterCommit
)
2471 switch(dlg
.m_PostCmd
)
2473 case GIT_POST_CMD_DCOMMIT
:
2474 CAppUtils::SVNDCommit();
2480 // CGitProgressDlg progDlg;
2481 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2482 // if (parser.HasVal(_T("closeonend")))
2483 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2484 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2485 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2486 // progDlg.SetPathList(dlg.m_pathList);
2487 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2488 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2489 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2490 // progDlg.SetItemCount(dlg.m_itemsCount);
2491 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2492 // progDlg.DoModal();
2493 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2494 // err = (DWORD)progDlg.DidErrorsOccur();
2495 // bFailed = progDlg.DidErrorsOccur();
2496 // bRet = progDlg.DidErrorsOccur();
2497 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2498 // if (DWORD(bFailRepeat)==0)
2499 // bFailed = false; // do not repeat if the user chose not to in the settings.
2506 BOOL
CAppUtils::SVNDCommit()
2508 CSVNDCommitDlg dcommitdlg
;
2509 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2510 if (gitSetting
== _T("")) {
2511 if (dcommitdlg
.DoModal() != IDOK
)
2517 if (dcommitdlg
.m_remember
)
2519 if (dcommitdlg
.m_rmdir
)
2521 gitSetting
= _T("true");
2525 gitSetting
= _T("false");
2527 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2529 CMessageBox::Show(NULL
,_T("Fail to set config"),_T("TortoiseGit"),MB_OK
);
2535 BOOL IsStash
= false;
2536 if(!g_Git
.CheckCleanWorkTree())
2538 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2541 cmd
=_T("git.exe stash");
2542 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2544 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2556 CProgressDlg progress
;
2557 if (dcommitdlg
.m_rmdir
)
2559 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2563 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2565 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2569 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2572 cmd
=_T("git.exe stash pop");
2573 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2575 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2590 BOOL
CAppUtils::Merge(CString
*commit
)
2594 dlg
.m_initialRefName
= *commit
;
2596 if(dlg
.DoModal()==IDOK
)
2608 squash
=_T("--squash");
2611 nocommit
=_T("--no-commit");
2613 if(!dlg
.m_strLogMesage
.IsEmpty())
2615 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2617 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2622 g_Git
.FixBranchName(dlg
.m_VersionName
));
2624 CProgressDlg Prodlg
;
2625 Prodlg
.m_GitCmd
= cmd
;
2627 if (dlg
.m_bNoCommit
)
2628 Prodlg
.m_PostCmdList
.Add(_T("Commit"));
2630 int ret
= Prodlg
.DoModal();
2632 if (ret
== IDC_PROGRESS_BUTTON1
)
2633 return Commit(_T(""), TRUE
, CString(), CTGitPathList(), CTGitPathList(), true);
2635 return !Prodlg
.m_GitStatus
;
2640 void CAppUtils::EditNote(GitRev
*rev
)
2643 dlg
.m_sHintText
=_T("Edit Notes");
2644 dlg
.m_sInputText
= rev
->m_Notes
;
2645 dlg
.m_sTitle
=_T("Edit Notes");
2646 //dlg.m_pProjectProperties = &m_ProjectProperties;
2647 dlg
.m_bUseLogWidth
= true;
2648 if(dlg
.DoModal() == IDOK
)
2651 cmd
=_T("notes add -f -F \"");
2653 CString tempfile
=::GetTempFile();
2654 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2657 cmd
+= rev
->m_CommitHash
.ToString();
2661 if(git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2663 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2668 rev
->m_Notes
= dlg
.m_sInputText
;
2672 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2674 CFile::Remove(tempfile
);
2679 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2682 CString progressarg
;
2685 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2686 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2688 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2691 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2693 if((DWORD
)time
== regTime
)
2700 version
= *versionstr
;
2704 cmd
= _T("git.exe --version");
2705 if(g_Git
.Run(cmd
, &version
, &err
, CP_ACP
))
2707 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2715 CString str
=version
.Tokenize(_T("."),start
);
2716 int space
= str
.ReverseFind(_T(' '));
2717 str
=str
.Mid(space
+1,start
);
2721 version
= version
.Mid(start
);
2723 str
= version
.Tokenize(_T("."),start
);
2725 ver
|= (_ttol(str
)&0xFF)<<16;
2727 str
= version
.Tokenize(_T("."),start
);
2728 ver
|= (_ttol(str
)&0xFF)<<8;
2730 str
= version
.Tokenize(_T("."),start
);
2731 ver
|= (_ttol(str
)&0xFF);
2733 regTime
= time
&0xFFFFFFFF;
2739 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2741 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2743 HMODULE hShell
= LoadLibrary(_T("Shell32.dll"));
2746 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2748 IPropertyStore
*pps
;
2749 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2750 if (SUCCEEDED(hr
)) {
2753 var
.boolVal
= VARIANT_TRUE
;
2754 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2758 FreeLibrary(hShell
);
2762 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2764 ASSERT(dialogname
.GetLength() < 70);
2765 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2766 WCHAR pathbuf
[MAX_PATH
] = {0};
2768 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2770 wcscat_s(pathbuf
, L
" - ");
2771 wcscat_s(pathbuf
, dialogname
);
2772 wcscat_s(pathbuf
, L
" - ");
2773 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2774 SetWindowText(hWnd
, pathbuf
);