diff hgext/largefiles/overrides.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children eef9a2d67051
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/largefiles/overrides.py	Sun Oct 06 09:48:39 2019 -0400
@@ -88,9 +88,9 @@
 
     lfmatcher = None
     if lfutil.islfilesrepo(repo):
-        lfpats = ui.configlist(lfutil.longname, 'patterns')
+        lfpats = ui.configlist(lfutil.longname, b'patterns')
         if lfpats:
-            lfmatcher = matchmod.match(repo.root, '', list(lfpats))
+            lfmatcher = matchmod.match(repo.root, b'', list(lfpats))
 
     lfnames = []
     m = matcher
@@ -106,7 +106,7 @@
         # The normal add code will do that for us.
         if exact and exists:
             if lfile:
-                ui.warn(_('%s already a largefile\n') % uipathfn(f))
+                ui.warn(_(b'%s already a largefile\n') % uipathfn(f))
             continue
 
         if (exact or not exists) and not lfutil.isstandin(f):
@@ -121,7 +121,7 @@
             if large or abovemin or (lfmatcher and lfmatcher(f)):
                 lfnames.append(f)
                 if ui.verbose or not exact:
-                    ui.status(_('adding %s as a largefile\n') % uipathfn(f))
+                    ui.status(_(b'adding %s as a largefile\n') % uipathfn(f))
 
     bad = []
 
@@ -136,11 +136,11 @@
                 lfutil.writestandin(
                     repo,
                     standinname,
-                    hash='',
+                    hash=b'',
                     executable=lfutil.getexecutable(repo.wjoin(f)),
                 )
                 standins.append(standinname)
-                if lfdirstate[f] == 'r':
+                if lfdirstate[f] == b'r':
                     lfdirstate.normallookup(f)
                 else:
                     lfdirstate.add(f)
@@ -177,23 +177,23 @@
     if after:
         remove = deleted
         result = warn(
-            modified + added + clean, _('not removing %s: file still exists\n')
+            modified + added + clean, _(b'not removing %s: file still exists\n')
         )
     else:
         remove = deleted + clean
         result = warn(
             modified,
             _(
-                'not removing %s: file is modified (use -f'
-                ' to force removal)\n'
+                b'not removing %s: file is modified (use -f'
+                b' to force removal)\n'
             ),
         )
         result = (
             warn(
                 added,
                 _(
-                    'not removing %s: file has been marked for add'
-                    ' (use forget to undo)\n'
+                    b'not removing %s: file has been marked for add'
+                    b' (use forget to undo)\n'
                 ),
             )
             or result
@@ -205,7 +205,7 @@
         lfdirstate = lfutil.openlfdirstate(ui, repo)
         for f in sorted(remove):
             if ui.verbose or not m.exact(f):
-                ui.status(_('removing %s\n') % uipathfn(f))
+                ui.status(_(b'removing %s\n') % uipathfn(f))
 
             if not dryrun:
                 if not after:
@@ -234,7 +234,7 @@
 
 # For overriding mercurial.hgweb.webcommands so that largefiles will
 # appear at their right place in the manifests.
-@eh.wrapfunction(webcommands, 'decodepath')
+@eh.wrapfunction(webcommands, b'decodepath')
 def decodepath(orig, path):
     return lfutil.splitstandin(path) or path
 
@@ -243,28 +243,28 @@
 
 
 @eh.wrapcommand(
-    'add',
+    b'add',
     opts=[
-        ('', 'large', None, _('add as largefile')),
-        ('', 'normal', None, _('add as normal file')),
+        (b'', b'large', None, _(b'add as largefile')),
+        (b'', b'normal', None, _(b'add as normal file')),
         (
-            '',
-            'lfsize',
-            '',
+            b'',
+            b'lfsize',
+            b'',
             _(
-                'add all files above this size (in megabytes) '
-                'as largefiles (default: 10)'
+                b'add all files above this size (in megabytes) '
+                b'as largefiles (default: 10)'
             ),
         ),
     ],
 )
 def overrideadd(orig, ui, repo, *pats, **opts):
     if opts.get(r'normal') and opts.get(r'large'):
-        raise error.Abort(_('--normal cannot be used with --large'))
+        raise error.Abort(_(b'--normal cannot be used with --large'))
     return orig(ui, repo, *pats, **opts)
 
 
-@eh.wrapfunction(cmdutil, 'add')
+@eh.wrapfunction(cmdutil, b'add')
 def cmdutiladd(orig, ui, repo, matcher, prefix, uipathfn, explicitonly, **opts):
     # The --normal flag short circuits this override
     if opts.get(r'normal'):
@@ -280,7 +280,7 @@
     return bad
 
 
-@eh.wrapfunction(cmdutil, 'remove')
+@eh.wrapfunction(cmdutil, b'remove')
 def cmdutilremove(
     orig, ui, repo, matcher, prefix, uipathfn, after, force, subrepos, dryrun
 ):
@@ -304,7 +304,7 @@
     )
 
 
-@eh.wrapfunction(subrepo.hgsubrepo, 'status')
+@eh.wrapfunction(subrepo.hgsubrepo, b'status')
 def overridestatusfn(orig, repo, rev2, **opts):
     try:
         repo._repo.lfstatus = True
@@ -313,7 +313,7 @@
         repo._repo.lfstatus = False
 
 
-@eh.wrapcommand('status')
+@eh.wrapcommand(b'status')
 def overridestatus(orig, ui, repo, *pats, **opts):
     try:
         repo.lfstatus = True
