Fixed issue #2495: "Show Reflog" dialog shows empty action for "push" entries
[TortoiseGit.git] / src / Git / GitRevRefBrowser.cpp
blob75d354883d2dc5f0ab430687f4fe68b22ec8190e
2 // TortoiseGit - a Windows shell extension for easy version control
4 // Copyright (C) 2009-2015 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #pragma once
22 #include "stdafx.h"
23 #include "gittype.h"
24 #include "Git.h"
25 #include "GitRevRefBrowser.h"
27 GitRevRefBrowser::GitRevRefBrowser()
29 GitRev();
32 void GitRevRefBrowser::Clear()
34 GitRev::Clear();
35 m_Description.Empty();
36 m_UpstreamRef.Empty();
39 int GitRevRefBrowser::GetGitRevRefMap(MAP_REF_GITREVREFBROWSER& map, CString& err, std::function<bool(const CString& refName)> filterCallback)
41 err.Empty();
42 MAP_STRING_STRING descriptions;
43 g_Git.GetBranchDescriptions(descriptions);
45 CString allRefs;
46 if (g_Git.Run(L"git.exe for-each-ref --format=\"%(refname)%04 %(objectname)%04 %(upstream)%04 %(subject)%04 %(authorname)%04%(authordate:raw)%03\"", &allRefs, &err, CP_UTF8))
47 return -1;
49 int linePos = 0;
50 CString singleRef;
51 while (!(singleRef = allRefs.Tokenize(L"\03", linePos)).IsEmpty())
53 singleRef.TrimLeft(L"\r\n");
54 int valuePos = 0;
55 CString refName = singleRef.Tokenize(L"\04", valuePos);
57 if (refName.IsEmpty() || (filterCallback && !filterCallback(refName)))
58 continue;
60 GitRevRefBrowser ref;
61 ref.m_CommitHash = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
62 ref.m_UpstreamRef = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
63 ref.m_Subject = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
64 ref.m_AuthorName = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
65 CString date = singleRef.Tokenize(L"\04", valuePos).Trim();
66 ref.m_AuthorDate = StrToInt(date);
68 if (wcsncmp(refName, L"refs/heads/", 11) == 0)
69 ref.m_Description = descriptions[refName.Mid(11)];
71 map.insert(std::make_pair(refName, ref));
74 return 0;