X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2FGit%2FGit.cpp;h=3353b5442e0c559a7aecacbbcfba26f420853105;hb=588f1a6cb8ca51c1318db041bd0f228c84be313e;hp=0d00b9ae9178978e3172e740c84fb7acc3dfa899;hpb=585719bf1d98434dcdf2fb2162f2bf9a3938fc12;p=tortoisegit%2FTortoiseGitJp.git diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 0d00b9a..3353b54 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -6,9 +6,11 @@ #include "GitConfig.h" #include #include "UnicodeUtils.h" +#include "gitdll.h" int CGit::m_LogEncode=CP_UTF8; + static LPTSTR nextpath(LPCTSTR src, LPTSTR dst, UINT maxlen) { LPCTSTR orgsrc; @@ -126,12 +128,18 @@ CGit::CGit(void) { GetCurrentDirectory(MAX_DIRBUFFER,m_CurrentDir.GetBuffer(MAX_DIRBUFFER)); m_CurrentDir.ReleaseBuffer(); - + m_IsGitDllInited = false; + m_GitDiff=0; CheckMsysGitDir(); } CGit::~CGit(void) { + if(this->m_GitDiff) + { + git_close_diff(m_GitDiff); + m_GitDiff=0; + } } static char g_Buffer[4096]; @@ -174,7 +182,9 @@ int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CStri DWORD dwFlags = pEnv ? CREATE_UNICODE_ENVIRONMENT : 0; //DETACHED_PROCESS make ssh recognize that it has no console to launch askpass to input password. - dwFlags |= DETACHED_PROCESS; + dwFlags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP; + + memset(&this->m_CurrentGitPi,0,sizeof(PROCESS_INFORMATION)); if(!CreateProcess(NULL,(LPWSTR)cmd.GetString(), NULL,NULL,TRUE,dwFlags,pEnv,(LPWSTR)m_CurrentDir.GetString(),&si,&pi)) { @@ -186,6 +196,8 @@ int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CStri return GIT_ERROR_CREATE_PROCESS; } + m_CurrentGitPi = pi; + CloseHandle(hWrite); if(piOut) *piOut=pi; @@ -327,7 +339,7 @@ CString CGit::GetCurrentBranch(void) CString output; //Run(_T("git.exe branch"),&branch); - int ret=g_Git.Run(_T("git.exe branch"),&output,CP_UTF8); + int ret=g_Git.Run(_T("git.exe branch --no-color"),&output,CP_UTF8); if(!ret) { int pos=0; @@ -468,10 +480,8 @@ int CGit::GetLog(BYTE_VECTOR& logOut, CString &hash, CTGitPath *path ,int count return GetLog(&gitCall,hash,path,count,mask,from,to); } -//int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path ,int count,int mask) -int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path, int count, int mask,CString *from,CString *to) +CString CGit::GetLogCmd( CString &hash, CTGitPath *path, int count, int mask,CString *from,CString *to,bool paramonly) { - CString cmd; CString log; CString num; @@ -519,6 +529,9 @@ int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path, int count, if(mask& CGit::LOG_INFO_SHOW_MERGEDFILE) param += _T(" -c "); + if(mask& CGit::LOG_INFO_FULL_DIFF) + param += _T(" --full-diff "); + if(from != NULL && to != NULL) { CString range; @@ -527,40 +540,35 @@ int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path, int count, } param+=hash; - cmd.Format(_T("git.exe log %s -z --topo-order %s --parents --pretty=format:\""), + if(paramonly) + cmd.Format(_T("%s -z --topo-order %s --parents "), + num,param); + else + cmd.Format(_T("git.exe log %s -z --topo-order %s --parents --pretty=format:\""), num,param); BuildOutputFormat(log,!(mask&CGit::LOG_INFO_ONLY_HASH)); - cmd += log; - cmd += CString(_T("\" "))+hash+file; + if(paramonly) + { + cmd += hash+file; + }else + { + cmd += log; + cmd += CString(_T("\" "))+hash+file; + } - pgitCall->SetCmd(cmd); + return cmd; +} +//int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path ,int count,int mask) +int CGit::GetLog(CGitCall* pgitCall, CString &hash, CTGitPath *path, int count, int mask,CString *from,CString *to) +{ + pgitCall->SetCmd( GetLogCmd(hash,path,count,mask,from,to) ); return Run(pgitCall); // return Run(cmd,&logOut); } -#if 0 -int CGit::GetShortLog(CString &logOut,CTGitPath * path, int count) -{ - CString cmd; - CString log; - int n; - if(count<0) - n=100; - else - n=count; - cmd.Format(_T("git.exe log --left-right --boundary --topo-order -n%d --pretty=format:\""),n); - BuildOutputFormat(log,false); - cmd += log+_T("\""); - if (path) - cmd+= _T(" -- \"")+path->GetGitPathString()+_T("\""); - //cmd += CString(_T("\" HEAD~40..HEAD")); - return Run(cmd,&logOut); -} -#endif - #define BUFSIZE 512 void GetTempPath(CString &path) { @@ -704,7 +712,7 @@ int CGit::GetBranchList(STRING_VECTOR &list,int *current,BRANCH_TYPE type) { int ret; CString cmd,output; - cmd=_T("git.exe branch"); + cmd=_T("git.exe branch --no-color"); if(type==(BRANCH_LOCAL|BRANCH_REMOTE)) cmd+=_T(" -a"); @@ -740,7 +748,7 @@ int CGit::GetRemoteList(STRING_VECTOR &list) { int ret; CString cmd,output; - cmd=_T("git.exe config --get-regexp remote.*.url"); + cmd=_T("git.exe config --get-regexp \"^^remote[.].*[.]url\""); ret=g_Git.Run(cmd,&output,CP_UTF8); if(!ret) { @@ -826,7 +834,7 @@ BOOL CGit::CheckMsysGitDir() } TCHAR *oldpath,*home; - size_t homesize,size; + size_t homesize,size,httpsize; // set HOME if not set already _tgetenv_s(&homesize, NULL, 0, _T("HOME")); @@ -839,12 +847,51 @@ BOOL CGit::CheckMsysGitDir() CString str; #ifndef _TORTOISESHELL + //set http_proxy + _tgetenv_s(&httpsize, NULL, 0, _T("http_proxy")); + if (!httpsize) + { + CString regServeraddress_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-host"), _T("")); + CString regServerport_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-port"), _T("")); + CString regUsername_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-username"), _T("")); + CString regPassword_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-password"), _T("")); + CString regTimeout_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-timeout"), _T("")); + CString regExceptions_copy = CRegString(_T("Software\\TortoiseGit\\Servers\\global\\http-proxy-exceptions"), _T("")); + + CString http_proxy; + if(!regServeraddress_copy.IsEmpty()) + { + if(regServeraddress_copy.Left(4) != _T("http")) + http_proxy=_T("http://"); + + if(!regUsername_copy.IsEmpty()) + { + http_proxy += regUsername_copy; + http_proxy += _T(":")+regPassword_copy; + http_proxy += _T("@"); + } + http_proxy+=regServeraddress_copy; + if(!regServerport_copy.IsEmpty()) + { + http_proxy +=_T(":")+regServerport_copy; + } + _tputenv_s(_T("http_proxy"),http_proxy); + } + } //setup ssh client CString sshclient=CRegString(_T("Software\\TortoiseGit\\SSH")); if(!sshclient.IsEmpty()) { _tputenv_s(_T("GIT_SSH"),sshclient); + + //Setup SVN_SSH + CString ssh=sshclient; + ssh.Replace(_T("/"),_T("\\")); + ssh.Replace(_T("\\"),_T("\\\\")); + ssh=CString(_T("\""))+ssh+_T('\"'); + _tputenv_s(_T("SVN_SSH"),ssh); + }else { TCHAR sPlink[MAX_PATH]; @@ -853,6 +900,13 @@ BOOL CGit::CheckMsysGitDir() if (ptr) { _tcscpy(ptr + 1, _T("TortoisePlink.exe")); _tputenv_s(_T("GIT_SSH"), sPlink); + + //Setup SVN_SSH + CString ssh=sPlink; + ssh.Replace(_T("/"),_T("\\")); + ssh.Replace(_T("\\"),_T("\\\\")); + ssh=CString(_T("\""))+ssh+_T('\"'); + _tputenv_s(_T("SVN_SSH"),ssh); } } @@ -911,6 +965,10 @@ BOOL CGit::CheckMsysGitDir() if( !FindGitPath() ) { + if(!homesize) + { + _tputenv_s(_T("HOME"),_T("")); + } return false; } else @@ -1100,11 +1158,11 @@ BOOL CGit::EnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsig CString sSubPath = pszSubPath; sSubPath.Replace(_T('\\'), _T('/')); - cmd.Format(_T("igit.exe \"%s\" status %s \"%s\""), sProjectPath, sMode, sSubPath); + cmd.Format(_T("tgit.exe statusex \"%s\" status %s \"%s\""), sProjectPath, sMode, sSubPath); } else { - cmd.Format(_T("igit.exe \"%s\" status %s"), sProjectPath, sMode); + cmd.Format(_T("tgit.exe statusex \"%s\" status %s"), sProjectPath, sMode); } //OutputDebugStringA("---");OutputDebugStringW(cmd);OutputDebugStringA("\r\n"); @@ -1200,4 +1258,49 @@ int CGit::ListConflictFile(CTGitPathList &list,CTGitPath *path) list.ParserFromLsFile(vector); return 0; -} \ No newline at end of file +} + +bool CGit::IsFastForward(CString &from, CString &to) +{ + CString base,hash; + CString cmd; + cmd.Format(_T("git.exe merge-base %s %s"), to,from); + + if(g_Git.Run(cmd,&base,CP_ACP)) + { + //CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return false; + } + base=base.Left(40); + + hash=g_Git.GetHash(from); + + hash=hash.Left(40); + + return hash == base; +} + +unsigned int CGit::Hash2int(CString &hash) +{ + int ret=0; + for(int i=0;i<8;i++) + { + ret =ret <<4; + if(hash[i]>=_T('a')) + ret |= (hash[i]-_T('a')+10)&0xFF; + else if(hash[i]>=_T('A')) + ret |= (hash[i]-_T('A')+10)&0xFF; + else + ret |= (hash[i]-_T('0'))&0xFF; + + } + return ret; +} + +int CGit::RefreshGitIndex() +{ + CString cmd,output; + cmd=_T("git.exe update-index --refresh"); + return Run(cmd,&output,CP_ACP); +} +