5 #include "GitAdminDir.h"
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(){}
29 class CEnvironment
:public std::vector
<TCHAR
>
32 void CopyProcessEnvironment();
33 CString
GetEnv(TCHAR
*name
);
34 void SetEnv(TCHAR
* name
, TCHAR
* value
);
41 bool m_IsGitDllInited
;
44 CComCriticalSection m_critGitDllSec
;
47 CEnvironment m_Environment
;
49 static BOOL
GitPathFileExists(CString
&path
)
51 if(path
[0] == _T('\\') && path
[1] == _T('\\'))
52 //it is netshare \\server\sharefoldername
53 // \\server\.git will create smb error log.
55 int length
= path
.GetLength();
60 int start
= path
.Find(_T('\\'),2);
64 start
= path
.Find(_T('\\'),start
+1);
68 return PathFileExists(path
);
72 return PathFileExists(path
);
74 void CheckAndInitDll()
79 m_IsGitDllInited
=true;
89 git_open_diff(&m_GitDiff
,"-C -M -r");
94 BOOL
CheckMsysGitDir();
97 static CString ms_LastMsysGitDir
; // the last msysgitdir added to the path, blank if none
98 static int m_LogEncode
;
99 unsigned int Hash2int(CString
&hash
);
100 // static CString m_MsysGitPath;
102 PROCESS_INFORMATION m_CurrentGitPi
;
107 int Run(CString cmd
, CString
* output
,int code
);
108 int Run(CString cmd
, BYTE_VECTOR
*byte_array
);
109 int Run(CGitCall
* pcall
);
111 int RunAsync(CString cmd
,PROCESS_INFORMATION
*pi
, HANDLE
* hRead
, CString
*StdioFile
=NULL
);
112 int RunLogFile(CString cmd
, CString
&filename
);
114 int GetGitEncode(TCHAR
* configkey
);
116 bool IsFastForward(CString
&from
, CString
&to
);
117 CString
GetConfigValue(CString name
, int encoding
=CP_UTF8
, CString
*GitPath
=NULL
);
119 int SetConfigValue(CString key
, CString value
, CONFIG_TYPE type
=CONFIG_LOCAL
, int encoding
=CP_UTF8
, CString
*GitPath
=NULL
);
121 CString
GetUserName(void);
122 CString
GetUserEmail(void);
123 CString
GetCurrentBranch(void);
124 CString
GetSymbolicRef(const wchar_t* symbolicRefName
= L
"HEAD", bool bStripRefsHeads
= true);
125 // read current branch name from HEAD file, returns 0 on success, -1 on failure, 1 detached (branch name "HEAD" returned)
126 int GetCurrentBranchFromFile(const CString
&sProjectRoot
, CString
&sBranchOut
);
127 BOOL
CheckCleanWorkTree();
128 int Revert(CTGitPath
&path
,bool keep
=true);
129 int Revert(CTGitPathList
&list
,bool keep
=true);
131 bool SetCurrentDir(CString path
)
133 bool b
= m_GitDir
.HasAdminDir(path
,&m_CurrentDir
);
134 if(m_CurrentDir
.GetLength() == 2 && m_CurrentDir
[1] == _T(':')) //C: D:
136 m_CurrentDir
+=_T('\\');
140 CString m_CurrentDir
;
146 BRANCH_ALL
=BRANCH_LOCAL
|BRANCH_REMOTE
,
152 LOG_INFO_FILESTATE
=0x2,
154 LOG_INFO_FULLHISTORY
=0x8,
155 LOG_INFO_BOUNDARY
=0x10,
156 LOG_INFO_ALL_BRANCH
=0x20,
157 LOG_INFO_ONLY_HASH
=0x40,
158 LOG_INFO_DETECT_RENAME
=0x80,
159 LOG_INFO_DETECT_COPYRENAME
=0x100,
160 LOG_INFO_FIRST_PARENT
= 0x200,
161 LOG_INFO_NO_MERGE
= 0x400,
162 LOG_INFO_FOLLOW
= 0x800,
163 LOG_INFO_SHOW_MERGEDFILE
=0x1000,
164 LOG_INFO_FULL_DIFF
= 0x2000,
167 int GetRemoteList(STRING_VECTOR
&list
);
168 int GetBranchList(STRING_VECTOR
&list
, int *Current
,BRANCH_TYPE type
=BRANCH_LOCAL
);
169 int GetTagList(STRING_VECTOR
&list
);
170 int GetMapHashToFriendName(MAP_HASH_NAME
&map
);
172 //hash is empty means all. -1 means all
174 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
,
175 CString
*from
=NULL
,CString
*to
=NULL
);
176 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
,
177 CString
*from
=NULL
,CString
*to
=NULL
);
179 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
,
180 CString
*from
=NULL
,CString
*to
=NULL
, bool paramonly
=false);
182 BOOL
EnumFiles(const TCHAR
*pszProjectPath
, const TCHAR
*pszSubPath
, unsigned int nFlags
, WGENUMFILECB
*pEnumCb
, void *pUserData
);
184 git_revnum_t
GetHash(const CString
&friendname
);
186 int BuildOutputFormat(CString
&format
,bool IsFull
=TRUE
);
187 //int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1);
188 static void StringAppend(CString
*str
,BYTE
*p
,int code
=CP_UTF8
,int length
=-1);
191 int ListConflictFile(CTGitPathList
&list
,CTGitPath
*path
=NULL
);
192 int GetRefList(STRING_VECTOR
&list
);
194 int RefreshGitIndex();
195 int GetOneFile(CString Refname
, CTGitPath
&path
, CString
&outputfile
);
197 //Example: master -> refs/heads/master
198 CString
GetFullRefName(CString shortRefName
);
199 //Removes 'refs/heads/' or just 'refs'. Example: refs/heads/master -> master
200 static CString
StripRefName(CString refName
);
202 int GetCommitDiffList(CString
&rev1
,CString
&rev2
,CTGitPathList
&outpathlist
);
203 int GetInitAddList(CTGitPathList
&outpathlist
);
205 __int64
filetime_to_time_t(const FILETIME
*ft
)
207 long long winTime
= ((long long)ft
->dwHighDateTime
<< 32) + ft
->dwLowDateTime
;
208 winTime
-= 116444736000000000LL; /* Windows to Unix Epoch conversion */
209 winTime
/= 10000000; /* Nano to seconds resolution */
210 return (time_t)winTime
;
213 int GetFileModifyTime(LPCTSTR filename
, __int64
*time
, bool * isDir
=NULL
)
215 WIN32_FILE_ATTRIBUTE_DATA fdata
;
216 if (GetFileAttributesEx(filename
, GetFileExInfoStandard
, &fdata
))
219 *time
= filetime_to_time_t(&fdata
.ftLastWriteTime
);
222 *isDir
= !!( fdata
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
229 extern void GetTempPath(CString
&path
);
230 extern CString
GetTempFile();
236 inline static BOOL
wgEnumFiles(const TCHAR
*pszProjectPath
, const TCHAR
*pszSubPath
, unsigned int nFlags
, WGENUMFILECB
*pEnumCb
, void *pUserData
)
238 return g_Git
.EnumFiles(pszProjectPath
, pszSubPath
, nFlags
, pEnumCb
, pUserData
);