1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 #define GIT_HASH_SIZE 20
29 unsigned char m_hash
[GIT_HASH_SIZE
];
33 memset(m_hash
,0, GIT_HASH_SIZE
);
37 memcpy(m_hash
,p
,GIT_HASH_SIZE
);
39 CGitHash
& operator = (CString
&str
)
45 CGitHash(CString
&str
)
47 if(str
.GetLength()<GIT_HASH_SIZE
)
55 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)
59 for(int j
=2*i
;j
<=2*i
+1;j
++)
64 if(ch
>= _T('0') && ch
<= _T('9'))
65 a
|= (ch
- _T('0'))&0xF;
66 else if(ch
>=_T('A') && ch
<= _T('F'))
67 a
|= ((ch
- _T('A'))&0xF) + 10 ;
68 else if(ch
>=_T('a') && ch
<= _T('f'))
69 a
|= ((ch
- _T('a'))&0xF) + 10;
76 void ConvertFromStrA(char *str
)
78 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)
82 for(int j
=2*i
;j
<=2*i
+1;j
++)
87 if(ch
>= '0' && ch
<= '9')
88 a
|= (ch
- ('0'))&0xF;
89 else if(ch
>=('A') && ch
<= ('F'))
90 a
|= ((ch
- ('A'))&0xF) + 10 ;
91 else if(ch
>=_T('a') && ch
<= ('f'))
92 a
|= ((ch
- ('a'))&0xF) + 10;
100 memset(m_hash
,0, GIT_HASH_SIZE
);
104 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)
116 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)
118 a
.Format(_T("%02x"),m_hash
[i
]);
128 bool operator == (const CGitHash
&hash
)
130 return memcmp(m_hash
,hash
.m_hash
,GIT_HASH_SIZE
) == 0;
134 friend bool operator<(const CGitHash
& left
, const CGitHash
& right
)
136 return memcmp(left
.m_hash
,right
.m_hash
,GIT_HASH_SIZE
) < 0;
139 friend bool operator>(const CGitHash
& left
, const CGitHash
& right
)
141 return memcmp(left
.m_hash
, right
.m_hash
, GIT_HASH_SIZE
) > 0;
144 friend bool operator != (const CGitHash
& left
, const CGitHash
& right
)
146 return memcmp(left
.m_hash
, right
.m_hash
, GIT_HASH_SIZE
) != 0;
148 #if defined(_MFC_VER)
149 friend CArchive
& AFXAPI
operator<<(CArchive
& ar
, CGitHash
& hash
)
151 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)
155 friend CArchive
& AFXAPI
operator>>(CArchive
& ar
, CGitHash
& hash
)
157 for(int i
=0;i
<GIT_HASH_SIZE
;i
++)