From a2463a853f200244885be73ffaa97a16dc40d565 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 11 Jan 2014 01:57:42 +0100 Subject: [PATCH] Avoid CString.GetBuffer() and make use of default (LPCTSTR) operator Thereby we can avoid lots of ReleaseBuffer() calls. Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 65 ++++++---------------- src/Git/Git.h | 1 - src/Git/GitIndex.cpp | 28 ++++------ src/Git/GitStatus.cpp | 44 ++++++--------- src/TortoiseMerge/MainFrm.cpp | 9 +-- src/TortoiseProc/AppUtils.cpp | 6 +- src/TortoiseProc/CheckForUpdatesDlg.cpp | 4 +- .../Commands/CreateRepositoryCommand.cpp | 6 +- src/TortoiseProc/CommitDlg.cpp | 20 ++----- src/TortoiseProc/GitProgressList.cpp | 12 ++-- src/TortoiseProc/GitRefCompareList.cpp | 5 +- src/TortoiseProc/ProjectProperties.cpp | 12 +--- src/TortoiseProc/Settings/SettingGitCredential.cpp | 1 - src/TortoiseProc/TortoiseProc.cpp | 2 +- src/TortoiseShell/GITPropertyPage.cpp | 15 ++--- 15 files changed, 71 insertions(+), 159 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 1941c6fd3..be4c30e6d 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -498,7 +498,7 @@ CString CGit::GetConfigValue(const CString& name, int encoding, BOOL RemoveCR) try { - if (git_get_config(key.GetBuffer(), value.GetBufferSetLength(4096), 4096)) + if (git_get_config(key, value.GetBufferSetLength(4096), 4096)) return CString(); } catch (const char *msg) @@ -507,7 +507,7 @@ CString CGit::GetConfigValue(const CString& name, int encoding, BOOL RemoveCR) return CString(); } - StringAppend(&configValue,(BYTE*)value.GetBuffer(),encoding); + StringAppend(&configValue, (BYTE*)(LPCSTR)value, encoding); if(RemoveCR) return configValue.Tokenize(_T("\n"),start); return configValue; @@ -553,7 +553,7 @@ int CGit::SetConfigValue(const CString& key, const CString& value, CONFIG_TYPE t try { - return get_set_config(keya.GetBuffer(), valuea.GetBuffer(), type); + return get_set_config(keya, valuea, type); } catch (const char *msg) { @@ -603,7 +603,7 @@ int CGit::UnsetConfigValue(const CString& key, CONFIG_TYPE type, int encoding) try { - return get_set_config(keya.GetBuffer(), nullptr, type); + return get_set_config(keya, nullptr, type); } catch (const char *msg) { @@ -1095,12 +1095,8 @@ int CGit::GetHash(CGitHash &hash, const TCHAR* friendname) { git_repository *repo = NULL; CStringA gitdirA = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdirA.GetBuffer())) - { - gitdirA.ReleaseBuffer(); + if (git_repository_open(&repo, gitdirA)) return -1; - } - gitdirA.ReleaseBuffer(); int isHeadOrphan = git_repository_head_unborn(repo); if (isHeadOrphan != 0) @@ -1116,13 +1112,11 @@ int CGit::GetHash(CGitHash &hash, const TCHAR* friendname) CStringA refnameA = CUnicodeUtils::GetMulti(friendname, CP_UTF8); git_object * gitObject = NULL; - if (git_revparse_single(&gitObject, repo, refnameA.GetBuffer())) + if (git_revparse_single(&gitObject, repo, refnameA)) { - refnameA.ReleaseBuffer(); git_repository_free(repo); return -1; } - refnameA.ReleaseBuffer(); const git_oid * oid = git_object_id(gitObject); if (oid == NULL) @@ -1211,12 +1205,8 @@ int CGit::GetTagList(STRING_VECTOR &list) git_repository *repo = NULL; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdir.GetBuffer())) - { - gitdir.ReleaseBuffer(); + if (git_repository_open(&repo, gitdir)) return -1; - } - gitdir.ReleaseBuffer(); git_strarray tag_names; @@ -1471,12 +1461,8 @@ int CGit::GetRemoteList(STRING_VECTOR &list) git_repository *repo = NULL; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdir.GetBuffer())) - { - gitdir.ReleaseBuffer(); + if (git_repository_open(&repo, gitdir)) return -1; - } - gitdir.ReleaseBuffer(); git_strarray remotes; @@ -1561,12 +1547,8 @@ int CGit::GetRefList(STRING_VECTOR &list) git_repository *repo = NULL; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdir.GetBuffer())) - { - gitdir.ReleaseBuffer(); + if (git_repository_open(&repo, gitdir)) return -1; - } - gitdir.ReleaseBuffer(); if (git_reference_foreach(repo, libgit2_addto_list_each_ref_fn, &list)) { @@ -1665,12 +1647,8 @@ int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map) git_repository *repo = NULL; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdir.GetBuffer())) - { - gitdir.ReleaseBuffer(); + if (git_repository_open(&repo, gitdir)) return -1; - } - gitdir.ReleaseBuffer(); map_each_ref_payload payloadContent = { repo, &map }; @@ -1721,15 +1699,13 @@ int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map) static void SetLibGit2SearchPath(int level, const CString &value) { CStringA valueA = CUnicodeUtils::GetMulti(value, CP_UTF8); - git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, valueA.GetBuffer()); - valueA.ReleaseBuffer(); + git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, valueA); } static void SetLibGit2TemplatePath(const CString &value) { CStringA valueA = CUnicodeUtils::GetMulti(value, CP_UTF8); - git_libgit2_opts(GIT_OPT_SET_TEMPLATE_PATH, valueA.GetBuffer()); - valueA.ReleaseBuffer(); + git_libgit2_opts(GIT_OPT_SET_TEMPLATE_PATH, valueA); } BOOL CGit::CheckMsysGitDir(BOOL bFallback) @@ -1750,8 +1726,7 @@ BOOL CGit::CheckMsysGitDir(BOOL bFallback) if (!homesize) { CString home = GetHomeDirectory(); - m_Environment.SetEnv(_T("HOME"), home.GetBuffer()); - home.ReleaseBuffer(); + m_Environment.SetEnv(_T("HOME"), home); } CString str; @@ -1762,8 +1737,8 @@ BOOL CGit::CheckMsysGitDir(BOOL bFallback) if(!sshclient.IsEmpty()) { - m_Environment.SetEnv(_T("GIT_SSH"), sshclient.GetBuffer()); - m_Environment.SetEnv(_T("SVN_SSH"), sshclient.GetBuffer()); + m_Environment.SetEnv(_T("GIT_SSH"), sshclient); + m_Environment.SetEnv(_T("SVN_SSH"), sshclient); } else { @@ -1856,7 +1831,7 @@ BOOL CGit::CheckMsysGitDir(BOOL bFallback) CString path; path.Format(_T("%s;%s"),oldpath,str + _T(";")+ (CString)CRegString(REG_MSYSGIT_EXTRA_PATH,_T(""),FALSE)); - m_Environment.SetEnv(_T("PATH"),path.GetBuffer()); + m_Environment.SetEnv(_T("PATH"), path); CString str1 = m_Environment.GetEnv(_T("PATH")); @@ -2095,7 +2070,7 @@ int CGit::GetOneFile(const CString &Refname, const CTGitPath &path, const CStrin patha = CUnicodeUtils::GetMulti(path.GetGitPathString(), CP_UTF8); outa = CUnicodeUtils::GetMulti(outputfile, CP_UTF8); ::DeleteFile(outputfile); - return git_checkout_file((const char*)ref.GetBuffer(),(const char*)patha.GetBuffer(),(const char*)outa.GetBuffer()); + return git_checkout_file(ref, patha, outa); }catch(...) { @@ -2426,12 +2401,8 @@ static int GetUnifiedDiffLibGit2(const CTGitPath& /*path*/, const git_revnum_t& CStringA tree2 = CUnicodeUtils::GetMulti(rev2, CP_UTF8); int ret = 0; - if (git_repository_open(&repo, gitdirA.GetBuffer())) - { - gitdirA.ReleaseBuffer(); + if (git_repository_open(&repo, gitdirA)) return -1; - } - gitdirA.ReleaseBuffer(); int isHeadOrphan = git_repository_head_unborn(repo); if (isHeadOrphan != 0) diff --git a/src/Git/Git.h b/src/Git/Git.h index 2f64ee8e9..1e0a247cb 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -291,7 +291,6 @@ public: CString GetLogCmd(const CString &range, const CTGitPath *path = NULL, int count=-1, int InfoMask = LOG_INFO_FULL_DIFF|LOG_INFO_STAT|LOG_INFO_FILESTATE|LOG_INFO_BOUNDARY|LOG_INFO_DETECT_COPYRENAME|LOG_INFO_SHOW_MERGEDFILE, bool paramonly=false, CFilterData * filter =NULL); int GetHash(CGitHash &hash, const TCHAR* friendname); - int GetHash(CGitHash &hash, CString ref) { return GetHash(hash, ref.GetBuffer()); } int BuildOutputFormat(CString &format,bool IsFull=TRUE); //int GetShortLog(const CString &log,CTGitPath * path=NULL, int count =-1); diff --git a/src/Git/GitIndex.cpp b/src/Git/GitIndex.cpp index 02ca9f5b3..8e6730207 100644 --- a/src/Git/GitIndex.cpp +++ b/src/Git/GitIndex.cpp @@ -114,9 +114,7 @@ int CGitIndexList::ReadIndex(CString dgitdir) } git_index *index = NULL; - int ret = git_repository_open(&repository, gitdir.GetBuffer()); - gitdir.ReleaseBuffer(); - if (ret) + if (git_repository_open(&repository, gitdir)) { m_critRepoSec.Unlock(); return -1; @@ -181,8 +179,7 @@ int CGitIndexList::GetFileStatus(const CString &gitdir, const CString &pathorg, CString path = pathorg; path.MakeLower(); - int start = SearchInSortVector(*this, ((CString&)path).GetBuffer(), -1); - ((CString&)path).ReleaseBuffer(); + int start = SearchInSortVector(*this, path, -1); if (start < 0) { @@ -219,14 +216,13 @@ int CGitIndexList::GetFileStatus(const CString &gitdir, const CString &pathorg, git_oid actual; CStringA fileA = CUnicodeUtils::GetMulti(pathorg, CP_UTF8); m_critRepoSec.Lock(); // prevent concurrent access to repository instance and especially filter-lists - if (!git_repository_hashfile(&actual, repository, fileA.GetBuffer(), GIT_OBJ_BLOB, NULL) && !git_oid_cmp(&actual, (const git_oid*)at(index).m_IndexHash.m_hash)) + if (!git_repository_hashfile(&actual, repository, fileA, GIT_OBJ_BLOB, NULL) && !git_oid_cmp(&actual, (const git_oid*)at(index).m_IndexHash.m_hash)) { at(index).m_ModifyTime = time; *status = git_wc_status_normal; } else *status = git_wc_status_modified; - fileA.ReleaseBuffer(); m_critRepoSec.Unlock(); } else @@ -456,10 +452,9 @@ int CGitIndexFileMap::IsUnderVersionControl(const CString &gitdir, const CString if(pIndex.get()) { if(isDir) - *isVersion = (SearchInSortVector(*pIndex, subpath.GetBuffer(), subpath.GetLength()) >= 0); + *isVersion = (SearchInSortVector(*pIndex, subpath, subpath.GetLength()) >= 0); else - *isVersion = (SearchInSortVector(*pIndex, subpath.GetBuffer(), -1) >= 0); - subpath.ReleaseBuffer(); + *isVersion = (SearchInSortVector(*pIndex, subpath, -1) >= 0); } }catch(...) @@ -873,8 +868,7 @@ int CGitHeadFileList::ReadTree() ATLASSERT(this->empty()); do { - ret = git_repository_open(&repository, gitdir.GetBuffer()); - gitdir.ReleaseBuffer(); + ret = git_repository_open(&repository, gitdir); if(ret) break; ret = git_commit_lookup(&commit, repository, (const git_oid*)m_Head.m_hash); @@ -989,7 +983,7 @@ int CGitIgnoreItem::FetchIgnoreList(const CString &projectroot, const CString &f if(p[0] != '#' && p[0] != 0) git_add_exclude((const char*)p, - this->m_BaseDir.GetBuffer(), + this->m_BaseDir, m_BaseDir.GetLength(), this->m_pExcludeList, ++line); @@ -1229,8 +1223,7 @@ bool CGitIgnoreList::CheckAndUpdateCoreExcludefile(const CString &adminDir) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(systemConfig), GIT_CONFIG_LEVEL_SYSTEM, FALSE); const char * out = NULL; CStringA name(_T("core.excludesfile")); - git_config_get_string(&out, config, name.GetBuffer()); - name.ReleaseBuffer(); + git_config_get_string(&out, config, name); CStringA excludesFileA(out); excludesFile = CUnicodeUtils::GetUnicode(excludesFileA); if (excludesFile.IsEmpty()) @@ -1442,10 +1435,9 @@ int CGitHeadFileMap::IsUnderVersionControl(const CString &gitdir, const CString } if(isDir) - *isVersion = (SearchInSortVector(*treeptr, subpath.GetBuffer(), subpath.GetLength()) >= 0); + *isVersion = (SearchInSortVector(*treeptr, subpath, subpath.GetLength()) >= 0); else - *isVersion = (SearchInSortVector(*treeptr, subpath.GetBuffer(), -1) >= 0); - subpath.ReleaseBuffer(); + *isVersion = (SearchInSortVector(*treeptr, subpath, -1) >= 0); } catch(...) { diff --git a/src/Git/GitStatus.cpp b/src/Git/GitStatus.cpp index a583cdc14..ba18f9adc 100644 --- a/src/Git/GitStatus.cpp +++ b/src/Git/GitStatus.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2013 - TortoiseGit +// Copyright (C) 2008-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -415,8 +415,7 @@ int GitStatus::GetFileStatus(const CString &gitdir, const CString &pathParam, gi { //add item - int start =SearchInSortVector(*treeptr,lowcasepath.GetBuffer(),-1); - lowcasepath.ReleaseBuffer(); + int start = SearchInSortVector(*treeptr, lowcasepath, -1); if(start<0) { @@ -618,13 +617,11 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ if (!onepath.IsEmpty() && onepath[onepath.GetLength() - 1] == _T('/')) bIsDir = true; - LPTSTR onepathBuffer = onepath.GetBuffer(); int matchLength = -1; if (bIsDir) matchLength = onepath.GetLength(); - int pos = SearchInSortVector(*indexptr, onepathBuffer, matchLength); - int posintree = SearchInSortVector(*treeptr, onepathBuffer, matchLength); - onepath.ReleaseBuffer(); + int pos = SearchInSortVector(*indexptr, onepath, matchLength); + int posintree = SearchInSortVector(*treeptr, onepath, matchLength); if(pos <0 && posintree<0) { @@ -698,12 +695,11 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ }/*End of For*/ /* Check deleted file in system */ - LPTSTR lowcasepathBuffer = lowcasepath.GetBuffer(); int start=0, end=0; - int pos = SearchInSortVector(*indexptr, lowcasepathBuffer, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash + int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash std::map skipWorktreeMap; - if (GetRangeInSortVector(*indexptr, lowcasepathBuffer, lowcasepath.GetLength(), &start, &end, pos) == 0) + if (GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) { CGitIndexList::iterator it; CString oldstring; @@ -721,7 +717,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ if(oldstring != filename) { oldstring = filename; - if(SearchInSortVector(filelist, filename.GetBuffer(), filename.GetLength())<0) + if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) { bool skipWorktree = false; *status = git_wc_status_deleted; @@ -739,8 +735,8 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ } start = end =0; - pos = SearchInSortVector(*treeptr, lowcasepathBuffer, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash - if (GetRangeInSortVector(*treeptr, lowcasepathBuffer, lowcasepath.GetLength(), &start, &end, pos) == 0) + pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash + if (GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) { CGitHeadFileList::iterator it; CString oldstring; @@ -758,7 +754,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ if (oldstring != filename && skipWorktreeMap[filename] != true) { oldstring = filename; - if(SearchInSortVector(filelist, filename.GetBuffer(), filename.GetLength())<0) + if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) { *status = git_wc_status_deleted; if(callback) @@ -767,7 +763,6 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ } } } - lowcasepath.ReleaseBuffer(); }/*End of if status*/ }catch(...) @@ -803,8 +798,7 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w return 0; } - int pos=SearchInSortVector(*indexptr,lowcasepath.GetBuffer(),lowcasepath.GetLength()); - lowcasepath.ReleaseBuffer(); + int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); //Not In Version Contorl if(pos<0) @@ -846,9 +840,7 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w start=0; end = (int)indexptr->size() - 1; } - LPTSTR lowcasepathBuffer = lowcasepath.GetBuffer(); - GetRangeInSortVector(*indexptr, lowcasepathBuffer, lowcasepath.GetLength(), &start, &end, pos); - lowcasepath.ReleaseBuffer(); + GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos); CGitIndexList::iterator it; it = indexptr->begin()+start; @@ -889,8 +881,7 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w { for (int i = start; i<= end; ++i) { - pos =SearchInSortVector(*treeptr, (*it).m_FileName.GetBuffer(), -1); - (*it).m_FileName.ReleaseBuffer(); + pos = SearchInSortVector(*treeptr, (*it).m_FileName, -1); if(pos < 0) { @@ -926,7 +917,7 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w //Check Delete if( *status == git_wc_status_normal ) { - pos = SearchInSortVector(*treeptr, lowcasepathBuffer, lowcasepath.GetLength()); + pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); if(pos <0) { *status = max(git_wc_status_added, *status); // added file found @@ -935,19 +926,17 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w else { int hstart,hend; - GetRangeInSortVector(*treeptr, lowcasepathBuffer, lowcasepath.GetLength(), &hstart, &hend, pos); + GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &hstart, &hend, pos); CGitHeadFileList::iterator hit; hit = treeptr->begin() + hstart; CGitHeadFileList::iterator lastElement = treeptr->end(); for (int i = hstart; i <= hend && hit != lastElement; ++i) { - if( SearchInSortVector(*indexptr,(*hit).m_FileName.GetBuffer(),-1) < 0) + if (SearchInSortVector(*indexptr, (*hit).m_FileName, -1) < 0) { - (*hit).m_FileName.ReleaseBuffer(); *status = max(git_wc_status_deleted, *status); // deleted file found break; } - (*hit).m_FileName.ReleaseBuffer(); ++hit; } } @@ -955,7 +944,6 @@ int GitStatus::GetDirStatus(const CString &gitdir, const CString &subpath, git_w } }/* End lock*/ } - lowcasepath.ReleaseBuffer(); // If define callback, it need update each file status. // If not define callback, status == git_wc_status_conflicted, needn't check each file status // because git_wc_status_conflicted is highest.s diff --git a/src/TortoiseMerge/MainFrm.cpp b/src/TortoiseMerge/MainFrm.cpp index 8e841a69c..c2511878a 100644 --- a/src/TortoiseMerge/MainFrm.cpp +++ b/src/TortoiseMerge/MainFrm.cpp @@ -1658,19 +1658,14 @@ bool CMainFrame::FileSave(bool bCheckResolved /*=true*/) bool hasConflictInIndex = false; do { - if (git_repository_open(&repository, gitdir.GetBuffer())) - { - gitdir.ReleaseBuffer(); + if (git_repository_open(&repository, gitdir)) break; - } - gitdir.ReleaseBuffer(); if (git_repository_index(&index, repository)) break; CStringA path = CUnicodeUtils::GetMulti(subpath, CP_UTF8); - const git_index_entry * entry = git_index_get_bypath(index, path.GetBuffer(), 1); - path.ReleaseBuffer(); + const git_index_entry * entry = git_index_get_bypath(index, path, 1); hasConflictInIndex = entry != nullptr; } while(0); diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 57209f564..8def0fa9e 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -1263,8 +1263,7 @@ bool CAppUtils::OpenIgnoreFile(CIgnoreFile &file, const CString& filename) if (lastchar[0] != '\n') { CStringA eol = CStringA(file.m_eol.IsEmpty() ? _T("\n") : file.m_eol); - file.Write(eol.GetBuffer(), eol.GetLength()); - eol.ReleaseBuffer(); + file.Write(eol, eol.GetLength()); } } else @@ -1342,8 +1341,7 @@ bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask) file.m_Items.push_back(ignorePattern); ignorePattern += file.m_eol.IsEmpty() ? _T("\n") : file.m_eol; CStringA ignorePatternA = CUnicodeUtils::GetUTF8(ignorePattern); - file.Write(ignorePatternA.GetBuffer(), ignorePatternA.GetLength()); - ignorePatternA.ReleaseBuffer(); + file.Write(ignorePatternA, ignorePatternA.GetLength()); } if (ignoreDlg.m_IgnoreFile == 1) diff --git a/src/TortoiseProc/CheckForUpdatesDlg.cpp b/src/TortoiseProc/CheckForUpdatesDlg.cpp index 3e7c44859..7d6f1eceb 100644 --- a/src/TortoiseProc/CheckForUpdatesDlg.cpp +++ b/src/TortoiseProc/CheckForUpdatesDlg.cpp @@ -641,7 +641,7 @@ void CCheckForUpdatesDlg::FillChangelog(CStdioFile &file) str = CUnicodeUtils::GetUnicode(CStringA(str), CP_UTF8); temp += str + _T("\n"); } - ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast(temp.GetBuffer())); + ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast((LPCTSTR)temp)); } else ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast(_T("Could not load changelog."))); @@ -878,7 +878,7 @@ LRESULT CCheckForUpdatesDlg::OnFillChangelog(WPARAM, LPARAM lParam) { ASSERT(lParam != NULL); - TCHAR * changelog = reinterpret_cast(lParam); + LPCTSTR changelog = reinterpret_cast(lParam); m_cLogMessage.Call(SCI_SETREADONLY, FALSE); m_cLogMessage.SetText(changelog); m_cLogMessage.Call(SCI_SETREADONLY, TRUE); diff --git a/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp b/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp index 2f60fadf7..ad00316f9 100644 --- a/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp +++ b/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2013 - TortoiseGit +// Copyright (C) 2008-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -44,13 +44,11 @@ bool CreateRepositoryCommand::Execute() options.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; options.flags |= dlg.m_bBare ? GIT_REPOSITORY_INIT_BARE : 0; CStringA path(CUnicodeUtils::GetMulti(folder, CP_UTF8)); - if (git_repository_init_ext(&repo, path.GetBuffer(), &options)) + if (git_repository_init_ext(&repo, path, &options)) { - path.ReleaseBuffer(); CMessageBox::Show(hwndExplorer, CGit::GetLibGit2LastErr(_T("Could not initialize a new repository.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); return false; } - path.ReleaseBuffer(); git_repository_free(repo); if (!dlg.m_bBare) diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index 43230e36e..0baadb2fa 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -1,7 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2003-2013 - TortoiseSVN -// Copyright (C) 2008-2013 - TortoiseGit +// Copyright (C) 2008-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -666,13 +666,11 @@ void CCommitDlg::OnOK() { git_repository *repository = nullptr; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repository, gitdir.GetBuffer())) + if (git_repository_open(&repository, gitdir)) { - gitdir.ReleaseBuffer(); CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); break; } - gitdir.ReleaseBuffer(); CGitHash revHash; CString revRef = _T("HEAD"); @@ -753,14 +751,12 @@ void CCommitDlg::OnOK() if (entry->IsDirectory()) { git_submodule *submodule = nullptr; - if (git_submodule_lookup(&submodule, repository, filePathA.GetBuffer())) + if (git_submodule_lookup(&submodule, repository, filePathA)) { - filePathA.ReleaseBuffer(); bAddSuccess = false; CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); break; } - filePathA.ReleaseBuffer(); if (git_submodule_add_to_index(submodule, FALSE)) { bAddSuccess = false; @@ -770,25 +766,21 @@ void CCommitDlg::OnOK() } else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED) { - git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error - filePathA.ReleaseBuffer(); + git_index_remove_bypath(index, filePathA); // ignore error } else { - if (git_index_add_bypath(index, filePathA.GetBuffer())) + if (git_index_add_bypath(index, filePathA)) { - filePathA.ReleaseBuffer(); bAddSuccess = false; CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); break; } - filePathA.ReleaseBuffer(); } if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) { - git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error - filePathA.ReleaseBuffer(); + git_index_remove_bypath(index, filePathA); // ignore error } ++nchecked; diff --git a/src/TortoiseProc/GitProgressList.cpp b/src/TortoiseProc/GitProgressList.cpp index 3a5fbab25..0ca857cb1 100644 --- a/src/TortoiseProc/GitProgressList.cpp +++ b/src/TortoiseProc/GitProgressList.cpp @@ -1694,13 +1694,11 @@ bool CGitProgressList::CmdAdd(CString& sWindowTitle, bool& localoperation) git_index *index; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&repo, gitdir.GetBuffer())) + if (git_repository_open(&repo, gitdir)) { - gitdir.ReleaseBuffer(); ReportGitError(); return false; } - gitdir.ReleaseBuffer(); if (git_repository_index(&index, repo)) { @@ -1718,7 +1716,7 @@ bool CGitProgressList::CmdAdd(CString& sWindowTitle, bool& localoperation) for (m_itemCount = 0; m_itemCount < m_itemCountTotal; ++m_itemCount) { - if (git_index_add_bypath(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[m_itemCount].GetGitPathString(), CP_UTF8)).GetBuffer())) + if (git_index_add_bypath(index, CUnicodeUtils::GetMulti(m_targetPathList[m_itemCount].GetGitPathString(), CP_UTF8))) { ReportGitError(); git_index_free(index); @@ -2136,9 +2134,8 @@ bool CGitProgressList::CmdFetch(CString& sWindowTitle, bool& /*localoperation*/) m_pAnimate->Play(0, INT_MAX, INT_MAX); } - if (git_repository_open(&repo, gitdir.GetBuffer())) + if (git_repository_open(&repo, gitdir)) { - gitdir.ReleaseBuffer(); ReportGitError(); ret = false; break; @@ -2245,9 +2242,8 @@ bool CGitProgressList::CmdReset(CString& sWindowTitle, bool& /*localoperation*/) m_pAnimate->Play(0, INT_MAX, INT_MAX); } - if (git_repository_open(&repo, gitdir.GetBuffer())) + if (git_repository_open(&repo, gitdir)) { - gitdir.ReleaseBuffer(); ReportGitError(); ret = false; break; diff --git a/src/TortoiseProc/GitRefCompareList.cpp b/src/TortoiseProc/GitRefCompareList.cpp index 30b167b09..8453e1e9a 100644 --- a/src/TortoiseProc/GitRefCompareList.cpp +++ b/src/TortoiseProc/GitRefCompareList.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2013 - TortoiseGit +// Copyright (C) 2013-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -85,9 +85,8 @@ int CGitRefCompareList::OpenRepository() { m_Repository = nullptr; CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8); - if (git_repository_open(&m_Repository, gitdir.GetBuffer())) + if (git_repository_open(&m_Repository, gitdir)) { - gitdir.ReleaseBuffer(); CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); return -1; } diff --git a/src/TortoiseProc/ProjectProperties.cpp b/src/TortoiseProc/ProjectProperties.cpp index 096d7fe22..45786efa4 100644 --- a/src/TortoiseProc/ProjectProperties.cpp +++ b/src/TortoiseProc/ProjectProperties.cpp @@ -58,12 +58,8 @@ int ProjectProperties::GetStringProps(CString &prop, const CString &key) CStringA keyA = CUnicodeUtils::GetUTF8(key); const char * value = nullptr; - if (git_config_get_string(&value, gitconfig, keyA.GetBuffer())) - { - keyA.ReleaseBuffer(); + if (git_config_get_string(&value, gitconfig, keyA)) return -1; - } - keyA.ReleaseBuffer(); prop = CUnicodeUtils::GetUnicode(value); @@ -76,12 +72,8 @@ int ProjectProperties::GetBOOLProps(BOOL &b, const CString &key) CStringA keyA = CUnicodeUtils::GetUTF8(key); int value = FALSE; - if (git_config_get_bool(&value, gitconfig, keyA.GetBuffer())) - { - keyA.ReleaseBuffer(); + if (git_config_get_bool(&value, gitconfig, keyA)) return -1; - } - keyA.ReleaseBuffer(); b = value; diff --git a/src/TortoiseProc/Settings/SettingGitCredential.cpp b/src/TortoiseProc/Settings/SettingGitCredential.cpp index 22eabc381..8f012a8eb 100644 --- a/src/TortoiseProc/Settings/SettingGitCredential.cpp +++ b/src/TortoiseProc/Settings/SettingGitCredential.cpp @@ -519,7 +519,6 @@ CString CSettingGitCredential::Load(CString key) const git_config_entry *entry; if (!git_config_get_entry(&entry, config, cmdA)) valueA = CStringA(entry->value); - cmdA.ReleaseBuffer(); git_config_free(config); return CUnicodeUtils::GetUnicode(valueA); diff --git a/src/TortoiseProc/TortoiseProc.cpp b/src/TortoiseProc/TortoiseProc.cpp index 239f6d769..8e1fffc44 100644 --- a/src/TortoiseProc/TortoiseProc.cpp +++ b/src/TortoiseProc/TortoiseProc.cpp @@ -432,7 +432,7 @@ BOOL CTortoiseProcApp::InitInstance() { git_oid oid; CStringA wcRootA(wcroot + CPathUtils::GetAppDirectory()); - if (!git_odb_hash(&oid, wcRootA.GetBuffer(), wcRootA.GetLength(), GIT_OBJ_BLOB)) + if (!git_odb_hash(&oid, wcRootA, wcRootA.GetLength(), GIT_OBJ_BLOB)) { CStringA hash; git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid); diff --git a/src/TortoiseShell/GITPropertyPage.cpp b/src/TortoiseShell/GITPropertyPage.cpp index 215878917..b90010397 100644 --- a/src/TortoiseShell/GITPropertyPage.cpp +++ b/src/TortoiseShell/GITPropertyPage.cpp @@ -123,9 +123,7 @@ BOOL CGitPropertyPage::PageProc (HWND /*hwnd*/, UINT uMessage, WPARAM wParam, LP git_repository *repository = NULL; git_index *index = NULL; - int ret = git_repository_open(&repository, gitdir.GetBuffer()); - gitdir.ReleaseBuffer(); - if (ret) + if (git_repository_open(&repository, gitdir)) break; if (git_repository_index(&index, repository)) @@ -357,7 +355,7 @@ static git_commit * FindFileRecentCommit(git_repository *repository, CString pat return NULL; CStringA pathA = CUnicodeUtils::GetUTF8(path); - const char *pathC = pathA.GetBuffer(); + const char *pathC = pathA; char folder[MAX_PATH] = {0}, file[MAX_PATH] = {0}; const char *slash = strrchr(pathC, '/'); if (slash) @@ -371,7 +369,6 @@ static git_commit * FindFileRecentCommit(git_repository *repository, CString pat folder[0] = '\0'; strcpy(file, pathC); } - pathA.ReleaseBuffer(); TreewalkStruct treewalkstruct = { folder, file }; TreewalkStruct treewalkstruct2 = { folder, file }; @@ -515,9 +512,7 @@ int CGitPropertyPage::LogThread() CStringA gitdir = CUnicodeUtils::GetMulti(ProjectTopDir, CP_UTF8); git_repository *repository = NULL; - int ret = git_repository_open(&repository, gitdir.GetBuffer()); - gitdir.ReleaseBuffer(); - if (ret) + if (git_repository_open(&repository, gitdir)) return 0; int stripLength = ProjectTopDir.GetLength(); @@ -569,9 +564,7 @@ void CGitPropertyPage::InitWorkfileView() CStringA gitdir = CUnicodeUtils::GetMulti(ProjectTopDir, CP_UTF8); git_repository *repository = NULL; - int ret = git_repository_open(&repository, gitdir.GetBuffer()); - gitdir.ReleaseBuffer(); - if (ret) + if (git_repository_open(&repository, gitdir)) return; CString username; -- 2.11.4.GIT