1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-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 "resource.h"
\r
22 #include "..\TortoiseShell\resource.h"
\r
23 //#include "git_config.h"
\r
24 #include "GitStatus.h"
\r
25 #include "UnicodeUtils.h"
\r
26 //#include "GitGlobal.h"
\r
27 //#include "GitHelpers.h"
\r
30 //# include "MessageBox.h"
\r
31 //# include "registry.h"
\r
32 //# include "TGitPath.h"
\r
33 //# include "PathUtils.h"
\r
37 GitStatus::GitStatus(bool * pbCanceled)
\r
41 m_pool = git_pool_create (NULL);
\r
43 git_error_clear(git_client_create_context(&ctx, m_pool));
\r
47 ctx->cancel_func = cancel;
\r
48 ctx->cancel_baton = pbCanceled;
\r
52 git_error_clear(git_config_ensure(NULL, m_pool));
\r
54 // set up authentication
\r
55 m_prompt.Init(m_pool, ctx);
\r
57 // set up the configuration
\r
58 m_err = git_config_get_config (&(ctx->config), g_pConfigDir, m_pool);
\r
62 ::MessageBox(NULL, this->GetLastErrorMsg(), _T("TortoiseGit"), MB_ICONERROR);
\r
63 git_error_clear(m_err);
\r
64 git_pool_destroy (m_pool); // free the allocated memory
\r
68 // set up the Git_SSH param
\r
69 CString tgit_ssh = CRegString(_T("Software\\TortoiseGit\\SSH"));
\r
70 if (tgit_ssh.IsEmpty())
\r
71 tgit_ssh = CPathUtils::GetAppDirectory() + _T("TortoisePlink.exe");
\r
72 tgit_ssh.Replace('\\', '/');
\r
73 if (!tgit_ssh.IsEmpty())
\r
75 git_config_t * cfg = (git_config_t *)apr_hash_get ((apr_hash_t *)ctx->config, Git_CONFIG_CATEGORY_CONFIG,
\r
76 APR_HASH_KEY_STRING);
\r
77 git_config_set(cfg, Git_CONFIG_SECTION_TUNNELS, "ssh", CUnicodeUtils::GetUTF8(tgit_ssh));
\r
80 git_error_clear(git_config_ensure(NULL, m_pool));
\r
82 // set up the configuration
\r
83 m_err = git_config_get_config (&(ctx->config), g_pConfigDir, m_pool);
\r
89 GitStatus::~GitStatus(void)
\r
92 git_error_clear(m_err);
\r
93 git_pool_destroy (m_pool); // free the allocated memory
\r
97 void GitStatus::ClearPool()
\r
100 git_pool_clear(m_pool);
\r
105 CString GitStatus::GetLastErrorMsg() const
\r
107 // return Git::GetErrorString(m_err);
\r
108 return CString("");
\r
111 stdstring GitStatus::GetLastErrorMsg() const
\r
120 git_error_t * ErrPtr = m_err;
\r
121 if (ErrPtr->message)
\r
123 msg = CUnicodeUtils::StdGetUnicode(ErrPtr->message);
\r
127 /* Is this a Subversion-specific error code? */
\r
128 if ((ErrPtr->apr_err > APR_OS_START_USEERR)
\r
129 && (ErrPtr->apr_err <= APR_OS_START_CANONERR))
\r
130 msg = CUnicodeUtils::StdGetUnicode(git_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)));
\r
131 /* Otherwise, this must be an APR error code. */
\r
134 git_error_t *temp_err = NULL;
\r
135 const char * err_string = NULL;
\r
136 temp_err = git_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)-1), ErrPtr->pool);
\r
139 git_error_clear (temp_err);
\r
140 msg = _T("Can't recode error string from APR");
\r
144 msg = CUnicodeUtils::StdGetUnicode(err_string);
\r
150 while (ErrPtr->child)
\r
152 ErrPtr = ErrPtr->child;
\r
154 if (ErrPtr->message)
\r
156 msg += CUnicodeUtils::StdGetUnicode(ErrPtr->message);
\r
160 /* Is this a Subversion-specific error code? */
\r
161 if ((ErrPtr->apr_err > APR_OS_START_USEERR)
\r
162 && (ErrPtr->apr_err <= APR_OS_START_CANONERR))
\r
163 msg += CUnicodeUtils::StdGetUnicode(git_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)));
\r
164 /* Otherwise, this must be an APR error code. */
\r
167 git_error_t *temp_err = NULL;
\r
168 const char * err_string = NULL;
\r
169 temp_err = git_utf_cstring_to_utf8(&err_string, apr_strerror (ErrPtr->apr_err, errbuf, sizeof (errbuf)-1), ErrPtr->pool);
\r
172 git_error_clear (temp_err);
\r
173 msg += _T("Can't recode error string from APR");
\r
177 msg += CUnicodeUtils::StdGetUnicode(err_string);
\r
184 } // if (m_err != NULL)
\r
191 git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t depth)
\r
193 git_wc_status_kind statuskind;
\r
194 // git_client_ctx_t * ctx;
\r
196 // apr_pool_t * pool;
\r
197 // git_error_t * err;
\r
200 CString sProjectRoot;
\r
202 isDir = path.IsDirectory();
\r
203 if (!path.HasAdminDir(&sProjectRoot))
\r
204 return git_wc_status_none;
\r
206 // pool = git_pool_create (NULL); // create the memory pool
\r
208 // git_error_clear(git_client_create_context(&ctx, pool));
\r
210 // git_revnum_t youngest = Git_INVALID_REVNUM;
\r
211 // git_opt_revision_t rev;
\r
212 // rev.kind = git_opt_revision_unspecified;
\r
213 statuskind = git_wc_status_none;
\r
215 // TODO: not sure what to do with recursivenes, it's very unclear exactly what svn does, wingit will however return
\r
216 // the correct (recursive) status for folders, so WGEFF_NoRecurse can be specified to avoid unecessary processing
\r
217 //const BOOL bIsRecursive = (depth == git_depth_infinity || depth == git_depth_unknown); // taken from SVN source
\r
218 UINT nFlags = WGEFF_DirStatusAll;
\r
219 //if (!bIsRecursive)
\r
220 nFlags |= WGEFF_NoRecurse;
\r
222 LPCSTR lpszSubPath = NULL;
\r
224 CString s = path.GetDirectory().GetWinPathString();
\r
225 if (s.GetLength() > sProjectRoot.GetLength())
\r
227 sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));
\r
228 lpszSubPath = sSubPath;
\r
231 err = !wgEnumFiles(CStringA(sProjectRoot), lpszSubPath, nFlags, &getallstatus, &statuskind);
\r
233 /*err = git_client_status4 (&youngest,
\r
234 path.GetSVNApiPath(pool),
\r
242 FALSE, //ignore externals
\r
250 // git_error_clear(err);
\r
251 // git_pool_destroy (pool); //free allocated memory
\r
252 return git_wc_status_none;
\r
255 // git_pool_destroy (pool); //free allocated memory
\r
261 git_wc_status_kind GitStatus::GetAllStatusRecursive(const CTGitPath& path)
\r
263 return GetAllStatus(path, git_depth_infinity);
\r
267 git_wc_status_kind GitStatus::GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2)
\r
269 if (GetStatusRanking(status1) >= GetStatusRanking(status2))
\r
273 // static private method
\r
274 int GitStatus::GetStatusRanking(git_wc_status_kind status)
\r
278 case git_wc_status_none:
\r
280 case git_wc_status_unversioned:
\r
282 case git_wc_status_ignored:
\r
284 case git_wc_status_incomplete:
\r
286 case git_wc_status_normal:
\r
287 case git_wc_status_external:
\r
289 case git_wc_status_added:
\r
291 case git_wc_status_missing:
\r
293 case git_wc_status_deleted:
\r
295 case git_wc_status_replaced:
\r
297 case git_wc_status_modified:
\r
299 case git_wc_status_merged:
\r
301 case git_wc_status_conflicted:
\r
303 case git_wc_status_obstructed:
\r
309 git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false */, bool noignore /* = false */, bool noexternals /* = false */)
\r
312 apr_hash_t * statushash;
\r
313 apr_hash_t * exthash;
\r
314 apr_array_header_t * statusarray;
\r
315 const sort_item* item;
\r
317 git_error_clear(m_err);
\r
318 statushash = apr_hash_make(m_pool);
\r
319 exthash = apr_hash_make(m_pool);
\r
320 git_revnum_t youngest = Git_INVALID_REVNUM;
\r
321 git_opt_revision_t rev;
\r
322 rev.kind = git_opt_revision_unspecified;
\r
323 struct hashbaton_t hashbaton;
\r
324 hashbaton.hash = statushash;
\r
325 hashbaton.exthash = exthash;
\r
326 hashbaton.pThis = this;
\r
327 m_err = git_client_status4 (&youngest,
\r
328 path.GetGitApiPath(m_pool),
\r
332 git_depth_empty, //depth
\r
335 noignore, //noignore
\r
342 // Error present if function is not under version control
\r
343 if ((m_err != NULL) || (apr_hash_count(statushash) == 0))
\r
349 // Convert the unordered hash to an ordered, sorted array
\r
350 statusarray = sort_hash (statushash,
\r
351 sort_compare_items_as_paths,
\r
354 // only the first entry is needed (no recurse)
\r
355 item = &APR_ARRAY_IDX (statusarray, 0, const sort_item);
\r
357 status = (git_wc_status2_t *) item->value;
\r
361 return CString("");
\r
364 git_wc_status2_t * GitStatus::GetFirstFileStatus(const CTGitPath& path, CTGitPath& retPath, bool update, git_depth_t depth, bool bNoIgnore /* = true */, bool bNoExternals /* = false */)
\r
366 static git_wc_status2 st;
\r
368 m_fileCache.Reset();
\r
370 m_fileCache.Init( CStringA( path.GetWinPathString().GetString() ) );
\r
371 MessageBox(NULL, path.GetWinPathString(), _T("GetFirstFile"), MB_OK);
\r
372 m_fileCache.m_pFileIter = m_fileCache.m_pFiles;
\r
373 st.text_status = git_wc_status_none;
\r
375 if (m_fileCache.m_pFileIter)
\r
377 switch(m_fileCache.m_pFileIter->nStatus)
\r
379 case WGFS_Normal: st.text_status = git_wc_status_normal; break;
\r
380 case WGFS_Modified: st.text_status = git_wc_status_modified; break;
\r
381 case WGFS_Deleted: st.text_status = git_wc_status_deleted; break;
\r
384 //retPath.SetFromGit((const char*)item->key);
\r
386 m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext;
\r
392 const sort_item* item;
\r
394 git_error_clear(m_err);
\r
395 m_statushash = apr_hash_make(m_pool);
\r
396 m_externalhash = apr_hash_make(m_pool);
\r
397 headrev = Git_INVALID_REVNUM;
\r
398 git_opt_revision_t rev;
\r
399 rev.kind = git_opt_revision_unspecified;
\r
400 struct hashbaton_t hashbaton;
\r
401 hashbaton.hash = m_statushash;
\r
402 hashbaton.exthash = m_externalhash;
\r
403 hashbaton.pThis = this;
\r
404 m_statushashindex = 0;
\r
405 m_err = git_client_status4 (&headrev,
\r
406 path.GetGitApiPath(m_pool),
\r
413 bNoIgnore, //noignore
\r
414 bNoExternals, //noexternals
\r
420 // Error present if function is not under version control
\r
421 if ((m_err != NULL) || (apr_hash_count(m_statushash) == 0))
\r
426 // Convert the unordered hash to an ordered, sorted array
\r
427 m_statusarray = sort_hash (m_statushash,
\r
428 sort_compare_items_as_paths,
\r
431 // only the first entry is needed (no recurse)
\r
432 m_statushashindex = 0;
\r
433 item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item);
\r
434 retPath.SetFromGit((const char*)item->key);
\r
435 return (git_wc_status2_t *) item->value;
\r
441 unsigned int GitStatus::GetVersionedCount() const
\r
443 // return /**/m_fileCache.GetFileCount();
\r
445 unsigned int count = 0;
\r
447 const sort_item* item;
\r
448 for (unsigned int i=0; i<apr_hash_count(m_statushash); ++i)
\r
450 item = &APR_ARRAY_IDX(m_statusarray, i, const sort_item);
\r
453 if (GitStatus::GetMoreImportant(((git_wc_status_t *)item->value)->text_status, git_wc_status_ignored)!=git_wc_status_ignored)
\r
461 git_wc_status2_t * GitStatus::GetNextFileStatus(CTGitPath& retPath)
\r
463 static git_wc_status2 st;
\r
465 st.text_status = git_wc_status_none;
\r
467 /*if (m_fileCache.m_pFileIter)
\r
469 switch(m_fileCache.m_pFileIter->nStatus)
\r
471 case WGFS_Normal: st.text_status = git_wc_status_normal; break;
\r
472 case WGFS_Modified: st.text_status = git_wc_status_modified; break;
\r
473 case WGFS_Deleted: st.text_status = git_wc_status_deleted; break;
\r
476 m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext;
\r
482 const sort_item* item;
\r
484 if ((m_statushashindex+1) >= apr_hash_count(m_statushash))
\r
486 m_statushashindex++;
\r
488 item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item);
\r
489 retPath.SetFromGit((const char*)item->key);
\r
490 return (git_wc_status2_t *) item->value;
\r
495 bool GitStatus::IsExternal(const CTGitPath& path) const
\r
498 if (apr_hash_get(m_externalhash, path.GetGitApiPath(m_pool), APR_HASH_KEY_STRING))
\r
504 bool GitStatus::IsInExternal(const CTGitPath& path) const
\r
507 if (apr_hash_count(m_statushash) == 0)
\r
510 GitPool localpool(m_pool);
\r
511 apr_hash_index_t *hi;
\r
513 for (hi = apr_hash_first(localpool, m_externalhash); hi; hi = apr_hash_next(hi))
\r
515 apr_hash_this(hi, (const void**)&key, NULL, NULL);
\r
518 if (CTGitPath(CUnicodeUtils::GetUnicode(key)).IsAncestorOf(path))
\r
527 void GitStatus::GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string)
\r
532 case git_wc_status_none:
\r
533 buf = _T("none\0");
\r
535 case git_wc_status_unversioned:
\r
536 buf = _T("unversioned\0");
\r
538 case git_wc_status_normal:
\r
539 buf = _T("normal\0");
\r
541 case git_wc_status_added:
\r
542 buf = _T("added\0");
\r
544 case git_wc_status_missing:
\r
545 buf = _T("missing\0");
\r
547 case git_wc_status_deleted:
\r
548 buf = _T("deleted\0");
\r
550 case git_wc_status_replaced:
\r
551 buf = _T("replaced\0");
\r
553 case git_wc_status_modified:
\r
554 buf = _T("modified\0");
\r
556 case git_wc_status_merged:
\r
557 buf = _T("merged\0");
\r
559 case git_wc_status_conflicted:
\r
560 buf = _T("conflicted\0");
\r
562 case git_wc_status_obstructed:
\r
563 buf = _T("obstructed\0");
\r
565 case git_wc_status_ignored:
\r
566 buf = _T("ignored");
\r
568 case git_wc_status_external:
\r
569 buf = _T("external");
\r
571 case git_wc_status_incomplete:
\r
572 buf = _T("incomplete\0");
\r
578 _stprintf_s(string, buflen, _T("%s"), buf);
\r
581 void GitStatus::GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang)
\r
585 case git_wc_status_none:
\r
586 LoadStringEx(hInst, IDS_STATUSNONE, string, size, lang);
\r
588 case git_wc_status_unversioned:
\r
589 LoadStringEx(hInst, IDS_STATUSUNVERSIONED, string, size, lang);
\r
591 case git_wc_status_normal:
\r
592 LoadStringEx(hInst, IDS_STATUSNORMAL, string, size, lang);
\r
594 case git_wc_status_added:
\r
595 LoadStringEx(hInst, IDS_STATUSADDED, string, size, lang);
\r
597 case git_wc_status_missing:
\r
598 LoadStringEx(hInst, IDS_STATUSABSENT, string, size, lang);
\r
600 case git_wc_status_deleted:
\r
601 LoadStringEx(hInst, IDS_STATUSDELETED, string, size, lang);
\r
603 case git_wc_status_replaced:
\r
604 LoadStringEx(hInst, IDS_STATUSREPLACED, string, size, lang);
\r
606 case git_wc_status_modified:
\r
607 LoadStringEx(hInst, IDS_STATUSMODIFIED, string, size, lang);
\r
609 case git_wc_status_merged:
\r
610 LoadStringEx(hInst, IDS_STATUSMERGED, string, size, lang);
\r
612 case git_wc_status_conflicted:
\r
613 LoadStringEx(hInst, IDS_STATUSCONFLICTED, string, size, lang);
\r
615 case git_wc_status_ignored:
\r
616 LoadStringEx(hInst, IDS_STATUSIGNORED, string, size, lang);
\r
618 case git_wc_status_obstructed:
\r
619 LoadStringEx(hInst, IDS_STATUSOBSTRUCTED, string, size, lang);
\r
621 case git_wc_status_external:
\r
622 LoadStringEx(hInst, IDS_STATUSEXTERNAL, string, size, lang);
\r
624 case git_wc_status_incomplete:
\r
625 LoadStringEx(hInst, IDS_STATUSINCOMPLETE, string, size, lang);
\r
628 LoadStringEx(hInst, IDS_STATUSNONE, string, size, lang);
\r
634 CString GitStatus::GetDepthString(git_depth_t depth)
\r
640 case git_depth_unknown:
\r
641 sDepth.LoadString(IDS_Git_DEPTH_UNKNOWN);
\r
643 case git_depth_empty:
\r
644 sDepth.LoadString(IDS_Git_DEPTH_EMPTY);
\r
646 case git_depth_files:
\r
647 sDepth.LoadString(IDS_Git_DEPTH_FILES);
\r
649 case git_depth_immediates:
\r
650 sDepth.LoadString(IDS_Git_DEPTH_IMMEDIATE);
\r
652 case git_depth_infinity:
\r
653 sDepth.LoadString(IDS_Git_DEPTH_INFINITE);
\r
658 return CString("");
\r
662 void GitStatus::GetDepthString(HINSTANCE hInst, git_depth_t depth, TCHAR * string, int size, WORD lang)
\r
667 case git_depth_unknown:
\r
668 LoadStringEx(hInst, IDS_SVN_DEPTH_UNKNOWN, string, size, lang);
\r
670 case git_depth_empty:
\r
671 LoadStringEx(hInst, IDS_SVN_DEPTH_EMPTY, string, size, lang);
\r
673 case git_depth_files:
\r
674 LoadStringEx(hInst, IDS_SVN_DEPTH_FILES, string, size, lang);
\r
676 case git_depth_immediates:
\r
677 LoadStringEx(hInst, IDS_SVN_DEPTH_IMMEDIATE, string, size, lang);
\r
679 case git_depth_infinity:
\r
680 LoadStringEx(hInst, IDS_SVN_DEPTH_INFINITE, string, size, lang);
\r
687 int GitStatus::LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage)
\r
689 const STRINGRESOURCEIMAGE* pImage;
\r
690 const STRINGRESOURCEIMAGE* pImageEnd;
\r
691 ULONG nResourceSize;
\r
696 HRSRC hResource = FindResourceEx(hInstance, RT_STRING, MAKEINTRESOURCE(((uID>>4)+1)), wLanguage);
\r
699 // try the default language before giving up!
\r
700 hResource = FindResource(hInstance, MAKEINTRESOURCE(((uID>>4)+1)), RT_STRING);
\r
704 hGlobal = LoadResource(hInstance, hResource);
\r
707 pImage = (const STRINGRESOURCEIMAGE*)::LockResource(hGlobal);
\r
711 nResourceSize = ::SizeofResource(hInstance, hResource);
\r
712 pImageEnd = (const STRINGRESOURCEIMAGE*)(LPBYTE(pImage)+nResourceSize);
\r
713 iIndex = uID&0x000f;
\r
715 while ((iIndex > 0) && (pImage < pImageEnd))
\r
717 pImage = (const STRINGRESOURCEIMAGE*)(LPBYTE(pImage)+(sizeof(STRINGRESOURCEIMAGE)+(pImage->nLength*sizeof(WCHAR))));
\r
720 if (pImage >= pImageEnd)
\r
722 if (pImage->nLength == 0)
\r
725 ret = pImage->nLength;
\r
726 if (pImage->nLength > nBufferMax)
\r
728 wcsncpy_s(lpBuffer, nBufferMax, pImage->achString, pImage->nLength-1);
\r
729 lpBuffer[nBufferMax-1] = 0;
\r
733 wcsncpy_s(lpBuffer, nBufferMax, pImage->achString, pImage->nLength);
\r
739 BOOL GitStatus::getallstatus(const struct wgFile_s *pFile, void *pUserData)
\r
741 git_wc_status_kind * s = (git_wc_status_kind *)pUserData;
\r
742 *s = GitStatus::GetMoreImportant(*s, GitStatusFromWingit(pFile->nStatus));
\r
747 git_error_t * GitStatus::getallstatus(void * baton, const char * /*path*/, git_wc_status2_t * status, apr_pool_t * /*pool*/)
\r
749 git_wc_status_kind * s = (git_wc_status_kind *)baton;
\r
750 *s = GitStatus::GetMoreImportant(*s, status->text_status);
\r
751 *s = GitStatus::GetMoreImportant(*s, status->prop_status);
\r
752 return Git_NO_ERROR;
\r
757 git_error_t * GitStatus::getstatushash(void * baton, const char * path, git_wc_status2_t * status, apr_pool_t * /*pool*/)
\r
759 hashbaton_t * hash = (hashbaton_t *)baton;
\r
760 const StdStrAVector& filterList = hash->pThis->m_filterFileList;
\r
761 if (status->text_status == git_wc_status_external)
\r
763 apr_hash_set (hash->exthash, apr_pstrdup(hash->pThis->m_pool, path), APR_HASH_KEY_STRING, (const void*)1);
\r
764 return Git_NO_ERROR;
\r
766 if(filterList.size() > 0)
\r
768 // We have a filter active - we're only interested in files which are in
\r
770 if(!binary_search(filterList.begin(), filterList.end(), path))
\r
772 // This item is not in the filter - don't store it
\r
773 return Git_NO_ERROR;
\r
776 git_wc_status2_t * statuscopy = git_wc_dup_status2 (status, hash->pThis->m_pool);
\r
777 apr_hash_set (hash->hash, apr_pstrdup(hash->pThis->m_pool, path), APR_HASH_KEY_STRING, statuscopy);
\r
778 return Git_NO_ERROR;
\r
781 apr_array_header_t * GitStatus::sort_hash (apr_hash_t *ht,
\r
782 int (*comparison_func) (const GitStatus::sort_item *, const GitStatus::sort_item *),
\r
785 apr_hash_index_t *hi;
\r
786 apr_array_header_t *ary;
\r
788 /* allocate an array with only one element to begin with. */
\r
789 ary = apr_array_make (pool, 1, sizeof(sort_item));
\r
791 /* loop over hash table and push all keys into the array */
\r
792 for (hi = apr_hash_first (pool, ht); hi; hi = apr_hash_next (hi))
\r
794 sort_item *item = (sort_item*)apr_array_push (ary);
\r
796 apr_hash_this (hi, &item->key, &item->klen, &item->value);
\r
799 /* now quick sort the array. */
\r
800 qsort (ary->elts, ary->nelts, ary->elt_size,
\r
801 (int (*)(const void *, const void *))comparison_func);
\r
806 int GitStatus::sort_compare_items_as_paths (const sort_item *a, const sort_item *b)
\r
808 const char *astr, *bstr;
\r
810 astr = (const char*)a->key;
\r
811 bstr = (const char*)b->key;
\r
812 return git_path_compare_paths (astr, bstr);
\r
816 git_error_t* GitStatus::cancel(void *baton)
\r
819 volatile bool * canceled = (bool *)baton;
\r
823 temp.LoadString(IDS_Git_USERCANCELLED);
\r
824 return git_error_create(Git_ERR_CANCELLED, NULL, CUnicodeUtils::GetUTF8(temp));
\r
826 return Git_NO_ERROR;
\r
833 // Set-up a filter to restrict the files which will have their status stored by a get-status
\r
834 void GitStatus::SetFilter(const CTGitPathList& fileList)
\r
836 m_filterFileList.clear();
\r
837 for(int fileIndex = 0; fileIndex < fileList.GetCount(); fileIndex++)
\r
839 // m_filterFileList.push_back(fileList[fileIndex].GetGitApiPath(m_pool));
\r
841 // Sort the list so that we can do binary searches
\r
842 std::sort(m_filterFileList.begin(), m_filterFileList.end());
\r
845 void GitStatus::ClearFilter()
\r
847 m_filterFileList.clear();
\r