@@ -322,7 +322,7 @@
         repo.lfstatus = False
 
 
-@eh.wrapfunction(subrepo.hgsubrepo, 'dirty')
+@eh.wrapfunction(subrepo.hgsubrepo, b'dirty')
 def overridedirty(orig, repo, ignoreupdate=False, missing=False):
     try:
         repo._repo.lfstatus = True
@@ -331,7 +331,7 @@
         repo._repo.lfstatus = False
 
 
-@eh.wrapcommand('log')
+@eh.wrapcommand(b'log')
 def overridelog(orig, ui, repo, *pats, **opts):
     def overridematchandpats(
         orig,
@@ -339,7 +339,7 @@
         pats=(),
         opts=None,
         globbed=False,
-        default='relpath',
+        default=b'relpath',
         badfn=None,
     ):
         """Matcher that merges root directory with .hglf, suitable for log.
@@ -360,13 +360,13 @@
         pats = set(p)
 
         def fixpats(pat, tostandin=lfutil.standin):
-            if pat.startswith('set:'):
+            if pat.startswith(b'set:'):
                 return pat
 
             kindpat = matchmod._patsplit(pat, None)
 
             if kindpat[0] is not None:
-                return kindpat[0] + ':' + tostandin(kindpat[1])
+                return kindpat[0] + b':' + tostandin(kindpat[1])
             return tostandin(kindpat[1])
 
         cwd = repo.getcwd()
@@ -388,7 +388,7 @@
                 if os.path.isabs(cwd):
                     f = f[len(back) :]
                 else:
-                    f = cwd + '/' + f
+                    f = cwd + b'/' + f
                 return back + lfutil.standin(f)
 
         else:
@@ -402,7 +402,7 @@
 
         for i in range(0, len(m._files)):
             # Don't add '.hglf' to m.files, since that is already covered by '.'
-            if m._files[i] == '.':
+            if m._files[i] == b'.':
                 continue
             standin = lfutil.standin(m._files[i])
             # If the "standin" is a directory, append instead of replace to
@@ -427,7 +427,7 @@
 
         m.matchfn = lfmatchfn
 
-        ui.debug('updated patterns: %s\n' % ', '.join(sorted(pats)))
+        ui.debug(b'updated patterns: %s\n' % b', '.join(sorted(pats)))
         return m, pats
 
     # For hg log --patch, the match object is used in two different senses:
@@ -443,35 +443,35 @@
         return lambda ctx: match
 
     wrappedmatchandpats = extensions.wrappedfunction(
-        scmutil, 'matchandpats', overridematchandpats
+        scmutil, b'matchandpats', overridematchandpats
     )
     wrappedmakefilematcher = extensions.wrappedfunction(
-        logcmdutil, '_makenofollowfilematcher', overridemakefilematcher
+        logcmdutil, b'_makenofollowfilematcher', overridemakefilematcher
     )
     with wrappedmatchandpats, wrappedmakefilematcher:
         return orig(ui, repo, *pats, **opts)
 
 
 @eh.wrapcommand(
-    'verify',
+    b'verify',
     opts=[
         (
-            '',
-            'large',
+            b'',
+            b'large',
             None,
-            _('verify that all largefiles in current revision exists'),
+            _(b'verify that all largefiles in current revision exists'),
         ),
         (
-            '',
-            'lfa',
+            b'',
+            b'lfa',
             None,
-            _('verify largefiles in all revisions, not just current'),
+            _(b'verify largefiles in all revisions, not just current'),
         ),
         (
-            '',
-            'lfc',
+            b'',
+            b'lfc',
             None,
-            _('verify local largefile contents, not just existence'),
+            _(b'verify local largefile contents, not just existence'),
         ),
     ],
 )
@@ -487,7 +487,8 @@
 
 
 @eh.wrapcommand(
-    'debugstate', opts=[('', 'large', None, _('display largefiles dirstate'))]
+    b'debugstate',
+    opts=[(b'', b'large', None, _(b'display largefiles dirstate'))],
 )
 def overridedebugstate(orig, ui, repo, *pats, **opts):
     large = opts.pop(r'large', False)
@@ -511,7 +512,7 @@
 # The overridden function filters the unknown files by removing any
 # largefiles. This makes the merge proceed and we can then handle this
 # case further in the overridden calculateupdates function below.
-@eh.wrapfunction(merge, '_checkunknownfile')
+@eh.wrapfunction(merge, b'_checkunknownfile')
 def overridecheckunknownfile(origfn, repo, wctx, mctx, f, f2=None):
     if lfutil.standin(repo.dirstate.normalize(f)) in wctx:
         return False
@@ -544,7 +545,7 @@
 # Finally, the merge.applyupdates function will then take care of
 # writing the files into the working copy and lfcommands.updatelfiles
 # will update the largefiles.
-@eh.wrapfunction(merge, 'calculateupdates')
+@eh.wrapfunction(merge, b'calculateupdates')
 def overridecalculateupdates(
     origfn, repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs
 ):
@@ -569,71 +570,71 @@
         standin = lfutil.standin(lfile)
         (lm, largs, lmsg) = actions.get(lfile, (None, None, None))
         (sm, sargs, smsg) = actions.get(standin, (None, None, None))
-        if sm in ('g', 'dc') and lm != 'r':
-            if sm == 'dc':
+        if sm in (b'g', b'dc') and lm != b'r':
+            if sm == b'dc':
                 f1, f2, fa, move, anc = sargs
                 sargs = (p2[f2].flags(), False)
             # Case 1: normal file in the working copy, largefile in
             # the second parent
             usermsg = (
                 _(
-                    'remote turned local normal file %s into a largefile\n'
-                    'use (l)argefile or keep (n)ormal file?'
-                    '$$ &Largefile $$ &Normal file'
+                    b'remote turned local normal file %s into a largefile\n'
+                    b'use (l)argefile or keep (n)ormal file?'
+                    b'$$ &Largefile $$ &Normal file'
                 )
                 % lfile
             )
             if repo.ui.promptchoice(usermsg, 0) == 0:  # pick remote largefile
-                actions[lfile] = ('r', None, 'replaced by standin')
-                actions[standin] = ('g', sargs, 'replaces standin')
+                actions[lfile] = (b'r', None, b'replaced by standin')
+                actions[standin] = (b'g', sargs, b'replaces standin')
             else:  # keep local normal file
-                actions[lfile] = ('k', None, 'replaces standin')
+                actions[lfile] = (b'k', None, b'replaces standin')
                 if branchmerge:
-                    actions[standin] = ('k', None, 'replaced by non-standin')
+                    actions[standin] = (b'k', None, b'replaced by non-standin')
                 else:
-                    actions[standin] = ('r', None, 'replaced by non-standin')
-        elif lm in ('g', 'dc') and sm != 'r':
-            if lm == 'dc':
+                    actions[standin] = (b'r', None, b'replaced by non-standin')
+        elif lm in (b'g', b'dc') and sm != b'r':
+            if lm == b'dc':
                 f1, f2, fa, move, anc = largs
                 largs = (p2[f2].flags(), False)
             # Case 2: largefile in the working copy, normal file in
             # the second parent
             usermsg = (
                 _(
-                    'remote turned local largefile %s into a normal file\n'
-                    'keep (l)argefile or use (n)ormal file?'
-                    '$$ &Largefile $$ &Normal file'
+                    b'remote turned local largefile %s into a normal file\n'
+                    b'keep (l)argefile or use (n)ormal file?'
+                    b'$$ &Largefile $$ &Normal file'
                 )
                 % lfile
             )
             if repo.ui.promptchoice(usermsg, 0) == 0:  # keep local largefile
                 if branchmerge:
                     # largefile can be restored from standin safely
-                    actions[lfile] = ('k', None, 'replaced by standin')
-                    actions[standin] = ('k', None, 'replaces standin')
+                    actions[lfile] = (b'k', None, b'replaced by standin')
+                    actions[standin] = (b'k', None, b'replaces standin')
                 else:
                     # "lfile" should be marked as "removed" without
                     # removal of itself
                     actions[lfile] = (
-                        'lfmr',
+                        b'lfmr',
                         None,
-                        'forget non-standin largefile',
+                        b'forget non-standin largefile',
                     )
 
                     # linear-merge should treat this largefile as 're-added'
-                    actions[standin] = ('a', None, 'keep standin')
+                    actions[standin] = (b'a', None, b'keep standin')
             else:  # pick remote normal file
-                actions[lfile] = ('g', largs, 'replaces standin')
-                actions[standin] = ('r', None, 'replaced by non-standin')
+                actions[lfile] = (b'g', largs, b'replaces standin')
+                actions[standin] = (b'r', None, b'replaced by non-standin')
 
     return actions, diverge, renamedelete
 
 
-@eh.wrapfunction(merge, 'recordupdates')
+@eh.wrapfunction(merge, b'recordupdates')
 def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata):
-    if 'lfmr' in actions:
+    if b'lfmr' in actions:
         lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
-        for lfile, args, msg in actions['lfmr']:
+        for lfile, args, msg in actions[b'lfmr']:
             # this should be executed before 'orig', to execute 'remove'
             # before all other actions
             repo.dirstate.remove(lfile)
@@ -646,7 +647,7 @@
 
 # Override filemerge to prompt the user about how they wish to merge
 # largefiles. This will handle identical edits without prompting the user.
-@eh.wrapfunction(filemerge, '_filemerge')
+@eh.wrapfunction(filemerge, b'_filemerge')
 def overridefilemerge(
     origfn, premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None
 ):
@@ -665,10 +666,10 @@
             dhash == ahash
             or repo.ui.promptchoice(
                 _(
-                    'largefile %s has a merge conflict\nancestor was %s\n'
-                    'you can keep (l)ocal %s or take (o)ther %s.\n'
-                    'what do you want to do?'
-                    '$$ &Local $$ &Other'
+                    b'largefile %s has a merge conflict\nancestor was %s\n'
+                    b'you can keep (l)ocal %s or take (o)ther %s.\n'
+                    b'what do you want to do?'
+                    b'$$ &Local $$ &Other'
                 )
                 % (lfutil.splitstandin(orig), ahash, dhash, ohash),
                 0,
@@ -680,7 +681,7 @@
     return True, 0, False
 
 
-@eh.wrapfunction(copiesmod, 'pathcopies')
+@eh.wrapfunction(copiesmod, b'pathcopies')
 def copiespathcopies(orig, ctx1, ctx2, match=None):
     copies = orig(ctx1, ctx2, match=match)
     updated = {}
@@ -696,7 +697,7 @@
 # checks if the destination largefile already exists. It also keeps a
 # list of copied files so that the largefiles can be copied and the
 # dirstate updated.
-@eh.wrapfunction(cmdutil, 'copy')
+@eh.wrapfunction(cmdutil, b'copy')
 def overridecopy(orig, ui, repo, pats, opts, rename=False):
     # doesn't remove largefile on rename
     if len(pats) < 2:
@@ -717,7 +718,7 @@
         pats=(),
         opts=None,
         globbed=False,
-        default='relpath',
+        default=b'relpath',
         badfn=None,
     ):
         if opts is None:
@@ -725,11 +726,11 @@
         match = orig(ctx, pats, opts, globbed, default, badfn=badfn)
         return composenormalfilematcher(match, manifest)
 
-    with extensions.wrappedfunction(scmutil, 'match', normalfilesmatchfn):
+    with extensions.wrappedfunction(scmutil, b'match', normalfilesmatchfn):
         try:
             result = orig(ui, repo, pats, opts, rename)
         except error.Abort as e:
-            if pycompat.bytestr(e) != _('no files to copy'):
+            if pycompat.bytestr(e) != _(b'no files to copy'):
                 raise e
             else:
                 nonormalfiles = True
@@ -766,7 +767,7 @@
             pats=(),
             opts=None,
             globbed=False,
-            default='relpath',
+            default=b'relpath',
             badfn=None,
         ):
             if opts is None:
@@ -776,7 +777,7 @@
             # directory; we need to remove that now
             for pat in pats:
                 if matchmod.patkind(pat) is None and lfutil.shortname in pat:
-                    newpats.append(pat.replace(lfutil.shortname, ''))
+                    newpats.append(pat.replace(lfutil.shortname, b''))
                 else:
                     newpats.append(pat)
             match = orig(ctx, newpats, opts, globbed, default, badfn=badfn)
@@ -811,14 +812,16 @@
             if lfutil.shortname in src and dest.startswith(
                 repo.wjoin(lfutil.shortname)
             ):
-                destlfile = dest.replace(lfutil.shortname, '')
-                if not opts['force'] and os.path.exists(destlfile):
-                    raise IOError('', _('destination largefile already exists'))
+                destlfile = dest.replace(lfutil.shortname, b'')
+                if not opts[b'force'] and os.path.exists(destlfile):
+                    raise IOError(
+                        b'', _(b'destination largefile already exists')
+                    )
             copiedfiles.append((src, dest))
             orig(src, dest, *args, **kwargs)
 
-        with extensions.wrappedfunction(util, 'copyfile', overridecopyfile):
-            with extensions.wrappedfunction(scmutil, 'match', overridematch):
+        with extensions.wrappedfunction(util, b'copyfile', overridecopyfile):
+            with extensions.wrappedfunction(scmutil, b'match', overridematch):
                 result += orig(ui, repo, listpats, opts, rename)
 
         lfdirstate = lfutil.openlfdirstate(ui, repo)
@@ -826,9 +829,9 @@
             if lfutil.shortname in src and dest.startswith(
                 repo.wjoin(lfutil.shortname)
             ):
-                srclfile = src.replace(repo.wjoin(lfutil.standin('')), '')
-                destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '')
-                destlfiledir = repo.wvfs.dirname(repo.wjoin(destlfile)) or '.'
+                srclfile = src.replace(repo.wjoin(lfutil.standin(b'')), b'')
+                destlfile = dest.replace(repo.wjoin(lfutil.standin(b'')), b'')
+                destlfiledir = repo.wvfs.dirname(repo.wjoin(destlfile)) or b'.'
                 if not os.path.isdir(destlfiledir):
                     os.makedirs(destlfiledir)
                 if rename:
@@ -844,7 +847,7 @@
                 lfdirstate.add(destlfile)
         lfdirstate.write()
     except error.Abort as e:
-        if pycompat.bytestr(e) != _('no files to copy'):
+        if pycompat.bytestr(e) != _(b'no files to copy'):
             raise e
         else:
             nolfiles = True
@@ -852,7 +855,7 @@
         wlock.release()
 
     if nolfiles and nonormalfiles:
-        raise error.Abort(_('no files to copy'))
+        raise error.Abort(_(b'no files to copy'))
 
     return result
 
@@ -866,7 +869,7 @@
 # commits. Update the standins then run the original revert, changing
 # the matcher to hit standins instead of largefiles. Based on the
 # resulting standins update the largefiles.
-@eh.wrapfunction(cmdutil, 'revert')
+@eh.wrapfunction(cmdutil, b'revert')
 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts):
     # Because we put the standins in a bad state (by updating them)
     # and then return them to a correct state we need to lock to
@@ -890,7 +893,7 @@
             pats=(),
             opts=None,
             globbed=False,
-            default='relpath',
+            default=b'relpath',
             badfn=None,
         ):
             if opts is None:
@@ -912,7 +915,7 @@
                 standin = lfutil.standin(f)
                 if standin in ctx or standin in mctx:
                     matchfiles.append(standin)
-                elif standin in wctx or lfdirstate[f] == 'r':
+                elif standin in wctx or lfdirstate[f] == b'r':
                     continue
                 else:
                     matchfiles.append(f)
@@ -929,7 +932,7 @@
             m.matchfn = matchfn
             return m
 
-        with extensions.wrappedfunction(scmutil, 'match', overridematch):
+        with extensions.wrappedfunction(scmutil, b'match', overridematch):
             orig(ui, repo, ctx, parents, *pats, **opts)
 
         newstandins = lfutil.getstandinsstate(repo)
@@ -947,51 +950,57 @@
 # after pulling changesets, we need to take some extra care to get
 # largefiles updated remotely
 @eh.wrapcommand(
-    'pull',
+    b'pull',
     opts=[
         (
-            '',
-            'all-largefiles',
+            b'',
+            b'all-largefiles',
             None,
-            _('download all pulled versions of largefiles (DEPRECATED)'),
+            _(b'download all pulled versions of largefiles (DEPRECATED)'),
         ),
         (
-            '',
-            'lfrev',
+            b'',
+            b'lfrev',
             [],
-            _('download largefiles for these revisions'),
-            _('REV'),
+            _(b'download largefiles for these revisions'),
+            _(b'REV'),
         ),
     ],
 )
 def overridepull(orig, ui, repo, source=None, **opts):
     revsprepull = len(repo)
     if not source:
-        source = 'default'
+        source = b'default'
     repo.lfpullsource = source
     result = orig(ui, repo, source, **opts)
     revspostpull = len(repo)
     lfrevs = opts.get(r'lfrev', [])
     if opts.get(r'all_largefiles'):
-        lfrevs.append('pulled()')
+        lfrevs.append(b'pulled()')
     if lfrevs and revspostpull > revsprepull:
         numcached = 0
         repo.firstpulled = revsprepull  # for pulled() revset expression
         try:
             for rev in scmutil.revrange(repo, lfrevs):
-                ui.note(_('pulling largefiles for revision %d\n') % rev)
+                ui.note(_(b'pulling largefiles for revision %d\n') % rev)
                 (cached, missing) = lfcommands.cachelfiles(ui, repo, rev)
                 numcached += len(cached)
         finally:
             del repo.firstpulled
-        ui.status(_("%d largefiles cached\n") % numcached)
+        ui.status(_(b"%d largefiles cached\n") % numcached)
     return result
 
 
 @eh.wrapcommand(
-    'push',
+    b'push',
     opts=[
-        ('', 'lfrev', [], _('upload largefiles for these revisions'), _('REV'))
+        (
+            b'',
+            b'lfrev',
+            [],
+            _(b'upload largefiles for these revisions'),
+            _(b'REV'),
+        )
     ],
 )
 def overridepush(orig, ui, repo, *args, **kwargs):
@@ -999,11 +1008,11 @@
     lfrevs = kwargs.pop(r'lfrev', None)
     if lfrevs:
         opargs = kwargs.setdefault(r'opargs', {})
-        opargs['lfrevs'] = scmutil.revrange(repo, lfrevs)
+        opargs[b'lfrevs'] = scmutil.revrange(repo, lfrevs)
     return orig(ui, repo, *args, **kwargs)
 
 
-@eh.wrapfunction(exchange, 'pushoperation')
+@eh.wrapfunction(exchange, b'pushoperation')
 def exchangepushoperation(orig, *args, **kwargs):
     """Override pushoperation constructor and store lfrevs parameter"""
     lfrevs = kwargs.pop(r'lfrevs', None)
@@ -1012,7 +1021,7 @@
     return pushop
 
 
-@eh.revsetpredicate('pulled()')
+@eh.revsetpredicate(b'pulled()')
 def pulledrevsetsymbol(repo, subset, x):
     """Changesets that just has been pulled.
 
