diff hgext/relink.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/relink.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/relink.py	Sun Oct 06 09:48:39 2019 -0400
@@ -26,10 +26,12 @@
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
 # leave the attribute unspecified.
-testedwith = 'ships-with-hg-core'
+testedwith = b'ships-with-hg-core'
 
 
-@command('relink', [], _('[ORIGIN]'), helpcategory=command.CATEGORY_MAINTENANCE)
+@command(
+    b'relink', [], _(b'[ORIGIN]'), helpcategory=command.CATEGORY_MAINTENANCE
+)
 def relink(ui, repo, origin=None, **opts):
     """recreate hardlinks between two repositories
 
@@ -55,22 +57,22 @@
     command is running. (Both repositories will be locked against
     writes.)
     """
-    if not util.safehasattr(util, 'samefile') or not util.safehasattr(
-        util, 'samedevice'
+    if not util.safehasattr(util, b'samefile') or not util.safehasattr(
+        util, b'samedevice'
     ):
-        raise error.Abort(_('hardlinks are not supported on this system'))
+        raise error.Abort(_(b'hardlinks are not supported on this system'))
     src = hg.repository(
         repo.baseui,
-        ui.expandpath(origin or 'default-relink', origin or 'default'),
+        ui.expandpath(origin or b'default-relink', origin or b'default'),
     )
-    ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
+    ui.status(_(b'relinking %s to %s\n') % (src.store.path, repo.store.path))
     if repo.root == src.root:
-        ui.status(_('there is nothing to relink\n'))
+        ui.status(_(b'there is nothing to relink\n'))
         return
 
     if not util.samedevice(src.store.path, repo.store.path):
         # No point in continuing
-        raise error.Abort(_('source and destination are on different devices'))
+        raise error.Abort(_(b'source and destination are on different devices'))
 
     with repo.lock(), src.lock():
         candidates = sorted(collect(src, ui))
@@ -81,7 +83,7 @@
 def collect(src, ui):
     seplen = len(os.path.sep)
     candidates = []
-    live = len(src['tip'].manifest())
+    live = len(src[b'tip'].manifest())
     # Your average repository has some files which were deleted before
     # the tip revision. We account for that by assuming that there are
     # 3 tracked files for every 2 live files as of the tip version of
@@ -90,17 +92,17 @@
     # mozilla-central as of 2010-06-10 had a ratio of just over 7:5.
     total = live * 3 // 2
     src = src.store.path
-    progress = ui.makeprogress(_('collecting'), unit=_('files'), total=total)
+    progress = ui.makeprogress(_(b'collecting'), unit=_(b'files'), total=total)
     pos = 0
     ui.status(
-        _("tip has %d files, estimated total number of files: %d\n")
+        _(b"tip has %d files, estimated total number of files: %d\n")
         % (live, total)
     )
     for dirpath, dirnames, filenames in os.walk(src):
         dirnames.sort()
         relpath = dirpath[len(src) + seplen :]
         for filename in sorted(filenames):
-            if filename[-2:] not in ('.d', '.i'):
+            if filename[-2:] not in (b'.d', b'.i'):
                 continue
             st = os.stat(os.path.join(dirpath, filename))
             if not stat.S_ISREG(st.st_mode):
@@ -110,7 +112,7 @@
             progress.update(pos, item=filename)
 
     progress.complete()
-    ui.status(_('collected %d candidate storage files\n') % len(candidates))
+    ui.status(_(b'collected %d candidate storage files\n') % len(candidates))
     return candidates
 
 
@@ -126,7 +128,7 @@
         if not util.samedevice(src, dst):
             # No point in continuing
             raise error.Abort(
-                _('source and destination are on different devices')
+                _(b'source and destination are on different devices')
             )
         if st.st_size != ts.st_size:
             return False
@@ -134,7 +136,7 @@
 
     targets = []
     progress = ui.makeprogress(
-        _('pruning'), unit=_('files'), total=len(candidates)
+        _(b'pruning'), unit=_(b'files'), total=len(candidates)
     )
     pos = 0
     for fn, st in candidates:
@@ -143,19 +145,21 @@
         tgt = os.path.join(dst, fn)
         ts = linkfilter(srcpath, tgt, st)
         if not ts:
-            ui.debug('not linkable: %s\n' % fn)
+            ui.debug(b'not linkable: %s\n' % fn)
             continue
         targets.append((fn, ts.st_size))
         progress.update(pos, item=fn)
 
     progress.complete()
-    ui.status(_('pruned down to %d probably relinkable files\n') % len(targets))
+    ui.status(
+        _(b'pruned down to %d probably relinkable files\n') % len(targets)
+    )
     return targets
 
 
 def do_relink(src, dst, files, ui):
     def relinkfile(src, dst):
-        bak = dst + '.bak'
+        bak = dst + b'.bak'
         os.rename(dst, bak)
         try:
             util.oslink(src, dst)
@@ -169,7 +173,7 @@
     savedbytes = 0
 
     progress = ui.makeprogress(
-        _('relinking'), unit=_('files'), total=len(files)
+        _(b'relinking'), unit=_(b'files'), total=len(files)
     )
     pos = 0
     for f, sz in files:
@@ -177,8 +181,8 @@
         source = os.path.join(src, f)
         tgt = os.path.join(dst, f)
         # Binary mode, so that read() works correctly, especially on Windows
-        sfp = open(source, 'rb')
-        dfp = open(tgt, 'rb')
+        sfp = open(source, b'rb')
+        dfp = open(tgt, b'rb')
         sin = sfp.read(CHUNKLEN)
         while sin:
             din = dfp.read(CHUNKLEN)
@@ -188,7 +192,7 @@
         sfp.close()
         dfp.close()
         if sin:
-            ui.debug('not linkable: %s\n' % f)
+            ui.debug(b'not linkable: %s\n' % f)
             continue
         try:
             relinkfile(source, tgt)
@@ -196,11 +200,11 @@
             relinked += 1
             savedbytes += sz
         except OSError as inst:
-            ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst)))
+            ui.warn(b'%s: %s\n' % (tgt, stringutil.forcebytestr(inst)))
 
     progress.complete()
 
     ui.status(
-        _('relinked %d files (%s reclaimed)\n')
+        _(b'relinked %d files (%s reclaimed)\n')
         % (relinked, util.bytecount(savedbytes))
     )