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
)
1201 dlg
.m_Base
=*CommitHash
;
1203 if (dlg
.DoModal() == IDOK
)
1212 branch
.Format(_T("-b %s"),dlg
.m_NewBranch
);
1216 track
=_T("--track");
1218 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1224 CProgressDlg progress
;
1225 progress
.m_GitCmd
=cmd
;
1226 if(progress
.DoModal()==IDOK
)
1233 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1236 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1240 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1244 ignorefile
+=_T("\\.gitignore");
1248 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1250 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1258 //file.ReadString(ignorelist);
1260 for(int i
=0;i
<path
.GetCount();i
++)
1264 mask
=_T("*")+path
[i
].GetFileExtension();
1265 if(ignorelist
.Find(mask
)<0)
1266 ignorelist
+=_T("\n")+mask
;
1270 ignorelist
+=_T("\n/")+path
[i
].GetGitPathString();
1273 file
.WriteString(ignorelist
);
1287 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1290 dlg
.m_ResetType
=type
;
1291 if (dlg
.DoModal() == IDOK
)
1295 switch(dlg
.m_ResetType
)
1310 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1312 CProgressDlg progress
;
1313 progress
.m_GitCmd
=cmd
;
1314 if(progress
.DoModal()==IDOK
)
1321 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1325 descript
=_T("Deleted");
1330 descript
=_T("Modified");
1333 descript
=_T("Created");
1337 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1340 file
=g_Git
.m_CurrentDir
+_T("\\")+merge
.GetDirectory().GetWinPathString()+_T("\\")+merge
.GetFilename()+_T(".")+type
+merge
.GetFileExtension();
1345 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool bAlternativeTool
)
1349 CTGitPath merge
=path
;
1350 CTGitPath directory
= merge
.GetDirectory();
1354 // we have the conflicted file (%merged)
1355 // now look for the other required files
1357 //stat.GetStatus(merge);
1358 //if (stat.status == NULL)
1364 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1366 if(g_Git
.Run(cmd
,&vector
))
1372 list
.ParserFromLsFile(vector
);
1374 if(list
.GetCount() == 0)
1377 TCHAR szTempName
[512];
1378 GetTempFileName(_T(""),_T(""),0,szTempName
);
1379 CString
temp(szTempName
);
1380 temp
=temp
.Mid(1,temp
.GetLength()-5);
1387 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1388 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1389 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1393 format
=_T("git.exe cat-file blob \":%d:%s\"");
1395 //create a empty file, incase stage is not three
1396 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1398 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1400 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1403 bool b_base
=false, b_local
=false, b_remote
=false;
1405 for(int i
=0;i
<list
.GetCount();i
++)
1409 cmd
.Format(format
,list
[i
].m_Stage
,list
[i
].GetGitPathString());
1411 if( list
[i
].m_Stage
== 1)
1414 outfile
=base
.GetWinPathString();
1416 if( list
[i
].m_Stage
== 2 )
1419 outfile
=mine
.GetWinPathString();
1421 if( list
[i
].m_Stage
== 3 )
1424 outfile
=theirs
.GetWinPathString();
1426 g_Git
.RunLogFile(cmd
,outfile
);
1429 if(b_local
&& b_remote
)
1431 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1432 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1436 CFile::Remove(mine
.GetWinPathString());
1437 CFile::Remove(theirs
.GetWinPathString());
1438 CFile::Remove(base
.GetWinPathString());
1440 CDeleteConflictDlg dlg
;
1441 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1442 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1443 dlg
.m_bShowModifiedButton
=b_base
;
1444 dlg
.m_File
=merge
.GetGitPathString();
1445 if(dlg
.DoModal() == IDOK
)
1450 cmd
.Format(_T("git.exe rm \"%s\""),merge
.GetGitPathString());
1452 cmd
.Format(_T("git.exe add \"%s\""),merge
.GetGitPathString());
1454 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
1456 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1470 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1471 base
, theirs
, mine
, merge
);
1474 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1476 // we have a text conflict, use our merge tool to resolve the conflict
1478 CTSVNPath
theirs(directory
);
1479 CTSVNPath
mine(directory
);
1480 CTSVNPath
base(directory
);
1481 bool bConflictData
= false;
1483 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1485 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1486 bConflictData
= true;
1488 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1490 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1491 bConflictData
= true;
1493 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1495 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1496 bConflictData
= true;
1503 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1504 base
, theirs
, mine
, merge
);
1507 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1509 // we have a property conflict
1510 CTSVNPath
prej(directory
);
1511 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1513 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1514 // there's a problem: the prej file contains a _description_ of the conflict, and
1515 // that description string might be translated. That means we have no way of parsing
1516 // the file to find out the conflicting values.
1517 // The only thing we can do: show a dialog with the conflict description, then
1518 // let the user either accept the existing property or open the property edit dialog
1519 // to manually change the properties and values. And a button to mark the conflict as
1521 CEditPropConflictDlg dlg
;
1522 dlg
.SetPrejFile(prej
);
1523 dlg
.SetConflictedItem(merge
);
1524 bRet
= (dlg
.DoModal() != IDCANCEL
);
1528 if (stat
.status
->tree_conflict
)
1530 // we have a tree conflict
1532 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1535 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1537 CTSVNPath
theirs(directory
);
1538 CTSVNPath
mine(directory
);
1539 CTSVNPath
base(directory
);
1540 bool bConflictData
= false;
1542 if (pInfoData
->treeconflict_theirfile
)
1544 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1545 bConflictData
= true;
1547 if (pInfoData
->treeconflict_basefile
)
1549 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1550 bConflictData
= true;
1552 if (pInfoData
->treeconflict_myfile
)
1554 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1555 bConflictData
= true;
1562 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1563 base
, theirs
, mine
, merge
);
1565 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1567 CString sConflictAction
;
1568 CString sConflictReason
;
1569 CString sResolveTheirs
;
1570 CString sResolveMine
;
1571 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1572 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1574 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1576 switch (pInfoData
->treeconflict_operation
)
1578 case svn_wc_operation_update
:
1579 switch (pInfoData
->treeconflict_action
)
1581 case svn_wc_conflict_action_edit
:
1582 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1583 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1585 case svn_wc_conflict_action_add
:
1586 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1587 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1589 case svn_wc_conflict_action_delete
:
1590 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1591 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1595 case svn_wc_operation_switch
:
1596 switch (pInfoData
->treeconflict_action
)
1598 case svn_wc_conflict_action_edit
:
1599 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1600 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1602 case svn_wc_conflict_action_add
:
1603 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1604 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1606 case svn_wc_conflict_action_delete
:
1607 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1608 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1612 case svn_wc_operation_merge
:
1613 switch (pInfoData
->treeconflict_action
)
1615 case svn_wc_conflict_action_edit
:
1616 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1617 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1619 case svn_wc_conflict_action_add
:
1620 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1621 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1623 case svn_wc_conflict_action_delete
:
1624 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1625 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1631 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1633 switch (pInfoData
->treeconflict_operation
)
1635 case svn_wc_operation_update
:
1636 switch (pInfoData
->treeconflict_action
)
1638 case svn_wc_conflict_action_edit
:
1639 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1640 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1642 case svn_wc_conflict_action_add
:
1643 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1644 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1646 case svn_wc_conflict_action_delete
:
1647 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1648 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1652 case svn_wc_operation_switch
:
1653 switch (pInfoData
->treeconflict_action
)
1655 case svn_wc_conflict_action_edit
:
1656 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1657 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1659 case svn_wc_conflict_action_add
:
1660 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1661 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1663 case svn_wc_conflict_action_delete
:
1664 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1665 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1669 case svn_wc_operation_merge
:
1670 switch (pInfoData
->treeconflict_action
)
1672 case svn_wc_conflict_action_edit
:
1673 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1674 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1676 case svn_wc_conflict_action_add
:
1677 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1678 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1680 case svn_wc_conflict_action_delete
:
1681 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1682 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1690 switch (pInfoData
->treeconflict_reason
)
1692 case svn_wc_conflict_reason_edited
:
1693 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1694 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1696 case svn_wc_conflict_reason_obstructed
:
1697 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1698 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1700 case svn_wc_conflict_reason_deleted
:
1701 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1702 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1704 case svn_wc_conflict_reason_added
:
1705 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1706 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1708 case svn_wc_conflict_reason_missing
:
1709 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1710 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1712 case svn_wc_conflict_reason_unversioned
:
1713 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1714 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1717 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1719 CTreeConflictEditorDlg dlg
;
1720 dlg
.SetConflictInfoText(sConflictReason
);
1721 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1722 dlg
.SetPath(treeConflictPath
);
1723 INT_PTR dlgRet
= dlg
.DoModal();
1724 bRet
= (dlgRet
!= IDCANCEL
);
1733 * FUNCTION : FormatDateAndTime
1734 * DESCRIPTION : Generates a displayable string from a CTime object in
1735 * system short or long format or as a relative value
1737 * option - DATE_SHORTDATE or DATE_LONGDATE
1738 * bIncluedeTime - whether to show time as well as date
1739 * bRelative - if true then relative time is shown if reasonable
1740 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1741 * rather than locale
1742 * RETURN : CString containing date/time
1744 CString
CAppUtils::FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
/*=true*/,
1745 bool bRelative
/*=false*/)
1750 datetime
= ToRelativeTimeString( cTime
);
1754 // should we use the locale settings for formatting the date/time?
1755 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
))
1759 cTime
.GetAsSystemTime( sysTime
);
1763 GetDateFormat(LOCALE_USER_DEFAULT
, option
, &sysTime
, NULL
, buf
,
1764 sizeof(buf
)/sizeof(TCHAR
)-1);
1768 datetime
+= _T(" ");
1769 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &sysTime
, NULL
, buf
, sizeof(buf
)/sizeof(TCHAR
)-1);
1775 // no, so fixed format
1778 datetime
= cTime
.Format(_T("%Y-%m-%d %H:%M:%S"));
1782 datetime
= cTime
.Format(_T("%Y-%m-%d"));
1790 * Converts a given time to a relative display string (relative to current time)
1791 * Given time must be in local timezone
1793 CString
CAppUtils::ToRelativeTimeString(CTime time
)
1796 // convert to COleDateTime
1798 time
.GetAsSystemTime( sysTime
);
1799 COleDateTime
oleTime( sysTime
);
1800 answer
= ToRelativeTimeString(oleTime
, COleDateTime::GetCurrentTime());
1805 * Generates a display string showing the relative time between the two given times as COleDateTimes
1807 CString
CAppUtils::ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
)
1810 COleDateTimeSpan ts
= RelativeTo
- time
;
1812 if(fabs(ts
.GetTotalDays()) >= 3*365)
1814 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/365, IDS_YEAR_AGO
, IDS_YEARS_AGO
);
1817 if(fabs(ts
.GetTotalDays()) >= 60)
1819 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/30, IDS_MONTH_AGO
, IDS_MONTHS_AGO
);
1823 if(fabs(ts
.GetTotalDays()) >= 14)
1825 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/7, IDS_WEEK_AGO
, IDS_WEEKS_AGO
);
1829 if(fabs(ts
.GetTotalDays()) >= 2)
1831 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays(), IDS_DAY_AGO
, IDS_DAYS_AGO
);
1835 if(fabs(ts
.GetTotalHours()) >= 2)
1837 answer
= ExpandRelativeTime( (int)ts
.GetTotalHours(), IDS_HOUR_AGO
, IDS_HOURS_AGO
);
1841 if(fabs(ts
.GetTotalMinutes()) >= 2)
1843 answer
= ExpandRelativeTime( (int)ts
.GetTotalMinutes(), IDS_MINUTE_AGO
, IDS_MINUTES_AGO
);
1847 answer
= ExpandRelativeTime( (int)ts
.GetTotalSeconds(), IDS_SECOND_AGO
, IDS_SECONDS_AGO
);
1852 * Passed a value and two resource string ids
1853 * if count is 1 then FormatString is called with format_1 and the value
1854 * otherwise format_2 is used
1855 * the formatted string is returned
1857 CString
CAppUtils::ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
)
1862 answer
.FormatMessage( format_1
, count
);
1866 answer
.FormatMessage( format_n
, count
);
1871 bool CAppUtils::IsSSHPutty()
1873 CString sshclient
=CRegString(_T("Software\\TortoiseGit\\SSH"));
1874 sshclient
=sshclient
.MakeLower();
1875 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1882 CString
CAppUtils::GetClipboardLink()
1884 if (!OpenClipboard(NULL
))
1887 CString sClipboardText
;
1888 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1891 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1892 sClipboardText
= CString(lpstr
);
1895 hglb
= GetClipboardData(CF_UNICODETEXT
);
1898 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1899 sClipboardText
= lpstr
;
1904 if(!sClipboardText
.IsEmpty())
1906 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1907 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1909 if(sClipboardText
.Find( _T("http://")) == 0)
1910 return sClipboardText
;
1912 if(sClipboardText
.Find( _T("https://")) == 0)
1913 return sClipboardText
;
1915 if(sClipboardText
.Find( _T("git://")) == 0)
1916 return sClipboardText
;
1918 if(sClipboardText
.Find( _T("ssh://")) == 0)
1919 return sClipboardText
;
1921 if(sClipboardText
.GetLength()>=2)
1922 if( sClipboardText
[1] == _T(':') )
1923 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1924 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1925 return sClipboardText
;
1928 return CString(_T(""));
1931 CString
CAppUtils::ChooseRepository(CString
*path
)
1933 CBrowseFolder browseFolder
;
1934 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1935 CString strCloneDirectory
;
1937 strCloneDirectory
=*path
;
1940 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1942 browseFolder
.SetInfo(title
);
1944 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1946 return strCloneDirectory
;
1955 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1959 dlg
.m_PathList
= list
;
1961 if(dlg
.DoModal()==IDOK
)
1963 if(dlg
.m_PathList
.GetCount() == 0)
1966 CGitProgressDlg progDlg
;
1968 theApp
.m_pMainWnd
= &progDlg
;
1969 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1971 progDlg
.SetAutoClose(autoclose
);
1973 progDlg
.SetPathList(dlg
.m_PathList
);
1974 //ProjectProperties props;
1975 //props.ReadPropsPathList(dlg.m_pathList);
1976 //progDlg.SetProjectProperties(props);
1977 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1980 if(dlg
.m_bAttachment
)
1981 flags
|= SENDMAIL_ATTACHMENT
;
1983 flags
|= SENDMAIL_COMBINED
;
1985 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1993 int CAppUtils::GetLogOutputEncode()
1997 cmd
=_T("git.exe config i18n.logOutputEncoding");
1998 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2000 cmd
=_T("git.exe config i18n.commitencoding");
2001 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2005 output
=output
.Tokenize(_T("\n"),start
);
2006 return CUnicodeUtils::GetCPCode(output
);
2010 output
=output
.Tokenize(_T("\n"),start
);
2011 return CUnicodeUtils::GetCPCode(output
);
2014 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2016 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2020 cmd
=_T("git.exe config i18n.commitencoding");
2021 if(g_Git
.Run(cmd
,&output
,CP_ACP
))
2025 output
=output
.Tokenize(_T("\n"),start
);
2026 cp
=CUnicodeUtils::GetCPCode(output
);
2028 int len
=message
.GetLength();
2031 buf
= new char[len
*4 + 4];
2032 SecureZeroMemory(buf
, (len
*4 + 4));
2034 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2036 file
.Write(buf
,lengthIncTerminator
-1);
2042 bool CAppUtils::Push()
2045 // dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
2046 if(dlg
.DoModal()==IDOK
)
2048 // CString dir=dlg.m_Directory;
2049 // CString url=dlg.m_URL;
2057 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2065 force
=_T("--force");
2067 cmd
.Format(_T("git.exe push %s %s %s \"%s\" %s"),
2070 dlg
.m_BranchSourceName
);
2071 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2073 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2076 CProgressDlg progress
;
2077 progress
.m_GitCmd
=cmd
;
2078 if(progress
.DoModal()==IDOK
)
2085 bool CAppUtils::CreateMultipleDirectory(CString
& szPath
)
2087 CString
strDir(szPath
);
2088 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2090 strDir
.AppendChar(_T('\\'));
2092 std::vector
<CString
> vPath
;
2094 bool bSuccess
= false;
2096 for (int i
=0;i
<strDir
.GetLength();++i
)
2098 if (strDir
.GetAt(i
) != _T('\\'))
2100 strTemp
.AppendChar(strDir
.GetAt(i
));
2104 vPath
.push_back(strTemp
);
2105 strTemp
.AppendChar(_T('\\'));
2109 std::vector
<CString
>::const_iterator vIter
;
2110 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2112 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;