Commit Graph

519 Commits

Author SHA1 Message Date
Bryan O'Sullivan
173258cfa2 ui: rewrite configint in terms of configwith 2017-02-12 21:44:55 -08:00
Bryan O'Sullivan
0fd65c7a86 ui: add a configwith method
This is a long-overdue generalization of the pattern in configint
and configbool.
2017-02-12 21:40:46 -08:00
Pulkit Goyal
56031921a5 py3: convert the mode argument of os.fdopen to unicodes (2 of 2) 2017-02-13 22:15:28 +05:30
Pulkit Goyal
8edc9540ee py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
sys.platform returns unicode on python 3 world. Our code base has most of the
things bytes because of the transformer. So we have a bytes version of this as
pycompat.sysplatform. This series of 2 patches replaces occurences of
sys.platform with pycompat.sysplatform.
2016-12-19 02:15:24 +05:30
Pulkit Goyal
24a9271007 py3: replace os.environ with encoding.environ (part 4 of 5) 2016-12-18 02:06:00 +05:30
Yuya Nishihara
26dd8d740c ui: do not translate empty configsource() to 'none' (API)
It should be processed when displaying data, so we can get "source": "" in
JSON output.
2016-10-23 17:47:00 +09:00
Pulkit Goyal
4245797c62 py3: avoid use of basestring
"In this case, result is a source variable of a list to be returned, it
shouldn't be unicode. Hence we can use bytes instead of basestring here." -Yuya
2016-11-30 23:51:11 +05:30
Yuya Nishihara
1d44bd2bbb ui: factor out ui.load() to create a ui without loading configs (API)
This allows us to write doctests depending on a ui object, but not on global
configs.

ui.load() is a class method so we can do wsgiui.load(). All ui() calls but
for doctests are replaced with ui.load(). Some of them could be changed to
not load configs later.
2016-10-22 14:35:10 +09:00
Gregory Szorc
9f87ab8fca ui: use try..finally in configoverride
@contextmanager almost always have their "yield" inside a try..finally
block. This is because if the calling code inside the activated
context manager raises, the code after the "yield" won't get
executed. A "finally" block, however, will get executed in this
scenario.
2016-11-26 09:14:41 -08:00
Pulkit Goyal
97f340e354 py3: use pycompat.getcwd() instead of os.getcwd()
We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.
2016-11-23 00:03:11 +05:30
Kostia Balytskyi
652e43055e ui: add configoverride context manager
I feel like this idea might've been discussed before, so please
feel free to point me to the right mailing list entry to read
about why it should not be done.

We have a common pattern of the following code:
    backup = ui.backupconfig(section, name)
    try:
        ui.setconfig(section, name, temporaryvalue, source)
        do_something()
    finally:
        ui.restoreconfig(backup)

IMO, this looks better:
    with ui.configoverride({(section, name): temporaryvalue}, source):
        do_something()

Especially this becomes more convenient when one has to backup multiple
config values before doing something. In such case, adding a new value
to backup requires codemod in three places.
2016-11-21 16:22:26 -08:00
Yuya Nishihara
47f9c8b52e py3: bulk replace sys.stdin/out/err by util's
Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's.
There are a few exceptions:

 - lsprof.py and statprof.py are untouched since they are a kind of vendor
   code and they never import mercurial modules right now.
 - ui._readline() needs to replace sys.stdin and stdout to pass them to
   raw_input(). We'll need another workaround here.
2016-10-20 23:53:36 +09:00
Augie Fackler
d40f484280 ui: explicitly open config files in binary mode
This has been working mostly accidentally, but now it works explicitly.
2016-10-09 09:17:49 -04:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
Yuya Nishihara
d1b623a5c1 scmutil: extend termwidth() to return terminal height, renamed to termsize()
It appears crecord.py has its own termsize() function. I want to get rid of it.

The fallback height is chosen from the default of cmd.exe on Windows, and
VT100 on Unix.
2016-10-20 23:09:05 +09:00
Yuya Nishihara
5b9ee7c321 scmutil: make termwidth() obtain stdio from ui
I'm getting rid of direct sys.stderr|out|in references so Py3 porting will
be slightly easier.
2016-10-20 21:42:11 +09:00
Yuya Nishihara
52e59de51c scmutil: move util.termwidth()
I'm going to get rid of sys.stderr|out|in references from posix.termwidth().
In order to do that, termwidth() needs to take a ui, but functions in util.py
shouldn't depend on a ui object. So moves termwidth() to scmutil.py.
2016-10-20 21:38:44 +09:00
Pulkit Goyal
a1ce407d6d py3: use encoding.environ in ui.py
Using source transformer we add b'' everywhere. So there are no chances
that those bytes string will work with os.environ on Py3 as that returns a
dict of unicodes. We are relying on the errors, even though no error is raised
even in future, these pieces of codes will tend to do wrong things.
if statements can result in wrong boolean and certain errors can be raised
while using this piece of code. Let's not wait for them to happen, fix what is
wrong. If this patch goes in, I will try to do it for all the cases.
Leaving it as it is buggy.
2016-11-03 03:12:57 +05:30
timeless
94b5113786 samplehgrcs: use single quotes in use warning 2016-09-20 23:49:00 +00:00
Jun Wu
5e8afd381a ui: drop values returned by inspect.*frame*() to avoid cycles
"f = inspect.currentframe()" instantly creates a cycle because
"f.f_locals['f']" is "f" itself.

This patch explicitly sets those frame objects to None to avoid cycles.
2016-08-10 15:05:20 +01:00
Gregory Szorc
9c6bc630a3 ui: path option to declare which revisions to push by default
Now that we have a mechanism for declaring path sub-options, we can
start to pile on features!

Many power users have expressed frustration that bare `hg push`
attempts to push all local revisions to the remote. This patch
introduces the "pushrev" path sub-option to control which revisions
are pushed when no "-r" argument is specified.

The value of this sub-option is a revset, naturally.

A future feature addition could potentially introduce a "pushnames"
sub-options that declares the list of names (branches, bookmarks,
topics, etc) to push by default. The entire "what to push by default"
feature should probably be considered before this patch lands.
2016-06-26 07:59:02 -07:00
Gregory Szorc
bbde62ff9f ui: don't fixup [paths] sub-options
As part of developing a subsequent patch I discovered that sub-option
values like "." were getting converted to paths. This is because the
[paths] section is treated specially during config loading.

This patch prevents post-processing sub-options from the [paths]
section.
2016-06-25 18:35:14 -07:00
liscju
ade9d0fabe url: remember http password database in ui object
This makes http password database stored in ui object.
It allows reusing authentication information when we
use this database for creating password manager for
the new connection.
2016-06-09 11:41:36 +02:00
Yuya Nishihara
bed8e170aa ui: provide official way to reset internal state per command
This will allow us to clear in-memory password storage per runcommand().

I've updated commandserver to call resetstate() of both ui and repo.ui because
they may have different states in theory.
2016-06-12 14:07:26 +09:00
Gregory Szorc
df3e0225af ui: add an instance flag to hold --insecure bit
Currently, when --insecure is used we set web.cacerts=! and
socket validation takes this value into account. web.cacerts=!
is not documented AFAICT and is purely an internal implementation
detail.

