bool CFileDiffDlg::SortCompare(const CTGitPath& Data1, const CTGitPath& Data2) { int result = 0; int d1, d2; switch (m_nSortedColumn) { case 0: //path column result = Data1.GetWinPathString().Compare(Data2.GetWinPathString()); break; case 1: //action column result = Data1.m_Action - Data2.m_Action; break; case 2: d1 = CSorter::A2L(Data1.m_StatAdd); d2 = CSorter::A2L(Data2.m_StatAdd); result = d1 - d2; break; case 3: d1 = CSorter::A2L(Data1.m_StatDel);; d2 = CSorter::A2L(Data2.m_StatDel); result = d1 - d2; break; default: break; } if (!m_bAscending) result = -result; return result < 0; }
CTGitPath CTGitPath::GetSubPath(const CTGitPath &root) { CTGitPath path; if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString()) { CString str=GetWinPathString(); path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1)); } return path; }
void CGitStatusCache::CloseWatcherHandles(HANDLE hFile) { CTGitPath path = watcher.CloseInfoMap(hFile); if (!path.IsEmpty()) m_folderCrawler.BlockPath(path); CGitStatusCache::Instance().m_GitStatus.ReleasePathsRecursively(path.GetWinPathString()); }
CString CCachedDirectory::GetCacheKey(const CTGitPath& path) { // All we put into the cache as a key is just the end portion of the pathname // There's no point storing the path of the containing directory for every item return path.GetWinPathString().Mid(m_directoryPath.GetWinPathString().GetLength()).MakeLower().TrimLeft(_T("\\")); }
void CHooks::AddErrorParam(CString& sCmd, const CString& error) { CTGitPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)error); AddParam(sCmd, tempPath.GetWinPathString()); }
void CFolderCrawler::AddDirectoryForUpdate(const CTGitPath& path) { /* Index file changing*/ if( GitStatus::IsExistIndexLockFile((CString&)path.GetWinPathString())) return; if (!CGitStatusCache::Instance().IsPathGood(path)) return; { ATLTRACE(_T("AddDirectoryForUpdate %s\n"),path.GetWinPath()); AutoLocker lock(m_critSec); RemoveDuplicate(m_foldersToUpdate, path); m_foldersToUpdate.push_back(path); m_foldersToUpdate.back().SetCustomData(GetTickCount()+10); //ATLASSERT(path.IsDirectory() || !path.Exists()); // set this flag while we are sync'ed // with the worker thread m_bItemsAddedSinceLastCrawl = true; } //if (SetHoldoff()) SetEvent(m_hWakeEvent); }
CTGitPath CHooks::AddMessageFileParam(CString& sCmd, const CString& message) { CTGitPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)message); AddParam(sCmd, tempPath.GetWinPathString()); return tempPath; }
void CCheckCertificateDlg::OnBnClickedOpencert() { CTGitPath tempFile = CTempFiles::Instance().GetTempFilePath(true, CTGitPath(_T("certificate.der"))); try { CFile file(tempFile.GetWinPathString(), CFile::modeReadWrite); file.Write(cert->data, (UINT)cert->len); file.Close(); } catch (CFileException* e) { MessageBox(_T("Could not write to file."), _T("TortoiseGit"), MB_ICONERROR); e->Delete(); return; } CAppUtils::ShellOpen(tempFile.GetWinPathString(), GetSafeHwnd()); }
UINT CChangedDlg::ChangedStatusThread() { InterlockedExchange(&m_bBlock, TRUE); g_Git.RefreshGitIndex(); m_bCanceled = false; SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL))); DialogEnableWindow(IDC_REFRESH, FALSE); DialogEnableWindow(IDC_SHOWUNVERSIONED, FALSE); DialogEnableWindow(IDC_SHOWUNMODIFIED, FALSE); DialogEnableWindow(IDC_SHOWIGNORED, FALSE); DialogEnableWindow(IDC_SHOWUSERPROPS, FALSE); CString temp; m_FileListCtrl.Clear(); if (!m_FileListCtrl.GetStatus(&m_pathList, m_bRemote, m_bShowIgnored != FALSE, m_bShowUnversioned != FALSE)) { if (!m_FileListCtrl.GetLastErrorMessage().IsEmpty()) m_FileListCtrl.SetEmptyString(m_FileListCtrl.GetLastErrorMessage()); } unsigned int dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS | GITSLC_SHOWLOCKS | GITSLC_SHOWSWITCHED | GITSLC_SHOWINCHANGELIST; dwShow |= m_bShowUnversioned ? GITSLC_SHOWUNVERSIONED : 0; dwShow |= m_iShowUnmodified ? GITSLC_SHOWNORMAL : 0; dwShow |= m_bShowIgnored ? GITSLC_SHOWIGNORED : 0; dwShow |= m_bShowExternals ? GITSLC_SHOWEXTERNAL | GITSLC_SHOWINEXTERNALS | GITSLC_SHOWEXTERNALFROMDIFFERENTREPO : 0; m_FileListCtrl.Show(dwShow); UpdateStatistics(); bool bIsDirectory = false; CTGitPath commonDir = m_FileListCtrl.GetCommonDirectory(false); if (m_pathList.GetCount() == 1) { if (m_pathList[0].IsEmpty()) CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle); else CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetWinPathString()).TrimRight('\\'), m_sTitle); bIsDirectory = m_pathList[0].IsDirectory() || m_pathList[0].IsEmpty(); // if it is empty it is g_Git.m_CurrentDir which is a directory } else CAppUtils::SetWindowTitle(m_hWnd, commonDir.GetWinPathString(), m_sTitle); SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK))); DialogEnableWindow(IDC_REFRESH, TRUE); DialogEnableWindow(IDC_SHOWUNVERSIONED, bIsDirectory); //DialogEnableWindow(IDC_SHOWUNMODIFIED, bIsDirectory); DialogEnableWindow(IDC_SHOWIGNORED, bIsDirectory); DialogEnableWindow(IDC_SHOWUSERPROPS, TRUE); InterlockedExchange(&m_bBlock, FALSE); // revert the remote flag back to the default m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE); RefreshCursor(); return 0; }
void GitStatus::GetStatus(const CTGitPath& path, bool /*update*/ /* = false */, bool noignore /* = false */, bool /*noexternals*/ /* = false */) { // NOTE: unlike the SVN version this one does not cache the enumerated files, because in practice no code in all of // Tortoise uses this, all places that call GetStatus create a temp GitStatus object which gets destroyed right // after the call again CString sProjectRoot; if ( !path.HasAdminDir(&sProjectRoot) ) return; bool isfull = ((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? ShellCache::dll : ShellCache::exe) == ShellCache::dllFull); int err = 0; { LPCTSTR lpszSubPath = NULL; CString sSubPath; CString s = path.GetWinPathString(); if (s.GetLength() > sProjectRoot.GetLength()) { sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength()); lpszSubPath = sSubPath; // skip initial slash if necessary if (*lpszSubPath == _T('\\')) ++lpszSubPath; } m_status.prop_status = m_status.text_status = git_wc_status_none; m_status.assumeValid = false; m_status.skipWorktree = false; if(path.IsDirectory()) { err = GetDirStatus(sProjectRoot,lpszSubPath,&m_status.text_status , isfull, false,!noignore, NULL, NULL); if (m_status.text_status == git_wc_status_added || m_status.text_status == git_wc_status_deleted) // fix for issue #1769; a folder is either modified, conflicted or normal m_status.text_status = git_wc_status_modified; } else { err = GetFileStatus(sProjectRoot, lpszSubPath, &m_status.text_status ,isfull, false,!noignore, NULL,NULL, &m_status.assumeValid, &m_status.skipWorktree); } } // Error present if function is not under version control if (err) { status = NULL; return; } status = &m_status; }
// static method git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t depth) { git_wc_status_kind statuskind; // git_client_ctx_t * ctx; // apr_pool_t * pool; // git_error_t * err; BOOL err; BOOL isDir; CString sProjectRoot; isDir = path.IsDirectory(); if (!path.HasAdminDir(&sProjectRoot)) return git_wc_status_none; // pool = git_pool_create (NULL); // create the memory pool // git_error_clear(git_client_create_context(&ctx, pool)); // git_revnum_t youngest = Git_INVALID_REVNUM; // git_opt_revision_t rev; // rev.kind = git_opt_revision_unspecified; statuskind = git_wc_status_none; const BOOL bIsRecursive = (depth == git_depth_infinity || depth == git_depth_unknown); // taken from SVN source CString sSubPath; CString s = path.GetWinPathString(); if (s.GetLength() > sProjectRoot.GetLength()) { if (sProjectRoot.GetLength() == 3 && sProjectRoot[1] == _T(':')) sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength()); else sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/); } bool isfull = ((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? ShellCache::dll : ShellCache::exe) == ShellCache::dllFull); if(isDir) { err = GetDirStatus(sProjectRoot,sSubPath,&statuskind, isfull,bIsRecursive,isfull,NULL, NULL); } else { err = GetFileStatus(sProjectRoot,sSubPath,&statuskind,isfull, false,isfull, NULL,NULL); } return statuskind; }
bool CHooks::PreCommit(const CString& workingTree, const CTGitPathList& pathList, CString& message, DWORD& exitcode, CString& error) { auto it = FindItem(pre_commit_hook, workingTree); if (it == end()) return false; CString sCmd = it->second.commandline; AddPathParam(sCmd, pathList); CTGitPath temppath = AddMessageFileParam(sCmd, message); AddCWDParam(sCmd, workingTree); exitcode = RunScript(sCmd, workingTree, error, it->second.bWait, it->second.bShow); if (!exitcode && !temppath.IsEmpty()) CStringUtils::ReadStringFromTextFile(temppath.GetWinPathString(), message); return true; }
bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const { possibleDescendant.EnsureBackslashPathSet(); EnsureBackslashPathSet(); bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength())); if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength()) { return bPathStringsEqual; } return (bPathStringsEqual && ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')|| (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':'))); }
bool CFileDiffDlg::SortCompare(const CTGitPath& Data1, const CTGitPath& Data2) { int result = 0; int d1, d2; switch (m_nSortedColumn) { case 0: //path column result = Data1.GetWinPathString().Compare(Data2.GetWinPathString()); break; case 1: //extension column result = Data1.GetFileExtension().Compare(Data2.GetFileExtension()); break; case 2: //action column result = Data1.m_Action - Data2.m_Action; break; case 3: d1 = CSorter::A2L(Data1.m_StatAdd); d2 = CSorter::A2L(Data2.m_StatAdd); result = d1 - d2; break; case 4: d1 = CSorter::A2L(Data1.m_StatDel);; d2 = CSorter::A2L(Data2.m_StatDel); result = d1 - d2; break; default: break; } // sort by path name as second priority if (m_nSortedColumn != 0 && result == 0) result = Data1.GetWinPathString().Compare(Data2.GetWinPathString()); if (!m_bAscending) result = -result; return result < 0; }
void CFolderCrawler::AddPathForUpdate(const CTGitPath& path) { /* Index file changing*/ if( GitStatus::IsExistIndexLockFile((CString&)path.GetWinPathString())) return; { AutoLocker lock(m_critSec); m_pathsToUpdate.Push(path); m_bPathsAddedSinceLastCrawl = true; } //if (SetHoldoff()) SetEvent(m_hWakeEvent); }
bool CHooks::StartCommit(const CTGitPathList& pathList, CString& message, DWORD& exitcode, CString& error) { hookiterator it = FindItem(start_commit_hook, pathList); if (it == end()) return false; CString sCmd = it->second.commandline; AddPathParam(sCmd, pathList); CTGitPath temppath = AddMessageFileParam(sCmd, message); AddCWDParam(sCmd, pathList); exitcode = RunScript(sCmd, pathList.GetCommonRoot().GetDirectory().GetWinPath(), error, it->second.bWait, it->second.bShow); if (!exitcode && !temppath.IsEmpty()) { CStringUtils::ReadStringFromTextFile(temppath.GetWinPathString(), message); } return true; }
CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch /* = true */) { CString sProjectRoot; bool bIsVersionedPath; bool bRequestForSelf = false; if(path.IsEquivalentToWithoutCase(m_directoryPath)) { bRequestForSelf = true; AutoLocker lock(m_critSec); // HasAdminDir might modify m_directoryPath, so we need to do it synchronized bIsVersionedPath = m_directoryPath.HasAdminDir(&sProjectRoot); } else bIsVersionedPath = path.HasAdminDir(&sProjectRoot); // In all most circumstances, we ask for the status of a member of this directory. ATLASSERT(m_directoryPath.IsEquivalentToWithoutCase(path.GetContainingDirectory()) || bRequestForSelf); //If is not version control path if( !bIsVersionedPath) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": %s is not underversion control\n"), path.GetWinPath()); return CStatusCacheEntry(); } // We've not got this item in the cache - let's add it // We never bother asking SVN for the status of just one file, always for its containing directory if (GitAdminDir::IsAdminDirPath(path.GetWinPathString())) { // We're being asked for the status of an .git directory // It's not worth asking for this return CStatusCacheEntry(); } if(bFetch) { return GetStatusFromGit(path, sProjectRoot); } else { return GetStatusFromCache(path, bRecursive); } }
UINT CChangedDlg::ChangedStatusThread() { InterlockedExchange(&m_bBlock, TRUE); m_bCanceled = false; SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL))); DialogEnableWindow(IDC_REFRESH, FALSE); DialogEnableWindow(IDC_CHECKREPO, FALSE); DialogEnableWindow(IDC_SHOWUNVERSIONED, FALSE); DialogEnableWindow(IDC_SHOWUNMODIFIED, FALSE); DialogEnableWindow(IDC_SHOWIGNORED, FALSE); DialogEnableWindow(IDC_SHOWUSERPROPS, FALSE); CString temp; if (!m_FileListCtrl.GetStatus(&m_pathList, m_bRemote, m_bShowIgnored != FALSE, m_bShowUnversioned,m_bShowUserProps != FALSE)) { if (!m_FileListCtrl.GetLastErrorMessage().IsEmpty()) m_FileListCtrl.SetEmptyString(m_FileListCtrl.GetLastErrorMessage()); } DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWSWITCHED | SVNSLC_SHOWINCHANGELIST; dwShow |= m_bShowUnversioned ? SVNSLC_SHOWUNVERSIONED : 0; dwShow |= m_iShowUnmodified ? SVNSLC_SHOWNORMAL : 0; dwShow |= m_bShowIgnored ? SVNSLC_SHOWIGNORED : 0; dwShow |= m_bShowExternals ? SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO : 0; m_FileListCtrl.Show(dwShow); UpdateStatistics(); CTGitPath commonDir = m_FileListCtrl.GetCommonDirectory(false); bool bSingleFile = ((m_pathList.GetCount()==1)&&(!m_pathList[0].IsDirectory())); if (bSingleFile) SetWindowText(m_sTitle + _T(" - ") + m_pathList[0].GetWinPathString()); else SetWindowText(m_sTitle + _T(" - ") + commonDir.GetWinPathString()); SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK))); DialogEnableWindow(IDC_REFRESH, TRUE); DialogEnableWindow(IDC_CHECKREPO, TRUE); DialogEnableWindow(IDC_SHOWUNVERSIONED, !bSingleFile); DialogEnableWindow(IDC_SHOWUNMODIFIED, !bSingleFile); DialogEnableWindow(IDC_SHOWIGNORED, !bSingleFile); DialogEnableWindow(IDC_SHOWUSERPROPS, TRUE); InterlockedExchange(&m_bBlock, FALSE); // revert the remote flag back to the default m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE); RefreshCursor(); return 0; }
CTGitPath CTempFiles::ConstructTempPath(const CTGitPath& path) { DWORD len = ::GetTempPath(0, nullptr); auto temppath = std::make_unique<TCHAR[]>(len + 1); auto tempF = std::make_unique<TCHAR[]>(len + 50); ::GetTempPath (len+1, temppath.get()); CTGitPath tempfile; CString possibletempfile; if (path.IsEmpty()) { ::GetTempFileName(temppath.get(), L"tsm", 0, tempF.get()); tempfile = CTGitPath (tempF.get()); } else { int i=0; do { // use the UI path, which does unescaping for urls CString filename = path.GetUIFileOrDirectoryName(); // remove illegal chars which could be present in urls filename.Remove('?'); filename.Remove('*'); filename.Remove('<'); filename.Remove('>'); filename.Remove('|'); filename.Remove('"'); // the inner loop assures that the resulting path is < MAX_PATH // if that's not possible without reducing the 'filename' to less than 5 chars, use a path // that's longer than MAX_PATH (in that case, we can't really do much to avoid longer paths) do { possibletempfile.Format(L"%s%s.tsm%3.3x.tmp%s", temppath.get(), (LPCTSTR)filename, i, (LPCTSTR)path.GetFileExtension()); tempfile.SetFromWin(possibletempfile); filename = filename.Left(filename.GetLength()-1); } while ( (filename.GetLength() > 4) && (tempfile.GetWinPathString().GetLength() >= MAX_PATH)); i++; } while (PathFileExists(tempfile.GetWinPath())); } // caller has to actually grab the file path return tempfile; }
// static method git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t depth, bool * assumeValid, bool * skipWorktree) { git_wc_status_kind statuskind; BOOL err; BOOL isDir; CString sProjectRoot; isDir = path.IsDirectory(); if (!path.HasAdminDir(&sProjectRoot)) return git_wc_status_none; // rev.kind = git_opt_revision_unspecified; statuskind = git_wc_status_none; const BOOL bIsRecursive = (depth == git_depth_infinity || depth == git_depth_unknown); // taken from SVN source CString sSubPath; CString s = path.GetWinPathString(); if (s.GetLength() > sProjectRoot.GetLength()) { if (sProjectRoot.GetLength() == 3 && sProjectRoot[1] == _T(':')) sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength()); else sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/); } bool isfull = ((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? ShellCache::dll : ShellCache::exe) == ShellCache::dllFull); if(isDir) { err = GetDirStatus(sProjectRoot,sSubPath,&statuskind, isfull,bIsRecursive,isfull,NULL, NULL); // folders must not be displayed as added or deleted only as modified (this is for Shell Overlay-Modes) if (statuskind == git_wc_status_unversioned && sSubPath.IsEmpty()) statuskind = git_wc_status_normal; else if (statuskind == git_wc_status_deleted || statuskind == git_wc_status_added) statuskind = git_wc_status_modified; } else { err = GetFileStatus(sProjectRoot, sSubPath, &statuskind, isfull, false, isfull, NULL, NULL, assumeValid, skipWorktree); } return statuskind; }
int CSendMailCombineable::SendAsSingleMail(const CTGitPath& path, CGitProgressList* instance) { ASSERT(instance); CString pathfile(path.GetWinPathString()); CString body; CStringArray attachments; if (m_bAttachment) attachments.Add(pathfile); else if (GetFileContents(pathfile, body)) { instance->ReportError(_T("Could not open ") + pathfile); return -2; } return SendMail(path, instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, m_sSubject, body, attachments); }
int CGitDiff::DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative) { if (path1.GetWinPathString().IsEmpty()) { CFileDiffDlg dlg; dlg.SetDiff(nullptr, r2, r1); dlg.DoModal(); } else if (path1.IsDirectory()) { CFileDiffDlg dlg; dlg.SetDiff(&path1, r2, r1); dlg.DoModal(); } else Diff(&path1, &path2, r1, r2, false, false, 0, bAlternative); return 0; }
CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch /* = true */) { CString strCacheKey; bool bRequestForSelf = false; if(path.IsEquivalentToWithoutCase(m_directoryPath)) { bRequestForSelf = true; } //OutputDebugStringA("GetStatusForMember: ");OutputDebugStringW(path.GetWinPathString());OutputDebugStringA("\r\n"); // In all most circumstances, we ask for the status of a member of this directory. ATLASSERT(m_directoryPath.IsEquivalentToWithoutCase(path.GetContainingDirectory()) || bRequestForSelf); CString sProjectRoot; const BOOL bIsVersionedPath = path.HasAdminDir(&sProjectRoot); //If is not version control path if( !bIsVersionedPath) { ATLTRACE(_T("%s is not underversion control\n"), path.GetWinPath()); return CStatusCacheEntry(); } // We've not got this item in the cache - let's add it // We never bother asking SVN for the status of just one file, always for its containing directory if (g_GitAdminDir.IsAdminDirPath(path.GetWinPathString())) { // We're being asked for the status of an .git directory // It's not worth asking for this return CStatusCacheEntry(); } if(bFetch) { return GetStatusFromGit(path, sProjectRoot); } else { return GetStatusFromCache(path, bRecursive); } }
void CFolderCrawler::AddPathForUpdate(const CTGitPath& path) { /* Index file changing*/ if( GitStatus::IsExistIndexLockFile((CString&)path.GetWinPathString())) return; if (!CGitStatusCache::Instance().IsPathGood(path)) return; { AutoLocker lock(m_critSec); RemoveDuplicate(m_pathsToUpdate, path); m_pathsToUpdate.push_back(path); m_pathsToUpdate.back().SetCustomData(GetTickCount()+1000); m_bPathsAddedSinceLastCrawl = true; } //if (SetHoldoff()) SetEvent(m_hWakeEvent); }
int CGitDiff::DiffCommit(const CTGitPath &path1, const CTGitPath &path2, const CString &r1, const CString &r2) { if (path1.GetWinPathString().IsEmpty()) { CFileDiffDlg dlg; dlg.SetDiff(NULL, r1, r2); dlg.DoModal(); } else if (path1.IsDirectory()) { CFileDiffDlg dlg; dlg.SetDiff(&path1, r1, r2); dlg.DoModal(); } else { Diff(&path1, &path2, r1, r2); } return 0; }
int CGitDiff::DiffCommit(CTGitPath &path, CString r1, CString r2) { if (path.GetWinPathString().IsEmpty()) { CFileDiffDlg dlg; dlg.SetDiff(NULL,r1,r2); dlg.DoModal(); } else if (path.IsDirectory()) { CFileDiffDlg dlg; dlg.SetDiff(&path,r1,r2); dlg.DoModal(); } else { Diff(&path,&path,r1,r2); } return 0; }
int CGitDiff::DiffCommit(const CTGitPath &path1, const CTGitPath &path2, const GitRev *r1, const GitRev *r2) { if (path1.GetWinPathString().IsEmpty()) { CFileDiffDlg dlg; dlg.SetDiff(NULL, *r1, *r2); dlg.DoModal(); } else if (path1.IsDirectory()) { CFileDiffDlg dlg; dlg.SetDiff(&path1, *r1, *r2); dlg.DoModal(); } else { Diff(&path1, &path2, r1->m_CommitHash.ToString(), r2->m_CommitHash.ToString()); } return 0; }
int CSendMailPatch::SendAsSingleMail(CTGitPath &path, CGitProgressList * instance) { ASSERT(instance); CString pathfile(path.GetWinPathString()); CPatch patch; if (patch.Parse(pathfile)) { instance->ReportError(_T("Could not open/parse ") + pathfile); return -2; } CString body; CStringArray attachments; if (m_bAttachment) attachments.Add(pathfile); else body = patch.m_strBody; return SendMail(path, instance, m_sSenderName, m_sSenderMail, m_sTo, m_sCC, patch.m_Subject, body, attachments); }
void CFolderCrawler::AddDirectoryForUpdate(const CTGitPath& path) { /* Index file changing*/ if( GitStatus::IsExistIndexLockFile((CString&)path.GetWinPathString())) return; if (!CGitStatusCache::Instance().IsPathGood(path)) return; { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": AddDirectoryForUpdate %s\n", path.GetWinPath()); AutoLocker lock(m_critSec); m_foldersToUpdate.Push(path); //ATLASSERT(path.IsDirectory() || !path.Exists()); // set this flag while we are sync'ed // with the worker thread m_bItemsAddedSinceLastCrawl = true; } //if (SetHoldoff()) SetEvent(m_hWakeEvent); }
bool CloneCommand::Execute() { CTGitPath cloneDirectory; if (!parser.HasKey(_T("hasurlhandler"))) { if (orgCmdLinePath.IsEmpty()) { cloneDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> tszPath(new TCHAR[len]); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(cloneDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. cloneDirectory.Reset(); } } else cloneDirectory = orgCmdLinePath; } CCloneDlg dlg; dlg.m_Directory = cloneDirectory.GetWinPathString(); if (parser.HasKey(_T("url"))) dlg.m_URL = parser.GetVal(_T("url")); if (parser.HasKey(_T("exactpath"))) dlg.m_bExactPath = TRUE; if(dlg.DoModal()==IDOK) { CString recursiveStr; if(dlg.m_bRecursive) recursiveStr = _T("--recursive"); else recursiveStr = _T(""); CString bareStr; if(dlg.m_bBare) bareStr = _T("--bare"); else bareStr = _T(""); CString nocheckoutStr; if (dlg.m_bNoCheckout) nocheckoutStr = _T("--no-checkout"); CString branchStr; if (dlg.m_bBranch) branchStr = _T("--branch ") + dlg.m_strBranch; CString originStr; if (dlg.m_bOrigin) originStr = _T("--origin ") + dlg.m_strOrigin; if(dlg.m_bAutoloadPuttyKeyFile) { CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); } CAppUtils::RemoveTrailSlash(dlg.m_Directory); if (!dlg.m_bSVN) CAppUtils::RemoveTrailSlash(dlg.m_URL); CString dir=dlg.m_Directory; CString url=dlg.m_URL; // is this a windows format UNC path, ie starts with \\? if (url.Find(_T("\\\\")) == 0) { // yes, change all \ to / // this should not be necessary but msysgit does not support the use \ here yet int atSign = url.Find(_T('@')); if (atSign > 0) { CString path = url.Mid(atSign); path.Replace(_T('\\'), _T('/')); url = url.Mid(0, atSign) + path; } else url.Replace( _T('\\'), _T('/')); } CString depth; if (dlg.m_bDepth) { depth.Format(_T(" --depth %d"),dlg.m_nDepth); } g_Git.m_CurrentDir = GetExistingDirectoryForClone(dlg.m_Directory); CString cmd; CString progressarg; int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070002) //above 1.7.0.2 progressarg = _T("--progress"); cmd.Format(_T("git.exe clone %s %s %s %s %s %s -v %s \"%s\" \"%s\""), nocheckoutStr, recursiveStr, bareStr, branchStr, originStr, progressarg, depth, url, dir); // Handle Git SVN-clone if(dlg.m_bSVN) { //g_Git.m_CurrentDir=dlg.m_Directory; cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""), url,dlg.m_Directory); if(dlg.m_bSVNTrunk) cmd+=_T(" -T ")+dlg.m_strSVNTrunk; if(dlg.m_bSVNBranch) cmd+=_T(" -b ")+dlg.m_strSVNBranchs; if(dlg.m_bSVNTags) cmd+=_T(" -t ")+dlg.m_strSVNTags; if(dlg.m_bSVNFrom) { CString str; str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom); cmd+=_T(" -r ")+str; } if(dlg.m_bSVNUserName) { cmd+= _T(" --username "); cmd+=dlg.m_strUserName; } } else { if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE)) { CGitProgressDlg GitDlg; CTGitPathList list; g_Git.m_CurrentDir = dir; list.AddPath(CTGitPath(dir)); GitDlg.SetCommand(CGitProgressList::GitProgress_Clone); GitDlg.SetUrl(url); GitDlg.SetPathList(list); GitDlg.SetIsBare(!!dlg.m_bBare); GitDlg.SetRefSpec(dlg.m_bBranch ? dlg.m_strBranch : CString()); GitDlg.SetRemote(dlg.m_bOrigin ? dlg.m_strOrigin : CString()); GitDlg.SetNoCheckout(!!dlg.m_bNoCheckout); GitDlg.DoModal(); return !GitDlg.DidErrorsOccur(); } } CProgressDlg progress; progress.m_GitCmd=cmd; progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENULOG))); progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_EXPLORE))); INT_PTR ret = progress.DoModal(); if (dlg.m_bSVN) ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command")); if( progress.m_GitStatus == 0) { if(dlg.m_bAutoloadPuttyKeyFile) { g_Git.m_CurrentDir = dlg.m_Directory; SetCurrentDirectory(g_Git.m_CurrentDir); if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL, CP_UTF8)) { CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR); return FALSE; } } if (ret == IDC_PROGRESS_BUTTON1) { CString cmd = _T("/command:log"); cmd += _T(" /path:\"") + dlg.m_Directory + _T("\""); CAppUtils::RunTortoiseGitProc(cmd); return TRUE; } if (ret == IDC_PROGRESS_BUTTON1 + 1) { ShellExecute(nullptr, _T("explore"), dlg.m_Directory, nullptr, nullptr, SW_SHOW); return TRUE; } } if(ret == IDOK) return TRUE; } return FALSE; }