Prepare release and bump version numbers to 2.13.0
[TortoiseGit.git] / src / Git / gittype.h
blob1fc9b9fe503b3f509ba867882bbdbaa4f26f8ae5
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.
20 #pragma once
21 #include "GitHash.h"
22 #include <unordered_map>
24 enum
26 TGIT_GIT_SUCCESS=0,
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>
34 public:
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)
39 return i;
40 return npos;
42 size_t RevertFind(BYTE data, size_t start = npos) const
44 if (start == npos)
46 if (empty())
47 return npos;
48 start = size() - 1;
51 for (size_t i = start + 1; i-- > 0;)
52 if ((*this)[i] == data)
53 return i;
54 return npos;
56 size_t findNextString(size_t start = 0) const
58 size_t pos = start;
59 size_t end = size();
62 pos=find(0,pos);
63 if(pos != npos)
64 ++pos;
65 else
66 break;
68 if (pos >= end)
69 return npos;
71 }while(at(pos)==0);
73 return pos;
75 size_t append(std::vector<BYTE> &v, size_t start = 0, size_t end = npos)
77 if (end == npos)
78 end = v.size();
79 for (size_t i = start; i < end; ++i)
80 this->push_back(v[i]);
81 return 0;
83 void append(const BYTE* data, size_t dataSize)
85 if (dataSize == 0)
86 return;
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");
93 #pragma warning(push)
94 #if _MSC_VER < 1920
95 #pragma warning(disable: 4309) // 'static_cast': truncation of constant value
96 #endif
97 static_assert(-1 == static_cast<int>(npos), "NPOS must equal -1");
98 #pragma warning(pop)
101 class CGitGuardedByteArray : public CGitByteArray
103 private:
104 CGitGuardedByteArray(const CGitGuardedByteArray&) = delete;
105 CGitGuardedByteArray& operator=(const CGitGuardedByteArray&) = delete;
106 public:
107 CGitGuardedByteArray() {}
108 ~CGitGuardedByteArray() {}
109 CComAutoCriticalSection m_critSec;
112 struct TGitRef
114 CString name;
115 CGitHash hash;
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;