Let's be more explicit about what is going on by introducing a
dedicated variable outside of the config values to track that
--insecure is used.
2016-05-05 00:33:38 -07:00
Pierre-Yves David
219311a353 devel: use the new 'config' argument of the develwarn in deprecwarn
Controling all deprecation warnings with the same config seems sensible. This
mirror a fix (about missing gating) submitted for stable but with the new API.
2016-05-08 10:43:41 +02:00
Pierre-Yves David
55590a35e7 develwarn: move config gating inside the develwarn function
The config gating is almost always the same and contributor tend to forget it.
We move the logic inside the function. Call site will be updated in later
changeset. We might make the sub config mandatory in the future (once all old
call sites are gone).
2016-05-08 10:43:41 +02:00
Pierre-Yves David
981a2cbeeb deprecation: gate deprecation warning behind devel configuration
Regular users are not supposed to be exposed to the API deprecation warnings.
We now only issue them when the developper warnings are enabled.
2016-05-05 16:29:31 +02:00
timeless
4466b53c45 config: use single quotes around command hint
Windows command lines use double quotes to quote arguments with spaces.
This change is in a series to unify around using single quotes around
commands, and double quotes around interior arguments.
2016-04-14 15:18:59 +00:00
Yuya Nishihara
d21d4d0b82 ui: drop template aliases by HGPLAIN
Otherwise, scripting output could be suffered from user aliases.
2016-03-27 21:05:55 +09:00
Jordi Gutiérrez Hermoso
bc9b8cd792 edit: allow to configure the suffix of the temporary filename
Sometimes, we can pick a more appropriate default suffix than ".txt",
for example, diffs could have a ".diff" suffix.
2016-03-20 13:55:41 -04:00
timeless
45450b6576 ui: add prompt argument to write (issue5154) (API)
When code like filemerge._iprompt calls ui.prompt, it expects
the user to see the output in addition to getting the prompt.

Other code such as histedit may call ui.pushbuffer, but its
goal is not to interfere with prompts, so this commit adds
an optional prompt flag to ui.write and has _readline
include that argument.

ui.promptchoice calls ui.prompt which calls ui._readline.

This commit also updates hgext.color.write.
2016-03-25 21:51:00 +00:00
timeless
f6dffaf6bd progress: update comment to reflect implementation
Progress has been on by default in core for a while,
the comment was written before this happened.
2016-03-17 18:34:32 +00:00
Simon Farnsworth
c7b3ee31ad ui: add new config flag for interface selection
This patch introduces a new config flag ui.interface to select the interface
for interactive commands. It currently only applies to chunks selection.
The config can be overridden on a per feature basis with the flag
ui.interface.<feature>.

features for the moment can only be 'chunkselector', moving forward we expect
to have 'histedit' and other commands there.

If an incorrect value is given to ui.interface we print a warning and use the
default interface: text. If HGPLAIN is specified we also use the default
interface: text.

Note that we fail quickly if a feature does not handle all the interfaces
that we permit in ui.interface; in future, we could design a fallback path
(e.g. blackpearl to curses, curses to text), but let's leave that until we
need it.
2016-03-14 15:01:27 +00:00
timeless
7081e9f3c4 ui: log devel warnings 2016-01-29 14:37:16 +00:00
Matt Mackall
0fcff83b31 merge with stable 2016-02-24 15:55:44 -06:00
Yuya Nishihara
02e214117d ui: fix crash by non-interactive prompt echo for user name
Since we've dropped a str cast at write() by 7dbd3db608c5, ui.prompt() should
convert default to '' if it is None. Otherwise, write() would fail with
"TypeError: object of type 'NoneType' has no len()".

This patch includes the tests for both interactive and non-interactive cases
because "ui.askusername" was never tested.
2016-02-06 20:43:20 +09:00
Yuya Nishihara
b14e0888a3 config: drop progress extension from sample hgrc as it is in core now 2015-12-15 23:50:48 +09:00
Bryan O'Sullivan
b0ea3c69dd config: add hasconfig method and supporting plumbing
We add the hasconfig method to make it possible to distinguish between a
config value that was never supplied and one that is empty.
2016-01-07 19:45:03 -08:00
Yuya Nishihara
de1b826a0e paths: do not process default-push as pushurl of default path (issue5000)
It didn't work because "default-push" and "default" are independent named
items. Without this patch, "hg push default" would push to "default-push"
because paths["default"].pushloc was overwritten by "default-push".

Also, we shouldn't ban a user from doing "hg push default-push" so long as
"default-push" item is defined, not "default:pushurl". Otherwise, he would
be confused by missing "default-push" path.

