Patchwork [1,of,2,STABLE] dispatch: make "_checkshellalias" reusable regardless of adding aliases

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 9, 2014, 4:32 p.m.
Message ID <da54cba6a073c5cbe04e.1410280356@feefifofum>
Download mbox | patch
Permalink /patch/5737/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Sept. 9, 2014, 4:32 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1410277304 -32400
#      Wed Sep 10 00:41:44 2014 +0900
# Branch stable
# Node ID da54cba6a073c5cbe04e73ebbfb043c49066d215
# Parent  71227dc24311b6d83904c50bacf7b339b1454bec
dispatch: make "_checkshellalias" reusable regardless of adding aliases

To reduce changes in the subsequent patch fixing issue4355, this patch
makes "_checkshellalias" reusable regardless of adding aliases.

In this patch, alias definitions are added and restored, only when
"precheck=True".

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -627,7 +627,12 @@ 
 
     return path, lui
 
-def _checkshellalias(lui, ui, args):
+def _checkshellalias(lui, ui, args, precheck=True):
+    """Return the function to run the shell alias, if it is required
+
+    'precheck' is whehter this function is invoked before adding
+    aliases or not.
+    """
     options = {}
 
     try:
@@ -638,14 +643,18 @@ 
     if not args:
         return
 
-    norepo = commands.norepo
-    optionalrepo = commands.optionalrepo
-    def restorecommands():
-        commands.norepo = norepo
-        commands.optionalrepo = optionalrepo
-
-    cmdtable = commands.table.copy()
-    addaliases(lui, cmdtable)
+    if precheck:
+        norepo = commands.norepo
+        optionalrepo = commands.optionalrepo
+        def restorecommands():
+            commands.norepo = norepo
+            commands.optionalrepo = optionalrepo
+        cmdtable = commands.table.copy()
+        addaliases(lui, cmdtable)
+    else:
+        def restorecommands():
+            pass
+        cmdtable = commands.table
 
     cmd = args[0]
     try: