1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
32 * \ingroup TortoiseProc
33 * An utility class with static functions.
39 * Flags for StartExtDiff function.
46 bool bAlternativeTool
; // If true, invert selection of TortoiseMerge vs. external diff tool
48 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
49 DiffFlags
& Wait(bool b
= true) { bWait
= b
; return *this; }
50 DiffFlags
& Blame(bool b
= true) { bBlame
= b
; return *this; }
51 DiffFlags
& ReadOnly(bool b
= true) { bReadOnly
= b
; return *this; }
52 DiffFlags
& AlternativeTool(bool b
= true) { bAlternativeTool
= b
; return *this; }
59 * Launches the external merge program if there is one.
60 * \return TRUE if the program could be started
62 static BOOL
StartExtMerge(
63 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
64 const CString
& basename
= CString(), const CString
& theirname
= CString(), const CString
& yourname
= CString(),
65 const CString
& mergedname
= CString(), bool bReadOnly
= false);
68 * Starts the external patch program (currently always TortoiseMerge)
70 static BOOL
StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
,
71 const CString
& sOriginalDescription
= CString(), const CString
& sPatchedDescription
= CString(),
72 BOOL bReversed
= FALSE
, BOOL bWait
= FALSE
);
75 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
76 * If no app is associated with those file types, the default text editor is used.
78 static BOOL
StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
= FALSE
);
81 * Starts the external diff application
83 static bool StartExtDiff(
84 const CString
& file1
, const CString
& file2
,
85 const CString
& sName1
, const CString
& sName2
, const DiffFlags
& flags
);
88 * Launches the standard text viewer/editor application which is associated
90 * \return TRUE if the program could be started.
92 static BOOL
StartTextViewer(CString file
);
95 * Checks if the given file has a size of less than four, which means
96 * an 'empty' file or just newlines, i.e. an empty diff.
98 static BOOL
CheckForEmptyDiff(const CTGitPath
& sDiffPath
);
101 * Create a font which can is used for log messages, etc
103 static void CreateFontForLogs(CFont
& fontToCreate
);
106 * Launch an external application (usually the diff viewer)
108 static bool LaunchApplication(const CString
& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
);
111 * Launch the external blame viewer
113 static bool LaunchTortoiseBlame(
114 const CString
& sBlameFile
, CString Rev
, const CString
& sParams
= CString());
117 * Launch alternative editor
119 static bool LaunchAlternativeEditor(const CString
& filename
);
122 * Sets the title of a dialog
124 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
127 * Formats text in a rich edit control (version 2).
128 * text in between * chars is formatted bold
129 * text in between ^ chars is formatted italic
130 * text in between _ chars is underlined
132 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
133 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
135 static bool FileOpenSave(CString
& path
, int * filterindex
, UINT title
, UINT filter
, bool bOpen
, HWND hwndOwner
= NULL
);
137 static bool SetListCtrlBackgroundImage(HWND hListCtrl
, UINT nID
, int width
= 128, int height
= 128);
140 * guesses a name of the project from a repository URL
142 static CString
GetProjectNameFromURL(CString url
);
145 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
147 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
148 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
150 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
151 bool bAlternateDiff
= false,
152 bool bIgnoreAncestry
= false,
154 bool bMerge
= false);
156 static bool Export(CString
*BashHash
=NULL
);
157 static bool CreateBranchTag(bool IsTag
=TRUE
,CString
*CommitHash
=NULL
, bool switch_new_brach
=false);
158 static bool Switch(CString
*CommitHash
, CString initialRefName
= CString(), bool autoClose
= false);
159 static bool PerformSwitch(CString ref
, bool bForce
= false, CString sNewBranch
= CString(), bool bBranchOverride
= false, bool bTrack
= false, bool autoClose
= false);
161 // static bool IgnoreFile(CTGitPath &file, bool IsMask);
162 static bool IgnoreFile(CTGitPathList
&filelist
,bool IsMask
);
163 static bool GitReset(CString
*CommitHash
,int type
=1);
164 static bool ConflictEdit(CTGitPath
&file
,bool bAlternativeTool
=false,bool revertTheirMy
=false);
166 * FUNCTION : FormatDateAndTime
167 * DESCRIPTION : Generates a displayable string from a CTime object in
168 * system short or long format or as a relative value
170 * option - DATE_SHORTDATE or DATE_LONGDATE
171 * bIncluedeTime - whether to show time as well as date
172 * bRelative - if true then relative time is shown if reasonable
173 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
175 * RETURN : CString containing date/time
177 static CString
FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
=true,
178 bool bRelative
=false );
180 * Converts a given time to a relative display string (relative to current time)
181 * Given time must be in local timezone
183 static CString
ToRelativeTimeString(CTime time
);
185 static CString
GetMergeTempFile(CString str
,CTGitPath
&merge
);
186 static bool StashSave();
187 static int StashApply(CString ref
, bool showChanges
= true);
188 static int StashPop(bool showChanges
= true);
190 static bool IsSSHPutty();
192 static bool LaunchRemoteSetting();
194 static bool LaunchPAgent(CString
*keyfile
=NULL
,CString
* pRemote
=NULL
);
196 static CString
GetClipboardLink();
197 static CString
ChooseRepository(CString
*path
);
199 static bool SendPatchMail(CTGitPathList
&pathlist
,bool autoclose
=false);
200 static bool SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
=false);
202 static int SaveCommitUnicodeFile(CString
&filename
, CString
&mesage
);
204 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
206 static bool Fetch(CString remoteName
= _T(""), bool allowRebase
= false, bool autoClose
= false);
207 static bool Push(CString selectLocalBranch
= CString(), bool autoClose
= false);
208 static bool RequestPull(CString endrevision
= _T(""), CString repositoryUrl
= _T(""));
210 static bool CreateMultipleDirectory(const CString
&dir
);
212 static void RemoveTrailSlash(CString
&path
);
214 static BOOL
Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
215 CTGitPathList
&pathList
,
216 CTGitPathList
&selectedList
,
217 bool bSelectFilesForCommit
,
218 bool autoClose
= false);
220 static int GetCommitTemplate(CString
&temp
);
222 static BOOL
SVNDCommit();
223 static BOOL
Merge(CString
*commit
=NULL
);
224 static void RemoveTempMergeFile(CTGitPath
&path
);
225 static void EditNote(GitRev
*hash
);
226 static int GetMsysgitVersion(CString
*versionstring
=NULL
);
227 static void MarkWindowAsUnpinnable(HWND hWnd
);
230 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
231 static bool GetMimeType(const CTGitPath
& file
, CString
& mimetype
);
233 * Generates a display string showing the relative time between the two given times as COleDateTimes
235 static CString
ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
);
236 static CString
ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
);
238 static void DescribeFile(bool mode
, bool base
,CString
&descript
);