Tests are included in a patch for stable branch.
2015-12-26 16:06:12 +09:00
Yuya Nishihara
171a817aca paths: make getpath() accept multiple defaults
This is necessary to handle "default-push" and "default" as fallback items.
We can't apply the same rule as "default:pushurl" because "default-push" is
a valid named path.

This series is for default branch. I have a simpler patch for stable.
2015-12-26 16:10:39 +09:00
Bryan O'Sullivan
357b2bf2ee ui: remove unreachable code 2015-12-22 15:25:40 -08:00
Matt Mackall
356bea2fb3 merge with stable 2015-12-17 17:27:32 -06:00
Matt Mackall
11c5081e05 ui: try to handle $$ more robustly in prompts (issue4970) 2015-11-30 13:47:29 -06:00
Gregory Szorc
51ee0dd173 ui: support paths.default-push without paths.default set (issue4914)
This behavior regressed as part of the paths API refactoring. Previous
behavior was to accept "default-push" without "default" defined. Current
behavior aborts with "default repository not configured!." This patch
restores the old behavior and adds test coverage for the scenario, which
was absent before.
2015-10-22 18:59:03 +00:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
FUJIWARA Katsunori
36207b46bf cmdutil: make in-memory changes visible to external editor (issue4378)
Before this patch, external editor process for the commit log can't
view some in-memory changes (especially, of dirstate), because they
aren't written out until the end of transaction (or wlock).

This causes unexpected output of Mercurial commands spawned from that
editor process.

To make in-memory changes visible to external editor process, this
patch does:

  - write (or schedule to write) in-memory dirstate changes, and
  - set HG_PENDING environment variable, if:
    - a transaction is running, and
    - there are in-memory changes to be visible

"hg diff" spawned from external editor process for "hg qrefresh"
shows:

  - "changes newly imported into the topmost" before ab68b153ce34(*)
  - "all changes recorded in the topmost by refreshing" after this patch

(*) ab68b153ce34 changed steps invoking editor process

Even though backward compatibility may be broken, the latter behavior
looks reasonable, because "hg diff" spawned from the editor process
consistently shows "what changes new revision records" regardless of
invocation context.

In fact, issue4378 itself should be resolved by b46029eb5b29, which
made 'repo.transaction()' write in-memory dirstate changes out
explicitly before starting transaction. It also made "hg qrefresh"
imply 'dirstate.write()' before external editor invocation in call
chain below.

  - mq.queue.refresh
    - strip.strip
      - repair.strip
        - localrepository.transaction
          - dirstate.write
    - localrepository.commit
      - invoke external editor

Though, this patch has '(issue4378)' in own summary line to indicate
that issues like issue4378 should be fixed by this.

BTW, this patch adds '-m' option to a 'hg ci --amend' execution in
'test-commit-amend.t', to avoid invoking external editor process.

In this case, "unsure" states may be changed to "clean" according to
timestamp or so on. These changes should be written into pending file,
if external editor invocation is required,

Then, writing dirstate changes out breaks stability of test, because
it shows "transaction abort!/rollback completed" occasionally.

Aborting after editor process invocation while commands below may
cause similar instability of tests, too (AFAIK, there is no more such
one, at this revision)

  - commit --amend
    - without --message/--logfile

  - import
    - without --message/--logfile,
    - without --no-commit,
    - without --bypass,
    - one of below, and
      - patch has no description text, or
      - with --edit
    - aborting at the 1st patch, which adds or removes file(s)
      - if it only changes existing files, status is checked only for
        changed files by 'scmutil.matchfiles()', and transition from
        "unsure" to "normal" in dirstate doesn't occur (= dirstate
        isn't changed, and written out)
      - aborting at the 2nd or later patch implies other pending
        changes (e.g. changelog), and always causes showing
        "transaction abort!/rollback completed"
