changeset 50869:e0cae2b44191

absorb: migrate `opts` to native kwargs
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 20 Aug 2023 15:16:18 -0400
parents 788113f056d4
children 47af00b2217f
files hgext/absorb.py
diffstat 1 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/absorb.py	Thu Aug 17 15:53:32 2023 -0400
+++ b/hgext/absorb.py	Sun Aug 20 15:16:18 2023 -0400
@@ -299,7 +299,7 @@
         4. read results from "finalcontents", or call getfinalcontent
     """
 
-    def __init__(self, fctxs, path, ui=None, opts=None):
+    def __init__(self, fctxs, path, ui=None, **opts):
         """([fctx], ui or None) -> None
 
         fctxs should be linear, and sorted by topo order - oldest first.
@@ -308,7 +308,7 @@
         self.fctxs = fctxs
         self.path = path
         self.ui = ui or nullui()
-        self.opts = opts or {}
+        self.opts = opts
 
         # following fields are built from fctxs. they exist for perf reason
         self.contents = [f.data() for f in fctxs]
@@ -375,7 +375,7 @@
                     % (short(self.fctxs[idx].node()), a1, a2, len(blines))
                 )
             self.linelog.replacelines(rev, a1, a2, b1, b2)
-        if self.opts.get(b'edit_lines', False):
+        if self.opts.get('edit_lines', False):
             self.finalcontents = self._checkoutlinelogwithedits()
         else:
             self.finalcontents = self._checkoutlinelog()
@@ -668,7 +668,7 @@
         4. call commit, to commit changes to hg database
     """
 
-    def __init__(self, stack, ui=None, opts=None):
+    def __init__(self, stack, ui=None, **opts):
         """([ctx], ui or None) -> None
 
         stack: should be linear, and sorted by topo order - oldest first.
@@ -676,7 +676,7 @@
         """
         assert stack
         self.ui = ui or nullui()
-        self.opts = opts or {}
+        self.opts = opts
         self.stack = stack
         self.repo = stack[-1].repo().unfiltered()
 
@@ -696,7 +696,7 @@
         self.paths = []
         # but if --edit-lines is used, the user may want to edit files
         # even if they are not modified
-        editopt = self.opts.get(b'edit_lines')
+        editopt = self.opts.get('edit_lines')
         if not self.status.modified and editopt and match:
             interestingpaths = match.files()
         else:
@@ -720,7 +720,7 @@
                 continue
             seenfctxs.update(fctxs[1:])
             self.fctxmap[path] = ctx2fctx
-            fstate = filefixupstate(fctxs, path, ui=self.ui, opts=self.opts)
+            fstate = filefixupstate(fctxs, path, ui=self.ui, **self.opts)
             if fm is not None:
                 fm.startitem()
                 fm.plain(b'showing changes for ')
@@ -1009,7 +1009,7 @@
     return overlaycontext(memworkingcopy, ctx)
 
 
-def absorb(ui, repo, stack=None, targetctx=None, pats=None, opts=None):
+def absorb(ui, repo, stack=None, targetctx=None, pats=None, **opts):
     """pick fixup chunks from targetctx, apply them to stack.
 
     if targetctx is None, the working copy context will be used.
@@ -1036,22 +1036,21 @@
         targetctx = repo[None]
     if pats is None:
         pats = ()
-    if opts is None:
-        opts = {}
-    state = fixupstate(stack, ui=ui, opts=opts)
-    matcher = scmutil.match(targetctx, pats, opts)
-    if opts.get(b'interactive'):
+
+    state = fixupstate(stack, ui=ui, **opts)
+    matcher = scmutil.match(targetctx, pats, pycompat.byteskwargs(opts))
+    if opts.get('interactive'):
         diff = patch.diff(repo, stack[-1].node(), targetctx.node(), matcher)
         origchunks = patch.parsepatch(diff)
         chunks = cmdutil.recordfilter(ui, origchunks, matcher)[0]
         targetctx = overlaydiffcontext(stack[-1], chunks)
-    if opts.get(b'edit_lines'):
+    if opts.get('edit_lines'):
         # If we're going to open the editor, don't ask the user to confirm
         # first
-        opts[b'apply_changes'] = True
+        opts['apply_changes'] = True
     fm = None
-    if opts.get(b'print_changes') or not opts.get(b'apply_changes'):
-        fm = ui.formatter(b'absorb', opts)
+    if opts.get('print_changes') or not opts.get('apply_changes'):
+        fm = ui.formatter(b'absorb', pycompat.byteskwargs(opts))
     state.diffwith(targetctx, matcher, fm)
     if fm is not None:
         fm.startitem()
@@ -1074,9 +1073,9 @@
                 label=b'absorb.description',
             )
         fm.end()
-    if not opts.get(b'dry_run'):
+    if not opts.get('dry_run'):
         if (
-            not opts.get(b'apply_changes')
+            not opts.get('apply_changes')
             and state.ctxaffected
             and ui.promptchoice(
                 b"apply changes (y/N)? $$ &Yes $$ &No", default=1
@@ -1154,12 +1153,10 @@
 
     Returns 0 on success, 1 if all chunks were ignored and nothing amended.
     """
-    opts = pycompat.byteskwargs(opts)
-
     with repo.wlock(), repo.lock():
-        if not opts[b'dry_run']:
+        if not opts['dry_run']:
             cmdutil.checkunfinished(repo)
 
-        state = absorb(ui, repo, pats=pats, opts=opts)
+        state = absorb(ui, repo, pats=pats, **opts)
         if sum(s[0] for s in state.chunkstats.values()) == 0:
             return 1