[PATCH] commands: add an option to display only the full id with 'hg id'

Mathias De Maré mathias.demare at gmail.com
Thu Nov 19 13:58:16 UTC 2015


# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1447866343 -3600
#      Wed Nov 18 18:05:43 2015 +0100
# Node ID afb732f543249e09acfd0438747223fbf7a4484f
# Parent  53c668dc6b1601c8bda5098df4e33030dbdb454d
commands: add an option to display only the full id with 'hg id'

'hg id --full' can display the full revision id without having to use --debug.
This avoids potential additional debug messages being printed
and is more intuitive (it's a specific option to 'hg id').

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4165,6 +4165,7 @@
      _('identify the specified revision'), _('REV')),
     ('n', 'num', None, _('show local revision number')),
     ('i', 'id', None, _('show global revision id')),
+    ('', 'full', None, _('show full global revision id')),
     ('b', 'branch', None, _('show branch')),
     ('t', 'tags', None, _('show tags')),
     ('B', 'bookmarks', None, _('show bookmarks')),
@@ -4172,7 +4173,8 @@
     _('[-nibtB] [-r REV] [SOURCE]'),
     optionalrepo=True)
 def identify(ui, repo, source=None, rev=None,
-             num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
+             num=None, id=None, branch=None, tags=None, bookmarks=None,
+             full=None, **opts):
     """identify the working directory or specified revision
 
     Print a summary identifying the repository state at REV using one or
@@ -4194,6 +4196,11 @@
 
           hg id --id > build-id.dat
 
+      - generate a build identifier with the full revision id
+        for the working directory::
+
+          hg id --full > build-id.dat
+
       - find the revision corresponding to a tag::
 
           hg id -n -r 1.3
@@ -4209,11 +4216,11 @@
         raise error.Abort(_("there is no Mercurial repository here "
                            "(.hg not found)"))
 
-    if ui.debugflag:
+    if ui.debugflag or full:
         hexfunc = hex
     else:
         hexfunc = short
-    default = not (num or id or branch or tags or bookmarks)
+    default = not (num or id or full or branch or tags or bookmarks)
     output = []
     revs = []
 
@@ -4264,18 +4271,18 @@
                 taglist.extend(p.tags())
 
             changed = ""
-            if default or id or num:
+            if default or id or full or num:
                 if (any(repo.status())
                     or any(ctx.sub(s).dirty() for s in ctx.substate)):
                     changed = '+'
-            if default or id:
+            if default or id or full:
                 output = ["%s%s" %
                   ('+'.join([hexfunc(p.node()) for p in parents]), changed)]
             if num:
                 output.append("%s%s" %
                   ('+'.join([str(p.rev()) for p in parents]), changed))
         else:
-            if default or id:
+            if default or id or full:
                 output = [hexfunc(ctx.node())]
             if num:
                 output.append(str(ctx.rev()))
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -277,7 +277,7 @@
   grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
   heads: rev, topo, active, closed, style, template
   help: extension, command, keyword
-  identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
+  identify: rev, num, id, full, branch, tags, bookmarks, ssh, remotecmd, insecure
   import: strip, base, edit, force, no-commit, bypass, partial, exact, prefix, import-branch, message, logfile, date, user, similarity
   incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
   locate: rev, print0, fullpath, include, exclude
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -101,7 +101,7 @@
 test generic hooks
 
   $ hg id
-  pre-identify hook: HG_ARGS=id HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None} HG_PATS=[]
+  pre-identify hook: HG_ARGS=id HG_OPTS={'bookmarks': None, 'branch': None, 'full': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None} HG_PATS=[]
   abort: pre-identify hook exited with status 1
   [255]
   $ hg cat b
diff --git a/tests/test-identify.t b/tests/test-identify.t
--- a/tests/test-identify.t
+++ b/tests/test-identify.t
@@ -35,6 +35,8 @@
   cb9a9f314b8b tip
   $ hg id -n
   0
+  $ hg id --full
+  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
   $ hg id -t
   tip
   $ hg id -b
@@ -43,12 +45,16 @@
   cb9a9f314b8b
   $ hg id -n -t -b -i
   cb9a9f314b8b 0 default tip
+  $ hg id -n --full -t -b -i
+  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b 0 default tip
 
 with modifications
 
   $ echo b > a
   $ hg id -n -t -b -i
   cb9a9f314b8b+ 0+ default tip
+  $ hg id -n --full -t -b -i
+  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b+ 0+ default tip
 
 other local repo
 


More information about the Mercurial-devel mailing list