2015-10-17 01:15:34 +09:00
Pierre-Yves David
63cc76d3b4 ui: add a 'deprecwarn' helper to issue deprecation warnings
As discussed on the list, we are adding an official way to keep old API around
for a short time in order to help third party developer to catch up. The
deprecated API will issue developer warning (issued by default during test runs)
to warn extensions authors that they need to upgrade their code without
instantaneously breaking tool chains and normal users.

The version is passed as an explicit argument so that developer think about it
and a potential future script can automatically check for it.

This is not build as a decorator because accessing the 'ui' instance will likely
be different each time. The message is also free form because deprecated API are
replaced in a variety of ways. I'm not super happy about the final rendering of
that message, but this is a developer oriented warning and I would like to move
forward.
2015-12-05 23:05:49 -08:00
Pierre-Yves David
9e2713890f ui: add a 'stacklevel' argument to 'develwarn'
This allows helper functions (like deprecation warning) to prepare a devel
warning for higher up in the stack. The argument is named after the one in the
Python's 'warning,warn' function.
2015-12-05 23:05:33 -08:00
Gregory Szorc
e2ea48dfff ui: support declaring path push urls as sub-options
Power users often want to apply per-path configuration options. For
example, they may want to declare an alternate URL for push operations
or declare a revset of revisions to push when `hg push` is used
(as opposed to attempting to push all revisions by default).

This patch establishes the use of sub-options (config options with
":" in the name) to declare additional behavior for paths.

New sub-options are declared by using the new ``@ui.pathsuboption``
decorator. This decorator serves multiple purposes:

* Declaring which sub-options are registered
* Declaring how a sub-option maps to an attribute on ``path``
  instances (this is needed to `hg paths` can render sub-options
  and values properly)
* Validation and normalization of config options to attribute
  values
* Allows extensions to declare new sub-options without monkeypatching
* Allows extensions to overwrite built-in behavior for sub-option
  handling

As convenient as the new option registration decorator is, extensions
(and even core functionality) may still need an additional hook point
to perform finalization of path instances. For example, they may wish
to validate that multiple options/attributes aren't conflicting with
each other. This hook point could be added later, if needed.

To prove this new functionality works, we implement the "pushurl"
path sub-option. This option declares the URL that `hg push` should
use by default.

We require that "pushurl" is an actual URL. This requirement might be
controversial and could be dropped if there is opposition. However,
objectors should read the complicated code in ui.path.__init__ and
commands.push for resolving non-URL values before making a judgement.

We also don't allow #fragment in the URLs. I intend to introduce a
":pushrev" (or similar) option to define a revset to control which
revisions are pushed when "-r <rev>" isn't passed into `hg push`.
This is much more powerful than #fragment and I don't think #fragment
is useful enough to continue supporting.

The [paths] section of the "config" help page has been updated
significantly. `hg paths` has been taught to display path sub-options.

The docs mention that "default-push" is now deprecated. However, there
are several references to it that need to be cleaned up. A large part
of this is converting more consumers to the new paths API. This will
happen naturally as more path sub-options are added and more and more
components need to access them.
2015-12-05 21:11:04 -08:00
Gregory Szorc
88ed7013ad ui: pass ui instance to path.__init__
It will be used in a subsequent patch.
2015-12-06 12:31:46 -08:00
Gregory Szorc
fb6cc829b7 ui: store pushloc as separate attribute
The magic @property is going to interfere with the ability to print
path sub-options. We only access it in one location and it is trivial
to in-line, so do that.
2015-12-06 11:49:02 -08:00
Gregory Szorc
cf7ff66486 ui: optionally ignore sub-options from configitems()
For convenience.
2015-12-05 20:24:39 -08:00
Gregory Szorc
220a833776 ui: add method to return option and all sub-options
Apparently ":" has been blessed as a generic separator for
options and sub-options. We formalize this by introducing an API
for obtaining an option and all its sub-options.

This will be used in a subsequent patch for declaring sub-options
for [paths].
2015-12-05 20:20:57 -08:00
Mykola Nikishov
b606ca0911 ui: allow open editor with custom filename
By default, editor will use temp file named after hard-coded pattern
'hg-editor-XXX.txt' which makes it impossible for extensions to use
another filename if desired.

