Fixed issue #3307: Abort Merge on a single file always results in a parameter error...
[TortoiseGit.git] / src / TortoiseProc / SerialPatch.cpp
blob863c68509af95702a58258f8bc39cde39e3ec897
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "SerialPatch.h"
22 #include "Git.h"
24 CSerialPatch::CSerialPatch()
28 CSerialPatch::~CSerialPatch()
31 int CSerialPatch::Parse(const CString& pathfile, bool parseBody)
33 m_PathFile = pathfile;
35 CFile PatchFile;
37 if (!PatchFile.Open(m_PathFile, CFile::modeRead))
38 return -1;
40 PatchFile.Read(CStrBufA(m_Body, (UINT)PatchFile.GetLength()), (UINT)PatchFile.GetLength());
41 PatchFile.Close();
43 try
45 int start = 0;
46 CStringA one;
47 one = m_Body.Tokenize("\n", start);
49 if (start == -1)
50 return -1;
51 one = m_Body.Tokenize("\n", start);
52 if (one.GetLength()>6)
53 CGit::StringAppend(&m_Author, (BYTE*)(LPCSTR)one + 6, CP_UTF8, one.GetLength() - 6);
54 m_Author.TrimRight(L'\r');
56 if (start == -1)
57 return -1;
58 one = m_Body.Tokenize("\n", start);
59 if (one.GetLength()>6)
60 CGit::StringAppend(&m_Date, (BYTE*)(LPCSTR)one + 6, CP_UTF8, one.GetLength() - 6);
61 m_Date.TrimRight(L'\r');
63 if (start == -1)
64 return -1;
65 one = m_Body.Tokenize("\n", start);
66 if (one.GetLength()>9)
68 CGit::StringAppend(&m_Subject, (BYTE*)(LPCSTR)one + 9, CP_UTF8, one.GetLength() - 9);
69 while (m_Body.GetLength() > start && m_Body.GetAt(start) == L' ')
71 one = m_Body.Tokenize("\n", start);
72 CGit::StringAppend(&m_Subject, (BYTE*)(LPCSTR)one, CP_UTF8, one.GetLength());
74 m_Subject.TrimRight(L'\r');
77 if (!parseBody)
78 return 0;
80 while (start > 0)
82 if (m_Body.Mid(start - 1, 2) == L"\n\n")
83 break;
84 if (m_Body.Mid(start - 4, 4) == L"\r\n\r\n")
86 --start;
87 break;
89 m_Body.Tokenize("\n", start);
92 if (start == -1)
93 return -1;
95 if (start + 1 < m_Body.GetLength())
96 CGit::StringAppend(&m_strBody, (BYTE*)(LPCSTR)m_Body + start + 1, CP_UTF8, m_Body.GetLength() - start - 1);
98 catch (CException *)
100 return -1;
103 return 0;