Commit Graph

350 Commits

Author SHA1 Message Date
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Pierre-Yves David
40147b2819 devel-warn: move the develwarn function as a method of the ui object
We are going to use this feature in more and more place. Having to import
scmutil makes it an import cycle hell.
2015-06-19 11:19:45 -07:00
Matt Harbison
1378c4e950 ui: flush stderr after printing a non-chained exception for Windows
There were consistent test failures in test-bad-extension.t, because Windows
buffers stderr when redirected to a file (per the comment in ui.write_err()).
That resulted in failures like this:

  --- c:/Users/Matt/Projects/hg/tests/test-bad-extension.t
  +++ c:/Users/Matt/Projects/hg/tests/test-bad-extension.t.err
  @@ -23,11 +23,11 @@
     Traceback (most recent call last):
     Exception: bit bucket overflow
     *** failed to import extension badext2: No module named badext2
  -  Traceback (most recent call last):
  -  ImportError: No module named badext2
     hg help [-ec] [TOPIC]

     show help for a given topic or a help overview
  +  Traceback (most recent call last):
  +  ImportError: No module named badext2

   show traceback for ImportError of hgext.name if debug is set
   (note that --debug option isn't applied yet when loading extensions)

Instead of inserting another flush immediately after the print, to go along with
the one recently added prior to the print (see 3cd72de3be66), funnel the output
through ui.write_err().  The flush prior to printing the traceback only mentions
that stdout needs to be flushed, and only stderr needs to be flushed after
printing the traceback.  ui.write_err() does both for us without needing to
redocument the quirky Windows behavior.  It will also clear any progress bar.
2015-06-12 22:09:41 -04:00
Pierre-Yves David
beda8bc247 progress: display progress bars by default with core Mercurial
As discussed multiple time during sprint, we should activate progress by
default. Having progress bar significantly improve the user experience.
2015-06-07 17:51:27 -07:00
Pierre-Yves David
5446aa78a9 progress: move all logic altering the ui object logic in mercurial.ui
The ui object can take care of its progress object logic by itself.

test-subrepo-recursion is modified because it is a bit sensitive to the "no
progress bar" default. It will become unnecessary in the next step when
progress will be on by default in core.
2015-06-07 17:50:56 -07:00
Pierre-Yves David
5f05d2698e progress: move the singleton logic to the ui module
The use of a singleton for all of progress handling is debatable (because
config may vary). However this is how the extension has been doing it so far.
We move that code into the ui module because this is where is should belong when
progress is moved into core.
2015-06-07 17:26:34 -07:00
Yuya Nishihara
398221202a ui: flush stdout before writing traceback to stderr
Sometimes a traceback message is paired with ui.debug(). This patch makes sure
that these messages are displayed in the right order.
2015-05-31 14:40:28 +09:00
Augie Fackler
a5b17bd9d1 cleanup: use __builtins__.any instead of util.any
any() is available in all Python versions we support now.
2015-05-16 14:30:07 -04:00
Pierre-Yves David
281365197e progress: get the extremely verbose output out of default debug
When the progress extension is not enabled, each call to 'ui.progress' used to
issue a debug message. This results is a very verbose output and often redundant
in tests. Dropping it makes tests less volatile to factor they do not meant to
test.

We had to alter the sed trick in 'test-rename-merge2.t'. Sed is used to drop all
output from a certain point and hidding the progress output remove its anchor.
So we anchor on something else.
2015-05-09 23:40:40 -07:00
Siddharth Agarwal
eba77fa34f ui: disable revsetaliases in plain mode (BC)
ui.plain() is supposed to disable config options that change the UI to the
detriment of scripts. As the test demonstrates, revset aliases can actually
override builtin ones, just like command aliases. Therefore I believe this is a
bugfix and appropriate for stable.
2015-04-30 07:46:54 -07:00
Pierre-Yves David
3ecff4d3f6 ui: allow capture of subprocess output
We want to capture hooks output during bundle2 processing. For this purpose we
introduce a new 'subproc' argument to 'ui.pushbuffer'. When set, the output of
sub process created through 'ui.system' will be captured in the buffer too.

This will be used in the next changeset.
2015-04-23 14:57:39 +01:00
Alexander Drozdov
0af407fa48 editor: prefer 'intermediate-source' extra to use for HGREVISION environment variable
Revision 7fbf0ef28408 ('graft: record intermediate grafts in extras') introduced
'intermediate-source' extra which refers to the closest graft source.

As 'intermediate-source' extra provides more detailed information about the source
changeset than 'source' one, it is better to prefer the first one to use as a
value of HGREVISION environment variable for an editor.
2015-04-10 08:05:50 +03:00
Mathias De Maré
8b3f5b98e3 commands: add ui.statuscopies config knob
statuscopies enables viewing of copies and moves in 'hg status' by default.
2015-03-24 21:25:57 +01:00
Gregory Szorc
2d9de90ccf ui: represent paths as classes
Many have long wanted for paths to have expanded functionality and
flexibility.

In order to make that transition possible, we need to start
representing paths as something more than simple strings.

This patch introduces two classes:

1) "path" for representing a single path instance
2) "paths" for representing a collection of "paths"

