sapling/hgext3rd/hiddenhash.py
Arun Kulshreshtha da74a12dac hiddenhash: make hidden commit errors more user friendly
Summary:
Previously, when a command tried to access a hidden revision without the `--hidden` flag, the user would get the following error:

```
abort: hidden revision '0'!
(use --hidden to access hidden revisions)
```

With this extension, the error is now:

```
abort: hidden commit b8144197c244!
```

This way, novice users aren't tempted to immediately re-run the command with `--hidden`, which may have undesired results. It also makes it much easier to find the commit in question in `hg sl --hidden` since by default smartlog does not show rev numbers.


Test Plan: Attempt to access a hidden commit, observe new error message as seen above. Note that in the test file the word "changeset" is present instead of "commit" due to the lack of the `dialect` extension in the test.

Reviewers: #mercurial, simonfar

Reviewed By: simonfar

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4506065

Tasks: 15747879

Signature: t1:4506065:1486122372:d82ebd488a00d1958c235f733a9455111954c116
2017-02-03 12:26:22 -08:00

40 lines
1.1 KiB
Python

# hiddenhash.py
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""friendlier error messages for filtered lookup errors"""
testedwith = 'ships-with-fb-hgext'
import re
from mercurial import (
context,
error,
extensions,
)
from mercurial.i18n import _
from mercurial.node import short
def uisetup(ui):
extensions.wrapfunction(context, 'changectx', _wrapchangectx)
def _wrapchangectx(orig, repo, *args, **kwargs):
"""Edit the error message for FilteredRepoLookupError to show a
hash instead of a rev number, and don't suggest using --hidden.
"""
try:
return orig(repo, *args, **kwargs)
except error.FilteredRepoLookupError as e:
match = re.match(r"hidden revision '(\d+)'", e.message)
if not match:
raise
rev = int(match.group(1))
node = repo.unfiltered().changelog.node(rev)
msg = _("hidden changeset %s") % short(node)
raise error.FilteredRepoLookupError(msg)