From b94a7149c3bc784d7d7e45d45ba6b9932f363431 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Mon, 11 Nov 2013 23:36:44 +0100 Subject: [PATCH] Preserve empty lines in commit message CString.Tokenize skips empty tokens. Regression of 5076b9aca9b0324ecc2901068c3572d0a0157b3e. Signed-off-by: Sven Strickroth --- src/TortoiseProc/AppUtils.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 2c7149a01..309ca361d 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -2180,15 +2180,23 @@ int CAppUtils::SaveCommitUnicodeFile(CString &filename, CString &message) CFile file(filename,CFile::modeReadWrite|CFile::modeCreate ); int cp = CUnicodeUtils::GetCPCode(g_Git.GetConfigValue(_T("i18n.commitencoding"))); - bool stripComments = (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE) == TRUE); + bool stripComments = (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE) == FALSE); message.TrimRight(L" \r\n"); + int len = message.GetLength(); int start = 0; - while (start >= 0) + while (start >= 0 && start < len) { - CString line = message.Tokenize(L"\n", start); - if (stripComments && (line.GetLength() > 1 && line.GetAt(0) == '#') || start < 0) + int oldStart = start; + start = message.Find(L"\n", oldStart); + CString line = message.Mid(oldStart); + if (start != -1) + { + line = line.Left(start - oldStart); + ++start; // move forward so we don't find the same char again + } + if (stripComments && (line.GetLength() >= 1 && line.GetAt(0) == '#') || (start < 0 && line.IsEmpty())) continue; line.TrimRight(L" \r"); CStringA lineA = CUnicodeUtils::GetMulti(line, cp) + L"\n"; -- 2.11.4.GIT