From feb015c9ab9109e19c77dbb8bc213588c778009f Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Mon, 1 Sep 2014 23:44:53 +0800 Subject: [PATCH] Use libgit2 to list remote tags Signed-off-by: Sup Yut Sum --- src/Git/Git.cpp | 37 ++++++++++++++++++++++++++++++++- src/Git/Git.h | 3 ++- src/TortoiseProc/DeleteRemoteTagDlg.cpp | 6 ++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index ed4d6c55d..229c38467 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -1684,8 +1684,43 @@ int CGit::GetRemoteList(STRING_VECTOR &list) } } -int CGit::GetRemoteTags(const CString& remote, STRING_VECTOR &list) +int CGit::GetRemoteTags(const CString& remote, STRING_VECTOR &list, git_remote_callbacks* callback) { + if (UsingLibGit2(GIT_CMD_FETCH)) + { + CAutoRepository repo(GetGitRepository()); + if (!repo) + return -1; + + CStringA remoteA = CUnicodeUtils::GetUTF8(remote); + CAutoRemote remote; + if (git_remote_load(remote.GetPointer(), repo, remoteA) < 0) + return -1; + + git_remote_set_callbacks(remote, callback); + if (git_remote_connect(remote, GIT_DIRECTION_FETCH) < 0) + return -1; + + const git_remote_head** heads = nullptr; + size_t size = 0; + if (git_remote_ls(&heads, &size, remote) < 0) + return -1; + + for (int i = 0; i < size; i++) + { + CString ref = CUnicodeUtils::GetUnicode(heads[i]->name); + CString shortname; + if (!GetShortName(ref, shortname, _T("refs/tags/"))) + continue; + // dot not include annotated tags twice; this works, because an annotated tag appears twice (one normal tag and one with ^{} at the end) + if (shortname.Find(_T("^{}")) >= 1) + continue; + list.push_back(shortname); + } + std::sort(list.begin(), list.end(), g_bSortTagsReversed ? LogicalCompareReversedPredicate : LogicalComparePredicate); + return 0; + } + CString cmd, out, err; cmd.Format(_T("git.exe ls-remote -t \"%s\""), remote); if (Run(cmd, &out, &err, CP_UTF8)) diff --git a/src/Git/Git.h b/src/Git/Git.h index d215e9dd6..d6bb66646 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -29,6 +29,7 @@ #define REG_MSYSGIT_EXTRA_PATH _T("Software\\TortoiseGit\\MSysGitExtra") struct git_repository; +struct git_remote_callbacks; class CFilterData { @@ -311,7 +312,7 @@ public: int GetRemoteList(STRING_VECTOR &list); int GetBranchList(STRING_VECTOR &list, int *Current,BRANCH_TYPE type=BRANCH_LOCAL); int GetTagList(STRING_VECTOR &list); - int GetRemoteTags(const CString& remote, STRING_VECTOR &list); + int GetRemoteTags(const CString& remote, STRING_VECTOR &list, git_remote_callbacks* callback = nullptr); int GetMapHashToFriendName(MAP_HASH_NAME &map); static int GetMapHashToFriendName(git_repository* repo, MAP_HASH_NAME &map); diff --git a/src/TortoiseProc/DeleteRemoteTagDlg.cpp b/src/TortoiseProc/DeleteRemoteTagDlg.cpp index 327c6448a..9db8f0f9d 100644 --- a/src/TortoiseProc/DeleteRemoteTagDlg.cpp +++ b/src/TortoiseProc/DeleteRemoteTagDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2012-2013 - TortoiseGit +// Copyright (C) 2012-2014 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -93,7 +93,9 @@ void CDeleteRemoteTagDlg::Refresh() sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModal(this, true); - g_Git.GetRemoteTags(m_sRemote, m_taglist); + git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; + callbacks.credentials = CAppUtils::Git2GetUserPassword; + g_Git.GetRemoteTags(m_sRemote, m_taglist, &callbacks); sysProgressDlg.Stop(); BringWindowToTop(); -- 2.11.4.GIT