OSDN Git Service

Update RevisionGraph to 15570
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / FoldTags.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 "FoldTags.h"\r
21 #include "VisibleGraphNode.h"\r
22 \r
23 // that the line from node downward have any visible copy targets?\r
24 \r
25 bool CFoldTags::CopyTargetsVisibile (const CVisibleGraphNode* node) const\r
26 {\r
27     for (; node != NULL; node = node->GetNext())\r
28         if (node->GetFirstCopyTarget() != NULL)\r
29             return true;\r
30 \r
31     return false;\r
32 }\r
33 \r
34 // construction\r
35 \r
36 CFoldTags::CFoldTags (CRevisionGraphOptionList& list)\r
37     : inherited (list)\r
38 {\r
39 }\r
40 \r
41 // implement IModificationOption\r
42 \r
43 void CFoldTags::Apply (CVisibleGraph* graph, CVisibleGraphNode* node)\r
44 {\r
45     // We will not remove tags that get copied to non-tags\r
46     // that have not yet been removed from the graph.\r
47 \r
48     DWORD forbidden = CNodeClassification::COPIES_TO_TRUNK \r
49                     | CNodeClassification::COPIES_TO_BRANCH \r
50                     | CNodeClassification::COPIES_TO_OTHER;\r
51 \r
52     CNodeClassification classification = node->GetClassification();\r
53     bool isTag = classification.Matches (CNodeClassification::IS_TAG, 0);\r
54     bool isFinalTag = classification.Matches (CNodeClassification::IS_TAG, forbidden);\r
55 \r
56     // fold tags at the point of their creation\r
57 \r
58     if (isTag)\r
59     {\r
60         // this is a node on some tag but maybe not the creation point\r
61         // (e.g. if we don't want to fold a tag and that tag gets\r
62         // modified in several revisions)\r
63 \r
64         if (   (node->GetCopySource() != NULL)\r
65             || (   (node->GetPrevious() != NULL)\r
66                 && classification.Is (CNodeClassification::IS_RENAMED)))\r
67         {\r
68             // this is the point where the tag got created / renamed\r
69             // (CopyTargetsVisibile can be expensive -> don't do it\r
70             // in the first "if" condition 4 lines above)\r
71 \r
72             if (isFinalTag || !CopyTargetsVisibile (node))\r
73             {\r
74                 // it does not copy to branch etc.\r
75                 // (if it copies to a tag, that one will be folded first\r
76                 // and we will fold this one only in the next iteration)\r
77 \r
78                 node->FoldTag (graph);\r
79             }\r
80         }\r
81     }\r
82 }\r