← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] ~pappacena/turnip:py3-strings-compat into turnip:master

 


Diff comments:

> diff --git a/turnip/api/store.py b/turnip/api/store.py
> index 11b4756..2179f27 100644
> --- a/turnip/api/store.py
> +++ b/turnip/api/store.py
> @@ -333,14 +334,21 @@ def repack(repo_path, ignore_alternates=False, single=False,
>  
>  def get_refs(repo_store, repo_name, exclude_prefixes=None):
>      """Return all refs for a git repository."""
> +    if exclude_prefixes:
> +        # Convert exclude_prefixes to bytes, since refs will be bytes too.
> +        exclude_prefixes = [ensure_binary(i, 'utf-8')
> +                            for i in exclude_prefixes]
>      with open_repo(repo_store, repo_name) as repo:
>          refs = {}
> -        for ref in repo.listall_references():
> -            git_object = repo.references[ref].peel()
> +        for ref_obj in repo.listall_reference_objects():

Previous `repo.listall_references()` raises an exception on python3 when there are refs with some special character.

>              # Filter non-unicode refs, as refs are treated as unicode
>              # given json is unable to represent arbitrary byte strings.
>              try:
> -                ref = ref.decode('utf-8')
> +                if hasattr(ref_obj.name, 'decode'):  # py2
> +                    ref = ref_obj.name.decode('utf-8')
> +                else:  # py3
> +                    ref = bytes(ref_obj.name, 'utf-8')
> +                git_object = repo.references[ref].peel()
>              except UnicodeDecodeError:
>                  pass
>              else:
> diff --git a/turnip/api/tests/test_helpers.py b/turnip/api/tests/test_helpers.py
> index dac6950..cc2e471 100644
> --- a/turnip/api/tests/test_helpers.py
> +++ b/turnip/api/tests/test_helpers.py
> @@ -96,12 +97,16 @@ class RepoFactory(object):
>  
>      def add_tag(self, tag_name, tag_message, oid):
>          """Create a tag from tag_name and oid."""
> -        repo = self.repo
> -        repo.create_tag(tag_name, oid, GIT_OBJ_COMMIT,
> -                        self.committer, tag_message)
> +        subprocess.check_call(
> +            ['git', '-C', self.repo_path,
> +             'tag', '-m', tag_message, tag_name, oid.hex])

`repo.create_tag` was misbehaving with utf8 characters on python3, and this change has been proposed on the reference branch either by cjwatson or twom, and it seems to work just fine.

>  
>      def makeSignature(self, name, email, encoding='utf-8'):
>          """Return an author or committer signature."""
> +        # xxx: pappacena 2020-03-09:
> +        # email should always be str on python3, but pygit2
> +        # doesn't enforce the same for name.
> +        email = six.ensure_str(email)
>          return Signature(name, email, encoding=encoding)
>  
>      def stage(self, path, content):


-- 
https://code.launchpad.net/~pappacena/turnip/+git/turnip/+merge/380451
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/turnip:py3-strings-compat into turnip:master.