4 //# include "SVNPrompt.h"
8 #pragma warning (push,1)
9 typedef std::basic_string
<wchar_t> wide_string
;
11 # define stdstring wide_string
13 # define stdstring std::string
19 typedef enum type_git_wc_status_kind
22 git_wc_status_unversioned
,
23 git_wc_status_ignored
,
25 git_wc_status_external
,
26 git_wc_status_incomplete
,
27 git_wc_status_missing
,
28 git_wc_status_deleted
,
29 git_wc_status_replaced
,
30 git_wc_status_modified
,
33 git_wc_status_conflicted
,
34 git_wc_status_obstructed
,
48 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
49 #define GIT_INVALID_REVNUM _T("")
50 typedef CString git_revnum_t
;
51 typedef int git_error_t
;
53 typedef struct git_wc_entry_t
62 typedef struct git_wc_status2_t
64 /** The status of the entries text. */
65 git_wc_status_kind text_status
;
67 /** The status of the entries properties. */
68 git_wc_status_kind prop_status
;
70 //git_wc_entry_t *entry;
73 #define MAX_STATUS_STRING_LENGTH 256
76 /////////////////////////////////////////////////////////////////////
77 // WINGIT API (replaced by commandline tool, but defs and data types kept so old code still works)
79 // Flags for wgEnumFiles
82 WGEFF_NoRecurse
= (1<<0), // only enumerate files directly in the specified path
83 WGEFF_FullPath
= (1<<1), // enumerated filenames are specified with full path (instead of relative to proj root)
84 WGEFF_DirStatusDelta
= (1<<2), // include directories, in enumeration, that have a recursive status != WGFS_Normal (may have a slightly better performance than WGEFF_DirStatusAll)
85 WGEFF_DirStatusAll
= (1<<3), // include directories, in enumeration, with recursive status
86 WGEFF_EmptyAsNormal
= (1<<4), // report sub-directories, with no versioned files, as WGFS_Normal instead of WGFS_Empty
87 WGEFF_SingleFile
= (1<<5) // indicates that the status of a single file or dir, specified by pszSubPath, is wanted
101 WGFS_Unversioned
= -2,
109 WGFF_Directory
= (1<<0) // enumerated file is a directory
114 LPCTSTR sFileName
; // filename or directory relative to project root (using forward slashes)
115 int nStatus
; // the WGFILESTATUS of the file
116 int nFlags
; // a combination of WGFILEFLAGS
118 const BYTE
* sha1
; // points to the BYTE[20] sha1 (NULL for directories, WGFF_Directory)
121 // Application-defined callback function for wgEnumFiles, returns TRUE to abort enumeration
122 // NOTE: do NOT store the pFile pointer or any pointers in wgFile_s for later use, the data is only valid for a single callback call
123 typedef BOOL (__cdecl WGENUMFILECB
)(const struct wgFile_s
*pFile
, void *pUserData
);
126 /////////////////////////////////////////////////////////////////////
129 // convert wingit.dll status to git_wc_status_kind
130 inline static git_wc_status_kind
GitStatusFromWingit(int nStatus
)
134 case WGFS_Normal
: return git_wc_status_normal
;
135 case WGFS_Modified
: return git_wc_status_modified
;
136 case WGFS_Staged
: return git_wc_status_merged
;
137 case WGFS_Added
: return git_wc_status_added
;
138 case WGFS_Conflicted
: return git_wc_status_conflicted
;
139 case WGFS_Deleted
: return git_wc_status_deleted
;
141 case WGFS_Ignored
: return git_wc_status_ignored
;
142 case WGFS_Unversioned
: return git_wc_status_unversioned
;
143 case WGFS_Empty
: return git_wc_status_unversioned
;
146 return git_wc_status_none
;
149 // convert 20 byte sha1 hash to the git_revnum_t type
150 inline static git_revnum_t
ConvertHashToRevnum(const BYTE
*sha1
)
153 return GIT_INVALID_REVNUM
;
157 for (int i
=0; i
<20; i
++)
159 #pragma warning(push)
160 #pragma warning(disable: 4996)
161 sprintf(p
, "%02x", (UINT
)*sha1
);
170 typedef void (*FIll_STATUS_CALLBACK
)(CString
&path
,git_wc_status_kind status
,void *pdata
);
174 * Handles Subversion status of working copies.
179 static int GetFileStatus(CString
&gitdir
,CString
&path
,git_wc_status_kind
* status
,BOOL IsFull
=false, BOOL IsRecursive
=false,FIll_STATUS_CALLBACK callback
=NULL
,void *pData
=NULL
);
180 static int GetDirStatus(CString
&gitdir
,CString
&path
,git_wc_status_kind
* status
,BOOL IsFull
=false, BOOL IsRecursive
=false,FIll_STATUS_CALLBACK callback
=NULL
,void *pData
=NULL
);
183 GitStatus(bool * pbCanceled
= NULL
);
188 * Reads the Subversion status of the working copy entry. No
189 * recurse is done, even if the entry is a directory.
190 * If the status of the text and property part are different
191 * then the more important status is returned.
193 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
);
196 * Reads the Subversion status of the working copy entry and all its
197 * subitems. The resulting status is determined by using priorities for
198 * each status. The status with the highest priority is then returned.
199 * If the status of the text and property part are different then
200 * the more important status is returned.
202 static git_wc_status_kind
GetAllStatusRecursive(const CTGitPath
& path
);
205 * Returns the status which is more "important" of the two statuses specified.
206 * This is used for the "recursive" status functions on folders - i.e. which status
207 * should be returned for a folder which has several files with different statuses
210 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
213 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
214 * E.g. a "normal" status is not important, but "modified" is.
215 * \param status the status to check
217 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
220 * Reads the Subversion text status of the working copy entry. No
221 * recurse is done, even if the entry is a directory.
222 * The result is stored in the public member variable status.
223 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
225 * \param path the pathname of the entry
226 * \param update true if the status should be updated with the repository. Default is false.
227 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
228 * \remark If the return value is -2 then the status could not be obtained.
230 git_revnum_t
GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
233 * Returns a string representation of a Subversion status.
234 * \param status the status enum
235 * \param string a string representation
237 static void GetStatusString(git_wc_status_kind status
, size_t buflen
, TCHAR
* string
);
238 static void GetStatusString(HINSTANCE hInst
, git_wc_status_kind status
, TCHAR
* string
, int size
, WORD lang
);
241 * Returns the string representation of a depth.
244 static CString
GetDepthString(git_depth_t depth
);
246 static void GetDepthString(HINSTANCE hInst
, git_depth_t depth
, TCHAR
* string
, int size
, WORD lang
);
249 * Returns the status of the first file of the given path. Use GetNextFileStatus() to obtain
250 * the status of the next file in the list.
251 * \param path the path of the folder from where the status list should be obtained
252 * \param retPath the path of the file for which the status was returned
253 * \param update set this to true if you want the status to be updated with the repository (needs network access)
254 * \param recurse true to fetch the status recursively
255 * \param bNoIgnore true to not fetch the ignored files
256 * \param bNoExternals true to not fetch the status of included Git:externals
259 git_wc_status2_t
* GetFirstFileStatus(const CTGitPath
& path
, CTGitPath
& retPath
, bool update
= false, git_depth_t depth
= git_depth_infinity
, bool bNoIgnore
= true, bool bNoExternals
= false);
260 unsigned int GetFileCount() const {return /*apr_hash_count(m_statushash);*/0;}
261 unsigned int GetVersionedCount() const;
263 * Returns the status of the next file in the file list. If no more files are in the list then NULL is returned.
264 * See GetFirstFileStatus() for details.
266 git_wc_status2_t
* GetNextFileStatus(CTGitPath
& retPath
);
268 * Checks if a path is an external folder.
269 * This is necessary since Subversion returns two entries for external folders: one with the status Git_wc_status_external
270 * and one with the 'real' status of that folder. GetFirstFileStatus() and GetNextFileStatus() only return the 'real'
271 * status, so with this method it's possible to check if the status also is Git_wc_status_external.
273 bool IsExternal(const CTGitPath
& path
) const;
275 * Checks if a path is in an external folder.
277 bool IsInExternal(const CTGitPath
& path
) const;
280 * Clears the memory pool.
285 * This member variable hold the status of the last call to GetStatus().
287 git_wc_status2_t
* status
; ///< the status result of GetStatus()
289 git_revnum_t headrev
; ///< the head revision fetched with GetFirstStatus()
293 friend class Git
; // So that Git can get to our m_err
295 * Returns the last error message as a CString object.
297 CString
GetLastErrorMsg() const;
300 * Set a list of paths which will be considered when calling GetFirstFileStatus.
301 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
303 void SetFilter(const CTGitPathList
& fileList
);
308 * Returns the last error message as a CString object.
310 stdstring
GetLastErrorMsg() const;
315 // apr_pool_t * m_pool; ///< the memory pool
317 typedef struct sort_item
324 typedef struct hashbaton_t
327 // apr_hash_t * hash;
328 // apr_hash_t * exthash;
331 // git_client_ctx_t * ctx;
332 git_wc_status_kind m_allstatus
; ///< used by GetAllStatus and GetAllStatusRecursive
333 // git_error_t * m_err; ///< Subversion error baton
336 git_wc_status2_t m_status
; // used for GetStatus
339 // GitPrompt m_prompt;
343 * Returns a numeric value indicating the importance of a status.
344 * A higher number indicates a more important status.
346 static int GetStatusRanking(git_wc_status_kind status
);
349 * Callback function which collects the raw status from a Git_client_status() function call
351 //static git_error_t * getallstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
352 static BOOL
getallstatus(const struct wgFile_s
*pFile
, void *pUserData
);
353 static BOOL
getstatus(const struct wgFile_s
*pFile
, void *pUserData
);
356 * Callback function which stores the raw status from a Git_client_status() function call
359 // static git_error_t * getstatushash (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
362 * helper function to sort a hash to an array
364 // static apr_array_header_t * sort_hash (apr_hash_t *ht, int (*comparison_func) (const sort_item *,
365 // const sort_item *), apr_pool_t *pool);
368 * Callback function used by qsort() which does the comparison of two elements
370 static int __cdecl
sort_compare_items_as_paths (const sort_item
*a
, const sort_item
*b
);
372 //for GetFirstFileStatus and GetNextFileStatus
373 // apr_hash_t * m_statushash;
374 // apr_array_header_t * m_statusarray;
375 unsigned int m_statushashindex
;
376 // apr_hash_t * m_externalhash;
378 #pragma warning(push)
379 #pragma warning(disable: 4200)
380 struct STRINGRESOURCEIMAGE
385 #pragma warning(pop) // C4200
387 static int LoadStringEx(HINSTANCE hInstance
, UINT uID
, LPTSTR lpBuffer
, int nBufferMax
, WORD wLanguage
);
388 static git_error_t
* cancel(void *baton
);
390 // A sorted list of filenames (in Git format, in lowercase)
391 // when this list is set, we only pick-up files during a GetStatus which are found in this list
392 typedef std::vector
<std::string
> StdStrAVector
;
393 StdStrAVector m_filterFileList
;