OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / Git / GitHash.h
index 900aa16..4d65ba7 100644 (file)
@@ -6,8 +6,9 @@
 \r
 class CGitHash\r
 {\r
-       unsigned char m_hash[GIT_HASH_SIZE];\r
 public:\r
+       unsigned char m_hash[GIT_HASH_SIZE];\r
+\r
        CGitHash()\r
        {\r
                memset(m_hash,0, GIT_HASH_SIZE);\r
@@ -28,17 +29,18 @@ public:
                {\r
                        unsigned char a;\r
                        a=0;\r
-                       for(int j=2*i;j<2*i+1;j++)\r
+                       for(int j=2*i;j<=2*i+1;j++)\r
                        {\r
+                               a =a<<4;\r
+\r
                                TCHAR ch = str[j];\r
                                if(ch >= _T('0') && ch <= _T('9'))\r
                                        a |= (ch - _T('0'))&0xF;\r
                                else if(ch >=_T('A') && ch <= _T('F'))\r
-                                       a |= (ch - _T('A'))&0xF;\r
+                                       a |= ((ch - _T('A'))&0xF) + 10 ;\r
                                else if(ch >=_T('a') && ch <= _T('f'))\r
-                                       a |= (ch - _T('a'))&0xF;\r
+                                       a |= ((ch - _T('a'))&0xF) + 10;         \r
                                \r
-                               a =a<<4;\r
                        }\r
                        m_hash[i]=a;\r
                }\r
@@ -63,7 +65,7 @@ public:
                CString a;\r
                for(int i=0;i<GIT_HASH_SIZE;i++)\r
                {\r
-                       a.Format(_T("%02X"),m_hash[i]);\r
+                       a.Format(_T("%02x"),m_hash[i]);\r
                        str+=a;\r
                }\r
                return str;\r
@@ -89,6 +91,10 @@ public:
                return memcmp(left.m_hash, right.m_hash, GIT_HASH_SIZE) > 0;\r
        }\r
 \r
+       friend bool operator != (const CGitHash& left, const CGitHash& right)\r
+       {\r
+               return memcmp(left.m_hash, right.m_hash, GIT_HASH_SIZE) != 0;\r
+       }\r
 #if defined(_MFC_VER)\r
        friend CArchive& AFXAPI operator<<(CArchive& ar, CGitHash& hash)\r
        {\r