Documentation: Rename remaining link macros
[stgit] / stgit / utils.py
index 979fd3b..1fa96c2 100644 (file)
@@ -170,17 +170,21 @@ def rename(basedir, file1, file2):
 class EditorException(StgException):
     pass
 
+def get_editor():
+    for editor in [os.environ.get('GIT_EDITOR'),
+                   config.get('stgit.editor'), # legacy
+                   config.get('core.editor'),
+                   os.environ.get('VISUAL'),
+                   os.environ.get('EDITOR'),
+                   'vi']:
+        if editor:
+            return editor
+
 def call_editor(filename):
     """Run the editor on the specified filename."""
-
-    # the editor
-    editor = config.get('stgit.editor')
-    if not editor:
-        editor = os.environ.get('EDITOR', 'vi')
-    editor += ' %s' % filename
-
-    out.start('Invoking the editor: "%s"' % editor)
-    err = os.system(editor)
+    cmd = '%s %s' % (get_editor(), filename)
+    out.start('Invoking the editor: "%s"' % cmd)
+    err = os.system(cmd)
     if err:
         raise EditorException, 'editor failed, exit code: %d' % err
     out.done()
@@ -196,13 +200,22 @@ def edit_string(s, filename):
     os.remove(filename)
     return s
 
+def find_patch_name(patchname, unacceptable):
+    """Find a patch name which is acceptable."""
+    if unacceptable(patchname):
+        suffix = 0
+        while unacceptable('%s-%d' % (patchname, suffix)):
+            suffix += 1
+        patchname = '%s-%d' % (patchname, suffix)
+    return patchname
+
 def patch_name_from_msg(msg):
     """Return a string to be used as a patch name. This is generated
     from the top line of the string passed as argument."""
     if not msg:
         return None
 
-    name_len = config.get('stgit.namelength')
+    name_len = config.getint('stgit.namelength')
     if not name_len:
         name_len = 30
 
@@ -216,12 +229,7 @@ def make_patch_name(msg, unacceptable, default_name = 'patch'):
     patchname = patch_name_from_msg(msg)
     if not patchname:
         patchname = default_name
-    if unacceptable(patchname):
-        suffix = 0
-        while unacceptable('%s-%d' % (patchname, suffix)):
-            suffix += 1
-        patchname = '%s-%d' % (patchname, suffix)
-    return patchname
+    return find_patch_name(patchname, unacceptable)
 
 # any and all functions are builtin in Python 2.5 and higher, but not
 # in 2.4.