74 import email.Utils, email.Encoders, email.Generator |
74 import email.Utils, email.Encoders, email.Generator |
75 from mercurial import cmdutil, commands, hg, mail, patch, util |
75 from mercurial import cmdutil, commands, hg, mail, patch, util |
76 from mercurial.i18n import _ |
76 from mercurial.i18n import _ |
77 from mercurial.node import bin |
77 from mercurial.node import bin |
78 |
78 |
79 def prompt(ui, prompt, default='', rest=':', empty_ok=False): |
79 def prompt(ui, prompt, default=None, rest=':'): |
80 if not ui.interactive(): |
80 if not ui.interactive(): |
81 if default or empty_ok: |
81 if default is not None: |
82 return default |
82 return default |
83 raise util.Abort(_("%s Please enter a valid value" % (prompt+rest))) |
83 raise util.Abort(_("%s Please enter a valid value" % (prompt+rest))) |
84 if default: |
84 if default: |
85 prompt += ' [%s]' % default |
85 prompt += ' [%s]' % default |
86 prompt += rest |
86 prompt += rest |
88 r = ui.prompt(prompt, default=default) |
88 r = ui.prompt(prompt, default=default) |
89 if r: |
89 if r: |
90 return r |
90 return r |
91 if default is not None: |
91 if default is not None: |
92 return default |
92 return default |
93 if empty_ok: |
|
94 return r |
|
95 ui.warn(_('Please enter a valid value.\n')) |
93 ui.warn(_('Please enter a valid value.\n')) |
96 |
94 |
97 def cdiffstat(ui, summary, patchlines): |
95 def cdiffstat(ui, summary, patchlines): |
98 s = patch.diffstat(patchlines) |
96 s = patch.diffstat(patchlines) |
99 if summary: |
97 if summary: |