1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2006-2008 - TortoiseGit
\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 "TGitPath.h"
\r
24 #include "GitStatus.h"
\r
27 * \ingroup TortoiseProc
\r
28 * enumeration of all client hook types
\r
30 typedef enum hooktype
\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
53 bool operator < (const hookkey& hk) const
\r
55 if (htype == hk.htype)
\r
56 return (path < hk.path);
\r
58 return htype < hk.htype;
\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
67 typedef struct hookcmd
\r
69 CString commandline;
\r
74 typedef std::map<hookkey, hookcmd>::iterator hookiterator;
\r
77 * \ingroup TortoiseProc
\r
78 * Singleton class which deals with the client hook scripts.
\r
80 class CHooks : public std::map<hookkey, hookcmd>
\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
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
100 /// Saves the hook script information to the registry.
\r
103 * Removes the hook script identified by \c key. To make the change persistent
\r
106 bool Remove(hookkey key);
\r
108 * Adds a new hook script. To make the change persistent, call Save().
\r
110 void Add(hooktype ht, const CTGitPath& Path, LPCTSTR szCmd,
\r
111 bool bWait, bool bShow);
\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
119 * Executes the Start-Update-Hook that first matches one of the paths in
\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
129 bool StartUpdate(const CTGitPathList& pathList, DWORD& exitcode,
\r
132 * Executes the Pre-Update-Hook that first matches one of the paths in
\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
147 bool PreUpdate(const CTGitPathList& pathList, git_depth_t depth,
\r
148 GitRev rev, DWORD& exitcode, CString& error);
\r
150 * Executes the Post-Update-Hook that first matches one of the paths in
\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
165 bool PostUpdate(const CTGitPathList& pathList, git_depth_t depth,
\r
166 GitRev rev, DWORD& exitcode, CString& error);
\r
169 * Executes the Start-Commit-Hook that first matches one of the paths in
\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
183 bool StartCommit(const CTGitPathList& pathList, CString& message,
\r
184 DWORD& exitcode, CString& error);
\r
186 * Executes the Pre-Commit-Hook that first matches one of the paths in
\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
201 bool PreCommit(const CTGitPathList& pathList, git_depth_t depth,
\r
202 const CString& message, DWORD& exitcode,
\r
205 * Executes the Post-Commit-Hook that first matches one of the paths in
\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
221 bool PostCommit(const CTGitPathList& pathList, git_depth_t depth,
\r
222 GitRev rev, const CString& message,
\r
223 DWORD& exitcode, CString& error);
\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
234 DWORD RunScript(CString cmd, LPCTSTR currentDir, CString& error, bool bWait, bool bShow);
\r
236 * Find the hook script information for the hook type \c t which matches a
\r
237 * path in \c pathList.
\r
239 hookiterator FindItem(hooktype t, const CTGitPathList& pathList);
\r
240 static CHooks * m_pInstance;
\r