Fixed issue #507: Help Spell error and push wrongly link to sync
[TortoiseGit.git] / src / Git / Git.h
blobbf602d20637f97cb04a857df88ea02fe5122c592
1 #pragma once
2 #include "GitType.h"
3 #include "GitRev.h"
4 #include "GitStatus.h"
5 #include "GitAdminDir.h"
6 #include "gitdll.h"
8 class CGitCall
10 public:
11 CGitCall(){}
12 CGitCall(CString cmd):m_Cmd(cmd){}
14 CString GetCmd()const{return m_Cmd;}
15 void SetCmd(CString cmd){m_Cmd=cmd;}
17 //This function is called when command output data is available.
18 //When this function returns 'true' the git command should be aborted.
19 //This behavior is not implemented yet.
20 virtual bool OnOutputData(const BYTE* data, size_t size)=0;
21 virtual void OnEnd(){}
23 private:
24 CString m_Cmd;
28 class CTGitPath;
29 class CEnvironment:public std::vector<TCHAR>
31 public:
32 void CopyProcessEnvironment();
33 CString GetEnv(TCHAR *name);
34 void SetEnv(TCHAR* name, TCHAR* value);
36 class CGit
38 private:
39 GitAdminDir m_GitDir;
40 protected:
41 bool m_IsGitDllInited;
42 GIT_DIFF m_GitDiff;
43 public:
44 CComCriticalSection m_critGitDllSec;
46 CEnvironment m_Environment;
48 static BOOL GitPathFileExists(CString &path)
50 if(path[0] == _T('\\') && path[1] == _T('\\'))
51 //it is netshare \\server\sharefoldername
52 // \\server\.git will create smb error log.
54 int length = path.GetLength();
56 if(length<2)
57 return false;
59 int start = path.Find(_T('\\'),2);
60 if(start<0)
61 return false;
63 start = path.Find(_T('\\'),start+1);
64 if(start<0)
65 return false;
67 return PathFileExists(path);
70 else
71 return PathFileExists(path);
73 void CheckAndInitDll()
75 if(!m_IsGitDllInited)
77 git_init();
78 m_IsGitDllInited=true;
82 GIT_DIFF GetGitDiff()
84 if(m_GitDiff)
85 return m_GitDiff;
86 else
88 git_open_diff(&m_GitDiff,"-C -M -r");
89 return m_GitDiff;
93 BOOL CheckMsysGitDir();
94 BOOL m_bInitialized;
96 static CString ms_LastMsysGitDir; // the last msysgitdir added to the path, blank if none
97 static int m_LogEncode;
98 unsigned int Hash2int(CString &hash);
99 // static CString m_MsysGitPath;
101 PROCESS_INFORMATION m_CurrentGitPi;
103 CGit(void);
104 ~CGit(void);
106 int Run(CString cmd, CString* output,int code);
107 int Run(CString cmd, BYTE_VECTOR *byte_array);
108 int Run(CGitCall* pcall);
110 int RunAsync(CString cmd,PROCESS_INFORMATION *pi, HANDLE* hRead, CString *StdioFile=NULL);
111 int RunLogFile(CString cmd, CString &filename);
113 bool IsFastForward(CString &from, CString &to);
114 CString GetConfigValue(CString name);
115 CString GetUserName(void);
116 CString GetUserEmail(void);
117 CString GetCurrentBranch(void);
118 CString GetSymbolicRef(const wchar_t* symbolicRefName = L"HEAD", bool bStripRefsHeads = true);
119 // read current branch name from HEAD file, returns 0 on success, -1 on failure, 1 detached (branch name "HEAD" returned)
120 int GetCurrentBranchFromFile(const CString &sProjectRoot, CString &sBranchOut);
121 BOOL CheckCleanWorkTree();
122 int Revert(CTGitPath &path,bool keep=true);
123 int Revert(CTGitPathList &list,bool keep=true);
125 bool SetCurrentDir(CString path)
127 bool b = m_GitDir.HasAdminDir(path,&m_CurrentDir);
128 if(m_CurrentDir.GetLength() == 2 && m_CurrentDir[1] == _T(':')) //C: D:
130 m_CurrentDir+=_T('\\');
132 return b;
134 CString m_CurrentDir;
136 typedef enum
138 BRANCH_LOCAL=0x1,
139 BRANCH_REMOTE=0x2,
140 BRANCH_ALL=BRANCH_LOCAL|BRANCH_REMOTE,
141 }BRANCH_TYPE;
143 typedef enum
145 LOG_INFO_STAT=0x1,
146 LOG_INFO_FILESTATE=0x2,
147 LOG_INFO_PATCH=0x4,
148 LOG_INFO_FULLHISTORY=0x8,
149 LOG_INFO_BOUNDARY=0x10,
150 LOG_INFO_ALL_BRANCH=0x20,
151 LOG_INFO_ONLY_HASH=0x40,
152 LOG_INFO_DETECT_RENAME=0x80,
153 LOG_INFO_DETECT_COPYRENAME=0x100,
154 LOG_INFO_FIRST_PARENT = 0x200,
155 LOG_INFO_NO_MERGE = 0x400,
156 LOG_INFO_FOLLOW = 0x800,
157 LOG_INFO_SHOW_MERGEDFILE=0x1000,
158 LOG_INFO_FULL_DIFF = 0x2000,
159 }LOG_INFO_MASK;
161 int GetRemoteList(STRING_VECTOR &list);
162 int GetBranchList(STRING_VECTOR &list, int *Current,BRANCH_TYPE type=BRANCH_LOCAL);
163 int GetTagList(STRING_VECTOR &list);
164 int GetMapHashToFriendName(MAP_HASH_NAME &map);
166 //hash is empty means all. -1 means all
168 int GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path = NULL,int count=-1,int InfoMask=LOG_INFO_FULL_DIFF|LOG_INFO_STAT|LOG_INFO_FILESTATE|LOG_INFO_BOUNDARY|LOG_INFO_DETECT_COPYRENAME|LOG_INFO_SHOW_MERGEDFILE,
169 CString *from=NULL,CString *to=NULL);
170 int GetLog(BYTE_VECTOR& logOut,CString &hash, CTGitPath *path = NULL,int count=-1,int InfoMask=LOG_INFO_FULL_DIFF|LOG_INFO_STAT|LOG_INFO_FILESTATE|LOG_INFO_BOUNDARY|LOG_INFO_DETECT_COPYRENAME|LOG_INFO_SHOW_MERGEDFILE,
171 CString *from=NULL,CString *to=NULL);
173 CString GetLogCmd(CString &hash, CTGitPath *path = NULL,int count=-1,int InfoMask=LOG_INFO_FULL_DIFF|LOG_INFO_STAT|LOG_INFO_FILESTATE|LOG_INFO_BOUNDARY|LOG_INFO_DETECT_COPYRENAME|LOG_INFO_SHOW_MERGEDFILE,
174 CString *from=NULL,CString *to=NULL, bool paramonly=false);
176 BOOL EnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsigned int nFlags, WGENUMFILECB *pEnumCb, void *pUserData);
178 git_revnum_t GetHash(const CString &friendname);
180 int BuildOutputFormat(CString &format,bool IsFull=TRUE);
181 //int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1);
182 static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8,int length=-1);
184 BOOL IsInitRepos();
185 int ListConflictFile(CTGitPathList &list,CTGitPath *path=NULL);
186 int GetRefList(STRING_VECTOR &list);
188 int RefreshGitIndex();
190 //Example: master -> refs/heads/master
191 CString GetFullRefName(CString shortRefName);
192 //Removes 'refs/heads/' or just 'refs'. Example: refs/heads/master -> master
193 static CString StripRefName(CString refName);
195 int GetCommitDiffList(CString &rev1,CString &rev2,CTGitPathList &outpathlist);
196 int GetInitAddList(CTGitPathList &outpathlist);
198 __int64 filetime_to_time_t(const FILETIME *ft)
200 long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
201 winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
202 winTime /= 10000000; /* Nano to seconds resolution */
203 return (time_t)winTime;
206 int GetFileModifyTime(LPCTSTR filename, __int64 *time, bool * isDir=NULL)
208 WIN32_FILE_ATTRIBUTE_DATA fdata;
209 if (GetFileAttributesEx(filename, GetFileExInfoStandard, &fdata))
211 if(time)
212 *time = filetime_to_time_t(&fdata.ftLastWriteTime);
214 if(isDir)
215 *isDir = !!( fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
217 return 0;
219 return -1;
222 extern void GetTempPath(CString &path);
223 extern CString GetTempFile();
226 extern CGit g_Git;
228 #if 0
229 inline static BOOL wgEnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsigned int nFlags, WGENUMFILECB *pEnumCb, void *pUserData)
231 return g_Git.EnumFiles(pszProjectPath, pszSubPath, nFlags, pEnumCb, pUserData);
233 #endif