Now the middle part of the pattern ('editor') can be changed by
setting extra['prefix'].
2015-11-21 22:04:09 +02:00
Gregory Szorc
d84af347c4 ui: avoid needless casting to a str
In many cases, we don't need to cast to a str because the object will
be cast when it is eventually written.

As part of testing this, I added some code to raise exceptions when a
non-str was passed in and wasn't able to trigger it. i.e. we're already
passing str into this function everywhere, so the casting isn't
necessary.
2015-11-22 14:44:55 -08:00
Gregory Szorc
b184853d7f ui: remove labeled argument from popbuffer
It was moved to pushbuffer and currently does nothing.
2015-11-24 11:23:10 -08:00
Gregory Szorc
b338644768 ui: track label expansion when creating buffers
As part of profiling `hg log` performance, I noticed a lot of time
is spent in buffered writes to ui instances. This patch starts a series
that refactors buffered writes with the eventual intent to improve
performance.

Currently, labels are expanded when buffers are popped. This means
we have to preserve the original text and the label until we render
the final output. This is avoidable overhead and adds complexity
since we're retaining state.

This patch adds functionality to ui.pushbuffer() to declare whether
label expansion should be active for the buffer. Labels are still
evaluated during buffer pop. This will change in a subsequent
patch.

Since we'll need to access the "expand labels" flag on future write()
operations, we prematurely optimize how the current value is stored
to optimize for rapid retrieval.
2015-11-22 14:10:48 -08:00
Gregory Szorc
de3b37d77c ui.write: don't clear progress bar when writing to a buffer
ui.write() has 2 modes: buffered and unbuffered. In buffered mode, we
capture output before writing it. This is how changeset printing works,
for example.

Previously, we were potentially clearing the progress bar for every
call to ui.write(). In buffered mode, this clearing was useless because
the clearing function would be called again before actually writing
the buffered data.

This patch stops the useless calling of _progclear() unless we are
actually writing data. During changeset printing with the default
template, this removes ~6 function calls per changeset, making
changeset printing slightly faster.

before: 23.76s
after:  23.35s
delta:  -0.41s (98.3% of original)
2015-11-14 17:14:14 -08:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Yuya Nishihara
0ef9100e86 ui: send traceback of devel warning to appropriate output stream
If ui.ferr is a command-server channel, traceback should be written to it.
2015-10-03 23:10:40 +09:00
Siddharth Agarwal
6cf13d398f ui: avoid mutable default arguments
I almost introduced a bug around this code by accidentally mutating a default
argument. There's no reason for these to exist.

It is OK to not assign {} to environ in ui.system because util.system knows how
to deal with that.
2015-09-22 16:56:34 -07:00
Augie Fackler
62a104b3a9 ui: improve docs on ui.log
This makes the documentation on ui.log line up with the use of that
interface in blackbox.
2015-09-10 10:50:03 -04:00
Gregory Szorc
7c62588e37 ui: change default path fallback mechanism (issue4796)
The previous paths API code always fell back to the default path. This
was wrong because if a requested path doesn't exist, that should error.
Only if no path was requested should we fall back to the default.

As part of implementing the test case for issue 4796, it was discovered
that the "repository does not exist" error message raised by
localrepository.__init__ wasn't being seen because the paths API
validates paths before localrepository.__init__ was being called.
The exception and error message from localrepository.__init__ has
been introduced to getpath(). This necessitated rewriting
expandpath() both to catch the exception and to have proper
default fallback.

This code is more complicated than I'd like. But making all tests pass
was a big chore. As more code moves to getpath(), there will likely be
opportunities to improve things a bit.
2015-09-06 11:28:48 -07:00
Durham Goode
19ed8b04d1 paths: move path validation logic to its own function
Hard coding the '.hg' path in the paths class made it difficult for the hggit
extension to pull from gitrepos.

