Replace var++ by ++var and use size_t where necessary
[TortoiseGit.git] / src / TortoiseProc / Commands / UnIgnoreCommand.cpp
blobc66a6ac114cee7ca4ee354fe2699d598b0b1a937
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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.
19 #include "stdafx.h"
20 #include "UnIgnoreCommand.h"
22 #include "MessageBox.h"
23 #include "PathUtils.h"
24 #include "SVNProperties.h"
26 bool UnIgnoreCommand::Execute()
28 CString filelist;
29 BOOL err = FALSE;
30 for (int nPath = 0; nPath < pathList.GetCount(); ++nPath)
32 CString name = CPathUtils::PathPatternEscape(pathList[nPath].GetFileOrDirectoryName());
33 if (parser.HasKey(_T("onlymask")))
35 name = _T("*")+pathList[nPath].GetFileExtension();
37 filelist += name + _T("\n");
38 CTSVNPath parentfolder = pathList[nPath].GetContainingDirectory();
39 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
40 CStringA value;
41 for (int i = 0; i < props.GetCount(); ++i)
43 CString propname(props.GetItemName(i).c_str());
44 if (propname.CompareNoCase(_T("svn:ignore"))==0)
46 //treat values as normal text even if they're not
47 value = (char *)props.GetItemValue(i).c_str();
48 break;
51 value = value.Trim("\n\r");
52 value += "\n";
53 value.Remove('\r');
54 value.Replace("\n\n", "\n");
56 // Delete all occurrences of 'name'
57 // "\n" is temporarily prepended to make the algorithm easier
58 value = "\n" + value;
59 value.Replace("\n" + CUnicodeUtils::GetUTF8(name) + "\n", "\n");
60 value = value.Mid(1);
62 CStringA sTrimmedvalue = value;
63 sTrimmedvalue.Trim();
64 if (sTrimmedvalue.IsEmpty())
66 if (!props.Remove(_T("svn:ignore")))
68 CString temp;
69 temp.Format(IDS_ERR_FAILEDUNIGNOREPROPERTY, (LPCTSTR)name);
70 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_ICONERROR);
71 err = TRUE;
72 break;
75 else
77 if (!props.Add(_T("svn:ignore"), (LPCSTR)value))
79 CString temp;
80 temp.Format(IDS_ERR_FAILEDUNIGNOREPROPERTY, (LPCTSTR)name);
81 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_ICONERROR);
82 err = TRUE;
83 break;
87 if (err == FALSE)
89 CString temp;
90 temp.Format(IDS_PROC_UNIGNORESUCCESS, (LPCTSTR)filelist);
91 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_ICONINFORMATION);
92 return true;
94 return false;