OSDN Git Service

Share resource file between TortoiseGitBlame and TortoiseProc
[tortoisegit/TortoiseGitJp.git] / src / Git / GitRev.cpp
index f1e4f37..bc9aee3 100644 (file)
@@ -1,10 +1,12 @@
 #include "StdAfx.h"\r
 #include "GitRev.h"\r
-\r
+#include "Git.h"\r
 \r
 GitRev::GitRev(void)\r
 {\r
        m_Action=0;\r
+       m_IsFull = 0;\r
+       m_IsUpdateing = 0;\r
 }\r
 \r
 GitRev::~GitRev(void)\r
@@ -20,6 +22,37 @@ GitRev& GitRev::operator=(GitRev &rev)
        return *this;\r
 }\r
 #endif\r
+void GitRev::Clear()\r
+{\r
+       this->m_Action=0;\r
+       this->m_Files.Clear();\r
+       this->m_Action=0;\r
+       this->m_ParentHash.clear();\r
+       m_CommitterName.Empty();\r
+       m_CommitterEmail.Empty();\r
+       m_Body.Empty();\r
+       m_Subject.Empty();\r
+       m_CommitHash.Empty();\r
+       m_Mark=0;\r
+\r
+}\r
+int GitRev::CopyFrom(GitRev &rev)\r
+{\r
+       m_AuthorName    =rev.m_AuthorName       ;\r
+       m_AuthorEmail   =rev.m_AuthorEmail      ;\r
+       m_AuthorDate    =rev.m_AuthorDate       ;\r
+       m_CommitterName =rev.m_CommitterName    ;\r
+       m_CommitterEmail=rev.m_CommitterEmail;\r
+       m_CommitterDate =rev.m_CommitterDate    ;\r
+       m_Subject               =rev.m_Subject          ;\r
+       m_Body                  =rev.m_Body                     ;\r
+       m_CommitHash    =rev.m_CommitHash       ;\r
+       m_ParentHash    =rev.m_ParentHash       ;\r
+       m_Files                 =rev.m_Files                    ;       \r
+       m_Action                =rev.m_Action           ;\r
+       m_Mark                  =rev.m_Mark;\r
+       return 0;\r
+}\r
 int GitRev::ParserFromLog(CString &log)\r
 {\r
        int pos=0;\r
@@ -27,7 +60,7 @@ int GitRev::ParserFromLog(CString &log)
        CString key;\r
        CString text;\r
        CString filelist;\r
-       TCHAR mode;\r
+       TCHAR mode=0;\r
        CTGitPath  path;\r
        this->m_Files.Clear();\r
     m_Action=0;\r
@@ -41,6 +74,9 @@ int GitRev::ParserFromLog(CString &log)
                        mode = one[2];\r
                        switch(mode)\r
                        {\r
+                       case LOG_REV_ITEM_BEGIN:\r
+                               this->Clear();\r
+\r
                        case LOG_REV_AUTHOR_NAME:\r
                                this->m_AuthorName = text;\r
                                break;\r
@@ -66,10 +102,21 @@ int GitRev::ParserFromLog(CString &log)
                                this->m_Body = text +_T("\n");\r
                                break;\r
                        case LOG_REV_COMMIT_HASH:\r
-                               this->m_CommitHash = text;\r
+                               this->m_CommitHash = text.Right(40);\r
+                               if(text.GetLength()>40)\r
+                               {\r
+                                       this->m_Mark=text[0];\r
+                               }\r
                                break;\r
                        case LOG_REV_COMMIT_PARENT:\r
-                               this->m_ParentHash.insert(this->m_ParentHash.end(),text);\r
+                               while(text.GetLength()>0)\r
+                               {\r
+                                       this->m_ParentHash.insert(this->m_ParentHash.end(),text.Left(40));\r
+                                       if(text.GetLength()>40)\r
+                                               text=text.Right(text.GetLength()-41);\r
+                                       else\r
+                                               break;\r
+                               }\r
                                break;\r
                        case LOG_REV_COMMIT_FILE:\r
                                break;\r
@@ -104,3 +151,27 @@ CTime GitRev::ConverFromString(CString input)
                         _wtoi(input.Mid(20,4)));\r
        return tm;\r
 }\r
+\r
+int GitRev::SafeFetchFullInfo(CGit *git)\r
+{\r
+       if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)\r
+       {\r
+               //GitRev rev;\r
+               CString onelog;\r
+               TCHAR oldmark=this->m_Mark;\r
+       \r
+               git->GetLog(onelog,m_CommitHash,NULL,1);\r
+               CString oldhash=m_CommitHash;\r
+               ParserFromLog(onelog);\r
+               \r
+               //ASSERT(oldhash==m_CommitHash);\r
+               if(oldmark!=0)\r
+                       this->m_Mark=oldmark;  //parser full log will cause old mark overwrited. \r
+                                                              //So we need keep old bound mark.\r
+\r
+               InterlockedExchange(&m_IsUpdateing,FALSE);\r
+               InterlockedExchange(&m_IsFull,TRUE);\r
+               return 0;\r
+       }\r
+       return -1;\r
+}
\ No newline at end of file