Keep the font size of 8 for the explorer property page
[TortoiseGit.git] / src / Git / GitRevRefBrowser.cpp
blobf8b731e4a51c7c5ce65e9a451ae8f634451ffcbd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2018 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "stdafx.h"
22 #include "gittype.h"
23 #include "Git.h"
24 #include "GitRevRefBrowser.h"
25 #include "StringUtils.h"
27 GitRevRefBrowser::GitRevRefBrowser() : GitRev()
31 void GitRevRefBrowser::Clear()
33 GitRev::Clear();
34 m_Description.Empty();
35 m_UpstreamRef.Empty();
38 int GitRevRefBrowser::GetGitRevRefMap(MAP_REF_GITREVREFBROWSER& map, int mergefilter, CString& err, std::function<bool(const CString& refName)> filterCallback)
40 err.Empty();
41 MAP_STRING_STRING descriptions;
42 g_Git.GetBranchDescriptions(descriptions);
44 CString args;
45 switch (mergefilter)
47 case 1:
48 args = L" --merged HEAD";
49 break;
50 case 2:
51 args = L" --no-merged HEAD";
52 break;
55 CString cmd;
56 cmd.Format(L"git.exe for-each-ref%s --format=\"%%(refname)%%04 %%(objectname)%%04 %%(upstream)%%04 %%(subject)%%04 %%(authorname)%%04%%(authordate:raw)%%03\"", (LPCTSTR)args);
57 CString allRefs;
58 if (g_Git.Run(cmd, &allRefs, &err, CP_UTF8))
59 return -1;
61 int linePos = 0;
62 CString singleRef;
63 while (!(singleRef = allRefs.Tokenize(L"\03", linePos)).IsEmpty())
65 singleRef.TrimLeft(L"\r\n");
66 int valuePos = 0;
67 CString refName = singleRef.Tokenize(L"\04", valuePos);
69 if (refName.IsEmpty() || (filterCallback && !filterCallback(refName)))
70 continue;
72 GitRevRefBrowser ref;
73 ref.m_CommitHash = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
74 ref.m_UpstreamRef = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
75 ref.m_Subject = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
76 ref.m_AuthorName = singleRef.Tokenize(L"\04", valuePos).Trim(); if (valuePos < 0) continue;
77 CString date = singleRef.Tokenize(L"\04", valuePos).Trim();
78 ref.m_AuthorDate = StrToInt(date);
80 if (CStringUtils::StartsWith(refName, L"refs/heads/"))
81 ref.m_Description = descriptions[refName.Mid((int)wcslen(L"refs/heads/"))];
83 map.emplace(refName, ref);
86 return 0;