OSDN Git Service

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