diff options
author | Shawn O. Pearce <sop@google.com> | 2009-07-02 12:45:47 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-07-02 12:45:47 -0700 |
commit | 1dcb58a7d0f07bf358ba485733580413ebe2478b (patch) | |
tree | d6aba27e0585a06d103cf859339f5bdb5c4f101a /editor.py | |
parent | 37dbf2bf0fa799530052ffd010dadbd4c01b7746 (diff) | |
download | git-repo-1dcb58a7d0f07bf358ba485733580413ebe2478b.tar.gz |
Support GIT_EDITOR='vim -c "set textwidth=80"'
If there are shell special characters in the editor string, we must
use /bin/sh to parse and execute it, rather than trying to rely on
a simple split(' '). This avoids vim starting up with two empty
buffers, due to a misparsed command line.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'editor.py')
-rw-r--r-- | editor.py | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -14,6 +14,7 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | import os | 16 | import os |
17 | import re | ||
17 | import sys | 18 | import sys |
18 | import subprocess | 19 | import subprocess |
19 | import tempfile | 20 | import tempfile |
@@ -38,9 +39,10 @@ class Editor(object): | |||
38 | if e: | 39 | if e: |
39 | return e | 40 | return e |
40 | 41 | ||
41 | e = cls.globalConfig.GetString('core.editor') | 42 | if cls.globalConfig: |
42 | if e: | 43 | e = cls.globalConfig.GetString('core.editor') |
43 | return e | 44 | if e: |
45 | return e | ||
44 | 46 | ||
45 | e = os.getenv('VISUAL') | 47 | e = os.getenv('VISUAL') |
46 | if e: | 48 | if e: |
@@ -69,21 +71,32 @@ least one of these before using this command.""" | |||
69 | Returns: | 71 | Returns: |
70 | new value of edited text; None if editing did not succeed | 72 | new value of edited text; None if editing did not succeed |
71 | """ | 73 | """ |
72 | editor = cls._GetEditor().split() | 74 | editor = cls._GetEditor() |
75 | if editor == ':': | ||
76 | return data | ||
77 | |||
73 | fd, path = tempfile.mkstemp() | 78 | fd, path = tempfile.mkstemp() |
74 | try: | 79 | try: |
75 | os.write(fd, data) | 80 | os.write(fd, data) |
76 | os.close(fd) | 81 | os.close(fd) |
77 | fd = None | 82 | fd = None |
78 | 83 | ||
84 | if re.compile("^.*[$ \t'].*$").match(editor): | ||
85 | args = [editor + ' "$@"'] | ||
86 | shell = True | ||
87 | else: | ||
88 | args = [editor] | ||
89 | shell = False | ||
90 | args.append(path) | ||
91 | |||
79 | try: | 92 | try: |
80 | rc = subprocess.Popen(editor + [path]).wait() | 93 | rc = subprocess.Popen(args, shell=shell).wait() |
81 | except OSError, e: | 94 | except OSError, e: |
82 | raise EditorError('editor failed, %s: %s %s' | 95 | raise EditorError('editor failed, %s: %s %s' |
83 | % (str(e), cls._GetEditor(), path)) | 96 | % (str(e), editor, path)) |
84 | if rc != 0: | 97 | if rc != 0: |
85 | raise EditorError('editor failed with exit status %d: %s %s' | 98 | raise EditorError('editor failed with exit status %d: %s %s' |
86 | % (rc, cls._GetEditor(), path)) | 99 | % (rc, editor, path)) |
87 | 100 | ||
88 | fd2 = open(path) | 101 | fd2 = open(path) |
89 | try: | 102 | try: |