This patch moves the logic out to it's own function so extensions can add
additional checks to what is a valid path (i.e. a git repo is valid when hggit
is enabled).
2015-08-24 19:33:36 -07:00
Gregory Szorc
ee8f8b8d5d ui: capture push location on path instances
Currently, we treat "default" and "default-push" as separate paths,
even though they are the same logical entity but with different paths
for different operations. Because they are the same entity and
because we will eventually be implementing an official mechanism
for declaring push URLs for paths, we establish a "pushloc" attribute
on path instances. We populate this attribute on the "default" path
with the "default-push" value, if present. This will enable
consumers stop referencing "default-push" which will make their code
simpler.
2015-08-07 21:53:34 -07:00
Gregory Szorc
6ade48b23b ui: move URL and path detection into path API
ui.expandpath() has code for recognizing URLs or local filesystem
paths. Our goal is to use ``path`` class instances everywhere a path
is represented.

Changing ui.expandpath() to return path instances is a lot of work.
Our goal is to slowly marginalize it by moving logic into the paths
API and to convert callers to the paths API.

Many callers of ui.expandpath() pass in a value that could be a
local filesystem path or URI. We move the detection of these strings
from ui.expandpath() to paths.getpath() and path.__init__(). To do
this properly in a way that is compatible with future callers, we
need to parse the "#branch" syntax out of locations. This is a bit
complicated, but it is necessary.

The code for URL parsing is essentially a copy of hg.parseurl().
Once all consumers are speaking the paths API, it is likely that
this function won't be called any more and it can be deleted.
2015-08-08 00:16:02 -07:00
Siddharth Agarwal
6e6f3927e3 error: add structured exception for EOF at prompt
We'll catch this exception for promptchoice queries to provide better error
handling.
2015-11-10 00:46:45 -08:00
Gregory Szorc
97fa6a9809 ui: use absolute_import
And we have no more ambiguous mixed imports \o/
2015-08-08 18:25:41 -07:00
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
Martin Geisler
2fb6d24292 ui: lowercase "no username" warning 2012-06-12 14:18:18 +02:00
Martin Geisler
85338c4193 ui: lowercase "not trusting file" warning message 2012-06-12 14:18:18 +02:00
Martin Geisler
d599cd6742 ui: lowercase ConfigError warning message 2012-06-12 14:18:18 +02:00
Matt Mackall
b267442ddb ui: add _isatty method to easily disable cooked I/O 2012-05-20 14:31:56 -05:00
Brodie Rao
46ce54af4d cleanup: replace more naked excepts with more specific ones 2012-05-13 13:17:31 +02:00
Brodie Rao
d6a6abf2b0 cleanup: eradicate long lines 2012-05-12 15:54:54 +02:00
Steven Stallion
d79ff306e5 plan9: initial support for plan 9 from bell labs
This patch contains support for Plan 9 from Bell Labs. A README is
provided in contrib/plan9 which describes the port in greater detail.
A new extension is also provided named factotum which permits the
factotum(4) authentication agent to provide credentials for HTTP
repositories. This extension is also applicable to other POSIX
platforms which make use of Plan 9 from User Space (aka plan9ports).
2012-04-08 12:43:41 -07:00
Matt Mackall
560dd93d34 merge with stable 2012-04-06 15:18:14 -05:00
Kevin Bullock
cb270596b4 ui: swallow EBADF on stderr
ui.write_err already swallows EPIPE and EIO if a write to stderr fails.
On Mac OS X at least, a write to a closed file descriptor results in
EBADF. Before this patch, hg would exit with status 1 if a write to
stderr failed during startup (e.g. while trying to print a warning about
not finding an extension):

  $ ./hg --config extensions.foo= version 2>&-; echo $?
  1

With this patch, it correctly swallows stderr and continues to run the
command:

  $ ./hg --config extensions.foo= version 2>&-
  Mercurial Distributed SCM (version 2.1)
  ...
