1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2021 - 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.
19 // CTortoiseGitBlameData.h : interface of the CTortoiseGitBlameData class
25 #include "gitlogcache.h"
26 #include <unordered_set>
28 class CTortoiseGitBlameData
32 CTortoiseGitBlameData();
33 virtual ~CTortoiseGitBlameData();
36 int GetEncode(unsigned char * buffer
, int size
, int *bomoffset
);
37 int GetEncode(int *bomoffset
);
38 void ParseBlameOutput(BYTE_VECTOR
&data
, CGitHashMap
& HashToRev
, DWORD dateFormat
, bool bRelativeTimes
);
39 // updates sourcecode lines to the given encoding, encode==0 detects the encoding, returns the used encoding
40 int UpdateEncoding(int encode
= 0);
42 BOOL
IsValidLine(int line
)
44 return line
>= 0 && line
< static_cast<int>(m_Hash
.size());
46 int FindNextLine(CGitHash
& commithash
, int line
, bool bUpOrDown
=false);
47 // find first line with the given hash starting with given "line"
48 int FindFirstLine(const CGitHash
& commithash
, int line
)
50 int numberOfLines
= static_cast<int>(GetNumberOfLines());
51 for (int i
= (line
>= 0 ? line
: 0); i
< numberOfLines
; ++i
)
53 if (m_Hash
[i
] == commithash
)
58 // find first line of the current block with the given hash starting with given "line"
59 int FindFirstLineInBlock(const CGitHash
& commithash
, int line
)
63 if (m_Hash
[line
] != commithash
)
69 enum SearchDirection
{ SearchNext
= 0, SearchPrevious
= 1 };
70 int FindFirstLineWrapAround(SearchDirection direction
, const CString
& what
, int line
, bool bCaseSensitive
, std::function
<void()> wraparound
);
72 size_t GetNumberOfLines() const
77 CGitHash
& GetHash(size_t line
)
82 void GetHashes(std::unordered_set
<CGitHash
>& hashes
)
85 for (const auto& hash
: m_Hash
)
91 const CString
& GetDate(size_t line
) const
96 const CString
& GetAuthor(size_t line
) const
98 return m_Authors
[line
];
101 const CString
& GetFilename(size_t line
) const
103 return m_Filenames
[line
];
106 int GetOriginalLineNumber(size_t line
) const
108 return m_OriginalLineNumbers
[line
];
111 const CStringA
& GetUtf8Line(size_t line
) const
113 return m_Utf8Lines
[line
];
116 bool ContainsOnlyFilename(const CString
&filename
) const;
118 GitRevLoglist
* GetRev(int line
, CGitHashMap
& hashToRev
)
120 return GetRevForHash(hashToRev
, GetHash(line
), GitRevLoglist::s_Mailmap
.get());
124 static GitRevLoglist
* GetRevForHash(CGitHashMap
& HashToRev
, const CGitHash
& hash
, const CGitMailmap
* mailmap
, CString
* err
= nullptr);
125 static CString
UnquoteFilename(const CStringA
& s
);
127 std::vector
<CGitHash
> m_Hash
;
128 std::vector
<CString
> m_Dates
;
129 std::vector
<CString
> m_Authors
;
130 std::vector
<CString
> m_Filenames
;
131 std::vector
<int> m_OriginalLineNumbers
;
132 std::vector
<BYTE_VECTOR
> m_RawLines
;
135 std::vector
<CStringA
> m_Utf8Lines
;