[PATCH 2 of 2] id: add bookmarks to id

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Feb 23 20:48:24 CST 2011


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1298070548 21600
# Branch stable
# Node ID 6a71bc58c67669d7c0e205bb0f6c4cee4d51a1a1
# Parent  0357458cca79624d79a84896067c43020e5170a5
id: add bookmarks to id

Since bookmarks are no longer merged with repo.tags() as of
d012d95499f7, they don't show up in `hg id` as they used to. This adds
them back into the summary that `hg id` prints, and adds a
-B/--bookmarks flag alongside the -t/--tags and -b/--branch options.

Note this introduces a slight backwards-incompatibility: the summary
printed by `hg id` now separates bookmarks from tags with a space, as
seen below, instead of running it into the tags list.

Default summary output:

  $ hg id
  db815d6d32e6 tip/tag1 bm1/bm2

Output with --bookmarks:

  $ hg id --bookmarks
  bm1 bm2

See also afc84a879ac8 which adds bookmarks back into `hg summary`.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2240,8 +2240,8 @@
             else:
                 ui.write("%s\n" % opt)
 
-def identify(ui, repo, source=None,
-             rev=None, num=None, id=None, branch=None, tags=None):
+def identify(ui, repo, source=None, rev=None,
+             num=None, id=None, branch=None, tags=None, bookmarks=None):
     """identify the working copy or specified revision
 
     With no revision, print a summary of the current state of the
@@ -2263,7 +2263,7 @@
                            "(.hg not found)"))
 
     hexfunc = ui.debugflag and hex or short
-    default = not (num or id or branch or tags)
+    default = not (num or id or branch or tags or bookmarks)
     output = []
 
     revs = []
@@ -2277,9 +2277,9 @@
             rev = revs[0]
         if not rev:
             rev = "tip"
-        if num or branch or tags:
-            raise util.Abort(
-                "can't query remote revision number, branch, or tags")
+        if num or branch or tags or bookmarks:
+            raise util.Abort("can't query remote revision number,"
+                             " branch, tags, or bookmarks")
         output = [hexfunc(repo.lookup(rev))]
     elif not rev:
         ctx = repo[None]
@@ -2310,12 +2310,20 @@
         if t:
             output.append(t)
 
+        # multiple bookmarks for a single parent separated by '/'
+        bm = '/'.join(ctx.bookmarks())
+        if bm:
+            output.append(bm)
+
     if branch:
         output.append(ctx.branch())
 
     if tags:
         output.extend(ctx.tags())
 
+    if bookmarks:
+        output.extend(ctx.bookmarks())
+
     ui.write("%s\n" % ' '.join(output))
 
 def import_(ui, repo, patch1, *patches, **opts):
@@ -4460,8 +4468,9 @@
           ('n', 'num', None, _('show local revision number')),
           ('i', 'id', None, _('show global revision id')),
           ('b', 'branch', None, _('show branch')),
-          ('t', 'tags', None, _('show tags'))],
-         _('[-nibt] [-r REV] [SOURCE]')),
+          ('t', 'tags', None, _('show tags')),
+          ('B', 'bookmarks', None, _('show bookmarks'))],
+         _('[-nibtB] [-r REV] [SOURCE]')),
     "import|patch":
         (import_,
          [('p', 'strip', 1,
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -234,3 +234,7 @@
   commit: (clean)
   update: 1 new changesets, 2 branch heads (merge)
 
+test id
+
+  $ hg id
+  db815d6d32e6 tip Y/Z/x  y
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -230,7 +230,7 @@
   grep: print0, all, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
   heads: rev, topo, active, closed, style, template
   help: 
-  identify: rev, num, id, branch, tags
+  identify: rev, num, id, branch, tags, bookmarks
   import: strip, base, force, no-commit, exact, import-branch, message, logfile, date, user, similarity
   incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, 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
@@ -66,7 +66,7 @@
 test generic hooks
 
   $ hg id
-  pre-identify hook: HG_ARGS=id HG_OPTS={'branch': None, 'id': None, 'num': None, 'rev': '', 'tags': None} HG_PATS=[] 
+  pre-identify hook: HG_ARGS=id HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'num': None, 'rev': '', 'tags': None} HG_PATS=[] 
   warning: pre-identify hook exited with status 1
   [1]
   $ 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
@@ -62,10 +62,28 @@
   $ hg id http://localhost:$HGPORT1/
   cb9a9f314b8b
 
+remote with rev number?
+
+  $ hg id -n http://localhost:$HGPORT1/
+  abort: can't query remote revision number, branch, tags, or bookmarks
+  [255]
+
 remote with tags?
 
   $ hg id -t http://localhost:$HGPORT1/
-  abort: can't query remote revision number, branch, or tags
+  abort: can't query remote revision number, branch, tags, or bookmarks
+  [255]
+
+remote with branch?
+
+  $ hg id -b http://localhost:$HGPORT1/
+  abort: can't query remote revision number, branch, tags, or bookmarks
+  [255]
+
+remote with bookmarks?
+
+  $ hg id -B http://localhost:$HGPORT1/
+  abort: can't query remote revision number, branch, tags, or bookmarks
   [255]
 
 Make sure we do not obscure unknown requires file entries (issue2649)


More information about the Mercurial-devel mailing list