2012-04-04 12:46:54 -05:00
Matt Mackall
107150b868 ui: add formatter method 2012-02-20 16:42:48 -06:00
Pierre-Yves David
3dfd3d6ee3 config: have a way to backup and restore value in config
This is introduce to allow temporary overwriting of a config value while being
able to reinstall the old value once done. The main advantage over using
``config`` and ``setconfig`` is that backup and restore will properly restore
the lack of any config. Restoring the fact that there was no value is important
to allow config user to keep using meaniful default value.

A more naive approach will result in the following scenario::

  Before:
    config(section, item, my_default) --> my_default

  temporal overwrite
    old = config(section, item)
    …
    setconfig(section, item, old)

  After
    config(section, item, my_default) --> None

The first user of this feature should be mq to overwriting minimal phase of
future commit.
2012-01-18 16:52:26 +01:00
Matt Mackall
864ce9da04 misc: adding missing file close() calls
Spotted by Victor Stinner <victor.stinner@haypocalc.com>
2011-11-03 11:24:55 -05:00
Matt Mackall
af293bcf51 merge with stable 2011-09-12 23:02:45 -05:00
Simon Heimberg
4cccc99bac ui: write traceback to self.ferr 2011-09-11 14:42:30 +02:00
Martin Geisler
9b3666843e ui: also swap sys.stdout with self.fout in _readline
In 55a66b5d9114, _readline was changed to output a space using
raw_input and this was done using sys.stdout directly, not self.fout.

This change broke the command server for JavaHg since it (and other
clients) would see a spurious ' ' on stdout and interpret this as an
unknown channel.
2011-08-30 14:18:58 +02:00
Idan Kamara
9b89917a5f ui: pass ' ' to raw_input when prompting
This is a workaround for calling ui.prompt(...), typing some character then
hitting backspace which causes the entire line to delete rather than just the
one character. This was seen on Debian using gnome-terminal.

(credits to Mads for the idea)

Python bug can be found here: http://bugs.python.org/issue12833
2011-08-25 22:06:03 +03:00
Idan Kamara
bc85c198e4 ui: call write() so the prompt string goes through subclassed implementation 2011-08-01 19:53:00 +03:00
Martin Geisler
0bbf634d5b merge with stable 2011-08-30 15:22:10 +02:00
Matt Mackall
afa4ceeda8 merge with stable 2011-08-25 16:21:53 -05:00
Matt Mackall
eebe42565e ui: allow alternatives for config options 2011-08-11 14:34:03 -05:00
Matt Mackall
eb714d4d00 merge with stable 2011-08-01 14:52:11 -05:00
Simon Heimberg
9cc31081c5 ui: config path relative to repo root 2011-07-23 06:09:14 +02:00
Simon Heimberg
e99ca763b9 ui: providing no default value to configpath should not raise an Error 2011-07-23 06:08:52 +02:00
Simon Heimberg
28de693a93 ui: fix error, base can not be a list 2011-07-23 06:08:49 +02:00
Matt Mackall
d056d98ad8 ui: rename _is_trusted to _trusted
is and do are pointless, underbar separators are style violations
2011-07-12 16:36:22 -05:00
Idan Kamara
fce499faf1 ui: use ui out descriptor when calling util.system 2011-06-24 17:04:37 +03:00
David Soria Parra
881ac28f17 i18n: remove translation of debug messages 2011-06-21 18:35:13 +02:00
Idan Kamara
325f77da0a ui: use I/O descriptors internally
and as a result:
- fix webproto to redirect the ui descriptors instead of sys.stdout/err
- fix sshserver to use the ui descriptors
2011-06-08 01:39:20 +03:00
Idan Kamara
d3e4ddd52a ui: add I/O descriptors 2011-06-07 13:39:09 +03:00
Idan Kamara
02f21a70dc util: add helper function isatty(fd) to check for tty-ness 2011-06-02 00:43:34 +03:00
Yann E. MORIN
236f8c6745 ui: enable alias exception when reading config in plain mode
When in plain mode with "alias" present in the exception list,
keep the aliases. This will be used later to enable auto-completion.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
2011-05-17 00:17:52 +02:00