OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / Git / Git.h
1 #pragma once\r
2 #include "GitType.h"\r
3 #include "GitRev.h"\r
4 #include "GitStatus.h"\r
5 #include "GitAdminDir.h"\r
6 #include "gitdll.h"\r
7 \r
8 class CGitCall\r
9 {\r
10 public:\r
11         CGitCall(){}\r
12         CGitCall(CString cmd):m_Cmd(cmd){}\r
13 \r
14         CString                 GetCmd()const{return m_Cmd;}\r
15         void                    SetCmd(CString cmd){m_Cmd=cmd;}\r
16 \r
17         //This function is called when command output data is available.\r
18         //When this function returns 'true' the git command should be aborted.\r
19         //This behavior is not implemented yet.\r
20         virtual bool    OnOutputData(const BYTE* data, size_t size)=0;\r
21         virtual void    OnEnd(){}\r
22 \r
23 private:\r
24         CString m_Cmd;\r
25 \r
26 };\r
27 \r
28 class CTGitPath;\r
29 \r
30 class CGit\r
31 {\r
32 private:\r
33         GitAdminDir m_GitDir;\r
34 protected:\r
35         bool m_IsGitDllInited;\r
36         GIT_DIFF m_GitDiff;\r
37 public:\r
38         void CheckAndInitDll()\r
39         { \r
40                 if(!m_IsGitDllInited) \r
41                 {\r
42                         git_init();\r
43                         m_IsGitDllInited=true;\r
44                 } \r
45         }\r
46 \r
47         GIT_DIFF GetGitDiff()\r
48         {\r
49                 if(m_GitDiff)\r
50                         return m_GitDiff;\r
51                 else\r
52                 {\r
53                         git_open_diff(&m_GitDiff,"-C -M -r");\r
54                         return m_GitDiff;\r
55                 }\r
56         }\r
57 \r
58         static BOOL CheckMsysGitDir();\r
59         static CString ms_LastMsysGitDir;       // the last msysgitdir added to the path, blank if none\r
60         static int m_LogEncode;\r
61         unsigned int Hash2int(CString &hash);\r
62 //      static CString m_MsysGitPath;\r
63         \r
64         PROCESS_INFORMATION m_CurrentGitPi;\r
65 \r
66         CGit(void);\r
67         ~CGit(void);\r
68         \r
69         int Run(CString cmd, CString* output,int code);\r
70         int Run(CString cmd, BYTE_VECTOR *byte_array);\r
71         int Run(CGitCall* pcall);\r
72 \r
73         int RunAsync(CString cmd,PROCESS_INFORMATION *pi, HANDLE* hRead, CString *StdioFile=NULL);\r
74         int RunLogFile(CString cmd, CString &filename);\r
75 \r
76         bool IsFastForward(CString &from, CString &to);\r
77         CString GetConfigValue(CString name);\r
78         CString GetUserName(void);\r
79         CString GetUserEmail(void);\r
80         CString GetCurrentBranch(void);\r
81         CString GetSymbolicRef(const wchar_t* symbolicRefName = L"HEAD", bool bStripRefsHeads = true);\r
82         // read current branch name from HEAD file, returns 0 on success, -1 on failure, 1 detached (branch name "HEAD" returned)\r
83         int GetCurrentBranchFromFile(const CString &sProjectRoot, CString &sBranchOut);\r
84         BOOL CheckCleanWorkTree();\r
85         int Revert(CTGitPath &path,bool keep=true);\r
86         int Revert(CTGitPathList &list,bool keep=true);\r
87 \r
88         bool SetCurrentDir(CString path)\r
89         {\r
90                 bool b = m_GitDir.HasAdminDir(path,&m_CurrentDir);\r
91                 if(m_CurrentDir.GetLength() == 2 && m_CurrentDir[1] == _T(':')) //C: D:\r
92                 {\r
93                         m_CurrentDir+=_T('\\');\r
94                 }\r
95                 return b;\r
96         }\r
97         CString m_CurrentDir;\r
98 \r
99         typedef enum\r
100         {\r
101                 BRANCH_LOCAL=0x1,\r
102                 BRANCH_REMOTE=0x2,\r
103                 BRANCH_ALL=BRANCH_LOCAL|BRANCH_REMOTE,\r
104         }BRANCH_TYPE;\r
105 \r
106         typedef enum\r
107         {\r
108                 LOG_INFO_STAT=0x1,\r
109                 LOG_INFO_FILESTATE=0x2,\r
110                 LOG_INFO_PATCH=0x4,\r
111                 LOG_INFO_FULLHISTORY=0x8,\r
112                 LOG_INFO_BOUNDARY=0x10,\r
113         LOG_INFO_ALL_BRANCH=0x20,\r
114                 LOG_INFO_ONLY_HASH=0x40,\r
115                 LOG_INFO_DETECT_RENAME=0x80,\r
116                 LOG_INFO_DETECT_COPYRENAME=0x100,\r
117                 LOG_INFO_FIRST_PARENT = 0x200,\r
118                 LOG_INFO_NO_MERGE = 0x400,\r
119                 LOG_INFO_FOLLOW = 0x800,\r
120                 LOG_INFO_SHOW_MERGEDFILE=0x1000,\r
121                 LOG_INFO_FULL_DIFF = 0x2000,\r
122         }LOG_INFO_MASK;\r
123 \r
124         int GetRemoteList(STRING_VECTOR &list);\r
125         int GetBranchList(STRING_VECTOR &list, int *Current,BRANCH_TYPE type=BRANCH_LOCAL);\r
126         int GetTagList(STRING_VECTOR &list);\r
127         int GetMapHashToFriendName(MAP_HASH_NAME &map);\r
128         \r
129         //hash is empty means all. -1 means all\r
130 \r
131         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,\r
132                                                                 CString *from=NULL,CString *to=NULL);\r
133         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,\r
134                                                                 CString *from=NULL,CString *to=NULL);\r
135 \r
136         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,\r
137                                                                 CString *from=NULL,CString *to=NULL, bool paramonly=false);\r
138 \r
139         BOOL EnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsigned int nFlags, WGENUMFILECB *pEnumCb, void *pUserData);\r
140 \r
141         git_revnum_t GetHash(const CString &friendname);\r
142 \r
143         int BuildOutputFormat(CString &format,bool IsFull=TRUE);\r
144         //int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1);\r
145         static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8,int length=-1);\r
146 \r
147         BOOL IsInitRepos();\r
148         int ListConflictFile(CTGitPathList &list,CTGitPath *path=NULL);\r
149         int GetRefList(STRING_VECTOR &list);\r
150 \r
151         int RefreshGitIndex();\r
152 \r
153         //Example: master -> refs/heads/master\r
154         CString GetFullRefName(CString shortRefName);\r
155         //Removes 'refs/heads/' or just 'refs'. Example: refs/heads/master -> master\r
156         static CString StripRefName(CString refName);\r
157 \r
158         int GetCommitDiffList(CString &rev1,CString &rev2,CTGitPathList &outpathlist);\r
159 \r
160         \r
161 };\r
162 extern void GetTempPath(CString &path);\r
163 extern CString GetTempFile();\r
164 \r
165 \r
166 extern CGit g_Git;\r
167 \r
168 inline static BOOL wgEnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsigned int nFlags, WGENUMFILECB *pEnumCb, void *pUserData) { return g_Git.EnumFiles(pszProjectPath, pszSubPath, nFlags, pEnumCb, pUserData); }\r