internal: rename "to_str" to "to_bytes" for clarity
This commit is contained in:
@@ -40,7 +40,7 @@ from .remote import Remote, get_credentials
|
||||
from .config import Config
|
||||
from .index import Index, IndexEntry
|
||||
from .errors import check_error
|
||||
from .ffi import ffi, C, to_str
|
||||
from .ffi import ffi, C, to_bytes
|
||||
|
||||
|
||||
def init_repository(path, bare=False,
|
||||
@@ -84,15 +84,15 @@ def init_repository(path, bare=False,
|
||||
options.version = 1
|
||||
options.flags = flags
|
||||
options.mode = mode
|
||||
options.workdir_path = to_str(workdir_path)
|
||||
options.description = to_str(description)
|
||||
options.template_path = to_str(template_path)
|
||||
options.initial_head = to_str(initial_head)
|
||||
options.origin_url = to_str(origin_url)
|
||||
options.workdir_path = to_bytes(workdir_path)
|
||||
options.description = to_bytes(description)
|
||||
options.template_path = to_bytes(template_path)
|
||||
options.initial_head = to_bytes(initial_head)
|
||||
options.origin_url = to_bytes(origin_url)
|
||||
|
||||
# Call
|
||||
crepository = ffi.new('git_repository **')
|
||||
err = C.git_repository_init_ext(crepository, to_str(path), options)
|
||||
err = C.git_repository_init_ext(crepository, to_bytes(path), options)
|
||||
check_error(err)
|
||||
|
||||
# Ok
|
||||
@@ -156,7 +156,7 @@ def clone_repository(
|
||||
checkout_branch_ref = ffi.new('char []', branch)
|
||||
opts.checkout_branch = checkout_branch_ref
|
||||
|
||||
remote_name_ref = ffi.new('char []', to_str(remote_name))
|
||||
remote_name_ref = ffi.new('char []', to_bytes(remote_name))
|
||||
opts.remote_name = remote_name_ref
|
||||
|
||||
opts.version = 1
|
||||
@@ -168,7 +168,7 @@ def clone_repository(
|
||||
opts.remote_callbacks.credentials = _credentials_cb
|
||||
opts.remote_callbacks.payload = d_handle
|
||||
|
||||
err = C.git_clone(crepo, to_str(url), to_str(path), opts)
|
||||
err = C.git_clone(crepo, to_bytes(url), to_bytes(path), opts)
|
||||
C.git_repository_free(crepo[0])
|
||||
|
||||
if 'exception' in d:
|
||||
@@ -196,7 +196,7 @@ def clone_into(repo, remote, branch=None):
|
||||
"""
|
||||
|
||||
err = C.git_clone_into(repo._repo, remote._remote, ffi.NULL,
|
||||
to_str(branch), ffi.NULL)
|
||||
to_bytes(branch), ffi.NULL)
|
||||
|
||||
if remote._stored_exception:
|
||||
raise remote._stored_exception
|
||||
|
@@ -28,7 +28,7 @@
|
||||
# Import from the future
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from .ffi import ffi, C, to_str, is_string
|
||||
from .ffi import ffi, C, to_bytes, is_string
|
||||
from .errors import check_error
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class Config(object):
|
||||
err = C.git_config_new(cconfig)
|
||||
else:
|
||||
assert_string(path, "path")
|
||||
err = C.git_config_open_ondisk(cconfig, to_str(path))
|
||||
err = C.git_config_open_ondisk(cconfig, to_bytes(path))
|
||||
|
||||
check_error(err, True)
|
||||
self._config = cconfig[0]
|
||||
@@ -103,7 +103,7 @@ class Config(object):
|
||||
assert_string(key, "key")
|
||||
|
||||
cstr = ffi.new('char **')
|
||||
err = C.git_config_get_string(cstr, self._config, to_str(key))
|
||||
err = C.git_config_get_string(cstr, self._config, to_bytes(key))
|
||||
|
||||
return err, cstr
|
||||
|
||||
@@ -136,19 +136,19 @@ class Config(object):
|
||||
|
||||
err = 0
|
||||
if isinstance(value, bool):
|
||||
err = C.git_config_set_bool(self._config, to_str(key), value)
|
||||
err = C.git_config_set_bool(self._config, to_bytes(key), value)
|
||||
elif isinstance(value, int):
|
||||
err = C.git_config_set_int64(self._config, to_str(key), value)
|
||||
err = C.git_config_set_int64(self._config, to_bytes(key), value)
|
||||
else:
|
||||
err = C.git_config_set_string(self._config, to_str(key),
|
||||
to_str(value))
|
||||
err = C.git_config_set_string(self._config, to_bytes(key),
|
||||
to_bytes(value))
|
||||
|
||||
check_error(err)
|
||||
|
||||
def __delitem__(self, key):
|
||||
assert_string(key, "key")
|
||||
|
||||
err = C.git_config_delete_entry(self._config, to_str(key))
|
||||
err = C.git_config_delete_entry(self._config, to_bytes(key))
|
||||
check_error(err)
|
||||
|
||||
def __iter__(self):
|
||||
@@ -169,7 +169,8 @@ class Config(object):
|
||||
|
||||
citer = ffi.new('git_config_iterator **')
|
||||
err = C.git_config_multivar_iterator_new(citer, self._config,
|
||||
to_str(name), to_str(regex))
|
||||
to_bytes(name),
|
||||
to_bytes(regex))
|
||||
check_error(err)
|
||||
|
||||
return ConfigMultivarIterator(self, citer[0])
|
||||
@@ -184,8 +185,8 @@ class Config(object):
|
||||
assert_string(regex, "regex")
|
||||
assert_string(value, "value")
|
||||
|
||||
err = C.git_config_set_multivar(self._config, to_str(name),
|
||||
to_str(regex), to_str(value))
|
||||
err = C.git_config_set_multivar(self._config, to_bytes(name),
|
||||
to_bytes(regex), to_bytes(value))
|
||||
check_error(err)
|
||||
|
||||
def get_bool(self, key):
|
||||
@@ -225,7 +226,7 @@ class Config(object):
|
||||
|
||||
Add a config file instance to an existing config."""
|
||||
|
||||
err = C.git_config_add_file_ondisk(self._config, to_str(path), level,
|
||||
err = C.git_config_add_file_ondisk(self._config, to_bytes(path), level,
|
||||
force)
|
||||
check_error(err)
|
||||
|
||||
@@ -249,7 +250,7 @@ class Config(object):
|
||||
@staticmethod
|
||||
def parse_bool(text):
|
||||
res = ffi.new('int *')
|
||||
err = C.git_config_parse_bool(res, to_str(text))
|
||||
err = C.git_config_parse_bool(res, to_bytes(text))
|
||||
check_error(err)
|
||||
|
||||
return res[0] != 0
|
||||
@@ -257,7 +258,7 @@ class Config(object):
|
||||
@staticmethod
|
||||
def parse_int(text):
|
||||
res = ffi.new('int64_t *')
|
||||
err = C.git_config_parse_int64(res, to_str(text))
|
||||
err = C.git_config_parse_int64(res, to_bytes(text))
|
||||
check_error(err)
|
||||
|
||||
return res[0]
|
||||
|
@@ -37,7 +37,7 @@ import sys
|
||||
(major_version, _, _, _, _) = sys.version_info
|
||||
|
||||
if major_version < 3:
|
||||
def to_str(s, encoding='utf-8', errors='strict'):
|
||||
def to_bytes(s, encoding='utf-8', errors='strict'):
|
||||
if s == ffi.NULL or s is None:
|
||||
return ffi.NULL
|
||||
|
||||
@@ -47,7 +47,7 @@ if major_version < 3:
|
||||
|
||||
return s
|
||||
else:
|
||||
def to_str(s, encoding='utf-8', errors='strict'):
|
||||
def to_bytes(s, encoding='utf-8', errors='strict'):
|
||||
if s == ffi.NULL or s is None:
|
||||
return ffi.NULL
|
||||
|
||||
@@ -97,7 +97,7 @@ def strings_to_strarray(l):
|
||||
if not is_string(l[i]):
|
||||
raise TypeError("Value must be a string")
|
||||
|
||||
s = ffi.new('char []', to_str(l[i]))
|
||||
s = ffi.new('char []', to_bytes(l[i]))
|
||||
refs[i] = s
|
||||
strings[i] = s
|
||||
|
||||
|
@@ -30,7 +30,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from _pygit2 import Oid, Tree, Diff
|
||||
|
||||
from .ffi import ffi, C, to_str, is_string, strings_to_strarray
|
||||
from .ffi import ffi, C, to_bytes, is_string, strings_to_strarray
|
||||
from .errors import check_error
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Index(object):
|
||||
to read from and write to.
|
||||
"""
|
||||
cindex = ffi.new('git_index **')
|
||||
err = C.git_index_open(cindex, to_str(path))
|
||||
err = C.git_index_open(cindex, to_bytes(path))
|
||||
check_error(err)
|
||||
|
||||
self._index = cindex[0]
|
||||
@@ -69,7 +69,7 @@ class Index(object):
|
||||
return C.git_index_entrycount(self._index)
|
||||
|
||||
def __contains__(self, path):
|
||||
err = C.git_index_find(ffi.NULL, self._index, to_str(path))
|
||||
err = C.git_index_find(ffi.NULL, self._index, to_bytes(path))
|
||||
if err == C.GIT_ENOTFOUND:
|
||||
return False
|
||||
|
||||
@@ -79,7 +79,7 @@ class Index(object):
|
||||
def __getitem__(self, key):
|
||||
centry = ffi.NULL
|
||||
if is_string(key):
|
||||
centry = C.git_index_get_bypath(self._index, to_str(key), 0)
|
||||
centry = C.git_index_get_bypath(self._index, to_bytes(key), 0)
|
||||
elif not key >= 0:
|
||||
raise ValueError(key)
|
||||
else:
|
||||
@@ -165,7 +165,7 @@ class Index(object):
|
||||
def remove(self, path):
|
||||
"""Remove an entry from the Index.
|
||||
"""
|
||||
err = C.git_index_remove(self._index, to_str(path), 0)
|
||||
err = C.git_index_remove(self._index, to_bytes(path), 0)
|
||||
check_error(err, True)
|
||||
|
||||
def add_all(self, pathspecs=[]):
|
||||
@@ -193,7 +193,7 @@ class Index(object):
|
||||
|
||||
if is_string(path_or_entry):
|
||||
path = path_or_entry
|
||||
err = C.git_index_add_bypath(self._index, to_str(path))
|
||||
err = C.git_index_add_bypath(self._index, to_bytes(path))
|
||||
elif isinstance(path_or_entry, IndexEntry):
|
||||
entry = path_or_entry
|
||||
centry, str_ref = entry._to_c()
|
||||
@@ -345,7 +345,7 @@ class IndexEntry(object):
|
||||
# basically memcpy()
|
||||
ffi.buffer(ffi.addressof(centry, 'id'))[:] = self.id.raw[:]
|
||||
centry.mode = self.mode
|
||||
path = ffi.new('char[]', to_str(self.path))
|
||||
path = ffi.new('char[]', to_bytes(self.path))
|
||||
centry.path = path
|
||||
|
||||
return centry, path
|
||||
@@ -394,7 +394,7 @@ class ConflictCollection(object):
|
||||
ctheirs = ffi.new('git_index_entry **')
|
||||
|
||||
err = C.git_index_conflict_get(cancestor, cours, ctheirs,
|
||||
self._index._index, to_str(path))
|
||||
self._index._index, to_bytes(path))
|
||||
check_error(err)
|
||||
|
||||
ancestor = IndexEntry._from_c(cancestor[0])
|
||||
@@ -404,7 +404,7 @@ class ConflictCollection(object):
|
||||
return ancestor, ours, theirs
|
||||
|
||||
def __delitem__(self, path):
|
||||
err = C.git_index_conflict_remove(self._index._index, to_str(path))
|
||||
err = C.git_index_conflict_remove(self._index._index, to_bytes(path))
|
||||
check_error(err)
|
||||
|
||||
def __iter__(self):
|
||||
|
@@ -28,7 +28,7 @@
|
||||
# Import from the future
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .ffi import ffi, C, to_str
|
||||
from .ffi import ffi, C, to_bytes
|
||||
from .errors import check_error
|
||||
|
||||
|
||||
@@ -66,18 +66,18 @@ class Refspec(object):
|
||||
"""src_matches(str) -> Bool
|
||||
|
||||
Returns whether the given string matches the source of this refspec"""
|
||||
return bool(C.git_refspec_src_matches(self._refspec, to_str(ref)))
|
||||
return bool(C.git_refspec_src_matches(self._refspec, to_bytes(ref)))
|
||||
|
||||
def dst_matches(self, ref):
|
||||
"""dst_matches(str) -> Bool
|
||||
|
||||
Returns whether the given string matches the destination of this
|
||||
refspec"""
|
||||
return bool(C.git_refspec_dst_matches(self._refspec, to_str(ref)))
|
||||
return bool(C.git_refspec_dst_matches(self._refspec, to_bytes(ref)))
|
||||
|
||||
def _transform(self, ref, fn):
|
||||
buf = ffi.new('git_buf *', (ffi.NULL, 0))
|
||||
err = fn(buf, self._refspec, to_str(ref))
|
||||
err = fn(buf, self._refspec, to_bytes(ref))
|
||||
check_error(err)
|
||||
|
||||
try:
|
||||
|
@@ -30,7 +30,7 @@ from __future__ import absolute_import
|
||||
|
||||
from _pygit2 import Oid
|
||||
|
||||
from .ffi import ffi, C, to_str, strarray_to_strings, strings_to_strarray
|
||||
from .ffi import ffi, C, to_bytes, strarray_to_strings, strings_to_strarray
|
||||
from .errors import check_error, GitError
|
||||
from .refspec import Refspec
|
||||
|
||||
@@ -160,7 +160,7 @@ class Remote(object):
|
||||
raise ValueError("New remote name must be a non-empty string")
|
||||
|
||||
problems = ffi.new('git_strarray *')
|
||||
err = C.git_remote_rename(problems, self._remote, to_str(new_name))
|
||||
err = C.git_remote_rename(problems, self._remote, to_bytes(new_name))
|
||||
check_error(err)
|
||||
|
||||
ret = strarray_to_strings(problems)
|
||||
@@ -176,7 +176,7 @@ class Remote(object):
|
||||
|
||||
@url.setter
|
||||
def url(self, value):
|
||||
err = C.git_remote_set_url(self._remote, to_str(value))
|
||||
err = C.git_remote_set_url(self._remote, to_bytes(value))
|
||||
check_error(err)
|
||||
|
||||
@property
|
||||
@@ -187,7 +187,7 @@ class Remote(object):
|
||||
|
||||
@push_url.setter
|
||||
def push_url(self, value):
|
||||
err = C.git_remote_set_pushurl(self._remote, to_str(value))
|
||||
err = C.git_remote_set_pushurl(self._remote, to_bytes(value))
|
||||
check_error(err)
|
||||
|
||||
def save(self):
|
||||
@@ -210,7 +210,7 @@ class Remote(object):
|
||||
ptr = ffi.NULL
|
||||
|
||||
self._stored_exception = None
|
||||
err = C.git_remote_fetch(self._remote, ptr, to_str(message))
|
||||
err = C.git_remote_fetch(self._remote, ptr, to_bytes(message))
|
||||
if self._stored_exception:
|
||||
raise self._stored_exception
|
||||
|
||||
@@ -269,7 +269,7 @@ class Remote(object):
|
||||
|
||||
Add a fetch refspec to the remote"""
|
||||
|
||||
err = C.git_remote_add_fetch(self._remote, to_str(spec))
|
||||
err = C.git_remote_add_fetch(self._remote, to_bytes(spec))
|
||||
check_error(err)
|
||||
|
||||
def add_push(self, spec):
|
||||
@@ -277,7 +277,7 @@ class Remote(object):
|
||||
|
||||
Add a push refspec to the remote"""
|
||||
|
||||
err = C.git_remote_add_push(self._remote, to_str(spec))
|
||||
err = C.git_remote_add_push(self._remote, to_bytes(spec))
|
||||
check_error(err)
|
||||
|
||||
@ffi.callback("int (*cb)(const char *ref, const char *msg, void *data)")
|
||||
@@ -304,7 +304,7 @@ class Remote(object):
|
||||
push = cpush[0]
|
||||
|
||||
try:
|
||||
err = C.git_push_add_refspec(push, to_str(spec))
|
||||
err = C.git_push_add_refspec(push, to_bytes(spec))
|
||||
check_error(err)
|
||||
|
||||
err = C.git_push_finish(push)
|
||||
@@ -325,7 +325,7 @@ class Remote(object):
|
||||
else:
|
||||
ptr = ffi.NULL
|
||||
|
||||
err = C.git_push_update_tips(push, ptr, to_str(message))
|
||||
err = C.git_push_update_tips(push, ptr, to_bytes(message))
|
||||
check_error(err)
|
||||
|
||||
finally:
|
||||
@@ -426,13 +426,13 @@ def get_credentials(fn, url, username, allowed):
|
||||
ccred = ffi.new('git_cred **')
|
||||
if cred_type == C.GIT_CREDTYPE_USERPASS_PLAINTEXT:
|
||||
name, passwd = creds.credential_tuple
|
||||
err = C.git_cred_userpass_plaintext_new(ccred, to_str(name),
|
||||
to_str(passwd))
|
||||
err = C.git_cred_userpass_plaintext_new(ccred, to_bytes(name),
|
||||
to_bytes(passwd))
|
||||
|
||||
elif cred_type == C.GIT_CREDTYPE_SSH_KEY:
|
||||
name, pubkey, privkey, passphrase = creds.credential_tuple
|
||||
err = C.git_cred_ssh_key_new(ccred, to_str(name), to_str(pubkey),
|
||||
to_str(privkey), to_str(passphrase))
|
||||
err = C.git_cred_ssh_key_new(ccred, to_bytes(name), to_bytes(pubkey),
|
||||
to_bytes(privkey), to_bytes(passphrase))
|
||||
|
||||
else:
|
||||
raise TypeError("unsupported credential type")
|
||||
|
@@ -34,7 +34,7 @@ from _pygit2 import Oid, GIT_OID_HEXSZ, GIT_OID_MINPREFIXLEN
|
||||
from _pygit2 import GIT_CHECKOUT_SAFE_CREATE, GIT_DIFF_NORMAL
|
||||
from _pygit2 import Reference, Tree, Commit, Blob
|
||||
|
||||
from .ffi import ffi, C, to_str
|
||||
from .ffi import ffi, C, to_bytes
|
||||
from .errors import check_error
|
||||
from .remote import Remote
|
||||
from .config import Config
|
||||
@@ -82,8 +82,8 @@ class Repository(_Repository):
|
||||
|
||||
cremote = ffi.new('git_remote **')
|
||||
|
||||
err = C.git_remote_create(cremote, self._repo, to_str(name),
|
||||
to_str(url))
|
||||
err = C.git_remote_create(cremote, self._repo, to_bytes(name),
|
||||
to_bytes(url))
|
||||
check_error(err)
|
||||
|
||||
return Remote(self, cremote[0])
|
||||
@@ -192,7 +192,7 @@ class Repository(_Repository):
|
||||
copts.checkout_strategy = strategy
|
||||
|
||||
if directory:
|
||||
target_dir = ffi.new('char[]', to_str(directory))
|
||||
target_dir = ffi.new('char[]', to_bytes(directory))
|
||||
refs.append(target_dir)
|
||||
copts.target_directory = target_dir
|
||||
|
||||
|
Reference in New Issue
Block a user