Show More
@@ -524,6 +524,59 b' PyObject *lowerencode(PyObject *self, Py' | |||
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | /* |
|
527 | * Avoiding a trip through Python would improve performance by 50%, | |
|
528 | * but we don't encounter enough long names to be worth the code. | |
|
529 | */ | |
|
530 | static int sha1hash(char hash[20], const char *str, Py_ssize_t len) | |
|
531 | { | |
|
532 | static PyObject *shafunc; | |
|
533 | PyObject *shaobj, *hashobj; | |
|
534 | ||
|
535 | if (shafunc == NULL) { | |
|
536 | PyObject *util, *name = PyString_FromString("mercurial.util"); | |
|
537 | ||
|
538 | if (name == NULL) | |
|
539 | return -1; | |
|
540 | ||
|
541 | util = PyImport_Import(name); | |
|
542 | Py_DECREF(name); | |
|
543 | ||
|
544 | if (util == NULL) { | |
|
545 | PyErr_SetString(PyExc_ImportError, "mercurial.util"); | |
|
546 | return -1; | |
|
547 | } | |
|
548 | shafunc = PyObject_GetAttrString(util, "sha1"); | |
|
549 | Py_DECREF(util); | |
|
550 | ||
|
551 | if (shafunc == NULL) { | |
|
552 | PyErr_SetString(PyExc_AttributeError, | |
|
553 | "module 'mercurial.util' has no " | |
|
554 | "attribute 'sha1'"); | |
|
555 | return -1; | |
|
556 | } | |
|
557 | } | |
|
558 | ||
|
559 | shaobj = PyObject_CallFunction(shafunc, "s#", str, len); | |
|
560 | ||
|
561 | if (shaobj == NULL) | |
|
562 | return -1; | |
|
563 | ||
|
564 | hashobj = PyObject_CallMethod(shaobj, "digest", ""); | |
|
565 | Py_DECREF(shaobj); | |
|
566 | ||
|
567 | if (!PyString_Check(hashobj) || PyString_GET_SIZE(hashobj) != 20) { | |
|
568 | PyErr_SetString(PyExc_TypeError, | |
|
569 | "result of digest is not a 20-byte hash"); | |
|
570 | Py_DECREF(hashobj); | |
|
571 | return -1; | |
|
572 | } | |
|
573 | ||
|
574 | memcpy(hash, PyString_AS_STRING(hashobj), 20); | |
|
575 | Py_DECREF(hashobj); | |
|
576 | return 0; | |
|
577 | } | |
|
578 | ||
|
579 | /* | |
|
527 | 580 | * We currently implement only basic encoding. |
|
528 | 581 | * |
|
529 | 582 | * If a name is too long to encode due to Windows path name limits, |
General Comments 0
You need to be logged in to leave comments.
Login now