← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:unsixify-bzr-revisions into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:unsixify-bzr-revisions into launchpad:master.

Commit message:
Remove six from bzr revision handling

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/427768

On Python 3, Breezy always stores revision IDs as bytes.  Simplify our handling of these to avoid `six`.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:unsixify-bzr-revisions into launchpad:master.
diff --git a/lib/lp/code/bzr.py b/lib/lp/code/bzr.py
index c2563a4..8c30aed 100644
--- a/lib/lp/code/bzr.py
+++ b/lib/lp/code/bzr.py
@@ -340,7 +340,7 @@ def branch_changed(db_branch, bzr_branch=None):
         stacked_on = bzr_branch.get_stacked_on_url()
     except (NotStacked, UnstackableBranchFormat):
         stacked_on = None
-    last_revision = six.ensure_text(bzr_branch.last_revision())
+    last_revision = bzr_branch.last_revision().decode()
     formats = get_branch_formats(bzr_branch)
     db_branch.branchChanged(stacked_on, last_revision, *formats)
 
diff --git a/lib/lp/code/model/branch.py b/lib/lp/code/model/branch.py
index 8823c62..262b156 100644
--- a/lib/lp/code/model/branch.py
+++ b/lib/lp/code/model/branch.py
@@ -1375,7 +1375,7 @@ class Branch(SQLBase, WebhookTargetMixin, BzrIdentityMixin):
         # in the database, so if the revision_date is a future date, then we
         # use the date created instead.
         if db_revision is None:
-            revision_id = six.ensure_text(NULL_REVISION)
+            revision_id = NULL_REVISION.decode()
             revision_date = UTC_NOW
         else:
             revision_id = db_revision.revision_id
diff --git a/lib/lp/code/model/branchjob.py b/lib/lp/code/model/branchjob.py
index 0317827..09424d5 100644
--- a/lib/lp/code/model/branchjob.py
+++ b/lib/lp/code/model/branchjob.py
@@ -551,8 +551,7 @@ class RevisionsAddedJob(BranchJobDerived):
         """Iterate through revisions added to the mainline."""
         repository = self.bzr_branch.repository
         added_revisions = repository.get_graph().find_unique_ancestors(
-            six.ensure_binary(self.last_revision_id),
-            [six.ensure_binary(self.last_scanned_id)],
+            self.last_revision_id.encode(), [self.last_scanned_id.encode()]
         )
         # Avoid hitting the database since breezy makes it easy to check.
         # There are possibly more efficient ways to get the mainline
