OSDN Git Service

Add TortoiseProc
[tortoisegit/TortoiseGitJp.git] / Utils / Hooks.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2006-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 #pragma once\r
20 #include <map>\r
21 #include "registry.h"\r
22 #include "TSVNPath.h"\r
23 #include "SVNRev.h"\r
24 \r
25 /**\r
26  * \ingroup TortoiseProc\r
27  * enumeration of all client hook types\r
28  */\r
29 typedef enum hooktype\r
30 {\r
31         unknown_hook,\r
32         start_commit_hook,\r
33         pre_commit_hook,\r
34         post_commit_hook,\r
35         start_update_hook,\r
36         pre_update_hook,\r
37         post_update_hook,\r
38         issue_tracker_hook\r
39 } hooktype;\r
40 \r
41 /**\r
42  * \ingroup TortoiseProc\r
43  * helper class, used as the key to the std::map we store\r
44  * the data for the client hook scripts in.\r
45  */\r
46 class hookkey\r
47 {\r
48 public:\r
49         hooktype                htype;\r
50         CTSVNPath               path;\r
51 \r
52         bool operator < (const hookkey& hk) const \r
53         {\r
54                 if (htype == hk.htype) \r
55                         return (path < hk.path); \r
56                 else \r
57                         return htype < hk.htype;\r
58         }\r
59 };\r
60 \r
61 /**\r
62  * \ingroup TortoiseProc\r
63  * helper struct, used as the value to the std::map we\r
64  * store the data for the client hook scripts in.\r
65  */\r
66 typedef struct hookcmd\r
67 {\r
68         CString                 commandline;\r
69         bool                    bWait;\r
70         bool                    bShow;\r
71 } hookcmd;\r
72 \r
73 typedef std::map<hookkey, hookcmd>::iterator hookiterator;\r
74 \r
75 /**\r
76  * \ingroup TortoiseProc\r
77  * Singleton class which deals with the client hook scripts.\r
78  */\r
79 class CHooks : public std::map<hookkey, hookcmd>\r
80 {\r
81 private:\r
82         CHooks();\r
83         ~CHooks();\r
84         void AddPathParam(CString& sCmd, const CTSVNPathList& pathList);\r
85         void AddDepthParam(CString& sCmd, svn_depth_t depth);\r
86         void AddCWDParam(CString& sCmd, const CTSVNPathList& pathList);\r
87         void AddErrorParam(CString& sCmd, const CString& error);\r
88         void AddParam(CString& sCmd, const CString& param);\r
89         CTSVNPath AddMessageFileParam(CString& sCmd, const CString& message);\r
90 public:\r
91         /// Create the singleton. Call this at the start of the program.\r
92         static bool                     Create();\r
93         /// Returns the singleton instance\r
94         static CHooks&          Instance();\r
95         /// Destroys the singleton object. Call this at the end of the program.\r
96         static void                     Destroy();\r
97 \r
98 public:\r
99         /// Saves the hook script information to the registry.\r
100         bool                            Save();\r
101         /**\r
102          * Removes the hook script identified by \c key. To make the change persistent\r
103          * call Save().\r
104          */\r
105         bool                            Remove(hookkey key);\r
106         /**\r
107          * Adds a new hook script. To make the change persistent, call Save().\r
108          */\r
109         void                            Add(hooktype ht, const CTSVNPath& Path, LPCTSTR szCmd, \r
110                                                         bool bWait, bool bShow);\r
111 \r
112         /// returns the string representation of the hook type.\r
113         static CString          GetHookTypeString(hooktype t);\r
114         /// returns the hooktype from a string representation of the same.\r
115         static hooktype         GetHookType(const CString& s);\r
116 \r
117         /**\r
118          * Executes the Start-Update-Hook that first matches one of the paths in\r
119          * \c pathList.\r
120          * \param pathList a list of paths to look for the hook scripts\r
121          * \param exitcode on return, contains the exit code of the hook script\r
122          * \param error the data the hook script outputs to stderr\r
123          * \remark the string "%PATHS% in the command line of the hook script is \r
124          * replaced with the path to a temporary file which contains a list of files\r
125          * in \c pathList, separated by newlines. The hook script can parse this\r
126          * file to get all the paths the update is about to be done on.\r
127          */\r
128         bool                            StartUpdate(const CTSVNPathList& pathList, DWORD& exitcode, \r
129                                                                         CString& error);\r
130         /**\r
131          * Executes the Pre-Update-Hook that first matches one of the paths in\r
132          * \c pathList.\r
133          * \param pathList a list of paths to look for the hook scripts\r
134          * \param depth the depth of the commit\r
135          * \param rev the revision the update is done to\r
136          * \param exitcode on return, contains the exit code of the hook script\r
137          * \param error the data the hook script outputs to stderr\r
138          * \remark the string "%PATHS% in the command line of the hook script is \r
139          * replaced with the path to a temporary file which contains a list of files\r
140          * in \c pathList, separated by newlines. The hook script can parse this\r
141          * file to get all the paths the update is about to be done on.\r
142          * The string "%RECURSIVE%" is replaced with either "recursive" or "nonrecursive" according\r
143          * to the \c bRecursive parameter. And the string "%REVISION%" is replaced with\r
144          * the string representation of \c rev.\r
145          */\r
146         bool                            PreUpdate(const CTSVNPathList& pathList, svn_depth_t depth, \r
147                                                                         SVNRev rev, DWORD& exitcode, CString& error);\r
148         /**\r
149          * Executes the Post-Update-Hook that first matches one of the paths in\r
150          * \c pathList.\r
151          * \param pathList a list of paths to look for the hook scripts\r
152          * \param depth the depth of the commit\r
153          * \param rev the revision the update was done to\r
154          * \param exitcode on return, contains the exit code of the hook script\r
155          * \param error the data the hook script outputs to stderr\r
156          * \remark the string "%PATHS% in the command line of the hook script is \r
157          * replaced with the path to a temporary file which contains a list of files\r
158          * in \c pathList, separated by newlines. The hook script can parse this\r
159          * file to get all the paths the update is about to be done on.\r
160          * The string "%RECURSIVE%" is replaced with either "recursive" or "nonrecursive" according\r
161          * to the \c bRecursive parameter. And the string "%REVISION%" is replaced with\r
162          * the string representation of \c rev.\r
163          */\r
164         bool                            PostUpdate(const CTSVNPathList& pathList, svn_depth_t depth, \r
165                                                                         SVNRev rev, DWORD& exitcode, CString& error);\r
166 \r
167         /**\r
168          * Executes the Start-Commit-Hook that first matches one of the paths in\r
169          * \c pathList.\r
170          * \param pathList a list of paths to look for the hook scripts\r
171          * \param message a commit message\r
172          * \param exitcode on return, contains the exit code of the hook script\r
173          * \param error the data the hook script outputs to stderr\r
174          * \remark the string "%PATHS% in the command line of the hook script is \r
175          * replaced with the path to a temporary file which contains a list of files\r
176          * in \c pathList, separated by newlines. The hook script can parse this\r
177          * file to get all the paths the commit is about to be done on.\r
178          * The string %MESSAGEFILE% is replaced with path to temporary file containing\r
179          * \c message. If the script finishes successfully, contents of this file\r
180          * is read back into \c message parameter.\r
181          */\r
182         bool                            StartCommit(const CTSVNPathList& pathList, CString& message,\r
183                                                                         DWORD& exitcode, CString& error);\r
184         /**\r
185          * Executes the Pre-Commit-Hook that first matches one of the paths in\r
186          * \c pathList.\r
187          * \param pathList a list of paths to look for the hook scripts\r
188          * \param depth the depth of the commit\r
189          * \param message the commit message\r
190          * \param exitcode on return, contains the exit code of the hook script\r
191          * \param error the data the hook script outputs to stderr\r
192          * \remark the string "%PATHS% in the command line of the hook script is \r
193          * replaced with the path to a temporary file which contains a list of files\r
194          * in \c pathList, separated by newlines. The hook script can parse this\r
195          * file to get all the paths the update is about to be done on.\r
196          * The string "%DEPTH%" is replaced with the numerical value (string) of the\r
197          * svn_depth_t parameter. See the Subversion source documentation about the\r
198          * values.\r
199          */\r
200         bool                            PreCommit(const CTSVNPathList& pathList, svn_depth_t depth, \r
201                                                                         const CString& message, DWORD& exitcode, \r
202                                                                         CString& error);\r
203         /**\r
204          * Executes the Post-Commit-Hook that first matches one of the paths in\r
205          * \c pathList.\r
206          * \param pathList a list of paths to look for the hook scripts\r
207          * \param depth the depth of the commit\r
208          * \param message the commit message\r
209          * \param rev the revision the commit was done to\r
210          * \param exitcode on return, contains the exit code of the hook script\r
211          * \param error the data the hook script outputs to stderr\r
212          * \remark the string "%PATHS% in the command line of the hook script is \r
213          * replaced with the path to a temporary file which contains a list of files\r
214          * in \c pathList, separated by newlines. The hook script can parse this\r
215          * file to get all the paths the commit is about to be done on.\r
216          * The string "%DEPTH%" is replaced with the numerical value (string) of the\r
217          * svn_depth_t parameter. See the Subversion source documentation about the\r
218          * values.\r
219          */\r
220         bool                            PostCommit(const CTSVNPathList& pathList, svn_depth_t depth, \r
221                                                                         SVNRev rev, const CString& message, \r
222                                                                         DWORD& exitcode, CString& error);\r
223 \r
224 private:\r
225         /**\r
226          * Starts a new process, specified in \c cmd.\r
227          * \param error the data the process writes to stderr\r
228          * \param bWait if true, then this method waits until the created process has finished. If false, then the return\r
229          * value will always be 0 and \c error will be an empty string.\r
230          * \param bShow set to true if the process should be started visible.\r
231          * \return the exit code of the process if \c bWait is true, zero otherwise.\r
232          */\r
233         DWORD                           RunScript(CString cmd, LPCTSTR currentDir, CString& error, bool bWait, bool bShow);\r
234         /**\r
235          * Find the hook script information for the hook type \c t which matches a\r
236          * path in \c pathList.\r
237          */\r
238         hookiterator            FindItem(hooktype t, const CTSVNPathList& pathList);\r
239         static CHooks *         m_pInstance;\r
240 };\r