From 6b1eb6fd9839feb5f8fa302df1efdf4cbcd60e10 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Mon, 19 Jan 2009 23:32:53 +0800 Subject: [PATCH] TGitPath Add Rename handle Signed-off-by: Frank Li --- src/Git/GitStatusListCtrl.cpp | 5 +++ src/Git/TGitPath.cpp | 37 +++++++++++++++-- src/Git/TGitPath.h | 10 ++++- src/TortoiseProc/CommitDlg.cpp | 48 +++++++++++++++------- src/TortoiseProc/TortoiseProc.vcproj | 48 +++++++++++----------- .../TortoiseProc.vcproj.FSL.B20596.user | 2 +- 6 files changed, 106 insertions(+), 44 deletions(-) diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index 46aebff..a2c7e45 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -1442,6 +1442,11 @@ void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD langID, int listInde icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath); } // relative path + CString rename; + rename.Format(_T("(from %s)"),GitPath->GetGitOldPathString()); + if(GitPath->m_Action & CTGitPath::LOGACTIONS_REPLACED) + entryname+=rename; + InsertItem(index, entryname, icon_idx); this->SetItemData(index, (DWORD_PTR)GitPath); diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index b0aec5c..018f272 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -116,11 +116,13 @@ void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory) m_bIsDirectory = bIsDirectory; } -void CTGitPath::SetFromGit(const CString& sPath) +void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath) { Reset(); m_sFwdslashPath = sPath; SanitizeRootPath(m_sFwdslashPath, true); + if(oldpath) + m_sOldFwdslashPath = *oldpath; } void CTGitPath::SetFromWin(LPCTSTR pPath) @@ -188,6 +190,10 @@ const CString& CTGitPath::GetGitPathString() const return m_sFwdslashPath; } +const CString &CTGitPath::GetGitOldPathString() const +{ + return m_sOldFwdslashPath; +} #if 0 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const { @@ -876,6 +882,7 @@ int CTGitPathList::ParserFromLog(CString &log) while( pos>=0 ) { one=log.Tokenize(_T("\n"),pos); + path.Reset(); if(one[0]==_T(':')) { int tabstart=0; @@ -901,15 +908,30 @@ int CTGitPathList::ParserFromLog(CString &log) }else { - path.SetFromGit(pathname); + int ac=path.ParserAction(action); + if(ac & CTGitPath::LOGACTIONS_REPLACED) + { + CString oldname; + int oldnametab=pathname.Find(_T("\t")); + if(oldnametab>0) + path.SetFromGit(pathname.Right(pathname.GetLength()-oldnametab-1),&pathname.Left(oldnametab)); + else + { + ASSERT(FALSE); + path.SetFromGit(pathname); + } + }else + path.SetFromGit(pathname); + path.m_Action=ac; //action must be set after setfromgit. SetFromGit will clear all status. - this->m_Action|=path.ParserAction(action); + this->m_Action|=ac; AddPath(path); } } }else { + int tabstart=0; path.Reset(); CString StatAdd=(one.Tokenize(_T("\t"),tabstart)); @@ -917,7 +939,13 @@ int CTGitPathList::ParserFromLog(CString &log) break; CString StatDel=(one.Tokenize(_T("\t"),tabstart)); //SetFromGit will reset all context of GitRev - path.SetFromGit(one.Right(one.GetLength()-tabstart)); + one=one.Right(one.GetLength()-tabstart); + int rename=one.Find(_T(" => ")); + if(rename>0) + { + path.SetFromGit(one.Right(one.GetLength()-rename-4),&one.Left(rename)); + }else + path.SetFromGit(one.Right(one.GetLength()-tabstart)); CTGitPath *GitPath=LookForGitPath(path.GetGitPathString()); if(GitPath) @@ -932,6 +960,7 @@ int CTGitPathList::ParserFromLog(CString &log) AddPath(path); } } + } return pos; } diff --git a/src/Git/TGitPath.h b/src/Git/TGitPath.h index 130e5ee..5b99a67 100644 --- a/src/Git/TGitPath.h +++ b/src/Git/TGitPath.h @@ -29,7 +29,8 @@ public: */ void SetFromGit(const char* pPath); void SetFromGit(const char* pPath, bool bIsDirectory); - void SetFromGit(const CString& sPath); + void SetFromGit(const CString& sPath,CString *OldPath=NULL); + /** * Set the path as UNICODE with backslashes */ @@ -52,6 +53,8 @@ public: * Returns the path with forward slashes. */ const CString& GetGitPathString() const; + + const CString& GetGitOldPathString() const; /** * Returns the path completely prepared to be fed the the Git APIs * It will be in UTF8, with URLs escaped, if necessary @@ -245,6 +248,11 @@ private: mutable CString m_sUIPath; mutable CStringA m_sUTF8FwdslashPath; mutable CStringA m_sUTF8FwdslashPathEscaped; + + //used for rename case + mutable CString m_sOldBackslashPath; + mutable CString m_sOldFwdslashPath; + // Have we yet determined if this is a directory or not? mutable bool m_bDirectoryKnown; mutable bool m_bIsDirectory; diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index 56ef4a8..7b23d16 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -337,6 +337,7 @@ void CCommitDlg::OnOK() //first add all the unversioned files the user selected //and check if all versioned files are selected int nUnchecked = 0; + int nchecked = 0; m_bRecursive = true; int nListItems = m_ListCtrl.GetItemCount(); @@ -347,8 +348,11 @@ void CCommitDlg::OnOK() //std::set checkedLists; //std::set uncheckedLists; - CString checkedfiles; - CString uncheckedfiles; + //CString checkedfiles; + //CString uncheckedfiles; + + CString cmd; + CString out; for (int j=0; jGetGitPathString()); + g_Git.Run(cmd,&out); + nchecked++; //checkedLists.insert(entry->GetGitPathString()); - checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" "); +// checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" "); } else { //uncheckedLists.insert(entry->GetGitPathString()); - uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" "); + if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED) + { //To init git repository, there are not HEAD, so we can use git reset command + cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString()); + g_Git.Run(cmd,&out); + } + else + { + cmd.Format(_T("git.exe reset -- %s"),entry->GetGitPathString()); + g_Git.Run(cmd,&out); + } + + // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" "); #if 0 if ((entry->status != Git_wc_status_unversioned) && (entry->status != Git_wc_status_ignored)) @@ -412,18 +430,17 @@ void CCommitDlg::OnOK() } } - CString cmd; - CString out; - if(uncheckedfiles.GetLength()>0) - { - cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles); - g_Git.Run(cmd,&out); - } + //if(uncheckedfiles.GetLength()>0) + //{ + // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles); + // g_Git.Run(cmd,&out); + //} - if(checkedfiles.GetLength()>0) + //if(checkedfiles.GetLength()>0) + if(nchecked) { - cmd.Format(_T("git.exe update-index -- %s"),checkedfiles); - g_Git.Run(cmd,&out); + // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles); + // g_Git.Run(cmd,&out); CString tempfile=::GetTempFile(); CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate ); @@ -1034,6 +1051,9 @@ void CCommitDlg::GetAutocompletionList() CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i); + if(path == NULL) + continue; + CString sPartPath =path->GetGitPathString(); m_autolist.insert(sPartPath); diff --git a/src/TortoiseProc/TortoiseProc.vcproj b/src/TortoiseProc/TortoiseProc.vcproj index 3d68115..aa7f0de 100644 --- a/src/TortoiseProc/TortoiseProc.vcproj +++ b/src/TortoiseProc/TortoiseProc.vcproj @@ -574,11 +574,11 @@ > + + + + + + - - - - - -