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 const BOOL bIsRecursive = (depth == git_depth_infinity || depth == git_depth_unknown); // taken from SVN source
\r
217 LPCSTR lpszSubPath = NULL;
\r
219 CString s = path.GetWinPathString();
\r
220 if (s.GetLength() > sProjectRoot.GetLength())
\r
222 sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));
\r
223 lpszSubPath = sSubPath;
\r
227 // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here
\r
228 UINT nFlags = WGEFF_SingleFile;
\r
230 nFlags |= WGEFF_NoRecurse;
\r
232 // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)
\r
233 nFlags |= WGEFF_EmptyAsNormal;
\r
235 // enumerate all files, recursively if requested
\r
238 nFlags |= WGEFF_NoRecurse;
\r
241 err = !wgEnumFiles(CStringA(sProjectRoot), lpszSubPath, nFlags, &getallstatus, &statuskind);
\r
243 /*err = git_client_status4 (&youngest,
\r
244 path.GetSVNApiPath(pool),
\r
252 FALSE, //ignore externals
\r
260 // git_error_clear(err);
\r
261 // git_pool_destroy (pool); //free allocated memory
\r
262 return git_wc_status_none;
\r
265 // git_pool_destroy (pool); //free allocated memory
\r
271 git_wc_status_kind GitStatus::GetAllStatusRecursive(const CTGitPath& path)
\r
273 return GetAllStatus(path, git_depth_infinity);
\r
277 git_wc_status_kind GitStatus::GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2)
\r
279 if (GetStatusRanking(status1) >= GetStatusRanking(status2))
\r
283 // static private method
\r
284 int GitStatus::GetStatusRanking(git_wc_status_kind status)
\r
288 case git_wc_status_none:
\r
290 case git_wc_status_unversioned:
\r
292 case git_wc_status_ignored:
\r
294 case git_wc_status_incomplete:
\r
296 case git_wc_status_normal:
\r
297 case git_wc_status_external:
\r
299 case git_wc_status_added:
\r
301 case git_wc_status_missing:
\r
303 case git_wc_status_deleted:
\r
305 case git_wc_status_replaced:
\r
307 case git_wc_status_modified:
\r
309 case git_wc_status_merged:
\r
311 case git_wc_status_conflicted:
\r
313 case git_wc_status_obstructed:
\r
319 git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false */, bool noignore /* = false */, bool noexternals /* = false */)
\r
321 // NOTE: unlike the SVN version this one does not cache the enumerated files, because in practice no code in all of
\r
322 // Tortoise uses this, all places that call GetStatus create a temp GitStatus object which gets destroyed right
\r
323 // after the call again
\r
325 // apr_hash_t * statushash;
\r
326 // apr_hash_t * exthash;
\r
327 // apr_array_header_t * statusarray;
\r
328 // const sort_item* item;
\r
330 // git_error_clear(m_err);
\r
331 // statushash = apr_hash_make(m_pool);
\r
332 // exthash = apr_hash_make(m_pool);
\r
333 git_revnum_t youngest = GIT_INVALID_REVNUM;
\r
334 // git_opt_revision_t rev;
\r
335 // rev.kind = git_opt_revision_unspecified;
\r
337 CString sProjectRoot;
\r
338 if ( !path.HasAdminDir(&sProjectRoot) )
\r
341 struct hashbaton_t hashbaton;
\r
342 // hashbaton.hash = statushash;
\r
343 // hashbaton.exthash = exthash;
\r
344 hashbaton.pThis = this;
\r
346 LPCSTR lpszSubPath = NULL;
\r
348 CString s = path.GetWinPathString();
\r
349 if (s.GetLength() > sProjectRoot.GetLength())
\r
351 sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));
\r
352 lpszSubPath = sSubPath;
\r
355 // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here
\r
356 UINT nFlags = WGEFF_SingleFile | WGEFF_NoRecurse;
\r
358 // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)
\r
359 nFlags |= WGEFF_EmptyAsNormal;
\r
361 m_status.prop_status = m_status.text_status = git_wc_status_none;
\r
363 // NOTE: currently wgEnumFiles will not enumerate file if it isn't versioned (so status will be git_wc_status_none)
\r
364 m_err = !wgEnumFiles(CStringA(sProjectRoot), lpszSubPath, nFlags, &getstatus, &m_status);
\r
366 /*m_err = git_client_status4 (&youngest,
\r
367 path.GetGitApiPath(m_pool),
\r
371 git_depth_empty, //depth
\r
374 noignore, //noignore
\r
381 // Error present if function is not under version control
\r
382 if ((m_err != NULL) /*|| (apr_hash_count(statushash) == 0)*/)
\r
386 return GIT_INVALID_REVNUM;
\r
389 // Convert the unordered hash to an ordered, sorted array
\r
390 /*statusarray = sort_hash (statushash,
\r
391 sort_compare_items_as_paths,
\r
394 // only the first entry is needed (no recurse)
\r
395 // item = &APR_ARRAY_IDX (statusarray, 0, const sort_item);
\r
397 // status = (git_wc_status2_t *) item->value;
\r
398 status = &m_status;
\r
402 const BYTE *sha1 = wgGetRevisionID(CStringA(sProjectRoot), NULL);
\r
404 youngest = ConvertHashToRevnum(sha1);
\r
410 git_wc_status2_t * GitStatus::GetFirstFileStatus(const CTGitPath& path, CTGitPath& retPath, bool update, git_depth_t depth, bool bNoIgnore /* = true */, bool bNoExternals /* = false */)
\r
412 static git_wc_status2 st;
\r
414 m_fileCache.Reset();
\r
416 m_fileCache.Init( CStringA( path.GetWinPathString().GetString() ) );
\r
417 MessageBox(NULL, path.GetWinPathString(), _T("GetFirstFile"), MB_OK);
\r
418 m_fileCache.m_pFileIter = m_fileCache.m_pFiles;
\r
419 st.text_status = git_wc_status_none;
\r
421 if (m_fileCache.m_pFileIter)
\r
423 switch(m_fileCache.m_pFileIter->nStatus)
\r
425 case WGFS_Normal: st.text_status = git_wc_status_normal; break;
\r
426 case WGFS_Modified: st.text_status = git_wc_status_modified; break;
\r
427 case WGFS_Deleted: st.text_status = git_wc_status_deleted; break;
\r
430 //retPath.SetFromGit((const char*)item->key);
\r
432 m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext;
\r
438 const sort_item* item;
\r
440 git_error_clear(m_err);
\r
441 m_statushash = apr_hash_make(m_pool);
\r
442 m_externalhash = apr_hash_make(m_pool);
\r
443 headrev = Git_INVALID_REVNUM;
\r
444 git_opt_revision_t rev;
\r
445 rev.kind = git_opt_revision_unspecified;
\r
446 struct hashbaton_t hashbaton;
\r
447 hashbaton.hash = m_statushash;
\r
448 hashbaton.exthash = m_externalhash;
\r
449 hashbaton.pThis = this;
\r
450 m_statushashindex = 0;
\r
451 m_err = git_client_status4 (&headrev,
\r
452 path.GetGitApiPath(m_pool),
\r
459 bNoIgnore, //noignore
\r
460 bNoExternals, //noexternals
\r
466 // Error present if function is not under version control
\r
467 if ((m_err != NULL) || (apr_hash_count(m_statushash) == 0))
\r
472 // Convert the unordered hash to an ordered, sorted array
\r
473 m_statusarray = sort_hash (m_statushash,
\r
474 sort_compare_items_as_paths,
\r
477 // only the first entry is needed (no recurse)
\r
478 m_statushashindex = 0;
\r
479 item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item);
\r
480 retPath.SetFromGit((const char*)item->key);
\r
481 return (git_wc_status2_t *) item->value;
\r
487 unsigned int GitStatus::GetVersionedCount() const
\r
489 // return /**/m_fileCache.GetFileCount();
\r
491 unsigned int count = 0;
\r
493 const sort_item* item;
\r
494 for (unsigned int i=0; i<apr_hash_count(m_statushash); ++i)
\r
496 item = &APR_ARRAY_IDX(m_statusarray, i, const sort_item);
\r
499 if (GitStatus::GetMoreImportant(((git_wc_status_t *)item->value)->text_status, git_wc_status_ignored)!=git_wc_status_ignored)
\r
507 git_wc_status2_t * GitStatus::GetNextFileStatus(CTGitPath& retPath)
\r
509 static git_wc_status2 st;
\r
511 st.text_status = git_wc_status_none;
\r
513 /*if (m_fileCache.m_pFileIter)
\r
515 switch(m_fileCache.m_pFileIter->nStatus)
\r
517 case WGFS_Normal: st.text_status = git_wc_status_normal; break;
\r
518 case WGFS_Modified: st.text_status = git_wc_status_modified; break;
\r
519 case WGFS_Deleted: st.text_status = git_wc_status_deleted; break;
\r
522 m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext;
\r
528 const sort_item* item;
\r
530 if ((m_statushashindex+1) >= apr_hash_count(m_statushash))
\r
532 m_statushashindex++;
\r
534 item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item);
\r
535 retPath.SetFromGit((const char*)item->key);
\r
536 return (git_wc_status2_t *) item->value;
\r
541 bool GitStatus::IsExternal(const CTGitPath& path) const
\r
544 if (apr_hash_get(m_externalhash, path.GetGitApiPath(m_pool), APR_HASH_KEY_STRING))
\r
550 bool GitStatus::IsInExternal(const CTGitPath& path) const
\r
553 if (apr_hash_count(m_statushash) == 0)
\r
556 GitPool localpool(m_pool);
\r
557 apr_hash_index_t *hi;
\r
559 for (hi = apr_hash_first(localpool, m_externalhash); hi; hi = apr_hash_next(hi))
\r
561 apr_hash_this(hi, (const void**)&key, NULL, NULL);
\r
564 if (CTGitPath(CUnicodeUtils::GetUnicode(key)).IsAncestorOf(path))
\r
573 void GitStatus::GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string)
\r
578 case git_wc_status_none:
\r
579 buf = _T("none\0");
\r
581 case git_wc_status_unversioned:
\r
582 buf = _T("unversioned\0");
\r
584 case git_wc_status_normal:
\r
585 buf = _T("normal\0");
\r
587 case git_wc_status_added:
\r
588 buf = _T("added\0");
\r
590 case git_wc_status_missing:
\r
591 buf = _T("missing\0");
\r
593 case git_wc_status_deleted:
\r
594 buf = _T("deleted\0");
\r
596 case git_wc_status_replaced:
\r
597 buf = _T("replaced\0");
\r
599 case git_wc_status_modified:
\r
600 buf = _T("modified\0");
\r
602 case git_wc_status_merged:
\r
603 buf = _T("merged\0");
\r
605 case git_wc_status_conflicted:
\r
606 buf = _T("conflicted\0");
\r
608 case git_wc_status_obstructed:
\r
609 buf = _T("obstructed\0");
\r
611 case git_wc_status_ignored:
\r
612 buf = _T("ignored");
\r
614 case git_wc_status_external:
\r
615 buf = _T("external");
\r
617 case git_wc_status_incomplete:
\r
618 buf = _T("incomplete\0");
\r
624 _stprintf_s(string, buflen, _T("%s"), buf);
\r
627 void GitStatus::GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang)
\r
631 case git_wc_status_none:
\r
632 LoadStringEx(hInst, IDS_STATUSNONE, string, size, lang);
\r
634 case git_wc_status_unversioned:
\r
635 LoadStringEx(hInst, IDS_STATUSUNVERSIONED, string, size, lang);
\r
637 case git_wc_status_normal:
\r
638 LoadStringEx(hInst, IDS_STATUSNORMAL, string, size, lang);
\r
640 case git_wc_status_added:
\r
641 LoadStringEx(hInst, IDS_STATUSADDED, string, size, lang);
\r
643 case git_wc_status_missing:
\r
644 LoadStringEx(hInst, IDS_STATUSABSENT, string, size, lang);
\r
646 case git_wc_status_deleted:
\r
647 LoadStringEx(hInst, IDS_STATUSDELETED, string, size, lang);
\r
649 case git_wc_status_replaced:
\r
650 LoadStringEx(hInst, IDS_STATUSREPLACED, string, size, lang);
\r
652 case git_wc_status_modified:
\r
653 LoadStringEx(hInst, IDS_STATUSMODIFIED, string, size, lang);
\r
655 case git_wc_status_merged:
\r
656 LoadStringEx(hInst, IDS_STATUSMERGED, string, size, lang);
\r
658 case git_wc_status_conflicted:
\r
659 LoadStringEx(hInst, IDS_STATUSCONFLICTED, string, size, lang);
\r
661 case git_wc_status_ignored:
\r
662 LoadStringEx(hInst, IDS_STATUSIGNORED, string, size, lang);
\r
664 case git_wc_status_obstructed:
\r
665 LoadStringEx(hInst, IDS_STATUSOBSTRUCTED, string, size, lang);
\r
667 case git_wc_status_external:
\r
668 LoadStringEx(hInst, IDS_STATUSEXTERNAL, string, size, lang);
\r
670 case git_wc_status_incomplete:
\r
671 LoadStringEx(hInst, IDS_STATUSINCOMPLETE, string, size, lang);
\r
674 LoadStringEx(hInst, IDS_STATUSNONE, string, size, lang);
\r
680 CString GitStatus::GetDepthString(git_depth_t depth)
\r
686 case git_depth_unknown:
\r
687 sDepth.LoadString(IDS_Git_DEPTH_UNKNOWN);
\r
689 case git_depth_empty:
\r
690 sDepth.LoadString(IDS_Git_DEPTH_EMPTY);
\r
692 case git_depth_files:
\r
693 sDepth.LoadString(IDS_Git_DEPTH_FILES);
\r
695 case git_depth_immediates:
\r
696 sDepth.LoadString(IDS_Git_DEPTH_IMMEDIATE);
\r
698 case git_depth_infinity:
\r
699 sDepth.LoadString(IDS_Git_DEPTH_INFINITE);
\r
704 return CString("");
\r
708 void GitStatus::GetDepthString(HINSTANCE hInst, git_depth_t depth, TCHAR * string, int size, WORD lang)
\r
713 case git_depth_unknown:
\r
714 LoadStringEx(hInst, IDS_SVN_DEPTH_UNKNOWN, string, size, lang);
\r
716 case git_depth_empty:
\r
717 LoadStringEx(hInst, IDS_SVN_DEPTH_EMPTY, string, size, lang);
\r
719 case git_depth_files:
\r
720 LoadStringEx(hInst, IDS_SVN_DEPTH_FILES, string, size, lang);
\r
722 case git_depth_immediates:
\r
723 LoadStringEx(hInst, IDS_SVN_DEPTH_IMMEDIATE, string, size, lang);
\r
725 case git_depth_infinity:
\r
726 LoadStringEx(hInst, IDS_SVN_DEPTH_INFINITE, string, size, lang);
\r
733 int GitStatus::LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage)
\r
735 const STRINGRESOURCEIMAGE* pImage;
\r
736 const STRINGRESOURCEIMAGE* pImageEnd;
\r
737 ULONG nResourceSize;
\r
742 HRSRC hResource = FindResourceEx(hInstance, RT_STRING, MAKEINTRESOURCE(((uID>>4)+1)), wLanguage);
\r
745 // try the default language before giving up!
\r
746 hResource = FindResource(hInstance, MAKEINTRESOURCE(((uID>>4)+1)), RT_STRING);
\r
750 hGlobal = LoadResource(hInstance, hResource);
\r
753 pImage = (const STRINGRESOURCEIMAGE*)::LockResource(hGlobal);
\r
757 nResourceSize = ::SizeofResource(hInstance, hResource);
\r
758 pImageEnd = (const STRINGRESOURCEIMAGE*)(LPBYTE(pImage)+nResourceSize);
\r
759 iIndex = uID&0x000f;
\r
761 while ((iIndex > 0) && (pImage < pImageEnd))
\r
763 pImage = (const STRINGRESOURCEIMAGE*)(LPBYTE(pImage)+(sizeof(STRINGRESOURCEIMAGE)+(pImage->nLength*sizeof(WCHAR))));
\r
766 if (pImage >= pImageEnd)
\r
768 if (pImage->nLength == 0)
\r
771 ret = pImage->nLength;
\r
772 if (pImage->nLength > nBufferMax)
\r
774 wcsncpy_s(lpBuffer, nBufferMax, pImage->achString, pImage->nLength-1);
\r
775 lpBuffer[nBufferMax-1] = 0;
\r
779 wcsncpy_s(lpBuffer, nBufferMax, pImage->achString, pImage->nLength);
\r
785 BOOL GitStatus::getallstatus(const struct wgFile_s *pFile, void *pUserData)
\r
787 git_wc_status_kind * s = (git_wc_status_kind *)pUserData;
\r
788 *s = GitStatus::GetMoreImportant(*s, GitStatusFromWingit(pFile->nStatus));
\r
792 BOOL GitStatus::getstatus(const struct wgFile_s *pFile, void *pUserData)
\r
794 git_wc_status2_t * s = (git_wc_status2_t*)pUserData;
\r
795 s->prop_status = s->text_status = GitStatus::GetMoreImportant(s->prop_status, GitStatusFromWingit(pFile->nStatus));
\r
800 git_error_t * GitStatus::getallstatus(void * baton, const char * /*path*/, git_wc_status2_t * status, apr_pool_t * /*pool*/)
\r
802 git_wc_status_kind * s = (git_wc_status_kind *)baton;
\r
803 *s = GitStatus::GetMoreImportant(*s, status->text_status);
\r
804 *s = GitStatus::GetMoreImportant(*s, status->prop_status);
\r
805 return Git_NO_ERROR;
\r
810 git_error_t * GitStatus::getstatushash(void * baton, const char * path, git_wc_status2_t * status, apr_pool_t * /*pool*/)
\r
812 hashbaton_t * hash = (hashbaton_t *)baton;
\r
813 const StdStrAVector& filterList = hash->pThis->m_filterFileList;
\r
814 if (status->text_status == git_wc_status_external)
\r
816 apr_hash_set (hash->exthash, apr_pstrdup(hash->pThis->m_pool, path), APR_HASH_KEY_STRING, (const void*)1);
\r
817 return Git_NO_ERROR;
\r
819 if(filterList.size() > 0)
\r
821 // We have a filter active - we're only interested in files which are in
\r
823 if(!binary_search(filterList.begin(), filterList.end(), path))
\r
825 // This item is not in the filter - don't store it
\r
826 return Git_NO_ERROR;
\r
829 git_wc_status2_t * statuscopy = git_wc_dup_status2 (status, hash->pThis->m_pool);
\r
830 apr_hash_set (hash->hash, apr_pstrdup(hash->pThis->m_pool, path), APR_HASH_KEY_STRING, statuscopy);
\r
831 return Git_NO_ERROR;
\r
834 apr_array_header_t * GitStatus::sort_hash (apr_hash_t *ht,
\r
835 int (*comparison_func) (const GitStatus::sort_item *, const GitStatus::sort_item *),
\r
838 apr_hash_index_t *hi;
\r
839 apr_array_header_t *ary;
\r
841 /* allocate an array with only one element to begin with. */
\r
842 ary = apr_array_make (pool, 1, sizeof(sort_item));
\r
844 /* loop over hash table and push all keys into the array */
\r
845 for (hi = apr_hash_first (pool, ht); hi; hi = apr_hash_next (hi))
\r
847 sort_item *item = (sort_item*)apr_array_push (ary);
\r
849 apr_hash_this (hi, &item->key, &item->klen, &item->value);
\r
852 /* now quick sort the array. */
\r
853 qsort (ary->elts, ary->nelts, ary->elt_size,
\r
854 (int (*)(const void *, const void *))comparison_func);
\r
859 int GitStatus::sort_compare_items_as_paths (const sort_item *a, const sort_item *b)
\r
861 const char *astr, *bstr;
\r
863 astr = (const char*)a->key;
\r
864 bstr = (const char*)b->key;
\r
865 return git_path_compare_paths (astr, bstr);
\r
869 git_error_t* GitStatus::cancel(void *baton)
\r
872 volatile bool * canceled = (bool *)baton;
\r
876 temp.LoadString(IDS_Git_USERCANCELLED);
\r
877 return git_error_create(Git_ERR_CANCELLED, NULL, CUnicodeUtils::GetUTF8(temp));
\r
879 return Git_NO_ERROR;
\r
886 // Set-up a filter to restrict the files which will have their status stored by a get-status
\r
887 void GitStatus::SetFilter(const CTGitPathList& fileList)
\r
889 m_filterFileList.clear();
\r
890 for(int fileIndex = 0; fileIndex < fileList.GetCount(); fileIndex++)
\r
892 // m_filterFileList.push_back(fileList[fileIndex].GetGitApiPath(m_pool));
\r
894 // Sort the list so that we can do binary searches
\r
895 std::sort(m_filterFileList.begin(), m_filterFileList.end());
\r
898 void GitStatus::ClearFilter()
\r
900 m_filterFileList.clear();
\r