@@ -1035,18 +1044,18 @@
     try:
         firstpulled = repo.firstpulled
     except AttributeError:
-        raise error.Abort(_("pulled() only available in --lfrev"))
+        raise error.Abort(_(b"pulled() only available in --lfrev"))
     return smartset.baseset([r for r in subset if r >= firstpulled])
 
 
 @eh.wrapcommand(
-    'clone',
+    b'clone',
     opts=[
         (
-            '',
-            'all-largefiles',
+            b'',
+            b'all-largefiles',
             None,
-            _('download all versions of all largefiles'),
+            _(b'download all versions of all largefiles'),
         )
     ],
 )
@@ -1056,14 +1065,14 @@
         d = hg.defaultdest(source)
     if opts.get(r'all_largefiles') and not hg.islocal(d):
         raise error.Abort(
-            _('--all-largefiles is incompatible with non-local destination %s')
+            _(b'--all-largefiles is incompatible with non-local destination %s')
             % d
         )
 
     return orig(ui, source, dest, **opts)
 
 
-@eh.wrapfunction(hg, 'clone')
+@eh.wrapfunction(hg, b'clone')
 def hgclone(orig, ui, opts, *args, **kwargs):
     result = orig(ui, opts, *args, **kwargs)
 
@@ -1080,7 +1089,7 @@
         # Caching is implicitly limited to 'rev' option, since the dest repo was
         # truncated at that point.  The user may expect a download count with
         # this option, so attempt whether or not this is a largefile repo.