Since we don't like patches that introduce new code without any
consumers, we convert ui.expandpath() to use the new APIs internally.
Upcoming patches will start exposing "path" instances to consumers
that currently interface with string paths.

The new "paths" attribute of ui is populated from config data the first
time it is accessed. Since it isn't updated when the configs are
modified, this could lead to some inaccurate caching behavior. It
shouldn't be an issue, as paths information is typically not accessed
until command dispatch, which occurs after the repository config
and extensions have been loaded. Time will tell if we need to refresh
paths information when the underlying config changes.
2015-02-07 12:42:10 -08:00
Yuya Nishihara
c3aa617f2e ui: introduce util.system() wrapper to make sure ui.fout is used
This change is intended to avoid future problem of data corruption under
command server.  out=ui.fout is mandatory as long as command server uses
stdout as IPC channel.
2014-11-08 12:57:42 +09:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Yuya Nishihara
df336dc3c8 ui: separate option to show prompt echo, enabled only in tests (issue4417)
The problem in commandserver was addressed by 766cfbe766dc, but it is tricky
to reuse ui.nontty option to disable echo back.  Instead, this patch introduces
new option to enable echoing of prompt response.

Prompt echoing is changed to be off by default, which should avoid possible
breakage of output parsing in user scripts.

For now, this option is undocumented because it exists for internal use.
2014-10-21 23:16:46 +09:00
Jordi Gutiérrez Hermoso
c978db634c config: use the same hgrc for a cloned repo as for an uninitted repo
This just copies the same local sample hgrc, except it sets the
default path to the repo it was cloned from.

This is cut-and-paste from the local sample hgrc, but I think it's
acceptable, since the two pieces of code are right next to each other
and they're small. There is danger of them going out of synch, but it
would complicate the code too much to get rid of this C&P.

I also add ui as an import to hg.py, but with demandimport, this
should not be a noticeable performance hit.
2014-10-06 16:35:02 -04:00
Jordi Gutiérrez Hermoso
e296a9f550 config: give a more detailed sample repo config
Some examples of the typical configurations that one might want to do
in an .hg/hgrc file. This includes a default-push that happens to
point to the same location as my-fork.

I insist on the myfork terminology for a server-side clone. Bitbucket,
Github, and others have widely popularised this meaning of "fork".

This also includes a gentle nudge to use a repo-specific username,
which is something that people might not instinctively realise is an
option.
2014-10-08 07:45:51 -04:00
Yuya Nishihara
2f53d7a8aa ui: disable echo back of prompt input if ui is set to non-tty purposely
d735f8a82023 is nice for test output, but it also affects command-server
channel.  Command-server client shouldn't receive echo-back message, which
makes it harder to parse the output.
2014-10-08 20:51:01 +09:00
Matt Mackall
6712145426 ui: fix comment about non-interactive prompts
This fixes my earlier in-flight addition to Mads' change.
2014-10-02 18:00:05 -05:00
Mads Kiilerich
29285eb86d ui: show prompt choice if input is not a tty but is forced to be interactive
The tests often set ui.interactive to control normally interactive prompts from
stdin. That gave an output where it was non-obvious what prompts got which
which response, and the output lacked the newline users would see after input.

