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
;
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();
59 int start
= path
.Find(_T('\\'),2);
63 start
= path
.Find(_T('\\'),start
+1);
67 return PathFileExists(path
);
71 return PathFileExists(path
);
73 void CheckAndInitDll()
78 m_IsGitDllInited
=true;
88 git_open_diff(&m_GitDiff
,"-C -M -r");
93 BOOL
CheckMsysGitDir();
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
;
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('\\');
134 CString m_CurrentDir
;
140 BRANCH_ALL
=BRANCH_LOCAL
|BRANCH_REMOTE
,
146 LOG_INFO_FILESTATE
=0x2,
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,
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);
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
))
212 *time
= filetime_to_time_t(&fdata
.ftLastWriteTime
);
215 *isDir
= !!( fdata
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
222 extern void GetTempPath(CString
&path
);
223 extern CString
GetTempFile();
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
);