dispatch: parse and apply cwd opt early
authorMatt Mackall <mpm@selenic.com>
Mon, 11 Jun 2007 21:09:24 -0500
changeset 4552 38cdee6b6675
parent 4551 61e33f1d44a8
child 4553 741f64dfc04d
dispatch: parse and apply cwd opt early
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon Jun 11 21:09:24 2007 -0500
+++ b/mercurial/cmdutil.py	Mon Jun 11 21:09:24 2007 -0500
@@ -238,7 +238,20 @@
             raise util.Abort(_('malformed --config option: %s') % cfg)
     return parsed
 
+def earlygetopt(aliases, args):
+    if "--" in args:
+        args = args[:args.index("--")]
+    for opt in aliases:
+        if opt in args:
+            return args[args.index(opt) + 1]
+    return None
+
 def dispatch(ui, args):
+    # check for cwd first
+    cwd = earlygetopt(['--cwd'], args)
+    if cwd:
+        os.chdir(cwd)
+
     extensions.loadall(ui)
     ui.addreadhook(extensions.loadall)
 
@@ -261,9 +274,6 @@
                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
         atexit.register(print_time)
 
-    if options['cwd']:
-        os.chdir(options['cwd'])
-
     ui.updateopts(options["verbose"], options["debug"], options["quiet"],
                  not options["noninteractive"], options["traceback"],
                  parseconfig(options["config"]))