OSDN Git Service

TortoiseMerge Basic Support Git patch created by format patch
authorFrank Li <lznuaa@gmail.com>
Mon, 6 Apr 2009 03:16:25 +0000 (11:16 +0800)
committerFrank Li <lznuaa@gmail.com>
Mon, 6 Apr 2009 03:16:25 +0000 (11:16 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseMerge/Patch.cpp
src/TortoiseMerge/Patch.h

index 79ea336..c13c515 100644 (file)
@@ -34,6 +34,7 @@ static char THIS_FILE[] = __FILE__;
 CPatch::CPatch(void)\r
 {\r
        m_nStrip = 0;\r
+       m_IsGitPatch = false;\r
 }\r
 \r
 CPatch::~CPatch(void)\r
@@ -76,10 +77,20 @@ BOOL CPatch::OpenUnifiedDiffFile(const CString& filename)
        //now we got all the lines of the patch file\r
        //in our array - parsing can start...\r
 \r
+       for(nIndex=0;PatchLines.GetCount();nIndex++)\r
+       {\r
+               sLine = PatchLines.GetAt(nIndex);\r
+               if(sLine.Left(10).Compare(_T("diff --git")) == 0)\r
+               {\r
+                       this->m_IsGitPatch=true;\r
+                       break;\r
+               }\r
+       }\r
+\r
        //first, skip possible garbage at the beginning\r
        //garbage is finished when a line starts with "Index: "\r
        //and the next line consists of only "=" characters\r
-       for (; nIndex<PatchLines.GetCount(); nIndex++)\r
+       for (nIndex=0; nIndex<PatchLines.GetCount(); nIndex++)\r
        {\r
                sLine = PatchLines.GetAt(nIndex);\r
                if (sLine.Left(4).Compare(_T("--- "))==0)\r
@@ -87,6 +98,10 @@ BOOL CPatch::OpenUnifiedDiffFile(const CString& filename)
                if ((nIndex+1)<PatchLines.GetCount())\r
                {\r
                        sLine = PatchLines.GetAt(nIndex+1);\r
+\r
+                       if(sLine.IsEmpty()&&m_IsGitPatch)\r
+                               continue;\r
+\r
                        sLine.Replace(_T("="), _T(""));\r
                        if (sLine.IsEmpty())\r
                                break;\r
@@ -114,7 +129,7 @@ BOOL CPatch::OpenUnifiedDiffFile(const CString& filename)
                        ending = EOL_AUTOLINE;\r
                if (state == 0)\r
                {\r
-                       if ((sLine.Left(4).Compare(_T("--- "))==0)&&(sLine.Find('\t') >= 0))\r
+                       if ((sLine.Left(4).Compare(_T("--- "))==0)&&((sLine.Find('\t') >= 0)||this->m_IsGitPatch))\r
                        {\r
                                state = 2;\r
                                if (chunks)\r
@@ -124,10 +139,19 @@ BOOL CPatch::OpenUnifiedDiffFile(const CString& filename)
                                        m_arFileDiffs.Add(chunks);\r
                                }\r
                                chunks = new Chunks();\r
+                               \r
                                int nTab = sLine.Find('\t');\r
+\r
+                               int filestart = 4;\r
+                               if(m_IsGitPatch)\r
+                               {\r
+                                       nTab=sLine.GetLength();\r
+                                       filestart = 6;\r
+                               }\r
+\r
                                if (nTab >= 0)\r
                                {\r
-                                       chunks->sFilePath = sLine.Mid(4, nTab-4).Trim();\r
+                                       chunks->sFilePath = sLine.Mid(filestart, nTab-filestart).Trim();\r
                                }\r
                        }\r
                }\r
index 72d3340..1c01452 100644 (file)
@@ -95,4 +95,5 @@ protected:
         * stripped by 4 prefixes is interpreted as "dir/file.txt"\r
         */\r
        int                                                     m_nStrip;\r
+       bool                                            m_IsGitPatch;\r
 };\r