Instead, if the input not is a tty, write the selection and a newline.
2014-10-01 01:04:18 +02:00
Matt Mackall
5bfd322b62 ui: move samplehgrcs from config
config is generic code that doesn't know about Mercurial usage, so
this was at the wrong layer
2014-09-11 12:26:12 -05:00
Yuya Nishihara
7bc5b972be ui: add brief comment why raw_input() needs dummy ' ' prompt string
Retrieved from 55a66b5d9114.

I was about to move ' ' to label(msg + ' ', 'ui.prompt') so that subclass can
distinguish prompt output from data.  But it was not that simple.
2014-08-24 12:35:53 +09:00
FUJIWARA Katsunori
e8856bc78d ui: invoke editor for committing with HGEDITFORM environment variable
At the external editor invocation for committing, the value specified
as "editform" for "cmdutil.getcommiteditor" is in "HGEDITFORM".

This enables external editor to do own customization according to
commit types.
2014-08-15 23:05:53 +09:00
anatoly techtonik
023b57a106 config: allow 'user' in .hgrc ui section (issue3169) 2014-07-26 09:27:11 +03:00
Yuya Nishihara
96a8ea56df cmdserver: forcibly use L channel to read password input (issue3161)
Command server is designed to use the channel protocol even if the server
process is accessible to tty, whereas vanilla hg should be able to read
password from tty in that case.  So it isn't enough to swap sys.stdin:

    # works only if the server process is detached from the console
    sys.stdin = self.fin
    getpass.getpass('')
    sys.stdin = oldin

or test isatty:

    # vanilla hg can't talk to tty if stdin is redirected
    if self._isatty(self.fin):
        return getpass.getpass('')
    else:
        ...

Since ui.nontty flag is undocumented and command-server channels don't provide
isatty(), this change won't affect the other uses of ui._isatty().

issue3161 also suggests to provide some context of messages.  I think it can
be implemented by using the generic templating function.
2014-04-26 18:13:06 +09:00
Pierre-Yves David
2feab6f005 ui: pushbuffer can now also capture stderr
We need an easy way to capture both stderr and stdout during bundle2 processing
of a remote bundle. This changeset adds simple changes to the `ui` class to make
this possible.

I expect the interface to change in future releases as bundle2 will probably want to
distinguish stdout and stderr. The current change will, however, do for now.
2014-04-16 23:36:57 -04:00
Mads Kiilerich
160aa99a26 config: give a useful hint of source for the most common command line settings
'hg showconfig --debug' will instead of:
  none: ui.verbose=False
give the better hint:
  --verbose: ui.verbose=False
2014-03-19 02:45:04 +01:00
Mads Kiilerich
55b56c55c8 config: backout 012889e73d40 - 8224e8f455bf removed the only use of overlay 2014-03-19 01:59:15 +01:00
Alexander Drozdov
8bd59ff2d8 ui: edit(): transplant: set HGREVISION environment variable for an editor
transplant command set 'transplant_source' extra for the revision.
Allow an editor to access the extra using HGREVISION environment variable.

This may be useful when an editor is actually a script which modifies a commit
message. Transplant filters is an alternative way to do it.
2014-02-10 07:13:10 +04:00
Alexander Drozdov
bc85c50d9f ui: edit(): rebase, graft: set HGREVISION environment variable for an editor
rebase and graft commands set 'rebase_source' or 'source' extras for the revision.
Allow an editor to access the extras using HGREVISION environment variable.

This may be useful when an editor is actually a script which modifies a commit
message.

