1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "PathUtils.h"
24 //#include "GitProperties.h"
25 #include "StringUtils.h"
26 #include "MessageBox.h"
30 //#include "RepositoryBrowser.h"
31 //#include "BrowseFolder.h"
32 #include "UnicodeUtils.h"
33 #include "ExportDlg.h"
34 #include "ProgressDlg.h"
35 #include "GitAdminDir.h"
36 #include "ProgressDlg.h"
37 #include "BrowseFolder.h"
38 #include "DirFileEnum.h"
39 #include "MessageBox.h"
40 #include "GitStatus.h"
41 #include "CreateBranchTagDlg.h"
42 #include "GitSwitchDlg.h"
44 #include "DeleteConflictDlg.h"
45 #include "ChangedDlg.h"
46 #include "SendMailDlg.h"
47 #include "SVNProgressDlg.h"
50 CAppUtils::CAppUtils(void)
54 CAppUtils::~CAppUtils(void)
58 int CAppUtils::StashApply(CString ref
)
61 cmd
=_T("git.exe stash apply ");
64 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
66 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
70 if(CMessageBox::Show(NULL
,CString(_T("<ct=0xff0000>Stash Apply Success</ct>\nDo you want to show change?"))
71 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
74 dlg
.m_pathList
.AddPath(CTGitPath());
81 bool CAppUtils::GetMimeType(const CTGitPath
& file
, CString
& mimetype
)
84 GitProperties
props(file
, GitRev::REV_WC
, false);
85 for (int i
= 0; i
< props
.GetCount(); ++i
)
87 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
89 mimetype
= props
.GetItemValue(i
).c_str();
97 BOOL
CAppUtils::StartExtMerge(
98 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
99 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
102 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
103 CString ext
= mergedfile
.GetFileExtension();
104 CString com
= regCom
;
105 bool bInternal
= false;
110 // is there an extension specific merge tool?
111 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
112 if (CString(mergetool
) != "")
117 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
119 // is there a mime type specific merge tool?
120 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
121 if (CString(mergetool
) != "")
127 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
131 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
132 com
= tortoiseMergePath
;
135 com
= CPathUtils::GetAppDirectory();
136 com
+= _T("TortoiseMerge.exe");
138 com
= _T("\"") + com
+ _T("\"");
139 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
140 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
142 // check if the params are set. If not, just add the files to the command line
143 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
145 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
146 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
147 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
148 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
150 if (basefile
.IsEmpty())
152 com
.Replace(_T("/base:%base"), _T(""));
153 com
.Replace(_T("%base"), _T(""));
156 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
157 if (theirfile
.IsEmpty())
159 com
.Replace(_T("/theirs:%theirs"), _T(""));
160 com
.Replace(_T("%theirs"), _T(""));
163 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
164 if (yourfile
.IsEmpty())
166 com
.Replace(_T("/mine:%mine"), _T(""));
167 com
.Replace(_T("%mine"), _T(""));
170 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
171 if (mergedfile
.IsEmpty())
173 com
.Replace(_T("/merged:%merged"), _T(""));
174 com
.Replace(_T("%merged"), _T(""));
177 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
178 if (basename
.IsEmpty())
180 if (basefile
.IsEmpty())
182 com
.Replace(_T("/basename:%bname"), _T(""));
183 com
.Replace(_T("%bname"), _T(""));
187 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
191 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
192 if (theirname
.IsEmpty())
194 if (theirfile
.IsEmpty())
196 com
.Replace(_T("/theirsname:%tname"), _T(""));
197 com
.Replace(_T("%tname"), _T(""));
201 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
205 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
206 if (yourname
.IsEmpty())
208 if (yourfile
.IsEmpty())
210 com
.Replace(_T("/minename:%yname"), _T(""));
211 com
.Replace(_T("%yname"), _T(""));
215 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
219 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
220 if (mergedname
.IsEmpty())
222 if (mergedfile
.IsEmpty())
224 com
.Replace(_T("/mergedname:%mname"), _T(""));
225 com
.Replace(_T("%mname"), _T(""));
229 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
233 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
235 if ((bReadOnly
)&&(bInternal
))
236 com
+= _T(" /readonly");
238 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
246 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
250 viewer
= CPathUtils::GetAppDirectory();
251 viewer
+= _T("TortoiseMerge.exe");
253 viewer
= _T("\"") + viewer
+ _T("\"");
254 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
255 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
257 viewer
+= _T(" /reversedpatch");
258 if (!sOriginalDescription
.IsEmpty())
259 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
260 if (!sPatchedDescription
.IsEmpty())
261 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
262 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
269 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
271 // Is there a mime type specific diff tool?
273 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
275 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
276 if (!difftool
.IsEmpty())
280 // Is there an extension specific diff tool?
281 CString ext
= file2
.GetFileExtension().MakeLower();
284 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
285 if (!difftool
.IsEmpty())
287 // Maybe we should use TortoiseIDiff?
288 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
289 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
290 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
291 (ext
== _T(".dib")) || (ext
== _T(".emf")))
294 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
295 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
299 // Finally, pick a generic external diff tool
300 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
304 bool CAppUtils::StartExtDiff(
305 const CString
& file1
, const CString
& file2
,
306 const CString
& sName1
, const CString
& sName2
,
307 const DiffFlags
& flags
)
311 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
312 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
314 viewer
= PickDiffTool(file1
, file2
);
315 // If registry entry for a diff program is commented out, use TortoiseMerge.
316 bool bCommentedOut
= viewer
.Left(1) == _T("#");
317 if (flags
.bAlternativeTool
)
319 // Invert external vs. internal diff tool selection.
321 viewer
.Delete(0); // uncomment
325 else if (bCommentedOut
)
329 bool bInternal
= viewer
.IsEmpty();
333 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
334 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
336 viewer
+= _T(" /blame");
338 // check if the params are set. If not, just add the files to the command line
339 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
341 viewer
+= _T(" \"")+file1
+_T("\"");
342 viewer
+= _T(" \"")+file2
+_T("\"");
344 if (viewer
.Find(_T("%base")) >= 0)
346 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
348 if (viewer
.Find(_T("%mine")) >= 0)
350 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
353 if (sName1
.IsEmpty())
354 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
356 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
358 if (sName2
.IsEmpty())
359 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
361 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
363 if (flags
.bReadOnly
&& bInternal
)
364 viewer
+= _T(" /readonly");
366 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
369 BOOL
CAppUtils::StartExtDiffProps(const CTGitPath
& file1
, const CTGitPath
& file2
, const CString
& sName1
, const CString
& sName2
, BOOL bWait
, BOOL bReadOnly
)
371 CRegString
diffpropsexe(_T("Software\\TortoiseGit\\DiffProps"));
372 CString viewer
= diffpropsexe
;
373 bool bInternal
= false;
374 if (viewer
.IsEmpty()||(viewer
.Left(1).Compare(_T("#"))==0))
376 //no registry entry (or commented out) for a diff program
379 viewer
= CPathUtils::GetAppDirectory();
380 viewer
+= _T("TortoiseMerge.exe");
381 viewer
= _T("\"") + viewer
+ _T("\"");
382 viewer
= viewer
+ _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
384 // check if the params are set. If not, just add the files to the command line
385 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
387 viewer
+= _T(" \"")+file1
.GetWinPathString()+_T("\"");
388 viewer
+= _T(" \"")+file2
.GetWinPathString()+_T("\"");
390 if (viewer
.Find(_T("%base")) >= 0)
392 viewer
.Replace(_T("%base"), _T("\"")+file1
.GetWinPathString()+_T("\""));
394 if (viewer
.Find(_T("%mine")) >= 0)
396 viewer
.Replace(_T("%mine"), _T("\"")+file2
.GetWinPathString()+_T("\""));
399 if (sName1
.IsEmpty())
400 viewer
.Replace(_T("%bname"), _T("\"") + file1
.GetUIFileOrDirectoryName() + _T("\""));
402 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
404 if (sName2
.IsEmpty())
405 viewer
.Replace(_T("%yname"), _T("\"") + file2
.GetUIFileOrDirectoryName() + _T("\""));
407 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
409 if ((bReadOnly
)&&(bInternal
))
410 viewer
+= _T(" /readonly");
412 if(!LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, !!bWait
))
419 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
422 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
424 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
427 viewer
= CPathUtils::GetAppDirectory();
428 viewer
+= _T("TortoiseUDiff.exe");
429 // enquote the path to TortoiseUDiff
430 viewer
= _T("\"") + viewer
+ _T("\"");
432 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
435 if (viewer
.Find(_T("%1"))>=0)
437 if (viewer
.Find(_T("\"%1\"")) >= 0)
438 viewer
.Replace(_T("%1"), patchfile
);
440 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
443 viewer
+= _T(" \"") + patchfile
+ _T("\"");
444 if (viewer
.Find(_T("%title")) >= 0)
446 viewer
.Replace(_T("%title"), title
);
449 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
456 BOOL
CAppUtils::StartTextViewer(CString file
)
459 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
461 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
462 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
465 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
466 TCHAR
* buf
= new TCHAR
[len
+1];
467 ExpandEnvironmentStrings(viewer
, buf
, len
);
470 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
471 buf
= new TCHAR
[len
+1];
472 ExpandEnvironmentStrings(file
, buf
, len
);
475 file
= _T("\"")+file
+_T("\"");
476 if (viewer
.IsEmpty())
478 OPENFILENAME ofn
= {0}; // common dialog box structure
479 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
480 // Initialize OPENFILENAME
481 ofn
.lStructSize
= sizeof(OPENFILENAME
);
482 ofn
.hwndOwner
= NULL
;
483 ofn
.lpstrFile
= szFile
;
484 ofn
.nMaxFile
= sizeof(szFile
)/sizeof(TCHAR
);
486 sFilter
.LoadString(IDS_PROGRAMSFILEFILTER
);
487 TCHAR
* pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
488 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
489 // Replace '|' delimiters with '\0's
490 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
491 while (ptr
!= pszFilters
)
497 ofn
.lpstrFilter
= pszFilters
;
498 ofn
.nFilterIndex
= 1;
499 ofn
.lpstrFileTitle
= NULL
;
500 ofn
.nMaxFileTitle
= 0;
501 ofn
.lpstrInitialDir
= NULL
;
503 temp
.LoadString(IDS_UTILS_SELECTTEXTVIEWER
);
504 CStringUtils::RemoveAccelerators(temp
);
505 ofn
.lpstrTitle
= temp
;
506 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
508 // Display the Open dialog box.
510 if (GetOpenFileName(&ofn
)==TRUE
)
512 delete [] pszFilters
;
513 viewer
= CString(ofn
.lpstrFile
);
517 delete [] pszFilters
;
521 if (viewer
.Find(_T("\"%1\"")) >= 0)
523 viewer
.Replace(_T("\"%1\""), file
);
525 else if (viewer
.Find(_T("%1")) >= 0)
527 viewer
.Replace(_T("%1"), file
);
535 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
542 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
545 HANDLE hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
546 if (hFile
== INVALID_HANDLE_VALUE
)
548 length
= ::GetFileSize(hFile
, NULL
);
549 ::CloseHandle(hFile
);
556 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
559 HDC hScreenDC
= ::GetDC(NULL
);
560 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
561 ::ReleaseDC(NULL
, hScreenDC
);
563 logFont
.lfEscapement
= 0;
564 logFont
.lfOrientation
= 0;
565 logFont
.lfWeight
= FW_NORMAL
;
566 logFont
.lfItalic
= 0;
567 logFont
.lfUnderline
= 0;
568 logFont
.lfStrikeOut
= 0;
569 logFont
.lfCharSet
= DEFAULT_CHARSET
;
570 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
571 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
572 logFont
.lfQuality
= DRAFT_QUALITY
;
573 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
574 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
575 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
578 bool CAppUtils::LaunchApplication(const CString
& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
)
581 PROCESS_INFORMATION process
;
582 memset(&startup
, 0, sizeof(startup
));
583 startup
.cb
= sizeof(startup
);
584 memset(&process
, 0, sizeof(process
));
586 CString
cleanCommandLine(sCommandLine
);
588 if (CreateProcess(NULL
, const_cast<TCHAR
*>((LPCTSTR
)cleanCommandLine
), NULL
, NULL
, FALSE
, 0, 0, sOrigCWD
, &startup
, &process
)==0)
590 if(idErrMessageFormat
!= 0)
593 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
594 FORMAT_MESSAGE_FROM_SYSTEM
|
595 FORMAT_MESSAGE_IGNORE_INSERTS
,
598 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
604 temp
.Format(idErrMessageFormat
, lpMsgBuf
);
605 CMessageBox::Show(NULL
, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
606 LocalFree( lpMsgBuf
);
613 WaitForInputIdle(process
.hProcess
, 10000);
616 CloseHandle(process
.hThread
);
617 CloseHandle(process
.hProcess
);
620 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
633 cmd
.Format(_T("git.exe config remote.%s.puttykeyfile"),remote
);
634 g_Git
.Run(cmd
,&key
,CP_ACP
);
636 key
= key
.Tokenize(_T("\n"),start
);
644 CString proc
=CPathUtils::GetAppDirectory();
645 proc
+= _T("pageant.exe \"");
649 return LaunchApplication(proc
, IDS_ERR_PAGEANT
, false);
651 bool CAppUtils::LaunchRemoteSetting()
653 CString proc
=CPathUtils::GetAppDirectory();
654 proc
+= _T("TortoiseProc.exe /command:settings");
655 proc
+= _T(" /path:\"");
656 proc
+= g_Git
.m_CurrentDir
;
657 proc
+= _T("\" /page:remote");
658 return LaunchApplication(proc
, IDS_ERR_EXTDIFFSTART
, false);
661 * Launch the external blame viewer
663 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
665 CString viewer
= CPathUtils::GetAppDirectory();
666 viewer
+= _T("TortoiseGitBlame.exe");
667 viewer
+= _T(" \"") + sBlameFile
+ _T("\"");
668 //viewer += _T(" \"") + sLogFile + _T("\"");
669 //viewer += _T(" \"") + sOriginalFile + _T("\"");
671 viewer
+= CString(_T(" /rev:"))+Rev
;
672 viewer
+= _T(" ")+sParams
;
674 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, false);
677 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
682 bool bStyled
= false;
683 pWnd
->GetWindowText(sText
);
684 // the rich edit control doesn't count the CR char!
685 // to be exact: CRLF is treated as one char.
686 sText
.Replace(_T("\r"), _T(""));
688 // style each line separately
693 nNewlinePos
= sText
.Find('\n', offset
);
694 CString sLine
= sText
.Mid(offset
);
696 sLine
= sLine
.Left(nNewlinePos
-offset
);
699 while (FindStyleChars(sLine
, '*', start
, end
))
701 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
702 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
704 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
705 format
.cbSize
= sizeof(CHARFORMAT2
);
706 format
.dwMask
= CFM_BOLD
;
707 format
.dwEffects
= CFE_BOLD
;
708 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
714 while (FindStyleChars(sLine
, '^', start
, end
))
716 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
717 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
719 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
720 format
.cbSize
= sizeof(CHARFORMAT2
);
721 format
.dwMask
= CFM_ITALIC
;
722 format
.dwEffects
= CFE_ITALIC
;
723 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
729 while (FindStyleChars(sLine
, '_', start
, end
))
731 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
732 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
734 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
735 format
.cbSize
= sizeof(CHARFORMAT2
);
736 format
.dwMask
= CFM_UNDERLINE
;
737 format
.dwEffects
= CFE_UNDERLINE
;
738 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
742 offset
= nNewlinePos
+1;
743 } while(nNewlinePos
>=0);
747 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
750 bool bFoundMarker
= false;
751 // find a starting marker
752 while (sText
[i
] != 0)
754 if (sText
[i
] == stylechar
)
756 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
757 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
769 // find ending marker
770 bFoundMarker
= false;
771 while (sText
[i
] != 0)
773 if (sText
[i
] == stylechar
)
775 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
776 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
789 bool CAppUtils::BrowseRepository(CHistoryCombo
& combo
, CWnd
* pParent
, GitRev
& rev
)
793 combo
.GetWindowText(strUrl
);
794 strUrl
.Replace('\\', '/');
795 strUrl
.Replace(_T("%"), _T("%25"));
796 strUrl
= CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(strUrl
)));
797 if (strUrl
.Left(7) == _T("file://"))
799 CString
strFile(strUrl
);
800 Git::UrlToPath(strFile
);
803 if (svn
.IsRepository(CTGitPath(strFile
)))
805 // browse repository - show repository browser
806 Git::preparePath(strUrl
);
807 CRepositoryBrowser
browser(strUrl
, rev
, pParent
);
808 if (browser
.DoModal() == IDOK
)
811 combo
.SetWindowText(browser
.GetPath());
812 rev
= browser
.GetRevision();
818 // browse local directories
819 CBrowseFolder folderBrowser
;
820 folderBrowser
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
821 // remove the 'file:///' so the shell can recognize the local path
822 Git::UrlToPath(strUrl
);
823 if (folderBrowser
.Show(pParent
->GetSafeHwnd(), strUrl
) == CBrowseFolder::OK
)
825 Git::PathToUrl(strUrl
);
828 combo
.SetWindowText(strUrl
);
833 else if ((strUrl
.Left(7) == _T("http://")
834 ||(strUrl
.Left(8) == _T("https://"))
835 ||(strUrl
.Left(6) == _T("svn://"))
836 ||(strUrl
.Left(4) == _T("svn+"))) && strUrl
.GetLength() > 6)
838 // browse repository - show repository browser
839 CRepositoryBrowser
browser(strUrl
, rev
, pParent
);
840 if (browser
.DoModal() == IDOK
)
843 combo
.SetWindowText(browser
.GetPath());
844 rev
= browser
.GetRevision();
850 // browse local directories
851 CBrowseFolder folderBrowser
;
852 folderBrowser
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
853 if (folderBrowser
.Show(pParent
->GetSafeHwnd(), strUrl
) == CBrowseFolder::OK
)
855 Git::PathToUrl(strUrl
);
858 combo
.SetWindowText(strUrl
);
866 bool CAppUtils::FileOpenSave(CString
& path
, int * filterindex
, UINT title
, UINT filter
, bool bOpen
, HWND hwndOwner
)
868 OPENFILENAME ofn
= {0}; // common dialog box structure
869 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
870 ofn
.lStructSize
= sizeof(OPENFILENAME
);
871 ofn
.hwndOwner
= hwndOwner
;
872 _tcscpy_s(szFile
, MAX_PATH
, (LPCTSTR
)path
);
873 ofn
.lpstrFile
= szFile
;
874 ofn
.nMaxFile
= sizeof(szFile
)/sizeof(TCHAR
);
876 TCHAR
* pszFilters
= NULL
;
879 sFilter
.LoadString(filter
);
880 pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
881 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
882 // Replace '|' delimiters with '\0's
883 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
884 while (ptr
!= pszFilters
)
890 ofn
.lpstrFilter
= pszFilters
;
892 ofn
.nFilterIndex
= 1;
893 ofn
.lpstrFileTitle
= NULL
;
894 ofn
.nMaxFileTitle
= 0;
895 ofn
.lpstrInitialDir
= NULL
;
899 temp
.LoadString(title
);
900 CStringUtils::RemoveAccelerators(temp
);
902 ofn
.lpstrTitle
= temp
;
904 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_EXPLORER
;
906 ofn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_EXPLORER
;
909 // Display the Open dialog box.
913 bRet
= !!GetOpenFileName(&ofn
);
917 bRet
= !!GetSaveFileName(&ofn
);
922 delete [] pszFilters
;
923 path
= CString(ofn
.lpstrFile
);
925 *filterindex
= ofn
.nFilterIndex
;
929 delete [] pszFilters
;
933 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl
, UINT nID
, int width
/* = 128 */, int height
/* = 128 */)
935 ListView_SetTextBkColor(hListCtrl
, CLR_NONE
);
936 COLORREF bkColor
= ListView_GetBkColor(hListCtrl
);
937 // create a bitmap from the icon
938 HICON hIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID
), IMAGE_ICON
, width
, height
, LR_DEFAULTCOLOR
);
944 rect
.bottom
= height
;
947 HWND desktop
= ::GetDesktopWindow();
950 HDC screen_dev
= ::GetDC(desktop
);
953 // Create a compatible DC
954 HDC dst_hdc
= ::CreateCompatibleDC(screen_dev
);
957 // Create a new bitmap of icon size
958 bmp
= ::CreateCompatibleBitmap(screen_dev
, rect
.right
, rect
.bottom
);
961 // Select it into the compatible DC
962 HBITMAP old_dst_bmp
= (HBITMAP
)::SelectObject(dst_hdc
, bmp
);
963 // Fill the background of the compatible DC with the given color
964 ::SetBkColor(dst_hdc
, bkColor
);
965 ::ExtTextOut(dst_hdc
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
967 // Draw the icon into the compatible DC
968 ::DrawIconEx(dst_hdc
, 0, 0, hIcon
, rect
.right
, rect
.bottom
, 0, NULL
, DI_NORMAL
);
969 ::SelectObject(dst_hdc
, old_dst_bmp
);
974 ::ReleaseDC(desktop
, screen_dev
);
984 lv
.ulFlags
= LVBKIF_TYPE_WATERMARK
;
986 lv
.xOffsetPercent
= 100;
987 lv
.yOffsetPercent
= 100;
988 ListView_SetBkImage(hListCtrl
, &lv
);
992 CString
CAppUtils::GetProjectNameFromURL(CString url
)
995 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
996 (name
.CompareNoCase(_T("tags"))==0) ||
997 (name
.CompareNoCase(_T("trunk"))==0))
999 name
= url
.Mid(url
.ReverseFind('/')+1);
1000 url
= url
.Left(url
.ReverseFind('/'));
1002 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
1004 // a name of svn or svnroot indicates that it's not really the project name. In that
1005 // case, we try the first part of the URL
1006 // of course, this won't work in all cases (but it works for Google project hosting)
1007 url
.Replace(_T("http://"), _T(""));
1008 url
.Replace(_T("https://"), _T(""));
1009 url
.Replace(_T("svn://"), _T(""));
1010 url
.Replace(_T("svn+ssh://"), _T(""));
1011 url
.TrimLeft(_T("/"));
1012 name
= url
.Left(url
.Find('.'));
1017 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
1018 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
1019 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1020 bool bAlternateDiff
/* = false */, bool bIgnoreAncestry
/* = false */, bool /* blame = false */)
1023 CString tempfile
=GetTempFile();
1025 if(rev1
== GitRev::GetWorkingCopy())
1027 cmd
.Format(_T("git.exe diff --stat -p %s "),rev2
);
1030 cmd
.Format(_T("git.exe diff-tree -r -p --stat %s %s"),rev1
,rev2
);
1033 if( !url1
.IsEmpty() )
1036 cmd
+=url1
.GetGitPathString();
1039 g_Git
.RunLogFile(cmd
,tempfile
);
1040 CAppUtils::StartUnifiedDiffViewer(tempfile
,rev1
.Left(6)+_T(":")+rev2
.Left(6));
1045 sCmd
.Format(_T("%s /command:showcompare /unified"),
1046 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1047 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1049 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1050 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1052 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1054 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1055 if (headpeg
.IsValid())
1056 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1059 sCmd
+= _T(" /alternatediff");
1061 if (bIgnoreAncestry
)
1062 sCmd
+= _T(" /ignoreancestry");
1066 sCmd
+= _T(" /hwnd:");
1068 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1072 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1077 bool CAppUtils::StartShowCompare(HWND hWnd
, const CTGitPath
& url1
, const GitRev
& rev1
,
1078 const CTGitPath
& url2
, const GitRev
& rev2
,
1079 const GitRev
& peg
/* = GitRev */, const GitRev
& headpeg
/* = GitRev */,
1080 bool bAlternateDiff
/* = false */, bool bIgnoreAncestry
/* = false */, bool blame
/* = false */)
1084 sCmd
.Format(_T("%s /command:showcompare"),
1085 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1086 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1088 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1089 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1091 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1093 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1094 if (headpeg
.IsValid())
1095 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1097 sCmd
+= _T(" /alternatediff");
1098 if (bIgnoreAncestry
)
1099 sCmd
+= _T(" /ignoreancestry");
1101 sCmd
+= _T(" /blame");
1105 sCmd
+= _T(" /hwnd:");
1107 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1111 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1116 bool CAppUtils::Export(CString
*BashHash
)
1120 // ask from where the export has to be done
1123 dlg
.m_Revision
=*BashHash
;
1125 if (dlg
.DoModal() == IDOK
)
1128 cmd
.Format(_T("git.exe archive --format=zip --verbose %s"),
1131 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1134 pro
.m_LogFile
=dlg
.m_strExportDirectory
;
1141 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
)
1143 CCreateBranchTagDlg dlg
;
1146 dlg
.m_Base
= *CommitHash
;
1148 if(dlg
.DoModal()==IDOK
)
1154 track
=_T(" --track ");
1161 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1164 dlg
.m_BranchTagName
,
1171 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1174 dlg
.m_BranchTagName
,
1179 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1181 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1183 if( !IsTag
&& dlg
.m_bSwitch
)
1185 // it is a new branch and the user has requested to switch to it
1186 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1187 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1188 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1197 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
)
1201 dlg
.m_Base
=*CommitHash
;
1202 if(!initialRefName
.IsEmpty())
1203 dlg
.m_initialRefName
= initialRefName
;
1205 if (dlg
.DoModal() == IDOK
)
1214 branch
.Format(_T("-b %s"),dlg
.m_NewBranch
);
1218 track
=_T("--track");
1220 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1226 CProgressDlg progress
;
1227 progress
.m_GitCmd
=cmd
;
1228 if(progress
.DoModal()==IDOK
)
1235 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1238 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1242 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1246 ignorefile
+=_T("\\.gitignore");
1250 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1252 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1260 //file.ReadString(ignorelist);
1262 for(int i
=0;i
<path
.GetCount();i
++)
1266 mask
=_T("*")+path
[i
].GetFileExtension();
1267 if(ignorelist
.Find(mask
)<0)
1268 ignorelist
+=_T("\n")+mask
;
1272 ignorelist
+=_T("\n/")+path
[i
].GetGitPathString();
1275 file
.WriteString(ignorelist
);
1289 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1292 dlg
.m_ResetType
=type
;
1293 if (dlg
.DoModal() == IDOK
)
1297 switch(dlg
.m_ResetType
)
1312 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1314 CProgressDlg progress
;
1315 progress
.m_GitCmd
=cmd
;
1316 if(progress
.DoModal()==IDOK
)
1323 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1327 descript
=_T("Deleted");
1332 descript
=_T("Modified");
1335 descript
=_T("Created");
1339 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1342 file
=g_Git
.m_CurrentDir
+_T("\\")+merge
.GetDirectory().GetWinPathString()+_T("\\")+merge
.GetFilename()+_T(".")+type
+merge
.GetFileExtension();
1347 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool bAlternativeTool
)
1351 CTGitPath merge
=path
;
1352 CTGitPath directory
= merge
.GetDirectory();
1356 // we have the conflicted file (%merged)
1357 // now look for the other required files
1359 //stat.GetStatus(merge);
1360 //if (stat.status == NULL)
1366 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1368 if(g_Git
.Run(cmd
,&vector
))
1374 list
.ParserFromLsFile(vector
);
1376 if(list
.GetCount() == 0)
1379 TCHAR szTempName
[512];
1380 GetTempFileName(_T(""),_T(""),0,szTempName
);
1381 CString
temp(szTempName
);
1382 temp
=temp
.Mid(1,temp
.GetLength()-5);
1389 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1390 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1391 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1395 format
=_T("git.exe cat-file blob \":%d:%s\"");
1397 //create a empty file, incase stage is not three
1398 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1400 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1402 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1405 bool b_base
=false, b_local
=false, b_remote
=false;
1407 for(int i
=0;i
<list
.GetCount();i
++)
1411 cmd
.Format(format
,list
[i
].m_Stage
,list
[i
].GetGitPathString());
1413 if( list
[i
].m_Stage
== 1)
1416 outfile
=base
.GetWinPathString();
1418 if( list
[i
].m_Stage
== 2 )
1421 outfile
=mine
.GetWinPathString();
1423 if( list
[i
].m_Stage
== 3 )
1426 outfile
=theirs
.GetWinPathString();
1428 g_Git
.RunLogFile(cmd
,outfile
);
1431 if(b_local
&& b_remote
)
1433 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1434 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1438 CFile::Remove(mine
.GetWinPathString());
1439 CFile::Remove(theirs
.GetWinPathString());
1440 CFile::Remove(base
.GetWinPathString());
1442 CDeleteConflictDlg dlg
;
1443 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1444 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1445 dlg
.m_bShowModifiedButton
=b_base
;
1446 dlg
.m_File
=merge
.GetGitPathString();
1447 if(dlg
.DoModal() == IDOK
)
1452 cmd
.Format(_T("git.exe rm \"%s\""),merge
.GetGitPathString());
1454 cmd
.Format(_T("git.exe add \"%s\""),merge
.GetGitPathString());
1456 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
1458 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1472 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1473 base
, theirs
, mine
, merge
);
1476 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1478 // we have a text conflict, use our merge tool to resolve the conflict
1480 CTSVNPath
theirs(directory
);
1481 CTSVNPath
mine(directory
);
1482 CTSVNPath
base(directory
);
1483 bool bConflictData
= false;
1485 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1487 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1488 bConflictData
= true;
1490 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1492 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1493 bConflictData
= true;
1495 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1497 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1498 bConflictData
= true;
1505 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1506 base
, theirs
, mine
, merge
);
1509 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1511 // we have a property conflict
1512 CTSVNPath
prej(directory
);
1513 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1515 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1516 // there's a problem: the prej file contains a _description_ of the conflict, and
1517 // that description string might be translated. That means we have no way of parsing
1518 // the file to find out the conflicting values.
1519 // The only thing we can do: show a dialog with the conflict description, then
1520 // let the user either accept the existing property or open the property edit dialog
1521 // to manually change the properties and values. And a button to mark the conflict as
1523 CEditPropConflictDlg dlg
;
1524 dlg
.SetPrejFile(prej
);
1525 dlg
.SetConflictedItem(merge
);
1526 bRet
= (dlg
.DoModal() != IDCANCEL
);
1530 if (stat
.status
->tree_conflict
)
1532 // we have a tree conflict
1534 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1537 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1539 CTSVNPath
theirs(directory
);
1540 CTSVNPath
mine(directory
);
1541 CTSVNPath
base(directory
);
1542 bool bConflictData
= false;
1544 if (pInfoData
->treeconflict_theirfile
)
1546 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1547 bConflictData
= true;
1549 if (pInfoData
->treeconflict_basefile
)
1551 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1552 bConflictData
= true;
1554 if (pInfoData
->treeconflict_myfile
)
1556 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1557 bConflictData
= true;
1564 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1565 base
, theirs
, mine
, merge
);
1567 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1569 CString sConflictAction
;
1570 CString sConflictReason
;
1571 CString sResolveTheirs
;
1572 CString sResolveMine
;
1573 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1574 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1576 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1578 switch (pInfoData
->treeconflict_operation
)
1580 case svn_wc_operation_update
:
1581 switch (pInfoData
->treeconflict_action
)
1583 case svn_wc_conflict_action_edit
:
1584 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1585 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1587 case svn_wc_conflict_action_add
:
1588 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1589 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1591 case svn_wc_conflict_action_delete
:
1592 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1593 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1597 case svn_wc_operation_switch
:
1598 switch (pInfoData
->treeconflict_action
)
1600 case svn_wc_conflict_action_edit
:
1601 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1602 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1604 case svn_wc_conflict_action_add
:
1605 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1606 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1608 case svn_wc_conflict_action_delete
:
1609 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1610 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1614 case svn_wc_operation_merge
:
1615 switch (pInfoData
->treeconflict_action
)
1617 case svn_wc_conflict_action_edit
:
1618 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1619 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1621 case svn_wc_conflict_action_add
:
1622 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1623 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1625 case svn_wc_conflict_action_delete
:
1626 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1627 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1633 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1635 switch (pInfoData
->treeconflict_operation
)
1637 case svn_wc_operation_update
:
1638 switch (pInfoData
->treeconflict_action
)
1640 case svn_wc_conflict_action_edit
:
1641 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1642 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1644 case svn_wc_conflict_action_add
:
1645 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1646 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1648 case svn_wc_conflict_action_delete
:
1649 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1650 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1654 case svn_wc_operation_switch
:
1655 switch (pInfoData
->treeconflict_action
)
1657 case svn_wc_conflict_action_edit
:
1658 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1659 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1661 case svn_wc_conflict_action_add
:
1662 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1663 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1665 case svn_wc_conflict_action_delete
:
1666 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1667 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1671 case svn_wc_operation_merge
:
1672 switch (pInfoData
->treeconflict_action
)
1674 case svn_wc_conflict_action_edit
:
1675 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1676 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1678 case svn_wc_conflict_action_add
:
1679 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1680 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1682 case svn_wc_conflict_action_delete
:
1683 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1684 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1692 switch (pInfoData
->treeconflict_reason
)
1694 case svn_wc_conflict_reason_edited
:
1695 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1696 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1698 case svn_wc_conflict_reason_obstructed
:
1699 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1700 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1702 case svn_wc_conflict_reason_deleted
:
1703 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1704 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1706 case svn_wc_conflict_reason_added
:
1707 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1708 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1710 case svn_wc_conflict_reason_missing
:
1711 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1712 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1714 case svn_wc_conflict_reason_unversioned
:
1715 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1716 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1719 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1721 CTreeConflictEditorDlg dlg
;
1722 dlg
.SetConflictInfoText(sConflictReason
);
1723 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1724 dlg
.SetPath(treeConflictPath
);
1725 INT_PTR dlgRet
= dlg
.DoModal();
1726 bRet
= (dlgRet
!= IDCANCEL
);
1735 * FUNCTION : FormatDateAndTime
1736 * DESCRIPTION : Generates a displayable string from a CTime object in
1737 * system short or long format or as a relative value
1739 * option - DATE_SHORTDATE or DATE_LONGDATE
1740 * bIncluedeTime - whether to show time as well as date
1741 * bRelative - if true then relative time is shown if reasonable
1742 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1743 * rather than locale
1744 * RETURN : CString containing date/time
1746 CString
CAppUtils::FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
/*=true*/,
1747 bool bRelative
/*=false*/)
1752 datetime
= ToRelativeTimeString( cTime
);
1756 // should we use the locale settings for formatting the date/time?
1757 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
))
1761 cTime
.GetAsSystemTime( sysTime
);
1765 GetDateFormat(LOCALE_USER_DEFAULT
, option
, &sysTime
, NULL
, buf
,
1766 sizeof(buf
)/sizeof(TCHAR
)-1);
1770 datetime
+= _T(" ");
1771 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &sysTime
, NULL
, buf
, sizeof(buf
)/sizeof(TCHAR
)-1);
1777 // no, so fixed format
1780 datetime
= cTime
.Format(_T("%Y-%m-%d %H:%M:%S"));
1784 datetime
= cTime
.Format(_T("%Y-%m-%d"));
1792 * Converts a given time to a relative display string (relative to current time)
1793 * Given time must be in local timezone
1795 CString
CAppUtils::ToRelativeTimeString(CTime time
)
1798 // convert to COleDateTime
1800 time
.GetAsSystemTime( sysTime
);
1801 COleDateTime
oleTime( sysTime
);
1802 answer
= ToRelativeTimeString(oleTime
, COleDateTime::GetCurrentTime());
1807 * Generates a display string showing the relative time between the two given times as COleDateTimes
1809 CString
CAppUtils::ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
)
1812 COleDateTimeSpan ts
= RelativeTo
- time
;
1814 if(fabs(ts
.GetTotalDays()) >= 3*365)
1816 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/365, IDS_YEAR_AGO
, IDS_YEARS_AGO
);
1819 if(fabs(ts
.GetTotalDays()) >= 60)
1821 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/30, IDS_MONTH_AGO
, IDS_MONTHS_AGO
);
1825 if(fabs(ts
.GetTotalDays()) >= 14)
1827 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/7, IDS_WEEK_AGO
, IDS_WEEKS_AGO
);
1831 if(fabs(ts
.GetTotalDays()) >= 2)
1833 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays(), IDS_DAY_AGO
, IDS_DAYS_AGO
);
1837 if(fabs(ts
.GetTotalHours()) >= 2)
1839 answer
= ExpandRelativeTime( (int)ts
.GetTotalHours(), IDS_HOUR_AGO
, IDS_HOURS_AGO
);
1843 if(fabs(ts
.GetTotalMinutes()) >= 2)
1845 answer
= ExpandRelativeTime( (int)ts
.GetTotalMinutes(), IDS_MINUTE_AGO
, IDS_MINUTES_AGO
);
1849 answer
= ExpandRelativeTime( (int)ts
.GetTotalSeconds(), IDS_SECOND_AGO
, IDS_SECONDS_AGO
);
1854 * Passed a value and two resource string ids
1855 * if count is 1 then FormatString is called with format_1 and the value
1856 * otherwise format_2 is used
1857 * the formatted string is returned
1859 CString
CAppUtils::ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
)
1864 answer
.FormatMessage( format_1
, count
);
1868 answer
.FormatMessage( format_n
, count
);
1873 bool CAppUtils::IsSSHPutty()
1875 CString sshclient
=CRegString(_T("Software\\TortoiseGit\\SSH"));
1876 sshclient
=sshclient
.MakeLower();
1877 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1884 CString
CAppUtils::GetClipboardLink()
1886 if (!OpenClipboard(NULL
))
1889 CString sClipboardText
;
1890 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1893 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1894 sClipboardText
= CString(lpstr
);
1897 hglb
= GetClipboardData(CF_UNICODETEXT
);
1900 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1901 sClipboardText
= lpstr
;
1906 if(!sClipboardText
.IsEmpty())
1908 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1909 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1911 if(sClipboardText
.Find( _T("http://")) == 0)
1912 return sClipboardText
;
1914 if(sClipboardText
.Find( _T("https://")) == 0)
1915 return sClipboardText
;
1917 if(sClipboardText
.Find( _T("git://")) == 0)
1918 return sClipboardText
;
1920 if(sClipboardText
.Find( _T("ssh://")) == 0)
1921 return sClipboardText
;
1923 if(sClipboardText
.GetLength()>=2)
1924 if( sClipboardText
[1] == _T(':') )
1925 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1926 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1927 return sClipboardText
;
1930 return CString(_T(""));
1933 CString
CAppUtils::ChooseRepository(CString
*path
)
1935 CBrowseFolder browseFolder
;
1936 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1937 CString strCloneDirectory
;
1939 strCloneDirectory
=*path
;
1942 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1944 browseFolder
.SetInfo(title
);
1946 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1948 return strCloneDirectory
;
1957 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1961 dlg
.m_PathList
= list
;
1963 if(dlg
.DoModal()==IDOK
)
1965 if(dlg
.m_PathList
.GetCount() == 0)
1968 CGitProgressDlg progDlg
;
1970 theApp
.m_pMainWnd
= &progDlg
;
1971 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1973 progDlg
.SetAutoClose(autoclose
);
1975 progDlg
.SetPathList(dlg
.m_PathList
);
1976 //ProjectProperties props;
1977 //props.ReadPropsPathList(dlg.m_pathList);
1978 //progDlg.SetProjectProperties(props);
1979 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1982 if(dlg
.m_bAttachment
)
1983 flags
|= SENDMAIL_ATTACHMENT
;
1985 flags
|= SENDMAIL_COMBINED
;
1987 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1995 int CAppUtils::GetLogOutputEncode()
1999 cmd
=_T("git.exe config i18n.logOutputEncoding");
2000 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2002 cmd
=_T("git.exe config i18n.commitencoding");
2003 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2007 output
=output
.Tokenize(_T("\n"),start
);
2008 return CUnicodeUtils::GetCPCode(output
);
2012 output
=output
.Tokenize(_T("\n"),start
);
2013 return CUnicodeUtils::GetCPCode(output
);
2016 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2018 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2022 cmd
=_T("git.exe config i18n.commitencoding");
2023 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2027 output
=output
.Tokenize(_T("\n"),start
);
2028 cp
=CUnicodeUtils::GetCPCode(output
);
2030 int len
=message
.GetLength();
2033 buf
= new char[len
*4 + 4];
2034 SecureZeroMemory(buf
, (len
*4 + 4));
2036 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2038 file
.Write(buf
,lengthIncTerminator
-1);
2044 bool CAppUtils::Push()
2047 // dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
2048 if(dlg
.DoModal()==IDOK
)
2050 // CString dir=dlg.m_Directory;
2051 // CString url=dlg.m_URL;
2059 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2067 force
=_T("--force");
2069 cmd
.Format(_T("git.exe push %s %s %s \"%s\" %s"),
2072 dlg
.m_BranchSourceName
);
2073 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2075 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2078 CProgressDlg progress
;
2079 progress
.m_GitCmd
=cmd
;
2080 if(progress
.DoModal()==IDOK
)
2087 bool CAppUtils::CreateMultipleDirectory(CString
& szPath
)
2089 CString
strDir(szPath
);
2090 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2092 strDir
.AppendChar(_T('\\'));
2094 std::vector
<CString
> vPath
;
2096 bool bSuccess
= false;
2098 for (int i
=0;i
<strDir
.GetLength();++i
)
2100 if (strDir
.GetAt(i
) != _T('\\'))
2102 strTemp
.AppendChar(strDir
.GetAt(i
));
2106 vPath
.push_back(strTemp
);
2107 strTemp
.AppendChar(_T('\\'));
2111 std::vector
<CString
>::const_iterator vIter
;
2112 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2114 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;