changeset 4484:c927c568a5ad

Automated merge with http://hg.intevation.org/mercurial/crew
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 27 May 2007 14:43:29 -0700
parents a11e13d50645 (diff) 8fa54b9c6c5a (current diff)
children 6d2d1dcd5f74
files mercurial/commands.py mercurial/patch.py
diffstat 7 files changed, 64 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/acl.py
+++ b/hgext/acl.py
@@ -55,7 +55,7 @@ class checker(object):
 
     def buildmatch(self, key):
         '''return tuple of (match function, list enabled).'''
-        if not self.ui.has_config(key):
+        if not self.ui.has_section(key):
             self.ui.debug(_('acl: %s not enabled\n') % key)
             return None, False
 
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -70,12 +70,6 @@ from mercurial import cmdutil, commands,
 from mercurial.i18n import _
 from mercurial.node import *
 
-try:
-    # readline gives raw_input editing capabilities, but is not
-    # present on windows
-    import readline
-except ImportError: pass
-
 def patchbomb(ui, repo, *revs, **opts):
     '''send changesets by email
 
@@ -120,6 +114,12 @@ def patchbomb(ui, repo, *revs, **opts):
     '''
 
     def prompt(prompt, default = None, rest = ': ', empty_ok = False):
+        try:
+            # readline gives raw_input editing capabilities, but is not
+            # present on windows
+            import readline
+        except ImportError: pass
+
         if default: prompt += ' [%s]' % default
         prompt += rest
         while True:
@@ -223,6 +223,9 @@ def patchbomb(ui, repo, *revs, **opts):
                 pass
             os.rmdir(tmpdir)
 
+    if not opts['test']:
+        mail.validateconfig(ui)
+
     # option handling
     commands.setremoteconfig(ui, opts)
     if opts.get('outgoint') and opts.get('bundle'):
@@ -250,23 +253,6 @@ def patchbomb(ui, repo, *revs, **opts):
     def genmsgid(id):
         return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
 
-    sender = (opts['from'] or ui.config('email', 'from') or
-              ui.config('patchbomb', 'from') or
-              prompt('From', ui.username()))
-
-    def getaddrs(opt, prpt, default = None):
-        addrs = opts[opt] or (ui.config('email', opt) or
-                              ui.config('patchbomb', opt) or
-                              prompt(prpt, default = default)).split(',')
-        return [a.strip() for a in addrs if a.strip()]
-
-    to = getaddrs('to', 'To')
-    cc = getaddrs('cc', 'Cc', '')
-
-    bcc = opts['bcc'] or (ui.config('email', 'bcc') or
-                          ui.config('patchbomb', 'bcc') or '').split(',')
-    bcc = [a.strip() for a in bcc if a.strip()]
-
     def getexportmsgs():
         patches = []
 
@@ -344,6 +330,23 @@ def patchbomb(ui, repo, *revs, **opts):
     else:
         msgs = getexportmsgs()
 
+    sender = (opts['from'] or ui.config('email', 'from') or
+              ui.config('patchbomb', 'from') or
+              prompt('From', ui.username()))
+
+    def getaddrs(opt, prpt, default = None):
+        addrs = opts[opt] or (ui.config('email', opt) or
+                              ui.config('patchbomb', opt) or
+                              prompt(prpt, default = default)).split(',')
+        return [a.strip() for a in addrs if a.strip()]
+
+    to = getaddrs('to', 'To')
+    cc = getaddrs('cc', 'Cc', '')
+
+    bcc = opts['bcc'] or (ui.config('email', 'bcc') or
+                          ui.config('patchbomb', 'bcc') or '').split(',')
+    bcc = [a.strip() for a in bcc if a.strip()]
+
     ui.write('\n')
 
     if not opts['test'] and not opts['mbox']:
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -885,11 +885,10 @@ def debuginstall(ui):
 
     # patch
     ui.status(_("Checking patch...\n"))
-    path = os.environ.get('PATH', '')
     patcher = ui.config('ui', 'patch')
