1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2006-2008 - TortoiseSVN
\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
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
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
21 #include "registry.h"
\r
22 #include "TSVNPath.h"
\r
26 * \ingroup TortoiseProc
\r
27 * enumeration of all client hook types
\r
29 typedef enum hooktype
\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
52 bool operator < (const hookkey& hk) const
\r
54 if (htype == hk.htype)
\r
55 return (path < hk.path);
\r
57 return htype < hk.htype;
\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
66 typedef struct hookcmd
\r
68 CString commandline;
\r
73 typedef std::map<hookkey, hookcmd>::iterator hookiterator;
\r
76 * \ingroup TortoiseProc
\r
77 * Singleton class which deals with the client hook scripts.
\r
79 class CHooks : public std::map<hookkey, hookcmd>
\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
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
99 /// Saves the hook script information to the registry.
\r
102 * Removes the hook script identified by \c key. To make the change persistent
\r
105 bool Remove(hookkey key);
\r
107 * Adds a new hook script. To make the change persistent, call Save().
\r
109 void Add(hooktype ht, const CTSVNPath& Path, LPCTSTR szCmd,
\r
110 bool bWait, bool bShow);
\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
118 * Executes the Start-Update-Hook that first matches one of the paths in
\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
128 bool StartUpdate(const CTSVNPathList& pathList, DWORD& exitcode,
\r
131 * Executes the Pre-Update-Hook that first matches one of the paths in
\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
146 bool PreUpdate(const CTSVNPathList& pathList, svn_depth_t depth,
\r
147 SVNRev rev, DWORD& exitcode, CString& error);
\r
149 * Executes the Post-Update-Hook that first matches one of the paths in
\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
164 bool PostUpdate(const CTSVNPathList& pathList, svn_depth_t depth,
\r
165 SVNRev rev, DWORD& exitcode, CString& error);
\r
168 * Executes the Start-Commit-Hook that first matches one of the paths in
\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
182 bool StartCommit(const CTSVNPathList& pathList, CString& message,
\r
183 DWORD& exitcode, CString& error);
\r
185 * Executes the Pre-Commit-Hook that first matches one of the paths in
\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
200 bool PreCommit(const CTSVNPathList& pathList, svn_depth_t depth,
\r
201 const CString& message, DWORD& exitcode,
\r
204 * Executes the Post-Commit-Hook that first matches one of the paths in
\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
220 bool PostCommit(const CTSVNPathList& pathList, svn_depth_t depth,
\r
221 SVNRev rev, const CString& message,
\r
222 DWORD& exitcode, CString& error);
\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
233 DWORD RunScript(CString cmd, LPCTSTR currentDir, CString& error, bool bWait, bool bShow);
\r
235 * Find the hook script information for the hook type \c t which matches a
\r
236 * path in \c pathList.
\r
238 hookiterator FindItem(hooktype t, const CTSVNPathList& pathList);
\r
239 static CHooks * m_pInstance;
\r