commit: move the addremove logic around to make the next changeset clearer
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 05 Feb 2023 15:38:23 +0100
changeset 50028 a46dfc2b58a3
parent 50027 0b4a6912292e
child 50029 28dfb2df4ab9
commit: move the addremove logic around to make the next changeset clearer Lets do the noise now, without changing any thing. So the new changeset can focus on the actual semantic changes.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Wed Feb 15 10:46:46 2023 +0100
+++ b/mercurial/cmdutil.py	Sun Feb 05 15:38:23 2023 +0100
@@ -2794,8 +2794,6 @@
     date = opts.get(b'date')
     if date:
         opts[b'date'] = dateutil.parsedate(date)
-    message = logmessage(ui, opts)
-    matcher = scmutil.match(repo[None], pats, opts)
 
     dsguard = None
     # extract addremove carefully -- this function can be called from a command
@@ -2803,15 +2801,29 @@
     if opts.get(b'addremove'):
         dsguard = dirstateguard.dirstateguard(repo, b'commit')
     with dsguard or util.nullcontextmanager():
-        if dsguard:
-            relative = scmutil.anypats(pats, opts)
-            uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative)
-            if scmutil.addremove(repo, matcher, b"", uipathfn, opts) != 0:
-                raise error.Abort(
-                    _(b"failed to mark all new/missing files as added/removed")
+        message = logmessage(ui, opts)
+        matcher = scmutil.match(repo[None], pats, opts)
+        if True:
+            # extract addremove carefully -- this function can be called from a
+            # command that doesn't support addremove
+            if opts.get(b'addremove'):
+                relative = scmutil.anypats(pats, opts)
+                uipathfn = scmutil.getuipathfn(
+                    repo,
+                    legacyrelativevalue=relative,
                 )
-
-        return commitfunc(ui, repo, message, matcher, opts)
+                r = scmutil.addremove(
+                    repo,
+                    matcher,
+                    b"",
+                    uipathfn,
+                    opts,
+                )
+                m = _(b"failed to mark all new/missing files as added/removed")
+                if r != 0:
+                    raise error.Abort(m)
+
+            return commitfunc(ui, repo, message, matcher, opts)
 
 
 def samefile(f, ctx1, ctx2):