-        if opts.get('all_largefiles'):
+        if opts.get(b'all_largefiles'):
             success, missing = lfcommands.downloadlfiles(ui, repo, None)
 
             if missing != 0:
@@ -1089,9 +1098,9 @@
     return result
 
 
-@eh.wrapcommand('rebase', extension='rebase')
+@eh.wrapcommand(b'rebase', extension=b'rebase')
 def overriderebase(orig, ui, repo, **opts):
-    if not util.safehasattr(repo, '_largefilesenabled'):
+    if not util.safehasattr(repo, b'_largefilesenabled'):
         return orig(ui, repo, **opts)
 
     resuming = opts.get(r'continue')
@@ -1104,7 +1113,7 @@
         repo._lfcommithooks.pop()
 
 
-@eh.wrapcommand('archive')
+@eh.wrapcommand(b'archive')
 def overridearchivecmd(orig, ui, repo, dest, **opts):
     repo.unfiltered().lfstatus = True
 
@@ -1114,7 +1123,7 @@
         repo.unfiltered().lfstatus = False
 
 
-@eh.wrapfunction(webcommands, 'archive')
+@eh.wrapfunction(webcommands, b'archive')
 def hgwebarchive(orig, web):
     web.repo.lfstatus = True
 
@@ -1124,7 +1133,7 @@
         web.repo.lfstatus = False
 
 
