1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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
= (size_t)-1; // bad/missing length/position
92 static_assert(MAXSIZE_T
== npos
, "NPOS must equal MAXSIZE_T");
94 #pragma warning(disable: 4310)
95 static_assert(-1 == (int)npos
, "NPOS must equal -1");
99 class CGitGuardedByteArray
: public CGitByteArray
102 CGitGuardedByteArray(const CGitGuardedByteArray
&) = delete;
103 CGitGuardedByteArray
& operator=(const CGitGuardedByteArray
&) = delete;
105 CGitGuardedByteArray() { m_critSec
.Init(); }
106 ~CGitGuardedByteArray() { m_critSec
.Term(); }
107 CComCriticalSection m_critSec
;
114 operator const CString
&() const { return name
; }
117 typedef std::vector
<CString
> STRING_VECTOR
;
118 typedef std::unordered_map
<CGitHash
, STRING_VECTOR
> MAP_HASH_NAME
;
119 typedef std::map
<CString
, CString
> MAP_STRING_STRING
;
120 typedef std::vector
<TGitRef
> REF_VECTOR
;
121 typedef CGitByteArray BYTE_VECTOR
;