-    if not patcher:
-        patcher = util.find_in_path('gpatch', path,
-                                    util.find_in_path('patch', path, None))
+    patcher = ((patcher and util.find_exe(patcher)) or
+               util.find_exe('gpatch') or
+               util.find_exe('patch'))
     if not patcher:
         ui.write(_(" Can't find patch or gpatch in PATH\n"))
         ui.write(_(" (specify a patch utility in your .hgrc file)\n"))
@@ -927,9 +926,7 @@ def debuginstall(ui):
     ui.status(_("Checking merge helper...\n"))
     cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
            or "hgmerge")
-    cmdpath = util.find_in_path(cmd, path)
-    if not cmdpath:
-        cmdpath = util.find_in_path(cmd.split()[0], path)
+    cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
     if not cmdpath:
         if cmd == 'hgmerge':
             ui.write(_(" No merge helper set and can't find default"
@@ -963,9 +960,7 @@ def debuginstall(ui):
     editor = (os.environ.get("HGEDITOR") or
               ui.config("ui", "editor") or
               os.environ.get("EDITOR", "vi"))
-    cmdpath = util.find_in_path(editor, path)
-    if not cmdpath:
-        cmdpath = util.find_in_path(editor.split()[0], path)
+    cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
     if not cmdpath:
         if editor == 'vi':
             ui.write(_(" No commit editor set and can't find vi in PATH\n"))
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -68,3 +68,15 @@ def connect(ui):
 
 def sendmail(ui, sender, recipients, msg):
     return connect(ui).sendmail(sender, recipients, msg)
+
+def validateconfig(ui):
+    '''determine if we have enough config data to try sending email.'''
+    method = ui.config('email', 'method', 'smtp')
+    if method == 'smtp':
+        if not ui.config('smtp', 'host'):
+            raise util.Abort(_('smtp specified as email transport, '
+                               'but no smtp host configured'))
+    else:
+        if not util.find_exe(method):
+            raise util.Abort(_('%r specified as email transport, '
+                               'but not in PATH') % method)
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -298,11 +298,13 @@ def patch(patchname, ui, strip=1, cwd=No
 
         args = []
         patcher = ui.config('ui', 'patch')
+        patcher = ((patcher and util.find_exe(patcher)) or
+                   util.find_exe('gpatch') or
+                   util.find_exe('patch'))
         if not patcher:
-            patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
-                                        'patch')
-            if util.needbinarypatch():
-                args.append('--binary')
+            raise util.Abort(_('no patch command found in hgrc or PATH'))
+        if util.needbinarypatch():
+            args.append('--binary')
                                     
         if cwd:
             args.append('-d %s' % util.shellquote(cwd))
@@ -646,7 +648,7 @@ def export(repo, revs, template='hg-%h.p
         single(rev, seqno+1, fp)
 
 def diffstat(patchlines):
-    if not util.find_in_path('diffstat', os.environ.get('PATH', '')):
+    if not util.find_exe('diffstat'):
         return
     fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
     try:
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -270,7 +270,7 @@ class ui(object):
             result = result.replace(",", " ").split()
         return result
 
-    def has_config(self, section, untrusted=False):
+    def has_section(self, section, untrusted=False):
         '''tell whether section exists in config.'''
         cdata = self._get_cdata(untrusted)
         return cdata.has_section(section)
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1087,6 +1087,18 @@ else:
                 return p_name
         return default
 
+def find_exe(name, default=None):
+    '''find path of an executable.
+    if name contains a path component, return it as is.  otherwise,
+    use normal executable search path.'''
+
+    if os.sep in name:
+        # don't check the executable bit.  if the file isn't
+        # executable, whoever tries to actually run it will give a
+        # much more useful error message.
+        return name
+    return find_in_path(name, os.environ.get('PATH', ''), default=default)
+
 def _buildencodefun():
     e = '_'
     win_reserved = [ord(x) for x in '\\:*?"<>|']