-@eh.wrapfunction(archival, 'archive')
+@eh.wrapfunction(archival, b'archive')
 def overridearchive(
     orig,
     repo,
@@ -1133,7 +1142,7 @@
     kind,
     decode=True,
     match=None,
-    prefix='',
+    prefix=b'',
     mtime=None,
     subrepos=None,
 ):
@@ -1150,13 +1159,13 @@
         lfcommands.cachelfiles(repo.ui, repo, node)
 
     if kind not in archival.archivers:
-        raise error.Abort(_("unknown archive type '%s'") % kind)
+        raise error.Abort(_(b"unknown archive type '%s'") % kind)
 
     ctx = repo[node]
 
-    if kind == 'files':
+    if kind == b'files':
         if prefix:
-            raise error.Abort(_('cannot give prefix when archiving to files'))
+            raise error.Abort(_(b'cannot give prefix when archiving to files'))
     else:
         prefix = archival.tidyprefix(dest, kind, prefix)
 
@@ -1170,9 +1179,9 @@
 
     archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
 
-    if repo.ui.configbool("ui", "archivemeta"):
+    if repo.ui.configbool(b"ui", b"archivemeta"):
         write(
-            '.hg_archival.txt',
+            b'.hg_archival.txt',
             0o644,
             False,
             lambda: archival.buildmetadata(ctx),
@@ -1189,7 +1198,7 @@
                 if path is None:
                     raise error.Abort(
                         _(
-                            'largefile %s not found in repo store or system cache'
+                            b'largefile %s not found in repo store or system cache'
                         )
                         % lfile
                     )
@@ -1199,26 +1208,26 @@
             f = lfile
 
             getdata = lambda: util.readfile(path)
-        write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
+        write(f, b'x' in ff and 0o755 or 0o644, b'l' in ff, getdata)
 
     if subrepos:
         for subpath in sorted(ctx.substate):
             sub = ctx.workingsub(subpath)
             submatch = matchmod.subdirmatcher(subpath, match)
-            subprefix = prefix + subpath + '/'
+            subprefix = prefix + subpath + b'/'
             sub._repo.lfstatus = True
             sub.archive(archiver, subprefix, submatch)
 
     archiver.done()
 
 
-@eh.wrapfunction(subrepo.hgsubrepo, 'archive')
+@eh.wrapfunction(subrepo.hgsubrepo, b'archive')
 def hgsubrepoarchive(orig, repo, archiver, prefix, match=None, decode=True):
-    lfenabled = util.safehasattr(repo._repo, '_largefilesenabled')
+    lfenabled = util.safehasattr(repo._repo, b'_largefilesenabled')
     if not lfenabled or not repo._repo.lfstatus:
         return orig(repo, archiver, prefix, match, decode)
 
-    repo._get(repo._state + ('hg',))
+    repo._get(repo._state + (b'hg',))
     rev = repo._state[1]
     ctx = repo._repo[rev]
 
@@ -1247,7 +1256,7 @@
                 if path is None:
                     raise error.Abort(
                         _(
-                            'largefile %s not found in repo store or system cache'
+                            b'largefile %s not found in repo store or system cache'
                         )
                         % lfile
                     )
@@ -1258,12 +1267,12 @@
 
             getdata = lambda: util.readfile(os.path.join(prefix, path))
 
-        write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
+        write(f, b'x' in ff and 0o755 or 0o644, b'l' in ff, getdata)
 
     for subpath in sorted(ctx.substate):
         sub = ctx.workingsub(subpath)
         submatch = matchmod.subdirmatcher(subpath, match)
-        subprefix = prefix + subpath + '/'
+        subprefix = prefix + subpath + b'/'
         sub._repo.lfstatus = True
         sub.archive(archiver, subprefix, submatch, decode)
 
@@ -1272,17 +1281,17 @@
 # standin until a commit. cmdutil.bailifchanged() raises an exception
 # if the repo has uncommitted changes. Wrap it to also check if
 # largefiles were changed. This is used by bisect, backout and fetch.
-@eh.wrapfunction(cmdutil, 'bailifchanged')
+@eh.wrapfunction(cmdutil, b'bailifchanged')
 def overridebailifchanged(orig, repo, *args, **kwargs):
     orig(repo, *args, **kwargs)
     repo.lfstatus = True
     s = repo.status()
     repo.lfstatus = False
     if s.modified or s.added or s.removed or s.deleted:
-        raise error.Abort(_('uncommitted changes'))
+        raise error.Abort(_(b'uncommitted changes'))
 
 
-@eh.wrapfunction(cmdutil, 'postcommitstatus')
+@eh.wrapfunction(cmdutil, b'postcommitstatus')
 def postcommitstatus(orig, repo, *args, **kwargs):
     repo.lfstatus = True
     try:
@@ -1291,7 +1300,7 @@
         repo.lfstatus = False
 
 
-@eh.wrapfunction(cmdutil, 'forget')
+@eh.wrapfunction(cmdutil, b'forget')
 def cmdutilforget(
     orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive
 ):
@@ -1321,20 +1330,20 @@
         fstandin = lfutil.standin(f)
         if fstandin not in repo.dirstate and not repo.wvfs.isdir(fstandin):
             ui.warn(
-                _('not removing %s: file is already untracked\n') % uipathfn(f)
+                _(b'not removing %s: file is already untracked\n') % uipathfn(f)
             )
             bad.append(f)
 
     for f in forget:
         if ui.verbose or not m.exact(f):
-            ui.status(_('removing %s\n') % uipathfn(f))
+            ui.status(_(b'removing %s\n') % uipathfn(f))
 
     # Need to lock because standin files are deleted then removed from the
     # repository and we could race in-between.
     with repo.wlock():
         lfdirstate = lfutil.openlfdirstate(ui, repo)
         for f in forget:
-            if lfdirstate[f] == 'a':
+            if lfdirstate[f] == b'a':
                 lfdirstate.drop(f)
             else:
                 lfdirstate.remove(f)
@@ -1376,7 +1385,7 @@
 
 
 def outgoinghook(ui, repo, other, opts, missing):
-    if opts.pop('large', None):
+    if opts.pop(b'large', None):
         lfhashes = set()
         if ui.debugflag:
             toupload = {}
@@ -1389,7 +1398,7 @@
 
             def showhashes(fn):
                 for lfhash in sorted(toupload[fn]):
-                    ui.debug('    %s\n' % lfhash)
+                    ui.debug(b'    %s\n' % lfhash)
 
         else:
             toupload = set()
@@ -1404,19 +1413,19 @@
         _getoutgoings(repo, other, missing, addfunc)
 
         if not toupload:
-            ui.status(_('largefiles: no files to upload\n'))
+            ui.status(_(b'largefiles: no files to upload\n'))
         else:
             ui.status(
-                _('largefiles to upload (%d entities):\n') % (len(lfhashes))
+                _(b'largefiles to upload (%d entities):\n') % (len(lfhashes))
             )
             for file in sorted(toupload):
-                ui.status(lfutil.splitstandin(file) + '\n')
+                ui.status(lfutil.splitstandin(file) + b'\n')
                 showhashes(file)
-            ui.status('\n')
+            ui.status(b'\n')
 
 
 @eh.wrapcommand(
-    'outgoing', opts=[('', 'large', None, _('display outgoing largefiles'))]
+    b'outgoing', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))]
 )
 def _outgoingcmd(orig, *args, **kwargs):
     # Nothing to do here other than add the extra help option- the hook above
