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.
24 #include "GitRevRefBrowser.h"
25 #include "StringUtils.h"
27 GitRevRefBrowser::GitRevRefBrowser() : GitRev()
31 void GitRevRefBrowser::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
)
41 MAP_STRING_STRING descriptions
;
42 g_Git
.GetBranchDescriptions(descriptions
);
48 args
= L
" --merged HEAD";
51 args
= L
" --no-merged HEAD";
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
);
58 if (g_Git
.Run(cmd
, &allRefs
, &err
, CP_UTF8
))
63 while (!(singleRef
= allRefs
.Tokenize(L
"\03", linePos
)).IsEmpty())
65 singleRef
.TrimLeft(L
"\r\n");
67 CString refName
= singleRef
.Tokenize(L
"\04", valuePos
);
69 if (refName
.IsEmpty() || (filterCallback
&& !filterCallback(refName
)))
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
);