[PATCH 3 of 3] ui: Add option to set number of revision hash digits displayed
Eric Hopper
hopper at omnifarious.org
Fri Jul 24 13:29:38 CDT 2009
mercurial/cmdutil.py | 4 ++--
mercurial/commands.py | 14 +++++++-------
mercurial/dispatch.py | 2 ++
mercurial/patch.py | 2 +-
mercurial/ui.py | 29 +++++++++++++++++++++++++++++
tests/test-debugcomplete.out | 2 ++
tests/test-extension.out | 2 ++
7 files changed, 45 insertions(+), 10 deletions(-)
# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Date 1248458748 25200
# Node ID 858a881314e7f8afb74ba617fd46a7df8696c3f6
# Parent 63508fc4d03cb3b78a7a80f0131f3be22c6b92b9
ui: Add option to set number of revision hash digits displayed.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -655,7 +655,7 @@
extra = changes[5]
branch = extra.get("branch")
- hexfunc = self.ui.debugflag and hex or short
+ hexfunc = self.ui.nodehash
parents = [(p, hexfunc(log.node(p)))
for p in self._meaningful_parentrevs(log, rev)]
@@ -737,7 +737,7 @@
def __init__(self, ui, repo, patch, diffopts, mapfile, buffered):
changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
- formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
+ formatnode = ui.formatnode
self.t = templater.templater(mapfile, {'formatnode': formatnode},
cache={
'parent': '{rev}:{node|formatnode} ',
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -440,7 +440,7 @@
Use the command 'hg update' to switch to an existing branch.
"""
- hexfunc = ui.debugflag and hex or short
+ hexfunc = ui.nodehash
activebranches = [encoding.tolocal(repo[n].branch())
for n in repo.heads()]
def testactive(tag, node):
@@ -662,10 +662,8 @@
(parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
ui.status(_('created new head\n'))
- if ui.debugflag:
- ui.write(_('committed changeset %d:%s\n') % (rev, hex(node)))
- elif ui.verbose:
- ui.write(_('committed changeset %d:%s\n') % (rev, short(node)))
+ if ui.verbose:
+ ui.write(_('committed changeset %d:%s\n') % (rev, ui.nodehash(node)))
def copy(ui, repo, *pats, **opts):
"""mark files as copied for the next commit
@@ -1628,7 +1626,7 @@
raise util.Abort(_("There is no Mercurial repository here "
"(.hg not found)"))
- hexfunc = ui.debugflag and hex or short
+ hexfunc = ui.nodehash
default = not (num or id or branch or tags)
output = []
@@ -2917,7 +2915,7 @@
used, a third column "local" is printed for local tags.
"""
- hexfunc = ui.debugflag and hex or short
+ hexfunc = ui.nodehash
tagtype = ""
for t, n in reversed(repo.tagslist()):
@@ -3060,6 +3058,8 @@
('', 'encoding', encoding.encoding, _('set the charset encoding')),
('', 'encodingmode', encoding.encodingmode,
_('set the charset encoding mode')),
+ ('', 'hashdigits', int,
+ _('number of revision hash digits shown (default: 12)')),
('', 'traceback', None, _('print traceback on exception')),
('', 'time', None, _('time how long the command takes')),
('', 'profile', None, _('print command execution profile')),
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -414,6 +414,8 @@
ui.setconfig('ui', 'traceback', 'on')
if options['noninteractive']:
ui.setconfig('ui', 'interactive', 'off')
+ if options['hashdigits'] is not None:
+ ui.setconfig('ui', 'hashdigits', str(int(options['hashdigits'])))
if options['help']:
return commands.help_(ui, cmd, options['version'])
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1274,7 +1274,7 @@
if repo.ui.quiet:
r = None
else:
- hexfunc = repo.ui.debugflag and hex or short
+ hexfunc = repo.ui.nodehash
r = [hexfunc(node) for node in [node1, node2] if node]
if opts.git:
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -8,6 +8,7 @@
from i18n import _
import errno, getpass, os, socket, sys, tempfile, traceback
import config, util, error
+import node
_booleans = {'1': True, 'yes': True, 'true': True, 'on': True,
'0': False, 'no': False, 'false': False, 'off': False}
@@ -16,6 +17,7 @@
def __init__(self, src=None):
self._buffers = []
self.quiet = self.verbose = self.debugflag = self._traceback = False
+ self.hashdigits = len(node.short(node.nullid))
self._reportuntrusted = True
self._ocfg = config.config() # overlay
self._tcfg = config.config() # trusted
@@ -100,6 +102,9 @@
self.quiet = not self.debugflag and self.configbool('ui', 'quiet')
if self.verbose and self.quiet:
self.quiet = self.verbose = False
+ self.hashdigits = (not self.debugflag and
+ self.configint('ui', 'hashdigits', self.hashdigits)) \
+ or 0
self._reportuntrusted = self.configbool("ui", "report_untrusted", True)
self._traceback = self.configbool('ui', 'traceback', False)
@@ -145,6 +150,18 @@
result = result.replace(",", " ").split()
return result
+ def configint(self, section, name, default=None, untrusted=False):
+ """Returns an integer."""
+ result = self.config(section, name, untrusted=untrusted)
+ if (result is not None) and (not isinstance(result, (int,long))):
+ try:
+ result = int(result)
+ except ValueError, e:
+ result = None
+ if result is None:
+ result = default
+ return result
+
def has_section(self, section, untrusted=False):
'''tell whether section exists in config.'''
return section in self._data(untrusted)
@@ -196,6 +213,18 @@
if not self.verbose: user = util.shortuser(user)
return user
+ def nodehash(self, nodeval):
+ return self.formatnode(node.hex(nodeval))
+
+ def formatnode(self, nodehex):
+ if self.hashdigits == 0:
+ return nodehex
+ result = nodehex[:self.hashdigits]
+ if len(result) < self.hashdigits:
+ return (self.hashdigits - len(result)) * '0' + result
+ else:
+ return result
+
def _path(self, loc):
p = self.config('paths', loc)
if p and '%%' in p:
diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out
--- a/tests/test-debugcomplete.out
+++ b/tests/test-debugcomplete.out
@@ -97,6 +97,7 @@
--debugger
--encoding
--encodingmode
+--hashdigits
--help
--noninteractive
--profile
@@ -125,6 +126,7 @@
--encoding
--encodingmode
--errorlog
+--hashdigits
--help
--ipv6
--name
diff --git a/tests/test-extension.out b/tests/test-extension.out
--- a/tests/test-extension.out
+++ b/tests/test-extension.out
@@ -46,6 +46,7 @@
--debugger start debugger
--encoding set the charset encoding (default: ascii)
--encodingmode set the charset encoding mode (default: strict)
+ --hashdigits number of revision hash digits shown (default: 12)
--traceback print traceback on exception
--time time how long the command takes
--profile print command execution profile
@@ -76,6 +77,7 @@
--debugger start debugger
--encoding set the charset encoding (default: ascii)
--encodingmode set the charset encoding mode (default: strict)
+ --hashdigits number of revision hash digits shown (default: 12)
--traceback print traceback on exception
--time time how long the command takes
--profile print command execution profile
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090724/a4c0d9de/attachment.pgp
More information about the Mercurial-devel
mailing list