From 6edcb67f2b7c7f99556d9ccbb211259122f5476d Mon Sep 17 00:00:00 2001 From: Frank Li Date: Thu, 10 Feb 2011 21:05:59 +0800 Subject: [PATCH] use gitdll gethash and clean up some warning Signed-off-by: Frank Li --- src/Git/Git.cpp | 62 +++++++++++++++----------- src/Git/Git.h | 5 ++- src/Git/GitStatus.cpp | 2 +- src/Git/stdafx.h | 2 + src/TortoiseProc/BrowseRefsDlg.cpp | 10 ++--- src/TortoiseProc/Commands/SVNRebaseCommand.cpp | 2 +- src/TortoiseProc/CommitDlg.cpp | 2 +- src/TortoiseProc/GitLogListAction.cpp | 2 +- src/TortoiseProc/GitLogListBase.cpp | 7 ++- src/TortoiseProc/GitLogListBase.h | 2 +- src/TortoiseProc/LogDlg.cpp | 2 +- src/TortoiseProc/RebaseDlg.cpp | 33 ++++++-------- src/TortoiseProc/RebaseDlg.h | 4 +- src/TortoiseProc/SyncDlg.cpp | 14 +++--- src/TortoiseProc/SyncDlg.h | 2 +- src/TortoiseShell/ShellCache.h | 6 ++- 16 files changed, 82 insertions(+), 75 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 1c9a22e30..8b305209e 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -789,17 +789,34 @@ int CGit::RunLogFile(CString cmd,CString &filename) // return 0; } -git_revnum_t CGit::GetHash(const CString &friendname) +CGitHash CGit::GetHash(TCHAR* friendname) { - CString cmd; - CString out; - cmd.Format(_T("git.exe rev-parse %s" ),friendname); - Run(cmd,&out,CP_UTF8); -// int pos=out.ReverseFind(_T('\n')); - int pos=out.FindOneOf(_T("\r\n")); - if(pos>0) - return out.Left(pos); - return out; + if(this->m_IsUseGitDLL) + { + this->CheckAndInitDll(); + + CGitHash hash; + CStringA ref; + ref = CUnicodeUtils::GetMulti(friendname,CP_ACP); + try + { + git_get_sha1(ref, hash.m_hash); + + }catch(...) + { + } + return hash; + + }else + { + CString cmd; + CString out; + cmd.Format(_T("git.exe rev-parse %s" ),friendname); + Run(cmd,&out,CP_UTF8); + // int pos=out.ReverseFind(_T('\n')); + int pos=out.FindOneOf(_T("\r\n")); + return CGitHash(out); + } } int CGit::GetInitAddList(CTGitPathList &outputlist) @@ -1452,7 +1469,8 @@ int CGit::ListConflictFile(CTGitPathList &list,CTGitPath *path) bool CGit::IsFastForward(CString &from, CString &to) { - CString base,hash; + CString base; + CGitHash basehash,hash; CString cmd; cmd.Format(_T("git.exe merge-base %s %s"), to,from); @@ -1461,28 +1479,20 @@ bool CGit::IsFastForward(CString &from, CString &to) //CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); return false; } - base=base.Left(40); - - hash=g_Git.GetHash(from); + basehash = base.Left(40); - hash=hash.Left(40); + hash=g_Git.GetHash(from.GetBuffer()); - return hash == base; + return hash == basehash; } -unsigned int CGit::Hash2int(CString &hash) +unsigned int CGit::Hash2int(CGitHash &hash) { int ret=0; - for(int i=0;i<8;i++) + for(int i=0;i<4;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; - + ret = ret << 8; + ret |= hash.m_hash[i]; } return ret; } diff --git a/src/Git/Git.h b/src/Git/Git.h index 987483229..09275a426 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -112,7 +112,7 @@ public: static CString ms_LastMsysGitDir; // the last msysgitdir added to the path, blank if none static int m_LogEncode; - unsigned int Hash2int(CString &hash); + unsigned int Hash2int(CGitHash &hash); // static CString m_MsysGitPath; PROCESS_INFORMATION m_CurrentGitPi; @@ -198,7 +198,8 @@ public: BOOL EnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsigned int nFlags, WGENUMFILECB *pEnumCb, void *pUserData); - git_revnum_t GetHash(const CString &friendname); + CGitHash GetHash(TCHAR* friendname); + CGitHash GetHash(CString ref){return GetHash(ref.GetBuffer());} int BuildOutputFormat(CString &format,bool IsFull=TRUE); //int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1); diff --git a/src/Git/GitStatus.cpp b/src/Git/GitStatus.cpp index d53455d54..335614496 100644 --- a/src/Git/GitStatus.cpp +++ b/src/Git/GitStatus.cpp @@ -388,7 +388,7 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false { // done to match TSVN functionality of this function (not sure if any code uses the reutrn val) // if TGit does not need this, then change the return type of function - youngest = g_Git.GetHash(CString(_T("HEAD"))); + youngest = g_Git.GetHash(_T("HEAD")); } return youngest; diff --git a/src/Git/stdafx.h b/src/Git/stdafx.h index 88411fdd6..7e0e3facc 100644 --- a/src/Git/stdafx.h +++ b/src/Git/stdafx.h @@ -5,6 +5,8 @@ #pragma once +#define _CRT_SECURE_NO_WARNINGS + #include "targetver.h" #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers diff --git a/src/TortoiseProc/BrowseRefsDlg.cpp b/src/TortoiseProc/BrowseRefsDlg.cpp index b7f00a8dd..2d86752d5 100644 --- a/src/TortoiseProc/BrowseRefsDlg.cpp +++ b/src/TortoiseProc/BrowseRefsDlg.cpp @@ -427,14 +427,14 @@ bool CBrowseRefsDlg::ConfirmDeleteRef(VectorPShadowTree& leafs) csMessage += L""; //Check if branch is fully merged in HEAD - CString branchHash = g_Git.GetHash(leafs[0]->GetRefName()); - CString commonAncestor; + CGitHash branchHash = g_Git.GetHash(leafs[0]->GetRefName()); + CGitHash commonAncestor; + CString commonAncestorstr; CString cmd; cmd.Format(L"git.exe merge-base HEAD %s", leafs[0]->GetRefName()); - g_Git.Run(cmd,&commonAncestor,CP_UTF8); + g_Git.Run(cmd,&commonAncestorstr,CP_UTF8); - branchHash=branchHash.Left(40); - commonAncestor=commonAncestor.Left(40); + commonAncestor=commonAncestorstr; if(commonAncestor != branchHash) { diff --git a/src/TortoiseProc/Commands/SVNRebaseCommand.cpp b/src/TortoiseProc/Commands/SVNRebaseCommand.cpp index 5d8d5a70a..9d689cee5 100644 --- a/src/TortoiseProc/Commands/SVNRebaseCommand.cpp +++ b/src/TortoiseProc/Commands/SVNRebaseCommand.cpp @@ -75,7 +75,7 @@ bool SVNRebaseCommand::Execute() dlg.m_Upstream=out; - CString UpStreamOldHash,HeadHash,UpStreamNewHash; + CGitHash UpStreamOldHash,HeadHash,UpStreamNewHash; UpStreamOldHash=g_Git.GetHash(out); HeadHash = g_Git.GetHash(_T("HEAD")); CProgressDlg progress; diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index eb2acc5b1..27885673d 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -664,7 +664,7 @@ void CCommitDlg::OnOK() BSTR logMessage = m_sLogMessage.AllocSysString(); - CString hash=g_Git.GetHash(CString(_T("HEAD"))); + CGitHash hash=g_Git.GetHash(_T("HEAD")); LONG version = g_Git.Hash2int(hash); BSTR temp = NULL; diff --git a/src/TortoiseProc/GitLogListAction.cpp b/src/TortoiseProc/GitLogListAction.cpp index 21ad45c73..775e67e8d 100644 --- a/src/TortoiseProc/GitLogListAction.cpp +++ b/src/TortoiseProc/GitLogListAction.cpp @@ -405,7 +405,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe break; } - headhash=g_Git.GetHash(CString(_T("HEAD"))); + headhash=g_Git.GetHash(_T("HEAD")); if(!g_Git.CheckCleanWorkTree()) { diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 9355e0272..4b0142699 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -99,7 +99,7 @@ CGitLogListBase::CGitLogListBase():CHintListCtrl() g_Git.GetMapHashToFriendName(m_HashMap); m_CurrentBranch=g_Git.GetCurrentBranch(); - this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40); + this->m_HeadHash=g_Git.GetHash(_T("HEAD")); m_From=-1;; m_To=-1; @@ -1714,10 +1714,9 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if(headindex>=0) { head.Format(_T("HEAD~%d"),LastSelect-headindex); - CString hash=g_Git.GetHash(head); - hash=hash.Left(40); + CGitHash hash=g_Git.GetHash(head); GitRev* pLastEntry = reinterpret_cast(m_arShownList.SafeGetAt(LastSelect)); - if(pLastEntry->m_CommitHash.ToString() == hash) { + if(pLastEntry->m_CommitHash == hash) { popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE); bAddSeparator = true; } diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index be5fb2721..b0bb1adbf 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -290,7 +290,7 @@ public: m_HashMap.clear(); g_Git.GetMapHashToFriendName(m_HashMap); m_CurrentBranch=g_Git.GetCurrentBranch(); - this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40); + this->m_HeadHash=g_Git.GetHash(_T("HEAD")); m_wcRev.m_ParentHash.clear(); m_wcRev.m_ParentHash.push_back(m_HeadHash); } diff --git a/src/TortoiseProc/LogDlg.cpp b/src/TortoiseProc/LogDlg.cpp index d34e9a011..077559184 100644 --- a/src/TortoiseProc/LogDlg.cpp +++ b/src/TortoiseProc/LogDlg.cpp @@ -1269,7 +1269,7 @@ void CLogDlg::DiffSelectedFile() } -void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool blame, bool unified) +void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool /*blame*/, bool /*unified*/) { DialogEnableWindow(IDOK, FALSE); // SetPromptApp(&theApp); diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index 59e97bb64..54f39eb2f 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -421,16 +421,17 @@ void CRebaseDlg::OnCbnSelchangeUpstream() void CRebaseDlg::FetchLogList() { - CString base,hash; + CGitHash base,hash; + CString basestr; CString cmd; m_IsFastForward=FALSE; cmd.Format(_T("git.exe merge-base %s %s"), m_UpstreamCtrl.GetString(),m_BranchCtrl.GetString()); - if(g_Git.Run(cmd,&base,CP_ACP)) + if(g_Git.Run(cmd,&basestr,CP_ACP)) { - CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + CMessageBox::Show(NULL,basestr,_T("TortoiseGit"),MB_OK|MB_ICONERROR); return; } - base=base.Left(40); + base=basestr; hash=g_Git.GetHash(m_BranchCtrl.GetString()); @@ -446,8 +447,6 @@ void CRebaseDlg::FetchLogList() return; } - hash=hash.Left(40); - if(hash == base ) { //fast forword @@ -470,13 +469,7 @@ void CRebaseDlg::FetchLogList() if(!this->m_bForce) { - cmd.Format(_T("git.exe rev-parse %s"), m_UpstreamCtrl.GetString()); - if( g_Git.Run(cmd,&hash,CP_ACP)) - { - CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); - return; - } - hash=hash.Left(40); + hash=g_Git.GetHash(m_UpstreamCtrl.GetString()); if( base == hash ) { @@ -673,10 +666,10 @@ int CRebaseDlg::StartRebase() if( !this->m_IsCherryPick ) { - cmd.Format(_T("git.exe rev-parse %s"),this->m_BranchCtrl.GetString()); - if(g_Git.Run(cmd,&this->m_OrigBranchHash,CP_UTF8)) + m_OrigBranchHash = g_Git.GetHash(this->m_BranchCtrl.GetString()); + if(m_OrigBranchHash.IsEmpty()) { - this->AddLogString(m_OrigBranchHash); + this->AddLogString(m_OrigBranchHash.ToString()); return -1; } this->AddLogString(_T("Start Rebase\r\n")); @@ -707,7 +700,7 @@ int CRebaseDlg::FinishRebase() if(this->m_IsCherryPick) //cherry pick mode no "branch", working at upstream branch return 0; - git_revnum_t head = g_Git.GetHash(CString(_T("HEAD"))); + git_revnum_t head = g_Git.GetHash(_T("HEAD")); CString out,cmd; out.Empty(); @@ -1395,7 +1388,7 @@ void CRebaseDlg::OnBnClickedAbort() if(this->m_IsFastForward) { - cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.Left(40)); + cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.ToString()); if(g_Git.Run(cmd,&out,CP_UTF8)) { AddLogString(out); @@ -1411,7 +1404,7 @@ void CRebaseDlg::OnBnClickedAbort() return ; } - cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash.Left(40)); + cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash.ToString()); if(g_Git.Run(cmd,&out,CP_UTF8)) { AddLogString(out); @@ -1431,7 +1424,7 @@ void CRebaseDlg::OnBnClickedAbort() return ; } - cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.Left(40)); + cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.ToString()); if(g_Git.Run(cmd,&out,CP_UTF8)) { AddLogString(out); diff --git a/src/TortoiseProc/RebaseDlg.h b/src/TortoiseProc/RebaseDlg.h index d8ceba694..d0b152413 100644 --- a/src/TortoiseProc/RebaseDlg.h +++ b/src/TortoiseProc/RebaseDlg.h @@ -81,8 +81,8 @@ protected: BOOL m_IsFastForward; - CString m_OrigBranchHash; - CString m_OrigUpstreamHash; + CGitHash m_OrigBranchHash; + CGitHash m_OrigUpstreamHash; int VerifyNoConflict(); CString GetRebaseModeName(int rebasemode); diff --git a/src/TortoiseProc/SyncDlg.cpp b/src/TortoiseProc/SyncDlg.cpp index 1fde56353..dc1d8cccb 100644 --- a/src/TortoiseProc/SyncDlg.cpp +++ b/src/TortoiseProc/SyncDlg.cpp @@ -105,7 +105,7 @@ void CSyncDlg::OnBnClickedButtonPull() this->UpdateData(); UpdateCombox(); - m_oldHash = g_Git.GetHash(CString(_T("HEAD"))); + m_oldHash = g_Git.GetHash(_T("HEAD")); if( CurrentEntry == 0) { @@ -260,7 +260,7 @@ void CSyncDlg::PullComplete() this->FetchOutList(true); CString newhash; - newhash = g_Git.GetHash(CString(_T("HEAD"))); + newhash = g_Git.GetHash(_T("HEAD")); if( this ->m_GitCmdStatus ) { @@ -305,10 +305,10 @@ void CSyncDlg::PullComplete() this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true); this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true); - this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash); + this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash.ToString()); m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE, - &this->m_oldHash,&newhash); + &this->m_oldHash.ToString(),&newhash); } this->ShowTab(IDC_IN_LOGLIST); } @@ -436,7 +436,7 @@ void CSyncDlg::OnBnClickedButtonPush() void CSyncDlg::OnBnClickedButtonApply() { CString oldhash; - oldhash=g_Git.GetHash(CString(_T("HEAD"))); + oldhash=g_Git.GetHash(_T("HEAD")); CImportPatchDlg dlg; CString cmd,output; @@ -461,7 +461,7 @@ void CSyncDlg::OnBnClickedButtonApply() this->m_ctrlCmdOut.ReplaceSel(output); } - CString newhash=g_Git.GetHash(CString(_T("HEAD"))); + CString newhash=g_Git.GetHash(_T("HEAD")); this->m_InLogList.Clear(); this->m_InChangeFileList.Clear(); @@ -859,7 +859,7 @@ void CSyncDlg::FetchOutList(bool force) return ; } - else if(g_Git.GetHash(remotebranch).GetLength()<40) + else if(g_Git.GetHash(remotebranch).IsEmpty()) { CString str; str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch); diff --git a/src/TortoiseProc/SyncDlg.h b/src/TortoiseProc/SyncDlg.h index d1137a799..41694348d 100644 --- a/src/TortoiseProc/SyncDlg.h +++ b/src/TortoiseProc/SyncDlg.h @@ -132,7 +132,7 @@ protected: CString m_OutLocalBranch; CString m_OutRemoteBranch; - CString m_oldHash; + CGitHash m_oldHash; void ShowProgressCtrl(bool bShow=true); void ShowInputCtrl(bool bShow=true); diff --git a/src/TortoiseShell/ShellCache.h b/src/TortoiseShell/ShellCache.h index 03dd9e3cb..5c8805898 100644 --- a/src/TortoiseShell/ShellCache.h +++ b/src/TortoiseShell/ShellCache.h @@ -86,8 +86,10 @@ public: excludedasnormalticker = cachetypeticker; hidemenusforunversioneditemsticker = cachetypeticker; excontextticker = cachetypeticker; - menulayoutlow = CRegStdWORD(_T("Software\\TortoiseGit\\ContextMenuEntries"), MENUSYNC|MENUCREATEREPOS|MENUCLONE|MENUCOMMIT); - menulayouthigh = CRegStdWORD(_T("Software\\TortoiseGit\\ContextMenuEntrieshigh"), (MENUSYNC|MENUCREATEREPOS|MENUCLONE|MENUCOMMIT)>>32); + + unsigned __int64 entries = MENUSYNC|MENUCREATEREPOS|MENUCLONE|MENUCOMMIT; + menulayoutlow = CRegStdWORD(_T("Software\\TortoiseGit\\ContextMenuEntries"), entries&0xFFFFFFFF); + menulayouthigh = CRegStdWORD(_T("Software\\TortoiseGit\\ContextMenuEntrieshigh"), entries>>32); unsigned __int64 ext=(MENUSVNIGNORE|MENUREFLOG|MENUREFBROWSE|MENUSTASHAPPLY|MENUDELUNVERSIONED|MENUSUBSYNC|MENUCREATEPATCH); menuextlow = CRegStdWORD(_T("Software\\TortoiseGit\\ContextMenuExtEntriesLow"), ext&0xFFFFFFFF ); -- 2.11.4.GIT