mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Hashlib doesn't take unicode.
This commit is contained in:
parent
a34f3fc7c9
commit
5d1ffcba75
3 changed files with 14 additions and 11 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
@ -11,6 +10,7 @@ from plumbum import local
|
||||||
|
|
||||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||||
from pre_commit.util import clean_path_on_failure
|
from pre_commit.util import clean_path_on_failure
|
||||||
|
from pre_commit.util import hex_md5
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('pre_commit')
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
@ -75,9 +75,7 @@ class Store(object):
|
||||||
self.require_created()
|
self.require_created()
|
||||||
|
|
||||||
# Check if we already exist
|
# Check if we already exist
|
||||||
sha_path = os.path.join(
|
sha_path = os.path.join(self.directory, sha + '_' + hex_md5(url))
|
||||||
self.directory, sha + '_' + hashlib.md5(url).hexdigest()
|
|
||||||
)
|
|
||||||
if os.path.exists(sha_path):
|
if os.path.exists(sha_path):
|
||||||
return os.readlink(sha_path)
|
return os.readlink(sha_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -56,3 +57,11 @@ def noop_context():
|
||||||
|
|
||||||
def shell_escape(arg):
|
def shell_escape(arg):
|
||||||
return "'" + arg.replace("'", "'\"'\"'".strip()) + "'"
|
return "'" + arg.replace("'", "'\"'\"'".strip()) + "'"
|
||||||
|
|
||||||
|
|
||||||
|
def hex_md5(s):
|
||||||
|
"""Hexdigest an md5 of the string.
|
||||||
|
|
||||||
|
:param text s:
|
||||||
|
"""
|
||||||
|
return hashlib.md5(s.encode('utf-8')).hexdigest()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import io
|
import io
|
||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
|
|
@ -14,6 +13,7 @@ from pre_commit import five
|
||||||
from pre_commit.store import _get_default_directory
|
from pre_commit.store import _get_default_directory
|
||||||
from pre_commit.store import logger
|
from pre_commit.store import logger
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
|
from pre_commit.util import hex_md5
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
from testing.util import get_head_sha
|
from testing.util import get_head_sha
|
||||||
|
|
||||||
|
|
@ -105,9 +105,7 @@ def test_clone(store, tmpdir_factory, log_info_mock):
|
||||||
assert get_head_sha(ret) == sha
|
assert get_head_sha(ret) == sha
|
||||||
|
|
||||||
# Assert that we made a symlink from the sha to the repo
|
# Assert that we made a symlink from the sha to the repo
|
||||||
sha_path = os.path.join(
|
sha_path = os.path.join(store.directory, sha + '_' + hex_md5(path))
|
||||||
store.directory, sha + '_' + hashlib.md5(path).hexdigest(),
|
|
||||||
)
|
|
||||||
assert os.path.exists(sha_path)
|
assert os.path.exists(sha_path)
|
||||||
assert os.path.islink(sha_path)
|
assert os.path.islink(sha_path)
|
||||||
assert os.readlink(sha_path) == ret
|
assert os.readlink(sha_path) == ret
|
||||||
|
|
@ -141,9 +139,7 @@ def test_clone_when_repo_already_exists(store):
|
||||||
os.mkdir(repo_dir_path)
|
os.mkdir(repo_dir_path)
|
||||||
os.symlink(
|
os.symlink(
|
||||||
repo_dir_path,
|
repo_dir_path,
|
||||||
os.path.join(
|
os.path.join(store.directory, 'fake_sha' + '_' + hex_md5('url')),
|
||||||
store.directory, 'fake_sha' + '_' + hashlib.md5('url').hexdigest(),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = store.clone('url', 'fake_sha')
|
ret = store.clone('url', 'fake_sha')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue