OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / RevisionGraph / RemovePathsBySubString.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "RemovePathsBySubString.h"\r
21 #include "FullGraphNode.h"\r
22 \r
23 // construction\r
24 \r
25 CRemovePathsBySubString::CRemovePathsBySubString (CRevisionGraphOptionList& list)\r
26     : inherited (list)\r
27 {\r
28 }\r
29 \r
30 // get / set limits\r
31 \r
32 /// access to the sub-string container\r
33 \r
34 const std::set<std::string>& CRemovePathsBySubString::GetFilterPaths() const\r
35 {\r
36     return filterPaths;\r
37 }\r
38 \r
39 std::set<std::string>& CRemovePathsBySubString::GetFilterPaths()\r
40 {\r
41     return filterPaths;\r
42 }\r
43 \r
44 // implement ICopyFilterOption\r
45 \r
46 ICopyFilterOption::EResult \r
47 CRemovePathsBySubString::ShallRemove (const CFullGraphNode* node) const\r
48 {\r
49     // short-cut\r
50 \r
51     if (filterPaths.empty())\r
52         return ICopyFilterOption::KEEP_NODE;\r
53 \r
54     // node to classify\r
55 \r
56     const CDictionaryBasedPath& path = node->GetRealPath();\r
57 \r
58     // ensure the index is valid within classification cache \r
59 \r
60     if (pathClassification.size() <= path.GetIndex())\r
61     {\r
62         size_t newSize = max (8, pathClassification.size()) * 2;\r
63         while (newSize <= path.GetIndex())\r
64             newSize *= 2;\r
65 \r
66         pathClassification.resize (newSize, UNKNOWN);\r
67     }\r
68 \r
69     // auto-calculate the entry\r
70 \r
71     PathClassification& classification = pathClassification[path.GetIndex()];\r
72     if (classification == UNKNOWN)\r
73     {\r
74         std::string fullPath = path.GetPath();\r
75 \r
76         classification = KEEP;\r
77         for ( std::set<std::string>::const_iterator iter = filterPaths.begin()\r
78             , end = filterPaths.end()\r
79             ; iter != end\r
80             ; ++iter)\r
81         {\r
82             if (fullPath.find (*iter) != std::string::npos)\r
83             {\r
84                 classification = REMOVE;\r
85                 break;\r
86             }\r
87         }\r
88     }\r
89 \r
90     // return the result\r
91 \r
92     return classification == REMOVE\r
93         ? ICopyFilterOption::REMOVE_NODE\r
94         : ICopyFilterOption::KEEP_NODE;\r
95 }\r
96 \r
97 void CRemovePathsBySubString::Prepare()\r
98 {\r
99     pathClassification.clear();\r
100 }\r