The name 'HGREVISION' has been selected as transplant already sets this variable
for its filters (--filter).
2014-02-06 12:21:20 +04:00
Alexander Drozdov
76bdfab906 ui: allow edit() to work with revision extras
Make edit() to accept optional 'extra' dictionary. Revision extras will be
used in upcoming patches to set some environment variables.
2014-02-06 11:38:28 +04:00
Matt Mackall
ab8d3b450f ui: fix extra space in username abort 2014-02-27 15:14:37 -06:00
Matt Mackall
6ba3cc7397 ui: suggest config --edit when no username is set 2014-02-27 14:46:29 -06:00
FUJIWARA Katsunori
1629d4ee7f ui: add "extractchoices()" to share the logic to extract choices from prompt 2013-12-02 00:50:29 +09:00
Matt Mackall
397a3b5d72 merge with stable 2013-10-09 14:15:34 -07:00
Matt Mackall
4b0ea6e3c8 ui: send password prompts to stderr again (issue4056) 2013-10-09 11:27:59 -07:00
Augie Fackler
15caa41e46 ui.config: fix bug in config alternatives from 98114deb235a 2013-07-24 19:13:39 -04:00
Matt Mackall
13d2a13ea6 ui: merge prompt text components into a singe string
This will help avoid problems with partial or mismatched translation
of the components.
2013-05-22 17:31:43 -05:00
Bryan O'Sullivan
7f31537028 ui: use util.sizetoint in configbytes 2013-05-14 15:16:44 -07:00
FUJIWARA Katsunori
2de8c4416b i18n: show the non-ASCII password prompt text correctly
Before this patch, the prompt text for asking password is directly
passed to "getpass.getpass()" of Python standard library.

In "getpass.getpass()" implementation on Windows environment, the
prompt text is split into byte sequence and "msvcrt.putch()" is
applied on each bytes in it. This splitting causes non-ASCII prompt
text to be broken.

This patch shows the prompt text for asking password on "ui.getpass()"
side, and invokes "getpass.getpass()" with empty prompt text. This
prevents non-ASCII prompt text from being broken in
"getpass.getpass()" implementation.

This patch also sets "ui.prompt" label to prompt text to follow
"ui.prompt()" style.
2013-04-25 20:48:49 +09:00
Bryan O'Sullivan
12ef7ce995 ui: add a configbytes method, for space configuration
This accepts a floating point number, followed by optional whitespace,
followed by an optional one- or two-letter unit specifier (for
bytes, kilobytes, megabytes, or gigabytes).
2013-04-18 12:58:28 -07:00
Matt Harbison
7f63ccb02c ui: add 'force' parameter to traceback() to override the current print setting
This will allow a current traceback.print_exc() call in dispatch to be replaced
with ui.traceback() even if --traceback was not given on the command line.
2013-02-09 14:22:52 -05:00
Matt Harbison
8ab43e8c5a ui: add support for fully printing chained exception stacks in ui.traceback()
Currently, only SubrepoAbort has a cause chained to it.
2013-02-09 14:15:34 -05:00
Durham Goode
4add84adea blackbox: adds a blackbox extension
Adds a blackbox extension that listens to ui.log() and writes the messages to
.hg/blackbox.log. Future commits will use ui.log() to log commands, unhandled
exceptions, incoming changes, and hooks.  The extension defaults to logging
everything, but can be configured via blackbox.track to only log certain events.
Log lines are of the format:  "date time user> message"

Example log line:
2013/02/09 08:35:19 durham> 1 incoming changes - new heads: d84ced58aaa
2013-02-12 14:08:33 -08:00
Mads Kiilerich
ac8e1fc147 check-code: there must also be whitespace between ')' and operator
The check pattern only checked for whitespace between keyword and operator.

Now it also warns:
 >     x = f(),7
 missing whitespace after ,
 >     x = f()+7
 missing whitespace in expression
2012-12-09 23:33:16 +01:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Matt Mackall
61aa1f42b8 merge with stable 2012-06-29 00:40:52 -05:00
Idan Kamara
7875dccb0b ui: add a variable to control whether hooks should be called
So hooks can be temporarily disabled.
2012-06-23 19:57:07 +03:00