@@ -1425,7 +1434,7 @@
 
 
 def summaryremotehook(ui, repo, opts, changes):
-    largeopt = opts.get('large', False)
+    largeopt = opts.get(b'large', False)
     if changes is None:
         if largeopt:
             return (False, True)  # only outgoing check is needed
@@ -1435,7 +1444,7 @@
         url, branch, peer, outgoing = changes[1]
         if peer is None:
             # i18n: column positioning for "hg summary"
-            ui.status(_('largefiles: (no remote repo)\n'))
+            ui.status(_(b'largefiles: (no remote repo)\n'))
             return
 
         toupload = set()
@@ -1449,17 +1458,17 @@
 
         if not toupload:
             # i18n: column positioning for "hg summary"
-            ui.status(_('largefiles: (no files to upload)\n'))
+            ui.status(_(b'largefiles: (no files to upload)\n'))
         else:
             # i18n: column positioning for "hg summary"
             ui.status(
-                _('largefiles: %d entities for %d files to upload\n')
+                _(b'largefiles: %d entities for %d files to upload\n')
                 % (len(lfhashes), len(toupload))
             )
 
 
 @eh.wrapcommand(
-    'summary', opts=[('', 'large', None, _('display outgoing largefiles'))]
+    b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))]
 )
 def overridesummary(orig, ui, repo, *pats, **opts):
     try:
@@ -1469,7 +1478,7 @@
         repo.lfstatus = False
 
 
-@eh.wrapfunction(scmutil, 'addremove')
+@eh.wrapfunction(scmutil, b'addremove')
 def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None):
     if opts is None:
         opts = {}
@@ -1505,7 +1514,7 @@
             True,
             m,
             uipathfn,
-            opts.get('dry_run'),
+            opts.get(b'dry_run'),
             **pycompat.strkwargs(opts)
         )
     # Call into the normal add code, and any files that *should* be added as
@@ -1522,7 +1531,7 @@
 
 # Calling purge with --all will cause the largefiles to be deleted.
 # Override repo.status to prevent this from happening.
-@eh.wrapcommand('purge', extension='purge')
+@eh.wrapcommand(b'purge', extension=b'purge')
 def overridepurge(orig, ui, repo, *dirs, **opts):
     # XXX Monkey patching a repoview will not work. The assigned attribute will
     # be set on the unfiltered repo, but we will only lookup attributes in the
@@ -1537,7 +1546,7 @@
     oldstatus = repo.status
 
     def overridestatus(
-        node1='.',
+        node1=b'.',
         node2=None,
         match=None,
         ignored=False,
@@ -1549,8 +1558,8 @@
             node1, node2, match, ignored, clean, unknown, listsubrepos
         )
         lfdirstate = lfutil.openlfdirstate(ui, repo)
-        unknown = [f for f in r.unknown if lfdirstate[f] == '?']
-        ignored = [f for f in r.ignored if lfdirstate[f] == '?']
+        unknown = [f for f in r.unknown if lfdirstate[f] == b'?']
+        ignored = [f for f in r.ignored if lfdirstate[f] == b'?']
         return scmutil.status(
             r.modified, r.added, r.removed, r.deleted, unknown, ignored, r.clean
         )
@@ -1560,25 +1569,25 @@
     repo.status = oldstatus
 
 