@@ -714,7 +713,7 @@ class RevisionsAddedJob(BranchJobDerived):
             BranchMergeProposal.target_branch == self.branch.id,
             BranchMergeProposal.source_branch == Branch.id,
             Branch.last_scanned_id.is_in(
-                {six.ensure_text(revision_id) for revision_id in revision_ids}
+                {revision_id.decode() for revision_id in revision_ids}
             ),
             (
                 BranchMergeProposal.queue_status
@@ -853,7 +852,7 @@ class RosettaUploadJob(BranchJobDerived):
 
         if from_revision_id is None:
             from_revision_id = NULL_REVISION
-        from_revision_id = six.ensure_text(from_revision_id)
+        from_revision_id = from_revision_id.decode()
 
         if force_translations_upload or cls.providesTranslationFiles(branch):
             metadata = cls.getMetadata(
@@ -941,10 +940,10 @@ class RosettaUploadJob(BranchJobDerived):
 
         bzrbranch = self.branch.getBzrBranch()
         from_tree = bzrbranch.repository.revision_tree(
-            six.ensure_binary(self.from_revision_id)
+            self.from_revision_id.encode()
         )
         to_tree = bzrbranch.repository.revision_tree(
-            six.ensure_binary(self.branch.last_scanned_id)
+            self.branch.last_scanned_id.encode()
         )
 
         importer = TranslationImporter()
diff --git a/lib/lp/code/model/diff.py b/lib/lp/code/model/diff.py
index b9e76b9..21e9968 100644
--- a/lib/lp/code/model/diff.py
+++ b/lib/lp/code/model/diff.py
@@ -326,8 +326,8 @@ class Diff(SQLBase):
             diff_ignore_branches(
                 source_branch,
                 ignore_branches,
-                six.ensure_binary(old_revision.revision_id),
-                six.ensure_binary(new_revision.revision_id),
+                old_revision.revision_id.encode(),
+                new_revision.revision_id.encode(),
                 diff_content,
             )
         return cls.fromFileAtEnd(diff_content)
diff --git a/lib/lp/code/model/directbranchcommit.py b/lib/lp/code/model/directbranchcommit.py
index d4f602d..886a479 100644
--- a/lib/lp/code/model/directbranchcommit.py
+++ b/lib/lp/code/model/directbranchcommit.py
@@ -11,7 +11,6 @@ __all__ = [
 
 import os.path
 
-import six
 from breezy.bzr.generate_ids import gen_file_id
 from breezy.bzr.transform import TransformPreview
 from breezy.revision import NULL_REVISION
@@ -91,7 +90,7 @@ class DirectBranchCommit:
 
         self.last_scanned_id = self.db_branch.last_scanned_id
         if self.last_scanned_id is not None:
-            self.last_scanned_id = six.ensure_binary(self.last_scanned_id)
+            self.last_scanned_id = self.last_scanned_id.encode()
 
         if committer is None:
             committer = db_branch.owner
@@ -134,7 +133,7 @@ class DirectBranchCommit:
             and revision_id == NULL_REVISION
         ):
             return True
-        return six.ensure_text(revision_id) == self.db_branch.last_mirrored_id
+        return revision_id.decode() == self.db_branch.last_mirrored_id
 
     def _getDir(self, path):
         """Get trans_id for directory "path."  Create if necessary."""
@@ -251,7 +250,7 @@ class DirectBranchCommit:
                 )
             IMasterObject(self.db_branch).branchChanged(
                 get_stacked_on_url(self.bzrbranch),
-                None if new_rev_id is None else six.ensure_text(new_rev_id),
+                None if new_rev_id is None else new_rev_id.decode(),
                 self.db_branch.control_format,
                 self.db_branch.branch_format,
                 self.db_branch.repository_format,
diff --git a/lib/lp/code/model/revision.py b/lib/lp/code/model/revision.py
index 2daa422..b0738ed 100644
--- a/lib/lp/code/model/revision.py
+++ b/lib/lp/code/model/revision.py
@@ -15,7 +15,6 @@ from datetime import datetime, timedelta
 from operator import itemgetter
 
 import pytz
-import six
 from breezy.revision import NULL_REVISION
 from storm.expr import And, Asc, Desc, Join, Or, Select
 from storm.locals import (
@@ -413,7 +412,7 @@ class RevisionSet:
         # Collect all data for making Revision objects.
         data = []
         for bzr_revision, author_name in zip(revisions, author_names):
-            revision_id = six.ensure_text(bzr_revision.revision_id)
+            revision_id = bzr_revision.revision_id.decode()
             revision_date = self._timestampToDatetime(bzr_revision.timestamp)
             revision_author = revision_authors[author_name]
 
@@ -445,7 +444,7 @@ class RevisionSet:
         parent_data = []
         property_data = []
         for bzr_revision in revisions:
-            db_id = revision_db_id[six.ensure_text(bzr_revision.revision_id)]
+            db_id = revision_db_id[bzr_revision.revision_id.decode()]
             # Property data: revision DB id, name, value.
             for name, value in bzr_revision.properties.items():
                 # pristine-tar properties can be huge, and storing them
@@ -454,8 +453,7 @@ class RevisionSet:
                     continue
                 property_data.append((db_id, name, value))
             parent_ids = [
-                six.ensure_text(parent_id)
-                for parent_id in bzr_revision.parent_ids
+                parent_id.decode() for parent_id in bzr_revision.parent_ids
             ]
             # Parent data: revision DB id, sequence, revision_id
             seen_parents = set()
diff --git a/lib/lp/code/model/tests/test_branch.py b/lib/lp/code/model/tests/test_branch.py
index e5e0ce7..5f037c4 100644
--- a/lib/lp/code/model/tests/test_branch.py
+++ b/lib/lp/code/model/tests/test_branch.py
@@ -6,7 +6,6 @@
 import json
 from datetime import datetime, timedelta
 
-import six
 import transaction
 from breezy.branch import Branch
 from breezy.bzr.bzrdir import BzrDir
@@ -2548,9 +2547,7 @@ class TestRevisionHistory(TestCaseWithFactory):
         # breezy.revision.NULL_REVISION.
         branch = self.factory.makeBranch()
         branch.updateScannedDetails(None, 0)
-        self.assertEqual(
-            six.ensure_text(NULL_REVISION), branch.last_scanned_id
-        )
+        self.assertEqual(NULL_REVISION.decode(), branch.last_scanned_id)
         self.assertIs(None, branch.getTipRevision())
 
     def test_tip_revision_is_updated(self):
@@ -2759,7 +2756,7 @@ class TestPendingWritesAndUpdates(TestCaseWithFactory):
         # Cheat! The actual API for marking a branch as scanned is to run
         # the BranchScanJob. That requires a revision in the database
         # though.
-        removeSecurityProxy(branch).last_scanned_id = six.ensure_text(rev_id)
+        removeSecurityProxy(branch).last_scanned_id = rev_id.decode()
         [job] = getUtility(IBranchScanJobSource).iterReady()
         removeSecurityProxy(job).job._status = JobStatus.COMPLETED
         self.assertFalse(branch.pending_writes)
diff --git a/lib/lp/code/model/tests/test_branchjob.py b/lib/lp/code/model/tests/test_branchjob.py
index be039b5..24aeb5b 100644
--- a/lib/lp/code/model/tests/test_branchjob.py
+++ b/lib/lp/code/model/tests/test_branchjob.py
@@ -8,7 +8,6 @@ import os
 import shutil
 
 import pytz
-import six
 import transaction
 from breezy import errors as bzr_errors
 from breezy.branch import Branch
@@ -455,12 +454,12 @@ class TestRevisionsAddedJob(TestCaseWithFactory):
         """
         for bzr_revision in bzr_branch.repository.get_revisions(revision_ids):
             existing = branch.getBranchRevision(
-                revision_id=six.ensure_text(bzr_revision.revision_id)
+                revision_id=bzr_revision.revision_id.decode()
             )
             if existing is None:
                 RevisionSet().newFromBazaarRevisions([bzr_revision])
             revision = RevisionSet().getByRevisionId(
-                six.ensure_text(bzr_revision.revision_id)
+                bzr_revision.revision_id.decode()
             )
             try:
                 revno = bzr_branch.revision_id_to_revno(revision.revision_id)
@@ -1060,7 +1059,7 @@ class TestRosettaUploadJob(TestCaseWithFactory):
         # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
         # required to generate the revision-id.
         with override_environ(BRZ_EMAIL="me@xxxxxxxxxxx"):
-            revision_id = six.ensure_text(self.tree.commit(commit_message))
+            revision_id = self.tree.commit(commit_message).decode()
         self.branch.last_scanned_id = revision_id
         self.branch.last_mirrored_id = revision_id
         return revision_id
@@ -1313,7 +1312,7 @@ class TestRosettaUploadJob(TestCaseWithFactory):
         # and last_mirror_id are different.
         self._makeBranchWithTreeAndFiles([])
         # Was not scanned yet.
-        self.branch.last_scanned_id = six.ensure_text(NULL_REVISION)
+        self.branch.last_scanned_id = NULL_REVISION.decode()
         self._makeProductSeries(TranslationsBranchImportMode.IMPORT_TEMPLATES)
         # Put the job in ready state.
         self._makeRosettaUploadJob()
diff --git a/lib/lp/code/model/tests/test_branchmergeproposaljobs.py b/lib/lp/code/model/tests/test_branchmergeproposaljobs.py
index dd9a6e9..807fc0a 100644
--- a/lib/lp/code/model/tests/test_branchmergeproposaljobs.py
+++ b/lib/lp/code/model/tests/test_branchmergeproposaljobs.py
@@ -7,7 +7,6 @@ import hashlib
 from datetime import datetime, timedelta
 
 import pytz
-import six
 import transaction
 from fixtures import FakeLogger
 from lazr.lifecycle.event import ObjectModifiedEvent
@@ -447,7 +446,7 @@ def make_runnable_incremental_diff_job(test_case):
     test_case.factory.makeRevision(rev_id=source_rev_id)
     test_case.factory.makeRevision(rev_id=parent_id)
     return GenerateIncrementalDiffJob.create(
-        bmp, six.ensure_text(parent_id), six.ensure_text(source_rev_id)
+        bmp, parent_id.decode(), source_rev_id.decode()
     )
 
 
diff --git a/lib/lp/code/model/tests/test_diff.py b/lib/lp/code/model/tests/test_diff.py
index ce47123..833e04e 100644
--- a/lib/lp/code/model/tests/test_diff.py
+++ b/lib/lp/code/model/tests/test_diff.py
@@ -9,7 +9,6 @@ from difflib import unified_diff
 from io import BytesIO
 from textwrap import dedent
 
-import six
 import transaction
 from breezy import trace
 from breezy.patches import InsertLine, RemoveLine, parse_patches
@@ -568,12 +567,8 @@ class TestPreviewDiff(DiffTestCase):
         # Correctly generates a PreviewDiff from a BranchMergeProposal.
         bmp, source_rev_id, target_rev_id = self.createExampleBzrMerge()
         preview = PreviewDiff.fromBranchMergeProposal(bmp)
-        self.assertEqual(
-            six.ensure_text(source_rev_id), preview.source_revision_id
-        )
-        self.assertEqual(
-            six.ensure_text(target_rev_id), preview.target_revision_id
-        )
+        self.assertEqual(source_rev_id.decode(), preview.source_revision_id)
+        self.assertEqual(target_rev_id.decode(), preview.target_revision_id)
         transaction.commit()
         self.checkExampleBzrMerge(preview.text)
         self.assertEqual({"foo": (5, 0)}, preview.diffstat)
diff --git a/lib/lp/code/tests/test_directbranchcommit.py b/lib/lp/code/tests/test_directbranchcommit.py
index a479f8a..df4dd7c 100644
--- a/lib/lp/code/tests/test_directbranchcommit.py
+++ b/lib/lp/code/tests/test_directbranchcommit.py
@@ -3,7 +3,6 @@
 
 """Tests for `DirectBranchCommit`."""
 
-import six
 from testtools.testcase import ExpectedException
 from zope.security.proxy import removeSecurityProxy
 
@@ -215,9 +214,7 @@ class TestDirectBranchCommit(DirectBranchCommitTestCase, TestCaseWithFactory):
         # the branch.
         self.committer.writeFile("hi.c", b'main(){puts("hi world");}')
         revid = self.committer.commit("")
-        self.assertEqual(
-            six.ensure_text(revid), self.db_branch.last_mirrored_id
-        )
+        self.assertEqual(revid.decode(), self.db_branch.last_mirrored_id)
 
     def test_commit_uses_getBzrCommitterID(self):
         # commit() passes self.getBzrCommitterID() to bzr as the
diff --git a/lib/lp/codehosting/bzrutils.py b/lib/lp/codehosting/bzrutils.py
index ad0fe37..43e7abb 100644
--- a/lib/lp/codehosting/bzrutils.py
+++ b/lib/lp/codehosting/bzrutils.py
@@ -312,7 +312,7 @@ def get_branch_info(branch):
     """
     info = {}
     info["stacked_on_url"] = get_stacked_on_url(branch)
-    info["last_revision_id"] = six.ensure_str(branch.last_revision())
+    info["last_revision_id"] = branch.last_revision().decode()
     # XXX: Aaron Bentley 2008-06-13
     # Bazaar does not provide a public API for learning about
     # format markers.  Fix this in Bazaar, then here.
diff --git a/lib/lp/codehosting/puller/tests/test_acceptance.py b/lib/lp/codehosting/puller/tests/test_acceptance.py
index beae357..37657bf 100644
--- a/lib/lp/codehosting/puller/tests/test_acceptance.py
+++ b/lib/lp/codehosting/puller/tests/test_acceptance.py
@@ -9,7 +9,6 @@ __all__ = []
 import os
 from subprocess import PIPE, Popen
 
-import six
 import transaction
 from breezy import errors
 from breezy.branch import Branch
@@ -78,8 +77,7 @@ class TestBranchPuller(PullerBranchTestCase, LoomTestMixin):
         self.assertEqual(0, db_branch.mirror_failures)
         mirrored_branch = self.openBranchAsUser(db_branch, accessing_user)
         self.assertEqual(
-            six.ensure_text(source_branch.last_revision()),
-            db_branch.last_mirrored_id,
+            source_branch.last_revision().decode(), db_branch.last_mirrored_id
         )
         self.assertEqual(
             source_branch.last_revision(), mirrored_branch.last_revision()
diff --git a/lib/lp/codehosting/puller/tests/test_scheduler.py b/lib/lp/codehosting/puller/tests/test_scheduler.py
index a221a90..ee089d0 100644
--- a/lib/lp/codehosting/puller/tests/test_scheduler.py
+++ b/lib/lp/codehosting/puller/tests/test_scheduler.py
@@ -698,7 +698,7 @@ class TestPullerMasterIntegration(PullerBranchTestCase):
                         LAUNCHPAD_SERVICES,
                         self.db_branch.id,
                         "",
-                        six.ensure_str(revision_id),
+                        revision_id.decode(),
                         control_string,
                         branch_string,
                         repository_string,
diff --git a/lib/lp/codehosting/scanner/bzrsync.py b/lib/lp/codehosting/scanner/bzrsync.py
index 92e7c45..637b007 100755
--- a/lib/lp/codehosting/scanner/bzrsync.py
+++ b/lib/lp/codehosting/scanner/bzrsync.py
@@ -15,7 +15,6 @@ __all__ = [
 import logging
 
 import pytz
-import six
 import transaction
 from breezy.graph import DictParentsProvider
 from breezy.revision import NULL_REVISION
@@ -85,8 +84,7 @@ class BzrSync:
         # if something is wrong with the branch.
         self.logger.info("Retrieving history from breezy.")
         bzr_history = [
-            six.ensure_text(revid)
-            for revid in branch_revision_history(bzr_branch)
+            revid.decode() for revid in branch_revision_history(bzr_branch)
         ]
         # The BranchRevision, Revision and RevisionParent tables are only
         # written to by the branch-scanner, so they are not subject to
@@ -154,9 +152,7 @@ class BzrSync:
             Revision.id == BranchRevision.revision_id,
         )
         parent_map = {
-            six.ensure_binary(r.revision_id): [
-                six.ensure_binary(revid) for revid in r.parent_ids
-            ]
+            r.revision_id.encode(): [revid.encode() for revid in r.parent_ids]
             for r in revisions
         }
         parents_provider = DictParentsProvider(parent_map)
@@ -176,16 +172,14 @@ class BzrSync:
             added_ancestry = get_ancestry(bzr_branch.repository, bzr_last)
             removed_ancestry = set()
         else:
-            db_last = six.ensure_binary(db_last)
+            db_last = db_last.encode()
             graph = self._getRevisionGraph(bzr_branch, db_last)
             added_ancestry, removed_ancestry = graph.find_difference(
                 bzr_last, db_last
             )
             added_ancestry.discard(NULL_REVISION)
-        added_ancestry = {six.ensure_text(revid) for revid in added_ancestry}
-        removed_ancestry = {
-            six.ensure_text(revid) for revid in removed_ancestry
-        }
+        added_ancestry = {revid.decode() for revid in added_ancestry}
+        removed_ancestry = {revid.decode() for revid in removed_ancestry}
         return added_ancestry, removed_ancestry
 
     def getHistoryDelta(self, bzr_history, db_history):
@@ -267,7 +261,7 @@ class BzrSync:
             Revision objects for.
         """
         revisions = bzr_branch.repository.get_parent_map(
-            [six.ensure_binary(revid) for revid in revisions]
+            [revid.encode() for revid in revisions]
         )
         return bzr_branch.repository.get_revisions(revisions.keys())
 
@@ -283,7 +277,7 @@ class BzrSync:
         self.revision_set.newFromBazaarRevisions(bzr_revisions)
         mainline_revisions = []
         for bzr_revision in bzr_revisions:
-            revision_id = six.ensure_text(bzr_revision.revision_id)
+            revision_id = bzr_revision.revision_id.decode()
             if revids_to_insert[revision_id] is None:
                 continue
             mainline_revisions.append(bzr_revision)
diff --git a/lib/lp/codehosting/scanner/email.py b/lib/lp/codehosting/scanner/email.py
index 68a3fba..95be256 100644
--- a/lib/lp/codehosting/scanner/email.py
+++ b/lib/lp/codehosting/scanner/email.py
@@ -8,7 +8,6 @@ __all__ = [
     "queue_tip_changed_email_jobs",
 ]
 
-import six
 from zope.component import getUtility
 
 from lp.code.enums import BranchSubscriptionNotificationLevel
@@ -87,7 +86,7 @@ def queue_tip_changed_email_jobs(tip_changed):
         job = getUtility(IRevisionsAddedJobSource).create(
             tip_changed.db_branch,
             tip_changed.db_branch.last_scanned_id,
-            six.ensure_text(tip_changed.bzr_branch.last_revision()),
+            tip_changed.bzr_branch.last_revision().decode(),
             config.canonical.noreply_from_address,
         )
     job.celeryRunOnCommit()
diff --git a/lib/lp/codehosting/scanner/events.py b/lib/lp/codehosting/scanner/events.py
index 442da4c..0615c22 100644
--- a/lib/lp/codehosting/scanner/events.py
+++ b/lib/lp/codehosting/scanner/events.py
@@ -9,7 +9,6 @@ __all__ = [
     "TipChanged",
 ]
 
-import six
 from zope.interface import implementer
 from zope.interface.interfaces import IObjectEvent, ObjectEvent
 
@@ -75,7 +74,7 @@ class TipChanged(ScannerEvent):
     @property
     def new_tip_revision_id(self):
         """The new tip revision id from this scan."""
-        return six.ensure_text(self.bzr_branch.last_revision())
+        return self.bzr_branch.last_revision().decode()
 
     @staticmethod
     def composeWebhookPayload(branch, old_revid, new_revid):
diff --git a/lib/lp/codehosting/scanner/mergedetection.py b/lib/lp/codehosting/scanner/mergedetection.py
index a28813b..37460d2 100644
--- a/lib/lp/codehosting/scanner/mergedetection.py
+++ b/lib/lp/codehosting/scanner/mergedetection.py
@@ -8,7 +8,6 @@ __all__ = [
     "auto_merge_proposals",
 ]
 
-import six
 from breezy.revision import NULL_REVISION
 from zope.component import getUtility
 
@@ -168,9 +167,7 @@ def auto_merge_proposals(scan_completed):
     for proposal in db_branch.landing_candidates:
         tip_rev_id = proposal.source_branch.last_scanned_id
         if tip_rev_id in new_ancestry:
-            merged_revno = find_merged_revno(
-                merge_sorted, six.ensure_binary(tip_rev_id)
-            )
+            merged_revno = find_merged_revno(merge_sorted, tip_rev_id.encode())
             # Remember so we can find the merged revision number.
             merge_detected(
                 logger,
diff --git a/lib/lp/codehosting/scanner/tests/test_bzrsync.py b/lib/lp/codehosting/scanner/tests/test_bzrsync.py
index bae6fa3..0b7f81c 100644
--- a/lib/lp/codehosting/scanner/tests/test_bzrsync.py
+++ b/lib/lp/codehosting/scanner/tests/test_bzrsync.py
@@ -9,7 +9,6 @@ import random
 import time
 
 import pytz
-import six
 from breezy.revision import NULL_REVISION
 from breezy.revision import Revision as BzrRevision
 from breezy.tests import TestCaseWithTransport
@@ -407,14 +406,14 @@ class TestBzrSync(BzrSyncTestCase):
         # test that the last scanned revision ID is recorded
         self.syncAndCount()
         self.assertEqual(
-            six.ensure_text(NULL_REVISION), self.db_branch.last_scanned_id
+            NULL_REVISION.decode(), self.db_branch.last_scanned_id
         )
         last_modified = self.db_branch.date_last_modified
         last_scanned = self.db_branch.last_scanned
         self.commitRevision()
         self.syncAndCount(new_revisions=1, new_numbers=1, new_authors=1)
         self.assertEqual(
-            six.ensure_text(self.bzr_branch.last_revision()),
+            self.bzr_branch.last_revision().decode(),
             self.db_branch.last_scanned_id,
         )
         self.assertTrue(
@@ -520,7 +519,7 @@ class TestBzrSync(BzrSyncTestCase):
         self.commitRevision(rev_id=b"rev-1")
         bzrsync = self.makeBzrSync(self.db_branch)
         bzr_history = [
-            six.ensure_text(revid)
+            revid.decode()
             for revid in branch_revision_history(self.bzr_branch)
         ]
         added_ancestry = bzrsync.getAncestryDelta(self.bzr_branch)[0]
@@ -537,7 +536,7 @@ class TestBzrSync(BzrSyncTestCase):
         )
         bzrsync = self.makeBzrSync(db_branch)
         bzr_history = [
-            six.ensure_text(revid)
+            revid.decode()
             for revid in branch_revision_history(bzr_tree.branch)
         ]
         added_ancestry = bzrsync.getAncestryDelta(bzr_tree.branch)[0]
@@ -632,19 +631,19 @@ class TestPlanDatabaseChanges(BzrSyncTestCase):
         # If a BranchRevision is being added, and it's already in the DB, but
         # not found through the graph operations, we should schedule it for
         # deletion anyway.
-        rev1_id = six.ensure_text(
-            self.bzr_tree.commit("initial commit", committer="me@xxxxxxxxxxx")
-        )
+        rev1_id = self.bzr_tree.commit(
+            "initial commit", committer="me@xxxxxxxxxxx"
+        ).decode()
         merge_tree = self.bzr_tree.controldir.sprout(
             "merge"
         ).open_workingtree()
-        merge_id = six.ensure_text(
-            merge_tree.commit("mergeable commit", committer="me@xxxxxxxxxxx")
-        )
+        merge_id = merge_tree.commit(
+            "mergeable commit", committer="me@xxxxxxxxxxx"
+        ).decode()
         self.bzr_tree.merge_from_branch(merge_tree.branch)
-        rev2_id = six.ensure_text(
-            self.bzr_tree.commit("merge", committer="me@xxxxxxxxxxx")
-        )
+        rev2_id = self.bzr_tree.commit(
+            "merge", committer="me@xxxxxxxxxxx"
+        ).decode()
         self.useContext(read_locked(self.bzr_tree))
         syncer = BzrSync(self.db_branch)
         syncer.syncBranchAndClose(self.bzr_tree.branch)
@@ -732,8 +731,8 @@ class TestBzrTranslationsUploadJob(BzrSyncTestCase):
         self._makeProductSeries(TranslationsBranchImportMode.IMPORT_TEMPLATES)
         revision_id = self.commitRevision()
         self.makeBzrSync(self.db_branch).syncBranchAndClose()
-        self.db_branch.last_mirrored_id = six.ensure_text(revision_id)
-        self.db_branch.last_scanned_id = six.ensure_text(revision_id)
+        self.db_branch.last_mirrored_id = revision_id.decode()
+        self.db_branch.last_scanned_id = revision_id.decode()
         ready_jobs = list(getUtility(IRosettaUploadJobSource).iterReady())
         self.assertEqual(1, len(ready_jobs))
         job = ready_jobs[0]
@@ -780,7 +779,7 @@ class TestGenerateIncrementalDiffJob(BzrSyncTestCase):
             parent_id,
             revision_date=self.factory.getUniqueDate(),
         )
-        self.db_branch.last_scanned_id = six.ensure_text(parent_id)
+        self.db_branch.last_scanned_id = parent_id.decode()
         # Make sure that the merge proposal is created in the past.
         date_created = datetime.datetime.now(pytz.UTC) - datetime.timedelta(
             days=7
@@ -794,8 +793,8 @@ class TestGenerateIncrementalDiffJob(BzrSyncTestCase):
         switch_dbuser("branchscanner")
         self.makeBzrSync(self.db_branch).syncBranchAndClose()
         (job,) = self.getPending()
-        self.assertEqual(six.ensure_text(revision_id), job.new_revision_id)
-        self.assertEqual(six.ensure_text(parent_id), job.old_revision_id)
+        self.assertEqual(revision_id.decode(), job.new_revision_id)
+        self.assertEqual(parent_id.decode(), job.old_revision_id)
 
 
 class TestSetRecipeStale(BzrSyncTestCase):
@@ -879,7 +878,7 @@ class TestTriggerWebhooks(BzrSyncTestCase):
                 target=self.db_branch, event_types=["bzr:push:0.1"]
             )
         self.commitRevision()
-        new_revid = six.ensure_text(self.bzr_branch.last_revision())
+        new_revid = self.bzr_branch.last_revision().decode()
         self.makeBzrSync(self.db_branch).syncBranchAndClose()
         delivery = hook.deliveries.one()
         payload_matcher = MatchesDict(
diff --git a/lib/lp/codehosting/scanner/tests/test_mergedetection.py b/lib/lp/codehosting/scanner/tests/test_mergedetection.py
index b37b585..5c9da31 100644
--- a/lib/lp/codehosting/scanner/tests/test_mergedetection.py
+++ b/lib/lp/codehosting/scanner/tests/test_mergedetection.py
@@ -5,7 +5,6 @@
 
 import logging
 
-import six
 import transaction
 from breezy.revision import NULL_REVISION
 from lazr.lifecycle.event import ObjectModifiedEvent
@@ -262,7 +261,7 @@ class TestMergeDetection(TestCaseWithFactory):
         # of the branch is the NULL_REVISION no merge event is emitted for
         # that branch.
         source = self.factory.makeProductBranch(product=self.product)
-        source.last_scanned_id = six.ensure_text(NULL_REVISION)
+        source.last_scanned_id = NULL_REVISION.decode()
         self.autoMergeBranches(self.db_branch, ["revid"])
         self.assertEqual([], self.merges)
 
diff --git a/lib/lp/codehosting/tests/test_acceptance.py b/lib/lp/codehosting/tests/test_acceptance.py
index c9bb224..52a87f5 100644
--- a/lib/lp/codehosting/tests/test_acceptance.py
+++ b/lib/lp/codehosting/tests/test_acceptance.py
@@ -9,7 +9,6 @@ import xmlrpc.client
 from urllib.request import urlopen
 
 import breezy.branch
-import six
 from breezy.tests import TestCaseWithTransport
 from breezy.tests.per_repository import all_repository_format_scenarios
 from breezy.urlutils import local_path_from_url
@@ -111,7 +110,7 @@ class SSHTestCase(TestCaseWithTransport, LoomTestMixin, TestCaseWithFactory):
         self.local_branch_path = local_path_from_url(self.local_branch.base)
         self.build_tree(["local/foo"])
         tree.add("foo")
-        self.revid = six.ensure_text(tree.commit("Added foo"))
+        self.revid = tree.commit("Added foo").decode()
 
     def __str__(self):
         return self.id()
diff --git a/lib/lp/codehosting/vfs/tests/test_branchfs.py b/lib/lp/codehosting/vfs/tests/test_branchfs.py
index cccecc3..5d9c713 100644
--- a/lib/lp/codehosting/vfs/tests/test_branchfs.py
+++ b/lib/lp/codehosting/vfs/tests/test_branchfs.py
@@ -1040,8 +1040,7 @@ class TestBranchChangedNotification(TestCaseWithTransport):
         branch.unlock()
         self.assertEqual(1, len(self._branch_changed_log))
         self.assertEqual(
-            six.ensure_text(revid),
-            self._branch_changed_log[0]["last_revision"],
+            revid.decode(), self._branch_changed_log[0]["last_revision"]
         )
 
     def assertStackedOnIsRewritten(self, input, output):
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 6703b9d..61b3c6f 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -932,9 +932,7 @@ class TestCaseWithFactory(TestCase):
         if parent:
             bzr_branch.pull(parent)
             naked_branch = removeSecurityProxy(db_branch)
-            naked_branch.last_scanned_id = six.ensure_text(
-                bzr_branch.last_revision()
-            )
+            naked_branch.last_scanned_id = bzr_branch.last_revision().decode()
         return bzr_branch
 
     def useTempBzrHome(self):
diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
index 6d6424c..2c14674 100644
--- a/lib/lp/testing/factory.py
+++ b/lib/lp/testing/factory.py
@@ -1955,8 +1955,10 @@ class LaunchpadObjectFactory(ObjectFactory):
             parent_ids = []
         if rev_id is None:
             rev_id = self.getUniqueUnicode("revision-id")
+        elif isinstance(rev_id, bytes):
+            rev_id = rev_id.decode()
         else:
-            rev_id = six.ensure_text(rev_id)
+            rev_id = rev_id
         if log_body is None:
             log_body = self.getUniqueString("log-body")
         return getUtility(IRevisionSet).new(
diff --git a/lib/lp/translations/scripts/tests/test_translations_to_branch.py b/lib/lp/translations/scripts/tests/test_translations_to_branch.py
index 50dc2e0..414e6ae 100644
--- a/lib/lp/translations/scripts/tests/test_translations_to_branch.py
+++ b/lib/lp/translations/scripts/tests/test_translations_to_branch.py
@@ -8,7 +8,6 @@ import re
 from textwrap import dedent
 
 import pytz
-import six
 import transaction
 from breezy.errors import NotBranchError
 from testtools.matchers import MatchesRegex
@@ -174,8 +173,7 @@ class TestExportTranslationsToBranch(TestCaseWithFactory):
         self.becomeDbUser("translationstobranch")
         self.assertFalse(db_branch.pending_writes)
         self.assertNotEqual(
-            db_branch.last_mirrored_id,
-            six.ensure_text(tree.branch.last_revision()),
+            db_branch.last_mirrored_id, tree.branch.last_revision().decode()
         )
         # The export code works on a Branch from the standby store.  It
         # shouldn't stop the scan request.
@@ -184,8 +182,7 @@ class TestExportTranslationsToBranch(TestCaseWithFactory):
         )
         exporter._exportToBranch(standby_series)
         self.assertEqual(
-            db_branch.last_mirrored_id,
-            six.ensure_text(tree.branch.last_revision()),
+            db_branch.last_mirrored_id, tree.branch.last_revision().decode()
         )
         self.assertTrue(db_branch.pending_writes)
         matches = MatchesRegex(
diff --git a/lib/lp/translations/tests/test_rosetta_branches_script.py b/lib/lp/translations/tests/test_rosetta_branches_script.py
index c0e950a..3044270 100644
--- a/lib/lp/translations/tests/test_rosetta_branches_script.py
+++ b/lib/lp/translations/tests/test_rosetta_branches_script.py
@@ -7,7 +7,6 @@ This would normally be done in a doctest but TestCaseWithFactory has all the
 provisions to handle Bazaar branches.
 """
 
-import six
 import transaction
 from breezy.revision import NULL_REVISION
 from zope.component import getUtility
@@ -48,8 +47,8 @@ class TestRosettaBranchesScript(TestCaseWithFactory):
         # required to generate the revision-id.
         with override_environ(BRZ_EMAIL="me@xxxxxxxxxxx"):
             revision_id = tree.commit("first commit")
-        branch.last_scanned_id = six.ensure_text(revision_id)
-        branch.last_mirrored_id = six.ensure_text(revision_id)
+        branch.last_scanned_id = revision_id.decode()
+        branch.last_mirrored_id = revision_id.decode()
         series = self.factory.makeProductSeries()
         series.branch = branch
         series.translations_autoimport_mode = (