Make prompting go
authormpm@selenic.com
Wed, 18 May 2005 18:25:37 -0800
changeset 107 707a7481a861
parent 106 e8d4bbf4c9e2
child 108 8d55c2d72c7c
Make prompting go Minor UI tweaking Add merge prompting
hg
mercurial/hg.py
--- a/hg	Wed May 18 17:37:49 2005 -0800
+++ b/hg	Wed May 18 18:25:37 2005 -0800
@@ -87,7 +87,9 @@
 options = {}
 opts = [('v', 'verbose', None, 'verbose'),
         ('d', 'debug', None, 'debug'),
-        ('q', 'quiet', None, 'quiet')]
+        ('q', 'quiet', None, 'quiet'),
+        ('y', 'noninteractive', None, 'run non-interactively'),
+        ]
 
 args = fancyopts.fancyopts(sys.argv[1:], opts, options,
                            'hg [options] <command> [command options] [files]')
@@ -98,7 +100,8 @@
 except:
     cmd = ""
 
-ui = hg.ui(options["verbose"], options["debug"], options["quiet"])
+ui = hg.ui(options["verbose"], options["debug"], options["quiet"],
+           not options["noninteractive"])
     
 if cmd == "init":
     repo = hg.repository(ui, ".", create=1)
@@ -348,6 +351,9 @@
     for f in files:
         print hg.hex(m[f]), f
 
+elif cmd == "debugprompt":
+    print ui.prompt(args[0], args[1], args[2])
+
 elif cmd == "debughash":
     f = repo.file(args[0])
     print f.encodepath(args[0])
--- a/mercurial/hg.py	Wed May 18 17:37:49 2005 -0800
+++ b/mercurial/hg.py	Wed May 18 18:25:37 2005 -0800
@@ -675,7 +675,7 @@
         omap = self.manifest.read(mo) # other
         amap = self.manifest.read(ma) # ancestor
         mmap = self.manifest.read(mm) # mine
-        self.ui.debug("ancestor %s local %s other %s\n" %
+        self.ui.debug("ancestor %s local %s remote %s\n" %
                       (short(ma), short(mm), short(mo)))
         nmap = {}
 
@@ -691,8 +691,10 @@
                 del omap[f]
             elif f in amap:
                 if mid != amap[f]:
-                    self.ui.debug("local changed %s which other deleted\n" % f)
-                    pass # we should prompt here
+                    r = self.ui.prompt(
+                        ("local changed %s which remote deleted\n" % f) +
+                        "(k)eep or (d)elete?", "[kd]", "k")
+                    if r == "k": nmap[f] = mid
                 else:
                     self.ui.debug("other deleted %s\n" % f)
                     pass # other deleted it
@@ -705,8 +707,10 @@
         for f, oid in omap.iteritems():
             if f in amap:
                 if oid != amap[f]:
-                    self.ui.debug("other changed %s which we deleted\n" % f)
-                    pass # this is the nasty case, we should prompt
+                    r = self.ui.prompt(
+                        ("remote changed %s which local deleted\n" % f) +
+                        "(k)eep or (d)elete?", "[kd]", "k")
+                    if r == "k": nmap[f] = oid
                 else:
                     pass # probably safe
             else:
@@ -811,26 +815,33 @@
         return localrepository(ui, path, create)
 
 class ui:
-    def __init__(self, verbose=False, debug=False, quiet=False):
+    def __init__(self, verbose=False, debug=False, quiet=False,
+                 interactive=True):
         self.quiet = quiet and not verbose and not debug
         self.verbose = verbose or debug
         self.debugflag = debug
+        self.interactive = interactive
     def write(self, *args):
         for a in args:
             sys.stdout.write(str(a))
-    def prompt(self, msg, pat):
+    def readline(self):
+        return sys.stdin.readline()[:-1]
+    def prompt(self, msg, pat, default = "y"):
+        if not self.interactive: return default
         while 1:
-            sys.stdout.write(msg)
-            r = sys.stdin.readline()[:-1]
+            self.write(msg, " ")
+            r = self.readline()
             if re.match(pat, r):
                 return r
+            else:
+                self.write("unrecognized response\n")
     def status(self, *msg):
         if not self.quiet: self.write(*msg)
     def warn(self, msg):
         self.write(*msg)
-    def note(self, msg):
+    def note(self, *msg):
         if self.verbose: self.write(*msg)
-    def debug(self, msg):
+    def debug(self, *msg):
         if self.debugflag: self.write(*msg)
     def edit(self, text):
         (fd, name) = tempfile.mkstemp("hg")