1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "HistoryCombo.h"
23 #include "CommonAppUtils.h"
27 struct git_transfer_progress
;
35 * \ingroup TortoiseProc
36 * An utility class with static functions.
38 class CAppUtils
: public CCommonAppUtils
42 * Flags for StartExtDiff function.
49 bool bAlternativeTool
; // If true, invert selection of TortoiseGitMerge vs. external diff tool
51 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
52 DiffFlags
& Wait(bool b
= true) { bWait
= b
; return *this; }
53 DiffFlags
& Blame(bool b
= true) { bBlame
= b
; return *this; }
54 DiffFlags
& ReadOnly(bool b
= true) { bReadOnly
= b
; return *this; }
55 DiffFlags
& AlternativeTool(bool b
= true) { bAlternativeTool
= b
; return *this; }
62 * Launches the external merge program if there is one.
63 * \return TRUE if the program could be started
65 static BOOL
StartExtMerge(
66 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
67 const CString
& basename
= CString(), const CString
& theirname
= CString(), const CString
& yourname
= CString(),
68 const CString
& mergedname
= CString(), bool bReadOnly
= false);
71 * Starts the external patch program (currently always TortoiseGitMerge)
73 static BOOL
StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
,
74 const CString
& sOriginalDescription
= CString(), const CString
& sPatchedDescription
= CString(),
75 BOOL bReversed
= FALSE
, BOOL bWait
= FALSE
);
78 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
79 * If no app is associated with those file types, the default text editor is used.
81 static BOOL
StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
= FALSE
);
84 * Sets up all the default diff and merge scripts.
85 * \param force if true, overwrite all existing entries
86 * \param either "Diff", "Merge" or an empty string
88 static bool SetupDiffScripts(bool force
, const CString
& type
);
91 * Starts the external diff application
93 static bool StartExtDiff(
94 const CString
& file1
, const CString
& file2
,
95 const CString
& sName1
, const CString
& sName2
,
96 const CString
& originalFile1
, const CString
& originalFile2
,
97 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
, const DiffFlags
& flags
);
100 * Launches the standard text viewer/editor application which is associated
102 * \return TRUE if the program could be started.
104 static BOOL
StartTextViewer(CString file
);
107 * Checks if the given file has a size of less than four, which means
108 * an 'empty' file or just newlines, i.e. an empty diff.
110 static BOOL
CheckForEmptyDiff(const CTGitPath
& sDiffPath
);
113 * Create a font which can is used for log messages, etc
115 static void CreateFontForLogs(CFont
& fontToCreate
);
118 * Launch the external blame viewer
120 static bool LaunchTortoiseBlame(
121 const CString
& sBlameFile
, CString Rev
, const CString
& sParams
= CString());
124 * Launch alternative editor
126 static bool LaunchAlternativeEditor(const CString
& filename
, bool uac
= false);
129 * Sets the title of a dialog
131 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
134 * Formats text in a rich edit control (version 2).
135 * text in between * chars is formatted bold
136 * text in between ^ chars is formatted italic
137 * text in between _ chars is underlined
139 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
140 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
143 * guesses a name of the project from a repository URL
145 static CString
GetProjectNameFromURL(CString url
);
148 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
150 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
151 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
153 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
154 bool bAlternateDiff
= false,
155 bool bIgnoreAncestry
= false,
158 bool bCompact
= false);
160 static bool Export(CString
*BashHash
=NULL
);
161 static bool CreateBranchTag(bool IsTag
=TRUE
,CString
*CommitHash
=NULL
, bool switch_new_brach
=false);
162 static bool Switch(CString initialRefName
= CString(), bool autoClose
= false);
163 static bool PerformSwitch(CString ref
, bool bForce
= false, CString sNewBranch
= CString(), bool bBranchOverride
= false, BOOL bTrack
= 2, bool autoClose
= false);
165 static bool IgnoreFile(CTGitPathList
&filelist
,bool IsMask
);
166 static bool GitReset(CString
*CommitHash
,int type
=1);
167 static bool ConflictEdit(CTGitPath
&file
,bool bAlternativeTool
=false,bool revertTheirMy
=false);
169 static CString
GetMergeTempFile(CString str
,CTGitPath
&merge
);
170 static bool StashSave();
171 static bool StashApply(CString ref
, bool showChanges
= true);
172 static bool StashPop(bool showChanges
= true);
174 static bool IsSSHPutty();
176 static bool LaunchRemoteSetting();
178 static bool LaunchPAgent(CString
*keyfile
=NULL
,CString
* pRemote
=NULL
);
180 static CString
GetClipboardLink();
181 static CString
ChooseRepository(CString
*path
);
183 static bool SendPatchMail(CTGitPathList
&pathlist
,bool autoclose
=false);
184 static bool SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
=false);
186 static int SaveCommitUnicodeFile(CString
&filename
, CString
&mesage
);
188 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
190 static bool Fetch(CString remoteName
= _T(""), bool allowRebase
= false, bool autoClose
= false);
191 static bool Push(CString selectLocalBranch
= CString(), bool autoClose
= false);
192 static bool RequestPull(CString endrevision
= _T(""), CString repositoryUrl
= _T(""));
194 static bool CreateMultipleDirectory(const CString
&dir
);
196 static void RemoveTrailSlash(CString
&path
);
198 static bool CheckUserData();
200 static BOOL
Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
201 CTGitPathList
&pathList
,
202 CTGitPathList
&selectedList
,
203 bool bSelectFilesForCommit
,
204 bool autoClose
= false);
206 static int GetCommitTemplate(CString
&temp
);
208 static BOOL
SVNDCommit();
209 static BOOL
Merge(CString
*commit
=NULL
);
210 static void RemoveTempMergeFile(CTGitPath
&path
);
211 static void EditNote(GitRev
*hash
);
212 static int GetMsysgitVersion(CString
*versionstring
=NULL
);
213 static void MarkWindowAsUnpinnable(HWND hWnd
);
215 static bool BisectStart(CString lastGood
, CString firstBad
, bool autoClose
= false);
217 static int Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int allowed_types
, void *payload
);
220 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
221 static bool GetMimeType(const CTGitPath
& file
, CString
& mimetype
);
223 static bool OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
);
225 static void DescribeFile(bool mode
, bool base
,CString
&descript
);