-@eh.wrapcommand('rollback')
+@eh.wrapcommand(b'rollback')
 def overriderollback(orig, ui, repo, **opts):
     with repo.wlock():
         before = repo.dirstate.parents()
         orphans = set(
             f
             for f in repo.dirstate
-            if lfutil.isstandin(f) and repo.dirstate[f] != 'r'
+            if lfutil.isstandin(f) and repo.dirstate[f] != b'r'
         )
         result = orig(ui, repo, **opts)
         after = repo.dirstate.parents()
         if before == after:
             return result  # no need to restore standins
 
-        pctx = repo['.']
+        pctx = repo[b'.']
         for f in repo.dirstate:
             if lfutil.isstandin(f):
                 orphans.discard(f)
-                if repo.dirstate[f] == 'r':
+                if repo.dirstate[f] == b'r':
                     repo.wvfs.unlinkpath(f, ignoremissing=True)
                 elif f in pctx:
                     fctx = pctx[f]
@@ -1586,7 +1595,7 @@
                 else:
                     # content of standin is not so important in 'a',
                     # 'm' or 'n' (coming from the 2nd parent) cases
-                    lfutil.writestandin(repo, f, '', False)
+                    lfutil.writestandin(repo, f, b'', False)
         for standin in orphans:
             repo.wvfs.unlinkpath(standin, ignoremissing=True)
 
@@ -1602,7 +1611,7 @@
     return result
 
 
-@eh.wrapcommand('transplant', extension='transplant')
+@eh.wrapcommand(b'transplant', extension=b'transplant')
 def overridetransplant(orig, ui, repo, *revs, **opts):
     resuming = opts.get(r'continue')
     repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
@@ -1615,10 +1624,10 @@
     return result
 
 
-@eh.wrapcommand('cat')
+@eh.wrapcommand(b'cat')
 def overridecat(orig, ui, repo, file1, *pats, **opts):
     opts = pycompat.byteskwargs(opts)
-    ctx = scmutil.revsingle(repo, opts.get('rev'))
+    ctx = scmutil.revsingle(repo, opts.get(b'rev'))
     err = 1
     notbad = set()
     m = scmutil.match(ctx, (file1,) + pats, opts)
@@ -1658,12 +1667,12 @@
     m.visitdir = lfvisitdirfn
 
     for f in ctx.walk(m):
-        with cmdutil.makefileobj(ctx, opts.get('output'), pathname=f) as fp:
+        with cmdutil.makefileobj(ctx, opts.get(b'output'), pathname=f) as fp:
             lf = lfutil.splitstandin(f)
             if lf is None or origmatchfn(f):
                 # duplicating unreachable code from commands.cat
                 data = ctx[f].data()
-                if opts.get('decode'):
+                if opts.get(b'decode'):
                     data = repo.wwritedata(f, data)
                 fp.write(data)
             else:
@@ -1674,20 +1683,20 @@
                     if len(success) != 1:
                         raise error.Abort(
                             _(
-                                'largefile %s is not in cache and could not be '
-                                'downloaded'
+                                b'largefile %s is not in cache and could not be '
+                                b'downloaded'
                             )
                             % lf
                         )
                 path = lfutil.usercachepath(repo.ui, hash)
-                with open(path, "rb") as fpin:
+                with open(path, b"rb") as fpin:
                     for chunk in util.filechunkiter(fpin):
                         fp.write(chunk)
         err = 0
     return err
 
 
-@eh.wrapfunction(merge, 'update')
+@eh.wrapfunction(merge, b'update')
 def mergeupdate(orig, repo, node, branchmerge, force, *args, **kwargs):
     matcher = kwargs.get(r'matcher', None)
     # note if this is a partial update
@@ -1717,7 +1726,7 @@
             unknown=False,
         )
         oldclean = set(s.clean)
-        pctx = repo['.']
+        pctx = repo[b'.']
         dctx = repo[node]
         for lfile in unsure + s.modified:
             lfileabs = repo.wvfs.join(lfile)
@@ -1771,7 +1780,7 @@
         return result
 
 
-@eh.wrapfunction(scmutil, 'marktouched')
+@eh.wrapfunction(scmutil, b'marktouched')
 def scmutilmarktouched(orig, repo, files, *args, **kwargs):
     result = orig(repo, files, *args, **kwargs)
 
@@ -1792,23 +1801,23 @@
     return result
 
 
-@eh.wrapfunction(upgrade, 'preservedrequirements')
-@eh.wrapfunction(upgrade, 'supporteddestrequirements')
+@eh.wrapfunction(upgrade, b'preservedrequirements')
+@eh.wrapfunction(upgrade, b'supporteddestrequirements')
 def upgraderequirements(orig, repo):
     reqs = orig(repo)
-    if 'largefiles' in repo.requirements:
-        reqs.add('largefiles')
+    if b'largefiles' in repo.requirements:
+        reqs.add(b'largefiles')
     return reqs
 
 
-_lfscheme = 'largefile://'
+_lfscheme = b'largefile://'
 
 
-@eh.wrapfunction(urlmod, 'open')
+@eh.wrapfunction(urlmod, b'open')
 def openlargefile(orig, ui, url_, data=None):
     if url_.startswith(_lfscheme):
         if data:
-            msg = "cannot use data on a 'largefile://' url"
+            msg = b"cannot use data on a 'largefile://' url"
             raise error.ProgrammingError(msg)
         lfid = url_[len(_lfscheme) :]
         return storefactory.getlfile(ui, lfid)