##// END OF EJS Templates
manifest: start removing 40-byte hash restrictions from C code...
Augie Fackler -
r45192:0b0e72b5 default
parent child Browse files
Show More
@@ -53,21 +53,35 b' static PyObject *nodeof(line *l)'
53 53 {
54 54 char *s = l->start;
55 55 Py_ssize_t llen = pathlen(l);
56 Py_ssize_t hlen = l->len - llen - 2;
57 Py_ssize_t hlen_raw = 20;
56 58 PyObject *hash;
57 59 if (llen + 1 + 40 + 1 > l->len) { /* path '\0' hash '\n' */
58 60 PyErr_SetString(PyExc_ValueError, "manifest line too short");
59 61 return NULL;
60 62 }
61 hash = unhexlify(s + llen + 1, 40);
63 switch (hlen) {
64 case 40: /* sha1 */
65 case 41: /* sha1 with cruft for a merge */
66 break;
67 case 64: /* new hash */
68 case 65: /* new hash with cruft for a merge */
69 hlen_raw = 32;
70 break;
71 default:
72 PyErr_SetString(PyExc_ValueError, "invalid node length in manifest");
73 return NULL;
74 }
75 hash = unhexlify(s + llen + 1, hlen_raw * 2);
62 76 if (!hash) {
63 77 return NULL;
64 78 }
65 79 if (l->hash_suffix != '\0') {
66 char newhash[21];
67 memcpy(newhash, PyBytes_AsString(hash), 20);
80 char newhash[33];
81 memcpy(newhash, PyBytes_AsString(hash), hlen_raw);
68 82 Py_DECREF(hash);
69 newhash[20] = l->hash_suffix;
70 hash = PyBytes_FromStringAndSize(newhash, 21);
83 newhash[hlen_raw] = l->hash_suffix;
84 hash = PyBytes_FromStringAndSize(newhash, hlen_raw+1);
71 85 }
72 86 return hash;
73 87 }
@@ -78,15 +92,20 b' static PyObject *hashflags(line *l)'
78 92 char *s = l->start;
79 93 Py_ssize_t plen = pathlen(l);
80 94 PyObject *hash = nodeof(l);
81
82 /* 40 for hash, 1 for null byte, 1 for newline */
83 Py_ssize_t hplen = plen + 42;
84 Py_ssize_t flen = l->len - hplen;
95 ssize_t hlen;
96 Py_ssize_t hplen, flen;
85 97 PyObject *flags;
86 98 PyObject *tup;
87 99
88 100 if (!hash)
89 101 return NULL;
102 /* hash is either 20 or 21 bytes for an old hash, so we use a
103 ternary here to get the "real" hexlified sha length. */
104 hlen = PyBytes_GET_SIZE(hash) < 22 ? 40 : 64;
105 /* 1 for null byte, 1 for newline */
106 hplen = plen + hlen + 2;
107 flen = l->len - hplen;
108
90 109 flags = PyBytes_FromStringAndSize(s + hplen - 1, flen);
91 110 if (!flags) {
92 111 Py_DECREF(hash);
General Comments 0
You need to be logged in to leave comments. Login now