1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017, 2019-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.
22 #include <unordered_map>
27 TGIT_GIT_ERROR_OPEN_PIP
,
28 TGIT_GIT_ERROR_CREATE_PROCESS
,
29 TGIT_GIT_ERROR_GET_EXIT_CODE
32 class CGitByteArray
:public std::vector
<BYTE
>
35 size_t find(BYTE data
, size_t start
= 0) const
37 for (size_t i
= start
, end
= size(); i
< end
; ++i
)
38 if ((*this)[i
] == data
)
42 size_t RevertFind(BYTE data
, size_t start
= npos
) const
51 for (size_t i
= start
+ 1; i
-- > 0;)
52 if ((*this)[i
] == data
)
56 size_t findNextString(size_t start
= 0) const
75 size_t append(std::vector
<BYTE
> &v
, size_t start
= 0, size_t end
= npos
)
79 for (size_t i
= start
; i
< end
; ++i
)
80 this->push_back(v
[i
]);
83 void append(const BYTE
* data
, size_t dataSize
)
87 size_t oldsize
=size();
88 resize(oldsize
+dataSize
);
89 memcpy(&*(begin()+oldsize
),data
,dataSize
);
91 static const size_t npos
= static_cast<size_t>(-1); // bad/missing length/position
92 static_assert(MAXSIZE_T
== npos
, "NPOS must equal MAXSIZE_T");
95 #pragma warning(disable: 4309) // 'static_cast': truncation of constant value
97 static_assert(-1 == static_cast<int>(npos
), "NPOS must equal -1");
101 class CGitGuardedByteArray
: public CGitByteArray
104 CGitGuardedByteArray(const CGitGuardedByteArray
&) = delete;
105 CGitGuardedByteArray
& operator=(const CGitGuardedByteArray
&) = delete;
107 CGitGuardedByteArray() {}
108 ~CGitGuardedByteArray() {}
109 CComAutoCriticalSection m_critSec
;
116 operator const CString
&() const { return name
; }
119 using STRING_VECTOR
= std::vector
<CString
>;
120 using MAP_HASH_NAME
= std::unordered_map
<CGitHash
, STRING_VECTOR
>;
121 using MAP_STRING_STRING
= std::map
<CString
, CString
>;
122 using REF_VECTOR
= std::vector
<TGitRef
>;
123 using BYTE_VECTOR
= CGitByteArray
;